
function check(f) {
	
	var i;
	var currfieldval = true;
	var formvalid = true;
	var focusfield = "";
	var tempFormName;

	var errormsg = "The following errors were found when attempting to submit the form:\n\n";

	// Loop through entire form of input fields.
	for (i = 0; i < f.elements.length; i++) {

		currfield = f.elements[i].name;
		currfield = currfield.toLowerCase();
			
		if ( 	(f.elements[i].type == "select-one" )  ) {

				currfieldval = checkoption(f.elements[i]);
				
				if ( !currfieldval ) {
					formvalid = false;
					focusfield = f.elements[i];
					tempFormName = f.elements[i].name;
					errormsg = errormsg + '  - ' + tempFormName.toUpperCase() + ' is missing or invalid. \n';
				}
			}
			
		// If input type is a "text", "textarea" or "password", do this test.
		if ( 	(f.elements[i].type == "text" )  ) {

			if ( currfield.indexOf("email") == -1){
			
				currfieldval = checktest(f.elements[i].value);
				// currfieldval = checkfield(f.elements[i]);

				if ( !currfieldval ) {
					formvalid = false;
					focusfield = f.elements[i];
					tempFormName = f.elements[i].name;
					errormsg = errormsg + '  - ' + tempFormName.toUpperCase() + ' is missing or invalid. \n';
				}
			}
		}
		///////////////////////////////////////////////
		if ( 	(f.elements[i].type == "text" ) ||
				(f.elements[i].type == "file" )) {
				
			if ( currfield.indexOf("email") != -1) {
				currfieldval = checkemail(f.elements[i]);
					
			} else if ( currfield.indexOf("displaytext") != -1) {
				currfieldval = checkfield(f.elements[i]);
			}
			
			 else if ( currfield.indexOf("postal") != -1) {
				currfieldval = isValidPostalcode(f.elements[i].value);
			}
			
			else if ( currfield.indexOf("rank") != -1) {
				if (f.elements[i].value != "") {
					currfieldval = checknumber(f.elements[i]);
				}	
			}	
			else {
				currfieldval = checkfield(f.elements[i]);
					//currfieldval = true;
				}
					if ( !currfieldval ) {
						formvalid = false;
						focusfield = f.elements[i];
						tempFormName = f.elements[i].name;
						errormsg = errormsg + '  - ' + tempFormName.toUpperCase() + ' is missing or invalid. \n';
					}
				}
				

	}

	if ( formvalid ) {
		//alert('Form is validated. This should return true instead of false.');
		return true; 		// Should return true
	} else {
		errormsg = errormsg + '  \n  - text fields special characters:  \'.#()-_@,:&';
		errormsg = errormsg + '  \n  - numeric fields do not permit special characters \n';
		alert(errormsg);
		//focusfield.focus();
		return false;
	}
}

// admin\supercategory\frm_supercategory.cfm // admin\region\frm_region.cfm
function checkcat(f) {
	
	var i;
	var currfieldval = true;
	var formvalid = true;
	var focusfield = "";
	var tempFormName;

	var errormsg = "The following errors were found when attempting to submit the form:\n\n";

	// Loop through entire form of input fields.
	for (i = 0; i < f.elements.length; i++) {

		currfield = f.elements[i].name;
		currfield = currfield.toLowerCase();
			
		// If input type is a "text", "textarea" or "password", do this test.
		if ( 	(f.elements[i].type == "text" ) || 
				//(f.elements[i].type == "textarea") ||
				(f.elements[i].type == "file") ||
				(f.elements[i].type == "password") ) {
				
				if (currfield.indexOf("rank") == -1){
					currfieldval = checktest(f.elements[i].value);
					}
				else {
					currfieldval = true;
				}
				
				if ( !currfieldval ) {
					formvalid = false;
					focusfield = f.elements[i];
					tempFormName = f.elements[i].name;
					tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
					tempFormName = tempFormName.substring(0, tempFormName.indexOf("."));
					errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
				}
			}
		///////////////////////////////////////////////
		if ( 	(f.elements[i].type == "text" ) ||
				(f.elements[i].type == "password") ) {
			
			if ( currfield.indexOf("name") != -1) {
				currfieldval = checkfield(f.elements[i]);
					
			} 
			else if ( currfield.indexOf("title") != -1) {
				currfieldval = checkfield(f.elements[i]);
					
			}
			else if ( currfield.indexOf("rank") != -1) {
				if (f.elements[i].value != "") {
					currfieldval = checknumber(f.elements[i]);
				}
					
			}else {
					currfieldval = true;
				}
					if ( !currfieldval ) {
						formvalid = false;
						focusfield = f.elements[i];
						tempFormName = f.elements[i].name;
						tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
						tempFormName = tempFormName.substring(0, tempFormName.indexOf("."));
						errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
					}
				}

	}

	if ( formvalid ) {
		//alert('Form is validated. This should return true instead of false.');
		return true; 		// Should return true
	} else {
		errormsg = errormsg + '  \n  - text fields special characters:  \'.#()-_@,:&';
		errormsg = errormsg + '  \n  - numeric fields do not permit special characters \n';
		alert(errormsg);
		focusfield.focus();
		return false;
	}
}

