/***************************************************************************
*            functions.js
*
*  Tue Mar 25 17:54:06 2003
*  Copyright  2003  cooly
*  cooly@moby
***************************************************************************/
function OpenNewWindowForPicture(title,picture,width,height){
	pscroll="no"
	if(height>screen.availHeight) {
		height=screen.availHeight-5;
		pscroll="yes";
	}
	if(width>screen.availWidth){
		width=screen.availWidth-5;
		pscroll="yes";	
	}
	myWindow=window.open('',"Galerie_Foto", "width="+width+",height="+height+",location=no,menubar=no,status=0,toolbar=no,scrollbars="+pscroll+",resizable=no");
	myWindow.document.writeln("<html><head><title>"+title+"</title></head><body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
	myWindow.document.writeln("<img src="+picture+" alt='Clic pentru a inchide' onClick='window.close();'></body></html>");
	myWindow.document.close();
}

function my_window(picture)
{
	window.open(picture, "Harta_statiune", "width=497,height=657,location=no,menubar=no,status=no,toolbar=no,scrollbars=no,resizable=no");
}

//scans all forms elemens and sorts out radio options, check options
function validate_form(form)
{
	len = form.length;
	msg = "";
	for (i = 0; i < len; i++)
	{
		base = form.elements[i];
		if (	base.type != "hidden" && base.type != "submit" 
			 && base.type != "reset"  && base.type != "button")
		{
			celem = base.type;
			switch (celem)
			{
				case "radio":
				{
					if (base.checked)
						res = "sub 50 locuri";
					else
					{
						if (form.elements[i+1].checked)
							res = "peste 50 locuri";
						else
							res = "nespecificat";
					}
					msg+= base.name + ": " + res + "\n";
					i++;
					break;
				}
				case "checkbox":
				{
					if (base.checked)
						res = "DA";
					else
						res = "NU";
					msg+= base.name + ": " + res + "\n";
					break;
				}
				default:
					msg+= base.name + ": " + base.value + "\n";
					break;
			}
		}
	}
	window.alert(msg, "Verificare");
	window.name("Verificare");
	return true;
}

function agency_form()
{
	value = document.forms[0].offer_type_id.options[document.forms[0].offer_type_id.selectedIndex].value;
	if (value == 1 || value == 5)
	{
		document.forms[0].info_asig.disabled = false;
		document.forms[0].info_transp.disabled = false;
		document.forms[0].info_masa.disabled = false;
		document.forms[0].info_cazare.disabled = false;
		document.forms[0].destination.disabled = false;
		document.forms[0].country.disabled = false;
		document.forms[0].city.disabled = false;
		document.forms[0].duration.disabled = false;
	}
	if (value == 2)
	{
		document.forms[0].info_asig.disabled = false;
		document.forms[0].info_transp.disabled = true;
		document.forms[0].info_masa.disabled = false;
		document.forms[0].info_cazare.disabled = false;
		document.forms[0].destination.disabled = false;
		document.forms[0].country.disabled = false;
		document.forms[0].city.disabled = false;
		document.forms[0].duration.disabled = false;
	}
	if (value == 3)
	{
		document.forms[0].info_asig.disabled = false;
		document.forms[0].info_transp.disabled = false;
		document.forms[0].info_masa.disabled = true;
		document.forms[0].info_cazare.disabled = true;
		document.forms[0].destination.disabled = false;
		document.forms[0].country.disabled = false;
		document.forms[0].city.disabled = false;
		document.forms[0].duration.disabled = true;
	}
	if (value == 4)
	{
		document.forms[0].info_asig.disabled = false;
		document.forms[0].info_transp.disabled = true;
		document.forms[0].info_masa.disabled = true;
		document.forms[0].info_cazare.disabled = true;
		document.forms[0].destination.disabled = true;
		document.forms[0].country.disabled = true;
		document.forms[0].city.disabled = true;
		document.forms[0].duration.disabled = true;
	}
}

function agency_dest(msg)
{
	val = document.forms[0].destination.options[document.forms[0].destination.selectedIndex].value;
	if (val != 0)
	{
		document.forms[0].country.disabled = true;
		document.forms[0].city.disabled = true;
	}
	else
	{
		document.forms[0].country.disabled = false;
		document.forms[0].city.disabled = false;
		//document.forms[0].submit();
	}
	//document.location.reload();
	
}

function select_hotel(value, htext, hcateg)
{
	sel = new Array();
	sel[hcateg] = "checked";
	
	if (value == 0)
	{
		my = "<table border=0><tr><td><font color=#1c3664 size=1 face=Tahoma>";
		my+= "<strong>Tip cazare:</strong></font></td><td>";
		my+= "<select {S10} name=tipc id=tipc>";
		my+= "<option value=1>Hotel</option>";
		my+= "<option value=2>Pensiune</option>";
		my+= "<option value=3>Cabana</option>";
		my+= "<option value=4>Vila</option>";
		my+= "<option value=5>Motel</option>";
		my+= "</select></td></tr>";
		my+= "<tr><td><font color=#1c3664 size=1 face=Tahoma><strong>Nume:</strong></font></td><td><input size=38 type=text name=hotelname value="+htext+"></td></tr>";
		my+= "<tr><td></td><td><input " + sel[1] + " type=radio name=stars id=stars value=1><img src=img/stars-1.gif></td></tr>";
		my+= "<tr><td></td><td><input " + sel[2] + " type=radio name=stars id=stars value=2><img src=img/stars-2.gif></td></tr>";
		my+= "<tr><td></td><td><input " + sel[3] + " type=radio name=stars id=stars value=3><img src=img/stars-3.gif></td></tr>";
		my+= "<tr><td></td><td><input " + sel[4] + " type=radio name=stars id=stars value=4><img src=img/stars-4.gif></td></tr>";
		my+= "<tr><td></td><td><input " + sel[5] + " type=radio name=stars id=stars value=5><img src=img/stars-5.gif></td></tr>";
		my+= "</table>";
	}
	else
		my = "";
	
	document.getElementById("ohotel").innerHTML = my;
	return true;
}

function ts(val, lang)
{
	fnt1 = "<font face=Tahoma color=\"#003366\" size=1><b>";
	fnt2 = "</b></font>";
	fnt3 = "<font face=Tahoma color=\"#003366\" size=1>";
	fnt4 = "</font>";
	my = "<table border=0 cellpading=0 cellspacing=0 width=\"100%\"><tr><td><table border=0 cellpading=0 cellspacing=1 width=\"100%\"><tr><td width=120>";
	my += "<font face=Tahoma color=\"#003366\" size=2><b>";
	my += lang ? "Chair lift" : "Telescaun"
	my += "</b></font></td><td></td></tr><tr><td>";
	my += lang ? fnt3+"Length(m):"+fnt4 : fnt3+"Lungime(m):"+fnt4;
	my += "</td><td>";
	my = my + fnt1 + document.getElementById('lungime'+val+"-3").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Capacity(pers/h):"+fnt4 : fnt3+"Capacitate(pers/h):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('capacitate'+val+"-3").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Up price(rol):"+fnt4 : fnt3+"Pret urcare(lei):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('pret_urcare'+val+"-3").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Down price(rol):" +fnt4: fnt3+"Pret coborare(lei):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('pret_coborare'+val+"-3").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Up-Down price(rol):"+fnt4 : fnt3+"Pret u-c(lei):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('pret_uc'+val+"-3").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Timetable:"+fnt4 : fnt3+"Orar:"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('orar'+val+"-3").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Phone:"+fnt4 : fnt3+"Telefon:"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('tel'+val+"-3").value + fnt2;
	my += "</td></tr></table></td>";
	my += "<td align=right width=180><table align=right><tr><td><img src=img/sageata-uriasa.png></td></tr></table></td></tr></table>";
	document.getElementById('mytag').innerHTML = my;
}

function tc(val, lang)
{
	fnt1 = "<font face=Tahoma color=\"#003366\" size=1><b>";
	fnt2 = "</b></font>";
	fnt3 = "<font face=Tahoma color=\"#003366\" size=1>";
	fnt4 = "</font>";
	my = "<table border=0 cellpading=0 cellspacing=0 width=\"100%\"><tr><td><table border=0 cellpading=0 cellspacing=1 width=\"100%\"><tr><td width=120>";
	my += "<font face=Tahoma color=\"#003366\" size=2><b>";
	my += lang ? "Car lift" : "Telecabina"
	my += "</b></font></td><td></td></tr><tr><td>";
	my += lang ? fnt3+"Length(m):"+fnt4 : fnt3+"Lungime(m):"+fnt4;
	my += "</td><td>";
	my = my + fnt1 + document.getElementById('lungime'+val+"-4").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Capacity(pers/h):"+fnt4 : fnt3+"Capacitate(pers/h):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('capacitate'+val+"-4").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Up price(rol):"+fnt4 : fnt3+"Pret urcare(lei):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('pret_urcare'+val+"-4").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Down price(rol):" +fnt4: fnt3+"Pret coborare(lei):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('pret_coborare'+val+"-4").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Up-Down price(rol):"+fnt4 : fnt3+"Pret u-c(lei):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('pret_uc'+val+"-4").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Timetable:"+fnt4 : fnt3+"Orar:"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('orar'+val+"-4").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Phone:"+fnt4 : fnt3+"Telefon:"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('tel'+val+"-4").value + fnt2;
	my += "</td></tr></table></td>";
	my += "<td align=right width=180><table align=right><tr><td><img src=img/sageata-uriasa.png></td></tr></table></td></tr></table>";
	document.getElementById('mytag').innerHTML = my;
}

function tski(val, lang)
{
	fnt1 = "<font face=Tahoma color=\"#003366\" size=1><b>";
	fnt2 = "</b></font>";
	fnt3 = "<font face=Tahoma color=\"#003366\" size=1>";
	fnt4 = "</font>";
	my = "<table border=0 cellpading=0 cellspacing=0 width=\"100%\"><tr><td><table border=0 cellpading=0 cellspacing=1 width=\"100%\"><tr><td width=120>";
	my += "<font face=Tahoma color=\"#003366\" size=2><b>";
	my += lang ? "Ski lift" : "Teleschi";
	my += "</b></font></td><td></td></tr><tr><td>";
	my += lang ? fnt3+"Length(m):"+fnt4 : fnt3+"Lungime(m):"+fnt4;
	my += "</td><td>";
	my = my + fnt1 + document.getElementById('lungime'+val+"-1").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Capacity(pers/h):"+fnt4 : fnt3+"Capacitate(pers/h):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('capacitate'+val+"-1").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Up price(rol):"+fnt4 : fnt3+"Pret urcare(lei):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('pret_urcare'+val+"-1").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Down price(rol):" +fnt4: fnt3+"Pret coborare(lei):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('pret_coborare'+val+"-1").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Up-Down price(rol):"+fnt4 : fnt3+"Pret u-c(lei):"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('pret_uc'+val+"-1").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Timetable:"+fnt4 : fnt3+"Orar:"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('orar'+val+"-1").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Phone:"+fnt4 : fnt3+"Telefon:"+fnt4;
	my = my +"</td><td>"+ fnt1 + document.getElementById('tel'+val+"-1").value + fnt2;
	my += "</td></tr></table></td>";
	my += "<td align=right width=180><table align=right><tr><td><img src=img/sageata-uriasa.png></td></tr></table></td></tr></table>";
	document.getElementById('mytag').innerHTML = my;
}

function combo_jump(val)
{
	if (val == 1)
		location.href = "index.php?pn=show_resort&res="
			+ eval('document.forms[0].location.options[document.forms[0].location.selectedIndex].value');
	if (val == 0)
		location.href = "index.php?pn=show_town&res="
			+ eval('document.forms[0].location.options[document.forms[0].location.selectedIndex].value') + "&pm=0";
}

function combo_jump2(val)
{
	location.href = "index.php?pn=edit_sreport&id="
		+ eval('document.forms[0].res.options[document.forms[0].res.selectedIndex].value');
}

function tgon(val, lang)
{
	fnt1 = "<font face=Tahoma color=\"#003366\" size=1><b>";
	fnt2 = "</b></font>";
	fnt3 = "<font face=Tahoma color=\"#003366\" size=1>";
	fnt4 = "</font>";
	my = "<table border=0 cellpading=0 cellspacing=0 width=\"100%\"><tr><td><table border=0 cellpading=0 cellspacing=1 width=\"100%\"><tr><td width=120>";
	my += "<font face=Tahoma color=\"#003366\" size=2><b>";
	my += lang ? "Gondola" : "Telegondola";
	my += "</b></font></td><td></td></tr><tr><td>"
	my += lang ? fnt3+"Length(m):"+fnt4: fnt3+"Lungime(m):"+fnt4;
	my = my + "</td><td>"+ fnt1 + document.getElementById('lungime'+val+"-2").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Capacity(pers/h):"+fnt4: fnt3+"Capacitate(pers/h):"+fnt4;
	my = my + "</td><td>"+ fnt1 + document.getElementById('capacitate'+val+"-2").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Up price(rol):"+fnt4: fnt3+"Pret urcare(lei):"+fnt4;
	my = my + "</td><td>"+ fnt1 + document.getElementById('pret_urcare'+val+"-2").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Down price(rol):"+fnt4: fnt3+"Pret coborare(lei):"+fnt4;
	my = my + "</td><td>"+ fnt1 + document.getElementById('pret_coborare'+val+"-2").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Up-Down price(rol):"+fnt4: fnt3+"Pret u-c(lei):"+fnt4;
	my = my + "</td><td>"+ fnt1 + document.getElementById('pret_uc'+val+"-2").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Timetable:"+fnt4: fnt3+"Orar:"+fnt4;
	my = my + "</td><td>"+ fnt1 + document.getElementById('orar'+val+"-2").value + fnt2;
	my += "</td></tr><tr><td>";
	my += lang ? fnt3+"Phone:"+fnt4: fnt3+"Telefon:"+fnt4;
	my = my + "</td><td>"+ fnt1 + document.getElementById('tel'+val+"-2").value + fnt2;
	my += "</font></td></tr></table></td>";
	my += "<td align=right width=180><table align=right><tr><td><img src=img/sageata-uriasa.png></td></tr></table></td></tr></table>";
	document.getElementById('mytag').innerHTML = my;
}

function tpic(val)
{
	my = document.getElementById('pic'+val).value;
	my2 = document.getElementById('des'+val).value;
	if (my)
	{
		document.getElementById('mytag').innerHTML = "<center><font face=Tahoma size=-1>Partia \""+my2+"\"</font></center><center><img src=\""+my+"\" height=100></center>";
	}
	else
		document.getElementById('mytag').innerHTML = "";
}

var tls = new Image();
tls.src = "img/icons/teleski.png";
var ths = new Image();
ths.src = "img/icons/teleski_high.png";
var tlc = new Image();
tlc.src = "img/icons/telecabina.png";
var thc = new Image();
thc.src = "img/icons/telecabina_high.png";
var tlg = new Image();
tlg.src = "img/icons/gondola.png";
var thg = new Image();
thg.src = "img/icons/gondola_high.png";
var tlss = new Image();
tlss.src = "img/icons/telescaun.png";
var thss = new Image();
thss.src = "img/icons/telescaun_high.png";


function highlight(imgname, but)
{
	document.images[imgname].src = eval(but + ".src");
}

/* Pop a confirmation message */
function conf(msg)
{
	return confirm(msg);
}

function setCheckboxes(the_form, do_check)
{
    var elts      = (typeof(document.forms[the_form].elements['eml[]']) != 'undefined')
                  ? document.forms[the_form].elements['eml[]']
                  : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
                  ? document.forms[the_form].elements['selected_tbl[]']
                  : document.forms[the_form].elements['selected_fld[]'];
    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

function conf(msg)
{
	return confirm(msg);
}

/**
 * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
 * This function is called while clicking links
 *
 * @param   object   the link
 * @param   object   the sql query to submit
 *
 * @return  boolean  whether to run the query or not
 */
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


/**
 * Displays an error message if a "DROP DATABASE" statement is submitted
 * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
 * sumitting it if required.
 * This function is called by the 'checkSqlQuery()' js function.
 *
 * @param   object   the form
 * @param   object   the sql query textarea
 *
 * @return  boolean  whether to run the query or not
 *
 * @see     checkSqlQuery()
 */
function confirmQuery(theForm1, sqlQuery1)
{
    // Confirmation is not required in the configuration file
    if (confirmMsg == '') {
        return true;
    }

    // The replace function (js1.2) isn't supported
    else if (typeof(sqlQuery1.value.replace) == 'undefined') {
        return true;
    }

    // js1.2+ -> validation with regular expressions
    else {
        // "DROP DATABASE" statement isn't allowed
        if (noDropDbMsg != '') {
            var drop_re = new RegExp('DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
            if (drop_re.test(sqlQuery1.value)) {
                alert(noDropDbMsg);
                theForm1.reset();
                sqlQuery1.focus();
                return false;
            } // end if
        } // end if

        // Confirms a "DROP/DELETE/ALTER" statement
        //
        // TODO: find a way (if possible) to use the parser-analyser
        // for this kind of verification
        // For now, I just added a ^ to check for the statement at
        // beginning of expression
        
        //var do_confirm_re_0 = new RegExp('DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
        //var do_confirm_re_1 = new RegExp('ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
        //var do_confirm_re_2 = new RegExp('DELETE\\s+FROM\\s', 'i');
        var do_confirm_re_0 = new RegExp('^DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
        var do_confirm_re_1 = new RegExp('^ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
        var do_confirm_re_2 = new RegExp('^DELETE\\s+FROM\\s', 'i');
        if (do_confirm_re_0.test(sqlQuery1.value)
            || do_confirm_re_1.test(sqlQuery1.value)
            || do_confirm_re_2.test(sqlQuery1.value)) {
            var message      = (sqlQuery1.value.length > 100)
                             ? sqlQuery1.value.substr(0, 100) + '\n    ...'
                             : sqlQuery1.value;
            var is_confirmed = confirm(confirmMsg + ' :\n' + message);
            // drop/delete/alter statement is confirmed -> update the
            // "is_js_confirmed" form field so the confirm test won't be
            // run on the server side and allows to submit the form
            if (is_confirmed) {
                theForm1.elements['is_js_confirmed'].value = 1;
                return true;
            }
            // "DROP/DELETE/ALTER" statement is rejected -> do not submit
            // the form
            else {
                window.focus();
                sqlQuery1.focus();
                return false;
            } // end if (handle confirm box result)
        } // end if (display confirm box)
    } // end confirmation stuff

    return true;
} // end of the 'confirmQuery()' function


/**
 * Displays an error message if the user submitted the sql query form with no
 * sql query, else checks for "DROP/DELETE/ALTER" statements
 *
 * @param   object   the form
 *
 * @return  boolean  always false
 *
 * @see     confirmQuery()
 */
function checkSqlQuery(theForm)
{
    var sqlQuery = theForm.elements['sql_query'];
    var isEmpty  = 1;

    // The replace function (js1.2) isn't supported -> basic tests
    if (typeof(sqlQuery.value.replace) == 'undefined') {
        isEmpty      = (sqlQuery.value == '') ? 1 : 0;
        if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
            isEmpty  = (theForm.elements['sql_file'].value == '') ? 1 : 0;
        }
        if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
            isEmpty  = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
        }
        if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
            isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
        }
    }
    // js1.2+ -> validation with regular expressions
    else {
        var space_re = new RegExp('\\s+');
        isEmpty      = (sqlQuery.value.replace(space_re, '') == '') ? 1 : 0;
        // Checks for "DROP/DELETE/ALTER" statements
        if (!isEmpty && !confirmQuery(theForm, sqlQuery)) {
            return false;
        }
        if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
            isEmpty  = (theForm.elements['sql_file'].value.replace(space_re, '') == '') ? 1 : 0;
        }
        if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
            isEmpty  = (theForm.elements['sql_localfile'].value.replace(space_re, '') == '') ? 1 : 0;
        }
        if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
            isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
            isEmpty  = (theForm.elements['id_bookmark'].selectedIndex == 0);
        }
        if (isEmpty) {
            theForm.reset();
        }
    }

    if (isEmpty) {
        sqlQuery.select();
        alert(errorMsg0);
        sqlQuery.focus();
        return false;
    }

    return true;
} // end of the 'checkSqlQuery()' function


