﻿var intervalMsg = null;
var intervalTimeMsg = 3;
var arrChracters = "אבגדהוזחטיכלמנסעפצקרשת";
var browser = navigator.appName;

function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function goUrl(url)
{
    if (url!="")
    {
        window.location.href = url;
    }
}

function showOpenDiv() {

    var scrWidth = document.body.clientWidth;
    var scrHeight = document.body.clientHeight;
    /*
    var scrWidth = document.documentElement.clientWidth;
    var scrHeight = document.documentElement.clientHeight;*/
    
    var el = document.getElementById("divOpenBg");
    var elInner = document.getElementById("divOpenBgInner");
    
    el.style.width = scrWidth + "px";
    el.style.height = scrHeight + 20 + "px";
    
    /*elInner.style.left = scrWidth/2-291 + "px"*/
    /*elInner.style.top = scrHeight/2 + "px"*/
    elInner.style.left = scrWidth/2-330 + "px"
    elInner.style.top = "250px"
    
    if (el.style.display == "block")
    {
        el.style.display = "none";
        elInner.style.display = "none";
    }
    else
    {
        el.style.display = "block";
        elInner.style.display = "block";
    }
}

function funSelectDateStation()
{
    window.location.href = "rentcardatestation.aspx";
}


//function funRentCarSelect()
//{
//    var flagDates = true, flagStation = true, flagAgree = true, flagRentDays = true;
//    var rentDays;
//    
//    var country = "", countryFrom = 0, countryTo = 0;
//    var oCountry = document.getElementById("ctl00_cphInnerPage_selectToArea");
//    if (oCountry != null && oCountry.style.display == "")
//    {
//        country = document.getElementById("ctl00_cphInnerPage_selectToArea").options[document.getElementById("ctl00_cphInnerPage_selectToArea").selectedIndex].text;
//        countryTo = document.getElementById("ctl00_cphInnerPage_selectToArea").selectedIndex;
//        countryFrom = document.getElementById("ctl00_cphInnerPage_selectFromArea").selectedIndex;
//    }
//    else
//    {
//        country = "ISRAEL";
//        countryTo = 0;
//        countryFrom = 0;
//    }
//    var fromTime = document.getElementById("ctl00_cphInnerPage_selectFromTime").options[document.getElementById("ctl00_cphInnerPage_selectFromTime").selectedIndex].text;
//    var toTime = document.getElementById("ctl00_cphInnerPage_selectToTime").options[document.getElementById("ctl00_cphInnerPage_selectToTime").selectedIndex].text;
//    
//    /// check validation to proceed.
//    /// check the dates.
//    var fromDays = document.getElementById("ctl00_cphInnerPage_selectFromDay").options[document.getElementById("ctl00_cphInnerPage_selectFromDay").selectedIndex].value;
//    var fromMonth = document.getElementById("ctl00_cphInnerPage_selectFromMonth").options[document.getElementById("ctl00_cphInnerPage_selectFromMonth").selectedIndex].value;
//    var fromYear = document.getElementById("ctl00_cphInnerPage_selectFromYear").options[document.getElementById("ctl00_cphInnerPage_selectFromYear").selectedIndex].value;
//    
//    var toDays = document.getElementById("ctl00_cphInnerPage_selectToDay").options[document.getElementById("ctl00_cphInnerPage_selectToDay").selectedIndex].value;
//    var toMonth = document.getElementById("ctl00_cphInnerPage_selectToMonth").options[document.getElementById("ctl00_cphInnerPage_selectToMonth").selectedIndex].value;
//    var toYear = document.getElementById("ctl00_cphInnerPage_selectToYear").options[document.getElementById("ctl00_cphInnerPage_selectToYear").selectedIndex].value;
//    
//    if (parseInt(fromMonth) < 10)
//    {
//        fromMonth = "0" + fromMonth;
//    }
//    
//    if (parseInt(toMonth) < 10)
//    {
//        toMonth = "0" + toMonth;
//    }
//    
//    if (parseInt(fromDays) < 10)
//    {
//        fromDays = "0" + fromDays;
//    }
//    
//    if (parseInt(toDays) < 10)
//    {
//        toDays = "0" + toDays;
//    }
//    
//    var fromDate = new Date(fromYear + "/" + fromMonth + "/" + fromDays + " " + fromTime);
//    var toDate = new Date(toYear + "/" + toMonth + "/" + toDays + " " + toTime);
//    var currentTime = new Date();
//    var month = currentTime.getMonth() + 1;
//    var day = currentTime.getDate();
//    var year = currentTime.getFullYear();
//    var today = new Date(year + "/" + month + "/" + day);

