function checkEmail(emailValue)
{	//runs the validate script and returns error box or nonerror
	//allows blank email address

	if (emailValue == "")
	{
		return true;
	}

	if(!validEmail(emailValue))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		return false;
	}
	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 = " /:;"

// remove leading spaces
	while(email.substring(0,1)==" ")
	{
		email = email.substring(1,email.length);
	}

// remove trailing spaces
	while(email.substring(email.length-1,email.length)==" ")
	{

		email = email.substring(0,email.length-1);
	}

	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 PaidformCheck(mode)
{ 
 var username = document.paidform.DIGITAL_ACC_USER_ID.value.length
 var username1 = document.paidform.DIGITAL_ACC_USER_ID.value 
 var pass = document.paidform.DIGITAL_ACC_PASSWORD.value.length
 var pass1 = document.paidform.DIGITAL_ACC_PASSWORD.value 

	if(!CheckUnselects(document.paidform.PRODUCT))	
	{
		alert("Please select your subscription.");
        	document.paidform.PRODUCT[0].focus();
		return false;
	}
	if (!CheckPaymentInfo())
	{
		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 (!CheckUnselects(document.paidform.PRIMARY_ACTIVITY))
    		{
    			alert("Please specify the primary activity of your organization.");
            		document.paidform.PRIMARY_ACTIVITY[0].focus();
    			return false;
    		}
        if (CheckedRadioValue(document.paidform.PRIMARY_ACTIVITY)=="98")
			{
				if(document.paidform.PRIMARY_ACTIVITY_DESC1.value == "")
				{
					alert("Please specify the description of your business.");
	        			document.paidform.PRIMARY_ACTIVITY_DESC1.focus();
					return false;
				}
			}
                if (CheckedRadioValue(document.paidform.PRIMARY_ACTIVITY)=="97")
			{
				if(document.paidform.PRIMARY_ACTIVITY_DESC.value == "")
				{
					alert("Please specify the description of your type of photography.");
	        			document.paidform.PRIMARY_ACTIVITY_DESC.focus();
					return false;
				}
			}
                if (!CheckUnselects(document.paidform.JOB_TITLE))
    		{
    			alert("Please specify your job title.");
            		document.paidform.JOB_TITLE[0].focus();
    			return false;
    		}
                if (CheckedRadioValue(document.paidform.JOB_TITLE)=="98")
			{
				if(document.paidform.JOB_TITLE_DESC.value == "")
				{
					alert("Please specify the description of your job title.");
	        			document.paidform.JOB_TITLE_DESC.focus();
					return false;
				}
			} 
 if ((CheckedRadioValue(document.paidform.PRODUCT) == "11")
||(CheckedRadioValue(document.paidform.PRODUCT) == "12")
||(CheckedRadioValue(document.paidform.PRODUCT) == "13")
||(CheckedRadioValue(document.paidform.PRODUCT) == "21")
||(CheckedRadioValue(document.paidform.PRODUCT) == "22")
||(CheckedRadioValue(document.paidform.PRODUCT) == "23"))
                {
                   if(document.paidform.DIGITAL_ACC_USER_ID.value == "")
	   	{
 			alert("Please provide a user name.");
			document.paidform.DIGITAL_ACC_USER_ID.focus();
			return false;
		}
                                   
		if (((username < 4)||(username > 30))||((!isValidChar(username1))))
        		{
        			alert("Your Digital Username must be between 4 - 30 alpha-numeric characters. (The special characters _ @ . are also allowed.)");
        	        	document.paidform.DIGITAL_ACC_USER_ID.focus();
        			return false;
        		}	
         
            if(document.paidform.DIGITAL_ACC_PASSWORD.value == "")
	   	{
 			alert("Please provide a password.");
			document.paidform.DIGITAL_ACC_PASSWORD.focus();
			return false;
		}
                if (((pass < 4)||(pass > 12))||((!isValidCharPass(pass1))))
        		{
        			alert("Your Digital Password must be between 4 - 12 alpha-numeric characters. (The special characters # _ @ * are also allowed.)");
        	        	document.paidform.DIGITAL_ACC_PASSWORD.focus();
        			return false;
        		}	 
               if ((document.paidform.DIGITAL_ACC_PASSWORD.value != "")&& (document.paidform.PASSWORD2.value == ""))
		{
			alert("Please confirm your password.");
        		document.paidform.PASSWORD2.focus();
			return false;
		}
		if (document.paidform.DIGITAL_ACC_PASSWORD.value != document.paidform.PASSWORD2.value)
		{
			alert("Please re-enter your password.");
        		document.paidform.DIGITAL_ACC_PASSWORD.focus();
			return false;
		} 
         }
}

 

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 IsCanadian(StateCD)
{
	for(i=0;i<13;i++)
	{
		if (StateCD==CanCodes[i])
		{
			return true;
		}
	}
	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 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.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;
	}
	
	return true;
}
function ValidNum(NumObj)
{
	var myNum, cleanNum;
	
	myNum = NumObj.value
	cleanNum = parseInt(myNum);

	if ( myNum == "")
	{
		return true;
	}
       	if(myNum != cleanNum)
	
	{
		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[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[document.paidform.COUNTRY.selectedIndex].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.STATE[document.paidform.STATE.selectedIndex].value == "53")
        {

	 if ((CheckedRadioValue(document.paidform.PRODUCT) == "01")
||(CheckedRadioValue(document.paidform.PRODUCT) == "02") 
||(CheckedRadioValue(document.paidform.PRODUCT) == "03")
||(CheckedRadioValue(document.paidform.PRODUCT) == "21")
||(CheckedRadioValue(document.paidform.PRODUCT) == "22")
||(CheckedRadioValue(document.paidform.PRODUCT) == "23"))
                {
             
	      alert("International subscribers may receive digital version only.");
                      return false;
                }
		
			
        }
        
	if (document.paidform.EMAIL_ADDRESS.value == "")
	{
		alert("Please specify your E-mail Address.");
        	document.paidform.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 (document.paidform.EMAIL_ADDRESS2.value == "")
	       {
		      alert("Please confirm your email address.");
		      document.paidform.EMAIL_ADDRESS2.focus();
		      return false;
                }
        
            if(document.paidform.EMAIL_ADDRESS.value.toUpperCase() != document.paidform.EMAIL_ADDRESS2.value.toUpperCase())
	       {
	           alert("Confirmation email address does not match email address.");
	           document.paidform.EMAIL_ADDRESS.focus();
	           return false;
	       }
	}
        
     if (document.paidform.PHONE.value == "")
		{
			alert("Please specify your Business Phone.");
	    		document.paidform.PHONE.focus();
			return false;
		}
	
	return true;
}
function showhideJT(JOB_TITLE)
{
var jt= CheckedRadioValue(document.paidform.JOB_TITLE);
if (jt == "98")
   {
    document.getElementById('job_title_other').style.display = "block";
    }
else
  {
    document.getElementById('job_title_other').style.display = "none";
    }
  	
}

function FreeShowHideJT(JOB_TITLE)
{
var jt_free= CheckedRadioValue(document.forms[0].JOB_TITLE);
if (jt_free == "98")
   {
    document.getElementById('job_title_other').style.display = "block";
    }
else
  {
    document.getElementById('job_title_other').style.display = "none";
    }
  	
}



function showhideACT(PRIMARY_ACTIVITY)
{
var act= CheckedRadioValue(document.paidform.PRIMARY_ACTIVITY);

if (act == "97")
   {
    document.getElementById('type_other').style.display = "block";
    }
else
  {
    document.getElementById('type_other').style.display = "none";
    }
if (act == "98")
   {
    document.getElementById('activity_other').style.display = "block";
    }
else
  {
    document.getElementById('activity_other').style.display = "none";
    }
}
function FreeShowHideACT(PRIMARY_ACTIVITY)
{
var act_free= CheckedRadioValue(document.forms[0].PRIMARY_ACTIVITY);

if (act_free == "97")
   {
    document.getElementById('type_other').style.display = "block";
    }
else
  {
    document.getElementById('type_other').style.display = "none";
    }

if (act_free == "98")
   {
    document.getElementById('activity_other').style.display = "block";
    }
else
  {
    document.getElementById('activity_other').style.display = "none";
    }
  	
}
function formCheck(mode, description)
{ 
         if(!CheckUnselects(document.forms[0].RECEIVE_YES_NO))
	{
		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].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.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.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;
		}	        
        
	if (!CheckUnselects(document.forms[0].PRIMARY_ACTIVITY))
    		{
    			alert("Please specify the primary activity of your organization.");
            		document.forms[0].PRIMARY_ACTIVITY[0].focus();
    			return false;
    		}
        if (CheckedRadioValue(document.forms[0].PRIMARY_ACTIVITY)=="98")
			{
				if(document.forms[0].PRIMARY_ACTIVITY_DESC1.value == "")
				{
					alert("Please specify the description of your business.");
	        			document.forms[0].PRIMARY_ACTIVITY_DESC1.focus();
					return false;
				}
			}
                if (CheckedRadioValue(document.forms[0].PRIMARY_ACTIVITY)=="97")
			{
				if(document.forms[0].PRIMARY_ACTIVITY_DESC.value == "")
				{
					alert("Please specify the description of your type of photography.");
	        			document.forms[0].PRIMARY_ACTIVITY_DESC.focus();
					return false;
				}
			}
                if (!CheckUnselects(document.forms[0].JOB_TITLE))
    		{
    			alert("Please specify your job title.");
            		document.forms[0].JOB_TITLE[0].focus();
    			return false;
    		}
                if (CheckedRadioValue(document.forms[0].JOB_TITLE)=="98")
			{
				if(document.forms[0].JOB_TITLE_DESC.value == "")
				{
					alert("Please specify the description of your job title.");
	        			document.forms[0].JOB_TITLE_DESC.focus();
					return false;
				}
			}
               if (!CheckDropdown(document.forms[0].PERSONAL_ID))
		{
		alert ("Please select your Personal Identifier.");
		document.forms[0].PERSONAL_ID.focus();
		return false;
		} 
			
 }

