/*=======================================================================================================
	Review from for Canada:
	Copyright 2006 by: 	Tom Faulkner							http://www.bbsci.com
						BBS Consultants, Inc.
						3215 Guess Rd., #105
						Durham, North Carolina 27705
						US
			
	You are welcome to use these routines on any website you develop; however, they are not public domain
	and can not be used in other way without permission.
	======================================================================================================
*/

/*========================================================================================================
	List of fields and the validation requirements
	Field:			Human Name:		Required:	Invalid/Valid Characters or strings: 	Length: Min/Max:
	==============	==============	=========== ======================================	===============
	aaaClubName		Club Name		Yes			Invalid: http://	...					3/50
	abaAddress		Club Address	No			Invalid: http:// [ ] ...				0/50
	acaCity			Club City		Yes			Invalid: http:// [ ] .					3/50
	adaProvince		Province		Yes			valid: AB BC MB NU NB NL NS ON PE QC SK YT
	aeaPhone		Phone Number	No			valid: 0 1 2 3 4 5 6 7 8 9 - ( )	
	afaWebsite		Club Website	No			valid: letters numbers . : - _ /			
	agaGPS			GPS Coordinates	No			invalid: http:// [ ] . 					10/30
	ahaType			Club Type		Yes			valid: Nude, Topless, Pasties, Lingerie,
													   Bikini, Gay
	aiaAge			Minimum Age		No			valid: numbers							2/2
	ajaBar			Bar				No			valid: Full, Beer, BYOB, None
	akaFood			Food			No			valid: Full Menu, Light Menu, Snacks, None
	alaDances		Dances			No			Valid: Table, Stage, Couch, Shower, Private, Other
	amaDancers		Dancer Gender	Yes			Valid: Male, Female, Both
	anaAudience		Audience		Yes			Valid: Everyone Welcome
													   Mixed
													   Asian
													   Black
													   Latino
													   White
													   Gay/Lesbian
													   Other
	aoaCouples		Couple Friendly	No			valid: Yes, No
	apaBikers		Biker Friendly	No			valid: Yes, No
	aqaTruckers		Trucker Parking	No			valid: Yes, No
	araRating		Your Rating		No			valid: 1, 2, 3, 4, 5
	asaComments		Your Comments	No			invalid: http:// [ ] 					0/99
	ataEmail		Your Email		Warning			

  ========================================================================================================
*/


