// JScript File
var xmlHtlResult; 
var _splitRT
var decimalPref = "0"
var xu = new XML();
var dom =new DOM();
var currCode = dom.$("ctl00_contentMain_Basket1_hdnFareCurrency") == null ? "" : dom.$("ctl00_contentMain_Basket1_hdnFareCurrency").value;
var currFactor = 1.0;
var scripts = new Array();
var scripts1 = new Array();
var Allmarker = new Array();
var cm_mapHTMLS = new Array();
function fnGetElement(strName,strType)
{
    if(strType=="ROOM")
    {
        strName= "ctl00$contentMain$ctl00$" + strName
    }
    else if(strType=="ROOM1")
    {
        strName= "ctl00$contentMain$ctl00$SearchHotelRoom1$" + strName
    }
    else if(strType=="ROOM2")
    {
        strName= "ctl00$contentMain$ctl00$SearchHotelRoom2$" + strName
    }
    else if(strType=="ROOM3")
    {
        strName= "ctl00$contentMain$ctl00$SearchHotelRoom3$" + strName
    }

    return document.getElementById(strName)
}

//fnSearch
var CheckinDate
var CheckOutDate
function fnHotelSearch(channelName, wsPrefix, src)
{
    var boolReply = true
    if(src == "M")
    {
        strCity = document.getElementById("ctl00_contentMain_Modify_txtHTCity").value
        strCompCode = document.getElementById("ctl00_contentMain_Modify_hndCompCode").value
        CheckinDate  = document.getElementById("ctl00_contentMain_Modify_txtHTCheckIn").value
        CheckOutDate  = document.getElementById("ctl00_contentMain_Modify_txtHTCheckOut").value
    }
    else
    {
        strCity = getElementWithSeparator("txtHTCity", true, "ctl00", "_").value
        strCompCode = getElementWithSeparator("hndCompCode", true, "ctl00", "_").value
        CheckinDate = getElementWithSeparator("txtHTCheckIn", true, "ctl00", "_").value
        CheckOutDate = getElementWithSeparator("txtHTCheckOut", true, "ctl00", "_").value
    }
    var strCity1 = strCity.replace(/ /g,'')
//    //debugger;
    if(strCity1=="" || strCity=="No Results")
    {
        boolReply=false
        alert("Invalid Departure or Arrival City. Please enter again.") //Invalid Departure or Arrival City. Please enter again.
    }
    if(boolReply)
    {
        var myDateIn = new Date(splitDateTime(CheckinDate)); 
        var myDateOut = new Date(splitDateTime(CheckOutDate)); 

        if(myDateIn > myDateOut)
        {
            boolReply=false
            alert("Please select valid dates. The checkout date should be later than the checkin date.")//Please select valid dates. The checkout date should be later than the checkin date.
        }
    }
    if(boolReply)
    {
        if (src != "TMFrame")
        {
        xmlHttp = new Ajax().GetXmlHttpObject();
        var xmldom=new Ajax().GetXmlHttpObject();
            if (xmlHttp)
            {
                 try
                 {
                       var arrCity = strCity1.split('(');
                       var arrCity1 = arrCity[1].split(')');
                       strCity= arrCity1[0];
                       boolReply=true
                 }
                 catch(ex)
                 {
                        boolReply=false
                        if (navigator.userAgent.indexOf("Opera") == -1)
                        {
                            alert("Invalid Departure or Arrival City. Please enter again.")//Invalid Departure or Arrival City. Please enter again.
                        }
                 }
            }
       }
    }
    if (boolReply==false)
    {     
        return boolReply
    } 
    
    if (src == "TMFrame")
        {
        src = ""
        }
        document.aspnetForm.action= wsPrefix + "HotelResult.aspx?CityCode=" + strCity + "&src=" + src;
   try{
            var target = "";
            switch (channelName)
            {
                        case "online-dc":
                        case "online-sa":
                                    target = "_parent";
                                    break;
                        case "bo-dc":
                        case "bo-sa":
                                    //target = "frm2";
                                    target = "main";
                                    break;
                        case "subagent":
                                    target = "login";
                                    break;
            }

            if (target=="login")
            {
                 document.aspnetForm.target = "main";
            }
            else
            {
                 document.aspnetForm.target = target;
            }
           }
      catch(ex)
      {
      throw(ex);
      }
}

function splitDateTime(inputDate)
{
    var splitdate = inputDate.split('-');
    var strReturn = splitdate[1] + " " + splitdate[0] + ", " + splitdate[2];
    return strReturn;
}

