/* Utility functions */
function addEvent(obj, evType, fn) {
  /* adds an eventListener for browsers which support it Written by Scott Andrew */
  if (obj.addEventListener) { obj.addEventListener(evType, fn, true); return true; }
  else if (obj.attachEvent) { var r = obj.attachEvent("on"+evType, fn); return r; }
  else { return false; }
}
function element(id) {
  var e = false;
  if (document.getElementById) { e = document.getElementById(id); }
  else if (document.all) { e = document.all(id); }
  return e;
}
// login
function toPassword(objOldInput) {
	var objNewElement = document.createElement('input');
	objNewElement.setAttribute('type', 'password');
    objNewElement.setAttribute('name', objOldInput.name);
	objOldInput.parentNode.replaceChild(objNewElement, objOldInput);
	toPassword.el = objNewElement;
	setTimeout('toPassword.el.focus()',100);
	return true;
}
// menu.js
function elementContains(elmOuter, elmInner) {
	while (elmInner && elmInner != elmOuter) { elmInner = elmInner.parentNode; }
	if (elmInner == elmOuter) {return true;}
	return false;
}
function getPageXY(elm) {
	var point = { x: 0, y: 0 };
	while (elm)	{
		point.x += elm.offsetLeft;
		point.y += elm.offsetTop;
		elm = elm.offsetParent;
	}
	return point;
}
function setPageXY(elm, x, y) {
	var parentXY = {x: 0, y: 0 };
	if (elm.offsetParent) { parentXY = getPageXY(elm.offsetParent); }
	elm.style.left = (x - parentXY.x) + 'px';
	elm.style.top  = (y - parentXY.y) + 'px';
}

