﻿// getElementById Special to handle quirky browsers
// most will use getElementById()
function getElementById_s(id){
	var obj = null;
	if(document.getElementById){
	/* Prefer the widely supported W3C DOM method, if
	available:-
	*/
		obj = document.getElementById(id);
	}else if(document.all){
	/* Branch to use document.all on document.all only
	browsers. Requires that IDs are unique to the page
	and do not coincide with NAME attributes on other
	elements:-
	*/
	obj = document.all[id];
	}
	/* If no appropriate element retrieval mechanism exists on
	this browser this function always returns null:-
	*/
	return obj;
}
function getElementsByName_s(sname){
	var obj = null;
	if(document.getElementsByName){
	/* Prefer the widely supported W3C DOM method, if
	available:-
	*/
		obj = document.getElementsByName(sname);
	}else if(document.all){
	/* Branch to use document.all on document.all only
	browsers. Requires that IDs are unique to the page
	and do not coincide with NAME attributes on other
	elements:-
	*/
	obj = document.all[sname];
	}
	/* If no appropriate element retrieval mechanism exists on
	this browser this function always returns null:-
	*/
	return obj;
}
//Returns the node text value 
function getInnerText (node)
{
	if(node!=null)
	{
		if(node.childNodes.length>0)
			return (node.textContent || node.innerText || node.text || node.childNodes[0].nodeValue) ;
		else
			return (node.textContent || node.innerText || node.text) ;
	}
	else
		return '';
}
function setInnerText (node, val) {

	if (typeof node.value != 'undefined') 
	{
	    node.value=val;
	}
	else if (typeof node.textContent != 'undefined') 
	{
		node.textContent=val;
		
	}
	else if (typeof node.innerText != 'undefined') 
	{
		node.innerText=val;
	}
	else if (typeof node.text != 'undefined') 
	{
		node.text=val;
	}
	else if (typeof node.childNodes[0].nodeValue != 'undefined')
	{
		node.childNodes[0].nodeValue=val;
	}
}
function PasswordReminderEmail(clientID, controlID, sLanguage, sFromPartnerEmail)
{
    try
    {
        if(clientID!='')
            clientID+='_';
        if(controlID=='')
            controlID='txtEmail';
            
        var sEmailId = getElementById_s(clientID+controlID).value;
       
        if (sEmailId == "")
        {
            var sErrMsg = new String(getElementById_s(clientID+"hdnTP_EmailIdErrMsg").value);
            alert(sErrMsg);
        }
        else
        {
 	        var sURL = location.protocol+"//"+location.hostname+":"+location.port+"/services/misc.asmx/SendPwdReminder?sToAddress="+sEmailId+"&sLang="+sLanguage+"&sFromPartnerEmail="+sFromPartnerEmail;           
            AJAXcallback("PasswordReminder", sURL, function(){DisplayPwdReminderMsg(clientID);})                      
        }        
    }
    catch(e)
    {
    }
    
    function DisplayPwdReminderMsg(clientID)
    {
        var bReturnVal = getInnerText(aXmlHttp['PasswordReminder'].responseXML.documentElement);

        if (bReturnVal == "false")
            sErrMsg = new String(getElementById_s(clientID+"hdnTP_InvalidEmailIdErrMsg").value);
        else
            sErrMsg = new String(getElementById_s(clientID+"hdnTP_PwdReminderEmailSentMsg").value);

        alert(sErrMsg);
    }
}
function listSelectedValue(name)
{
	var list=getElementById_s(name);
	return list.options[list.selectedIndex].value;
}

function Round(dNumber,dExchangeRate,iExponent)
{
    dNumber = replaceCommaDecimalSeparator(dNumber);
    dExchangeRate = replaceCommaDecimalSeparator(dExchangeRate);
    dNumber = (Math.round(parseFloat(dNumber).toFixed(2) * dExchangeRate * Math.pow(10, iExponent)) / Math.pow(10, iExponent)).toFixed(iExponent);
    return dNumber;
}

function replaceDecimalSeparator(dNumber,sDecimalSeparator,iExponent)
{
	if(sDecimalSeparator != '' && sDecimalSeparator != '.')
		dNumber=parseFloat(dNumber).toFixed(iExponent).toString().replace('.', sDecimalSeparator);
    else if(sDecimalSeparator != '' && sDecimalSeparator == '.')
		dNumber=parseFloat(dNumber).toFixed(iExponent);
    
	return dNumber;
}

function replaceCommaDecimalSeparator(dNumber)
{
	dNumber=dNumber.toString().replace(',', '.');
	return dNumber;
}

function checkEmail(sClientID)  // For UserName
{
    if(sClientID!='')
        sClientID+='_';

    var email = document.getElementById(sClientID + "username");
    var ErrorMsg = document.getElementById(sClientID + "hdnUsernameErrorMsg");
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email.value)) 
    {
        alert(ErrorMsg.value);
        email.focus;
        return false;
    }
    return true;
}

