function crearFlash(url, width, height, wmode, clase) {
    document.write('<object type="application/x-shockwave-flash" data="' + url + '" width="' + width + '" height="' + height + '" class="' + clase + '"><param name="movie" value="' + url + '" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="' + wmode + '" /></object>');
}




function validarTexto(formulario, campo, mensaje) {
	if(document.forms[formulario].elements[campo].value == '') {
		alert(mensaje);
		document.forms[formulario].elements[campo].focus();
		return false;
	}
	return true;
}

function validarEmail(formulario, campo, mensaje) {
   if(!document.forms[formulario].elements[campo].value.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)) {
		alert(mensaje);
		document.forms[formulario].elements[campo].focus();
		return false;
   }
	return true;
}

function validarSelector(formulario, campo, mensaje) {
	if(document.forms[formulario].elements[campo].selectedIndex == 0) {
		alert(mensaje);
		document.forms[formulario].elements[campo].focus();
		return false;
	}
	return true;
}

function validarNumero(formulario, campo, mensaje, vacio, desde, hasta) {
    var num = document.forms[formulario].elements[campo].value;
    if (vacio && num == '')
		return true;
    num = parseInt(num);
    if (isNaN(num) || num < desde || num > hasta) {
        alert(mensaje);
		document.forms[formulario].elements[campo].focus();
		return false;
    }
	return true;
}

function validarLogin() {
	if(!validarTexto('login', 'usr_documento', 'Debe ingresar su DOCUMENTO.')) return false;
	return true;
}

function validarBuscar() {
	if(!validarTexto('buscar', 's', 'Debe ingresar un criterio de búsqueda.')) return false;
	return true;
}

function validarContacto() {
	if(!validarTexto('contacto', 'apellido', 'Debe ingresar su APELLIDO.')) return false;
	if(!validarTexto('contacto', 'nombre', 'Debe ingresar su NOMBRE.')) return false;
	if(!validarEmail('contacto', 'email', 'Debe ingresar su E-MAIL.')) return false;
	if(!validarSelector('contacto', 'asunto', 'Debe ingresar su ASUNTO.')) return false;
	if(!validarTexto('contacto', 'comentario', 'Debe ingresar su COMENTARIO.')) return false;
	return true;
}

function validarDatos() {
	if(!validarTexto('datos', 'socio', 'Debe ingresar su NRO. DE SOCIO.')) return false;
	if(!validarEmail('datos', 'email', 'Debe ingresar su E-MAIL.')) return false;
	return true;
}


function validarConsulta() {
	if(!validarTexto('consulta', 'socio', 'Debe ingresar su NRO. DE SOCIO.')) return false;
	if(!validarEmail('consulta', 'email', 'Debe ingresar su E-MAIL.')) return false;
	return true;
}

function validarEncuesta() {
	if(!validarNumero('encuesta', 'enc_p1', 'Debe ingresar un NUMERO entero <= 100.', false, 0, 100)) return false;
	if(!validarNumero('encuesta', 'enc_p2', 'Debe ingresar un NUMERO entero.', false, 0)) return false;
	if(!validarNumero('encuesta', 'enc_p3', 'Debe ingresar un NUMERO entero <= 100.', false, 0, 100)) return false;
	return true;
}




function createXMLHttp() {
	if (typeof XMLHttpRequest != 'undefined') {
		return new XMLHttpRequest();
	}
    else if (window.ActiveXObject) {
		var aVersions = ['MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp', 'Microsoft.XMLHttp'];
		for (var i = 0; i < aVersions.length; i++) {
			try {
				var oXmlHttp = new ActiveXObject(aVersions[i]);
				return oXmlHttp;
			}
            catch (oError) {
			}
		}
	}
	throw new Error('XMLHttp object could be created.');
}

function cargarPagina(pagina, contenedor, datos, x, y) {
    document.getElementById(contenedor).innerHTML = 'Cargando...';
	if (x != -1 && y != -1)
        window.scrollTo(x, y);
    var oXmlHttp = createXMLHttp();
    if (datos) {
        oXmlHttp.open('post', pagina, true);
        oXmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    }
    else {
        oXmlHttp.open('get', pagina, true);
    }
    oXmlHttp.onreadystatechange = function() {
	    if (oXmlHttp.readyState == 4)
		    if (oXmlHttp.status == 200) {
                if (oXmlHttp.getResponseHeader('Content-Type') == 'text/html')
                    document.getElementById(contenedor).innerHTML = oXmlHttp.responseText;
            }
            else
                document.getElementById(contenedor).innerHTML = '';
    };
    oXmlHttp.send(datos);
    return false;
}

