var allPos, topDivs, topLiS, overElm, last, fHotel, timeOutF;

function chSpam(This) {
  var r = Math.random(0,1);
  This.src = './secured/includes/captcha_gd.php?i='+r;	
}



/*_-----------------------------------------_*/
function belongsToWhich(elm) {
	 var bLongTo = '';
	 if ( topLiS.indexOf(elm.id) > -1 ) { bLongTo = elm.id; }
	 else { 
		 for (i = 0; i <topLiS.size(); i++ ) {
			if ( $(elm).descendantOf(topLiS[i]) ) {
			   bLongTo = topLiS[i];
			   break;
			}
		 }
	 }
	 return bLongTo;
}
/*---------------------------------------------------------------------------------------*/
function headerInfoPopUp() {
	 var allPos = [];
	 topLiS =  ['timeLi','weatherLi', 'currencyLi', 'transportLi'];
	 topDivs = ['timeDiv','weatherDiv','currencyDiv','transportDiv'];
	 var wE = {
			   fx: function(event) {
					 var elm = Event.element(event);
					 var bLongTo = belongsToWhich(elm);
					 if (bLongTo == '') {
						 topDivs.each(function(e){ if ( $(e).getStyle('display') == 'block' ) {new Effect.toggle($(e),'slide',{duration:0.2}); }}); 
					     return false;
					 }
					 //alert(bLongTo)
					 var div = bLongTo.replace('Li','Div');
					 if ( $(div).getStyle('display') == 'block' ) { return false;}
					 new  Effect.toggle($(div),'slide',{duration:0.4, afterUpdate:function(){
														for (i=0;i<topDivs.size();i++) {
						                                    if(topDivs[i] != last) { 
															    if ( $(topDivs[i]).getStyle('display') == 'block' )
																  new Effect.toggle($(topDivs[i]),'slide',{duration:0.2});
															}
					                                     }
													}}); 
					 last = div;
			      }
			 };
	wE.bfx = wE.fx.bindAsEventListener(wE);
	for (i = 0; i < topDivs.size(); i++ ) {
		allPos[i] = $(topLiS[i]).cumulativeOffset();
		$(topDivs[i]).setStyle({width:$(topLiS[i]).offsetWidth-1+'px',visibility:'visible',display:'block'});
		new Effect.toggle($(topDivs[i]),'slide',{duration:0.0});
	}
    
	var lis = $$('.infoAreaPop li');
	lis.each(function(e){
					   Event.observe(e, 'mouseover', (function(event){
															          var elm = Event.element(event);
															          $(elm).setStyle({backgroundColor:'#f1f2f3'});
																	  var aa = $(elm).getElementsByTagName('a'); 
																	  if (aa[0]) { $(aa[0]).setStyle({backgroundColor:'#f1f2f3'});}
															         })
									 );
					   Event.observe(e, 'mouseout', (function(event){
															      var elm = Event.element(event);$(elm).setStyle({backgroundColor:'#ffffff'});
																  var aa = $(elm).getElementsByTagName('a'); 
																  if (aa[0]) { $(aa[0]).setStyle({backgroundColor:'#ffffff'});}
															  })
									 );
					   
					  
					  });
	Event.observe(document, 'mouseover', wE.bfx); 
    b = (new Date()).getTime();
    taken = (b-a) + ' ms';
	//$('timeTaking').innerHTML += taken;  
	
	// play images featured
	 fHotel = new imagePlay('featuredHotelsCont', 'li', 'nxt', 'play', 1.5, 'top', 200, 'autoPlayF()', 'fSBHotel', 'timeOutF');
     Event.observe($('fPBHotel'), 'click', fHotel.playPrevious.bindAsEventListener(fHotel));  // play previous
     Event.observe($('fSBHotel'), 'click', fHotel.autoPlayPause.bindAsEventListener(fHotel));  // auto play or stop 
     Event.observe($('fNBHotel'), 'click', fHotel.playNext.bindAsEventListener(fHotel)); // play next
	 if ( navigator.appVersion.match("MSIE") )
	    correctPNG();
	 autoPlayF();
}
/*---------------------------------------------------------------------------------------*/
 var imagePlay = Class.create({
		   initialize:function(containerElm, tagNameToMove, stopCssClass, playCssClass, duration, moveTowards, howMuchMove, autoPlayFnName, autoPlayId, interValCont ) {
			   this.running = false;
			   this.containerElm = containerElm;
			   this.stopCssClass = stopCssClass;
			   this.playCssClass = playCssClass;
			   this.duration = duration;
			   this.moveTowards = moveTowards;
			   this.howMuchMove = howMuchMove;
			   this.autoPlayFnName = autoPlayFnName;
			   this.autoPlayId = autoPlayId;
			   this.intervalCont = interValCont;
			   this.tagNameToMove = tagNameToMove;
			   this.top = (moveTowards == 'top') ? (-1)*howMuchMove : 0;
			   this.left = (moveTowards == 'top') ? 0 : (-1)*howMuchMove;
		   },
		   playNext: function(event) {
			  if ( this.running) return false;
			  if ( typeof event == 'object' ) { 
			     clearInterval(eval(this.intervalCont)); 
				 $(this.autoPlayId).className = this.playCssClass;
			  }
			  else {
				 $(this.autoPlayId).className = this.stopCssClass;
			  }
			  this.running =  true;
			  new Effect.MoveBy($(this.containerElm), this.top, this.left, {duration:this.duration,elm:this, afterFinishInternal:function(){
									   This = this.elm;
									   This.running = false; 
									  // alert($(This.containerElm).firstDescendant().id)
									   $(This.containerElm).insert($(This.containerElm).firstDescendant()).setStyle({top:'0px',left:'0px'}); 
									 }});
		   },
		   playPrevious: function(event) {
			  if ( this.running ) return false;
			  if ( typeof event == 'object' ) { 
			     clearInterval(eval(this.intervalCont)); 
				 $(this.autoPlayId).className = this.playCssClass;
			  }
			  else {
				 $(this.autoPlayId).className = stopCssClass;
			  }
			  this.running = true;
			   elm = $A($(this.containerElm).getElementsByTagName(this.tagNameToMove)).compact().last();
			   $(this.containerElm).insertBefore($(elm),$(this.containerElm).firstDescendant());
			   $(this.containerElm).setStyle({top:this.top+'px',left:this.left+'px'});
			   new Effect.MoveBy($(this.containerElm), Math.abs(this.top), Math.abs(this.left),{duration:this.duration,elm:this,afterFinishInternal:function(){ 
									this.elm.running = false; $(this.elm.containerElm).setStyle({top:'0px',left:'0px'}); }});
		   },
		   autoPlayPause: function(event) {
			  var elm = Event.element(event);
			  clearInterval(eval(this.intervalCont)); 
			  $(elm).className = ($(elm).className == this.stopCssClass) ? this.playCssClass : this.stopCssClass;
			  if ( $(elm).className == this.stopCssClass) {  this.playNext(); eval(this.autoPlayFnName);  }
			   
		   }
  });


