
function disableDateofCalendar(date, y, m, d) {

   var minDate = new Date();
   
   if((date.getFullYear() < minDate.getFullYear()) || (date.getFullYear() == minDate.getFullYear() && date.getMonth() < minDate.getMonth()) || (date.getFullYear() == minDate.getFullYear() && date.getMonth() == minDate.getMonth() && date.getDate() < minDate.getDate())){
   
      return true;
	  
   }
   
}

function gf_sity(value) {	
	
	var rootSelect = document.formSubmit.tairport;		
	
	var length = rootSelect.length, str = '';
	
	for(var i = 0; i < length; i++) {
	
		str = rootSelect.options[i].value;		
	
		if(str.indexOf(value) != -1) {
		
			rootSelect.value = str;
			
			break;
		
		}
	
	}	
	
}

function gf_hS(id, action) {

	$("#" + id).css('display', action);
	
}

function gf_trim(s) {

	return s.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
	
}

function gf_requestForm(domain) {	
	document.getElementById('formSubmitOn').action = 'http://' + domain + '/request-form';									
	$('#formSubmitOn').submit();
}

function gf_checkEmail(str) {

	return str.search(/^([\w\+\-]+)(\.[\w\+\-]+)*@([a-z\d\-]+\.)+[a-z]{2,6}$/i) > -1; 
	
}

function gf_checkDate(str) {

	 return str.search(/^([\d]{2})\/([\d]{2})\/([\d]{4})$/i) > -1;
			
}


function gf_resetField(id) {

	$("#" + id).css("display", "none");
	
	$("#d" + id).css("display", "none");
	
	$("#cd" + id).css("display", "none");
	
}



function gf_checkForm(type) {
	
	var depdate = $('#depdate').val();
	
	var retdate = $('#retdate').val();
	
	var gfId = type == 1 ? 'efFF' : (type == 2 ? 'bfFF' : 'gfFF');
	
	if ($('#fairport').val() == 'Select Departure'){
	
		$("#" + gfId).css("display", "block");
		
		$("#d" + gfId).css("display", "block");
		
		//alert ("You forgot to fill in where you\'re flying from!");		
		
		$('#fairport').focus();
		
		return false;
		
	}
	
	if ($('#tairport').val() == 'Select Destination'){
	
		gfId = type == 1 ? 'etFF' : (type == 2 ? 'btFF' : 'gtFF');
	
		//alert ("You forgot to fill in where you\'re flying to!");
		
		$("#" + gfId).css("display", "block");
		
		$("#d" + gfId).css("display", "block");
		
		$('#tairport').focus();
		
		return false;
		
	}
			
	if (gf_trim(depdate) == '' || !gf_checkDate(depdate)){
	
		$("#" + gfId).css("display", "block");
		
		$("#cd" + gfId).css("display", "block");
		
		//alert ("Your departure date format is not correct!");
		
		$('#depdate').focus();
		
		return false;
		
	}
		
	if ((gf_trim(retdate) == '' || !gf_checkDate(retdate)) && !$("#bf-radio-2").is(':checked')) {
		
		gfId = type == 1 ? 'etFF' : (type == 2 ? 'btFF' : 'gtFF');
		
		$("#" + gfId).css("display", "block");
		
		$("#cd" + gfId).css("display", "block");		
		
		//alert ("You forgot to fill in return date!");
		
		$('#retdate').focus();
		
		return false;
		
	}
	
	var checkdepDate = gf_parse_date(depdate);
	
	var checkretDate = gf_parse_date(retdate);
			
	if($("#one_way")&&$("#bf-radio-2")) {
		if(($("#bf-radio-2").attr('checked') == null||$("#bf-radio-2").attr('checked') == false)&& (checkretDate - checkdepDate < 0)) {
		
			alert('Please, check you return date!');
			
			return false;
			
		}
		
	}
	
	else {
	
		if(checkretDate - checkdepDate < 0) {
		 
			alert('Please, check you return date!');
			
			return false;
			
		}
		
	}
	
	if(type == 3) {		
	
		if($('#contactWay').val() == 'emailFF'){		
		 
			if(!gf_checkPhoneNumber($('#phone').val())){				
			 
				$("#phoneFF").css("display", "block");
				
				$('#phone').focus();
				
				return false;		
			}					
		}	
		else {
		
			if(gf_trim($('#phone').val()) != '') {				
			
				if(!gf_checkPhoneNumber($('#phone').val())) {
				
					$("#phoneFF").css("display", "block");
					
					$('#phone').focus();
					
					return false;		
					
				}	
			}	
			
			if(gf_trim($('#email').val()) != '') {
			
				if(!gf_checkEmail($('#email').val())) {
				
					$("#emailFF").css("display", "block");
					
					$('#email').focus();
					
					return false;		
					
				}
				
			}	
			
			else {
			
				$("#emailFF").css("display", "block");
				
				$('#email').focus();
				
				return false;		
				
			}
			
		}	
		
	}	
				
	if($("#bf-radio-3").is(':checked')) {
		
		if(gf_trim($("#openjaw").val()) == "") {
										
			gfId = type == 1 ? 'egFF' : (type == 2 ? 'bgFF' : 'ggFF');
									
			$("#" + gfId).css("display", "block");
				
			$("#openjaw").focus();				
				
			return false;
				
		}	
			
	}
			
	return true;	
	
}


