/* $Id: js_school.tpl,v 1.3 2004/09/22 12:14:52 bas Exp $ */



// Function:	getObj
// Parameters:	name of object
// Returns:		object
// Description:	creates object with right DOM
//
function getObj(name)
{
  if (document.getElementById && document.getElementById(name))
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all && document.all[name])
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers && document.layers[name])
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

// Function:	getObjNN4
// Parameters:	name of object
// Returns:		layer
// Description:	creates object with right nested layers for NN4 
//
function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function showObj(o)
{
	var x = new getObj(o);
	if (x.obj) x.style.display = "block";
}

function hideObj(o) 
{
	var x = new getObj(o);
	if (x.obj) x.style.display = "none";
}

// Validate reaction form
//
function validate_any_note(form,alrt)
{
	if (alrt == null || isSizeSmaller(alrt, 1))
	{
		alrt = "Alle velden zijn verplicht.";
	}
	var msg		 = "";
	var itsValue = "";
	var isValid  = true;

	// Check title
	itsValue = getvalue(form.elements["note[title]"]);
	if (isSizeSmaller(itsValue, 1))
	{	
		isValid = false;
		form.elements["note[title]"].focus();
	}
	
	// Check text
	itsValue = getvalue(form.elements["note[body]"]);
	if (isSizeSmaller(itsValue, 1))
	{	
		isValid = false;
		form.elements["note[body]"].focus();
	}

	// Check name
	itsValue = getvalue(form.elements["note[chapeau]"]);
	if (isSizeSmaller(itsValue, 1))
	{	
		isValid = false;
		form.elements["note[chapeau]"].focus();
	}

	if (!isValid)
	{
		alert(alrt);
	}
	else
	{
		form.submit();
	}
}

// Popup
//
function popup(thg_id,label,l,t,w,h) 
{ 
	if (l == null) l = 100;
	if (t == null) t = 100;
	if (w == null) w = 600;
	if (h == null) h = 600;

	var aPopupWin=window.open('','PopupWin','scrollbars=yes,menubar=no,locationbar=no,directories=no,statusbar=no,toolbar=no,resizable=yes,width='+w+',height='+h+',top='+t+',left='+l);
	aPopupWin.document.open(); 
	aPopupWin.document.close();
	var p = 'popup.php?id='+thg_id+'&label='+label;
	aPopupWin.document.location.href = p;
	if(aPopupWin&&!aPopupWin.closed) {
		aPopupWin.focus();
	}	
}

// helper functions
//
function getvalue(ffield)
{
  v="";
  t=ffield.type;
  if(!t)t=ffield[0].type;
  if(t=="checkbox")if(ffield.checked)v=ffield.value;
  if(t=="file") v=ffield.value;
  if(t=="hidden") v=ffield.value;
  if(t=="password") v=ffield.value;

  if(t=="radio")
  {
  	if(ffield.length){for(gv_i=0;gv_i<ffield.length;gv_i++)if(ffield[gv_i].checked) v=ffield[gv_i].value;}  
    else{if(ffield.checked) v=ffield.value;}	
  }
    
  if(t=="select-multiple")  v=ffield.options[ffield.selectedIndex].value;
  if(t=="select-one")  v=ffield.options[ffield.selectedIndex].value;
  if(t=="text") v=ffield.value;
  if(t=="textarea") v=ffield.value;
  //alert("type="+t + "<br><img src='trans.gif' width='1' height='5' alt=''><br>value=" + v)
  
  return v;
}

function isSizeSmaller(theValue, size)
{
	if (theValue.length < size) return true;
	else return false;
}

function isSizeGreater(theValue, size)
{
	if (theValue.length > size) return true;
	else return false;
}



