// $Id: scripts.js,v 1.10 2004/02/06 15:41:50 k-fish Exp $

//used in settings for password
function testLength(frm_name, field_name, min_length, err_mess, zero_length, allow_continue) {
    if(document.forms[frm_name].elements[field_name].value.length >= min_length || 
       (zero_length == true && document.forms[frm_name].elements[field_name].value.length == 0) ) return true;
    if(allow_continue == true) {
	return window.confirm(err_mess);
    } else {
	alert(err_mess);
	return false;
    }
}

function strcmp(frm_name, field_name1, field_name2, err_mess, allow_continue) {
    if(document.forms[frm_name].elements[field_name1].value == document.forms[frm_name].elements[field_name2].value) return true;
    if(allow_continue == true) {
	return window.confirm(err_mess);
    } else {
	alert(err_mess);
	return false;
    }
}

function openHelpWin(url){
    hw=window.open(url,'helpWin','width=750,height=575,dependent=yes,location=no,menubar=no,toolbar=yes,status=no,scrollbars=yes');
    hw.focus();
}

function openWin(url,w,h,title){
    hw=window.open(url,title,'width='+w+',height='+h+',dependent=yes,location=no,menubar=no,toolbar=yes,status=no,scrollbars=yes,resizable=yes');
    hw.focus();
}

function show_holi(id, sid){
    selectorUrl = "urlaub.php?action=details&uid="+id+"&"+sid;
    selector = open(selectorUrl,"selectorWindow","width=450,height=450,screenX=0,screenY=0");
    selector.focus();
}
 
function MoveOption (MoveFrom, MoveTo) {
    //tested on:
    // - Win2k: MSIE5.5, MSIE6, NN6.2.1, NN6.2.2
    // - Mac: NN4.7/MacOS9.0.4 and MSIE5/MacOS9.0.4
    // - others: Mozilla0.9.8/FreeBSD4.5, Mozilla snapshot 2002040410 on Linux 2.4.18 
    var name;
    var ID;
    var i;
    var SelectFrom = eval('window.document.nd.elements[\"'+MoveFrom+'[]\"]');
    var SelectTo = eval('window.document.nd.elements[\"'+MoveTo+'[]\"]');
    var SelectedIndex = SelectFrom.options.selectedIndex;

    if (SelectedIndex == -1) {
	alert(err_no_person);
    }
    else {
	for (i=0; i<SelectFrom.options.length; i++) {
	    if(SelectFrom.options[i].selected) {
		name = SelectFrom.options[i].text;
		ID = SelectFrom.options[i].value;
		SelectFrom.options[i] = null;
		SelectTo.options[SelectTo.options.length]=new Option (name,ID);
		i--;
	    }
	}

	//begin of sorting stuff, it could be very slooow
	//needs JS1.1 and higher
	var sorting = new Array();		
	for (i=0; i<SelectTo.options.length; i++) {
	    sorting[i] = SelectTo.options[i].text+"###"+SelectTo.options[i].value;
	}
	sorted = sorting.sort();
	for (i=0; i<SelectTo.options.length; i++) {
	    var tmp = sorted[i].split("###");
	    name = tmp[0];
	    ID = tmp[1];
	    SelectTo.options[i]=new Option (name,ID);
	}
	// end of sorting stuff
    }
    return;
}

function testAvail(call) {

    if(call=="new"){
	fday = document.nd.elements["start_day"];
	day = fday.options[fday.selectedIndex].value;
	fmonth = document.nd.elements["start_month"];
	month = fmonth.options[fmonth.selectedIndex].value;
	fyear = document.nd.elements["start_year"];
	year = fyear.options[fyear.selectedIndex].value;
    }
    else{
	fday = document.nd.elements["serial_start_day"];
	day = fday.options[fday.selectedIndex].value;
	fmonth = document.nd.elements["serial_start_month"];
	month = fmonth.options[fmonth.selectedIndex].value;
	fyear = document.nd.elements["serial_start_year"];
	year = fyear.options[fyear.selectedIndex].value;
    }

    ids = "";
    separator = ".";
    to_form = document.nd.elements["participants[]"];
    app_start = document.nd.elements["appointment_start"];
    start = app_start.options[app_start.selectedIndex].value;
    app_end = document.nd.elements["appointment_end"];
    end = app_end.options[app_end.selectedIndex].value;
    for(i=0; i < to_form.length; i++) {
	if(ids!="") ids = ids+separator+to_form.options[i].value;
	else ids = to_form.options[i].value;
    }
    if(ids=="") {
	alert("You must select at least one participant!");
    }
    else {
	params = "parts="+ids+"&datum="+day+month+year+"&from="+start+"&to="+end;
	colwin=window.open("collisions.php?"+params,"collisions","width=700,height=300,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,dependent=yes");
	colwin.focus();
    }
    return;
}

// Added for printing by Paulo Orvalho
function printWindow(){
    bV = parseInt(navigator.appVersion);
    if (bV >= 4) window.print();
}


// Added to disable form options
function milestone_toggle(){
   if(window.document.np.milestone.checked){    
      window.document.np.EndMonth.value = window.document.np.StartMonth.value;
      window.document.np.EndDay.value = window.document.np.StartDay.value;
      window.document.np.EndYear.value = window.document.np.StartYear.value;
      window.document.np.EndMonth.disabled = true;
      window.document.np.EndDay.disabled = true;
      window.document.np.EndYear.disabled = true;
  } 
  else {
      window.document.np.EndMonth.disabled = false;
      window.document.np.EndDay.disabled = false;
      window.document.np.EndYear.disabled = false;
  }
  return;     

}

