function getElement(elementName){
	return document.getElementById(elementName);	
}

function tryLogin(e){
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if(keycode == 13){
		if(document.getElementById('gebruikersnaam').value != '' && document.getElementById('wachtwoord').value != ''){
			document.formlogin.submit();
		}
	}
}

function activateTab(tab){
	getElement('managementTab').className = 'invisible';
	getElement('dossiersTab').className = 'invisible';
	getElement('instellingenTab').className = 'invisible';
	
	getElement('managementHeader').className = 'inactivePanelHeader';
	getElement('dossiersHeader').className = 'inactivePanelHeader';
	getElement('instellingenHeader').className = 'inactivePanelHeader';
	
	getElement(tab+'Tab').className = '';
	getElement(tab+'Header').className = 'activePanelHeader';
}

function changeMainFrame(url){
	window.frames['mainWindow'].location = url;	
}

function openClienten(divCounter,project_id){
	for(var i = 0; document.getElementById('clienten_'+i); i++){
		if(divCounter == i){
			document.getElementById('clienten_'+i).className = '';
			document.getElementById('clientenDIV_'+i).innerHTML = '<iframe id="clientenFrame" width="100%" height="100%" frameborder="0" src="modules/clienten/clienten.php?project_id='+project_id+'"></iframe>';
		} else {
			document.getElementById('clienten_'+i).className = 'invisible';			
			document.getElementById('clientenDIV_'+i).innerHTML = '';
		}
	}
}

/* POPUP FUNCTIONS */
var popup_width;
var popup_height;
var popup_top;
var popup_left;
var popup_state = 'variable';

function openPopupWindow(url,name,title,width,height,scrolling,resizable)
{
	
	var url,name,title,width,height,scrolling,resizable;

	parent.document.getElementById('popup_filter').style.display = '';
	parent.document.getElementById('popup_window').style.display = '';

	parent.document.getElementById('popup_title').innerHTML = title;

	parent.document.getElementById('popup_iframe').style.width = width + 'px';
	parent.document.getElementById('popup_iframe').style.height = height + 'px';
	parent.document.getElementById('popup_iframe').scroll = scrolling;

	parent.window.frames['popup_iframe'].document.location = url;
	
	if (window.innerHeight) { 
		if(parent.window.innerHeight){
			var windowwidth = parent.window.innerWidth;
			var windowheight = parent.window.innerHeight;
		} else {
			var windowwidth = window.innerWidth;
			var windowheight = window.innerHeight;
		}
	} else if( document.documentElement && document.documentElement.clientWidth ) {     //IE 6+ in 'standards compliant mode'    
		if(parent.document.documentElement && parent.document.documentElement.clientWidth ) {
			var windowwidth = parent.document.documentElement.clientWidth;   
			var windowheight = parent.document.documentElement.clientHeight;   
		} else {
			var windowwidth = document.documentElement.clientWidth;   
			var windowheight = document.documentElement.clientHeight;   
		}
	} else if( document.body && document.body.clientWidth ) {     //IE 4 compatible     
		if( parent.document.body && parent.document.body.clientWidth ) {  
			var windowwidth = parent.document.body.clientWidth;   
			var windowheight = parent.document.body.clientHeight;   
		} else {
			var windowwidth = document.body.clientWidth;   
			var windowheight = document.body.clientHeight;   
		}
	}  else {
		var windowwidth = screen.width;
		var windowheight = screen.height-166;
	}
	
	parent.document.getElementById('popup_window').style.top = (windowheight/2)-(height/2);
	parent.document.getElementById('popup_window').style.left = (windowwidth/2)-(width/2);

	popup_state = 'variable';
}

function closePopupWindow()
{
	document.getElementById('popup_filter').style.display = 'none';
	document.getElementById('popup_window').style.display = 'none';
	//window.frames['popup_iframe'].document.location = './blank.php';
	
	window.frames['popup_iframe'].document.body.innerHTML = '';

	popup_state = 'variable';
}

