var correctos = new Array('0','1','2','3','4','5','6','7','8','9','.');
 
      /***
      * var global estado     >> variable booleana, true si el caracter introducido es correcto y false en caso contrario
      * var global codigoTecla   >>  valor ASCII de la tacla pulsada para cada navegador (son diferentes)
      * var global cadenaTecla  >>  cadena que representa a la tecla pulsada (igual para todos los navegadores)
      */
      var estado=false;
      var codigoTecla, cadenaTecla;
 
      /**
      * function pulsada >> funcion principal  >> comprueba la tecla pulsada y la escribe o no
      * si es correcta      >>  retorna true al manejador de eventos de la caja de texto >> se escribe el caracter
      * si es incorrecta   >>  retorna false al manejador de eventos de la caja de texto >> no se escribe el caracter
      */
           
      function pulsada(e)
      {
 
          estado=false
 
          if(document.all)
          {
              codigoTecla = event.keyCode
              cadenaTecla = (String.fromCharCode(event.keyCode));
          }
          else if(document.layers)
          {
              codigoTecla = e.which
              cadenaTecla = String.fromCharCode(e.which);
          }
          else if(document.getElementById)
          {
              codigoTecla = (window.Event) ? e.which : e.keyCode;
              cadenaTecla=(String.fromCharCode(codigoTecla));
          }
 
          for(i=0;i<correctos.length;i++)
          {
              if(cadenaTecla==correctos[i])
                  estado=true;
          }
 
          if(estado==false)
          {
              if(document.all)
                  event.returnValue = false;
              else
                  return false;
          }
          
          return true;
      }
 

		function trim(sString)
		{
	  		while (sString.substring(0,1) == ' ')
	  		{
	        	sString = sString.substring(1, sString.length);
	  		}
	  		while (sString.substring(sString.length-1, sString.length) == ' ')
	  		{
	        	sString = sString.substring(0,sString.length-1);
	  		}
	  		return sString;
	 
		}
 
		
		
function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
 
    return (true)
  } else {
    return (false);
  }
}
 

function Lineas(tr,color,action,clickcolor){
 	  
      tr = document.getElementById(tr);
 
      if(tr.style.background != clickcolor){
           if(action == 'over'){
                 tr.style.background = color;
           }else{
                  if(action == 'out'){
                      tr.style.background = color;                      
                  }else{
                    tr.style.background = clickcolor;
      tr.style.color = "#FFFFFF"; 
                  }
           }
 
      }else{
           if(action == 'click'){
                tr.style.background = color;
  tr.style.color = "#000000";
  
           }else{
                tr.style.background = clickcolor;
  
    }
 
  
      }
 
}


function validar(msg){
 
  if(confirm(msg))
      "";
  else
      return false;


}

function encode(str) {

        var result = "";
	var i = 0;
	var sextet = 0;
	var leftovers = 0;
	var octet = 0;

        if((str != '')&&(str != undefined)){

          for (i=0; i < str.length; i++) {
  		octet = str.charCodeAt(i);
  		switch( i % 3 )
  		{
  			case 0:
  			{
  				sextet = ( octet & 0xFC ) >> 2 ;
  				leftovers = octet & 0x03 ;
  
  				// sextet contains first character in quadruple
  				break;
  			}
  
  			case 1:
  			{
  				sextet = ( leftovers << 4 ) | ( ( octet & 0xF0 ) >> 4 );
  				leftovers = octet & 0x0F ;
  
  				// sextet contains 2nd character in quadruple
  				break;
  			}
  
  			case 2:
  			{
  				sextet = ( leftovers << 2 ) | ( ( octet & 0xC0 ) >> 6 ) ;
  				leftovers = ( octet & 0x3F ) ;
  
  				// sextet contains third character in quadruple
  				// leftovers contains fourth character in quadruple
  				break;
  			}
  		}
  
  		result = result + base64ToAscii(sextet);
  
  		// don't forget about the fourth character if it is there
  		if( (i % 3) == 2 )
  		{
  			result = result + base64ToAscii(leftovers);
  		}
  
  	}
  
  	// figure out what to do with leftovers and padding
  	switch( str.length % 3 )
  	{
  		case 0:
  		{
  			// an even multiple of 3, nothing left to do
  			break ;
  		}
  		case 1:
  		{
  			// one 6-bit chars plus 2 leftover bits
  			leftovers =  leftovers << 4 ;
  			result = result + base64ToAscii(leftovers);
  			result = result + "==";
  			break ;
  		}
  		case 2:
  		{
  			// two 6-bit chars plus 4 leftover bits
  			leftovers = leftovers << 2 ;
  			result = result + base64ToAscii(leftovers);
  			result = result + "=";
  			break ;
  		}
  	}
  
  	return result;
	
        }
}


