﻿// JScript File

/*----------------------------------------------------------------------------------
        doPost
------------------------------------------------------------------------------------*/

function doPost(form, url) {
			form.action = url;
			form.submit();
}


 
/*----------------------------------------------------------------------------------
       UserSearch
------------------------------------------------------------------------------------*/
function UserSearch(SearchType) {
	    switch (SearchType) {
		case "AboutUs" :
		    UserSearchWindow = window.open("../public/AboutUs.html", "UserSearch","menubar=yes,toolbar=no,width=780,height=580,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no");
		    break;
		case "Contact" : 
		    UserSearchWindow = window.open("../public/contact.html", "UserSearch","menubar=yes,toolbar=no,width=780,height=580,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no");
		    break;
		case "TellaColleague" :
    		    UserSearchWindow = window.open("../TellAColleagueAnonymous.m", "UserSearch","menubar=yes,toolbar=no,width=780,height=580,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no");
		    break;
		};
	}

/*----------------------------------------------------------------------------------
       ShowAllVendorLocations
------------------------------------------------------------------------------------*/
	function ShowAllVendorLocations() {
	    document.pageForm.browseBy.value = 'ALL' ;
	    '<%if (!model.NeighborhoodId.IsValid) {%>'
		document.pageForm.searchKeyword.value = '';
	    '<%}%>'
	    doPost(document.pageForm, 'ConsumerVendorSelection.m');
	}


/*----------------------------------------------------------------------------------
       ShowVendorLocations
------------------------------------------------------------------------------------*/        
	function ShowVendorLocations(strBrowse,vendorGroupDetailId, form, url,neighborhoodId) {
	    document.pageForm.browseBy.value = strBrowse ;
	    	    
	    document.pageForm.searchCuisineId.value = vendorGroupDetailId;
	    document.pageForm.searchType.value = "Food";
	    document.pageForm.neighborhoodId.value = neighborhoodId;
	    document.pageForm.specialSearchCriteria.value = strBrowse;	    
	    doPost(document.pageForm, url);    	
	}


/*----------------------------------------------------------------------------------
       ShowVendorLocationsSort
------------------------------------------------------------------------------------*/        
	function ShowVendorLocationsSort(strSort) {
	    if(document.pageForm.sortBy.value == strSort) {
	        if(document.pageForm.sortDirection.value == "Normal") {
	            document.pageForm.sortDirection.value = "Reverse";
	        } else {
	            document.pageForm.sortDirection.value = "Normal";
	        }
	    } else {
	        document.pageForm.sortBy.value = strSort;
	        document.pageForm.sortDirection.value = "Normal";
	    }
	    doPost(document.pageForm, 'ConsumerVendorSelection.m');
	}
	
/*----------------------------------------------------------------------------------
      ShowNewAddressEditFields
------------------------------------------------------------------------------------*/	
 function ShowNewAddressEditFields() {
	//document.getElementById('NeighborhoodNewAddress').style.display = 'block';
	//document.getElementById('NewAddressLink').style.display = 'none';
	if(document.pageForm.addressId != null){
	    document.pageForm.addressId.options[0].selected=true;
	}
    }
 
 
 /*----------------------------------------------------------------------------------
      HideNewAddressEditFields
------------------------------------------------------------------------------------*/       
 function HideNewAddressEditFields() {
	document.getElementById('NeighborhoodNewAddress').style.display = 'none';
	document.getElementById('NewAddressLink').style.display = 'block';    	
 }	


/*----------------------------------------------------------------------------------
      writeVendorGroupDetailIdAndPost
------------------------------------------------------------------------------------*/	
function writeVendorGroupDetailIdAndPost(vendorGroupDetailId, form, url,neighborhoodId) {
	    document.pageForm.CuisineSelectedFromList.value = "Y";
	    document.pageForm.StayOnStep2OnError.value = "Y";
	    document.pageForm.searchCuisineId.value = vendorGroupDetailId;
	    document.pageForm.searchType.value = "Food";
	    document.pageForm.searchKeyword.value = "";
	    document.pageForm.browseBy.value = "";
	    
	    document.pageForm.neighborhoodId.value = neighborhoodId;
	    doPost(form, url);
}	


