// COPYRIGHT (C) 2004
// RNIT INTERACTIVE, INFO@RNIT.SE ALL RIGHTS RESERVED.
//
// REPRODUCTION IN PART OR IN WHOLE WITHOUT THE PRIOR WRITTEN PERMISSION
// OF THE COPYRIGHT HOLDER IS EXPRESSLY PROHIBITED.
// ____________________________________________________________________
//
// Part of: ContentaWeb 3.0
// Modified:
//
// 2004-10-26: More advanced css2 processing

var strCls
var strCls2
var strLevel
var strActiveClassName = "menulevel"

function activeMenu(cN,clsName, id, level) {
	if (strCls2) {
		if (document.layers) {
			document.layers[strCls2].className=strActiveClassName //reset the old active item
		}
		else if (document.all) {
			document.all[strCls2].className=strActiveClassName //reset the old active item
		}
		else if (document.getElementById) {
			document.getElementById(strCls2).className=strActiveClassName //reset the old active item
		}
	} else {
		getElementbyClass("submenulevelactive")
		getElementbyClass("menulevelactive")
	}
	strCls2 = id //store active item id
	this.className = clsName
	strCls = this.className
	strActiveClassName = "menulevel"+level
	
	if (level < 1) closeAllItems()
}

function closeAllItems() {
	var string
	var alltags = document.all? document.all : document.getElementsByTagName("*")
	for (i=0; i < alltags.length; i++) {
		string = alltags[i].id
		if (string.indexOf('m') == 0) {
			alltags[i].style.display = 'none'
		}
	}
}

function getElementbyClass(classname) {
	ccollect = new Array()
	var inc = 0
	var alltags = document.all? document.all : document.getElementsByTagName("*")
	
	for (i=0; i < alltags.length; i++) {
		if (alltags[i].className==classname) {
			ccollect[inc++]=alltags[i]
			alltags[i].className=strActiveClassName //reset the old active item
		}
	}
}

function block(nr) {
	var alltags = document.all? document.all : document.getElementsByTagName("*")

	if (document.layers) {
		current = (document.layers['m'+nr].display == 'none') ? 'block' : 'none';
		document.layers['m'+nr].display = current;
	}
	else if (document.all) {
		current = (document.all['m'+nr].style.display == 'none') ? 'block' : 'none';
		document.all['m'+nr].style.display = current;
	}
	else if (document.getElementById) {
		current = (document.getElementById('m'+nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById('m'+nr).style.display = current;
	}
}

function validate(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) {
		alert("E-mail seems to be wrong (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
	    alert("Your name in the e-mail meens to be wrong.")
	    return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
		  if (IPArray[i]>255) {
	      alert("Destination IP address is wrong!")
				return false
		  }
	  }
	  return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The domainname in the e-mail i wrong.")
	  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) {
		alert("Please check the e-mail again")
		return false
	}
	if (len<2) {
		var errStr="The e-mail is missing a hostname!"
		alert(errStr)
		return false
	}
}