function cssjsmenu(menuid, menutype) {
	// make the variables
	var i, j, node, child, parent, ul, li, deept, deeper, menudiv, version, offset;
	// if the browser doesn't even support document.getElementById, give up now.
	if (!document.getElementById) { return true; }
	offset = navigator.userAgent.indexOf('Opera');
	if (offset != -1) {
		version = parseInt('0' + navigator.userAgent.substr(offset + 6), 10);
		if (version < 7) { return true; }
	}
	offset = navigator.userAgent.indexOf('MSIE');
	if (offset != -1) { if (navigator.userAgent.indexOf('Mac') != -1) { return true; }}
	// horisontal or vertical menu
	var type = (menutype == 'vertical') ? 'vertical' : 'horisontal' ;
	// set the variables
	var deept = 0, deeper = false, ul = new Array(), li = new Array();
	menudiv = document.getElementById(menuid);
	// first ul (this is the horisontal head navigation)
	ul[deept] = new Array();
	for (i = 0; i < menudiv.childNodes.length; i++) {
		node = menudiv.childNodes[i];
		if (node.nodeName.toUpperCase() == 'UL') { ul[deept][ul[deept].length] = node; }
	}
	// first ul > li (this is the horisontal head navigation)
	li[deept] = new Array();
	for (i = 0; i < ul[deept].length; i++)	{
		node = ul[deept][i];
		for (j = 0; j < node.childNodes.length; j++) {
			child = node.childNodes[j];
			if (child.nodeName.toUpperCase() == 'LI') {	li[deept][li[deept].length] = child; }
		}
	}
	// if there are li's => go deeper (this is for the vertical sub navigations)
	if (li[deept].length > 0 ) deeper = true;
	for (deept=1; deeper==true; deept++) {
		var deeper = false;
		// deeper ul
		ul[deept] = new Array();
		for (i = 0; i < li[deept-1].length; i++) {
			node = li[deept-1][i];
			for (j = 0; j < node.childNodes.length; j++) {
				child = node.childNodes[j];
				if (child.nodeName.toUpperCase() == 'UL') {
					ul[deept][ul[deept].length] = child;
					// attach hover to parent li
					parent = child.parentNode;

					if (menuid == 'generalMenu') {
						if (deept > 1) {
							// onmouseover function
							parent.onmouseover = function (e) {
								var i, child, point;
								if (this.firstChild.nodeName.toUpperCase() == 'A') {
									if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active mouse'; }
									else { this.firstChild.className = 'mouse'; }
								}
								for (i = 0; i < this.childNodes.length; i++) {
									child = this.childNodes[i];
									if (child.nodeName.toUpperCase() == 'UL') {child.style.visibility = 'visible'; }
								}
								return false;
							};

							parent.onmouseout = function (e) {
								var relatedTarget = null;
								if (e) {
									relatedTarget = e.relatedTarget;
									/*work around Gecko Linux only bug where related target is null when clicking on menu links or when right clicking and moving into a context menu.*/
									if (navigator.product == 'Gecko' && navigator.platform.indexOf('Linux') != -1 && !relatedTarget) { relatedTarget = e.originalTarget; }
								}
								else if (window.event) { relatedTarget = window.event.toElement; }
								if (elementContains(this, relatedTarget)) { return false; }
								var i, child;
								for (i = 0; i < this.childNodes.length; i++) {
									child = this.childNodes[i];
									if (child.nodeName.toUpperCase() == 'UL') {	child.style.visibility = 'hidden';}
								}
								if (this.firstChild.nodeName.toUpperCase() == 'A') {
									if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active'; }
									else { this.firstChild.className = ''; }
								}
								return false;
							};
						}
					} else {
						// onmouseover function
						parent.onmouseover = function (e) {
							var i, child, point;
							if (this.firstChild.nodeName.toUpperCase() == 'A') {
								if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active mouse'; }
								else { this.firstChild.className = 'mouse'; }
							}
							for (i = 0; i < this.childNodes.length; i++) {
								child = this.childNodes[i];
								if (child.nodeName.toUpperCase() == 'UL') {child.style.visibility = 'visible'; }
							}
							return false;
						};
						// onmouseout function
						parent.onmouseout = function (e) {
							var relatedTarget = null;
							if (e) {
								relatedTarget = e.relatedTarget;
								/*work around Gecko Linux only bug where related target is null when clicking on menu links or when right clicking and moving into a context menu.*/
								if (navigator.product == 'Gecko' && navigator.platform.indexOf('Linux') != -1 && !relatedTarget) { relatedTarget = e.originalTarget; }
							}
							else if (window.event) { relatedTarget = window.event.toElement; }
							if (elementContains(this, relatedTarget)) { return false; }
							var i, child;
							for (i = 0; i < this.childNodes.length; i++) {
								child = this.childNodes[i];
								if (child.nodeName.toUpperCase() == 'UL') {	child.style.visibility = 'hidden';}
							}
							if (this.firstChild.nodeName.toUpperCase() == 'A') {
								if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active'; }
								else { this.firstChild.className = ''; }
							}
							return false;
						};
					}
				}
			}
		}
		// deeper ul > li
		li[deept] = new Array();
		for (i = 0; i < ul[deept].length; i++) {
			node = ul[deept][i];
			for (j = 0; j < node.childNodes.length; j++) {
				child = node.childNodes[j];
				if (child.nodeName.toUpperCase() == 'LI') {	li[deept][li[deept].length] = child; }
			}
		}
		// if there are li's => go deeper and do this lus again
		if (li[deept].length != 0) { deeper = true; }
	}
	return true;
}
function email_check(email_id,err_id){
	emailRegExp = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.([a-zA-Z]){2,4})$/;
	var err_mail='Email addres incorrect!';
	if(emailRegExp.test(document.getElementById(email_id).value)){
		//alert('true');
		return true;
	}else{
		alert(err_mail);
		return false;
	}
}
/* Better(?) Image cross fader (C)2004 Patrick H. Lauke aka redux */
var	previousImage, currentImage, galleryImages, gallery, galleryId = 'photogallery'; /* general variables */
function preInit() { /* hide the image gallery list before even onload is triggered */
	if ((document.getElementById)&&(gallery=document.getElementById(galleryId))) {
		gallery.style.visibility = "hidden";
		clearTimeout(preInitTimer);
	} else { preInitTimer = setTimeout("preInit()",2); }
}
function fader(imageNumber,opacity) {
	var obj=galleryImages[imageNumber];
	if (obj.style.MozOpacity!=null) { obj.style.MozOpacity = (opacity/100) - .001; }
	else if (obj.style.opacity!=null) { obj.style.opacity = (opacity/100) - .001; }
	else if (obj.style.filter!=null) { obj.style.filter = "alpha(opacity="+opacity+")"; }
}
function fadeInit() {
	if (document.getElementById) { //preInit(); /* shouldn't be necessary, but IE can sometimes get ahead of itself and trigger fadeInit first */
		gallery=document.getElementById(galleryId);
		if(gallery){
			galleryImages = gallery.childNodes; /* get all child nodes... */
			for(i=0;i<galleryImages.length;i++) {
				galleryImages[i].style.position='absolute';
				galleryImages[i].style.top=0;
				galleryImages[i].style.zIndex=0;
				fader(i,0); /* set their opacity to transparent */
			}
			gallery.style.visibility = 'visible'; /* make the list visible again */
			currentImage=0; /* initialise a few parameters to get the cycle going */
			previousImage=galleryImages.length-1;
			opacity=100;
			fader(currentImage,100);
			window.setTimeout("crossfade(100)", 5000); /* start the whole crossfade process after a second's pause */
			return void(0);
		}
		else { return false; }
	}
	else { return false; }
}
function crossfade(opacity) {
    if (opacity < 101) {
        fader(currentImage,opacity);
        opacity += 5;
        window.setTimeout("crossfade("+opacity+")", 100);
    } else {
        fader(previousImage,0);
        previousImage=currentImage;
        currentImage+=1;
        if (currentImage>=galleryImages.length) { currentImage=0; }
        galleryImages[previousImage].style.zIndex = 0;
        galleryImages[currentImage].style.zIndex = 100;
        opacity=0;
        window.setTimeout("crossfade("+opacity+")", 5000);
    }
}