//    var nowDate = new Date();
//    
//    if (Math.ceil((toDate.getTime() - fromDate.getTime()) / (1000*60*60*24)) > 2)
//    {
//        flagRentDays = false;
//    }
//    
//    if (toDate > fromDate)
//    {   
//        if (country == "ISRAEL")
//        {
//            if (fromDate >= nowDate && toDate >= nowDate && fromDate > today && toDate > today)
//            {
//                flagDates = false;
//                
//                rentDays = Math.ceil((toDate.getTime() - fromDate.getTime()) / (1000*60*60*24));
//            } 
//        }
//        else
//        {
//            if (fromDate >= nowDate && toDate >= nowDate)
//            {
//                flagDates = false;
//                
//                rentDays = Math.ceil((toDate.getTime() - fromDate.getTime()) / (1000*60*60*24));
//            } 
//        }  
//    }
//    
//    /// check station.
//    var oSelectFromStation = document.getElementById("ctl00_cphInnerPage_selectFromStation");
//    var oSelectToStation = document.getElementById("ctl00_cphInnerPage_selectToStation");
//    if (oSelectFromStation.selectedIndex > 0 && oSelectToStation.selectedIndex > 0)
//    {
//        flagStation = false;
//    }
//    
//    /// cehck selected agreement
//    var oChkAgree = document.getElementById("ctl00_cphInnerPage_chkAgree");
//    if (oChkAgree.checked == true)
//    {
//        flagAgree = false;
//    }
//    
//    if (flagDates == false && flagStation == false && flagAgree == false && flagRentDays == false)
//    {
//        doAjaxRequest(buildAjaxRentCarSelect(fromYear + "/" + fromMonth + "/" + fromDays, toYear + "/" + toMonth + "/" + toDays, oSelectFromStation.options[oSelectFromStation.selectedIndex].value, oSelectToStation.options[oSelectToStation.selectedIndex].value, oSelectFromStation.options[oSelectFromStation.selectedIndex].text, oSelectToStation.options[oSelectToStation.selectedIndex].text, rentDays, fromTime, toTime, country, countryFrom, countryTo), {method:"GET", onSuccess:ajaxRentCarSelect, onFailure:ajaxFailure});
//    }
//    else
//    {
//        if (flagRentDays == true)
//        {
//            document.getElementById("divErrorRentDays").style.display = "block";
//        }
//        else
//        {
//            document.getElementById("divErrorRentDays").style.display = "none";
//        }
//        if (flagDates == true)
//        {
//            document.getElementById("divErrorDates").style.display = "block";
//        }
//        else
//        {
//            document.getElementById("divErrorDates").style.display = "none";
//        }
//        if (flagStation == true)
//        {
//            document.getElementById("divErrorStation").style.display = "block";
//        }
//        else
//        {
//            document.getElementById("divErrorStation").style.display = "none";
//        }
//        if (flagAgree == true)
//        {
//            document.getElementById("divErrorAgree").style.display = "block";
//        }
//        else
//        {
//            document.getElementById("divErrorAgree").style.display = "none";
//        }
//    }
//}

//function buildAjaxRentCarSelect(fromDate, toDate, fromStation, toStation, fromStationText, toStationText, rentDays, fromTime, toTime, county, countryFrom, countryTo)
//{
//    var ajaxCommand = "ajaxFunctionID=4&param=" + fromDate + ";" + toDate + ";" + fromStation + ";" + toStation + ";" + fromStationText + ";" + toStationText + ";" + rentDays + ";" + fromTime + ";" + toTime + ";" + county + ";" + countryFrom + ";" + countryTo;
//    return ajaxCommand;
//}

//function ajaxRentCarSelect()
//{
//    window.location.href = "rentcarselectcar.aspx";
//}

function ajaxLoadStationByCountry(){}

function funRentCarUpdateCarDetails()
{
    window.location.href = "rentcarselectcar.aspx";
}

/// load accessories save car param
function funSelectAccessories()
{
    if (document.getElementById("ctl00_cphInnerPage_UcCarNavigation1_divNavSelectedCar").style.display == "block")
    {
        window.location.href = "rentcarselectaccessories.aspx";
    }
    else
    {
        document.getElementById("divErrorCar").style.display = "block";
    }
}

/// end

/// get the car paramters and set them in the navigation panel.
function funGetCarDetails(carDesc, carProduct, carImg, carPrice, currency)
{
    document.getElementById("ctl00_cphInnerPage_UcCarNavigation1_divNavSelectedCar").style.display = "block";
    document.getElementById("ctl00_cphInnerPage_UcCarNavigation1_divCarParam").innerHTML = "<b>סוג הרכב</b> : " + carDesc + "<br />מחיר : " + carPrice + " " + currency;

    document.getElementById("ctl00_cphInnerPage_UcCarNavigation1_imgNavCar").src = carImg.replace("~/","");
    
    doAjaxRequest(buildAjaxSetCarDetails(carDesc, carProduct, carImg, carPrice, currency),{method:"GET", onSuccess:ajaxRentSetCarDetails, onFailure:ajaxFailure});
}

function buildAjaxSetCarDetails(carDesc, carProduct, carImg, carPrice, currency)
{
    var ajaxCommand = "ajaxFunctionID=6&param=" + carDesc + "~" + carProduct + "~" + carImg + "~" + carPrice + "~" + currency;
    return ajaxCommand;
}

function ajaxRentSetCarDetails(){}

