var fototeller, totaal;

fototeller=1;

function SetPage(doel)
{
  window.location.href=doel;
}

function nextPic()
{
  var foto, fnaam

  foto=document.fotoalbum.foto.src;

  fnaam=foto.substring(27)

  if (typeof window.ActiveXObject != 'undefined' )
   {
     xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
     xmlDoc.onreadystatechange = nextprocess ;
   }
  else
   {
     xmlDoc = new XMLHttpRequest();
     xmlDoc.onload = nextprocess ;
   }
  xmlDoc.open( "GET", "nextpic.asp?item=" + fnaam, true );
  xmlDoc.send( null );
}

function prevPic()
{
  var foto, fnaam

  foto=document.fotoalbum.foto.src;

  fnaam=foto.substring(27)

  if (typeof window.ActiveXObject != 'undefined' )
   {
     xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
     xmlDoc.onreadystatechange = prevprocess ;
   }
  else
   {
     xmlDoc = new XMLHttpRequest();
     xmlDoc.onload = prevprocess ;
   }
  xmlDoc.open( "GET", "prevpic.asp?item=" + fnaam, true );
  xmlDoc.send( null );
}

function nextprocess()
{
  if ( xmlDoc.readyState != 4 ) return ;
  if (xmlDoc.responseText!='null')
   {
     parent.document.fotoalbum.foto.src='../Album/' + xmlDoc.responseText;
     var newImg = new Image();
     newImg.src = '../Album/' + xmlDoc.responseText;
   }
}

function prevprocess()
{
  if ( xmlDoc.readyState != 4 ) return ;
  if (xmlDoc.responseText!='null')
   {
     parent.document.fotoalbum.foto.src='../Album/' + xmlDoc.responseText;
     var newImg = new Image();
     newImg.src = '../Album/' + xmlDoc.responseText;
   }
}

function CStijl(doel,klasse)
{
  document.getElementById(doel).className=klasse;
}

function HomeProfiel(doel,klasse,klasse2)
{
  CStijl('Date' + doel,klasse);
  CStijl('N' + doel,klasse);
  CStijl('D' + doel,klasse2);
}

function NWSbar(doel,klasse,klasse2)
{
  CStijl('nwsN' + doel,klasse);
  CStijl('nwsD' + doel,klasse2);
  CStijl('nwsT' + doel,klasse2);
}

function Login()
{
  document.aanmelden.submit();
}

function EnteredForm()
{
  if (event.keyCode==13)
  {
    document.aanmelden.submit();
  }
}

function ChangePic(img,src)
{
  document[img].src=src;
}

function getWidth() {
    alert("'" + this.name + "' is " + this.width + " by " + this.height + " pixels in size.");
    return this.width;
}

function getHeight() {
    alert("'" + this.name + "' is " + this.width + " by " + this.height + " pixels in size.");
    return this.height;
}

function loadFailure() {
    alert("'" + this.name + "' failed to load.");
    return -1;
}

function SetSize()
{
  var newImg = new Image();
  newImg.src = parent.document.fotoalbum.foto.src;
  var width = newImg.width;
  var height = newImg.height;
  if (width>height)
   {
     parent.document.fotoalbum.foto.height=300;
   }
  else
   {
     parent.document.fotoalbum.foto.height=450;
   }
}

function getHoogte()
{
  var newImg = new Image();
  newImg.src = parent.document.fotoalbum.foto.src;
  var height = newImg.height;
  return height;
}

function ChangeFoto(pic)
{
  parent.document.fotoalbum.foto.src='../Album/' + pic;
  var newImg = new Image();
  newImg.src = '../Album/' + pic;
}

function EditTimesheet(pid)
{
  this.location.href="default.asp?page=editts&tsid=" + pid;
}

function VerwijderTS(id)
{
  if (confirm('Bent u zeker dat u deze timesheet wilt verwijderen?'))
   {
     this.location.href="default.asp?page=deletets&tsid=" + id;
   }
}

function TSStijl(doel,klasse)
{
  CStijl('C' + doel,klasse);
  CStijl('P' + doel,klasse);
  CStijl('K' + doel,klasse);
  CStijl('R' + doel,klasse);
}

function ViewTS(id)
{
  this.location.href="default.asp?page=viewts&tsid=" + id;
}

function AViewTS(id)
{
  this.location.href="default.asp?page=admin_viewts&tsid=" + id;
}

function AViewVerlof(id)
{
  this.location.href="default.asp?page=admin_viewverlof&vid=" + id;
}

function AddTS(id)
{
  this.location.href="default.asp?page=editts&tsid=" + id + "&addts=1";
}

function EditTS(id,weeknum,codenum)
{
  this.location.href="default.asp?page=editts&tsid=" + id + "&editts=1&weeknum=" + weeknum + "&codenum=" + codenum;
}