function fnHoletDetails(userRef,iHotel,hotelIndex,hotelCode,roomIndex,roomCode,BoardBasisCode,type,Ratetype,RateIndex)
{
//    //debugger;
    if(type=='H' && iHotel!='')
    {
        var strRoomIndex;
        strRoomIndex='';
        _splitRT = document.getElementById("hndIndRateType" + iHotel).value.split('-')
        var intRateType = _splitRT[2]
        for(intCtr=1;intCtr<=3;intCtr++)
        {   
            if(Ratetype==2)
            {
                if(document.getElementById("hndPriceIndex_H" + iHotel + "_R" + intCtr + "_T" + intRateType)!=null)
                {
                    strRoomArr=(document.getElementById("hndPriceIndex_H" + iHotel + "_R" + intCtr + "_T" + intRateType).value).split("-")
                    RateIndex=strRoomArr[4]
                    strRoomIndex=strRoomArr[5]
                }
            }
            else
            {
                if(document.getElementById("hndPriceIndex_H" + iHotel + "_R" + intCtr + "_T" + intRateType)!=null)
                {
                    strRoomArr=(document.getElementById("hndPriceIndex_H" + iHotel + "_R" + intCtr + "_T" + intRateType).value).split("-")
                    RateIndex=strRoomArr[4]
                    if(strRoomIndex=='')
                        strRoomIndex=strRoomArr[5]
                    else
                        strRoomIndex=strRoomIndex+','+strRoomArr[5]
                }
            }
        }
        roomIndex=strRoomIndex
    }//type=='H'
    window.open("HotelDetails.aspx?Uref="+userRef+"&H_Index="+hotelIndex+"&Room="+roomCode+"&R_Index="+roomIndex+"&BoardBasisCode="+BoardBasisCode+"&Type="+type+"&Ratetype="+Ratetype+"&RateIndex="+RateIndex,"","location=0,scrollbars=1,width=700,height=600,toolbar=1");
}

function fnGetHotelDetails()
{
////debugger;
    var inputXML=document.getElementById("hdnInputHotelDetails").value;
    xmlHttp = new Ajax().GetXmlHttpObject();
    var xmldom=new Ajax().GetXmlHttpObject();
    if (xmlHttp)
    {
        var webServiceURL;

        webServiceURL="Validations.aspx?Validate=HotelFareDetails"
        xmlHttp.open("POST", webServiceURL, true);
        xmlHttp.onreadystatechange = fnFetchHotelFareResult;
 
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlHttp.send("strInputXML=" + inputXML);
    }
}

function fnFetchHotelFareResult()
{
   ////debugger;
    var fareType=document.getElementById("hdnInputFareType").value;
    var Printsupplierlogo;
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		if (xmlHttp.status == 200)
		{
			var strReply=xmlHttp.responseText
      xmlHtlResult = xu.LoadXMLString(strReply);
					
              hdnGoogleAPIKey=document.getElementById("hdnGoogleAPIKey").value;
            
                 
              if (document.getElementById("ctl00_contentMain_hdnPrintsupplierlogo") != "")
            {
             Printsupplierlogo = document.getElementById("hdnPrintsupplierlogo").value
            }
            if((strReply.indexOf("Error") == -1)&&(strReply != ""))
            {
               ////debugger;
                if(fareType=="NEGO")
                {
                 xu.AddParameter("Printsupplierlogo", Printsupplierlogo);
                strResult = xu.XSLTransform(xmlHtlResult, "../XSLT/HotelDetailsNego.xslt.ay", "html");
                }
                else
                {
									xu.AddParameter("hdnGoogleAPIKey", hdnGoogleAPIKey);
								  xu.AddParameter("decFormat", document.getElementById("ctl00_hdnRegionCode").value);
									if (dom.$("ctl00_hdnRegionCode").value == "AR")
                  {
                        xu.AddParameter("ArabCult", "true")
                  }
                 strResult = xu.XSLTransform(xmlHtlResult, "../XSLT/HotelDetails.xslt.ay", "html");
                }
                
                
                strResult = strResult.replace(/#####/g, '');
                strResult = strResult.replace(/##br##/g, '<br>');
                newrow = dom.InsertTableRow("tblResults",0)
                newCell = dom.InsertTableCell(newrow,0);
                newCell.innerHTML=strResult
                
                //This Code Is Done For Hitting To Google Map
                //********Start*********
               
                var hotelAddress;
                var CountryCode;
                var hdnGoogleAPIKey;
                               
                var Latti =xu.SelectNodeValue(xmlHtlResult,"/Hotels/HotelFeatures_Reply/Hotel/@Latitude"); 
                var Langi = xu.SelectNodeValue(xmlHtlResult,"/Hotels/HotelFeatures_Reply/Hotel/@Longitude"); 
                var HotelName=xu.SelectNodeValue(xmlHtlResult,"/Hotels/HotelFeatures_Reply/Hotel/@HNm"); 
                var hotelAddress=xu.SelectNodeValue(xmlHtlResult,"/Hotels/HotelFeatures_Reply/Hotel/@Address");                
                
                //hotelAddress=document.getElementById("hdnhotelAddress").value;
                CountryCode=document.getElementById("hdnCountryCode").value;
                hdnGoogleAPIKey=document.getElementById("hdnGoogleAPIKey").value;
                
                 //alert(hdnGoogleAPIKey);               
                if((Latti != "" && Langi != "" && hdnGoogleAPIKey !="") && (Latti != null && Langi != null && hdnGoogleAPIKey !=null))
                {
             
                 InitializeGMap(Latti, Langi,HotelName,hotelAddress,CountryCode);
                }
                else
                {
                document.getElementById("MapCanvas").style.display="none"
                }
                 //********End************
            }
            else
            {
                 newrow = dom.InsertTableRow("tblResults",0)
                newCell = dom.InsertTableCell(newrow,0);
                newCell.innerHTML="<html><body><table cellpadding=\"4\" cellspacing=\"0\" width=\"650px\" class=\"Popup\"><tr><th height=\"40px\" align=\"left\" >Hotel Details</th></tr><tr><td id=\"tdcancel\" runat=\"server\">The system could not fetch any hotel features/facilities for the selected hotel room type !!  If the problem persists for all hotel room types, please do contact the Site Administrator!!</td></tr></table></body></html>"
            }
            document.getElementById("divWait").style.visibility="hidden"
            document.getElementById("divWait").style.position="absolute"
            document.getElementById("divWait").innerHTML = ""
            document.getElementById("hdnInputHotelDetails").value=""
            
            if (document.getElementById("hdnType") != null)
             {
                 if(document.getElementById("hdnType").value == "H")
                  {
                        
                 
                        if (document.getElementById("tblRoomDetails") != null)
                            document.getElementById("tblRoomDetails").style.display="none"
                  }
             }
        }
    }
}


function fnOnerror(errImg,errId)
{
    if (typeof errImg == "undefined")
    {
        errImg = "img";
    }
    var y = document.getElementById(errImg+errId);
    if(y != null)
    {    
	y.src="../Images/imgna.jpg";	
    }
 
}
function addCommas(nStr)
{
    //Get Display format for hidden filed.
    var decSeparator = document.getElementById("ctl00_hdnDecSeparator").value;
    var numFormat = "";
    if(decSeparator == ",")
        numFormat = ".";
    else
        numFormat = ",";
    
    nStr += '';
    var x = nStr.split('.');
    var x1 = x[0];
    var x2 = x.length > 1 ? decSeparator + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1))
    {
        x1 = x1.replace(rgx, '$1' + numFormat + '$2');
    }
    return x1 + x2;
}
var prev_id=0;
function fnOnLoad(imgName,id)
{//alert(id);
   while(prev_id+1<id)
   {
      var search=prev_id+1;
      //logic
      var y = document.getElementById(imgName+search);
      if(y != null)
      {
      var imglength = y.fileSize;
	  if(imglength<1)
		{
		y.src="../Images/imgna.jpg";
		}
		prev_id++;
      }  
   }
    
    var y = document.getElementById(imgName+id);
    if(y != null)
    {
	var imglength = y.fileSize;
	if(imglength<1)
		{
		y.src="../Images/imgna.jpg";
		}
	prev_id=id;
    }
}

