//------------------------
//FUNCIONES PARA IMAGENES
//------------------------
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_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_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_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];}
}
//----------------------------
//Open Windows
//----------------------------
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//----------------------------

//------------------------
//VALIDACIONES
//------------------------
function soloCaracteres( valor ) {
	var hayNumeros = /\d+/
	return !hayNumeros.test( valor );
}

function valida_caracteres( valor ) {
	totnumeros = true;
	f_temp = 0
	f_temp = valor; 
	for ( i = 0; i < f_temp.length; i++ ) {// mirar todos los caracteres	
		if ( ( f_temp.substring( i, i + 1 ) != "." ) && ( f_temp.substring( i, i + 1 ) != "0" ) && ( f_temp.substring( i, i + 1 ) != "1" ) && ( f_temp.substring( i, i + 1 ) != "2" ) && ( f_temp.substring( i, i + 1 ) != "3" ) && ( f_temp.substring( i, i + 1 ) != "4" ) && ( f_temp.substring( i, i + 1 ) != "5" ) && ( f_temp.substring( i, i + 1 ) != "6" ) && ( f_temp.substring( i, i + 1 ) != "7" ) && ( f_temp.substring( i, i + 1 ) != "8" ) && ( f_temp.substring( i, i + 1 ) != "9" ) ) {
			totnumeros = false;
		}
	} 
	return( totnumeros );
}

function esEmail( email ) {
	var filtro=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	return filtro.test( email );
}

//VALIDACION DE CAMPOS FECHA---------------------------------
function esDigito(sChr) { 
    var sCod = sChr.charCodeAt(0); 
    return ((sCod > 47) && (sCod < 58)); 
} 

function valSep(oTxt) { 
	var bOk = false; 
	var sep1 = oTxt.value.charAt(2); 
	var sep2 = oTxt.value.charAt(5); 
	bOk = bOk || ((sep1 == "-") && (sep2 == "-")); 
	bOk = bOk || ((sep1 == "../index.html") && (sep2 == "../index.html")); 
	return bOk; 
} 

function finMes(oTxt) { 
	var nMes = parseInt(oTxt.value.substr(3, 2), 10); 
	var nAno = parseInt(oTxt.value.substr(6), 10); 
	var nRes = 0; 
	switch (nMes) { 
		 case 1: nRes = 31; break; 
		 case 2: nRes = 28; break; 
		 case 3: nRes = 31; break; 
		 case 4: nRes = 30; break; 
		 case 5: nRes = 31; break; 
		 case 6: nRes = 30; break; 
		 case 7: nRes = 31; break; 
		 case 8: nRes = 31; break; 
		 case 9: nRes = 30; break; 
		 case 10: nRes = 31; break; 
		 case 11: nRes = 30; break; 
		 case 12: nRes = 31; break; 
	} 
	return nRes + (((nMes == 2) && (nAno % 4) == 0)? 1: 0); 
} 

function valDia(oTxt){ 
	var bOk = false; 
	var nDia = parseInt(oTxt.value.substr(0, 2), 10); 
	bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt))); 
	return bOk; 
} 

function valMes(oTxt){ 
	var bOk = false; 
	var nMes = parseInt(oTxt.value.substr(3, 2), 10); 
	bOk = bOk || ((nMes >= 1) && (nMes <= 12)); 
	return bOk; 
} 

function valAno(oTxt){ 
	var bOk = true; 
	var nAno = oTxt.value.substr(6); 
	bOk = bOk && ((nAno.length == 2) || (nAno.length == 4)); 
	if (bOk) { 
 		for (var i = 0; i < nAno.length; i++) { 
  			bOk = bOk && esDigito(nAno.charAt(i)); 
 		} 
	} 
	return bOk; 
} 

