document.getElementsByClassName = function(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}

		var account_code='THOMA11125';
		var license_code='WJ56-NY32-WF69-JK32';
		var machine_id='';
		
		function pcaByPostcodeBegin()
		   {
			  var postcode = document.forms[0]["postcode_search"].value;
		      var scriptTag = document.getElementById("pcaScriptTag");
		      var headTag = document.getElementsByTagName("head").item(0);
		      var strUrl = "";
		      
		      document.getElementById("divLoading").style.display = '';
		      
		      //Build the url
		      strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
		      strUrl += "&action=lookup";
		      strUrl += "&type=by_postcode";
		      strUrl += "&postcode=" + escape(postcode);
		      strUrl += "&account_code=" + escape(account_code);
		      strUrl += "&license_code=" + escape(license_code);
		      strUrl += "&machine_id=" + escape(machine_id);
		      strUrl += "&callback=pcaByPostcodeEnd";
		      
		      //Make the request
		      if (scriptTag)
		         {
		            //The following 2 lines perform the same function and should be interchangeable
		            headTag.removeChild(scriptTag);
		            //scriptTag.parentNode.removeChild(scriptTag);
		         }
		      scriptTag = document.createElement("script");
		      scriptTag.src = strUrl
		      scriptTag.type = "text/javascript";
		      scriptTag.id = "pcaScriptTag";
		      headTag.appendChild(scriptTag);
		      
		      
		      
		   }

		function pcaByPostcodeEnd()
		   {
			  document.getElementById("divLoading").style.display = 'none';
			  
		      //Test for an error
		      if (pcaIsError)
		         {
		            //Show the error message
		            document.getElementById("selector").style.display = 'none';
		            //document.getElementById("btnFetch").style.display = 'none';
		            alert(pcaErrorMessage);
		         }
		      else
		         {
		            //Check if there were any items found
		            if (pcaRecordCount==0)
		               {
		                  document.getElementById("selector").style.display = 'none';
						  //document.getElementById("btnFetch").style.display = 'none';
		                  alert("Sorry, no matching items found. Please try another postcode.");
		               }
		            else
		               {
						 // document.forms[0]["selectaddress"].style.display = '';
						  document.getElementById("selector").style.display = '';
						  
						  for (i=document.forms[0]["selectaddress"].options.length-1; i>=0; i--){
							  document.forms[0]["selectaddress"].options[i] = null;
							}
						  for (i=0; i<pca_id.length; i++){
		                    document.forms[0]["selectaddress"].options[document.forms[0]["selectaddress"].length] = new Option(pca_description[i], pca_id[i]);
		                  }
		               }
		         }
		   }
		
		function pcaFetchBegin()
		   {
			  var address_id = document.forms[0]["selectaddress"].value;
		      var scriptTag = document.getElementById("pcaScriptTag");
		      var headTag = document.getElementsByTagName("head").item(0);
		      var strUrl = "";

		      //Build the url
		      strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
		      strUrl += "&action=fetch";
		      strUrl += "&id=" + escape(address_id);
		      strUrl += "&account_code=" + escape(account_code);
		      strUrl += "&license_code=" + escape(license_code);
		      strUrl += "&machine_id=" + escape(machine_id);
		      strUrl += "&callback=pcaFetchEnd";

		      //Make the request
		      if (scriptTag)
		         {
		            //The following 2 lines perform the same function and should be interchangeable
		            headTag.removeChild(scriptTag);
		            //scriptTag.parentNode.removeChild(scriptTag);
		         }
		      scriptTag = document.createElement("script");
		      scriptTag.src = strUrl
		      scriptTag.type = "text/javascript";
		      scriptTag.id = "pcaScriptTag";
		      headTag.appendChild(scriptTag);
		      
		      //document.forms[0]["selectaddress"].style.display = 'none';
		      document.getElementById("selector").style.display = 'none';
		   }

		function pcaFetchEnd()
		   {
		      //Test for an error
		      if (pcaIsError)
		         {
		            //Show the error message
		            alert(pcaErrorMessage);
		         }
		      else
		         {
		            //Check if there were any items found
		            if (pcaRecordCount==0)
		               {
		                  alert("Sorry, no matching items found");
		               }
		            else
		               {
						  var f_address1 = document.getElementsByClassName('paf_address1');
						  var f_address2 = document.getElementsByClassName('paf_address2');
						  var f_address3 = document.getElementsByClassName('paf_address3');

						  var f_town = document.getElementsByClassName('paf_town');
						  var f_county = document.getElementsByClassName('paf_county');
						  
						   var f_postcode = document.getElementsByClassName('paf_postcode');
						  
						  if(pca_organisation_name[0]!=""){
						  	  f_address1[0].value = '' + pca_organisation_name[0];
						  }else{
							  f_address1[0].value = '' + pca_line1[0];
							  }
							  
						  if(pca_organisation_name[0]!=""){
						  	  f_address2[0].value = '' + pca_line1[0];
						  }else{
							  f_address2[0].value = '' + pca_line2[0];
							  }
							  
						  if(pca_organisation_name[0]!=""){
						  	  f_address3[0].value = '' + pca_line2[0];
							  '' + pca_line3[0];
						  	  '' + pca_line4[0];
    						  '' + pca_line5[0];
						  }else{
							  f_address3[0].value = '' + pca_line3[0];
							  '' + pca_line4[0];
    						  '' + pca_line5[0];
							  }
						
						  f_town[0].value = '' + pca_post_town[0];
						  f_county[0].value = '' + pca_county[0];
						  f_postcode[0].value = '' + pca_postcode[0];
						  
						  
						  document.getElementsByClassName('paf_address1')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="block";
document.getElementsByClassName('paf_address1')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="block";
document.getElementsByClassName('paf_address2')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="block";
document.getElementsByClassName('paf_address3')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="block";

document.getElementsByClassName('paf_town')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="block";
document.getElementsByClassName('paf_county')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="block";

document.getElementsByClassName('paf_postcode')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="block";
						  
		               }
		         }
		   }


if(document.getElementsByClassName('DynamicForms_Summary')[0].style.display=="none"){
	document.getElementsByClassName('paf_address1')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
	document.getElementsByClassName('paf_address1')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
	document.getElementsByClassName('paf_address2')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
	document.getElementsByClassName('paf_address3')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
	document.getElementsByClassName('paf_town')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
	document.getElementsByClassName('paf_county')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
	document.getElementsByClassName('paf_postcode')[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
}



