/*
 * Funciones de formularios
 */
 
/*function uploadfile(pNameField, pCtrlName, pFileName, pPath){
var sFeatures = 'toolbar=0,status=0,width=350,height=150';
	window.open('uploadfile.php?nf='+pNameField+'&cn=' + pCtrlName+'&fn='+pFileName+'&pt='+pPath+'', 'UploadFile', sFeatures);
}*/

/**
 * 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)
{
	for (var i = 0; i < document.forms[the_form].elements[basename].length; i++) {
        if (typeof(document.forms[the_form].elements[basename][i]) != 'undefined') {
            document.forms[the_form].elements[basename][i].checked = do_check;
        }
/*        if (typeof(document.forms[the_form].elements[basename + i + 'r']) != 'undefined') {
            document.forms[the_form].elements[basename + i + 'r'].checked = do_check;
        }*/
    }

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


function setCheckbox(the_form, basename, the_value)
{
    for (var i = 0; i < document.forms[the_form].elements[basename].length; i++) {
        if (typeof(document.forms[the_form].elements[basename][i]) != 'undefined') {
	        if (document.forms[the_form].elements[basename][i].value == the_value) {
	            document.forms[the_form].elements[basename][i].checked = !document.forms[the_form].elements[basename][i].checked;
			}
        }
/*        if (typeof(document.forms[the_form].elements[basename + i + 'r']) != 'undefined') {
            document.forms[the_form].elements[basename + i + 'r'].checked = do_check;
        }*/
    }

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

function logout(){
	if(confirm('Do you really want to logout?')){
		window.location.href = "start_session.php?act=logout";
	}
}

function initPage() {
	$('divPage').className = (screen.width >= 1024)?"wideScreen":"";
	$nBodyHeight = $('divBody').getHeight();
	if(($('divTop').getHeight() + $nBodyHeight) > $('divLeftMenu').getHeight())
		$('divLeftMenu').style.height = ($('divTop').getHeight() + $nBodyHeight) + "px";
	if($nBodyHeight > $('divBanners').getHeight())
		$('divBanners').style.height = $('divBody').getHeight() + "px";
}

function updateList(){
	
	frmList.submit();
}

function submitForm(oForm){

	if(isValid(oForm))
		oForm.submit();
	else{
		return false;
	}
}

function isValid(oForm){
	
	switch(oForm.name){
		case "frmContact":
			/*if($('agency').getValue() == ""){
				alert("Error agency name requiered");
				$('agency').focus();
				return false;
			}*/
			if($('first_name').getValue() == ""){
				alert("Error first name requiered");
				$('first_name').focus();
				return false;
			}
			if($('last_name').getValue() == ""){
				alert("Error last name requiered");
				$('last_name').focus();
				return false;
			}
			if(!isEmail($('email').getValue())){
				alert("Error wrong email format");
				$('email').focus();
				return false;
			}
			/*if($('phone_mobile').getValue() == ""){
				alert("Error telephone requiered");
				$('phone_mobile').focus();
				return false;
			}*/
		break;
	}
	return true;
}