/// get the included paramters and set them in the navigation panel.
function funGetIncluded(servDescName, servicePrice, servDescId, servQuantity)
{

    var servCount = document.getElementById("txtServCount");
    //document.getElementById("ctl00_cphInnerPage_dlCarIncluded_ctl00_UcCarIncluded1_divGetIncluded").onclick = "return false;";
    document.getElementById("ctl00_cphInnerPage_UcCarNavigation1_divNavCarIncluded").style.display = "block";
    var count = document.getElementsByTagName("input");
    
    document.getElementById("ctl00_cphInnerPage_UcCarNavigation1_divCarIncluded").innerHTML += "<b>" + servDescName + "</b><span> יחידות : " + count[4].value + "</span><br />";

    doAjaxRequest(buildAjaxGetIncluded(servDescId, servQuantity, servCount.value, servDescName, servicePrice, count[4].value),{method:"GET", onSuccess:ajaxGetIncluded, onFailure:ajaxFailure});
    servCount.value = servCount.value + 1;
}

function buildAjaxGetIncluded(servDescId, servQuantity, servCount, servDescName, servicePrice, count)
{
    var ajaxCommand = "ajaxFunctionID=7&param=" + servDescId + "~" + servQuantity + "~" + servCount + "~" + servDescName + "~" + servicePrice + "~" + count;
    return ajaxCommand;
}

function ajaxGetIncluded () 
{
 

}

function funSelectPersonalDetails() {


    doAjaxRequest(buildAjaxInsurance("false", document.getElementById("rbtnCDW").checked, document.getElementById("rbtnTPPD").checked),{method:"GET", onSuccess:ajaxInsurance, onFailure:ajaxFailure});
    funChangePriceMsg();
}

function buildAjaxInsurance(oChk, oRCDW, oTPPD)
{
    var ajaxCommand = "ajaxFunctionID=8&param=" + oChk + "~" + oRCDW + "~" + oTPPD;
    return ajaxCommand;
}

function ajaxInsurance () {}

function funChangePriceMsg()
{
    intervalMsg = window.setInterval("funIntervalChangePriceMsg()",1000);
}

function funIntervalChangePriceMsg()
{
    if (intervalTimeMsg > 0)
    {
        document.getElementById("divOpenBgInner").style.top = "250px";
        document.getElementById("divOpenBgInner").style.left = "200px";
        document.getElementById("divOpenBgInner").style.display = "block";
        intervalTimeMsg--;
    }
    else {

      
        document.getElementById("divOpenBgInner").style.display = "none";
        clearInterval(intervalMsg);
        window.location.href = "rentcarselectpersonaldetails.aspx";
        //window.location.href = window.location.href.replace("http", "https");
        //alert(window.location.protocol);
        //alert(href);
    }
}
/// open side menu.
/// and save the selected parent menu id to session.
function funOpenSideMenu(menuId)
{
    /// close all side menu.
    funCloseSideMenu(menuId);

    try 
    {
        var oDiv = document.getElementById("ctl00_UcSideMenu1_divParentMenu_" + menuId);
        var oImg = document.getElementById("ctl00_UcSideMenu1_imgParentMenu_" + menuId);
        var oDivSubMenu = document.getElementById("ctl00_UcSideMenu1_divSubMenu_" + menuId);
        
        if (oDiv.className == "divRightMenuTitleOpen")
        {
            oDiv.className = "divRightMenuTitle";
            oImg.src = "images/closeMenu.gif";
            oDivSubMenu.style.display = "none";
        }
        else
        {
            oDiv.className = "divRightMenuTitleOpen";
            oImg.src = "images/openMenu.gif";
            oDivSubMenu.style.display = "block";
        }
        
        doAjaxRequest(buildAjaxSetActiveSideMenu(menuId),{method:"GET", onSuccess:ajaxSetActiveSideMenu, onFailure:ajaxFailure});
    }
    catch(ex)
    {}
}

function buildAjaxSetActiveSideMenu(menuId)
{
    var ajaxCommand = "ajaxFunctionID=5&param=" + menuId;
    return ajaxCommand;
}

function ajaxSetActiveSideMenu(){};
/// end save the selected parent menu id to session.


function funCloseSideMenu(menuId)
{
    var oHdn = document.getElementById("ctl00_UcSideMenu1_hdnParentsId");
    var splitParentId = oHdn.value.split(',');
    
    for (index = 0; index < splitParentId.length; index++)
    {
        try 
        {
            if (menuId != splitParentId[index])
            {
                var oDiv = document.getElementById("ctl00_UcSideMenu1_divParentMenu_" + splitParentId[index]);
                var oImg = document.getElementById("ctl00_UcSideMenu1_imgParentMenu_" + splitParentId[index]);
                var oDivSubMenu = document.getElementById("ctl00_UcSideMenu1_divSubMenu_" + splitParentId[index]);
                
                oDiv.className = "divRightMenuTitle";
                oImg.src = "images/closeMenu.gif";
                oDivSubMenu.style.display = "none";
            }
        }
        catch(ex)
        {}
    }
}

