var VGusuar=localStorage.getItem("USERAPI");
var VGupass=localStorage.getItem("PASSAPI");

var TEXTEMPORAL="";


function createREQ() {try {req = new XMLHttpRequest(); /* p.e. Firefox */
} catch(err1) {try {req = new ActiveXObject('Msxml2.XMLHTTP'); /* algunas versiones IE */
} catch (err2) {try {req = new ActiveXObject("Microsoft.XMLHTTP"); /* algunas versiones IE */
} catch (err3) {req = false;}}
}return req;
}
function requestGET(url, query, req) {
myRand=parseInt(Math.random()*99999999);
if(query == ''){query='no=no';}
req.open("GET",url+'?'+query+'&rand='+myRand,true);
req.send(null);
}
function requestPOST(url, query, req) {
req.open("POST", url,true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(query);
}
function doCallback(callback,item) {
eval(callback + '(item)');
}
function doAjax(url,query,callback,reqtype,getxml,contenedor_espera) {
var myreq = createREQ();
myreq.onreadystatechange = function() {//function()
if(myreq.readyState == 4) {//1
	if(contenedor_espera != '' ){document.getElementById(contenedor_espera).innerHTML ='';}
	if(myreq.status == 200) {//2
      	var item = myreq.responseText;
    	if(getxml==1) {//3
         item = myreq.responseXML;
    	}//3
      doCallback(callback, item);
    }//2
}//1
  else
     {//4
	   if(contenedor_espera != '' ){document.getElementById(contenedor_espera).innerHTML ='<img src="anim.gif">';}
     }//4
}//function()
	if(reqtype=='post') {//5
		requestPOST(url,query,myreq);			
	}else{
		requestGET(url,query,myreq);
	}//5
}//***************fin de createREQ*****************
//CUENTAAPI


//CUENTAAPI
function validarEmail(valor) {
emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
  if (emailRegex.test(valor)) {
     return false ;
  } else {
     return true;
  }
  
}
//*******************funciones herramientas****************************
function Fecha_hoy(formato){//funcion de pedir fecha actual
	var fechaActual = new Date();
	dia = fechaActual.getDate();
	mes = fechaActual.getMonth() +1;
	anno = fechaActual.getFullYear();
	if (dia <10) dia = "0" + dia;
	if (mes <10) mes = "0" + mes;
	if(formato=="yyyy-mm-dd"){
		fechaHoy =anno  + "-" + mes + "-" + dia;
		}
	fechaHoy =anno  + "-" + mes + "-" + dia;
	return fechaHoy;
}//fin de fecha

function mostrar_ocultar_elem(accion,element){
	if(accion=="mostrar"){
		document.getElementById(element).style.display = '';
		}else{
		document.getElementById(element).style.display='none';
	}
}

function formatNumber(num,prefix){//cambiar a formato maneda
num = Math.round(parseFloat(num)*Math.pow(10,2))/Math.pow(10,2)
prefix = prefix || '';
num += '';
var splitStr = num.split('.');
var splitLeft = splitStr[0];
var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';
splitRight = splitRight + '';
splitRight = splitRight.substr(0,3);
var regx = /(\d+)(\d{3})/;
while (regx.test(splitLeft)) {
splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');
}
return prefix + splitLeft + splitRight;
}
function getGET(){
   var loc = document.location.href;
   var getString = loc.split('?')[1];
   try {
	     var GET = getString.split('&');
   	     var get = {};
         for(var i = 0, l = GET.length; i < l; i++){
         	var tmp = GET[i].split('=');
         	get[tmp[0]] = unescape(decodeURI(tmp[1]));
         }
	} catch(e) {
    	get="NOPARAM";
	}
   return get;
}

function redireccionar(pagina){location.href=pagina;} 

function trim(myString)
{
return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}


function daysBetween(date1, date2){
	 if(typeof date2 !== 'undefined' && date2 !== null) {
		 
   if (date1.indexOf("-") != -1) { date1 = date1.split("-"); } else if (date1.indexOf("/") != -1) { date1 = date1.split("/"); } else { return 0; }
   if (date2.indexOf("-") != -1) { date2 = date2.split("-"); } else if (date2.indexOf("/") != -1) { date2 = date2.split("/"); } else { return 0; }
   if (parseInt(date1[0], 10) >= 1000) {
       var sDate = new Date(date1[0]+"/"+date1[1]+"/"+date1[2]);
   } else if (parseInt(date1[2], 10) >= 1000) {
       var sDate = new Date(date1[2]+"/"+date1[0]+"/"+date1[1]);
   } else {
       return 0;
   }
   if (parseInt(date2[0], 10) >= 1000) {
       var eDate = new Date(date2[0]+"/"+date2[1]+"/"+date2[2]);
   } else if (parseInt(date2[2], 10) >= 1000) {
       var eDate = new Date(date2[2]+"/"+date2[0]+"/"+date2[1]);
   } else {
       return 0;
   }
   var one_day = 1000*60*60*24;
   var daysApart = Math.ceil((sDate.getTime()-eDate.getTime())/one_day);
   return daysApart;
   }else{
       return 0;
   }
    
}


function decimal(valor, decimal){
	var result=Math.round(valor);
	if(decimal==1){result=Math.round(valor*10)/10;}
	if(decimal==2){result=Math.round(valor*100)/100;}
	if(decimal==3){result=Math.round(valor*1000)/1000;}
	if(decimal==3){result=Math.round(valor*10000)/10000;}
	return result;
}


function decAhex(dec) { 
    dec = parseInt(dec) 
    var hexChars="0123456789ABCDEF" 
    var dig = new Array(10) 
    if (dec >= 1e12 ) { return 'demasiado grande' } 
    for (k=0; k<10; k++) 
    {   dig[k] = dec % 16 
        dec = (dec-dig[k]) / 16 
    } 
    var resul = "" 
    for (k=9; k>-1; k--) 
    {    resul += hexChars.charAt(dig[k]) 
    }     
    return resul 
}  


function myTrim(x) {
  return x.replace(/^\s+|\s+$/gm,'');
}


function setCookie(cname,cvalue,exdays) {
  var d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  var expires = "expires=" + d.toGMTString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
  var name = cname + "=";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for(var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

function checkCookie(Cnombre,Cvalor) {
  var user=getCookie(Cnombre);
  if (user != "") {
    return user;
  } else {
     user = Cvalor;
     if (user != "" && user != null) {
       setCookie(Cnombre, user, 30);
     }
  }
}
