var disappeardelay=500 ;
var delais = 0;
var ie5=document.all
var ns6=document.getElementById&&!document.all

function swap_td1(id,o)
{
	document.getElementById(id).className='menu1'+(o?'_on':'');
}
function swap_td2(id,o)
{
	document.getElementById(id).className='menu2'+(o?'_on':'');
}
function swap_li(id,o)
{
	document.getElementById('li_'+id).className='menu'+(o?'_on':'');
	document.getElementById('a_'+id).className='menu'+(o?'_on':'');
}

function trim(str)
{
   //str = str.replace(/\'/g,"\'\'");
   //str = str.replace(/\"/g,"&quot;");
   return str.replace(/^\s*|\s*$/g,"");
}

//  window width
if (parseInt(navigator.appVersion)>3) {
	//if (ns6) { winW = window.innerWidth-14;}
	//if (ie5) { var winW = document.body.offsetWidth-18; }
	var winW = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winW = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winW = document.body.clientWidth;
	}
}

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function clickreturnvalue(){
	if ((ie5||ns6) && !1) return false
	else return true
}

function dropdownmenu(obj, e, dropmenuID){
	
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	if (typeof dropmenuobj!="undefined") //hide previous menu
		dropmenuobj.style.display="none"
		clearhidemenu()
	if (ie5||ns6){
		//obj.onmouseout=delayhidemenu
		dropmenuobj=document.getElementById("ul_"+dropmenuID)
		if (trim(dropmenuobj.innerHTML)=="") return;
		dropmenuobj.onmouseover=clearhidemenu
		dropmenuobj.style.display="block"
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		var yOffset=ie5?0:0
		var xOffset=142;//obj.offsetWidth
		dropmenuobj.style.left=dropmenuobj.x+xOffset+"px"
		dropmenuobj.style.top=dropmenuobj.y+yOffset+"px"
	}
	return clickreturnvalue()
}
/*
function showsubmenu(id,o)
{	
	if (typeof subobj!="undefined") //hide previous menu
		subobj.style.display="none"
		clearsubhidemenu()
		clearhidemenu()
	subobj=$(id)
	subobj.style.display='block';
	o.style.backgroundColor="#CECECE";
	o.style.color="White";
}
*/
function delayhidemenu(){
	delayhide=setTimeout("dropmenuobj.style.display='none'",disappeardelay)
}

function clearhidemenu(){
	if (typeof delayhide!="undefined") clearTimeout(delayhide)
}

function hideall()
{
	delayhidesubmenu()
	delayhidemenu()
}

function clearallhide()
{
	if (typeof delaysubhide!="undefined") clearTimeout(delaysubhide)
	if (typeof delayhide!="undefined") clearTimeout(delayhide)
}

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=0;
	
	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("The email address is incorrect (check the @ and .)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("The user name ("+user.value+")\ncontains non-valid characters");
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
	   }
	}

	if (user.match(userPat)==null) {
		alert("The user name ("+user+")\nis not valid");
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("The destination IP address is not valid!");
				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("The domain name ("+domArr+")\nis not valid!");
			return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must finish with a known domain (ex: CA)!");
		return false;
	}

	// Make sure there's a host name preceding the domain.
	
	if (len<2) {
		alert("This address does\'t have a domain name!");
		return false;
	}
	
	return true;
}

