
function validate_password(field)
{
	var i;
	var size;
	for (i = 0; i < 20; i++)
	{
		if (field.charAt(i) == null || field.charAt(i) == "")
			break;
	}
	
	size = i;
	
	if (size < 6 || size > 18)
	{
		alert("Your password must be between 6-18 characters\nPrelease re-enter your password");
		return false;
	}

	for (i=0; i<size; i++)
	{
		if ((field.charAt(i) >= 'a' && field.charAt(i) <= 'z') || (field.charAt(i) >= 'A' && field.charAt(i) <= 'Z'))
			break;
	}
	
	if (i == size)
	{
		alert("Your password must contain at least one letter\nPrelease re-enter your password");
		return false;
	}
	
	for (i=0; i<size; i++)
	{
		if (field.charAt(i) >= '0' && field.charAt(i) <= '9')
			break;
	}
	
	if (i == size)
	{
		alert("Your password must contain at least one number\nPrelease re-enter your password");
		return false;
	}
		
	return true;
}

function validate_numeric(field,size,errmessage)
{
	var i;
	for (i = 0; i < size; i++)
	{
		if (field.charAt(i) < '0' || field.charAt(i) > '9')
		{
			alert(errmessage);
			return false;
		}
	}

	return true;
}

function validate_email(field,errmessage)
{
	var apos=field.indexOf("@");
	var dotpos=field.lastIndexOf(".");
		
	if (apos<1 || dotpos-apos<2) 
	{
		alert(errmessage);
		return false;
	}
	
	return true;
}

function autoTab(input,len, e) 
{
  var isNN = (navigator.appName.indexOf("Netscape")!=-1);
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}

function fieldNotBlank(field, errMessage)
{
	if (field == '' || field == null)
	{
		alert(errMessage);
		return false;
	}
	return true;
}



function checkformSupporter()
{
	if (document.supporterRegistrationForm.INDIVIDUAL_ACCOUNT.value == "")
	{
		alert('Please select the type of account the earnings\nshould be applied to - General or Individual.\nif Individual, please enter the Name of the Individual');
		return false;
	}

	if (document.supporterRegistrationForm.FUNDRAISER_CODE.value == '')
	{
		alert('ALL blanks on this page must be filled in.\n\nPlease enter the fundraising code for your\norganization in the "fundraiser code" field');
		return false;
	}

	if ( (document.supporterRegistrationForm.FUNDRAISER_CODE.value < '500014') || (document.supporterRegistrationForm.FUNDRAISER_CODE.value > '999999' ) )
	{
		alert('The fundraising code entered is out of range.\n\nPlease enter the fundraising code for your\norganization in the "fundraiser code" field');
		return false;
	}
		if (validate_numeric(document.supporterRegistrationForm.FUNDRAISER_CODE.value,6,'The fundraising code entered is invalid.\n\nPlease enter the fundraising code for your\norganization in the "fundraiser code" field')==false){	return false;}


	if (document.supporterRegistrationForm.CUST_FRST_NM.value == '')
	{
		alert('ALL blanks on this page must be filled in.\n\nPlease enter your first name in the\n"first name" field');
		return false;
	}
	
	if (document.supporterRegistrationForm.CUST_LAST_NM.value == '')
	{
		alert('ALL blanks on this page must be filled in.\n\nPlease enter your last name in the\n"Last name" field');
		return false;
	}

	if (document.supporterRegistrationForm.phone1.value == '' || document.supporterRegistrationForm.phone2.value == '' || document.supporterRegistrationForm.phone3.value == '')
	{
		alert('ALL blanks on this page must be filled in.\n\nPlease enter your phone number in \nthe "primary phone no" field');
		return false;
	}
	
	if (validate_numeric(document.supporterRegistrationForm.phone1.value,3,'The "primary phone no" value entered is invalid.\n\nPlease enter your phone number in the "primary phone no" field')==false){	return false;}

	if (validate_numeric(document.supporterRegistrationForm.phone2.value,3,'The "primary phone no" value entered is invalid.\n\nPlease enter your phone number in the "primary phone no" field')==false){	return false;}

	if (validate_numeric(document.supporterRegistrationForm.phone3.value,4,'The "primary phone no" value entered is invalid.\n\nPlease enter your phone number in the "primary phone no" field')==false){	return false;}
	
	if (document.supporterRegistrationForm.CUST_EMAIL_ADDR_TXT.value == '')
	{
		alert('ALL blanks on this page must be filled in.\n\nPlease enter your email address in\nthe"email address" field');
		return false;
	}

	if (validate_email(document.supporterRegistrationForm.CUST_EMAIL_ADDR_TXT.value,'An invalid email address was entered.\n\nPlease enter your email address in\nthe"email address" field')==false){	return false;}

	if (document.supporterRegistrationForm.CUST_EMAIL_ADDR_TXT_CONFIRM.value == '')
	{
		alert('ALL blanks on this page must be filled in.\n\nPlease confirm your email address in\nthe "confirm email address" field');
		return false;
	}

	if (document.supporterRegistrationForm.CUST_EMAIL_ADDR_TXT.value != document.supporterRegistrationForm.CUST_EMAIL_ADDR_TXT_CONFIRM.value)
	{
		alert('Your "email" and "confirm email" are different.\n\nPlease re-enter your email address in\nthe "email address" and\n"confirm email address" fields');
		return false;
	}
}



