/********************************************/
/***** hotelcommonV2.js Code start here *****/
/********************************************/
/******************************************************************************
 * File name:hotelcommon.js
 * Description: This file contains all the validation and javascript functions
 *				related to Hotel UI
 *******************************************************************************/
var IE = document.all?true:false
//if (!IE) document.captureEvents(Event.MOUSEMOVE)
//document.onmousemove = getMouseXY;
//var tempX = 0;
//var tempY = 0; 
var mapViewwindow;
var loadimages=new Array();
 /***********************************************************************
 * Function Name : showpopup
 * Description   : To display popup for checkin checout dates
 * Arguments     : None
 * Return values : popup window
 ***********************************************************************/
function showpopup(){
	document.getElementById('detailspopup').style.display='';
	var details='<div class="mainblock" style="z-index:1003;"><table width="190" border="0" cellspacing="0" cellpadding="0"><tr><td></td><td colspan="2" class="topbg"><table width="180" border="0" align="right" cellpadding="0" cellspacing="0"><tr><td width="15">&nbsp;</td><td width="151" class="number">Booking Details </td><td width="24"><a href=javascript:closepopup();><img src="http://video.tv18online.com/general/ytrimg/images/xhotelv2/closesign.gif" border="0" width="14" height="25" /></a></td></tr></table></td></tr><tr><td width="21" align="right" valign="top" style="padding-top:30px"><img src="http://video.tv18online.com/general/ytrimg/images/xhotelv2/popuparrow.gif" width="20" height="25" /></td><td width="6" style="background-color:#ffffff;"><img src="http://video.tv18online.com/general/ytrimg/images/xhotelv2/leftline.gif" width="1" height="131" /></td><td width="185" class="leftright"><form name="hotelDetails" method="get" style="margin:0px;"><table width="100%" height="131" border="0" align="left" cellpadding="0" cellspacing="0" style="background-color:#ffffff;"><tr><td width="35%" class="bodytext">Check-in</td><td align="left" width="14%"><select id="chiDate" name="chiDate" size="1"><option value="">dd</option><option value="01">01</option><option value="02">02</option><option value="03">03</option><option value="04">04</option><option value="05">05</option><option value="06">06</option><option value="07">07</option><option value="08">08</option><option value="09">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option></select></td><td align="left"><select id="chiMonthYear" name="chiMonthYear"><option value="">mm/yy</option><option value="03/2008">March 08</option><option value="04/2008">April 08</option><option value="05/2008">May 08</option><option value="06/2008">June 08</option><option value="07/2008">July 08</option><option value="03/2008">Mar 08</option><option value="04/2008">Apr 08</option><option value="05/2008">May 08</option><option value="08/2008">Aug 08</option><option value="09/2008">Sept 08</option><option value="10/2008">Oct 08</option><option value="11/2008">Nov 08</option><option value="10/2008">Oct 08</option><option value="10/2008">Nov 08</option><option value="11/2008">Dec 08</option><option value="12/2008">Sep 08</option></select></td></tr><tr><td class="bodytext">Check-out</td><td align="left" width="14%"><select id="choDate" name="choDate" size="1"><option value="">dd</option><option value="01">01</option><option value="02">02</option><option value="03">03</option><option value="04">04</option><option value="05">05</option><option value="06">06</option><option value="07">07</option><option value="08">08</option><option value="09">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option></select></td><td align="left"><select id="choMonthYear" name="choMonthYear"><option value="">mm/yy</option><option value="10/2007">Oct 07</option><option value="11/2007">Nov 07</option><option value="12/2007">Dec 07</option><option value="01/2008">Jan 08</option><option value="02/2008">Feb 08</option><option value="03/2008">Mar 08</option><option value="04/2008">Apr 08</option><option value="05/2008">May 08</option><option value="06/2008">Jun 08</option><option value="07/2008">Jul 08</option><option value="08/2008">Aug 08</option><option value="09/2008">Sep 08</option><option value="10/2008">Oct 08</option><option value="10/2008">Nov 08</option><option value="11/2008">Dec 08</option><option value="12/2008">Sep 08</option></select></td></tr></form><tr><td colspan="3" align="center" class="findflight"><input type="image" src="http://video.tv18online.com/general/ytrimg/images/xhotelv2/findhotel.gif" id="hotelform" onclick=go_detail("hotelDetails"); /></td></tr></table></td></tr><tr><td colspan="3" valign="top"><img src="http://video.tv18online.com/general/ytrimg/images/xhotelv2/bottomline.gif" width="211" height="5" /></td></tr></table></div>';
	document.getElementById('detailspopup').innerHTML=details;
	document.getElementById('detailspopup').style.top=(tempY-250)+'px';
	document.getElementById('detailspopup').style.left=(tempX-230) +'px';
}
 /***********************************************************************
 * Function Name : closepopup
 * Description   :Close the pop up window
 * Arguments     : None
 * Return values : 
 ***********************************************************************/
