// JavaScript Document
var baseUrl = 'http://www.alsuper.com.do/web/';

function jQueryAjaxSend(jform, jtype, jurl, jredirect)
{
	var res=$(jform).valid();
	if (res == false){
		return false;
	} else {
		$.ajax({
		type: jtype,
		url: jurl,
		data: $(jform).serialize(),
		
		beforeSend:function(){
		// this is where we append a loading image
			$('#submit').hide();
			$('#load').show();
			$('#load').html('<span><img src="'+baseUrl+'assets/doppler/images/loadSm.gif" alt="Loading..." /></span>');
		},
		
		success:function(data){
		// successful request; do something with the data
		if(data == 1){   
			//$(location).attr('href',jredirect);
			parent.location = jredirect;
		}else{
			$('.error_msg').html("<span id='errors'>"+data+"</span>");
			$('#load').html('');
			$('#load').hide();
			$('#submit').show();
			//$.scrollTo( '#main_content', 800, {easing:'elasout'} );
			$(document).scrollTo('#main_content');	
		}
		},
		
		error:function(){
		// failed request; give feedback to user
			$('#error_msg').html('<div class="box box-error" style="margin-top:7px"><strong>Advertencia:</strong> hubo problemas al realizar esta operaci&oacute;n.</div>');
			$('#load').html('');
			$('#load').hide();
			$('#submit').show();
		}
		});	
	}	
}

function jQueryAjaxDeleteCart(jtype, jurl)
{
	//alert(id+jtype+jurl+jredirect);
	if (confirm('Advertencia: Esta seguro que desea borrar los items del carrito?'))
	{		
	$.ajax({
	type: jtype,
	url: jurl,
	
	beforeSend:function(){
	// this is where we append a loading image
	/*$('#submit-'+id).hide();
	$('#load-'+id).html('<span><img src="'+baseUrl+'assets/img/nyro/loadSm.gif" alt="Loading..." /> procesando</span>');*/
	
	},
	
	success:function(data){
	// successful request; do something with the data
	if(data == 1){   
	//$(location).attr('href',jredirect);
	$('#response').html('<div class="box box-success" style="margin-top:7px"><strong>Exito!</strong> La operaci&oacute;n fue procesada exitosamente.</div>');
	$('#rebbon_total').html("$0.00");
	$('#table-holder').html('<h2 style="color:#999;">El carrito esta vac&iacute;o...</h2>');
	}else{
	$('#response').html(data);	
	}
	},
	removeEventCallback : function (elem) {
		$("tr.address:odd").addClass("row_odd");
		$("tr.address:even").addClass("row_even");
    },
	
	error:function(){
	// failed request; give feedback to user
	$('#response').html('<div class="box box-error " style="margin-top:7px"><strong>Advertencia:</strong> problemas para eliminar el registro.</div>');
	/*$('#load-'+id).html('');
	$('#submit-'+id).show();*/
	}
	
	});	
	}
	else
	{
		return false;
	}	
}

