
/****************************************************************************

  This file is part of the QuakeLive.tv Content Management System

	QuakeLive.tv CMS by Steve "GreasedScotsman" Huff, 
	Copyright 2009 Steve Huff
	
	It is distributed under the terms of the 
	GNU General Public License
		
***************************************************************************/

function validateFormOnSubmit(theForm) {

	var reason = "";

	reason += validateNum(theForm.sbRecentMatchesNum);
	reason += validateNum(theForm.sbFeaturedMatchesNum);
      
	if (reason != "") {
		alert("Some fields need correction:\n\n" + reason);
		return false;
	}

	//alert("All fields are filled correctly\n");
	theForm.formValidated.value = "true";
	return true;
};

function trim(s) {
  return s.replace(/^\s+|\s+$/, '');
};

function validateEmpty(fld) {

	var error = "";
 
	if (fld.value.length == 0) {
		fld.style.background = 'Yellow'; 
		error = "The required field, "+fld.name+", has not been filled in.\n"
	}
	else {
		fld.style.background = 'white';
	}

	if (error != "") {
	    error += "\n";
	}
	return error;  
};

function validateNum(fld) {

	var error = "";
	var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

	if (fld.value == "") {
		fld.style.background = 'Yellow'; 
		error = "You didn't enter a value for "+fld.name+".\n";
	} 
	else if (isNaN(stripped)) {
	        fld.style.background = 'Yellow'; 
	        error = "The field: "+fld.name+" should be a number.\n";
	}

	if (error != "") {
	    error += "Valid format is: # \n\n";
	}
	
	return error;
};

// EOF
