// JavaScript Document

function manda_transformacion(comentario){
//OJO que el que transforma en caracteres basura las vocales con tilde
//y la ñ es el php, es decir no valdria de nada que la  base de datos 
//este configurada con utf-8(que acepta todo tipo de caracteres), porque antes
//de grabar la data el php ya lo tranformo en caracteres basura 
//por lo tanto se grabara caracteres basura.
	
	
	 comentario=comentario.replace(/#/g, "#35;");
	 comentario=comentario.replace(/á/g, "aacute;");//no le pongo el & delante 
	                                                //de aacute porque
													//cuando llega a php 
													//al toque ya lo reconoce como
													//caracter con tilde y
													//lo transforma en caracter 
													//basura
													
	 comentario=comentario.replace(/Á/g, "Aacute;");//igual para todos los demas
	 comentario=comentario.replace(/é/g, "eacute;");
	 comentario=comentario.replace(/É/g, "Eacute;");
	 comentario=comentario.replace(/í/g, "iacute;");
	 comentario=comentario.replace(/Í/g, "Iacute;");
	 comentario=comentario.replace(/ó/g, "oacute;");
	 comentario=comentario.replace(/Ó/g, "Oacute;");
	 comentario=comentario.replace(/ú/g, "uacute;");
	 comentario=comentario.replace(/Ú/g, "Uacute;");
	 comentario=comentario.replace(/ñ/g, "nacute;");
	 comentario=comentario.replace(/Ñ/g, "Nacute;");
	 
	 comentario=comentario.replace(/ü/g, "uuuml;");
	 comentario=comentario.replace(/Ü/g, "UUuml;");
	 comentario=comentario.replace(/À/g, "Agrave;");
	 comentario=comentario.replace(/È/g, "Egrave;");
	 comentario=comentario.replace(/Ì/g, "Igrave;");
	 comentario=comentario.replace(/Ò/g, "Ograve;");
	 comentario=comentario.replace(/Ù/g, "Ugrave;");
	 comentario=comentario.replace(/Î/g, "Icirc;");
	 comentario=comentario.replace(/Ô/g, "Ocirc;");
	 comentario=comentario.replace(/ô/g, "ocirc;");	 
	 comentario=comentario.replace(/º/g, "ordm;");
	 comentario=comentario.replace(/°/g, "deg;");
	 comentario=comentario.replace(/&/g, "amp;");
 
	 comentario=comentario.replace(/²/g, "sup2;");
	 comentario=comentario.replace(/'/g, "#39;");
	 comentario=comentario.replace(/"/g, "#34;");
	 comentario=comentario.replace(/`/g, "#96;");
	 
	 
	 
	 do {   comentario = comentario.replace('+','#43;');
	 } while(comentario.indexOf('+') >= 0);
	
	 comentario=comentario.replace(/´/g, "#180;");
	 comentario=comentario.replace(/¿/g, "iquest;");	
	
     return comentario;	
	 
}




function recibe_transformacion(comentario){
	 //cuando el php regrese la data de
	 //la base de datos tranformamos esta vez 
	 //en forma inversa, es decir regeneramos 
	 //las vocales con  tildes y la ñ
	 comentario=comentario.replace(/aacute;/g, "á");
	 comentario=comentario.replace(/Aacute;/g, "Á");
	 comentario=comentario.replace(/eacute;/g, "é");
	 comentario=comentario.replace(/Eacute;/g, "É");
	 comentario=comentario.replace(/iacute;/g, "í");
	 comentario=comentario.replace(/Iacute;/g, "Í");
	 comentario=comentario.replace(/oacute;/g, "ó");
	 comentario=comentario.replace(/Oacute;/g, "Ó");
	 comentario=comentario.replace(/uacute;/g, "ú");
	 comentario=comentario.replace(/Uacute;/g, "Ú");
	 comentario=comentario.replace(/nacute;/g, "ñ");
	 comentario=comentario.replace(/Nacute;/g, "Ñ");
	 comentario=comentario.replace(/uuuml;/g, "ü");
	 comentario=comentario.replace(/UUuml;/g, "Ü");
	 comentario=comentario.replace(/Egrave;/g,"È");
	 comentario=comentario.replace(/Ograve;/g, "Ò");
	 comentario=comentario.replace(/Ocirc;/g, "Ô");
	 //comentario=comentario.replace(/ordm;/g, "º");
	// comentario=comentario.replace(/amp;/g, "&");
	 //comentario=comentario.replace(/acute;/g, "´");
	 
	 
	 comentario=comentario.replace(/034;/g, "\"");
	 comentario=comentario.replace(/039;/g, "\'");
	 comentario=comentario.replace(/sup2;/g, "²");
	 comentario=comentario.replace(/alt35;/g, "#");
	 //comentario=comentario.replace(/alt38;/g, "&");
	 //comentario=comentario.replace(/#43;/g, "+");
	 comentario=comentario.replace(/iquest;/g, "¿");
     return comentario;	
}



function cambia_marco(objeto, clase_normal, clase_sobre) {
	//alert(objeto.className);

     //alert(objeto+"|"+clase_normal+"|"+clase_sobre)
   
	var clase = objeto.className;
	if(clase==clase_normal)
	{
		objeto.className = clase_sobre;	
	}
	if(clase==clase_sobre)
	{
		objeto.className = clase_normal;	
	}	
	
}


function captura_id(formulario){
	
	//donde la variable formulario esta 
	//commpuesta por: document.nombre_formulario.nombre_checkbox
	
	
	chk=formulario;
	
	
	 lista_id="";
	 
		 //si es null es porque no existe ningun checkbox
		 if(chk==null){
			 
			 return lista_id;
			 
		 }//
	 
	 
           
		if(typeof(chk.length)=="undefined"){//si es indefined es que solo hay 1 checkbox
		                                    //que no se comportara como un arreglo
											//es decir necesitamos minimo 2 checkbox con
		                                    //el mismo nombre para forma un arreglo de 
											//controles
				if(chk.checked){
					lista_id=chk.value;							
				}
	  }else{
           		
				for (i=0;i<chk.length;i++)
           		{
                   if (chk[i].checked)
                   {
                           lista_id=lista_id + chk[i].value + " ";
                   }
           		}//end for
	  }//end if
	  
          return trim(lista_id);
	
}

//FUNCION TRIM QUE TE PERMITE 
//ELIMINAR LOS ESPACIOS EN BLANCO
function trim(cadena)
{
	/*
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	*/
	
	return cadena;
}



//FUNCION UBICAR OPTION
function posicionar_option(idoption, name_cbo){
    	
	var obj=document.getElementById(name_cbo);
	for (var opcombo=0;	opcombo < obj.length;	opcombo++){ 
	     
		 if(obj[opcombo].value==idoption){ 
			obj.selectedIndex=opcombo; 
			
			break;
		 } //end if
	}//end for

}


//VALIDAR QUE EL TEXTBOX SOLO ACEPTE NUMEROS, EL PUNTO Y EL BACKSPACE
//ESTO SE TIENE QUE PONER EN LAS CAJAS DE 
//DE TEXTO	onKeyPress='return acceptNum(event)'
var nav4 = window.Event ? true : false;
function acceptNum(evt){

// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57, '.' = 46
var key = nav4 ? evt.which : evt.keyCode;
return (key <= 13 || (key >= 48 && key <= 57) || key == 46);
}

//onKeyPress='return acceptLetras(event)'
function acceptLetras(evt){

// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57, '.' = 46
var key = nav4 ? evt.which : evt.keyCode;
return ( (key >= 97 && key <= 122) || (key >= 65 && key <= 90) );
}



//onKeyPress='return acceptLetras_y_Num(event)'
function acceptLetras_y_Num(evt){
	
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57, '.' = 46
var key = nav4 ? evt.which : evt.keyCode;
return ( (key == 8) || (key >= 48 && key <= 57) || (key >= 97 && key <= 122) || (key >= 65 && key<= 90) );
	
}



//FORMATEA LA FECHA DE YYYY-MM-DD A DD-MM-YYYY
function fecha_normal(fecha){
	
	var arreglo=fecha.split("-");
	fecha=arreglo[2]+"-"+arreglo[1]+"-"+arreglo[0];
	
    return 	fecha;
}


//FORMATEA LA FECHA DE DD-MM-YYYY A YYYY-MM-DD  
function fecha_mysql(fecha){
	
	var arreglo=fecha.split("-");
	fecha=arreglo[2]+"-"+arreglo[1]+"-"+arreglo[0];
    return 	fecha;
	
}


//FORMATEA SALIDA DE NUMERO CON COMAS Y PUNTO
//num=NUMERO A FORMATEAR
//numDec=NUMERO DE DECIMALES
//decSep=SEPARADOR DE DECIMALES
//thousandSep=SEPARADOR DE MILES
function NumberFormat(num, numDec, decSep, thousandSep){ 
    var arg; 
    var Dec; 
    Dec = Math.pow(10, numDec);  
    if (typeof(num) == 'undefined') return;  
    if (typeof(decSep) == 'undefined') decSep = ','; 
    if (typeof(thousandSep) == 'undefined') thousandSep = '.'; 
    if (thousandSep == '.') 
     arg=/./g; 
    else 
     if (thousandSep == ',') arg=/,/g; 
    if (typeof(arg) != 'undefined') num = num.toString().replace(arg,''); 
    num = num.toString().replace(/,/g, '.');  
    if (isNaN(num)) num = "0"; 
    sign = (num == (num = Math.abs(num))); 
    num = Math.floor(num * Dec + 0.50000000001); 
    cents = num % Dec; 
    num = Math.floor(num/Dec).toString();  
    if (cents < (Dec / 10)) cents = "0" + cents;  
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) 
     num = num.substring(0, num.length - (4 * i + 3)) + thousandSep + num.substring(num.length - (4 * i + 3)); 
    if (Dec == 1) 
     return (((sign)? '': '-') + num); 
    else 
     return (((sign)? '': '-') + num + decSep + cents); 
   }  
   
 
 
 ////////////////////////////////////////////////////////////
 //SEPARADOR DE MILES SIN PUNTO AL FINAL ES DECIR SIN ".OO"
 ///////////////////////////////////////////////////////////
  
 function addCommas(nStr){ 
    nStr += ''; 
    x = nStr.split('.'); 
    x1 = x[0]; 
    x2 = x.length > 1 ? '.' + x[1] : ''; 
    var rgx = /(\d+)(\d{3})/; 
    while (rgx.test(x1)) { 
        x1 = x1.replace(rgx, '$1' + ',' + '$2'); 
    } 
    return x1 + x2; 
} 


//////////////////////////////////////////////////////////
//CENTRAR POPUP
/////////////////////////////////////////////////////////
//se habre asi esto lo puedes poner dentro de un Onclick
//centrar_popup(this.href,'name','300','300','yes')
function centrar_popup(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}