function validateLength(sClientID) // For Password
{
    if(sClientID!='')
        sClientID+='_';

    var txtpassword = document.getElementById(sClientID + "password");
    var ErrorMsg = document.getElementById(sClientID + "hdnPasswordErrorMsg");
    if (txtpassword.value != "" )
    {
        if ((txtpassword.value.length <6) || (txtpassword.value.length  > 40))
        {
            alert (ErrorMsg.value);
            return false;
        }
    }
    else
    {
        alert (ErrorMsg.value);
        return false;
    }
    return true;
}        


function Validate(sClientID)
{
    //validate_email();
    var bReturn;
    bReturn =  checkEmail(sClientID);
    if (bReturn == true) 
        bReturn = validateLength(sClientID);
    return bReturn;
}

//Clears the contents of combo box and adds the states of currently selected country
function ClearAndSetListItems(listName, nodeName, countryNode, attributeName, sClientId)
{
    if(sClientId!='')
        sClientId+='_';

	for(i=0; i<listName.length; i++)
	{
		list = document.getElementById(sClientId+listName[i]);
		if(list!=null)
		{
		    if(list.selectedIndex!=-1)
		        var selected = list.options[list.selectedIndex].value;
			try
			{
				//Clears the combo box contents.
				for (var count = list.options.length-1; count >-1; count--)
				{
					list.options[count] = null;
				}

				var nodes = countryNode.getElementsByTagName(nodeName);
				var textValue; 
				var optionItem;
				//Add new states list to the state combo box.
				for (var count = 0; count < nodes.length; count++)
				{
				    if(attributeName==null)
				        optionItem = new Option( getInnerText(nodes[count].getElementsByTagName("text")[0]), getInnerText(nodes[count].getElementsByTagName("value")[0])); 
				    else
					    optionItem = new Option( getInnerText(nodes[count]), nodes[count].getAttribute(attributeName)); 
					list.options[list.length] = optionItem;
					if(optionItem.value==selected)
					    list.options[list.length-1].selected=true;
				}
				//Early Mozilla (v1.x) builds don't seem to automatically select first in the list
				if((list.selectedIndex<=0)&&(list.length>0))
					list.selectedIndex=0;
			}
			catch(e)
			{}
			list.disabled=false;
		}
	}
}    

function setCalendarLimitByCountry(sCountry, CountryEndDates)
{
    sCountry=sCountry.toLowerCase();
    var aCountryEndDate;
    
    if(CountryEndDates[sCountry]!=null)
        aCountryEndDate=CountryEndDates[sCountry].split("/");
    else
        aCountryEndDate=CountryEndDates["row"].split("/");
    
    var dtCountryEndDate=new Date(aCountryEndDate[2], aCountryEndDate[1]-1, aCountryEndDate[0]);
    var dtNow = new Date();
    rm.calendarLimit=Math.floor((dtCountryEndDate-dtNow)/86400000)+1;
}

function CheckTimes(pubPick,pubDrop,pubClient)
{
    var bReturn = true;

    try
    {
        sPickUpPeriod = document.getElementById(pubPick + "_PeriodPickerDropDownList").value;
        sDropOffPeriod = document.getElementById(pubDrop + "_PeriodPickerDropDownList").value;
        var trLocationPickUpAddress = getElementById_s(pubClient + "_trLocationPickUpAddress");

        if (trLocationPickUpAddress.className == "")
        {
            var sLocationPickUpAddress = getElementById_s(pubClient + "_txtLocationPickUpAddress").value;
            var sEnterAddressErrMsg = document.getElementById(pubClient + '_hdnEnterAddressMsg').value;
            
            if ((trim(sLocationPickUpAddress) == "") || (sLocationPickUpAddress == sEnterAddressErrMsg) )
            {
                alert(sEnterAddressErrMsg);
                bReturn=false;
            }
        }
        
        if ((sPickUpPeriod == "0{" || sPickUpPeriod == "") && bReturn==true)
        {
            var sPickupTimeErrMsg = document.getElementById(pubClient + '_hdnPickupTimeMsg').value;
            alert(sPickupTimeErrMsg);
            bReturn=false;
        }
            
        else if ((sDropOffPeriod == "0{" || sDropOffPeriod == "") && bReturn==true)
        {
            var sReturnTimeErrMsg = document.getElementById(pubClient + '_hdnReturnTimeMsg').value;
            alert(sReturnTimeErrMsg);
            bReturn=false;
        }
    }
    catch(e)
    {
        bReturn = true;
    }

    return bReturn;
}

function HiddenLabel(lbl,sDefault,sClientId)
{
    if(sClientId!='')
        sClientId+='_';

    var hdnlbl=getElementById_s(sClientId+lbl);
    var s;
    if(hdnlbl!=null)
    {
        s=hdnlbl.value;
    }
    else
    {
        s=sDefault;
    }
    return s;
}