/*----------------------------------------------------------------------------------
        EngageSearchAddress
------------------------------------------------------------------------------------*/
function EngageSearchAddress(e) {
	    var keycode;
	    if (window.event) keycode = window.event.keyCode;
	    else if (e) keycode = e.which;
	    if (keycode == 13)
	    {    
		SearchAddress();
	    }
}

	
/*----------------------------------------------------------------------------------
        postURL
------------------------------------------------------------------------------------*/
function postURL(DestURL,PostAction){
	    document.forms.pageForm.postAction.value = PostAction;
	    doPost(document.forms.pageForm, DestURL);
}


/*----------------------------------------------------------------------------------
        PostNeighborhood
------------------------------------------------------------------------------------*/
function PostNeighborhood(id) {
	document.pageForm.changeAddress.value = "N";
	document.pageForm.neighborhoodId.value = id;
	doPost(document.pageForm, 'UpdateConsumerHome.m');
 }
 
/*----------------------------------------------------------------------------------
        spiderSubmit
------------------------------------------------------------------------------------*/ 
function spiderSubmit() {
	document.getElementById("searchKeyword").value = "%";
	doPost(document.pageForm, 'UpdateConsumerHome.m');
 }
 

/*----------------------------------------------------------------------------------
        EngageLogin
------------------------------------------------------------------------------------*/ 
 function EngageLogin(e) {
		var keycode;

		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;

		if (keycode == 13) {   
		    doPost(document.loginForm, 'SubmitLogin.m');
		}
}


/*----------------------------------------------------------------------------------
        goForward
------------------------------------------------------------------------------------*/
 function goForward(form,vlocationId,url){
	document.pageForm.vendorLocationId.value = vlocationId;
	doPost(form, url);
 }
 
/*----------------------------------------------------------------------------------
        GetVendor
------------------------------------------------------------------------------------*/
 function GetVendor(vendorLocationId,isFeaturedVendor){
	    document.pageForm.vendorLocationId.value=vendorLocationId;
	    document.pageForm.updateFeaturedVendorLocationId.value = isFeaturedVendor;  
	    doPost(document.pageForm, 'UpdateConsumerStep2.m');	    
}
 
 
/*----------------------------------------------------------------------------------
        UpdateSSGODistance
------------------------------------------------------------------------------------*/       
 function UpdateSSGODistance(){
	    //ClearSearch();
	    doPost(document.pageForm, 'SSGOSetup.m?deliveryType=P');
	}

/*----------------------------------------------------------------------------------
UpdateDistance
------------------------------------------------------------------------------------*/
function UpdateDistance() {
    //ClearSearch();
    doPost(document.pageForm, 'ConsumerVendorSelection.m');
}
 
/*----------------------------------------------------------------------------------
        EditDeliveryInfo
------------------------------------------------------------------------------------*/
function EditDeliveryInfo(DestURL){
	    document.forms.pageForm.edit.value = 'Y'
	    doPost(document.forms.pageForm, DestURL);
}


/*----------------------------------------------------------------------------------
        SubmitAddressEditFromDeliveryInfo
------------------------------------------------------------------------------------*/
function SubmitAddressEditFromDeliveryInfo(){
 	    doPost(document.pageForm, 'ConsumerHome.m');
 }
 
 
/*----------------------------------------------------------------------------------
        ApplyCouponOnly
------------------------------------------------------------------------------------*/
 function ApplyCouponOnly() {
document.pageForm.applyCouponOnly.value = "Y";
 }
 
/*----------------------------------------------------------------------------------
        ChangeAddressIfValidId
------------------------------------------------------------------------------------*/
function ChangeAddressIfValidId() {
        
	var AddrId=document.getElementById("AddressId");
	if (AddrId.options[AddrId.selectedIndex].text != "") {
	    document.pageForm.changeAddress.value = "Y";
	} else {
	    document.pageForm.changeAddress.value = "N";
	}
        
 }
 
