$(document).ready(function(){

//	$("div").css("border","1px solid red");
//	$("td").css("border","1px solid green");
//	$("img").css("border","1px solid pink");

	textobusq = "Buscar producto...";
	$("#q1").val(textobusq);
	
	$("#q1").click(function(){
		actual = $(this).val();

		if(actual == textobusq) {
			$(this).css("color","#777777");
			$(this).val("");
		}
		
		if(actual == "") {
			$(this).css("color","#AAAAAA");
			$(this).val(textobusq);
		}

	});
	
	$("#q1").blur(function() {
		actual = $(this).val();

		if(actual == "") {
			$(this).css("color","#AAAAAA");
			$(this).val(textobusq);
		}
	});

});


function ordenar(x,p) {
	
	var orden = $("#ordenar").val();
	var pag = document.location.href;
	
	/*if(pag.match(/"start"/i) == null) {
		pag = pag + "?orden=" + orden;
	} else {
		pag = pag + "&orden=" + orden;
	}*/
	
	
	
	document.location = p+"?orden="+orden;
	
}


function agregar(x)
{
	var v = $("#producto_"+x).val();
	$("#carrito").html("<div class='pos_carrito'><img alt='Cargando' src='images/cargando.gif'/><br/>Cargando...</div>");
	$.ajax({
		type:'get',
		dataType:'html',
		url:"agregar-carrito.php?idproducto="+x+"&q="+v,
		success:function(a){
			$("#carrito").html(a);
		}
	});
	
}


function eliminar(x)
{
	document.location = "eliminar-carrito.php?idproducto="+x;
}

function activarspin() {
	$("input.addcart").spin();
}

function ver_carrito() {
	$("#carrito").html("<div class='pos_carrito'><img alt='Cargando' src='images/cargando.gif'/><br/>Cargando...</div>");
	$.ajax({
		type:'get',
		dataType:'html',
		url:"carrito.php",
		success:function(a){
			$("#carrito").html(a);
		}
	});
}

function carrito_mod(a,b) {

	var c = true;

	if(a=="mod") {
		var v = $("#producto_"+b).val();
	} else {
		if(confirm("Realmente desea eliminar este producto del carrito?") == false) {
			c = false;
		}
		var v = 0;
	}
	
	if(c) {
	
		$.ajax({
			type:'get',
			dataType:'html',
			url:"agregar-carrito.php?idproducto="+b+"&q="+v,
			success:function(d){
				if(a=="del") {
					$("#tr_"+b).remove();
				} else {
					activar_msg_mod(b);
				}
				$("#carrito").html(d);			
			}
		});
		
	}
}

function activar_msg_mod(x) {
	$("#celda_"+x).append(" <span class='alertmod'>Modificado</span>");
	setTimeout(killmod,2000);
}

function killmod() {
	$(".alertmod").fadeOut();
}

function validar()
{
	var msg = '';
	var d = document.form1;
	
	if( d.nombre.value == '' )
		msg += 'Debe completar su nombre.\n';
	if( d.apellido.value == '' )
		msg += 'Debe completar su apellido.\n';
	if( d.email.value == '' )
		msg += 'Debe completar su dirección de email.\n';
	if( d.telefono.value == '' )
		msg += 'Debe completar su teléfono.\n';
	if( d.localidad.value == '' )
		msg += 'Debe completar la localidad.\n';
	if( d.provincia.value == '' )
		msg += 'Debe completar la provincia.\n';
	
	if( msg == '' )
		return true;
	else
	{
		alert(msg);
		return false;
	}
}

function imprimir_mail() {

	$("#acamail").html("<a href='mailto:info" + "&#64" + "raovet.com.ar'>" + "info" + "&#64" + "raovet.com.ar</a>");

}


function agregar_detalle(x)
{
	var v = $("#producto_"+x).val();
	$("#carrito").html("<div class='pos_carrito'><img alt='Cargando' src='images/cargando.gif'/><br/>Cargando...</div>");
	$.ajax({
		type:'get',
		dataType:'html',
		url:"agregar-carrito.php?idproducto="+x+"&q="+v,
		success:function(a){
			$("#carrito").html(a);
			$("#botonagregar").remove();
			$("#acaboton").html("<span class='alertmod'>Agregado!</span>");
		}
	});
	
}
