
function KeyDownHandler()
{    //When press Enter key on client Form (Global search)
     // process only the Enter key
        if (event.keyCode == 13)
        {
            // cancel the default submit
            event.returnValue=false;
            event.cancel = true;
            // submit the form by programmatically clicking the specified button
            document.getElementById('btnGeneralSearch').click();
        }

}
//function ApplySortFilter() 
//{
//    if (document.all.cboSortBy.options != null)
//        {window.location=document.all.cboSortBy.options[document.all.cboSortBy.selectedIndex].value}
//}
function ProcessGeneralSearch() 
{

/*
    href: "http://localhost/apps/travel/destinations/SearchResults.aspx?searchType=0&pageD=1&pageP=9&displayMode=1&bc=#link_attraction"
    protocol: "http:"
    host: "localhost"
    hostname: "localhost"
    port: ""
    pathname: "/apps/travel/destinations/SearchResults.aspx"
    search: "?searchType=0&pageD=1&pageP=9&displayMode=1&bc="
    hash: "#link_attraction"
*/
    
    var theForm = document.getElementById("frmPlacesSearch");
    var txt = theForm.txtGeneralSearch.value;
    
    //var txt = document.all.frmPlacesSearch.txtGeneralSearch.value;
    

    if (txt.length < 2)
    {
        alert('Destination name must be at least two characters.')    
        theForm.txtGeneralSearch.focus();
        return false;
    }
   
    theForm.action='SearchResults.aspx?searchType=0&keyword=' + txt + '&displayMode=0&source=d&page=1';
    theForm.submit();
    
    //document.all.frmPlacesSearch.action='SearchResults.aspx?searchType=0&keyword=' + txt + '&displayMode=0&source=d&page=1';                                                  
    //document.all.frmPlacesSearch.submit();

}

function ShowDiamondRatingPopup()
{
    var url = ""
    switch (document.getElementById('hdnTBSearchType').value)
    {
        case "1": //2^0
            url="Hotel"
            break;
        case "4": //2^2
            url="Restaurant"
            break;
        default:
            url="Hotel"
    }
    window.open('Diamonds.html#'+ url, '', 
    'location=no, menubar=no, scrollbars=yes height=350, width=320, status=yes, resizable=no')
    
}

function $(id){
	return document.getElementById(id);	
}

function ManageAdvancedSearchDisplayOnLoad() 
{
	
   // var searchType = document.getElementById('goodHdnSearchType').value;
	//alert($('hdnTBSearchType').value);
     switch ($('hdnTBSearchType').value)
    {
        case "1":
            ManageAdvancedSearchDisplay($('rdbHotel'));
            break;
        case "2":
            ManageAdvancedSearchDisplay($('rdbAttraction'))
            break;
        case "4":
            ManageAdvancedSearchDisplay($('rdbRestaurant'));
            break;
        default:
            ManageAdvancedSearchDisplay($('rdbHotel'));     
    }
	UpdateStateList();
	$('txtName').focus();
    
}



function ManageAdvancedSearchDisplay(rdbutton)
{
    //alert('ctl00_cphMain_rdbHotel clicked');
    //onclick="return ManageAdvancedSearchDisplay(this);" 
    if (rdbutton.id.toLowerCase().indexOf('hotel') > -1) {
        $('divHotel').style.display='';
        $('divDiamondRating').style.display='';
        $('divAttraction').style.display='none';
        $('divRestaurant').style.display='none';
        $('rdbHotel').value="on";
        $('rdbAttraction').value="";
        $('rdbRestaurant').value="";
        $('rdbAttraction').checked=false;
        $('rdbRestaurant').checked=false;
        $('hdnTBSearchType').value="1"; //2^0
		$('goodHdnSearchType').value = 'rdbHotel';
    }
    
        if (rdbutton.id.toLowerCase().indexOf('attraction') > -1) {
        $('divHotel').style.display='none';
        $('divDiamondRating').style.display='none';
        $('divRestaurant').style.display='none'; 
        $('divAttraction').style.display='';  
        $('rdbHotel').value="";
        $('rdbAttraction').value="on";
        $('rdbRestaurant').value=""; 
        $('rdbHotel').checked=false;  
        $('rdbRestaurant').checked=false;
        $('hdnTBSearchType').value="2"; //2^1
		$('goodHdnSearchType').value = 'rdbAttraction';
    }
    
        if (rdbutton.id.toLowerCase().indexOf('restaurant') > -1) {
        $('divHotel').style.display='none';
        $('divAttraction').style.display='none';
        $('divDiamondRating').style.display='';
        $('divRestaurant').style.display=''; 
        $('rdbHotel').value="";
        $('rdbAttraction').value="";
        $('rdbRestaurant').value="on"; 
        $('rdbHotel').checked=false;
        $('rdbAttraction').checked=false;
        $('hdnTBSearchType').value="4"; //2^2
		$('goodHdnSearchType').value = 'rdbRestaurant';
    }    
    
    rdbutton.checked=true;
	
}