function resizePopupWindow(method)
{
	if (popup_state=='variable') {
		popup_width = parent.document.getElementById('popup_iframe').style.width;
		popup_height = parent.document.getElementById('popup_iframe').style.height;

		popup_top = parent.document.getElementById('popup_window').style.top;
		popup_left = parent.document.getElementById('popup_window').style.left;
	}

	if (method=='maximize') {
		if (popup_state=='variable') {
			popup_state = 'maximized';
			
			if (window.innerHeight) {
				var width = window.innerWidth-44;
				var height = window.innerHeight-70;
			} else if( document.documentElement && document.documentElement.clientWidth ) {     //IE 6+ in 'standards compliant mode'    
				if(parent.document.documentElement && parent.document.documentElement.clientWidth ) {
					var width = parent.document.documentElement.clientWidth-44;   
					var height = parent.document.documentElement.clientHeight-70;  
				} else {
					var width = document.documentElement.clientWidth-44;  
					var height = document.documentElement.clientHeight-70;   
				}
			} else if( document.body && document.body.clientWidth ) {     //IE 4 compatible     
				if( parent.document.body && parent.document.body.clientWidth ) {  
					var width = parent.document.body.clientWidth-44;   
					var height = parent.document.body.clientHeight-70;  
				} else {
					var width = document.body.clientWidth-44;   
					var height = document.body.clientHeight-70;   
				}
			}  else {
				var width = screen.width-46;
				var height = screen.height-266;
			}

			width = width + 'px';
			height = height + 'px';

			var top = '10px';
			var left = '10px';
		} else
		if (popup_state=='maximized') {
			popup_state = 'variable';

			var width = popup_width;
			var height = popup_height;
			var top = popup_top;
			var left = popup_left;
		}
	}

	parent.document.getElementById('popup_window').style.top = top;
	parent.document.getElementById('popup_window').style.left = left;

	parent.document.getElementById('popup_iframe').style.width = width;
	parent.document.getElementById('popup_iframe').style.height = height;
}

function downloadFile(file, location, key){
	if(window.frames['downloadWindow']){
		var downloadWindow = window.frames['downloadWindow'];
	} else if(parent.window.frames['downloadWindow']){
		var downloadWindow = parent.window.frames['downloadWindow'];
	} else if(parent.parent.window.frames['downloadWindow']){
		var downloadWindow = parent.parent.window.frames['downloadWindow'];
	}
	downloadWindow.location = '../../modules/bestanden/bestand_downloaden.php?file='+file+'&location='+location+'&key='+key;
}


function makeNumber(e,objectId,maxValue,noDot)
{
	var objectId;
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	var maxValue;
	var noDot;
	
	if(key >= 37 && key <= 40){ return true; }
	
	if(keychar == '.'){
		if(objectId){
			if(!hasChar(getElement(objectId).value,',')  && noDot != 1){
				setTimeout("getElement('"+objectId+"').value += ','",50);
			}
		}
		return false;
	}
	else if(keychar == ',' && objectId){
		return (!hasChar(getElement(objectId).value,',') && noDot != 1);
	}
	else{  
		if(isNumeric(keychar) || key == 8 || key == 45){
			if(maxValue > 0){
				setTimeout("validateMaxValue('"+objectId+"',"+maxValue+");",100);
			}
			return key;	
		}
		else{
			return false;	
		}
	} 
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for(i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if(ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;  
}

function hasChar(sText, needle){
   var needle;
   var hasChar=false;
   var Char;

   for(i = 0; i < sText.length && hasChar == false; i++){ 
      Char = sText.charAt(i); 
      if(needle.indexOf(Char) != -1){
         hasChar = true;
      }
   }
   return hasChar;  	
}

function validateMaxValue(objectId,maxValue){
	if(getElement(objectId).value > maxValue){
		alert('De in te vullen waarde mag niet groter dan '+maxValue+' zijn!');
		getElement(objectId).value = maxValue;
	}
}

