
	var reservedArray = new Array();
reservedArray[0] = '|';
reservedArray[1] = ';';
reservedArray[2] = '=';
reservedArray[3] = '$';
reservedArray[4] = '%';
reservedArray[5] = '!';
reservedArray[6] = '*';
reservedArray[7] = '^';
reservedArray[8] = '?';
reservedArray[9] = '~';

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;
}
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;
}

function isReserved(s,n) {

  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    var rLength = reservedArray.length;
    	for (var j = 0; j < rLength; j++) {
    		if(c == reservedArray[j]){
    			alert('The field "' + n + '" contains a special character you cannot use. That special character is: \n' + ' \n' + reservedArray[j]);
    			return false;
    		}
    	}
  }
  return true;
}

function getCookie(name){	// function to grab cookie using name of cookie
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return 'null';
}
//............. function to set cookie

function setCookie(name, value, expires, path, domain, secure) { 
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}
//............. function to delete cookie using name of cookie

function delCookie (name,path,domain) {	
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//..................................................................................

function checkMandatoryFields(f){
	if(mandatoryList){
		for(x=0;x<mandatoryList.length;x++){
			thisObj = eval('f.' + mandatoryList[x]);
			if(!thisObj.value)return 0;
			if(!stripSpaces(thisObj.value))return 0;
		}
	}
	return 1;
}
//..................................................................................

function checkPulldown(list,f,choose){
	if((list) && (list.length >0)){	// check to see if there is a list of pulldown lists
		for(x=0;x<list.length;x++){	// loop thru list
			myObj = eval('f.' +  checkPulldownList[x])
			if(myObj.options.length!=0){
				for(y=0;y<myObj.options.length;y++){
					if(myObj.options[y].value != "spacer"){
					  if(myObj.options[y].value)myObj.options[y].selected=choose;
					}
				}			
			}
		}
	}
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function checkRANGE(e){
	var additional=""
		if(e.value.charAt(2)=="-" && e.value.charAt(5)=="-"){
			if(e.value.length!=10){
				additional += "\n Birthdate must be 10 characters long" ;
			}else{
				b = e.value.split("-")
				if(b.length!=3){
					additional += "\n Birthdate is not formed right, please use this format \n\n 03-31-1960" ;
				}else{
					
						if(isNaN(b[0]))additional += "\n Birth month not formed right, Enter numbers for the month like:\n\n 03" ;
						if(isNaN(b[1]))additional += "\n Birth day not formed right, Enter numbers for the day like:\n\n 31" ;
						if(isNaN(b[2]))additional += "\n Birth year not formed right, Enter numbers for the year like:\n\n 1960" ;
				
						if(b[0] > 12)additional += "\n Birth month not formed right, Enter numbers for the month like:\n\n 03" ;
						if(b[1] > 31)additional += "\n Birth day not formed right, Enter numbers for the day like:\n\n 31" ;
						if(b[2] > 2000)additional += "\n Birth year not formed right, Enter numbers for the year like:\n\n 1960" ;
						
				}
			}
		
		}else{
			additional += "\n Birthdate is not formed right, please use this format \n\n 03-31-1960" ;
		}
		
		if(additional){
			alert(additional);
			return false;
			
		}
		

	var month,day,year;

	month = b[0] - 1;
	day = Math.round(b[1]);
	year = parseInt(b[2]);
	
	
	
		if((!year) || (!day) || (month<0)){
			additional = "\n Please update your birthdate \n" ;
			alert(additional);
			return false;
		}else{
			var today = new Date()
			var userage = new Date()
			userage.setMonth(month)
			userage.setDate(day)
			userage.setFullYear(year)
			difference = (today.getTime() - userage.getTime())
			difference = (difference / (1000 * 60 * 60 * 24 * 365.25));
			
				if(difference >= 12.999){
			
							for(i in fields){
								if(fields[i] && fields[i] != "birthdate"){
									if(document.promoform[fields[i]])document.promoform[fields[i]].disabled=0;
								}else{
									if(fields[i]){
										if(document.promoform[fields[i]])document.promoform[fields[i]].disabled=1;
									}
								}
							}
				}else{
						additional = "\n\n Sorry but you are not eligible to register or participate in this activity at this time.  For more information, please consult our privacy policy \n\n";
						alert(additional);
						return false;
				}
		}
	

  
 return true;


	
}

var emailf;
function checkForm(f) {
  var msg,errormsg;
  var empty_fields="";
  var additional = "";
  var checkmsg = "";
  var errors = "";
  var pwdmsg = "";
  var counter = 0;
 
  var myNum = 0;
  var d = 0;
  var g = 0;
  var radio=0;
  var checkList = new Array();
  var badList = [];
  var errorlist = new Array();
  var ranges = (ranges)?ranges:'';
	
	//fields, formcheck
	
var oInput = document.createElement('input');
oInput.setAttribute('name', 'formcheck');
oInput.setAttribute('type', 'hidden');
oInput.setAttribute('value','100');
f.appendChild(oInput);


// check to see if we should check for birthdate
for(i in fields){
	if(fields[i] == "birthdate"){
	
		break;
	}
}

if(!checkRANGE(document.promoform.birthdate))return false;

    // since range questions have a unique format lets find this question
   
	if(ranges){
		for(var gg=0;gg<ranges.length;gg++){
			if(mandatory[ranges[gg].question] && ranges[gg].length>0){
				// build  string from choices
				var str = new Array();
				if(ranges[gg].length > 0){
					for(var zz = 0;zz<ranges[gg].length;zz++){
						
						if(!ranges[gg].min)continue;
						var q = ranges[gg].question + '_range_' + (zz+1);
						var numMatch=/^[0-9]+$/;
						if(f[q] && f[q].value){
							
							if(!f[q].value.match(numMatch)){
								additional += "\n error #1:" + ranges[gg].question + " choice: " + (zz+1) + " must be a number between :\n\n " + ranges[gg].min + " and " + ranges[gg].max 
								errorlist.push(additional);
							}else{
								if(parseInt(f[q].value) < parseInt(ranges[gg].min) || parseInt(f[q].value) > parseInt(ranges[gg].max) ){
									additional += "\n error #2:" + ranges[gg].question + " choice: " + (zz+1) + " must be a number between :\n\n " + ranges[gg].min + " and " + ranges[gg].max ;
									errorlist.push(additional);
								}else{
									str.push(f[q].value);
								}
							}
						}else{
							
								additional += "\n error #3:" + ranges[gg].question + " choice: " + (zz+1) + " must be a number between :\n\n " + ranges[gg].min + " and " + ranges[gg].max 
								errorlist.push(additional);
						}
						var r = ranges[gg].question;
						
					}
					f[ranges[gg].question].value = str.join("|");
				}
			}
		}
	
	}
	

  for (var i=0; i<f.length; i++) {
    var e = f.elements[i];
	
	/// do some generic testing first before anything.
	if(e.name=="age"){
		if(isNaN(e.value))additional += "\n Age should be a number" ;
	}
	if(e.name=="birthdate"){
		if(e.value.charAt(2)=="-" && e.value.charAt(5)=="-"){
			if(e.value.length!=10){
				additional += "\n Birthdate must be 10 characters long" ;
			}else{
				b = e.value.split("-")
				if(b.length!=3){
					additional += "\n Birthdate is not formed right, please use this format \n\n 03-31-1960" ;
				}else{
					
						if(isNaN(b[0]))additional += "\n Birth month not formed right, Enter numbers for the month like:\n\n 03" ;
						if(isNaN(b[1]))additional += "\n Birth day not formed right, Enter numbers for the day like:\n\n 31" ;
						if(isNaN(b[2]))additional += "\n Birth year not formed right, Enter numbers for the year like:\n\n 1960" ;
				
						if(b[0] > 12)additional += "\n Birth month not formed right, Enter numbers for the month like:\n\n 03" ;
						if(b[1] > 31)additional += "\n Birth day not formed right, Enter numbers for the day like:\n\n 31" ;
						if(b[2] > 2000)additional += "\n Birth year not formed right, Enter numbers for the year like:\n\n 1960" ;
						
				}
			}
		
		}else{
			additional += "\n Birthdate is not formed right, please use this format \n\n 03-31-1960" ;
		}
		
		if(additional){
			alert(additional);
			return false;
			
		}
		emailf=b[2]+'-'+b[0]+'-'+b[1];
	//e.value=b[2]+'-'+b[0]+'-'+b[1];	
	}
	
	// MANDATORY
	//if(e.name.indexOf('_range')!=-1){
		//var sname = e.name.split('_');
		
	//}
	
	
	
	
	mandatory[e.name] = (mandatory[e.name]) ? 1:0;
	
	
		if(mandatory[e.name]){
		
			if(e.type.indexOf('select') > -1) {											// is pulldown menu
   						if(e.selectedIndex < 1)empty_fields += "\n        " + e.name;
   						
   			}
			if(e.type.indexOf('text')>-1){ // text fields
   						if((e.value == null) || (e.value == "") || isblank(e.value)) {
      				 			empty_fields += "\n        " + e.name;
       							//continue;
       					}
       					if(!isReserved(e.value,e.name))return false;
						if(e.name=="email")emailCheck(e.value,e);
						if(e.name=="username" && e.value.length<4)empty_fields += "\n        *Username length must be longer than 4 characters*";
						if(e.name=="username" && e.value.length>16)empty_fields += "\n        *Username length must be less than 16 characters*";
						
						
						
						
			}
			if(e.type.indexOf('password')>-1){ // text fields
   						if((e.value == null) || (e.value == "") || isblank(e.value)) {
      				 			empty_fields += "\n        " + e.name;
       							//continue;
       					}
       					if(!isReserved(e.value,e.name))return false;
						
						if(e.value.length<4)empty_fields += "\n        *Password length must be longer than 4 characters*";
			}
			if(e.type.indexOf('radio')>-1 || e.type.indexOf('check')>-1){ // radio buttons
			
					if(badList[e.name]){
						////alert(e.name)
						if(e.checked){
							badList[e.name]=2;
							//alert("checked "+e.name)
						}
					}else{
						
						badList[e.name]=1;
						if(e.checked)badList[e.name]=2;
						checkList.push(e.name)
					}
   						
			}
			
       		
		}else{
			// email or username cannot be optional!!!
			if(e.name=="email"){
				if(!emailCheck(e.value,e))additional += "\n Email address not properly formatted" ;
			}
			if(e.name=="username"){
				if((e.value == null) || (e.value == "") || isblank(e.value) || (e.value.length<4)) {
      				 			additional += "\n Username cannot be less than 4 characters" + e.name;
       			}
			}
		}
	// END MANDATORY 
	
		
	}
	
	for(y=0;y<checkList.length;y++){
		if(badList[checkList[y]]==1){
			checkList[y] = checkList[y].replace('[]','');
			empty_fields += "\n        " + checkList[y];
		}
	}
	
	if(mandatory["password1"]){
		if (!isBlank(f.password1.value) || !isBlank(f.password2.value)) {
			if(f.password1.value != f.password2.value)pwdmsg += "Your password and the confirmation do not match\n";
		}else{
			//pwdmsg += "You must enter both your password and confirmation password.\n";
		}
	}
	
	if (empty_fields){
		msg = "The following required field(s) are empty:" + empty_fields + "\n";
	}
   // if(errors)errormsg = "You must choose an option from the following pulldown menus:" + "\n" + errors + "\n\n";
  	if(msg){
		alert(msg);
		return false;
	}
	if(additional){
			alert(additional);
			return false;
	}
    //if(errormsg)alert(errormsg);
    if(pwdmsg){
		alert(pwdmsg); 
		return false;
	}
	
	if(f.birthdate){
		f.birthdate.disabled=0
	}
	
	//f.birthdate.value=emailf;
   
}


/* 1.1.3: added four letter domain suffix option
   1.1.2: Fixed a bug where trailing . in e-mail address was passing
            (the bug is actually in the weak regexp engine of the browser; I
            simplified the regexps to make it work).
   1.1.1: Removed restriction that countries must be preceded by a domain,
            so abc@host.uk is now legal.  However, there's still the 
            restriction that an address must end in a two or three letter
            word.
     1.1: Rewrote most of the function to conform more closely to RFC 822.
     1.0: Original  */

function emailCheck (emailStr,obj) {
/* 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("Email address seems incorrect (check @ and .'s)")
        obj.focus()
	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 username doesn't seem to be valid.")
    obj.focus()
    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("Destination IP address is invalid!")
                obj.focus()
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
        obj.focus()
        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>4) {
   // the address must end in a two, three, or four letter word.
   alert("The address must end in a two-, three-, or four-letter domain, or two letter country.")
   obj.focus()
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   obj.focus()
   return false
}

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


