function clear_traffic_data_source()
	{
	if(document.publisher_app.website_traffic_data_source_type[0].checked==true)
		{
		document.publisher_app.website_traffic_data_source_2.value="";
		document.publisher_app.website_traffic_data_source_date_2.value="";
		}
	if(document.publisher_app.website_traffic_data_source_type[1].checked==true)
		{
		document.publisher_app.website_traffic_data_source_1.value="";
		document.publisher_app.website_traffic_data_source_date_1.value="";
		}
	if(document.publisher_app.website_traffic_data_source_type[2].checked==true)
		{
		document.publisher_app.website_traffic_data_source_1.value="";
		document.publisher_app.website_traffic_data_source_date_1.value="";
		document.publisher_app.website_traffic_data_source_2.value="";
		document.publisher_app.website_traffic_data_source_date_2.value="";
		}
	}
function clear_audience_data_source()
	{
	if(document.publisher_app.website_audience_data_source_type[0].checked==true)
		{
		document.publisher_app.website_audience_data_source_2.value="";
		document.publisher_app.website_audience_data_source_date_2.value="";
		}
	if(document.publisher_app.website_audience_data_source_type[1].checked==true)
		{
		document.publisher_app.website_audience_data_source_1.value="";
		document.publisher_app.website_audience_data_source_date_1.value="";
		}
	if(document.publisher_app.website_audience_data_source_type[2].checked==true)
		{
		document.publisher_app.website_audience_data_source_1.value="";
		document.publisher_app.website_audience_data_source_date_1.value="";
		document.publisher_app.website_audience_data_source_2.value="";
		document.publisher_app.website_audience_data_source_date_2.value="";
		}
	}
function clear_payment_method()
	{
	if(document.publisher_app.website_payment_method[0].checked==true)
		{
		document.publisher_app.website_payment_check_payee.value="";
		}
	if(document.publisher_app.website_payment_method[1].checked==true)
		{
		document.publisher_app.website_payment_paypal_email.value="";
		}
	}
