var invalidCharMsg=" contains characters which are incompatible with this system.";

function checkValidString(evalString) {
	var i=0;
	var possible="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	possible += "abcdefghijklmnopqrstuvwxyz";
	possible += "1234567890";
	possible += "~!@#$%^&*()_-=+><:.;'|,/? ";
	for (i=0; i<evalString.length; i++) {
		if (possible.indexOf(evalString.charAt(i))==-1)
			return false;
	}
	return true;
}

function checkValidCommonString(evalString) {
	var i=0;
	var possible="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	possible += "abcdefghijklmnopqrstuvwxyz";
	possible += "1234567890";
	possible += ",~!@#$%^&*()_-=+>:.;'| \r\n";

	for (i=0; i<evalString.length; i++) {
		if (possible.indexOf(evalString.charAt(i))==-1) {
			if (possible.indexOf(evalString.charAt(i))==-1) {
				return false;
			}
		}
	}
	return true;
}

function checkValidSpecialString(evalString) {
	var badstr = "";
	var flag = false;
	for(var i=0;i<evalString.length;i++)
  	{
  		var c = evalString.charCodeAt(i);
  		if((97 <= c)&&(122 >= c) || (65 <= c)&&(90 >= c)) {continue;} //These are a-z, A-Z
  		if((48 <= c)&&(57 >= c)) {continue;} //These are 0-9
		//if((224 <= c)&&(255 >= c) || (160 <= c)&&(191 >= c)) {continue;} //Netscape does not allow.
		if((123 <= c)&&(126 >= c) || (91 <= c)&&(96 >= c)) {continue;} //These are special char.
		if((32 <= c)&&(47 >= c) || (58 <= c)&&(59 >= c)) {continue;} //These are special char.
		if((61 <= c)&&(64 >= c) || c==9 || c==10 || c==13) {continue;} //These are special char.
  		if(c == 60){ //Converts the less-than char.
			evalString = evalString.replace(/</g, "&lt;"); 
			continue; 
		} 
		if(badstr.indexOf(String.fromCharCode(c))==-1)
			badstr += String.fromCharCode(c);
  	} 
	if(badstr != ""){ 
		alert("Please do not use characters "+badstr); 
		return(false);
	}
	return(evalString);
}

function disableImage() {
	button = document.getElementById("submitButton");
	alert("Button: " + button);
	button.disabled = true;
}

