function checkDate(strDate) {
	
	var monthsOf30Days = " 4 6 9 11 "
	var monthsOf31Days = " 1 3 5 7 8 10 12 "
	var startIndex = 0;
	strDate += " ";

	if(strDate == "")
		return false;
	
	//Take out any Time elements
	strDate = strDate.slice(0, strDate.indexOf(" ", 0));
		
	//Check month
	var endIndex = strDate.indexOf("/");
	if(endIndex == -1) 
		return false;	//not a valid date
	var iMonth = new Number(strDate.substring(startIndex, endIndex));
	if(isNaN(iMonth))
		return false;
	if(iMonth < 1 || iMonth > 12)
		return false;
	
	//Check Day
	startIndex = ++endIndex;
	endIndex = strDate.indexOf("/", startIndex);
	if(endIndex == -1) 
		return false;	//not a valid date
	var iDay = new Number(strDate.substring(startIndex, endIndex));
	if(isNaN(iDay))
		return false;
	if(iDay < 1)
		return false;
	
	//Check if the day is valid for months with thirty days
	if((monthsOf30Days.indexOf(" " + iMonth + " ") >= 0 ) && iDay > 30)
		return false;
	
	//Check if the day is valid for months with thirty-one days
	if((monthsOf31Days.indexOf(" " + iMonth + " ") >= 0) && iDay > 31)
		return false;
		
	//Check Year (need year to check February)
	startIndex = ++endIndex;
	var iYear = new Number(strDate.substring(startIndex));

	if(isNaN(iYear))
		return false;
	if(iYear < 1900 || iYear > 9999)
		return false;
	
	//Check for February 28 days and Leap year with 29 days
	if(iMonth == 2) { //if Feb
		if((iDay > 28) && ((iYear % 4) != 0)) // day greater than 28 not a leap year
			return false;
		if(iDay > 29 ) //if it is a leap year and the day is greater than 29 kill it
			return false;
	}
	
	return true;
}

function fillDate(objDateText) {
	
	if(!((typeof objDateText) == "undefined")) {
		var strDate = new String(objDateText.value); 
		if(strDate.indexOf("/") == -1) {
			var theDate = new Date();
			var strDate = (theDate.getMonth() + 1) + "/";
			strDate += theDate.getDate() + "/";
			var sYear = theDate.getYear();
			if(sYear < 1900)
				sYear += 1900;
			strDate += sYear;
			objDateText.value = strDate;
		}
	}
}


function checkEmail(objEmail) {

	if(objEmail.value == "") { 
		alert("An Email Address is required");
		objEmail.focus();
		return false;
	}
	
	var sEmail = objEmail.value
	if(sEmail.indexOf("@") == -1) {
		alert("A valid Email Address requires an '@' symbol");
		objEmail.focus();
		return false;
	}
	
	if(sEmail.indexOf(".") == -1) {
		alert("A valid Email Address requires a '.xxx' extention");
		objEmail.focus();
		return false;
	}
	
	if(sEmail.indexOf(" ") > -1) {
		alert("A valid Email Address should not contain spaces");
		objEmail.focus();
		return false;
	}
	return true;
}

function checkEmailStr(sEmail) {

	if(sEmail.indexOf("@") == -1) {
		alert("This Email Address requires an '@' symbol\r" + sEmail);
		return false;
	}
	
	if(sEmail.indexOf(".") == -1) {
		alert("This Email Address requires a '.xxx' extention\r" + sEmail);
		return false;
	}

	if(sEmail.indexOf(" ") > -1) {
		alert("This Email Address should not contain spaces\r" + sEmail);
		return false;
	}
	return true;
}

function checkBlank(val2check) {
	if(val2check == "")
		return false;
	return true;
}

function checkNumber(num2check){

	if(!checkBlank(num2check))
		return false;

	if(isNaN(num2check))
		return false;
	return true;
}

function verify_ccard(inNumber, type)
{// returns 0 if valid, positive number if invalid.
        total = 1*0;
        tmp = 1*0;

        number = "";

        // make sure there are only numbers in the string...
        for(i = 0; i < inNumber.length; i++)
        {
		if(inNumber.charAt(i) >= "0" && inNumber.charAt(i) <= "9")
                {
                        number = number + inNumber.charAt(i);
                }
        }

        if(number.length < 13) return 10; // too short for anything

        first = "" + number.charAt(0);
        second = "" + number.charAt(1);
        third = "" + number.charAt(2);
        firstTwo = first + second;
        firstFour = firstTwo + third + number.charAt(3);

        if(type == "MC")
        {
                if(first != "5" || second < "1" || second > "5")
                        return 11;// invalid Mastercard prefix
                if(number.length != 16)
                        return 21;
        }
        else if(type == "VISA")
        {
                if(first != "4")
                        return 12;// invalid Visa prefix
                if(number.length != 13 && number.length != 16)
                        return 22;
        }
        else if(type == "AMEX")
        {
                if(first != "3" || (second != "4" && second != "7"))
                        return 13;// invalid American Express Prefix
                if(number.length != 15) 
                        return 23;
        }
        else if(type == "DISC")
        {
                        if(firstFour != "6011")
                                return 14;// invalid prefix.
                        if(number.length != 16)
                                return 24;
        }
        else if(type == "DCCB")
        {
                if(firstTwo != "36"
                        && firstTwo != "38"
                        && (firstTwo != "30" ||
                                (third < "0" || third > "5")))
                {
                        return 15;
                }
                if(number.length != 14)
                        return 25;
        }
        else if(type == "enRoute")
        {
                if(firstFour != "2014"
                        && firstFour != "2149")
                        return 16;// invalid enRoute card
                if(number.length != 15)
                        return 26;
		return 0; // no check sum calculation needed
        }
        else if(type == "JCB")
        {
                if(firstFour != "2131"
                        && firstFour != "1800"
                        && (first != "3") )
                        return 17;
                if(number.length != 16 && first =="3")
                        return 27;
                if(number.length != 15 && first != "3")
                        return 28;
        }
        // now check the credit card suffix and length vs. the type

    
         // do the check sum
        for(loc = number.length - 2; loc >= 0; loc -= 2)
        {
                total += 1 * number.charAt(loc +1);
                tmp = number.charAt(loc) * 2;
		if(tmp > 9) total += 1;
		total += tmp%10;
        }
	if(number.length % 2 > 0)
	total += 1 * number.charAt(0);


        return (total % 10);
}