//Common functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_statusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function printpg() {
	window.print();
}

function bookmarkpg() { 
  var bookmarktitle = document.title;
  var bookmarkurl = document.location;
  var netscape
  netscape="Attention Netscape Users. To Bookmark this page please click the page you would like to bookmark and press CTRL+D.";
  if (window.sidebar&&window.sidebar.addPanel) { 
    alert(netscape);
  } else if (document.all) {
    window.external.AddFavorite(bookmarkurl, bookmarktitle);
  } else if (window.opera && window.print) {
    return true;
  }
}

function goprevious() {
	history.go(-1);
}

function swapClass() {
  var i,j=0,x,a=swapClass.arguments; document.SC_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.SC_sr[j++]=x; if(!x.oClassName) x.oClassName=x.className; x.className=a[i+2];}
}
function restoreClass() {
  var i,x,a=document.SC_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oClassName;i++) x.className=x.oClassName;
}



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);
	var msgAlert=""
	if (matchArray==null) {
		return ("Email address seems incorrect (check @ and .'s)");
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
		return ("Ths username contains invalid characters.");
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
		return ("Ths domain name contains invalid characters.");
	   }
	}

	if (user.match(userPat)==null) {
		return ("The username doesn't seem to be valid.");
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return ("Destination IP address is invalid!");
		   }
		}
		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) {
			return ("The domain name does not seem to be valid.");
		   }
		}
		if (checkTLD && domArr[domArr.length-1].length!=2 && 
			domArr[domArr.length-1].search(knownDomsPat)==-1) {
			return ("The address must end in a well-known domain or two letter " + "country.");
		}
		if (len<2) {
			return ("This address is missing a hostname!");
		}
		return true;
	}

function validateContact () {
	var errorMsg = "";	
	var valEmail = emailCheck(document.contactform.email.value);
	if (document.contactform.salutation.value==""){errorMsg += "\n\tTitle";}
	if (document.contactform.name.value==""){errorMsg += "\n\tFirst name";}	
	if (document.contactform.surname.value==""){errorMsg += "\n\tSurname";}	
	if (document.contactform.position.value==""){errorMsg += "\n\tPosition";}	
	if (document.contactform.company.value==""){errorMsg += "\n\tCompany";}
	if (document.contactform.telephone.value==""){errorMsg += "\n\tTelephone";}
	if (document.contactform.enquiry.value==""){errorMsg += "\n\tEnquiry";}
	if (valEmail!=true){errorMsg += "\n\tEmail: " + valEmail;}
	if (errorMsg != ""){
		msg = "______________________________________________\n\n";
		msg += "Your request has not been submitted because the form\n";
		msg += "has not been completed properly.\n\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "_____________________________________________\n\n";
		msg += "Please correct the following field(s): -\n";	
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	return true;
}
function validateRefer () {
	var errorMsg = "";	
	var valSendEmail = emailCheck(document.referform.visitormail.value);
	var valRecEmail = emailCheck(document.referform.friendmail.value);
	if (document.referform.visitorname.value==""){errorMsg += "\n\tYour name";}	
	if (valSendEmail!=true){errorMsg += "\n\tRecipient's email: " + valSendEmail;}
	if (document.referform.friendname.value==""){errorMsg += "\n\tRecipient's name";}
	if (valRecEmail!=true){errorMsg += "\n\tRecipient's email: " + valRecEmail;}
	if (errorMsg != ""){
		msg = "______________________________________________\n\n";
		msg += "Your request has not been submitted because the form\n";
		msg += "has not been completed properly.\n\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "_____________________________________________\n\n";
		msg += "Please correct the following field(s): -\n";	
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	return true;
}
function validateRequest () {
	var errorMsg = "";
	var valEmail = emailCheck(document.requestform.email.value);
	if (document.requestform.salutation.value==""){errorMsg += "\n\tTitle";}
	if (document.requestform.name.value==""){errorMsg += "\n\tFirst name";}	
	if (document.requestform.surname.value==""){errorMsg += "\n\tSurname";}	
	if (document.requestform.telephone.value==""){errorMsg += "\n\tTelephone";}
	if (document.requestform.company.value==""){errorMsg += "\n\tCompany";}
	if (valEmail!=true){errorMsg += "\n\tEmail: " + valEmail;}
	if (errorMsg != ""){
		msg = "______________________________________________\n\n";
		msg += "Your request has not been submitted because the form\n";
		msg += "has not been completed properly.\n\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "_____________________________________________\n\n";
		msg += "Please correct the following field(s): -\n";	
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	return true;
}