function TicFormValidator(form)
{
	<!-- Variables -->
	var i = 0;
	var numberOfAts = 0;
	var numberOfDots = 0;
	var index = 0;
	var emailString;
	var tempString;
		
	// First Name field
	if (form.firstName.value == "")
	{
		alert("Please enter your First Name.");
		form.firstName.focus();
		return false;
	}
	if (!checkValidCommonString(form.firstName.value)) {
		alert("First name field" + invalidCharMsg);
		form.firstName.focus();
		return false;
	}
	// Last Name field
	if (form.lastName.value == "")
	{
		alert("Please enter your Last Name.");
		form.lastName.focus();
		return false;
	}
	if (!checkValidCommonString(form.lastName.value)) {
		alert("Last name field" + invalidCharMsg);
		form.lastName.focus();
		return false;
	}

	// Company Field
	if (form.company.value == "")
	{
		alert("Please enter your Company Name.");
		form.company.focus();
		return false;
	}
	if (!checkValidCommonString(form.company.value)) {
		alert("Company name field" + invalidCharMsg);
		form.company.focus();
		return false;
	}
	
	if (!checkValidCommonString(form.phone.value)) {
		alert("Phone number" + invalidCharMsg);
		form.phone.focus();
		form.phone.select();
		return false;
	}
	
	if (form.subject.value == "") {
		alert("Please enter a subject.");
		form.subject.focus();
		return false;
	}
	var new_value = checkValidSpecialString(form.subject.value);
	if (!new_value) {
		//alert("Subject field" + invalidCharMsg);
		form.subject.focus();
		return false;
	}else { form.subject.value = new_value; } 
	
	if (form.description.value == "") {
		alert("Please enter a description.");
		form.description.focus();
		return false;
	}
	<!-- Check description length -->
	if(form.description.value.length > 2000)
	{
		alert("The description field contains " + form.description.value.length + " characters. The maximum size for this field is 2000 characters.");
		form.description.focus();
		form.description.select();
		return false;
	}
	var new_value = checkValidSpecialString(form.description.value);
	if (!new_value) {
		//alert("Description field" + invalidCharMsg);
		form.description.focus();
		return (false);
	}else { form.description.value = new_value; } 
		
	//Email Address field
	if (form.email.value == "")
	{
		alert("Please enter your Email Address.");
		form.email.focus();
		return false;
	}
	if (!checkValidString(form.email.value)) {
		alert("Email address field" + invalidCharMsg);
		form.email.focus();
		form.email.select();
		return false;
	}

	<!-- Check e-mail syntax -->
 	for (i = 0; i < form.email.value.length; ++i)
	{
		if (form.email.value.charAt(i) == '@') ++numberOfAts;
		else if (numberOfAts==1) {
			if (form.email.value.charAt(i) == '.') ++numberOfDots;
		}
		
		if (form.email.value.charAt(i) == ' ')
		{	++numberOfAts;
			++numberOfAts;
		}
	}

	if ((numberOfAts != 1) || (numberOfDots==0))
	{
		alert("You have entered an invalid email address. Please re-enter.");
		form.email.focus();
		return false;
	}

	//Phone field
	if (form.phone.value == "")
	{
		alert("Please enter your Phone Number.");
		form.phone.focus();
		return false;
	}
	if (!checkValidCommonString(form.phone.value)) {
		alert("Phone number" + invalidCharMsg);
		form.phone.focus();
		return false;
	}

	emailString = form.email.value;
	tempString = emailString.toLowerCase();
	form.email.value = tempString; 	
	
	button = document.getElementById("submitButton");
	button.disabled = true;
	
	return true;
}

function invokeSubmit(form) {
  if ( TicFormValidator(form)) {
  	form.submit();
  }
}

function selectCategory(formName, name, id) {
	document.forms[formName].elements["categoryName"].value = name;
	document.forms[formName].elements["categoryId"].value = id;
}

function showVirusWarning() {
			nolink = true;
			var theURL = '';
			w = window.open(theURL, 'Warning', 'directories=no,height=300,width=500,menubar=no,resizable=no,status=no,toolbar=no,scrollbars=no');
			w.document.open();
			w.document.writeln('<' + 'title>');
			w.document.writeln('Warning');
			w.document.writeln('<' + '/title>');
			w.document.writeln('<link rel="stylesheet" type="text/css" href="/site/css/generalON.css" />');
			w.document.writeln('<link rel="stylesheet" type="text/css" href="/site/css/support.css" />');
			w.document.writeln('<link rel="stylesheet" type="text/css" href="/site/css/fonts.css" />');
			w.document.writeln('<' + 'body onload="window.focus">');
			w.document.writeln('<div class="support bodyWrapper">');
			w.document.writeln('<' + 'form>');
			w.document.writeln('<' + 'h2>Warning</h2>');
			w.document.writeln('<br />');
			w.document.writeln('The Intusoft download can produce a false virus ');
			w.document.writeln('warning when uncompressed as defined by the following URLS:');
			w.document.writeln('<ul class="navlist">');
			w.document.writeln('<li>');
			w.document.writeln('<a href="http://isc.sans.org/diary.php?storyid=835" target="_blank">');
			w.document.writeln('http://isc.sans.org/diary.php?storyid=835');
			w.document.writeln('</a>');
			w.document.writeln('</li><li>');			
			w.document.writeln('<a href="http://www.techworld.com/security/news/index.cfm?NewsID=4768" target="_blank">');
			w.document.writeln('http://www.techworld.com/security/news/index.cfm?NewsID=4768');
			w.document.writeln('</a>');
			w.document.writeln('</li>');
			w.document.writeln('<br />');
			w.document.writeln('<' + 'input type=button value=Close onClick="window.close()">');
			w.document.writeln('<' + '/form>');
			w.document.writeln('</div>');
			w.document.close();
			if (window.moveBy) { w.moveTo(100,100); }
			w.focus();
}




