	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(",");
	if(lSplitArray.length>3)
	{
	r=lSplitArray[0]+","+lSplitArray[1]+","+lSplitArray[2];
	
 	return r;
	}
	else
	{
	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;
	alert(document.theForm.foundedaddress.value);
	lstrarray=lstrRaw.split(",");
	lstrStreet="";
	/*for(lctr=0;lctr<lstrarray.length-1;lctr++)
	{
		
		lstrStreet=lstrStreet+" "+lstrarray[lctr];
		
		
	}*/
	if(lstrarray.length<=2)
	{
	document.theForm.street.value=lstrarray[0];
	//document.theForm.town.value=lstrarray[1];
	document.theForm.city.value=lstrarray[1];
	}
	else
	{
		var ctrarr,strarr;
		strarr="";
		for(ctrarr=0;ctrarr<lstrarray.length-1;ctrarr++)		
		{
			strarr=strarr+" "+lstrarray[ctrarr];
		}
		
	document.theForm.street.value=strarr;
	//document.theForm.town.value=lstrarray[1];
	document.theForm.city.value=lstrarray[lstrarray.length-1];
	}
	
	}
function displayaddress()
{
	
	var lstrpostcode,larray,ctr,spacearray,check;
	lstrpostcode=document.theForm.postcode.value;
	document.theForm.foundedaddress.disabled=false;
	check_disable=1;
	//for Development server
	//var u="http://192.168.254.93/fsnsites/carfinance.co.uk_2007/getpostcode.asp?pcode="+lstrpostcode;
	//for Online server
	var u="getpostcode.asp?pcode="+lstrpostcode;
	var responseText;

		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) 
				{
					
					responseText="CV6 6ff  ---Select,Address--- /"+xmlhttp.responseText
					document.theForm.foundedaddress.value = xmlhttp.responseText;
					//alert(responseText);
					larray=responseText.split("/");
					
					spacearray=larray[1].split(":");
					if(trimAll(spacearray[0])=="Error")
								
								{
								//addOption(document.theForm.foundedaddress,"--Post code not valid--","");
								document.theForm.foundedaddress.disabled=true;
								alert("Please enter your valid postcode");
								document.theForm.postcode.value="";
								document.theForm.postcode.focus();
								return false;
								}
					document.forms['theForm'].foundedaddress.options.length = 1;
					//addOption(document.theForm.foundedaddress,"---Please select---","0");
					for(ctr=0;ctr<larray.length;ctr++)
					{
						if(larray[ctr] !="")
						{
								
									if(ctr==0)
									{
										
										//addOption(document.theForm.foundedaddress,trimAll(larray[ctr].substring(8)),"0,0");
									}
									else
									{
										
									addOption(document.theForm.foundedaddress,trimAll(larray[ctr].substring(8)),trimAll(larray[ctr].substring(8)));
									}
							document.theForm.foundedaddress.focus();
							
								
								
						}
					}
					
				} else
				 {
					
					
				}
			}
	
	
		
	 	}
	 	xmlhttp.send(null)
	 
}
//to get address from getpostcode.asp file
function displayaddress1()
{
	
	var lstrpostcode,larray,ctr,xmlhttp;
	lstrpostcode=document.theForm.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();
	
}
