var submt=false;
var cargado=false;
var newslet_tmp = '';
function ajaxDisplay (req, div) { 	
	if (req.readyState == 4) {
		if (req.status == 200) 
		{
			// Inserts the new code inside the "content" div
			//document.getElementById("window").style.display = 'block';
			/*if ( div == 'add2newsletter' )
			{
				document.getElementById(div).innerHTML = newslet_tmp+req.responseText;
				return;
			}*/
			
			
			if ( div == 'mailformstat' )
			{
				eval(req.responseText);
				return;
			}
			
			
			
			document.getElementById(div).innerHTML = req.responseText;
			cargado = true;
			if ( div == 'category_tree')
			{
				if ( fue != null )
					document.getElementById('pop_up_frame').innerHTML = document.getElementById(fue).innerHTML;
			}
		} 
		else	
		{
			// Error message
			document.getElementById(div).innerHTML = "Lo sentimos, ha ocurrido un error.<br>" + req.status + " " + req.statusText;
		}	
	} 
}	

function ajaxSubmit (template, div, imgt, met, params) {
	cargado=false;
	imgt = imgt || 1;
	met = met || 'GET';
	params = params || null;
	var req = null;
	
	//if ( div == 'aj_postit' ){
	if ( imgt == 1){
		document.getElementById(div).innerHTML = '<div align="center" style="padding:5px;"><img src="images_fh/ajax-loader.gif" title="Consultando..." alt="Consultando..."></div>';
	}
	else
	{
		document.getElementById(div).innerHTML = '<div align="center" style="padding:5px;"><img src="images_fh/'+imgt+'.gif" title="Consultando..." alt="Consultando..."></div>';
	}
		
	// Safari, Firefox, etc
	if (window.XMLHttpRequest) {
 		req = new XMLHttpRequest();
		if (req.overrideMimeType) {
			//req.overrideMimeType('text/xml');
			req.overrideMimeType('text/html');
		}
	}
	// Internet Explorer
	else if (window.ActiveXObject) {
		try { req = new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} }
	}
	// When ready calls the function that displays the loaded code
	req.onreadystatechange = function() { ajaxDisplay (req, div); }
	req.open (met, template, true); 
	req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded"); 
	req.send (params);
	submt = false;
}



function ajaxClose (div) {
	document.getElementById(div).style.display = 'none';
}

//####### POST-IT #######
function deleteProducts()
{
	x = document.postitform.elements;
	aux = document.postitform.action+'?';
	if ( x.length != undefined )
	{
		for ( i=0; i<x.length; i++)
		{
			if( x[i].type != 'checkbox' ||  (x[i].type == 'checkbox' && x[i].checked)){
			aux = aux + x[i].name + '=' +x[i].value;
			if( (i+1) != (x.length) ){
				aux = aux+'&'; }
			}
		}
	}
	//alert(aux);
	ajaxSubmit(aux,'aj_postit');	
}


//####### COMPARATIVE PAGE #######
function dropProduct(p,page)
{
	if (document.similarcomparison.prod.length==2)
	{ 
		ok=confirm('Si elimina este producto regresará a la página de inicio'); 
		if(!ok) return false;
	}
	//var postit_prod = new Array();
	//alert(document.similarcomparison.prod[p].checked);
	
	//document.similarcomparison.postit_prod[{math equation="x -1" x=$smarty.foreach.prods.iteration}].checked=false; document.similarcomparison.submit();
	var aux = 'http://'+page+'.acuista.com/~?section='+document.similarcomparison.section.value+'&';
	for (i=0;i<document.similarcomparison.prod.length;i++)
	{
		if (p != i)
			aux = aux+'postit_prod['+i+']='+document.similarcomparison.prod[i].value+'&';
	}
	//alert(aux);
	document.location = aux;
}

function ajaxSubmitT (template, div, timeout) { 
	if(!submt){
		setTimeout('ajaxSubmit(\''+template+'\', \''+div+'\', 2)', timeout );
		submt = true;
	}
		
}


