function validate_form2()
{
if (document.form2.Affiliate_Company_Name.value == "")
{
          document.form2.Affiliate_Company_Name.focus();
          document.form2.Affiliate_Company_Name.style.backgroundColor = "ffffcc"
          return !(alert ("please enter the company Name"));

}
if (document.form2.Affiliate_Address_1.value == "")
{
          document.form2.Affiliate_Address_1.focus();
          document.form2.Affiliate_Address_1.style.backgroundColor = "ffffcc"
          return !(alert ("please enter the Address"));

}

if (document.form2.Affiliate_City.value == "")
{
          document.form2.Affiliate_City.focus();
          document.form2.Affiliate_City.style.backgroundColor = "ffffcc"
          return !(alert ("please enter the city"));

}

if (document.form2.Affiliate_State.value == "")
{
          document.form2.Affiliate_State.focus();
          document.form2.Affiliate_State.style.backgroundColor = "ffffcc"
          return !(alert ("please select the State"));

}

{
var lzip = new String
lzip = document.form2.Affiliate_Zip.value;
lzip = lzip.toLowerCase();
if (document.form2.Affiliate_Zip.value == "" || lzip == "zip")
{
          document.form2.Affiliate_Zip.focus();
          document.form2.Affiliate_Zip.select();
          document.form2.Affiliate_Zip.style.backgroundColor = "ffffcc"
          return !(alert ("please enter the Zip"));

}
}

if (document.form2.Affiliate_Country.value == "")
{
          document.form2.Affiliate_Country.focus();
          document.form2.Affiliate_Country.style.backgroundColor = "ffffcc"
          return !(alert ("please select the Country"));

}

if (document.form2.Affiliate_Contact_Fname.value == "")
{
          document.form2.Affiliate_Contact_Fname.focus();
          document.form2.Affiliate_Contact_Fname.style.backgroundColor = "ffffcc"
          return !(alert ("please enter the Contact First Name"));

}

if (document.form2.Affiliate_Contact_Lname.value == "")
{
          document.form2.Affiliate_Contact_Lname.focus();
          document.form2.Affiliate_Contact_Lname.style.backgroundColor = "ffffcc"
          return !(alert ("please enter the Contact Last Name"));

}

if (document.form2.Affiliate_Area_Code.value == "")
{
          document.form2.Affiliate_Area_Code.focus();
          document.form2.Affiliate_Area_Code.style.backgroundColor = "ffffcc"
          return !(alert ("please enter the Area Code"));
}

if (document.form2.Affiliate_Phone1.value == "")
{
          document.form2.Affiliate_Phone1.focus();
          document.form2.Affiliate_Phone1.style.backgroundColor = "ffffcc"
          return !(alert ("please enter the Phone 1"));
}

if (document.form2.Affiliate_Phone2.value == "")
{
          document.form2.Affiliate_Phone2.focus();
          document.form2.Affiliate_Phone2.style.backgroundColor = "ffffcc"
          return !(alert ("please enter the Phone 2"));
}
if (document.form2.Affiliate_Contact_Email.value == "")
{
          document.form2.Affiliate_Contact_Email.focus();
          document.form2.Affiliate_Contact_Email.style.backgroundColor = "ffffcc"
          return !(alert ("please enter emain address"));
}
}


function validate_form1()
{
document.form1.action = "add_affiliate_2.asp";
if (document.form1.Link_Type(0).checked == false && document.form1.Link_Type(1).checked == false)
{
          document.form1.Link_Type(0).style.backgroundColor = "ffffcc"
          document.form1.Link_Type(1).style.backgroundColor = "ffffcc"
          return !(alert ("please select one of the options for link type"));
}
}


function validate_form1_signin()
{
document.form1.action = "affiliate_signin.asp";
if (document.form1.Account_ID.value == "")
{
          document.form1.Account_ID.style.backgroundColor = "ffffcc"
          document.form1.Account_ID.focus();
          return !(alert ("please enter your account id"));
}

if (document.form1.Password.value == "")
{
          document.form1.Password.style.backgroundColor = "ffffcc"
          document.form1.Password.focus();
          return !(alert ("please enter a valid password"));
}

}