function validate_publisher_app()
	{
	var msg = "";
	msg += checkInput(document.publisher_app.contact_fname.value,"First Name");
	msg += checkInput(document.publisher_app.contact_lname.value,"Last Name");
	//msg += checkInput(document.publisher_app.contact_title.value,"Title");
	msg += checkInput(document.publisher_app.company_name.value,"Company Name");
	//msg += checkInput(document.publisher_app.contact_address1.value,"Address");
	msg += checkInput(document.publisher_app.contact_city.value,"City");
	msg += checkInput(document.publisher_app.contact_state.value,"State");
	msg += checkInput(document.publisher_app.contact_zip.value,"Zip Code");
	msg += checkInput(document.publisher_app.contact_phone.value,"Phone");
	msg += checkEmail(document.publisher_app.contact_email.value);
	msg += checkConfirm(document.publisher_app.contact_email.value,document.publisher_app.email_confirm.value,"Email");
	//msg += checkInput(document.publisher_app.website_name.value,"Web Site Name");
	msg += checkInput(document.publisher_app.website_url.value,"Web Site URL");
	/*
	msg += checkInput(document.publisher_app.website_description.value,"Web Site Description");
	msg += checkDropdown(document.publisher_app.website_category_id.selectedIndex,"Web Site Category");
	msg += checkInput(document.publisher_app.website_visitors_month.value,"Web Site Traffic - Monthly Visitors");
	msg += checkInput(document.publisher_app.website_visitors_day.value,"Web Site Traffic - Daily Visitors");
	msg += checkInput(document.publisher_app.website_page_views_month.value,"Web Site Traffic - Monthly Page Views");
	msg += checkInput(document.publisher_app.website_ad_impressions_month.value,"Web Site Traffic - Monthly Ad Impressions");
	msg += checkRadio(document.publisher_app.website_traffic_data_source_type,3,"Web Site Traffic - Data Source");
	*/
	if (document.publisher_app.website_traffic_data_source_type[0].checked==true)
		{
		msg += checkInput(document.publisher_app.website_traffic_data_source_1.value,"Web Site Traffic - Third Party Source");
		msg += checkInput(document.publisher_app.website_traffic_data_source_date_1.value,"Web Site Traffic - Third Party Date");
		}
	if (document.publisher_app.website_traffic_data_source_type[1].checked==true)
		{
		msg += checkInput(document.publisher_app.website_traffic_data_source_2.value,"Web Site Traffic - Site Survey Source");
		msg += checkInput(document.publisher_app.website_traffic_data_source_date_2.value,"Web Site Traffic - Site Survey Date");
		}
	/*
	msg += check_ad_sizes();
	msg += checkDropdown(document.publisher_app.website_audience_gender.selectedIndex,"Web Site Audience - Gender");
	msg += checkDropdown(document.publisher_app.website_audience_age.selectedIndex,"Web Site Audience - Age");
	msg += checkDropdown(document.publisher_app.website_audience_income.selectedIndex,"Web Site Audience - Income");
	msg += checkRadio(document.publisher_app.website_audience_data_source_type,3,"Web Site Audience - Data Source");
	*/
	if (document.publisher_app.website_audience_data_source_type[0].checked==true)
		{
		msg += checkInput(document.publisher_app.website_audience_data_source_1.value,"Web Site Audience - Third Party Source");
		msg += checkInput(document.publisher_app.website_audience_data_source_date_1.value,"Web Site Audience - Third Party Date");
		}
	if (document.publisher_app.website_audience_data_source_type[1].checked==true)
		{
		msg += checkInput(document.publisher_app.website_audience_data_source_2.value,"Web Site Audience - Site Survey Source");
		msg += checkInput(document.publisher_app.website_audience_data_source_date_2.value,"Web Site Audience - Site Survey Date");
		}
	msg += checkDropdown(document.publisher_app.website_content_user_generated.selectedIndex,"user generated content response");
	/*
	msg += checkDropdown(document.publisher_app.website_auto_refreshing_impressions.selectedIndex,"Web Site Content - Auto-refreshing?");
	if(document.publisher_app.website_agreement_accepted[0].checked==false &&
		document.publisher_app.website_agreement_accepted[1].checked==false)
		{
		//msg += "You must accept the Terms of Agreement in order to submit this form.\n";
		msg += "Please select Yes or No to acceptance of Online Publisher Agreement.\n";
		}
	msg += checkInput(document.publisher_app.website_logon_user_name.value,"Logon User Name");
	msg += checkInput(document.publisher_app.website_logon_password.value,"Logon Password");
	msg += checkConfirm(document.publisher_app.website_logon_password.value,document.publisher_app.password_confirm.value,"Password");
	msg += checkDropdown(document.publisher_app.company_entity.selectedIndex,"Company Entity");
	msg += checkInput(document.publisher_app.company_tax_id.value,"Company Tax ID");
	msg += checkRadio(document.publisher_app.website_payment_method,2,"Payment Method");
	*/
	if (document.publisher_app.website_payment_method[0].checked==true)
		{
		msg += checkInput(document.publisher_app.website_payment_paypal_email.value,"Paypal Account Email");
		}
	if (document.publisher_app.website_payment_method[1].checked==true)
		{
		msg += checkInput(document.publisher_app.website_payment_check_payee.value,"Payee on check");
		}
	if (msg != "")
		{
		alert(msg);
		return false;
		}
	if(document.publisher_app.website_traffic_data_source_type[0].checked==true)
		{
		document.publisher_app.website_traffic_data_source.value=document.publisher_app.website_traffic_data_source_1.value;
		document.publisher_app.website_traffic_data_source_date.value=document.publisher_app.website_traffic_data_source_date_1.value;
		}
	if(document.publisher_app.website_traffic_data_source_type[1].checked==true)
		{
		document.publisher_app.website_traffic_data_source.value=document.publisher_app.website_traffic_data_source_2.value;
		document.publisher_app.website_traffic_data_source_date.value=document.publisher_app.website_traffic_data_source_date_2.value;
		}
	if(document.publisher_app.website_traffic_data_source_type[2].checked==true)
		{
		document.publisher_app.website_traffic_data_source.value="";
		document.publisher_app.website_traffic_data_source_date.value="";
		}
	if(document.publisher_app.website_audience_data_source_type[0].checked==true)
		{
		document.publisher_app.website_audience_data_source.value=document.publisher_app.website_audience_data_source_1.value;
		document.publisher_app.website_audience_data_source_date.value=document.publisher_app.website_audience_data_source_date_1.value;
		}
	if(document.publisher_app.website_audience_data_source_type[1].checked==true)
		{
		document.publisher_app.website_audience_data_source.value=document.publisher_app.website_audience_data_source_2.value;
		document.publisher_app.website_audience_data_source_date.value=document.publisher_app.website_audience_data_source_date_2.value;
		}
	if(document.publisher_app.website_audience_data_source_type[2].checked==true)
		{
		document.publisher_app.website_audience_data_source.value="";
		document.publisher_app.website_audience_data_source_date.value="";
		}
	return true;
	}