function autoPlayF() {
   if (timeOutF) clearInterval(timeOutF);
   timeOutF = setInterval("fHotel.playNext()",5000);
}

function saveForCompare(hotelId) {
   parms = 'hotelId='+hotelId;
   new Ajax.Request('./saveForCompare.php',{method:'get', parameters: parms, onComplete: function(OReq){alert(OReq.responseText);}});  
}
/*---------------------------------------------------------------------------------------*/

function getPageScroll(){
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
/*---------------------------------------------------------------------------------------*/
var a = (new Date()).getTime();
//document.observe('dom:loaded', headerInfoPopUp);
window.onload = headerInfoPopUp;
/*---------------------------------------------------------------------------------------*/
function printMap() {
	return false; 
}

function sendToMyFriends(This,type,id){
  if ($('sendFriends')) {$('sendFriends').remove();}
  overLayWholeDocs();
  popUp  = document.createElement('div');
  document.body.appendChild(popUp);
  popUp.id = 'sendFriends';
  pos = $(This).cumulativeOffset();
  popUp.setStyle({position:'absolute',top:pos[1]-240+'px',left:'250px',zIndex:1200});
  $(popUp).innerHTML = '<div class="box popup formArea pad" style="padding-top:10px;"><strong class="hdrtxt space2">Send To Your Friends</strong><span class="close"><a href="javascript:void(0);" onclick="javascript:closeOverLayF();">Close (X)</a></span><label>Your Name *</label><input type="text" class="txtType2 space2" name="sName" id="sName"><label>Your Email * </label><input type="text" class="txtType2 space2" name="sEmail" id="sEmail"><label>Your Friends Emails * [ use comma(,) for multiple address]</label><input type="text" class="txtType2 space2" name="fEmail" id="fEmail"><input type="hidden" name="eId" id="eId" value="'+id+'" /><input type="hidden" name="eType" id="eType" value="'+type+'" /><label>Your Comments *</label><textarea class="txtArea1 space" rows="7" cols="40" name="userComments" id="userComments"></textarea><input type="button" class="subbtn flspr" value="Submit" onclick="javascript:SendFriendsNow();" /><input type="button" class="subbtn" value="Cancel" onclick="javascript:closeOverLayF();" /></div>';
  $('sendFriends').scrollTo();
}
function closeOverLayF() {
  if ($('overlay')) { 
     new Effect.Fade('overlay', { duration: 0.5}); 
	  if ($('sendFriends')) { $('sendFriends').remove(); }
  }
}
function SendFriendsNow() {
  
  // check for empty
  if ( $('fEmail').value.blank() || $('userComments').value.blank() || $('sName').value.blank() || $('sEmail').value.blank()  ) {
     alert('Required Value Missing!!\n check and try again');
	 return false;
  }
   
  // check for email address
  var emailchar = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  if (!emailchar.test($('sEmail').value)) {
		 alert('seems your email address invalid!!\n check again and try.');return false;
  }
  emails = $('fEmail').value.split(',');
  for (i=0;i<emails.size();i++) { 
	  if (!emailchar.test(emails[i])) {
		 alert('seems one or more email address invalid!!\n check again and try.');return false;
	  }
  }

  
  var parms = 'sName='+encodeURIComponent($('sName').value)+'&sEmail='+$('sEmail').value+'&eId='+$('eId').value+'&eType='+$('eType').value+'&fEmail='+$('fEmail').value+'&userComments='+encodeURIComponent($('userComments').value)+'&wLink='+window.location.href;	
  new Ajax.Request('./SendFriend.php',{method:'post', parameters: parms, onComplete: function(OReq){
											alert(OReq.responseText=='success'?'Successfully Sent to your Friend(s)\n Thank You!!':'Try Later!!');
											closeOverLayF();
																			
					}});
} // end function




function openLinks(serviceName) {
 var serviceName = serviceName;
 var destinationUrl = '';
 var title = encodeURIComponent(document.title);
 var url = encodeURIComponent(window.location.href);
 if ( serviceName == 'myspace' ) {
	destinationUrl = 'http://www.myspace.com/Modules/PostTo/Pages/?u='+url+'&t='+title+'&c=';
 }
 else if ( serviceName == 'facebook' ) {
    destinationUrl = 'https://www.facebook.com/login.php?popup&next=http%253A%252F%252Fwww.facebook.com%252Fsharer.php%253Fu%253D'+url
 }
 else if ( serviceName == 'delicious' ) {
	destinationUrl = 'http://del.icio.us/post?url='+url+'&title='+title; 
 }
 else if ( serviceName == 'digg' ) {
	destinationUrl = 'http://digg.com/submit?phase=2&url='+url; 
 }
 else if ( serviceName == 'yahoo' ) {
	destinationUrl = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+url+'&t='+title;
 }
 else if ( serviceName == 'google' ) {
	destinationUrl = 'http://www.google.com/ig/add?feedurl='+url;
 }
 else if ( serviceName == 'technorati' ) {
	destinationUrl = 'http://technorati.com/faves?add='+url; 
 }
 //alert(destinationUrl);
 window.open(destinationUrl,"TripBD","scrollbars=yes,menubar=yes,width=620,height=500,resizable=yes,toolbar=no,location=no,status=yes");
 
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}



/*
var objD = $('dest');
function showSuggestions(event) {
	//find if any , in the text
	var comIn = objD.value.lastIndexOf(',');
	txt =  (comIn == -1) ? objD.value : objD.value.substr(comIn+1,objD.value.length);
	txt = txt.strip().toLowerCase();
	if (txt == '') return false;
	var atleastOneMatched = false;
	sg = '';
	for (i=0;i<dA.size();i++) {
	   if (dA[i].toLowerCase().startsWith(txt)){
		  sg += '<li><a id="sgId_'+i+'" href="javascript:void(0);" onclick="javascript:updateText('+i+','+comIn+');">'+dA[i]+'</a></li>';
		  atleastOneMatched = true;
	   }
	}
	if (atleastOneMatched) {  //  match so show the list
	    $('sList').update(sg);
	    var posX = Event.pointerX(event);
	    var posY = Event.pointerY(event);
	    pos = $('dest').cumulativeOffset();
		var leftPos = topPos = 0;
		topPos =  (parseInt(($('dest').value.length) / 85)+1) * 20;
		//alert(($('dest').value.length) % 96)
		//topPos = (topPos == 0) ? 20 : topPos;
		
		factor = 6;
		topPos = pos[1]+topPos;
		leftPos = ($('dest').value.length * 7);
		if ( leftPos > 470 ) leftPos = 5;
		leftPos = pos[0] + leftPos;
		$('sugBox').setStyle({position:'absolute',top:topPos+'px',left:leftPos+'px',zIndex:1200,border:'1px solid #cccccc',background:'#ffffff'}).show();
	}
	else{
	 	$('sList').update('');
	    $('sugBox').hide();
	}
}
function createSuggBox(event) {
  d  = document.createElement('div');
  document.body.appendChild(d);
  d.id = 'sugBox';
  $(d).update('<ul id="sList"></ul>');
}
function rmvSuggBox(event) {
  elm = Event.element(event);
  if ( elm.id.include('sgId_') || elm.id.include('dest') ){ return false;}
  if ( $('sugBox') ) $('sugBox').remove();	
}
function updateText(dAindex, comIn) {
	if (!objD.value.include(dA[dAindex])) {
	   objD.value = objD.value.substr(0,comIn+1) + dA[dAindex] + ',';
	}
	else{
	   alert('You have the destination listed already!');
	}
	if ( $('sugBox') ) $('sugBox').remove();
	$('dest').focus();
	return 1;
}

Event.observe($('dest'),'keyup', showSuggestions);
Event.observe($('dest'),'focus', createSuggBox);
Event.observe(document,'click',  rmvSuggBox);
*/


