var isNav, isIE
var range	= ""
var style 	= ""
var outerDiv 	=""

if (navigator.appVersion.indexOf("MSIE") != -1) 
{
	isIE		= true
	var range 	= "all."
	var style 	= ".style"
} 
else 
{
	isNav 		= true
	outerDiv	= ""
}			
function PaidformCheck(mode)
{ 

	if ((mode == "SHORT")||(mode=="SHORTRN"))
	{
		if(document.forms[0].FNAME.value == "")
		{
			alert("Please specify your First name.");
	       		document.forms[0].FNAME.focus();
			return false;
		}
		if(document.forms[0].LNAME.value == "")
		{
			alert("Please specify your Last name.");
       			document.forms[0].LNAME.focus();
			return false;
		}
		if (!CheckBusAddress())
		{
			return false;
		}

		if (!document.forms[0].PRODUCT.checked)	
		{
			alert("Please select your subscription.");
        		document.forms[0].PRODUCT.focus();
			return false;
		}
		if (!CheckPaymentInfo())
		{
			return false;
		}
		return true;
	}



	if(!checkUnselects(document.forms[0].PRODUCT))	
	{
		alert("Please select your subscription.");
        	document.forms[0].PRODUCT[0].focus();
		return false;
	}

	if ((CheckedRadioValue(document.forms[0].PRODUCT) == "01")||(CheckedRadioValue(document.forms[0].PRODUCT) == "02") || (CheckedRadioValue(document.forms[0].PRODUCT) == "03") || (CheckedRadioValue(document.forms[0].PRODUCT) == "21") || (CheckedRadioValue(document.forms[0].PRODUCT) == "22") || (CheckedRadioValue(document.forms[0].PRODUCT) == "23"))
	{
        if (document.forms[0].EMAIL_ADDRESS.value == "")
		{
			alert("Please enter email address.");
		        document.forms[0].EMAIL_ADDRESS.focus();
			return false;
		}
		
        if (document.forms[0].EMAIL_ADDRESS.value != "") 
        {
            if(!validEmail(document.forms[0].EMAIL_ADDRESS.value))
	       {
		      alert("You have entered an invalid email address. Please re-enter it.");
		      document.forms[0].EMAIL_ADDRESS.focus();
		      return false;
	       }	 
	       if (document.forms[0].EMAIL_ADDRESS2.value == "")
	       {
		      alert("Please confirm your email address.");
		      document.forms[0].EMAIL_ADDRESS2.focus();
		      return false;
            }
        
            if(document.forms[0].EMAIL_ADDRESS.value != document.forms[0].EMAIL_ADDRESS2.value)
	       {
	           alert("Confirmation email address does not match email address.");
	           document.forms[0].EMAIL_ADDRESS.focus();
	           return false;
	       }
        }   
        if(document.forms[0].WEB_ACCESS_PASSWORD.value == "")
	   	{
 			alert("Please provide a password for access to Fire Engineering Online.");
			document.forms[0].WEB_ACCESS_PASSWORD.focus();
			return false;
		}

	 	if ((document.forms[0].WEB_ACCESS_PASSWORD.value != "")&& (document.forms[0].PASSWORD2.value == ""))
		{
			alert("Please confirm your Password.");
        		document.forms[0].PASSWORD2.focus();
			return false;
		}
		if (document.forms[0].WEB_ACCESS_PASSWORD.value != document.forms[0].PASSWORD2.value)
		{
			alert("Please re-enter your Password.");
        		document.forms[0].WEB_ACCESS_PASSWORD.focus();
			return false;
		}
	}

	
	if (!CheckPaymentInfo())
	{
		return false;
	}

	if ((mode == "ADD"))
  	{
		if(document.forms[0].FNAME.value == "")
		{
			alert("Please specify your First name.");
	       		document.forms[0].FNAME.focus();
			return false;
		}
		if(document.forms[0].LNAME.value == "")
		{
			alert("Please specify your Last name.");
       			document.forms[0].LNAME.focus();
			return false;
		}
	}
	if (mode != "RENEW") 
  	{
		if (!CheckBusAddress())
		{
			return false;
		}
		if (!CheckHomeAddress())
		{
			return false;
		}
	} 
	
	//if(!checkUnselects(document.forms[0].DEPT_MEMBER))	
	//{
	//	alert("Please select your Member status.");
	//       	document.forms[0].DEPT_MEMBER[0].focus();
	//	return false;
//	}
		
	if ((CheckedRadioValue(document.forms[0].PRODUCT) == "01")||(CheckedRadioValue(document.forms[0].PRODUCT) == "02") || (CheckedRadioValue(document.forms[0].PRODUCT) == "03") || (CheckedRadioValue(document.forms[0].PRODUCT) == "21") || (CheckedRadioValue(document.forms[0].PRODUCT) == "22") || (CheckedRadioValue(document.forms[0].PRODUCT) == "23"))
	{
        if (document.forms[0].EMAIL_ADDRESS.value == "")
		{
			alert("Please enter email address.");
		        document.forms[0].EMAIL_ADDRESS.focus();
			return false;
		}
		
        if (document.forms[0].EMAIL_ADDRESS.value != "") 
        {
            if(!validEmail(document.forms[0].EMAIL_ADDRESS.value))
	       {
		      alert("You have entered an invalid email address. Please re-enter it.");
		      document.forms[0].EMAIL_ADDRESS.focus();
		      return false;
	       }	 
	       if (document.forms[0].EMAIL_ADDRESS2.value == "")
	       {
		      alert("Please confirm your email address.");
		      document.forms[0].EMAIL_ADDRESS2.focus();
		      return false;
            }
        
            if(document.forms[0].EMAIL_ADDRESS.value != document.forms[0].EMAIL_ADDRESS2.value)
	       {
	           alert("Confirmation email address does not match email address.");
	           document.forms[0].EMAIL_ADDRESS.focus();
	           return false;
	       }
        }   
        if(document.forms[0].WEB_ACCESS_PASSWORD.value == "")
	   	{
 			alert("Please provide a password for access to Fire Engineering Online.");
			document.forms[0].WEB_ACCESS_PASSWORD.focus();
			return false;
		}

	 	if ((document.forms[0].WEB_ACCESS_PASSWORD.value != "")&& (document.forms[0].PASSWORD2.value == ""))
		{
			alert("Please confirm your Password.");
        		document.forms[0].PASSWORD2.focus();
			return false;
		}
		if (document.forms[0].WEB_ACCESS_PASSWORD.value != document.forms[0].PASSWORD2.value)
		{
			alert("Please re-enter your Password.");
        		document.forms[0].WEB_ACCESS_PASSWORD.focus();
			return false;
		}
	}
}

