function onload_procedures(){
	add_event_listeners();
	//setTimeout('alert("TEST ALERT BOX")',2000);
	document.getElementById('app1_christian_names').focus();
}//end function
function referral_source_select_changed(){
	if(document.getElementById('referral_source').selectedIndex==6){
		document.getElementById('referral_source_2').disabled=false;
		document.getElementById('referral_source_2').focus();
	}else{
		document.getElementById('referral_source_2').value="";
		document.getElementById('referral_source_2').disabled=true;
	}//end if
}//end function
function submit_application_clicked(){
		//if(invalid_field_entries()){return;}
		if(document.getElementById('app1_christian_names').value.length==0 && document.getElementById('app1_surname').value.length==0){
			temp();//return;
		}//end if
		var elements_array_raw=document.getElementsByTagName('*');
		var string="";
		var data_string="";
		id_array=[];
		for(var i=0;i<elements_array_raw.length;i++){
			element_id=""+elements_array_raw[i].getAttribute("id");
			if(check_if_element_should_be_included(element_id)){
				data_string+=element_id+"-key_value_sep-"+url_character_replacement(document.getElementById(element_id).value)+"-element_sep-";
			}//end if
		}//end for
		data_string+="app1_date_of_birth-key_value_sep-"+document.getElementById('app1_dob_year').value+"-"+document.getElementById('app1_dob_month').value+"-"+document.getElementById('app1_dob_day').value;
		//data_string=data_string.substr(0,data_string.length-13);
		//document.getElementById('main_panel_text_container1').innerHTML=data_string;return;
		document.getElementById('main_panel_text_container1').innerHTML=submitting_your_application_html();
		//Make AJAX CALL
			var url="applicationfull.php?submit_application=true&data_string="+data_string;
			xmlHttp="";
			// code for IE7+, Firefox, Chrome, Opera, Safari
			if (window.XMLHttpRequest){
				xmlHttp=new XMLHttpRequest();
			}else{ 
				// code for IE6, IE5
				if (window.ActiveXObject){
				
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}else{
					alert("Your browser does not support XMLHTTP!");
				}//end if
			}//end if
			xmlHttp.onreadystatechange = processStateChange;
			
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
}//end function
function check_if_element_should_be_included(element_id){
	if(element_id.substr(0,5)=="app1_" && element_id.substr(0,9)!="app1_dob_"){return 1;}
	if(element_id.substr(0,9)=="referral_"){return 1;}
	if(element_id.substr(0,10)=="sys_option"){return 1;}
	return 0;
}//end function
function thank_you_for_your_application_html(){
		var return_string='<table border="0" cellpadding="2" cellspacing="2" width="100%"><tbody><tr><td>&nbsp;</td></tr><tr><td style="font-family: Times New Roman,Times,serif; font-size: 24px; font-weight: bold;" align="center">Thank you for your Application.</td></tr><tr><td style="font-family: Times New Roman,Times,serif; font-size: 18px; text-align: center;">We will contact you shortly in regard to processing your application. All processing of applications is done during business hours Monday to Friday. If you have any questions or wish to check on the progress of your application, please contact our office at anytime, via phone or email.</td></tr></tbody></table>';
		return return_string;
}//end function
function submitting_your_application_html(){
		var return_string='<table border="0" cellpadding="2" cellspacing="2" width="100%"><tbody><tr><td>&nbsp;</td></tr><tr><td style="font-family: Times New Roman,Times,serif; font-size: 24px; font-weight: bold; color: #ff0000;" align="center">Submitting your Application.</td></tr><tr><td align="center"><img src="./images/ajax-loader.gif" height="15" width="128"></td></tr></tbody></table>';
		return return_string;
}//end function
// URL Charcater Replacement - version 1.0
function url_character_replacement(pre_convert_string){
		var working_string=pre_convert_string;
		working_string=str_replace("'", "-apos-", working_string);
		working_string=str_replace("&", "-amp-", working_string);

		working_string=str_replace(",", "-comma-", working_string);
		working_string=str_replace('"', "-double_quotes-", working_string);
		working_string=str_replace("<", "-less_than-", working_string);
		working_string=str_replace(">", "-greater_than-", working_string);
		working_string=str_replace("!", "-exclamation-", working_string);
		return working_string;
}//end function
function processStateChange(){
					if(xmlHttp.readyState==4){
					return_string=xmlHttp.responseText;
					//document.getElementById('output_area_1').innerHTML=return_string;
					document.getElementById('main_panel_text_container1').innerHTML=thank_you_for_your_application_html();
					//document.getElementById('main_panel_text_container1').innerHTML=return_string;
					//remove_popup_css_panel(note_panel_id);
					//alert(return_string);return;
					//document.form1.submit();
				}
	}//end function