function base64ToAscii(c)
{
	var theChar = 0;
	
	if (0 <= c && c <= 25)
	{
		theChar = String.fromCharCode(c + 65);
	}
	else if (26 <= c && c <= 51)
	{
		theChar = String.fromCharCode(c - 26 + 97);
	}
	else if (52 <= c && c <= 61)
	{
		theChar = String.fromCharCode(c - 52 + 48);
	}
	else if (c == 62)
	{
		theChar = '+';
	}
	else if( c == 63 )
	{
		theChar = '/';
	}
	else
	{
		theChar = String.fromCharCode(0xFF);
	}

	return theChar;
}


function decode(str) {
	var result = "";
	var i = 0;
	var x;
	var shiftreg = 0;
	var count = -1;

	
	for (i=0; i < str.length; i++) {
		c = str.charAt(i);
		if ('A' <= c && c <= 'Z')
			x = str.charCodeAt(i) - 65;
		else if ('a' <= c && c <= 'z')
			x = str.charCodeAt(i) - 97 + 26;
		else if ('0' <= c && c <= '9')
			x = str.charCodeAt(i) - 48 + 52;
		else if (c == '+')
			x = 62;
		else if (c == '/')
			x = 63;
		else
			continue;

		count++;

		switch (count % 4)
		{
		case 0:
			shiftreg = x;
			continue;
		case 1:
			v = (shiftreg<<2) | (x >> 4);
			shiftreg = x & 0x0F;
			break;
		case 2:
			v = (shiftreg<<4) | (x >> 2);
			shiftreg = x & 0x03;
			break;
		case 3:
			v = (shiftreg<<6) | (x >> 0);
			shiftreg = x & 0x00;
			break;
		}

		if (!is_binary && (v < 32 || v > 126) && (v != 0x0d) && (v != 0x0a)) 
		{
			result = result + "<";
			result = result + "0123456789ABCDEF".charAt((v/16)&0x0F);
			result = result + "0123456789ABCDEF".charAt((v/1)&0x0F);
			result = result + ">";
		}
		else
			result = result + String.fromCharCode(v);

	}
	return result.toString();
}


function getFormatSeg(segundos)
{

	minutos=segundos/60;

	horas= Math.floor(minutos/60);

	minutos2=minutos%60;

	segundos_2=segundos%60%60%60;

	if(minutos2<10)	minutos2='0'+minutos2;

	if(segundos_2<10)	segundos_2='0'+segundos_2;
	
	if(segundos<60)
 		     
 		     { /* segundos */
  
 		     	resultado= Math.round(segundos)+' Segundos';

		     } 
		     
		     else if(segundos>60 && segundos<3600)
		     
		     {/* minutos */
  
		     	resultado= minutos2+':'+segundos_2+' Minutos';
 
		     }
		     
		     	else{/* horas */
  
		     		resultado= horas+':'+minutos2+':'+segundos_2+' Horas';
 				}






	return resultado;

}

function cambiarIdioma(idioma){
	
	ingles = document.getElementById("idiomaIngles");
	espanol = document.getElementById("idiomaEspanol");
	
	if(idioma == 1){		
		ingles.style.display = 'none';
		espanol.style.display = '';
	}else if(idioma == 2){
		ingles.style.display = '';
		espanol.style.display = 'none';
	}
	
	var oEditor = FCKeditorAPI.GetInstance('descripcion'+idioma);
    if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
    {
        oEditor.MakeEditable();
    }
	
}



function enteros() {
   if (window.event.keyCode < 48 || window.event.keyCode  > 57)
       return false;
}

