﻿// JScript File

/*----------------------------------------------------------------------------------
        SetStars
------------------------------------------------------------------------------------*/	
function SetStars(numberOfStars) {
	    document.forms.popupForm.foodRating.value = numberOfStars;

	    var elems = getElementsByClass('current-rating', null, null);

	    var elem = elems[0];

	    elem.style.width = numberOfStars*20+'%';
}


/*----------------------------------------------------------------------------------
       doSort
------------------------------------------------------------------------------------*/
function doSort (searchString) {
		document.DateSubmit.searchString.value = searchString;
		document.DateSubmit.submit();
}

 
/*----------------------------------------------------------------------------------
       copyAndSaveFavorite
------------------------------------------------------------------------------------*/    
 function copyAndSaveFavorite(orderId) {
	        //Copy stuff and things.
	        document.pageForm.InfoPopup_orderId.value = orderId;
	        document.pageForm.InfoPopup_name.value = document.getElementById('InfoPopup_name_'+orderId).value;
	        saveFavorite();
}


/*----------------------------------------------------------------------------------
       checkIfValidKeyPress
------------------------------------------------------------------------------------*/
 var isValidKeyPress = true;
function checkIfValidKeyPress(e){
		var keycode;

		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;

		if (keycode != 9 && keycode != 144 && keycode != 20) { //9=Tab, 144=NumLock , 20=CapsLock, 
		    isValidKeyPress = true;
		}else{
		    isValidKeyPress = false;
		}
}


/*----------------------------------------------------------------------------------
       toggleInProgressGraphic
------------------------------------------------------------------------------------*/
 function toggleInProgressGraphic(displayText, show){
                if(show){
                    document.getElementById('ajaxIndicatorPlaceHolder').innerHTML = displayText + '<br><br><img src=\"../images/ajaxIndicator.gif\" />';
                }else{
                    document.getElementById('ajaxIndicatorPlaceHolder').innerHTML = '';
                }
 }	    

/*----------------------------------------------------------------------------------
       toggleTableState
------------------------------------------------------------------------------------*/  
function toggleTableState(tableId,isDisabled){
                    if(document.getElementById(tableId) != null)
			document.getElementById(tableId).disabled = isDisabled;
 }	 
 
 
/*----------------------------------------------------------------------------------
       setTimer
------------------------------------------------------------------------------------*/ 
var allTimeoutIds = '';
var timeoutId;
            
function setTimer(timedFunction){    
                timeoutId = window.setTimeout(timedFunction, 2000); 
                setAllTimeoutIds();
 } 
 
 

/*----------------------------------------------------------------------------------
       setAllTimeoutIds
------------------------------------------------------------------------------------*/  
 function setAllTimeoutIds(){
                if(typeof allTimeoutIds != 'undefined'){
                    if(allTimeoutIds != ''){
                        allTimeoutIds += ',' + timeoutId;
                    }else{
                        allTimeoutIds = ',' + timeoutId;
                    }
                }else{
                    allTimeoutIds = ',' + timeoutId;
                }
  }  
	  


/*----------------------------------------------------------------------------------
      UpdateFavoriteRank
------------------------------------------------------------------------------------*/	  
function UpdateFavoriteRank(templateId){
	    var temp;
	    temp = allTimeoutIds.split(",");
	     
	    for(var i=0; i<temp.length; i++){
	        clearTimeout(temp[i]);
	    }
	    
        var favoriteRank = document.getElementById('template_' + templateId).value;
        
        if(isNaN(favoriteRank)){
            toggleInProgressGraphic('',false);
            toggleTableState('favoriteManagementTable',false)
            alert("Please enter a Valid Favorite Rank. (Numbers Only)");
            document.getElementById('template_' + templateId).focus();
        }else{
            CreateCommand('<%=AjaxEnum.UPDATEFAVORITERANK.Code%>',templateId);
        }
 }  
 
 
/*----------------------------------------------------------------------------------
      AddThis
------------------------------------------------------------------------------------*/ 
function AddThis() {
	    var reviewText = document.getElementById('reviewText').value;
	    CreateCommand('<%=AjaxEnum.ADDREVIEW.Code%>', reviewText);
}


/*----------------------------------------------------------------------------------
      submitProductTags
------------------------------------------------------------------------------------*/ 
function submitProductTags() {
	    var url = 'UpdateTagPopup.m'; 
	    document.tagForm.action=url;
	    document.tagForm.submit(); 
}


/*----------------------------------------------------------------------------------
      SetReferAFriendFlagToTrue
------------------------------------------------------------------------------------*/
function SetReferAFriendFlagToTrue() {
	    document.pageForm.ReferAFriendFromStep1.value = 'Y';
}


/*----------------------------------------------------------------------------------
      saveSMSLocationCode
------------------------------------------------------------------------------------*/
function saveSMSLocationCode(deliveryAddressId){
	checkIfValidKeyPress();
	if(isValidKeyPress){
	    toggleInProgressGraphic('Saving Address Code',true);
	    toggleTableState('addressManagementTable',true);
	    setTimer('updateSMSLocationCode(' + deliveryAddressId + ')');
	}
}
    