// admin\package\option\frm_option.cfm // admin\package\frm_package.cfm
function checkpackage(f) {
	
	var i;
	var currfieldval = true;
	var formvalid = true;
	var focusfield = "";
	var tempFormName;

	var errormsg = "The following errors were found when attempting to submit the form:\n\n";

	// Loop through entire form of input fields.
	for (i = 0; i < f.elements.length; i++) {

		currfield = f.elements[i].name;
		currfield = currfield.toLowerCase();
			
		// If input type is a "text", "textarea" or "password", do this test.
		if ( 	(f.elements[i].type == "text" ) || 
				//(f.elements[i].type == "textarea") ||
				(f.elements[i].type == "file") ||
				(f.elements[i].type == "password") ) {

				if( (currfield.indexOf("feature") == -1) &&
				    (currfield.indexOf("pricingtable") == -1) ){
					currfieldval = checktest(f.elements[i].value);
				}
				
				if ( !currfieldval ) {
					formvalid = false;
					focusfield = f.elements[i];
					tempFormName = f.elements[i].name;
					tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
					tempFormName = tempFormName.substring(0, tempFormName.indexOf("."));
					errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
				}
			}
		///////////////////////////////////////////////
		if ( 	(f.elements[i].type == "text" ) ||
				(f.elements[i].type == "password") ) {
				
			if ( currfield.indexOf("name") != -1) {
				currfieldval = checkfield(f.elements[i]);
					
			} else if ( currfield.indexOf("optioncode") != -1) {
				currfieldval = checkfield(f.elements[i]);
					
			}else {
					currfieldval = true;
				}
					if ( !currfieldval ) {
						formvalid = false;
						focusfield = f.elements[i];
						tempFormName = f.elements[i].name;
						tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
						tempFormName = tempFormName.substring(0, tempFormName.indexOf("."));
						errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
					}
				}
		
		if ( (f.elements[i].type == "select-one")) {
		
				currfield = f.elements[i].name;
				currfield = currfield.toLowerCase();
				
				if ( currfield.indexOf("categoryid") != -1) {
					currfieldval = checkoption(f.elements[i]);
					
				}
				
				else if ( currfield.indexOf("hotelid") != -1) {
					currfieldval = checkoption(f.elements[i]);
					
				}
				
				else{
					currfieldval = true
					}
				

				if ( !currfieldval ) {
					formvalid = false;
					focusfield = f.elements[i];
					tempFormName = f.elements[i].name;
					//tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
					tempFormName = tempFormName.substring(0, tempFormName.indexOf("id"));
					errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
				}
			}
				

	}

	if ( formvalid ) {
		//alert('Form is validated. This should return true instead of false.');
		return true; 		// Should return true
	} else {
		errormsg = errormsg + '  \n  - text fields special characters:  \'.#()-_@,:& ';
		errormsg = errormsg + '  \n  - numeric fields do not permit special characters \n';
		alert(errormsg);
		focusfield.focus();
		return false;
	}
}