/* load station by country */

function funLoadToStationByCountry(countryId, oSelectCountry)
{
    var countryDesc =  oSelectCountry.options[oSelectCountry.selectedIndex].text;
    doAjaxRequest(buildAjaxLoadStationByCountry(countryId, countryDesc),{method:"GET", onSuccess:ajaxLoadToStationByCountry, onFailure:ajaxFailure});
}

function funLoadStationByCountry(countryId, oSelectCountry)
{
    var countryDesc =  oSelectCountry.options[oSelectCountry.selectedIndex].text;
    doAjaxRequest(buildAjaxLoadStationByCountry(countryId, countryDesc),{method:"GET", onSuccess:ajaxLoadStationByCountry, onFailure:ajaxFailure});
}

function buildAjaxLoadStationByCountry(countryId, countryDesc)
{
    var ajaxCommand = "ajaxFunctionID=3&param=" + countryId + "~" + countryDesc;
    return ajaxCommand;
}

function ajaxLoadToStationByCountry(oReq)
{
    var oSelectToStation = document.getElementById("ctl00_cphInnerPage_selectToStation");

    var ajaxReturnvalue = oReq.responseText.split("*~~*");
    var splitAjaxReturnvalue = ajaxReturnvalue[0].split(';');
    
    oSelectToStation.length = 1;
    
    for (index = 0; index < splitAjaxReturnvalue.length; index++)
    {
        var strStationName =  splitAjaxReturnvalue[index].split(',')[0];
        var strStationId = splitAjaxReturnvalue[index].split(',')[1];
        
        oSelectToStation.options.add(new Option(strStationName));
        oSelectToStation.options[index].value = strStationId;
    }
}

function ajaxLoadStationByCountry(oReq)
{
    var oSelectFromStation = document.getElementById("ctl00_cphInnerPage_selectFromStation");
    //var oSelectToStation = document.getElementById("ctl00_cphInnerPage_selectToStation");
    
    var ajaxReturnvalue = oReq.responseText.split("*~~*");
    var splitAjaxReturnvalue = ajaxReturnvalue[0].split(';');
    
    oSelectFromStation.length = 1;
    //oSelectToStation.length = 0;
    
    for (index = 0; index < splitAjaxReturnvalue.length; index++)
    {
        var strStationName =  splitAjaxReturnvalue[index].split(',')[0];
        var strStationId = splitAjaxReturnvalue[index].split(',')[1];
        
        oSelectFromStation.options.add(new Option(strStationName));
        oSelectFromStation.options[index].value = strStationId;
        
//        oSelectToStation.options.add(new Option(strStationName));
//        oSelectToStation.options[index].value = strStationId;
    }
    
    //document.getElementById("ctl00_cphInnerPage_selectToArea").selectedIndex = document.getElementById("ctl00_cphInnerPage_selectFromArea").selectedIndex;
}
/* end */

/* load days from month, year */
function funLoadDays(month, type)
{
    var days;
    var oDays;
    var oYear;
    if (type == "from")
    {
        oDays = document.getElementById("ctl00_cphInnerPage_selectFromDay");
        oYear = document.getElementById("ctl00_cphInnerPage_selectFromYear");
    }
    else if (type == "mainIsarel")
    {
        oDays = document.getElementById("ctl00_cphMainPage_selectFromDayIsrael");
        oYear = document.getElementById("ctl00_cphMainPage_selectFromYearIsarel");
    }
    else if (type == "mainWorld")
    {
        oDays = document.getElementById("ctl00_cphMainPage_selectFromDayAllWorld");
        oYear = document.getElementById("ctl00_cphMainPage_selectFromYearAllWorld");
    }
    else
    {
        oDays = document.getElementById("ctl00_cphInnerPage_selectToDay");
        oYear = document.getElementById("ctl00_cphInnerPage_selectToYear");
    }
    var year = oYear.options[oYear.selectedIndex].value;
    
    var m = [31,28,31,30,31,30,31,31,30,31,30,31];
    if (month != 2)
    {
       days = m[month - 1];
    }
    else if (year%4 != 0) 
    {
        days = m[1];
    }
    else if (year%100 == 0 && year%400 != 0) 
    {
        days = m[1];
    }
    else
    {
        days = m[1] + 1;
    }
    
    var selectdDay = oDays.selectedIndex;
    
    oDays.length = 0;
    for (index = 1, row = 0; index <= days; index++, row++)
    {
        oDays.options.add(new Option(index));
        oDays.options[row].value = index;
    } 
    
    try
    {
        oDays.selectedIndex = selectdDay;
    }
    catch(ex){}
}