function quitarEspacios(){
    var key = window.event ? event.keyCode : event.which;
	if (key == 32)
       return false;
}


function mayusculas(campo){

      campo.value = trim(campo.value.toUpperCase());
}

function parsearConstante(campo){
	mayusculas(campo);
	campo.value = campo.value.replace(" ","");
}


function Confirmar(msg,url){

	mensajes = document.getElementById("alertas");
	
	
	/*texto = '<div id="inner">';
	texto += '<table border="0" align="center" cellpadding="0" cellspacing="0" class="LaTableta">';
	texto += '<tr>';
	texto += '<td class="Pregunta">';
    texto += msg;
    texto += '</td></tr><tr><td>';
    texto += '<p><a href="'+url+'"><img src="/imagenes/button_ok.gif" width="76" height="28" class="BotonIzquierdo" border=\"0\" /></a><img src="/imagenes/button_cancel.gif" width="76" height="28" class="BotonDerecho" onClick="mensajes.style.display=\'none\'"/></p>';
    texto += '<p>&nbsp;</p>';
    texto += '<p>&nbsp;</p>';
    texto += '</tr>';
    texto += '</table>';
    texto += '</div>';
   */
    

	
	
	texto = '    <table width="250" border="0" align="center" cellpadding="0" cellspacing="0">';
  	texto += '			<tr id="handle" style="cursor:move">';
    texto += '				<td><img src="/imagenes/publiCornerTopLeft.gif" width="19" height="25" /></td>';
	texto += '		    	<td background="/imagenes/publiCornerTop.gif"><img src="/imagenes/pixt.gif" width="140" height="21" /></td>';
	texto += '		    	<td><img src="/imagenes/publiCornerTopRight.gif" width="27" height="25" /></td>';
	texto += '		  </tr>';
	texto += '		  <tr >	';		    
	texto += '		    <td background="/imagenes/publiCornerLeft2.gif" width="19" bgcolor="#FFFFFF" ></td>';
	texto += '		    <td bgcolor="#FFFFFF" >';		
	texto += '		            <table  align="center" width="100%">';
	texto += '		              <tr>';
	texto += '		                <td align="center" width="50" valign="top"><img src="/imagenes/signitoPregunta.gif"></td>';	
	texto += '		                <td align="left" width="200"><div id="Pregunta">'+msg+'</div></td>';	
	texto += '					  </tr>';
	texto += '		              <tr>';
	texto += '		                <td colspan="2" align="center"><a href="'+url+'"><img src="/imagenes/button_ok.gif" width="76" height="27" border="0"/></a> ';
	texto += '		                <img src="/imagenes/button_cancel.gif" width="76" height="27" onClick="mensajes.style.display=\'none\'" style="cursor:pointer" /></td>';
	texto += '		              </tr>';
	texto += '		            </table>';
	texto += '			</td>';
	texto += '		    		<td background="/imagenes/publiCornerRight.gif"  width="19"></td>';
	texto += '		  		</tr>';
	texto += '		  		<tr>';
	texto += '		    		<td><img src="/imagenes/publiCornerBottomLeft.gif" width="19" height="24" /></td>';
	texto += '		    		<td background="/imagenes/publiCornerBottom.gif"><img src="/imagenes/pixt.gif" width="140" height="24" /></td>';
	texto += '		    		<td><img src="/imagenes/publiCornerBottomRight.gif" width="27" height="24" /></td>';
	texto += '		  		</tr>';
	texto += '			</table>';
	
  
    mensajes.style.display = '';
	mensajes.innerHTML = texto;
	
	var theHandle = document.getElementById("handle");				
	Drag.init(theHandle, mensajes);
   	
	
	centrar('alertas');
	document.getElementById('alertas').style.display = "block"; 
}