var errMsgEmail='';
var empty='';

function echeck(str)
	{

		var at='@';
		var dot='.';
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str.indexOf(at)==-1)
			{
				errMsgEmail='Invalid E-mail Address. \n'
				return false
			}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
			{
				errMsgEmail='Invalid E-mail Address. \n'
				return false
			}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
			{
				errMsgEmail='Invalid E-mail Address. \n'
				return false
			}
		 if (str.indexOf(at,(lat+1))!=-1)
			{
				errMsgEmail='Invalid E-mail Address. \n'
				return false
			}
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
			{
				errMsgEmail='Invalid E-mail Address. \n'
				return false
			}
		 if (str.indexOf(dot,(lat+2))==-1)
			{
				errMsgEmail='Invalid E-mail Address. \n'
				return false
			}
		 if (str.indexOf(" ")!=-1)
			{
				errMsgEmail='Invalid E-mail Address. \n'
				return false
			}
			
 		 return true					
	}

function ValidateEmail(emailvalue)
	{
		var emailID=emailvalue
	
		if ((emailID==null)||(emailID==""))
			{
				errMsgEmail='Please Enter an Email Address. \n';
				return errMsgEmail;
			}
		if (echeck(emailID)==false)
			{
			return errMsgEmail;
			}
		else
			{
				return empty;
			}
	}

/*
There are three functions in this set for credit card validation.
The main function is:
validateCard(cardNumber,cardType,cardMonth,cardYear)
	parameters:
		all paramaters are string values.
		Month & Year come from the select input fields in the form, so they are defined.
		cardType can be:
			'a' for American Express
			'd' for Discover
			'm' for MasterCard
			'v' for Visa
	description:
		this function will check string length, valid characters, specific credit card prefixes and test
		the Mod 10 (LUHN Formula) for validating possible credit card numbers. this function can only
		authorize that the given card data is potentially valid. You would still need to run actual
		card validation routines to verify the actual account.
	returns:
		this function returns true if the card number could be valid for the card type and expiration date.
		false otherwise.	
supporting functions:
mod10( cardNumber )
	parameters:
		this function takes the text string card number and runs the Mod 10 formula on its respective digits.
	description:
		Mod 10 is the check digit formula for the supported cards these functions attempt to validate.
	returns:
		this function returns true if the number passes the check digit test.
		false otherwise.
expired( cardMonth, cardYear )
	parameters:
		this function takes the text string values given by the html form.
	description:
		this function basically will check to make sure todays date is less than the expiration date the user inputs.
		this function is not locked into using 2 digit dates.
	returns:
		this fucntion returns true if the card is expired.
		false otherwise.
*/
function mod10(cardNumber ) { // LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;


    	for( i = 0; i < cardNumber.length; ++i ) {
    		ar[i] = parseInt(cardNumber.charAt(i));
    	}
    	for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
    		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
    		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
    	}										 // if the double digit is > 9, ADD those individual digits together 


        	for( i = 0; i < ar.length; ++i ) {
        		sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds
        	}
        	return (((sum%10)==0)?true:false);	 	
    }


        function expired( month, year ) {
        	var now = new Date();							// this function is designed to be Y2K compliant.
        	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
        	expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
        	if( now.getTime() < expiresIn.getTime() ) return false;
        	return true;									// then we get the miliseconds, and do a long integer comparison
}


