// *** BEGIN Validate Function
function stripSpaces(string) {
	while('' + string.charAt(string.length-1) == ' ')
		string = string.substring(0, string.length-1);
	while('' + string.charAt(0) == ' ')
		string = string.substring(1, string.length);
	return string;
}

	
function checkSpaces(myString)
{
	for(var i=0;i < myString.length;i++)
	{
		if(myString.charAt(i) == ' ')
		{
			return true;
		}
	}
	return false;
}


function validate() {

	/* BEGIN Validate all User information */
	var f=document.UserInfo;
	var MaxFieldCount = 10;
	var validationList = [f.f_FirstNm, f.f_LastNm, f.f_UsrEmail, f.f_Addr1, f.f_City, f.f_State, f.f_Zip, f.f_UsrPhone1, f.f_UsrLogin, f.f_UsrPasswrd];
	var elementNames = ["First Name","Last Name","Email","Address","City","State","Zip Code","Phone Number","User Name","Password"];
	
	var count = 0;
	var ntfyCnt = 0;
	var notificationList = new Array();
	while(count < MaxFieldCount) {
	  if(typeof validationList[count] == "undefined" ) {
	  } else {
		  if(validationList[count].name == "State") {
			if(f.state.options[f.state.options.selectedIndex].value == ""){
			  notificationList[ntfyCnt] = "State \n";
			  ntfyCnt++;
			}
		  } else {
			if(validationList[count].value == null || stripSpaces(validationList[count].value).length < 1 ) {
			  notificationList[ntfyCnt] = " \t" + elementNames[count] + " \n" ;
			  ntfyCnt++;
			}
		  }
	  }
	  count++;
	}
	var errorString = "";
	if(notificationList.length > 0){
	
			for(i = 0; i < notificationList.length; i++){
					errorString = errorString + notificationList[i];
			}
	}
	
	if(errorString.length > 1){
			alert("The following fields have not been filled in: \n \n" + errorString );
			return false;
	}
	/* END Validate all User information */

		/* VERIFY USER NAME */
		if (UsrLogin.length < 4) {
			alert("The username is the wrong length.\n");
			f.UsrLogin.focus();
			f.UsrLogin.blur();
			f.UsrLogin.select();
			return false;
		}
		
		
	
	/* VERIFY PASSWORD */
	if (f.UsrPasswrd.value.length < 6 || f.UsrPasswrd.value.length > 20) {
	  f.UsrPasswrd.value="";
	  f.UsrPasswrdVerify.value="";
	  alert("Password must be 6-20 characters in length. Please choose a new password.");
	  return false;
	}
		if (f.UsrPasswrd.value != f.UsrPasswrdVerify.value){
	
			f.UsrPasswrd.value="";
			f.UsrPasswrdVerify.value="";
			alert("Password must match re-typed password. \n Please correct and re-submit information.");
			return false;
		}

	
		if(checkSpaces(f.UsrPasswrd.value))
		{
			f.UsrPasswrd.value="";
			f.UsrPasswrdVerify.value="";
			alert("Your password cannot contain spaces. \n Please re-enter and re-submit information.");
			f.UsrPasswrd.focus();
			f.UsrPasswrd.blur();
			f.UsrPasswrd.select();
			return false;
		}


var emailStr=document.UserInfo.f_UsrEmail.value;	
return emailCheck(emailStr);
}

// *** END Validate Function





/* BEGIN EMAIL VALIDATION FUNCTION
	This script and many more are available free online at
	The JavaScript Source!! http://javascript.internet.com
*/
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. */
	   if(emailStr.length == 0) {
		 var errStr="You did not enter an e-mail address. Please enter and confirm your e-mail address in the spaces provided."
		 alert(errStr)
		 return false
	   }
	
	/* 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("Your e-mail address seems to be incorrect. Please check the characters @ and .")
	  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("The email account username doesn't seem to be valid. Please check the email address again.")
		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("The destination IP in this e-mail address is invalid. Please try again. (This is a numeric name such as 220.12.15.112, as opposed to a symbolic host name like 'CompanyName.com')")
		return false
		  }
		}
		return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
	  alert("The domain name (.com, .org, .net, etc.) doesn't seem to be valid. Please try again.");
		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>6) {
	   // the address must end in a two letter or three letter word.
	   alert("The e-mail address must include a domain name such as .com, .org, .ca, etc. Please add it and try again.");
	   return false;
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="The e-mail address must include a host name. (i.e., the name following @, such as \"@CompanyName.com\")";
	   alert(errStr);
	   return false;
	}

// If we've gotten this far, everything's valid!
return true;
}
//  End









function ValidateShipInfo() {

	/* BEGIN Validate all User information */
	var f=document.BillInfo;
	var MaxFieldCount = 7;
	var validationList = [f.f_SFirstNm, f.f_SLastNm, f.f_SAddr1, f.f_SCity, f.f_SState, f.f_SZip, f.f_SUsrPhone];
	var elementNames = ["First Name","Last Name","Address","City","State","Zip Code","Phone Number"];
	
	var count = 0;
	var ntfyCnt = 0;
	var notificationList = new Array();
	while(count < MaxFieldCount) {
	  if(typeof validationList[count] == "undefined" ) {
	  } else {
		  if(validationList[count].name == "State") {
			if(f.state.options[f.state.options.selectedIndex].value == ""){
			  notificationList[ntfyCnt] = "State \n";
			  ntfyCnt++;
			}
		  } else {
			if(validationList[count].value == null || stripSpaces(validationList[count].value).length < 1 ) {
			  notificationList[ntfyCnt] = " \t" + elementNames[count] + " \n" ;
			  ntfyCnt++;
			}
		  }
	  }
	  count++;
	}
	var errorString = "";
	if(notificationList.length > 0){
	
			for(i = 0; i < notificationList.length; i++){
					errorString = errorString + notificationList[i];
			}
	}
	
	if(errorString.length > 1){
			alert("The following fields have not been filled in: \n \n" + errorString );
			return false;
	}
	/* END Validate all User information */



return true;
}
// *** END Validate Function




// *** BEGIN Validate Order Form
function ValidateOrderForm(){
	/* BEGIN Validate all User information */
	var f=document.OrderForm;
	var MaxFieldCount = 3;
	var validationList = [f.f_ItmSku, f.f_ItmExtColr, f.f_ItmQty];
	var elementNames = ["Color and Size","Custom Firebird Color", "Item Quantity"];
	

	var count = 0;
	var ntfyCnt = 0;
	var notificationList = new Array();
	while(count < MaxFieldCount) {
	  if(typeof validationList[count] == "undefined" ) {
	  } else {
		if(validationList[count].value == null || stripSpaces(validationList[count].value).length < 1 ) {
		  notificationList[ntfyCnt] = " \t" + elementNames[count] + " \n" ;
		  ntfyCnt++;
		}
	  }
	  count++;
	}
	var errorString = "";
	if(notificationList.length > 0){
		for(i = 0; i < notificationList.length; i++){
				errorString = errorString + notificationList[i];
		}
	}
	
	if(errorString.length > 1){
			alert("The following fields have not been filled in: \n \n" + errorString );
			return false;
	}
	/* END Validate all User information */
return true;
}
// *** END Validate Order Form






// BEGIN "image" rollovers
/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_over'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

window.onload = initRollovers;
 
// END "image" rollovers