function updateHours(sControl, sType, xml, selected, sClientId)
{
    if(sClientId!='')
        sClientId+='_';

	var list = document.getElementById(sClientId+"uc_"+sType+"PeriodPicker_PeriodPickerDropDownList");
    
    if(list!=null)	
    {
        try
        {
            // Update dropdown of available pickup/dropoff times
            list.disabled=true; 
        
		    //var selected = "";
		    //Clears the combo box contents.
		    // while count>0 will leave first item in the list 
		    // i.e. the local language version of "Select a time..."
		    if((list.options.selectedIndex>0)&&(selected==null||selected==''))
		    {
			    //store currently selected value 
			    selected=list.options[list.selectedIndex].value;
			    var iSelected = parseInt(selected);
		    }
    		
		    //checking if one entry in list is fallatious since that one entry might read "closed" so change it back to "select a time..."
		    //if(list.options.length==0)
		    //{
		        var sSelectTime=HiddenLabel('hdnlblSelectTime','Select a time...','LocationDateControl');
		        list.options[0] = new Option(sSelectTime, ''); 
		    //}
		    //else
		    {
		        //this is would be quicker but then it removes local version of initial "Select a time..." option
		        list.options.length=1;
		        /*var count;
		        for (count = list.options.length-1; count>0; count--)
		        {
			        list.options[count] = null;
		        }*/		
		    }
    		
		    var nodes = xml.getElementsByTagName("Table");
	        var textValue; 
	        var optionItem;
	        //Add new states list to the state combo box.
	        var count;
	        for (count = 0; count < nodes.length; count++)
	        {
		        if(getInnerText(nodes[count].getElementsByTagName("Included")[0])=="Y")
		        {
			        optionItem = new Option( getInnerText(nodes[count].getElementsByTagName("Starttime")[0]) + " - " + getInnerText(nodes[count+1].getElementsByTagName("Starttime")[0]), getInnerText(nodes[count].getElementsByTagName("Period")[0])+"{"); 
			        if((selected!=null)&&(list.selectedIndex==0))
			        {
				        //var iPeriod = parseInt(optionItem.value.substring(0,optionItem.value.indexOf("{")));
				        var iPeriod = parseInt(optionItem.value);

				        // commented the || part as it was causing wrong pick up period to be set
				        // when the start date was changed to within lead time
				        if((optionItem.value==selected)) //||(list.length==1&&iSelected<iPeriod))
				        {
					        //apply previously selected value
					        optionItem.selected=true;
				        }
			        }
			        list.options[list.length] = optionItem;
		        }
            }
            
            if(list.length==1)
		    {
                var sClosed=HiddenLabel('hdnlblClosed','Closed','LocationDateControl');
		        if(nodes.length==0)
		        {
		            var hdnSelectedLocation=getElementById_s(sClientId+"hdnSelectedLocation");
		            if(hdnSelectedLocation.value=='')
		            {
		                var sSelectTime=HiddenLabel('hdnlblSelectTime','Select a time...','LocationDateControl');
		                list.options[0] = new Option(sSelectTime, ''); 	        
		            }
		            else
		            {
		   	            list.options[0] = new Option(sClosed, ''); 	        
		   	        }
		   	    }
		   	    else
		   	    {
		   	        if((sType=='PickUp'&&(global.calendar.dateValue[departureField.id] > new Date()))||(sType=='DropOff'&&(global.calendar.dateValue[arrivalField.id] > new Date())))
		   	        {
		   	            list.options[0] = new Option(sClosed, ''); 	        
		   	        }
		   	        else
		   	        {
		   	            var sAvailableTomorrow=HiddenLabel('hdnlblAvailableTomorrow','Available tomorrow','LocationDateControl');
		   	            list.options[0] = new Option(sAvailableTomorrow, ''); 	        
		   	        }
		   	    }
		    }
		    else
		    {
	            list.disabled=false;	
		    }

	    }
	    catch(e)
	    {alert(e);}	
    }	    
}

function UpdateRegionsAndLocations(sClientId)
{
	ClearAndSetListItems(Array("DropDownRegion","cmbOneWayDropOffRegions"), "Region", aXmlHttp["Regions"].responseXML.documentElement, "Code", sClientId);
	
	var bAirportsOnly=false;
	
	try
	{
	    //bAirportsOnly=document.getElementById("<%=Me.ClientID%>_chkAirportsOnlyPickUp").checked;
	    bAirportsOnly= false;
	}
	catch(e)
	{
	    bAirportsOnly=false;
	}
	
	// Pass both dropoff location boxes so they both get update with the same return from the service, since the regions have been set the same
	RegionListOnChange(sClientId+"_DropDownRegion", Array("ListBoxLocation","lstOneWayDropOffLocations"), bAirportsOnly);
}