function PaidformCheckAlt(mode)
{ 
	if(!checkUnselects(document.forms[0].PRODUCT))	
	{
		alert("Please select your subscription.");
        	document.forms[0].PRODUCT[0].focus();
		return false;
	}
	
	if(!checkUnselects(document.forms[0].PAY_STAT))	
	{
		alert("Please specify payment method.");
        	document.forms[0].PAY_STAT[0].focus();
		return false;
	}

	if(document.forms[0].PAY_STAT[1].checked)
	{// check payment info if PAY_STAT=2 or credit payment
	
		if (!CheckPaymentInfo())
		{
			return false;
		}	
	}

    if (mode == "ADD")
	{
		if(document.forms[0].FNAME.value == "")
		{
			alert("Please specify your First name.");
        		document.forms[0].FNAME.focus();
			return false;
		}
		if(document.forms[0].LNAME.value == "")
		{
			alert("Please specify your Last name.");
        		document.forms[0].LNAME.focus();
			return false;
		}
	}

	if (mode != "RENEW")
	{
		if (!CheckBusAddress())
		{
			return false;
		}
		if (!CheckHomeAddress())
		{
			return false;
		}

	if(!checkUnselects(document.forms[0].DEPT_MEMBER))	
		{
			alert("Please select your Member status.");
        		document.forms[0].DEPT_MEMBER[0].focus();
			return false;
		}
	}
	
	if ((CheckedRadioValue(document.forms[0].PRODUCT) == "01")|| (CheckedRadioValue(document.forms[0].PRODUCT) == "02") || (CheckedRadioValue(document.forms[0].PRODUCT) == "03") || (CheckedRadioValue(document.forms[0].PRODUCT) == "21") || (CheckedRadioValue(document.forms[0].PRODUCT) == "22") || (CheckedRadioValue(document.forms[0].PRODUCT) == "23"))
	{
        if (document.forms[0].EMAIL_ADDRESS.value == "")
		{
			alert("Please enter email address.");
		        document.forms[0].EMAIL_ADDRESS.focus();
			return false;
		}
            if(!validEmail(document.forms[0].EMAIL_ADDRESS.value))
	       {
		      alert("You have entered an invalid email address. Please re-enter it.");
		      document.forms[0].EMAIL_ADDRESS.focus();
		      return false;
	       }	 
	       if (document.forms[0].EMAIL_ADDRESS2.value == "")
	       {
		      alert("Please confirm your email address.");
		      document.forms[0].EMAIL_ADDRESS2.focus();
		      return false;
            }
        
            if(document.forms[0].EMAIL_ADDRESS.value != document.forms[0].EMAIL_ADDRESS2.value)
	       {
	           alert("Confirmation email address does not match email address.");
	           document.forms[0].EMAIL_ADDRESS.focus();
	           return false;
	       }
         
        if(document.forms[0].WEB_ACCESS_PASSWORD.value == "")
	   	{
 			alert("Please provide a password for access to Fire Engineering Online.");
			document.forms[0].WEB_ACCESS_PASSWORD.focus();
			return false;
		}

	 	if ((document.forms[0].WEB_ACCESS_PASSWORD.value != "")&& (document.forms[0].PASSWORD2.value == ""))
		{
			alert("Please confirm your Password.");
        		document.forms[0].PASSWORD2.focus();
			return false;
		}
		if (document.forms[0].WEB_ACCESS_PASSWORD.value != document.forms[0].PASSWORD2.value)
		{
			alert("Please re-enter your Password.");
        		document.forms[0].WEB_ACCESS_PASSWORD.focus();
			return false;
		}
	}
}

function AcceptformCheck()
{ 
	if (!document.forms[0].RECEIVE_YES_NO.checked)
	{
		alert("You have not accepted the offer. Please check 'Yes' box.");
        	document.forms[0].RECEIVE_YES_NO.focus();
		return false;
	}

	//if (document.forms[0].JOB_TITLE_OTHER.value == "")
	//{
	//	alert("Please specify your Rank.");
	//        document.forms[0].JOB_TITLE_OTHER.focus();
	//	return false;
	//}

	if (document.forms[0].COMPANY.value == "")
	{
		alert("Please specify your Department.");
	        document.forms[0].COMPANY.focus();
		return false;
	}
}

function BillmeformCheck(mode)
{ 
	if (mode == "ADD")
  	{
		if(document.forms[0].FNAME.value == "")
		{
			alert("Please specify your First name.");
	       		document.forms[0].FNAME.focus();
			return false;
		}
		if(document.forms[0].LNAME.value == "")
		{
			alert("Please specify your Last name.");
       			document.forms[0].LNAME.focus();
			return false;
		}
	}

	if (mode != "RENEW") 
  	{
		if (!CheckBusAddress())
		{
			return false;
		}
	} 
}

