function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

function valButton(btn) {
	var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
      
function lenCheck(value, field, category) {
	
		// Requires at least 2 characters to be entered.
	if (value < 2)
		{
			alert('Please enter at least 2 characters in the ' + category + ' field.');
			field.value='';
			field.focus();
			return false;
		}
		
		// Requires at most 29 characters to be entered.
	if (value > 29)
		{
			alert('Please enter no more than 29 characters in the ' + category + ' field.');
			field.value='';
			field.focus();
			return false;
		}
	return true;
}


function Form1_Validator(theForm)
{
	// Create necessary variables.
	var fnameID = theForm.fname;
	var lnameID = theForm.lname;
	var addID = theForm.add;
	var add2ID = theForm.add2;
	var emID = theForm.em;
	var ctID = theForm.ct;
	var stID = theForm.st;
	var zipID = theForm.zip;
	var phone_area_codeID = theForm.phone_area_code;
	var phone_prefixID = theForm.phone_prefix;
	var phone_exchangeID = theForm.phone_exchange;
	var dob_monthID = theForm.dob_month;
	var dob_dayID = theForm.dob_day;
	var dob_yearID = theForm.dob_year;
	var gnID = theForm.gn;
	var btn = valButton(theForm.gn);				// Gender Button
	var cnID = theForm.cn;
	var optoutID = theForm.optout;

	var alphaRegxp = /^([a-zA-Z\s\-]+)$/;			// Letters, whitespace, and hyphen.
	var alphaNumRegxp = /^([0-9A-Za-z\s\-]+)$/;		// Letters, numbers, whitespace, and hyphen.
	var NumRegxp = /^([0-9]+)$/;					// Numbers only -- Any Length.
	
	// First Name Check	
	
		if (!fnameID.value)
			{
				alert('You must enter your First Name.');
				fnameID.value='';
				fnameID.focus();
				return false;
			}
		
		if (alphaRegxp.test(fnameID.value) != true)
			{
				alert('First name contains illegal characters.');
				fnameID.value='';
				fnameID.focus();
				return false;
			}
		
		if (lenCheck(fnameID.value.length, fnameID, 'First Name') == false)
				return false;
		
	// Last Name Check		
	
			if (!lnameID.value)
			{
				alert('You must enter your Last Name.');
				lnameID.value='';
				lnameID.focus();
				return false;
			}								
		
		if (alphaRegxp.test(lnameID.value) != true)
			{
				alert('Last name contains illegal characters.');
				lnameID.value='';
				lnameID.focus();
				return false;
			}

		// Require at least 2 characters and no more than 29 characters to be entered.
		
		if (lenCheck(lnameID.value.length, lnameID, 'Last Name') == false)
				return false;
		
	// Address 1 Check
		// Check for Address Line 1 Field
	
		// Check for Empty String.
			if (!addID.value)
				{
					alert('You must fill in the Address Line 1 Field.');
					addID.value='';
					addID.focus();
					return false;
				}
			if (alphaNumRegxp.test(addID.value) != true)
				{
					alert('Address Line 1 field contains illegal characters.');
					addID.value='';
					addID.focus();
					return false;
				}
			
			if (lenCheck(addID.value.length, addID, 'Address Line 1') == false)
					return false;
	// Address Line 2 Field
		
		// Require at most 29 characters to be entered.
			if (add2ID.value.length > 29)
				{
					alert('Please enter no more than 29 characters in the Address Line 2 field.');
					add2ID.value='';
					add2ID.focus();
					return false;
				}		
						
	// City Check
		// Check for Empty String.
			if (!ctID.value)
				{
					alert('You must fill in the City Field.');
					ctID.value='';
					ctID.focus();
					return false;
				}
			if (alphaRegxp.test(ctID.value) != true)
				{
					alert('City field contains illegal characters.');
					ctID.value='';
					ctID.focus();
					return false;
				}
			
			if (lenCheck(ctID.value.length, ctID, 'City') == false)
					return false;
	// State Selection Check
		if (stID.selectedIndex == '')
			{
				alert('Please select your State.');
				stID.value='';
				stID.focus();
				return false;
			}		
	// Zip Code Check
		
		var zip_len = zipID.value.length;
		if (!zipID)
		{
				alert('You must fill in the Zip Code Field.');
				zipID.value='';
				zipID.focus();
				return false;
		}
		
		if (zip_len != 5)
			{
				alert('Please enter exactly five (5) digits for your Zip Code.');
				zipID.value='';
				zipID.focus();
				return false;
			}
		
		if (NumRegxp.test(zipID.value) != true)
				{
					alert('Please enter only numbers for your Zip Code.');
					zipID.value='';
					zipID.focus();
					return false;
				}
	
	// Email Check
		// Check if Email is Empty.	
		if (!emID.value)
			{
				alert('Please Enter your Email Address');
				emID.focus();
				return false;
			}
		var emailRegxp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		if (emailRegxp.test(emID.value) != true)
			{
				alert('Please enter a valid Email Address.');
				emID.value='';
				emID.focus();
				return false;
			}	
	// Phone Area Code Check

		var pac_len = phone_area_codeID.value.length;
		if (!phone_area_codeID)
		{
				alert('You must fill in the Area Code Field.');
				phone_area_codeID.value='';
				phone_area_codeID.focus();
				return false;
		}
		
		if (pac_len != 3)
			{
				alert('Please enter exactly three (3) digits for your Area Code.');
				phone_area_codeID.value='';
				phone_area_codeID.focus();
				return false;
			}
		
		if (NumRegxp.test(phone_area_codeID.value) != true)
				{
					alert('Please enter only numbers for your Area Code.');
					phone_area_codeID.value='';
					phone_area_codeID.focus();
					return false;
				}
	// Phone Prefix Check
	
		var pre_len = phone_prefixID.value.length;
		if (!phone_prefixID)
		{
				alert('You must fill in the Phone Prefix field.');
				phone_prefixID.value='';
				phone_prefixID.focus();
				return false;
		}
		
		if (pre_len != 3)
			{
				alert('Please enter exactly three (3) digits for your Phone Prefix.');
				phone_prefixID.value='';
				phone_prefixID.focus();
				return false;
			}
		
		if (NumRegxp.test(phone_prefixID.value) != true)
				{
					alert('Please enter only numbers for your Phone Prefix.');
					phone_prefixID.value='';
					phone_prefixID.focus();
					return false;
				}
	// Phone Exchange Check
		
		var ex_len = phone_exchangeID.value.length;
		if (!phone_exchangeID)
		{
				alert('You must fill in the Phone Exchange field.');
				phone_exchangeID.value='';
				phone_exchangeID.focus();
				return false;
		}
		
		if (ex_len != 4)
			{
				alert('Please enter exactly four (4) digits for your Phone Exchange.');
				phone_exchangeID.value='';
				phone_exchangeID.focus();
				return false;
			}
		
		if (NumRegxp.test(phone_exchangeID.value) != true)
				{
					alert('Please enter only numbers for your Phone Exchange.');
					phone_exchangeID.value='';
					phone_exchangeID.focus();
					return false;
				}		
	// DOB Month Check
		if (dob_monthID.selectedIndex == '')
			{
				alert('Please select your Date of Birth Month.');
				dob_monthID.value='';
				dob_monthID.focus();
				return false;
			}		
	// DOB Day Check
		if (dob_dayID.selectedIndex == '')
			{
				alert('Please select your Date of Birth Day.');
				dob_dayID.value='';
				dob_dayID.focus();
				return false;
			}				
	// DOB Year Check
		if (dob_yearID.selectedIndex == '')
			{
				alert('Please select your Date of Birth Year.');
				dob_yearID.value='';
				dob_yearID.focus();
				return false;
			}				
	// Gender Check
		if (btn == null)
		{
			alert('Please select your Gender.');
			return false;
		}
	// Country Check
		if (cnID.selectedIndex == '')
			{
				alert('Please select your Country.');
				cnID.value='';
				cnID.focus();
				return false;
			}
	// Optout Check
	if (!optoutID.checked)
		{
			alert('Please check the Age Verification Box to continue.');
			return false;
		}
	// Otherwise all correct, so exit with true value.	
	
	else
	{
           document.getElementById('phone').value =
              document.getElementById('phone_area_code').value +
              document.getElementById('phone_prefix').value +
              document.getElementById('phone_exchange').value;
            document.getElementById('dob').value =
                document.getElementById('dob_year').options[document.getElementById('dob_year').selectedIndex].value + "-" +
                document.getElementById('dob_month').options[document.getElementById('dob_month').selectedIndex].value + "-" +
                document.getElementById('dob_day').options[document.getElementById('dob_day').selectedIndex].value;
	return true;
	}
	
} // End of Script