function checkformOrganization()
{
	if (fieldNotBlank(document.organizationRegistrationForm.ORG_NM.value, "Please enter the organization's name") == false) return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.ADDR_LINE_1_TXT.value, "Please enter the organization's address") == false) return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.ADDR_CITY_NM.value, "Please enter the organization's city") == false) return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.STATE_CD.value, "Please enter the organization's state") == false) return false;	
	
	if (fieldNotBlank(document.organizationRegistrationForm.ADDR_ZIP_CD.value, "Please enter the organization's zip code") == false) return false;	
	
	if (validate_numeric(document.organizationRegistrationForm.ADDR_ZIP_CD.value,5,"The zip code value entered for the organization is invalid.\n\nPlease re-enter the organization's zip code")==false)return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.ADDR_CNTRY_CD.value, "Please enter the organization's country") == false) return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.PRIMARY_FIRST_NM.value, "Please enter the primary contact's first name") == false) return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.PRIMARY_LAST_NM.value, "Please enter the primary contact's last name") == false) return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.PRIMARY_phone1.value, "Please enter the primary contact's phone number") == false) return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.PRIMARY_phone2.value, "Please enter the primary contact's phone number") == false) return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.PRIMARY_phone3.value, "Please enter the primary contact's phone number") == false) return false;
	
	if (validate_numeric(document.organizationRegistrationForm.PRIMARY_phone1.value,3,"The phone no entered for the primary contact is invalid.\n\nPlease re-enter the primary contact's phone number")==false)return false;
	
	if (validate_numeric(document.organizationRegistrationForm.PRIMARY_phone2.value,3,"The phone no entered for the primary contact is invalid.\n\nPlease re-enter the primary contact's phone number")==false)return false;
	
	if (validate_numeric(document.organizationRegistrationForm.PRIMARY_phone3.value,4,"The phone no entered for the primary contact is invalid.\n\nPlease re-enter the primary contact's phone number")==false)return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.PRIMARY_EMAIL_ADDR_TXT.value, "Please enter the primary contact's email address") == false) return false;

	if (validate_email(document.organizationRegistrationForm.PRIMARY_EMAIL_ADDR_TXT.value,"An invalid email address was entered for the primary contact.\n\nPlease re-enter the primary contact's email address")==false) return false;
	
	if (fieldNotBlank(document.organizationRegistrationForm.PRIMARY_EMAIL_ADDR_TXT_CONFIRM.value, "Please enter the primary contact's email address confirmation") == false) return false;
	
	if (document.organizationRegistrationForm.PRIMARY_EMAIL_ADDR_TXT.value != document.organizationRegistrationForm.PRIMARY_EMAIL_ADDR_TXT_CONFIRM.value)
	{
		alert("The primary contact's email and confirm email addresses are different.\n\nPlease re-enter the primary contact's email address in\nthe email address and\n confirm email address fields");
		return false;
	}

	if (document.organizationRegistrationForm.SECONDARY_phone1.value != "" ||
		document.organizationRegistrationForm.SECONDARY_phone2.value != "" ||
		document.organizationRegistrationForm.SECONDARY_phone3.value != "" )
	{
		if (validate_numeric(document.organizationRegistrationForm.SECONDARY_phone1.value,3,"The phone no entered for the secondary contact is invalid.\n\nPlease re-enter the secondary contact's phone number")==false)return false;
	
		if (validate_numeric(document.organizationRegistrationForm.SECONDARY_phone2.value,3,"The phone no entered for the secondary contact is invalid.\n\nPlease re-enter the secondary contact's phone number")==false)return false;
	
		if (validate_numeric(document.organizationRegistrationForm.SECONDARY_phone3.value,4,"The phone no entered for the secondary contact is invalid.\n\nPlease re-enter the secondary contact's phone number")==false)return false;
			
	}

	if (document.organizationRegistrationForm.SECONDARY_EMAIL_ADDR_TXT.value != "" ||
		document.organizationRegistrationForm.SECONDARY_EMAIL_ADDR_TXT_CONFIRM.value != "")
	{
		if (validate_email(document.organizationRegistrationForm.SECONDARY_EMAIL_ADDR_TXT.value,"An invalid email address was entered for the secondary contact.\n\nPlease re-enter the secondary contact's email address")==false) return false;
	
		if (fieldNotBlank(document.organizationRegistrationForm.SECONDARY_EMAIL_ADDR_TXT_CONFIRM.value, "Please enter the secondary contact's email address confirmation") == false) return false;
	
		if (document.organizationRegistrationForm.SECONDARY_EMAIL_ADDR_TXT.value != document.organizationRegistrationForm.SECONDARY_EMAIL_ADDR_TXT_CONFIRM.value)
		{
			alert("The secondary contact's email and confirm email addresses are different.\n\nPlease re-enter the secondary contact's email address in\nthe email address and confirm email address fields");
			return false;
		}
	}

}


function getParm(string,parm) 
{
    // returns value of parm from string
    var startPos = string.indexOf(parm + "=");
    if (startPos > -1) {
        startPos = startPos + parm.length + 1;
        var endPos = string.indexOf("&",startPos);
        if (endPos == -1)
            endPos = string.length;
        return unescape(string.substring(startPos,endPos));
    }
    return '';
}

function preLoadOrgID()
{
	var passed = location.search.substring(1);
	var id = getParm(passed,'id');
	var f = getParm(passed,'f4');
	
	if (id != "")
	{
		document.supporterRegistrationForm.FUNDRAISER_CODE.value = id;
		document.supporterRegistrationForm.FUNDRAISER_CODE.readOnly=true;
	}
	
	if (f != "")
	{
		document.supporterRegistrationForm.INDIVIDUAL_ACCOUNT.value = f;
		document.supporterRegistrationForm.INDIVIDUAL_ACCOUNT.readOnly=true;
		
		document.supporterRegistrationForm.accountType[0].checked = false;
		document.supporterRegistrationForm.accountType[1].checked = true;
		document.supporterRegistrationForm.accountType[0].disabled=true;
		document.supporterRegistrationForm.accountType[1].disabled=true;
	}

}