/**
 * Displays an error message if an element of a form hasn't been completed and
 * should be
 *
 * @param   object   the form
 * @param   string   the name of the form field to put the focus on
 *
 * @return  boolean  whether the form field is empty or not
 */
function emptyFormElements(theForm, theFieldName)
{
    var isEmpty  = 1;
    var theField = theForm.elements[theFieldName];
    // Whether the replace function (js1.2) is supported or not
    var isRegExp = (typeof(theField.value.replace) != 'undefined');

    if (!isRegExp) {
        isEmpty      = (theField.value == '') ? 1 : 0;
    } else {
        var space_re = new RegExp('\\s+');
        isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
    }
    if (isEmpty) {
        theForm.reset();
        theField.select();
        alert(errorMsg0);
        theField.focus();
        return false;
    }

    return true;
} // end of the 'emptyFormElements()' function


/**
 * Ensures a value submitted in a form is numeric and is in a range
 *
 * @param   object   the form
 * @param   string   the name of the form field to check
 * @param   integer  the minimum authorized value
 * @param   integer  the maximum authorized value
 *
 * @return  boolean  whether a valid number has been submitted or not
 */
function checkFormElementInRange(theForm, theFieldName, min, max)
{
    var theField         = theForm.elements[theFieldName];
    var val              = parseInt(theField.value);

    if (typeof(min) == 'undefined') {
        min = 0;
    }
    if (typeof(max) == 'undefined') {
        max = Number.MAX_VALUE;
    }

    // It's not a number
    if (isNaN(val)) {
        theField.select();
        alert(errorMsg1);
        theField.focus();
        return false;
    }
    // It's a number but it is not between min and max
    else if (val < min || val > max) {
        theField.select();
        alert(val + errorMsg2);
        theField.focus();
        return false;
    }
    // It's a valid number
    else {
        theField.value = val;
    }

    return true;
} // end of the 'checkFormElementInRange()' function


