<!--
/*
-----------------------------------------
|     By Mattias Sjöberg 28/11-96       |
|You're welcome to use/edit this script.|
| Keep the comments and drop me a note. |
-----------------------------------------
|      mattias.sjoberg@swipnet.se       |
| www.geocities.com/SiliconValley/7116  |
|     Visit  The JavaScript Planet      |
-----------------------------------------
*/

function checkdate(aForm, popup){
//	window.onerror=null // for all other strange errors
	var err=0
	var psj=0;
	a=aForm.value
	if (a.length != 8) err=1
	b = a.substring(0, 2)// day
	c = a.substring(2, 3)// '/'
	d = a.substring(3, 5)// month
	e = a.substring(5, 6)// '/'
	f = a.substring(6, 8)// year

	//basic error checking
	if (d<1 || d>12) err = 1
	if (c != '/') err = 1
	if (b<1 || b>31) err = 1
	if (e != '/') err = 1
	if (f<0 || f>99) err = 1
	
	//advanced error checking

	// months with 30 days
	if (d==4 || d==6 || d==9 || d==11){
		if (b==31) err=1
	}

	// february, leap year
	if (d==2){
		// feb
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}

		if (b>29) err=1
		if (b==29 && ((f/4)!=parseInt(f/4))) err=1
	}

	if (err==1){
		if (popup) alert('Please enter a valid date (dd/mm/yyyy) in the ' + aForm.name + ' field.');
		return false;
	}
	else{
		return true;
	}

}

<!-- Begin
function checkemail(aForm, aFormName, popup) {
if ((aForm.value == "") || (aForm.value.indexOf('@') == -1) || (aForm.value.indexOf('.') == -1)) {
	if (popup) alert('Please enter a valid E-mail address (someone@somewhere.com) in the ' + aFormName + ' field.');
	return false;
}
else {
	return true;
	}
}

function checkrequiredtext(aForm, aFormName, popup) {
if (aForm.value == "") {
	if (popup) alert('Please enter something in the ' + aFormName + ' field.');
	return false;
}
else return true;
}

function checkall(aForm) {
	missinginfo = "";
if (aForm.name == "Domain") {
	if (!(checkrequiredtext(aForm.DomainPrefix, '', false))) {
	if (missinginfo == "") aForm.DomainPrefix.select();
	missinginfo += "\n     - Domain Name";
	}
}
if (aForm.name == "frmlogin") {
	if (!(checkrequiredtext(this.document.forms.frmlogin.UserID, '', false))) {
	if (missinginfo == "") this.document.forms.frmlogin.UserID.focus();
	missinginfo += "\n     - User ID";
	}
	if (!(checkrequiredtext(this.document.forms.frmlogin.Password, '', false))) {
	if (missinginfo == "") this.document.forms.frmlogin.Password.focus();
	missinginfo += "\n     - Password";
	}
}
if (aForm.name == "step1") {
	if (!(checkrequiredtext(this.document.forms.domain.DomainPrefix, '', false))) {
	if (missinginfo == "") this.document.forms.domain.DomainPrefix.select();
	missinginfo += "\n     - Domain Name";
	}
}

if (aForm.name == "step2" || aForm.name == "frmUpdateCustomer") {
	if (!(checkrequiredtext(aForm.CustomerContactName, '', false))) {
	if (missinginfo == "") aForm.CustomerContactName.select();
	missinginfo += "\n     - Your Name";
	}
	if (!(checkemail(aForm.CustomerEMail, '', false))) {
	if (missinginfo == "") aForm.CustomerEMail.select();
	missinginfo += "\n     - E-Mail";
	}
}

if (aForm.name == "step3") {
	if (!(checkrequiredtext(aForm.CardHolderName, '', false))) {
	if (missinginfo == "") aForm.CardHolderName.focus();
	missinginfo += "\n     - Card Holder's Name";
	}

	// aForm.PaymentMedia[0] is the Cheque RADIO control
	// aForm.PaymentMedia[1] is the Credit Card RADIO control
	if ((!(checkrequiredtext(aForm.CardType, '', false))) && (aForm.PaymentMedia[1].checked)) {
	if (missinginfo == "") aForm.CardType.focus();
	missinginfo += "\n     - Card Type";
	}
	
	if ((!(checkrequiredtext(aForm.CardNumber, '', false))) && (aForm.PaymentMedia[1].checked)) {
	if (missinginfo == "") aForm.CardNumber.focus();
	missinginfo += "\n     - Card Number";
	}

	if ((!(checkrequiredtext(aForm.CardIssueNum, '', false))) && (aForm.PaymentMedia[1].checked) && (aForm.CardType.value == "SWITCH")) {
	if (missinginfo == "") aForm.CardIssueNum.focus();
	missinginfo += "\n     - Card Issue Number (switch only)";
	}

	if (((!(checkrequiredtext(aForm.CardValidFromDateMonth, '', false))) || (!(checkrequiredtext(aForm.CardValidFromDateYear, '', false)))) && (aForm.PaymentMedia[1].checked)) {
	if (missinginfo == "") aForm.CardValidFromDateMonth.focus();
	missinginfo += "\n     - Card Valid From Date";
	}

	if (((!(checkrequiredtext(aForm.CardExpiryDateMonth, '', false))) || (!(checkrequiredtext(aForm.CardExpiryDateYear, '', false)))) && (aForm.PaymentMedia[1].checked)) {
	if (missinginfo == "") aForm.CardExpiryDateMonth.focus();
	missinginfo += "\n     - Card Expiry Date";
	}

	if (((aForm.CardExpiryDateYear.value == aForm.CardValidFromDateYear.value) && (aForm.CardExpiryDateMonth.value <= aForm.CardValidFromDateMonth.value)) && ( (checkrequiredtext(aForm.CardValidFromDateMonth, '', false)) && (checkrequiredtext(aForm.CardValidFromDateYear, '', false)) && (checkrequiredtext(aForm.CardExpiryDateMonth, '', false)) && (checkrequiredtext(aForm.CardExpiryDateYear, '', false))   ) ) {
	if (missinginfo == "") aForm.CardExpiryDateMonth.focus();
	missinginfo += "\n     - Card Expiry Date earlier than Valid From Date!";
	}

}

if (missinginfo != "") {
	missinginfo = "____________________________________\n" + "You failed to correctly fill in your:\n" + missinginfo + "\n____________________________________\n" +	"Please re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;		
}
//-->