// admin\region\frm_region.cfm
// admin\supercategory\frm_supercategory.cfm
function checkhotel(f) {

	var i;
	var currfieldval = true;
	var formvalid = true;
	var focusfield = "";
	var tempFormName;

	var errormsg = "The following errors were found when attempting to submit the form:\n\n";

	// Loop through entire form of input fields.
	for (i = 0; i < f.elements.length; i++) {
	
			currfield = f.elements[i].name;
			currfield = currfield.toLowerCase();

		// If input type is a "text", "textarea" or "password", do this test.
		if ( 	(f.elements[i].type == "text" ) || 
				//(f.elements[i].type == "textarea") ||
				(f.elements[i].type == "file") ||
				(f.elements[i].type == "password") ) {
				
				if (( currfield.indexOf("desc") == -1) &&
					( currfield.indexOf("email") == -1) &&
					( currfield.indexOf("capacity") == -1) ){
					
					currfieldval = checktest(f.elements[i].value);
					}
				else {
					currfieldval = true;
				}
					
				if ( !currfieldval ) {
					formvalid = false;
					focusfield = f.elements[i];
					tempFormName = f.elements[i].name;
					tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
					tempFormName = tempFormName.substring(0, tempFormName.indexOf("."));
					errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
				}
			}
		///////////////////////////////////////////////
		if ( 	(f.elements[i].type == "text" ) ||
				(f.elements[i].type == "password") ) {
				
			if ( currfield.indexOf("name") != -1) {
				currfieldval = checkfield(f.elements[i]);
				
				if ( currfield.indexOf("domain") != -1 && currfieldval) {
					
					currfieldval = checkdomain(f.elements[i].value);
				}
			}  
	
		 	else if ( currfield.indexOf("email") != -1) {
				if (f.elements[i].value != "") {
					currfieldval = checkemail(f.elements[i]);
				}
			}
			
			else if ( currfield.indexOf("capacity") != -1) {
				if (f.elements[i].value != "") {
					
					currfieldval = checknumber(f.elements[i]);
				}
					
			}else {
					currfieldval = true;
				}
					if ( !currfieldval ) {
						formvalid = false;
						focusfield = f.elements[i];
						tempFormName = f.elements[i].name;
						if (tempFormName.indexOf(".") != -1){
							tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
							tempFormName = tempFormName.substring(0, tempFormName.indexOf("."));
						}
						errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
					}
				}
				
			if ( (f.elements[i].type == "select-one")) {
		
				currfield = f.elements[i].name;
				currfield = currfield.toLowerCase();
				
				if (( currfield.indexOf("city") != -1) ||
				  	( currfield.indexOf("prov") != -1) ){
					currfieldval = checkoption(f.elements[i]);
					
				}
				else{
					currfieldval = true
					}
				

				if ( !currfieldval ) {
					formvalid = false;
					focusfield = f.elements[i];
					tempFormName = f.elements[i].name;
					if (tempFormName.indexOf(".") != -1){
							tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
							tempFormName = tempFormName.substring(0, tempFormName.indexOf("."));
						}
						errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
				}
			}
	}
	
	

	if ( formvalid ) {
		//alert('Form is validated. This should return true instead of false.');
		return true; 		// Should return true
	} else {
		errormsg = errormsg + '  \n  - text fields special characters:  \'.#()-_@,:& ';
		errormsg = errormsg + '  \n  - numeric fields do not permit special characters \n';
		alert(errormsg);
		focusfield.focus();
		return false;
	}
}


// This checks the form submission. This uses array indices, so order of the form fields ARE important.
// admin\project\frm_complete.cfm
function checkimage(f) {

	var i;
	var currfieldval = true;
	var formvalid = true;
	var focusfield = "";
	var tempFormName;

	var errormsg = "The following errors were found when attempting to submit the form:\n\n";

	// Loop through entire form of input fields.
	for (i = 0; i < f.elements.length; i++) {
		
		if ( (f.elements[i].type == "select-one" || f.elements[i].type == "select-multiple") ) {
		
				currfield = f.elements[i].name;
				currfield = currfield.toLowerCase();
				
				if ( currfield.indexOf("image") != -1) 	{
					currfieldval = checkoption(f.elements[i]);
				}
				else{
					currfieldval = true;
				}
					
	
					if ( !currfieldval ) {
						formvalid = false;
						focusfield = f.elements[i];
						tempFormName = f.elements[i].name;
						if (tempFormName.indexOf(".") != -1){
							tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
							tempFormName = tempFormName.substring(0, tempFormName.indexOf("."));
						}
						errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
						}
				}
				
		///////////////////////////////////////////////
		if ( (f.elements[i].type == "text" ) ||
				(f.elements[i].type == "password") ) {
				
			currfield = f.elements[i].name;
			currfield = currfield.toLowerCase();
			
			if ( currfield.indexOf("title") != -1) {
				currfieldval = checkfield(f.elements[i]);
					
			} else {
					currfieldval = true;
				}
					
	
					if ( !currfieldval ) {
						formvalid = false;
						focusfield = f.elements[i];
						tempFormName = f.elements[i].name;
						if (tempFormName.indexOf(".") != -1){
							tempFormName = tempFormName.substring(tempFormName.indexOf(".") + 1, tempFormName.length);
							tempFormName = tempFormName.substring(0, tempFormName.indexOf("."));
						}
						errormsg = errormsg + '  - ' + tempFormName + ' is missing or invalid. \n';
						}
				}
				

	}

	if ( formvalid ) {
		//alert('Form is validated. This should return true instead of false.');
		return true; 		// Should return true
	} else {
		alert(errormsg);
		focusfield.focus();
		return false;
	}
}
