// $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;     

}