// file manager functions

var activeDropDown

function contextMenu(id)
{

id.oncontextmenu=showmenu(id)
id.onclick=hidemenu();

}

function showmenu(id)
{
//activeDropDown.style.visibility = 'hidden';
this.leftPos = (id != null) ? findPos('y', getObj('icon' + id) ) : this.leftPos
this.topPos  = (id != null) ? findPos('x', getObj('icon' + id) ) : this.topPos
getObj('contextmenu' + id).style.top            = this.topPos  + 16  + 'px'
getObj('contextmenu' + id).style.left           = this.leftPos - 124 + 'px'
getObj('contextmenu' + id).style.visibility = 'visible'
return false;
}

function hidemenu()
{
//	activeDropDown.style.visibility = 'hidden';
}

function calender_invisible()
{
	getObj('calender').style.visibility = 'hidden'
}

function customDate()
{
	getObj(this.activeDropDown + 'date').value = this.calenderDate
		getObj(this.activeDropDown + 'time').value = this.calenderTime
		calender_invisible()
}

function getObj(objId)
{
	return document.getElementById(objId);
}

function findPos(dir, obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += dir == 'y' ? obj.offsetLeft : obj.offsetTop
				obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += dir == 'y' ? obj.x : obj.y;
	return curleft;
}

function jump(e){
	var firingobj=ie5? event.srcElement : e.target
		if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
			if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode
				if (firingobj.getAttribute("target"))
					window.open(firingobj.getAttribute("url"),firingobj.getAttribute("target"))
				else
					window.location=firingobj.getAttribute("url")
		}
}

var currentFileBoxID;
//function Show(me, What, cname) 
//onClick="javascript: Show('filebox51','contextmenu51','index.php?chgDirId=51&')"
function Show(me, What, targ, newWin) 
{

	// me = filebox51
	// What  = contextmenu51 
	var a, i;

	currentFileBoxID = me; /* filebox..*/

	thabox = getObj(me);
	thamenu = getObj(What);
	var thacolor = "blue";

	if(thabox.style.backgroundColor == thacolor) {
		if(newWin) {
			openWin(targ,800,600);
		} else {
			window.location = targ;
		}
	}

	clearContextMenus(); // hide all menus

	//if(arguments.length == 2) {
		cname = 'filebox';
	//}

	if (!document.getElementsByTagName) 
		return;
	a = document.body.getElementsByTagName("div");
	if (a.length == 0) 
		return;
	if (typeof a[0].style != 'object') 
		return;
	if (typeof a[0].style.display == 'undefined') 
		return;
	for (i = 0; i < a.length; i++) {
		if (a[i].className != cname) {
			continue;
		}

		if (a[i].id != me) {
			a[i].style.backgroundColor = "white"; 
//			thabox.style.backgroundColor = "white";
			/*
			a[i].style.display = "none";
			thabox.style.backgroundColor = "none";
			*/
		} else  {
			
			thamenu.style.display = "block";
			thamenu.style.visibility = "visible";
			
			thabox.style.backgroundColor = thacolor;
			//a[i].style.backgroundColor = thacolor;

		}
	}

	return true;
}

function clearContextMenus()
{

	var b;
	// reset selected
	b = document.body.getElementsByTagName("div");

	for (i = 0; i < b.length; i++) {

		if (b[i].className != 'contextmenu') {

		} else {
			b[i].style.visibility = 'hidden';
		}
	}
}

function clearFileBoxes()
{
alert('clearingo');
	var b;
	// reset selected
	b = document.body.getElementsByTagName("div");

	for (i = 0; i < b.length; i++) {

		if (b[i].className != 'filebox') {

		} else {
			b[i].backgroundColor = 'green';
		}
	}
}

function Reset(id) 
{
	//currentFileBoxID = '';
	return true;
}

function setDefault()
{
	return true;
	if(currentFileBoxID == null) {

	if (!document.getElementsByTagName) 
		return;
	a = document.body.getElementsByTagName("div");
	if (a.length == 0) 
		return;
	if (typeof a[0].style != 'object') 
		return;
	if (typeof a[0].style.display == 'undefined') 
		return;
	for (i = 0; i < a.length; i++) {
		if (a[i].className != 'contextmenu') {
			continue;
		}

		if (a[i].id != 'contextmenuHelp') {
			/* a[i].style.backgroundColor = "white"; thabox.style.borderColor = "white";
			*/
			a[i].style.display = "none";
			/*
			a[i].style.display = "none";
			thabox.style.backgroundColor = "none";
			*/
		} else  {

			a[i].style.display = "block";
			a[i].style.visibility = "visible";
			/*
			thabox.style.backgroundColor = "silver";
			thabox.style.borderColor = "black";
			*/
		}
	}

	}

	return true;

}

function prevButton()
{
	if(history.previous != '') {
		// show backbutton
		alert('ada previous');
	} else {
		alert('tidak ada previous');
	}
}

function nextButton()
{	if(history.next != '') {
	// show forward active button
		alert('ada next');
	} else {
	// show non-active
		alert('tidak ada next');
	}
}
