/************************************
**	WorldVentures
**	Author : Mukesh P, and Brian Blocker did 1 thing... which was insignificant
**	Version:2008.02.09
*************************************/
var psStype='';
function crObj(o){ return  document.getElementById(o);}
function hideandshow(){				//displays forms required
	var argv = hideandshow.arguments;
//	alert(argv[0]);
  	var argc = argv.length;  	
//  	switch(argv[0]){
//  		case "multi_trip":
//  			crObj('btnAirSearch').value='';
//  			break;
//  		case "flight":
//  			crObj('ttr').click();
//  			hideandshow('round_trip','oneway_trip','multi_trip');
//  			break;
//  		case "oneway_trip":
//  			if(crObj('flihot')){
//	  			if(crObj('flihot').checked)
//	  				crObj('btnAirSearch').value='';
//  			}
//  			else
//  				crObj('btnAirSearch').value='';
//  			break;
//  		case "round_trip":
//  			if(crObj('flihot')){
//	  			if(crObj('flihot').checked)
//	  				crObj('btnAirSearch').value='';
//  			}
//  			else
//  				crObj('btnAirSearch').value='';  	
//  			break;
//  	}	
//  	if(argv[0]=='cruise_d' || argv[0]=='cruise_l')
//  	{
////  		alert(argv[0]);
//  		psCruiseDefault(argv[0]);
//  	}
  	showit(argv[0]);
  	for (var i = 1; i < argc; i++) {
  		if(wv_chkId(argv[i]))
  			hideit(argv[i]);
  	}
}
function hideit(o){	
  //hides an element
  var thing =wv_chkId(o);
  if (thing != false )
  { 
        thing.style.display='none';	
  }
}
function showit(o)
{					//displays an element
  var thing = wv_chkId(o);
   if (thing != false )
  {
    thing.style.display='block';
  }
}
function highlightIcon(o){          //select state for dreamtrips icons
  var thing = wv_chkId(o);
  if (thing != false )
  {
      thing.style.border='3px double #cfcfcf';
      thing.style.background = '#ffffff';
	    thing.style.height='30px';
      thing.style.color='black';
  }
}
function delightIcon(o){        //de-select state for dreamtrips icons
  var thing = wv_chkId(o);
  if (thing != false )
  {  
      thing.style.border='3px double #ffffff';
	    thing.style.background='#ffffff';
	    thing.style.height='30px';
      thing.style.color='gray';
  }
}
function SwitchIt(o){                  //switches an element between show/hide
  var thing = wv_chkId(o);
  if (thing != false )
  {
   if(thing.style.display!='none'){
		thing.style.display = 'none';
	}
	else {
		thing.style.display = 'block';
	}
  }
}
function wv_chkId(o)				//Checks and returns ID objects
{
	if(document.getElementById(o))
		return document.getElementById(o);
	else
		return false;
}

function Test (obj)
{
    
    var temp = document.getElementById(obj);
    alert(temp);
}


/*	STYLES	*/

function bgchange(){
	var argv = bgchange.arguments;
  	var argc = argv.length;
  	highlight(argv[0]);
  	for (var i = 1; i < argc; i++) {
  		if(wv_chkId(argv[i]))
  			delight(argv[i]);
  	}
}

function highlight(o){
  var thing = document.getElementById(o);
  thing.style.background = '#ffffff';
  thing.style.borderBottom='1px solid #ffffff';
  thing.style.color='#1a33a8';
}
function delight(o){
  var thing = document.getElementById(o);
  thing.style.background='url(../App_Themes/DefaultV4/images/DT_tab_ns.jpg)';
  thing.style.borderBottom='1px solid #cfcfcf';
  thing.style.color='#666666';
}

function mhov(o){
  if(crObj(o))
 	crObj(o).textDecoration='underline';
}
function mout(o){
  if(crObj(o))
 	crObj(o).style.textDecoration='none';
}