function validateUSForm() {
	var letters ="abcdefghijklmnopqrstuvwxyz";
	var inValidStrings = "";
	var validStrings = "";
	var numbers = "0123456789";
	var special = ".";
	var emptyChr = " "; 
	var checkOK = "";
	var submitOK = true;
	
	//alert( "Start");
	// validate aaa.ClubName
	var theField = document.forms[0].aaaClubName;
	var elem = document.getElementById('lblClubName');
	elem.firstChild.nodeValue = " *"
	var validCharacters = /[^\w\s\.-]/g;
	var notValidString = /(http)|(url)|(\.{3})/ig;
	
	if ( validCharacters.test(theField.value)) {	
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR: 101 Invalid Character.";  
	  	elem.className = "error";
		}
	if ( notValidString.test(theField.value)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 102 Invalid String.";  
	  	elem.className = "error";
		}	
	if (!checkFieldLength(theField.value,3,50)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 103 Invalid Length.";  
	  	elem.className = "error";		
		}
	// end validate aaaClubName
	//alert("1");

	// validate abaAddress
	theField = document.forms[0].abaAddress;
	elem = document.getElementById('lblAddress');
	elem.firstChild.nodeValue = " ";

	var validCharacters = /[^\w\s\.\-#]/g;
	var notValidString = /(http)|(url)|(\.{3})/ig;
	
	if ( validCharacters.test(theField.value)) {	
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR: 101 Invalid Character.";  
	  	elem.className = "error";
		}
	if ( notValidString.test(theField.value)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 102 Invalid String.";  
	  	elem.className = "error";
		}
	if (!checkFieldLength(theField.value,0,50)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 103 Invalid Length.";  
	  	elem.className = "error";		
		}		
	// End validate abaAddress	
	//alert("2");

	// validate acaCity
	theField = document.forms[0].acaCity;
	elem = document.getElementById('lblCity');
	elem.firstChild.nodeValue = " ";
	var validCharacters = /[^a-zA-Z\s]/g;
	var notValidString = /(http)|(url)|(\.{3})/ig;
	
	if ( validCharacters.test(theField.value)) {	
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR: 101 Invalid Character.";  
	  	elem.className = "error";
		}
	if ( notValidString.test(theField.value)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 102 Invalid String.";  
	  	elem.className = "error";
		}	
	if (!checkFieldLength(theField.value,3,50)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 103 Invalid Length.";  
	  	elem.className = "error";		
		}
	// end Validate acaCity
	//alert("3");
	
	// validate adaState
	//document.test.test2.options[0].selected
	theField = document.forms[0].adaState;
	elem = document.getElementById('lblState')
	elem.firstChild.nodeValue = " *";
	var validCharacters = /[^a-zA-Z\s]/g;
	var notValidString = /(http)|(url)|(\.{3})/ig;
	//alert( "State 1");
	if ( validCharacters.test(theField.value)) {	
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR: 101 Invalid Character.";  
	  	elem.className = "error";
		}
	//alert( "State 2");
	if ( notValidString.test(theField.value)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 102 Invalid String.";  
	  	elem.className = "error";
		}	
	//alert( "State 3");
	if (!checkFieldLength(theField.value,2,50)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 103 Invalid Length.";  
	  	elem.className = "error";		
		}
	// end Validate State
	//alert("State OK");	


	// validate aeaPhone
	theField = document.forms[0].aeaPhone;
	elem = document.getElementById('lblPhone');
	elem.firstChild.nodeValue = " ";
	var validCharacters = /[^\d\s\.)(-]/g;
	var notValidString = /(http)|(url)|(\.{3})/ig;
	
	if ( validCharacters.test(theField.value)) {	
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR: 101 Invalid Character.";  
	  	elem.className = "error";
		}
	if ( notValidString.test(theField.value)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 102 Invalid String.";  
	  	elem.className = "error";
		}	
	if (!checkFieldLength(theField.value,0,15)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 103 Invalid Length.";  
	  	elem.className = "error";		
		}
	// end aeaPhone
	
	// validate afawebsite
	// Don't care
	// end Validate afawebsite
	
	// validate agaGPS
	theField = document.forms[0].agaGPS;
	elem = document.getElementById('lblGPS');
	elem.firstChild.nodeValue = " "
	var validCharacters = /[^NSEW\d\s\.\u00B0'"]/g;
	var notValidString = /(http)|(url)|(\.{3})/ig;
	
	if ( validCharacters.test(theField.value)) {	
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR: 101 Invalid Character.";  
	  	elem.className = "error";
		}
	if ( notValidString.test(theField.value)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 102 Invalid String.";  
	  	elem.className = "error";
		}	
	if (!checkFieldLength(theField.value,0,50)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 103 Invalid Length.";  
	  	elem.className = "error";		
		}
	// end Validate agaGPS
	//alert("GPS OK");	
	
	// validate ahaType
	theField = document.forms[0].ahaType;
	elem = document.getElementById('lblType');
	elem.firstChild.nodeValue = " *";
	//   validateField( theField, valid, required, minLength, maxLength)
	var isChecked = false;
	for (i=0;i<theField.length;i++){
		if (document.forms[0].ahaType[i].checked){
			isChecked = true;
			break;
		}
	}
	if (!isChecked) {
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR 115: You must make a selection.";  
	  	elem.className = "error";
	}
	// end Validate ahaType	
	
	// validate amaDancerGender
	theField = document.forms[0].amaDancerGender;
	elem = document.getElementById('lblGender');
	elem.firstChild.nodeValue = " *";
	//   validateField( theField, valid, required, minLength, maxLength)
	var isChecked = false;
	for (i=0;i<theField.length;i++){
		if (document.forms[0].amaDancerGender[i].checked){
			isChecked = true;
			break;
		}
	}
	if (!isChecked) {
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR 104: Please Make a Selection.";  
	  	elem.className = "error";
	}
	// end Validate amaDancerGender
	
	//validate anaAudience
	theField = document.forms[0].anaAudience;
	elem = document.getElementById('lblAudience');
	elem.firstChild.nodeValue = " *";
	//   validateField( theField, valid, required, minLength, maxLength)
	var isChecked = false;
	if (theField.selectedIndex == 0 ) {
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR 104: Please Make a Selection.";  
	  	elem.className = "error";
	}
	// end Validate amaDancerGender	
	
	// validate asaUserComments
	theField = document.forms[0].asaUserComments;
	elem = document.getElementById('lblComments');
	elem.firstChild.nodeValue = " .";
	var validCharacters = /[^\w\s\.-]/g;
	var notValidString = /(http)|(url)|(fuck)/ig;
	
	//if ( validCharacters.test(theField.value)) {	
	//	submitOK = false;
	//	elem.firstChild.nodeValue = "ERROR: 101 Invalid Character.";  
	//  	elem.className = "error";
	//	}
	if ( notValidString.test(theField.value)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 102 Invalid String.";  
	  	elem.className = "error";
		}	
	if (!checkFieldLength(theField.value,0,150)) {
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 103 Invalid Length.";  
	  	elem.className = "error";		
		}
	// end Validate araUserComments
	
	
	
	if( !submitOK) {
		var msg = "Please correct the errors indicated and re-submit.\n\n";
		msg += "I process all submissions manually.\n";
		msg += "Please help make it easy on me by submitting accurate data.\n\n";
		msg += "(P.S. If you're getting paid to post links to irrelevant websites,\n";
		msg += "save us both time and just tell them you did. Since the posts don't\n";
		msg += "go anywhere anyway, they will never know!)\n\nThank you\nThe Wize Old Man";
		alert(msg);
		}
	
	
	return (submitOK)
	
}

function checkFieldLength (theValue, minLength, maxLength) {
	var theLen = 0;
	theLen = trimAll(theValue).length;	
	if ((theLen < minLength) || (theLen > maxLength) ){
			return false;
		}
	else
		{
		return true;
		}
}




/*
function validateUSForm() {
	var letters ="abcdefghijklmnopqrstuvwxyz";
	var inValidStrings = "";
	var validStrings = "";
	var numbers = "0123456789";
	var special = ".";
	var emptyChr = " "; 
	var checkOK = "";
	var submitOK = true;
	
	// validate aaa.ClubName
	var theField = document.forms[0].aaaClubName;
	var elem = document.getElementById('lblClubName');
	elem.firstChild.nodeValue = " *"
	if (!validateField(theField,letters + numbers + "- ",true,3,50)) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR: 101 Invalid Value.";  
	  	elem.className = "error";
		}

	// check for invalid values	
	if (checkInvalidString( theField, "http:" ) || checkInvalidString( theField,"...") ) { 
		submitOK = false;
	  	elem.firstChild.nodeValue = "ERROR: 102 Invalid Value.";  
	  	elem.className = "error";
		}
	// end validate ClubName


	// validate aba.Address
	theField = document.forms[0].abaAddress;
	elem = document.getElementById('lblAddress');
	elem.firstChild.nodeValue = " ";
	// validateField( theField, valid, required, minLength, maxLength)
	if (!validateField(theField,letters + numbers + "- ",false,0,50)) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 103: Invalid Value.";  
	  	elem.className = "error";
		}

	// check for invalid values		
	if ( checkInvalidString( theField, "http://" ) || checkInvalidString( theField,"...") ) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 104: Invalid Value.";  
	  	elem.className = "error";
		}
	// end Validate Address

	// validate aca.City
	theField = document.forms[0].acaCity;
	elem = document.getElementById('lblCity');
	elem.firstChild.nodeValue = " *";
	//   validateField( theField, valid, required, minLength, maxLength)
	if (!validateField(theField,letters + "- ",true,3,50)) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 105: Invalid Value.";  
	  	elem.className = "error";
		}

	// check for invalid values		
	if ( checkInvalidString( theField, "http:" ) || checkInvalidString( theField,"...") ) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 106: Invalid Value.";  
	  	elem.className = "error";
		}
	// end Validate City


	// validate adaState
	theField = document.forms[0].adaState;
	elem = document.getElementById('lblState');
	elem.firstChild.nodeValue = " *";
	//   validateField( theField, valid, required, minLength, maxLength)
	if (!validateField(theField,letters + " ",true,2,25)) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 103: Invalid Value.";  
	  	elem.className = "error";
		}

	// check for invalid values		

	if ( checkInvalidString( theField, "http://" ) || checkInvalidString( theField,"...") ) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 104: Invalid Value.";  
	  	elem.className = "error";
		}
	if ( checkInvalidString( theField, "url" ) || checkInvalidString( theField,"href") ) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 104: Invalid Value.";  
	  	elem.className = "error";
		}

	// end Validate State


	// validate aea.Phone
	theField = document.forms[0].aeaPhone;
	elem = document.getElementById('lblPhone');
	elem.firstChild.nodeValue = "  ";
	//   validateField( theField, valid, required, minLength, maxLength)
	if (!validateField(theField,numbers + "- ()" ,false,0,15)) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 109: Invalid Value.";  
	  	elem.className = "error";
		}

	// check for invalid values		
	if ( checkInvalidString( theField, "http:" ) || checkInvalidString( theField,"...") ) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 110: Invalid Value.";  
	  	elem.className = "error";
		}
	// end Validate Phone

	// validate afawebsite
	theField = document.forms[0].afawebsite;
	elem = document.getElementById('lblWebSite');
	elem.firstChild.nodeValue = "  ";
	//   validateField( theField, valid, required, minLength, maxLength)
	if (!validateField(theField,letters + numbers + "-_.//:" ,false,0,50)) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 111: Invalid Value.";  
	  	elem.className = "error";
		}

	// check for invalid values		
	if ( checkInvalidString( theField,"...") ) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 112: Invalid Value.";  
	  	elem.className = "error";
		}
	// end Validate website
	
	// validate agaGPS
	theField = document.forms[0].agaGPS;
	elem = document.getElementById('lblGPS');
	elem.firstChild.nodeValue = " .";
	//   validateField( theField, valid, required, minLength, maxLength)
	//
	//if (!validateField(theField,"NSEW" + numbers + "-_.,'\"" + "&deg;" ,false,0,50)) {
	//	submitOK = false;
	//	//elem = document.getElementById('lblClubName');
	//  	elem.firstChild.nodeValue = "ERROR 113: Invalid Value.";  
	// 	elem.className = "error";
	//	}
	//
	// check for invalid values		
	if ( checkInvalidString( theField, "http:" ) || checkInvalidString( theField,"...") ) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 114: Invalid Value.";  
	  	elem.className = "error";
		}
	// end Validate agaGPS
	
	
	// validate ahaType
	theField = document.forms[0].ahaType;
	elem = document.getElementById('lblType');
	elem.firstChild.nodeValue = " *";
	//   validateField( theField, valid, required, minLength, maxLength)
	var isChecked = false;
	for (i=0;i<theField.length;i++){
		if (document.forms[0].ahaType[i].checked){
			isChecked = true;
			break;
		}
	}
	if (!isChecked) {
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR 115: You must make a selection.";  
	  	elem.className = "error";
	}
	// end Validate ahaType	
	
	// validate amaDancerGender
	theField = document.forms[0].amaDancerGender;
	elem = document.getElementById('lblGender');
	elem.firstChild.nodeValue = " *";
	//   validateField( theField, valid, required, minLength, maxLength)
	var isChecked = false;
	for (i=0;i<theField.length;i++){
		if (document.forms[0].amaDancerGender[i].checked){
			isChecked = true;
			break;
		}
	}
	if (!isChecked) {
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR 116: You must make a selection.";  
	  	elem.className = "error";
	}
	// end Validate amaDancerGender
	
	//validate anaAudience
	theField = document.forms[0].anaAudience;
	elem = document.getElementById('lblAudience');
	elem.firstChild.nodeValue = " *";
	//   validateField( theField, valid, required, minLength, maxLength)
	var isChecked = false;
	if (theField.selectedIndex == 0 ) {
		submitOK = false;
		elem.firstChild.nodeValue = "ERROR 117: You must make a selection.";  
	  	elem.className = "error";
	}
	// end Validate amaDancerGender	
	
	// validate araUserComments
	theField = document.forms[0].araUserComments;
	elem = document.getElementById('lblComments');
	elem.firstChild.nodeValue = " .";
	//   validateField( theField, valid, required, minLength, maxLength)
	if (!validateField(theField,letters + numbers + "- .",false,0,250)) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 118: Invalid Value.";  
	  	elem.className = "error";
		}

	// check for invalid values		
	if ( checkInvalidString( theField, "http:" ) || checkInvalidString( theField,"...") || checkInvalidString( theField,"url") ) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 119: Invalid Value.";  
	  	elem.className = "error";
		}
	if ( checkInvalidString( theField, "href" ) ) {
		submitOK = false;
		//elem = document.getElementById('lblClubName');
	  	elem.firstChild.nodeValue = "ERROR 119: Invalid Value.";  
	  	elem.className = "error";
		}		
	// end Validate araUserComments
	
	
	
	if( !submitOK) {
		var msg = "Please correct the errors indicated and re-submit.\n\n";
		msg += "I process all submissions manually.\n";
		msg += "Please help make it easy on me by submitting accurate data.\n\n";
		msg += "(P.S. If you're getting paid to post links to irrelevant websites,\n";
		msg += "save us both time and just tell them you did. Since the posts don't\n";
		msg += "go anywhere anyway, they will never know!)\n\nThank you\nThe Wize Old Man";
		alert(msg);
		}
	

	return (submitOK)
	
}

function inString (string1, testChar ) {
	// Searching string1 for string2
	var validLen = string1.length;
	var theResult = false;
	for (i=0; i <= validLen; i++) {
		if (string1.charAt(i) == testChar ) {
			theResult = true;
		}
	}
	return (theResult)
	//var theResult = string1.match(string2);
	//return (theResult == null ? false : true );
}

function validateField( theField, valid, required, minLength, maxLength) {
	var fieldLen = theField.value.length;
	var fieldStr = theField.value.toLowerCase();
	valid = valid.toLowerCase();
	//var validLen = valid.length;
	//alert( valid );
	
	if (required) {
		//var x = valid.length;
		if (fieldLen < minLength || fieldLen > maxLength ){
			return false;
		}
	}
	else {
		if (fieldLen > maxLength ) {
			return false;
		}
	}
		
	for ( i=0; i < fieldLen; i++ ) {
		foundIt = false;
		for (j=0; j < valid.length; j++){
			if ( fieldStr.charAt(i) == valid.charAt(j) ) {
				foundIt = true;
				break;
			}
		
		}
		if ( !foundIt ) { 
			return false
		}
		//testChar = valid.charAt(i);
		//if (!inString ( valid, testChar )){
		//	return false;
		//}
	}
	
	return (true);	
}


function checkInvalidString( theField, theBadString ) {
	var x = theField.value.toLowerCase().replace('...',"~~~");
	var y = theBadString.toLowerCase().replace('...','~~~');
	//alert( x + ' \n ' + y );
	//if (theField.value.toLowerCase().match( theBadString.toLowerCase() ) == null ) {
	if (x.match(y) == null ) {
		//alert("FALSE -- " + theField.value);
		return false;
	}
	else
	{ 
		return true;
	}
}

*/