window.undefined=window.undefined;
var wtp=0;
var wc = ",width="+(screen.width*0.8)+",height="+(screen.height*0.8)+",resizable = yes,scrollbars=yes, toolbar=yes, location=yes";
var params = '';
function setParams(frm){
	var p='';
	for(var i=0;i<frm.elements.length;i++) {
		if(frm.elements[i].type=='radio' && frm.elements[i].checked==false) continue;
		if(frm.elements[i].name && frm.elements[i].value)
			p+='&'+frm.elements[i].name+'='+frm.elements[i].value;
	}
	return p;
}
function jump(mId, mName, siteType) {
	var myWinCoord = "left="+(wtp+=20)+",top="+wtp+wc;
	var link = "http://www.travelgrove.com/cgi-bin"+siteType+"/link_counter_new.cgi?merchant="+mName+"&intitem="+mId+params;
	window.open(link,"_blank",myWinCoord);
	return true;
}
function ppups(frm, st) {
	if(!frm) return true;
	siteType = (st!=undefined && st=='air') ? '' : '/hotels';
	params = setParams(frm);
	if(frm.dest!=undefined)
		if(details = frm.dest.value.match(/(.*),\s?([a-zA-Z]+)/)) {
			params += '&destination='+details[1];
			params += details[2].length>2 ? '&country='+details[2] : '&state='+details[2];
		} else
			params += '&destination='+frm.dest.value;
	if(frm.fromAir!=undefined && frm.toAir!=undefined) {
		var fAirCity = tAirCity= '';
		var idx = frm.fromAir.value.indexOf("(");
		if(idx >= 0) {
			fAirCity = frm.fromAir.value.substring(0,idx-1);
			fAir = frm.fromAir.value.substring(idx+1, frm.fromAir.value.length-1);
		} else fAir = frm.fromAir.value;
		idx = frm.toAir.value.indexOf("(");
		if(idx >= 0) {
			tAirCity = frm.toAir.value.substring(0,idx-1);
			tAir = frm.toAir.value.substring(idx+1, frm.toAir.value.length-1);
		} else tAir = frm.toAir.value;
		params += '&fromair='+fAir+'&fromAirCity='+fAirCity+'&toair='+tAir+'&toAirCity='+tAirCity;
	}
	$('#'+frm.id+' input[@type=checkbox]').each(function() {
		if(this.checked) jump(this.value, this.name, siteType);
	});
	return false;
}

function validate() {
	var df= document.forms.destHotels;
	var msg="";

	var d1=df.day1.value;
	var m1=df.month1.value-1;
	var y1=df.year1.value;
	var d2=df.day2.value;
	var m2=df.month2.value-1;
	var y2=df.year2.value;
	var dep = new Date();
	dep.setFullYear(y1,m1,d1);
	var arr = new Date();
	arr.setFullYear(y2,m2,d2);
	var today=new Date();
	var chnr=df.children.value;

	if (df.dest.value=="") msg+=arrCityError+"\n";
	if (dep<today) msg+=_nonTargetednegDateError+"\n";
	if (arr<dep) msg+=dateError+"\n";
	var cherror=false;
	if(chnr>0) for(var i=1; i<=chnr; i++) if($("#child"+i+"age")[0].value < 2) cherror=true;
	if (cherror) msg+=chAgeError+"\n";
	if (msg) {alert(errorMsg+"\n"+msg);return false;}
	return true;
}

function showpopup(pName){
	$(function() {
		var w = $('#'+pName)[0];
		if (w) {
			w.style.visibility = 'visible';
			return false;
		} else createWindow(pName);
		return true;
	});
}

function hidepopup(pName){$('#'+pName).css("visibility","hidden");return true}

function createWindow(win) {
	var leftPos = noTarget ? calcLeftPosNoTarget() : calcLeftPos();
	if (win=="childrenpopup") var topPos = $("a.ppLink")[0].offsetTop;
	if (win=="whyselected") var topPos = noTarget ? $("a.ppLink")[1].offsetTop : $("a.ppLink")[1].offsetTop-18;
	$.post("/ajax/popupwindow.php",{window : win,mname:selectedMerchantName,language:document.forms.destHotels.searchsystem.value,leftPos:leftPos,topPos:topPos},function(data) {$(document.body).append(data).ready(function(){Rounded("#"+win,"#fff","#87A4C2");});});
}

function calcLeftPos() {return $("a.ppLink")[0].offsetLeft-520;};
function calcLeftPosNoTarget() {return $("a.ppLink")[0].offsetLeft-520;};