var sErrorOne = "The $ email address '%' seems incorrect (check @ and .'s)"
var sErrorTwo = "the username '%' contains invalid characters."
var sErrorThree = "Ths domain name '%' contains invalid characters."
var sErrorFour = "The £ username '$' doesn't seem to be valid, please remove the character '%' from the email address"
var sErrorFive = "The $ username '%' contains a space - an email address can not contain an empty space."
var sErrorSix = "The $ Destination IP address '%' is invalid!"
var sErrorSeven = "The $ domain name '%' doesn't seem to be valid."
var sErrorEight = "The $ email address '%' must end in a three-letter domain, or two letter country."
var sErrorNine = "The $ address is missing a hostname!"

// This function is used by the client script to retrive the current
// windows width
function getWindowWidth(){
	if (navigator.appName=="Netscape") {
		return window.innerWidth;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		return document.body.offsetWidth;
	}
}

// *************************************************************
// This function is used by the client script to retrive the current
// windows height
function getWindowHeight(){
	if (navigator.appName=="Netscape") {
		return window.innerHeight;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		return document.body.offsetHeight;
	}
}

// FPRM VALIDATION CODE STARTS HERE
// Helper method
// A utility function  that returns true if a string contains only whitespace characters.
function isBlank(str) {
	for (var i=0;i<str.length;i++) {
		var c = str.charAt(i);
		if ((c!=' ') && (c!='\n') && (c!='\t')) return false;
	}
	return true;
}

// Joins an array value
function joinArray(aValue, sDelimiter) {
	var sConcat = '';
	for (var i=0; i<aValue.length; i++) {
		sConcat += aValue[i]
		if (i != aValue.length-1) sConcat += sDelimiter
	}
	
	return sConcat;
}

// Extract querysstring value
function getQueryString(variable) {
    var query = window.location.toString();
    var question = query.indexOf("?");
    if(question != -1){
        query = query.substr(question + 1);
        var vars = query.split("&");
        for (var i=0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return unescape(pair[1]);
            }
        }
    }
    return "";
}

//Image loading and swaping functions
//preload images
function preloadImages() 
{
	for (var i=0;i<arguments.length;i++) {
		//alert(arguments[i])
	}
	// Don't bother if there's no document.images
	if (document.images) {
		if (typeof(document.cdImages) == 'undefined'){
			document.cdImages = new Object();
		}
		document.cdImages.loadedImages = new Array();
		// Loop through all the arguments.
		var argLength = preloadImages.arguments.length;
		for(arg = 0;arg < argLength;arg++) {
			// For each arg, create a new image.
			document.cdImages.loadedImages[arg] = new Image();
			// Then set the source of that image to the current argument.
			document.cdImages.loadedImages[arg].src = preloadImages.arguments[arg];
		}
	}
}

/*Copyright(c) 2001-2003 Crystal Decisions, Inc., 895 Emerson St., Palo Alto, California, USA 94301.  All rights reserved.*/
/*Crystal Decisions Confidential Proprietary Information*/
/*This file contains confidential, proprietary information, trade secrets and copyrighted expressions that are the property of Crystal Decisions, Inc., 895 Emerson St., Palo Alto, California, USA 94301.  Any disclosure, reproduction, sale or license of all or any part of the information or expression contained in this file is prohibited by California law and the United States copyright law, and may be subject to criminal penalties.  If you are not an employee of Crystal Decisions or otherwise authorized in writing by Crystal Decisions to possess this file, please contact Crystal Decisions immediately at the address listed above.*/

