<!--
//=======================
//Author:		Dan Pettit
//Date Created:	02/08/01
//Description:	This page has all Javascript functions for the site
//========================

		
	function emailCheck (emailStr,msgStr) {
		/* Set up our error message */
		var errMsg="Please double check " + msgStr + " email address.\n";
		/* 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 represents the range of characters allowed as the first character in a valid username or domain. I just made it  the same as above, but if you want to add a different constraint, you would change it here. */
		var firstChars=validChars;
		/* 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 at atom (basically a series of  non-special characters.) */
		var atom="(" + firstChars + 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 course 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(errMsg + "Email address seems incorrect (check @ and .\'s)");
			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(errMsg + "The e-mail username doesn't seem to be valid.");
		    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(errMsg + "Destination IP address is invalid!");
						return false;
				}
			}
			return true;
		}

		// Domain is symbolic name
		var domainArray=domain.match(domainPat);
		if (domainArray==null) {
			alert(errMsg + "The domain name doesn't seem to be 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).   If there's a country code at the end of the address, the full domain  must include a hostname and category (e.g. host.co.uk or host.pub.nl).  If it ends in a .com or something, make sure there's a hostname.*/
		/* 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>3) {
		   // the address must end in a two letter or three letter word.
		   alert(errMsg + "The address must end in a three-letter domain, or two letter country.");
		   return false;
		}

		/* === REMOVING THIS CHECK - New addresses do not comply to previous standard - ZIP_LRR === */
		/* If it ends in a country code, we want to make sure there are at least 2 atoms preceding it (representing host and category (i.e. com, gov, etc.)) */
		/* if (domArr[domArr.length-1].length==2 && len<3) {
		   var errStr="This address ends in two characters, which is a country";
		   errStr+=" code.  Country codes must be preceded by";
		   errStr+="a hostname and category (like com, co, pub, pu, etc.)";
		   alert(errMsg + errStr);
		   return false;
		}
		*/
		
		/* If it just ends in .com, .gov, etc., make sure
		there's a host name.
   This case can never actually happen because earlier
		checks take
		 care of this implicitly, but we'll do it anyway. */
		if (domArr[domArr.length-1].length==3 && len<2) {
			var errStr="This address is missing a hostname!";
			alert(errMsg + errStr);
			return false;
		}
		// If we've gotten this far, everything's valid!
		return true;
	}

	function ValidateZipCode(strZip) {
			var valid = "0123456789-";
			var hyphencount = 0;

			if (strZip.length!=5 && strZip.length!=9 && strZip.length!=10) {
				alert("Please enter a properly formatted 5 digit or 5 digit + 4 zip code, like '12345' or '12345-6789'.");
				return false;
			}
			
			for (var i=0; i < strZip.length; i++) {
				temp = "" + strZip.substring(i, i+1);
				if (temp == "-") hyphencount++;
				if (valid.indexOf(temp) == "-1") {
					alert("Please enter a properly formatted 5 digit or 5 digit + 4 zip code, like '12345' or '12345-6789'.");
					return false;
				}
				if ((hyphencount > 1) || (strZip.length==9) || ((strZip.length==10) && ""+strZip.charAt(5)!="-")) {
					alert("The hyphen character should be used with a properly formatted 5 digit+4 zip code, like '12345-6789'.   Please try again.");
					return false;
				}
			}
			return true;
		}




//**********************************
// This function opens the contest popup window (used on Contest Window Popup)
	function Popup(page) {
	OpenWin = this.open(page, "Contest", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=570,height=600,screenX=100,screenY=100,top=100,left=100");
	}

//Script is for popup windows - (Bug Report Page)
	var newWin;
	function ShowDoc(url) {
		if (url != "") {
			if (newWin) {
				if (!newWin.closed) {
					newWin.location=url;
				} else {
					newWin=window.open(url,"newWin","statusbar,resizable,height=400,width=585,scrollbars");
				}	
				newWin.focus();
			} else {
				newWin=window.open(url,"newWin","statusbar,resizable,height=400,width=585,scrollbars");
				newWin.focus();
			}
		}
		return (true);
	}

//**This Function validates fomr on .asp

//******************************************************
function isBlank(s) {
	for (var i=0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}
//****************************************************

//**This Function validates form on postcardmain.asp

//*********************************
function checkForm(frmMain) {
	var errs = ''
	var checkedoff = ''
	if (isBlank(frmMain.elements.name1.value)) errs += 'Your Name\n'
	if (isBlank(frmMain.elements.emailaddress.value)) errs += 'Your E-Mail\n'
	if (isBlank(frmMain.elements.RName1.value)) errs += 'Recipient\'s Name\n'
	if (isBlank(frmMain.elements.RemailAddress.value)) errs += 'Recipient\'s E-Mail\n'
	if (frmMain.elements.R1BrandID.options[frmMain.elements.R1BrandID.selectedIndex].value == "0") errs += 'Recipient\'s State of Residence\n'	
		
	 if (emailCheck(frmMain.emailaddress.value," your ") == false) {
	  frmMain.emailaddress.focus();
	  return (false);
	 }
	
	 if (emailCheck(frmMain.RemailAddress.value," your ") == false) {
	  frmMain.RemailAddress.focus();
	  return (false);
	 }

	
	  //Set the postcard template id
	  frmMain.postcardTemplateID.value=arrPostcardTemplates[iImgIndex].id;
	  //Set the postcard image tag (only used by the preview page)
	  frmMain.postcardImageTag.value=arrPostcardTemplates[iImgIndex].imageTag;

	
	if (errs!='') errs = 'You left the following required fields blank:\n' + errs
	if (errs!='') { alert(errs); return false } else return true
}


//****************************************	  

//**This Function validates form on contact.asp

//*********************************
function checkRadio(button) {
	var radioValue = null;
	
	for (var i=0; i <button.length ; i++) {
		if (button[i].checked) {
			radioValue = button[i].value;
			break;
		}
	}

	if (radioValue == null) {
		return false;
	} else {
		return true;
	}	
}
function checkContactForm(contactfrm) {
	var errs = ''
	var checkedoff = ''
	if (contactfrm.elements.subjectid.options[contactfrm.elements.subjectid.selectedIndex].value == "0") errs += 'This message is in reference to\n'
	if (isBlank(contactfrm.elements.Name1.value)) errs += 'First Name\n'
	if (isBlank(contactfrm.elements.Name2.value)) errs += 'Last Name\n'
	if (isBlank(contactfrm.elements.Address1.value)) errs += 'Address\n'
	if (isBlank(contactfrm.elements.City.value)) errs += 'City\n'
	if (isBlank(contactfrm.elements.EmailAddress.value)) errs += 'E-Mail\n'
	if (isBlank(contactfrm.elements.Message.value)) errs += 'Type your question or comment here\n'
	if (checkRadio(contactfrm.elements.over18)==false) errs += 'Please indicate whether or not you are over 18 years old.\n'		
		 
	 //if (emailCheck(contactfrm.EmailAddress.value,"") == false) {
	 // contactfrm.EmailAddress.focus();
	 // return (false);
	 //}
	
	if (errs!='') errs = 'You left the following field(s) blank:\n' + errs + 'Please complete the form and resubmit.'
	if (errs!='') { alert(errs); return false } else return true
}


//****************************************	  

	//-- This function opens the contest popup window.
	<!-- Begin
	function Popup(page) {
	OpenWin = this.open(page, "Contest", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=645,height=500,screenX=5,screenY=5,top=5,left=5");
	}
	
	//Trim Functions
	function AllTrim(myString) 
		{ 
		//This JavaScript function performs the same task as the 
		//Trim() function in VB. It will trim the spaces on 
		//both sides of the string that was passed. 
		while (myString.charAt(0)==' ') myString=myString.substring(1); 
		while (myString.charAt(myString.length - 1) ==' ') 
		myString=myString.substring(0,myString.length - 1); 
		return myString; 
	} 
	function LeftTrim(myString) 
		{ 
		//This JavaScript function performs the same task as the 
		//LTrim() function in VB. It will trim the spaces on 
		//the left side of the string that was passed. 
		while (myString.charAt(0)==' ') myString=myString.substring(1); 
		return myString; 
	} 
	function RightTrim(myString) 
		{ 
		//This JavaScript function performs the same task as the 
		//RTrim() function in VB. It will trim the spaces on 
		//the right side of the string that was passed. 
		while (myString.charAt(myString.length - 1) ==' ') 
		myString=myString.substring(0,myString.length - 1); 
		return myString; 
	} 
	
	
	// End -->




//-->