function fnFareBreakUp(HotelIndex,RoomType,iHotel)
{

var strSelectIndex = "";
   if(iHotel != undefined)
   {
    _splitRT = document.getElementById("hndIndRateType" + iHotel).value.split('-')
    var intRateType = _splitRT[2]
   if(_splitRT[1].toString() != '2')
   {
        var strSelectIndex, iRCnt, iSelRoom
        iSelRoom=""
        iRCnt=0
        
        for(intCtr=1;intCtr<=3;intCtr++)
        {   
           if(document.getElementById("hndPriceIndex_H" + iHotel + "_R" + intCtr + "_T" + intRateType)!=null)
            {
                iRCnt+=1
                strPrice=(document.getElementById("hndPriceIndex_H" + iHotel + "_R" + intCtr + "_T" + intRateType).value).split("-")
                if(iSelRoom == "")
                {
                    iSelRoom = parseFloat(strPrice[0])
                }
                else
                {
                    iSelRoom = iSelRoom + "," + parseFloat(strPrice[0])
                }
           }
        }
        strSelectIndex="H1[" + HotelIndex + "]-T" + _splitRT[1] + "[" + _splitRT[2] + "]-R" + iRCnt + "[" + iSelRoom + "]"
    }
    else
    {
        
        var strSelectIndex, iRCnt, iSelRoom
        iSelRoom=""
        iRCnt=0
        
        for(intCtr=1;intCtr<=3;intCtr++)
        {   
           if(document.getElementById("hndPriceIndex_H" + iHotel + "_R" + intCtr + "_T" + intRateType)!=null)
            {
                iRCnt+=1
                strPrice=(document.getElementById("hndPriceIndex_H" + iHotel + "_R" + intCtr + "_T" + intRateType).value).split("-")
                if(iSelRoom == "")
                {
                    iSelRoom = parseFloat(strPrice[0])
                }
                else
                {
                    iSelRoom = iSelRoom + "," + parseFloat(strPrice[0])
                }
           }
        }
        strSelectIndex="H1[" + HotelIndex + "]-T" + _splitRT[1] + "[" + _splitRT[2] + "]-R" + iRCnt + "[" + iSelRoom + "]"
    }
   }
   //debugger
  
  var url = "HotelFareBreakUp.aspx?HotelIndex="+HotelIndex+"&Index=" + strSelectIndex+"+&RoomType="+ RoomType
		url += "&SelCurr=" + currCode + "&CurrFactor=" + currFactor;
  window.open(url,"","scrollbars=yes,location=0,width=700,height=600,toolbar=yes");
}

//Additional parameter with SelRooms added. - AJ - 20/02/2009.
function fnCancellation(userRef, hotelIndex,roomIndex, selRooms, BoardBasisCode, Ratetype,RateIndex)
{

  window.open("HotelCancellationPolicy.aspx?Uref=" + userRef + "&H_Index=" + hotelIndex + "&R_Index=" + roomIndex + "&SelRooms=" + selRooms + "&BoardBasisCode=" + BoardBasisCode + "&Ratetype="+Ratetype+"&RateIndex="+RateIndex, "", "scrollbars=yes,location=0,width=700,height=600");
}


