var options;

$(function() {
	options = {
		delay:175,
		json:true,
		loadingClass:"aLoad",
		timeout:50000,
		script:'/ajax/suggestions/airports.php',
		ajaxParams:{action:"", json:true, searchsystem:typeof(searchsystem)=='undefined' ? 'def' : searchsystem},
		format:function(selLiObj) {
			return (selLiObj.innerHTML.replace(/<\/?b>/gi,'')).replace(/(.*),(.*)\((.*)\)/,'$1 ($3)');
		},
		callback:function(){refreshMerchants();},
		errorHandler:function(asObj){
			$(asObj.fld).addClass("err").focus(remErr);
		}
	};
	as1 = new AS('fromAir', options);
	as2 = new AS('toAir', options);

	linkCounter = "http://www.travelgrove.com/" + "cgi-bin/" + "vacation/" + "link_counter_new.cgi";
	merchantsRefreshFile = "/ajax/merchants/vacation_new2.json.php";
});

function validateBox(frm){
	errorMsg	= '';
	errorClass	= '';
	var patt1	= /.*\s\(...\)/i;
	var patt2	= /[0-9]{2}\/[0-9]{2}\/[0-9]{4}/;
	var date	= new Date();
	var d1	= $(frm).find("#dep_cal").datepicker('getDate');
	var d2	= $(frm).find("#arr_cal").datepicker('getDate');
	if (!patt1.test($(frm).find("#fromAir").val())) {errorMsg += '\t'+errMsg['dep']+'\n';errorClass+="#fromAir,";}
	if (!patt1.test($(frm).find("#toAir").val())) 	{errorMsg += '\t'+errMsg['arr']+'\n';errorClass+="#toAir,";}
	if (!patt2.test($(frm).find("#dep_cal").val())) {errorMsg += '\t'+errMsg['d1']+'\n';errorClass+="#dep_cal,";}
	if (!patt2.test($(frm).find("#arr_cal").val())) {errorMsg += '\t'+errMsg['d2']+'\n';errorClass+="#arr_cal,";}
	if (d1>0 && d1<date)				{errorMsg += '\t'+errMsg['d1']+'\n';errorClass+="#dep_cal,";}
	if (d1>0 && d2>0 && d1>d2)			{errorMsg += '\t'+errMsg['d1d2']+'\n';errorClass+="#arr_cal,";}
	if ($(".mSel").length<1)			{errorMsg += '\t'+errMsg['selectOne']+'\n';}

	/*	if there are hotel rooms -> check max 4 travelers / room	*/
	if($(frm).find('#roomsVacation')) {
		var travelers	= parseInt($(frm).find('#adultsAir').val()) +
				parseInt($(frm).find('#childrenAir').val()) +
				parseInt($(frm).find('#seniorsAir').val());
		var rooms	= parseInt($(frm).find('#roomsVacation').val());
		if(travelers / rooms > 4) {
			/* errorClass	+= '#roomsVacation,'; */
			errorMsg	+= '\t'+errMsg['maxPProom']+'\n';
		}
	}

	if (errorMsg) errorMsg = errMsg['enterFirst']+'\n'+errorMsg;
	$(errorClass).addClass("err").focus(remErr);
	return errorMsg ? errorMsg : false;
};
