function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

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("oversrc");
        if (!oversrc) {
            continue;
        }
        x[i].oversrc_img = new Image;
        x[i].oversrc_img.src = oversrc;
        x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
        x[i].onmouseout = new Function("SimpleSwap(this);");
        x[i].setAttribute("origsrc", x[i].src);
    }
}

function getStyle(el,styleProp){
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function str_replace(busca, repla, orig){
	str 	= new String(orig);
	rExp	= "/"+busca+"/g";
	rExp	= eval(rExp);
	newS	= String(repla);
	str = new String(str.replace(rExp, newS));
	return str;
}

function stristr( haystack, needle) {
    var pos = 0;
    haystack += '';
    pos = haystack.toLowerCase().indexOf( (needle+'').toLowerCase() );
    if( pos == -1 ){
    	return false;
    }
    else{
	return true;
    }
}

function strtr(str,from,to) {

    var fr = '', i = 0, j = 0, lenStr = 0, lenFrom = 0;
    var tmpFrom = [];
    var tmpTo   = [];
    var ret = '';
    var match = false;

    if (typeof from === 'object') {
        this.krsort(from);
        for (fr in from) {
            tmpFrom.push(fr);
            tmpTo.push(from[fr]);
        }

        from = tmpFrom;
        to   = tmpTo;
    }
    
    lenStr  = str.length;
    lenFrom = from.length;
    for (i = 0; i < lenStr; i++) {
        match = false;
        for (j = 0; j < lenFrom; j++) {
            if (str.substr(i, from[j].length) == from[j]) {
                match = true;

                // Fast forward
                i = (i + from[j].length)-1;
                
                break;
            }
        }
        
        if (false !== match) {
            ret += to[j];
        } else {
            ret += str[i];
        }
    }

    return ret;
}

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 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 vaciar(dato){
	dato.value = "";
}

function comprobarEmail(texto){

	var mailres = true;            
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
	var arroba = texto.indexOf("@",0);
	
	if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
	
	var punto = texto.lastIndexOf(".");      
	for (var contador = 0 ; contador < texto.length ; contador++){
		if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
			mailres = false;
			 break;
		}
	}

	if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
		mailres = true;
	else
		mailres = false;

	return mailres;
}

function comprobarFecha(Cadena){

	var Fecha = new String(Cadena);
	var RealFecha= new Date();

	var Ano = new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length));
	var Mes = new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")));
	var Dia = new String(Fecha.substring(0,Fecha.indexOf("/")));
	
	var ok = 1;

	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){  
		ok = 0;
	}  
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){  
		ok = 0;
	}  
	if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){  
		ok = 0;
	} 
	
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {  
		if (Mes==2 && Dia > 28 || Dia>30) {  
			ok = 0;
		}  
	}
	
	if(ok == 1){
		return true;
	}
	else{
		return false;
	}

}

/********** Cargar funciones **************/


Cufon.replace("h1",{hover:true,hoverables:{a:true},fontFamily:"Trajan Pro"});
Cufon.replace("h2",{hover:true,hoverables:{a:true},fontFamily:"Trajan Pro"});
Cufon.replace("h3",{hover:true,hoverables:{a:true},fontFamily:"Trajan Pro"});
Cufon.replace("h4",{hover:true,hoverables:{a:true},fontFamily:"Trajan Pro"});

addLoadEvent(SimpleSwapSetup);



