// JavaScript Document
<!--
//alert(Date().toLocaleString());
//alert(URL().host);
//alert(URL.hostname);
//alert(window.location.host);

//--Validation Part
var path		= "";
var alertmsg	= "";
var flag		= true;
var varfocus 	= ""

function Alpha_Space(){
   if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97) || (event.keyCode ==124) || (event.keyCode ==126) ||(event.keyCode > 47 && event.keyCode < 58) ) 
   event.returnValue = false;
}

function Phone(){
   if ((event.keyCode > 32 && event.keyCode < 40)|| (event.keyCode > 41 && event.keyCode < 43)|| (event.keyCode > 43 && event.keyCode < 45) || (event.keyCode > 45 && event.keyCode < 47)||(event.keyCode > 57 && event.keyCode < 95)||(event.keyCode > 96))
   event.returnValue = false;
}

function Numeric(){
   if ((event.keyCode < 47)||(event.keyCode > 57))
   event.returnValue = false;
}

function validate(page){
	//--Name Validation-------------------------------------------------------------
	
	function validname(firstname,lable){
		if (firstname.value.length == ""){
			alertmsg = alertmsg + "\n"+"Enter the \""+lable+"\"!";
			flag = false;
			if(varfocus=="")
				varfocus = firstname
		}
		var checkOK = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ";
		var checkStr = firstname.value;
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++){
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
					if (j == checkOK.length){
						allValid = false;
						break;
					}
		}
		if (!allValid){
			alertmsg = alertmsg + "\n"+"Enter only letter characters for \""+lable+"\"!";
			flag = false;
			if(varfocus=="")
				varfocus = firstname
		}
	}

	//--Number------------------------------------------------------------------------
	function req_number(number,lable){
		var valid = "0123456789"
		var temp;
		var ok = "yes";
		for (var i=0; i<number.value.length; i++) {
			temp = "" + number.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") ok = "no";
		}
		if (ok == "no") {
			alertmsg = alertmsg + "\n"+"Enter the \""+lable+"\"!";
			flag = false;
			if(varfocus=="")
				varfocus = number
		}
	}


	//--Phone------------------------------------------------------------------------
	function validphone(phone,lable){
		if (phone.value.length ==""){
			alertmsg = alertmsg + "\n"+"Enter the \""+lable+"\"!";
			flag = false;
			if(varfocus=="")
				varfocus = phone
		}
	}

	//--E-Mail Validation--------------------------------------------------------------------
	function validemail(email,lable){
		var emailStr=email.value;
		/* The following variable tells the rest of the function whether or not
		to verify that the address ends in a two-letter country or well-known
		TLD.  1 means check it, 0 means don't. */
		var checkTLD=1;
		
		/* The following is the list of known TLDs that an e-mail address must end with. */
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		
		/* The following pattern is used to check if the entered e-mail address
		fits the user@domain format.  It also is used to separate the username
		from the domain. */
		var emailPat=/^(.+)@(.+)$/;
		
		/* The following string represents the pattern for matching all special
		characters.  We don't want to allow special characters in the address. 
		These characters include ( ) < > @ , ; : \ " . [ ] */
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		
		/* The following string represents the range of characters allowed in a 
		username or domainname.  It really states which chars aren't allowed.*/
		var validChars="\[^\\s" + specialChars + "\]";
		
		/* The following pattern applies if the "user" is a quoted string (in
		which case, there are no rules about which characters are allowed
		and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		is a legal e-mail address. */
		var quotedUser="(\"[^\"]*\")";
		
		/* The following pattern applies for domains that are IP addresses,
		rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
		e-mail address. NOTE: The square brackets are required. */
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		
		/* The following string represents an atom (basically a series of non-special characters.) */
		var atom=validChars + '+';
		
		/* The following string represents one word in the typical username.
		For example, in john.doe@somewhere.com, john and doe are words.
		Basically, a word is either an atom or quoted string. */
		var word="(" + atom + "|" + quotedUser + ")";
		
		// The following pattern describes the structure of the user
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		
		/* The following pattern describes the structure of a normal symbolic
		domain, as opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		
		/* Finally, let's start trying to figure out if the supplied address is valid. */
		
		/* Begin with the coarse pattern to simply break up user@domain into
		different pieces that are easy to analyze. */
		var matchArray=emailStr.match(emailPat);
		
		if (matchArray==null) {
			/* Too many/few @'s or something; basically, this address doesn't
			even fit the general mould of a valid e-mail address. */
			alertmsg = alertmsg + "\n"+"The \""+lable+"\" address seems incorrect (check @ and .'s)!";
			flag = false;
			if(varfocus=="")
				varfocus = emailStr
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		
		// Start by checking that only basic ASCII characters are in the strings (0-127).
		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
				alertmsg = alertmsg + "\n"+"The \""+lable+"\" username contains invalid characters!";
				flag = false;
				if(varfocus=="")
					varfocus = emailStr
				return false;
			}
		}
		
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				alertmsg = alertmsg + "\n"+"The \""+lable+"\" domain name contains invalid characters!";
				flag = false;
				if(varfocus=="")
					varfocus = emailStr
				return false;
			}
		}
		
		// See if "user" is valid 
		if (user.match(userPat)==null) {
			// user is not valid
			alertmsg = alertmsg + "\n"+"The \""+lable+"\" username doesn't seem to be valid!";
			flag = false;
			if(varfocus=="")
				varfocus = emailStr
			return false;
		}
		
		/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
			// this is an IP address
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					alertmsg = alertmsg + "\n"+"The \""+lable+"\" destination IP address is invalid!";
					flag = false;
					if(varfocus=="")
						varfocus = emailStr
					return false;
				}
			}
			return true;
		}
		
		// Domain is symbolic name.  Check if it's valid.
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
				alertmsg = alertmsg + "\n"+"The \""+lable+"\" domain name does not seem to be valid!";
				flag = false;
				if(varfocus=="")
					varfocus = emailStr
				return false;
			}
		}
		
		/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */
		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
			alertmsg = alertmsg + "\n"+"The \""+lable+"\" address must end in a well-known domain or two letter " + "country!";
			flag = false;
			if(varfocus=="")
				varfocus = emailStr
			return false;
		}
		
		// Make sure there's a host name preceding the domain.
		if (len<2) {
			alertmsg = alertmsg + "\n"+"This \""+lable+"\" address is missing a hostname!";
			flag = false;
			if(varfocus=="")
				varfocus = emailStr
			return false;
		}
	}
	
	//--Required Check Box------------
	function requiredfield(field){
		flag1 = false;
		for (i =1; i <= 8; i++){
			if (eval("field.check_"+i).checked){
				flag1 = true;
				//eval("field.check_"+i).value = 'yes';
			}else{
				//eval("field.check_"+i).value = 'no';
			}
		}
		if(!flag1){
			alertmsg = alertmsg + "\n"+"Select a business\"!";
			flag = false;
			if(varfocus=="")
				varfocus = field.check_1
		}
	}
	
	//--Required Validation-------------------------------------------------------------
	function requiredtext(name,lable){
		if (name.value==""){
			alertmsg = alertmsg + "\n"+"Enter the \""+lable+"\"!";
			flag = false;
			if(varfocus=="")
				varfocus = name
		}
	}
	
	//--Select Combo Validation--
	function requiredselect(name,lable){
		if (name.selectedIndex==0){
			if(!lable.length == 0)
				alertmsg = alertmsg + "\n"+"Select the \""+lable+"\"!"
			flag = false;
			if(varfocus=="")
				varfocus = name
			return (true);
		}
	}
	
	//--Common----
	var path = document.frm_contact;
	var alertmsg = "";
	var flag = true;
	var focusitem = "";
	
	//--Contact enquiry form
	if(page == "contact"){
		validname(path.txt_name, "name");
		requiredtext(path.txt_company, "company");
		validphone(path.txt_phone, "phone");
		validemail(path.txt_email, "email");
		requiredfield(path);
		req_number(path.txt_sites, "number of sites");
		requiredselect(path.cmd_intro, "introduced by");
		if(flag == false){
			alertmsg = "PLEASE CHECK THE FOLLOWING(S)!\n"+alertmsg;
			alert(alertmsg);
			alertmsg = '';
			flag = true;
			varfocus.focus();
			varfocus = '';
			return;
		}
		else{
			path.action="email.asp?Mode=Submit";
			path.submit();
		}
	}