function leerFormulario(formulario) {
    var oForm = document.forms[formulario];
    var aParams = new Array();
    for (var i = 0; i < oForm.elements.length; i++) {
        if ((oForm.elements[i].type != 'radio' || oForm.elements[i].checked)) {
            var sParam = escape(oForm.elements[i].name);
            sParam += '=';
            if (oForm.elements[i].type != 'checkbox' || oForm.elements[i].checked)
                sParam += escape(oForm.elements[i].value);
            aParams.push(sParam);
        }
    }
    return aParams.join('&');
}

function activarOpcion(id, menu) {
	var menuRoot
	if (menu)
		menuRoot = document.getElementById(menu);
	else
		menuRoot = document.getElementById('submenu');
	if (menuRoot)
		for (i = 0; i < menuRoot.childNodes.length; i++) {
			tmp = menuRoot.childNodes[i];
			if (tmp.nodeName == 'A') {
				if (tmp.id == id) {
					if (tmp.className.indexOf(' submenuButtonActive') == -1)
						tmp.className += ' submenuButtonActive';
				}
				else
					tmp.className = tmp.className.replace(' submenuButtonActive', '');
			}
		}
}

function cargarNota(did, col, titulo, menu) {
	cargarPagina('/nota.asp?did=' + did + '&col=' + col, 'nota');
	if (titulo)
    	document.getElementById('listadoTitulo').innerHTML = titulo;
	cargarPagina('/listado.asp?col=' + col, 'listado');
	if (col == 0)
		col = did;
	activarOpcion('o' + col, menu);
	return false;
}

function verificarNota(path, col) {
	if(location.pathname == path)
		cargarNota(-1, col);
	else
		location.href = path + '?col=' + col;
	return false;
}

function cargarProspectiva(did, col) {
	if (col) {
		activarOpcion('o1');
		cargarPagina('nota.asp?did=' + did + '&col=' + col, 'nota');
		activarOpcion('o' + col, 'submenu2ciencia');
		document.getElementById('submenu2prospectiva').style.display = 'none';
		document.getElementById('submenu2ciencia').style.display = 'block';
		document.getElementById('listadoseccion').style.display = 'block';
		document.getElementById('listado').style.display = 'block';
		cargarPagina('listado.asp?col=' + col, 'listado');
	}
	else {
		activarOpcion('o2');
		cargarPagina('nota.asp?did=' + did, 'nota');
		activarOpcion('', 'submenu2prospectiva');
		document.getElementById('submenu2ciencia').style.display = 'none';
		document.getElementById('submenu2prospectiva').style.display = 'block';
		document.getElementById('listadoseccion').style.display = 'none';
		document.getElementById('listado').style.display = 'none';
		document.getElementById('listado').innerHTML = '';
	}
	return false;
}

function cargarProspectivaNota(did) {
	cargarPagina('/nota.asp?did=' + did, 'nota');
	activarOpcion('o' + did, 'submenu2prospectiva');
}

function cargarInstitucional(m) {
	var t, n1, n2;
	switch (m) {
	case 5:
		t = 'Sitios Recomendados';
		n1 = 11527;
		n2 = 11528;
		break;
	case 4:
		t = 'Pol&iacute;tica de Calidad';
		n1 = 11525;
		n2 = 11526;
		break;
	case 3:
		t = 'SD en Argentina';
		n1 = 11523;
		n2 = 11524;
		break;
	case 2:
		t = '&iquest;Qui&eacute;nes Somos?';
		n1 = 11521;
		n2 = 11522;
		break;
	case 1:
	default:
		t = '&iquest;Qu&eacute; es Aapresid?';
		n1 = 11519;
		n2 = 11520;
	}
    document.getElementById('titulo').innerHTML = 'Institucional - ' + t;
	cargarPagina('nota.asp?did=' + n1, 'nota1');
	cargarPagina('nota.asp?did=' + n2, 'nota2');
	return false;
}

function verificarInstitucional(m) {
	if(location.pathname == '/institucional.asp')
		cargarInstitucional(m);
	else
		location.href = '/institucional.asp?m=' + m;
	return false;
}

function cargarSocio(m) {
	var t, n1, n2;
	switch (m) {
	case 5:
		t = 'Atenci&oacute;n al Socio';
		n1 = 11537;
		n2 = 11538;
		break;
	case 4:
		t = 'Formas de Pago';
		n1 = 11535;
		n2 = 11536;
		break;
	case 3:
		t = 'Categor&iacute;as';
		n1 = 11533;
		n2 = 11534;
		break;
	case 2:
		t = 'Ficha';
		n1 = 11531;
		n2 = 11532;
		break;
	case 1:
	default:
		t = 'Beneficios';
		n1 = 11529;
		n2 = 11530;
	}
    document.getElementById('titulo').innerHTML = 'Socio Aapresid - ' + t;
	cargarPagina('nota.asp?did=' + n1, 'nota1');
	cargarPagina('nota.asp?did=' + n2, 'nota2');
	return false;
}

