function GetXmlHttpObject(handler){ 
var objXmlHttp=null;

if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP";
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP";
} 
try
{ 
objXmlHttp=new ActiveXObject(strName);
objXmlHttp.onreadystatechange=handler;
return objXmlHttp;
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled");
return;
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest();
objXmlHttp.onload=handler;
objXmlHttp.onerror=handler;
return objXmlHttp;
}
} 

function keepshopping(){ 
document.location = "./default.asp";
} 

function switchMenu(obj){
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function comprar(p,n,i){ 
if(document.frmComprar.encarrito.value==1){
	alert('Ya tiene este producto en su carrito');
}else{
	var url="c.asp?n=" +n +"&p=" +p;
	var txt="&nbsp;productos";
	xmlHttp=GetXmlHttpObject(stateComprar);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	if(i==0){
	txt="&nbsp;producto"
	}
	contenidoCarrito.innerHTML = '<img src="./images/carrito.gif" height="25" alt="" border="0" align="absmiddle">&nbsp;&nbsp;<a href="./carrito_1.asp">' + (i+1) + txt + '</a>';
	document.frmComprar.encarrito.value=1;
	document.frmComprar.imgCar.src = './images/carritof.gif';
	}
}

function getD(id){ 
document.location = "./detalle.asp?prd=" + id;
} 
function getL(id){ 
document.location = "./listado.asp?cat=" + id;
} 

function stateChanged(){ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById('detx').innerHTML= xmlHttp.responseText;
document.getElementById('loading').style.display = 'none'; 
document.getElementById('detx').style.display = ''; 
}
} 

function stateChanged2(){ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById('detprd').innerHTML= xmlHttp.responseText;
document.getElementById('loading2').style.display = 'none'; 
document.getElementById('detprd').style.display = ''; 
}
} 
function stateComprar(){ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
}
} 
function popup(url){
WindowObjectReference = window.open(url,'','menu=0,resizable=1,scrollbars=1');
}
		
function openWindow(url, width, height) {
  var win;
  var windowName;
  var params;
  windowName  = "features";
  params = "toolbar=0,";
  params += "location=0,";
  params += "directories=0,";
  params += "status=0,";
  params += "menubar=0,";
  params += "scrollbars=1,";
  params += "resizable=1,";
  params += "top=50,";
  params += "left=50,";
  params += "width="+width+",";
  params += "height="+height;
  win = window.open(url, windowName, params);

  win.focus();

  return;
}
	
function validarEmail(){
var valor = document.formLogin.usu.value

  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
  {    
    return true;
  } else {
    alert("La direccion de email no es valida");
    return false;
  }
}

function validarEmailRegistro(){
var valor = document.formRegistro.mail.value

  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
  {    
    return true;
  } else {
    alert("La direccion de email no es valida");
    return false;
  }
}

function validarPwd2() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.formRegistro.pwd1.value;
var pw2 = document.formRegistro.pwd2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (pw1.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (pw1.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else {
alert('Nice job.');
return true;
      }
   }
}

function validarPwd(){
	var p1 = document.formRegistro.pwd1.value;
	var p2 = document.formRegistro.pwd2.value;
	
	if (p1 == p2){		
		return true;
	}else{
		alert("Los passwords no coinciden");
		return false;
	}
}

function isNumberKey(evt,field){  
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
  return false;
  
if(field.style.backgroundColor == "red")
  field.style.backgroundColor = "white"
return true;
}

function foco(){
	document.form1.s.focus();
}

function validarCantidad(){
  if(document.comprar.prdCnt.value.length<1)
  {
    document.comprar.prdCnt.style.backgroundColor = "red";
    return false;
   }
   
  if(document.comprar.prdCnt.value<1)
  {
    document.comprar.prdCnt.style.backgroundColor = "red";
    return false;
   }   
   
   document.comprar.submit();
   //return true;
}

function checkout(){
		if(confirm("Confirma finalizar el pedido?"))
			document.location = "./finalizar.asp";
}

function checkout3(){
		if(confirm("Confirma finalizar el pedido?"))			
			document.frmCarrito.finalizado.value = 1;
			document.frmCarrito.action = './carrito_3.asp';
			document.frmCarrito.submit();
}

function checkout2(){
	document.location = "./carrito_2.asp";
}

function mostrar(obj,img) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
		document.getElementById(img).src = '/images/search_show.gif';
	}
	else {
		el.style.display = '';
		document.getElementById(img).src = '/images/search_hide.gif';
	}
}

function preview(id){ 
document.getElementById('detprd').style.display = 'none'; 
document.getElementById('loading2').style.display = ''; 
var url="prev.asp?prd=" + id ;

xmlHttp=GetXmlHttpObject(stateChanged2);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
}

function addEngine(){
    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function"))
    {
        window.sidebar.addSearchEngine(
            "http://www.fastimport.com.uy/firefox/fastimport.src",  /* engine URL */
            "http://www.fastimport.com.uy/firefox/fastimport.jpg",  /* icon URL */
            "Fastimport",                                         /* engine name */
            "General" );                                               /* category name */
    }
    else
    {
        alert("Necesitas tener Firefox instalado!");
    }
}

function createRequestObject() { 

   var req; 

   if(window.XMLHttpRequest){ 
	  // Firefox, Safari, Opera... 
	  req = new XMLHttpRequest(); 
   } else if(window.ActiveXObject) { 
	  // Internet Explorer 5+ 
	  req = new ActiveXObject("Microsoft.XMLHTTP"); 
   } else { 
	  // There is an error creating the object, 
	  // just as an old browser is being used. 
	  alert('Problem creating the XMLHttpRequest object'); 
   } 

   return req; 

} 

// Make the XMLHttpRequest object 
var http = createRequestObject(); 

function sendRequest(q) { 

  if(q=='')
  {
	document.getElementById("searchResults").innerHTML = '';
  }else{

   // Open PHP script for requests 
   http.open('get', 'z.asp?q='+q); 
   http.onreadystatechange = handleResponse; 
   http.send(null); 
   }

} 

function handleResponse() { 
    
       if(http.readyState == 4 && http.status == 200){ 
    
          // Text returned FROM the PHP script 
          var response = http.responseText; 
    
          if(response) { 
             // UPDATE ajaxTest content 
             document.getElementById("searchResults").innerHTML = response; 
          } 
    
       } 
    
    } 