var tries = 0;
var int_id;
function loadImg()
{	
	/*if ( document.getElementById('col1') && document.getElementById('col_left') )
	{
		document.getElementById('col_left').innerHTML = document.getElementById('col1').innerHTML;
		document.getElementById('col1').innerHTML = '';
	}*/
	
	/*var filtros = document.getElementsByName('filtro');
	for ( keyVar in filtros ) { 
		document.getElementsByName('filtro')[keyVar].onmouseover = function(){ this.className="button_white_3" };
		document.getElementsByName('filtro')[keyVar].onmouseout = function(){ this.className='' };
	}*/
	
}

// --------- Mostrar myOrders' menu -----------
function mostrar(menu)
{
	var enlc = document.getElementById(menu);
	if(enlc.style.display=="")
	{
		enlc.style.display='none';
		document.getElementById('sign'+menu).innerHTML = '+';
	}
	else
	{
		enlc.style.display = "";
		document.getElementById('sign'+menu).innerHTML = '-';
	}
}
// ------------------------------------------------------------ MOSTRAR CONFIGURADOR
function verConfigurador(action,config){

	switch (configurador)
	{
		default:
			aux = "<iframe frameborder='0' height='1200' width='580' src='http://www.ec.kingston.com/ecom/config/default.asp?referid=682'> Si no puede ver el configurador por favor haga click <a  href='http://www.ec.kingston.com/ecom/config/default.asp?referid=682'>aqui</a> </iframe>";
			break;
	}

	switch (action)
	{
		case 1:
			document.getElementById('').style.display = '';
			document.getElementById('').innerHTML = "<p>Cerrar</p>"+aux;

			break;
		case 0:
			document.getElementById('').style.display = '';
			//document.getElementById('').innerHTML = '';
			break;
	}


}
// ------------------------------------------------------------ POP UP
function popup(url,alto,ancho,vscroll,allowresize){
			topV=(screen.availHeight/2) - alto/2;
			leftV=(screen.availWidth/2) - ancho/2;
			win="fullscreen=0,directories=0,resizable="+allowresize+",location=0,status=0,scrollbars="+vscroll+",toolbar=0,menubar=0,width="+ancho+",height="+alto+",screenX="+topV+",screenY="+leftV+",top="+topV+",left="+leftV
			variable=window.ven
			if (variable) window.ven.close();
			ven=window.open(url,'ven',win);
			window.ven.focus();
}
// ------------------------------------------------------------ CHANGE PICTURE
function chngPic(picName,imgName)
{
	if (document.images)
	{
		document.getElementById('pic2change').innerHTML = '<img src="'+imgName+'" alt="'+picName+'" title="'+picName+'" />';
    	//imgOn=eval(imgName + ".src");
    	//document[picName].src= imgOn;
    	//document[picName].src = imgName;
	}
}
// ------------------------------------------------------------ CHANGE ATTRIBUTE
function chngAtt(ID,att,val){
	if( document.getElementById(ID) )
	eval("document.getElementById('"+ID+"').style."+att+"='"+val+"';");
}
// ------------------------------------------------------------ GO TO TAB
function gotoTab(ID, total) {
	for (var i=1; i<=total; i++) {
		if(document.getElementById('tab'+i)){
			if (document.getElementById('tab'+i) == document.getElementById(ID)) {
				document.getElementById('tab'+i).className='product_tab_on';
				document.getElementById('info'+i).style.display='block';
			} else {
					document.getElementById('tab'+i).className='product_tab_off';
					document.getElementById('info'+i).style.display='none';
			}
		}
	}
	checkBanner('columna_central');
}
// ------------------------------------------------------------ OCULTAR/MOSTRAR BANNER DERECHA SEGUN TAMANYO DIV PRINCIPAL
function checkBanner(div)
{
	var doc = document.getElementById(div);
	//var debug = document.getElementById('debug');
	//debug.innerHTML = doc.offsetHeight;
	if(doc.offsetHeight > 1500)
		displayTrue('bannerLeft');
	else
		displayFalse('bannerLeft');
}
function displayTrue(div)
{
	var object = document.getElementById(div);
	object.style.display = '';
}
function displayFalse(div)
{
	var object = document.getElementById(div);
	object.style.display = 'none';
}
// ------------------------------------------------------------ DROPDOWN MENU
var mstatus=true;
var timer1=false;
var mstep=8;      //velocidad
var cm=null;
var hide_delay=500; //delay
var tstat=0;
isNS6 = (!document.all && document.getElementById) ? true : false;
function switchDiv(objElement,bolVisible) {
	if(!bolVisible) {
		objElement.style.display = "none";
	} else {
        objElement.style.display = "";
	}
	return 1;
}
function getPos(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos
}
function show(el,m) {
	if (m!=null) {
		m= document.getElementById(m);
	}
	if ((el==null) && (cm)) {
        mstatus=false;
        movefx()
	} else if ((m!=cm) && (m)) {
        if (cm!=null) switchDiv(cm,false);
        switchDiv(m,true);
        fxel=el;
        fxm=m;
        fxrect=0;
        mstatus=true;
        movefx()
	}
    if (m) cm=m;
  	if (tstat==1) {
  		clearTimeout(timer1);
  		tstat=0
  	}
}
function hidemenu(b) {
	if (b)  {
		tstat=1;
		timer1=setTimeout("show(null)",hide_delay);
	}
	else {
		tstat=0;
		show(null);
	}
}
function cancelhide() {
	if (!mstatus) {
		mstatus=1;
	}
	tstat=0;
	clearTimeout(timer1);
}
function movefx() {
	if ((mstatus) && (fxrect>fxm.offsetHeight)) {
		fxrect=fxm.offsetHeight;
		return 1;
	}
	if ((!mstatus) && (fxrect<0)) {
		fxrect=0;
		switchDiv(fxm,false);
		mstatus=true;
		cm=null;
		return 1;
	}
	fxm.style.left = getPos(fxel,"Left")+"px";
	//	fxm.style.clip ='rect(' + (fxm.offsetHeight-fxrect) + ' '+ fxm.offsetWidth + ' ' + (fxm.offsetHeight+60) +' '+ 0 +')';
	// fxm.style.clip ='rect(' + (fxm.offsetHeight+60-fxrect) + ' '+ fxm.offsetWidth + ' ' + fxm.offsetHeight +' '+ 0 +')';
	fxm.style.top = getPos(fxel,"Top")+(fxel.offsetHeight-fxm.offsetHeight+fxrect+2)+"px";
	/*if (isNS6) {
		fxm.style.MozOpacity = fxrect/100;
	} else {
		fxm.style.filter = 'alpha(opacity='+fxrect+')';
	}*/
	if (mstatus) {
		fxrect=fxrect+mstep;
		setTimeout('movefx()',5);
	} else {
		fxrect=fxrect-mstep;
		setTimeout('movefx()',1);
	}
	return 1;
}
// ------------------------------------------------------------ Bï¿½SQUEDA Rï¿½PIDA
// IE 7
function addSearchIE()
{
	window.external.AddSearchProvider("http://www.acuista.com/frontend/home/live-search.xml");
}
// Firefox 1*-1.5
function addSearchFirefox()
{
  if ((typeof window.sidebar == "object") && (typeof
  window.sidebar.addSearchEngine == "function"))
  {
    window.sidebar.addSearchEngine("http://www.acuista.com/frontend/home/acuista.src","http://www.acuista.com/frontend/home/acuista.jpg","Acuista.com. Tienda de informatica online","");
  }
  else
  {
    alert("Error al aï¿½adir el buscador");
  }
}