/**
 * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
 * checkboxes is consistant
 *
 * @param   object   the form
 * @param   string   a code for the action that causes this function to be run
 *
 * @return  boolean  always true
 */
function checkTransmitDump(theForm, theAction)
{
    var formElts = theForm.elements;

    // 'zipped' option has been checked
    if (theAction == 'zip' && formElts['zip'].checked) {
        if (!formElts['asfile'].checked) {
            theForm.elements['asfile'].checked = true;
        }
        if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
            theForm.elements['gzip'].checked = false;
        }
        if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
            theForm.elements['bzip'].checked = false;
        }
    }
    // 'gzipped' option has been checked
    else if (theAction == 'gzip' && formElts['gzip'].checked) {
        if (!formElts['asfile'].checked) {
            theForm.elements['asfile'].checked = true;
        }
        if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
            theForm.elements['zip'].checked = false;
        }
        if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
            theForm.elements['bzip'].checked = false;
        }
    }
    // 'bzipped' option has been checked
    else if (theAction == 'bzip' && formElts['bzip'].checked) {
        if (!formElts['asfile'].checked) {
            theForm.elements['asfile'].checked = true;
        }
        if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
            theForm.elements['zip'].checked = false;
        }
        if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
            theForm.elements['gzip'].checked = false;
        }
    }
    // 'transmit' option has been unchecked
    else if (theAction == 'transmit' && !formElts['asfile'].checked) {
        if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
            theForm.elements['zip'].checked = false;
        }
        if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
            theForm.elements['gzip'].checked = false;
        }
        if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
            theForm.elements['bzip'].checked = false;
        }
    }

    return true;
} // end of the 'checkTransmitDump()' function