function CountryOnChange(sClientId, bDisplayUSCitizenMsg, CountryEndDates,DropOffRegion,DropOffLocation,DropDownRegion,ListBoxLocation,
                       trDropDownCountry, chkOneWayRental, trOneWayRentalChkBox, trNoOneWay, dvNoOneWay, OneWayCountries)
{
    var countryList = getElementById_s(sClientId+"_DropDownCountry");
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
	var bProceed = true;

    try
    {
        var txtLocationPickUpAddress = getElementById_s(sClientId+"_txtLocationPickUpAddress");
        var hdnEnterAddressMsg=getElementById_s(sClientId+"_hdnEnterAddressMsg");

        if (txtLocationPickUpAddress != null)
	        txtLocationPickUpAddress.value = hdnEnterAddressMsg.value;
	}
	catch(e)
	{}
	
	if (bDisplayUSCitizenMsg)
	{
	    if(selectedCountry.toUpperCase()=="US" || selectedCountry.toUpperCase()=="CA")
	    {
            var sUSCitizenMsg = document.getElementById(sClientId + '_hdnUSCitizenMsg').value;
	        bProceed=confirm(sUSCitizenMsg);
	    }
		
	    if (bProceed==false)
	    {
            var sUSCitizenMsg = document.getElementById(sClientId + '_hdnUSCitizenNoAvailMsg').value;
	        alert(sUSCitizenMsg);
	        countryList.value="UK";
	        selectedCountry="UK";
	    }
	}    
	
	setCalendarLimitByCountry(selectedCountry, CountryEndDates);

	DropDownRegion.disabled=true;
	if(DropOffRegion!=null)
		DropOffRegion.disabled=true;
	ListBoxLocation.disabled=true;
	if(DropOffLocation!=null)
		DropOffLocation.disabled=true;
	
	var aCountries = OneWayCountries.split(",");
	var bOneWay = false;
	for(var i=0; i<aCountries.length; i++)
	{
		if(aCountries[i]==selectedCountry)
		{
			bOneWay=true;
			break;
		}
	}

	//If is one way country but can't find the OneWayRental check box then PostBack the page
	if(bOneWay)
	{	
	    trDropDownCountry.className="country";
		if(chkOneWayRental==null)
		{
			_doPostBack(sClientId+'$DropDownCountry',selectedCountry);
			return;
		}
		else
		{
		    if(trOneWayRentalChkBox.style.display=='none')
		    {
			    trOneWayRentalChkBox.style.display='';
			    trNoOneWay.style.display='none';
			    dvNoOneWay.style.display='none';
			}
		}
	}
    else
	    trDropDownCountry.className="country";

	if((!bOneWay)&&(chkOneWayRental!=null))
	{ 
		if(chkOneWayRental.checked==false)
		{
			//else can just hide row containing onewayrental checkbox
			trOneWayRentalChkBox.style.display='none';
			trNoOneWay.style.display='';
			dvNoOneWay.style.display='';
		}
	}

	return bOneWay;
}

function GetPickupLocation(sClientId)
{
    var sPickUpLocation="";
	var ListBoxLocation=getElementById_s(sClientId+"_ListBoxLocation");
    var trLocationPickUpAddress = getElementById_s(sClientId+"_trLocationPickUpAddress");

	if (trLocationPickUpAddress.className == "")
	    sPickUpLocation="UKTMLHRXXA";
    else
    {
	    if(ListBoxLocation!=null)
	    {
	        if(ListBoxLocation.selectedIndex!=-1)
	            sPickUpLocation=ListBoxLocation.options[ListBoxLocation.selectedIndex].value;
	    }
	    else
	    {
	        var hdnSelectedLocation = document.getElementById(sClientId+"_hdnSelectedLocation");
	        if(hdnSelectedLocation!=null)
	            sPickUpLocation=hdnSelectedLocation.value;
	    }
    }
    
	return sPickUpLocation;
}

function GetDropOffLocation(sClientId,sPickUpLocation)
{
    var sDropOffLocation="";
    var lstDropOffLocations=getElementById_s(sClientId+"_lstOneWayDropOffLocations");
    if(lstDropOffLocations!=null)
    {
        if(lstDropOffLocations.selectedIndex!=-1)
            sDropOffLocation=lstDropOffLocations.options[lstDropOffLocations.selectedIndex].value;
    }
    else
    {
	    var hdnSelectedLocationDropOff = document.getElementById(sClientId+"_hdnSelectedDropOffLocation");
	    if(hdnSelectedLocationDropOff!=null)
	        sDropOffLocation=hdnSelectedLocationDropOff.value;
	}
	
	if(sDropOffLocation=='')
        sDropOffLocation=sPickUpLocation;

	return sDropOffLocation;
}