/*----------------------------------------------------------------------------------
       toggleSaveFavorite
------------------------------------------------------------------------------------*/ 
function toggleSaveFavorite() {
	var obj = document.getElementById("SaveFavoriteInput");
	var cBox = document.getElementById("SaveFavoriteOption");
	if (cBox.checked) {
	    obj.style.display = "block";
	    obj.style.visibility = "visible";
	} else {
	    obj.style.display = "none";
	    obj.style.visibility = "hidden";
	}		    
	
    } 
    
    
/*----------------------------------------------------------------------------------
       PossibleNewAddressEntered
------------------------------------------------------------------------------------*/   
function PossibleNewAddressEntered() {
	document.pageForm.changeAddress.value = "Y";
 }
 

/*----------------------------------------------------------------------------------
       ShowEditDeliveryTime
------------------------------------------------------------------------------------*/ 
 function ShowEditDeliveryTime() {
	HideElement('deliveryTimeDisplay');
	ShowElement('deliveryTimeEdit');
  }
  

/*----------------------------------------------------------------------------------
      ClickAddToOrder
------------------------------------------------------------------------------------*/   
function ClickAddToOrder(ajaxEnum,orderId) {
	if(document.orderAttributes.addItemToOrderClicked.value != "Y") {
	    document.orderAttributes.addItemToOrderClicked.value="Y";
	    CreateCommand(ajaxEnum,orderId);
	}
 }
 

/*----------------------------------------------------------------------------------
      adjustItemPrice
------------------------------------------------------------------------------------*/  
 function adjustItemPrice(cartItemCount, totalPrice) {
	var obj = document.getElementById("totalItemPrice" + cartItemCount);
	//alert("OBJ: " + obj);
	if (obj != null) {
	    //alert("SETTING PRICE: " + totalPrice);
	    obj.innerHTML = totalPrice;
	}
 }  
 
 
/*----------------------------------------------------------------------------------
      populateBrowseBy
------------------------------------------------------------------------------------*/ 
function populateBrowseBy(strBrowse) {
	document.pageForm.browseBy.value = strBrowse ;
        
}

/*----------------------------------------------------------------------------------
      SetHiddenFields
------------------------------------------------------------------------------------*/
function SetHiddenFields(neighId,cuisine) {
	    document.pageForm.searchCuisineId.value = cuisine;
}


/*----------------------------------------------------------------------------------
      writesearchcuisine
------------------------------------------------------------------------------------*/
function writesearchcuisine(id) {
	document.pageForm.searchCuisineId.value = id ;
}

/*----------------------------------------------------------------------------------
      CancelDateSelector
------------------------------------------------------------------------------------*/
function CancelDateSelector() {
	    HideDateSelector();
	    //TODO::reset default values.
}


/*----------------------------------------------------------------------------------
      HideDateSelector
------------------------------------------------------------------------------------*/        
function HideDateSelector() {
	    document.getElementById('VisibleDeliveryDate').style.display = 'none';
	    document.getElementById('VisibleDeliveryDate').style.visibility = 'invisible';
}


/*----------------------------------------------------------------------------------
      ToggleDetailViewValue
------------------------------------------------------------------------------------*/
function ToggleDetailViewValue() {
	var detailView = document.getElementById("restaurantListDetailView").value;
	var newValue;
	if (detailView == "Y") {
	    newValue = "N";
	} else {
	    newValue = "Y";
	}
	document.getElementById("restaurantListDetailView").value = newValue;
 }
 
 
/*----------------------------------------------------------------------------------
      writeProductCategoryInfo
------------------------------------------------------------------------------------*/ 
function writeProductCategoryInfo(prodId,catId) {
		document.pageForm.productId.value = prodId;
		document.pageForm.categoryId.value = catId;
}

/*----------------------------------------------------------------------------------
      hideElementsOfClass
------------------------------------------------------------------------------------*/
function hideElementsOfClass(className) {
	    var elementsList = getElementsByClass(className, null, null);
	    
	    for (var i =0; i<elementsList.length; i++) {
	        elementsList[i].style.display = 'none';
	    }
	    
	    toggleViewHideDetails();
}	
	
/*----------------------------------------------------------------------------------
      showElementsOfClass
------------------------------------------------------------------------------------*/	
function showElementsOfClass(className) {
	    var elementsList = getElementsByClass(className, null, null);
	    
	    for (var i=0; i<elementsList.length; i++) {
	        elementsList[i].style.display = 'block';
	    }
	    
	    toggleViewHideDetails();
}
	
