// JavaScript Document

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



function clr_txt() { 
// clear the postcode search

if (document.getElementById('dest_postcode').value == "Enter a Postcode") {
	document.getElementById('dest_postcode').maxLength = 8;
	document.getElementById('dest_postcode').style.color = "#000";
	document.getElementById('dest_postcode').value = "";
}
}


function chk_txt() {
	
if ( (document.getElementById('dest_postcode').value == "Enter a Postcode") || (document.getElementById('dest_postcode').value == '') ) {
	alert ('Please enter a postcode.');
	return false;
}
}

function set_txt_onload() {
// set the postciode search txt onload
	document.getElementById('dest_postcode').maxLength = 30;
	document.getElementById('dest_postcode').style.color = "#990000";
	document.getElementById('dest_postcode').value = "Enter a Postcode";
}


function ShowHideContent(tid) {
	
if(document.getElementById(tid).style.display == "none") {
	document.getElementById(tid).style.display = "";
	return;
	} 


if(document.getElementById(tid).style.display == "") {
	document.getElementById(tid).style.display = "none";
	return;
	} 

}



function ShowContent(tid) {
		
if(document.getElementById(tid).style.display == "none") {
	document.getElementById(tid).style.display = "";
	} 
}// end function


function HideContent(tid) {
		
if(document.getElementById(tid).style.display == "") {
	document.getElementById(tid).style.display = "none";
	} 
}// end function


function set_focus_after_delay () {
/*Set focus to a control after a delay.
The set focus event in IE was not working - as maybe the OnLoad call was happening before the DOM loaded. (The Rounded DIV cbb was causing the problem)
This was the simplest way to fix anyway.*/
setTimeout("document.getElementById('StreetName').focus();",100);
}


function reset_step_one () {
// attached to the unload event of the page to ensure that progress animation is removed when going BACK to the page with browser back button.
//ShowContent('street');	
//HideContent('wait');
//HideContent('postcode_div');

}

function hide_progress_div () {
// attached to the unload event of the page to ensure that progress animation is removed when going BACK to the page with browser back button.
//HideContent('wait');
}


	
function SubmitByJS (form_name,form_action) {
//This function allows you to show a progress GIF on form submit and works in IE also.

//In IE any animation on the page is frozen on the first frame if a form is submitted using the  submit button and the form's action="" attrubute. This also happens if you use the onsubmit="" attribute, This function circumvents this problem by having the action attribute assigned by javascript - and JS submit the form also.

window.status = 'Searching, please wait';
document.getElementById(form_name + '_submit').disabled = true;//disable the submit button
document.getElementById(form_name).action = form_action;//set forms action
document.getElementById(form_name).submit();//submit form via JS


//show hide animations - feed in Form Name
switch (form_name) {

case "step1":
	//For Step 1 
	HideContent('street');
	// HideContent('postcode_div');
	ShowContent('wait');
	break
	
case "step2":
	//For Step 2
	HideContent('locality_select');
	ShowContent('wait');
	break

case "step3":
	//For Step 2
	HideContent('prop_list');
	ShowContent('wait');
	break
	
case "step4":
	//For Step 4
	HideContent('round_address');
	HideContent('address_text');
	ShowContent('wait');
	break
	
case "step5":
	//For Step 5
	ShowContent('wait_address');
	break
	
}//end switch

return true;

} //end function



//Original Function Pre - GIS removal of Postcode search

/*function check_step1_fields () {
	
	if  ( (document.getElementById('StreetName').value == "" ) && (document.getElementById('Postcode').value == "" ) ) {
		alert('Please enter either a Street Name \n\n .... or a Postcode and click on "Next"');
		document.getElementById('StreetName').focus();			
	return false;
	} 
	
	//IF - Postcode has en entry - check it using Postcode Validation script
	else if  (document.getElementById('Postcode').value != "" ) {
			return testPostCode ();
	} 
	
	else {
	// Else - All OK hide existing DIVS & show animation
	SubmitByJS('step1','step2.cfm');
	}
	
	
	
}// end function*/


function check_step1_fields () {
	
	
	if  (document.getElementById('StreetName').value == "" ) {
		alert('Please enter a Street Name and click on "Next"');
		document.getElementById('StreetName').focus();			
	return false;
	} 
	
	else {
	// Else - All OK hide existing DIVS & show animation
	SubmitByJS('step1','step2.cfm');
	}
	
	
	
}// end function


function disable_postcode() {

//Clear text within
document.getElementById('Postcode').value = ''; 
//set hidden flag

}// end function


function disable_streetname() {

//Disable postcode field & Clear text within 
document.getElementById('StreetName').value = ''; 
//set hidden flag

}// end function



function check_select (option) {
//check if any option has been chosen	
	
if(document.getElementById(option).selectedIndex >= 0) {
	
//an option has been selected - all ok show the progress gif
switch (option) {

case 'SelectLocality':
	//send to our submit function with params
	SubmitByJS('step2','step3.cfm');
break
	
case 'getpropertiesaction_delim_str':
	SubmitByJS('step3','step4.cfm');
break	
	
	
}// end switch
	
} 

// else no option selected
else {
	
	if (option == 'SelectLocality') {
		alert('Please select your street name from the list below then click "Next" \n\nOr alternatively click "Back" to perform a different search.');		
	}
	
	if (option == 'getpropertiesaction_delim_str') {
		alert('Please select an address from the list below and click "Next" \n\nOr alternatively click "Back" to select a different street name.');		
	}

	return false;
} 


}// end function


/*In IE hitting ENTER after filling in Search box did not submit the form properly.
This code detects user pressing 'enter' and submits the form.
Have to create a new element and then hide it!!*/
function submitenter(myForm,e) {
var keycode;
if(window.event) { 
keycode = window.event.keyCode;
}
else if (e) { 
keycode = e.which;
}
if(keycode == 13){
var newInput = document.createElement('input');
newInput.type = 'text';
newInput.name = 'StreetName';
myForm.appendChild(newInput);
//hide the input thats been created - if we leave it visible the Progress GIF doesn't animate for some reason
newInput.style.display = "none";
myForm.submit();
}
}