function validateCard(cardNumber,cardMonth,cardYear)
 {
        	if(cardNumber.length == 0 ) {						//most of these checks are self explanitory
			document.cc_form.x_card_num.focus();
			  document.cc_form.x_card_num.style.backgroundColor = "ffffcc";
        		alert("Please enter a valid card number.");
        		return false;				
        	}
        	if( parseInt(cardNumber) == 0 ) {						//most of these checks are self explanitory
			document.cc_form.x_card_num.focus();
			  document.cc_form.x_card_num.style.backgroundColor = "ffffcc";
        		alert("Please enter a valid card number.");
        		return false;				
        	}

        	for( var i = 0; i < cardNumber.length; ++i ) {		// make sure the number is all digits.. (by design)
        		var c = cardNumber.charAt(i);


            		if( c < '0' || c > '9' ) {
				document.cc_form.x_card_num.focus();
				 document.cc_form.x_card_num.style.backgroundColor = "ffffcc";
            			alert("Please enter a valid card number. Use only digits. do not use spaces or hyphens.");
            			return false;
            		}
            	}
            	var length = cardNumber.length;			//perform card specific length and prefix tests


                                                	if( !mod10( cardNumber ) ) { 		// run the check digit algorithm
    											      document.cc_form.x_card_num.focus();
 														document.cc_form.x_card_num.style.backgroundColor = "ffffcc";
                                                		alert("Sorry! this is not a valid credit card number.");
                                                		return false;
                                                	}
        	if(document.cc_form.x_exp_month.value == "" ) {						//most of these checks are self explanitory
			document.cc_form.x_exp_month.focus();
			  document.cc_form.x_exp_month.style.backgroundColor = "ffffcc";
        		alert("Please enter exp month.");
        		return false;				
        	}
        	if(parseInt(document.cc_form.x_exp_month.value) >12 ) {						//most of these checks are self explanitory
			document.cc_form.x_exp_month.focus();
			  document.cc_form.x_exp_month.style.backgroundColor = "ffffcc";
        		alert("Please enter a valid exp month.");
        		return false;				
        	}

        	if( document.cc_form.x_exp_year.value == "" ) {						//most of these checks are self explanitory
			document.cc_form.x_exp_year.focus();
			  document.cc_form.x_exp_year.style.backgroundColor = "ffffcc";
        		alert("Please enter exp year.");
        		return false;				
        	}

		year = 20+cardYear
       if( expired( cardMonth, year ) ) {		
       		alert("Sorry! The expiration date you have entered would make this card invalid.");
             return false;
             }
       if (document.cc_form.x_first_name.value == "")
       {
          document.cc_form.x_first_name.focus();
          document.cc_form.x_first_name.style.backgroundColor = "ffffcc";
          alert ("please enter First Name");
		  return false;
       }   
       if (document.cc_form.x_last_name.value == "")
       {
          document.cc_form.x_last_name.focus();
		  document.cc_form.x_last_name.style.backgroundColor = "ffffcc";
         alert ("please enter last name");
		  return false;

	   }
		if (document.cc_form.x_email.value == "")
       {
          document.cc_form.x_email.focus();
		  document.cc_form.x_email.style.backgroundColor = "ffffcc";
          alert ("please enter an email address");
		  return false;

	   }

		if (document.cc_form.x_email.value != "")
		{
		errMsg=ValidateEmail(document.cc_form.x_email.value);
		if (errMsg != "")
		{
          document.cc_form.x_email.focus();
		  document.cc_form.x_email.style.backgroundColor = "ffffcc";
          alert ("please enter a valid email address");
		  return false;
		}	
		}

		if (document.cc_form.x_address.value == "")
       {
          document.cc_form.x_address.focus();
		  document.cc_form.x_address.style.backgroundColor = "ffffcc";
          alert ("please enter address");
		  return false;

	   }
		if (document.cc_form.x_city.value == "")
       {
          document.cc_form.x_city.focus();
		  document.cc_form.x_city.style.backgroundColor = "ffffcc";
          alert ("please enter a city");
		  return false;

	   }
		if (document.cc_form.x_state.value == "")
       {
          document.cc_form.x_state.focus();
		  document.cc_form.x_state.style.backgroundColor = "ffffcc";
          alert ("please select a state");
		  return false;

	   }
		if (document.cc_form.x_zip.value == "")
       {
          document.cc_form.x_zip.focus();
		  document.cc_form.x_zip.style.backgroundColor = "ffffcc";
          alert ("please enter zipcode");
		  return false;

	   }
		if (document.cc_form.x_country.value == "")
       {
          document.cc_form.x_country.focus();
		  document.cc_form.x_country.style.backgroundColor = "ffffcc";
          alert ("please enter country");
		  return false;

	   }
		if (document.cc_form.Phone_AreaCode.value == "")
       {
          document.cc_form.Phone_AreaCode.focus();
		  document.cc_form.Phone_AreaCode.style.backgroundColor = "ffffcc";
          alert ("please enter the area code");
		  return false;

	   }

		if (document.cc_form.Phone_1.value == "")
       {
          document.cc_form.Phone_1.focus();
		  document.cc_form.Phone_1.style.backgroundColor = "ffffcc";
          alert ("please enter phone number");
		  return false;

	   }
		if (document.cc_form.Phone_2.value == "")
       {
          document.cc_form.Phone_2.focus();
		  document.cc_form.Phone_2.style.backgroundColor = "ffffcc";
         alert ("please enter phone number");
		  return false;
	   }
     	return true; // at this point card has not been proven to be invalid
}