///* set the days to rent the car */
//function funRentDays()
//{
//    var fromDays = document.getElementById("ctl00_cphInnerPage_selectFromDay").options[document.getElementById("ctl00_cphInnerPage_selectFromDay").selectedIndex].value;
//    var fromMonth = document.getElementById("ctl00_cphInnerPage_selectFromMonth").options[document.getElementById("ctl00_cphInnerPage_selectFromMonth").selectedIndex].value;
//    var fromYear = document.getElementById("ctl00_cphInnerPage_selectFromYear").options[document.getElementById("ctl00_cphInnerPage_selectFromYear").selectedIndex].value;
//    var fromTime = document.getElementById("ctl00_cphInnerPage_selectFromTime").options[document.getElementById("ctl00_cphInnerPage_selectFromTime").selectedIndex].text;
//    
//    var toDays = document.getElementById("ctl00_cphInnerPage_selectToDay").options[document.getElementById("ctl00_cphInnerPage_selectToDay").selectedIndex].value;
//    var toMonth = document.getElementById("ctl00_cphInnerPage_selectToMonth").options[document.getElementById("ctl00_cphInnerPage_selectToMonth").selectedIndex].value;
//    var toYear = document.getElementById("ctl00_cphInnerPage_selectToYear").options[document.getElementById("ctl00_cphInnerPage_selectToYear").selectedIndex].value;
//    var toTime = document.getElementById("ctl00_cphInnerPage_selectToTime").options[document.getElementById("ctl00_cphInnerPage_selectToTime").selectedIndex].text;
//    
//    var fromDate = "";
//    var toDate = "";
//    
//    if (parseInt(fromMonth) < 10)
//    {
//        if (parseInt(fromDays) < 10)
//        {
//            fromDate = fromYear + "0" + fromMonth + "0" + fromDays;
//        }
//        else
//        {
//            fromDate = fromYear + "0" + fromMonth + fromDays;
//        }
//    }
//    else
//    {
//        if (parseInt(fromDays) < 10)
//        {
//            fromDate = fromYear + fromMonth + "0" + fromDays;
//        }
//        else
//        {
//            fromDate = fromYear + fromMonth + fromDays;
//        }
//    }
//    
//    if (parseInt(toMonth) < 10)
//    {
//        if (parseInt(toDays) < 10)
//        {
//            toDate = toYear + "0" + toMonth + "0" + toDays;
//        }
//        else
//        {
//            toDate = toYear + "0" + toMonth +  toDays;
//        }
//    }
//    else
//    {
//        if (parseInt(toDays) < 10)
//        {
//            toDate = toYear + toMonth + "0" + toDays;
//        }
//        else
//        {
//            toDate = toYear + toMonth +  toDays;
//        }
//    }
//    doAjaxRequest(buildAjaxRentDays(fromDate, toDate, fromTime.replace(":",""), toTime.replace(":","")),{method:"GET", onSuccess:ajaxRentDays, onFailure:ajaxFailure});
//    
////    if (toDate > fromDate)
////    {
////        var one_day = 1000*60*60*24;

////        document.getElementById("ctl00_cphInnerPage_spanRentDays").innerText = Math.ceil((toDate.getTime() - fromDate.getTime()) / (one_day));
////    }
//}

//function buildAjaxRentDays(fromDate, toDate, fromTime, toTime)
//{
//    var ajaxCommand = "ajaxFunctionID=12&param=" + fromDate + "~" + toDate + "~" + fromTime + "~" + toTime;
//    return ajaxCommand;
//}

//function ajaxRentDays(oReq)
//{
//    var ajaxReturnvalue = oReq.responseText.split("*~~*");
//    if (browser == "Microsoft Internet Explorer")
//    { 
//       document.getElementById("ctl00_cphInnerPage_spanRentDays").innerText = ajaxReturnvalue[0];
//    }
//    else
//    {
//       document.getElementById("ctl00_cphInnerPage_spanRentDays").textContent = ajaxReturnvalue[0];
//    }
//    
//}

/// load the selected station to both drops.
//function funSelectStation(oSelect)
//{
//    var oSelectFromStation = document.getElementById("ctl00_cphInnerPage_selectFromStation");
//    var oSelectToStation = document.getElementById("ctl00_cphInnerPage_selectToStation");
//    
//    oSelectFromStation.selectedIndex = oSelect.selectedIndex;
//    oSelectToStation.selectedIndex = oSelect.selectedIndex; 
//}

