function FormatFechaLarga(fecha, formato)
{
	var m_names = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
	var d_names = new Array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");

	var d = new Date(fecha);
	var curr_day = d.getDay();
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	var curr_year = d.getFullYear();
	
	return (d_names[curr_day] + ", " + curr_date + " de " + m_names[curr_month] + " de "  + curr_year);
};

function SQLDateToJSDate(string)
{
  var date = new Date()
  mes = parseInt(string.substring(3, 5));
  date.setMonth(mes - 1); //en javascript los meses van de 0 a 11
  date.setDate(string.substring(0, 2));
  date.setYear(string.substring(6, 10));
  return date;
};

function enviarmail(destino)
{
	dest="mailto:"+destino+"@fiscalia.gba.gov.ar";
	location.href=dest;
};

function download_secfytdoc(documento, publico)
{
	if (publico == 0) 
	{
		tipodoc = 'privados'
	}
	else
	{
		tipodoc = 'publicos'
	}
	// CiS 14/09/2011 ANTES: dest="http://" + document.domain + "/secfyt/documentos/" + tipodoc + "/" + documento;
	dest="https://" + document.domain + "/secfyt/documentos/" + tipodoc + "/" + documento;
	location.href=dest;
};

function download_compactacion(documento)
{
	dest="http://" + document.domain + "/compactaciones/" + documento;
	//window.alert(dest);
	window.open(dest, 'Compactaciones');
	//location.href=dest;
};

function showDiv(objectID)
{
	var divlayer = document.getElementById(objectID);
	if(divlayer.style.display == "none")
	{
		divlayer.style.display = "block";
	}
	else
	{
		divlayer.style.display = "none";
	}
};

function telefonoValido(tel)
{
	var RegEx_tel = /^\(\d{2,5}\)\s\d{2,4}-\d{4}$/;
	var RegEx_cel = /^\(\d{2,5}\)\s15\s\d{2,4}-\d{4}$/;
	var RegEx_telint = /^\(\d{2,5}\)\s\d{2,4}-\d{4}\sint\s\d{1,5}$/;
	return (RegEx_tel.test(tel) || RegEx_cel.test(tel) || RegEx_telint.exec(tel));
};

function emailValido(email)	
{	
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return re.test(email);
};

function numeroFacturaValido(factura)
{
	var RegEx_factura = /^\d(4)-\d(8)$/;
	return (RegEx_factura.test(factura));
};

function codigoPostalValido(cp)	
{	
	cp = cp.toUpperCase();
	var codviejo = /^\d{4}$/;
	var codnuevo = /^[A-Z]\d{4}[A-Z]{3}$/;
	return (codviejo.test(cp) || codnuevo.test(cp));
};

function upperCase(x)
{
var y=document.getElementById(x).value;
document.getElementById(x).value=y.toUpperCase();
};

function lowerCase(x)
{
var y=document.getElementById(x).value;
document.getElementById(x).value=y.toLowerCase();
};

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
};
function logoutae()
{
	//var Backlen=history.length;
	//history.go(-Backlen);
	
   // top.window.location.replace ="logout.dssa";
	var Backlen=history.length;
	var i=0;
	for (i=0;i<=Backlen;i++)
	{
		history.go(-1);
		top.window.location.replace("");
	}
	//history.go(-Backlen);
	top.window.location.href ="logout.dssa";
};
function formatNumber(num,prefix){
    prefix = prefix || '';
    num += '';
    var splitStr = num.split('.');
    var splitLeft = splitStr[0];
    var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';
    var regx = /(\d+)(\d{3})/;
    while (regx.test(splitLeft))
	{
		splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');
    }
    return prefix + splitLeft + splitRight;
};
function unformatNumber(num) {
   return num.replace(/([^0-9\.\-])/g,'')*1;
};
function FormatNumerico(Valor, SepMil, SepDec, NumDec)
{
	//Comprobamos si viene con decimales y separamos el valor entero y el decimal
	var ValorEntero; var ValorEntero2 = ""; var ValorDecimal = ""; var arrayNum = Valor.toString().split("."); ValorEntero = arrayNum[0].toString();
	if (arrayNum.length==2)
	{
		ValorDecimal = arrayNum[1].toString();
		ValorDecimal = ValorDecimal.substring(0,NumDec)
	}
	else
	{
		for (var con=1;con<=NumDec;con++) ValorDecimal += "0";
	}
	//Formateamos la parte entera con separador de millar pasado por parámetros
	for (con=ValorEntero.length-3;con>-1;con-=3) ValorEntero2 = ValorEntero.substring(con,con+3) + SepMil + ValorEntero2;
	
	//Eliminamos el £ltimo caracter
	ValorEntero2 = ValorEntero2.substring(0,ValorEntero2.length-1);

	//A¤adimos el resto de la cifra si lo hubiera calculando el resto (m¢dulo) de la divisi¢n entre 3
	if (ValorEntero.length%3>0) ValorEntero2 = ValorEntero.substring(0,ValorEntero.length%3) + SepMil + ValorEntero2;
 
	//Devolvemos el n£mero formateado seg£n el n£mero de decimales pasado por par metros

	if (NumDec>0) return (ValorEntero2 + SepDec + ValorDecimal).replace('.,', ','); else

	return ValorEntero2.replace('.,', ',');
};
function validar_numeros(e)
{
	var key;
	
	if(window.event) // IE
	{key = e.keyCode;}
	else if(e.which) // Netscape/Firefox/Opera
		{key = e.which;}
	
	var ret = ((key >= 48 && key <= 57) || (key == 8) || (key == 46) || (key == 44));

	return ret;
};
function soloNumeros(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	// decimal point jump
	else if (dec && (keychar == "."))
	{
		myfield.form.elements[dec].focus();
		return false;
	}
	else
		return false;
};
function validar_letras(e)
{
	var key;
	
	if(window.event) // IE
	{key = e.keyCode;}
	else if(e.which) // Netscape/Firefox/Opera
		{key = e.which;}
	
	var ret = (!(key >= 48 && key <= 57));

	return ret;
};
function imprimirSeleccion(nombre)
{
  var ficha = document.getElementById(nombre);
  var ventimp = window.open(' ', 'popimpr');
  ventimp.document.write( ficha.innerHTML );
  ventimp.document.close();
  ventimp.print();
  ventimp.close();
};

function showError(mensaje, despuesde)
{
	despuesde = "#" + despuesde;

	var date = new Date();
	var idunique = date.getTime();
	var divid = 'divError_' + idunique;
	$j(despuesde).after('<div class="div_alerta oculto" id="' + divid + '">' + mensaje + '</div>');
	$j('#' + divid).show('slow');
	setTimeout("$j('#" + divid + "').hide('drop', function(){$j('#" + divid + "').remove()})", 10000);
};
