function generarNumeroAleatorio(max) {
  return Math.round(Math.random()*(max-1)+1);
}

function posicionarPie() {
	navegador = navigator.appName;
	version = navigator.userAgent;
	capaPie = document.getElementById("pie");
	capaPieFalso = document.getElementById("pieFalso");
	posicion = 0;
	
	if (navegador == "Microsoft Internet Explorer"){
		if(!/MSIE 6.0/i.test(navigator.userAgent)){
			capaPie.style.visibility = "visible";
			capaPieFalso.style.visibility = "hidden";
			posicion = document.documentElement.scrollTop;
		}else{
			capaPie.style.visibility = "hidden";
		}
	}else{
		capaPie.style.display = "block";
		capaPieFalso.style.display = "none";
		posicion = window.pageYOffset;
	}

	if(!(/MSIE 6.0/i.test(navigator.userAgent))){
		capaPie = document.getElementById("pie");
		capaPie.style.position = "absolute";
		capaPie.style.bottom = 0 - posicion +"px";
		setTimeout('posicionarPie()',100);
	}
}
function updateCheckbox(hiddenField, checkField) {
	var hField = document.getElementById(hiddenField);
	var cField = document.getElementById(checkField);
	if(cField.checked) {
		hField.value = 'S';
	} else {
		hField.value = 'N';
	}
}

function updateCheckboxOnSearch(hiddenField, checkField) {
	var hField = document.getElementById(hiddenField);
	var cField = document.getElementById(checkField);
	if(cField.checked) {
		hField.value = 'S';
	} else {
		hField.value = 'I';
	}
}

function createFckeditor(id, texto, altura) {
	if(!altura) { altura = 300; }
	var ruta = "fckeditor/";
	var rutaSkin = ruta+"editor/skins/silver/";
	var oFCKeditor = new FCKeditor(id) ;
	oFCKeditor.BasePath	= ruta;
				
	oFCKeditor.ToolbarSet = "Ibercon";
	oFCKeditor.Height = altura;
	oFCKeditor.Value = texto;
	oFCKeditor.Create() ;	
}

function displayWindow(title, url, w ,h) {
    displayWindow(title, url, w ,h, false);
}

function displayWindow(title, url, w ,h, centered) {  
    var w, h, l, t;
    //w = 250;
    //h = 250;
    if (centered) {
        //l = Math.floor((screen.width - w)/2);
        l = Math.floor((document.body.clientWidth - w)/2);        
        if (l < 0) l = 0;  //para soportar windows mas altas que el espacio visible
        t = Math.floor((document.body.clientHeight - h)/2);        
        if (t < 0) t = 0; //para soportar windows mas anchas que el espacio visible
        //alert('<l, t>: <' + l + ', ' + t + '>');
    } else {    
        l = screen.width/4;
        t = screen.height/4 - 10; //se resta 10 para subirla un poco a la ventana        
    }

    t = t + document.body.scrollTop;
	window.open();
}


function openCenteredWindow(w, sUrl, sName, dialogW, dialogH, sFeatures) {
	var wleft = Math.floor((window.screen.width - dialogW)/2);
	var wtop = Math.floor((window.screen.height - dialogH)/2);
	var res = w.open(sUrl, sName, sFeatures+",height="+dialogH+",width="+dialogW+",left="+wleft+",top="+wtop+",screenX="+wleft+",screenY="+wtop);
	return res;
}


function openCenteredWindow1(sUrl) {
	window.open(sUrl);
}


function cambiarIdioma(idioma,ruta){
	if (!ruta){
		ruta = "";
	}
	var url = ruta+"cambiarIdioma";
	var parametros = "lang="+idioma;
	
	new Ajax.Request(url, {method:'post', parameters: parametros, onComplete: recargarPagina});
}
function recargarPagina (){
	window.location.reload();
}