Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};

// strips whitespace -- usage: this.value.fullTrim()
String.prototype.fullTrim = function(){
	theString = this.replace(/\s+/g," ");
	theString = theString.replace(/^\s*([\S\s]*\S+)\s*$/,"$1");
	return (theString==" ")?"":theString;
}

function isEmpty(inputStr) {
	if (inputStr == null || inputStr == "") {
		return true
	}
	return false
}

function div_ref(divID) {
	if( document.layers ) {
		return document.layers[divID]; }
	if( document.getElementById ) {
		return document.getElementById(divID); }
	if( document.all ) {
		return document.all[divID]; }
	if( document[divID] ) {
		return document[divID]; }

	return false;
}

function errortext(text) {
	div_ref("errorbox").innerHTML = text;
}

function precheck(form) {
	if (isEmpty(form.first.value) || isEmpty(form.last.value) || isEmpty(form.email.value) || isEmpty(form.country.value) || isEmpty(form.oper.value)) {
		errortext("Please Make Sure All Fields Are Filled In");
		return false
	} 
	return true
}

function checknumber(form) {
	if (!document.getElementById) { // skip checks if non-DOM browser; leave it to the server
    return true;
	}
	if (isEmpty(form.AREA_CODE.value)) {
				alert("Please enter your area code in the phone number field.")
				form.AREA_CODE.focus();
				return false
			}
	if (isEmpty(form.EXCHANGE.value)) {
				alert("Please enter your exchange in the phone number field.")
				form.EXCHANGE.focus();
				return false
			}
	if (isEmpty(form.NUMBER.value)) {
				alert("Please enter your number in the phone number field.")
				form.NUMBER.focus();
				return false
			}
	return true;
	
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   errortext("Invalid e-mail address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   errortext("Invalid e-mail address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    errortext("Invalid e-mail address.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    errortext("Invalid e-mail address.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    errortext("Invalid e-mail address.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    errortext("Invalid e-mail address.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    errortext("Invalid e-mail address.")
		    return false
		 }

 		 return true					
	}

function prechecks(form) {
	if (!echeck(document.crform.email.value)) {
				errortext("Invalid e-mail address.")
				return false
			}
	return true
}

function precheckcc(form) {
			
	if (isEmpty(document.crform.Name.value)) {
				errortext("Please enter your name.")
				return false
			}

	if (isEmpty(document.crform.AddressOne.value)) {
				errortext("Please enter your address.")
				return false
			}
	if (isEmpty(document.crform.Number.value)) {
				errortext("Please enter your card number.")
				return false
			}

	if (isEmpty(document.crform.CardType.value)) {
				errortext("Please enter your card type.")
				return false
			}
	if (isEmpty(document.crform.City.value)) {
				errortext("Please enter your City.")
				return false
			}			
			
	if (isEmpty(document.crform.State.value)) {
				errortext("Please enter your State.")
				return false
			}			
				if (isEmpty(document.crform.Zip.value)) {
				errortext("Please enter your Zip.")
				return false
			}	
	  	if (isEmpty(document.crform.Country.value)) {
				errortext("Please enter your Country.")
				return false
			}	
	if (isEmpty(document.crform.Exp_Month.value)) {
				errortext("Please enter your expiration month.")
				return false
			}		
		if (isEmpty(document.crform.Exp_Year.value)) {
				errortext("Please enter your expiration year.")
				return false
			}			
	return true
}




function prechecksettings(form) {
	

			
	if (isEmpty(document.crform.DJname.value)) {
				errortext("Please enter your DJname.")
				return false
			}

	if (isEmpty(document.crform.first.value)) {
				errortext("Please enter your first name.")
				return false
			}
	if (isEmpty(document.crform.last.value)) {
				errortext("Please enter your last name.")
				return false
	  	}
			
	if (!echeck(document.crform.email.value)) {
				errortext("Invalid e-mail address.")
				return false
			}


			
	if (isEmpty(document.crform.country.value)) {
				errortext("Please enter your country.")
				return false
			}

	return true
}