
//This function check the e-mail format
function checkEmail(obj)
{
	str= obj.value;

	if(str !=="") {
		index=str.indexOf("@");
		if(index==-1)
		{
			alert("Invalid e-mail address.");
			obj.value="";
			obj.focus();
		}
	}
}

function checkCategory(theFormObject)
{
	var catcount =0;
		if (document.formName.ind_check_1.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_2.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_3.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_4.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_5.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_6.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_7.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_8.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_9.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_10.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_11.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_12.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_13.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_14.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_15.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_16.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_17.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_18.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_19.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_20.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_22.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_23.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_24.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_25.checked === true ) {
			catcount += 1;
		}
		if (document.formName.ind_check_26.checked === true ) {
			catcount += 1;
		}

	if (catcount > 3)
	{
		alert("You have selected more than 3 industry types. Please deselect one of them first.");
		theFormObject.checked = false;
	} 
	if (catcount === 0)
	{
		alert("Please select at least one industry type.");
		return false;
	} 

}
function checkAffiliate()
{
	var valid;
	valid=true;

	if(document.formName.affiliate_url_website.value === "")
	{
		alert ("Please enter your home URL.");
		valid=false;
		document.formName.affiliate_url_website.focus();
	}
	return valid;
}

function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
		alert ("Invalid URL.");
        return false;
    }
} 

function checkForm()
{
	var valid;
	var check1;


	valid=true;
	check1=false;

	check1=checkAffiliate();
	if (check1===false) {
		return(false);
	}

	checkInd = checkCategory(null);
	if (checkInd===false) {
		return(false);
	}

	if (document.formName.check_user_email.value!=="" && document.formName.check_user_password.value==="")
	{
			alert ("Please enter your AffiliateShop Account Password.");
			valid=false;
			document.formName.check_user_email.focus();
	}
	if (document.formName.check_user_email.value==="" && document.formName.check_user_password.value==="")
	{
		if(document.formName.user_email.value==="")
		{
			alert ("Please enter your user Email address.");
			valid=false;
			document.formName.user_email.focus();
		}
		else
		if(document.formName.user_password.value==="")
		{
			alert ("Please enter a password for your user account");
			valid=false;
			document.formName.user_password.value="";
			document.formName.user_password_confirmation.value="";
			document.formName.user_password.focus();
		}
		else
		if(document.formName.user_password.value!==document.formName.user_password_confirmation.value)
		{
			alert ("Affiliate account passwords do not match.");
			valid=false;
			document.formName.user_password.value="";
			document.formName.user_password_confirmation.value="";
			document.formName.user_password.focus();
		}
		else
		if(document.formName.user_contact.value==="")
		{
			alert ("Please enter your user Contact Name.");
			valid=false;
			document.formName.user_contact.focus();
		}
	}

	return valid;
}