function closepopup(){
	//document.getElementById('hoteldetailspopup').style.display='none';
	//document.getElementById('overeffect').style.display='none';
	document.getElementById('HADT').style.display='';
	document.getElementById('HCHD').style.display='';
	document.getElementById('HRM').style.display='';	
	document.getElementById('HPR').style.display='';
	document.getElementById('HHN').style.display='';
	document.getElementById('HHT').style.display='';
	
}
/*function getMouseXY(e) {
  if (IE) {
     tempX = event.clientX + document.body.scrollLeft
     tempY = event.clientY + document.body.scrollTop
  } else {
    tempX = e.pageX
    tempY = e.pageY
  }
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  return true
}*/
function go_detail(formName,cinDate,codDate){
	var obDate=document.getElementById(cinDate).value;
	var ibDate=document.getElementById(codDate).value;	
	//call to isValidhotel function of isValidate.js for checkin and checkout date validation
	var isValid=isValidpopup(formName,obDate,ibDate);
if(document.getElementById('selectcity')){
	document.getElementById('selectcity').style.display='none';
}
	if(isValid==true){		
		//document.getElementById('hoteldetailspopup').style.display='';
		//document.getElementById('HADT').style.display='none';
		//document.getElementById('HCHD').style.display='none';
		//document.getElementById('HRM').style.display='none';
		//document.getElementById('HPR').style.display='none';
		//document.getElementById('HHN').style.display='none';
		//document.getElementById('HHT').style.display='none';		
		
	}else{		
		return false;
	}	
}
function openhoteldetails(){
		document.getElementById('overeffect').style.display='';
		document.getElementById('hoteldetailspopup').style.display='';
}
function hoteldetailsmenu(liName,divName){
        //set the continue booking button
        setContinueBookingButton(divName);
		setRaahiLogoImg(divName);
	for(i=1; i<=7; i++){
    	if(document.getElementById('hoteldetail'+i)){
			document.getElementById('hoteldetail'+i).className='';
	      	document.getElementById('detail'+i).style.display='none';
		}      
	}
    document.getElementById(liName).className='onmenu';
    document.getElementById(divName).style.display='';
    if(divName == 'detail5'){
		hotel_details_map();	
	}
   
}
function ShowSection(section){
	  //set the continue booking button
      setContinueBookingButton(section);
	  setRaahiLogoImg(section);
	var sectionID=new Array('detail1','detail2','detail3','detail4','detail5','detail6','detail7')
	for(i=0;i<sectionID.length; i++){
	if(document.getElementById(sectionID[i])){
		if(section==sectionID[i]){
			document.getElementById(sectionID[i]).style.display='block';
		if(sectionID[i] == 'detail5'){
			hotel_details_map();	
		}
		}else{
			document.getElementById(sectionID[i]).style.display='none';
		}
	}
  	}
}
function setImage(img,tdId){
    var idArr = new Array('d001img','d002img','d003img','d004img','d005img','d006img','d007img');
	var tdArr = new Array('t001','t002','t003','t004','t005','t006','t007');
	var imgOnArr = new Array('about_hotel_on_new','rate_details_on_new','photo_gallery_on_new','destination_guide_on_new','map_on_new','user_review_on_new','videos_on_new');
	var imgOffArr = new Array('about_hotel_off_new','rate_details_off_new','photo_gallery_off_new','destination_guide_off_new','map_off_new','user_review_off_new','videos_off_new');
        var len=idArr.length;
        for (var i=0; i<len; i++){
		if(document.getElementById(idArr[i]) && document.getElementById(tdArr[i])){
          if(idArr[i]==img && tdArr[i]==tdId){
			document.getElementById(idArr[i]).src='http://video.tv18online.com/general/ytrimg/images/xhotelv2/'+imgOnArr[i]+'.gif';
			document.getElementById(tdArr[i]).className='offborder';
			}else{
			document.getElementById(idArr[i]).src='http://video.tv18online.com/general/ytrimg/images/xhotelv2/'+imgOffArr[i]+'.gif';
			document.getElementById(tdArr[i]).className='onborder';
			}
		}
        }
}


/***********************************************************************
 * Function Name : GetXmlHttpObject
 * Description   : To create the xmlHttp request object used for ajax
 * Arguments     : None
 * Return values : None
 ***********************************************************************/
function GetXmlHttpObject()
{
    var objXMLHttp=null

    if(window.XMLHttpRequest) {
       try {
             objXMLHttp = new XMLHttpRequest();
           } catch(e) {
             objXMLHttp = false;
           }
    } else if(window.ActiveXObject) {
       try {
             objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
           } catch(e) {
             objXMLHttp = false;
           }
    }
    return objXMLHttp;
}

