//----------------------------------------------------------
// Name: VALIDATE.JS
// Description: TECHSUPPORT VALIDATION
// Created By: Balrog
// Last Update: July 18, 2003
// 2003 Micronet Software Manila, Inc.
//----------------------------------------------------------

function MSM_validateForm()
{			
	with (document.download) {	
		
		name.value = trim(name.value);
		coname.value = trim(coname.value);		
		email.value = trim(email.value);				
		
		if (name.value.length==0) {
			alert("Please enter your full name.");
			name.focus();
			return;
		}
		
		if (coname.value.length==0) {
			alert("Please enter your Company's name.");
			coname.focus();
			return;
		}
		
		if (email.value.length==0) {
			alert("Please enter your email.");
			email.focus();
			return;
		}
		
		if (email.value.length>0){
			if(!MSM_isValidEmail(email.value)) {
				alert("Please submit a valid email.");
				email.focus();
				return;
			}
		}		
						
	}			
	document.download.submit();
}

function MSM_isValidEmail(email) {
	var len;
	var atSignPos;
	var dotPos;
	var chCode;
	var i;
	
	len = email.length;
	if (len < 6) return false;
	atSignPos = email.indexOf("@");
	if (atSignPos <= 0 || atSignPos == (len - 1)) return false;
	if (atSignPos != email.lastIndexOf("@")) return false;
	dotPos = email.indexOf(".");
	if (dotPos <= 0) return false;
	dotPos = email.lastIndexOf(".");
	if (atSignPos > dotPos) return false;
	if (dotPos == (len - 1)) return false;
	if (dotPos == (len - 2)) return false;
	dotPos = -1;
	for (i = 0; i < len; i++) {
		chCode = email.charCodeAt(i) 
		switch (chCode) {
			case 46: 
				if (dotPos == (i - 1)) return false;
				if (atSignPos == (i - 1)) return false;
				dotPos = i;
				break;
			case 64:
				if (dotPos == (i - 1)) return false;
				break;
			default:
				if ((chCode >= 48 && chCode <= 57) ||
				    (chCode >= 65 && chCode <= 90) ||
				    (chCode >= 97 && chCode <= 122) ||
				    (chCode == 45 || chCode == 95));
				else
					return false;
				break;
		}
	}
	return true;
}

function trim(str) {
    if (str.length > 0) while (str.indexOf(' ') == 0) str = str.substr(1);
    if (str.length > 0) while(str.lastIndexOf(' ') == str.length - 1) str = str.substr(0, str.length - 1);
    return str;
}