/*----------------------------------------------------------------------------------
      toggleViewHideDetails
------------------------------------------------------------------------------------*/	
function toggleViewHideDetails() {
	    var elem = document.getElementById('viewHideDetails');
	    
	    if (elem.innerHTML == 'View Details') {
	        elem.innerHTML = 'Hide Details';
	        elem.href = "javascript:hideElementsOfClass('hidden');";
	    } else if (elem.innerHTML == 'Hide Details') {
	        elem.innerHTML = 'View Details';
	        elem.href = "javascript:showElementsOfClass('hidden');";
	    }
}


/*----------------------------------------------------------------------------------
      ClearFav
------------------------------------------------------------------------------------*/
function ClearFav(){
	document.forms.pageForm.favoriteName.value = "";
}


/*----------------------------------------------------------------------------------
      ClearFav
------------------------------------------------------------------------------------*/ 
function StoreAndClearStreet(o) {
	    if (o.value == 'Enter Address Here') {
		textFieldStoreAndClear(o);
	    } else {
		//If they had an email and delete it, we'll store this to replace an empty box on blur.
		o.originalText = 'Enter Address Here';
		'<%if(model.IsRecognized.IsFalse && address.Length<1){%>'
			o.originalColor="Black"
		'<%}%>' 
	    }
}


/*----------------------------------------------------------------------------------
      ChangeSearchType
------------------------------------------------------------------------------------*/
function ChangeSearchType(searchVal) {
		document.pageForm.SearchType.value = searchVal;
}

/*----------------------------------------------------------------------------------
      ShowPrivacyPopup
------------------------------------------------------------------------------------*/
function ShowPrivacyPopup() {
	UserSearchWindow = window.open("../public/privacy.html", "UserSearch","menubar=yes,toolbar=no,width=610,height=520,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes");	
}

/*----------------------------------------------------------------------------------
      writeLine
------------------------------------------------------------------------------------*/	
function writeLine(line) {
	    document.pageForm.lineId.value = line;
}


/*----------------------------------------------------------------------------------
      refineResultsAction
------------------------------------------------------------------------------------*/
function refineResultsAction(filter) {
		    switch (filter) {
            case "All Restaurants":
                ClearCuisineType();
                ShowAllVendorLocations();
                break;
            case "Open Restaurants":
                ClearCuisineType();
                ShowVendorLocations('OpenRestaurants','',document.pageForm, 'ConsumerVendorSelection.m','<%=model.NeighborhoodId%>');
                break;
            case "New Restaurants":
                ClearCuisineType();
                ShowVendorLocations('NewRestaurants','',document.pageForm, 'ConsumerVendorSelection.m','<%=model.NeighborhoodId %>');
                break;
            case "My Bookmarked Restaurants":
                ClearCuisineType();
                ShowVendorLocations('MyBookmarkedRestaurants', '', document.pageForm, 'ConsumerVendorSelection.m', '<%=model.NeighborhoodId %>');
                break;   
            case "5":
                writeVendorGroupDetailIdAndPost('5', document.pageForm, 'ConsumerVendorSelection.m','<%=model.NeighborhoodId%>');
                break;
            default:
                writeVendorGroupDetailIdAndPost(filter, document.pageForm,'ConsumerVendorSelection.m','<%=model.NeighborhoodId%>');
                break;
        }        
        
  }
  

/*----------------------------------------------------------------------------------
      getElementsByClass
------------------------------------------------------------------------------------*/  
   function getElementsByClass(searchClass,node,tag) {
		    var classElements = new Array();
		    if ( node == null )
			node = document;
		    if ( tag == null )
			tag = '*';
		    var els = node.getElementsByTagName(tag);
		    var elsLen = els.length;
		    var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
		    for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
			    classElements[j] = els[i];
			    j++;
			}
		    }
		    return classElements;
		}
		
		

/*----------------------------------------------------------------------------------
      popUpVerisign
------------------------------------------------------------------------------------*/
 function popUpVerisign(url) 
{
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin"; 
 }	

  
  