﻿function Ajax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

var divListado;

/*
//Ver producto
function fChangeProduct(id){	
	divListado = document.getElementById("producto");	
	ajax=Ajax();
	var currentTime = new Date();
	var segundos = currentTime.getSeconds();	
	urls = "mostrar_producto.php?id="+id+"&time="+segundos+"#position";
	ajax.open("GET", urls);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divListado.innerHTML = ajax.responseText
			fver_carrito();			
			$("#nom_prod"+id).css({'color':'804040'});		
			document.location.href = "#position";		
		}
	}
	ajax.send(null);
}
*/

//Agregar pregucto al carro
function func_addProduct(id,nombre,importe){	
	var cantidad = $("#div_"+id+" #cantidad").val();
		
	if (cantidad<=0){
		alert("Debes ingresar una cantidad mayor a 0");
		return false;
	}
	
	$("#div_"+id+" #load").show();		
	ajax=Ajax();
	var currentTime = new Date();
	var segundos = currentTime.getSeconds();	
	urls = "carrito/agregar_producto.php?id="+id+"&nombre="+nombre+"&importe="+importe+"&cantidad="+cantidad+"&time="+segundos;
	ajax.open("GET", urls);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			$("#div_"+id+" #load").hide();
			alert("Su producto ha sigo agregado al carrito!");
			$("#div_"+id+" #cantidad").attr('value','');
		}
	}
	ajax.send(null);
}


//Eliminar producto del carro
function func_deleteProduct(id){
	divListado = document.getElementById("view_carro");
	divListado.innerHTML = "<img src='images/ajax-loader.gif' border='0' align='center'/>";
	
	ajax=Ajax();
	var currentTime = new Date();
	var segundos = currentTime.getSeconds();	
	urls = "carrito/eliminar_producto.php?linea="+id+"&time="+segundos;
	ajax.open("GET", urls);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			fver_carrito();
		}
	}
	ajax.send(null);
}



//Ver carro
function fver_carrito(){
	divListado = document.getElementById("view_carro");	
	ajax=Ajax();
	var currentTime = new Date();
	var segundos = currentTime.getSeconds();	
	urls = "carrito/ver_carrito.php?time="+segundos;
	ajax.open("GET", urls);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divListado.innerHTML = ajax.responseText
		}
	}
	ajax.send(null);
}


/*
//Validar login
function validar_login(usuario,password){
	divListado = document.getElementById("login_gral");	
	ajax=Ajax();
	var currentTime = new Date();
	var segundos = currentTime.getSeconds();	
	urls = "login_validar.php?usuario="+usuario+"&password="+password+"&time="+segundos;
	ajax.open("GET", urls);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divListado.innerHTML = ajax.responseText
		}
	}
	ajax.send(null);
}
*/

/*
//Cambiar imagen galeria
function fCambiar_imagen(imagen,id){
	var url = "admin/img_productos/thumbs_galeria/"+imagen;
	document.getElementById("imagen").src=url;
	$("#imagen_href").attr("href","javascript:fOpen_image('"+imagen+"')");
	if(id){
		$("td div").css("background-color","#fff");
		$("#"+id).css("background-color","#ccc");
	}
}
*/

/*
//Abrir imagen Lightbox
function fOpen_image(img){
$.fancybox({
		'padding'		: 0,
		'autoScale'		: true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'href'			: 'admin/img_productos/'+img,
		'type'			: 'image'
	});
}
*/

/*
//Borrar session
function fBorrar_session(){	
	divListado = document.getElementById("login_gral");	
	ajax=Ajax();
	var currentTime = new Date();
	var segundos = currentTime.getSeconds();	
	urls = "cerrar_session.php?time="+segundos;
	ajax.open("GET", urls);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divListado.innerHTML = ajax.responseText
		}
	}	
	ajax.send(null);
}
*/