function fnGetCancellationDetails()
{
//  //debugger;
    var inputXML=document.getElementById("hdnInputCancellationDetails").value;
    var suppType =document.getElementById("hdnSupplierType").value;
    xmlHttp = new Ajax().GetXmlHttpObject();
    var xmldom= new Ajax().GetXmlHttpObject();
    if (xmlHttp)
    {
        var webServiceURL;

        webServiceURL="Validations.aspx?Validate=HotelCancellationDetails&suppType="+suppType
        xmlHttp.open("POST", webServiceURL, true);
        xmlHttp.onreadystatechange = fnFetchHotelCancellation;
 
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

        inputXML = encodeURIComponent(inputXML);
        
        xmlHttp.send("strInputXML=" + inputXML);
    }
}

function fnFetchHotelCancellation()
{
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		if (xmlHttp.status == 200)
		{
		
		      var strReply=xmlHttp.responseText
	        // xmlHtlResult = xu.LoadXMLString(strReply);
            if((strReply.indexOf("Error") == -1)&&(strReply != ""))
            {
               document.getElementById("tdcancel").innerHTML = strReply
            }
            else
            {
               document.getElementById("tdcancel").innerHTML = "Cancellation policy is not available."
            }
            document.getElementById("divWait").style.visibility="hidden"
            document.getElementById("divWait").style.position="absolute"
            document.getElementById("divWait").innerHTML = ""
             document.getElementById("divResults").style.display="block"
            document.getElementById("hdnInputCancellationDetails").value=""
            
           }
    }
}


function setHotelSearch()
{
////debugger
    document.getElementById("trChd1").style.display="none"; 
    if(document.getElementById("ctl00_contentMain_ctl00_ddlHTRooms").value == "1")
    {
        document.getElementById("trRoom2").style.display="none";
        document.getElementById("trRoom3").style.display="none";
        if (document.getElementById("ctl00_contentMain_ctl00_ddlChildRoom1").value != "0")
        {
            document.getElementById("trAge1").style.display="";   
            document.getElementById("trChd1").style.display=""; 
        }
        document.getElementById("trAge2").style.display="none";   
        document.getElementById("trAge3").style.display="none";   
    }
    if(document.getElementById("ctl00_contentMain_ctl00_ddlHTRooms").value == "2")
    {
        document.getElementById("trRoom2").style.display="";
        document.getElementById("trRoom3").style.display="none";
        if (document.getElementById("ctl00_contentMain_ctl00_ddlChildRoom1").value != "0")
        {
         document.getElementById("trAge1").style.display="";   
          document.getElementById("trChd1").style.display=""; 
        }
        if (document.getElementById("ctl00_contentMain_ctl00_ddlChildRoom2").value != "0")
        {
         document.getElementById("trAge2").style.display=""; 
          document.getElementById("trChd1").style.display="";   
        }
        document.getElementById("trAge3").style.display="none";   
    }
    if(document.getElementById("ctl00_contentMain_ctl00_ddlHTRooms").value == "3")
    {
        document.getElementById("trRoom2").style.display="";
        document.getElementById("trRoom3").style.display="";
        if (document.getElementById("ctl00_contentMain_ctl00_ddlChildRoom1").value != "0")
        {
          document.getElementById("trAge1").style.display="";   
           document.getElementById("trChd1").style.display=""; 
        }
        if (document.getElementById("ctl00_contentMain_ctl00_ddlChildRoom2").value != "0")
        {
            document.getElementById("trAge2").style.display="";
             document.getElementById("trChd1").style.display="";    
        }
        if (document.getElementById("ctl00_contentMain_ctl00_ddlChildRoom3").value != "0")
        {
            document.getElementById("trAge3").style.display="";  
             document.getElementById("trChd1").style.display="";  
        }
    }
}

function setChildDdlModifySearch(child)
{  
       
    var maxChildren = GetMaxChildren();
    SetLabelVisibility(maxChildren);

    var NoOfChild = document.getElementById("ctl00_contentMain_ctl00_ddlChildRoom" + child).value
    document.getElementById("trChd1").style.display=""; 
    if (NoOfChild == "0")
    {
        setHotelSearch();
        document.getElementById("trAge" + child).style.display="none";   
    }
    else
    {
				document.getElementById("trChildLabels").style.display = "";
        if(child == "1")
        {
         document.getElementById("trAge1").style.display="";    
        }
        if(child == "2")
        {
         document.getElementById("trAge2").style.display="";    
        }
        if(child == "3")
        {
         document.getElementById("trAge3").style.display="";    
        }
    }
      
    document.getElementById("ctl00_contentMain_ctl00_span" + child).style.visibility="visible";
    if(NoOfChild == "0")
    {
        document.getElementById("ctl00_contentMain_ctl00_span" + child).style.visibility="hidden";
    }
    for(var _i=1;_i<= NoOfChild; _i++)
    {
        var childId = "ctl00_contentMain_ctl00_ddlAgeChild" + child + "_" + _i
        document.getElementById(childId).style.visibility="visible";
    }   
    if(NoOfChild < 3)
    {
             var _i = 3 - NoOfChild
             for(var _ii=3;_ii> NoOfChild; _ii--)
             {
                var childId = "ctl00_contentMain_ctl00_ddlAgeChild" + child + "_" + _ii
                document.getElementById(childId).style.visibility="hidden";
             }   
    }
} 
    
    
    function GetMaxChildren()
    {
			var max = 0;
			for (var i = 1; i <= 3; i++)
			{
				var ddlName = "ddlChildRoom" + i;
				var ddlChildren = getDDLNameWithSeparator(ddlName, true, "ctl00", "_");
				
				// Check if this DDL is visible.
				var rowName = "trRoom" + i;
				var rowForRoom = document.getElementById(rowName);
				if ((rowForRoom.style.display == "block") || (rowForRoom.style.display == ""))
				{
					var value = document.getElementById(ddlChildren).value;
					if (max < value)
						max = value;
				}
			}
			return max;
    }
    
    function SetLabelVisibility(maxChildren)
    {
			maxChildren = parseInt(maxChildren);
			for (var i = 1; i <= maxChildren; i++)
			{
				var childLabel = document.getElementById("spanChild" + i);
				childLabel.style.visibility = "visible";
			}
			for (var i = (maxChildren + 1); i <= 3; i++)
			{
				var childLabel = document.getElementById("spanChild" + i);
				childLabel.style.visibility = "hidden";
			}			
    }
 
