//this page is used to set up general functions used through out the search boxes and WCT pages. 

// Popup windows
var o_popurl = "#";
var o_popwindow = 0;
var b_popwindow = 1;
function checkpopUp(){
 b_popwindow = (o_popwindow) ? o_popwindow.closed : 1;
  if(b_popwindow) document.location = o_popurl;
  else o_popwindow.focus();
}

function popUp(s_url,s_name,s_attrib){
 o_popurl = s_url;
 o_popwindow = window.open(s_url,s_name,s_attrib);
 setTimeout("checkpopUp()",500);
}


//used to switch the class of elements on the fly.
function changeClass(id, newClass) 
{	
	try
	{
		var obj = getElObj(id,'',searchType+"_frame");		
		if(typeof(obj) != "object")
			id = YAHOO.util.Dom.get(id);
		else
			id= obj;					
		var oldClassName = id.className;
		if(newClass.length == 0 )
		{
			YAHOO.util.Dom.removeClass(id,oldClassName);
		}
		else
		{
			YAHOO.util.Dom.replaceClass(id,oldClassName,newClass);
		}
	}
	catch(error){}
}

function hide(idLayer) { 
//	alert(idLayer);
//	alert(document.getElementById(idLayer));
	try {
		if(typeof(idLayer) != "object")
		{
			try
			{
				document.getElementById(idLayer).style.display='none'; 
			}
			catch(error){}
		}
		else
		{	
			idLayer.style.display='none'; 
		}
	}
	catch(e){};
}

// used to hide and show elements. 
function show(idLayer) {
	try{
		if(typeof(idLayer) != "object")
			document.getElementById(idLayer).style.display='block';  
		else
			idLayer.style.display='block';  
	}
	catch(e){};
}

function showInline(idLayer) { 
	try{
		if(typeof(idLayer) != "object")
			document.getElementById(idLayer).style.display='inline'; 
		else
			idLayer.style.display='inline'; 
	} 
	catch(e){};
}



function getElObj(id,tag,root)
{
	var element;
	var re = new RegExp('(?:^|\\s+)' +id+ '(?:\\s+|$)');
	var method = function(el) {return re.test(el["id"])};
	var elementList = YAHOO.util.Dom.getElementsBy(method,tag,root);
	if (elementList.length > 0)
		element=elementList[0];
		
	return element;	
}
			   

function loadErrorTranslation(errmsgObj)
{
// checking to see if there are translated Error messages
if(typeof(errmsgObj) == "undefined"){
	// specifying defaults message if there is no translation
	var validateError = new Object();
	validateError = {cityError:'enter a city' , dateError:'enter dates'};
}
}