function CheckBusAddress()
{
	if(document.forms[0].ADDRESS2.value == "")
	{
		alert("Please specify your Street Address.");
	        document.forms[0].ADDRESS2.focus();
		return false;
	}
	if(document.forms[0].CITY.value == "")
	{
		alert("Please specify your City.");
	        document.forms[0].CITY.focus();
		return false;
	}
	if (document.forms[0].STATE[document.forms[0].STATE.selectedIndex].value == "")
	{
		alert("Please specify your State/Province or select 'I am not in the U.S. or Canada'.");
		       document.forms[0].STATE.focus();
		return false;
	}

	// validate Canadian state/postal code combination
	if (!ValidCanPostal(document.forms[0].STATE[document.forms[0].STATE.selectedIndex].value,document.forms[0].ZIPCODE.value))
	{
		alert ("Invalid Canadian province/postal code combination.");
        	document.forms[0].STATE.focus();
		return false;
	}
		
	if (document.forms[0].STATE[document.forms[0].STATE.selectedIndex].value == "53")
	{
		if (ObjectExists(document.forms[0], "COUNTRY"))
		{
			if (document.forms[0].COUNTRY[document.forms[0].COUNTRY.selectedIndex].value == "")
			{
				alert("Please specify your Country.");
	        		document.forms[0].COUNTRY.focus();
				return false;
			}
		}
	}
	else
	{
		if (document.forms[0].ZIPCODE.value.length < 5)
		{
			alert("Please specify your Zip/Postal Code.");
	        	document.forms[0].ZIPCODE.focus();
			return false;
		}
	}
        
	if (ObjectExists(document.forms[0], "COUNTRY"))
	{	
		if((document.forms[0].COUNTRY[document.forms[0].COUNTRY.selectedIndex].value == "NIGERIA")||(document.forms[0].COUNTRY[document.forms[0].COUNTRY.selectedIndex].value == "GHANA"))
        {
			alert("We have encountered problems processing your order.Please contact fesub@pennwell.com to complete your subscription request.");
		
			return false;
        }
	}
	
//	if (document.forms[0].formname.value!="CREDIT")
 	if (ObjectExists(document.forms[0], "REQUESTED_VERSION"))
	{
		if((document.forms[0].EMAIL_ADDRESS.value == "")&&(document.forms[0].REQUESTED_VERSION[0].checked == true))
		{
			alert("Please specify your E-mail Address.");
	       		document.forms[0].EMAIL_ADDRESS.focus();
			return false;
	    }
	}
	if (document.forms[0].EMAIL_ADDRESS.value!='')	
	{
		if (!validEmail(document.forms[0].EMAIL_ADDRESS.value))
		{
			alert("You have entered an invalid email address. Please re-enter it.");
			document.forms[0].EMAIL_ADDRESS.focus();
			return false;
		}
	       if (document.forms[0].EMAIL_ADDRESS2.value == "")
	       {
		      alert("Please confirm your email address.");
		      document.forms[0].EMAIL_ADDRESS2.focus();
		      return false;
            }
        
            if(document.forms[0].EMAIL_ADDRESS.value != document.forms[0].EMAIL_ADDRESS2.value)
	       {
	           alert("Confirmation email address does not match email address.");
	           document.forms[0].EMAIL_ADDRESS.focus();
	           return false;
	       }
	}
	
	return true;
}

function CheckHomeAddress()
{
	if (ObjectExists(document.forms[0], "HOME_COUNTRY"))
	{	
		if ((document.forms[0].HOME_ADDRESS1.value != "") || 
		(document.forms[0].HOME_ADDRESS2.value != "") || 
		(document.forms[0].HOME_CITY.value != "") || 
		(document.forms[0].HOME_ZIPCODE.value != "") || 
		(document.forms[0].HOME_COUNTRY.value != "") || 
		(document.forms[0].HOME_STATE.selectedIndex > 0))
		{
			if (document.forms[0].HOME_ADDRESS2.value == "")
			{
				alert("Please specify your optional delivery Street Address.");
	       		document.forms[0].HOME_ADDRESS2.focus();
				return false;
			}
			if (document.forms[0].HOME_CITY.value == "")
			{
				alert("Please specify your optional delivery City.");
        		document.forms[0].HOME_CITY.focus();
				return false;
			}
			if (document.forms[0].HOME_STATE.selectedIndex == 0)
			{
				alert("Please specify your optional delivery State/Province or select 'I am not in the US or Canada'.");
		        document.forms[0].HOME_STATE.focus();
				return false;
			}

			// validate Canadian state/postal code combination
			if (!ValidCanPostal(document.forms[0].HOME_STATE[document.forms[0].HOME_STATE.selectedIndex].value,document.forms[0].HOME_ZIPCODE.value))
			{			
				alert ("Invalid optional delivery Canadian province/postal code combination.");
	        	document.forms[0].HOME_STATE.focus();
				return false;
			}

			if (document.forms[0].HOME_STATE[document.forms[0].HOME_STATE.selectedIndex].value == "53")
			{
				if (document.forms[0].HOME_COUNTRY.value == "")
				{
					alert("Please specify your optional delivary Country.");
	        		document.forms[0].HOME_COUNTRY.focus();
					return false;
				}
			}
			else
			{
				if (document.forms[0].HOME_ZIPCODE.value.length < 5)
				{
					alert("Please specify your optional delivery Zip/Postal Code.");
	        		document.forms[0].HOME_ZIPCODE.focus();
					return false;
				}
			}
		}
	}
	else
	{
		if ((document.forms[0].HOME_ADDRESS1.value != "") || 
		(document.forms[0].HOME_ADDRESS2.value != "") || 
		(document.forms[0].HOME_CITY.value != "") || 
		(document.forms[0].HOME_ZIPCODE.value != "") || 
		(document.forms[0].HOME_STATE.selectedIndex > 0))
		{
			if (document.forms[0].HOME_ADDRESS2.value == "")
			{
				alert("Please specify your optional delivery Street Address.");
	       		document.forms[0].HOME_ADDRESS2.focus();
				return false;
			}
			if (document.forms[0].HOME_CITY.value == "")
			{
				alert("Please specify your optional delivery City.");
        		document.forms[0].HOME_CITY.focus();
				return false;
			}
			if (document.forms[0].HOME_STATE.selectedIndex == 0)
			{
				alert("Please specify your optional delivery State/Province or select 'I am not in the US or Canada'.");
		        document.forms[0].HOME_STATE.focus();
				return false;
			}

			// validate Canadian state/postal code combination
			if (!ValidCanPostal(document.forms[0].HOME_STATE[document.forms[0].HOME_STATE.selectedIndex].value,document.forms[0].HOME_ZIPCODE.value))
			{			
				alert ("Invalid optional delivery Canadian province/postal code combination.");
	        	document.forms[0].HOME_STATE.focus();
				return false;
			}

			if (document.forms[0].HOME_ZIPCODE.value.length < 5)
			{
				alert("Please specify your optional delivery Zip/Postal Code.");
        		document.forms[0].HOME_ZIPCODE.focus();
				return false;
			}
		}
	}
	return true;
}

