//form check  
function isNotEmpty(elem) {
   var str = elem.value;
   if(str == null || str.length == 0) 
      return false;
   else 
      return true;
}
 
function validate(form) {
   var attrVal, attrReg, attrEq, attrFail, strTemp;

   for (var i = 0; i < form.length; i++) {
      attrVal = form[i].getAttribute("validate");
   
      switch (attrVal) {
         case 'required' :
            if (!isNotEmpty(form[i])) {
               attrFail = form[i].getAttribute("failure");
     
               if (attrFail)
                  alert(attrFail);
               else     
                  alert('Niet alle verplichte velden zijn ingevuld.');
               form[i].focus();
               return false;
            }
            break;
    
         case 'regex' :
            attrReg = form[i].getAttribute("regex");
            if (attrReg != null && attrReg.length != 0) {
               var regex = new RegExp(attrReg);
               strTemp = form[i].value;
               if (!strTemp.match(regex)) {
                  attrFail = form[i].getAttribute("failure");
         
                  if (attrFail)
                     alert(attrFail);
                  else
                     alert('Invalid data format at field "' + form[i].name + '".');
                  form[i].focus();
                  return false;
               }
            }
            break;
            
         case 'equals' :
            attrEq = form[i].getAttribute("equals");
            var objEq = document.getElementById(attrEq);
            if (objEq) {
               if (form[i].value != objEq.value) {
                  attrFail = form[i].getAttribute("failure");
              
                  if (attrFail)
                     alert(attrFail);
                  else
                     alert('Form fields do not match');
                  form[i].focus();
                  return false;
               }
            }
         break;
      }
   
   }
   return true;
}

function FormFields() {
   var htmlElements = Array('select', 'input', 'textarea');
   var htmlTempArray;
   for (var i = 0; i < htmlElements.length; i++) {
      htmlTempArray = document.getElementsByTagName(htmlElements[i]);

      for (var j = 0; j < htmlTempArray.length; j++) {
         if(htmlTempArray[j].type!='checkbox') {
            htmlTempArray[j].onfocus = htmlTempArray[j].onfocus = function() {
               this.style.background = '#BBBBBB';
            }
            htmlTempArray[j].onblur = htmlTempArray[j].onblur = function() {
               this.style.background = '#FFFFFF';
            }
         }
      }
   }
} 

function ExpandCollapse(name, img1, img2) {
	if (document.getElementById(name).style.display == "")         
		document.getElementById(name).style.display = "none";  
	else  
		document.getElementById(name).style.display = ""; 
		
	if (document.getElementById(img1).style.display == "") {        
		document.getElementById(img1).style.display = "none"; 
		document.getElementById(img2).style.display = ""; 
	}	
	else {
		document.getElementById(img2).style.display = "none"; 
		document.getElementById(img1).style.display = ""; 
  }	
}

function openBlock(pID, pNum) {
	for(var i=1; i<=pNum; i++) {
		var myDiv = document.getElementById('block_'+i);
		var myDiv2 = document.getElementById('block_'+i+'_image');
		if(i==pID) {
			myDiv.style.display='block';
			myDiv2.innerHTML = '<img src=\"/admin/images/arrow_black_down.gif\">';
		} else {
			myDiv.style.display='none';
			myDiv2.innerHTML = '<img src=\"/admin/images/arrow_dark.gif\">';
		}
	}
}

//function to open a window
var win=null;
function openWindow(mypage,myname,w,h) {
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width="+w+",height="+h+",top="+mytop+",left="+myleft+",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	alert(myname);
	win=window.open(mypage, myname, settings);
	win.focus();
}




  PositionX 		= 100;
  PositionY 		= 100;
  defaultWidth  	= 500;
  defaultHeight 	= 500;


  var AutoClose = true;

  if (parseInt(navigator.appVersion.charAt(0))>=4)
  {
    var isNN=(navigator.appName=="Netscape")?1:0;
    var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
  }
  var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
  var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

  function popImage(imageURL,imageTitle)
  {
    if (isNN){imgWin=window.open('about:blank','',optNN);}
    if (isIE){imgWin=window.open('about:blank','',optIE);}
    with (imgWin.document)
    {
      writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
      writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
      writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
      writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
      writeln('width=100-(document.body.clientWidth-document.images[0].width);');
      writeln('height=100-(document.body.clientHeight-document.images[0].height);');
      writeln('window.resizeTo(width,height);}');writeln('if (isNN){');
      writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
      writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
      if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
      else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
      writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
      close();
    }
}