// Required For Request Control
function psPassengerInfo(sfx)
{
	psSeniors=0;
	psAdult=crObj('adult_'+sfx).value;
	if(crObj('seniors_'+sfx))
		psSeniors=crObj('seniors_'+sfx).value;
	psChild=crObj('children_'+sfx).value;
	var psCAges=new Array();
	psCAges[1]='';psCAges[2]='';psCAges[3]='';
	if(psChild > 0)				//Checking for Child Count
	{
		for(i=1;i<=psChild;i++)
		{
			objChildA=crObj('childage_'+sfx+i);
			if(objChildA.value==0)					//Checking Child Ages
			{
				alert("Enter Child Ages");
				objChildA.focus();
				return false;
			}
			else
				psCAges[i]=objChildA.value;			//Setting Child Ages
		}
	}
	query+="&adult="+psAdult+"&children="+psChild;
	query+="&childage1="+psCAges[1]+"&childage2="+psCAges[2]+"&childage3="+psCAges[3]+"&seniors="+psSeniors;	//Common Age Queries[AIR]
	return true;
}
function psBtnControl(o,t)
{
	o.disabled=false;
	o.value=t;
	return false;
}
function crossCheckDate(d1,d2)
{
	cObj=crObj("mDt"+d1);
	if(cObj.value=='mm/dd/yy') 
		cObj.value='';
	if(cObj.value=='')
	{
		alert("Invalid Date");
		cObj.focus();
		return false;
	}
	date1=cObj.value.split("/");
	date1="20"+date1[2]+date1[0]+date1[1];	
	if(date1<d2)
	{
		alert("Invalid Date");
		cObj.focus();
		return false;
	}
	else
		return true;
}
function psTodayCheck(dt)
{
	if(dt==''){
		var today_=new Date();
		day=today_.getDate();
		day=(day<10) ? "0"+day : day;
		mon=(today_.getMonth()+1)
		mon=(mon<10) ? "0"+mon : mon;
		yr=today_.getFullYear();
	}
	else{
		date1=dt.split("/");
		yr="20"+date1[2];
		mon=date1[0];
		day=date1[1];
	}
	today=yr+""+mon+day;
//	alert(today);
	return today;
}
var xmlHttpRequest='';
//alert(createRequestObject());
  function crRequest(cUrl)
	{
		xmlHttpRequest = createRequestObject();
		cUrl=cUrl+"&sid="+Math.random();
		xmlHttpRequest.open('get', cUrl);
		xmlHttpRequest.onreadystatechange =crReqResponse;
		xmlHttpRequest.send(null);
	}
	function crReqResponse()
		{
			try
			{
				if(xmlHttpRequest.readyState == 4)
				{
					if(xmlHttpRequest.status == 200)
					{
//						alert(xmlHttpRequest.responseText);
						if(xmlHttpRequest.responseText.split("ALERT:").length>1)
						{
							m4m=xmlHttpRequest.responseText.split("ALERT:")[1];
							alert(m4m);
						}
						if(xmlHttpRequest.responseText.split("MOVENEXT:").length>1)
						{
							surl=xmlHttpRequest.responseText.split("MOVENEXT:")[1].split("?")[1];
							switch(tType){
								case "hotelonly":
									document.location.href="http://www.worldventures.com/results.hotel.html?"+surl;
								break;
								case "airhotel":
									document.location.href="http://www.worldventures.com/results.vacation.html?"+surl;
								break;
								case "airhotelcar":
//									alert(xmlHttpRequest.responseText);
									document.location.href="http://www.worldventures.com/results.package.html?"+surl;
								
								break;								
								case "air":
									_url_="results.flight.html?"+surl;
									if(psStype)
										if(psStype=='multicity')
											_url_="results.multiflight.html?"+surl;
									document.location.href=_url_;
								break;							
							}
						}
						if(xmlHttpRequest.responseText.split("ERROR:").length>1)
						{
							m4m=xmlHttpRequest.responseText.split("ERROR:")[1];
							m4m=m4m.split("::")
							alert(m4m[0]);
						}
					}
					else
					{
						
					}
				}
			}
			catch(e)
			{
				alert(e.message);
			}
		}
function request_create(q,type)
{
	vFile="ps.request.php?";
//	alert(type);
//	alert(q);
//	return false;
	switch(type){
		
		case "airhotel":			
			file='ajx_crt_req.php?'+q;
			crRequest(file);
			return;
		break;
		case "airhotelcar":
			file='ajx_crt_req.php?'+q;
			crRequest(file);
			return;
		break;
		case "air":
			if(crObj('source_res')){
				if(crObj('source_res').value=='ps'){
					file='ajx_crt_req.php?'+q;
//					alert(file);
					crRequest(file);				
					return 0;
				}
			}
		break;
		case "Flight":			if(crObj('source_res')){
				if(crObj('source_res').value=='ps'){
					file='ajx_crt_req.php?'+q;
//					alert(file);
					crRequest(file);				
					return 0;
				}
			}
		break;
		case "hotelonly":
			file='ps.request.php?'+q+"&search=current";
//			alert(file);
			crRequest(file);
			return 0;
		break;
		case "cruisedestini":
			vFile='http://www.worldventuresres.com/travel/cruise/destination.rvlx?'+q;
			window.location=vFile;
			return 0;
		break;
		case "cruiseline":
			vFile='http://www.worldventuresres.com/travel/cruise/vendor.rvlx?'+q;
			window.location=vFile;
			return 0;
		break;
		case "cruise":
			vFile='http://www.worldventuresres.com/travel/cruise/search.rvlx?'+q;
			window.location=vFile;
			return 0;
		break;
	}
	window.location=vFile+q;
//	alert('TEST MODE ACTIVE \nStatus: Success!!\n'+vFile+'?'+q);
	
}
function setchildages(o,tget,pfx)
{
	if(o.value>0)
	{
		childHTML='';
		for(i=1;i<=o.value;i++)
		{
			childHTML+='Child Age['+i+']<select name="childage_'+pfx+i+'" id="childage_'+pfx+i+'" style="font:normal 10px verdana"><option value="0" selected>0</option><option value="1">1</option>';
			childHTML+='<option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>';
			childHTML+='<option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option>';
			childHTML+='<option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option>';
			childHTML+='<option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option></SELECT><BR>';
		}				
		crObj(tget).innerHTML=childHTML;
	}
	else
		crObj(tget).innerHTML="";					
}