function jQueryAjaxDeleteItemCart(id, jtype, jurl, jredirect)
{
	//alert(id+jtype+jurl+jredirect);
	if (confirm('Advertencia: Esta seguro que desea borrar el item?'))
	{		
		$.ajax({
		type: jtype,
		url: jurl,
		
		beforeSend:function(){
		// this is where we append a loading image
		$('#submit-'+id).hide();
		$('#load-'+id).html('<span><img src="'+baseUrl+'assets/doppler/images/loadSm.gif" alt="Loading..." /></span>');
		
		},
		
		success:function(data){
		// successful request; do something with the data
		
		if(data != "" || data != 0){   
			//$(location).attr('href',jredirect);
			var e = $('#blck-content').find('.verify').length;
			
			if (e == 1)
			{		
				$('#rebbon_total').html("$0.00");
				$('#table-holder').html('<h2 style="color:#999;">El carrito esta vac&iacute;o...</h2>');
			}else
			{
				/*$('#response').html('<div class="box box-success" style="margin-top:7px"><strong>Exito!</strong> La operaci&oacute;n fue procesada exitosamente.</div>');*/
				
				$('#product_'+id).fadeOut('400');
				
				setTimeout( function() { $("#product_"+id).remove(); }, 400 );
		
				//$('#blck-content').find('#product_'+id).remove();
				//$('#product_'+id).remove();
				$('#cart_total').val("RD$"+formatCurrency(data));
				$('#rebbon_total').html("$"+formatCurrency(data));
				$('#hidden_cart_total').val(data);
			}	
		}else{
			$('#response').html(data);
			$('#load-'+id).html('');
			$('#submit-'+id).show();
		}
		},
		removeEventCallback : function (elem) {
			$("li.contacts:odd").addClass("odd");
			$("li.contacts:even").addClass("even");
	    },
		
		error:function(){
		// failed request; give feedback to user
		$('#response').html('<div class="box box-error " style="margin-top:7px"><strong>Advertencia:</strong> problemas para eliminar el registro.</div>');
		$('#load-'+id).html('');
		$('#submit-'+id).show();
		}
		
		});	
	}
	else
	{
		return false;
	}	
}

function jQueryAjaxDeleteList(id, jtype, jurl)
{
	//alert(id+jtype+jurl+jredirect);
	if (confirm('Advertencia: Esta seguro que desea borrar el item?'))
	{		
		$.ajax({
		type: jtype,
		url: jurl,
		
		beforeSend:function(){
		// this is where we append a loading image
		$('#submit-'+id).hide();
		$('#load-'+id).html('<span><img src="'+baseUrl+'assets/doppler/images/loadSm.gif" alt="Loading..." /></span>');
		
		},
		
		success:function(data){
		// successful request; do something with the data
			var e = $('#myproducts').find('.mylist').length;
			
			if (e == 1)
			{				
				$('#myproducts').html('<h3 style="font-size:19px; color:#999;">No ha agregado ninguna lista...</h3>');
			}else
			{
				/*$('#response').html('<div class="box box-success" style="margin-top:7px"><strong>Exito!</strong> La operaci&oacute;n fue procesada exitosamente.</div>');*/
				$('#list_product_'+id).fadeOut('slow');
				$('#list_product_'+id).remove();
				
			}	
		},
		removeEventCallback : function (elem) {
			$("li.contacts:odd").addClass("odd");
			$("li.contacts:even").addClass("even");
	    },
		
		error:function(){
		// failed request; give feedback to user
		$('#response').html('<div class="box box-error " style="margin-top:7px"><strong>Advertencia:</strong> problemas para eliminar el registro.</div>');
		$('#load-'+id).html('');
		$('#submit-'+id).show();
		}
		
		});	
	}
	else
	{
		return false;
	}	
}


function jQueryAjaxDeleteAddress(id, jtype, jurl)
{
	//alert(id+jtype+jurl+jredirect);
	if (confirm('Advertencia: Esta seguro que desea borrar el item?'))
	{		
		$.ajax({
		type: jtype,
		url: jurl,
		
		beforeSend:function(){
		// this is where we append a loading image
		$('#submit-'+id).hide();
		$('#load-'+id).html('<span><img src="'+baseUrl+'assets/doppler/images/loadSm.gif" alt="Loading..." /></span>');
		
		},
		
		success:function(data){
		// successful request; do something with the data
			var e = $('#myaddress').find('.address').length;
			if (data == 1)
			{
				if (e == 1)
				{
					$('.title_address').html('');
				}	
				/*$('#response').html('<div class="box box-success" style="margin-top:7px"><strong>Exito!</strong> La operaci&oacute;n fue procesada exitosamente.</div>');*/
				//$('#address_'+id).fadeOut('slow');
				$('#address_'+id).remove();				
			}
			
		},
		removeEventCallback : function (elem) {
			$("tr.address:odd").addClass("row_odd");
			$("tr.address:even").addClass("row_even");
	    },
		
		error:function(){
		// failed request; give feedback to user
		$('#response').html('<div class="box box-error " style="margin-top:7px"><strong>Advertencia:</strong> problemas para eliminar el registro.</div>');
		$('#load-'+id).html('');
		$('#submit-'+id).show();
		}
		
		});	
	}
	else
	{
		return false;
	}	
}

