
function delete_items_select(cname){
   while (cname.options.length>0)
    {
	 deleteIndex=cname.options.length-1;
	 cname.options[deleteIndex]=null;
	}
}

function add_select_item(cname, thevalue, thetext, theindex){
	var myOption=new Option();
	myOption.text=thetext;
	myOption.value=thevalue;
	ind = (theindex==-1 ? cname.length : theindex);
	cname.options[ind]=myOption;
}

function exists_in_select( cname, theitem ){
	exists = false;
	var c = cname;
	var i;
	for(i=0; i<c.length; i++){
		if (c[i].value == theitem) return true;
	}
	return false;
}

function valid_email_address(src){
	var x = src;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(x);
}

function valid_time(src){
	var x = src;
	p = x.indexOf(':',0);
	if (p==-1) return false;
	h = x.substring(0,p);
	if ( !(h>=0 && h<=23) ) return false;
	m = x.substring(p+1, x.length);
	if ( !(m>=0 && m<=59) ) return false;
	return true;
}

/**
 * Checks/unchecks all rows
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 * @param   string   basename of the element
 * @param   integer  min element count
 * @param   integer  max element count
 *
 * @return  boolean  always true
 */
// modified 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
// - set the other checkboxes (if available) too
function setCheckboxesRange(the_form, do_check, basename)
{
    vControl = document.getElementsByName( basename );
	for (var i = 0; i < vControl.length; i++) {
        if (typeof(vControl[i]) != 'undefined') {
	        vControl[i].checked = do_check;
        }
    }

    return true;
} // end of the 'setCheckboxesRange()' function


function setCheckbox(the_form, basename, the_value)
{
    vControl = document.getElementsByName( basename );
	for (var i = 0; i < vControl.length; i++) {
        if (typeof(vControl[i]) != 'undefined') {
	        vControl[i].checked = the_value;
        }
    }

    return true;
} // end of the 'setCheckboxesRange()' function

// added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
//   copy the checked from left to right or from right to left
//   so it's easier for users to see, if $cfg['ModifyAtRight']=true, what they've checked ;)
function copyCheckboxesRange(the_form, the_name, the_clicked)
{
    if (typeof(document.forms[the_form].elements[the_name]) != 'undefined' && typeof(document.forms[the_form].elements[the_name + 'r']) != 'undefined') {
        if (the_clicked !== 'r') {
            if (document.forms[the_form].elements[the_name].checked == true) {
                document.forms[the_form].elements[the_name + 'r'].checked = true;
            }else {
                document.forms[the_form].elements[the_name + 'r'].checked = false;
            }
        } else if (the_clicked == 'r') {
            if (document.forms[the_form].elements[the_name + 'r'].checked == true) {
                document.forms[the_form].elements[the_name].checked = true;
            }else {
                document.forms[the_form].elements[the_name].checked = false;
            }
       }
    }
}

function open_sized_window(src, width, height) {
	win = window.open( src, 'cWin','height=' + height + ', width=' + width + ', top=50, left=50, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');
	win.focus();
}

function open_window(src) {
	win = window.open( src, 'cWin','top=50, left=50, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
	win.focus();
}