function UpdatePickUpLocations()
{
	if(document.body.style.cursor!="wait")
		document.body.style.cursor = "wait";
		
    if(ListBoxLocation!=null)
		ListBoxLocation.disabled=true;			

	//Getting the selected country from country combo box.
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
	var selectedRegion = DropDownRegion.options[DropDownRegion.selectedIndex].value;
	var oneWayRental=false;
	var chkAirportsOnly;
	var airportsOnly=false;
	try
	{
	    //chkAirportsOnly=getElementById_s("<%=Me.ClientID()%>_chkAirportsOnlyPickUp");
	    //airportsOnly=chkAirportsOnly.checked;
	    airportsOnly = false;
	}
	catch(e)
	{
	    airportsOnly=false;
	}
	
	if(chkOneWayRental!=null)
	    oneWayRental = chkOneWayRental.checked;
	
	var requestUrl = "/services/ParentLocationList.asmx/GetLocationsXML?iPartnerID="+partnerID+"&sLanguage=<%=Language()%>&sCountry=" + encodeURIComponent(selectedCountry) + "&sRegionID=" + encodeURIComponent(selectedRegion) + "&sBookingCurrency=" + bookingCurrency + "&iExcludeNonFreeSaleLocation=" + excludeNonFreeSaleLocation + "&sSelectedLocation=" + selectedLocation + "&sPickerMode="+pickerMode+"&bOneWayRental="+oneWayRental+"&sNationalGroup="+nationalGroup+"&bIsChangeBooking="+changeBooking+"&bAirportsOnly="+airportsOnly+"&iSupplierId="+SupplierID;
	AJAXcallback("PickUpLocations", requestUrl, function(){ClearAndSetListItems(Array("ListBoxLocation"), "Location", aXmlHttp["PickUpLocations"].responseXML.documentElement,null, "LocationDateControl",true);});
}

function UpdateDropOffLocs(DropOffLocation, countryList, DropOffRegion, chkOneWayRental, partnerID, sLanguage, bookingCurrency, excludeNonFreeSaleLocation, selectedLocation, pickerMode, nationalGroup, changeBooking, SupplierID)
{
    if(DropOffLocation!=null)
		DropOffLocation.disabled=true;			

	//Getting the selected country from country combo box.
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
	var selectedRegion = DropOffRegion.options[DropOffRegion.selectedIndex].value;
	var oneWayRental=false;

	var airportsOnlyDropOff = false;
	if(chkOneWayRental!=null)
	    oneWayRental = chkOneWayRental.checked;
	
	var requestUrl = "/services/ParentLocationList.asmx/GetLocationsXML?iPartnerID="+partnerID+"&sLanguage="+sLanguage+"&sCountry=" + encodeURIComponent(selectedCountry) + "&sRegionID=" + encodeURIComponent(selectedRegion) + "&sBookingCurrency=" + bookingCurrency + "&iExcludeNonFreeSaleLocation=" + excludeNonFreeSaleLocation + "&sSelectedLocation=" + selectedLocation + "&sPickerMode="+pickerMode+"&bOneWayRental="+oneWayRental+"&sNationalGroup="+nationalGroup+"&bIsChangeBooking="+changeBooking+"&bAirportsOnly="+airportsOnlyDropOff+"&iSupplierId="+SupplierID;
    return requestUrl;
}

// ******************** HelpPopup.ascx functions - Start **************************************//
function CloseDiv(e)
{ 
    try
    {
        var target = (e && e.target) || (event && event.srcElement); 
        var objDiv = getElementById_s("divHelpPopup"); 

        if (objDiv != null)
        {
            //If the div is visible
            if (objDiv.className=="")
            {
                //Check if the click is outside the div
                var bIsClickOutsideDiv = checkParent(target,"divHelpPopup"); 
                
                //If it is outside the div, hide the div
                if(bIsClickOutsideDiv)
                    HideDiv(); //objDiv.className="Invisible";
            }
        }

        // Store the X & Y coordinates of the mouse click in variables posX & posY resp.
	    if (!e) var e = window.event;
	    if (e.pageX || e.pageY)
	    {
		    posX = e.pageX;
		    posY = e.pageY;
	    }
	    else if (e.clientX || e.clientY)
	    {
		    posX = e.clientX + document.body.scrollLeft;
		    posY = e.clientY + document.body.scrollTop;
	    }

        // Adjust the Y coordinate slightly
        posY = posY + 3;
     
        var ctlTbHelpPopup = getElementById_s("tbHelpPopup");
       
        if(ctlTbHelpPopup != null)
        {
            // If the X pos of the Div goes outside the screen size, then adjust the X coordinate
            if ((posX + ctlTbHelpPopup.offsetWidth) > 980)
		        posX = 980 - (ctlTbHelpPopup.offsetWidth + 15);
        }
        
        if(iCtr==0)
        {
            ShowDiv(sHelpTextVar, iPopupWidthVar, 1, sControlIdVar, sTextControlIdVar);
        }
    }
    catch(e)
    {
    }
} 

