function PaidformCheck(mode)
{ 
	if (ObjectExists(document.paidform, "SUBSCRIPTION"))
     	{
		if (!checkUnselects(document.paidform.SUBSCRIPTION))	
		{
			alert("Please select your subscription.");
		        document.paidform.SUBSCRIPTION[0].focus();
			return false;
		}
      	}

	if (ObjectExists(document.paidform, "FNAME"))
  	{
		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 (!CheckBusAddressNew(mode))
	{
		return false;
	}			

	if (document.paidform.EMAIL_ADDRESS.value == "")
	{
		alert ("Please enter email address.");
		document.paidform.EMAIL_ADDRESS.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 ((mode!="EM99P")&&(mode!="EM99PINTL"))
           {
        	if (document.paidform.PHONE.value == "")
		{
		alert ("Please specify your Business Phone.");
	    	document.paidform.PHONE.focus();
		return false;
		}	
           }
	
	if (document.paidform.SAME_ADDRESS.checked)
	{
		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 (ObjectExists(document.paidform, "PAY_STAT"))
     	{		
		if (!checkUnselects(document.paidform.PAY_STAT))	
		{
			alert("Please specify payment method.");
        		document.paidform.PAY_STAT[0].focus();
			return false;
		}
        }
	if (document.getElementById("one_option"))
           {
               var paystat=document.paidform.PAY_STAT.value;
		if (paystat == '2')
		{
		if (!CheckPaymentInfo())
			{
			  return false;
			}
        	}
           }
	if (document.getElementById("two_options"))
            {
                var paystat=CheckedRadioValue(document.paidform.PAY_STAT); 
		if (document.paidform.PAY_STAT[0].checked)
		{
		if (!CheckPaymentInfo())
			{
			  return false;
			}
        	}
          
           }
         
        if (ObjectExists(document.forms[0],"BUSINESS"))
	{
		if (!checkDropdown(document.forms[0].BUSINESS))
		{
			alert ("Please select the type of your business.");
			document.forms[0].BUSINESS.focus();
			return false;
		}
		if ((document.forms[0].BUSINESS[document.forms[0].BUSINESS.selectedIndex].value == '11')&& (document.forms[0].BUSINESS_TXT.value == ''))
		{
			alert ("Please specify your business description.");
			document.forms[0].BUSINESS_TXT.focus();
			return false;
		}
		
		
	}

	if (ObjectExists(document.forms[0],"BUSINESS2"))
	{
		if (!checkDropdown(document.forms[0].BUSINESS2))
		{
			alert ("Please select the type of your business.");
			document.forms[0].BUSINESS2.focus();
			return false;
		}
		if ((document.forms[0].BUSINESS2[document.forms[0].BUSINESS2.selectedIndex].value == '11')&& (document.forms[0].BUSINESS2_TXT.value == ''))
		{
			alert ("Please specify your business description.");
			document.forms[0].BUSINESS2_TXT.focus();
			return false;
		}
	}

	if (!checkDropdown(document.forms[0].JOB_FUNCTION))
	{
		alert ("Please select your job function.");
		document.forms[0].JOB_FUNCTION.focus();
		return false;
	}
	
	return true;
}


function FormCheck()
{ 
	if (ObjectExists(document.paidform, "FNAME"))
  	{
		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 (!CheckBusAddress())
	{
		return false;
	}
	if (document.paidform.PHONE.value == "")
	{
		alert ("Please specify your phone number.");
	        document.paidform.PHONE.focus();
		return false;
	}		
	if (ObjectExists(document.forms[0],"BUSINESS2"))
	{
		//if (!checkUnselects(document.forms[0].BUSINESS2))
		//{
		//	alert ("Please select the type of your business.");
		//	document.forms[0].BUSINESS2[0].focus();
		//	return false;
		//}
		//if ((CheckedRadioValue(document.forms[0].BUSINESS2) == '11') && //(document.forms[0].BUSINESS2_TXT.value == ''))
		//{
		//	alert ("Please specify your business description.");
		//	document.forms[0].BUSINESS2_TXT.focus();
		//	return false;
		//}
		if (!checkDropdown(document.paidform.BUSINESS2))	
		{
			alert ("Please select the type of your business.");
        		document.paidform.BUSINESS2.focus();
			return false;
		}
		if ((document.paidform.BUSINESS2[document.paidform.BUSINESS2.selectedIndex].value == '11')&& (document.paidform.BUSINESS2_TXT.value == ''))
		{
				alert ("Please select the type of your business - other.");
        			document.paidform.BUSINESS2_TXT.focus();
				return false;
		}
	}
       if (ObjectExists(document.paidform,"JOB_FUNCTION"))
	{
		if (!checkDropdown(document.paidform.JOB_FUNCTION))	
		{
			alert ("Please select your job function.");
        		document.paidform.JOB_FUNCTION.focus();
			return false;
		}
				
	}

}


function CheckBusAddress()
{
	if (document.paidform.TITLE.value == "")
	{
		alert ("Please specify your Title.");
	        document.paidform.TITLE.focus();
		return false;
	}
	if(document.paidform.COMPANY.value == "")
	{
		alert ("Please specify your Company name.");
        	document.paidform.COMPANY.focus();
		return false;
	}	
	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.Intl.value == "Intl") || ObjectExists(document.forms[0],"COUNTRY")) 
	{
		if (document.paidform.COUNTRY.value == "")
		{
			alert ("Please specify your Country.");
	        	document.paidform.COUNTRY.focus();
			return false;
		}
	}

	if (document.paidform.STATE.value != "53")
	{
		if (document.paidform.STATE.selectedIndex == 0)
		{
			alert("Please specify your State/Province.");
		        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.ZIPCODE.value.length < 5)
		{
			alert ("Please specify your Zip/Postal Code.");
	        	document.paidform.ZIPCODE.focus();
			return false;
		}
	}
	return true;
}
			
function CheckPaymentInfo()
{
	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;
	}

	// 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;
	}
	// zh
	return true;
}
function checkDropdown(selectBox)
{
	if(selectBox.selectedIndex == "0")
	{
		return false;
	}
	else
	{
		return true;
         }
}

