function fnDateToText(argYear,argMonth,argDate,id){
	var jsDate ="";
	var vYear = parseInt(argYear);
	var vMonth = parseInt(argMonth); 
	var vMonth = parseInt(argMonth);
	vMonth = argMonth  - 1 ;
	var vDate = parseInt(argDate); 
	var vWeekDays = new Array("Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday");
	var vMonthNames = new Array("Jan", "Feb", "Mar","Apr", "May", "Jun", "Jul", "Aug", "Sep","Oct", "Nov", "Dec");
	jsDate  = new Date(argYear,vMonth,argDate);
	var month = jsDate.getMonth();
	var day = jsDate.getDay();
	var date = jsDate.getDate();
	var year = jsDate.getFullYear();
	var vTextDate =vWeekDays[day] + ", " +vMonthNames[month]+" "+date+" "+year;
}

function fnChangeClass(id){
	document.getElementById(id).style.color = "#000000";
	 document.getElementById(id).value = "";
}

function   fnDateCls(id){
	document.getElementById(id).style.color = "#000000";
	if(document.getElementById(id).value == 'mm/dd/yyyy'){
		 document.getElementById(id).value="";
	}	 
}

function fnDateCount(fromDate,toDate){
    var dtStDate = new Date(fromDate);
    var dtEndDate = new Date(toDate);
    var one_day=1000*60*60*24;  
    if(dtStDate !="NaN" &&  dtEndDate !="NaN") {
   	    return Math.ceil((dtEndDate.getTime()-dtStDate.getTime())/(one_day));
   }
}

/*	fnOnBlur Function is used for ajax search  */ 

function fnOnBlur(){
	var from = document.getElementById('txt_from_code').value;
	var to = document.getElementById('txt_to_code').value;
	var leave = document.getElementById('leave_date').value;
	var retn = document.getElementById('return_date').value;
	var trvlrs = document.getElementById('adult').value;
	var vTripType = 2;	

	if(vTripType == 2) {
		if( (from == '' || from=='Enter City or Airport Code') ||  (to =='' || to=='Enter City or Airport Code') || (leave == '' || leave =='mm/dd/yyyy' || leave =='mm/dd/yyyy') || (retn == '' || retn=='mm/dd/yyyy' || retn=='mm/dd/yyyy') ){

		}else{
			var leave = document.getElementById('leave_date').value;
			var retn = document.getElementById('return_date').value;
			var vFromCityCheck = 1;
			var vToCityCheck = 1;		
			var from = document.getElementById('txt_from_code').value;
			var to = document.getElementById('txt_to_code').value;	
			var vLeaveDate  = fnDateCheck('leave_date');
			if(vTripType == '2'){
				var vReturnDate = fnDateCheck('return_date');
			}else{
				vReturnDate =1;
				retn ="&nbsp;";
			}
			if((vLeaveDate =='1') && (vReturnDate=='1')){
				var vDayCount =  fnDateCount(leave,retn);
				if(vDayCount < 0){
			  		vReturnDate =0;
				}
			}
			if(((from=='' || from=='Enter City or Airport Code') || (to=='' || to=='Enter City or Airport Code'))&&((leave=='' || leave=='mm/dd/yyyy' ) || (retn=='' || retn=='mm/dd/yyyy' ) )){
				alert("Please enter your CITY & DATE flight details to compare airfares at top sites.");
				return false;
			}else if( (from=='' || from=='Enter City or Airport Code') || (to=='' || to=='Enter City or Airport Code or City Code ') ) {
				alert("Please enter your CITY & DATE flight details to compare airfares at top sites.");
				return false;
			}else if( (leave=='' || leave=='mm/dd/yyyy' ) || (retn=='' || retn=='mm/dd/yyyy' ) ) {
				alert("Please enter your CITY & DATE flight details to compare airfares at top sites.");
				return false;
			}else if((vFromCityCheck == 0) && (vToCityCheck == 0) && (vLeaveDate == 0) && (vReturnDate == 0)) {
				alert("Unrecognized departure, destination airport, please check and reenter.");
				document.getElementById('txt_from_code').value = "";
				document.getElementById('txt_to_code').value = "";
				document.getElementById('leave_date').value = "";
				document.getElementById('return_date').value = "";
				document.getElementById('txt_from_code').focus();
			}else if((vFromCityCheck == 0) && (vToCityCheck == 0)  ){
				alert("Unrecognized departure, destination airport, please check and reenter.");
				document.getElementById('txt_from_code').value = "";
				document.getElementById('txt_to_code').value = "";
				document.getElementById('txt_from_code').focus();
			}else if(vFromCityCheck == 0){
				alert("Unrecognized departure airport, please check and reenter.");
				document.getElementById('txt_from_code').value = "";
				document.getElementById('txt_from_code').focus();
				return false;
			}else if(vToCityCheck == 0){
				alert("Unrecognized destination airport, please check and reenter.");
				document.getElementById('txt_to_code').value = "";
				document.getElementById('txt_to_code').focus();
				return false;
			}else if((vLeaveDate == 0) && (vReturnDate == 0)  ){
				alert("Please enter a valid DEPARTURE Date. (mm/dd/yyyy).");
				document.getElementById('leave_date').value = "";
		   		document.getElementById('return_date').value = "";
		   		document.getElementById('leave_date').focus();
		   		return false;
			}else if(vLeaveDate == 0){
		   		alert("Please enter a valid DEPARTURE Date. (mm/dd/yyyy)");
		   		document.getElementById('leave_date').value = "";
		   		document.getElementById('leave_date').focus();
		   		return false;
			}else if(vReturnDate == 0){
		   		alert("Please enter a valid RETURN Date. (mm/dd/yyyy).");
		   		document.getElementById('return_date').value = "";
		   		document.getElementById('return_date').focus();
		   		return false;
			}
		}
	}
}