function valFecha(oTxt){ 
	var bOk = true; 
	if (oTxt.value != "") { 
		bOk = bOk && (valAno(oTxt)); 
	 	bOk = bOk && (valMes(oTxt)); 
	 	bOk = bOk && (valDia(oTxt)); 
	 	bOk = bOk && (valSep(oTxt)); 
	 	if (!bOk) { 
	  		alert("Fecha inválida"); 
	  		oTxt.value = ""; 
	  		oTxt.focus(); 
	 	} 
	} 
} 

function comparar_fechas(String1,String2) {
	Data1_arr = String1.split('-')
	Data2_arr = String2.split('-')
	String1 = Data1_arr[2] + Data1_arr[1] + Data1_arr[0] 
	String2 = Data2_arr[2] + Data2_arr[1] + Data2_arr[0]
	String1 = parseInt(String1);
	String2 = parseInt(String2);

	if (String1 <= String2) {
		return 0;	
	}
	else{
	    return 1;
	}
}


function validorut(valor1,valor2) {
	rut = document.form1.elements[valor1].value;
	dv = document.form1.elements[valor2].value;
	if ((document.form1.elements[valor1].value=="") && (document.form1.elements[valor2].value==""))
	{
	   alert("Ingrese Rut");
	   document.form1.elements[valor1].focus();
	   return false;
	}
   
	var ElRut = rut.toUpperCase();
	var ElDv = dv.toUpperCase();
	var largo_rut = ElRut.length;
	var largo_dv = ElDv.length;
	var RutC = ElRut+ElDv;
	var rut00 = "000000000";
	if (ElRut.substring(0, 1) == "0"){
    	alert("El Rut que ingresó no\nes válido, por favor\nintente nuevamente\nNo anteponga 0s al Rut");
	    document.form1.elements[valor1].focus();
        return false;
    }
	if (rut00.substring(0, largo_rut) == ElRut){
        alert("El Rut que ingresó no\nes válido, por favor\nintente nuevamente");
        document.form1.elements[valor1].focus();
        return false;
    }
    if (largo_rut==0) {
        alert("El Rut está vacío");
        document.form1.elements[valor1].focus();
        return false;
    }
 	if (largo_dv==0) {
    	 alert("El Dígito Verificador está vacío");
	     document.form1.elements[valor2].focus();
	     return false;	 
	 } else if ( largo_dv == 2 ){
	     alert("El Dígito Verificador sólo debe tener un caracter");
	     document.form1.elements[valor2].focus();
	     return false;
	 }		
	 for(i=0;i<largo_rut;i++){
	    c=ElRut.charAt(i);
	    if (c<"0" || c>"9"){
	       alert("El Rut que ingresó no\nes válido, por favor\nintente nuevamente");
	       document.form1.elements[valor1].focus();
	       return false;
	    }
	 }
	 c=ElDv.charAt(0);
	 if ( (c<"0" || c>"9") && c!="K" ){
	    alert("El Dígito Verificador\n que ingresó no es válido,\n por favor intente nuevamente");
	    document.form1.elements[valor2].focus();
	    return false;
	 }
	
	 var suma=0;
	 var mult=2;
		
	 if (ElDv=="K") ElDv="10";
	 for (i=largo_rut-1;i>=0;i--){
	     c=ElRut.charAt(i);
	     suma+=parseInt(c,10)*mult;
	     mult++;
	     if (mult>7) mult=2;
	  }
	  var calculado=11-suma%11;
	  if (calculado==11) calculado=0;
	  if(parseInt(ElDv)!=calculado){
		 alert("El RUT que ingresó no\nes válido, por favor\nintente nuevamente");
		 document.form1.elements[valor1].focus();
		 return false;
	  }
   
	return true;
}


/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["banner"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("http://www.futuro.cl/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller




/*
function clic() { 
	if (event.button==2) 
		alert("Derechos Reservados IberoAmerican Radio Chile y Radio FMHit"); 
}
document.onmousedown=clic;

function vervideo(ancho,alto,url){
	window.open(url,'AUD','width='+ancho+',height='+alto+',toolbar=no,menubar=no,resizable=yes,location=no,directories=no,status=no,scrollbars=yes,copyhistory=no');
}
*/