function validate_form4()
{
if (document.form4.Affiliate_Web_Address.value == "")
{
          document.form4.Affiliate_Web_Address.focus();
          document.form4.Affiliate_Web_Address.style.backgroundColor = "ffffcc";
          return !(alert ("please enter the Affiliate Web Address"));

}
if (document.form4.Affiliate_Site_Title.value == "")
{
          document.form4.Affiliate_Site_Title.focus();
          document.form4.Affiliate_Site_Title.style.backgroundColor = "ffffcc";
          return !(alert ("please enter the Site Title"));

}

if (document.form4.Affiliate_Category_Type_ID.value == "")
{
          document.form4.Affiliate_Category_Type_ID.focus();
          document.form4.Affiliate_Category_Type_ID.style.backgroundColor = "ffffcc";
          return !(alert ("please select Category Type"));
}

if (document.form4.Affiliate_Webmaster.value == "")
{
          document.form4.Affiliate_Webmaster.focus();
          document.form4.Affiliate_Webmaster.style.backgroundColor = "ffffcc";
          return !(alert ("please enter the  Affiliate Webmaster"));

}

if (document.form4.Affiliate_Webmaster_Email.value == "")
{
          document.form4.Affiliate_Webmaster_Email.focus();
          document.form4.Affiliate_Webmaster_Email.style.backgroundColor = "ffffcc";
          return !(alert ("please enter the Affiliate Webmaster Email"));

}

if (document.form4.Affiliate_Link_Send_Email(0).checked == false && document.form4.Affiliate_Link_Send_Email(1).checked == false && document.form4.Affiliate_Link_Send_Email(2).checked == false)
{
          document.form4.Affiliate_Link_Send_Email(0).style.backgroundColor = "ffffcc";
          document.form4.Affiliate_Link_Send_Email(1).style.backgroundColor = "ffffcc";
          document.form4.Affiliate_Link_Send_Email(2).style.backgroundColor = "ffffcc";
          return !(alert ("please select one of the options"));

}



if (document.form4.Affiliate_Account_ID.value == "")
{
          document.form4.Affiliate_Account_ID.focus();
          document.form4.Affiliate_Account_ID.style.backgroundColor = "ffffcc";
          return !(alert ("please enter the affiliate account id"));

}

if (document.form4.Affiliate_Password.value == "")
{
          document.form4.Affiliate_Password.focus();
          document.form4.Affiliate_Password.style.backgroundColor = "ffffcc";
          return !(alert ("please enter the affiliate account password"));

}

if (document.form4.Affiliate_Password_V.value == "")
{
          document.form4.Affiliate_Password_V.focus();
          document.form4.Affiliate_Password_V.style.backgroundColor = "ffffcc";
          return !(alert ("please reenter the affiliate account password"));

}

{
var pass_word = new String
var pass_word_v = new String

pass_word = document.form4.Affiliate_Password.value;
pass_word = pass_word.toLowerCase();

pass_word_v = document.form4.Affiliate_Password_V.value;
pass_word_v = pass_word_v.toLowerCase();



if (pass_word !=  pass_word_v)
{
          document.form4.Affiliate_Password_V.focus();
          document.form4.Affiliate_Password_V.style.backgroundColor = "ffffcc";
          return !(alert ("your passwords did not match. please enter again"));

}
}

}


