var errormsg="";

 
 

function validateNewsletterForm(f) {
	var e = f.email.value;
	var e2 = f.email2.value;
	
	if (!e){ 
		alert('Du måste ange en e-mailadress');
	}else if(!e.match(/^.+@.+\.[a-z]{2,10}$/gi)){
		alert('E-postadressen är inte korrekt ifylld');
	}else if (e != e2){ 
		alert('E-postadresserna måste vara samma');
	}else{
		void(f.submit());
	}
}



if(errormsg){
	alert(errormsg);
}


function set_cookie(name,value) {
	document.cookie = name + '=' + escape(value)+'; expires=Fri, 31-Jan-2010 00:00:01 GMT';
}

function get_cookie(name) {
	var index = document.cookie.indexOf(name + "=");
	if (index == -1) return null;
	index = document.cookie.indexOf("=", index) + 1;
	var endstr = document.cookie.indexOf(";", index);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(index, endstr));
}

function tip_a_friend() {
	window.open('tip_a_friend.php','wwf_tip','width=300,height=300,toolbars=0,scrollbars=0,resizable=0');
}

function showlayer(i) {
	document.getElementById(i).style.display = 'block';
}

function hidelayer(i) {
	document.getElementById(i).style.display = 'none';
}

function showflash(id,width,height,bgcolor) {
	if (!bgcolor) bgcolor = 'white';
	var url = 'showflash.php?id='+id+'&width='+width+'&height='+height+'&bgcolor='+bgcolor;
	window.open(url,'wwf_flash_'+id,'width='+(width)+',height='+(height)+',toolbars=0,scrollbars=0,status=0,resizable=0');
}

function showSpel(){
	var spelWin = window.open('avtryck.html','spelwin','toolbar=no,directories=no,status=no,menubar=no,scrollbars=auto,left=0,top=0,resizable=yes,width=800,height=600');
	if (spelWin) {
		spelWin.focus();
	}
}



//Fontstorlekar
window.addEvent("domready", function() {
  new Fx.Font($$('div#left, div#main, div#footer'), $('big-text'), $('medium-text'), $('normal-text'));
  applesearch.init();
});

// Expandable
window.addEvent("domready", function() {
	$$('.extendable').each(function(extendable) {
		extendable.triggerElement = extendable.getElementsBySelector('.ext-top')[0];
		
		if (extendable.triggerElement != null) {
			extendable.triggerElement.style.cursor = "pointer";
			extendable.triggerElement.fxAnimator = new Fx.Slide(extendable.getElementsBySelector('.ext-content', {duration: 500})[0]);
			extendable.triggerElement.addEvent('click', function() {
			  if (window.webbrowser.ie6) {
			    // IE6 doesn't like Fx.Slider.
			    this.fxAnimator.show();
			  } else {
			    this.fxAnimator.toggle();
		    }
			});
			if (extendable.getElementsBySelector('.error').length == 0) {
			  extendable.triggerElement.fxAnimator.hide();
		  }
		}
	});
});

// Footer
window.addEvent("domready", fix_footer_at_bottom);
window.addEvent("resize", fix_footer_at_bottom);

function fix_footer_at_bottom() {
  var footer = $('footer');
  var footerBottom = footer.getCoordinates().bottom - (footer.marginFixedAt != null ? footer.marginFixedAt : 0);
  var windowHeight = window.getHeight();
  if (windowHeight - footerBottom > 20) {
    footer.style.marginTop = (windowHeight - footerBottom) + 'px';
    footer.marginFixedAt = (windowHeight - footerBottom);
  } else {
    footer.style.marginTop = '20px';
    footer.marginFixedAt = 20;
  }
}

// Clickable top in IE6
if (window.ie6) {
  window.addEvent("domready", function() {
    $E('h1').style.cursor = 'pointer';
    $$('h1').addEvent("click", function() {
      $E('h1 a').click();
    });
    
  });
}

window.addEvent("domready", function() {
  if (!window.ie) {
    $$('#top-image img').each(function(element) {
      if (element.alt != '' && element.title == '') {
        element.title = element.alt;
      }
    });
  }
});