function CloseDivMouseOver(e)
{ 
    try
    {
        var target = (e && e.target) || (event && event.srcElement); 

        // Store the X & Y coordinates of the mouse click in variables posX & posY resp.
	    if (!e) var e = window.event;
	    if (e.pageX || e.pageY)
	    {
		    posX = e.pageX;
		    posY = e.pageY;
	    }
	    else if (e.clientX || e.clientY)
	    {
		    posX = e.clientX + document.body.scrollLeft;
		    posY = e.clientY + document.body.scrollTop;
	    }

        // Adjust the Y coordinate slightly
        posY = posY + 3;
     
        var ctlTbHelpPopup = getElementById_s("tbHelpPopup");
       
        if(ctlTbHelpPopup != null)
        {
            // If the X pos of the Div goes outside the screen size, then adjust the X coordinate
            if ((posX + ctlTbHelpPopup.offsetWidth) > 980)
		        posX = 980 - (ctlTbHelpPopup.offsetWidth + 15);
        }
        
        if(iCtr==0)
        {
            ShowHoverDiv(sHelpTextVar, iPopupWidthVar, 1, sControlIdVar, sTextControlIdVar);
        }
    }
    catch(e)
    {
    }
} 

function ShowHelpDiv(sHelpText, iPopupWidth, iCtrVal, sControlId, sTextControlId, sBrowser) 
{
    iCtr=iCtrVal;
    sHelpTextVar=sHelpText;
    iPopupWidthVar=iPopupWidth;
    sControlIdVar=sControlId;
    sTextControlIdVar=sTextControlId;
 
    if(iCtrVal==1 && sHelpText!=undefined)
    {
        var ctlDivId = getElementById_s("divHelpPopup");
        var ctlDivHelpPopupMid = getElementById_s("divHelpPopupMid");
        var ctlTbHelpPopup = getElementById_s("tbHelpPopup");
        var ctlDivHelpPopupStart = getElementById_s("divHelpPopupStart");
        var ctlDivHelpPopupEnd = getElementById_s("divHelpPopupEnd");
        var ctlDivHelpPopupMidStart = getElementById_s("divHelpPopupMidStart");
        var ctlDivHelpPopupMidEnd = getElementById_s("divHelpPopupMidEnd");
        var ctlDivHelpPopupMidSingle = getElementById_s("divHelpPopupMidSingle");
        var trMultiple = getElementById_s("trMultiple");
        var trSingle = getElementById_s("trSingle");
       
        if(sHelpText == '' && sTextControlIdVar != '')
        {
            var ctlTextId = getElementById_s(sTextControlIdVar);
            
            if(ctlTextId!=null)
                sHelpText=ctlTextId.value;
        }
        
        // Show the div
        if(ctlDivId!=null)
            ctlDivId.className="";

        // Display the content
        if(ctlDivHelpPopupMid!=null)
        {       
            ctlDivHelpPopupMid.style.height="";
            ctlDivHelpPopupMid.innerHTML=sHelpText;
            ctlDivHelpPopupMid.style.width=iPopupWidth + 'px';
        }
  
        if(ctlDivHelpPopupMidSingle!=null)
        {       
            ctlDivHelpPopupMidSingle.style.height="";
            ctlDivHelpPopupMidSingle.innerHTML=sHelpText;
            ctlDivHelpPopupMidSingle.style.width=(iPopupWidth + 48) + 'px';
        }
              
        // Adjust the width of the table & divs based on what is passed in
        if(ctlTbHelpPopup!=null)
        {
            var iWidth = iPopupWidth + 38;
            ctlTbHelpPopup.style.width=iWidth + 'px';
        }
        
        if(ctlDivHelpPopupStart!=null)
        {
            ctlDivHelpPopupStart.style.width=iPopupWidth + 'px';
        }
        
        if(ctlDivHelpPopupEnd!=null)
            ctlDivHelpPopupEnd.style.width=iPopupWidth + 'px';
        
        // Adjust the height of the middle div based on the text length
        if(ctlDivHelpPopupMidStart!=null)
        {
            var iHeight=ctlDivHelpPopupMid.offsetHeight;
            
            if (iPopupWidth == 201)
                iHeight=ctlDivHelpPopupMidSingle.offsetHeight;
                
            if (sTextControlIdVar!="" && sBrowser=="Opera")
                iHeight=iHeight+11;
                
            ctlDivHelpPopupMidStart.style.height=iHeight + 'px'; 
            ctlDivHelpPopupMidEnd.style.height=iHeight + 'px';
            ctlDivHelpPopupMid.style.height=iHeight + 'px';
            ctlDivHelpPopupMidSingle.style.height=iHeight + 'px';

            if (iPopupWidth == 201)
            {
                trMultiple.className = "Invisible";
                ctlDivHelpPopupMidStart.className = "Invisible";
                ctlDivHelpPopupMidEnd.className = "Invisible";
                ctlDivHelpPopupMid.className = "Invisible";
                trSingle.className = "";
            }
            else
            {
                trMultiple.className = "";
                trSingle.className = "Invisible";
            }            
        }
 
         // If the X pos of the Div goes outside the screen size, then adjust the X coordinate
        if ((posX + iPopupWidth) > 980)
		    posX = 980 - (iPopupWidth + 38);

        // Position the div at the mouse-click coordinates
        if (dom && !document.all) 
        {
            ctlDivId.style.top = posY + 'px';                 
            ctlDivId.style.left = posX + 'px'; 
        }
        if (document.layers) 
        {
            document.layers["divHelpPopup"].top = posY + 'px';                 
            document.layers["divHelpPopup"].left = posX + 'px'; 
        }
        if (document.all) 
        {
            document.all["divHelpPopup"].style.top = posY + 'px'; 
            document.all["divHelpPopup"].style.left = posX + 'px'; 
        }
        
        if(sControlIdVar!="")
        {
            if (HideCombo() == true)
            {
                var arrControlId = sControlIdVar.split("!");

                for(iCtr = 0; iCtr < arrControlId.length; iCtr++)
                {
                    var ctlControlId = getElementById_s(arrControlId[iCtr]);
                    
                    if(ctlControlId!=null)
                        ctlControlId.className="Invisible";
                }
            }
        }
    }
}