function Alerta(msg){

	

	texto = '    <table width="300" border="0" align="center" cellpadding="0" cellspacing="0">';
  	texto += '			<tr id="handle" style="cursor:move">';
    texto += '				<td><img src="/imagenes/publiCornerTopLeft.gif" width="19" height="25" /></td>';
	texto += '		    	<td background="/imagenes/publiCornerTop.gif"><img src="/imagenes/pixt.gif" width="140" height="21" /></td>';
	texto += '		    	<td><img src="/imagenes/publiCornerTopRight.gif" width="27" height="25" /></td>';
	texto += '		  </tr>';
	texto += '		  <tr >	';		    
	texto += '		    <td background="/imagenes/publiCornerLeft2.gif" width="19" bgcolor="#FFFFFF" ></td>';
	texto += '		    <td bgcolor="#FFFFFF" >';		
	texto += '		            <table  align="center" width="100%">';
	texto += '		              <tr>';
	texto += '		                <td align="center" width="50" valign="top"><img src="/imagenes/popupExclamacion.gif"></td>';	
	texto += '		                <td align="left" width="250"><div id="PreguntaAlert">'+msg+'</div></td>';	
	texto += '					  </tr>';
	texto += '		              <tr>';
	texto += '		                <td align="center" colspan="2"><img src="/imagenes/button_ok.gif" width="76" height="27" border="0" onClick="mensajes.style.display=\'none\'" style="cursor:pointer" /></a></td>';	
	texto += '		              </tr>';
	texto += '		            </table>';
	texto += '			</td>';
	texto += '		    		<td background="/imagenes/publiCornerRight.gif"  width="19"></td>';
	texto += '		  		</tr>';
	texto += '		  		<tr>';
	texto += '		    		<td><img src="/imagenes/publiCornerBottomLeft.gif" width="19" height="24" /></td>';
	texto += '		    		<td background="/imagenes/publiCornerBottom.gif"><img src="/imagenes/pixt.gif" width="140" height="24" /></td>';
	texto += '		    		<td><img src="/imagenes/publiCornerBottomRight.gif" width="27" height="24" /></td>';
	texto += '		  		</tr>';
	texto += '			</table>';
	
  
    
	mensajes = document.getElementById("alertas");
	mensajes.style.display = '';
	mensajes.innerHTML = texto;
	
	var theHandle = document.getElementById("handle");				
	Drag.init(theHandle, mensajes);
	
	
	centrar('alertas');	
}



function centrar(div,noHeight) { 

  
     var IpopLeft = (document.body.offsetWidth - document.getElementById(div).offsetWidth)/2;
     document.getElementById(div).style.left=IpopLeft +  +document.body.scrollLeft+'px';
     
     if(noHeight==undefined){     
        document.getElementById(div).style.top=200+'px';     
        document.getElementById(div).style.display = "";      
     }
     
     window.scrollTo(1,1);  

} 


function centrarMenu() { 

	 div = "menu2";
  
     var IpopLeft = (document.body.offsetWidth - document.getElementById(div).offsetWidth)/2 -125;
     document.getElementById(div).style.left=IpopLeft +  +document.body.scrollLeft+'px';
     
}




function centrarTodo(){
	centrar("alertas");
	centrarMenu();
}

/* dice si cadena es url (http://... ) o no                                     */
function ValidarURL(cadena)
{                   
										// DECLARACION DE CONSTANTES
	var http = "http://";              	// protocolo HTTP
								   		// DECLARACION DE VARIABLES
	var es_url;                        	// cadena es url o no
	if(cadena.length <= 7)             	// INICIO
		es_url = false;                 // no cabe "http://*"
	else
		es_url = http.indexOf(cadena.substring(0, 7)) != - 1; // lee "http://*"
	return(es_url);
}//end function url



/**
*COMIENZA FUNCION VALIDAR FECHA EN JAVASCRIPT
*/
	function esDigito(sChr)
	{
		var sCod = sChr.charCodeAt(0);
		return ((sCod > 47) && (sCod < 58));
	}

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

	function finMes(oTxt){
		var nMes = parseInt(oTxt.value.substr(0, 2), 10);
		var nRes = 0;
		switch (nMes){
			case 1: nRes = 31; break;
			case 2: nRes = 29; 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;
	}

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

	function valMes(oTxt){
		var bOk = false;
		var nMes = parseInt(oTxt.value.substr(0, 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();
			}
		}
	}
/**
*FIN VALIDACION FECHA EN JAVASCRIPT
*/

moverFecha = function(idto, idfrom){
	$(idto).value = $(idfrom).value;
}