function gf_parse_date(date) {	
	
	var checkDate = date.split("/");		
	
	var resDate = checkDate[2] + '' + checkDate[0] + '' + checkDate[1];	
	
	return parseInt(resDate);		
	 
}


function gf_checkPhoneNumber(str) {

	return str.search(/^([0-9]{3})+(\-)+([0-9]{3})+(\-)+([0-9]{4})$/i) > -1;
	
}


function gf_onSubmit(type, domain) {	

	var check = gf_checkForm(type);		
		
	if(check) {

		document.getElementById('formSubmit').action = 'http://' + domain + '/' + (type == 1 ? "search-specials-fly" : (type == 2 ? "search-business-fly" : "result-group-fares"));									
		
		$('#formSubmit').submit();
	
	}	

}


function changeClass(type, domain) {	

	//alert(type);
	
	document.getElementById('formSubmit').action = 'http://' + domain + '/' + (type == 1 ? "" : "business");									
	
	//alert(type);
	
	$('#formSubmit').submit();
	
}


function gf_check_req_form() {
		
	if(gf_trim($('#firstName').val()) == '') {
	
		alert ("You must to fill your First name!");
		$('#firstName').focus();
		return false;
		
	}		
	if(gf_trim($('#lastName').val()) == '') {
		alert ("You must to fill your Last name!");
		$('#lastName').focus();
		return false;
	}	
	if($('#contactWay').val() == 1){		
		if(!gf_checkPhoneNumber($('#phone').val())){				
			alert("Your Phone is not correct! Please check it and try again.");
			$('#phone').focus();
			return false;		
		}					
	}	
	else {	
		if(gf_trim($('#phone').val()) != ''){				
			if(!gf_checkPhoneNumber($('#phone').val())){
				alert("Your Phone is not correct! Please check it and try again.");
				$('#phone').focus();
				return false;		
			}	
		}	
		if(gf_trim($('#email').val()) != '') {
			if(!gf_checkEmail($('#email').val())){
				alert("Your Email is not correct! Please check it and try again.");
				$('#email').focus();
				return false;		
			}
		}		
		else{
			alert("Your Email is not correct! Please check it and try again.");
			$('#email').focus();
			return false;		
		}
	}	
	return true;	
}


function gf_subRequestForm(domain) {	

	var checkForm = gf_check_req_form();
	
	if(checkForm){
	
		document.getElementById('formSubmit').action = 'http://' + domain + '/send-form';									
		
		$('#formSubmit').submit();
		
	}
	
}
