// JavaScript Document

function help(x){
	var MyWin = open(x, "displayWindow", "left=100,top=100,height=400,width=410,toolbar=no,menubar=no,statusbar=no,scrollbars=yes,resizable=yes");
}

function checkEmail(formElement) {
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(formElement.value))){		
		return false;	
	} else {
		return true;
	}
}

function checkRadio(formElement) {
	var cnt = -1;

	for (var i=formElement.length-1; i > -1; i--) {
        if (formElement[i].checked) {cnt = i; i = -1;}
    }
	
    if (cnt == -1) {
		//alert("Please select a Charity to proceed");
		return false;
	}
		
	return true;	
}

function submitGCF01(form) {
	if(!checkRadio(form.GiftCertificateTypeID)) {
		alert('Please select the Gift Certificate Type');		
		return false;
	} 
	else {
		return true;
	}
}

function submitGCF02(form) {
	if(form.GiftCertificateFirstName.value == '') {
		alert('Please enter your First Name');
		form.GiftCertificateFirstName.focus();
		return false;
	} else if(form.GiftCertificateLastName.value == '') {
		alert('Please enter your Last Name');
		form.GiftCertificateLastName.focus();
		return false;
	} else if(!checkEmail(form.GiftCertificateEmail)) {
		alert('Please enter a valid Email Address.');
		form.GiftCertificateEmail.focus();
		return false;
	} else if(form.GiftCertificateTypeID.value == 2) {
		
		if(form.GiftCertificateAddress.value == '') {
			alert('Please enter your Address');
			form.GiftCertificateAddress.focus();
			return false;
		} else if(form.GiftCertificateCity.value == '') {
			alert('Please enter your City');
			form.GiftCertificateCity.focus();
			return false;
		} else if(form.GiftCertificateState.value == '') {
			alert('Please enter your State');
			//form.GiftCertificateState.focus();
			return false;
		} else if(form.GiftCertificateZip.value == '') {
			alert('Please enter your Zip');
			//form.GiftCertificateZip.focus();
			return false;
		} else {
			return true;
		}
	}
	else {
		return true;
	}
}

function submitGCF03(form) {
	if(form.GiftCertificateBillingFirstName.value == '') {
		alert('Please enter your First Name');
		form.GiftCertificateBillingFirstName.focus();
		return false;
	} else if(form.GiftCertificateBillingLastName.value == '') {
		alert('Please enter your Last Name');
		form.GiftCertificateBillingLastName.focus();
		return false;
	} else if(!checkEmail(form.GiftCertificateBillingEmail)) {
		alert('Please enter a valid Email Address.');
		form.GiftCertificateBillingEmail.focus();
		return false;
	} else if(form.GiftCertificateBillingAddress.value == '') {
		alert('Please enter your Address');
		form.GiftCertificateBillingAddress.focus();
		return false;
	} else if(form.GiftCertificateBillingCity.value == '') {
		alert('Please enter your City');
		form.GiftCertificateBillingCity.focus();
		return false;
	} else if(form.GiftCertificateBillingState.value == '') {
		alert('Please enter your State');
		//form.GiftCertificateBillingState.focus();
		return false;
	} else if(form.GiftCertificateBillingZip.value == '') {
		alert('Please enter your Zip');
		form.GiftCertificateBillingZip.focus();
		return false;
	} else if(form.GiftCertificateBillingPhone.value == '') {
		alert('Please enter your Phone Number');
		form.GiftCertificateBillingPhone.focus();
		return false;
	} else if(!CheckCardNumber(form))	{
		return false;
	} else {
		return true;
	}	
}