function SetWeekNum(id)
{
  var weeknum

  weeknum=document.tsformulier.weeknum.value;

  this.location.href="default.asp?page=editts&tsid=" + id + "&addts=1&weeknum=" + weeknum;
}

function SetCode(id,weeknum)
 {
   var codenum

   codenum=document.tsformulier.codenum.value;

   this.location.href="default.asp?page=editts&tsid=" + id + "&addts=1&weeknum=" + weeknum + "&codenum=" + codenum;
}

function EditTSStijl(doel,klasse)
{
  var eind, item

  eind=doel+9;

  for (var x=doel; x<=eind; x++)
   {
     item="r" + x;

     document.getElementById(item).className=klasse;
   }
}

function VerwijderWeek(bdatum,edatum,tsid,codeid)
{
  if (confirm('Bent u zeker dat u de geselecteerde week wilt verwijderen?'))
   {
     this.location.href="DeleteTSRecord.asp?tsid=" + tsid + "&codeid=" + codeid + "&bdatum=" + bdatum + "&edatum=" + edatum;
   }
}

function LockTS()
{
  if (confirm('Wilt u deze timesheet voltooien?\n\nNa deze actie kunt u de timesheet niet meer wijzigen!'))
   {
     var id, uid

     id=document.getElementById('timesheetid').value;
     uid=document.getElementById('uid').value;

     this.location.href="LockTS.asp?id=" + id + "&uid=" + uid;
   }
}

function PrintTS(id)
{
  window.open('PrintTS.asp?id=' + id,"popup","menubar=no,resizable=no,scrollbars=yes,titlebar=no,height=600,width=800");
}

function APrintTS(id)
{
  window.open('admin_PrintTS.asp?id=' + id,"popup","menubar=no,resizable=no,scrollbars=yes,titlebar=no,height=600,width=800");
}

function VerlofStijl(doel,klasse)
{
  CStijl('C' + doel,klasse);
  CStijl('P' + doel,klasse);
  CStijl('A' + doel,klasse);
  CStijl('O' + doel,klasse);
  CStijl('G' + doel,klasse);
  CStijl('U' + doel,klasse);
}

function VerlofStijl2(doel,klasse)
{
  CStijl('C' + doel,klasse);
  CStijl('P' + doel,klasse);
  CStijl('A' + doel,klasse);
  CStijl('O' + doel,klasse);
  CStijl('U' + doel,klasse);
}

function ViewVerlof(id)
{
  this.location.href="default.asp?page=viewverlof&vid=" + id;
}

function VerwijderVerlof(id)
{
  if (confirm('Wilt u deze aanvraag verwijderen?'))
   {
     this.location.href="DeleteVerlof.asp?vid=" + id;
   }
}

function CheckDates()
{
  var date1, date2, date1array, date2array, str1, str2

  str1=document.verlofformulier.van.value;
  str2=document.verlofformulier.tot.value;
  date1array=str1.split("-");
  date2array=str2.split("-");

  date1=new Date();
  date1.setFullYear(date1array[2],date1array[0],date1array[1]);
  date2=new Date();
  date2.setFullYear(date2array[2],date2array[0],date2array[1]);
    

  if (str1)
   {
     if (str2)
      {
        if (date1<=date2)
         {
           document.verlofformulier.submit();
         }
        else
         {
           alert('Fout: De einddatum moet na de begindatum vallen!');
         }
      }
     else
      {
        document.verlofformulier.submit();
      }
   }
  else
   {
     alert('Fout: Gelieve een begindatum in te vullen!');
   }
}

function ChangePass(uid)
{
  this.location.href="default.asp?page=changepass&uid=" + uid;
}

function VerwijderUser(id,naam)
{
  if (confirm('Bent u zeker dat u deze user (' + naam + ') wilt verwijderen?\nAlle gegevens van deze persoon zoals timesheets en verlof worden hiermee ook verwijderd!'))
   {
     this.location.href="default.asp?page=deleteuser&uid=" + id
   }
}

function EditUser(id)
{
  this.location.href="default.asp?page=edituser&uid=" + id;
}

function CheckPass()
{
  if (document.userform.pass.value!=document.userform.pass2.value)
   {
     alert("Wachtwoorden komen niet overeen!")
   }
  else
   {
     document.userform.submit();
   }
}

function CheckText(doel)
{
 if (event.keyCode==13)
  {
        arguments[1]="<br/>"
	var subject=document.getElementById(doel);
	if (document.selection) {
		var range=document.selection.createRange();
		if (range.parentElement()==subject) {
			range.text=arguments[1]+(arguments[2]?range.text+arguments[2]:"");
			return;
		}
	}
	else if (subject.selectionStart || subject.selectionStart=='0') {	
		var str=subject.value;
		var a=subject.selectionStart, b=subject.selectionEnd;
		subject.value=str.substring(0,a)+arguments[1]+(arguments[2]?str.substring(a,b)+arguments[2]:"")+str.substring(b, str.length);
		return;
	}
	subject.value+=arguments[1]+(arguments[2] || "");
  }
}

