//alert("OK");
function ToASCII (c){
	//	restrict input to a single character
	c = c . charAt (0);
	//	loop through all possible ASCII values
	var i;
	for (i = 0; i < 256; ++ i){
		//	convert i into a 2-digit hex string
		var h = i . toString (16);
		if (h . length == 1) h = "0" + h ;
		//	insert a % character into the string
		h = "%" + h;
		//	determine the character represented by the escape code
		h = unescape (h);
		//	if the characters match, we've found the ASCII value
		if (h == c)
			break;
	}
	return i;
}

function CheckASCII(s1,s2){
	var j ;
	for (j=0; j<s1.length; j++) {
		ascii = ToASCII(s1.charAt(j)) ;
		if ( ascii<32 || ascii>125 ) {
			alert("Invalid characters in " + s2 + " field!");
			return false;
		}
	}
	return true;
}

function CheckASCII2(s1,s2){
	var j ;
	for (j=0; j<s1.length; j++) {
		ascii = ToASCII(s1.charAt(j)) ;
		if ( (ascii<32||ascii>125) && (ascii!=10) && (ascii!=13) ) {
			alert("Invalid characters in " + s2 + " field!");
			return false;
		}
	}
	return true;
}

function CheckASCII3(s1,s2){
	var j ;
	for (j=0; j<s1.length; j++) {
		ascii = ToASCII(s1.charAt(j)) ;
		if (!( (ascii>64&&ascii<91) || (ascii>96&&ascii<123) || ascii==32 )) {
			alert("English characters in " + s2 + " field only!");
			return false;
		}
	}
	return true;
}

function ValidateForm(form){

	var S_name = form.UserName.value ;
	var S_email = form.UserEmail.value ;
	var S_subject = form.Subject.value ;
	var S_content = form.Content.value ;

	//	Check for invalid characters
	if (!CheckASCII3(S_name,"Name")){
		form.UserName.focus();
		return false ;
	}
	if (!CheckASCII(S_subject,"Subject")){
		form.Subject.focus();
		return false ;
	}
	if (!CheckASCII(S_email,"Email")){
		form.UserEmail.focus();
		return false ;
	}
	if (!CheckASCII2(S_content,"Content")){
		form.Content.focus();
		return false ;
	}

	//	Check for Empty field
	if ( S_name.length == 0 ){
		alert("Please fill in your name!");
		form.UserName.focus();
		return false ;
	}
	if ( S_email.length == 0 ){
		alert("Please fill in your email!");
		form.UserEmail.focus();
		return false ;
	}
	if ( S_subject.length == 0 ){
		alert("Please fill in the subject!");
		form.Subject.focus();
		return false ;
	}
	if ( S_content.length == 0 ){
		alert("Please fill in the content!");
		form.Content.focus();
		return false ;
	}

	//	Check email
	if (!((S_email.indexOf("@") > 0) && (S_email.indexOf(".") > 2))){
		alert("Invalid email address!");
		form.UserEmail.focus();
		return false;
	}
	if (S_email.indexOf(" ") != -1 ){
		alert("No space in email address!");
		form.UserEmail.focus();
		return false;
	}

	form.UserName.value = form.Title.value + form.UserName.value ;
	var a1=".asp";
	var a2="form";
	var a3="us";
	var a4="tact";
	var a5="con";
	document.getElementById("form1").action= a5 + a4 + "2" + a3 + a2 + a1 ;
	return true ;
}