﻿// ajax calling
var _roomDDlClientId = "";
var _currRoomNumber;
 function refreshData()
	{
	try
	{
        dateFrom = SetDates("hid_FromDate");
        dateTo = SetDates("hid_ToDate");
        document.getElementById("lblDates2").innerHTML = CheckDates();

        var remarks = document.getElementById("hdn_Remarks").value;
        
        if ( document.getElementById("lblRemarks")!=null)
        {
            document.getElementById("lblRemarks").innerHTML = remarks;
            document.getElementById("lblRemarks").style.display = "";
            document.getElementById("tdRem").style.display = "";
            //document.getElementById("tdRemSep").style.display = "";
        }
        var specialPrice = document.getElementById("hdn_SpecialPrice").value;

//        var specialPrice = document.getElementById("hdn_SpecialPrice").value.replace(/{/g, "<").replace(/}/g, ">");
     if ( document.getElementById("lblRemSpecial")!=null)
        {
        try{
            document.getElementById("lblRemSpecial").innerHTML = specialPrice;
            document.getElementById("lblRemSpecial").style.display = "";
            document.getElementById("trRem").style.display = "";
             }catch(x){}
             //document.getElementById("tdRemSep").style.display = "";
        }

        FillRoomTypes();
        FillRoomGuestsForAllRooms();
        FillBasis();
        FillAdds();
        FillCurrencySymbolForAllRooms();
    
        document.getElementById(controlClientId + "pnlRooms").style.display = "";
        document.getElementById(controlClientId + "pnlSales").style.display = "none";
        
        CalcAll();
        }
        catch(ex)
        {
            //document.getElementById("spnTotalPrice").style.display="none";
            document.getElementById(controlClientId + "pnlRooms").style.display = "none";
            document.getElementById(controlClientId + "pnlDate").style.display = "";
        }
	}
	
function noResults()
{

    document.getElementById("imghour").style.display = "none";
    document.getElementById("lblsearch").style.display = "none";
    document.getElementById("searchtitle").style.display = "none";
    document.getElementById("searchbot").style.display = "none";
    
    
//	        document.getElementById("lblNoResults").style.display = "";
}

function callAjaxSales()
{
    var _hotelid2 =new String();
    _hotelid2 =  _hotelid;
    _hotelid2 = _hotelid2.replace("=","*");
     var query = "hotelcode="+_hotelcode+"&checkin="+document.getElementById(controlClientId+"hid_checkin").value+"&checkout="+document.getElementById(controlClientId+"hid_checkout").value+"&hotelid="+_hotelid2 + "&ddport="+_DDport;
     
     SendQuerySales(ajaxSalesUrl,query);
}

var reqSales;
function SendQuerySales(link,query)
{
    InitializeSales(); 
    var url=link + "?" + query;

    if(reqSales!=null)
    {
        reqSales.onreadystatechange = ProcessSales;
        reqSales.open("GET", url, true);
        reqSales.send(null);
    }
 }
 function InitializeSales()
{
    try
    {
        reqSales=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            reqSales=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {
            reqSales=null;
        }
    }

    if(!reqSales&&typeof XMLHttpRequest!="undefined")
    {
        reqSales= new
        XMLHttpRequest();
    }
}   
  function ProcessSales()
{
    if (reqSales.readyState == 4)
    {
    // only if "OK"
        if (reqSales.status == 200)
        {
            if(reqSales.responseText!="")
            {
                var _response = reqSales.responseText
                document.getElementById("divSales").innerHTML = _response.split("%splt%")[0];
                if (_response.split("%splt%")[1]=="false")
                {
//                     document.getElementById("tblResults").style.display = "none";
                    noResults();
                    document.getElementById(controlClientId + "pnlSales").style.display = "";
                  
                }
               else
               {
                document.getElementById("imghour").style.display = "none";
	            document.getElementById("lblsearch").style.display = "none";
	            document.getElementById("lblNoResults").style.display = "none";
	              document.getElementById(controlClientId + "pnlDate").style.display = "none";
	              document.getElementById(controlClientId + "pnlSales").style.display = "";
	              document.getElementById("searchtitle").style.display = "";
	              document.getElementById("searchbot").style.display = "";
                } 
            }
        }
        else
        {
        document.getElementById(controlClientId + "pnlDate").style.display = "none";
        document.getElementById(controlClientId + "pnlSales").style.display = "";

        document.getElementById("searchtitle").style.display = "";
        document.getElementById("searchbot").style.display = "";
                document.getElementById("imghour").style.display = "none";
	            document.getElementById("lblsearch").style.display = "none";
	            document.getElementById("lblNoResults").style.display = "none";
            document.getElementById("divSales").innerHTML= "היתה בעיה לקבל את הנתונים, אנא נסו שנית : "+reqSales.statusText;
        }
      }
     
 
 }
 
 
 function callAjaxPrices(_index)
{
     var query = "index="+_index+"&hotelId=" + _roomHotelId+"&checkin="+document.getElementById(controlClientId+"hid_checkin").value+"&checkout="+document.getElementById(controlClientId+"hid_checkout").value;
     SendQueryPrices(ajaxPricesUrl,query);
}

