//funciones varias para la web pública

//funciones para limitar tamaño del TEXTAREA
var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<br><span id="'+theform.toString()+'">'+thelimit+'</span></b> caracteres restantes.'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
}
}

/* ************ FUNCIONES PARA CAJA DE NOTICIAS *************************************************/

var delay = 2000; //set delay between message change (in miliseconds)
var maxsteps=30; // number of steps to take to change from start color to endcolor
var stepdelay=40; // time in miliseconds of a single step
//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
var startcolor= new Array(255,255,255); // start color (red, green, blue)
var endcolor=new Array(0,0,0); // end color (red, green, blue)

// apertura y cierre de las noticias, se puede poner CSS
begintag='<div>'; //set opening tag, such as font declarations
closetag='</div>';
// fin de apertura y cierre

var fwidth='180px'; //set scroller width
var fheight='150px'; //set scroller height

var fadelinks=1;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.

///No need to edit below this line/////////////////


var ie4=document.all&&!document.getElementById;
var DOM2=document.getElementById;
var faderdelay=0;
var index=0;


/*Rafael Raposo edited function*/
//function to change content
function changecontent(){
  if (index>=fcontent.length)
    index=0
  if (DOM2){
    document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")"
    document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag
    if (fadelinks)
      linkcolorchange(1);
    colorfade(1, 15);
  }
  else if (ie4)
    document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;
  index++
}

// colorfade() partially by Marcio Galli for Netscape Communications.  ////////////
// Modified by Dynamicdrive.com

function linkcolorchange(step){
  var obj=document.getElementById("fscroller").getElementsByTagName("A");
  if (obj.length>0){
    for (i=0;i<obj.length;i++)
      obj[i].style.color=getstepcolor(step);
  }
}

/*Rafael Raposo edited function*/
var fadecounter;
function colorfade(step) {
  if(step<=maxsteps) {	
    document.getElementById("fscroller").style.color=getstepcolor(step);
    if (fadelinks)
      linkcolorchange(step);
    step++;
    fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  }else{
    clearTimeout(fadecounter);
    document.getElementById("fscroller").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";
    setTimeout("changecontent()", delay);
	
  }   
}

/*Rafael Raposo's new function*/
function getstepcolor(step) {
  var diff
  var newcolor=new Array(3);
  for(var i=0;i<3;i++) {
    diff = (startcolor[i]-endcolor[i]);
    if(diff > 0) {
      newcolor[i] = startcolor[i]-(Math.round((diff/maxsteps))*step);
    } else {
      newcolor[i] = startcolor[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
    }
  }
  return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}

/********************* FIN DE FUNCIONES PARA CAJA DE NOTICIAS *********************************/
/**********************************************************************************************/
// Definimos el nivel de opacamiento de la imagen
var nivel = 40 // Menor valor más transparente se hace la imagen   
// Definimos la velocidad para el efecto, en milisegundos   
// no se recomienda valores superiores a 50   
var velocidad = 50   
  
/* **** NO EDITAR **** */
var i = 99
function opacarImagen() {

if ((efecto == 'on') && (i >= nivel)) {
    /* Cambiamos el valor de la propiedad filter hasta el nivel definido
    este cambio se hará en forma gradual ya que la función
    se ejecuta a una cierta velocidad. Este cambio servirá para el navegador IE
    y otros que reconozcan la propiedad filter */
    document.getElementById('img'+nImg).style.filter = 'alpha(Opacity='+i+')'
    /* Lo mismo hacemos para los navegadores que acepten la propiedad MozOpacity
    en este caso el valor de esta propiedad es del tipo 0.n por lo que agregamos
    la cadena '0.' a la variable i */
    document.getElementById('img'+nImg).style.MozOpacity = '0.'+i
    // Restamos 10 al valor actual de i
    i = i-10
    // Ejecutamos la función a la velocidad definida
    setTimeout("opacarImagen()",velocidad)
}

else if ((efecto == 'off') && (i <= 100)) {
    /* Volvemos a definir para ambas propiedades el valor mínimo de opacamiento,
    es decir 100 para filter y 1 para MozOpacity */
    document.getElementById('img'+nImg).style.filter = 'alpha(Opacity=100)'
    document.getElementById('img'+nImg).style.MozOpacity = '1'
    i = 99
}

} // Fin de la Función opacarImagen()

/********************* FUNCIÓN PARA EFECTO FADE-OUT EN IMÁGENES *****************************/
/***************** FIN FUNCIÓN PARA EFECTO FADE-OUT EN IMÁGENES *****************************/

/**************** FUNCIÓN PARA ABRIR POP-UP ****************************************/

//función que abre una ventana pop-up
//se usa principalmente para obtener el Tipo de Pago del pedido en Oferta
function abrePopupPars(URL,windowwdth,windowhght){
   window.open(URL,"ventana1","width="+windowwdth+",height="+windowhght+",TOP=50,LEFT=200,scrollbars=YES,resizable=NO")
}
/*************** FIN FUNCIÓN PARA ABRIR POP-UP *************************************/
