/*Takes user to the package details page (url) or asks him to login*/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

function viewPkg(url,isLoggedIn){
	if(isLoggedIn){
		window.location.href=rootpath+url;
	}else{
		if(url!='#'){
			document.loginform['spring-security-redirect'].value=url;
		}
		document.getElementById('loginerr').style.display='block';
		document.getElementById('loginerr').innerHTML='Please log in to proceed further.';
		showDiv('loginDIV');
		window.scrollTo(0,0);
		document.loginform.j_username.focus();
	} 
}
function vldteLogin(thisform) {
	//Remove form element in case its value is empty 
	if(thisform['spring-security-redirect'].value ==''){
		node = document.getElementById('spring-security-redirect');
		if(node){
		node.parentNode.removeChild(node);
		}
	}
	
	if (thisform.username.value ==null || (thisform.username.value).trim().length==0) {
		reason1="Please enter the Username."
		document.getElementById('loginerr').innerHTML = reason1;
		thisform.username.focus();
		return false;
	} 
	else if (thisform.password.value ==null || (thisform.password.value).trim().length==0) {
        reason1="Please enter the Password."
		document.getElementById('loginerr').innerHTML = reason1;
		thisform.password.focus();
		return false;
	}
	
		if(thisform.rememberme.checked==true)
	  {
	   createCookie('username',thisform.username.value,30);
	   createCookie('password',thisform.password.value,30);
	  }
	  document.loginform.submit();
	  return true;
}

function loadMap(url,pkgName)
 {
	BrowserDetect.init();
	if(!(BrowserDetect.browser=='Explorer' && BrowserDetect.version==6))
	{
	//open progress bar
//pb=openProgressBar();	
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET",url,false);
xmlhttp.send(null);
if((xmlhttp.responseText).replace(/^\s+|\s+$/g, '').length!=0)
{
if(pkgName){
document.getElementById("gMapPkgName").innerHTML=pkgName;
}
showDialogMap();
// buildMap();
assignData(xmlhttp.responseText);
}else{
	alert("Sorry can't locate the place.");
}
	}
else{
	alert("This feature is not available on browser:Internet Explorer 6.");
}
}

function openProgressBar() {
	Dom = YAHOO.util.Dom,Event = YAHOO.util.Event;
	pb = new YAHOO.widget.ProgressBar({value:10,minValue:0,maxValue:100}).render('progressBar');
	return pb;
}

function makemevis(a)
{var st=document.getElementsByTagName("div");

for(i=0;i<st.length;i++)
	{
	var aa=st[i].id;
	if(aa.indexOf("departure_") >-1)
		{
st[i].style.display="none";
		}
	}
	
document.getElementById(a).style.display="block";
}

function appendOptionLast() { 
	var elOptNew = document.createElement('option'); 
elOptNew.text = "Weekend Breakaways"; 
elOptNew.value = "Weekend Getaways"; 
var elSel =document.searchForm.category;

  try { elSel.add(elOptNew, null); } 
  catch(ex) { elSel.add(elOptNew); } 
  if(document.searchForm.category.value=="Weekend Breakaways") { 
  document.searchForm.category.value="Weekend Getaways";
  }
  
}



function submitSearchia(root)
	{
	 //get theme value
	theme='';
	for (var i=0; i < document.searchForm.tripchoice.length; i++)
	   {
	   if (document.searchForm.tripchoice[i].checked)
	      {
		   theme = document.searchForm.tripchoice[i].value;
	      break;
	      }
	   }


	  minDuration=1;
	  // get duration value
	maxDuration=document.searchForm.duration.value;
	if(maxDuration==7){
		 minDuration=4;
	}else if(maxDuration==10){
		 minDuration=7;
	}
	 //get month value
	depDateTokens=(document.searchForm.dateView.value).split('\/');
	month=-1;
	if(depDateTokens.length==3 && (depDateTokens[1]).match(/^\d{1,2}$/)){
		month=depDateTokens[1];
	}
	
urlToSubmit=root+'/indiaahoy/search?IKnowDest'+document.searchForm.knowmydest.value+'=&category=All+Packages&dest=&minDuration='+minDuration+'&month='+month+'&duration='+maxDuration+'&theme='+theme;
document.location.href = urlToSubmit;
}


