/* JQuery NC Form Process created by Jeff Boyus D3X606 */
/* Created on 12/9/2008 to address NC usability errors on a website */
/* Modified on 12/10/2008 by Geoffrey Elliot 3J190 to make the script dynamic for all input form fields*/

/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
/*##### replaceText is a looping function that processes all text input fields #####*/

function replaceText() {
	/*** This function loops though the fields, grabs the values and sends it to the replaceChar ***/
	/*** function and then sets the value of the field with the return value of the replaceChar function ***/
	$('input:text, textarea').each( function () {
		$(this).val(replaceChar($(this).val()));
	});
}

/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
/*##### replaceChar is a function that replaces NC error text with submittable values #####*/

function replaceChar(userString) {
	/*** replace all single quotes with some value, you can replace this on server side back to single quote ***/
	userString = userString.replace(/'/g,"_");
	/*** replace all asteriks with some value, you can replace this on server side back to an asterik ***/
	userString = userString.replace(/\*/g,"_Asterik_");
	/*** replace all .exe strings with some value, you can replace this on server side back to .exe ***/
	userString = userString.replace(/.exe/g,"_exe");
	/*** replace all .bat strings with some value, you can replace this on server side back to .bat ***/
	userString = userString.replace(/.bat/g,"_bat");
	
	/*** Return value back to looping function ***/
	return userString;
}

/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
/*##### submitForm function should be called on the onClick event of the submit function. #####*/
/*##### Your form should NOT have an onSubmit function call this form. #####*/

function submitForm() {
	replaceText(); /*** Function that does the looping through fields ***/
	document.testForm.submit();  /*** Place your form NAME in here ***/
}