function setSrchType(obj){
//	alert();
	var txtAry=new Array();
	txtAry['Flight']='';
	txtAry['FlightHotel']='';
	txtAry['FlightHotelCar']='';
	txtAry['FlightCar']='';
	crObj('srch_item').value=obj.value;
//	alert();
	if(obj.value.indexOf('Flight')!=-1)
		crObj('btnAirSearch').value=txtAry[obj.value];
}
function psSrchType(obj)
{
	var txtAry=new Array();
	txtAry['h']='';
	txtAry['v']='';
	txtAry['c']='';
	crObj('btnVacation').value=txtAry[obj.value];
}
function doCarLoc(it,i)
{
	display=(i==0) ? 'block' : 'none';
	crObj(it+'_area').style.display=display;	
}
function whereForm(o,ty)
{
	if(ty=='dr'){
		crObj('drCountry').innerHTML=crObj('puCountry').innerHTML;
		crObj('drState').innerHTML=crObj('puState').innerHTML;
		crObj('dr_postate').innerHTML=crObj('puState').innerHTML;		
	}
	else{
		crObj('dr_postate').innerHTML=crObj('puState').innerHTML;		
	}
	crObj(ty+'_poi').style.display='none';
	crObj(ty+'_address').style.display='none';
	crObj(ty+'_airport').style.display='none';
	crObj(ty+'_'+o.value).style.display='block';
	
}
// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
function changeForm(FormName,RadioName,NewCheck,DivID) {
	setCheckedValue(document.forms[FormName].elements[RadioName],NewCheck);
	var SearchTypes = new Array();
	SearchTypes[0] = 'flight';
	SearchTypes[1] = 'hotel';
	SearchTypes[2] = 'car';
	SearchTypes[3] = 'cruise';
	SearchTypes[4] = 'vacation';
	
	var SearchTypeLength = SearchTypes.length;
	for(var i = 0; i < SearchTypeLength; i++){
		if(SearchType[i] == DivID) {
			showit(wv_chkId(SearchType[i]));}
		else {
			hideit(wv_chkId(SearchType[i]));}}
}

var curBox="";
function loadCityList(oCity)
{
var xmlcitylist=createRequestObject();
	if(oCity.value.length>0)
	{
		curBox=oCity.getAttribute("id");
		crObj(curBox+"list").innerHTML="Validating....";
		url="grab.inc?grab=citylist&cn="+oCity.value;
		xmlcitylist.open('get', url);
		xmlcitylist.onreadystatechange =get_list_city1;
		xmlcitylist.send(null);
	}
}
function get_list_city1()
{
var xmlcitylist=createRequestObject();
	try{if(xmlcitylist.readyState == 4){
		if(xmlcitylist.status == 200){							
			if(!crObj(curBox+"list"))	
				return false;	
			else{
				
			}
			if(xmlcitylist.responseText.split("CONTINUE").length>1)
			{
				oCity=xmlcitylist.responseText.split("CONTINUE:")[1];
				oCity=oCity.split("::");
				crObj(curBox).value=oCity[0];
				crObj(curBox+"list").innerHTML="";
				crObj(curBox+"_name").innerHTML=oCity[1];
			}	
			else if(xmlcitylist.responseText.split("NOMATCH").length>1)
			{
				alert("There is no airport with the city name. Please enter the city name ");
				crObj(curBox+"list").innerHTML="";
			}
			else
			{				
				crObj(curBox+"list").innerHTML=xmlcitylist.responseText;
			}
		}else{}
	}
	}catch(e){//alert(e.message);
}
}
function set_city(oCity)
{
	oCity=oCity.split("::");
	crObj(curBox).value=oCity[0];
	crObj(curBox+"list").innerHTML="";
	crObj(curBox+"_name").innerHTML=oCity[1];
}