/*
 *		Description: Europassi default javascript
 *		Type: javascript
 *		Copyright: Opetushallitus
 *		Author: Luovakulma, Jani Tarvainen
 *
 */

// on load initialization
function init() {

	// init quicklinks navi
	for(i=0;i<document.getElementsByTagName("select").length;i++){
		if(document.getElementsByTagName("select").item(i).className == "locationSelect"){
			document.getElementsByTagName("select").item(i).onchange=changeLocation;
		}
	}

	// init resetbutton
	var resetButton = document.getElementById("resetButton");
	if (resetButton){
		resetButton.onclick=resetContactForm;
	}

	// js kludge to fix background hue
	var noHue = document.getElementById('noHue');
	var withHue = document.getElementById('withHue');
	if (withHue && noHue.clientHeight > withHue.clientHeight){
		withHue.style.height=noHue.clientHeight+'px';
	}

}

// do location change (for dropdown navi)
function changeLocation(){
  var local_link = /^index.php\?node_id=/;
  if (this.value.match(local_link)) {
    window.location.href=this.value;
  }
  else {
    window.open(this.value);
  } 
}

// reset contact form
function resetContactForm(){
	if(confirm('Oletko varma?')){
		document.getElementById('contactForm').reset();
	}
}

// do that init
window.onload=init;