function UpdateStateList() 
{
    if (document.getElementById('cboCountry').selectedIndex==-1) {return false;}
	
    var country = document.getElementById('cboCountry').options[document.getElementById('cboCountry').selectedIndex].value.toUpperCase();
    document.getElementById('hdnCountry').value=country;
    
    var list 
    var state = new Array();
    
    if ((document.getElementById('cboState') != null) &&
     (document.getElementById('cboState').options.length > 0))
     
    //{removeAllOptions(document.all.cboState)};
    document.getElementById('cboState').options.length=0

     switch (country)
    {
        case "USA":
            list = document.getElementById('hdnUSAStateList').value;
            break;
        case "CAN":
            list = document.getElementById('hdnCANStateList').value;
            break;
        case "MEX":
            list = document.getElementById('hdnMEXStateList').value;
            break;
    }
    
     
    state = list.split("|");
    for(var i=0; i < state.length; i++)
    {
        if(state[i].length>0)
            {addOption(i, document.getElementById('cboState'), state[i], state[i], document.getElementById('hdnState').value);}
    } 
    
    //The objective of piece below is to set the selected index of
    //state drop down ONLY when this function is being called from
    //Country's combo box (NOT when the page is being loaded).
    var source=event.srcElement;
    if (source != null)
    {document.getElementById('cboState').selectedIndex=0;}
    
}



function addOption(i, selectbox, value, text, selected )
{
    selectbox.options[i]=new Option(value,text);
    if (value==selected)
        selectbox.options[i].selected=true;

//snippet below also working OK.        
//	var optn = document.createElement("OPTION");
//	optn.text = text;
//	optn.value = value;

//	selectbox.options.add(optn);
}

function UpdateStateValue() 
{
    if (document.getElementById('cboState').selectedIndex > -1)
        {document.getElementById('hdnState').value=document.getElementById('cboState').options[document.getElementById('cboState').selectedIndex].value.toUpperCase(); 
        //document.all.cboState.focus();
        }
          
}

function ResetTourBookSearchForm()
{
     if ((document.getElementById('cboCountry').selectedIndex==0) &&
        (document.getElementById('cboState').selectedIndex>0))
            {document.getElementById('cboState').selectedIndex=0;
            UpdateStateValue();
            document.getElementById('cboState').options[0].value='';
            }    
    else if (document.getElementById('cboCountry').selectedIndex!=0)
        {document.getElementById('cboCountry').selectedIndex=0;
        UpdateStateList();}

     var oselects = document.body.getElementsByTagName("SELECT")
     for(j=0; j < oselects.length; j++) {
        var id = oselects[j].id.toLowerCase();
        if (id != "cbocountry" && id != "cbostate")
        oselects[j].selectedIndex=0;
     }
     
     var oInputs = document.body.getElementsByTagName("INPUT")
      for(j=0; j < oInputs.length; j++) {
        var type = oInputs[j].type.toLowerCase();
        switch (type) {
            case 'checkbox':
                oInputs[j].value='';
                oInputs[j].checked=false;
                break;
            case 'text':
                oInputs[j].value='';
                break;
//           leave the asset type intact                
//            case 'radio':
//                if (oInputs[j].id.toLowerCase()=='rdbhotel')
//                    {ManageAdvancedSearchDisplay(oInputs[j]);}
//                break;
        }        
     }
     
     document.getElementById('txtName').focus();
}
/*

//we used 'document.all.cboState.options.length=0'
//instead of function below. But this also works OK.
function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}
*/

/*
//OnClientClick="return ValidateEntryLength();"
function ValidateEntryLength() {
    var lName = document.all.txtName.value.length;
    var lCity = document.all.txtCity.value.length;
    var msgName = "Name must be at least two characters.";
    var msgCity = "City must be at least two characters.";
    
    if ((lName==1) && (lCity==1))
        {
            alert(msgName + '\r' + msgCity);
                 document.all.txtName.focus();
                 return false;
        }
    else if (lName==1) 
        {
            alert(msgName); 
            document.all.txtName.focus();
            return false;
        }

    else if (lCity==1)
        {
            alert(msgCity); 
            document.all.txtCity.focus();
            return false;
        }
}
*/
