function onLoad() {
  //Näytetään JS toiminnot vain JS-enabloiduille
  //document.getElementById("vainKorostetut").style.display = 'inline';
  document.getElementById("naytaHimmennetyt").style.display = 'inline';
  document.getElementById("naytaKorostetut").style.display = 'inline';
  document.getElementById("naytaNormaalit").style.display = 'inline';
}

function writeError(str, append)
{
  var dbgObj = document.getElementById("debug");
  dbgObj.innerHTML = append? (dbgObj.innerHTML + str): str;
}

function toggleLayer(theDiv) {
  //document.getElementById(theDiv).innerHTML = document.getElementById(theDiv).style.display;
	if(document.getElementById(theDiv).style.display == 'block'){
		document.getElementById(theDiv).style.display = 'none';
	}
	else {
	 document.getElementById(theDiv).style.display = 'block';
	}
}

function ohjelmaAuki(theDiv, noBorder) {
  var noBorder = (noBorder == null) ? false : noBorder;
  var kuvausDiv = 'kuvaus' + theDiv.toString()
  var oBoxDiv = 'oBox' + theDiv.toString()
  //document.getElementById(theDiv).innerHTML = document.getElementById(theDiv).style.display;
	if(document.getElementById(kuvausDiv).style.display == 'block') {
	  if (noBorder == true) {
		document.getElementById(oBoxDiv).style.border = '1px dotted black';
	  }
	  //Opera käyttää #f5f5f5 muotoa, firefox rgb...
	  //writeError(document.defaultView.getComputedStyle(document.getElementById(oBoxDiv), null).getPropertyValue("background-color"));
	  if (document.defaultView.getComputedStyle(document.getElementById(oBoxDiv), null).getPropertyValue("background-color") != 'rgb(230, 230, 230)' && document.defaultView.getComputedStyle(document.getElementById(oBoxDiv), null).getPropertyValue("background-color") != '#e6e6e6') {
	 		document.getElementById(oBoxDiv).style.backgroundColor = '#F5F5F5';
	 	}
	}
	else {
	 	document.getElementById(oBoxDiv).style.border = 'none';
	 	if (document.defaultView.getComputedStyle(document.getElementById(oBoxDiv), null).getPropertyValue("background-color") == 'rgb(245, 245, 245)' || document.defaultView.getComputedStyle(document.getElementById(oBoxDiv), null).getPropertyValue("background-color") == '#f5f5f5') {
			document.getElementById(oBoxDiv).style.backgroundColor= '';
			//writeError("Väri poistettu");
		}
		//writeError(document.getElementById(oBoxDiv).style.backgroundColor);
	}
}



function changecss(theClass,element,value) {
//documentation for this script at http://www.shawnolson.net/a/503/
 var cssRules;
 /*if (document.all) {
  cssRules = 'rules';
 }*/
 if (navigator.appName == "Microsoft Internet Explorer") {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }
 for (var S = 0; S < document.styleSheets.length; S++){
  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
   if (document.styleSheets[S][cssRules][R].selectorText.toUpperCase() == theClass.toUpperCase()) {
   //writeError(document.styleSheets[S][cssRules][R].style[element]+"Löydetty<br />", true);
    document.styleSheets[S][cssRules][R].style[element] = value;
   }
  }
 }
}

function getCssClassValue(theClass,element) {
//documentation for this script at http://www.shawnolson.net/a/503/
 var cssRules;
 if (navigator.appName == "Microsoft Internet Explorer") {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }
  //writeError("Aloitetaan<br />", true);
 for (var S = 0; S < document.styleSheets.length; S++){
  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
    //writeError(document.styleSheets[S][cssRules][R].selectorText+"Löydetty<br />", true);
   if (document.styleSheets[S][cssRules][R].selectorText.toUpperCase() == theClass.toUpperCase()) {
	//writeError(document.styleSheets[S][cssRules][R].style[element]+"Löydetty<br />", true);
    return document.styleSheets[S][cssRules][R].style[element];
   }
  }
 }
 /*writeError("Ei ole olemassa :/", true);
 if (document.styleSheets[0].addRule) {              // Browser is IE?
	document.styleSheets[0].addRule(theClass, null,0);      // Yes, add IE style
  } else {                                            // Browser is IE?
	document.styleSheets[0].insertRule(theClass + ' { }', 0); // Yes, add Moz style.
  }*/
 return false; 
}

function piilotaEiKorostetut() {
  if (getCssClassValue("div.oBox", "visibility") != "hidden") {
	  changecss("div.oBox", "visibility", "hidden");
	  changecss("div.highlight", "visibility", "visible");
	  changecss("div.agentti", "visibility", "visible");
	  document.getElementById("vainKorostetut").innerHTML = "<u>N</u>äytä kaikki"
	  
	}
  else {
    changecss("div.oBox", "visibility", "visible");
    document.getElementById("vainKorostetut").innerHTML = "<u>N</u>äytä vain korostetut"
	  //writeError("Vaihdettu");
	}  
}
function toggleClassVisibility(classT) {
  if (getCssClassValue(classT, "visibility") != "hidden") {
	  changecss(classT, "visibility", "hidden");
	}
  else {
    changecss(classT, "visibility", "visible");
	}  
}
function toggleIdOverline(id) {
  if (document.getElementById(id).style.textDecoration != "line-through") {
	  document.getElementById(id).style.textDecoration = "line-through";
	}
  else {
    document.getElementById(id).style.textDecoration = "none";
	}  
}
function submitDateSelectorForm()
{
  document.dateselector.submit();
}