function funLoadResevation()
{
    var boolFlagEmail = true;
    var boolFlagPhone = true;

    var oFName = document.getElementById("ctl00_cphInnerPage_txtFName");
    var oLName = document.getElementById("ctl00_cphInnerPage_txtLName");
    var oSelectCountry = document.getElementById("ctl00_cphInnerPage_selectCountry");
    var oPhone = document.getElementById("ctl00_cphInnerPage_txtPhone");
    var oCity = document.getElementById("ctl00_cphInnerPage_txtCity");
    var oAddress = document.getElementById("ctl00_cphInnerPage_txtAddress");
    var oEmail = document.getElementById("ctl00_cphInnerPage_txtEmail");
    var oFax = document.getElementById("ctl00_cphInnerPage_txtFax");
    var oComments = document.getElementById("ctl00_cphInnerPage_txtComments");
    var oZipCode = document.getElementById("ctl00_cphInnerPage_txtZipCode");
    var oFlightNumber = document.getElementById("ctl00_cphInnerPage_txtFlightNumber");
    var oGoldCard = document.getElementById("ctl00_cphInnerPage_txtGoldCard");
    
    /// credit card details checking only if outgoing reservation
    var oCreditCardType = document.getElementById("ctl00_cphInnerPage_selectCreditCardType");
    var oCreditCardNumber = document.getElementById("ctl00_cphInnerPage_txtCreditCardNumber");
    var oCreditCardYear = document.getElementById("ctl00_cphInnerPage_selectCreditCardYear");
    var oCreditCardMonth = document.getElementById("ctl00_cphInnerPage_selectCreditCardMonth");
    var oCreditCardID = document.getElementById("ctl00_cphInnerPage_txtCreditCardID");
    var oCreditCardName = document.getElementById("ctl00_cphInnerPage_txtCreditCardName");
    
    boolFlagEmail = checkEmailValidtaion(oEmail.value);
    boolFlagPhone = checkInternationalPhone(oPhone.value);
	
	if (document.getElementById("ctl00_cphInnerPage_divCreditCardDetails").style.display != "none")
	{
	    if (oFName.value != "" && oLName.value != "" && oSelectCountry.options[oSelectCountry.selectedIndex].text != "בחר מדינה" && oPhone.value != "" && oCity.value != "" && oAddress.value != "" && oEmail.value != "" && boolFlagEmail == true && boolFlagPhone == true && oCreditCardType.options[oCreditCardType.selectedIndex].text != "בחר כרטיס" && oCreditCardNumber.value != "" && oCreditCardYear.options[oCreditCardYear.selectedIndex].text != "" && oCreditCardMonth.options[oCreditCardMonth.selectedIndex].text != "" && oCreditCardID.value != "" && oCreditCardName.value != "")
        {
            doAjaxRequest(buildAjaxLoadResevationOut(oFName.value, oLName.value, oSelectCountry.options[oSelectCountry.selectedIndex].text, oPhone.value, oCity.value, oAddress.value, oEmail.value, oFax.value, oComments.value, oZipCode.value, oFlightNumber.value, oCreditCardType.options[oCreditCardType.selectedIndex].text, oCreditCardNumber.value, oCreditCardYear.options[oCreditCardYear.selectedIndex].text, oCreditCardMonth.options[oCreditCardMonth.selectedIndex].text, oCreditCardID.value, oCreditCardName.value),{method:"GET", onSuccess:ajaxLoadResevation, onFailure:ajaxFailure});
            window.location.href = "rentcarresevationdetails.aspx";
        }
        else
        {
            if (oFName.value == "")
                document.getElementById("divErrorFname").style.display = "block";
            else
                document.getElementById("divErrorFname").style.display = "none";
                
            if (oLName.value == "")
                document.getElementById("divErrorLname").style.display = "block";
            else
                document.getElementById("divErrorLname").style.display = "none";
                
            if (oSelectCountry.options[oSelectCountry.selectedIndex].text == "בחר מדינה")
                document.getElementById("divErrorCountry").style.display = "block";
            else
                document.getElementById("divErrorCountry").style.display = "none";
                
            if (oPhone.value == "")
                document.getElementById("divErrorPhone").style.display = "block";
            else
                document.getElementById("divErrorPhone").style.display = "none";
                
            if (oCity.value == "")
                document.getElementById("divErrorCity").style.display = "block";
            else
                document.getElementById("divErrorCity").style.display = "none";
                
            if (oAddress.value == "")
                document.getElementById("divErrorAddress").style.display = "block";
            else
                document.getElementById("divErrorAddress").style.display = "none";
                
            if (oEmail.value == "")
                document.getElementById("divErrorEmail").style.display = "block";
            else
                document.getElementById("divErrorEmail").style.display = "none";
            
            if (boolFlagEmail == false)
                document.getElementById("divErrorCheckEmail").style.display = "block";
            else
                document.getElementById("divErrorCheckEmail").style.display = "none";
                
            if (boolFlagPhone == false)
                document.getElementById("divErrorCheckPhone").style.display = "block";
            else
                document.getElementById("divErrorCheckPhone").style.display = "none";
                
             if (oCreditCardType.options[oCreditCardType.selectedIndex].text == "בחר כרטיס" == false)
                document.getElementById("divErrorCreditCardType").style.display = "block";
            else
                document.getElementById("divErrorCreditCardType").style.display = "none";
                
            if (oCreditCardNumber.value == "")
                document.getElementById("divErrorCreditCardNumber").style.display = "block";
            else
                document.getElementById("divErrorCreditCardNumber").style.display = "none";
                
             if (oCreditCardYear.options[oCreditCardYear.selectedIndex].text == "" || oCreditCardMonth.options[oCreditCardMonth.selectedIndex].text == "")
                document.getElementById("divErrorCreditCardPeriod").style.display = "block";
            else
                document.getElementById("divErrorCreditCardPeriod").style.display = "none";
            
             if (oCreditCardID.value == "")
                document.getElementById("divErrorCreditCardID").style.display = "block";
            else
                document.getElementById("divErrorCreditCardID").style.display = "none";
                
             if (oCreditCardName.value == "")
                document.getElementById("divErrorCreditCardName").style.display = "block";
            else
                document.getElementById("divErrorCreditCardName").style.display = "none";   
        }
	}
	else
	{
        if (oFName.value != "" && oLName.value != "" && oSelectCountry.options[oSelectCountry.selectedIndex].text != "בחר מדינה" && oPhone.value != "" && oCity.value != "" && oAddress.value != "" && oEmail.value != "" && boolFlagEmail == true && boolFlagPhone == true)
        {
            doAjaxRequest(buildAjaxLoadResevationIn(oFName.value, oLName.value, oSelectCountry.options[oSelectCountry.selectedIndex].text, oPhone.value, oCity.value, oAddress.value, oEmail.value, oFax.value, oComments.value + " " + "Gold card: " + oGoldCard.value, oZipCode.value, oFlightNumber.value),{method:"GET", onSuccess:ajaxLoadResevation, onFailure:ajaxFailure});
            window.location.href = "rentcarresevationdetails.aspx";
        }
        else
        {
            if (oFName.value == "")
                document.getElementById("divErrorFname").style.display = "block";
            else
                document.getElementById("divErrorFname").style.display = "none";
                
            if (oLName.value == "")
                document.getElementById("divErrorLname").style.display = "block";
            else
                document.getElementById("divErrorLname").style.display = "none";
                
            if (oSelectCountry.options[oSelectCountry.selectedIndex].text == "בחר מדינה")
                document.getElementById("divErrorCountry").style.display = "block";
            else
                document.getElementById("divErrorCountry").style.display = "none";
                
            if (oPhone.value == "")
                document.getElementById("divErrorPhone").style.display = "block";
            else
                document.getElementById("divErrorPhone").style.display = "none";
                
            if (oCity.value == "")
                document.getElementById("divErrorCity").style.display = "block";
            else
                document.getElementById("divErrorCity").style.display = "none";
                
            if (oAddress.value == "")
                document.getElementById("divErrorAddress").style.display = "block";
            else
                document.getElementById("divErrorAddress").style.display = "none";
                
            if (oEmail.value == "")
                document.getElementById("divErrorEmail").style.display = "block";
            else
                document.getElementById("divErrorEmail").style.display = "none";
            
            if (boolFlagEmail == false)
                document.getElementById("divErrorCheckEmail").style.display = "block";
            else
                document.getElementById("divErrorCheckEmail").style.display = "none";
                
            if (boolFlagPhone == false)
                document.getElementById("divErrorCheckPhone").style.display = "block";
            else
                document.getElementById("divErrorCheckPhone").style.display = "none";
        }
    }
}

