function trim(str){
str=$.trim(str);
return str;
}
function add_to_cart(obj) {
// ADDONS
var addon='';
$.each($(".addon"),function(){
if ($(this).attr('value')) addon=addon+"&addon["+$(this).attr('id')+"]="+$(this).attr('value')
});
//addons END;
$('#cart_dialog').dialog('open');
$.getJSON("./data/cart.php","cs=ש&action=add_product&pid="+$(obj).attr('product_id')+addon,function (data) {
show_cart_data(data);
});
}
function plus_cart(obj) {
// $('#cart_table').html("");
//alert() ;
$('#cart_dialog').dialog('open');
$.getJSON("./data/cart.php","cs=ש&action=more_product&key="+$(obj).attr('product_index'),function (data) {
show_cart_data(data);
});
}
function minus_cart(obj) {
//$('#cart_table').html("");
//alert() ;
$('#cart_dialog').dialog('open');
$.getJSON("./data/cart.php","cs=ש&action=less_product&key="+$(obj).attr('product_index'),function (data) {
show_cart_data(data);
});
}
function remove_from_cart(obj) {
//$('#cart_table').html("");
//alert() ;
$('#cart_dialog').dialog('open');
$.getJSON("./data/cart.php","cs=ש&action=remove_product&key="+$(obj).attr('product_index'),function (data) {
show_cart_data(data);
});
}
function show_cart(){
$('#cart_dialog').dialog('open');
}
function draw_cart(){
$("#minicart_table").hide();
$.getJSON("./data/cart.php","cs=ש",function (data) {
show_cart_data(data);
});
}
function show_cart_data(data){
var carthtml='';
var minicarthtml='';
if (data.subtotal==0 || data.subtotal=='-') carthtml='הסל ריק';
else {
carthtml=carthtml+='
';
$.each(data.products,function (index,value){
if (this.amount>1) minicarthtml=minicarthtml+''+this.amount+' יחידות '+this.name+' ב: '+this.price+' ליחידה, סה"כ: '+this.total+'
';
else minicarthtml=minicarthtml+''+this.name+' במחיר: '+this.total+'
';
carthtml=carthtml+'';
});
minicarthtml=minicarthtml+'סה"כ: '+data.subtotal+'
';
minicarthtml=minicarthtml+'';
carthtml=carthtml+'';
$("#minicart_table").show();
}
$('#cart_table').html(carthtml);
$('#cart_container').html(minicarthtml);
}
function searchSuggest() {
if (typeof $("body").data("before_search") == 'undefined' || $("body").data("before_search")=='') {
$("body").data("before_search",$(".main_col_container").html());
}
if ($("#search_input").val().length==0) {
$(".main_col_container").html($("body").data("before_search"));
$("body").data("before_search",'');
return
}
if ($("#search_input").val().length<2) {
return;
}
// start search ///
$(".main_col_container").html("");
$("#closesearch_container").html("סגור חיפוש");
$("#searchname").html("
מחפש: "+$("#search_input").val());
$('#closesearch_container').click(function(){
$(".main_col_container").html($("body").data("before_search"));
$("body").data("before_search",'');
});
$.ajax({
url: './data/dataserver.php',
dataType: 'json',
type: 'POST',
data: {search:$("#search_input").val(),action:'search_product'},
success: function(data){
if (data!=null ) {
var products_search='';
products_search=products_search+'';
$.each(data,function (index,value){
price_line='';
if (this.customer_price!=this.base_price) price_line=""+this.customer_price+""+this.base_price+""
else price_line=""+this.customer_price+"";
products_search=products_search+'
'+this.partdes+'
'+''+'
'+price_line+' ';
});
products_search=products_search+'
';
$("#products_items").html(products_search);
}
else $("#products_items").html("לא נמצאו מוצרים התואמים את החיפוש
");
$('#searching').remove();
}
});
$.ajax({
url: './data/dataserver.php',
dataType: 'json',
type: 'POST',
data: {search:$("#search_input").val(),action:'search_cat'},
success: function(data){
if (data!=null) {
var lable_search='';
lable_search=lable_search+'';
$.each(data,function (index,value){
lable_search=lable_search+'
'+this.partdes+'
';
});
lable_search=lable_search+'
';
$("#catpics_container").html(lable_search);
}
}
});
}
/////////////////////////////////////////////////////##
var timeout_reserver = null;
$(function(){
$.ajaxSetup({
contentType: "application/x-www-form-urlencoded;charset=windows-1255",
cache:false
});
draw_cart();
$(".catpic img").live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {
$(this).animate({
opacity: 0.5
});
} else {
$(this).animate({
opacity: 1
});
}
});
$(".product_catalog_item a img").live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {
$(this).animate({
opacity: 0.75
});
} else {
$(this).animate({
opacity: 1
});
}
});
$(".cart_add").live("click",function(){add_to_cart(this)});
$(".remove_from_cart").live("click",function(){remove_from_cart(this)});
$(".plus_cart").live("click",function(){plus_cart(this)});
$(".minus_cart").live("click",function(){minus_cart(this)});
$("#open_cart").click(function(){show_cart()});
$("#minicart_cash").click(function(e){e.stopPropagation();window.location='?template=checkout';});
$('#search_input').bind("keyup",function(){
if (timeout_reserver != null) clearTimeout(timeout_reserver);
timeout_reserver =setTimeout('searchSuggest()', 500);
});
$("#minicart_table").live("click",function(){show_cart()});
$("#open_audiodisk").live("click",function(){
$('#general_dialog').dialog('open');
$('#general_dialog').html ('');
});
$("#open_video").live("click",function(){
$('#general_dialog').html ('Loading the player ...
');
jwplayer("container_92").setup({ flashplayer: "./jwplayer/player.swf", file: $(this).attr('video_name'), height: 400, width: 550 });
$('#general_dialog').dialog('open');
});
$('#cart_dialog').dialog({
autoOpen: false,
modal: true,
width: 880,
height: $(window).height()*0.8,
buttons: {
"חזור לחנות": function() {
$(this).dialog("close");
},
"עבור לקופה": function() {
$(this).dialog("close");
window.location='/?template=checkout&phpsess='+$('body').data('phpsess');
}
}
});
$('#general_dialog').dialog({
autoOpen: false,
modal: true,
width: 880,
height: $(window).height()*0.8,
buttons: {
"סגור": function() {
$(this).dialog("close");
}
}
});
});