// JavaScript Document

function PopupImage( img ) {
//<a href="#" onclick="PopupImage('/public/PhotoPopup.aspx?pic=1&img=http://img.domain.com.au/img/223/4551195_1_FS.JPG?mod=060120-174115' )">
	if (typeof SymRealWinOpen != 'undefined') 
	{
		if (document.all)
		{ 
			window.open = SymRealWinOpen;
        } 
	}
    var win=window.open( img, 'ImageWindow', 'menubar=no,toolbar=no,status=no,width=1024,height=750,resizable=yes,scrollbars=yes' );
    win.focus();
}

//Burst out of frames
if (top!=self){ top.location = self.location }


function formatNumber(formField, fieldDisplayName) {
//From -> http://javascript.internet.com/forms/currency-format.html
	
	errMsg = "Please enter a numeric value only";
	num = formField.value.toString().replace(/\$|\,/g,'');
	//If nothing entered - return nothing so cgi forces user to enter a value
	// This stops us ending up with $0
	if(num == "" || num == " ") return ("");
	
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+
		num.substring(num.length-(4*i+3));
	// With cents
	//return (((sign)?'':'-')  + num + '.' + cents);
	
	
	//Check if we ended up with 0 - if so then tell user
	if(num == "0"){ 
		if(fieldDisplayName != ""){
			alert(errMsg+' for '+fieldDisplayName); 
		}else{
			alert(errMsg);
		}
		formField.focus();
		return("");
	}else{
		//Without cents
		return (((sign)?'':'-') + num);
	}
}


function formatCurrency(formField, fieldDisplayName) {
//From -> http://javascript.internet.com/forms/currency-format.html

	errMsg = "Please enter a numeric value only";
	num = formField.value.replace(/\$|\,/g,'');
	//If nothing entered - return nothing so cgi forces user to enter a value
	// This stops us ending up with $0
	if(num == "") return ("");
	
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	// With cents
	//return (((sign)?'':'-') + '$' + num + '.' + cents);
	
	//Check if we ended up with 0 - if so then tell user
	if(num == "0"){ 
		if(fieldDisplayName != ""){
			alert(errMsg+' for '+fieldDisplayName); 
		}else{
			alert(errMsg);
		}
		formField.focus();
		return("");
	}else{
		//Without cents
		//return (((sign)?'':'-') + num);
		return (((sign)?'':'-') + '$' + num);
	}
}



// FROM The JavaScript Source!! http://javascript.internet.com
// V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com)
function emailCheck (emailStr) {

	/* 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;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	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("Email address seems incorrect (check @ and .'s)");
		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) {
			//alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//alert("Ths domain name contains invalid characters.");
			return false;
		}
	}

	// See if "user" is valid 
	if (user.match(userPat)==null) {
		//alert("The username 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;
		}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		//alert("The address 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;
	}

	// If we've gotten this far, everything's valid!
	return true;
}