function str_replace(search, replace, subject) {
					// *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
					// *     returns 1: 'Kevin.van.Zonneveld'
					// *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
					// *     returns 2: 'hemmo, mars'
					
					var f = search, r = replace, s = subject;
					var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 					while (j = 0, i--) {
					if (s[i]) {
						while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
					}
					};
					return sa ? s : s[0];
}//end function
function app1_marital_stat_changed(){
	if(document.getElementById("app1_marital_stat").selectedIndex==1 ||document.getElementById("app1_marital_stat").selectedIndex==2){
		document.getElementById("app1_partners_name").disabled=false;
		document.getElementById("app1_partners_name").focus();
	}else{
		document.getElementById("app1_partners_name").value="";
		document.getElementById("app1_partners_name").disabled=true;
	}//end if
}//end function
function temp(){//alert(document.getElementById("sys_option1").type);
		var elements_array_raw=document.getElementsByTagName('*');
		var string="";
		var data_string="";
		id_array=[];
		for(var i=0;i<elements_array_raw.length;i++){
			element_id=""+elements_array_raw[i].getAttribute("id");
			if(check_if_element_should_be_included(element_id)){
				if(document.getElementById(element_id).type=="text"){
					document.getElementById(element_id).value="TestData";
				}//end if
				if(document.getElementById(element_id).type=="select-one"){
					document.getElementById(element_id).selectedIndex=1;
				}//end if
				if(document.getElementById(element_id).type=="textarea"){
					document.getElementById(element_id).value="TestData";
					document.getElementById(element_id).innerHTML="TestData";
				}//end if
			}//end if
		}//end for
		document.getElementById("app1_dob_day").selectedIndex=3;
		document.getElementById("app1_dob_month").selectedIndex=3;
		document.getElementById("app1_dob_year").selectedIndex=3;
}//end function
function invalid_field_entries(){
	if(document.getElementById('referral_source').selectedIndex==0){
		alert("Please tell us where you heard about us in the Marketing Section");
		return 1;
	}//end if
	return 0;
}//end function
function address_as_above_clicked(){
	if(document.getElementById("address_as_above").checked==true){
		document.getElementById("app1_post_address1").value=document.getElementById("app1_res_address1").value;
		document.getElementById("app1_post_suburb").value=document.getElementById("app1_res_suburb").value;
		document.getElementById("app1_post_city").value=document.getElementById("app1_res_city").value;
		document.getElementById("app1_post_state").selectedIndex=document.getElementById("app1_res_state").selectedIndex;
		document.getElementById("app1_post_postcode").value=document.getElementById("app1_res_postcode").value;
		document.getElementById("app1_post_address1").disabled=true;
		document.getElementById("app1_post_suburb").disabled=true;
		document.getElementById("app1_post_city").disabled=true;
		document.getElementById("app1_post_state").disabled=true;
		document.getElementById("app1_post_postcode").disabled=true;

	}else{
		document.getElementById("app1_post_address1").value="";
		document.getElementById("app1_post_suburb").value="";
		document.getElementById("app1_post_city").value="";
		document.getElementById("app1_post_state").selectedIndex=0;
		document.getElementById("app1_post_postcode").value="";
		document.getElementById("app1_post_address1").disabled=false;
		document.getElementById("app1_post_suburb").disabled=false;
		document.getElementById("app1_post_city").disabled=false;
		document.getElementById("app1_post_state").disabled=false;
		document.getElementById("app1_post_postcode").disabled=false;
	}//end if
}//end function
function test6(){
	alert("TEST6");
}//end function
function add_event_listeners(){
//document.getElementById('app1_res_address1').attachEvent('paste', address_field_changed);
//attachEvent("paste","app1_res_address1",address_field_changed);
	if(window.addEventListener){ // Mozilla, Netscape, Firefox
		document.getElementById('app1_res_address1').addEventListener('paste', 
						function(e){
							setTimeout('address_field_changed()',50);
						}, false
				);
		document.getElementById('app1_res_suburb').addEventListener('paste', 
						function(e){
							setTimeout('address_field_changed()',50);
						}, false
				);
		document.getElementById('app1_res_city').addEventListener('paste', 
						function(e){
							setTimeout('address_field_changed()',50);
						}, false
				);
		document.getElementById('app1_res_postcode').addEventListener('paste', 
						function(e){
							setTimeout('address_field_changed()',50);
						}, false
				);
		document.getElementById('app1_res_address1').addEventListener('cut', 
						function(e){
							setTimeout('address_field_changed()',50);
						}, false
				);
		document.getElementById('app1_res_suburb').addEventListener('cut', 
						function(e){
							setTimeout('address_field_changed()',50);
						}, false
				);
		document.getElementById('app1_res_city').addEventListener('cut', 
						function(e){
							setTimeout('address_field_changed()',50);
						}, false
				);
		document.getElementById('app1_res_postcode').addEventListener('cut', 
						function(e){
							setTimeout('address_field_changed()',50);
						}, false
				);
	}else{
		//document.getElementById('app1_res_address1').attachEvent('paste', address_field_changed);
	}//end if
}//end function
function address_field_changed(){
		if(document.getElementById("address_as_above").checked==false){return;}
		document.getElementById("app1_post_address1").value=document.getElementById("app1_res_address1").value;
		document.getElementById("app1_post_suburb").value=document.getElementById("app1_res_suburb").value;
		document.getElementById("app1_post_city").value=document.getElementById("app1_res_city").value;
		document.getElementById("app1_post_state").selectedIndex=document.getElementById("app1_res_state").selectedIndex;
		document.getElementById("app1_post_postcode").value=document.getElementById("app1_res_postcode").value;
}//end function

