function $(n){if(document.getElementById) return document.getElementById(n); return null;}
function getObj(n) {if(document.getElementById) return document.getElementById(n); if(document.all) return document.all[n]; return null;}

function emailCheck (emailStr) {
	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) {return "Email seems incorrect (check @ and .'s)";return false;}
	var user=matchArray[1]; var domain=matchArray[2];
	if (user.match(userPat)==null){return "The username doesn't seem to be valid."; return false;}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {if (IPArray[i]>255) {return " destination IP address is invalid!"; return false;}}
		return true;
	}
	var domainArray=domain.match(domainPat);
	if (domainArray==null) { return " the domain name doesn't seem to be valid."; return false; }
	var atomPat=new RegExp(atom,"g"); var domArr=domain.match(atomPat); var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4)
	{ return " the address must end in a four/three-letter domain, or two letter country."; return false;}
	if (len<2) {var errStr=" this address is missing a hostname!"; return errStr; return false;}
	return 1;
}

function findPosX(obj) {var curleft=0;
	if (obj.offsetParent) {while(obj.offsetParent) {curleft+=obj.offsetLeft; obj=obj.offsetParent;}} else if (obj.x) curleft+=obj.x;
	return curleft;
}

function findPosY(obj) {var curtop=0;
	if (obj.offsetParent) {while(obj.offsetParent) {curtop+=obj.offsetTop; obj=obj.offsetParent;}} else if (obj.y) curtop+=obj.y;
	return curtop;
}

function preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.pI) d.pI=new Array();
var i,j=d.pI.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.pI[j]=new Image; d.pI[j++].src=a[i];}}
}

function hideDiv(id){var div=getObj(id);div.style.display="none";}
function showDiv(id){var div=getObj(id);div.style.display="block";}
function getWindowWidth() {if (document.all) return document.body.scrollWidth; else return document.width;}
function getWindowHeight() {if (document.all) return document.body.scrollHeight; else return document.height;}
function trim(s) {return String(s).replace(/^[\s\t]+/g, "").replace(/[\s\t]+$/g, "");}

function escape_text(text) {return String(text).replace(/\&/g, "&amp;").replace(/\'/g, "&#039;").replace(/\"/g, '&quot;').replace(/</g, "&lt;").replace(/>/g, "&gt;");}
function unescape_text(text) {return String(text).replace(/\&amp;/g, "&").replace(/\&#039;/g, "'").replace(/\&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">");}
function strip_tags(text) {return String(text).replace(/<[^<>]*>/g, "").replace(/</g, "").replace(/>/g, "");}

function navigator_ie() {
	if(typeof _NAVIGATOR_IS_IE=='undefined'){var nav=navigator.userAgent.toLowerCase();_NAVIGATOR_IS_IE=(nav.indexOf("msie")!=-1);}
	return _NAVIGATOR_IS_IE;
}

function navigator_opera() {
	if(typeof _NAVIGATOR_IS_OPERA=='undefined') {
		var nav=navigator.userAgent.toLowerCase(), ind=nav.indexOf('opera'), version=parseFloat(nav.substr(ind+6, nav.length));
		_NAVIGATOR_IS_OPERA=(ind!=-1);
	}
	return _NAVIGATOR_IS_OPERA;
}

function getOperaVersion() {
	if(typeof _NAVIGATOR_OPERA_VERSION=='undefined') {
		var nav=navigator.userAgent.toLowerCase(), ind=nav.indexOf('opera'), version=parseFloat(nav.substr(ind+6, nav.length));
		_NAVIGATOR_OPERA_VERSION=version;
	}
	return _NAVIGATOR_OPERA_VERSION;
}

function getIEVersion() {
	if(typeof _NAVIGATOR_IE_VERSION=='undefined') {
		var nav=navigator.userAgent.toLowerCase(), ind=nav.indexOf('msie'), version=parseFloat(nav.substr(ind+5, ind+9));
		_NAVIGATOR_IE_VERSION=version;
	}
	return _NAVIGATOR_IE_VERSION;
}

function isBrowserCompatible() {
	if(document.getElementById) {
		if(navigator_opera()) return (getOperaVersion()>=8.5);
		if(navigator_ie()) return (getIEVersion()>=6);
		return true;
	}
	return false;
}

function checkHttpUrl(url) {
	return (new RegExp(/^(http|https):\/\/([a-zA-Z0-9\-]{2,}\.[a-zA-Z0-9\-]{2,})/i)).test(url);
}

function getHTML(url, post, response_func, loading_func, response_func_param, loading_func_param) {
	var req = new XMLHttpRequest();
	if (req) {
		loading_func(loading_func_param);
		req.onreadystatechange = function() {
			if (req.readyState==4) {
				if(response_func_param==null) response_func(req.responseText); else response_func(req.responseText, response_func_param);
			}
			if (req.readyState!=4) loading_func(loading_func_param);
		};
		req.open('POST', url); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); req.send(post);
	}
}

function createHTMLElement(name, id, position, display, left, top, width, height, border, background) {
	var elem=document.createElement(name);
	if(id!=null) elem.id=id;
	if(display!=null) elem.style.display=display
	if(position!=null) elem.style.position=position;
	if(left!=null) elem.style.left=left+'px';
	if(top!=null) elem.style.top=top+'px';
	if(width>0) elem.style.width=width+'px';
	if(height>0) elem.style.height=height+'px';
	if(border!=null) elem.style.border=border;
	if(background!=null) elem.style.backgroundColor=background;
	return elem;
}

function getDateStr(date) {var s='';s += date.getYear(); s += date.getHours(); s += date.getMinutes(); s += date.getSeconds(); s += date.getMilliseconds();s += (Math.floor(Math.random()*1000)-1);return s;}
function ws(text) {window.status=text;}
function debug(obj) {var s='';for (i in obj){s+=i+'::'+obj[i]+"\n";}return s;}

function p(s, divN) {
	if(divN==null) divN='';var o=getObj('debugDiv'+divN);if(o!=null){o.innerHTML=s;o.className="allBrd";}
	else{var div=document.createElement('div');div.id='debugDiv'+divN;div.className="allBrd";div.innerHTML=s;document.body.appendChild(div);}
}

if (window.ActiveXObject && !window.XMLHttpRequest) {
	window.XMLHttpRequest=function() {try {return new ActiveXObject("Microsoft.XMLHTTP")} catch (e){/*p('Your Browser does not support XMLHttpRequest: '+e.toString(), '__xmlhttpIE');*/;};return null;};
}

if (!window.ActiveXObject && window.XMLHttpRequest) {window.ActiveXObject=function(type) {return new XMLHttpRequest();};}

// getPageScroll()
// Returns array with x,y page scroll values (Core code from - quirksmode.org).
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll=self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll=document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll=document.body.scrollTop;
	}

	arrayPageScroll=new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {
		xScroll=document.body.scrollWidth;
		yScroll=window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight=windowHeight;
	} else {
		pageHeight=yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth=windowWidth;
	} else {
		pageWidth=xScroll;
	}

	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}


function dd(obj) {var s=''; for (i in obj) s+=i+' : '+obj[i]+'    <br />  '; getObj('debugDiv2').innerHTML=s;}
function dh(obj) {return debugHTML(obj);}
function debugHTML(obj) {var s=''; for (i in obj) s+=i+' : '+obj[i]+'   <br />   '; return s;}