var win= null;
var curtabid = "";
var curitemid = "";
var restore = "";
var selectedgroup = "";
var oldselect = "";
var newselect = "";

function NewWindow(mypage,myname,w,h,scroll){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings  ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
    settings +='left='+winl+',';
	settings +='scrollbars='+scroll+',';
    settings +='resizable=yes';
	win=window.open(mypage,myname,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function LoadTab(tabid,tabtype,tabitemdef,tabname,tabpage){
	if (tabtype == 1)
	{	
		SelectTab(tabid,tabname);
		document.all.TabFrame.src= 'viewitemtab.asp?tab=' + tabid + '&tabitemdef=' + tabitemdef;
	}
	else if (tabtype == 2)
	{
    	SelectTab(tabid,tabname);
		document.all.TabFrame.src= 'viewiteminput.asp?tab=' + tabid + '&tabitemdef=' + tabitemdef;
	}
	else if (tabtype == 3)
	{
    	SelectTab(tabid,tabname);
		document.all.TabFrame.src= 'viewpagetab.asp?tab=' + tabid + '&tabitemdef=' + tabitemdef + '&page=' + tabpage;
	}
	else if (tabtype == 4 || tabtype == 5)
	{
    	SelectTab(tabid,tabname);
		document.all.TabFrame.src= 'viewitemtable.asp?tab=' + tabid + '&tabitemdef=' + tabitemdef;
	}
}

function SelectTab(tabid,tabname){
	SetBanner(tabname);
	ShowTab(tabid);
}

function SetBanner(tabname){
	 document.all("banner").innerHTML = tabname;
}

function ShowTab(tabid){
	if (curtabid != "")
		 {
			 document.getElementById(curtabid).className = 'tab_notselect';
		 }
		 document.getElementById(tabid).className = 'tab_select';	
	curtabid = tabid;
}

function PreLoadTab(tabid){
	curtabid = tabid;
}

function PreSelectItem(itemid){
	curitemid = itemid
}

function SelectGroup(groupid){
	SelectItem(groupid);
	document.postform.group_id.value=groupid;
}

function SelectUser(userid){
	SelectItem(userid);
	document.postform.userid.value=userid;
}

function LoadGroup(){
	if (document.postform.group_id.value != "")
	{
	document.postform.submit();
	}
	else 
	{
	alert("Je moet een groep selecteren!")
	}
}

function LoadUser(){
	if (document.postform.userid.value != "")
	{
	document.postform.submit();
	}
	else 
	{
	alert("Je moet een gebruiker selecteren!")
	}
}

function SelectItem(itemid){		 	 
	 if (curitemid != "")
		 {	
			 document.getElementById(curitemid).className = 'notselected';
		 }
	 document.getElementById(itemid).className = 'selected';	 
	 curitemid = itemid;
	 restore = 'selected';
}

function LoadItem(itemid,tabid,tabitemdef){
	 SelectItem(itemid);
	 parent.document.all.ItemDetailFrame.src= 'viewitemdetails.asp?tab=' + tabid + '&tabitemdef=' + tabitemdef + '&item=' + itemid
}

function LinkToItem(tabtype,tabid,tabitemdef,itemid){
	if (tabtype == 1)
	{	
		document.all.TabFrame.src= 'viewitemtab.asp?tab=' + tabid + '&tabitemdef=' + tabitemdef + '&item=' + itemid	
	}
	else if (tabtype == 5)
	{    
		document.all.TabFrame.src= 'viewitemtabledetails.asp?tab=' + tabid + '&tabitemdef=' + tabitemdef + '&item=' + itemid;
	}
}

function MouseOverItem(itemid){
	restore = document.getElementById(itemid).className;
	document.getElementById(itemid).className = 'mouseover';
}

function markSelect(selectname) {
	document.all(selectname).className = "markedselect";
}

function MouseOutItem(itemid){
	document.getElementById(itemid).className = restore;
}

function markInput(name) {
	document.all(name).className = "markedinput";
}

function markInputById(id) { 
	document.getElementById(id).className = "markedinput";
}
	
function checkEmpty(name,count) {
	if (document.all(name)) {
		if (document.all(name).value == "") {
			markInput(name);
			count = count+1;		
		}
	}
	return count;
}

function checkSame(id1,id2,count){
	if (document.getElementById(id1))
	{
		if (document.getElementById(id2))
		{
			if (document.getElementById(id1).value != document.getElementById(id2).value)
			{
				markInputById(id1);
				markInputById(id2);
				count += 1;
			}
		}
	}		
	return count;
}

function checkEmptyById(id,count) { 
	if (document.getElementById(id))
	{
		if (document.getElementById(id).value == "" )
		{
			markInputById(id);
			count += 1;
		}
	}
	return count;
}

function checkChecked(layoutid,name,count,anwser,minmax){
	var fillcounter = 0;
	for (var i=0; i<document.all(name).length; i++)  { 
		if (document.all(name)[i].checked)  {
			fillcounter += 1;
		}
	} 

	if (minmax == 'min')
	{
		if (fillcounter < anwser){
			showFieldError(layoutid,"U moet minimaal " + anwser + " antwoord(en) ingevullen !");
			count += 1;
		}
	} else if (minmax == 'max') {
		if (fillcounter != anwser){
		showFieldError(layoutid,"U moet " + anwser + " antwoord(en) ingevullen !");
		count += 1;
		}
	}

	return count;
}

function checkCheckedNl(layoutid,anderslayout,andersid,name,count,anwser,minmax){
	var fillcounter = 0;
	for (var i=0; i<document.all(name).length; i++) { 		
		if (i == document.all(name).length-1)
		{
			if (document.all(name)[i].checked)
			{
				fillcounter += 1;	
				if (document.all(andersid).value == "") {
					showFieldError(anderslayout,"U moet een antwoord ingevullen !");
					count = count+1;		
				}
			};
		} else {
		if (document.all(name)[i].checked){fillcounter += 1;}
		}
	} 

	if (minmax == 'min')
	{
		if (fillcounter < anwser){
			showFieldError(layoutid,"U moet minimaal " + anwser + " antwoord(en) ingevullen !");
			count += 1;
		}
	} else if (minmax == 'max') {
		if (fillcounter != anwser){
		showFieldError(layoutid,"U moet " + anwser + " antwoord(en) ingevullen !");
		count += 1;
		}
	}

	return count;
}

function checkFill(layoutid,name,count){
	if (document.all(name)) {
		if (document.all(name).value == "") {
			showFieldError(layoutid,"U moet een antwoord ingevullen !");
			count = count+1;		
		}
	}
	return count; 
}

function unmarkInput(formname){
	for (i=0;i<document.all(formname).elements.length;i++)
	{
		document.all(formname).elements[i].className = "unmarkedinput";
	}
}

function markText(name) {
	document.getElementById(name).className = "markedtext";
}

function unmarkText(formname) {
	for (i=0;i<document.all(formname).elements.length;i++)
	{
		document.all(formname).elements[i].className = "unmarkedtext";
	}
}

function showError(string) {
	document.getElementById("errorreport").innerHTML = '<b>' + string + '</b>';
}

function showFieldError(name,string){
	document.getElementById(name).innerHTML = '<b>' + string + '</b>';
}

function clearErrorFields(){
	var ele = getElementsByClassName("markedtext");
		for(x=0;x<ele.length;x++) {
			ele[x].className="unmarkedtext";
			ele[x].innerHTML = '';
		}
}

function getFrameData(){
	var ele = getElementsByClassName("ContentFrame");
		for(x=0;x<ele.length;x++) {
			document.getElementById(ele[x].name).value = window.frames[ele[x].id].document.frames.TheFrame.document.body.innerHTML;
		}
}

function getElementsByClassName(class_name)
{
  var all_obj,ret_obj=new Array(),j=0,teststr;

  if(document.all)all_obj=document.all;
  else if(document.getElementsByTagName && !document.all)
    all_obj=document.getElementsByTagName("*");

  for(i=0;i<all_obj.length;i++)
  {
    if(all_obj[i].className.indexOf(class_name)!=-1)
    {
      teststr=","+all_obj[i].className.split(" ").join(",")+",";
      if(teststr.indexOf(","+class_name+",")!=-1)
      {
        ret_obj[j]=all_obj[i];
        j++;
      }
    }
  }
  return ret_obj;
}

