
function fixDotNetInit()
{
document.getElementById('__VIEWSTATE').value=' '; 
document.getElementById('aspnetForm').encoding='application/x-www-form-urlencoded'; 
document.getElementById('aspnetForm').action='http://www.fsb.org.uk/forms/cmsresponder_initforyou.asp';
}

function fixDotNet()
{
document.getElementById('__VIEWSTATE').value=' '; 
document.getElementById('aspnetForm').encoding='application/x-www-form-urlencoded'; 
document.getElementById('aspnetForm').action='http://www.fsb.org.uk/forms/cmsresponder.asp';
}

function fixDotNetGoogle()
{
document.getElementById('__VIEWSTATE').value=' '; 
document.getElementById('aspnetForm').encoding='application/x-www-form-urlencoded'; 
document.getElementById('aspnetForm').action='http:/maps.google.co.uk/maps';
}


// clear out aspnet form - change the action to my (ps) action.... this is for web forms
// so that they perform as normal forms
function formControl(theaction)
{
document.getElementById('__VIEWSTATE').value=''; 
document.getElementById('aspnetForm').encoding='application/x-www-form-urlencoded'; 
document.getElementById('aspnetForm').action=theaction;
document.getElementById('aspnetForm').onsubmit=='';
return true;
}


// put this on the onClick for forms  will need the name of the ASP.NET form - and the ID of a span for error message
// will  go through elements and colour if not what you asked for - options include required, postcode, email

function ps_form_validate(ferrors,theaction)
{ 
 var ers=document.getElementById(ferrors);
 var myform=document.getElementsByName('aspnetForm');
  var length = myform[0].length; // first form with this name - and the number of elements in it.
  var el;
  var emailReg = "^[\\w-_\.+]*[\\w-_\.]\@([\\w]+\\.)+[\\w]+[\\w]$";
  var postcodeReg="^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$";
  var regex = new RegExp(emailReg);
  var pregex = new RegExp(postcodeReg,"i");
  for (var i=0; i<(length-1); i++)  // iterate through elements - split them up by colon, look for options and process
    { 
       el=myform[0].elements[i]; 
	   el.style.backgroundColor="";
	   els=el.name.split("^");
	   m=els.length; // if more than 1, there are options
	   var b=0; 
	   while (++b<m)
		   {
		   if (els[b]=="required") { if (el.value=="") { el.style.backgroundColor='#ffddaa'; ers.innerHTML="* Input required"; return false; } }
		   if (els[b]=="email") { if ((!regex.test(el.value)) && (el.value!="")) { el.style.backgroundColor="yellow"; ers.innerHTML="* Email required"; return(false); } }
		   if (els[b]=="postcode") { if ((!pregex.test(el.value)) && (el.value!="")) { el.style.backgroundColor="yellow"; ers.innerHTML="* Postcode required"; return(false); } }
		   // more checks here if you like
	       }
    }

	 for (var i=0; i<(length-1); i++)  // iterate through form elements - remove first colon and anything after that - ie restore to original name
    { 
       el=myform[0].elements[i]; 
	   els=el.name.split("^");
	   el.name=els[0];
    }
	formControl(theaction);
}

