<!--

function InsertAddress(strID, strUser, strDomain){
	objSpan = document.getElementById(strID);
	objSpan.innerHTML = '<a hre' + 'f="ma' + 'ilto:' + strUser + '@' + strDomain + '">' + strUser + '@' + strDomain + '</a>';
	objSpan = null;
}

function trim(varString){

	var strTemp = varString.toString();
		
	if(strTemp.indexOf(" ") >= 0){
	
		// Left Trim
		for (i=0; i < strTemp.length; i++) {
			if(strTemp.charAt(i) == " "){
				strTemp = strTemp.substring(i + 1);
			}
			else{
				break
			}
		}
		
		// Right Trim
		for (i=strTemp.length - 1;  i >= 0; i--) {
			if(strTemp.charAt(i) == " "){
				strTemp = strTemp.substring(0, i);
			}
			else{
				break
			}
		}
	}
	
	return strTemp
}

function ShowError(strFormField){
	eval(strFormField).className = "show_error";	
}

function ClearError(strFormField){
	eval(strFormField).className = "clear_error";	
}

function IsValidEmail(strEmail) {

	invalidChars = " /:,;"

	if (strEmail == "") {
		return false;
	}

	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (strEmail.indexOf(badChar,0) > -1) {
			return false;
		}
	}
		
	atPos = strEmail.indexOf("@",1)
	if (atPos == -1) {
		return false;
	}

	periodPos = strEmail.indexOf(".",atPos)
	if (periodPos == -1) {
		return false;
	}

	if (periodPos + 3 > strEmail.length) {
		return false
	}

	return true;
	
}

function TrimDomain(objField){

	var strDomain = trim(objField.value);
	var blnUpdateReqd = false;
	var	arrExtensions = new Array(".com.au", ".net.au", ".org.au", ".asn.au", ".id.au", ".co.nz", ".net.nz", ".co.uk", ".me.uk", ".org.uk", ".com", ".net", ".org", ".biz", ".info", ".co", ".tel", ".asia");
	
	var objSelect = document.getElementById("ext");

	// remove the www (if present)
	if( strDomain.indexOf('www.', 0) > -1){
		strDomain = strDomain.substr(strDomain.indexOf('www.') + 4);
		blnUpdateReqd = true;
	}
	
	for (i=0; i < arrExtensions.length; i++) {
		if (strDomain.indexOf(arrExtensions[i], 0) > -1) {
			strDomain = strDomain.substr(0, (strDomain.length - arrExtensions[i].length));
			// select the correct option
			for(j=0; j<objSelect.length; j++){
				if(objSelect.options[j].text == arrExtensions[i]){
					objSelect.selectedIndex = j;
				}
			}
			blnUpdateReqd = true;
			break;
		}
	}
	
	objSelect = null;

	if(blnUpdateReqd){
		objField.value = strDomain;
	}
	
}

function IsValidDomain(strDomain){

	/* 
	this function checks that the domain is valid ie. -
	1. is between 2 & 63 characters long
	2. does not contain a hyphen in 3rd and 4th positions
	3. contains only alphanumeric characters and hyphens
	*/
	
	strDomain = strDomain.toLowerCase();

	var domainCheck = 1;
	var reg = /(^[a-z0-9])([a-z0-9\-]{1,62})/g;
	var result = strDomain.match(reg);
	var type = typeof(result);
	
	if (!result){
		domainCheck = 0;
	}
	
	if (domainCheck == 1 && result[0] == strDomain){
		
		reg = /\-\-/;
		result = strDomain.search(reg);
		
		if (result == 2){
			domainCheck = 0;
		}
		
	} else {
		domainCheck = 0;
	}
	
	if (domainCheck == 0){
		return false;
	} else {
		return true;
	}

}

