	function hideElement(elementId) 
	{
	var element;
	if (document.all)
	element = document.all[elementId];
	else if (document.getElementById)
	element = document.getElementById(elementId);
	if (element && element.style)
	element.style.display = 'none';
	}
	function callhide()
	{
		 hideElement("h_no"); 
		 hideElement("streetname") ;
		 hideElement("t_own") ;
	}
	

		function showElement(elementId) 
		{
		var element;
		if (document.all)
		element = document.all[elementId];
		else if (document.getElementById)
		element = document.getElementById(elementId);
		if (element && element.style)
		element.style.display = '';
		}

	function removeNL(s) {
		
		
 		 /*
  		** Remove NewLine, CarriageReturn and Tab characters from a String
 		 **   s  string to be processed
		  ** returns new string
 		 */
  		r = "";
  		for (i=0; i < s.length; i++) {
   		 if (s.charAt(i) != '\n' &&
       	 s.charAt(i) != '\r' &&
       	 s.charAt(i) != '\t') {
     	 r += s.charAt(i);
      }
    }
	var lSplitArray;
	lSplitArray=r.split(",");
	r=lSplitArray[0]+" "+lSplitArray[1];
	r=r.replace("  ",", ");
 	return r;
  }
	function addOption(selectbox,text,value )
	{
		
		var optn = document.createElement("OPTION");
		
		optn.text = removeNL(text);
		optn.value =removeNL(value);
		selectbox.options.add(optn);
	}
function trimAll(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}

function populate()
{
	var lstrarray,lstrStreet,lstrCity,lctr,lstrRaw;
	lstrRaw=document.theForm.foundedaddress.value;
	lstrarray=lstrRaw.split(",");
	lstrStreet="";
	/*for(lctr=0;lctr<lstrarray.length-1;lctr++)
	{
		
		lstrStreet=lstrStreet+" "+lstrarray[lctr];
		
		
	}*/
	document.theForm.applicant1_address.value=lstrarray[0];
	//document.theForm.town.value=lstrarray[1];
	document.theForm.applicant1_city.value=lstrarray[1];
	
	}
function displayaddress()
{
	
	var lstrpostcode,larray,ctr,spacearray,check;
	lstrpostcode=document.theForm.applicant1_postcode.value;
	document.theForm.foundedaddress.disabled=false;
	check_disable=1;
	//for Development server
	//var u="http://192.168.254.93/fsnsites/healthinsurance2007_NEW/getpostcode.asp?pcode="+lstrpostcode;
	//for Online server
	var u="http://www.healthinsurance.co.uk/getpostcode.asp?pcode="+lstrpostcode;
	

		if (document.all) 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else
		 {
			xmlhttp = new XMLHttpRequest();
		}

		xmlhttp.open("GET", u,true);
		xmlhttp.onreadystatechange=function()
 		{
	  		if (xmlhttp.readyState==4)
 			{
				// deal with broker response //
				if(xmlhttp.status == 200) 
				{
					
					
					document.theForm.foundedaddress.value = xmlhttp.responseText;
					larray=xmlhttp.responseText.split("/");
					spacearray=larray[0].split(":");
					
						
					
					document.forms['theForm'].foundedaddress.options.length = 0;
					for(ctr=0;ctr<larray.length;ctr++)
					{
						if(larray[ctr] !="")
						{
								if(trimAll(spacearray[0])!="Error")
								{
							addOption(document.theForm.foundedaddress,trimAll(larray[ctr].substring(8)),trimAll(larray[ctr].substring(8)));
							document.theForm.foundedaddress.focus();
								}
								else
								{
								addOption(document.theForm.foundedaddress,"--Post code not valid--","");
								document.theForm.foundedaddress.disabled=true;
								alert("Post code not valid");
								document.theForm.applicant1_postcode.value="";
								document.theForm.applicant1_postcode.focus();
								}
						}
					}
					
				} else
				 {
					
					
				}
			}
	
	
		
	 	}
	 	xmlhttp.send(null)
	 
}
//to get address from getpostcode.asp file
function displayaddress1()
{
	
	var lstrpostcode,larray,ctr,xmlhttp;
	lstrpostcode=document.theForm.applicant1_postcode.value;
	
	//document.theForm.foundedaddress.disabled=false;

	var u="getpostcode.asp?pcode="+lstrpostcode;
	

		if (document.all) 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else
		 {
			xmlhttp = new XMLHttpRequest();
		}

		xmlhttp.open("GET", u,true);
		
		xmlhttp.onreadystatechange=function()
 		{
	  		if (xmlhttp.readyState==4)
 			{
	 			
				// deal with broker response //
				if(xmlhttp.status == 200) 
				{
					//broker_step=2; // fake broker error
					//alert(xmlhttp.responseText);
					document.theForm.foundedaddress.value = xmlhttp.responseText;
					larray=xmlhttp.responseText.split("/");
					document.forms['theForm'].foundedaddress.options.length = 0;
					for(ctr=0;ctr<larray.length;ctr++)
					{
						addOption(document.theForm.foundedaddress,trimAll(larray[ctr].substring(8)),trimAll(larray[ctr].substring(8)));
					}
					
				} else
				 {
					
					alert("not found");
				}
	  		}
	 	}
	 	xmlhttp.send(null)
	 	
	document.theForm.foundedaddress.focus();
	
}