function CheckPaymentInfo()
{

    if(!checkUnselects(document.forms[0].PAY_STAT))	
	{
		alert("Please specify payment method.");
        	document.forms[0].PAY_STAT[0].focus();
		return false;
	}

	if(document.forms[0].PAY_STAT[0].checked)
	// don't check anything for mail payments
	{
		return true;
	}

	if(document.forms[0].PAY_STAT[1].checked)
	// check payment info if PAY_STAT=2
  	{
		if(!checkUnselects(document.forms[0].CARD_TYPE))
		{
			alert("Please specify credit card.");
	        	document.forms[0].CARD_TYPE[0].focus();
			return false;
		}
	
		if(document.forms[0].CARD_NUMBER.value == "")
		{
			alert("Please specify credit card number.");
	        	document.forms[0].CARD_NUMBER.focus();
			return false;
		}
	
		// MasterCard
		if(document.forms[0].CARD_TYPE[0].checked)
		{
			if (!isMasterCard(stripWhitespace(document.forms[0].CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
	        		document.forms[0].CARD_NUMBER.focus();
				return false;
			}
		}
		
		// Visa
		if(document.forms[0].CARD_TYPE[1].checked)
		{
			if (!isVisa(stripWhitespace(document.forms[0].CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
	        		document.forms[0].CARD_NUMBER.focus();
				return false;
			}
		}
	
		// AmEx
		if(document.forms[0].CARD_TYPE[2].checked)
		{
			if (!isAmericanExpress(stripWhitespace(document.forms[0].CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
	        		document.forms[0].CARD_NUMBER.focus();
				return false;
			}
		}
		
		// Discover
		if(document.forms[0].CARD_TYPE[3].checked)
		{
			if (!isDiscover(stripWhitespace(document.forms[0].CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
	        		document.forms[0].CARD_NUMBER.focus();
				return false;
			}
		}
	
		if(!checkDropdown(document.forms[0].ExpMon))
		{
	 		alert('Please select the expiration month.');
			document.forms[0].ExpMon.focus();
	 		return false;
		}
	
		if(!checkDropdown(document.forms[0].ExpYear))
		{
	 		alert('Please select the expiration year.');
			document.forms[0].ExpYear.focus();
	 		return false;
		}
		if(document.forms[0].SCODE.value == "")
		{
			alert("Please specify Security Code.");
	       		document.forms[0].SCODE.focus();
			return false;
		}
   	}

	return true;
}

function checkDropdown(selectBox)
{
	if(selectBox.selectedIndex == "0")
	{
		return false;
	}
	else
	{
		return true;
	}
}

function checkUnselects(radioItem)
{
	for(i=0;i<radioItem.length;i++)
	{
		if(radioItem[i].checked)
		{
			return true;
		}//end if
	}//end for
	return false;
}
 
//
//
// declare global variables
var i;

// two arrays for Canadian province/postal code validation
var CanCodes=new Array("54","55","56","57","58","59","60","66","61","62","63","64","65");
var CanLetters=new Array("T","UV","R","E","A","B","X","X","KLMNP","C","GHJ","S","Y");

// check if first letter of postal code matches selected Canadian province
// StateCD is 2-digit code that Omeda uses to identify Canadian provinces (value of STATE field)
// PostCD is entered postal code (value of ZIPCODE field)
function ValidCanPostal(StateCD, PostCD)
{
	var fletter=PostCD.substring(0,1);
	fletter = fletter.toUpperCase();

	for(i=0;i<13;i++)
	{
		if (StateCD==CanCodes[i])
		{
			if (CanLetters[i].indexOf(fletter,0) == -1)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	return true;
}

function checkEmailValue(emailValue)
{     //runs the validate script and returns error box or nonerror

	if (emailValue == "")
	{
		alert("You have not entered email address. Please re-enter it.");
		return false;
	}

	startPos = 0;

	commaPos = emailValue.indexOf(",",startPos+1);	//position of semicolomn
	while (commaPos != -1)
	{
		endPos = commaPos;
		emailElement = emailValue.substring(startPos,endPos);
		if(!validEmail(emailElement))
		{
			alert("You have entered an invalid email address. Please re-enter it.");
			return false;
		}
		startPos = endPos + 1;		
		commaPos = emailValue.indexOf(",",startPos);	//position of semicolomn
	}
	endPos = emailValue.length;
	emailElement = emailValue.substring(startPos,endPos);

	if(!validEmail(emailElement))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		return false;
	}
	return true;		
}				

function validEmail(email)
{
	invalidchars = " /:;"

	if(email == "")
	{			//checks to see if blank field
		return false;
	}
			
	for(i=0;i<invalidchars.length;i++)
	{ //checks for invalid chars
			
		badchars = invalidchars.charAt(i);
			
		if(email.indexOf(badchars,0)!= -1)
		{
			return false;
		}
	}
	
	atPos = email.indexOf("@",1)  //holds position of "@"
			
	if(atPos == -1) 
	{	//checks to see if "@" present
		return false;
	}
							
	if(email.indexOf("@",atPos+1) != -1) 
	{ //checks for second "@"
		return false;
	}
							
	periodPos = email.indexOf(".",atPos) //holds position of "."
			
	if(periodPos == -1)
	{ //checks for presence of "."
		return false;
	}
	if(periodPos+3 > email.length)
	{//makes sure at least two chars after the period
		return false;
	}
	return true;
}
function AnswerCheck(form)
{ 
var MyFocus;
 // at least one newsletter should be checked
if ((form.FIRE_NEWSLETTER.checked==false) && 					(form.FIRE_FOCUS.checked==false))
	{
 		alert('Please indicate which newsletter/s you wish to receive.');
		form.FIRE_NEWSLETTER.focus();
		return false;
	}
	      
		if(form.FNAME.value == "")
		{
			alert("Please specify your First name.");
        		form.FNAME.focus();
			return false;
		}
		if(form.LNAME.value == "")
		{
			alert("Please specify your Last name.");
        		form.LNAME.focus();
			return false;
		}
	if (document.forms[0].STATE[document.forms[0].STATE.selectedIndex].value == "")
	{
		alert("Please specify your State/Province or select 'I am not in the U.S. or Canada'.");
		       document.forms[0].STATE.focus();
		return false;
	}

	// validate Canadian state/postal code combination
	if (!ValidCanPostal(document.forms[0].STATE[document.forms[0].STATE.selectedIndex].value,document.forms[0].ZIPCODE.value))
	{
		alert ("Invalid Canadian province/postal code combination.");
        	document.forms[0].STATE.focus();
		return false;
	}
		
	if (document.forms[0].STATE[document.forms[0].STATE.selectedIndex].value == "53")
	{
		if (ObjectExists(document.forms[0], "COUNTRY"))
		{
			if (document.forms[0].COUNTRY[document.forms[0].COUNTRY.selectedIndex].value == "")
			{
				alert("Please specify your Country.");
	        		document.forms[0].COUNTRY.focus();
				return false;
			}
		}
	}
	else
	{
		if (document.forms[0].ZIPCODE.value.length < 5)
		{
			alert("Please specify your Zip/Postal Code.");
	        	document.forms[0].ZIPCODE.focus();
			return false;
		}
	}	
	
		
        if(form.EMAIL_ADDRESS.value == "")
		{
			alert("Please specify your E-mail Address.");
        		form.EMAIL_ADDRESS.focus();
			return false;
       		 }
	if(!validEmail(form.EMAIL_ADDRESS.value))
		{
			alert("You have entered an invalid email address. Please re-enter it.");
			form.EMAIL_ADDRESS.focus();
			return false;
		}
         if (form.EMAIL_ADDRESS2.value == "")
	     {
		      alert("Please confirm your email address.");
		      form.EMAIL_ADDRESS2.focus();
		      return false;
	     }
	     if(form.EMAIL_ADDRESS.value != form.EMAIL_ADDRESS2.value)
	     {
		      alert("Confirmation email address does not match email address.");
	          form.EMAIL_ADDRESS.focus();
		      return false;
         }
		return true;
	
	return true;
}

function CheckboxChecked(thisform,CheckBoxName)
{
var ChLength = CheckBoxName.length + 1;
var vName = CheckBoxName + "-";

var CBindex = 0;
	for ( i=0; i < thisform.elements.length; i++)
	{
		if (thisform.elements[i].type == "checkbox")
		{
			if (thisform.elements[i].name.substring(0,ChLength)==vName)
			{
				if (CBindex==0) {CBindex = i;}
				if (thisform.elements[i].checked)
				{
					return true;
					break;
				}
			}
		}

	}
	thisform.elements[CBindex].focus();
	return false;
}

function ObjectExists(form,fieldname)
{
	for ( i=0; i < form.elements.length; i++)
	{
		if (form.elements[i].name == fieldname)
		{
			return true;
		}
	}
	return false;
}
function FormCheck(mode, description)
{  
	if(document.forms[0].RECEIVE_YES_NO[0].checked == false && document.forms[0].RECEIVE_YES_NO[1].checked == false)
	{
	alert("Please specify whether you wish to receive " + description +"?");
        document.forms[0].RECEIVE_YES_NO[0].focus();
		return false;
	}
      if(document.forms[0].RECEIVE_YES_NO[1].checked == true)
	// stop validation when "not to receive" response
	{
		return true;
	}
       if(!checkUnselects(document.forms[0].REQUESTED_VERSION))	
	{
		alert("Please select subscription format.");
        	document.forms[0].REQUESTED_VERSION[0].focus();
		return false;
	}
       {
	if((document.forms[0].EMAIL_ADDRESS.value == "")&&(document.forms[0].REQUESTED_VERSION[1].checked == true))
	{
		alert("Please specify your E-mail Address.");
       	document.forms[0].EMAIL_ADDRESS.focus();
		return false;
    }
	if (document.forms[0].EMAIL_ADDRESS.value!='')	
	{
		if (!validEmail(document.forms[0].EMAIL_ADDRESS.value))
		{
			alert("You have entered an invalid email address. Please re-enter it.");
			document.forms[0].EMAIL_ADDRESS.focus();
			return false;
		}
 	    if (document.forms[0].EMAIL_ADDRESS2.value == "")
	    {
		    alert("Please confirm your email address.");
		    document.forms[0].EMAIL_ADDRESS2.focus();
		    return false;
	    }
        if(document.forms[0].EMAIL_ADDRESS.value != document.forms[0].EMAIL_ADDRESS2.value)
        {
	       alert("Confirmation email address does not match email address.");
	       document.forms[0].EMAIL_ADDRESS.focus();
	       return false;
        }       
	}
	
	}
	
       if (!checkDropdown(document.forms[0].PERSONAL_ID))
	{
 		alert('Please provide your Personal Identifier (the month you were born).');
		document.forms[0].PERSONAL_ID.focus();
		return false;
	}		
		
 }
function CheckedRadioValue(radioItem)
{
	for(i=0;i<radioItem.length;i++)
	{
		if(radioItem[i].checked)
		{
			return radioItem[i].value;
		}//end if
	}//end for
	return false;
}  
function SpecialformCheck()
{ 
	  if (document.forms[0].EMAIL_ADDRESS.value == "")
		{
			alert("Please enter email address.");
		        document.forms[0].EMAIL_ADDRESS.focus();
			return false;
			
		}
		
		if (document.forms[0].EMAIL_ADDRESS.value != "") 
        {
            if(!validEmail(document.forms[0].EMAIL_ADDRESS.value))
		    {
			     alert("You have entered an invalid email address. Please re-enter it.");
			     document.forms[0].EMAIL_ADDRESS.focus();
			     return false;
		     }
 	         //if (document.forms[0].EMAIL_ADDRESS2.value == "")
	         //{
		 //         alert("Please confirm your email address.");
		 ////         document.forms[0].EMAIL_ADDRESS2.focus();
		 //         return false;
	         //}
             //if(document.forms[0].EMAIL_ADDRESS.value != document.forms[0].EMAIL_ADDRESS2.value)
             //{
	     //          alert("Confirmation email address does not match email address.");
	     ////          document.forms[0].EMAIL_ADDRESS.focus();
	     //          return false;
             //}   
        }    
        if(document.forms[0].WEB_ACCESS_PASSWORD.value == "")
	   	{
 			alert("Please provide a password.");
			document.forms[0].WEB_ACCESS_PASSWORD.focus();
			return false;
		}
}

function PaidformCheck2(mode, description)
{ 

	{
		if(!checkUnselects(document.paidform.CARD_TYPE))
		{
			alert("Please specify credit card.");
        		document.paidform.CARD_TYPE[0].focus();
			return false;
		}

		if(document.paidform.CARD_NUMBER.value == "")
		{
			alert("Please specify credit card number.");
        		document.paidform.CARD_NUMBER.focus();
			return false;
		}

		// MasterCard
		if(document.paidform.CARD_TYPE[0].checked)
		{
			if (!isMasterCard(stripWhitespace(document.paidform.CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
       				document.paidform.CARD_NUMBER.focus();
				return false;
			}
		}

		// Visa
		if(document.paidform.CARD_TYPE[1].checked)
		{
			if (!isVisa(stripWhitespace(document.paidform.CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
       				document.paidform.CARD_NUMBER.focus();
				return false;
			}
		}

		// AmEx
		if(document.paidform.CARD_TYPE[2].checked)
		{
			if (!isAmericanExpress(stripWhitespace(document.paidform.CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
       				document.paidform.CARD_NUMBER.focus();
				return false;
			}
		}

		// Discover
		if(document.paidform.CARD_TYPE[3].checked)
		{
			if (!isDiscover(stripWhitespace(document.paidform.CARD_NUMBER.selectedIndex==4)))
			{
				alert("Invalid credid card number. Please re-enter.")
       				document.paidform.CARD_NUMBER.focus();
				return false;
			}
		}
	
	if(!checkDropdown(document.paidform.ExpMon))
	{
 		alert('Please select the expiration month.');
		document.paidform.ExpMon.focus();
 		return false;
	}

	if(!checkDropdown(document.paidform.ExpYear))
	{
 		alert('Please select the expiration year.');
		document.paidform.ExpYear.focus();
 		return false;
	}
var d, month, year;
   	d = new Date();
    
	month = d.getMonth() + 1;
	year = d.getFullYear() - 2000;
	if (document.forms[0].ExpYear[document.forms[0].ExpYear.selectedIndex].value < year)
	{
 		alert('Invalid Expiration date.');
		document.forms[0].ExpYear.focus();
 		return false;
	}
	else
	{
		if (document.forms[0].ExpYear[document.forms[0].ExpYear.selectedIndex].value == year)
		{
			if (document.forms[0].ExpMon[document.forms[0].ExpMon.selectedIndex].value < month)
			{
 				alert('Invalid Expiration date.');
				document.forms[0].ExpMon.focus();
 				return false;
			}
		}
	}
	if(document.paidform.SCODE.value == "")
	{
		alert('Please enter security code.');
		document.paidform.SCODE.focus();
		return false;
	}
	}

	
	if (mode != "RENEW")
	{
		if(document.paidform.ADDRESS2.value == "")
		{
			alert("Please specify your Street Address.");
	        	document.paidform.ADDRESS2.focus();
			return false;
		}
		if(document.paidform.CITY.value == "")
		{
			alert("Please specify your City.");
	        	document.paidform.CITY.focus();
			return false;
		}
		if (document.paidform.STATE[document.paidform.STATE.selectedIndex].value == "")
		{
			alert("Please specify your State/Province or select 'I am not in the U.S. or Canada'.");
		        document.paidform.STATE.focus();
			return false;
		}

		// validate Canadian state/postal code combination
		if (!ValidCanPostal(document.paidform.STATE[document.paidform.STATE.selectedIndex].value,document.paidform.ZIPCODE.value))
		{
			alert ("Invalid Canadian province/postal code combination.");
        		document.paidform.STATE.focus();
			return false;
		}

		

		if (document.paidform.STATE[document.paidform.STATE.selectedIndex].value == "53")
		{
			if(document.paidform.COUNTRY.value == "")
			{
				alert("Please specify your Country.");
	        		document.paidform.COUNTRY.focus();
				return false;
			}
		}
		else
		{
			if (document.paidform.ZIPCODE.value.length < 5)
			{
				alert("Please specify your Zip/Postal Code.");
	        		document.paidform.ZIPCODE.focus();
				return false;
			}
		}
	}
        
      if (document.paidform.EMAIL_ADDRESS.value != "") 
      {
        if (!validEmail(document.paidform.EMAIL_ADDRESS.value))
	    {
		  alert("You have entered an invalid email address. Please re-enter it.");
		  document.paidform.EMAIL_ADDRESS.focus();
		  return false;
	    }
    	if (document.paidform.EMAIL_ADDRESS2.value == "")
	    {
		    alert("Please confirm your email address.");
		    document.paidform.EMAIL_ADDRESS2.focus();
		    return false;
	    }
        if(document.paidform.EMAIL_ADDRESS.value != document.paidform.EMAIL_ADDRESS2.value)
        {
	       alert("Confirmation email address does not match email address.");
	       document.paidform.EMAIL_ADDRESS.focus();
	       return false;
        } 
      }      
if (!CheckHomeAddress())
		{
			return false;
		}
	
 } 
 function PaidOnlineFormCheck()
 {

	if(!checkUnselects(document.forms[0].CARD_TYPE))
	{
		alert("Please specify credit card.");
        	document.forms[0].CARD_TYPE[0].focus();
		return false;
	}

	if(document.forms[0].CARD_NUMBER.value == "")
	{
		alert("Please specify credit card number.");
        	document.forms[0].CARD_NUMBER.focus();
		return false;
	}

	// MasterCard
	if(document.forms[0].CARD_TYPE[0].checked)
	{
		if (!isMasterCard(stripWhitespace(document.forms[0].CARD_NUMBER.value)))
		{
			alert("Invalid credit card number. Please re-enter.")
        		document.forms[0].CARD_NUMBER.focus();
			return false;
		}
	}
	
	// Visa
	if(document.forms[0].CARD_TYPE[1].checked)
	{
		if (!isVisa(stripWhitespace(document.forms[0].CARD_NUMBER.value)))
		{
			alert("Invalid credit card number. Please re-enter.")
        		document.forms[0].CARD_NUMBER.focus();
			return false;
		}
	}

	// AmEx
	if(document.forms[0].CARD_TYPE[2].checked)
	{
		if (!isAmericanExpress(stripWhitespace(document.forms[0].CARD_NUMBER.value)))
		{
			alert("Invalid credit card number. Please re-enter.")
        		document.forms[0].CARD_NUMBER.focus();
			return false;
		}
	}
	
	// Discover
	if(document.forms[0].CARD_TYPE[3].checked)
	{
		if (!isDiscover(stripWhitespace(document.forms[0].CARD_NUMBER.value)))
		{
			alert("Invalid credit card number. Please re-enter.")
        		document.forms[0].CARD_NUMBER.focus();
			return false;
		}
	}

	if(!checkDropdown(document.forms[0].ExpMon))
	{
 		alert('Please select the expiration month.');
		document.forms[0].ExpMon.focus();
 		return false;
	}

	if(!checkDropdown(document.forms[0].ExpYear))
	{
 		alert('Please select the expiration year.');
		document.forms[0].ExpYear.focus();
 		return false;
	}
	if(document.forms[0].SCODE.value == "")
		{
			alert("Please specify Security Code.");
        		document.forms[0].SCODE.focus();
			return false;
		}
      
        if (document.forms[0].EMAIL_ADDRESS.value == "")
		{
			alert("Please enter email address.");
		    document.forms[0].EMAIL_ADDRESS.focus();
			return false;
			
		}
		
		if (document.forms[0].EMAIL_ADDRESS.value != "")  
        {
            if (!validEmail(document.forms[0].EMAIL_ADDRESS.value))
		    {
			     alert("You have entered an invalid email address. Please re-enter it.");
			     document.forms[0].EMAIL_ADDRESS.focus();
			     return false;
		    }
 	        if (document.forms[0].EMAIL_ADDRESS2.value == "")
	        {
		          alert("Please confirm your email address.");
		          document.forms[0].EMAIL_ADDRESS2.focus();
		          return false;
	        }
            if(document.forms[0].EMAIL_ADDRESS.value != document.forms[0].EMAIL_ADDRESS2.value)
            {
	           alert("Confirmation email address does not match email address.");
	           document.forms[0].EMAIL_ADDRESS.focus();
	           return false;
            }       
        }                                                                                                                     
        if(document.forms[0].WEB_ACCESS_PASSWORD.value == "")
	   	{
 			alert("Please provide a password for access to Fire Engineering Online.");
			document.forms[0].WEB_ACCESS_PASSWORD.focus();
			return false;
		}

	 if ((document.forms[0].WEB_ACCESS_PASSWORD.value != "")&& (document.forms[0].PASSWORD2.value == ""))
		{
			alert("Please confirm your Password.");
        		document.forms[0].PASSWORD2.focus();
			return false;
		}
		if (document.forms[0].WEB_ACCESS_PASSWORD.value != document.forms[0].PASSWORD2.value)
		{
			alert("Please re-enter your Password.");
        		document.forms[0].WEB_ACCESS_PASSWORD.focus();
			return false;
		}
 
 
 }
 
 
 
function checkEmailValuePA()
{   //runs the validate script and returns error box or nonerror
	
	if ((document.forms[0].email1.value != "") && (!validEmail(document.forms[0].email1.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].email1.focus();
		return false;
	}
	if ((document.forms[0].email2.value != "") && (!validEmail(document.forms[0].email2.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].email2.focus();		
		return false;
	}
	if ((document.forms[0].email3.value != "") && (!validEmail(document.forms[0].email3.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].email3.focus();		
		return false;
	}
	if ((document.forms[0].email4.value != "") && (!validEmail(document.forms[0].email4.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].email4.focus();		
		return false;
	}
	if ((document.forms[0].email5.value != "") && (!validEmail(document.forms[0].email5.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].email5.focus();		
		return false;
	}
	
	
	
	return true;		
}
function formCheckAlt(description)
{ 
			
		if(document.qualform.ADDRESS2.value == "")
		{
			alert("Please specify your Street Address.");
	        	document.qualform.ADDRESS2.focus();
			return false;
		}
		if(document.qualform.CITY.value == "")
		{
			alert("Please specify your City.");
	        	document.qualform.CITY.focus();
			return false;
		}
		if (document.qualform.STATE.selectedIndex == 0)
		{
			alert("Please specify your State/Province.");
		        document.qualform.STATE.focus();
			return false;
		}

		// validate Canadian state/postal code combination
		if (!ValidCanPostal(document.qualform.STATE[document.qualform.STATE.selectedIndex].value,document.qualform.ZIPCODE.value))
		{
			alert ("Invalid Canadian province/postal code combination.");
        		document.qualform.STATE.focus();
			return false;
		}

		if (document.qualform.STATE[document.qualform.STATE.selectedIndex].value == "53")
		{
			if (document.qualform.COUNTRY.value == "")
			{
				alert("Please specify your Country.");
	        		document.qualform.COUNTRY.focus();
				return false;
			}
		}
		else
		{
			if (document.qualform.ZIPCODE.value.length < 5)
			{
				alert("Please specify your Zip/Postal Code.");
	        		document.qualform.ZIPCODE.focus();
				return false;
			}
		}


		if ((document.qualform.HOME_ADDRESS1.value != "")
			|| (document.qualform.HOME_ADDRESS2.value != "")
			|| (document.qualform.HOME_CITY.value != "")
			|| (document.qualform.HOME_ZIPCODE.value != "")
			|| (document.qualform.HOME_STATE.selectedIndex > 0))
		{
			if(document.qualform.HOME_ADDRESS2.value == "")
			{
				alert("Please specify your optional delivery Street Address.");
	        		document.qualform.HOME_ADDRESS2.focus();
				return false;
			}
			if(document.qualform.HOME_CITY.value == "")
			{
				alert("Please specify your optional delivery City.");
	        		document.qualform.HOME_CITY.focus();
				return false;
			}
			if (document.qualform.HOME_STATE.selectedIndex == 0)
			{
				alert("Please specify your optional delivery State/Province.");
		        	document.qualform.HOME_STATE.focus();
				return false;
			}

			// validate Canadian state/postal code combination
			if (!ValidCanPostal(document.qualform.HOME_STATE[document.qualform.HOME_STATE.selectedIndex].value,document.qualform.HOME_ZIPCODE.value))
			{
				alert ("Invalid optional delivery Canadian province/postal code combination.");
        			document.qualform.HOME_STATE.focus();
				return false;
			}

			if (document.qualform.HOME_STATE[document.qualform.HOME_STATE.selectedIndex].value == "53")
			{
				if (document.qualform.HOME_COUNTRY.value == "")
				{
					alert("Please specify your optional delivery Country.");
	        			document.qualform.HOME_COUNTRY.focus();
					return false;
				}
			}
			else
			{
				if (document.qualform.HOME_ZIPCODE.value.length < 5)
				{
					alert("Please specify your optional delivery Zip/Postal Code.");
	        			document.qualform.HOME_ZIPCODE.focus();
					return false;
				}
			}
		}

	
	if (document.qualform.EMAIL_ADDRESS.value != "")
    {
        if(!validEmail(document.qualform.EMAIL_ADDRESS.value))
		{
			alert("You have entered an invalid email address. Please re-enter it.");
			document.qualform.EMAIL_ADDRESS.focus();
			return false;
		}
        if (document.forms[0].EMAIL_ADDRESS2.value == "")
	    {
		    alert("Please confirm your email address.");
		    document.forms[0].EMAIL_ADDRESS2.focus();
		    return false;
	    }
        if(document.forms[0].EMAIL_ADDRESS.value != document.forms[0].EMAIL_ADDRESS2.value)
        {
	       alert("Confirmation email address does not match email address.");
	       document.forms[0].EMAIL_ADDRESS.focus();
	       return false;
        }    
    }   
 } 
 function PaidformCheckGift(mode)
{ 
	
	if (!checkUnselects(document.paidform.PRODUCT))
	 {
		alert ("Please select your subscription.");
        	document.paidform.PRODUCT[0].focus();
		return false;
	}
	if (mode == "ADD") 
  	{
		if(document.paidform.FNAME.value == "")
		{
			alert("Please specify your First name.");
	       		document.paidform.FNAME.focus();
			return false;
		}
		if(document.paidform.LNAME.value == "")
		{
			alert("Please specify your Last name.");
       			document.paidform.LNAME.focus();
			return false;
		}
	}
        if (mode != "RENEW")
  	{
		if(document.paidform.ADDRESS2.value == "")
		{
		alert ("Please specify your Street Address.");
	        document.paidform.ADDRESS2.focus();
		return false;
		}
		if(document.paidform.CITY.value == "")
		{
		alert("Please specify your City.");
	        document.paidform.CITY.focus();
		return false;
		}
		if (document.paidform.STATE.selectedIndex == 0)
	{	
		alert ("Please specify your State/Province or select 'I am not in the U.S. or Canada'.");
		document.paidform.STATE.focus();
		return false;
		}
	// validate Canadian state/postal code combination
	if (!ValidCanPostal(document.paidform.STATE[document.paidform.STATE.selectedIndex].value,document.paidform.ZIPCODE.value))
		{
		alert ("Invalid Canadian province/postal code combination.");
        	document.paidform.STATE.focus();
		return false;
		}
		if (document.paidform.STATE[document.paidform.STATE.selectedIndex].value == "53")
		{
			if (document.paidform.COUNTRY.value == "")
			{
			alert ("Please specify your Country.");
	        	document.paidform.COUNTRY.focus();
			return false;
			}
		}
		else
		{
			if (document.paidform.ZIPCODE.value.length < 5)
			{
			alert("Please specify your Zip/Postal Code.");
	        	document.paidform.ZIPCODE.focus();
			return false;
			}
		}			
	} 
       	
	if ((document.paidform.EMAIL_ADDRESS.value != "") && (!validEmail(document.paidform.EMAIL_ADDRESS.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.paidform.EMAIL_ADDRESS.focus();
		return false;
	}
	if(document.paidform.PD_BILLING_NAME.value == "")
	{
		alert("Please specify the name of cardholder.");
       		document.paidform.PD_BILLING_NAME.focus();
		return false;
	}

	if (document.paidform.PD_BILLING_ADDRESS2.value == "")
	{
		alert("Please specify your Billing Street address.");
          	document.paidform.PD_BILLING_ADDRESS2.focus();
	  	return false;
	}
  	if (document.paidform.PD_BILLING_CITY.value == "")
	{
          	alert("Please specify your Billing City.");
	  	document.paidform.PD_BILLING_CITY.focus();
	  	return false;
	}
	if (document.paidform.PD_BILLING_STATE.selectedIndex == 0)
	{
	  	alert( "Please specify your Billing State/Province or select 'I am not in the US or Canada'.");
          	document.paidform.PD_BILLING_STATE.focus();
	  	return false;
	}

	// validate Canadian state/postal code combination
	if (!ValidCanPostal(document.paidform.PD_BILLING_STATE[document.paidform.PD_BILLING_STATE.selectedIndex].value,document.paidform.PD_BILLING_ZIPCODE.value))
	{
		alert ("Invalid Canadian province/postal code combination in Billing address.");
       		document.paidform.PD_BILLING_STATE.focus();
		return false;
	}

	if (document.forms[0].PD_BILLING_STATE[document.forms[0].PD_BILLING_STATE.selectedIndex].value == "53")
	{
		if (document.forms[0].PD_BILLING_COUNTRY.value == "")
		{
			alert( "Please specify your Billing Country.");
        		document.forms[0].PD_BILLING_COUNTRY.focus();
			return false;
		}
	}
	else
	{
		if (document.forms[0].PD_BILLING_ZIPCODE.value.length < 5)
		{
			alert ("Please specify your Billing Zip/Postal Code.");
        		document.forms[0].PD_BILLING_ZIPCODE.focus();
			return false;
		}
	}
			
	if (document.paidform.PD_BILLING_EMAIL_ADDRESS.value == "")
	{
		alert("Please enter the email address.");
		document.paidform.PD_BILLING_EMAIL_ADDRESS.focus();
		return false;
	}
	
	if ((document.paidform.PD_BILLING_EMAIL_ADDRESS.value != "") && (!validEmail(document.paidform.PD_BILLING_EMAIL_ADDRESS.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.paidform.PD_BILLING_EMAIL_ADDRESS.focus();
		return false;
	}
	
	if (document.paidform.PD_BILLING_PHONE.value == "")
	{
		alert("Please enter the Phone number.");
		document.paidform.PD_BILLING_PHONE.focus();
		return false;
	}

    if(!checkUnselects(document.paidform.CARD_TYPE))
	{
		alert("Please specify credit card.");
        	document.paidform.CARD_TYPE[0].focus();
		return false;
	}

	if(document.paidform.CARD_NUMBER.value == "")
	{
		alert("Please specify credit card number.");
        	document.paidform.CARD_NUMBER.focus();
		return false;
	}

	// MasterCard
	if(document.paidform.CARD_TYPE[0].checked)
		{
			if (!isMasterCard(stripWhitespace(document.paidform.CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
	        		document.paidform.CARD_NUMBER.focus();
				return false;
			}
		}

	// Visa
	if(document.paidform.CARD_TYPE[1].checked)
		{
			if (!isVisa(stripWhitespace(document.paidform.CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
	        		document.paidform.CARD_NUMBER.focus();
				return false;
			}
		}
	
	// AmEx
	if(document.paidform.CARD_TYPE[2].checked)
		{
			if (!isAmericanExpress(stripWhitespace(document.paidform.CARD_NUMBER.value)))
			{
				alert("Invalid credit card number. Please re-enter.")
	        		document.paidform.CARD_NUMBER.focus();
				return false;
			}
		}
	
	

	if(!checkDropdown(document.paidform.ExpMon))
	{
 		alert('Please select the expiration month.');
		document.paidform.ExpMon.focus();
 		return false;
	}

	if(!checkDropdown(document.paidform.ExpYear))
	{
 		alert('Please select the expiration year.');
		document.paidform.ExpYear.focus();
 		return false;
	}
var d, month, year;
   	d = new Date();
    
	month = d.getMonth() + 1;
	year = d.getFullYear() - 2000;
	if (document.paidform.ExpYear[document.paidform.ExpYear.selectedIndex].value < year)
	{
 		alert('Invalid Expiration date.');
		document.paidform.ExpYear.focus();
 		return false;
	}
	else
	{
		if (document.paidform.ExpYear[document.paidform.ExpYear.selectedIndex].value == year)
		{
			if (document.paidform.ExpMon[document.paidform.ExpMon.selectedIndex].value < month)
			{
 				alert('Invalid Expiration date.');
				document.paidform.ExpMon.focus();
 				return false;
			}
		}
	}
	if(document.paidform.SCODE.value == "")
	{
		alert('Please enter security code.');
		document.paidform.SCODE.focus();
		return false;
	}
     }		