function insertCode(doel){

	var subject=document.forms.formulier.omschrijving;
	if (document.selection) {
		var range=document.selection.createRange();
		if (range.parentElement()==subject) {
			range.text=arguments[0]+(arguments[1]?range.text+arguments[1]:"");
			return;
		}
	}
	else if (subject.selectionStart || subject.selectionStart=='0') {	
		var str=subject.value;
		var a=subject.selectionStart, b=subject.selectionEnd;
		subject.value=str.substring(0,a)+arguments[0]+(arguments[1]?str.substring(a,b)+arguments[1]:"")+str.substring(b, str.length);
		return;
	}
	subject.value+=arguments[0]+(arguments[1] || "");
}

function EditProfiel(pid)
{
  this.location.href="default.asp?page=editprofiel&pid=" + pid;
}

function VerwijderProfiel(id)
{
  if (confirm('Bent u zeker dat u dit record wilt verwijderen?'))
   {
     this.location.href="default.asp?page=deleteprofiel&pid=" + id;
   }
}

function Publish(pid)
{
  var bron, myelement, myteller

  bron='home' + pid;

  document.profform.pid.value=pid;

  if (document.getElementById(bron).checked==true)
   {
     document.profform.home.value=1;
   }
  else
   {
     document.profform.home.value=0;
   }

  document.profform.submit();

  myelement=document.getElementsByTagName('input');

  for (myteller=1;myteller<myelement.length;myteller++)
   {
     myelement[myteller].disabled=true;
   }
}

function EditAlbum(aid)
{
  this.location.href="default.asp?page=editalbum&aid=" + aid;
}

function VerwijderAlbum(id)
{
  if (confirm('Bent u zeker dat u dit album wilt verwijderen?\n\nAls u dit album verwijdert, dan worden ook alle foto\'s verwijderd.'))
   {
     this.location.href="default.asp?page=deletealbum.asp&aid=" + id
   }
}

function FotoVolgorde(id,direction)
{
  this.location.href="default.asp?page=foto_changevolgorde.asp&fid=" + id + "&direction=" + direction;
}

function DeleteFile(fid)
{
  if (confirm('Bent u zeker dat u deze foto wilt verwijderen?'))
   {
     this.location.href="default.asp?page=deleteimg&fid=" + fid;
   }
}

function AddFile(aid)
{
  this.location.href="default.asp?page=createupload&aid=" + aid;
}

function DeleteAlbum(aid)
{
  if (confirm('Wilt u het gehele album verwijderen?\n\nAls u dit album verwijderd, dan worden ook alle foto\'s verwijderd.'))
   {
     this.location.href="default.asp?page=deletealbum&aid=" + aid;
   }
}

function UpdateName(aid)
{
  this.location.href="default.asp?page=editalbum&aid=" + aid + "&status=upd_nm";
}

function BehandelVerlof(id)
{
  this.location.href="default.asp?page=behandelverlof&vid=" + id;
}

function SetTs()
{
  var usrselect

  usrselect=document.getElementById("usrselect").value;

  this.location.href="default.asp?page=admin_timesheets&uid=" + usrselect;
}

function SetVerlof()
{
  var usrselect

  usrselect=document.getElementById("usrselect").value;

  this.location.href="default.asp?page=admin_verlof&uid=" + usrselect;
}

function RequestProf(pid)
{
  document.profform.pid.value=pid;
  document.profform.submit();     
}

function EditRef(rid)
{
  this.location.href="default.asp?page=editreferentie&rid=" + rid;
}

function VerwijderRef(rid)
{
  if (confirm('Wilt u deze referentie verwijderen?'))
   {
     this.location.href="default.asp?page=deletereferentie&rid=" + rid;
   }
}

function Volgorde(id,direction)
{
  this.location.href="default.asp?page=referentie_changevolgorde&rid=" + id + "&direction=" + direction;
}

function EditNieuws(id)
{
  this.location.href="default.asp?page=editnieuws&nid=" + id;
}

function VerwijderNieuws(nid)
{
  if (confirm('Wilt u dit item verwijderen?'))
   {
     this.location.href="default.asp?page=deletenieuws&nid=" + nid;
   }
}

function GotoProf(doel)
{
  document.location.href="default.asp?page=profielen.asp#" + doel;
}

function GotoNWS(doel)
{
  document.location.href="default.asp?page=nieuws.asp#" + doel;
}

function slidePic(aid)
{
  document.location.href="default.asp?page=slideshow&album=" + aid;
}

function setCookie(c_name,value,expiredays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function setLanguage(taal)
{
  setCookie('bcm_lan',taal,365);
  window.location.reload();
}

function initLanguage(taal)
{
  setCookie('bcm_lan',taal,365);
}