function emailCheck(emailStr,emailPos) {
	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 domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var userName = /^(@|\|(|)|[|]|~|#|{|}|,|;|"\"")$/;
	var dom1="com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|arts|"
	var dom2="auction|school|agent|church|llp|love|llc|golf|scfi|shop|soc|mp3|med|inc|"
	var dom3="law|kids|travel|sport|game|family|fre|chat|ltd|video|gmbh|club|tech|hola"
	var knownDomains=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|arts|auction|school|agent|church|llp|love|llc|golf|scfi|shop|soc|mp3|med|inc|law|kids|travel|sport|game|family|fre|chat|ltd|video|gmbh|club|tech|hola)$/;
	var pos;
	emailPos+=1
	
	if ((emailPos==1)||(emailPos==21)) {
		pos=emailPos+"st"
	} else if ((emailPos==2)||(emailPos==22)) {
		pos=emailPos+"nd"
	} else if ((emailPos==3)||(emailPos==23)) {
		pos=emailPos+"rd"
	} else if ((emailPos>3)||(emailPos<21)) {
		pos=emailPos+"th"
	}			
		
	if (matchArray==null) {
		//var msg = sErrorOne.replace("$",pos).replace("%",emailStr)
		//alert(sErrorOne.replace("$",pos).replace("%",emailStr))
		var errMsg = sErrorOne.replace("$",'').replace("%",emailStr);
		alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+errMsg);
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// Only basic ASCII characters(0-127) allowed.
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			//alert(sErrorTwo.replace("%",user))
			var errMsg = sErrorTwo.replace("%",user);
			alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+errMsg);
			return false;
		}
	}

	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//alert(sErrorThree.replace("%",domain));
			var errMsg = sErrorThree.replace("%",domain);
			alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+errMsg);
			return false;
	   }
	}
	
	/* See if "user" doesn't contain invalid characters */
	for (i=0;i<user.length;i++) {
		var equal = "\""
		if (user.charAt(i).search(userName)!=-1) {
			//alert(sErrorFour.replace("£",pos).replace("$",user).replace("%",user.charAt(i)))
			var errMsg = sErrorFour.replace("£",'').replace("$",user).replace("%",user.charAt(i));
			alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+errMsg);
			return false;
		}
		else if ((user.charAt(i)==equal) || (user.charAt(i)=="\\") || (user.charAt(i)=="(") || (user.charAt(i)==")") || (user.charAt(i)=="[") || (user.charAt(i)=="]")){
			//alert(sErrorFour.replace("£",pos).replace("$",user).replace("%",user.charAt(i)))
			var errMsg = ErrorFour.replace("£",'').replace("$",user).replace("%",user.charAt(i));
			alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+errMsg);
			return false;
		}// || (user.charAt(i)=="{") || (user.charAt(i)=="}")
		//alert("hi")
	}
	
	/* See if the "User" doesn't contain a space */
	var space=/\s/;
	if (space.test(user)) {
		//alert("The "+pos+" username '"+user+"' contains a space - an email address can not contain an empty space.");
		//alert(sErrorFive.replace("$",pos).replace("%",user))
		var errMsg = sErrorFive.replace("$",'').replace("%",user);
		alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+errMsg);
		return false;
	}
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
		//var msg=sErrorFour.replace("£",pos).replace("$",user).split(",");
		var msg=sErrorFour.replace("£", '').replace("$",user).split(",");
		alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+msg[0]+".");
		return false;
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        //alert("The "+pos+" Destination IP address '"+domain+"' is invalid!")
				//alert(sErrorSix.replace("$",pos).replace("%",domain));
				var errMsg = sErrorSix.replace("$",'').replace("%",domain);
				alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+errMsg);
			return false
		    }
	    }
	    return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The "+pos+" domain name '"+domain+"' doesn't seem to be valid.")
		//alert(sErrorSeven.replace("$",pos).replace("%",domain));
		var errMsg = sErrorSeven.replace("$", '').replace("%",domain);
		alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+errMsg);
	    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].search(knownDomains)==-1) {
	   //alert("The "+pos+" email address '"+emailStr+"' must end in a three-letter domain, or two letter country.")
	  // alert(sErrorEight.replace("$",pos).replace("%",emailStr));
	   var errMsg = sErrorEight.replace("$",'').replace("%",emailStr);
	   alert(errPreFixMsg+'\n'+ERR_HEADER+'\n'+errPreFixMsg+'\n'+errMsg);
	   return false
	}

	if (len<2) {
	   //alert(sErrorNine.replace("$",pos));
	   alert(sErrorNine.replace("$",''));
	   return false
	}

	return true;
}


/* HTTP REQUEST */
var xmlHTTPRequestObject = null;

function intHTTPRequestObejct() {
	try {
		xmlHTTPRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
	   		xmlHTTPRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
	  	} catch (e) {
	   		xmlHTTPRequestObject = null;
	  		try {
				xmlHTTPRequestObject = new XMLHttpRequest();
			} catch (e) {}
		}
	}
}

// XmlHttp factory
function XmlHttp() {}

XmlHttp.create = function () {
	try {
   		if (window.XMLHttpRequest) {
       	var req = new XMLHttpRequest();
         
       	// some older versions of Moz did not support the readyState property
      	// and the onreadystate event so we patch it!
      	if (req.readyState == null) {
       		req.readyState = 1;
          	req.addEventListener("load", function () {
           		req.readyState = 4;
             		if (typeof req.onreadystatechange == "function")
                  		req.onreadystatechange();
            }, false);
         }
         
         return req;
      }
      if (window.ActiveXObject) {
         return new ActiveXObject(getControlPrefix() + ".XmlHttp");
      }
   }
   catch (ex) {}
   // fell through
   throw new Error("Your browser does not support XmlHttp objects");
}

// XmlDocument factory
function XmlDocument() {}

XmlDocument.create = function () {
	try {
		// DOM2
		if (document.implementation && document.implementation.createDocument) {
			var doc = document.implementation.createDocument("", "", null);
			
			// some versions of Moz do not support the readyState property
			// and the onreadystate event so we patch it!
			if (doc.readyState == null) {
				doc.readyState = 1;
				doc.addEventListener("load", function () {
				doc.readyState = 4;
				if (typeof doc.onreadystatechange == "function")
				doc.onreadystatechange();
				}, false);
			}
		
			return doc;
		}
		
		if (window.ActiveXObject)
			return new ActiveXObject(getControlPrefix() + ".XmlDom");
	} catch (ex) {}
	
	throw new Error("Your browser does not support XmlDocument objects");
}

