var IE4		= (document.all && !document.getElementById) ? true : false;
var IE5 	= (document.all && document.getElementById) ? true : false;
var MOZILLA	= (!document.all && document.getElementById) ? true : false;
var oldClass;
var currentBox;
var curTeamBox = "team1";
var curRondeBox = "ronde1";
var curLokatie = "lbox1";
var timer;
var map = null;
var geocoder = null;
var showmap = false;
//
function GetElementByID(elementID)
{
	if (IE4) return document.all[elementID];
	if (IE5 || MOZILLA)	return document.getElementById(elementID);
}
function showperiode(iframe,periode,type)
{
    var iframe = this.GetElementByID(iframe)
    iframe.src = "iframepage.php?pageID=11&periodeID=" + periode + "&typeID=" + type;
}
function changePage(selector)
{
    location.href = "index.php?pageID=" + selector.value;
}
function changeNewsPage(url,pageID)
{
    location.href = "index.php?pageID=" + pageID + "&" + url;
}
function MouseOver(tableRow)
{
  if(tableRow.className != "mouseRowOver")
  { 
      oldClass = tableRow.className;
  }
  tableRow.className = "mouseRowOver";
}

function MouseOut(tableRow)
{	
	if(tableRow.className == "mouseRowOver")
  {
      tableRow.className = oldClass;
  } 
}
function showBox(boxid)
{
    if(this.currentBox == null) this.currentBox = "box1";
    lb = this.GetElementByID(this.currentBox);
    if(this.GetElementByID(boxid) != null)
    {
      lb.style.display = "none";
      this.currentBox = boxid;
      box = this.GetElementByID(boxid);
      box.style.display = "";
    }
}
function showLokatieBox(boxid)
{
    if(this.curLokatie == null) this.curLokatie = 'lbox1';
    lb = this.GetElementByID(this.curLokatie);
    if(this.GetElementByID(boxid) != null)
    {
      lb.style.display = "none";
      this.curLokatie = boxid;
      box = this.GetElementByID(boxid);
      box.style.display = "";
    }
}
function changeItem(selektor,arguments)
{
    var sb = this.GetElementByID(selektor);
    var newitem = sb.options[sb.selectedIndex].value;
    location.href = arguments + newitem;
}
function changeSeizoen(selektor,target,arguments)
{
    var sb = this.GetElementByID(selektor);
    var newitem = sb.options[sb.selectedIndex].value;
    var iframe = this.GetElementByID(target)
    iframe.src = arguments + newitem;
}
function changeClublid(selektor,target,arguments)
{
    var sb = this.GetElementByID(selektor);
    var newitem = sb.options[sb.selectedIndex].value;
    var iframe = this.GetElementByID(target)
    iframe.src = arguments + newitem;
}
function changeteambox(selektor)
{
    for(var i=1;i<11;i++)
    {
        lb = this.GetElementByID("team"+i);
        if(lb != null) lb.style.display = "none";
    }
    var sb = this.GetElementByID(selektor);
    var newitem = sb.options[sb.selectedIndex].value;
    box = this.GetElementByID(newitem);
    box.style.display = "";
    this.curTeamBox = newitem;
}
function changerondebox(selektor)
{
    if(this.GetElementByID(selektor) == null) return;
    var sb = this.GetElementByID(selektor);
    var newitem = sb.options[sb.selectedIndex].value;
    var lb = this.GetElementByID(this.curRondeBox);
    if(lb != null) lb.style.display = "none";
    box = this.GetElementByID(newitem);
    if(box != null) box.style.display = "";
    this.curRondeBox = newitem;
}
function setAction(actionValue)
{
    if(confirm('Weet u zeker dat u deze actie wilt doen?') == true)
	  {
        document.getElementById("actionID").value = "update" + actionValue;
	  }
    else
    {
        document.getElementById("actionID").value = "updatenone";
    }    
}
function saveimage(fileNaam)
{
    alert(fileNaam);
    if(this.GetElementByID("actionID") != null)
    {
        this.GetElementByID("actionID").value = "save";
    }  
    if(this.GetElementByID("file") != null)
    {
        alert(fileNaam);
        a = this.GetElementByID("file");
        this.GetElementByID("fileName").value = a.value;
    }      
}
function savedocument()
{
    if(this.GetElementByID('box42') != null) this.showbox('box42');
    if(this.GetElementByID("actionID").value == "")
    {
      this.GetElementByID("actionID").value = "save";
      if(this.GetElementByID('box1') != null) 
      {
        var box1 = this.GetElementByID('box1');
        if(box1.style.display == "") 
        {
        document.getElementById("actionID").value = "savebox1";
        return;
        }
      }
      if(this.GetElementByID('box2') != null) 
      {
        var box2 = this.GetElementByID('box2');
        if(box2.style.display == "") 
        {
        document.getElementById("actionID").value = "savebox2";
        return;
        }
      }
      if(this.GetElementByID('box3') != null) 
      {
        var box3 = this.GetElementByID('box3');
        if(box3.style.display == "") 
        {
        document.getElementById("actionID").value = "savebox3";
        return;
        }
      }
      if(this.GetElementByID('box4') != null)
      {
        var box4 = this.GetElementByID('box4');
        if(box4.style.display == "") 
        {
        document.getElementById("actionID").value = "savebox4";
        return;
        }
      }
    }
}
function checkdocument(theForm)
{
    var x = theForm.knsbid.value;
    if(x != "")
    {
        var y = Math.floor(x%11);
        if(isNaN(y) || y != 0) 
        {
            alert('Geen geldig KNSB nummer');
            theForm.knsbid.focus();
            return false;
        }
    }
    x = theForm.naam.value;
    if(x == 0)
    {
        alert('Naam is verplicht');
        theForm.naam.focus();
				return false;
    }
    x = theForm.adres.value;
    if(x == 0)
    {
        alert('Adres is verplicht');
        theForm.adres.focus();
				return false;
    }
    x = theForm.woonplaats.value;
    if(x == 0)
    {
        alert('Adres is verplicht');
        theForm.woonplaats.focus();
				return false;
    }
		x = theForm.email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(x)) {
				alert('Geen geldig emailadres!');
				theForm.email.focus();
				return false;
		}
    document.getElementById("actionID").value = "verzend";
		return true;
}
function showurl(doel)
{
   var url = this.GetElementByID(doel); 
   window.open(url.value);
}
function closewindow(type)
{
    window.returnValue = "";
		if(type == "0")
		{
				var a = this.GetElementByID("itemselektor");
		    window.returnValue = a.options[a.selectedIndex].value;
		} 
    if(type == "1")
    {
        window.returnValue = "##########";
    }  
    if(type == "3")
    {
        window.returnValue = this.GetElementByID("file").value;
    } 
    if(type.length > 1) // return string
    {
        window.returnValue = type;
    }
    window.close();
}
function zoekeninberichten()
{
    this.hideunhide("topframe","none");
    this.hideunhide("berichten","none");
    this.hideunhide("topbar","none");
    this.hideunhide("bottombar","none");
    this.hideunhide("zoekframe","");
    // fetch the old values
}
function unselekt()
{
    this.hideunhide("topframe","");
    this.hideunhide("berichten","");
    this.hideunhide("topbar","");
    this.hideunhide("bottombar","");
    this.hideunhide("zoekframe","none");
    // oude waarden terug
}
function hideunhide(veld,waarde)
{
    if(this.GetElementByID(veld) != null)
    {
        this.GetElementByID(veld).style.display = waarde;
    }
}
function startzoeken(pageid)
{
    jaarnr = this.GetElementByID("jaar");
    jaarid = jaarnr.options[jaarnr.selectedIndex].value;
    searchstring = "?pageID=" + pageid;
    if(jaarid != "")
    {
        searchstring = searchstring + "&jaar=" + jaarid + "";
    }
    searchstring = searchstring + this.getinputstring("auteur");
    searchstring = searchstring + this.getinputstring("subject");
    location.href = searchstring;
}
function clearvelden()
{
    jaarnr = this.GetElementByID("jaar");
    jaarnr.selectedIndex = 0;
    this.GetElementByID("auteur").value = "";
    this.GetElementByID("subject").value = ""
}
function getinputstring(naamid)
{
    waarde = this.GetElementByID(naamid).value;
    if(waarde == "") return "";
    return "&" + naamid + "=" + waarde;
}
function checkMail(theForm)
{
			var x = theForm.email.value;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(x)) {
				alert('Geen geldig emailadres!');
				theForm.email.focus();
				return false;
			}
			this.savedocument();
			return true;
}
function setMailingFormulier()
{
    this.GetElementByID("mailingframe").src = "iframepage.php?pageID=7";
}
function scrolltop()
{
		document.getElementById('kalenderbox').style.top=document.body.scrollTop
		this.timer=setTimeout("scrolltop()",1)
}
function stoptimer()
{
			clearTimeout(this.timer)
}
function init(waarde)
{
}
function printbericht(content,header)
{
  var tkst = this.GetElementByID(content);
	var vf = window.open('', 'Frank', 'status=no,scrollbars=yes,menubar=no,toolbar=no,width=700,height=320')
	with ( vf.document )
	{	
      open();
      write('<HTML><HEAD><TITLE>Print formulier</TITLE><link href="common/stylesheets/common.css" type="text/css" rel="stylesheet" /><link href="common/stylesheets/berichten.css" type="text/css" rel="stylesheet" /></HEAD><BODY onLoad="window.print(); window.close();">')
      if(header != "")
      {
          head = this.GetElementByID(header);
          write(head.innerHTML);
          write('<br\><hr\>');
      }
      write(tkst.innerHTML);
      write('</BODY></HTML>')
      close();
  }
}
function competitieoverzicht(header)
{
    if(this.printbox('box1','contentbox1',header))    return;
    if(this.printbox('box2','contentbox2',header))    return;
    if(this.printbox('box3',this.curRondeBox,header)) return;
    if(this.printbox('box4',this.curTeamBox,header))  return;
    if(this.printbox('box5','tproverzicht',header))   return;
    if(this.printbox('box6','box6',header))           return;
    if(this.printbox('box10','box10',header))         return;
}
function printbox(boxid,printid,header)
{
    if(this.GetElementByID(boxid) != null)
    {
        if(this.GetElementByID(boxid).style.display == "")
        {
          this.printbericht(printid,header);
          return true;
        }
    }
    return false;
}
function ratingoverzicht(header)
{
    this.printfoverzicht(header);
}
function printoverzicht(header)
{
    var box = "";
    for(var id=1;id<12;id++)
    {
        box = "box" + id;
        if(this.GetElementByID(box) != null)
        {
            if(this.GetElementByID(box).style.display == "")  
            {
               this.printbericht(box,header);
               break;
            }  
        }
    }
}
function zoekRatPersoon(naam)
{
    var naamveld = this.GetElementByID(naam);
    var naamstring = naamveld.value;
    if(naamstring.length < 3)
    {
        alert("Type minimaal de eerste drie karakters van de achternaam in.");
    }
    else
    {
        location.href = "index.php?pageID=16&" + "searchstring=" + naamstring;
    }
}
function ratingperiode(top,typerating)
{
    var a = this.GetElementByID(top);
    location.href = "index.php?pageID=17&" + "periodeID=" + a.options[a.selectedIndex].value + "&typerating=" + typerating;
}
function ratingclubperiode(page,periode)
{
    var a = this.GetElementByID(periode);
    location.href = page + a.options[a.selectedIndex].value;
}
function calculatebodyheigth(rows,iframename)
{
    this.GetElementByID(iframename).style.height = ((rows*19) + 65);
}
function mapvisible()
{
    if(this.GetElementByID("map") != null)
    {
        if(this.GetElementByID("map").style.display == "")
        {
            this.googlemaps();
        }
    }
}
function lokatieBox(show,hide,ismap)
{
    this.GetElementByID(hide).style.display = "none";
    this.GetElementByID(show).style.display = "";
    this.showagendamap(false);
}
function showagendamap(metadress)
{
    if(this.showmap == true) return;
    this.googlemaps(metadress);
    this.showmap = true;
} 
 