// ------------------------------------------------------------ EXPANDIR CAJA FILTROS
function expandMe(id,action)
{
	if (action == 'expand')
	{
		document.getElementById(id).style.overflow = 'auto';
		/*document.getElementById(id).style.position = 'absolute';*/
		/*document.getElementById('parent_filtro_'+id).style.width = '300px';
		document.getElementById('parent_filtro_'+id).style.height = '200px';
		document.getElementById('parent_filtro_'+id).style.z-index = '10';*/
	}
	if (action == 'retract')
	{

		document.getElementById(id).style.overflow = 'hidden';
	/*	document.getElementById('parent_filtro_'+id).style.width = '110px';
		document.getElementById('parent_filtro_'+id).style.height = '90px';
		document.getElementById('parent_filtro_'+id).style.z-index = '0';*/
		/*document.getElementById(id).style.z-index = 'auto';
		document.getElementById(id).style.position = 'absolute';*/
	}
}


// ------------------------------------------------------------ MOSTRAR URL DIRECTA A LA FICHA DEL PRODUCTO
function directLink(link)
{
	document.getElementById('directLink').innerHTML = '<b><a href="'+link+'" title="URL directa a la ficha del producto">Copia esta direcci&oacute;n</a></b>';
	document.getElementById('directLink').style.color = 'black';
	document.getElementById('directLink').style.display = 'inline';
}