function DiscPaidformCheck(mode)
{ 
    if (!CheckPaymentInfo())
	{
		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.getElementById("us_state"))
                        {
                               if (document.paidform.STATE.selectedIndex == 0)
                                {
					alert("Please specify your State.");
					document.paidform.STATE.focus();
					return false;
                                }
                               if (document.paidform.ZIPCODE.value.length < 5)
				{
					alert("Please specify your Zip Code.");
	        			document.paidform.ZIPCODE.focus();
					return false;
				}
                                
			} 
		if (document.getElementById("all"))
{
                               if (document.paidform.STATE.selectedIndex == 0)
				{
					alert("Please specify your State/Province or select 'I am not in the US 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.STATE[document.paidform.STATE.selectedIndex].value >= 53)
			{
				alert("This offer is available to U.S. residents only.");
	        		document.paidform.STATE.focus();
				return false;
			}

        if (document.paidform.EMAIL_ADDRESS.value == "")
	{
		alert("Please specify your E-mail Address.");
        	document.paidform.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 (document.paidform.EMAIL_ADDRESS2.value == "")
	       {
		      alert("Please confirm your email address.");
		      document.paidform.EMAIL_ADDRESS2.focus();
		      return false;
                }
        
            if(document.paidform.EMAIL_ADDRESS.value.toUpperCase() != document.paidform.EMAIL_ADDRESS2.value.toUpperCase())
	       {
	           alert("Confirmation email address does not match email address.");
	           document.paidform.EMAIL_ADDRESS.focus();
	           return false;
	       }
	}
        if (document.paidform.PHONE.value == "")
		{
			alert("Please specify your Business Phone.");
	    		document.paidform.PHONE.focus();
			return false;
		}
	
	if (!CheckUnselects(document.paidform.PRIMARY_ACTIVITY))
    		{
    			alert("Please specify the primary activity of your organization.");
            		document.paidform.PRIMARY_ACTIVITY[0].focus();
    			return false;
    		}
        if (CheckedRadioValue(document.paidform.PRIMARY_ACTIVITY)=="98")
			{
				if(document.paidform.PRIMARY_ACTIVITY_DESC1.value == "")
				{
					alert("Please specify the description of your business.");
	        			document.paidform.PRIMARY_ACTIVITY_DESC1.focus();
					return false;
				}
			}
                if (CheckedRadioValue(document.paidform.PRIMARY_ACTIVITY)=="97")
			{
				if(document.paidform.PRIMARY_ACTIVITY_DESC.value == "")
				{
					alert("Please specify the description of your type of photography.");
	        			document.paidform.PRIMARY_ACTIVITY_DESC.focus();
					return false;
				}
			}
                if (!CheckUnselects(document.paidform.JOB_TITLE))
    		{
    			alert("Please specify your job title.");
            		document.paidform.JOB_TITLE[0].focus();
    			return false;
    		}
                if (CheckedRadioValue(document.paidform.JOB_TITLE)=="98")
			{
				if(document.paidform.JOB_TITLE_DESC.value == "")
				{
					alert("Please specify the description of your job title.");
	        			document.paidform.JOB_TITLE_DESC.focus();
					return false;
				}
			}
}
	return true;
}
function GiftformCheck(mode)
{ 
	if(!CheckUnselects(document.paidform.PRODUCT))	
	{
		alert("Please select your subscription.");
        	document.paidform.PRODUCT[0].focus();
		return false;
	}
	if (!CheckPaymentInfo())
	{
		return false;
	}
        if (!CheckBillingAddress())
		{
			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[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[document.paidform.COUNTRY.selectedIndex].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.STATE[document.paidform.STATE.selectedIndex].value == "53")
        {

	 if ((CheckedRadioValue(document.paidform.PRODUCT) == "01")
||(CheckedRadioValue(document.paidform.PRODUCT) == "02") 
||(CheckedRadioValue(document.paidform.PRODUCT) == "03")
||(CheckedRadioValue(document.paidform.PRODUCT) == "21")
||(CheckedRadioValue(document.paidform.PRODUCT) == "22")
||(CheckedRadioValue(document.paidform.PRODUCT) == "23"))
                {
             
	      alert("International subscribers may receive digital version only.");
                      return false;
                }
		
			
        }
        
	if (document.paidform.EMAIL_ADDRESS.value == "")
	{
		alert("Please specify your E-mail Address.");
        	document.paidform.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;
		}
	}
        
       
	
	return true;
      }
		
    } 
         
}               
 


function CheckBillingAddress()
{
		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 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.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.DONOR_EMAIL_ADDRESS.value == "")
	       {
		alert("Please specify your Billing E-mail Address.");
        	document.paidform.DONOR_EMAIL_ADDRESS.focus();
		return false;
	       }
	return true;
}
function isAllowdChar (c)
{   return ((c == "_") || (c == "@")||(c=="."))
    
}
function isAllowdCharPass (c)
{   return ((c == "#") || (c == "_")||(c=="@")||(c=="*"))
    
}

function isValidChar (s)

{   var i;
    
    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        

        if (! (isLetter(c) || isDigit(c) || isAllowdChar(c)))
        return false;
    }

    
    return true;
}

function isValidCharPass (s)

{   var i;
    
    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        

        if (! (isLetter(c) || isDigit(c) || isAllowdCharPass(c)))
        return false;
    }

    
    return true;
}







