// Example: preloadImages('file.gif', 'http://www.x.com/y.gif');

function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}
/////////////////////////////////////////////////////////////
// * Dependencies * 
// this function requires the following snippets:
// JavaScript/readable_MM_functions/findObj
//
// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');

function MM_findObj(n, d) 
{ //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() 
{ //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'':(v='hide')?'none':v; }
    obj.display=v; }
}
/////////////////////////////////////////////////////////////////////////////
function checkDelete()
{
	return confirm("Are you sure you wish to delete this record ? \n It cannot be recovered !");
}
function checkSave()
{
	return confirm("Are you sure you wish to save the changes ?");
}

/////////////////////////////////////////////////////////////////////////////
function emailCheck (emailStr) 
{
	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);
	var ret=true;
	if (matchArray==null) {
		alert("Email address seems incorrect")
		form1.email.focus();
		ret=false;
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) 
	{
		alert("The email name doesn't seem to be valid.")
		form1.email.focus();
		ret=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!")
					form1.email.focus();
					ret=false;
	    }
    }
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
	form1.email.focus();
  ret=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>3) {
   alert("The address must end in a three-letter domain, or two letter country.")
	 form1.email.focus();
   ret=false;
}
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
	 form1.email.focus();
   ret=false;
}
return ret;
}
////  End email check  ////////////////////////

///   Complete form 1 validation  ///////////////////
function validateForm1()
{
	var ret=true;
	///  Names  //////////////////////////////	
	if(form1.name.value.length<2)
	{
		alert("Please enter your name");
		form1.name.focus();
		ret=false;
	}
if(form1.country.value.length<2)
	{
		alert("Please enter your country of residence");
		form1.country.focus();
		ret=false;
	}
	///  Email  //////////////////////////////
	else if(form1.email.value.length<5)
	{
		alert("Please enter your email address");
		form1.email.focus();
		ret=false;
	}
	return ret;
}