function verificarSocio(m) {
	if(location.pathname == '/socio.asp')
		cargarSocio(m);
	else
		location.href = '/socio.asp?m=' + m;
	return false;
}

function cargarRegional(did, col) {
	if(col == -1) {
		col = '127,128,129,130,131,132,134,135,136,137,138,139,163,140,141,142,143,144,164,145,146,159,148,149,150,151,152,153,154,155,156,157';
		if(document.getElementById('regionales').style.height != '490px') {
			document.getElementById('regionales').style.height = '490px';
			document.getElementById('regionales').innerHTML = '<object type="application/x-shockwave-flash" data="/images/regionales.swf" width="243" height="500"><param name="movie" value="/images/regionales.swf" /><param name="quality" value="high" /><param name="menu" value="false" /></object>';
		}
		document.getElementById('regional').style.display = 'none';
    	document.getElementById('regional').innerHTML = '';
	}
	else {
		if(document.getElementById('regionales').style.height != '33px') {
			document.getElementById('regionales').style.height = '33px';
			document.getElementById('regionales').innerHTML = '<object type="application/x-shockwave-flash" data="/images/regionales.swf?m=1" width="243" height="500"><param name="movie" value="/images/regionales.swf?m=1" /><param name="quality" value="high" /><param name="menu" value="false" /></object>';
        }
		document.getElementById('regional').style.display = 'block';
		cargarPagina('/regional.asp?id=' + col, 'regional');
	}
	cargarPagina('/nota.asp?did=' + did + '&col=' + col, 'nota');
	document.getElementById('listadoseccion').style.display = 'block';
	document.getElementById('listado').style.display = 'block';
	cargarPagina('/listado.asp?col=' + col, 'listado');
	activarOpcion('oRegionales');
	return false;
}

function cargarRegionales() {
	document.getElementById('regionales').style.height = '490px';
	return false;
}

function cargarRegionalListado(did, col) {
	document.getElementById('regional').style.display = 'none';
    document.getElementById('regional').innerHTML = '';
	if(document.getElementById('regionales').style.height != '490px') {
		document.getElementById('regionales').style.height = '490px';
		document.getElementById('regionales').innerHTML = '<object type="application/x-shockwave-flash" data="/images/regionales.swf" width="243" height="500"><param name="movie" value="/images/regionales.swf" /><param name="quality" value="high" /><param name="menu" value="false" /></object>';
	}
	cargarPagina('nota.asp?did=' + did + '&col=' + col, 'nota');
	document.getElementById('listadoseccion').style.display = 'block';
	document.getElementById('listado').style.display = 'block';
	cargarPagina('/listado.asp?col=' + col, 'listado');
	activarOpcion('o' + col);
	return false;
}

function cargarRegionalNota(did) {
	document.getElementById('regional').style.display = 'none';
    document.getElementById('regional').innerHTML = '';
	if(document.getElementById('regionales').style.height != '490px') {
		document.getElementById('regionales').style.height = '490px';
		document.getElementById('regionales').innerHTML = '<object type="application/x-shockwave-flash" data="/images/regionales.swf" width="243" height="500"><param name="movie" value="/images/regionales.swf" /><param name="quality" value="high" /><param name="menu" value="false" /></object>';
	}
	cargarPagina('nota.asp?did=' + did, 'nota');
	document.getElementById('listadoseccion').style.display = 'none';
	document.getElementById('listado').style.display = 'none';
    document.getElementById('listado').innerHTML = '';
	activarOpcion('o' + did);
	return false;
}

function verificarRegionales(did, col) {
	if(location.pathname == '/regionales.asp') {
		if(did == 11927)
			cargarRegionalNota(11927);
		else if (col == 173)
			cargarRegionalListado(did, 173);
		else
			cargarRegional(did, col);
	}
	else
		location.href = '/regionales.asp?did=' + did + '&col=' + col;
	return false;
}

function cargarBuscar(did, col, s) {
	cargarPagina('nota.asp?did=' + did + '&col=' + col + '&s=' + s, 'nota');
	cargarPagina('listado.asp?col=' + col + '&s=' + s, 'listado');
	return false;
}

function validarPromociones() {
    cargarPagina('/promociones2.asp', 'listado', leerFormulario('promociones'));
    return false;
}








