function sessionFormCheck(formName,formLayer){	if (formLayer) { // Layers exist		var dom = document.getElementById ? true:false;		var nn4 = document.layers ? true:false;		var ie4 = document.all ? true:false;				if(ie4){			alert("IE4");			var formElements = document.forms[formName].length;			var formToEvaluate = document.forms[formName];		} 		else {			if(nn4){				alert("NN4");				var formElements = document.layers[formLayer].document.forms[formName].length;				var formToEvaluate = document.layers[formLayer].document.forms[formName];			}			else {				if(dom){				alert("DOM");				alert("Browser does not support form sheets");				}				else {					//what happens here. this may not function					alert("Unknown browser. May not function properly");					var formElements = document.all.forms[formName].length;					var formToEvaluate = document.all.forms[formName];				}       		}		}	}    	else { // No Layers		var formElements = document.forms[formName].length;		var formToEvaluate = document.forms[formName];	}        var arraySize = 0;    confirmFieldName = new Array();    confirmFieldValue = new Array();    var CardExpMonth = "";	var CardExpYear = "";	var CardNumber = "";		var pass = true;	for (i=0;i<formElements;i++) {		var tempName = formToEvaluate.elements[i].name;		var tempValue = formToEvaluate.elements[i].value;		var tempType = formToEvaluate.elements[i].type;		var tempSelectedIndex = formToEvaluate.elements[i].selectedIndex;				if(tempType == 'select-one'){			tempValue = formToEvaluate.elements[i].options[tempSelectedIndex].value;		}		 		// alert(tempSelectedIndex.options[1]);		 		//	alert(tempName+","+tempValue+","+tempType+","+tempSelectedIndex);				if ((tempName.substring(0,8)=="required")||(tempName.substring(0,8)=="IsEmail_")) {			alertFieldName = tempName.substring(8);						if(alertFieldName=='Sitename'){				alertFieldName = 'Val av tj'+unescape("%E4")+'nst';			}			 

			if(alertFieldName=='Username'){				alertFieldName = 'Anv'+unescape("%E4")+'ndarnamn';			}

			if(alertFieldName=='Password'){				alertFieldName = 'L'+unescape("%F6")+'senord';			}
						if(alertFieldName=='CardExpMonth'){				var CardExpMonth = tempValue;			}						if(alertFieldName=='CardExpYear'){				var CardExpYear = tempValue;			}						if(alertFieldName=='CardNumber'){				var CardNumber = tempValue;			}						// alert(alertFieldName+" = "+tempValue);						confirmName = (alertFieldName.substring(0,7)=="Confirm") ? alertFieldName.substring(7) : alertFieldName;			if (((tempType=="text" || tempType=="password" || tempType=="textarea") && tempValue=='') || (tempType.toString().charAt(0)=="s" && tempSelectedIndex==0)) { 				pass=false;				break;			} else {				if(tempName.substring(0,8)=="IsEmail_") {					if(emailCheck(tempValue)) {					} else {						return false;						break;					}				}       		}		arraySize = confirmFieldName.length;	// collect in confirm array here		confirmFieldName[arraySize] = confirmName;		confirmFieldValue[arraySize] = tempValue;				}		}			if (!pass) { // Display result and act		alert(alertFieldName+" ej korrekt ifyllt!");		return false;	}	else {					arraySize = confirmFieldName.length;		for (i=0;i<arraySize;i++) { // perform confirm check here			var refName = confirmFieldName[i];			for (n=0;n<arraySize-i;n++) {				if(refName == confirmFieldName[n]) {					if(confirmFieldValue[i] != confirmFieldValue[n]) { // we have a mismatch						alert("Values in "+refName+" does not match!");						return false;					}				}			}		}				if((CardExpMonth != '') && (CardExpYear != '') && (CardNumber != '')) {			var passRTN = false;			// check the format of credit card number			//	alert(CardNumber+" "+CardExpYear+" "+CardExpMonth)			errorstr=CheckCard(CardNumber,CardExpYear,CardExpMonth);			if (errorstr!="") {			     switch(errorstr)				{	case "DATEXP" : alert("Your card has expiredÉ"); error=true; break;					case "BADNUM" : alert("This number is not validÉ"); error=true; break;					case "UNKCAR" : alert("This card's type is not validÉ"); error=true; break;					case "INVLEN" : alert("Key's length of this card is not validÉ"); error=true; break;					case "INVKEY" : alert("Key of this card is not validÉ"); error=true; break;					default : alert("Your card is a "+errorstr);				} 			} else {				passRTN = true;	//	alert("Card OK");			}		return passRTN; 		}				//	alert("Everything seems OK but nothing will happen!");			return true; 	}	alert("Internal error");		return false; }function emailCheck (emailStr) {/* The following pattern is used to check if the entered e-mail address   fits the user@domain format.  It also is used to separate the username   from the domain. */var emailPat=/^(.+)@(.+)$//* The following string represents the pattern for matching all special   characters.  We don't want to allow special characters in the address.    These characters include ( ) < > @ , ; : \ " . [ ]    */var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"/* The following string represents the range of characters allowed in a    username or domainname.  It really states which chars aren't allowed. */var validChars="\[^\\s" + specialChars + "\]"/* The following pattern applies if the "user" is a quoted string (in   which case, there are no rules about which characters are allowed   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com   is a legal e-mail address. */var quotedUser="(\"[^\"]*\")"/* The following pattern applies for domains that are IP addresses,   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal   e-mail address. NOTE: The square brackets are required. */var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$//* The following string represents an atom (basically a series of   non-special characters.) */var atom=validChars + '+'/* The following string represents one word in the typical username.   For example, in john.doe@somewhere.com, john and doe are words.   Basically, a word is either an atom or quoted string. */var word="(" + atom + "|" + quotedUser + ")"// The following pattern describes the structure of the uservar userPat=new RegExp("^" + word + "(\\." + word + ")*$")/* The following pattern describes the structure of a normal symbolic   domain, as opposed to ipDomainPat, shown above. */var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")/* Finally, let's start trying to figure out if the supplied address is   valid. *//* Begin with the coarse pattern to simply break up user@domain into   different pieces that are easy to analyze. */var matchArray=emailStr.match(emailPat)if (matchArray==null) {  /* Too many/few @'s or something; basically, this address doesn't     even fit the general mould of a valid e-mail address. */	alert("Epostadress felaktig (kontrollera @ och .)")	return false}var user=matchArray[1]var domain=matchArray[2]// See if "user" is valid if (user.match(userPat)==null) {    // user is not valid    alert("Epostadress ogiltig!")    return false}/* if the e-mail address is at an IP address (as opposed to a symbolic   host name) make sure the IP address is valid. */var IPArray=domain.match(ipDomainPat)if (IPArray!=null) {    // this is an IP address	  for (var i=1;i<=4;i++) {	    if (IPArray[i]>255) {	        alert("Epost IP adress ogiltig!")		return false	    }    }    return true}// Domain is symbolic namevar domainArray=domain.match(domainPat)if (domainArray==null) {	alert("Email domain is not valid!")    return false}/* domain name seems valid, but now make sure that it ends in a   three-letter word (like com, edu, gov) or a two-letter word,   representing country (uk, nl), and that there's a hostname preceding    the domain or country. *//* Now we need to break up the domain to get a count of how many atoms   it consists of. */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>8) {   // the address must end in a two letter or three letter word. Now support .family   alert("Email address must end in at least a two letter word")   return false}// Make sure there's a host name preceding the domain.if (len<2) {   var errStr="Email domain missing!"   alert(errStr)   return false}// If we've gotten this far, everything's valid!return true;}function postSubmit(formName,actionURL) {  document.forms[formName].action=actionURL;  document.forms[formName].submit();}
function sessionSubmitByFormCheck (formName,actionURL) {  if (sessionFormCheck(formName)) {    document.forms[formName].action=actionURL;    document.forms[formName].submit();  }}
