function ins_form_validate(){
	try{
		var tmp_cbo_total_debt = xhanch_get_obj("cbo_total_debt");
		var tmp_cbo_num_creditor = xhanch_get_obj("cbo_num_creditor");
		var tmp_cbo_status = xhanch_get_obj("cbo_status");
		var tmp_txt_first_name = xhanch_get_obj("txt_first_name");
		var tmp_txt_surname = xhanch_get_obj("txt_surname");
		var tmp_txt_phone = xhanch_get_obj("txt_phone");
		var tmp_txt_email = xhanch_get_obj("txt_email");
		var tmp_chk_agree = xhanch_get_obj("chk_agree");

		if(tmp_cbo_total_debt.value == ""){
			tmp_cbo_total_debt.focus();
			xhanch_catch_error("Please select your Approximate Total Debt");
		}
		if(tmp_cbo_num_creditor.value == ""){
			tmp_cbo_num_creditor.focus();
			xhanch_catch_error("Please select How Many Creditors");
		}
		if(tmp_cbo_status.value == ""){
			tmp_cbo_status.focus();
			xhanch_catch_error("Please select your Employment Status");
		}
		if(tmp_txt_first_name.value == ""){
			tmp_txt_first_name.focus();
			xhanch_catch_error("Please type in your First Name");
		}
		if(tmp_txt_surname.value == ""){
			tmp_txt_surname.focus();
			xhanch_catch_error("Please type in your Surname");
		}
		if(tmp_txt_phone.value == ""){
			tmp_txt_phone.focus();
			xhanch_catch_error("Please type in your Phone");
		}
		if(!tmp_chk_agree.checked){
			tmp_chk_agree.focus();
			xhanch_catch_error("You have to agree with our privacy policy");
		}

		return true;
	}catch(e){
		alert(xhanch_get_error(e));
		return false;
	}
}

function ins_form_reset(){
	var tmp_cbo_total_debt = xhanch_get_obj("cbo_total_debt");
	var tmp_cbo_num_creditor = xhanch_get_obj("cbo_num_creditor");
	var tmp_cbo_status = xhanch_get_obj("cbo_status");
	var tmp_txt_first_name = xhanch_get_obj("txt_first_name");
	var tmp_txt_surname = xhanch_get_obj("txt_surname");
	var tmp_txt_phone = xhanch_get_obj("txt_phone");
	var tmp_txt_email = xhanch_get_obj("txt_email");
	var tmp_chk_agree = xhanch_get_obj("chk_agree");

	tmp_cbo_total_debt.value = "2-5";
	tmp_cbo_num_creditor.value = "1";
	tmp_cbo_status.value = "Full time Employed";
	tmp_txt_first_name.value = "";
	tmp_txt_surname.value = "";
	tmp_txt_phone.value = "";
	tmp_txt_email.value = "";
	tmp_chk_agree.checked = false;
}

function ins_form_submit(){
	try{
		if(!ins_form_validate())
			return;
		xhanch_ajax_disp_prg("ins_form");
		
		var tmp_cbo_total_debt = xhanch_get_obj("cbo_total_debt");
		var tmp_cbo_num_creditor = xhanch_get_obj("cbo_num_creditor");
		var tmp_cbo_status = xhanch_get_obj("cbo_status");
		var tmp_txt_first_name = xhanch_get_obj("txt_first_name");
		var tmp_txt_surname = xhanch_get_obj("txt_surname");
		var tmp_txt_phone = xhanch_get_obj("txt_phone");
		var tmp_txt_email = xhanch_get_obj("txt_email");
		
		var xhanch_misc = {
			"exec": "ins_form_submit_exec",
			"exec_done": "xhanch_ajax_disp_prg('ins_form', false);"
		};
		
		var xhanch_dat_post = {
			"cbo_total_debt": encodeURIComponent(tmp_cbo_total_debt.value),
			"cbo_num_creditor": encodeURIComponent(tmp_cbo_num_creditor.value),
			"cbo_status": encodeURIComponent(tmp_cbo_status.value),
			"txt_first_name": encodeURIComponent(tmp_txt_first_name.value),
			"txt_surname": encodeURIComponent(tmp_txt_surname.value),
			"txt_phone": encodeURIComponent(tmp_txt_phone.value),
			"txt_email": encodeURIComponent(tmp_txt_email.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);	
	}
}