function checkSearchField()
{
	if(document.getElementById('search_field').value=='Palabra Clave o #')
	{
		alert('Introduzca una Palabra Clave o un Cï¿½digo de Fabricante o un Cï¿½digo de Producto'); return false;
	}
	else
	{
		return true;
	}
}

function checkSearchField2()
{
	if(document.getElementById('search_field2').value=='Palabra Clave o #')
	{
		alert('Introduzca una Palabra Clave o un Cï¿½digo de Fabricante o un Cï¿½digo de Producto'); return false;
	}
	else
	{
		return true;
	}
}

function hideSearchHelp()
{
	document.getElementById('searchhelp').style.overflow = 'hidden';
	document.getElementById('searchhelp').style.display = 'none';
	return true;
}

function showSearchHelp()
{
	document.getElementById('searchhelp').style.overflow = 'hidden';
	document.getElementById('searchhelp').style.display = '';
	return true;
}

// ------------------------------------------------------------ DONDE HE CLICKADO
var fue = null;

function CapturarEvento(e, fuente,left,mouseleft)
{
  //alert(document.getElementById('category_tree').innerHTML);
  left = left || "180px";
  mouseleft = mouseleft || false;

  fue = fuente;

  //if ( !cargado )
  if( ! document.getElementById('pop_up') ) return false;

  	//return false;
  var stop = 1;
  var posx = 0;
  var posy = 0;
  if (!e) var e = window.event;
  if (e.pageX || e.pageY)
  {
    posx = e.pageX;
    posy = e.pageY;
    posy = posy + 1;
  	//scro = posy - 20;
  }
  else if (e.clientX || e.clientY)
  {
    posx = e.clientX + document.body.scrollLeft;
    posy = e.clientY + document.documentElement.scrollTop;
    //posy = posy + 1;
    posy = posy - 5;
  }

  if(mouseleft){left = posx+'px';}
  // ï¿½Pï¿½gina cargada?
  if ( document.getElementById('pop_up') == null )
  	return false;

 // alert(source);

  // Calcular la posiciï¿½n del elemento y mostrarlo en su sitio
  /*if ( document.getElementById('pop_up').offsetHeight < 20 )
  	document.getElementById('pop_up').style.top = posy+'px';
  else*/
    
  document.getElementById('pop_up').style.top = posy+'px';
  //window.scrollTo(0,posy-10);
  //document.getElementById('pop_up').style.top = window.scrollY;   //window.scrollTo(0,posy);
  //window.scrollTo(0, scro);
  document.getElementById('pop_up').style.display = 'inline';


  if (  !cargado )
  {
	document.getElementById('pop_up_frame').innerHTML = '<div align="center" style="padding:5px;">Cargando categor&iacute;as... <br> <img src="images_fh/loading_cats.gif" alt="Loading.."></div>';
  	//alert(fuente);
	if (!e.clientX)
		setTimeout("ClosePopUp();",10000);
  }
  else
  {
  	if( document.getElementById(fuente) )
  		document.getElementById('pop_up_frame').innerHTML = document.getElementById(fuente).innerHTML;
  	//setTimeout("ClosePopUp();",50000);
  }

  document.getElementById('pop_up').style.marginLeft = left;
  document.getElementById('pop_up').style.width = "auto";
  document.getElementById('pop_up').style.height = "auto";
  if( document.getElementById(fuente) )
  {
	  document.getElementById('pop_up').style.color = document.getElementById(fuente).style.color;
	  document.getElementById('pop_up').style.border = document.getElementById(fuente).style.border;
  }
  //document.getElementById('pop_up').style.padding = "5px 10px 5px 10px";
  //document.getElementById('pop_up_frame').style.width = "300px";

}

// ------------------------------------------------------------ ESCONDER POP-UP
function ClosePopUp()
{
  document.getElementById('pop_up').style.display = 'none';
  document.getElementById('pop_up').innerHTML = '<div align="right"><a href="javascript:void(0)" onclick="ClosePopUp();">cerrar [x]</a></div><div id="pop_up_frame"></div>';
}

