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 ((mode == "SHORT") || (mode == "ABBR"))
	{
		if (document.forms[0].EMAIL_ADDRESS.value == "")
		{
			alert ("Please specify your E-mail 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.toUpperCase() != document.forms[0].EMAIL_ADDRESS2.value.toUpperCase())
		{
			alert("Confirmation email address does not match email address.");
	        	document.forms[0].EMAIL_ADDRESS.focus();
			return false;
        	}        

		if (document.forms[0].PHONE.value == "")
		{
			alert("Please specify your Business Phone.");
	    		document.forms[0].PHONE.focus();
			return false;
		}	
		return true;
	}

	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 (document.forms[0].TITLE.value == "")
		{
			alert ("Please specify your Title.");
	        	document.forms[0].TITLE.focus();
			return false;
		}
		if (document.forms[0].COMPANY.value == "")
		{
			alert("Please specify your Company name.");
        		document.forms[0].COMPANY.focus();
			return false;
		}
		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.selectedIndex == 0)
		{
			alert ("Please specify your State/Province or select 'I am not in the US 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 (document.forms[0].COUNTRY.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;
			}
		}
	}
	
	//change email to be required all the time per email from acct. rep. on 7/3/08
    	if (document.forms[0].EMAIL_ADDRESS.value == "")
	{
		alert ("Please specify your E-mail 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.toUpperCase() != document.forms[0].EMAIL_ADDRESS2.value.toUpperCase())
    	{
       		alert("Confirmation email address does not match email address.");
       		document.forms[0].EMAIL_ADDRESS.focus();
       		return false;
    	}

    	if (mode == "COA")
    	{
	    	if (document.forms[0].PhoneArea.value.length < 3)
	    	{
		    	alert ("Please specify your area code.");
	      		document.forms[0].PhoneArea.focus();
		    	return false;
	    	}
	    	if (document.forms[0].PhoneExch.value.length < 3)
	    	{
		    	alert("Please specify first three digits of your phone number.");
	      		document.forms[0].PhoneExch.focus();
		    	return false;
	    	}
	    	if (document.forms[0].Phone.value.length < 4)
	    	{
		      	alert("Please specify the last four digits of your phone number.");
	      		  document.forms[0].Phone.focus();
		      	return false;
	    	}
    	}	
 }

function formCheckAlt(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 (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 (document.forms[0].TITLE.value == "")
		{
			alert ("Please specify your Title.");
	        	document.forms[0].TITLE.focus();
			return false;
		}
		if (document.forms[0].COMPANY.value == "")
		{
			alert ("Please specify your Company name.");
        		document.forms[0].COMPANY.focus();
			return false;
		}
		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.selectedIndex == 0)
		{
			alert("Please specify your State/Province.");
		        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 (document.forms[0].COUNTRY.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;
			}
		}

		//change email to be required all the time per email from acct. rep. on 7/3/08
		if (document.forms[0].EMAIL_ADDRESS.value == "")
		{
			alert ("Please specify your E-mail 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.toUpperCase() != document.forms[0].EMAIL_ADDRESS2.value.toUpperCase())
  	  	{
  	     		alert("Confirmation email address does not match email address.");
 	      		document.forms[0].EMAIL_ADDRESS.focus();
 	      		return false;
 	   	}

		if (mode == "COA")
		{
	       	    	if (document.forms[0].PHONE.value == "")
			{
				alert("Please specify your Business Phone.");
		    		document.forms[0].PHONE.focus();
				return false;
			}	
		}		  		
		

		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.");
			       	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 delivery 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;
				}
			}
		}
    	}
 }  

// 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 ValidNum(NumObj)
{
	var myNum, cleanNum;
	
	myNum = NumObj.value
	cleanNum = parseInt(myNum);

	if ( myNum == "")
	{
		return true;
	}
       	if(myNum != cleanNum)
	
	{
		alert("You have entered an invalid number for Personal ID question.Please re-enter.");
		NumObj.focus();
		return false;
	}
	return true;
}

