
function makeArray(n) {
    this.length = n;
    for (i=1;i<=n;i++){
        this[i]=0;
    }
    return this;
}

function displayDate() {
    var this_month = new makeArray(12);
    this_month[0]  = "Enero";
    this_month[1]  = "Febrero";
    this_month[2]  = "Marzo";
    this_month[3]  = "Abril";
    this_month[4]  = "Mayo";
    this_month[5]  = "Junio";
    this_month[6]  = "Julio";
    this_month[7]  = "Agosto";
    this_month[8]  = "Septiembre";
    this_month[9]  = "Octubre";
    this_month[10] = "Noviembre";
    this_month[11] = "Diciembre";
    var today = new Date();
    var day   = today.getDate();
    var month = today.getMonth();
    var year  = today.getYear();
    if (year < 1900){
        year += 1900;
    }
    var ret = (this_month[month]+" "+day+", "+year);
    document.write(ret);
    return;
}



function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



//devuelve una referencia al objeto
function getObj(obj) {
	return (isObj(obj) ? obj : document.getElementById(obj));
}

function escWin(ev) {
	ev = ev || window.event; // gets the event in ie or ns
	kCode = ev.keyCode || ev.which;
	if(kCode == 27) window.close();
	//alert(kCode);
}

function redirect(url) {
	window.location = url;
}

//devuelve si es Undefined o no
function isDef(val) {
	return ((typeof(val)=="undefined") || (val==null) ? false : true);
}

//devuelve si es Objeto o no
function isObj(val) {
	return (typeof(val)=="object");
}

//devuelve una propiedad especifica de un objeto
function objProp(obj, propName) {
	return (isObj(obj) ? obj.getAttribute(propName) : null);
}

//devuelve las coord de un obj en un array[posLeft, posTop]
function objPos(obj) {
	var curleft = curtop = 0;
	if(obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) 	{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

//devuelve si es un Array o no
function isArray(obj) {
	return (isObj(obj) && obj.constructor == Array);
}

//devuelve si un valor esta dentro de un array
function inArray(arr, val) {
	ret = arrayIndexOf(arr, val) != -1;
	return ret
}

function trim(txt) {
	txt = "" + txt;
	txt = txt.replace(/^\s+|\s+$/g,'');
	return(txt);
}

function replace(strOrig, strBuscar, strNew) {
	ret = ''+strOrig;
	while (ret.indexOf(strBuscar) > -1)
	{
		pos = ret.indexOf(strBuscar);
		ret = "" + (ret.substring(0, pos) + strNew + ret.substring((pos + strBuscar.length), ret.length));
	}
	return ret;
}

function stripos(f_haystack, f_needle, f_offset) {
	var haystack = f_haystack.toLowerCase();
	var needle = f_needle.toLowerCase();
	var index = 0;
	if(!isDef(f_offset)) f_offset = 0;
	if((index = haystack.indexOf(needle, f_offset)) > -1) return index;
	return false;
}


function empty(val) {
	if(!isDef(val)) return true;
	if(val==null) return true;
	if(trim("" + val)=="") return true;
	return false;
}
//convierte a minusculas.
function low(val) {
	return (empty(val) ? val : val.toLowerCase());
}
//convierte a mayusculas.
function upp(val) {
	return (empty(val) ? val : val.toUpperCase());
}

//convierte un string (valor) separado por (sep) a array.
//si valor ya era array, devuelve tal cual como lleg�
function toArray(valor, sep) {
	if(isArray(valor)) return valor;
	if(!sep) sep = ",";
	return valor.split(sep);
}

function contiene(pajar, aguja) {
	var vpajar = trim(low(pajar));
	var arr = toArray(aguja);
	for(var i in arr) {
		if(stripos(vpajar, trim(arr[i])) !== false) return true;
	}
	return false;
}

//si val1 == valores (valores puede ser array o string separado por comas)
function igual(val1, valores) {
	var v1 = trim(low(val1));
	var arr = toArray(low(valores));
	for(var i in arr) { if(trim(arr[i]) == v1) return true;}
	return false;
}

function debug() {
	return debug_r(arguments);
}

function debug_r(arrvals) {
	var ret = "";
	if(typeof(arrvals) == "string")
		arrvals = arrvals.split(",");
	for (i = 0; i < arrvals.length; i++) {
		ret += "" + " = " + arrvals[i] + "\n";
	}
	alert(ret);
	return;
}

function cInt(val) {
	if(empty(val) || isNaN(val)) val = 0;
	return parseInt(val,10);
}

function cDbl(val) {
	var ret = val;
	ret = replace(ret, ',', '.');
	if(empty(ret) || isNaN(ret)) ret = 0;
	ret = Math.round(ret * 100) / 100;
	return ret;
}

function abs(val) {
	return Math.abs(val);
}

function floor(val) {
	return Math.floor(val);
}

function isNum(val) {
	if(empty(val)) return false;
	var str = "1234567890,.";
	for(var i = 0; i < val.length; i++) {
		tmp = val.substring(i,i+1);
		if(str.indexOf(tmp, 0) == -1) return false;
	}
	return true;
}

function isAlfa(str) { //A-Z
	var tmp = upp(str);
	for(i=0;i<tmp.length;i++) {
		var ch = tmp.charCodeAt(i);
		if(ch < 65 || ch > 90) return false;
	}
	return true;
}

function xor(v1, v2) {
	v1 = empty(v1);
	v2 = empty(v2);
	res = (v1 ^ v2) ? true : false;
	return res;
}

function zerofill(valor) {
	tmp = valor.toString();
	return (tmp.length == 1) ? ""+"0"+tmp : tmp;
}


function getTagCont(aContent, aTag, aTag2, refIni) {
	if(!isDef(aTag)) aTag = null;
	if(!isDef(aTag2)) aTag2 = null;
	posIni = (isDef(refIni)) ? cInt(refIni) : 0;
	if (!aContent) return null;
	posIni = (aTag === null) ? 0 : stripos(aContent, aTag, posIni);
	if (posIni === false) return null;
	posIni += strlen(aTag);
	fin = (aTag2 === null) ? strlen(aContent) : stripos(aContent, aTag2, posIni);
	html = trim(substr(aContent, posIni, fin - posIni));
	posIni = fin;
	if(isDef(refIni)) refIni = posIni;
	return html;
}