function ShowDivMouseOver(sHelpText, iPopupWidth, iCtrVal, sControlId, sTextControlId, iPosX, iPosY) 
{
    posX = event.ClientX; /* iPosX;*/
    posY = event.ClientY; /*iPosY;*/
    ShowDiv(sHelpText, iPopupWidth, iCtrVal, sControlId, sTextControlId)
}

function checkParent(target, sDivId)
{ 
    while(target.parentNode)
    { 
        var objDiv = getElementById_s(sDivId);

        if (objDiv != null)
        {
            //If the parent is the Div, return false
            if(target==objDiv)
                return false; 
        }
            
        target=target.parentNode; 
    } 
    return true; 
} 

function HideDiv() 
{
    var objDiv = getElementById_s("divHelpPopup");

    if (objDiv != null)
        objDiv.className="Invisible";

    if(sControlIdVar!="")
    {
        if (HideCombo() == true)
        {            
            var arrControlId = sControlIdVar.split("!");

            for(iCtr = 0; iCtr < arrControlId.length; iCtr++)
            {
                var ctlControlId = getElementById_s(arrControlId[iCtr]);
                
                if(ctlControlId!=null)
                    ctlControlId.className="easyCarDropDown";
            }
        }
    }
}

// ******************** HelpPopup.ascx functions - End **************************************//


// Currency selected changes on LocationDatePicker.ascx.  Not in use currently so putting it here
// ********************************* Start **********************************************
//modified by hardik r shah 30/01/2007
//added partnerid to the CurrencyOnChangeMethod
function CurrencyListOnChange(PartnerId)
{
	var Currency = listSelectedValue("<%=Me.ClientID()%>_cmbCurrency")

	var requestWeeklyDealsUrl = "/services/Misc.asmx/GetWeeklyDeals?Currency="+Currency+"&sLanguage=<%=Language()%>&PartnerId="+PartnerId+"&bDisplayCols=<%=DisplayWeeklyDealsCols%>";
	AJAXcallback("WeeklyDeals", requestWeeklyDealsUrl, function(){updateWeeklyDeals(aXmlHttp["WeeklyDeals"].responseXML.documentElement);});
}

function updateWeeklyDeals(xml)
{
	var nodes = xml.getElementsByTagName("Table");
	var iTableCount;

	for(i=0; i<nodes.length; i++)
    	{
    	
	    for (iTableCount = 0 ; iTableCount < 4 ; iTableCount++)
	    {
	        var sTagNo;
	        if (iTableCount == 0 ) 
    	        	sTagNo = "";
	        else    
	            sTagNo = iTableCount;

	
		    var i;
		    var lnk, td;
		    var price,symbol,spacer;

	        var Locations = xml.getElementsByTagName("Location" + sTagNo);

	        var Prices = xml.getElementsByTagName("Price" + sTagNo);
    	        //var CurrencySymbols = xml.getElementsByTagName("CurrencyCode" + sTagNo);
     	        var CurrencySymbols = xml.getElementsByTagName("CurrencySymbol" + sTagNo);

		    symbol=getInnerText(CurrencySymbols[i])
		    lnk=getElementById_s("lnk"+getInnerText(Locations[i]));
		    if(lnk!=null)
		    {
			    if(lnk.href.indexOf('&Curr=')!=-1)
			    {
				    if(lnk.href.substr(lnk.href.indexOf('&Curr=')+6,3)!=symbol)
					    lnk.href=lnk.href.replace(lnk.href.substr(lnk.href.indexOf('&Curr='),9), '&Curr='+symbol);
			    }
		    }
		    td=getElementById_s("td"+getInnerText(Locations[i]));
		    if(td!=null)
		    {
			    price=getInnerText(Prices[i]);
			    price=parseFloat(price).toFixed(0);
			    if(rm.currencydecimalseparator!=''&&rm.currencydecimalseparator!='.')
				    price=price.replace('.',rm.currencydecimalseparator);
			    spacer="";//(symbol.length>1)?" ":"";
			    //setInnerText(td,symbol+spacer+price);//.toFixed(0));
			    SetTDValue("td"+getInnerText(Locations[i]),symbol+spacer+price);

		    }
	     }
	}
}

