function Validator(theForm,type) {
	
	if (type=="demo" || type=="demopda") {
		if (theForm.Product.selectedIndex == 0) {
			alert("Please, select a Product in the \"Online Presentation\" field.");
			theForm.Product.focus();
			return (false);
		}
	}

	if (type=="contact" || type=="product") {
		if (theForm.Title.selectedIndex == 0) {
			alert("Please, select an option in the \"Title\" field.");
			theForm.Title.focus();
			return (false);
		}
	}

	if (type!="newsletter") {
		theForm.Contact_FirstName.value=clearInvalidChars(theForm.Contact_FirstName.value);
		if (theForm.Contact_FirstName.value == "") {
			alert("Please enter a value for the \"First Name\" field using valid characters.");
			theForm.Contact_FirstName.focus();
			return (false);
		}
	
		if (theForm.Contact_FirstName.value.length < 2) {
		alert("The \"First Name\" field must have at least 2 (valid) characters.");
		theForm.Contact_FirstName.focus();
		return (false);
		}
		
		if (theForm.Contact_FirstName.value.length > 66) {
		alert("Please enter at most 66 (valid) characters in the \"First Name\" field.");
		theForm.Contact_FirstName.focus();
		return (false);
		}

		theForm.Contact_LastName.value=clearInvalidChars(theForm.Contact_LastName.value);
		if (theForm.Contact_LastName.value == "") {
		alert("Please enter a value for the \"Last Name\" field using valid characters.");
		theForm.Contact_LastName.focus();
		return (false);
		}
		
		theForm.Contact_Organization.value=clearInvalidChars(theForm.Contact_Organization.value);
		if(theForm.Contact_Organization.value == "") {
		alert("Please, enter your Company Name.");
		theForm.Contact_Organization.focus();
		return(false);
		}
				
		if (theForm.Contact_LastName.value.length < 2) {
		alert("The \"Last Name\" field must have at least 2 (valid) characters.");
		theForm.Contact_LastName.focus();
		return (false);
		}
		
		if (theForm.Contact_LastName.value.length > 66) {
		alert("Please enter at most 66 (valid) characters in the \"Last Name\" field.");
		theForm.Contact_LastName.focus();
		return (false);
		}
	}

	if(theForm.Contact_Email) {
		var addStr=trimAll(theForm.Contact_Email.value);

	  	if(addStr=="") {
			alert("Please enter a value for the \"E-mail address\" field.");
			theForm.Contact_Email.focus();
			return(false);
		}
	
		else {

				var address=addstr.split(";");

				for (kount = 0; kount<address.length; kount++)
				{
			
					var atPos=address[kount].indexOf("@");
					if(atPos < 0) {
						alert("Please, enter a valid email address. The one provided has no \"@\" character.");
						theForm.Contact_Email.focus();
						return(false);
					}
					else {
						var locStr=address[kount].substring(0,atPos);
						var domStr=address[kount].substring(atPos+1,address[kount].length)
						var validLoc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+-/=?^_`.{|}~";
						var validDom = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.";
						var allValid = true;
						var validGroups = true;
			
						if(locStr.length > 64 || domStr.length > 64) {
							alert("Sorry, this email address is too long.\nLocal names and domain names should have at most 64 characters.");
							theForm.Contact_Email.focus();
							return(false);
						}
			
						for (i = 0; i < locStr.length; i++) {
							ch = locStr.charAt(i);
							for (j = 0;  j < validLoc.length;  j++)
							if (ch == validLoc.charAt(j))
								break;
							if (j == validLoc.length) {
								allValid = false;
								break;
							}
						}
						
						for (i = 0; i < domStr.length; i++) {
							ch = domStr.charAt(i);
							for (j = 0;  j < validDom.length;  j++)
							if (ch == validDom.charAt(j))
								break;
							if (j == validDom.length) {
								allValid = false;
								break;
							}
						}
			
						if (!allValid || locStr.length==0 || domStr.length < 2 || locStr.substring(0,1)=="." || domStr.substring(0,1)=="-" ||
						domStr.substring(domStr.length-1,domStr.length)=="-" || locStr.indexOf("..")>0 || domStr.indexOf("..")>0) {
							alert("Please, enter a valid email address for " +address[kount] );
							theForm.Contact_Email.focus();
							return(false);
						}
				}		
						
			}
			
		}
	}
	
	if (type=="contact" || type=="demo" || type=="product") {
		theForm.Contact_Address1.value=clearInvalidChars(theForm.Contact_Address1.value);
		theForm.Contact_Address2.value=clearInvalidChars(theForm.Contact_Address2.value);
		if (theForm.Contact_Country.selectedIndex < 0) {
			alert("Please, choose your \"Country\" from the options listed.");
			theForm.Contact_Country.focus();
			return (false);
		}
	}

	else {
		if (type=="contactpda" || type=="productpda" || type=="demopda") {
			if (theForm.Contact_Country.value == "") {
				alert("Please, enter your \"Country\".");
				theForm.Contact_Country.focus();
				return (false);
			}
		}
	}
	
	if (type=="demo") theForm.Contact_Position.value=clearInvalidChars(theForm.Contact_Position.value);
	if (type=="product") {
		theForm.Contact_Phone.value=clearInvalidChars(theForm.Contact_Phone.value);
		theForm.Contact_Position.value=clearInvalidChars(theForm.Contact_Position.value);
	}
	if (type=="contact" || type=="contactpda") {
		theForm.Contact_Phone.value=clearInvalidChars(theForm.Contact_Phone.value);
		theForm.Subject.value=clearInvalidChars(theForm.Subject.value);
		if (theForm.Subject.value == "") {
		alert("Please enter a value for the \"Subject\" field using valid characters.");
		theForm.Subject.focus();
		return (false);
		}
		
		if (theForm.Subject.value.length < 2) {
		alert("The \"Subject\" field must have at least 2 (valid) characters.");
		theForm.Subject.focus();
		return (false);
		}
		
		if (theForm.Subject.value.length > 66) {
		alert("Please enter at most 66 (valid) characters in the \"Subject\" field.");
		theForm.Subject.focus();
		return (false);
		}

		theForm.Message.value=clearInvalidChars(theForm.Message.value);
		if (theForm.Message.value == "") {
		alert("The \"Message\" field is empty.\nPlease, write a message using only valid characters before submitting.");
		theForm.Message.focus();
		return (false);
		}
		
		if (theForm.Message.value.length < 4) {
		alert("The message must have at least 4 (valid) characters.");
		theForm.Message.focus();
		return (false);
		}
		
		if (theForm.Message.value.length > 1500) {
		alert("Please enter at most 1500 (valid) characters in the \"Message\" field.");
		theForm.Message.focus();
		return (false);
		}

		theForm.Contact_Organization.value=clearInvalidChars(theForm.Contact_Organization.value);
		if (theForm.Contact_Organization.value != "") {
			if (theForm.Contact_Organization.value.length < 2 || theForm.Contact_Organization.value.length > 50) {
				alert("Please, leave the \"Company Name\" field empty or enter a name\nbetween 2 and 50 (valid) characters long.");
				theForm.Contact_Organization.focus();
				return (false);
			}
		}

	}
	
	else {
		theForm.Contact_Organization.value=clearInvalidChars(theForm.Contact_Organization.value);
		if (theForm.Contact_Organization.value.length < 2) {
		alert("The name of you Company must have at least 2 (valid) characters.");
		theForm.Contact_Organization.focus();
		return (false);
		}

		if (theForm.Contact_Organization.value.length > 50) {
		alert("The name of you Company must have at most 50 (valid) characters.");
		theForm.Contact_Organization.focus();
		return (false);
		}
	}

	if (type=="product" || type=="productpda") {
		theForm.Message.value=clearInvalidChars(theForm.Message.value);
		if (theForm.Message.value == "") {
			if (theForm.Demo.value=="no") {
				alert("The \"Question/Comment\" field is empty. Please write a message using only valid characters before submitting.");
			}
			else {
				alert("The \"Question/Comment\" field is empty. Please write a message using only valid characters.\n If you only need an online demo, check the box and write \"demo\" in the message before submitting.");
			}
			theForm.Message.focus();
			return (false);
		}
		
		if (theForm.Message.value.length < 4) {
		alert("The question or comment must have at least 4 (valid) characters.");
		theForm.Message.focus();
		return (false);
		}
		
		if (theForm.Message.value.length > 1500) {
		alert("Please enter at most 1500 (valid) characters in the \"Question/Comment\" field.");
		theForm.Message.focus();
		return (false);
		}
	}
	
	return (true);

}

function clearInvalidChars(strInput) {
	var invalidChars="<>#{}|";
	var resultStr="";

	strInput=trimAll(strInput);
	for (i = 0; i < strInput.length; i++){
		ch=strInput.charAt(i);
		if(invalidChars.indexOf(ch) == -1) 
			resultStr=resultStr+ch;
	}

	resultStr=resultStr.replace("http","");
	resultStr=resultStr.replace("href","");
	resultStr=resultStr.replace("www","");
	resultStr=resultStr.replace("//","");
	resultStr=resultStr.replace("src","");

	return(resultStr);
}

function trimAll(sString) {
	sString=sString.replace(/^\s+|\s+$/g,'');
	return(sString);
}