function checkEmailValidtaion(str)
{
    var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	    return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	}
	if (str.indexOf(" ")!=-1){
	    return false;
	}	
	return true;
}


// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 9;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
    s=stripCharsInBag(strPhone,validWorldPhoneChars);
    return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }

function buildAjaxLoadResevationIn(fName, lName, country, phone, city, address, email, fax, comments, zipCode, flightNumber)
{
    var ajaxCommand = "ajaxFunctionID=9&param=" + fName + "~" + lName + "~" + country + "~" + phone + "~" + city + "~" + address + "~" + email + "~" + fax + "~" + comments + "~" + zipCode + "~" + flightNumber;
    return ajaxCommand;
}

function buildAjaxLoadResevationOut(fName, lName, country, phone, city, address, email, fax, comments, zipCode, flightNumber, creditCardType, creditCardNumber, creditCardYear, creditCardMonth, creditCardID, creditCardName)
{
    var ajaxCommand = "ajaxFunctionID=11&param=" + fName + "~" + lName + "~" + country + "~" + phone + "~" + city + "~" + address + "~" + email + "~" + fax + "~" + comments + "~" + zipCode + "~" + flightNumber + "~" + creditCardType + "~" + creditCardNumber + "~" + creditCardYear + "~" + creditCardMonth + "~" + creditCardID + "~" + creditCardName;
    return ajaxCommand;
}

function ajaxLoadResevation () {}

/// get the information from the selected station
function funGetStationInformation(selectId)
{
    var oSelect = document.getElementById(selectId);
    if (oSelect.selectedIndex > 0)
    {
        doAjaxRequest(buildAjaxGetStationInformation(oSelect.options[oSelect.selectedIndex].value, oSelect),{method:"GET", onSuccess:ajaxGetStationInformation, onFailure:ajaxFailure});
    }
}

function buildAjaxGetStationInformation(stationId, oSelect)
{
    var ajaxCommand = "ajaxFunctionID=10&param=" + stationId + "~" + oSelect;
    return ajaxCommand;
}

