function ins_form_validate(){
	try{
		var tmp_txt_name = xhanch_get_obj("txt_name");
		var tmp_txt_address = xhanch_get_obj("txt_address");
		var tmp_txt_post_code = xhanch_get_obj("txt_post_code");
		var tmp_txt_phone = xhanch_get_obj("txt_phone");
		var tmp_txt_email = xhanch_get_obj("txt_email");
		var tmp_txt_further_detail = xhanch_get_obj("txt_further_detail");
		var tmp_cbo_type = xhanch_get_obj("cbo_type");
		var tmp_txt_year = xhanch_get_obj("txt_year");
		var tmp_txt_post_code_holiday = xhanch_get_obj("txt_post_code_holiday");
		var tmp_txt_renewal = xhanch_get_obj("txt_renewal");
		var tmp_cbo_best_time = xhanch_get_obj("cbo_best_time");

		if(tmp_txt_name.value == ""){
			tmp_txt_name.focus();
			xhanch_catch_error("Please type in your Name");
		}
		if(tmp_txt_address.value == ""){
			tmp_txt_address.focus();
			xhanch_catch_error("Please type in your First line of address");
		}
		if(tmp_txt_post_code.value == ""){
			tmp_txt_post_code.focus();
			xhanch_catch_error("Please type in your Postcode");
		}
		if(tmp_txt_phone.value == ""){
			tmp_txt_phone.focus();
			xhanch_catch_error("Please type in your Phone");
		}
		if(tmp_txt_email.value == ""){
			tmp_txt_email.focus();
			xhanch_catch_error("Please type in your Email");
		}
		if(tmp_txt_further_detail.value == ""){
			tmp_txt_further_detail.focus();
			xhanch_catch_error("Please type in your Further enquiry details");
		}
		if(tmp_cbo_type.value == ""){
			tmp_cbo_type.focus();
			xhanch_catch_error("Please select a Type of insurance");
		}
		if(tmp_txt_year.value == ""){
			tmp_txt_year.focus();
			xhanch_catch_error("Please type in your Year of manufacture");
		}
		if(tmp_txt_post_code_holiday.value == ""){
			tmp_txt_post_code_holiday.focus();
			xhanch_catch_error("Please type in your Postcode of storage/holiday site");
		}
		if(tmp_txt_renewal.value == ""){
			tmp_txt_renewal.focus();
			xhanch_catch_error("Please type in your Renewal date");
		}
		if(tmp_cbo_best_time.value == ""){
			tmp_cbo_best_time.focus();
			xhanch_catch_error("Please select a Best time to call");
		}

		return true;
	}catch(e){
		alert(xhanch_get_error(e));
		return false;
	}
}

function ins_form_reset(){
	var tmp_txt_name = xhanch_get_obj("txt_name");
	var tmp_txt_address = xhanch_get_obj("txt_address");
	var tmp_txt_post_code = xhanch_get_obj("txt_post_code");
	var tmp_txt_phone = xhanch_get_obj("txt_phone");
	var tmp_txt_email = xhanch_get_obj("txt_email");
	var tmp_txt_further_detail = xhanch_get_obj("txt_further_detail");
	var tmp_cbo_type = xhanch_get_obj("cbo_type");
	var tmp_txt_year = xhanch_get_obj("txt_year");
	var tmp_txt_post_code_holiday = xhanch_get_obj("txt_post_code_holiday");
	var tmp_txt_renewal = xhanch_get_obj("txt_renewal");
	var tmp_cbo_best_time = xhanch_get_obj("cbo_best_time");

	tmp_txt_name.value = "";
	tmp_txt_address.value = "";
	tmp_txt_post_code.value = "";
	tmp_txt_phone.value = "";
	tmp_txt_email.value = "";
	tmp_txt_further_detail.value = "";
	tmp_cbo_type.value = "Static Caravan";
	tmp_txt_year.value = "";
	tmp_txt_post_code_holiday.value = "";
	tmp_txt_renewal.value = "";
	tmp_cbo_best_time.value = "9am-12pm";
}

function ins_form_submit(){
	try{
		if(!ins_form_validate())
			return;
		xhanch_ajax_disp_prg("ins_form");
		
		var tmp_txt_name = xhanch_get_obj("txt_name");
		var tmp_txt_address = xhanch_get_obj("txt_address");
		var tmp_txt_post_code = xhanch_get_obj("txt_post_code");
		var tmp_txt_phone = xhanch_get_obj("txt_phone");
		var tmp_txt_email = xhanch_get_obj("txt_email");
		var tmp_txt_further_detail = xhanch_get_obj("txt_further_detail");
		var tmp_cbo_type = xhanch_get_obj("cbo_type");
		var tmp_txt_year = xhanch_get_obj("txt_year");
		var tmp_txt_post_code_holiday = xhanch_get_obj("txt_post_code_holiday");
		var tmp_txt_renewal = xhanch_get_obj("txt_renewal");
		var tmp_cbo_best_time = xhanch_get_obj("cbo_best_time");
		
		var xhanch_misc = {
			"exec": "ins_form_submit_exec",
			"exec_done": "xhanch_ajax_disp_prg('ins_form', false);"
		};
		
		var xhanch_dat_post = {
			"txt_name": encodeURIComponent(tmp_txt_name.value),
			"txt_address": encodeURIComponent(tmp_txt_address.value),
			"txt_post_code": encodeURIComponent(tmp_txt_post_code.value),
			"txt_phone": encodeURIComponent(tmp_txt_phone.value),
			"txt_email": encodeURIComponent(tmp_txt_email.value),
			"txt_further_detail": encodeURIComponent(tmp_txt_further_detail.value),
			"cbo_type": encodeURIComponent(tmp_cbo_type.value),
			"txt_year": encodeURIComponent(tmp_txt_year.value),
			"txt_post_code_holiday": encodeURIComponent(tmp_txt_post_code_holiday.value),
			"txt_renewal": encodeURIComponent(tmp_txt_renewal.value),
			"cbo_best_time": encodeURIComponent(tmp_cbo_best_time.value),
		};

		if(!xhanch_ajax_query("ins-form-submit.php", xhanch_dat_post, xhanch_misc))
			setTimeout("ins_form_submit()", 1000);
	}catch(e){
		xhanch_ajax_hnd_err("ins_form", e);
	}
}

function ins_form_submit_exec(reply){
	try{
		xhanch_catch_error(xhanch_xml_msg(reply, "error"));
		
		var nds_res = xhanch_xml_nds_by_tag(reply, "info");
		if(nds_res.length > 0){
			ins_form_reset();
			alert("Thank you! We have received your submission.");
		}else
			xhanch_ajax_disp_prg("ins_form", false);
	}catch(e){
		xhanch_ajax_hnd_err("ins_form", e);	
	}
}