function populateSearchCriteria(theme,dest,maxDuration)
{
var re = new RegExp(theme);

for (var i=0; i < document.searchForm.tripchoice.length; i++)
	   {
	   
	   if (document.searchForm.tripchoice[i].value.match(re))
	      {
		  document.searchForm.tripchoice[i].checked=true;
			break;
	      }
	   }
	   


	     if(dest !="" && dest != "null"){
		
		document.getElementById('cityAuto').value=dest;
		}


	   if(maxDuration==7){
		
		document.searchForm.duration.options[2].selected=true;
	}else if(maxDuration==10){
		document.searchForm.duration.options[3].selected=true;
	}
	else if(maxDuration==3){
		document.searchForm.duration.options[1].selected=true;
	}
}



  
function submitSearchdom(root)
	{
	   document.searchForm.minDuration.value=1;
       if(document.searchForm.duration.value==7)
          document.searchForm.minDuration.value=4;
       if(document.searchForm.duration.value==10)
          document.searchForm.minDuration.value=8;
	   document.searchForm.dest.value ="";
	   var iKnow = document.getElementById('package.city').value;
       var autoSuggested = document.getElementById('cityAuto').value;
var frm=document.searchForm;
 


       if(iKnow == "" && (autoSuggested == "" || autoSuggested=='Enter your destination here') )
		{
		}
		else if(iKnow != "")
		{
	    	document.searchForm.dest.value = iKnow;
		}
		else if(!(autoSuggested == "" || autoSuggested=='Enter your destination here'))
		{
			document.searchForm.dest.value = autoSuggested;
		}
		if(autoSuggested=='Enter your destination here')
		{
		   document.getElementById('cityAuto').value='';
		}
		if(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' )
		{
		   document.searchForm.category.value=document.getElementById("search_"+0).innerHTML;
		}
		if(document.searchForm.month.value !="-1" || document.searchForm.duration.value != "-1")
		{       
			if(document.searchForm.category.value=="Weekend Breakaways") {

			 
			
			document.forms[0].submit();
		}
		return;
		}
	
        var destModified = document.searchForm.dest.value;
	    if(!(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' )
	       && !(document.searchForm.theme.value == null || document.searchForm.theme.value == '' || document.searchForm.theme.value == 'undefined' )
	       && !((destModified == null || destModified == '' || destModified == 'undefined') ))
        {
           var category = ReplaceAll(document.searchForm.category.value.toLowerCase(),' ','_');
           var dest = ReplaceAll(destModified.toLowerCase(),' ','_');
           var theme = ReplaceAll(document.searchForm.theme.value.toLowerCase(),' ','_');
           document.location.href = root+"/trips-" + theme +"-"+ category +"-"+ dest+".html";
        }
        else if(!(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' )
	       && !(document.searchForm.theme.value == null || document.searchForm.theme.value == '' || document.searchForm.theme.value == 'undefined' ))
        {
           var category = ReplaceAll(document.searchForm.category.value.toLowerCase(),' ','_');
           var theme = ReplaceAll(document.searchForm.theme.value.toLowerCase(),' ','_');
           document.location.href = root+"/tours-" + theme +"-"+ category +".html";
        }
        else if(!(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' )
	       && !((destModified == null || destModified == '' || destModified == 'undefined')))
        {
           var category = ReplaceAll(document.searchForm.category.value.toLowerCase(),' ','_');
           var dest = ReplaceAll(destModified.toLowerCase(),' ','_');
           document.location.href = root+"/travel-" + category +"-"+ dest+".html";
        }
        else if(!(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' ))
        {
        	var category = ReplaceAll(document.searchForm.category.value.toLowerCase(),' ','_');
        	var urlToSubmit =root+"/packages-" + category +".html";
            document.location.href = urlToSubmit;
        }
}

function ReplaceAll(Source,stringToFind,stringToReplace){
  var temp = Source;
  var index = temp.indexOf(stringToFind);
  while(index != -1)
  	{
       temp = temp.replace(stringToFind,stringToReplace);
       index = temp.indexOf(stringToFind);
    }
  return temp;

}

function isEnterKey(evt,url)
  {
      var charCode = (evt.which) ? evt.which : event.keyCode
     
      if ( charCode == 13) {
		submitSearchList(url);
      } else {

      }
  }

function makemevis_es(me,id)
{
	var st=document.getElementsByTagName("div");
	var showall=me;
	var cnt=0;
	if(showall.innerHTML=="Show All Departures")
	{
		for(i=0;i<st.length;i++)
		{
		var aa=st[i].id;	
		if(aa.indexOf("dates_"+id)>-1)
		{ cnt+=1;
		if(cnt>3) st[i].style.display="block";
		var stff=st[i].getElementsByTagName("span");
		var yeartobeloaded="";
		var yyyy="";
						for(j=0;j<stff.length;j++)
									{
									var aa=stff[j].id;	
												if(aa.indexOf("shiftyear")>-1)
												{
														if(stff[j].innerHTML.substring(2,4)!=yyyy)
														{		
														if(yyyy!="") {yyyy=yyyy+",";}
															yyyy =yyyy+stff[j].innerHTML.substring(2,4);
														}
												}
											if(aa.indexOf("yeartobeloaded")>-1)
											{yeartobeloaded=stff[j];
											}
								}
						yeartobeloaded.innerHTML="' "+yyyy;
		}
		}
	}
	if(showall.innerHTML=="Hide All Departures")
	{
		for(i=0;i<st.length;i++)
		{
		var aa=st[i].id;	
		if(aa.indexOf("dates_"+id)>-1)
		{cnt+=1;
		if(cnt>3) st[i].style.display="none";
	
		}
		}
	
	}
	if(showall.innerHTML=="Show All Departures")
	{
	showall.innerHTML="Hide All Departures"
	}
	else
	{
	showall.innerHTML="Show All Departures"
	}

}

function removeme()
{
document.getElementById("phonenumbers").style.display="none";
document.getElementById("blackoverlayphone").style.display="none";
}
function phonenumbers()
{
var maintableHeight = document.getElementById("maintable").offsetHeight;
document.getElementById("phonenumbers").style.display="block";
document.getElementById("blackoverlayphone").style.display="block";
var browserName = whichBrs(); 
   if(browserName=="IE")
  	{
  	 	var bodywidth = document.body.scrollWidth;
  	 	var bodyheight = document.body.scrollHeight;
  	 	document.getElementById("blackoverlayphone").style.width=bodywidth+"px";
  	 	document.getElementById("blackoverlayphone").style.height=bodyheight+"px";	
  	}
   if(browserName=="Firefox")
  	{
  		document.getElementById("blackoverlayphone").style.height=maintableHeight+480+"px";	
  	}
	if(browserName=="Safari")
  	{
  		document.getelementbyid(iframeclosebtn).style.left=leftpos+524+"px";
    	document.getelementbyid(iframeclosebtn).style.top=toppos-12+"px";
  	}
document.getElementById("phonenumbers").style.position="absolute";
 	

getpackagelisting(rootpath+'/transform.transform?style=/xslt/phonenumbers_xsl&content=phonenumbers_xml&domorobt=dom&rnd='+Math.random(),'phonenumbers')
}
function deselectallsortingstates()
{

document.getElementById("priority_img").src=rootpath+"/images/topbottom.gif";
document.getElementById("priority_img").style.height="12px";
document.getElementById("duration_img").src=rootpath+"/images/topbottom.gif";
document.getElementById("duration_img").style.height="12px";
document.getElementById("dicountedRates_img").src=rootpath+"/images/topbottom.gif";
document.getElementById("dicountedRates_img").style.height="12px";
}



function selectedstate()
{


}

function sortmeWraper()
{

	sortme(mysearcString.searchstring , mysearcString.nosorting , mysearcString.packageListing , mysearcString.context);
	

}
var sortingstate="";
var sortOrder='ASC';
flag=0;


function sortme(c,a,b,context)
{

deselectallsortingstates();
if(a!='includeflights' && a!='nosorting')
	{
if(sortOrder=='DESC' && sortingstate==a)
	{
	sortOrder='ASC';
	}
else if(sortOrder=='ASC' && sortingstate==a)
	{
	sortOrder='DESC';
	}

if(a=='priority' && flag==0)
{
	sortOrder='DESC';
	flag=1;
}
else 
{
	if(flag==1)
	{	sortOrder='ASC';
		flag=0;
	}
}

if(sortOrder=="ASC")
	{
document.getElementById(a+"_img").src=rootpath+"/images/sortop.GIF";
document.getElementById(a+"_img").style.height="6px";
}
else
	if(sortOrder=="DESC")
	{
document.getElementById(a+"_img").src=rootpath+"/images/sortbtm.GIF";
document.getElementById(a+"_img").style.height="6px";

}
	}

sortingstate=a;
var includeflights='';
/*
 * if(document.getElementById("includeflightss").checked==true) {
 * includeflights='&containsFlight=on'; } else { includeflights=''; }
 */
document.getElementById(b).innerHTML="Populating...";
var sliderdefaultsort="";

if(document.getElementById("priority").checked==true)
	{
	sliderdefaultsort='priority';
	}
else if(document.getElementById("pkg_duration").checked==true)
	{
	sliderdefaultsort= 'duration';
		}
else if(document.getElementById("dicountedRates").checked==true)
	{
	sliderdefaultsort= 'dicountedRates';
	}
	
	
	ExcludeThemes="";
	var selectedthemeslength=document.getElementsByName('refinethemes').length;
var st=document.getElementsByName('refinethemes');
for(i=0;i<selectedthemeslength;i++)
	{
if(st[i].checked==true)
		{
ExcludeThemes +=','+st[i].value;
		}
	}
var ExcludeThemeslength=ExcludeThemes.length;
	if(ExcludeThemes.charAt(0)==',')
	{
ExcludeThemes=ExcludeThemes.substring(1,ExcludeThemeslength);
	}

if(ExcludeThemes=="")
	{

	}
	else
	{ExcludeThemes="&includeThemes="+ExcludeThemes;

	}
	var duration_variable='';
	if(max_duration=="" || min_duration=="" || min_duration==max_duration || max_duration==null || min_duration==null)
	{

	}else
	{duration_variable='&duration='+max_duration+'&minDuration='+min_durationnew;
	}


	if(a=='nosorting')
	{

										

getpackagelisting(context+'/indiaahoy/includes/searchajax?sortName='+getsortname()+'&sortOrder='+sortOrder+c+includeflights+'&minRate='+min_rate+'&rate='+max_rate+duration_variable+ExcludeThemes,b);
											
	
	}
	else
	{
if(a=='includeflights')
		{
a=getsortname();
}

	getpackagelisting(context+'/indiaahoy/includes/searchajax?sortName='+a+'&sortOrder='+sortOrder+c+includeflights+'&minRate='+min_rate+'&rate='+max_rate+duration_variable+ExcludeThemes,b)
	

	}
}

function getsortname()
{
var a="";
var inputs=document.getElementsByName('sort');

for(i=0;i<inputs.length;i++)
			{
if(inputs[i].checked==true)
				{
	a=inputs[i].value;
				}
			}
		
return a;
}
function selectclass(tab_id)
{
	

	
document.getElementById('overview_tab').className="";
document.getElementById('overview_tab_data').style.display="none";

document.getElementById('itenary_tab').className="";
document.getElementById('itenary_tab_data').style.display="none";

/*
 * document.getElementById('route_map_tab').className="";
 * document.getElementById('route_map_tab_data').style.display="none";
 */

document.getElementById('hotel_tab').className="";
document.getElementById('hotel_tab_data').style.display="none";

document.getElementById('destination_tab').className="";
document.getElementById('destination_tab_data').style.display="none";

document.getElementById('photo_tab').className="";
document.getElementById('photo_tab_data').style.display="none";

document.getElementById('rates_tab').className="";
document.getElementById('rates_tab_data').style.display="none";

document.getElementById(tab_id).className="activetab";
document.getElementById(tab_id+"_data").style.display="block";

}
  function overlayOpens(getID)
  {

  	var maintableHeight = document.getElementById("maintable").offsetHeight;
  	document.body.style.scrollTop="0px";
  	document.getElementById(getID).style.display="block";
  	document.getElementById("fade").style.height=maintableHeight+40+"px";
  	document.getElementById("fade").style.display="block";
  }	
 function LoadGallery(pictureName,imageFile,captionID,captionText,imagealt)
 {
 	var picture = document.getElementById(pictureName);
   picture.src =imageFile;
   picture.alt =imagealt;
   picture.title =imagealt;
         
   if(captionText=='null')
	 {
		document.getElementById('photogalimg-desc').innerHTML="";
	 }
	 
	 else
	 {
   document.getElementById('photogalimg-desc').innerHTML=captionText;
	 }
	 
	  if(captionID=='null')
	 {
		document.getElementById('photogalimg-title').innerHTML="";
	 }
	 
	 else
	 {
	 document.getElementById("photogalimg-title").innerHTML=captionID;
	 }
  }

/*
function getData(package_id,tab_id,mode)
{
selectclass(tab_id);


}
*/
function selectme(a, category)
{

for(i=0;i<6;i++)
{
	try{
	document.getElementById("search_"+i).className="notselected";
	}catch(error) {
	}
	}
	
	a.className="selected";
	document.getElementById("srch_categories").style.backgroundColor="#fdf9d1";
	if(category=="Weekend Breakaways")
	{
		category="Weekend Getaways";
	}
	document.searchForm.category.value=category;

}
function sendrequestagain(a)
{
}


function AJAXInteraction(div,url, callback) {

    var req = init();
    req.onreadystatechange = processRequest;

    function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    }

    function processRequest () {
      if (req.readyState == 4) {
        if (req.status == 200) {
       
         if(document.getElementById(div) != null) {
        	 document.getElementById(div).innerHTML=req.responseText
       		}
         if (callback) {
        	 callback();
       	}
		}
      }
    }

    this.doGet = function() {
      req.open("GET", url, true);
      req.send(null);
    }

    this.doPost = function(body) {
      req.open("POST", url, true);
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      req.send(body);
    }
}

function makeRequest(url,div,callback) {
  var ai = new AJAXInteraction(div,url, callback);
  ai.doGet();


}
function makegetRequest()
{	
}

function getpackagelisting(url,div) {url=url+"&rnd="+Math.random();	
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
/*
 * if (http_request.overrideMimeType) {
 * http_request.overrideMimeType('text/html'); }
 */
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.open('GET', url, true);

http_request.send(null);
http_request.onreadystatechange = function()
{
if (http_request.readyState == 4) {
if (http_request.status == 200) {

result = http_request.responseText;

document.getElementById(div).innerHTML=result;

if(div=='modifyyoursearch') populaterefinebytheme();




} else {
alert('There was a problem with the request.');
}
}

}

}

var themes="";


function populaterefinebytheme()
{
var themelength=document.getElementById("package.theme").options.length;
var obj=document.getElementById("package.theme");
var themestring='<table><tr><td><b>Refine by Theme</b></td></tr><tr><td height="8px"></td></tr><tr><td><table border="0" cellspacing="0" cellpadding="0">';
themestring +='<tr>';
for(i=1;i<=themelength-1;i++)
	{
if(i<themelength-1)
		{
	themes +=obj.options[i].value+',';
		}
		else
		{
			themes +=obj.options[i].value;
		}

if(i % 2 !=0)
		{themestring +='<tr>';
		}
themestring +='<td width="22"><input type="checkbox" onclick="sortme(\''+searchstring+'\',\'nosorting\',\'packageListing\',\''+rootpath.replace("/",'')+'\')" name="refinethemes" id="'+obj.options[i].value+'"  value="'+obj.options[i].value+'" checked="checked"/></td>';
themestring +='<td height="20" width="65">'+obj.options[i].value+'</td>';
			if(i % 2 ==0){																
		themestring +='</tr>';
			}
	}
		themestring +='</tr>';
themestring +='</table></td></tr></table>'
if(document.getElementById("refinebythemes"))
	{
document.getElementById("refinebythemes").innerHTML=themestring;
	}
}
function calculatethemes()
{

}




function holidaythemelisting(context)
{
}




function holidaydestinationlisting(context)
{

}

function destinationlisting(url,div) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
/*
 * if (http_request.overrideMimeType) {
 * http_request.overrideMimeType('text/html'); }
 */
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.open('GET', url, true);

http_request.send(null);
http_request.onreadystatechange = function()
{
if (http_request.readyState == 4) {
if (http_request.status == 200) {

result = http_request.responseText;


document.getElementById(div).innerHTML=result;
if(div=='container')
	{
destinationlisting(rootpath+'/transform.transform?style=top3dest_heading_destinationpage_xsl&content=top3dest_heading_destinationpage_xml','top3destination_heading');
	}



if(div=='top3destination_heading')
	{
destinationlisting(rootpath+'/transform.transform?style=tagthis_xsl&content=tagthis_xml','tagthiscontainer');
	}
if(div=='tagthiscontainer')
{
	
	destinationlisting(rootpath+'/transform.transform?style=section1_xsl&content=section1_xml','honeymooncontainer');
}

if(div=='honeymooncontainer')
{destinationlisting(rootpath+'/transform.transform?style=section2_xsl&content=section2_xml','escortedcontainer');
}
if(div=='escortedcontainer')
{destinationlisting(rootpath+'/transform.transform?style=section3_xsl&content=section3_xml','section3');
}
if(div=='section3')
{destinationlisting(rootpath+'/transform.transform?style=section4_xsl&content=section4_xml','section4');
}
if(div=='section4')
{destinationlisting(rootpath+'/transform.transform?style=section5_xsl&content=section5_xml','section5');
}


} else {
alert('There was a problem with the request.');
}
}

}

}








function themelisting(url,div) {
http_request = false;

if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
/*
 * if (http_request.overrideMimeType) {
 * http_request.overrideMimeType('text/html'); }
 */
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.open('GET', url, true);

http_request.send(null);
http_request.onreadystatechange = function()
{
if (http_request.readyState == 4) {
if (http_request.status == 200) {

result = http_request.responseText;

document.getElementById(div).innerHTML=result;


if(div=='container')
	{
themelisting(rootpath+'/transform.transform?style=top3theme_heading_themespage_xsl&content=top3theme_heading_themespage_xml','top3theme_heading');
	}
if(div=='top3theme_heading')
	{
themelisting(rootpath+'/transform.transform?style=tagthis_xsl&content=tagthis_xml','tagthiscontainer');
	}
if(div=='tagthiscontainer')
{
	
	themelisting(rootpath+'/transform.transform?style=section1_xsl&content=section1_xml','honeymooncontainer');
}

if(div=='honeymooncontainer')
{themelisting(rootpath+'/transform.transform?style=section2_xsl&content=section2_xml','escortedcontainer');
}
if(div=='escortedcontainer')
{themelisting(rootpath+'/transform.transform?style=section3_xsl&content=section3_xml','section3');
}
if(div=='section3')
{themelisting(rootpath+'/transform.transform?style=section4_xsl&content=section4_xml','section4');
}
if(div=='section4')
{themelisting(rootpath+'/transform.transform?style=section5_xsl&content=section5_xml','section5');
}


} else {
alert('There was a problem with the request.');
}
}

}

}









function showpromotiondiv(id)
{
document.getElementById("completepromo_"+id).style.display="block";
document.getElementById("incompletepromo_"+id).style.display="none";

}
function showincompletediv(id)
{
document.getElementById("completepromo_"+id).style.display="none";
document.getElementById("incompletepromo_"+id).style.display="block";


}


function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
    
      return false;
   }
return true;
}


function registerMail() {
	if(validate(trim(document.emailRegisterForm["dealsEmail.emailId"].value)))
	{
	
	}
	else
	{	result="Please enter valid email";
				document.getElementById("status").innerHTML = result;
				document.getElementById("status").style.color="red";
				document.getElementById("status").style.display = "block";
		return false;
	}
	http_request = false;
	var emailId = document.emailRegisterForm["dealsEmail.emailId"].value;
	var branch =  document.emailRegisterForm["dealsEmail.branch"].value;
	var url= rootpath+ "/dealsEmail?dealsEmail.branch=" + branch + "&dealsEmail.emailId=" + emailId;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		/*
		 * if (http_request.overrideMimeType) {
		 * http_request.overrideMimeType('text/html'); }
		 */
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	}

	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	http_request.open('GET', url, true);

	http_request.send(null);
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {

				result = http_request.responseText;
				result="Email Registered Successfully..";
				document.getElementById("status").innerHTML = result;
				document.getElementById("status").style.color="red";
				document.getElementById("status").style.display = "block";

			} else {
				alert('There was a problem with the request.');
			}
		}

	}

}
function deselectsuggestion()
{document.getElementById('package.city').value="";
}
function deSelectDest(e){
			autoSuggested = document.getElementById('cityAuto').value;
			if(!(autoSuggested == "" || autoSuggested=='Enter your destination here')){
				document.getElementById('package.city').selectedIndex = 0;
			}
	}