/***********************************************************************
 * Function Name :preloadimages
 * Description   :preload the images 
 * Arguments     : 
 * Return values : 
 ***********************************************************************/
function preloadimages(){
	for(i=0;i<preloadimages.arguments.length;i++){
		loadimages[i]=new Image();
		loadimages[i].src=preloadimages.arguments[i];
	}
}	
//Enter path of images to be preloaded inside parenthesis. Extend list as desired.
preloadimages(
			"http://video.tv18online.com/general/ytrimg/images/xhotelv2/city_markup/mumbai-bullet.gif",
			"http://video.tv18online.com/general/ytrimg/images/xhotelv2/city_markup/chennai-bullet.gif",
			"http://video.tv18online.com/general/ytrimg/images/xhotelv2/city_markup/goa-bullet.gif",
			"http://video.tv18online.com/general/ytrimg/images/xhotelv2/city_markup/bangalore-bullet.gif",
			"http://video.tv18online.com/general/ytrimg/images/xhotelv2/city_markup/delhi-bullet.gif",
			"http://video.tv18online.com/general/ytrimg/images/xhotelv2/city_markup/jaipur-bullet.gif",
			"http://video.tv18online.com/general/ytrimg/images/xhotelv2/city_markup/kolkata-bullet.gif",
			"http://video.tv18online.com/general/ytrimg/images/xhotelv2/city_markup/hyderabad-bullet.gif"
			);


/***********************************************************************
 * Function Name :hideselect and showselect
 * Description   :When popup open hide all select box thats on page
 * Arguments     : 
 * Return values : 
 ***********************************************************************/
function hideselect(){
	 document.body.className='hideselectbox';
if(document.getElementById('rangeHandleMin0') && document.getElementById('rangeHandleMax0')){
	document.getElementById("rangeHandleMin0").style.display = "none";
	document.getElementById("rangeHandleMax0").style.display = "none";
}
	 //document.body.scroll = 'no';
	//if (IE) {
	//document.documentElement.style.overflow = "hidden";
	//}
 }
function showselect(){
	 document.body.className='';
if(document.getElementById('rangeHandleMin0') && document.getElementById('rangeHandleMax0')){
	 document.getElementById("rangeHandleMin0").style.display = "";
	document.getElementById("rangeHandleMax0").style.display = "";
}
	 //document.body.scroll = '';
	// if (IE) {
	//document.documentElement.style.overflow = "";
	// }
	if(document.getElementById('adzonediv')){
		document.getElementById('adzonediv').style.display='';
	}
 }






/*******************************************************************************
 * Function Name : uppercase_firstletter
 * Description   : To upper case the first character of each word in a string
 * Arguments     : str
 * Return values : string with upper case of firstcharacter of each word.
 ********************************************************************************/
function uppercase_firstletter(str) {
   // split string on spaces  
  var arrStr = str.split(" ");
   var strOut =''; 
   for (i=0;i<arrStr.length;i++)
   {
       // split string
       firstChar = arrStr[i].substring(0,1);
       remainChar = arrStr[i].substring(1);

       // convert case
       firstChar = firstChar.toUpperCase(); 
       remainChar = remainChar.toLowerCase();

       strOut += firstChar + remainChar + ' ';
   }
   // return string, but drop the last space
   return strOut.substring(0, strOut.length - 1);
}
/*******************************************************************************
 * Function Name : goback
 * Description   : back to previous page
 * Arguments     : 
 * Return values : 
 ********************************************************************************/
function goback(){
	history.go(-1);		
}
/*******************************************************************************
 * Function Name : Trim
 * Description   : trim the spaces
 * Arguments     : fld
 * Return values : 
 ********************************************************************************/
function Trim(fld)
{
        while(''+fld.charAt(0)==' ')
                fld=fld.substring(1,fld.length);
        while(''+fld.charAt(fld.length-1)==' ')
                fld=fld.substring(0,fld.length-1);
        while(''+fld.charCodeAt(0)==13 || ''+fld.charCodeAt(0)==10)
                fld=fld.substring(1,fld.length);
        while(''+fld.charCodeAt(fld.length-1)==13 || ''+fld.charCodeAt(fld.length-1)==10)
                fld=fld.substring(0,fld.length-1);
        return fld;
}
/*******************************************************************************
 * Function Name : open_mapview_popup
 * Description   : This function is use to open map dhtml popup
 * Arguments     : formname
 * Return values : 
 ********************************************************************************/
