/**Show info**/
function showInfoDiv(oEvent, div, left, content) {

	if (left==""){ myLeft=oEvent.clientX+15+"px";}	else myLeft=left+"px";
	myTop=oEvent.clientY-20+"px";

	document.getElementById(div).style.left=myLeft;
	document.getElementById(div).style.top=myTop;

	if (content){
	  document.getElementById(div).innerHTML=content;
	}
	document.getElementById(div).style.display="block";
}
function hideSelect(){
  for(i = 0; i < document.forms[0].elements.length; i++){
		if (document.forms[0].elements[i].type=="select-one"){
		  document.forms[0].elements[i].style.visibility="hidden";
		}
	}
}
function showSelect(){
  for(i = 0; i < document.forms[0].elements.length; i++){
		if (document.forms[0].elements[i].type=="select-one"){
		  document.forms[0].elements[i].style.visibility="visible";
		}
	}
}

/**Force view-mode**/
function forceViewMode(root){

	var root = root;
	var file = root + "/Systemfiles/session_destroy.php";
	var http = false;
  	if(navigator.appName == "Microsoft Internet Explorer") {
    	http = new ActiveXObject("Microsoft.XMLHTTP");
  	} else {
    	http = new XMLHttpRequest();
  	}	
	http.abort();
  	http.open("GET", file, true);
  	http.onreadystatechange=function() {
	    if(http.readyState == 4) {
		  document.location.href='?';
	    }
  	}
  	http.send(null);
}

/**Check all checkboxes in a form**/
function checkAll(form_number){
  var end = document.forms[form_number].length-1;
	var i=0;
	var temp = new Array();
	for (i=0;i<=end;i++){
	  if (document.forms[form_number].elements[i].type=="checkbox"){
		  if (document.forms[form_number].elements[i].checked==true){
			  document.forms[form_number].elements[i].checked=false;
			}
			else{
			  document.forms[form_number].elements[i].checked=true;
			}
		}
	}
}

/**Change background-color <tr>**/
function changeBgColor(field){
  var color=field.style.background;
	if (color=="#ffffff" || color=="") field.style.background="#eeeeee";
	if (color=="#eeeeee") field.style.background="#ffffff";
}

/*Show/hide info/help*/
function showInfo(show,content){
  if (show=='true'){
    var halfHeight = document.body.offsetHeight/2;
	  document.getElementById('info').innerHTML="<table cellspacing='5' cellpadding='10' width='150' bgcolor='#eeeeee'><tr><td bgcolor='#ffffff'>"+content+"</td></tr></table>";
		document.getElementById('info').style.posTop=event.clientY-20;
		document.getElementById('info').style.posLeft=event.clientX+30;
	  document.getElementById('info').style.visibility="visible";
	}
	else{
	  document.getElementById('info').style.visibility="hidden";
	}
}

//Copy content from one field to other fields (comma separated)
function copyField(field,value){
  field.value=value;
}

//Instantiate date picker
function datepicker(field,width,la,path){

  var dp = new DatePicker(field, 'mysql5', 'long2', '', '',true,false,la);

	//Set path to images
  	path = path + "Systemfiles/DatePicker/";

	//Set attributes and styes
	dp.setCSSAttribute(CSS_DATE_TEXT,'font:normal 10px verdana; padding-top: 2px; text-decoration:none; color: #333333;');
	dp.setCSSAttribute(CSS_MOUSESELECT,"background: URL(" + path + "RolloverImages/DP_DateSelector_018.gif);");
	dp.setCSSAttribute(CSS_MOUSEOVER,"background: URL(" + path + "RolloverImages/DP_DateSelector_015.gif);");
	dp.setCSSAttribute(CSS_DISPLAY_AREA,'font:normal 10px verdana; color:#666666; border:none; background-color:none;');
	dp.setCSSAttribute(CSS_BUTTON_TEXT,'');
	dp.setCSSAttribute(CSS_BUTTON,'background: URL('+path+'ButtonIcons/DateIcon_50.gif); border:0px; background-color:white; width:16px; height:16px;');
	dp.setCSSAttribute(CSS_CALENDAR,'background: #ffffff; border: 2px outset #000000;');
	dp.setCSSAttribute(CSS_DATEHEADER_ROW, 'background: #eeeeee;');
	dp.NavMonthNext = "<IMG SRC=" + path + "NavigationIcons/Button_19.gif BORDER=0>";
	dp.NavMonthPrevious = "<IMG SRC=" + path + "NavigationIcons/Button_20.gif BORDER=0>";
	dp.NavYearNext = "<IMG SRC=" + path + "NavigationIcons/Button_21.gif BORDER=0>";
	dp.NavYearPrevious = "<IMG SRC=" + path + "NavigationIcons/Button_22.gif BORDER=0>";
	dp.NavNull = "<IMG SRC=" + path + "Images/DateIcon_18.gif BORDER=0>";

  dp.Instantiate();
}

//Show/hide div
  function showHide(div){
	  if (document.getElementById(div).style.display=='none'){
		  document.getElementById(div).style.display='block';
		}
		else {
		  document.getElementById(div).style.display='none';
		}
	}

//Show div
  function show(div){
	  if (div){
	    document.getElementById(div).style.display='block';
		}
	}

//Change main menu items
  function changeMenu(show_items,close_items,image){

		//Show elements
		if (show_items){
		  var showArray = new Array();
		  showArray = show_items.split(',');
		  var todo;
		  for (i=0;i<showArray.length;i++){

				//Show/hide elements
				if (document.getElementById(showArray[i]).style.display=='block'){ todo='none'; } else { todo='block'; }
			  document.getElementById(showArray[i]).style.display=todo;

				//Change plus/minus image
				if (image){
				  if (todo=='block'){ image_src='Mediafiles/Images/minus.gif'; } else { image_src='Mediafiles/Images/plus.gif'; }
				  document.getElementById(image).src=image_src;
				}
      }
		}
		//Close elements
		if (close_items){
		  var closeArray = new Array();
		  closeArray = close_items.split(',');
		  for (i=0;i<closeArray.length;i++){
			  document.getElementById(closeArray[i]).style.display='none';
      }
	  }
	}

//Open window (src-file, title, width, height)
function openWindow(srcFile, title, width, height){

	if (!width){ width=750; } if (!height){ height=600; } if (!title){ title="Module"; }
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",scrollbars=1, status=0, resizable=1, left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
	window.open(srcFile, title, windowFeatures);

}

//Set the page type in menu frame - used to avoid inserts on welcome pages
function setPageType(pageType){

	try{
		parent.menu.document.getElementById('pageType').value=pageType;
	} 
	
	catch(err){
		var t=setTimeout("setPageType('"+pageType+"')",100);
	}
	
}

//Show Modal Window
function modalWindow(url,title,width,height) {

  	//Sets standard values
  	if (!width){ width=700; } if (!height){ height=600; } if (!title){ title="Module"; }

  	if (window.showModalDialog) {
    	return window.showModalDialog(url,title, "dialogWidth:"+width+"px;dialogHeight:"+height+"px");
  	}
	else {
    	window.open(url,title,'height='+height+',width='+width+',toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
}

//Break out of frameset
function break_frameset(){
	if (self != top) top.location.href = document.location.href;
}