/*	//--Demo request form
	else if(page == "demo"){
		validname(path.txt_name, "name");
		validname(path.txt_company, "company");
		validphone(path.txt_phone, "phone");
		validemail(path.txt_email, "email");
		requiredfield(path);
		
		if(flag == false){
			alertmsg = "PLEASE CHECK THE FOLLOWING(S)!\n"+alertmsg;
			alert(alertmsg);
			alertmsg = '';
			flag = true;
			varfocus.focus();
			varfocus = '';
			return;
		}
		else{
			path.action="email_d.asp?Mode=Submit";
			path.submit();
		}
	}
	//--Support request form
	else if(page == "support"){
		validname(path.txt_name, "name");
		requiredtext(path.txt_site, "site");
		validphone(path.txt_phone, "phone");
		
		if(flag == false){
			alertmsg = "PLEASE CHECK THE FOLLOWING(S)!\n"+alertmsg;
			alert(alertmsg);
			alertmsg = '';
			flag = true;
			varfocus.focus();
			varfocus = '';
			return;
		}
		else{
			path.action="http://www.programus.co.uk/salestar/email_s.asp?Mode=Submit";
			path.submit();
		}
	}
	//--Wish list request form
	
	else if(page == "wishlist"){
		validname(path.txt_name, "name");
		validname(path.txt_address, "address");
		validphone(path.txt_phone, "phone");
		validemail(path.txt_email, "email");
				
		if(flag == false){
			alertmsg = "PLEASE CHECK THE FOLLOWING(S)!\n"+alertmsg;
			alert(alertmsg);
			alertmsg = '';
			flag = true;
			varfocus.focus();
			varfocus = '';
			return;
		}
		else{
			path.action="http://www.programus.co.uk/salestar/email_w.asp?Mode=Submit";
			path.submit();
		}
	} */
}
//-->