// External JavaScript Resource for InmoUnidas.com
// Last modified 04MAY2002 by Julian Madle

function ReadCookie (key, skips) {
	if (skips == null) {skips = 0}
	var cookie_string = '' + document . cookie;
	var cookie_array = cookie_string . split ('; ');
	for (var i = 0; i < cookie_array . length; ++ i) {
		var single_cookie = cookie_array [i] . split ('=');
		if (single_cookie . length != 2) {continue}
		var name  = unescape (single_cookie [0]);
		var value = unescape (single_cookie [1]);
		if (key == name && skips -- == 0) {return value}
		}
	return 'None';
	}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + '=' + escape (value) +
		((expires == null) ? '' : ('; expires=' + expires.toGMTString())) +
		((path == null) ? '' : ('; path=' + path)) +
		((domain == null) ? '' : ('; domain=.oneclickhr-systems.com')) +
		((secure == true) ? '; secure' : '');
	}

function cookiesEnabled() {
	if (document.layers) {document.cookie = "test=ok"; var enabled=(document.cookie)?true:false}
	else {var enabled=(navigator.cookieEnabled)?true:false}
	return enabled;
	}

function javaScriptEnabled() {
	if (navigator.appName.indexOf("Netscape")!=-1) {
		if (document.getElementById) {document.getElementById("JScheck").style.display="none"}
		else if (document.layers) {document.JScheckNN.visibility="hide"}
		}
	}

function submitCommonForm(formRef, checkName) {if (checkCommonForm(formRef, checkName)) {formRef.submit()}}

function checkCommonForm(formRef, checkName) {
	if ((checkName==true) && (formRef.ContactName.value=="")) {alert("Please enter your name");formRef.ContactName.focus();return false}
	if (emailCheck(formRef.ContactEmailAddress.value)==false) {formRef.ContactEmailAddress.focus();return false}
	return true;
	}

function emailCheck (emailStr) {
	emailStr = emailStr.toLowerCase(); // Validate email address
	var checkTLD=1; // Verify that the address ends in a two-letter country or well-known TLD.  1 means check it, 0 means don't.
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co|uk)$/; // Known TLDs that an e-mail address must end with.
	var emailPat=/^(.+)@(.+)$/; // Pattern to check if the entered e-mail address fits the user@domain format, also used to separate the username from the domain.
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; // Pattern for matching all special characters. Do not allow special characters in address. These include ( ) < > @ , ; : \ " . [ ]
	var validChars="\[^\\s" + specialChars + "\]"; //Range of characters allowed in username or domainname (really states which chars aren't allowed).
	var quotedUser="(\"[^\"]*\")"; // Pattern applies if "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't).  E.g. "jiminy cricket"@disney.com is a legal e-mail address.
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; // 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 (square brackets are required).
	var atom=validChars + '+'; // Represents an atom (basically a series of non-special characters).
	var word="(" + atom + "|" + quotedUser + ")"; // Represents one word in the typical username. Eg. in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string.
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); // Pattern describes the structure of the user
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); // Pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above.

	// 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.
		alert("The Email address you entered seems incorrect (check @ and .'s)");
		return false;
		}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Check that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {if (user.charCodeAt(i)>127) {alert("The username you entered contains invalid characters. Please try again.");return false}}
	for (i=0; i<domain.length; i++) {if (domain.charCodeAt(i)>127) {alert("The domain name you entered contains invalid characters. Please try again.");return false}}
	// See if "user" is valid
	if (user.match(userPat)==null) {alert("The username you entered doesn't seem to be valid.");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) {alert("Destination IP address is invalid!");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) {alert("The domain name does not seem to be valid.");return false}}
	// Make sure domain name ends in a known top-level domain or a two-letter word representing country (uk, nl)
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {alert("The email address you enter must end in a well-known domain or two letter " + "country.");return false}
	// Make sure there's a host name preceding the domain.
	if (len<2) {alert("This address is missing a hostname!");return false}
	// Email address is valid!
	return true;
	}
	
function setChanged(FormRef,TID) {if (FormRef.Changedlist.value.indexOf("," + TID + ",")==-1) {FormRef.Changedlist.value+=TID + ","}}

function FSfncValidateEmailAddress(FormField,TheMessage,CheckTLD) {
	// CheckTLD is optional, it accepts values of true, false, and null.
	emailStr = FormField.value.toLowerCase()
	if (CheckTLD==null) {CheckTLD=false}
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co|uk)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {alert(TheMessage); FormField.focus(); FormField.focus(); return false}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {if (user.charCodeAt(i)>127) {alert(TheMessage); return false}}
	for (i=0; i<domain.length; i++) {if (domain.charCodeAt(i)>127) {alert(TheMessage); FormField.focus(); return false}}
	if (user.match(userPat)==null) {alert(TheMessage); FormField.focus(); return false}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {for (var i=1;i<=4;i++) {if (IPArray[i]>255) {alert(TheMessage); FormField.focus(); return false}}; return true}
	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) {alert(TheMessage); FormField.focus(); return false}}
	if ((CheckTLD) && (domArr[domArr.length-1].length!=2) && (domArr[domArr.length-1].search(knownDomsPat)==-1)) {alert(TheMessage); FormField.focus(); return false}
	if (len<2) {alert(TheMessage); FormField.focus(); return false}
	return true;
	}
	
function checkAll(field){for (i = 0; i < field.length; i++)	if (field[i].checked == true){field[i].checked = false;	}else{field[i].checked = true;}}