function AnswerCheck(form,mode)
{ 
var MyFocus;
// at least one newsletter should be checked
if ((form.WWR_NEWSLETTER.checked==false) && (form.IWW_NEWSLETTER.checked==false) &&(form.WWR_PUMPSYSTEM.checked==false)&&(form.WWR_SECURITY.checked==false)&&(form.WWR_STORM.checked==false)&&(form.WWR_AMR.checked==false)&&(form.WWI_NEWSLETTER.checked==false)&&(form.WATERWORLD_WKLY_VIDEO.checked==false)&&(form.WWR_CE_NEWSLETTER.checked==false))
	{
 		alert('Please indicate which newsletter/s you wish to receive.');
		form.WWR_NEWSLETTER.focus();
		return false;
	}
	
	if (mode == "ADD")
	{
		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 (form.COMPANY.value == "")
	{
		alert ("Please specify your company.");
        	form.COMPANY.focus();
		return false;
	}
	if (form.ADDRESS2.value == "")
	{
		alert ("Please specify your Street Address.");
	        form.ADDRESS2.focus();
		return false;
	}
	if (form.CITY.value == "")
	{
		alert ("Please specify your City.");
	        form.CITY.focus();
		return false;
	}

	if (form.STATE.selectedIndex == 0)
	{
		alert ("Please specify your State/Province.");
		form.STATE.focus();
		return false;
		}
	 // validate Canadian state/postal code combination
	if (!ValidCanPostal(form.STATE[form.STATE.selectedIndex].value,form.ZIPCODE.value))
	{
		alert ("Invalid Canadian province/postal code combination.");
        	form.STATE.focus();
		return false;
	}

	if (form.STATE[form.STATE.selectedIndex].value == "53")
	{
		if (form.COUNTRY.value == "")
		{
			alert ("Please specify your Country.");
	        	form.COUNTRY.focus();
			return false;
		}
	}
	else
	{
		if (form.ZIPCODE.value.length < 5)
		{
			alert ("Please specify your Zip/Postal Code.");
	        	form.ZIPCODE.focus();
			return false;
		}
	}
		
        if (form.EMAIL_ADDRESS.value == "")
	{
		alert ("Please specify your E-mail Address.");
        	form.EMAIL_ADDRESS.focus();
		return false;
       	}

	if ((form.EMAIL_ADDRESS.value != "") && (!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.toUpperCase() != form.EMAIL_ADDRESS2.value.toUpperCase())
    	{
	   	alert("Confirmation email address does not match email address.");
	   	form.EMAIL_ADDRESS.focus();
	   	return false;
	}       
	
        if (form.PHONE.value == "")
	{
		alert ("Please specify your phone number.");
        	form.PHONE.focus();
		return false;
       	}
//question 1

	if (!CheckDropdown(form.WEB_BUSINESS))
		{
		alert ("Please select the nature of your organization.");
		form.WEB_BUSINESS.focus();
		return false;
		}
//question 2

	if (!CheckUnselects(form.WEB_JOB_FUNCTION))
    		{
    			alert("Please specify your job title.");
    			form.WEB_JOB_FUNCTION[0].focus();
    			return false;
    		}
//question 3

	if (!CheckboxChecked(form,'WEB_PRODUCTS'))
		{
			alert ("Please check all products or systems that you recommend to purchase.");
			myFocus=document.getElementById("WEB_PRODUCTS");
			myFocus.scrollIntoView(true);
			return false;
		}
//question 4

	if (!CheckDropdown(form.WEB_LOCATION))
		{
		alert ("Please select the population served by your water system.");
		form.WEB_LOCATION.focus();
		return false;
		}
//question 5
	if (!CheckDropdown(form.WEB_POPULATION_SERVED))
		{
		alert ("Please select the population served by your water system.");
		form.WEB_POPULATION_SERVED.focus();
		return false;
		}
      	return true;
} 
function AnswerCheckPump(form)
{ 
var MyFocus;
	if(form.WWR_PUMPSYSTEM[0].checked == false && form.WWR_PUMPSYSTEM[1].checked == false)
	{
	alert("Please specify whether you wish to receive Pump Systems and Innovations Newsletter?");
        form.WWR_PUMPSYSTEM[0].focus();
		return false;
	}

	if(form.WWR_PUMPSYSTEM[1].checked == true)
	// stop validation when "not to receive" response
	{
		return true;
	}
	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(form.COMPANY.value == "")
	{
		alert("Please specify your Company name.");
        	form.COMPANY.focus();
		return false;
	}
	if(form.ADDRESS2.value == "")
	{
		alert("Please specify your Street Address.");
	       	form.ADDRESS2.focus();
		return false;
	}
	if(form.CITY.value == "")
	{
		alert("Please specify your City.");
	       	form.CITY.focus();
		return false;
	}

	if (form.STATE.selectedIndex == 0)
	{
		alert("Please specify your State/Province.");
		form.STATE.focus();
		return false;
	}
	 // validate Canadian state/postal code combination
	if (!ValidCanPostal(form.STATE[form.STATE.selectedIndex].value,form.ZIPCODE.value))
	{
		alert ("Invalid Canadian province/postal code combination.");
       		form.STATE.focus();
		return false;
	}

	if (form.STATE[form.STATE.selectedIndex].value == "53")
	{
		if (form.COUNTRY.value == "")
		{
			alert("Please specify your Country.");
        		form.COUNTRY.focus();
			return false;
		}
	}
	else
	{
		if (form.ZIPCODE.value.length < 5)
		{
			alert("Please specify your Zip/Postal Code.");
        		form.ZIPCODE.focus();
			return false;
		}
	}
		
        if(form.EMAIL_ADDRESS.value == "")
	{
		alert("Please specify your E-mail Address.");
       		form.EMAIL_ADDRESS.focus();
		return false;
       	 }
	if ((form.EMAIL_ADDRESS.value != "") && (!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.toUpperCase() != form.EMAIL_ADDRESS2.value.toUpperCase())
    	{
	   	alert("Confirmation email address does not match email address.");
	   	form.EMAIL_ADDRESS.focus();
	   	return false;
    	}       		

	if (!CheckUnselects(form.WEB_BUSINESS))
	{
		alert("Please select the nature of your organization.");
		form.WEB_BUSINESS[0].focus();
		return false;
	}


	if (!CheckUnselects(form.WEB_JOB_FUNCTION))
	{
		alert("Please select your JOB TITLE.");
		form.WEB_JOB_FUNCTION[0].focus();
		return false;
	}
	if (!CheckboxChecked(form,'WEB_PURCHASING'))
	{
		alert ("Please check your purchasing responsibility for pumps.");
		myFocus=document.getElementById("WEB_PURCHASING");
		myFocus.scrollIntoView(true);
		return false;
	}
	if (!CheckDropdown(form.WEB_PERSONAL_ID))
	{
		alert("Please select the first letter of the State/Territory in which you were born.")
		form.WEB_PERSONAL_ID.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;
}

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 CheckedRadioValue(radioItem)
{
	for(i=0;i<radioItem.length;i++)
	{
		if(radioItem[i].checked)
		{
			return radioItem[i].value;
		}//end if
	}//end for
	return false;
}
function PaidformCheck(mode)
{ 
	if(!CheckUnselects(document.paidform.SUBSCRIPTION))	
	{
		alert("Please select your subscription.");
        	document.paidform.SUBSCRIPTION[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 (!CheckBusAddress())
		{
			return false;
		}			
	} 
	if (((CheckedRadioValue(document.paidform.SUBSCRIPTION) == '11') ||
		(CheckedRadioValue(document.paidform.SUBSCRIPTION) == '12')|| 
		(CheckedRadioValue(document.paidform.SUBSCRIPTION) == '13'))&& (document.paidform.EMAIL_ADDRESS.value == ""))
	{
		alert("Email is required for digital version.");
       		document.paidform.EMAIL_ADDRESS.focus();
		return false;
	}	
	if ((document.forms[0].WWR_NEWSLETTER[0].checked)||
        	(document.forms[0].WWR_PUMPSYSTEM[0].checked)||
		(document.forms[0].WWR_SECURITY[0].checked)||
        	(document.forms[0].WWR_STORM[0].checked)||
        	(document.forms[0].WWR_AMR[0].checked)||
        	(document.forms[0].WWI_NEWSLETTER[0].checked))
    	{
        	if (document.forms[0].EMAIL_ADDRESS.value == "")
        	{
            		alert("Email Address is required to receive newsletters.");
            		document.forms[0].EMAIL_ADDRESS.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 (paidform.EMAIL_ADDRESS2.value == "")
	    	{
	       		alert("Please confirm your email address.");
	       		paidform.EMAIL_ADDRESS2.focus();
	       		return false;
	    	}
        	if(paidform.EMAIL_ADDRESS.value.toUpperCase() != paidform.EMAIL_ADDRESS2.value.toUpperCase())
        	{
	      		alert("Confirmation email address does not match email address.");
	       		paidform.EMAIL_ADDRESS.focus();
	       		return false;
        	}   
    	}    
	if (!CheckBillAddress())
	{
		return false;
	}
	if (!CheckPaymentInfo())
	{
		return false;
	}
	
	return true;
}
function CheckBusAddress()
{
	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;
		}
	}
	return true;
}
			
function CheckBillAddress()
{
	if (!ObjectExists(document.paidform, "SAME_ADDRESS"))
	{
		return true;
	}
	if (!document.paidform.SAME_ADDRESS.checked)
	{
		return true;
	}
	if(document.paidform.PD_BILLING_NAME.value == "")
	{
		alert("Please specify Name on card.");
	        document.paidform.PD_BILLING_NAME.focus();
		return false;
	}
	if(document.paidform.PD_BILLING_ADDRESS2.value == "")
	{
		alert("Please specify Billing Street Address.");
	        document.paidform.PD_BILLING_ADDRESS2.focus();
		return false;
	}
	if(document.paidform.PD_BILLING_CITY.value == "")
	{
		alert("Please specify Billing City.");
	        document.paidform.PD_BILLING_CITY.focus();
		return false;
	}
	if (document.paidform.PD_BILLING_STATE.selectedIndex == 0)
	{
		alert ("Please specify Billing State/Province or select 'Not in the U.S. 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.paidform.PD_BILLING_STATE[document.paidform.PD_BILLING_STATE.selectedIndex].value == "53")
	{
		if (document.paidform.PD_BILLING_COUNTRY.value == "")
		{
			alert("Please specify Billing Country.");
	        	document.paidform.PD_BILLING_COUNTRY.focus();
			return false;
		}
	}
	else
	{
		if (document.paidform.PD_BILLING_ZIPCODE.value.length < 5)
		{
			alert("Please specify Billing Zip/Postal Code.");
	        	document.paidform.PD_BILLING_ZIPCODE.focus();
			return false;
		}
	}
	return true;
}

function CheckPaymentInfo()
{
	if(!CheckDropdown(document.paidform.CARD_TYPE))
	{
		alert("Please specify credit card.");
        	document.paidform.CARD_TYPE.focus();
		return false;
	}

	if(document.paidform.CARD_NUMBER.value == "")
	{
		alert("Please specify credit card number.");
        	document.paidform.CARD_NUMBER.focus();
		return false;
	}

	// Visa
	if(document.paidform.CARD_TYPE.selectedIndex == 1)
	{
		if (!isVisa(stripWhitespace(document.paidform.CARD_NUMBER.value)))
		{
			alert("Invalid credit card number. Please re-enter.")
        		document.paidform.CARD_NUMBER.focus();
			return false;
		}
	}

	// MasterCard
	if(document.paidform.CARD_TYPE.selectedIndex == 2)
	{
		if (!isMasterCard(stripWhitespace(document.paidform.CARD_NUMBER.value)))
		{
			alert("Invalid credid card number. Please re-enter.")
        		document.paidform.CARD_NUMBER.focus();
			return false;
		}
	}
	
	// AmEx
	if(document.paidform.CARD_TYPE.selectedIndex == 3)
	{
		if (!isAmericanExpress(stripWhitespace(document.paidform.CARD_NUMBER.value)))
		{
			alert("Invalid credid card number. Please re-enter.")
        		document.paidform.CARD_NUMBER.focus();
			return false;
		}
	}
	
	// Discover
	if(document.paidform.CARD_TYPE.selectedIndex == 4)
	{
		if (!isDiscover(stripWhitespace(document.paidform.CARD_NUMBER.value)))
		{
			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;
	}
	// zh
	return true;
}
//Sample issues for digital edition		

function PopupSampleIssue()
{
	window.open("http://www.qmags.com/ww/latest","","height=400, 		width=750,toolbar=no,scrollbars=yes,resizable=yes");
}	

function ObjectExists(form,fieldname)
{
	for ( i=0; i < form.elements.length; i++)
	{
		if (form.elements[i].name == fieldname)
		{
			return true;
		}
	}
	return false;
}
function checkEmailValuePA()
{   //runs the validate script and returns error box or nonerror
	
	if ((document.forms[0].send_to_1.value != "") && (!validEmail(document.forms[0].send_to_1.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].send_to_1.focus();
		return false;
	}
	if ((document.forms[0].send_to_2.value != "") && (!validEmail(document.forms[0].send_to_2.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].send_to_2.focus();		
		return false;
	}
	if ((document.forms[0].send_to_3.value != "") && (!validEmail(document.forms[0].send_to_3.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].send_to_3.focus();		
		return false;
	}
	if ((document.forms[0].send_to_4.value != "") && (!validEmail(document.forms[0].send_to_4.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[0].send_to_4.focus();		
		return false;
	}
	

	return true;		
}
// declare global variables
var i;
var PRODUCTS;


// on load calculate indices for all group of checkboxes with 'None of the Above' option
function InitIndex(formindex)
{
	if (document.getElementsByName("PRODUCTS-67").length != 0)
	{
		for ( i=0; i < document.forms[formindex].elements.length; i++)
		{
			GetIndex(formindex, "PRODUCTS");
			PRODUCTS = i;
			i++;
			break;
		}
	}			
}
function GetIndex(formindex, GroupName)
{
	var namelen = GroupName.length;

	while (document.forms[formindex].elements[i].name.substring(0,namelen) != GroupName)
	{
		i++;
	}
}

// This function is running with assumption that 'None of the Above' option is the very last
// in the group of checkboxes.
// Start index must be calculation on when document is being loaded using InitIndex() function

function checker(formindex,start,groupname,none)
			// formindex - index of the form within current document, starts with 0
			// start - start index for group of checkboxes
			// generic name of group of checkboxes (Example: "QUES_77")
			// 'None of the above' option (Example: "99" if "QUES_77-99" is 
			//			a name of 'None of the above' checkbox
{
	var namelen = groupname.length;
	var OptionChecked = false;
	var LoopCount = parseInt(none);
	var NoneName = groupname + "-" + none;
	

	for ( var j=start; j < document.forms[formindex].elements.length; j++)
	{
		if (document.forms[formindex].elements[j].name.substring(0,namelen) == groupname)
		{	// group of check boxes located: continue loop inside the group
			while (LoopCount>=0)
			{ 
				if (document.forms[formindex].elements[j].name == NoneName)
 				{
 					if (OptionChecked)
 					{
 						document.forms[formindex].elements[j].checked = false;
 					}
 					LoopCount=0;	//break the loop when reach None option
 				}
 				else
 				{
					if (!OptionChecked)
					{
 						if (document.forms[formindex].elements[j].checked==true)
 						{
 							OptionChecked = true;
 						}
					}
				}
				j++;
				LoopCount--;
			}
			break;
		}
	}
}
