/*
		xhtml, css, javascript, php and db-design by:
				Johnny Mellgren
				http://www.mellgren.com
*/

function init(){
	if (document.getElementById){
		// Sets events for sub navigation "Föreställningar"
		holder = document.getElementById("subnav");
		if (!holder) return false;
		for (var i = 0; i < holder.getElementsByTagName("div").length+1; i++){
			normal = true;
			currentDiv = holder.getElementsByTagName("div")[i];
			if (!currentDiv) {
				currentDiv = document.getElementById("arrowBox");
				normal = false;
			}
			if (!currentDiv) break;
			if ((!currentDiv.id || !normal) && currentDiv.getElementsByTagName("a").length){
	         currentDiv.onmouseover = function flipColorOn(){
	            this.style.backgroundColor = "#01adad";
			if (this.style.cursor){
	            this.style.cursor = 'pointer';
	            this.style.cursor = 'hand';
			}
			
	         }
	         currentDiv.onmouseout = function flipColorOff(){
	            this.style.backgroundColor = "#009999";
	         }
	         currentDiv.onclick = function gotoUri(){
	            self.location = this.firstChild.href;
	         }
			}
		}
		// Sets events for "Detta är på gång" in boxB
		holder = document.getElementById("boxB");
		if (holder){
			for (var i = 0; i < holder.getElementsByTagName("p").length; i++){
				currentP = holder.getElementsByTagName("p")[i];
				currentP.onmouseover = function tglOn(){
					this.style.borderLeft = '4px solid #999999';
				}
				currentP.onmouseout = function tglOn(){
					this.style.borderLeft = '4px solid #cccccc';
				}
				currentP.onclick = function goToUriInCal(){
					self.location = this.getElementsByTagName("a")[0].href;
				}
			}
		}
		// Sets events for forms
		if (document.forms.length){
			for (var i = 0; i < document.forms.length; i++){
				for (var x = 0; x < document.forms[i].length; x++){
					if (document.forms[i][x].type == 'text' || document.forms[i][x].type == 'textarea'){
						document.forms[i][x].onfocus = function fieldFocus(){
							this.style.backgroundColor = "#ffffff";
						}
						document.forms[i][x].onblur = function fieldBlur(){
							this.style.backgroundColor = "#eeeeee";
						}
					}
				}
			}
		}
	}
}

window.onload = init;

function checkForm(frm){
	function validateEmail(emailAddress) {
	   atext1 = '[a-zA-Z0-9!#\\$%&\'\\*\\+\\-/=\\?\\^_`\\{|\\}~]+'
	   re = new RegExp('^\\s*(' + atext1 + '(\\.' + atext1 + ')*@' + atext1 + '(\\.' + atext1 + ')+)?\\s*$');
	   reArray = re.exec(emailAddress);
	   if (!reArray) return false;
	   if (reArray[0] != emailAddress) return false;
	   return true;
	}
	if (!frm.name.value.toString().length) {
		alert("Var god ange namn i fältet 'Ditt namn'.");
		return false;
	}
	if (frm.email.value.toString().length) {
		if (!validateEmail(frm.email.value)) {
	      alert("Den e-postadress du angivit är inte korrekt. Var god försök igen.");
	      return false;
		}
	}
	if (!frm.msg.value.toString().length) {
		alert("Du har inte skrivit något meddelande.");
		return false;
	}
	return true;
}

function popup(url, w, h){
	newwindow=window.open(url,'name','height='+(h+25)+',width='+(w+20));
	if (window.focus) {newwindow.focus()}
	return false;
}
