function select_all(){
	var main_form=document.main_form;
	n= main_form.elements.length;
	for (i=0;i<n;i++)
	{
		element = main_form.elements[i];
		if (element.type =="checkbox") element.checked = true;
	}
}
function activate_selected(){
	document.main_form.cmd.value='activate';
	document.main_form.submit();
}
function deactivate_selected(){
	document.main_form.cmd.value='deactivate';
	document.main_form.submit();
}

function delete_selected(){
	document.main_form.cmd.value='delete';
	document.main_form.submit();
}
function send_to_a_friend(url){
	open("/stf.php?"+url);
}
function invert_selection()
{
	var main_form=document.main_form;
	n= main_form.elements.length;
	for (i=0;i<n;i++)
	{
		element = main_form.elements[i];
		if (element.type =="checkbox") element.checked = ! element.checked;
	}
}

function nameIsUsed(username){
	url="/check.php?table=users&username="+username;
	returnValue = window.showModalDialog(url,"dialogWidth:0;dialogHeight:0");
	if (returnValue=='true')
		return true;
	return false;

}

function confirmLink(theLink, theSqlQuery)
{
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function


function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
			alert(newColor);
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
//	alert(theAction+'=>'+newColor);
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }

    theRow.className=newColor;

    return true;
} // end of the 'setPointer()' function

function setCheckboxes(the_form, do_check)
{
    var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
                  ? document.forms[the_form].elements['selected_db[]']
                  : document.forms[the_form].elements['selected_tbl[]'];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        } // end for
    } else {
        elts.checked        = do_check;
    } // end if... else

    return true;
} // end of the 'setCheckboxes()' function


/**
  * Checks/unchecks all options of a <select> element
  *
  * @param   string   the form name
  * @param   string   the element name
  * @param   boolean  whether to check or to uncheck the element
  *
  * @return  boolean  always true
  */
function setSelectOptions(the_form, the_select, do_check)
{
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    } // end for

    return true;
} // end of the 'setSelectOptions()' function
function SelectAll(form)
{
	n= document.forms[form].elements.length;
	for (i=0;i<n;i++)
	{
		element = document.forms[form].elements[i];
		if (element.type =="checkbox") element.checked = true;
	}
}
function InvertSelection(form)
{
	n= document.forms[form].elements.length;
	for (i=0;i<n;i++)
	{
		element = document.forms[form].elements[i];

		if (element.type =="checkbox") 		if (!element.disabled) element.checked = ! element.checked;
	}
}
function CountSelected(form)
{
	n= document.forms[form].elements.length;
	sc = 0;
	for (i=0;i<n;i++)
	{
		element = document.forms[form].elements[i];
		if (element.type =="checkbox") 	
		if ((!element.disabled)&&(element.checked))  sc++
	}
		return sc;
}