/*----------------------------------------------------------------------------------
      updateSMSLocationCode
------------------------------------------------------------------------------------*/
function updateSMSLocationCode(deliveryAddressId){
        var smsLocationCode = document.getElementById('addr_' + deliveryAddressId);
        smsLocationCode.value = smsLocationCode.value.toUpperCase();
        CreateCommand('<%=AjaxEnum.UPDATESMSLOCATIONCODE.Code%>',deliveryAddressId);
 }
 

/*----------------------------------------------------------------------------------
      DeletePrimaryCardAndUpdateAccount
------------------------------------------------------------------------------------*/ 
function DeletePrimaryCardAndUpdateAccount() {
	document.pageForm.PrimaryCCType.value = "";
	document.pageForm.PrimaryCCNumber.value = "";
	document.pageForm.PrimaryCCExpYear.value = "";
	document.pageForm.PrimaryCCExpMonth.value = "";
	document.pageForm.CreditCardZipCode.value = "";
	document.pageForm.CreditCardSecurityCode.value = "";
	doPost(document.pageForm, 'UpdateMyAccount.m');
}



/*----------------------------------------------------------------------------------
      CopyBirthDateToHiddenField
------------------------------------------------------------------------------------*/
function CopyBirthDateToHiddenField() {
       document.pageForm.birthDate.value = document.pageForm.birthMonth[document.pageForm.birthMonth.selectedIndex].value+'/'+
                                            document.pageForm.birthDay[document.pageForm.birthDay.selectedIndex].value+'/' +
                                            document.pageForm.birthYear[document.pageForm.birthYear.selectedIndex].value;
}


/*----------------------------------------------------------------------------------
      saveFavoriteRank
------------------------------------------------------------------------------------*/
function saveFavoriteRank(templateId){
	    checkIfValidKeyPress();
	    if(isValidKeyPress){
		toggleInProgressGraphic('Saving Favorite Numbers',true);
		toggleTableState('favoriteManagementTable',true);
		setTimer('UpdateFavoriteRank(' + templateId + ')');
	    }
}


/*----------------------------------------------------------------------------------
      SaveReview
------------------------------------------------------------------------------------*/
function SaveReview(){
	    doPost(document.forms.user_rating_form, 'UpdateConsumerStep3.m');
}



/*----------------------------------------------------------------------------------
      GoToMenu
------------------------------------------------------------------------------------*/
function GoToMenu() {
	var menuPlusTabIds = document.getElementById("seamlessWebMenuUserReviewTabIds");
	if(menuPlusTabIds != null) {
	    var menuId = menuPlusTabIds.value.toString().split('|');
	    changeMenuPlusTab(menuId[0]);
	} else {
	    doPost(document.pageForm, "ConsumerMenuSelection.m?extVendorLocationId="+document.forms.pageForm.vendorLocationId.value);
	}
 }


/*----------------------------------------------------------------------------------
      setTagType
------------------------------------------------------------------------------------*/
function setTagType(vendorLocationReviewTagType){
	    document.forms.pageForm.vendorLocationReviewTagType.value = vendorLocationReviewTagType;
	}
	


/*----------------------------------------------------------------------------------
      highlightTag
------------------------------------------------------------------------------------*/	
 /**
    * This method highlights elements in the tag cloud and on the page.
    * If you click on a tag, highlights menu items.  Click it again, it unhighlights.
    * Click on a another tag, unhighlights whatever was highlighted, and highlights the ones you want.
    * Mike Parsons with Bob Dunn's Aura!
    **/
    function highlightTag(tagListElementId) {
        var elems = getElementsByClass('tagCloudListItem', null, null);
        var highlight;
        
        
        /* first toggle the particular element we're interested in the tag cloud to active */
        var elem = document.getElementById(tagListElementId);
        
        if (!elem.className.match("active")) {
           elem.className += " active";
           highlight = true;
        } else {
            var rep = elem.className.match(' active')?' active':'active';
            elem.className = elem.className.replace(rep,'');
            highlight = false;
        }
        
        /* next remove active from all tags except target tag in the tag cloud */
        for (var i=0; i<elems.length; i++) {
            if (elems[i].id != tagListElementId) {
                var rep = elems[i].className.match(' active')?' active':'active';
                elems[i].className = elems[i].className.replace(rep,'');
            }
        }
        
        /* now toggle the highlight style on the menu items themselves.  This is all very complicated :-) */
        elems = getElementsByClass(elem.firstChild.innerHTML,null,null);
        
        
        for (var i=0; i<elems.length; i++) {
            if (!elems[i].className.match("highlight")) {
               elems[i].className += " highlight";
            } else {
                /* If the target tag is there, and it's highlighted, dont unhighlight it*/
                if (!elems[i].className.match(elem.firstChild.innerHTML) || highlight == false) {
                    var rep = elems[i].className.match(' highlight')?' highlight':'highlight';
                    elems[i].className = elems[i].className.replace(rep,'');
                }
            }
        }
        
        /*Remove highlight class from the rest of the elements.*/
        elems = getElementsByClass('CategoryTableClass', null, null);
        
        for (var i=0; i<elems.length; i++) {
            var tableRows = elems[i].getElementsByTagName('tr');
            
            for (var k=0; k < tableRows.length; k++) {
                if (tableRows[k].className.match(elem.firstChild.innerHTML)) {
                                                  
                } else {
                   var rep = tableRows[k].className.match(' highlight')?' highlight':'highlight';
                   tableRows[k].className = tableRows[k].className.replace(rep,''); 
                }
            }
        }
    }
  
  