function jQueryAjaxSendSingle2(id, jtype, jurl, target)
{
	//alert(jurl+id);
	$.ajax({
	type: jtype,
	url: jurl+id,
	
	beforeSend:function(){
	// this is where we append a loading image	
	},
	
	success:function(data){
	// successful request; do something with the data
	var a = $(target).css("display");
	if (a == 'none')
	{
		$('#change_'+id).html("<img src='"+baseUrl+"assets/doppler/images/icon_menos.jpg'>");
	}else
	{
		$('#change_'+id).html("<img src='"+baseUrl+"assets/doppler/images/mas_icon.jpg'>");
	}
	$(target).html(data);
	$(target).slideToggle('800');
		
	},
	
	error:function(){
	// failed request; give feedback to user
	$(target).html('<div class="box box-error " style="margin-top:7px"><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
	}
	});	
}

function jQueryAjaxSendSingleUbication(id, jtype, jurl, target)
{
	//alert(jurl+$(id).val());
	if ($(id).val()==0)
	{
		alert('Selecione una opción');	
	}
	else
	{
		//alert(jurl+$(id).val());
		$.ajax({
		type: jtype,
		url: jurl+$(id).val(),
		
		beforeSend:function(){
		// this is where we append a loading image
		},
		
		success:function(data){
		// successful request; do something with the data
		$(target).html(data);
		},
		
		error:function(){
		// failed request; give feedback to user
		$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
		}
		});	
	}		
	
}



function jQueryAjaxSendSingleModal(jtype, jurl, target)
{
	//alert(jurl+$(id).val());
	$.ajax({
	type: jtype,
	url: jurl,
	
	beforeSend:function(){
	// this is where we append a loading image
	},
	
	success:function(data){
	// successful request; do something with the data
	$(target).html(data);
	},
	
	error:function(){
	// failed request; give feedback to user
	$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
	}
	});		
}

function jQueryAjaxSendSingleCatalog(id, jtype, jurl)
{
	var returnUrl = window.location.pathname;

	$.ajax({
	type: jtype,
	url: jurl+$(id).val(),
	
	beforeSend:function(){
	// this is where we append a loading image
	},
	
	success:function(data){
	// successful request; do something with the data
		//alert(data);
		$(location).attr('href',returnUrl);
	},
	
	error:function(){
	// failed request; give feedback to user
	
	}
	});		
}

function modal(idm)
{
	//Get the A tag
	var id = idm;

	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
	//$('#mask').fadeIn(100);	
	$('#mask').fadeTo("fast",0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
          
	//Set the popup window to center
	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);

	//transition effect
	$(id).fadeIn(100); 
	

	
	//if close button is clicked
	$('.window .close').click(function () {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	
	
}

function jQueryAjaxSendBottomPrev(jtype, jurl, target)
{;
	$.ajax({
	type: jtype,
	url: jurl,
	
	beforeSend:function(){
	// this is where we append a loading image
	},
	
	success:function(data){
	// successful request; do something with the data
		if(data != 0)
		{
			//$(target).append(data);
			var element = '#slider-holder';
			//error.insertAfter(element.parent().find('label:first'));
			$(data).insertBefore($(target).find('li:first'));
		}
	},
	
	error:function(){
	// failed request; give feedback to user
	$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
	}
	});		
}

function jQueryAjaxSendBottomNext(jtype, jurl, target)
{
	$.ajax({
	type: jtype,
	url: jurl,
	
	beforeSend:function(){
	// this is where we append a loading image
	},
	
	success:function(data){
	// successful request; do something with the data
		if(data != 0)
		{
			$(target).append(data);
		}
	},
	
	error:function(){
	// failed request; give feedback to user
	$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
	}
	});		
}

function jQueryAjaxSendNumPag(jtype, jurl, target)
{
	$.ajax({
	type: jtype,
	url: jurl,
	
	beforeSend:function(){
	// this is where we append a loading image
	},
	
	success:function(data){
	// successful request; do something with the data
		if(data != 0)
		{
			$(target).html(data);
		}
	},
	
	error:function(){
	// failed request; give feedback to user
	$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
	}
	});		
}

function jQueryAjaxSendSingle(id, jtype, jurl, cartId)
{
	/*alert(jurl+cartId+"/"+$('#quantity_'+id).val());*/
	var val = $(id).val();
	if (val == 0 || val == "" || isNaN(val) == true)
	{
		alert('El valor es incorrecto o no ha ingresado nada en el campo!');		
		document.getElementById(id).value = "";
		document.getElementById(id).focus();
	}else
	{
		$.ajax({
		type: jtype,
		url: jurl+cartId+"/"+$(id).val(),
		
		beforeSend:function(){
		// this is where we append a loading image
		},
		
		success:function(data){
		// successful request; do something with the data
	
		var text = data.split('-');
		$('#cart_total').val("RD$"+formatCurrency(text[0]));
		$('#rebbon_total').html("$"+formatCurrency(text[0]));
		$('#rebbon_total_ticket').html("$"+formatCurrency(text[0]));
		$('#hidden_cart_total').val(text[0]);
		$('#price_total_'+cartId).html("RD$"+formatCurrency(text[1]));
		$('#amount_coupon_hidden').val(text[2]);
		$('#amount_coupon').html("RD$"+formatCurrency(text[2]));		
		},
		
		error:function(){
		// failed request; give feedback to user
		$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
		}
		});		
	}
}


function jQueryAjaxSendSingleCoupon(id, jtype, jurl)
{
	
	var val = $(id).val();
	var total = $('#hidden_cart_total').val();
	if (val == 0 || val == "")
	{	
		document.getElementById(id).value = "";
		document.getElementById(id).focus();
	}else
	{
		$.ajax({
		type: jtype,
		url: jurl+val+"/"+total,
		
		beforeSend:function(){
		// this is where we append a loading image
		},
		
		success:function(data){
		// successful request; do something with the data
			if(data!='f')
			{
				var text = data.split('-');
				$('#cart_total').val("RD$"+formatCurrency(text[0]));
				$('#hidden_cart_total').val(text[0]);
				$('#amount_coupon_hidden').val(text[1]);
				$('#rebbon_total').html("$"+formatCurrency(text[0]));
				$('#amount_coupon').html("RD$"+formatCurrency(text[1]));
				$('#discount_coupon_code').val("");
				jQuery.noticeAdd({
		            text: 'El cupón fue procesado!',
		            stay: false,
		            type: 'success'
		    	});	
			}else{
				$('#discount_coupon_code').val("");
				jQuery.noticeAdd({
		            text: 'El cupón es invalido!',
		            stay: false,
		            type: 'success'
		    	});	
			}
			
		},
		
		error:function(){
		// failed request; give feedback to user
		//$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
		}
		});		
	}
}

function jQueryAjaxSendSingleChangeSalect(id, jtype, jurl, cartId, typeId)
{
	/*alert(jurl+cartId+"/"+$('#quantity_'+id).val());*/
	var val = $(id).val();
	if (val == 0 || val == "" || isNaN(val) == true)
	{
		alert('El valor es incorrecto o no ha ingresado nada en el campo!');		
		document.getElementById(id).value = "";
		document.getElementById(id).focus();
	}else
	{
		$.ajax({
		type: jtype,
		url: jurl+cartId+"/"+$(id).val(),
		
		beforeSend:function(){
		// this is where we append a loading image
		},
		
		success:function(data){
		// successful request; do something with the data
		var text = data.split('-');
		$('#cart_total').val("RD$"+formatCurrency(text[0]));
		$('#hidden_cart_total').val(text[0]);
		$('#rebbon_total').html("$"+formatCurrency(text[0]));
		$('#price_total_'+cartId).html("RD$"+formatCurrency(text[1]));	
		$('#td_weight_'+cartId).html('<span onclick="changeSelect(\'#td_weight_'+cartId+'\', \''+baseUrl+'cart/change_select/'+val+'/'+typeId+'/\', \''+cartId+'\')">'+val+' lb</span>');	
		
		},
		
		error:function(){
		// failed request; give feedback to user
		$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
		}
		});		
	}
}

function addToCart(idp, jurl, idc)
{
	var quantity = $('#quantity_'+idp).val();
	//alert(jurl+"/"+idp+"/"+idc+"/"+quantity);
	$.ajax({
	type: 'GET',
	url: jurl+"/"+idp+"/"+idc+"/"+quantity,

	beforeSend:function(){
	},
	
	success:function(data){
		if(data != 0)	
		{
			jQuery.noticeAdd({
	            text: 'Producto agregado al carrito!',
	            stay: false,
	            type: 'success'
        	});

			$('#rebbon_total').html("$"+formatCurrency(data));
		}else{
			alert("El producto no pudo ser agregado al carrito.");
		}
		//addNotice({text: "", title:'Producto agregado!', type:'success_notify',position:'center'});
	},

	error:function(){
		alert("Error agregando el producto.");
	}
	
	});	
}



function jQueryAjaxSendSingleForm(jform,jtype, jurl, paymentForm)
{
	$.ajax({
	type: jtype,
	url: jurl,
	data: $(jform).serialize(),
	
	beforeSend:function(){
	// this is where we append a loading image
	$('#submit2').hide();
	$('#load').show();
	$('#load').html('<span><img src="'+baseUrl+'assets/doppler/images/loadSm.gif" alt="Loading..." /></span>');
	},
	
	success:function(data){
	// successful request; do something with the data
	
		if (data == "" || data == 0)
		{
			alert('La orden no pudo ser procesada!');
		}else
		{
			if (paymentForm == 12)
			{
				window.location = baseUrl+'cart/auth/'+paymentForm;
			}else
			{
				$('#orderId').val(data);
				$('#cartnet').submit();
			}
		}	
	},
	
	error:function(){
	// failed request; give feedback to user
	$('#response').html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
	}
	});	
}

//**************************************************************************************
//laboleteria / tikect office

function addToCartTicket(idps, jurl, idc)
{
	var quantity = $('#quantity_'+idps).val();
	//alert(jurl+"/"+idp+"/"+idc+"/"+quantity);
	$.ajax({
	type: 'GET',
	url: jurl+"/"+idps+"/"+idc+"/"+quantity,

	beforeSend:function(){
	},
	
	success:function(data){
		
		if(data != 0)	
		{
			var e = $('.cpt_maincontent').find('#header').length;
			if(e != 0)
			{
				window.location = baseUrl+"cart_laboleteria";
			}else
			{
				jQuery.noticeAdd({
		            text: 'Producto agregado al carrito!',
		            stay: false,
		            type: 'success'
	        	});
				$('#rebbon_total_ticket').html("$"+formatCurrency(data));
			}
			
		}else{
			alert("El producto no pudo ser agregado al carrito.");
		}
		//addNotice({text: "", title:'Producto agregado!', type:'success_notify',position:'center'});
	},

	error:function(){
		alert("Error agregando el producto.");
	}
	
	});	
}

function jQueryAjaxDeleteItemCartTicket(id, jtype, jurl, jredirect)
{
	//alert(id+jtype+jurl+jredirect);
	if (confirm('Advertencia: Esta seguro que desea borrar el item?'))
	{		
		$.ajax({
		type: jtype,
		url: jurl,
		
		beforeSend:function(){
		// this is where we append a loading image
		$('#submit-'+id).hide();
		$('#load-'+id).html('<span><img src="'+baseUrl+'assets/doppler/images/loadSm.gif" alt="Loading..." /></span>');
		
		},
		
		success:function(data){
		// successful request; do something with the data
		
		if(data != "" || data != 0){   
			//$(location).attr('href',jredirect);
			var e = $('#blck-content').find('.verify').length;
			
			if (e == 1)
			{		
				$('#rebbon_total_ticket').html("$0.00");
				$('#table-holder').html('<h2 style="color:#999; font-weight:normal;"">El carrito esta vac&iacute;o...</h2>');
			}else
			{
				/*$('#response').html('<div class="box box-success" style="margin-top:7px"><strong>Exito!</strong> La operaci&oacute;n fue procesada exitosamente.</div>');*/
				
				$('#product_'+id).fadeOut('300');
				
				setTimeout( function() { 
					$("#product_"+id).remove(); 
					$("tr.address:odd").addClass("row_odd");
					$("tr.address:even").addClass("row_even");					
				}, 300 );
		
				//$('#blck-content').find('#product_'+id).remove();
				//$('#product_'+id).remove();
				$('#cart_total').val("RD$"+formatCurrency(data));
				$('#rebbon_total_ticket').html("$"+formatCurrency(data));
				$('#hidden_cart_total').val(data);
				
			}	
		}else{
			$('#response').html(data);
			$('#load-'+id).html('');
			$('#submit-'+id).show();
		}
		},
		removeEventCallback : function (elem) {
			$("tr.address:odd").addClass("row_odd");
			$("tr.address:even").addClass("row_even");
	    },
		
		error:function(){
		// failed request; give feedback to user
		$('#response').html('<div class="box box-error " style="margin-top:7px"><strong>Advertencia:</strong> problemas para eliminar el registro.</div>');
		$('#load-'+id).html('');
		$('#submit-'+id).show();
		}
		
		});	
	}
	else
	{
		return false;
	}	
}

function jQueryAjaxDeleteCartTicket(jtype, jurl)
{
	//alert(id+jtype+jurl+jredirect);
	if (confirm('Advertencia: Esta seguro que desea borrar los items del carrito?'))
	{		
	$.ajax({
	type: jtype,
	url: jurl,
	
	beforeSend:function(){
	// this is where we append a loading image
	/*$('#submit-'+id).hide();
	$('#load-'+id).html('<span><img src="'+baseUrl+'assets/img/nyro/loadSm.gif" alt="Loading..." /> procesando</span>');*/
	
	},
	
	success:function(data){
	// successful request; do something with the data
	if(data == 1){   
	//$(location).attr('href',jredirect);
	$('#response').html('<div class="box box-success" style="margin-top:7px"><strong>Exito!</strong> La operaci&oacute;n fue procesada exitosamente.</div>');
	$('#rebbon_total_ticket').html("$0.00");
	$('#table-holder').html('<h2 style="color:#999; font-weight:normal;">El carrito esta vac&iacute;o...</h2>');
	$('#blck-content').css('he');
	}else{
	$('#response').html(data);	
	}
	},
	removeEventCallback : function (elem) {
			$("tr#cart_content_tbl:odd").addClass("row_odd");
			$("tr#cart_content_tbl:even").addClass("row_even");
    },
	
	error:function(){
	// failed request; give feedback to user
	$('#response').html('<div class="box box-error " style="margin-top:7px"><strong>Advertencia:</strong> problemas para eliminar el registro.</div>');
	/*$('#load-'+id).html('');
	$('#submit-'+id).show();*/
	}
	
	});	
	}
	else
	{
		return false;
	}	
}

//end laboleteria / tikect office
//**************************************************************************************


function addToCartFractional(jform, jtype, jurl)
{
	/*var res=$(jform).valid();
	if (res == false){
		return false;
	} else {*/
		$.ajax({
		type: jtype,
		url: jurl,
		data: $(jform).serialize(),
		
		beforeSend:function(){
		// this is where we append a loading image
			$('#submit').hide();
			$('#load').show();
			$('#load').html('<span><img src="'+baseUrl+'assets/doppler/images/loadSm.gif" alt="Loading..." /></span>');
		},
		
		success:function(data){
		// successful request; do something with the data
		if(data != 0){
			alert('El producto fue agregado al carrito!');  
			$('#rebbon_total').html("$"+formatCurrency(data));
			$('.window').hide(); 
			$('#mask').hide();
		}else{
			$('.error_msg').html(data);alert(data);
			$('#load').html('');
			$('#load').hide();
			$('#submit').show();
		}
		},
		
		error:function(){
		// failed request; give feedback to user
			$('#error_msg').html('<div class="box box-error" style="margin-top:7px"><strong>Advertencia:</strong> hubo problemas al realizar esta operaci&oacute;n.</div>');
			$('#load').html('');
			$('#load').hide();
			$('#submit').show();
		}
		});	
	/*}*/	
}

function addToCartFromProductDetail(idp, jurl, idc)
{
	var quantity = $('#quantity').val();
	//alert(jurl+"/"+idp+"/"+idc+"/"+quantity);
	$.ajax({
	type: 'GET',
	url: jurl+"/"+idp+"/"+idc+"/"+quantity,

	beforeSend:function(){
	},
	
	success:function(data){
		if(data != 0)	
		{
			$('#rebbon_total').html("$"+formatCurrency(data));
			jQuery.noticeAdd({
	            text: 'Producto agregado al carrito!',
	            stay: false,
	            type: 'success'
        	});
			
		}else{
			alert("El producto no pudo ser agregado al carrito.");
		}
		//addNotice({text: "", title:'Producto agregado!', type:'success_notify',position:'center'});
	},

	error:function(){
		alert("Error agregando el producto.");
	}
	
	});	
}

function addProductsToCart(jform, jtype, jurl, jredirect)
{
	//var quantity = $('#quantity_'+idp).val();
	//alert(jurl+"/"+idp+"/"+idc+"/"+quantity);
	$.ajax({
		type: jtype,
		url: jurl,
		data: $(jform).serialize(),
	
			
		beforeSend:function(){
		// this is where we append a loading image
			$('#submit').hide();
			$('#load').show();
			$('#load').html('<span><img src="'+baseUrl+'assets/doppler/images/loadSm.gif" alt="Loading..." /></span>');
		},
		
		success:function(data){
		// successful request; do something with the data
		if(data == 1){   
			$(location).attr('href',jredirect);
		}else{
			//$('.error_msg').html(data);
			$('#load').html('');
			$('#load').hide();
			$('#submit').show();
			alert('No ha selecionado ningun producto de la lista!');
		}
		},
		
		error:function(){
		// failed request; give feedback to user
			$('#error_msg').html('<div class="box box-error" style="margin-top:7px"><strong>Advertencia:</strong> hubo problemas al realizar esta operaci&oacute;n.</div>');
			$('#load').html('');
			$('#load').hide();
			$('#submit').show();
		}
	});	
}

// JavaScript Document
function updateCart(id, qty)
{

	$.ajax({
	type: 'GET',
	url: '/update_cart.php?pid='+id+'&qty='+qty,

	beforeSend:function(){
	},
	
	success:function(data){
		addNotice({text: "", title:'Producto actualizado!', type:'success_notify',position:'center'});
	},

	error:function(){
		alert("Error actualizando el producto.");
	}
	
	});	
	
	return false;

}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function closeDiv(id)
{
	//alert('sdfdsfsdf');
	//document.getElementById('div_'+id).style.display = 'none'; 	
	$('#div_'+id).slideToggle('slow');
}


function addListToShoppingCart(id, jtype, jurl)
{	
	//alert(jurl+id);
	$.ajax({
	type: jtype,
	url: jurl+id,
	
	beforeSend:function(){
	// this is where we append a loading image	
	},
	
	success:function(data){
	if(data != 0){   
		jQuery.noticeAdd({
	            text: 'Su lista ha sido agregada!',
	            stay: false,
	            type: 'success'
        	});
		$('#rebbon_total').html("$"+formatCurrency(data));
	}else{
		alert('La lista no pudo ser agregada!');
	}
	},
	
	error:function(){
	// failed request; give feedback to user
	//$(target).html('<div class="box box-error " style="margin-top:7px"><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
	}
	});	
}

function changeSelect(id, jurl, cartId)
{
	$.ajax({
		type: 'GET',
		url: jurl+cartId,
	
		beforeSend:function(){
		// this is where we append a loading image
		},
		
		success:function(data){
		// successful request; do something with the data
		$(id).html(data);
		},
		
		error:function(){
		// failed request; give feedback to user
		}
	});	
}	

function jQueryAjaxSendRebbonTotal(jtype, jurl, target)
{
	$.ajax({
	type: jtype,
	url: jurl,
	
	beforeSend:function(){
	// this is where we append a loading image
	},
	
	success:function(data){
	// successful request; do something with the data
		//$(rebbon_total_ticket).html(data);
	},
	
	error:function(){
	// failed request; give feedback to user
	$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
	}
	});		
}

function render_map(jtype, jurl, jval)
{
	var address;
	var country;
	var state;
	var sector;
	var countryId = $('#country').val();
	
	
	if(jval == 1)
	{
		country = $('#country option:selected').text();
		address = country;
	}
	if (countryId == 1)
	{
		if(jval == 2)
		{
			country = $('#country option:selected').text();
			state = $('#state option:selected').text();
			$('#address').val('');
			$('#address2').val('');
			address = country +","+ state;
		}
	}else
	{
		country = $('#country option:selected').text();
		state = $('#name_state').val();
		$('#address').val('');
		$('#address2').val('');
		address = country +","+ state;
	}
	
	
	if (countryId == 1)
	{
		if(jval == 3)
		{
			country = $('#country option:selected').text();
			state = $('#state option:selected').text();
			sector = $('#sector option:selected').text();
			address = country +","+ state +","+ sector;
			$('#address').val('');
			$('#address2').val('');
		}
	}else
	{
		country = $('#country option:selected').text();
		state = $('#name_state').val();
		sector = $('#name_city').val();
		address = country +","+ state +","+ sector;
		$('#address').val('');
		$('#address2').val('');
	}
	
	if (countryId == 1)
	{
		if(jval == 4)
		{
			country = $('#country option:selected').text();
			state = $('#state option:selected').text();
			sector = $('#sector option:selected').text();
			street = $('#address').val(); 
			address = country +","+ state +","+ sector +","+ street;
			
		}
	}else
	{
		country = $('#country option:selected').text();
		state = $('#name_state').val();
		sector = $('#name_city').val();
		street = $('#address').val(); 
		address = country +","+ state +","+ sector +","+ street;
	}
	
	$.ajax({
	type: jtype,
	url: jurl+urlencode(address),
	
	beforeSend:function(){
	// this is where we append a loading image
	},
	
	success:function(data){
	// successful request; do something with the data
		$('#google_map').html(data);
	},
	
	error:function(){
	// failed request; give feedback to user
	//$(target).html('<div class="box box-error "><strong>Oops!</strong> hubo problemas para realizar esta operaci&oacute;n.</div>');
	}
	});	
}

function scroll(id)
{
	$(document).scrollTo("#wrap");	
}

function urlencode (str) {
    
    str = (str + '').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}