// ------------------------------------------------------------ FORMULARIO NEWSLETTER
function showMailSubmit()
{
  //document.getElementById('add2newsletter').innerHTML = '<div class="text_s_dark" style="border: 1px solid #666666; padding: 5px; text-align: left;">Reciba las novedades y ofertas de Acuista.com<br/><form action="http://www.acuista.com/~" method="get" name="add2newsform" onsubmit="return false;"><input style="width: 125px;" type="text" id="add2newsinput" value="Introduzca su e-mail" onclick="checkMail()"><br><input type="button" value="Suscribirse" onclick="sendMailSubmit();"></form></div>';
  	ajaxSubmit('http://www.acuista.com/~?ajax_section=tools/add2newsletter&ver_form=1', 'add2newsletter', 'loading_disp');
}

function sendMailSubmit()
{
	ajaxSubmit('http://www.acuista.com/~?section=add2newsletter&ver_respuesta=1&mail='+document.getElementById('add2newsinput').value, 'add2newsletter', 'loading_disp');
}

function checkMail()
{
	if ( document.getElementById('add2newsinput').value == 'Introduzca su e-mail' )
		document.getElementById('add2newsinput').value = '';
}


// ------------------------------------------------------------ GO TO BY AJAX
function checkURL (obj, url, name)
{
	if ( obj.href == url+'~?section='+name ) obj.href = 'javascript:void(0)';
}

function goTo (url, name, divname, params)
{
	divname = divname || 'columna_central';
	params = '&'+params || '';

	if ( name == 'searchby' ) // Bï¿½squeda Avanzada => Aï¿½adimos JS extra
	{
		var headID = document.getElementsByTagName("head")[0];
		var newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = 'http://www.acuista.com/frontend/home/js_fh/searchby.js';
		headID.appendChild(newScript);
	}
	ajaxSubmit(url+'~?ajax_section='+name+params, divname, 'loading_disp'); window.scrollTo(0,0); //window.scrollTo(0,185);
}

// ------------------------------------------------------------ STAR MANAGEMENT

// SHOW X NUMBER OF STARS
var voted = false;
function showstars(x)
{
	for (var i=1; i<=10; i++)
	{
		if (!voted)
		{
			if (i<=x) document.getElementById('s'+i).style.visibility='visible';
			else document.getElementById('s'+i).style.visibility='hidden';
			if (x==2) document.getElementById('ratinglabel').innerHTML = 'Malo';
			else if (x==4) document.getElementById('ratinglabel').innerHTML = 'Regular';
			else if (x==6) document.getElementById('ratinglabel').innerHTML = 'Bueno';
			else if (x==8) document.getElementById('ratinglabel').innerHTML = 'Muy bueno';
			else if (x==10) document.getElementById('ratinglabel').innerHTML = 'Excelente';
		}
	}
}
// MOSTRAR
function vote(url, idprod, x)
{
	voted = true;
	for (var i=1; i<=10; i++)
	{
		if (i<=x) document.getElementById('s'+i).style.visibility='visible';
		else document.getElementById('s'+i).style.visibility='hidden';
	}

	ajaxSubmit(url+'~?ajax_section=vote_product&idprod='+idprod+'&punt='+x, 'product_stars');
	document.getElementById('ratinglabel').innerHTML = 'Gracias por votar';
}

// MOSTRAR ESTRELLAS PARA VOTAR
function showvote(act)
{
	if ( voted ) return false;

	if (act==1)
	{
		document.getElementById('product_stars').style.display='none';
		document.getElementById('vote_product').style.display='block';
	}
	else
	{
		document.getElementById('product_stars').style.display='block';
		document.getElementById('vote_product').style.display='none';
	}
}




/*


//////////////

 ////// /////// ///////  ///////  //      //
/       //      //   //  //   //  //      //
/////// //      ///////  //   //  //      //
      / //      // //    //   //  //      //
//////  //////  //  ///  ///////  /////// //////   !!!!


*/
/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag	= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup	= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};



/* =======================================================
* ypSimpleScroll
* 3/11/2001
* 
* http://www.youngpup.net/
* ======================================================= */

// Modified by Sergi Meseguer (www.zigotica.com) 04/2004
// Now it works with dragger and can use multiple instances in a page