function checkInput (strng,field)
	{
	var error = "";
	if (strng == "")
		{
		error = field+" not entered.\n";
		}
	return error; 
	}
function checkRadio (strng,count,field)
	{
	var error = "";
	var i=0;
	var selected=false;
	while (i<count)
		{
		if(strng[i].checked==true) selected=true;
		i++;
		}
	if (selected == false)
		{
		error = field+" - make a selection.\n";
		}
	return error; 
	}
function checkDropdown(choice,field)
	{
	var error = "";
	if (choice == 0)
		{
		error = "Please choose a "+field+" from the drop-down list.\n";
		}    
	return error;
	}
function checkConfirm (strng1,string2,field)
	{
	var error = "";
	if (strng1 != string2)
		{
		error = field+" confirmation does not match.\n";
		}
	return error; 
	}
function check_ad_sizes()
	{
	var error = "";
	if (document.publisher_app.website_ad_size_1.checked==false && document.publisher_app.website_ad_size_2.checked==false &&
	    document.publisher_app.website_ad_size_3.checked==false && document.publisher_app.website_ad_size_4.checked==false &&
	    document.publisher_app.website_ad_size_5.checked==false && document.publisher_app.website_ad_size_other.value=="")
		   {
	  	 error = "Check at least one Ad Size.\n";
	  	   }
	return error; 
	}
function checkEmail(string)
	{
	var error = "";
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(string)))
		{ 
		error = "Please enter a valid email address.\n";
		}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if (string.match(illegalChars))
		{
		error = "Email address contains illegal characters.\n";
		}
	return error;
	}
// Credit Card Validation Javascript
// copyright 12th May 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateCreditCard(s)
	{
	var v = "0123456789";
	var w = "";
	for (var i=0; i < s.length; i++)
		{
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1) w += x;
		}
	var j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7) return false;
	var k = Math.floor(j);
	var m = Math.ceil(j) - k;
	var c = 0;
	for (var i=0; i<k; i++)
		{
		a = w.charAt(i*2+m) * 2;
		c += a > 9 ? Math.floor(a/10 + a%10) : a;
		}
	for (var i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
	return (c%10 == 0);
	}
function checkCreditCard(cc_number)
	{
//	Diners Club/Carte Blanche prefix:300-305;36;38 length=14
	var error = "";
	if (publisher_app.cc_type.options[publisher_app.cc_type.options.selectedIndex].value=="Visa")
		{
		if (cc_number.charAt(0)!="4") error = "Not a Visa account number.\n";
		//visa length=13 or 16
		}
	if (publisher_app.cc_type.options[publisher_app.cc_type.options.selectedIndex].value=="Mastercard")
		{
		if (cc_number.charAt(0)!="5") error = "Not a MasterCard account number.\n";
		if (cc_number.charAt(1)<"1" || cc_number.charAt(1)>"5") error = "Not a MasterCard account number.\n";
		//MC length=16
		}
	if (publisher_app.cc_type.options[publisher_app.cc_type.options.selectedIndex].value=="Discover")
		{
		var prefix=cc_number.charAt(0)+cc_number.charAt(1)+cc_number.charAt(2)+cc_number.charAt(3);
		if (prefix!="6011") error = "Not a Discover account number.\n";
		//discover length=16
		}
	if (publisher_app.cc_type.options[publisher_app.cc_type.options.selectedIndex].value=="American Express")
		{
		if (cc_number.charAt(0)!="3") error = "Not an American Express account number.\n";
		if (cc_number.charAt(1)!="4" && cc_number.charAt(1)!="7") error = "Not an American Express account number.\n";
		//amex length=15
		}
	return error;
	}
function checkExpirationDate(month_index,year_index)
	{
	var error = "";
	var selected_year=publisher_app.cc_expire_year.options[year_index].value;
	var right_now=new Date();
	var current_month = right_now.getMonth()+1;
	var current_year = right_now.getYear();
	if (current_year < 2000) current_year = current_year + 1900;
	if (selected_year==current_year)
		{
		if (month_index < current_month) error = "Credit Card appears to be expired\n";
		}
	return error;
	}