function ajaxGetStationInformation(oReq)
{
    var ajaxReturnvalue = oReq.responseText.split("*~~*");
    var splitAjaxReturnvalue = ajaxReturnvalue[0].split(';');
    
    if (splitAjaxReturnvalue != "false")
    {
        try 
        {
            document.getElementById("tdStationName").innerText = splitAjaxReturnvalue[0];
            document.getElementById("tdStationAddress").innerText = splitAjaxReturnvalue[1];
            document.getElementById("tdStationCity").innerText = splitAjaxReturnvalue[2];
            document.getElementById("tdStationPhone").innerText = splitAjaxReturnvalue[3];
            document.getElementById("tdStationFax").innerText = splitAjaxReturnvalue[4];
            document.getElementById("tdStationManager").innerText = splitAjaxReturnvalue[5];
            document.getElementById("tdStationSunday").innerText = splitAjaxReturnvalue[6];
            document.getElementById("tdStationMonday").innerText = splitAjaxReturnvalue[7];
            document.getElementById("tdStationTuesday").innerText = splitAjaxReturnvalue[8];
            document.getElementById("tdStationWednesday").innerText = splitAjaxReturnvalue[9];
            document.getElementById("tdStationThursday").innerText = splitAjaxReturnvalue[10];
            document.getElementById("tdStationFriday").innerText = splitAjaxReturnvalue[11];
            document.getElementById("tdStationSaturday").innerText = splitAjaxReturnvalue[12];
        }
        catch(ex)
        {
            document.getElementById("tdStationName").contentText =  splitAjaxReturnvalue[0];
            document.getElementById("tdStationAddress").contentText =  splitAjaxReturnvalue[1];
            document.getElementById("tdStationCity").contentText = splitAjaxReturnvalue[2];
            document.getElementById("tdStationPhone").contentText =  splitAjaxReturnvalue[3];
            document.getElementById("tdStationFax").contentText =  splitAjaxReturnvalue[4];
            document.getElementById("tdStationManager").contentText =  splitAjaxReturnvalue[5];
            document.getElementById("tdStationSunday").contentText =  splitAjaxReturnvalue[6];
            document.getElementById("tdStationMonday").contentText =  splitAjaxReturnvalue[7];
            document.getElementById("tdStationTuesday").contentText =  splitAjaxReturnvalue[8];
            document.getElementById("tdStationWednesday").contentText =  splitAjaxReturnvalue[9];
            document.getElementById("tdStationThursday").contentText =  splitAjaxReturnvalue[10];
            document.getElementById("tdStationFriday").contentText =  splitAjaxReturnvalue[11];
            document.getElementById("tdStationSaturday").contentText =  splitAjaxReturnvalue[12];
        }
        
        var scrWidth = document.body.clientWidth;
        var scrHeight = document.body.clientHeight;
        /*
        var scrWidth = document.documentElement.clientWidth;
        var scrHeight = document.documentElement.clientHeight;*/
        
        var el = document.getElementById("divOpenBg");
        var elInner = document.getElementById("divOpenBgInner");
        
        el.style.width = scrWidth + "px";
        el.style.height = scrHeight + 20 + "px";
        
        /*elInner.style.left = scrWidth/2-291 + "px"*/
        /*elInner.style.top = scrHeight/2 + "px"*/
        elInner.style.left = scrWidth/2-300 + "px"
        elInner.style.top = "200px"
        
        if (el.style.display == "block"){
            el.style.display = "none";
            elInner.style.display = "none";
        }else{
            el.style.display = "block";
            elInner.style.display = "block";
        }

        //document.getElementById("divStationInformation").style.display = "block";
        //document.getElementById("divStationInformation").top = findPosX(splitAjaxReturnvalue[13]);
        //document.getElementById("divStationInformation").left = findPosY(splitAjaxReturnvalue[13])
    }
}

function funLoadHomePage()
{
    window.location.href = 'http://www.hertz.co.il';
}

function funLoadHomePageEN()
{
    window.location.href = 'http://www.hertz.co.il/en/';
}

function funCheckCharacter(oTxt)
{
    var strTxt = oTxt.value;
    oTxt.value = "";
    
    for (var index = 0; index < strTxt.length; index++) 
    {
        if (arrChracters.indexOf(strTxt.charAt(index)) == -1) 
        {
            oTxt.value += strTxt.charAt(index);
        }
    } 
}

function loadRenCar(type)
{
    if (type == "outgoing")
    {
        var oSelectYear = document.getElementById("selectFromYearAllWorld");
        var oSelectMonth = document.getElementById("selectFromMonthAllWorld");
        var oSelectDay = document.getElementById("selectFromDayAllWorld");
        var oSelectArea = document.getElementById("selectFromArea");
    
        doAjaxRequest(buildAjaxLoadRenCar(false),{method:"GET", onSuccess:ajaxLoadRenCar, onFailure:ajaxFailure});
    }
    else
    {
        doAjaxRequest(buildAjaxLoadRenCar(true),{method:"GET", onSuccess:ajaxLoadRenCar, onFailure:ajaxFailure});
    }
}

function buildAjaxLoadRenCar(type)
{
    var ajaxCommand = "ajaxFunctionID=13&param=" + type;
    return ajaxCommand;
}

function ajaxLoadRenCar() {}
