window.onload=function() {
	sfHover()
	setTarget()
	subscribeValidation()
	setConfirm()
	if(document.forms["mailForm"]) {
		document.forms["mailForm"].onsubmit=function() {
			validate();
			return returnValue
		}
	}
}
function confirm_entry() {
}

function setTarget() {
    if (!document.getElementsByTagName) {
      return null;
    }

	var links = document.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++) {
		if (links[i].getAttribute("href")) {
			var theHref =  links[i].getAttribute("href")
			if (links[i].getAttribute("rel")) {
				var theRel =  links[i].getAttribute("rel")
				if(theRel == "external") {
					links[i].target = "_blank";
					if(links[i].title){
						theTitleText = links[i].title;
						links[i].title = theTitleText + "  - Nytt fönster/New window";
					}
					else {
						links[i].title = "Nytt fönster/New window";
					}
				}
				else if(theRel == "example") {
					links[i].onclick = function() {
						theUrl=this.href;
						rExp = /default.asp/gi;
						popupUrl = "popup.asp"
						theUrl = theUrl.replace(rExp, popupUrl)
						var exampleWin = window.open(theUrl,'exampleWin','width=483,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes');
						exampleWin.focus()
						return false;
					}
					if(links[i].title){
						theTitleText = links[i].title;
						links[i].title = theTitleText + "  - Popup";
					}
					else {
						links[i].title = "Popup";
					}
				}
				else if(theRel == "popup") {
					links[i].onclick = function() {
						theUrl=this.href;
						var exampleWin = window.open(theUrl,'exampleWin','width=483,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes');
						exampleWin.focus()
						return false;
					}
					if(links[i].title){
						theTitleText = links[i].title;
						links[i].title = theTitleText + "  - Popup";
					}
					else {
						links[i].title = "Popup";
					}
				}
			}
		}
	}
}
function setConfirm() {
    if (!document.getElementsByTagName) {
      return null;
    }
	var links = document.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++) {
		if (links[i].className == "removeButton") {
			links[i].onclick = function() {
				inputBox=confirm("Vill du verkligen ta bort den här varan?");
				if (inputBox==true) { 
					return true;
				}
				else {
					return false
				}
			}
		}
	}
}

function sfHover() {
	if(!document.getElementById("nav")) {
		return
	}
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			if (!this.className) {
				this.className="sfhover";
			} else {
				this.className+=" sfhover";
			}
		}
		sfEls[i].onmouseout=function() {
			if (this.className == "sfhover") {
				this.className = "";
			} else {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

function fixNav() {
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		theHeight = document.getElementById("nav").offsetHeight;
		theDiv = document.createElement("div");
		document.getElementById("wrap").appendChild(theDiv);
		theDiv.style.position = "absolute";
		theDiv.style.top = "42px";
		theDiv.style.left = document.getElementById("nav").offsetLeft + "px";
		theDiv.style.width = "128px";
		theDiv.style.height = theHeight + "px";
		theDiv.style.zIndex = 8;
		theDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/point.images/nav.bkg.png', sizingMethod='scale')";
	
		fixSubnav()
	}
}
function fixSubnav() {
	theNavs = document.getElementById("nav").getElementsByTagName("div")
	for(var i=0;i<theNavs.length;i++) {
		if(theNavs[i].className == "subnav") {
			theHeight = theNavs[i].getElementsByTagName("ul")[0].offsetHeight +4;
			div1 = document.createElement("div");
			theNavs[i].appendChild(div1);
			div2 = document.createElement("div");
			theNavs[i].appendChild(div2);
			div1.style.position = "absolute";
			div1.style.top = "0";
			div1.style.left = "0";
			div1.style.width = "129px";
			div1.style.height = theHeight + "px";
			div1.style.zIndex = 8;
			div1.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.point65.se/point.images/nav.sub.bkg.png', sizingMethod='crop')";
			div2.style.position = "absolute";
			div2.style.top = theHeight + "px";
			div2.style.left = "0";
			div2.style.width = "129px";
			div2.style.height = "8px";
			div2.style.zIndex = 8;
			div2.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.point65.se/point.images/nav.sub.shadow.png', sizingMethod='crop')";
		}
	}
}

function subscribeValidation() {
	if(document.forms["form1"]) {
		document.forms["form1"].Username.focus();
		document.forms["form1"].onsubmit = function() {
			return isValidate();
		}
	}
}


function isValidate() {
	var sUsername = document.forms["form1"]["Username"].value;
	var sEmail    = document.forms["form1"]["Email"].value;

	if (sUsername.length != 0) {
		if (sEmail.length != 0) {
			if (!sEmail.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.biz)|(\.name)|(\.aero)|(\.coop)|(\.int)|(\.museum)|(\.pro)|(\..{2,2}))$)\b/gi)) {
				alert("Felaktig e-postadress!");
				document.forms["form1"]["Email"].focus();
				return false;
			} else {
				return true;
			}
		} else {
			alert('Du måste ange en e-postadress!');
			document.forms["form1"]["Email"].focus();
			return false;
		}
	} else {
		alert("Du måste ange ditt namn!");
		document.forms["form1"]["Username"].focus();
		return false;
	}
}

function showColor(theNum) {
	theValue = (125 * parseInt(theNum)) ;
	document.getElementById("kayakImagePic").style.top = "-" + theValue + "px"
}

function flashMe(daMovie,daWidth,daHeight) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + daWidth + '" height="' + daHeight + '" id="killer" align="middle">');
	document.write('<param name="movie" value="' + daMovie + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<embed src="' + daMovie + '" quality="high" bgcolor="#ffffff" width="' + daWidth + '" height="' + daHeight + '" name="killer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
function validate() {
	nameVal=document.forms["mailForm"]["namn"].value;
	emailVal=document.forms["mailForm"]["epost"].value;
	telVal=document.forms["mailForm"]["telefon"].value;
	mobiVal=document.forms["mailForm"]["mobil"].value;
	nameFoc=document.forms["mailForm"]["namn"];
	emailFoc=document.forms["mailForm"]["epost"];
	telFoc=document.forms["mailForm"]["telefon"];
	mobiFoc=document.forms["mailForm"]["mobil"];
	if ((document.forms["mailForm"]["kurs1"].checked == false) && (document.forms["mailForm"]["kurs2"].checked == false) && (document.forms["mailForm"]["kurs3"].checked == false) && (document.forms["mailForm"]["kurs4"].checked == false) && (document.forms["mailForm"]["kurs5"].checked == false) && (document.forms["mailForm"]["kurs6"].checked == false)) {
		alert('Du har inte valt någon kurs/utflykt');
		return returnValue=false;
	}
	if (nameVal=='') {
		alert('fyll i namn');
		nameFoc.focus()
		return returnValue=false;
	}
	else if (emailVal=='') {
		alert('fyll i e-post');
		emailFoc.focus()
		return returnValue=false;
	}
	else if(isEmail(emailVal)==false) {
		alert('skriv in en fungerande e-post');
		emailFoc.focus()
		return returnValue=isEmail(emailVal);
	}
	else if (telVal=='') {
		alert('Skriv in ditt telefonnummer');
		mobiFoc.focus()
		return returnValue=false;
	}
	else if (telVal=='') {
		alert('Skriv in ditt mobilnummer');
		mobiFoc.focus()
		return returnValue=false;
	}
	else{
		return returnValue=true;
	}
}
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}