function resetDest(packageCity){
	if(packageCity.value !='')
	{
	document.getElementById('cityAuto').value = "Enter your destination here";
	}
	else
	{
	document.getElementById('cityAuto').value = "";
	}

}

function selectDefaultCat(){
	try{
	 document.getElementById("search_"+0).className="selected";
	}catch(error) {
	 }
 
	 document.searchForm.category.value=document.getElementById("search_"+0).innerHTML;
 
}
 function initializeoverlay(iframeID,path)
  {

  		//document.getElementById(iframeID).src="/"+path+'&'+new Date();
		document.getElementById(iframeID).src=rootpath+"/loading";

  	
  }	
  

 function overlayOpen(iframeID,blackoverlayid,iframeClosebtn)
  { 
	  
	
   var browserName = whichBrs(); 
   maintableDiv=document.getElementById("maintable");
   if(maintableDiv){
   var maintableHeight = maintableDiv.offsetHeight;
   }else{
	   maintableHeight =getPageHeightWithScroll();
   }
   
   var leftPos = (screen.width / 2) - 251;
	 // var topPos = (screen.height / 2) - 255;
	 var topPos = (screen.height / 2) - 320;
   var bodywidth;
   var bodyheight;
   
   if(overlayOpen.arguments.length==4)
  	{
	   url=overlayOpen.arguments[3];
	   if(url.match(/http:\/\/.*/)){
		   document.getElementById(iframeID).src=url;
	   }
	   else{
  		document.getElementById(iframeID).src=url;
	   }
  	}
  	
  	if(overlayOpen.arguments.length==6)
		{
			document.getElementById(iframeID).src="/"+overlayOpen.arguments[3]+"&price="+overlayOpen.arguments[4]+"&destination="+overlayOpen.arguments[5]+"&timestamp="+new Date();
			// alert(document.getElementById(iframeID).src);
			// document.wr(document.getElementById(iframeID).src);
		}

   document.getElementById(iframeClosebtn).style.left=leftPos+525+"px";
   document.getElementById(iframeClosebtn).style.top=topPos+"px";
   document.getElementById(iframeClosebtn).style.display="block";
   
   document.getElementById(iframeID).style.left=leftPos+"px";
   document.getElementById(iframeID).style.top=topPos+"px";
   if(maintableDiv){
   document.getElementById(blackoverlayid).style.height=maintableHeight+480+"px";	
   }else{
	   document.getElementById(blackoverlayid).style.height=maintableHeight+"px";
   }
   if(browserName=="IE")
  	{
  	 	bodywidth = document.body.scrollWidth;
  	 	bodyheight = document.body.scrollHeight;
  	 	document.getElementById(blackoverlayid).style.width=bodywidth+"px";
  	 	document.getElementById(blackoverlayid).style.height=bodyheight+"px";	
  	}
   if(browserName=="Firefox")
  	{
	   if(maintableDiv){
		   document.getElementById(blackoverlayid).style.height=maintableHeight+480+"px";	
		   }else{
			   document.getElementById(blackoverlayid).style.height=maintableHeight+"px";
		   }
  		document.getElementById(iframeClosebtn).style.left=leftPos+523+"px";
  		document.getElementById(iframeClosebtn).style.top=topPos-41+"px";
  		document.getElementById(iframeID).style.top=topPos-30+"px";	  		
  	}

	if(browserName=="Safari")
	{
  		document.getElementById(iframeClosebtn).style.left=leftPos+524+"px";
    	document.getElementById(iframeClosebtn).style.top=topPos-12+"px";
  	}

  	document.getElementById(iframeID).style.display="block";
  	document.getElementById(blackoverlayid).style.display="block";
  }	
  
 function getPageHeightWithScroll() {
		if (window.innerHeight && window.scrollMaxY) {// Firefox
			yWithScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) {
			yWithScroll = document.body.scrollHeight;
		} else {
			yWithScroll = document.body.offsetHeight;
		}
		return yWithScroll;
	}
 
  function OverlayClose(iframeID,blackoverlayid,iframeClosebtn)
  {
  	document.getElementById(iframeID).src=rootpath+"/loading";
  	document.getElementById(iframeID).style.display="none";
  	document.getElementById(blackoverlayid).style.display="none";
  	document.getElementById(iframeClosebtn).style.display="none";
  }
  
  
  