function Browser() {
  var ua, s, i;
  this.isIE    = false;
  this.isOP    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

var activeButton = null;

if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {
  var el;

  if (activeButton == null)
    return;

  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);

  if (el == activeButton)
    return;

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

function buttonClick(event, menuId) {
  var button;

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  button.blur();

  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    if (button.menu.isInitialized == null)
      menuInit(button.menu);
  }

  if (activeButton != null)
    resetButton(activeButton);

  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;

  return false;
}

function buttonMouseover(event, menuId) {
  var button;

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function depressButton(button) {
  var x, y;

  button.className += " menuButtonActive";

//  x = getPageOffsetLeft(button);
//  y = getPageOffsetTop(button) + button.offsetHeight;

//  if (browser.isIE) {
//    x += button.offsetParent.clientLeft;
//    y += button.offsetParent.clientTop;
//  }

//  button.menu.style.left = x + "px";
//  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";

//  if (button.menu.iframeEl != null)
//  {
//    button.menu.iframeEl.style.left = button.menu.style.left;
//    button.menu.iframeEl.style.top  = button.menu.style.top;
//    button.menu.iframeEl.style.width  = button.menu.offsetWidth + "px";
//    button.menu.iframeEl.style.height = button.menu.offsetHeight + "px";
//    button.menu.iframeEl.style.display = "";
//  }
}

function resetButton(button) {
  removeClassName(button, "menuButtonActive");

  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";

    if (button.menu.iframeEl != null)
      button.menu.iframeEl.style.display = "none";
  }
}

function menuMouseover(event) {
  var menu;

  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  if (menu.activeItem != null)
    closeSubMenu(menu);
}

function menuItemMouseover(event, menuId) {
  var item, menu, x, y;

  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;
  menu = getContainerWith(item, "DIV", "menu");

  if (menu.activeItem != null)
    closeSubMenu(menu);
  menu.activeItem = item;

  item.className += " menuItemHighlight";

  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    if (item.subMenu.isInitialized == null)
      menuInit(item.subMenu);
  }

//  x = getPageOffsetLeft(item) + item.offsetWidth;
//  y = getPageOffsetTop(item);

//  var maxX, maxY;

//  if (browser.isIE) {
//    maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
//      (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
//    maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
//      (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
//  }
//  if (browser.isOP) {
//    maxX = document.documentElement.scrollLeft + window.innerWidth;
//    maxY = document.documentElement.scrollTop  + window.innerHeight;
//  }
//  if (browser.isNS) {
//    maxX = window.scrollX + window.innerWidth;
//    maxY = window.scrollY + window.innerHeight;
//  }
//  maxX -= item.subMenu.offsetWidth;
//  maxY -= item.subMenu.offsetHeight;

//  if (x > maxX)
//    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
//      + (menu.offsetWidth - item.offsetWidth));
//  y = Math.max(0, Math.min(y, maxY));

//  item.subMenu.style.left       = x + "px";
//  item.subMenu.style.top        = y + "px";
  item.subMenu.style.visibility = "visible";

//  if (item.subMenu.iframeEl != null)
//  {
//    item.subMenu.iframeEl.style.left    = item.subMenu.style.left;
//    item.subMenu.iframeEl.style.top     = item.subMenu.style.top;
//    item.subMenu.iframeEl.style.width   = item.subMenu.offsetWidth + "px";
//    item.subMenu.iframeEl.style.height  = item.subMenu.offsetHeight + "px";
//    item.subMenu.iframeEl.style.display = "";
//  }

  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}

function closeSubMenu(menu) {
  if (menu == null || menu.activeItem == null)
    return;

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);

    menu.activeItem.subMenu.style.visibility = "hidden";

    if (menu.activeItem.subMenu.iframeEl != null)
      menu.activeItem.subMenu.iframeEl.style.display = "none";

    menu.activeItem.subMenu = null;
  }

  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}

function menuInit(menu) {
  var itemList, spanList;
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  if (browser.isIE) {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;

  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN");
    textEl  = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow")) {
        arrowEl = spanList[j];
      }
    }
    if (textEl != null && arrowEl != null) {
      textEl.style.paddingRight = (itemWidth - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";

      if (browser.isOP)
        arrowEl.style.marginRight = "0px";
    }
  }

  if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }

  if (browser.isIE) {
    var iframeEl = document.createElement("IFRAME");
    iframeEl.frameBorder = 0;
    iframeEl.src = "javascript:false;";
    iframeEl.style.display = "none";
    iframeEl.style.position = "absolute";
    iframeEl.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
    menu.iframeEl = menu.parentNode.insertBefore(iframeEl, menu);
  }

  menu.isInitialized = true;
}

function getContainerWith(node, tagName, className) {
  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {
  var i, list;

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {
  var i, curList, newList;

  if (el.className == null)
    return;

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {
  var x;

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {
  var y;

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}