ypSimpleScroll.prototype.scrollNorth = function(count) { this.startScroll(90, count) }
ypSimpleScroll.prototype.scrollSouth = function(count) { this.startScroll(270, count) }
ypSimpleScroll.prototype.scrollWest = function(count) { this.startScroll(180, count) }
ypSimpleScroll.prototype.scrollEast = function(count) { this.startScroll(0, count) }

ypSimpleScroll.prototype.startScroll = function(deg, count) {
	if (this.loaded){
		if (this.aniTimer) window.clearTimeout(this.aniTimer)
		this.overrideScrollAngle(deg)
		this.speed = this.origSpeed
		this.lastTime = (new Date()).getTime() - this.y.minRes
		this.aniTimer = window.setTimeout(this.gRef + ".scroll('"+deg+"','"+count+"')", this.y.minRes)
	}
}

ypSimpleScroll.prototype.endScroll = function() {
	if (this.loaded){
		window.clearTimeout(this.aniTimer)
		this.aniTimer = 0;
		this.speed = this.origSpeed
	}
}

ypSimpleScroll.prototype.overrideScrollAngle = function(deg) {
	if (this.loaded){
		deg = deg % 360
		if (deg % 90 == 0) {
			var cos = deg == 0 ? 1 : deg == 180 ? -1 : 0
			var sin = deg == 90 ? -1 : deg == 270 ? 1 : 0
		} 
		else {
			var angle = deg * Math.PI / 180
			var cos = Math.cos(angle)
			var sin = Math.sin(angle)
			sin = -sin
		}
		this.fx = cos / (Math.abs(cos) + Math.abs(sin))
		this.fy = sin / (Math.abs(cos) + Math.abs(sin))
		this.stopH = deg == 90 || deg == 270 ? this.scrollLeft : deg < 90 || deg > 270 ? this.scrollW : 0
		this.stopV = deg == 0 || deg == 180 ? this.scrollTop : deg < 180 ? 0 : this.scrollH
	}
}

ypSimpleScroll.prototype.overrideScrollSpeed = function(speed) {
	if (this.loaded) this.speed = speed
}


ypSimpleScroll.prototype.scrollTo = function(stopH, stopV, aniLen) {
	if (this.loaded){
		if (stopH != this.scrollLeft || stopV != this.scrollTop) {
			if (this.aniTimer) window.clearTimeout(this.aniTimer)
			this.lastTime = (new Date()).getTime()
			var dx = Math.abs(stopH - this.scrollLeft)
			var dy = Math.abs(stopV - this.scrollTop)
			var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2))
			this.fx = (stopH - this.scrollLeft) / (dx + dy)
			this.fy = (stopV - this.scrollTop) / (dx + dy)
			this.stopH = stopH
			this.stopV = stopV
			this.speed = d / aniLen * 1000
			window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
		}
	}
}

ypSimpleScroll.prototype.jumpTo = function(nx, ny) { 
	if (this.loaded){
		nx = Math.min(Math.max(nx, 0), this.scrollW)
		ny = Math.min(Math.max(ny, 0), this.scrollH)
		this.scrollLeft = nx
		this.scrollTop = ny
		if (this.y.ns4)this.content.moveTo(-nx, -ny)
		else {
			this.content.style.left = -nx + "px"
			this.content.style.top = -ny + "px"
		}
	}
}

ypSimpleScroll.minRes = 10
ypSimpleScroll.ie = document.all ? 1 : 0
ypSimpleScroll.ns4 = document.layers ? 1 : 0
ypSimpleScroll.dom = document.getElementById ? 1 : 0
ypSimpleScroll.mac = navigator.platform == "MacPPC"
ypSimpleScroll.mo5 = document.getElementById && !document.all ? 1 : 0