// This Function is used to Replace Price for all the occurrences of the Location
function SetTDValue(nodeName, val)
{
    var i;
    var els = theForm.getElementsByTagName("td"); 
    for(i=0; i<els.length; i++) 
    {
        if (els[i].id == nodeName)
        {
            els[i].innerHTML = val;
        }
    }
}
// ********************************* End ************************************************
// 

function showpopupsubmenu(menu, isVan)
{
  try  {  
  
        if (isVan == true)
        {
             var dvPopupMenu = getElementById_s("popupmenu");
             dvPopupMenu.className="Invisible";
        }
        else
        {
             var dvPopupMenu = getElementById_s("popupmenu");
             dvPopupMenu.className="popupmenu";

             var dvMenu = getElementById_s(menu[0] + 'popupmenu');
             dvMenu.className="";
             
             for (var iCtr = 1; iCtr <= 10; iCtr++)
             {
                 dvMenu = getElementById_s(menu[iCtr] + 'popupmenu');
                 
                 if(dvMenu!=null)
                    dvMenu.className="Invisible";
             }
        }
        
  } catch (e) {}
}

function hidepopupmenu()
{
  try  
  {
     var dvPopupMenu = getElementById_s("popupmenu");
     dvPopupMenu.className="Invisible";
  } catch (e) {}
}

function SetAddrBox(sClientID)
{
    var txtLocationPickUpAddress=document.getElementById(sClientID+'txtLocationPickUpAddress');
    var hdnEnterAddressMsg=document.getElementById(sClientID+'hdnEnterAddressMsg');
    
    if(txtLocationPickUpAddress!=null)
    {
        if (txtLocationPickUpAddress.value==hdnEnterAddressMsg.value)
            setInnerText(txtLocationPickUpAddress, '');
    }
}
        
function AddrSearch(sClientID)
{
    var trLocationPickUp = document.getElementById(sClientID+"trLocationPickUp");
    var trLocationPickUpAddress = getElementById_s(sClientID+"trLocationPickUpAddress");
    var trOneWayRentalChkBox = document.getElementById(sClientID+"trOneWayRentalChkBox");
    var trNoOneWay = getElementById_s(sClientID+"trNoOneWay");
    var lnkAddressSearch = getElementById_s(sClientID+"lnkAddressSearch");
    var lnkListSearch = getElementById_s(sClientID+"lnkListSearch");
    var hdnTP_AddrSearch = getElementById_s(sClientID+"hdnTP_AddrSearch");

    trLocationPickUp.className = "Invisible";
    trLocationPickUpAddress.className = "";
    trOneWayRentalChkBox.style.display = "none";
    trNoOneWay.style.display = "none";
    lnkAddressSearch.style.display = "none";
    lnkListSearch.style.display = "";
    hdnTP_AddrSearch.value = "1";
}

function LstSearch(sClientID, OneWayCountries)
{
    var trLocationPickUp = document.getElementById(sClientID+"trLocationPickUp");
    var trLocationPickUpAddress = getElementById_s(sClientID+"trLocationPickUpAddress");
    var txtLocationPickUpAddress = getElementById_s(sClientID+"txtLocationPickUpAddress");
    var trOneWayRentalChkBox = document.getElementById(sClientID+"trOneWayRentalChkBox");
    var trNoOneWay = getElementById_s(sClientID+"trNoOneWay");
    var lnkAddressSearch = getElementById_s(sClientID+"lnkAddressSearch");
    var lnkListSearch = getElementById_s(sClientID+"lnkListSearch");
    var hdnTP_AddrSearch = getElementById_s(sClientID+"hdnTP_AddrSearch");
    var countryList = getElementById_s(sClientID+"DropDownCountry");
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
    var aCountries = OneWayCountries.split(",");
	var bOneWay = false;
    var hdnEnterAddressMsg=getElementById_s(sClientID+"hdnEnterAddressMsg");
    
    hdnTP_AddrSearch.value = "0";
    
    if (txtLocationPickUpAddress != null)
	    txtLocationPickUpAddress.value = hdnEnterAddressMsg.value;
	
	for(var i=0; i<aCountries.length; i++)
	{
		if(aCountries[i]==selectedCountry)
		{
			bOneWay=true;
			break;
		}
	}

    trLocationPickUp.className = "";
    trLocationPickUpAddress.className = "Invisible";
    lnkAddressSearch.style.display = "";
    lnkListSearch.style.display = "none";
    
    if(bOneWay)
    {
        trOneWayRentalChkBox.style.display = "";
        trNoOneWay.style.display = "none";
    }
    else
    {
        trOneWayRentalChkBox.style.display = "none";
        trNoOneWay.style.display = "";
    }    
}
            
function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}            
