//javascript doc
var quoteaborted=true;
var quoterequested=false;

$("document").ready(function(){
	var window_loc_path=window.location.pathname;
	//alert(window_loc_path);
	if(/\/getaquote\/(index\.htm)?/.test(window_loc_path)==true){
		// If the page is the getaquote index page
		
		//alert('1');
		$(window).unload(lds);
	}else{// if(/\/(index-mock-quotefrm\.htm)?/.test(window_loc_path)==true){
		// If the page is the Safestyle home page
		
		//alert('2');
		$(window).unload(ldsHangingForm);
	}

});

function lds(){ 
	
	if(!quoteaborted){
		quoteaborted=true;
		return;
	}	
		
	var noofwindows=jQuery.trim($("#no_of_windows").val());
	var noofdoors=jQuery.trim($("#no_of_doors").val());
	var nooffrenchdoors=jQuery.trim($("#no_of_doors2").val());
	var title=jQuery.trim($("#title").val());
	var fname=jQuery.trim($("#name22").val());
	var surname=jQuery.trim($("#surname").val());
	var postcode=jQuery.trim($("#Postcode").val());
	var email=jQuery.trim($("#email").val());
		email=email.replace(/\s+/,'');
		//alert(email);
	var dayphone=jQuery.trim($("#phone").val());
	var eveningphone=jQuery.trim($("#evening_phone").val());
	var wherehear=jQuery.trim($("#select").val());
	if($("#AddInfo"))
		var addinfo=jQuery.trim($("#AddInfo").val());
	if($("#RefCode"))
		var refcode=jQuery.trim($("#RefCode").val());
	
		
	if((fname!='' || surname!='') && (email!='' || dayphone!='' || eveningphone!='')){
		jQuery.ajax({
		type: "POST",
		data:"mode=sendPartialQuoteFormMail&noofwindows="+noofwindows+"&noofdoors="+noofdoors+"&nooffrenchdoors="+nooffrenchdoors+"&title="+title+"&fname="+fname+"&surname="+surname+"&postcode="+postcode+"&email="+email+"&dayphone="+dayphone+"&eveningphone="+eveningphone+"&wherehear="+wherehear+"&addinfo="+addinfo+"&refcode="+refcode,
		dataType:"text",
		url: "additional-functionality.php",
		async: false,
		success: function(resp, status){result(resp)},
		error:function(){}
		});
		
	
	}
}

function ldsHangingForm(){ 
	
	if(quoterequested==true){ // checking if the user has submited a quote before moving out of the page  
		//quoteaborted=true;
		return;
	}	
	//alert("Get form data.");	
	
	var noofwindows=jQuery.trim($("#tot_window").val());
	var noofdoors=jQuery.trim($("#tot_doors").val());
	var nooffrenchdoors=jQuery.trim($("#tot_doors2").val());
	var title=jQuery.trim($("#title").val());
	var fname=jQuery.trim($("#name").val());
	var surname=jQuery.trim($("#surname").val());
	var postcode=jQuery.trim($("#user_postcode").val());
	var email=jQuery.trim($("#email").val());
		email=email.replace(/\s+/,'');
		//alert(email);
	var dayphone=jQuery.trim($("#phone").val());
	var eveningphone=jQuery.trim($("#evening_phone").val());
	var wherehear=jQuery.trim($("#select").val());
	/**/
	/*if($("#AddInfo"))
		var addinfo=jQuery.trim($("#AddInfo").val());
	*/
	var refcode='';
	if(document.getElementById("RefCode")!=null)
		refcode=jQuery.trim($("#RefCode").val());
	
		
	if((fname!='' || surname!='') && (email!='' || dayphone!='' || eveningphone!='')){
		//alert('Sending form data to the server.');
		jQuery.ajax({
			type: "POST",
			data:"mode=sendPartialQuoteFormMail&noofwindows="+noofwindows+"&noofdoors="+noofdoors+"&nooffrenchdoors="+nooffrenchdoors+"&title="+title+"&fname="+fname+"&surname="+surname+"&postcode="+postcode+"&email="+email+"&dayphone="+dayphone+"&eveningphone="+eveningphone+"&wherehear="+wherehear+"&addinfo=&refcode="+refcode,
			dataType:"text",
			url: "getaquote/additional-functionality.php",
			async: false,
			success: function(resp, status){},
			error:function(){}
		});
		
	
	}
	//alert('OK Bye');
	
}

function result(resp){
	//alert(resp);

}
