// JavaScript Document

function dell_all(data1,data2)
{
	
	for(i=data1-1;i>0;i--)
	{
	data2.remove(i);
	}
}


function initiate()
{
	document.getElementById("searchinput").disabled = true;
	document.getElementById("searchinput").style.background = "#CCC";
}
		
function radio_action(str)
{

	if(str=="post")
	{
	document.getElementById("searchinput").disabled = false;
	document.getElementById("searchinput").style.background = "#FFF";
	document.getElementById("searchinput").value = "Enter Post Code"
	}
	else if(str=="address")
	{
	document.getElementById("searchinput").disabled = false;
	document.getElementById("searchinput").style.background = "#FFF";
	document.getElementById("searchinput").value = "Enter Street Name"
	}

}

function fill_county(str,st2,placeid)
{	
	
	var len=document.getElementById("town").length;
	List_level=document.first.town;
	dell_all(len,List_level);
	var alpha="a";
	common(str,st2,alpha);
	document.getElementById(placeid).value=str;   
	//alert("placeid:"+document.getElementById(placeid).value);
}
function fill_town(str,st2,placeid)
{	
	var alpha="b";
	common(str,st2,alpha);
	document.getElementById(placeid).value=str;  
	

}
///////////////////////////////////Fill the Second level directory/////////////////////////////////////////////////////////
function sel_second(str,st2,dirid)
{
	
	var len=document.getElementById("parent3").length;
	List_level=document.first.parent3;
	dell_all(len,List_level);
	var alpha="c";
	common(str,st2,alpha);
	document.getElementById(dirid).value=str;         

}
/////////////////////////////////Fill the Third Level Directory/////////////////////////////////////////////////////////////
function sel_third(str,st2,dirid)
{
	var alpha="i";
	common(str,st2,alpha);
	document.getElementById(dirid).value=str;       

	
}

function setPlaceId(value,placeid)
{
	
	document.getElementById(placeid).value=value;       
	//alert("placeid:"+document.getElementById(placeid).value);

	
}

function setDirId(value,dirid)
{
	
	document.getElementById(dirid).value=value;       
	//alert("dirid:"+document.getElementById(dirid).value);

	
}
function clearText(name)
{
	
	document.getElementById(name).value="";       
	//alert("dirid:"+document.getElementById(name).id);

	
}
function common(str,st2,alpha)
{
	
	xmlHttp=GetXmlHttpObject()
	if(xmlHttp==null)
    {
     	alert ("Browser does not support HTTP Request")
     	return;
	}
	
	var url="ajax_php_trans.php";
	url=url+"?"+alpha+"="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);	
	var mycombo = document.getElementById(st2);
	mycombo.options.length = 0;
	function stateChanged() 
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 			{ 
				var myString=xmlHttp.responseText.replace(/^\s*|\s*$/g,"");
				//alert(myString);
				var mySplitResult = myString.split(";");
				if(alpha=="a" || alpha=="b" || alpha=="c")
					{
						if(myString == "No Directory Available" )
							{
								
							}
						else
							{
							for(i = 0; i < mySplitResult.length-1; i++)
							{
    							var opt = document.createElement("option");
    							document.getElementById(st2).options.add(opt);       
    							var idval=mySplitResult[i].split(":");
    							opt.text = idval[1];
    							opt.value = idval[0];
							}
							}
					}
					else if(alpha=="i")
					{
						if(myString == "No Directory Available" )
							{
							document.getElementById("parent3").style.visibility="hidden";
							document.getElementById("hid_message").innerHTML="No Third Level";
							}
						else
							{
							document.getElementById("parent3").style.visibility="visible";
							document.getElementById("hid_message").innerHTML="";
						for(i = 0; i < mySplitResult.length-1; i++)
							{
    							var opt = document.createElement("option");
    							document.getElementById(st2).options.add(opt);       
    							var idval=mySplitResult[i].split(":");
							opt.text = idval[1];
    							opt.value = idval[0];
							}
							}
		
 					}
				
			}
		}
}

var xmlHttp;
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

function toggleDiv(divid){

   for(i=1;i<11;i++){
   str="contactblock"+i;
   if(document.getElementById(str))document.getElementById(str).style.display = 'none';
   }
    if(document.getElementById(divid).style.display == 'none'){
      
      document.getElementById(divid).style.display = 'block';
      
    }else{
      document.getElementById(divid).style.display = 'none';
    }
  }
  
  function hideDiv(divid){
  
    
        document.getElementById(divid).style.display = 'none';
    
  }
  
  
function showSendButton(id){
		
	
 	if(document.getElementById("message"+id).value !="" & document.getElementById("subject"+id).value !="")
        {document.getElementById("send"+id).disabled = false;}else{document.getElementById("send"+id).disabled = true;}

}



function showlogin(id){
 for(i=1;i<11;i++){
   str="login"+i;
   if(document.getElementById(str))document.getElementById(str).innerHTML = "";
   }
 document.getElementById(id).innerHTML="Please login to be able to send email"
}
