// Validate credit card expiration date.
function validateCCExpDate(jsyear, jsmonth, vbyear, vbmonth) {
if (jsyear.value < vbyear) 
	{ 
		jsyear.focus()
		alert("Invalid expiration year.") 
		return false
	}
	else
	{   if (jsyear.value == vbyear) 
		{ 
			if (jsmonth.value < vbmonth) 
			{ 
			jsmonth.focus()
			alert("Invalid expiration month.") 
			return false
			}
			else { return true }
		}
		else { return true }
	}

} // function



// Validates length of field.  Use for credit cards and foreign zipcodes.
function validateLength(myfield, size, fieldname) {
newstring=stripNum(myfield.value)	
if (newstring.length < size) 
	{
	alert("Invalid " + fieldname + ".  " + fieldname + " must be equal to or greater than " + size + ".")
	myfield.focus()
	return false
	} 
else 
	{ 
	return true 
	}//if not newstring
}


// Validates field for all numeric.
function validateNumber(myfield, fieldname) {

if (notNull(myfield.value)) { newstring=stripNum(myfield.value) }
if (! newstring) 
	{
	alert("Invalid " + fieldname + ".  Please input proper " + fieldname + ".")
	myfield.focus()
	return false
	} 
else 
	{ 
	return true 
	}//if not newstring
}



// Strips field of "-".  Use for credit cards and phone numbers.
function stripNum(str) {
var i
var newstring=""
for (i=0; i<str.length; i++ ) {
	mychar=str.charAt(i)
	if (mychar!="-") {
	if (isDigits(mychar)) {
		newstring+=mychar
		} else {
		return false 
		}  //digits
	} // if not -
} // for 
return newstring
}


function isNumeric(callingElement, check) 
{  

	//Check to make sure that a field has a valid number
	//Use in a fields onBlur event: e.gl onBlur="isNumeric(this)"
	badNumber=0
		for (var i=0; i < callingElement.value.length; i++) 
		{
			var ch = callingElement.value.substring(i, i+1);
			if (ch!=".")
			{
			if( ch < "0" || ch>"9" || callingElement.value.length == null) 
			{
				badNumber = 1
			}
			}
		}
		if ((callingElement.value<=0) && (callingElement.value.length>0)) {
			badNumber=1
			}
		if (badNumber==1)
		{
			if (check==1) {alert("Please enter a valid number above zero.");}
			callingElement.focus();
			return false;
		}
		return true
}


function notNull(str, fieldname) {
if (str.length == 0)
{
	return false
}
else
	return true
}

function notBlank(str) {
for (var i=0; i<str.length; i++) {
if (str.charAt(i) != " ")
return true
}
return false
}

function isSize(str, size) {
if (str.length==size)
	return true
else
	return false
}

function isDigits(str) {
var i
for (i=0; i<str.length; i++) {
mychar=str.charAt(i)
if (mychar<"0" || mychar>"9")
	return false
}
return true
}

function stripNonDigits(str) {
var i
var newstring=""
for (i=0; i<str.length; i++ ) {
	mychar=str.charAt(i)
	if (isDigits(mychar))
		newstring+=mychar
	}
return newstring
}



function validateNumFields(myfield, size1, size2, fieldname, format) {

if (notNull(myfield.value)) {
	newstring=stripNonDigits(myfield.value)	
	if (isSize(newstring,size1) || isSize(newstring, size2))
		return true
}
	myfield.focus()
	myfield.select()
	alert("Invalid " + fieldname + ".  Please enter numeric values in the format of " + format + ".")
	return false
}


var emptyString=" field is blank.  Please enter a "

function validateString(myfield, s) {

if (notNull(myfield.value) && notBlank(myfield.value))
	return true
else {
	myfield.focus()
	alert("The " + s + emptyString + s)
	return false
	}
}

function validateCombo(myfield, s) {
if (myfield.options[myfield.selectedIndex].value>0) {

return true
	} else {
	myfield.focus
	alert("Please select a " + s + ".")
	return false
	
	}

}

function validateState(myfield, s) {
if (myfield.options[myfield.selectedIndex].value!=-1) {

return true
	} else {
	alert("Please select a " + s + ".")
	myfield.focus
	return false
	
	}

}

function isEmail(callingElement) 
{
	//Check to make sure that a field has a valid Email
	//Use in a fields onBlur event: e.gl onBlur="isEmail(this)"
	if (callingElement =="") 
	{
		alert("Please enter a valid e-mail address!");
	    callingElement.focus();
	    return false;         
	} 
	else 
	{
		var Temp     = callingElement
		var AtSym    = Temp.value.indexOf("@")
		var Period   = Temp.value.lastIndexOf(".")
		var Space    = Temp.value.indexOf(" ")
		var Length   = Temp.value.length - 1   // Array is from 0 to length-1

		if ((AtSym < 1) ||                     // "@" cannot be in first position
	    	(Period <= AtSym+1) ||             // Must be atleast one valid char btwn "@" and "."
		   	(Period == Length ) ||             // Must be atleast one valid char after "."
	    	(Space  != -1))                    // No empty spaces permitted
		{  
			
			alert("Please enter a valid e-mail address!");
			callingElement.focus();
			callingElement.select();
			return false;
		}   
	} return true 
}
function checkYear(myfield) {
if ((myfield.value<1900) || (myfield.value>2000)) {
	alert("Please enter a valid year.")
	myfield.focus()
	myfield.select()
	return false
} else {
	return true
}


}
function checkMonth(myfield) {
if (myfield.value>0 && myfield.value<13) {
		return true
	} else {

	alert("Invalid month.  Must be between 1 and 12")
	myfield.focus()
	myfield.select()
	return false
	} 
	
	
}

function checkDay(myfield) {
if (myfield.value>0 && myfield.value<32) {
		return true
	} else {

	alert("Invalid day. Please enter a valid day")
	myfield.focus()
	myfield.select()
	return false
	} 
}

function checkWhich(evt) {
var isNav4, isIE4
if (parseInt(navigator.appVersion.charAt(0)) >=4) {
	var isNav4=(navigator.appName=="Netscape") ? true : false
	var isIE4=(navigator.appName.indexOf("Microsoft"!=-1)) ? true : false
}
var theKey
if (isNav4) {
	theKey=evt.which
} else if (isIE4) {
	theKey=window.event.keyCode
	} //else
	

return theKey
}

function changeField(str, size, evt) {
var strKey
strKey=checkWhich(evt)
alert(strKey)
if ((str.value.length==size) && (strKey>47) && (strKey<58)) {
for (var i=0; i<form1.elements.length; i++) {
if (form1.elements[i].value==str.value) {
	if ((strKey==9) && (str.value.length==0)) {
		form1.elements[i].focus()
		break
	 }else {
	form1.elements[i+1].focus()
	break }
	 } //if
	} //for
	}
}


function open1(x) 
{
window.open(x,'text','toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,scrolling=yes,resizable=no,copyhistory=no,width=450,height=400, top=10,left=100');
}
