function validcode(codeid)
{
	
	var requiredpcode=codeid;
	var num=0;
	var myArr = new Array();
	var postCode=document.getElementById(requiredpcode).value;
	var tempCode=postCode.substring(0,5);
	var country=document.ThisForm.requiredCountry.value;
	if(postCode=="")
	{
		if(country=="IRL"){	}
		else
		{	alert("Post Code can\'t be blank.");
			document.getElementById(requiredpcode).focus();	}
	}
	if(country=="UK")
	{
	var code=parseInt(tempCode.charAt(0));
		if(!isNaN(code))
		{
		alert("Post code no. start from Alphabets")
		document.getElementById(requiredpcode).focus();
		}
		else	
		{
			for(i=1;i<=4;i++)
				{
					myArr[i]=tempCode.charAt(i);
				}
			for(i=1;i<=4;i++)
				{
					if(!isNaN(tempCode.charAt(i)))
						{
							num++;
						}
				}
				if(num>=2)
				{					
				}
				else
				{
				alert("Invalid post code.")
				document.getElementById(requiredpcode).focus();
				}
		}
	} 
}
function LowerCase(Textboxid)
{
var txtval=Textboxid
var abc
abc=document.getElementById(txtval).value.toLowerCase()
document.getElementById(txtval).value=document.getElementById(txtval).value.toLowerCase()
}

function postit(code){ //check postcode format is valid
var requiredpcode=code;
 test = document.getElementById(requiredpcode).value; size = test.length
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {test = test.substr(1,size-1);size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {test = test.substr(0,size-1);size = test.length
  }
 document.getElementById(requiredpcode).value = test; //write back to form field
 if (size < 6 || size > 8){ //Code length rule
  alert(test + " is not a valid postcode - wrong length");
 

 document.getElementById(requiredpcode).focus();
  return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number");
   document.getElementById(requiredpcode).focus();
   return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position");
   document.getElementById(requiredpcode).focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   document.getElementById(requiredpcode).focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   document.getElementById(requiredpcode).focus();
   return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position");
   document.getElementById(requiredpcode).focus();
   return false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed");
   document.getElementById(requiredpcode).focus();
   return false;
  }
return true;
}

function remove_XS_whitespace(item)
{
  var tmp = "";
  var item_length = item.value.length;
  var item_length_minus_1 = item.value.length - 1;
  for (index = 0; index < item_length; index++)
  {
    if (item.value.charAt(index) != ' ')
    {
      tmp += item.value.charAt(index);
    }
    else
    {
      if (tmp.length > 0)
      {
        if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1)
        {
          tmp += item.value.charAt(index);
        }
      }
    }
  }
  item.value = tmp;
}

function checkrequired(which) {
//var country=document.ThisForm.requiredCountry.value;
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if(tempobj.type=="text"||tempobj.type=="textarea"){
	remove_XS_whitespace(tempobj);
}

if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea") && tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s" && tempobj.selectedIndex==0)) {
	pass=false;
	break;
         }
      }
   }
}
if (!pass) {
		
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
	alert("Please make sure all the field was properly completed.");
	tempobj.focus();
	return false;
			
}
else
	if(emailCheck(which.elements['requiredEMail'].value)){
		return true;
	}
	else{
		return false;
	}

}

function emailCheck(emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}
if (user.match(userPat)==null) {
alert("The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Please enter valid Email Address.");
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}
if (len<2) {
alert("This address is missing a hostname!");
return false;
}
return true;
}
function MM_openBrWindow(theURL,winName,features){window.open(theURL,winName,features);}
