function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function replaceSubstring(inputString, fromString, toString) {
	var temp = inputString;
	if (fromString == '') {
	return inputString;
	}
	if (toString.indexOf(fromString) == -1){
	while (temp.indexOf(fromString) != -1){
	 var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	 var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	 temp = toTheLeft + toString + toTheRight;
	}
	}
	else{
	var midStrings = new Array('~', '`', '_', '^', '#');
	var midStringLen = 1;
	var midString = '';
	while (midString == '') {
	 for (var i=0; i < midStrings.length; i++) {
	    var tempMidString = '';
	    for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
	    if (fromString.indexOf(tempMidString) == -1) {
	       midString = tempMidString;
	       i = midStrings.length + 1;
	    }
	 }
	}
	while (temp.indexOf(fromString) != -1) {
	 var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	 var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	 temp = toTheLeft + midString + toTheRight;
	}
	while (temp.indexOf(midString) != -1) {
	 var toTheLeft = temp.substring(0, temp.indexOf(midString));
	 var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
	 temp = toTheLeft + toString + toTheRight;
	}
	}
	return temp;
}

function vprint(idioma,plana,parametros) {
	window.open("/vprint.php?Idioma="+idioma+"&Plana="+plana+"&"+parametros, "","resizable=1,SCROLLBARS=YES,HEIGHT=600,WIDTH=766");
}

function imprimir(){
	window.print();
	window.close();
}

function paginadoListado(mipagina) {
	var ff=window.document.bava;
	ff.pagina.value=mipagina;
	ff.submit();
}

function getRadio(ctrl){
	for(i=0;i<ctrl.length;i++)
		if(ctrl[i].checked) return ctrl[i].value;
}

function elimina_acentos(cadena){
	tofind = "ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ,;.:-_´¨+*`[]'¡?¿ºª!·$%&/()=?¿|@#~’";
	replac = "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn                                   ";
	return(strtr(cadena,tofind,replac));
}

function Arregla_Rewrite(texto) {
	texto = elimina_acentos(texto);
	texto = str_replace('"',"",texto);
	texto = str_replace("  "," ",texto);
	texto = str_replace("  "," ",texto);
	texto = str_replace("  "," ",texto);
	texto = str_replace("  "," ",texto);
	texto = str_replace(" ","-",texto);
	return texto;
}

function SimpleSwap(el, which) {
    el.src = el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup() {
    var x = document.getElementsByTagName("img");
    for (var i = 0; i < x.length; i++) {
        var oversrc = x[i].getAttribute("longdesc");
        if (!oversrc) {
            continue;
        }
        x[i].oversrc_img = new Image;
        x[i].oversrc_img.src = oversrc;
        x[i].onmouseover = new Function("SimpleSwap(this,'longdesc');");
        x[i].onmouseout = new Function("SimpleSwap(this);");
        x[i].setAttribute("origsrc", x[i].src);
    }
}

function RedimensionarHome(){
	var empresa = window.document.getElementById("home-empresa").clientHeight;
	var campos = window.document.getElementById("home-campos").clientHeight;
	var novedades = window.document.getElementById("home-novedades").clientHeight;

	if((empresa != campos) || (empresa != novedades) || (campos != novedades)){
		if(empresa >= campos && empresa >= novedades){
			window.document.getElementById("home-campos").style.height = empresa + "px";
			window.document.getElementById("home-novedades").style.height = empresa + "px";
		}
		if(campos >= empresa && campos >= novedades){
			window.document.getElementById("home-empresa").style.height = campos + "px";
			window.document.getElementById("home-novedades").style.height = campos + "px";
		}
		if(novedades >= empresa && novedades >= campos){
			window.document.getElementById("home-empresa").style.height = novedades + "px";
			window.document.getElementById("home-campos").style.height = novedades + "px";
		}

	}

}