/*----------------------------------------------------------------------------------
      ShowReviews
------------------------------------------------------------------------------------*/
function ShowReviews() {
	    document.forms.pageForm.showReviews.value = "Y";
	    doPost(document.forms.pageForm, 'ConsumerMenuSelection.m');
}  


/*----------------------------------------------------------------------------------
      addToFavorites
------------------------------------------------------------------------------------*/
function addToFavorites() {
	if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion >= "4.0")
	    window.external.AddFavorite(location.href, document.title);
	else
	    alert("Please press OK, then press CTRL-D to bookmark this page.");
 }
 

/*----------------------------------------------------------------------------------
      CloseWindow
------------------------------------------------------------------------------------*/
function CloseWindow() {
	    top.window.close();
}


/*----------------------------------------------------------------------------------
      ShowGiftCardDeliveryAddressFields
------------------------------------------------------------------------------------*/
 function ShowGiftCardDeliveryAddressFields() {	    
	var isDeliverWithOrder = document.orderAttributes.AlternateGiftCardDeliveryAddress.checked;
	if(isDeliverWithOrder) {
	    document.getElementById('GiftCardDeliveryAddress').style.display = 'none';
	    try{
		document.pageForm.buildingFloor.value = '';
		document.pageForm.street.value = ''
		document.pageForm.zipCode.value = '';
	    }catch(err){}
	} else {
	    document.getElementById('GiftCardDeliveryAddress').style.display = '';
	}
 }
 
 
 /*----------------------------------------------------------------------------------
      SubmitForm
------------------------------------------------------------------------------------*/
 function SubmitForm(event) {
		var keycode;
 		if (window.event) keycode = window.event.keyCode;
 		else if (event) keycode = event.which;
 		if (keycode == 13) {    
 		    doPost();
 		}
 }
 
 /*----------------------------------------------------------------------------------
      resetStyle
------------------------------------------------------------------------------------*/ 
 function resetStyle(obj) {
    		obj.style.color = "Black";
		obj.style.fontWeight = "normal";
		if (obj.value = "Enter Personal Email") {
		    obj.value = "";
		}
	    
}
	    

 /*----------------------------------------------------------------------------------
      validateUserInfo
------------------------------------------------------------------------------------*/
function validateUserInfo(personalemail, password) {
		
		var email = personalemail.value;
		var pwd = password.value; 
		
		if (email.length == 0 || email == 'Enter Personal Email' || email.indexOf('@') <= 0 || email.indexOf('.') <= 0) {
		    alert("Your Email Address Appears to be Invalid. Please enter your personal email.");
		    personalemail.style.color = "red";
		    personalemail.style.fontWeight = "bold";
		    personalemail.value = "Enter Personal Email";
		    return false; 
		} 
		
		if (pwd.length == 0) {
		    alert("You must enter a password.");
		    return false;
		}
		
		return true;
 }

 
 /*----------------------------------------------------------------------------------
      DeleteAddress
------------------------------------------------------------------------------------*/
 function DeleteAddress(delivAddrId)
  {
      if (confirm('Are you sure you want to delete this address?')) {
          window.location = "AddressManagement.m?delete=" + delivAddrId;
      }
  }	
  

/*----------------------------------------------------------------------------------
      EngageReferral
------------------------------------------------------------------------------------*/
function EngageReferral(e) {
	    var keycode;
	    if (window.event) keycode = window.event.keyCode;
	    else if (e) keycode = e.which;
	    if (keycode == 13)
	    {    
		doPost(document.pageForm, 'ConsumerReferralStep1.m');
	    }
	}
	


/*----------------------------------------------------------------------------------
      CheckPromoClicked
------------------------------------------------------------------------------------*/	
function CheckPromoClicked(){
    document.getElementById('PromoCodeClicked').value="Y";
 }
 
 
/*----------------------------------------------------------------------------------
      EngageSubmit
------------------------------------------------------------------------------------*/	 
  function EngageSubmit(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	if (keycode == 13)
	{    
	    doPost(document.pageForm, 'SubmitLogin.m');
	}
 } 