function checkUnselects(radioItem)
{
	if (!(radioItem.length > 0))
	{
		return true;
	}
	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 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 doSubmit()
{
	SubmitFlag = true;
	return;
}


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 checkEmailValuePA()
{   //runs the validate script and returns error box or nonerror
	
	if ((document.forms[1].send_to_1.value != "") && (!validEmail(document.forms[1].send_to_1.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[1].send_to_1.focus();
		return false;
	}
	if ((document.forms[1].send_to_2.value != "") && (!validEmail(document.forms[1].send_to_2.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[1].send_to_2.focus();		
		return false;
	}
	if ((document.forms[1].send_to_3.value != "") && (!validEmail(document.forms[1].send_to_3.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[1].send_to_3.focus();		
		return false;
	}
	if ((document.forms[1].send_to_4.value != "") && (!validEmail(document.forms[1].send_to_4.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[1].send_to_4.focus();		
		return false;
	}
	if ((document.forms[1].send_to_5.value != "") && (!validEmail(document.forms[1].send_to_5.value)))
	{
		alert("You have entered an invalid email address. Please re-enter it.");
		document.forms[1].send_to_5.focus();		
		return false;
	}
	
	
	
	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 ShowDiv(it)
{
	document.getElementById(it).style.display = "block";
}
function HideDiv(it)
{
	document.getElementById(it).style.display = "none";
}


function showhideBUS(BUSINESS2)
{
var bus = (document.paidform.BUSINESS2[document.paidform.BUSINESS2.selectedIndex].value);
if (bus == "11")
    { ShowDiv('bus2_desc');}
else
    { HideDiv('bus2_desc');}
  	
}

function CheckBusAddressNew(mode)
{
  
  if ((mode != "4ASC199")&&(mode!="EM199")&&(mode!="EM99")&&(mode!="EM99INTL")
            &&(mode!="DM299")&&(mode!="DM299INTL")&&( mode!="DM249")&&(mode!="DM249INTL")
            && (mode!="DM199")&&(mode!="DM199INTL")&& (mode!="DM99")&&(mode!="DM99INTL")
            && (mode!="4BMI195")&&(mode!="SBDSS199")&&(mode!="DSTUD")&&(mode!="EM99P")
&&(mode!="EM99PINTL")&&(mode!="WBP")&&(mode!="M75PRINT")&&(mode!="MIDM")&&(mode!="DM75")
&&(mode!="DM75INTL")&&(mode!="mus10")&&(mode!="MUS10INTL"))

	{ 
		if (document.paidform.TITLE.value == "")
		{
		alert ("Please specify your Title.");
	        document.paidform.TITLE.focus();
		return false;
		}
		if(document.paidform.COMPANY.value == "")
		{
		alert ("Please specify your Company name.");
        	document.paidform.COMPANY.focus();
		return false;
		}	
        }
	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;
	}
//US only  address
        if (document.getElementById("us_state"))
                        {
                               if (document.forms[0].STATE.selectedIndex == 0)
                                {
					alert("Please specify your State.");
					document.forms[0].STATE.focus();
					return false;
                                }
                               if (document.forms[0].ZIPCODE.value.length < 5)
				{
					alert("Please specify your Zip Code.");
	        			document.forms[0].ZIPCODE.focus();
					return false;
				}
                                
			} 
//Canada only address
   if (document.getElementById("can_state"))
{
                               if (document.forms[0].STATE.selectedIndex == 0)
                                {
					alert("Please specify your 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].ZIPCODE.value.length < 5)
				{
					alert("Please specify your Postal Code.");
	        			document.forms[0].ZIPCODE.focus();
					return false;
				}
}

//US and Canada addresses
if (document.getElementById("us_can_state"))
{
                               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].ZIPCODE.value.length < 5)
				{
					alert("Please specify your Zip/Postal Code.");
	        			document.forms[0].ZIPCODE.focus();
					return false;
				}
}
//International address only
if (document.getElementById("intl_state"))
                        {
                               if (document.forms[0].COUNTRY.value == "")
				{
					alert("Please specify your Country.");
	        			document.forms[0].COUNTRY.focus();
					return false;
				}
			}   
// All kind of addresses

if (document.getElementById("all"))
{
                               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;
					}
				}

                                
	       	}
	
	
	return true;
}