function googlemaps(metadress)
{
    if (GBrowserIsCompatible())
    {
        this.geocoder = new GClientGeocoder();
        this.map = new GMap2(document.getElementById("map"));
        var a = this.GetElementByID("address");
        if(a != null)
        {
            items = a.value.split('#');
            if(items.length > 1)
            {
                for(i=0;i<items.length;i++)
                {
                   this.showAdress(items[i],false,9,i);
                }
            }
            else
            {
                this.showAdress(a.value,metadress,17,0);
            }
        }
    }
}
function createMarker(point, index, message) 
{  
   var marker = new GMarker(point);
   var s = this.createAdres(message);
   marker.value = index;  
   GEvent.addListener(marker, "click", 
      function() {    
         var myHtml = s;
         map.openInfoWindowHtml(point, s);
            }); 
   return marker;
}  
function createAdres(adres)
{
    clubitems = adres.split('|');
    r = "";
    if(clubitems[1] == null)
    {
       items= adres.split(',');
    }
    else
    {
      r = "<b>" + clubitems[0] + "</b>";
      items= clubitems[1].split(',');
    }
    for(i=0;i<items.length;i++)
    {
        r = r + "<br/>" + items[i];
    }
    return r;
}
function showAdress(address,metadress,zoom,nummer)
{
    if(this.geocoder)
    {
        this.geocoder.getLatLng(address,function(point)
        {
            if(!point)
            {
                //alert(address + " niet gevonden");
            }
            else
            {
               this.map.setCenter(point,zoom);
               var marker = this.createMarker(point,nummer,address);
               this.map.addOverlay(marker);
               this.map.addControl(new GLargeMapControl());
               this.map.addControl(new GMapTypeControl());
               if(metadress)
               { 
                  map.openInfoWindow(map.getCenter(),document.createTextNode(address));
               }
            }
        }
    );
    } 
}