ypSimpleScroll.prototype.scroll = function(deg,count) {
	this.aniTimer = window.setTimeout(this.gRef + ".scroll('"+deg+"','"+count+"')", this.y.minRes)
	var nt = (new Date()).getTime()
	var d = Math.round((nt - this.lastTime) / 1000 * this.speed)
	if (d > 0){
		var nx = d * this.fx + this.scrollLeft
		var ny = d * this.fy + this.scrollTop
		var xOut = (nx >= this.scrollLeft && nx >= this.stopH) || (nx <= this.scrollLeft && nx <= this.stopH)
		var yOut = (ny >= this.scrollTop && ny >= this.stopV) || (ny <= this.scrollTop && ny <= this.stopV)
		if (nt - this.lastTime != 0 && 
			((this.fx == 0 && this.fy == 0) || 
			(this.fy == 0 && xOut) || 
			(this.fx == 0 && yOut) || 
			(this.fx != 0 && this.fy != 0 && 
			xOut && yOut))) {
			this.jumpTo(this.stopH, this.stopV)
			this.endScroll()
		}
		else {
			this.jumpTo(nx, ny)
			this.lastTime = nt
		}
	// (zgtc) now we also update dragger position:
	if(deg=='270')	theThumb[count].style.top = parseInt(((theThumb[count].maxY-theThumb[count].minY)*this.scrollTop/this.stopV)+theThumb[count].minY) + "px"; //ok nomes down
	if(deg=='90')	theThumb[count].style.top = parseInt(((theThumb[count].maxY-theThumb[count].minY)*this.scrollTop/this.scrollH)+theThumb[count].minY) + "px"; //ok nomes down
	}
}

function ypSimpleScroll(id, left, top, width, height, speed) {
	var y = this.y = ypSimpleScroll
	if (document.layers && !y.ns4) history.go(0)
	if (y.ie || y.ns4 || y.dom) {
		this.loaded = false
		this.id = id
		this.origSpeed = speed
		this.aniTimer = false
		this.op = ""
		this.lastTime = 0
		this.clipH = height
		this.clipW = width
		this.scrollTop = 0
		this.scrollLeft = 0
		this.gRef = "ypSimpleScroll_"+id
		eval(this.gRef+"=this")
		var d = document
		d.write('<style type="text/css">')
		d.write('#' + this.id + 'Container { left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px; clip:rect(0 ' + width + ' ' + height + ' 0); overflow:hidden; }')
		d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; }')
		d.write('#' + this.id + 'Content { left:' + (-this.scrollLeft) + 'px; top:' + (-this.scrollTop) + 'px; width:' + width + 'px; }')
		// (zgtc) fix to overwrite p/div/ul width (would be clipped if wider than scroller in css):
		d.write('#' + this.id + 'Container p, #' + this.id + 'Container div {width:' + parseInt(width-10) + 'px; }')
		d.write('</style>')
	}
}

ypSimpleScroll.prototype.load = function() {
	var d, lyrId1, lyrId2
	d = document
	lyrId1 = this.id + "Container"
	lyrId2 = this.id + "Content"
	this.container = this.y.dom ? d.getElementById(lyrId1) : this.y.ie ? d.all[lyrId1] : d.layers[lyrId1]
	this.content = obj2 = this.y.ns4 ? this.container.layers[lyrId2] : this.y.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
	this.docH = Math.max(this.y.ns4 ? this.content.document.height : this.content.offsetHeight, this.clipH)
	this.docW = Math.max(this.y.ns4 ? this.content.document.width : this.content.offsetWidth, this.clipW)
	this.scrollH = this.docH - this.clipH
	this.scrollW = this.docW - this.clipW
	this.loaded = true
	this.scrollLeft = Math.max(Math.min(this.scrollLeft, this.scrollW),0)
	this.scrollTop = Math.max(Math.min(this.scrollTop, this.scrollH),0)
	this.jumpTo(this.scrollLeft, this.scrollTop)
}



// ==============================================================
// HANDLES SCROLLER/S
// Modified from Aaron Boodman http://webapp.youngpup.net/?request=/components/ypSimpleScroll.xml
// mixed ypSimpleScroll with dom-drag script and allowed multiple scrolelrs through array instances
// (c)2004 Sergi Meseguer (http://zigotica.com/), 04/2004:
// ==============================================================
var theHandle = []; var theRoot = []; var theThumb = []; var theScroll = []; var thumbTravel = []; var ratio = [];

function instantiateScroller(count, id, left, top, width, height, speed){
	if(document.getElementById) {
		theScroll[count] = new ypSimpleScroll(id, left, top, width, height, speed);
	}
}

