// AJAX
	if (!window.XMLHttpRequest)
	{
	    window.XMLHttpRequest = function()
	    {
			// assume IE6 or older
			var xmlHttp = null;
			var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
			'MSXML2.XMLHTTP.5.0',
			'MSXML2.XMLHTTP.4.0',
			'MSXML2.XMLHTTP.3.0',
			'MSXML2.XMLHTTP',
			'Microsoft.XMLHTTP');
			// try every prog id until one works
			for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
			{
				try
				{
					// try to create XMLHttpRequest object
					xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
				}
				catch (e) {} // ignore potential error
			}

			// return the created object or display an error message
			if (!xmlHttp)
				return undefined;
			else
				return xmlHttp;

	    }
	}

    function makeRequest(url,event_handler,method,data,mode) {
        var http_request = false;
        if(method == null) method = 'GET';
        if(mode == null) mode = true;

        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
            // See note below about this line
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() { event_handler(http_request); };
        http_request.open(method, url, mode);
        http_request.send(data);

        return true;
    }
// AJAX


// Para evitar el flirk de las imagenes de background con IE6
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

function setClass(Objeto,Clase){
	Objeto.className=Clase;
}


function validateForm() {
	var i, nm, cmp, req, cal, val, errors='', cmpsError=new Array(), args=validateForm.arguments;
	var reg_exp = /[0-9a-z]([-_.+0-9a-z])*@[0-9a-zñáéíóúÇ]([-.]?[0-9a-zñáéíóúÇ])*\.[a-z]{2,7}/i;
	for (i=0; i < (args.length-2); i+=3) {
		nm=args[i]; cmp=args[i+1]; req=args[i+2];
		val=document.getElementById(cmp).value;
		if ((req=='notempty') && val==""){errors+="* El campo "+nm+" no debe ser vacío\n"; cmpsError.push(cmp); }
		if ((req=='notemptyemail') && !(reg_exp.test(val))){errors+="* El campo "+nm+" debe contener una dirección de e-mail válida\n"; cmpsError.push(cmp); }
		if ((req=='email') && (val!="" && !(reg_exp.test(val)))){errors+="* El campo "+nm+" debe contener una dirección de e-mail válida\n"; cmpsError.push(cmp); }
	}
	if (errors != "") {
		alert('Han ocurrido los siguientes errores:\n\n'+errors);
		for (i=0; i < cmpsError.length; i+=1) {
			$(cmpsError[i]).toggleClassName('campoError');
		}
		return false;
	} else {
		return true;
	}
}

var FinalTapa='N';

function CambiarFinalTapa(Obj){
	FinalTapa='S';
}

function PonerTapa(Elemento){
	var Top=0, Left=0, Height, Width;
	if(Elemento=='Windows'){
		Width=xClientWidth();
		Height=xClientHeight();
	}else{
		Width=$(Elemento).getWidth();
		Height=$(Elemento).getHeight();
		Top = Position.page($(Elemento))[1];
		Left = Position.page($(Elemento))[0];
	}
	Width=Width+'px';
	Height=Height+'px';
	Top=Top+'px';
	Left=Left+'px';
	$("tapa").setStyle({ width: Width,  height: Height, top: Top, left: Left });
	Effect.Appear('tapa', { duration: 0.5, from:0, to:0.8, afterFinish: CambiarFinalTapa });
}

function SacarTapa(){
	Effect.Fade('tapa', { duration: 0.5, from:0.8, to:0 });
}

function MostraAjaxForm(Formulario){
	PonerTapa("Windows");
	new PeriodicalExecuter(function(pe){
		if(FinalTapa=='S'){
			pe.stop();
			FinalTapa='N'
			$('AjaxFormContainer').show();
			$(Formulario).show();
		}
	}, 1.0);
}

function OcultarAjaxForm(){
	$('ajax_resp_content').update();
	$('ajax_resp_content').hide();
	$('AjaxFormProceso').hide();
}

function EnviarAjaxForm(codigo){
	$('ajax_resp_content').update();
	$('ajax_resp_content').hide();
	$('AjaxFormProceso').show();
	new Ajax.Request("/sp/detalle_ajax.php", { parameters:'cod='+codigo, onComplete :
		function(transport) {
			$('AjaxFormProceso').hide();
			$('ajax_resp_content').show();
			$('ajax_resp_content').update(transport.responseText);
		}
  });
}

function CambiarImagen(codigo,numero){
	$('foto_ampliada').src='http://www.altrex.com.ar/sp/images/productos/'+codigo+'--g--'+numero+'.jpg';
}

function HideDetalle(ele){
	Effect.Fade(ele, { duration: 0.5, from:1, to:0 });
}

function ShowDetalle(ele){
	var WWidth=xClientWidth();
	var Width=$(ele).getWidth();
	var Left = (WWidth-Width)/2;
	Left=Left+'px';
	$(ele).setStyle({ left: Left });
	Effect.Appear(ele, { duration: 0.5, from:0, to:1});
}

function MostrarDetalles(codigo){
	PonerTapa("Windows");
	ShowDetalle('detalle_container');
	EnviarAjaxForm(codigo);
}

function OcultarDetalles(){
	OcultarAjaxForm();
	HideDetalle('detalle_container');
	SacarTapa();
}

function toggle_categoria(elemento){
	if(xGetElementById(elemento).style.display == 'none'){
		ShowProdLatMenu(elemento);
		//setClass(xGetElementById(elemento+'_link'),'br_lateral_prod_bt_1');
	}else{
		HideProdLatMenu(elemento);
		//setClass(xGetElementById(elemento+'_link'),'br_lateral_prod_bt_0');
	}
}

function HideProdLatMenu(elemento){
	Effect.Fade(elemento, { duration: 0.5, from:1, to:0 });
}

function ShowProdLatMenu(elemento){
	Effect.Appear(elemento, { duration: 0.5, from:0, to:1 });
}


function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function GetStartX(){
	var ref = document.getElementById('page_container');
	var refX = ref.offsetLeft + 765;
	return refX;
}

function staticbar(){
	var barheight = document.getElementById("chat_flotante").offsetHeight;
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	var startX = GetStartX(); //set x offset of bar in pixels
	var startY = 35; //set y offset of bar in pixels
	var verticalpos = "fromtop"; //enter "fromtop" or "frombottom"

	function ml(id){
		var el=d.getElementById(id);
		if(d.layers)el.style=el;
		el.sP = function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.V = function(){this.style.display='block';}
		el.x = startX;
		if (verticalpos=="fromtop"){
			el.y = startY;
		}else{
			el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
			el.y -= startY;
		}
		return el;
	}

	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
			var pY = ns ? pageYOffset : iecompattest().scrollTop;
			ftlObj.y += (pY + startY - ftlObj.y)/8;
		}else{
			var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
			ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}

	ftlObj = ml("chat_flotante");
	ftlObj.V();
	stayTopLeft();
}