function whichBrs() {
		var agt=navigator.userAgent.toLowerCase();
		if (agt.indexOf("opera") != -1) return 'Opera';
		if (agt.indexOf("staroffice") != -1) return 'Star Office';
		if (agt.indexOf("webtv") != -1) return 'WebTV';
		if (agt.indexOf("beonex") != -1) return 'Beonex';
		if (agt.indexOf("chimera") != -1) return 'Chimera';
		if (agt.indexOf("netpositive") != -1) return 'NetPositive';
		if (agt.indexOf("phoenix") != -1) return 'Phoenix';
		if (agt.indexOf("firefox") != -1) return 'Firefox';
		if (agt.indexOf("safari") != -1) return 'Safari';
		if (agt.indexOf("skipstone") != -1) return 'SkipStone';
		if (agt.indexOf("msie") != -1) return "IE";
		if (agt.indexOf("netscape") != -1) return 'Netscape';
		if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
		if (agt.indexOf('\/') != -1) {
		if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
		return navigator.userAgent.substr(0,agt.indexOf('\/'));}
		else return 'Netscape';} else if (agt.indexOf(' ') != -1)
		return navigator.userAgent.substr(0,agt.indexOf(' '));
		else return navigator.userAgent;
}

function submitSearchList(url) 
	{appendOptionLast();
	   document.searchForm.minDuration.value=1;
       if(document.searchForm.duration.value==7)
          document.searchForm.minDuration.value=4;
       if(document.searchForm.duration.value==10)
          document.searchForm.minDuration.value=8;
       var destModified="";
	   var iKnow = document.getElementById('package.city').value;
       var autoSuggested = document.searchForm.dest.value;
			

 var frm=document.searchForm;



       if(iKnow == "" && (autoSuggested == "" || autoSuggested=='Enter your destination here') )
		{
		}
	   else if(iKnow != "")
		{
	    	document.searchForm.dest.value = iKnow;
	    	destModified = iKnow;
		}
	   else if(!(autoSuggested == "" || autoSuggested=='Enter your destination here'))
		{
			document.searchForm.dest.value = autoSuggested;
			destModified = autoSuggested;
		}
	
		if(autoSuggested=='Enter your destination here')
		{
		   document.getElementById('cityAuto').value='';
		}
		if(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' )
		{
		   document.searchForm.category.value=document.getElementById("search_"+0).innerHTML;
		}
		if(document.searchForm.month.value !="-1" || document.searchForm.duration.value != "-1")
		{	
			document.searchForm.dest.value = destModified;
			
			
			document.forms[0].submit();
			return;
	    }
		if(!(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' )
	       && !(document.searchForm.theme.value == null || document.searchForm.theme.value == '' || document.searchForm.theme.value == 'undefined' )
	       && !((destModified == null || destModified == '' || destModified == 'undefined') ))
        {
		   var category = ReplaceAll(document.searchForm.category.value.toLowerCase(),' ','_');
           var dest = ReplaceAll(destModified.toLowerCase(),' ','_');
           var theme = ReplaceAll(document.searchForm.theme.value.toLowerCase(),' ','_');
           document.location.href = url+"/trips-" + theme +"-"+ category +"-"+ dest+".html";
        }
        else if(!(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' )
	       && !(document.searchForm.theme.value == null || document.searchForm.theme.value == '' || document.searchForm.theme.value == 'undefined' ))
        {
           var category = ReplaceAll(document.searchForm.category.value.toLowerCase(),' ','_');
           var theme = ReplaceAll(document.searchForm.theme.value.toLowerCase(),' ','_');
           document.location.href = url+"/tours-" + theme +"-"+ category +".html";
        }
        else if(!(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' )
	       && !((destModified == null || destModified == '' || destModified == 'undefined')))
        {
           var category = ReplaceAll(document.searchForm.category.value.toLowerCase(),' ','_');
           var dest = ReplaceAll(destModified.toLowerCase(),' ','_');
           document.location.href = url+"/travel-" + category +"-"+ dest+".html";
        }
        else if(!(document.searchForm.category.value == null || document.searchForm.category.value == '' || document.searchForm.category.value == 'undefined' ))
        {
        	var category = ReplaceAll(document.searchForm.category.value.toLowerCase(),' ','_');
        	var urlToSubmit = url+"/packages-" + category +".html";
            document.location.href = urlToSubmit;
        }
	}

	
function callme(a)
{
	if(a.indexOf("&")==-1)
	{
	var winLocString = window.location+"";
	if(winLocString.indexOf(".html") == -1)
	{
		if(winLocString.lastIndexOf("offset") == -1)
		   document.location.href = winLocString +"&offset="+a; 
		else
		   document.location.href =  winLocString.substring(0,winLocString.lastIndexOf("&offset"))+"&offset="+a;
	}
	else
		submitSearchListPagination((parseInt(a)/20)+1);	
		}
	else
	{
		document.getElementById('packageListing').innerHTML="populating...";
		getpackagelisting(rootpath+'/indiaahoy/includes/searchajax?'+a,'packageListing');
	}
}

function submitSearchListPagination(a)
{
	var winLocString = window.location+"";
	var splitLoc = winLocString.split('.html');
	var indexHyphen = winLocString.lastIndexOf("html");
	var lastElementString = splitLoc[0].substring(((splitLoc[0].length)-1),(splitLoc[0].length));
	var lastElement = parseInt(lastElementString);
	if(isNaN(lastElement))
	{
		document.location.href = splitLoc[0] + "-" + a + ".html";
	}
	else
	{
		if(a==1)
		  document.location.href = splitLoc[0].substring(0,splitLoc[0].lastIndexOf("-")) + ".html";
		else
	      document.location.href =  splitLoc[0].substring(0,splitLoc[0].lastIndexOf("-")) + "-" + a + ".html";
	} 
}
	
function ReplaceAll(Source,stringToFind,stringToReplace){
  var temp = Source;
  var index = temp.indexOf(stringToFind);
  while(index != -1)
  	{
       temp = temp.replace(stringToFind,stringToReplace);
       index = temp.indexOf(stringToFind);
    }
  return temp;

}
	
function ExpandCollapse(getID)	
{
	var obj = document.getElementById(getID);
	var status = document.getElementById(getID).style.display;
	
	/*
	 * var cookieVal = readCookie('collapse'); if(cookieVal==null) {
	 * createCookie('collapse','coll',7); obj.style.display='none'; } else {
	 */
		if(status==''||status=='none')
	{
			obj.style.display='block';
		document.getElementById("colps").setAttribute('src',rootpath+'/images/modifysearchopen.gif')

	}

		else
	{
		  obj.style.display='none';
		document.getElementById('colps').setAttribute('src',rootpath+'/images/modifysearchclose.gif')
	}
	//}		
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function getFont(getSpanObj)
{
	getSpanObj.style.backgroundColor="#6195c7" ;
	getSpanObj.style.Color="#fff";
}

function getOriginalFont(getSpanObj)
{
	getSpanObj.style.backgroundColor="" ;
	getSpanObj.style.Color="#6195c7";
}

function clearMe(destText){
	if(destText.value == 'Enter your destination here'){
		destText.value ='';
	}
}
