function MakeArray(n) {
this.length = n;
return this;
}
monthNames = new MakeArray(12)
monthNames[1] = "enero";
monthNames[2] = "febrero";
monthNames[3] = "marzo";
monthNames[4] = "abril";
monthNames[5] = "mayo";
monthNames[6] = "junio";
monthNames[7] = "julio";
monthNames[8] = "agosto";
monthNames[9] = "septiembre";
monthNames[10] = "octubre";
monthNames[11] = "noviembre";
monthNames[12] = "diciembre";
dayNames = new MakeArray(7)
dayNames[1] = "Domingo";
dayNames[2] = "Lunes";
dayNames[3] = "Martes";
dayNames[4] = "Miércoles";
dayNames[5] = "Jueves";
dayNames[6] = "Viernes";
dayNames[7] = "Sábado";

function customDateString(oneDate) {
  var theDay = dayNames[oneDate.getDay() + 1];
  var theMonth = monthNames[oneDate.getMonth() + 1];
  var theYear = oneDate.getYear();
  theYear += (theYear < 100) ? 1900 : 0;
//  return theDay + ", " + theMonth + " " + oneDate.getDate() + ", " + theYear;
  return theDay + ", " + oneDate.getDate() + " de " + theMonth + " de " + oneDate.getFullYear();
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

function SetCursorHand(object) {
	if(document.all)
		object.style.cursor='hand';
}

function cgi(){
  this.getName = new Array()
  this.getValue = new Array()
  if (document.location.search.length == 0){
    this.parameters = 0}
  else{
    matriu = document.location.search.slice(1).split("&")
    this.parameters = matriu.length	
    for (n = 0; n < matriu.length; n++){
      nom = unescape(matriu[n].substring(0,matriu[n].indexOf("=")))
      valor = unescape(matriu[n].substring(matriu[n].indexOf("=")+1))
      eval ('this.' + nom + ' = ' + 'valor')
      eval ('this.getName[' + n + '] = ' + 'nom')
      eval ('this.getValue[' + n + '] = ' + 'valor')
    }
  }
}

function OpenImage(htmldoc, name, height, width) {
	window.open (htmldoc+"?name="+name+"&height="+height+"&width="+width, "foto", "resizable=no; help=no; status=no; scroll= no; center=yes; toolbar=no; menubar=no;");
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function OpenNoResizeWindow(htmldoc) {
   wnd = window.open(htmldoc,'popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
   wnd.focus();
}

function SetImage(Destination, Source)
{
   document.images[Destination].src=Source;
}

function colorize(obj, color)
{
  obj.style.background=color;
}

function GetOffsetTop(obj){
  if (obj != null){
    var GlobalOffset = 0;
    while (obj.parentNode){
	  if ((obj.tagName == "BODY") || (obj.tagName == "TABLE")|| (obj.tagName == "TR") || (obj.tagName == "IMG"))
	    GlobalOffset += obj.offsetTop;
      obj = obj.parentNode;
    }
	return GlobalOffset;
  }
  else return 0;
}

function ShowLayer(num, LayerPrefix, HookPrefix, RulePrefix, Ajust, imgExpanded, imgCollapsed, manteinVisibility){
  var layer = document.getElementById(LayerPrefix + num)
  var img = document.getElementById(HookPrefix + num)
  var ShowStr = "";
  var HideStr = "";

  ns4 = (document.layers)? true:false
  if (ns4){
    ShowStr = "show";
	HideStr = "hide"
  }
  else {
    ShowStr = "visible";
	HideStr = "hidden"
  }

  for (i = 1; i <= 20; i ++) {
    var elem = document.getElementById(LayerPrefix + i);
    var hook = document.getElementById(HookPrefix + i);
	var rule = document.getElementById(RulePrefix + i);
	var yPosition = 0;
	if (elem != null) {
      if ((hook != null) && (HookPrefix != "")){
		yPosition = GetOffsetTop(hook);
		if ((rule != null) && (RulePrefix != "")) yPosition = yPosition - rule.offsetTop + Ajust; // el 7 es el ajuste para que cuadre con el texto
        elem.style.top = yPosition + "px";
	  }
      if (layer != elem) {
        elem.style.visibility=HideStr;
        if ((hook != null) && (HookPrefix != "") && (imgCollapsed != "")) hook.src = imgExpanded;
      }
    }
  }
  
  if (layer != null){
    if (layer.style.visibility==ShowStr){
	  if (! manteinVisibility){
	    layer.style.visibility=HideStr;
        if ((img != null) && (HookPrefix != "") && (imgCollapsed != "")) img.src = imgExpanded;
	  }
	}
    else{
	  layer.style.visibility=ShowStr;
      if ((img != null) && (HookPrefix != "") && (imgCollapsed != "")) img.src = imgCollapsed;
	}
  }
}

function GetClientHeight(){
  if (self.innerHeight)
    return self.innerHeight;
  else 
    if (document.documentElement && document.documentElement.clientHeight)
	  return document.documentElement.clientHeight;
	else
	  if (document.body)
	  return document.body.clientHeight;
}

function GetClientWidth(){
  if (self.innerWidth)
    return self.innerWidth;
  else 
    if (document.documentElement && document.documentElement.clientWidth)
	  return document.documentElement.clientWidth;
	else
	  if (document.body)
	  return document.body.clientWidth;
}

function writeInTextArea(objID,text) {
 // Detect Browser
  var IE = (document.all) ? 1 : 0;
  var DOM = 0; 
  if (parseInt(navigator.appVersion) >=5) DOM = 1;
  if (DOM) {
    var viewer = document.getElementById(objID);
		viewer.innerHTML = text;
  }
  else 
    if(IE) {
	  document.all[objID].innerHTML = text;
	}
}

function ValidLenght(what, maxLength, objID) 
{
  var str = new String(what.value);
  var len = str.length;
  if (len >= maxLength) {
	what.value = str.substr(0, maxLength - 1);
  }
  document.getElementById(objID).value = str.length.toString();
}