function calculaCUPS(Cod_REE, Cod_Cli){

	var Letras = "TRWAGMYFPDXBNJZSQVHLCKE";

	var Cod_Caracter = Cod_REE + "00000" + Cod_Cli;
	var Cod = Cod_Caracter % 529;
	
	var Cociente = Math.floor(Cod/23); 
	var Resto = Cod % 23; 
		//alert ("Cod: " + Cod + " Cociente: " + Cociente + " Resto: " + Resto);  
	var LetraCociente = Letras.substring(Cociente,Cociente+1);
	var LetraResto = Letras.substring(Resto,Resto+1);
		//alert(LetraCociente + LetraResto);
	return LetraCociente + LetraResto;
}
function actualizaCUPS(obxecto, Cod_REE, Obx_Cli){ 
	var obx		= document.getElementById(obxecto);
	var Cod_Cli = document.getElementById(Obx_Cli).value; 
	//alert (Cod_REE);
	var texto 	= calculaCUPS(Cod_REE, Cod_Cli);
	obx.value=texto;
	if (Cod_Cli.length<7){
		alert("El código de cliente debe tener 7 dígitos");
		document.getElementById(Obx_Cli).focus();	
	}
}


//-----------------------------------------------------------------------------------	

function roll_over(img_name, img_src){
   document[img_name].src = img_src;}

function resizeIframe(idIframe){
	var miIframe=document.getElementById(idIframe);
	if (miIframe.contentDocument){ // firefox
		miIframe.height = miIframe.contentDocument.height+20;
	}else{ // IE
		miIframe.style.height = miIframe.contentWindow.document.body.scrollHeight+20;} 	
	} 
//-----------------------------------------------------------------------------------	


	function elDOM(elemento){
		var dom = (document.getElementById) ? true : false;
		var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
		var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
		var ns4 = (document.layers && !dom) ? true : false;
		var ie4 = (document.all && !dom) ? true : false;
		var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;

		if (nodyn) return;
		referencia = (ns4)? document.elemento.document: (ie4)? document.all[elemento]: (ie5||ns5)? document.getElementById(elemento): null;
		estilo = (ns4)? document.elemento: referencia.style; 
		if (ie4||ie5||ns5) {	
		}
		return referencia; 
	}
	function elDOM2(elemento){
		var dom = (document.getElementById) ? true : false;
		var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
		var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
		var ns4 = (document.layers && !dom) ? true : false;
		var ie4 = (document.all && !dom) ? true : false;
		var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;

		if (nodyn) return;
		referencia = (ns4)? document.elemento.document: (ie4)? document.all[elemento]: (ie5||ns5)? document.getElementById(elemento): null;
		estilo = (ns4)? document.elemento: referencia.style; 
		if (ie4||ie5||ns5) {	
		}
		return estilo; 
	}


//-----------------------------------------------------------------------------------	

// Scrollers width here (in pixels)
var scrollerwidth="325px"

// Scrollers height here
var scrollerheight="210px"

// Scrollers speed here (larger is faster 1-10)
var scrollerspeed=1

// Scrollers content goes here! Keep all of the message on the same line!
var scrollercontent=""

var pauseit=1

// Change nothing below!
scrollerspeed=(document.all)? scrollerspeed : 1 //Math.max(1, scrollerspeed-1) //slow speed down by 1 for NS
var copyspeed=scrollerspeed
var iedom=document.all||document.getElementById
var actualheight=''
var cross_scroller, ns_scroller
var pausespeed=(pauseit==0)? copyspeed: 0

function populate(){
	if (iedom){
		cross_scroller=document.getElementById? document.getElementById("noticia") : document.all.noticia
		cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
		cross_scroller.innerHTML=scrollercontent
		actualheight=cross_scroller.offsetHeight
	}else if (document.layers){
		ns_scroller=document.ns_scroller.document.ns_scroller2
		ns_scroller.top=parseInt(scrollerheight)+8
		ns_scroller.document.write(scrollercontent)
		ns_scroller.document.close()
		actualheight=ns_scroller.document.height}
	lefttime=setInterval("scrollscroller()",20)
}

function scrollscroller(){
	if (iedom){
		if (parseInt(cross_scroller.style.top)>(actualheight*(-1)+8))
			cross_scroller.style.top=parseInt(cross_scroller.style.top)-copyspeed+"px"
		else
			cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
	}else if (document.layers){
		if (ns_scroller.top>(actualheight*(-1)+8))
			ns_scroller.top-=copyspeed
		else
			ns_scroller.top=parseInt(scrollerheight)+8}
}

function novas_scroll(texto_novas, scr_width, scr_height, scr_speed){
	scrollercontent=texto_novas
	scrollerwidth=scr_width
	scrollerheight=scr_height
	scrollerspeed=scr_speed
	
	window.onload=populate
	if (iedom||document.layers){
		with (document){
			if (iedom){
				write('<div id="noticiero" style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed">')
				write('<div id="noticia" style="position:absolute;left:20px;top:0px;width:80%">')
				write('</div></div>')
			}else if (document.layers){
				write('<ilayer width='+scrollerwidth+' height='+scrollerheight+' name="ns_scroller">')
				write('<layer name="ns_scroller2" width='+scrollerwidth+' height='+scrollerheight+' left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed"></layer>')
				write('</ilayer>')}
		}
	}
}
