// JavaScript Document
var WindowObjectReference = null; // global variable

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();
}

MM_reloadPage(true);

function P7_downClass2() { //v1.0 by PVII
 var j,args=P7_downClass2.arguments;if($){
 if(!document.p7setdown){p7dco=new Array();document.p7setdown=true;}
 p7dco.length=0;j=0;for(var i=0;i<args.length;i+=2){
  if($(args[i])!=null){p7dco[j]=args[i];p7dco[j+1]=args[i+1];
  $(args[i]).className=args[i+1];j+=2;}}}
}

function tamanyoVentana() {
				var Tamanyo = [0, 0];
				if (typeof window.innerWidth != 'undefined'){
					Tamanyo = [window.innerWidth,window.innerHeight];
				}else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
					Tamanyo = [document.documentElement.clientWidth,document.documentElement.clientHeight];
				}else{
					Tamanyo = [document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight];
				}
				return Tamanyo;
}

function openAviso(tipo) {
	if(tipo==1){
//			$('aviso').style.left = (tamanyoVentana()[0]/2)+85+'px'
//			$('aviso').style.top = (tamanyoVentana()[1]/2)-125+'px'
			$('aviso').style.visibility = 'visible';
	}else if(tipo==2){
//			$('aviso').style.left = (tamanyoVentana()[0]/2)-120+'px'
//			$('aviso').style.top = (tamanyoVentana()[1]/2)-110+'px'
			$('aviso').style.visibility = 'visible';
	}
}

function comportamientoCapa(tipo){
	if (tipo==1){
		$('texto').style.visibility = 'visible';
		$('boton').style.visibility = 'visible';
		}
	else{
		$('texto').style.visibility = 'hidden';
		$('boton').style.visibility = 'hidden';
	}
}

function agregarFavorito(){
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)){
		var url="http://www.estrusal.es/";
		var titulo=":: Estrusal ::";
		window.external.AddFavorite(url,titulo);
	}else{
		if(navigator.appName == "Netscape") 
			alert("Presione Crtl+D para agregar este sitio en sus Bookmarks");
		 }
	}

function abrirVentana(strUrl, strWindowName,ancho,alto)
{
	var titulo = strWindowName;
	
	if(WindowObjectReference == null || WindowObjectReference.closed)
 	 {
 	 	WindowObjectReference = window.open(strUrl, null,"toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width="+ancho+",height="+alto);
 	 }
  	else
  	{	 
   		WindowObjectReference.focus();
	};
}

function abrirImagen(strUrl, strWindowName,ancho,alto)
{
	if(WindowObjectReference == null || WindowObjectReference.closed)
  {
  WindowObjectReference = window.open(strUrl, strWindowName,"toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+ancho+",height="+alto);
  }
  else
  {
	 
   WindowObjectReference.focus();
  };
}


function creaObjAjax(){
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return http_request;
}


function cambiarIdioma(idioma){
	var rand = Math.random();
	var strUrl = "cambiaIdioma.asp?idi=" + idioma + "&rand=" + rand;
	var objAjax = false;
	objAjax = creaObjAjax();
	objAjax.open("GET",strUrl,false);
	objAjax.onreadystatechange = function() { 
		if (objAjax.readyState == 4) {
			if (objAjax.status == 200) {
				window.location.reload();
				//window.location.href = pag + "?rand=" + rand;
			}
		}
	}
	objAjax.send(null);
}

function sumaVisita(){
	var rand = Math.random();
	var strUrl = "visitas.php?accion=sumar&rand=" + rand;
	var objAjax = false;
	objAjax = creaObjAjax();
	objAjax.open("GET",strUrl,false);
	objAjax.onreadystatechange = function() { 
		if (objAjax.readyState == 4){
			if (objAjax.status == 200){
			}
		}
	}
	objAjax.send(null);
}

function dimeVisitas(){
	var rand = Math.random();
	var strUrl = "visitas.php?accion=consultar&rand=" + rand;
	var objAjax = false;
	var numVisitas = -1;
	objAjax = creaObjAjax();
	objAjax.open("GET",strUrl,false);
	objAjax.onreadystatechange = function() { 
		if (objAjax.readyState == 4){
			if (objAjax.status == 200){ 
				numVisitas = objAjax.responseText;
			}
		}
	}
	objAjax.send(null);
	return numVisitas;
}

function loadCats(codSeccion,pag) {
	if (pag==2) {
		$('volver_1').style.display = 'inline'
		$('volver_2').style.display = 'inline'
	}
	else {
		$('volver_1').style.display = 'none'
		$('volver_2').style.display = 'none'
	}
	var mURL = 'texto_aj.asp';
	new Ajax.Request(mURL,
		{
			method:'post',
			parameters: 'codSeccion='+codSeccion+'&pag='+pag,
			onSuccess: function(transport){
				var response = transport.responseText; 
				rellenaDiv(response)
			},
			onFailure: function(){ }   
	});
}


function rellenaDiv(response) {
	datos = response.split("|");
	$('text').innerHTML = datos[0];
}