/********************************************************************************/

/*										*/

/* Function name: fnGetAirportCodeFromCity					*/

/* Description: A function to get the airport code which is with in () 		*/

/*		of cty name							*/

/* Params: argCity - Gets the city name,	 				*/

/* Return Value: Airport code with in the parantesis().				*/

/*										*/

/********************************************************************************/

function fnGetAirportCodeFromCity(argCity){
	var vCity = argCity;
	var vIndex = vCity.indexOf('(');
	vIndex++;
	return vCity.substr(vIndex,3);
}

/* General Ajax Coding Start  */
function GetXmlHttpObject(){
	var xmlHttp=null;
	try
	{
		 // Firefox, Opera 8.0+, Safari
		 xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	if (xmlHttp==null)
	{
		 alert ("Browser does not support HTTP Request")
		 return
	}
	return xmlHttp;
}
/* General Ajax Coding End */


function fnSubsTring(argValue,argStart,argEnd){
	if (argValue != undefined) {
		return argValue.substring(argStart,argEnd)
	} 
	return "";
}

function fnGotoURL(url){
	window.location.href=url;
}

function fnReload(){
	var vUrl = document.getElementById("search_travelselect").value;
	if(vUrl !=""){
		document.travel.action = vUrl;
		document.travel.submit();
	}	
}

/***************************************/
function fn_selection_option(x,m){
		msg = "";
		v_temp_from_code = document.getElementById("txt_from_code").value;
		v_temp_to_code = document.getElementById("txt_to_code").value;
		
		
		
		if(v_temp_from_code!="Enter City or Airport Code"){
			arr_from_1 = v_temp_from_code.split("(");
			if(arr_from_1!=""){
				arr_from_2 = arr_from_1[1].split(")");
				v_city_1 = arr_from_2[0];
				//alert(v_city_1)
			}
		}
		
		if(v_temp_to_code!="Enter City or Airport Code"){
			arr_to_1 = v_temp_to_code.split("(");
			if(arr_to_1!=""){
				arr_to_2 = arr_to_1[1].split(")");
				v_city_2 = arr_to_2[0];
				//alert(v_city_2)
			}
		}
		
		v_date_1 = document.getElementById("leave_date").value;
		v_date_2 = document.getElementById("return_date").value;
		v_adult = document.getElementById("adult").value;
		
		if($jq("#round_trip").attr('checked')==true){
			v_flight_type = "2";
		}else if($("#one_way_trip").attr('checked')==true){
			v_flight_type = "1";
		}
		
//		alert(v_flight_type);
//		return false;
		if(v_date_2=="mm/dd/yyyy"){
			v_date_2 = "";
		}
		
		if(document.getElementById("flight").checked==true){
			
			if(v_temp_from_code=="" || v_temp_from_code == "Enter City or Airport Code"){
				msg += "Please enter from details\n";
			}
			
			if(v_temp_to_code=="" || v_temp_to_code == "Enter City or Airport Code"){
				msg += "Please enter to details\n";
			}
			
			if(v_date_1=="" || v_date_1 == "mm/dd/yyyy"){
				msg += "Please enter leave date\n";
			}
			
			if(v_flight_type=="2"){
				if(v_date_2=="" || v_date_2 == "mm/dd/yyyy"){
					msg += "Please to leave date\n";
				}
			}
			
		}else if(document.getElementById("hotel").checked==true){
			
			if(v_temp_from_code=="" || v_temp_from_code == "Enter City or Airport Code"){
				msg += "Please enter city details\n";
			}
			
			if(v_date_1=="" || v_date_1 == "mm/dd/yyyy"){
				msg += "Please enter check-in date\n";
			}
			
		}else if(document.getElementById("car").checked==true){
			
			if(v_temp_from_code=="" || v_temp_from_code == "Enter City or Airport Code"){
				msg += "Please enter city details\n";
			}
			
			if(v_date_1=="" || v_date_1 == "mm/dd/yyyy"){
				msg += "Please enter check-in date\n";
			}
			
		}
		
		if(msg==""){
			if(document.getElementById("flight").checked==true){
				
//				if(m=="1"){
//					if(v_date_2==""){
//						v_flight_type = "1";
//					}else{
//						v_flight_type = "2";
//					}
//				}
				
				v_url = "http://www.bookingwiz.com/iframe_sb_redirect.asp?";
				v_query = "singlemenu=air&process=referrer&fm_mic="+x+"&flighttype="+v_flight_type+"&city1="+v_city_1+"&city2="+v_city_2+"&fm_datecalc=0&date1="+v_date_1+"&date2="+v_date_2+"&adults="+v_adult+"&children=0";
				v_full_url = v_url+v_query;
				//alert(v_url+v_query);
			}else if(document.getElementById("hotel").checked==true){
//				if(v_date_2=="" || v_date_2 == "mm/dd/yyyy"){
//					alert("Please enter return date\n");
//					return false;
//				}
				v_url = "http://www.bookingwiz.com/iframe_sb_redirect.asp?";
				v_query = "singlemenu=hotel&process=referrer&fm_mic="+x+"&city1="+v_city_1+"&fm_datecalc=0&date1="+v_date_1+"&date2="+v_date_2+"&adults="+v_adult+"&children=0&rooms=1";
				v_full_url = v_url+v_query;
				//alert(v_url+v_query);
			}else if(document.getElementById("car").checked==true){
//				if(v_date_2=="" || v_date_2 == "mm/dd/yyyy"){
//					alert("Please enter return date\n");
//					return false;
//				}
				v_url = "http://www.bookingwiz.com/iframe_sb_redirect.asp?";
				v_query = "singlemenu=car&process=referrer&fm_mic="+x+"&city1="+v_city_1+"&fm_datecalc=0&date1="+v_date_1+"&date2="+v_date_2;
				//alert(v_url+v_query);
				v_full_url = v_url+v_query;
			}
			if(v_full_url!=""){
				window.open(v_full_url,"_blank");
			}
		}else{
			alert(msg);
			return false;
		}
		
	}
	
	
function fn_change_label(x){
	if(x=="flight"){
		$("#label_city_1").html('Leaving From:');
		$("#label_city_2").html('Going to:');
		$("#label_date_1").html('Departing:');
		$("#label_date_2").html('Returning:');
		$("#label_adult").html('Adults:');
		$("#input_adult").show();
		$("#label_adult").show();
		$("#label_date_2").show();
		$("#input_date_2").show();
		$("#label_city_2").show();
		$("#input_city_2").show();
	}else if(x=="hotel"){
		$("#label_city_1").html('City:');
		$("#label_city_2").hide();
		$("#input_city_2").hide();
		$("#label_date_1").html('Check-in:');
		$("#label_date_2").html('Check-out:');
		$("#label_adult").html('Adults:');
		$("#input_adult").show();
		$("#label_adult").show();
		$("#label_date_2").show();
		$("#input_date_2").show();
	}else if(x=="car"){
		$("#label_city_1").html('City:');
		$("#label_city_2").hide();
		$("#input_city_2").hide();
		$("#label_date_1").html('Check-in:');
		$("#label_date_2").hide();
		$("#input_date_2").hide();
		$("#label_adult").hide();
		$("#input_adult").hide();
	}
}

function fn_call_page(){
       $.ajax({
  type: "post",
  url: "email_subscribe_pro.php",
  data: {txt_subs_email:$("#txt_subs_email").val()},
  success: function(msg){
//    alert( msg );
    $("#dvClose").show();
    $("#pop_up").show();
		$("#pop_up").html(msg);
		
		//$("#pop_up").set;
	//	$("div.pop_up").delay(1000);
		setTimeout(function(){ 
			$("#pop_up").fadeOut('slow');
			$("#dvClose").hide();
		 }, 3500);
//		setTimeout(function () {$("#pop_up")}, 10);
		
		
  }
});
}

function megaHoverOver(){
					
	$(this).find(".sub").stop().fadeTo('fast', 1).show();
		
	//Calculate width of all ul's
	(function($) { 
		jQuery.fn.calcSubWidth = function() {
			rowWidth = 0;
			//Calculate row
			$(this).find("ul").each(function() {					
				rowWidth += $(this).width(); 
			});	
		};
	})(jQuery); 
	
	if ( $(this).find(".row").length > 0 ) { //If row exists...
		var biggestRow = 0;	
		//Calculate each row
		$(this).find(".row").each(function() {							   
			$(this).calcSubWidth();
			//Find biggest row
			if(rowWidth > biggestRow) {
				biggestRow = rowWidth;
			}
		});
		//Set width
		$(this).find(".sub").css({'width' :biggestRow});
		$(this).find(".row:last").css({'margin':'0'});
		
	} else { //If row does not exist...
		
		$(this).calcSubWidth();
		//Set Width
		$(this).find(".sub").css({'width' : rowWidth});
		
	}
}

function megaHoverOut(){ 
  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
	  $(this).hide(); 
  });
}