function ValidateAvailabilityForm(){
	
	var strDomain = trim(document.frmAvailability.txtDomain.value);
	var intErrors = 0;
	var strErrors = "Sorry, We could not check the availability of your domain name for the following reason(s):\n\n";
	var collObjects = document.getElementsByName("chkExtension[]");
	var blnExtensionOK = false;
	
	strDomainError = "The domain name you have entered is not valid.\n";
	strDomainError += "Please ensure that the name complies with the following rules -\n";
	strDomainError += "i. Domain names can only contain letters (A to Z), numbers(0-9) and hyphens (-)\n";
	strDomainError += "ii. Domain names must be between 2 and 63 characters long\n";
	strDomainError += "iii. Domain names must not have two hyphens together in the 3rd and 4th positions.\n\n";
	
	// check that the domain name is valid
	if(!IsValidDomain(strDomain)){
		intErrors++;
		strErrors += intErrors +") "+ strDomainError;
	}
	
	// check that at least one extension has been selected
	for(i=0; i<collObjects.length; i++){
		if(collObjects[i].checked){
			blnExtensionOK = true;
			break;
		}
	}
	
	if(!blnExtensionOK){
		intErrors++;
		strErrors += intErrors +") Please select at least one domain extension (.com.au etc.)\n";
	}
	
	if (intErrors == 0){
		return true;
	} else {
		alert(strErrors);
		return false;
	}
	
}

function ValidateDomainForm(){
	
	var strDomain = trim(document.frmAvailability.domain.value);
	var intErrors = 0;
	var strErrors = "Sorry, We could not check the availability of your domain name for the following reason(s):\n\n";
	
	strDomainError = "The domain name you have entered is not valid.\n";
	strDomainError += "Please ensure that the name complies with the following rules -\n";
	strDomainError += "i. Domain names can only contain letters (A to Z), numbers(0-9) and hyphens (-)\n";
	strDomainError += "ii. Domain names must be between 2 and 63 characters long\n";
	strDomainError += "iii. Domain names must not have two hyphens together in the 3rd and 4th positions.\n\n";
	
	// check that the domain name is valid
	if(!IsValidDomain(strDomain)){
		intErrors++;
		strErrors += intErrors +") "+ strDomainError;
	}
	
	if (intErrors == 0){
		return true;
	} else {
		alert(strErrors);
		return false;
	}
	
}

function OpenWin(strURL, strName, intWidth, intHeight){
	
	var posX = (screen.width / 2) - (intWidth / 2);
	
	window.open(strURL, strName, "height="+ intHeight +",width="+ intWidth +",left="+ posX +",top=100,toolbar=0,scrollbars=yes,resizable=yes");
}

function externalLinks() { 

	if (!document.getElementsByTagName) return;
	
	var anchors = document.getElementsByTagName("a"); 
		
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		var relvalue = anchor.getAttribute("rel");
		
		if (anchor.getAttribute("href")) {
			var external = /external/;
			var relvalue = anchor.getAttribute("rel");
			if (external.test(relvalue)) { anchor.target = "_blank"; }
		} 
	}
} 

function GoURL(strURL){
	document.location.href = strURL;
}

function IsNumeric(varValue){
	
	varValue = varValue.toString();

	if (varValue.length == 0){
		return false;
	}
	
	for (var n = 0; n < varValue.length; n++){
	
		if (isNaN(varValue.substring(n, n+1)) && (varValue.substring(n, n+1) != "."))
			return false;
		}
		
	return true;
}

function ClientLogin(){
	
		var intErrors = 0;
		var strErrors = "Sorry, your login could not be processed for the following reasons:\n\n";
	
		if(trim(document.frmClientLogin.username.value).length == 0){
			intErrors++;
			strErrors+= intErrors +") Please enter your email address.\n";
		} else if(!IsValidEmail(document.frmClientLogin.username.value)) {
			intErrors++;
			strErrors+= intErrors +") "+ document.frmClientLogin.username.value +" is not a valid email address.\n";
		}
	
		if(trim(document.frmClientLogin.password.value).length == 0){
			intErrors++;
			strErrors+= intErrors +") Please enter your password.\n";
		}
		
		if(0 == intErrors){	
			return true;
		} else {
			alert(strErrors);
			return false;
		}
	
	}
// -->