var reqPrices;
function SendQueryPrices(link,query)
{
    InitializePrices(); 
    var url=link + "?" + query;

    if(reqPrices!=null)
    {
        reqPrices.onreadystatechange = ProcessPrices;
        reqPrices.open("GET", url, true);
        reqPrices.send(null);
    }
 }
 function InitializePrices()
{
    try
    {
        reqPrices=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            reqPrices=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {
            reqPrices=null;
        }
    }

    if(!reqPrices&&typeof XMLHttpRequest!="undefined")
    {
        reqPrices= new
        XMLHttpRequest();
    }
}   
  function ProcessPrices()
{
    if (reqPrices.readyState == 4)
    {
    // only if "OK"
   
        if (reqPrices.status == 200)
        {
            if(reqPrices.responseText!="")
            {
                var _response = reqPrices.responseText
                document.getElementById("divRoomsAndPrices").innerHTML = _response;
                refreshData();
                
            }
        }
        else
        {
         
        document.getElementById(controlClientId + "pnlRooms").style.display = "";
        document.getElementById(controlClientId + "pnlSales").style.display = "none";
            document.getElementById("divRoomsAndPrices").innerHTML= "היתה בעיה לקבל את הנתונים, אנא נסו שנית : "+reqPrices.statusText;
            
        }
      }
 }





 function GetDates(str)
    {
        var result = '';
        if (str != '') {
            var temporaryDate = new Date(str);
            var month = temporaryDate.getMonth() + 1;
            if (month > 12) { month = 1; }
            result = temporaryDate.getDate() + "/" + month + "/" + temporaryDate.getFullYear();
        }
        return result;
    }
    
    function CheckDates() {
        return document.getElementById("fdt1").value + " - " + document.getElementById("fdt2").value;
    }
    
    function ChangeCheckout()
    {
        if (CompareDates())
        {
            document.getElementById("fdt2").value = document.getElementById("fdt1").value;
        }    
       
    }
    
    function changeHdnDates()
    {
        dateCheckIn = document.getElementById("fdt1").value;
        dateCheckOut = document.getElementById("fdt2").value;
        document.getElementById(controlClientId+"hid_checkout").value = dateCheckOut;
        document.getElementById(controlClientId + "hid_checkin").value = dateCheckIn;
//        var _link = _baseurl + "resources/services/loading_search.aspx?page=../../israel/results.aspx&ccode=" + _cityid + "&fdate=" + dateCheckIn + "&tdate=" + dateCheckOut + "&hrating=0&hbasis=0&hcode=0&rtype=0";
//        document.getElementById("linkToResults").innerHTML = "<a href='" + _link + "'>לחיפוש באותו איזור ובאותם התאריכים לחץ כאן</a>";

        
    }
    
    function ChangeCheckin()
    {
        if (CompareDates2())
        {
            document.getElementById("fdt1").value = document.getElementById("fdt2").value;
        }    
    }
    
    function CompareDates2()
    {
        var one_day = 1000*60*60*24;
        dateCheckIn = SetTestDates("fdt1"); //alert("dateCheckIn = " + dateCheckIn); 
        dateCheckOut = SetTestDates("fdt2"); //alert("dateCheckOut = " + dateCheckOut);
	    var diffDays = Math.ceil((dateCheckIn.getTime()-dateCheckOut.getTime())/(one_day));
	    return (diffDays >=7);
    }
    
    function CompareDates()
    {
        var one_day = 1000*60*60*24;
        dateCheckIn = SetTestDates("fdt1"); //alert("dateCheckIn = " + dateCheckIn); 
        dateCheckOut = SetTestDates("fdt2"); //alert("dateCheckOut = " + dateCheckOut);
	    var diffDays = Math.ceil((dateCheckOut.getTime()-dateCheckIn.getTime())/(one_day));
	    return (diffDays <=0);
    }

	function GotoSales()
	{
	    var dateCheckInTmp = document.getElementById("fdt1").value;
        var dateCheckOutTmp = document.getElementById("fdt2").value;
        var msg_error ;
        if (dateCheckInTmp == "" || dateCheckOutTmp == "" ) 
        {
            alert("יש למלא תאריכי כניסה ויציאה");
            return false;
        }
        
        if (CompareDates()){
            alert("תאריכים לא נכונים! תאריך יציאה חייב להיות יותר גדול מתאריך כניסה");
            return false;
        }
        
        //pageTracker._trackPageview('/onclick/Israel/chooseDate');
	    //document.getElementById(controlClientId + "hdnCheckIn").value = dateCheckIn;
	    //document.getElementById(controlClientId + "hdnCheckOut").value = dateCheckOut;
	    document.getElementById(controlClientId + "pnlRooms").style.display = "none";
	    document.getElementById("lblNoResults").style.display = "none";
	    document.getElementById("imghour").style.display = "";
	    document.getElementById("lblsearch").style.display = "";
	    document.getElementById("lblDates").innerHTML = CheckDates();
	   
	    callAjaxSales();
	      
        
	}
	
	function GotoDate()
	{
	    document.getElementById(controlClientId + "pnlRooms").style.display = "none";
	    document.getElementById(controlClientId + "pnlSales").style.display = "none";
        document.getElementById(controlClientId + "pnlDate").style.display = "";
//        document.getElementById("tdRem").style.display = "none";
	}
	
	function GotoRooms(index)
	{

	    callAjaxPrices(index);

	    
	}
	
	
	
	function SetRooms(roomNum){
        for (i=1; i<=roomNumber; ++i){  
            document.getElementById("trRoom" + i).style.display = "none";
        }	 
        for (i=1; i<=roomNum; ++i){  
            document.getElementById("trRoom" + i).style.display = "";
            //document.getElementById(controlClientId + "DomesticHotelsRoom" + i + "_slct_RoomGuests").selectedIndex = 0;
        }
        CalcTotalPrice();
       
    }

        function SetCheckInOutDates(_strDate){
            var _vecDates = _strDate.split("/");
            var _year  = _vecDates[2];
            var _month = _vecDates[1];
            var _day   = _vecDates[0];
            var _hour  = "0";
            var _min   = "0";
            var _sec   = "0";
            var myDate = new Date(_year, _month-1, _day, _hour, _min, _sec);
            return myDate;
        }
    
    function SetTestDates(_objName){
        var objDate = document.getElementById(_objName);
        var _vecDates = objDate.value.split("/");
        var _year  = _vecDates[2]; if (parseInt(_year) < 100 ) {_year = "20" + _year;}
        var _month = _vecDates[1];
        var _day   = _vecDates[0];
        var myDate = new Date(_year, _month-1, _day);
        return myDate;
    }
    
    function CalcAll(){
        YouCanCalculatePrices = true;
        CalcPrices();
        CalcTotalPrice();
    }

    function ShowRoomAndPrices(){
    	
        document.getElementById("spnDateFrom").style.display = "";
        document.getElementById("spnDateFrom").innerHTML = document.getElementById("fdt1").value;
        document.getElementById("fdt1").style.display = "none";
        document.getElementById("imgDateFrom").style.display = "none";
    	
        document.getElementById("spnDateTo").style.display = "";
        document.getElementById("spnDateTo").innerHTML = document.getElementById("fdt2").value;
        document.getElementById("fdt2").style.display = "none";
        document.getElementById("imgDateTo").style.display = "none";
    	
        document.getElementById("tdChangeDates").style.display = "";
        document.getElementById("btnCalcPrices").style.display = "none";
    }

    function HideRoomAndPrices(){
    	
        document.getElementById("spnDateFrom").style.display = "none";
        document.getElementById("fdt1").style.display = "";
        document.getElementById("imgDateFrom").style.display = "";
    	
        document.getElementById("spnDateTo").style.display = "none";
        document.getElementById("fdt2").style.display = "";
        document.getElementById("imgDateTo").style.display = "";
    	
        document.getElementById("tdChangeDates").style.display = "none";
        document.getElementById("btnCalcPrices").style.display = "";
    }
    
    function FillCurrencySymbolForAllRooms()
    {
        for (i=1; i<=roomNumber; ++i){
            var _objName = controlRoomSelectId + i + "_lbl_CurrencySymbol"; 
            var _currencysymbol=document.getElementById( "hid_currency").value; 
            document.getElementById(_objName).innerHTML =_currencysymbol; 
        }	 
    }
    
    function CalcAddsPrice(obj){
        var addID = obj.id.substr(obj.id.length-1, 1);
        var _objName = "hidAddsPrice" + addID;
        var _price = document.getElementById(_objName).value;
        _objName = "spnAdsPrice" + addID;
        document.getElementById(_objName).innerHTML = _price * obj.value;
        CalcTotalPrice();

    }
	
    function ClearAll(){
        ClearAdds();
        ClearRoomTypesInAllRooms();
        ClearRoomGuestsInAllRooms();
        ClearBasisInAllRooms();
    }

    function ClearBasisInAllRooms(){
        for (j=1; j<=roomNumber; ++j){
            var _objName = "DomesticHotelsRoom" + j + "_slct_Basis";  
            var obj = document.getElementById(_objName);
            while (obj.length > 0)	
            {
	            obj.options[0]=null;
            }
        }	 
    }

    function ClearRoomGuestsInAllRooms(){
        for (j=1; j<=roomNumber; ++j){
            var _objName = "DomesticHotelsRoom" + j + "_slct_RoomGuests";  
            var obj = document.getElementById(_objName);
            while (obj.length > 0)	
            {
	            obj.options[0]=null;
            }
        }	 
    }
	
    function ClearRoomTypesInAllRooms(){
        for (j=1; j<=roomNumber; ++j){
            var _objName =  "DomesticHotelsRoom" + j + "_slct_RoomTypes";  
            var obj = document.getElementById(_objName);
            while (obj.length > 0)	
            {
	            obj.options[0]=null;
            }
        }	 
    }
    
    function ClearAdds(){		
        var tbl = document.getElementById('tblAdds');
        var lastRow = tbl.rows.length;
        while (lastRow > 1) {
            tbl.deleteRow(lastRow - 1);
            lastRow = tbl.rows.length;
        }
    }
    
    function FillAdds(){
        var _code = "";
        var _text = "";
        var _id = "";
        var _vecAddsCodeText;
        var _objName = "";
        var _varAdds = document.getElementById("hid_Adds");
        var _currency = document.getElementById("hid_currency");

        if (_varAdds.value != ""){
            document.getElementById("tblAdds").style.display = "";
            document.getElementById("tblAdds").className = "DomesticHotelDetailsRoomSelectItem";
            var _vecAdds = _varAdds.value.split("|");
            NumberOfAdds = _vecAdds.length;
            var tbl = document.getElementById('tblAdds');
            for (i=0; i<_vecAdds.length; ++i){  
	            _vecAddsCodeText = _vecAdds[i].split(";");
	            
		            var lastRow = tbl.rows.length;
		            var iteration = lastRow - 1;
		            var row = tbl.insertRow(lastRow);
		            row.id = "trAds" + iteration;

		            _price = _vecAddsCodeText[2];
		            var cellPrice = row.insertCell(0);
		            var el = document.createElement('span');
		            with (el){
			            id = 'spnAdsCurrency' + iteration;
			            innerHTML = _currency.value + " ";
		            }
		            cellPrice.style.direction = "ltr";
		            cellPrice.appendChild(el);
													
		            _price = _vecAddsCodeText[2];
		            el = document.createElement('span');
		            with (el){
			            id = 'spnAdsPrice' + iteration;
			            innerHTML = "0";
		            }				
		            cellPrice.appendChild(el);
		             el = document.createElement('input');
		            with (el){
			            type = "hidden";
			            id = 'hidAddsPrice' + iteration;
			            value = _price;
		            }
		            cellPrice.appendChild(el);
				
		            var cellSelect = row.insertCell(0);
		            var elSelect = document.createElement('select');
		            elSelect.style.width = "50px";
		            for (j=0; j<=20; ++j){
			            elSelect.options[j] = new Option(j, j);
		            }
		            with (elSelect){
			            id = 'spnAdsQuantity' + iteration;
			            onchange=CalcAddsPriceTEST;
		            }					
		            cellSelect.appendChild(elSelect);
										
		            _desc = _vecAddsCodeText[1] + " (" + _vecAddsCodeText[2]  + " " + _currency.value + ")";
		            var cell = row.insertCell(0);
		            var el = document.createElement('select');
		            el.style.width = "245px";
		            with (el){
			            id = 'spnAdsName' + iteration;
			            el.options[0] = new Option(_desc, _vecAddsCodeText[0]);
		            }
		            cell.appendChild(el);
		            var cellEmpty = row.insertCell(0);
		            var el = document.createElement('span');
		            with (el){
			            id = 'spanEmpty' + iteration;
			            innerHTML = "";
		            }
		            cellEmpty.appendChild(el);
            }
        }
    }
    
    function CalcAddsPriceTEST() {
        var tbl = document.getElementById('tblAdds').firstChild;
        for (i=0; i<tbl.childNodes.length-1; ++i){
            var rowprice = parseFloat(document.getElementById('hidAddsPrice' + i).value);
            rowprice = rowprice * parseInt(document.getElementById('spnAdsQuantity' + i).value);
            document.getElementById('spnAdsPrice' + i).innerHTML = rowprice;
        }
        CalcTotalPrice();
    }
    
    function FillBasis(){
        for (i=1; i<=roomNumber; ++i){
            _objName = "DomesticHotelsRoom" + i + "_slct_RoomTypes"; 
		     ClearSelectControl("DomesticHotelsRoom" + i + "_slct_Basis");
            var _roomTypeSelectedCode = document.getElementById(_objName).value;
            FillRoomBasisForSpecificRoom(_roomTypeSelectedCode, i);
        }	
    }
    
    function FillRoomBasisForSpecificRoom(_currBasisSelectedCode, _currRoomNumber){
        var _vecBasisCodeText;
        var _roomBasisCode = "";
        var _code = "";
        var _text = "";
        var _id = "";
        
        ClearBasisForSpecificRoom(_currRoomNumber);
        var _varBasis = document.getElementById("hid_Basis");
        if (_varBasis.value != ""){
            var _vecBasis = _varBasis.value.split("|");
            for (k=0; k<_vecBasis.length; ++k){  
	            _vecBasisCodeText = _vecBasis[k].split(";");
	            _roomBasisCode = _vecBasisCodeText[4];
	            if (_roomBasisCode == _currBasisSelectedCode) {
                    _code = _vecBasisCodeText[0];
	                _text = _vecBasisCodeText[1];
	                _id = _vecBasisCodeText[2] + ";" + _vecBasisCodeText[3] + ";" + _vecBasisCodeText[4];
	                _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_Basis";  
		            insertToControl(_objName, _code, _text, _id);	
                }
            }
        }
    }

    function FillRoomGuestsForAllRooms(){
        for (i=1; i<=roomNumber; ++i){
            _objName = "DomesticHotelsRoom" + i + "_slct_RoomTypes";  
             ClearSelectControl("DomesticHotelsRoom" + i + "_slct_RoomGuests");
            var _roomTypeSelectedCode = document.getElementById(_objName).value;
            FillRoomGuestsForSpecificRoom(_roomTypeSelectedCode, i);
        }	 
    }

    function FillRoomGuestsForSpecificRoom(_currRoomTypeSelectedCode, _currRoomNumber){
        var _roomTypeCode = "";
        var _vecRoomGuestsCodeText = "";
        var _code = "";
        var _text = "";
        var _id = "";
        var _varRoomGuests = document.getElementById("hid_RoomGuests");
        if (_varRoomGuests.value != ""){
            var _vecRoomGuests = _varRoomGuests.value.split("|");
            for (k=0; k<_vecRoomGuests.length; ++k){
	            _vecRoomGuestsCodeText = _vecRoomGuests[k].split(";");
	            _roomTypeCode = _vecRoomGuestsCodeText[0];
	            if (_roomTypeCode == _currRoomTypeSelectedCode)
	            {
		            _code = _vecRoomGuestsCodeText[1];
		            _text = _vecRoomGuestsCodeText[2];
		            _id = _vecRoomGuestsCodeText[3]	+ ";" + _vecRoomGuestsCodeText[4] + ";" + _vecRoomGuestsCodeText[5]	+ ";" + _vecRoomGuestsCodeText[6] + ";" + _vecRoomGuestsCodeText[7] + ";" + _vecRoomGuestsCodeText[8];
		            _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_RoomGuests";  
		           insertToControl(_objName, _code, _text, _id);
		            if (_code == "DBL"){
		                document.getElementById(_objName).selectedIndex = document.getElementById(_objName).options.length - 1;
		            }
	            } 
            }
            
            _vecRoomGuestsCodeText = _vecRoomGuests[0].split(";");
            id = _vecRoomGuestsCodeText[3]	+ ";" + _vecRoomGuestsCodeText[4] + ";" + _vecRoomGuestsCodeText[5]	+ ";" + _vecRoomGuestsCodeText[6] + ";" + _vecRoomGuestsCodeText[7] + ";" + _vecRoomGuestsCodeText[8];
         
		    FillRoomInfantsForSpecificRoom(id , _currRoomNumber);
        }
    }
        
    function FillRoomInfantsForSpecificRoom(_currid, _currRoomNumber){
        var _code = "";
        var _text = "";
        var _id = "";
        var _vecRoomGuests = _currid.split(";");
        if (_vecRoomGuests.length = 6){
            var inf = _vecRoomGuests[4];
            var priceperinfant = _vecRoomGuests[5];
             
           _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_Infants";  
		            ClearSelectControl(_objName);
            for (k=0; k<=inf; ++k){
	            _code = priceperinfant;
	            _text = k;
	            _id = k*priceperinfant;
	            _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_Infants"; 
	            insertToControl(_objName, _code, _text, _id);
            }  
        }	
    }
    
     function CalcCurrentPrice(roomNumber){
        //var _vecRoomTypeIDs = obj.id.split("_");
        //var roomNumber = _vecRoomTypeIDs[1].substr(_vecRoomTypeIDs[1].length-1, 1);
        CalcPrice(roomNumber);		 
        CalcTotalPrice();
    }

    function ChangeRoomGuests(roomNumber){      
        //--<Fill Room Guests>
            _objName = "DomesticHotelsRoom" + roomNumber + "_slct_RoomTypes";  
            var _roomTypeSelectedCode = document.getElementById(_objName).value;
            ClearRoomGuestsForSpecificRoom(roomNumber);
            FillRoomGuestsForSpecificRoom(_roomTypeSelectedCode, roomNumber);
            FillRoomBasisForSpecificRoom(_roomTypeSelectedCode, roomNumber);
            ChangeRoomInfants(roomNumber);
 
            
    
    }
    
    function ChangeRoomInfants(roomNumber){
            _objName = "DomesticHotelsRoom" + roomNumber + "_slct_RoomGuests"; 
            var objRoomInfants = document.getElementById(_objName);
            var _roomGuestSelectedCode;
            for (j=0; j<objRoomInfants.length; ++j){
                if (objRoomInfants[j].selected == true){
                    _roomGuestSelectedCode = objRoomInfants[j].id; }
	        }
            ClearInfantsForSpecificRoom(roomNumber);
            FillRoomInfantsForSpecificRoom(_roomGuestSelectedCode, roomNumber);
            CalcTotalPrice();
    }

    function ClearRoomGuestsForSpecificRoom(_currRoomNumber){
        var _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_RoomGuests";  
        var obj = document.getElementById(_objName);
        while (obj.length > 0)	
        {
            obj.options[0]=null;
        }
    }
    
    function ClearInfantsForSpecificRoom(_currRoomNumber){
        var _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_Infants";  
        var obj = document.getElementById(_objName);
        while (obj.length > 0)	
        {
            obj.options[0]=null;
        }
    }

    function ClearBasisForSpecificRoom(_currRoomNumber){
        var _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_Basis";  
        var obj = document.getElementById(_objName);
        while (obj.length > 0)	
        {
            obj.options[0]=null;
        }
    }
		
    function FillRoomTypes(){
        var _code = "";
        var _text = "";
        var _vecRoomTypesCodeText;
        var _objName = "";
        var _varRoomTypes = document.getElementById("hid_RoomTypes");
         for (j=1; j<=roomNumber; ++j){
		            _objName = "DomesticHotelsRoom" + j + "_slct_RoomTypes";  
		            ClearSelectControl(_objName);
	            }	 
        if (_varRoomTypes.value != ""){
            var _vecRoomTypes = _varRoomTypes.value.split("|");
            for (i=0; i<_vecRoomTypes.length; ++i){  
	            _vecRoomTypesCodeText = _vecRoomTypes[i].split(";");
	            _code = _vecRoomTypesCodeText[0];
	            _text = _vecRoomTypesCodeText[1];
	            for (j=1; j<=roomNumber; ++j){
		            _objName = "DomesticHotelsRoom" + j + "_slct_RoomTypes";  
		            insertToControl(_objName, _code, _text, _text)	;
	            }	 
            } 	 
        } 
    }

    function insertToControl(_currObjName, _currCode, _currText, _currId)
    {
        MyOption = document.createElement("OPTION");
        MyOption.id = _currId;
        MyOption.text  = _currText;
        MyOption.value = _currCode;
        
        if (browserCode == "IE"){
        document.getElementById(_currObjName).add(MyOption);
        }
        else {
        document.getElementById(_currObjName).appendChild(MyOption)
        }
    }
    
    function SetDates(_objName){
        var objDate = document.getElementById(controlClientId+_objName).value;
        if (objDate == '') {return objDate}
        else {
        var _vecDates = objDate.split("/");
        var _year  = _vecDates[2];
        var _month = _vecDates[1];
        var _day   = _vecDates[0];
        var _hour  = 0;// _vecDates[3];
        var _min   = 0;// _vecDates[4];
        var _sec   = 0;// _vecDates[5];
        var myDate = new Date(_year, _month-1, _day, _hour, _min, _sec);
        return myDate;
        }
    }

    function CalcTotalPrice(){
        var _totalPrice = 0;
        var _objName = "";
        var obj;
        
        for (i=1; i<=roomNumber; ++i){
            _objName = "trRoom" + i;
            if (document.getElementById(_objName).style.display == ""){ 
	            _objName = "DomesticHotelsRoom" + i + "_spn_Price";
	            _totalPrice += parseFloat(document.getElementById(_objName).innerHTML, 10);
            }	
        }

        if (document.getElementById("tblAdds").style.display == ""){ 
            for (i=0; i<NumberOfAdds; ++i){
	            _objName = "trAds" + i;
	            if (document.getElementById(_objName).style.display == ""){ 
		            _objName = "spnAdsPrice" + i;
		            _totalPrice += parseFloat(document.getElementById(_objName).innerHTML, 10);
	            }	
            }
        }
		
        document.getElementById("spnTotalPrice").innerHTML = _totalPrice.toString();
        document.getElementById("spnCurrency").innerHTML = document.getElementById("hid_currency").value

        FillOutDataForCheckOut();
       
        
    }

    function CalcPrices(){
        for (i=1; i<=roomNumber; ++i)
            CalcPrice(i);
    }
    
    function CalcPrice(_currRoomNumber){
        if (YouCanCalculatePrices == true){
            var _totalPrice = 0;
            var _priceGuests = 0;
            var _priceBasis = 0;

                _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_RoomGuests"; 
                var objRoomGuests = document.getElementById(_objName);
                for (j=0; j<objRoomGuests.length; ++j){
	                if (objRoomGuests[j].selected == true){
		                _vecPrices = objRoomGuests[j].id.split(";");
		                _numberAdults = _vecPrices[2];
		                _numberChilds = _vecPrices[3];
		                _priceGuests = parseFloat(_vecPrices[0], 10); 
	                }
                }
                _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_Infants";
                var objRoomInfants = document.getElementById(_objName);
                for (j=0; j<objRoomInfants.length; ++j){
	                if (objRoomInfants[j].selected == true){
	                    _priceGuests += parseFloat(objRoomInfants[j].id, 10);
	                }
	            }
                
                _objName = "DomesticHotelsRoom" + _currRoomNumber + "_slct_Basis";  
                var objBasis = document.getElementById(_objName);
                for (j=0; j<objBasis.length; ++j){
	                if (objBasis[j].selected == true){
		                _vecPrices = objBasis[j].id.split(";");
		                _pricePerNightForAdult = _vecPrices[0];
		                _pricePerNightForChild = _vecPrices[1];
		                _priceBasis = (parseFloat(_pricePerNightForAdult, 10) * parseFloat(_numberAdults, 10));
		                _priceBasis += (parseFloat(_pricePerNightForChild, 10) * parseFloat(_numberChilds, 10));
	                }
                }
                _totalPrice = parseFloat(parseFloat(_priceGuests, 10) + parseFloat(_priceBasis, 10));  
                _objName = "DomesticHotelsRoom" + _currRoomNumber + "_spn_Price";  
                var objPrice = document.getElementById(_objName);
                objPrice.innerHTML = _totalPrice.toString();
        }
        else{
            _objName = "DomesticHotelsRoom" + _currRoomNumber + "_spn_Price";  
            var objPrice = document.getElementById(_objName);
            objPrice.innerHTML = "0";
        }		
    }

    function FillOutDataForCheckOut(){
        var _objSelectedRoomType = null;
        var _objSelectedRoomGuests = null;
        var _objSelectedRoomBasis = null;
        var _objSelectedRoomInfants = null;

        var _totalPrice = document.getElementById("spnTotalPrice").innerHTML;
  
        if (_totalPrice == 0){
          alert("נא לבחור תאריכים ומחירים");
          return;
        }

        else {

            for (var g = 1; g <= roomNumber; g++) {
                if (document.getElementById("trRoom" + g).style.display == "") {
                    removeAllOtherRadiosAndCalcPriceIsrael("1", g);
              }
            }
            


          var ChosenRoomPkIds = document.getElementById(controlClientId + "hidChosenRoomPkIds");
          ChosenRoomPkIds.value = "";
          
          if (document.getElementById(controlClientId+"hid_checkin").value == "" || document.getElementById(controlClientId+"hid_checkout").value == "") {
              document.getElementById(controlClientId+"hid_checkin").value = document.getElementById("fdt1").value;
              document.getElementById(controlClientId+"hid_checkout").value= document.getElementById("fdt2").value;
          }

          for (i=1; i<=roomNumber; ++i){  
            if (document.getElementById("trRoom" + i).style.display == ""){
                _objSelectedRoomType = document.getElementById( "DomesticHotelsRoom" + i + "_slct_RoomTypes").options[document.getElementById("DomesticHotelsRoom" + i + "_slct_RoomTypes").selectedIndex];
                
                _objSelectedRoomGuests = document.getElementById( "DomesticHotelsRoom" + i + "_slct_RoomGuests").options[document.getElementById( "DomesticHotelsRoom" + i + "_slct_RoomGuests").selectedIndex];
                _objSelectedRoomBasis = document.getElementById( "DomesticHotelsRoom" + i + "_slct_Basis").options[document.getElementById( "DomesticHotelsRoom" + i + "_slct_Basis").selectedIndex];
                _objSelectedRoomInfants = document.getElementById( "DomesticHotelsRoom" + i + "_slct_Infants").options[document.getElementById( "DomesticHotelsRoom" + i + "_slct_Infants").selectedIndex];
                if (ChosenRoomPkIds.value != "") { ChosenRoomPkIds.value += "|"; }   
                ChosenRoomPkIds.value += "RoomId=" + _objSelectedRoomType.value + ";RoomName=" + _objSelectedRoomType.id + ";BasisId=" + _objSelectedRoomBasis.value + ";RoomType=" + _objSelectedRoomGuests.value + ";Adults=" + GetValueByStringAndIndex(_objSelectedRoomGuests.id, 2) + ";Children=" + GetValueByStringAndIndex(_objSelectedRoomGuests.id, 3) + ";Infants=" + _objSelectedRoomInfants.text + ";Price=" + document.getElementById("DomesticHotelsRoom" + i + "_spn_Price").innerHTML;
            } 
          }
          var attr = document.getElementById(controlClientId + "hidAttractions");
          attr.value = '';
          var tbl = document.getElementById('tblAdds').firstChild;
          for (i=0; i<tbl.childNodes.length-1; ++i){
	        _objName = "spnAdsPrice" + i;
	        var rowprice = parseFloat(document.getElementById(_objName).innerHTML, 10);
	        if (rowprice > 0) {
	            _objName = "spnAdsQuantity" + i;
	            var _obj = document.getElementById("spnAdsName" + i)
	           attr.value += _obj.innerHtml + ";" + rowprice + ";" + document.getElementById(_objName).value + ";" + _obj.value + "|";
	        }
          }
        }
    }

    function GetValueByStringAndIndex(_str, _index){
            var _vecRoomTypes = _str.split(";");
            return _vecRoomTypes[_index];
      }

    function IsRoomSelectValid()
    {
    
      FillOutDataForCheckOut();
      var _totalPrice = document.getElementById("spnTotalPrice").innerHTML;
          if (_totalPrice == 0){
              alert("עליך להגדיר תאריכי כניסה ויציאה ולאחר מכן לחץ על חשב מחיר ");
              return false;
          }
          else if  (_totalPrice > 0){
            if (document.getElementById(controlClientId + "hdn_Rowid").value != "-1") { st_origin = "Search";}
//            pageTracker._trackPageview('/onclick/Israel/OrderButtonFrom' + st_origin);
            return true;
          }
      alert("שגיאה בחישוב מחירים. אנא בחר תאריכים שוב. ");
      return false;
  }

  function removeAllOtherRadiosAndCalcPriceIsrael(numNotRemove, _radioID) {

      document.getElementById("tdRoomsDesc").style.display = "";
      var _indexRooms = document.getElementById("slctRoomNumbers").selectedIndex;
      var _RoomsNum = document.getElementById("slctRoomNumbers").options[_indexRooms].text;
     
      var Dates = document.getElementById("lblDates2").innerHTML;
     
      var str = "";
   
          for (var i = 1; i <= _RoomsNum; i++) {
           var _indexSelectRoom = document.getElementById("DomesticHotelsRoom" + i + "_slct_RoomTypes").selectedIndex;
      var _indexSelectRoomGuests = document.getElementById("DomesticHotelsRoom" + i + "_slct_RoomGuests").selectedIndex;
      var _indexSelectBasis = document.getElementById("DomesticHotelsRoom" + i + "_slct_Basis").selectedIndex;
      var _indexSelectInfants = document.getElementById("DomesticHotelsRoom" + i + "_slct_Infants").selectedIndex;

      var Room = document.getElementById("DomesticHotelsRoom" + i + "_slct_RoomTypes").options[_indexSelectRoom].text;
      var Guests = document.getElementById("DomesticHotelsRoom" + i + "_slct_RoomGuests").options[_indexSelectRoomGuests].text;
      var Basis = document.getElementById("DomesticHotelsRoom" + i + "_slct_Basis").options[_indexSelectBasis].text;
      var Infants = document.getElementById("DomesticHotelsRoom" + i + "_slct_Infants").options[_indexSelectInfants].text;
      var InfantsToShow = "";
          
      if (Infants > 0)
          InfantsToShow = "תינוקות בחדר: " + Infants+"<br/>";
      else
          InfantsToShow = ""
      str += "<br/><b>חדר " + i + ": " + Guests + "</b><br/>בסיס אירוח:" + Basis + "<br/>סוג חדר:" + Room + "<br/>" + InfantsToShow;
          }
          var _html1 = "<div style='width:170px;min-height:200px;' class='dstGeneral'><img  alt='' src='http://www.issta.co.il/resources/images/details/bed.gif' /><span class='dstTitle' style='vertical-align:top;padding-right:5px;' >" + _hotelname + "</span><div style='padding-right:35px;'><b>" + Dates + "<br/>מס חדרים:" + _RoomsNum + "</b><br/>" + str + "</div></div><br/>";

      document.getElementById("tdRoomsDesc").innerHTML =  _html1;


      document.getElementById("ctl00_MainHolder_totalPrice").value = document.getElementById("spnCurrency").innerHTML+ document.getElementById("spnTotalPrice").innerHTML; 

      var _totalPrice = "";

      document.getElementById("sumDiv").style.display = "";
      if (document.getElementById(_summclientId + "discount_amount").value != "" && parseInt(document.getElementById("ctl00_MainHolder_totalPrice").value, 10) > 499) {
          var _priceAfterDiscount = parseInt(document.getElementById("ctl00_MainHolder_totalPrice").value, 10) - parseInt(document.getElementById(_summclientId + "discount_amount").value, 10);
          document.getElementById("sumDiv").innerHTML = "<div style='text-align:right;padding-right:10px;padding-left:10px;background-color:#FAF5D8;height:120px;width:206px;padding-top:5px;border-left:1px solid #E5E5E5;border-right:1px solid #E5E5E5;border-bottom:1px solid #E5E5E5;color:#433F3E;font-size:13px;vertical-align:middle;' ><b>סה\"כ לתשלום </b> = <span class='dtopriceIL'>" + _currencySymbol + document.getElementById("ctl00_MainHolder_totalPrice").value + "</span><br/><b>הנחה למזמינים באתר </b> = <span class='dtoprice'>" + _currencySymbol + document.getElementById(_summclientId + "discount_amount").value + "-</span><br/><b>מחיר אחרי הנחה </b> = <span class='dtoprice'>" + _currencySymbol + _priceAfterDiscount + "</span><br/>ההנחה תקוזז במעמד חיוב הכרטיס<br/>ההנחה תקפה למזמינים באתר עד גמר הזמן</div>";
      }

      else {
          document.getElementById("sumDiv").innerHTML = "<div style='text-align:center;background-color:#FAF5D8;height:30px;width:226px;padding-top:5px;border-left:1px solid #E5E5E5;border-right:1px solid #E5E5E5;border-bottom:1px solid #E5E5E5;color:#433F3E;font-size:13px;vertical-align:middle;' ><b>סה\"כ לתשלום</b> = <span class='dtopriceIL'>" + _currencySymbol + document.getElementById("ctl00_MainHolder_totalPrice").value + "</span></div>";
      }

      document.getElementById("ctl00_MainHolder_descSum").value = document.getElementById("sumDiv").innerHTML.replace(/</g, "&lt;");
      document.getElementById("nothing").style.display = "none";
      document.getElementById("divBtn").style.display = "";
      document.getElementById("sumDivB").style.display = "";

  }



  