//checks all of the search boxes for errors and displayes warnings
function checkForm(FormName, type) {

var form = document.getElementById(FormName);


var searchForm = form;
if( type=='hotel' ){ 
	var cityVal =  form.city.value;
	if (cityVal == "" || cityVal == validateError.cityError) 
			{
			changeClass("city","formWarning");
			form.city.value=validateError.cityError;
			blnPass = false;
			}
	
}
if(type=='air'){ 
	var leavingFromVal;
	var goingToVal;
		leavingFromVal =  form.leavingFrom.value
		goingToVal =  form.goingTo.value
		
	var chk_inVal =  form.leavingDate.value;
	var chk_outVal =  form.returningDate.value;

}

if(type=='car' ){
	var pucityVal =  form.pucity.value
	//var docityVal =  form.docity.value
}

if( type=='vacation' ){ 
	var cityVal =  form.cityfrom.value;
	if (cityVal == "" || cityVal == validateError.cityError) 
			{
			changeClass("cityfrom","formWarning");
			form.cityfrom.value=validateError.cityError;
			blnPass = false;
			}
	var city2Val =  form.cityto.value;
	if (city2Val == "" || city2Val == validateError.cityError) 
			{
			changeClass("cityto","formWarning");
			form.cityto.value=validateError.cityError;
			blnPass = false;
			}
	
}




if (type !='air')
{	
	var chk_inVal =  form.chk_in.value;
	var chk_outVal =  form.chk_out.value;	
}
var blnPass = true;



if( type=='air')
	{ 
			if (leavingFromVal == "" || leavingFromVal == validateError.cityError) 
				{
				changeClass(form.leavingFrom,"formWarning");
				form.leavingFrom.value=validateError.cityError;
				blnPass = false;
				}
			if (goingToVal == "" || goingToVal == validateError.cityError) 
				{
				changeClass(form.goingTo,"formWarning");
				form.goingTo.value=validateError.cityError;
				blnPass = false;
				}
			if (chk_inVal == "" || chk_inVal == validateError.dateError || chk_inVal == "mm/dd/yyyy" || chk_outVal == "" || chk_outVal == validateError.dateError || chk_outVal == "mm/dd/yyyy")
				{
					changeClass(form.chk_in,"formWarning");
					changeClass(form.chk_out,"formWarning");
					form.chk_in.value=validateError.dateError;
					form.chk_out.value=validateError.dateError;
					blnPass = false;
				}
	}
	

if(type!="air")
	{
		if (chk_inVal == "" || chk_inVal == validateError.dateError || chk_inVal == "mm/dd/yyyy" || chk_outVal == "" || chk_outVal == validateError.dateError || chk_outVal == "mm/dd/yyyy")
		{
			changeClass(form.chk_in,"formWarning");
			changeClass(form.chk_out,"formWarning");
			form.chk_in.value=validateError.dateError;
			form.chk_out.value=validateError.dateError;
			blnPass = false;
		}
	}

		
if(type=='car')
{ 
	// check to see if "same as pickup" checkbox is checked.  Populate dropoff city if check box is checked.
	if (pucityVal == "" || pucityVal == validateError.cityError) 
	{
	changeClass("pucity","formWarning");
	form.pucity.value=validateError.cityError;
	blnPass = false;  
	}
	
}

return blnPass;

}
var ids = new Array('tab_1', 'tab_2', 'tab_4', 'tab_5' );

function hideAll() {
	hide('hotel_frame');
	hide('air_frame');
	hide('car_frame');
	hide('vacation_frame');
	}

function flipTab(id){
	//make all of them flip off
	flipAllOff();
	//display the one that was clicked on
	flipOn(id);

	/*if (idLayer=='1' || idLayer=='hotel34' ){alert(idLayer); }
	if (idLayer=='2' || idLayer=='air'){alert(idLayer); }
	if (idLayer=='3' || idLayer=='car'){alert(idLayer);}
	if (idLayer=='4' || idLayer=='vac'){alert(idLayer);}*/
}
//flip on
function flipOn(id)
{
		var id1 = id+'_off';
		$(id1).hide();
		var id2 = id+'_on';
		$(id2).style.display = 'inline';
		if (id == 'tab_1')
			document.getElementById('pricelinewrapper').style.background='url(http://img1.corporateperks.com/SECURED/Offer/Merchant/priceline/hotels_bg.jpg)  no-repeat right';
		if (id == 'tab_2')
			document.getElementById('pricelinewrapper').style.background='url(http://img1.corporateperks.com/SECURED/Offer/Merchant/priceline/flights_bg.jpg) no-repeat right';
		if (id == 'tab_4')
			document.getElementById('pricelinewrapper').style.background='url(http://img1.corporateperks.com/SECURED/Offer/Merchant/priceline/cars_bg.jpg) no-repeat right';
		if (id == 'tab_5')
			document.getElementById('pricelinewrapper').style.background='url(http://img1.corporateperks.com/SECURED/Offer/Merchant/priceline/vac_bg.jpg) no-repeat right';

		var div = id+'_info';
		//$(div).show();
		Effect.Appear(div);

}

//flip all off
function flipAllOff()
{
	for(i=0; i<ids.length; i++)
	{
		var id = ids[i]+'_on';
		$(id).hide();

		var id2 = ids[i]+'_off';
		$(id2).style.display = 'inline';

		//also hide the divs
		var div = ids[i]+'_info';
		$(div).hide();
	}
}