function open_mapview_popup(formName){
      	if(formName != ''){  
	    
		var ciDate = document.forms[""+formName].cidate.value;
		var coDate = document.forms[""+formName].codate.value;
		var room  = document.forms[""+formName].room.value;
        var cityName=document.forms[""+formName].city_name.value;
		
		var adt1, adt2, adt3, adt4, chdroom1, chdroom2, chdroom3, chdroom4;
		var adt1_chdage1, adt1_chdage2, adt2_chdage1, adt2_chdage2;
		var adt3_chdage1,adt3_chdage2, adt4_chdage1, adt4_chdage2;
		var dhtmlWindowObj='CityMap_'+Math.random();
        url="waitpages/waitpage_mapviewpopupV2.html?randomid="+Math.random()+"&cityname="+cityName;		
		url = url+'&cidate='+ciDate+'&codate='+coDate+'&room='+room+'&dhtmlWindowObj='+dhtmlWindowObj;
		//Get guest details for room1 
		adt1 = document.forms[""+formName].adt1.value; 
		chdroom1 = document.forms[""+formName].chdroom1.value;
		if(chdroom1 > 0){
			adt1_chdage1 = document.forms[""+formName].adt1_chdage1.value;
			adt1_chdage2 = document.forms[""+formName].adt1_chdage2.value;
		}

		// Get guest details for room2 
		adt2 = document.forms[""+formName].adt2.value;
		chdroom2 = document.forms[""+formName].chdroom2.value;
		if(chdroom2 > 0){
			adt2_chdage1 = document.forms[""+formName].adt2_chdage1.value;
			adt2_chdage2 = document.forms[""+formName].adt2_chdage2.value;
		}

		// Get guest details for room3
		adt3 = document.forms[""+formName].adt3.value;
		chdroom3 = document.forms[""+formName].chdroom3.value;
		if(chdroom3 > 0){
			adt3_chdage1 = document.forms[""+formName].adt3_chdage1.value;
			adt3_chdage2 = document.forms[""+formName].adt3_chdage2.value;
        	}
		//Get guest details for room4
        	adt4 = document.forms[""+formName].adt4.value;
        	chdroom4 = document.forms[""+formName].chdroom4.value;
        	if(chdroom4 > 0){
            		adt4_chdage1 = document.forms[""+formName].adt4_chdage1.value;
            		adt4_chdage2 = document.forms[""+formName].adt4_chdage2.value;
        	}        	
		url = url+'&adt1='+adt1+'&chdroom1='+chdroom1+'&adt1_chdage1='+adt1_chdage1+'&adt1_chdage2='+adt1_chdage2;
              if(room>1)
			url = url+'&adt2='+adt2+'&chdroom2='+chdroom2+'&adt2_chdage1='+adt2_chdage1+'&adt2_chdage2='+adt2_chdage2;
		if(room>2)
			url = url+'&adt3='+adt3+'&chdroom3='+chdroom3+'&adt3_chdage1='+adt3_chdage1+'&adt3_chdage2='+adt3_chdage2;
              if(room>3)	
			url = url+'&adt4='+adt4+'&chdroom4='+chdroom4+'&adt4_chdage1='+adt4_chdage1+'&adt4_chdage2='+adt4_chdage2;
		closessh_map();
                mapviewWindow=dhtmlmodal.open(dhtmlWindowObj, 'iframe', url, 'Yatra Hotels', 'width=810,height=530,left=200,center=1,resize=0,scrolling=0');
		//To hide the select boxes
		hideselect(); 
	if(document.getElementById('adzonediv')){
		document.getElementById('adzonediv').style.display='none';
	}
	}	
	return false;
}
function rating_info(){
	window.open('/HOTEL/hotel/govtratings.html','popup','scrollbars=0,width=370,height=160,top=150,left=400');

}

function show_circle(){
        hideselect();
        document.getElementById('overeffect').style.display="";
        document.getElementById('flashdiv').style.display="";
}

//Functions added for PEGASUS full room name popup
function getTop(obj)
{
	if ('string' == typeof obj)
	obj = document.getElementById(obj);
	var y = 0;
	while (obj != null)
	{
	y += obj.offsetTop;
	obj = obj.offsetParent;
	}
	return y;
}
function getLeft(obj)
{
	if ('string' == typeof obj)
	obj = document.getElementById(obj);
	var x = 0;
	while (obj != null)
	{
	x += obj.offsetLeft;
	obj = obj.offsetParent;
	}
	return x;
}
function fullnameClick(evt,roomId,roomName)
			{
			var Div=document.getElementById('fullroomName');
			Div.style.display='block';
			Div.style.top=getTop(roomId) +260+'px';
			document.getElementById('fullroomName').innerHTML=uppercase_firstletter(roomName);
			}
function fullnameCloseOut()
			{
				document.getElementById('fullroomName').style.display='none'
			}




/*****************************************/
/******** Ajax.js Code start here ********/
/*****************************************/
function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					
                                        this.xmlhttp.open("GET", this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}

/********************************************/