function createDragger(count, handler, root, thumb, minX, maxX, minY, maxY){
		var buttons = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="images_fh/scroll_up.gif" width="15" height="15"></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="images_fh/scroll_down.gif" width="15" height="15"></a></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="images_fh/scroll_square.gif" width="15" height="15" style="cursor:pointer;"></div>';

		//alert( document.getElementById("scroll"+count+"Content").offsetHeight > '150');
		if ( document.getElementById('scroll'+count+'Content').offsetHeight < 110 ) return;
		
		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;

		theRoot[count]   = document.getElementById(root);
		theThumb[count]  = document.getElementById(thumb);
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);
		theThumb[count].style.left = parseInt(minX+15) + "px";
		thisup.style.left = parseInt(minX+15) + "px";
		thisdn.style.left = parseInt(minX+15) + "px";
		theThumb[count].style.border =0;
		theThumb[count].style.top = parseInt(minY) + "px";
		thisup.style.top = 0 + "px";
		thisdn.style.top = parseInt(minY+maxY) + "px";
		//thisdn.style.top = 15 + "px";

		theScroll[count].load();

		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		Drag.init(theThumb[count], null, minX+15, maxX+15, minY, maxY);
		
		// the number of pixels the thumb can travel vertically (max - min)
		thumbTravel[count] = theThumb[count].maxY - theThumb[count].minY;

		// the ratio between scroller movement and thumbMovement
		ratio[count] = theScroll[count].scrollH / thumbTravel[count];

		theThumb[count].onDrag = function(x, y) {
			theScroll[count].jumpTo(null, Math.round((y - theThumb[count].minY) * ratio[count]));
		}
}	

// INITIALIZER:
// ==============================================================
// ala Simon Willison http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(fn) {
      var old = window.onload;
      if (typeof window.onload != 'function') {
         window.onload = fn;
      }
      else {
         window.onload = function() {
         old();
         fn();
         }
      }
   }
addLoadEvent(function(){
		if(theScroll.length>0) {
		for(var i=0;i<theScroll.length;i++){
			createDragger(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 15, theScroll[i].clipH-30);
		}
	}
}) 


function showhideProducts(action)
{
	var str=window.location.toString();
	str = str.replace(/&show_unavailable/g,"");
	str = str.replace(/&hide_unavailable/g,"");
	window.location=str+'&'+action;
}

//---------------------------- AJAXSEND PARA EL FORMULARIO EN LA SECCION CONTACTO

function send_form(){
	frm = document.getElementById('mailform');
	posttxt = 'mailform_name=' + frm.mailform_name.value + '&mailform_email=' + frm.mailform_email.value+ '&mailform_npedido=' + frm.mailform_npedido.value+ '&mailform_asunto=' + frm.mailform_asunto.options[frm.mailform_asunto.selectedIndex].value + '&mailform_body=' + frm.mailform_body.value;
	ajaxSubmit ('http://www.acuista.com/?ajax_section=mailform', 'mailformstat', 1, 'POST', posttxt)
}

function clear_send_form(){
	frm = document.getElementById('mailform');
	frm.mailform_name.value = '';
	frm.mailform_email.value = '';
	frm.mailform_npedido.value = '';
	frm.mailform_body.value = '';
}


function ocultacapa (kpa) {
	document.getElementById(kpa).style.visibility="hidden";
}

function muestracapa (kpa) {
	document.getElementById(kpa).style.visibility="visible";
}
function quitarB(t) {
	var patron = /(<b>)([^<]+)(<\/b>)/g;
	return t.replace(patron,'$2');
}
/*
 * Navegar con el teclado por las sugerencias de busqueda
 * input: e -> event.keyCode
 *
shItem=0;
function eKey(e) {
	if (e == 38 && shItem > 1 && document.getElementById('searchhelp').style.display != 'none') {
		shItem=shItem-1;
		document.getElementById('search_field').value = quitarB(document.getElementById('search_helpId'+shItem).value);							
		return false;
	} else if (e == 40 && shItem < 10 && document.getElementById('searchhelp').style.display != 'none') {
		shItem=shItem+1;
		document.getElementById('search_field').value = quitarB(document.getElementById('search_helpId'+shItem).value);
		return false;
	} else if (e == 27) {
		hideSearchHelp();
		return false;
	} else 
		return true;
}*/