/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
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
	
	//currentColor = theCells[0].style.backgroundColor;
	//domDetect    = true;

    // 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;
        }
        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...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
function setCheckboxes(the_form, do_check)
{
    var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
                  ? document.forms[the_form].elements['selected_db[]']
                  : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
		  ? document.forms[the_form].elements['selected_tbl[]']
		  : document.forms[the_form].elements['selected_fld[]'];
    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

/**
  * Allows moving around inputs/select by Ctrl+arrows
  *
  * @param   object   event data   
  */
function onKeyDownArrowsHandler(e) {
    e = e||window.event;
    var o = (e.srcElement||e.target);
    if (!o) return;
    if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") return;
    if (!e.ctrlKey) return;
    if (!o.id) return;

    var pos = o.id.split("_");
    if (pos[0] != "field" || typeof pos[2] == "undefined") return;

    var x = pos[2], y=pos[1];
    
    // skip non existent fields
    for (i=0; i<10; i++)
    {
        switch(e.keyCode) {
            case 38: y--; break; // up
            case 40: y++; break; // down
            case 37: x--; break; // left
            case 39: x++; break; // right
            default: return;
        }

        var id = "field_" + y + "_" + x;
        var nO = document.getElementById(id);
        if (nO) break;
    }
    
    if (!nO) return;
    nO.focus();
    if (nO.tagName != 'SELECT') {
        nO.select();
    }
    e.returnValue = false;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