// ***************************  Supplement *******************************

function showTable()
{
var tr = document.getElementById("ctl00_contentMain_Basket1_trFeature")
if(tr.style.display == "none")
 {
 tr.style.display = "block"; 
 document.getElementById("ctl00_contentMain_Basket1_tdCancel").innerText = "-  Cancellation Policy";
 }
 else
 {
 tr.style.display = "none";
 document.getElementById("ctl00_contentMain_Basket1_tdCancel").innerText = "+  Cancellation Policy"
 }
}
function PriceCalculate(roomPos,rowCount,Type,Unit,optionalcode,decimalPref)
{
//debugger
var _result
var _storPreValue
var _orgPreValue
if (document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex == '0')
{
 _storPreValue = replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type))
}
_orgPreValue = replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type))

if(Unit == 'Unit')
 { 
     if(document.getElementById("ctl00_contentMain_Basket1_radio"+roomPos+"_"+rowCount+"_"+Type).checked)
    {
      if (document.getElementById("ctl00_contentMain_Basket1_hndShowDecimal").value>0)
      {
      if(optionalcode!="True")
        {  
        document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML = addCommas((document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * (parseFloat(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Tax"+roomPos+"_"+rowCount+"_"+Type)))+parseFloat(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type))))).toFixed(decimalPref))
        }
        else
        {
            document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML = addCommas((document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * (parseFloat(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Tax"+roomPos+"_"+rowCount+"_"+Type)))+parseFloat(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type))))).toFixed(decimalPref)) +"   paid at hotel"
        }
      }
      else
      {
        if(optionalcode!="True")
        {  
        document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML = addCommas(Math.round(document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * (Math.round(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Tax"+roomPos+"_"+rowCount+"_"+Type)))+Math.round(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type))))))
        }
        else
        {
            document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML = addCommas(Math.round(document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * (Math.round(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Tax"+roomPos+"_"+rowCount+"_"+Type)))+Math.round(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type)))))) +"   paid at hotel"
        }
      }
        
       // alert(addCommas(Math.round(document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * (Math.round(document.getElementById("ctl00_contentMain_Basket1_Tax"+roomPos+"_"+rowCount+"_"+Type).outerText.replace(/,/g,''))+Math.round(document.getElementById("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type).outerText.replace(/,/g,''))))))  
      var _split = replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_mainCost")) 
      var _splitTPrice = replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type))
     
      if(document.getElementById("ctl00_contentMain_Basket1_radio"+roomPos+"_"+rowCount+"_"+Type).checked == true)
        {
        //_result = parseFloat(_split) + parseFloat(_splitTPrice)
         if(optionalcode!="True")
        {    
           if (_storPreValue != null)
           {
           _result = parseFloat(_split) - parseFloat(_storPreValue)
           }
           else
           {
            _result = parseFloat(_split) + parseFloat(_splitTPrice) - parseFloat(_orgPreValue)
           }
           if (document.getElementById("ctl00_contentMain_Basket1_hndShowDecimal").value >0)
            {
            //alert(_result);
                document.getElementById("ctl00_contentMain_Basket1_mainCost").innerHTML =  addCommas(parseFloat(_result).toFixed(decimalPref))
            }
           else
            {
                document.getElementById("ctl00_contentMain_Basket1_mainCost").innerHTML =  addCommas(Math.round(parseFloat(_result),2))
            }
            if(optionalcode!="True")
            {    
          setSupplementCost();
            }
         }
        }
        else
        {
        //set the price as 0
        if(optionalcode=="False")
        document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML = "0"
        else
         document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML = "0" +"   paid at hotel"
        _result = parseFloat(_split) - parseFloat(_storPreValue)
       
           if (document.getElementById("ctl00_contentMain_Basket1_hndShowDecimal").value >0)
                document.getElementById("ctl00_contentMain_Basket1_mainCost").innerHTML = addCommas(parseFloat(_result).toFixed(decimalPref))
           else
               document.getElementById("ctl00_contentMain_Basket1_mainCost").innerHTML = addCommas(parseFloat(_result))
          
          if(optionalcode!="True")
            {    
          setSupplementCost();
            }
        }
     }
  }
  else
  {
     if (document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex != 0)
   {
        if(optionalcode!="True")
        {    
       if (document.getElementById("ctl00_contentMain_Basket1_hndShowDecimal").value >0)
            document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML =addCommas((document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * (parseFloat(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Tax"+roomPos+"_"+rowCount+"_"+Type)))+parseFloat(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type))))).toFixed(decimalPref)) //addCommas(Math.round(parseFloat(document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * document.getElementById("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type).outerText.replace(/,/g,''))))
       else
           document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML =addCommas(Math.round(document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * (Math.round(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Tax"+roomPos+"_"+rowCount+"_"+Type)))+Math.round(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type)))))) //addCommas(Math.round(parseFloat(document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * document.getElementById("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type).outerText.replace(/,/g,''))))
          }
          else
          {
            if (document.getElementById("ctl00_contentMain_Basket1_hndShowDecimal").value >0)
            document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML =addCommas((document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * (parseFloat(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Tax"+roomPos+"_"+rowCount+"_"+Type)))+parseFloat(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type))))).toFixed(decimalPref)) +"   paid at hotel"//addCommas(Math.round(parseFloat(document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * document.getElementById("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type).outerText.replace(/,/g,''))))
       else
           document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML =addCommas(Math.round(document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * (Math.round(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Tax"+roomPos+"_"+rowCount+"_"+Type)))+Math.round(replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type)))))) +"   paid at hotel" //addCommas(Math.round(parseFloat(document.getElementById("ctl00_contentMain_Basket1_Units"+roomPos+"_"+rowCount+"_"+Type).selectedIndex * document.getElementById("ctl00_contentMain_Basket1_Cost"+roomPos+"_"+rowCount+"_"+Type).outerText.replace(/,/g,''))))
          }
               
          }     
      var _split = replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_mainCost"))
      var _splitTPrice = replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type))
     
      if(document.getElementById("ctl00_contentMain_Basket1_radio"+roomPos+"_"+rowCount+"_"+Type).checked == true)
        {
        ////debugger
         if(optionalcode!="True")
          {    
         if (_storPreValue != null)
           {
           _result = parseFloat(_split) - parseFloat(_storPreValue)
           }
           else
           {
            _result = parseFloat(_split) + parseFloat(_splitTPrice)
           }
          if (document.getElementById("ctl00_contentMain_Basket1_hndShowDecimal").value >0)
              document.getElementById("ctl00_contentMain_Basket1_mainCost").innerHTML = addCommas(parseFloat(_result).toFixed(decimalPref))
          else
              document.getElementById("ctl00_contentMain_Basket1_mainCost").innerHTML = addCommas(Math.round(parseFloat(_result),2))
              
           if(optionalcode!="True")
            {    
           setSupplementCost();
            }
           }
         }
        else
        {
        // set the price as 0
        if(optionalcode!="True")
        document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML = "0"
        else
         document.getElementById("ctl00_contentMain_Basket1_TPrice"+roomPos+"_"+rowCount+"_"+Type).innerHTML = "0" +"   paid at hotel"
        _result = parseFloat(_split) - parseFloat(_orgPreValue)
          if (document.getElementById("ctl00_contentMain_Basket1_hndShowDecimal").value == "true")
              document.getElementById("ctl00_contentMain_Basket1_mainCost").innerHTML = addCommas(parseFloat(_result).toFixed(decimalPref))
          else
              document.getElementById("ctl00_contentMain_Basket1_mainCost").innerHTML = addCommas(Math.round(parseFloat(_result),2))
              
          if(optionalcode!="True")
            {    
           setSupplementCost();
        }
   }
  }
}

function setSupplementCost()
{
  //Changes Done by Vikash for Supplement  Purpose
  //04/feb/2011
    debugger;
    var mainCost = replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_Basket1_mainCost")) 
    var hdnItineraryFare = replaceSeparator(document.getElementById("ctl00_contentMain_Basket1_hdnItineraryFare").value) 
    var bDecimal = replaceSeparator(document.getElementById("ctl00_contentMain_chargesDelOnly_hdnDecimalPreference").value);
    var totItineraryFare = replaceSeparator(document.getElementById("ctl00_contentMain_Basket1_hndNetAmount").value);
    var lblItineraryFare = document.getElementById("ctl00_contentMain_Basket1_lblNetTotal")
    var htotal = replaceSeparator(document.getElementById("ctl00_contentMain_Basket1_hdntemp").value)
    var fareCurrency = document.getElementById("ctl00_contentMain_Basket1_hdnFareCurrency").value;
    var delChargeAmt; 
    var totPrice ="";
  if(document.getElementById("ctl00_contentMain_chargesDelOnly_hdnDelCharge")!=null)
  {
    delChargeAmt = document.getElementById("ctl00_contentMain_chargesDelOnly_hdnDelCharge").value
  }
  else
  {
      if (dom.GetElementInnerText("ctl00_contentMain_chargesDelOnly_lblDel0") == null)
      {
        delChargeAmt = replaceSeparator("0")
      }
      else
      {
        delChargeAmt = replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_chargesDelOnly_lblDel0"))
      }
  }
  document.getElementById("ctl00_contentMain_Basket1_hdnItineraryFare").value = addCommas(parseFloat(hdnItineraryFare) + (parseFloat(mainCost) - (parseFloat(hdnItineraryFare))))
 if (bDecimal >0)
  {
    totPrice += addCommas((parseFloat(delChargeAmt)+ parseFloat(totItineraryFare) + (parseFloat(mainCost) - (parseFloat(hdnItineraryFare)))).toFixed(bDecimal).toString());
    document.getElementById("ctl00_contentMain_Basket1_hndNetAmount").value=parseFloat(replaceSeparator(totPrice)) - delChargeAmt
    totPrice = fareCurrency + " " + totPrice;
    dom.SetElementInnerText(lblItineraryFare,totPrice);
  }
  else
  {
    totPrice += addCommas(parseFloat(Math.round(delChargeAmt))+ parseFloat(totItineraryFare) + (parseFloat(mainCost) - (parseFloat(hdnItineraryFare))))
    //mainCost-hdnItineraryFare
    document.getElementById("ctl00_contentMain_Basket1_hndNetAmount").value=parseFloat(replaceSeparator(totPrice)) - delChargeAmt
    totPrice = fareCurrency + " " + totPrice;
    dom.SetElementInnerText(lblItineraryFare,totPrice);
  }
}

function setSupplementValues()
{
    if (document.getElementById("ctl00_contentMain_Basket1_hdnShowSupplements") != null)
    {
        if (document.getElementById("ctl00_contentMain_Basket1_hdnShowSupplements").value == "True")
        {
            if(document.getElementById("ctl00_contentMain_Basket1_tdGrandTotal") != null)
                {
                document.getElementById("ctl00_contentMain_Basket1_tdGrandTotal").innerHTML = "<b>Total Amount for Stay</b>";
                }
        }
    }
    //set the first value into total price for calculating del. type.
      var bDecimal = dom.$("ctl00_contentMain_chargesDelOnly_hdnDecimalPreference").value;
     
      var totItineraryFare = replaceSeparator(dom.$("ctl00_contentMain_Basket1_hdnItineraryFare").value)
      var fareCurrency = dom.$("ctl00_contentMain_Basket1_hdnFareCurrency").value;
      var delChargeAmt 
      if (dom.GetElementInnerText("ctl00_contentMain_chargesDelOnly_lblDel0") == null)
      {
        delChargeAmt = replaceSeparator("0")
      }
      else
      {
        delChargeAmt = replaceSeparator(dom.GetElementInnerText("ctl00_contentMain_chargesDelOnly_lblDel0"))
      }
  
      var lblItineraryFare;
      var totPrice = "";
    
      if(document.getElementById("ctl00_contentMain_Basket1_mainCost") != null)
      {
        lblItineraryFare = document.getElementById("ctl00_contentMain_Basket1_mainCost")
      }
      else
      {
        lblItineraryFare = document.getElementById("ctl00_contentMain_Basket1_TotalRoomPrice")
        totPrice = fareCurrency + " ";
      }
        
      if (bDecimal == "True")
      {
        totPrice += (parseFloat(delChargeAmt)+ parseFloat(totItineraryFare)).toFixed(decimalPref).toString();
        dom.SetElementInnerText(lblItineraryFare,addCommas(totPrice));
      }
      else
      {
        totPrice += parseFloat(Math.round(delChargeAmt))+ parseFloat(totItineraryFare)
        dom.SetElementInnerText(lblItineraryFare,addCommas(totPrice));
      }
}
function trim(s)
{
	return s.replace(/^\s+|\s+$/g,"");
}
function showHideNett(inputPos)
{
    if(document.getElementById('spnAgentCost'+inputPos) != null)
    {
        if(document.getElementById('a'+inputPos).innerHTML=="+")
        {
            document.getElementById('a'+inputPos).innerHTML = "-";
            document.getElementById('spnAgentCost'+inputPos).style.visibility = "visible";
        }
        else
        {
            document.getElementById('a'+inputPos).innerHTML = "+";
            document.getElementById('spnAgentCost'+inputPos).style.visibility = "hidden";
        }
    }
}
function fnUpdateMarkUp(index)
{
//    //debugger;
    window.open("HotelMarkUp.aspx?index="+index,"","scrollbars=yes,location=0,width=650,height=275");
}

var chngeTd ="false";
function changeTdColor(control1,e)
{
    if((control1.style.backgroundColor == "#f1f3f8")|| (control1.style.backgroundColor == "rgb(241, 243, 248)"))
    {
        control1.style.backgroundColor="#2491ff";
        chngeTd = "true";
    }
    else
    {
        control1.style.backgroundColor="#2491ff";
        chngeTd = "false";
    }
}
function changeTdOutColor(control,evt)
{
    if(chngeTd == "true")
    {
        control.style.backgroundColor = "#f1f3f8";
    }
}
  
   


var argg;
var argg1;
var map = null;
  	
function HotelArrey(HotelList)
{
    argg = new Array();
    argg1 = new Array();
    
    argg= HotelList.split('|');
    var canvas = document.getElementById("map");
    map = new GMap2(canvas);

	var j=0;
    for (i = 0; i < (argg.length)-1; i++) 
    {
        argg1= argg[i].split('##');
        if(i == (argg.length)-2)
            new LoadHotelDetail(argg[i],j,j)
        else
            new LoadHotelDetail(argg[i],j,(argg.length)-1)
        j++;
    }
} 


function LoadHotelDetail(HotelDetail,i,Size)
{
        argg1= HotelDetail.split('##');
        map.setCenter(new GLatLng(argg1[0], argg1[1]), 17-5);
        InitializeGMap1(argg1[0],argg1[1],argg1[2],argg1[3],argg1[4],argg1[5],i,Size,argg1[6],argg1[7],argg1[8],argg1[9],argg1[10],argg1[11])
} 
function InitializeGMap1(latitude,longitude,HotelName,address,HotelImage,Des,i,Size,Star,TGHotel,HIndex,NodeCount,Currency,startposition)
{
    new ShowGMap1(address,HotelName,latitude,longitude,HotelImage,Des,i,Size,Star,TGHotel,HIndex,NodeCount,Currency,startposition);
}

 
function ShowGMap1(address,HotelName,latitude,longitude,HotelImage,Des,i,Size,Star,TGHotel,HIndex,NodeCount,Currency,startposition)
{
    var pointer = new GLatLng(parseFloat(latitude), parseFloat(longitude));
    // map.centerCross = true;
    map.enableDoubleClickZoom();
    scripts[i]=createMarker(latitude,longitude,HotelName,address,Des,HotelImage,Star,TGHotel,HIndex,NodeCount,Currency,startposition)
    Allmarker[NodeCount] = scripts[i];
    if(i==Size)
    {         
      for (j = 0; j <= scripts.length -1; j++) 
      {
        map.addOverlay(scripts[j]); 
      }
      map.addControl(new GLargeMapControl()); 
      map.addControl(new GScaleControl()); 
      map.addControl(new GMapTypeControl()); 
    }
}


function createMarker(latitude,longitude,HotelName,address,Des,HotelImage,Star,TGHotel,HIndex,NodeCount,Currency,startposition)
{ 
    var icon = new GIcon();
    icon.image = "../Images/marker1.png"; //'http://gmaps-samples.googlecode.com/svn/trunk/markers/circular/greencirclemarker.png';
    icon.iconSize = new GSize(32, 32);
    icon.iconAnchor = new GPoint(16, 16);
    icon.infoWindowAnchor = new GPoint(25, 7);

        opts = { 
          "icon": icon,
          "clickable": true,
          "title": HotelName.toString(),
          "labelText": (parseInt(NodeCount)+parseInt(startposition)).toString(),
          "labelOffset": new GSize(-6, -10)
        };
    var point = new GLatLng(parseFloat(latitude), parseFloat(longitude));
	var marker = new LabeledMarker(point, opts);
	if(Des.length >130)
	{
	    Des = Des.substring(0,130) + "...";
	}
	var showTGHotel;
	if (decimalPref == "0")
	{
	     showTGHotel= addCommas(Math.round(TGHotel))
	}
	else
	{
	     showTGHotel= addCommas(parseFloat(TGHotel).toFixed(decimalPref))
	}
	var html='<div>'+
        '<table border="0" cellpadding="1" cellspacing="0" style="width: 245px; height: 100px;vertical-align:top">'+
       '<tr><td colspan="2"><span style="font-family: tahoma; font-weight:bold; font-size:16px; color:#1f5a97">'+HotelName+'</span><br /><span class="ProductRating">'+Star+'</span></td></tr>'+
        '<tr>'+
        '<td style="width:32%"><img id="img'+ NodeCount +'" src='+HotelImage+' onerror="javascript:fnOnerror(img,'+ NodeCount +');" width="100" height="80" /></td>'+
        '<td style="padding-right:0px;height: 20px" valign="top" align="right"><span class="ProductName" style="color:#1f5a97;">'+Currency+'&nbsp;'+showTGHotel+'</span>'+
        '<br/><span class="Desc" style="font-size: x-small; color:#1f5a97; font-weight:normal;">TOTAL PRICE</span>'+
        '<br/><br/><br/><strong><a class="BtnContinue" onclick="javascript:fnContinue('+NodeCount+','+HIndex+')"><span name="book">Book Now</span></a></strong></td>'+
        '</tr>'+
        '<tr>'+
        '<td colspan="2">'+
        '<table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">'+
        '<tr>'+
        '<td><span style="font-size: 10px; font-weight:normal;">'+Des+'</span></td>'+
        '</tr>'+
        '</table>'+
        '</td>'+
        '</tr>'+
        '</table></div>';

    cm_mapHTMLS[NodeCount] = html;
    GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
    GEvent.addListener(marker, "mouseover", function() {
        marker.setImage('../Images/marker2.png');
      });

    GEvent.addListener(marker, "mouseout", function() {
        marker.setImage('../Images/marker1.png');
      });

    GEvent.addListener(marker, "infowindowclose", function() {
        marker.setImage('../Images/marker1.png');
      });
  return marker; 
} 

 function CloseMe()
{
   document.getElementById("pdmarkerwork").style.display ="none";
}

function BLoadHotelResult()
{
   ////debugger
    window.location.href = 'HotelResult.aspx?HHLBackButton=True';//+iHotel;
}

function LoadHotelResult (filename)
{
    //debugger
    var Findex = document.getElementById("ctl00_contentMain_Basket1_hdnFlightindex").value
    window.location.href = 'DynamicResult.aspx?DynamicHit=CAHR&IsHotel='+Findex;
}
