
function emailCheck (element) 
{
	emailStr=element;
	
	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 + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	var matchArray=emailStr.match(emailPat)
	
	if (matchArray==null) {
		return false
	}
	
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		return false
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			return false
			}
		}
		return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return false
	}
	
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>4) {
	   // the address must end in a two letter or three letter word.
	   return false
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   return false
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}


//  End -->

function ShowTR(id)
{
	if(document.getElementById(id).style.display == 'none')
		document.getElementById(id).style.display = 'block';
	else
		document.getElementById(id).style.display = 'none';
}

function checkphone(input)
{
	var returnval = false;
	input=input.replace(/[ ()]/g, "");
	var re = new RegExp('^[+]{0,1}[0]{0,2}[1-9][0-9]{8,}$');
	if (input.match(re)) {
		returnval = true;
	}
	return returnval;
}

function checkdate(input)
{
	var returnval = false;
	
	if (input == 'dd/mm/yyyy')
	    return true;
	
	var re = new RegExp('^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\\d\\d$');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checkcurrency(input)
{
	var returnval = false;
	
	var re = new RegExp('^\\d+\\.\\d\\d$');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checknumber(input)
{
	var returnval = false;
	
	var re = new RegExp('^[0-9]\\d*$');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checksortcode(input)
{
	var returnval = false;
	
	var re = new RegExp('^([0-9]{2})$');
	if (input.match(re)) {
		returnval = true;
	}
	return returnval;
}

function checktime(input)
{
	var returnval = false;
	
	var re = new RegExp('^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?$');
	if (input.match(re)) {
		returnval = true;
	}
	return returnval;
}

function checkccarddate(input)
{
	//var returnval = false;
	
	var re = /^\d{2}\/\d{2}$/.test(input);
	
	//var re = new RegExp('(^\d{1,2}\/\d{4}$)');
	//if (input.match(re)) {
	//	returnval = true;
	//}	
	return re; //returnval;
}

function checkccard(input, nl)
{
	var returnval = false;
	
	var re = new RegExp('^([0-9]{'+nl+'})$');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checkrequired(which)
{
	var pass=true;
	var ct;
	var gprop;
	
	for(x=0;x<valObjects.length;x++)
	{
		if (pass)
		{
			obj = document.getElementById(valObjects[x][0]);
			
			if (obj)
			{
				var prop = new Array();
				prop = valObjects[x][1].split(';');
				
				if ( (obj.type=="checkbox" && obj.checked==false) || ((obj.type=="text"||obj.type=="password"||obj.type=="textarea")&&
					obj.value=='')||(obj.type.toString().charAt(0)=="s"&&
					obj.selectedIndex==0) ) 
				{
					pass=false;
					break;
				}
				else
				{
					for (y=0;y<prop.length;y++)
					{		
						if (pass)
						{
							gprop = prop[y];
							
							if (gprop.substring(0,1) == '@')
							{
								switch(gprop.substring(1))
								{
									case "isdate":
										if (!checkdate(obj.value))
										{ pass = false; }
										break;
									case "istime":
										if (!checktime(obj.value))
										{ pass = false; }
										break;
									case "iscurrency":
										if (!checkcurrency(obj.value))
										{ pass = false; }
										break;
									case "isnumber":
										if (!checknumber(obj.value))
										{ pass = false; }
										break;
									case "lnum":
										/* if (parseFloat(obj.value) < parseFloat(tempobj.lnum))
										{ pass = false; }
										break; */
									case "unum":
										/* if (parseFloat(obj.value) > parseFloat(tempobj.unum))
										{ pass = false; }
										break; */
									case "isemail":
										if (emailCheck(obj.value) == false)
										{ pass = false; }
										break;
									case "isphone":
										if (checkphone(obj.value) == false)
										{ pass = false; }
										break;
									case "issortcode":
										if (checksortcode(obj.value) == false)
										{ pass = false; }
										break;
									case "isccarddate":
										if (checkccarddate(obj.value) == false)
										{ pass = false; }
										break;
									case "isccard":
										if (obj.value.length >= 13)
										{
											if(checkccard(obj.value, obj.value.length) == false)
											{ pass = false; }
										}
										else
										{ pass = false; }
										
										break;
									case "tomatch":
										var tomatch;
										
										for (z=0;z<prop.length;z++)
										{
											if (prop[z] == '@tomatch')
											{
												tomatch = prop[z+1];
												break;
											}
										}
									
										if (document.getElementById(tomatch))
										{
											if (obj.value != document.getElementById(tomatch).value)
											{
												pass = false;
											}
										}
										else
										{
											pass = false;
										}
										
										break;
										/*if(val != document.getElementById(tempobj.tomatch).value)
										{
											
											pass = false;
											alert ("Please make sure the " + tempobj.name.toUpperCase() + " field matches the " + tempobj.tomatch.toUpperCase() + " field.");
											tempobj.focus;
											return false;
										}*/
								}
							}
						}
					}
				}
			}
		}
	}
	
	if (!pass) 
	{
		shortFieldName = obj.name;
		
		for (y=0;y<prop.length;y++)
		{
			if (prop[y] == '@ct')
			{
				ct = prop[y+1];
				break;
			}
		}
		
		if(ct)
			alert(ct);
		else
		{
			alert("Please make sure the "+shortFieldName+" field was properly completed.");
		}
		
		if (obj.disabled != true)
			obj.focus();
		
		return false;
	}
	else
		return true;
}

// Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}