/*
  $Id: common.js,v 1.0 2009/07/01  Samad Kushan Exp $
  
  @author 	Samad kushan (samad1983@gmail.com) 		
  @copyright 	Copyright 2009, Tavrizh	I.T	
  
  Virtu, Open Source E-Commerce
  http://www.e-virtu.com/  
  
  Copyright (c) 2007-2009 Virtu E-Commerce
  Released under the GNU General Public License
  powered by JQuery
*/

$(document).ready(function(){


$("#search_details_btn a").click(function(event){
  event.preventDefault();
  $("#search_details_btn").hide();
  $("#search_details_btn_active").show();
  $("#search_details_container").slideDown();
  
  });
$("#search_details_btn_active a").click(function(event){
  event.preventDefault();
  $("#search_details_btn").show();
  $("#search_details_btn_active").hide();
  $("#search_details_container").slideUp();
  
  });
$("#login_slider_btn").toggle(function(event){
  event.preventDefault();
  $("#login_slider_container").slideDown();
  
  },function(event){
  event.preventDefault();
  $("#login_slider_container").slideUp();
  
  });
// dpay Begin

  $("#dpay_selection").show();
  if(!$("input[value=dpay_express]").attr("checked") && !$("input[value=dpay_common]").attr("checked")){
  	$("#dpay_selection").hide();
  }

  $(".moduleRow, #defaultSelected").click(function(event){
  	if($(this).find("input[type=radio]").attr("value") != "dpay_express" || $(this).find("input[type=radio]").attr("value") != "dpay_common" ){
		$("#dpay_selection").hide();
	}
  });
  $("#dpay_express_price, #dpay_common_price").parent().parent().click(function(event){
   $("#dpay_selection").show();
   if ($("input[name=dpay_calculated]").attr("value") == 0) {
   
   	$("#dpay_express_price").parent().find(".shipping_inprocess").show();
	$("#dpay_common_price").parent().find(".shipping_inprocess").show();
	$("#dpay_express_price").hide();
	$("#dpay_common_price").hide();
   	$("#dpay_error_holder").hide();
   		
   		$.getJSON("dpay_price_calculate.php", {
   			Vsid: session_id
   		}, function(data){
			
			$("#dpay_express_price").parent().find(".shipping_inprocess").hide();
		    $("#dpay_common_price").parent().find(".shipping_inprocess").hide();
		    $("#dpay_express_price").show();
		    $("#dpay_common_price").hide();
   			$("#dpay_calculate").show();
   			$("#dpay_error_holder").hide();
   			if (data['error'] == 1) {
   				$("#dpay_error_holder").html(data['error_description']);
   				$("#dpay_error_holder").show();
   			}
   			else {
   				$("#dpay_express_price").parent().parent().show();
   				$("#dpay_express_price").html(data['dpay_express_price']);
				$("input[name=dpay_calculated]").attr("value",1);
   				if (data['dpay_common_price'] != 0) {
   					$("#dpay_common_price").parent().parent().show();
   					$("#dpay_common_price").html(data['dpay_common_price']);
					$("#dpay_common_price").show();
   					
   				}
   			}
   		});
   	
   }
  });
  // if there is only dpay shipping module so trigger the click and calculate the price
  
  if($(".moduleRow, #defaultSelected").size()==1){
    $("#dpay_express_price, #dpay_common_price").parent().parent().trigger('click');	
  }
/* dpay tracking box */
  $("#dpay_tracking_button").click(function(event){
	
	$("#dpay_tracking_status_holder").parent().parent().show();
	$("#dpay_tracking_status_holder").hide();
	$("#dpay_tracking_status_inprocess").show();
	$("#dpay_tracking_button").hide();
	$("#dpay_tracking_status_error_holder").hide();
	
	dpay_tracking_code_value = $("input[name=dpay_tracking_code]").attr("value");
	$("input[name=dpay_tracking_code]").hide();
	
	$.getJSON("dpay_tracking_system.php", {dpay_tracking_code: dpay_tracking_code_value, Vsid: session_id }, function(data){	
		$("#dpay_tracking_status_inprocess").hide();
		$("input[name=dpay_tracking_code]").show();
		$("#dpay_tracking_button").show();
        
		if(data['error']==1){
			$("#dpay_tracking_status_error_holder").show();
			$("#dpay_tracking_status_error_holder").html(data['error_description'] );
		}else{
			$("#dpay_tracking_status_holder").show();
			$("#dpay_tracking_status_holder").html(data['dpay_order_status_description']);
		}	 
	  });
  });


/* account_history_info.php iranmc tracking */
  $("#history_info_dpay_tracking_button").click(function(event){
	event.preventDefault();
	$("#history_info_dpay_tracking_status_holder").parent().parent().show();
	$("#history_info_dpay_tracking_status_holder").hide();
	$("#history_info_dpay_tracking_status_inprocess").show();
	$("#history_info_dpay_tracking_button").hide();
	$("#history_info_dpay_tracking_status_error_holder").hide();
	
	dpay_tracking_code_value = $("input[name=history_info_dpay_tracking_code]").attr("value");
	$("#history_info_dpay_tracking_button").hide();
	
	$.getJSON("dpay_tracking_system.php", {dpay_tracking_code: dpay_tracking_code_value, Vsid: session_id }, function(data){	
		$("#history_info_dpay_tracking_status_inprocess").hide();		
        
		if(data['error']==1){
			$("#history_info_dpay_tracking_status_error_holder").show();
			$("#history_info_dpay_tracking_status_error_holder").html(data['error_description'] );
		}else{
			$("#history_info_dpay_tracking_status_holder").show();
			$("#history_info_dpay_tracking_status_holder").html(data['dpay_order_status_description']);
		}
	  });
	});
	
	if(($(".moduleRow, #defaultSelected").size()==1) || (($(".moduleRow, #defaultSelected").find("input[type=radio]:checked").attr('value')=="dpay_express" || $(".moduleRow, #defaultSelected").find("input[type=radio]:checked").attr('value')=="dpay_common") && $("input[name=dpay_calculated]").attr("value") == 0)){
    $("#dpay_express_price, #dpay_common_price").parent().parent().trigger('click');	
  }
// dpay END

// iranmc Begin

  $("#iranmc_selection").show();
  if(!$("input[value=iranmc_express]").attr("checked") || $("input[value=iranmc_common]").attr("checked")){
  	$("#iranmc_selection").hide();
  }

  $(".moduleRow, #defaultSelected").click(function(event){
  	if($(this).find("input[type=radio]").attr("value") != "iranmc_express" || $(this).find("input[type=radio]").attr("value") != "iranmc_common" ){
		$("#iranmc_selection").hide();
	}
  });
  $("#iranmc_express_price").parent().parent().click(function(event){
   $("#iranmc_selection").show();
   if ($("input[name=iranmc_calculated]").attr("value") == 0) {
   
   	$("#iranmc_express_price").parent().find(".shipping_inprocess").show();
	$("#iranmc_common_price").parent().find(".shipping_inprocess").show();
	$("#iranmc_express_price").hide();
	$("#iranmc_common_price").hide();
   	$("#iranmc_error_holder").hide();
   	$.ajax({
			type: "GET",
            url: "iranmc_price_calculate.php",
            data: "Vsid=" + session_id,
            timeout: 600,
			dataType:'json',
			success: function(data){
				                    $("#iranmc_express_price").parent().find(".shipping_inprocess").hide();
		                            $("#iranmc_common_price").parent().find(".shipping_inprocess").hide();
		                            $("#iranmc_express_price").show();
		                            $("#iranmc_common_price").hide();
		
   			                        $("#iranmc_calculate").show();
   			                        $("#iranmc_error_holder").hide();
   			                        if (data['error'] == 1) {
   				                      $("#iranmc_error_holder").html(data['error_description']);
   				                      $("#iranmc_error_holder").show();
   			                        }else {
   				                      $("#iranmc_express_price").parent().parent().show();
   				                      $("#iranmc_express_price").html(data['iranmc_express_price']);
				                      $("input[name=iranmc_calculated]").attr("value",1)
   				                      if (data['iranmc_common_price'] != 0) {
   					                    $("#iranmc_common_price").parent().parent().show();
   					                    $("#iranmc_common_price").html(data['iranmc_common_price']);
					                    $("#iranmc_common_price").show();
   				                      }
   			                        }
                                  },
           error: function(request, errorType, errorThrown){
		   	$("#iranmc_express_price").parent().find(".shipping_inprocess").hide();
		   	$("#iranmc_common_price").parent().find(".shipping_inprocess").hide();
		   	$("#iranmc_express_price").show();
		   	$("#iranmc_common_price").hide();
		   	
		   	$("#iranmc_calculate").show();
		   	$("#iranmc_error_holder").hide();
		   	
		   	if(request.status==0){
			    $("#iranmc_error_holder").html(js_text_ajax_offline_mode);
			}else if(request.status==404){
			    $("#iranmc_error_holder").html(js_text_ajax_url_not_found);
			}else if(request.status==500){
			    $("#iranmc_error_holder").html(js_text_ajax_internal_server_error);
			}else if (errorType == "timeout") {
		   	    $("#iranmc_error_holder").html(js_text_ajax_timeout);
		   	}else {
		   	    $("#iranmc_error_holder").html(js_text_ajax_unknown_error);
		   	}

		   	$("#iranmc_error_holder").show();
		   }

		 });
    }
  });
  // if in the beggining, there is only iranmc shipping module or selected radio is iranmc so trigger the click and calculate the price
  
  if(($(".moduleRow, #defaultSelected").size()==1) || (($(".moduleRow, #defaultSelected").find("input[type=radio]:checked").attr('value')=="iranmc_express" || $(".moduleRow, #defaultSelected").find("input[type=radio]:checked").attr('value')=="iranmc_common") && $("input[name=iranmc_calculated]").attr("value") == 0)){
    $("#iranmc_express_price, #iranmc_common_price").parent().parent().trigger('click');	
  }


/* iranmc tracking box */
  $("#iranmc_tracking_button").click(function(event){
	
	$("#iranmc_tracking_status_holder").parent().parent().show();
	$("#iranmc_tracking_status_holder").hide();
	$("#iranmc_tracking_status_inprocess").show();
	$("#iranmc_tracking_button").hide();
	$("#iranmc_tracking_status_error_holder").hide();
	
	iranmc_tracking_code_value = $("input[name=iranmc_tracking_code]").attr("value");
	$("input[name=iranmc_tracking_code]").hide();

	$.ajax({
			type: "GET",
            url: "iranmc_tracking_system.php",
            data: "iranmc_tracking_code=" + iranmc_tracking_code_value + "&Vsid=" + session_id,
            timeout: 60000,
			dataType:'json',
			success: function(data){
				                    $("#iranmc_tracking_status_inprocess").hide();
		                            $("input[name=iranmc_tracking_code]").show();
		                            $("#iranmc_tracking_button").show();
        
		                            if(data['error']==1){
			                          $("#iranmc_tracking_status_error_holder").show();
			                          $("#iranmc_tracking_status_error_holder").html(data['error_description'] );
		                            }else{
			                          $("#iranmc_tracking_status_holder").show();
			                          $("#iranmc_tracking_status_holder").html(data['iranmc_order_status_description']);
		                            }
                                  },
            error: function(request, errorType, errorThrown){
		   	                       $("#iranmc_tracking_status_inprocess").hide();
		                           $("input[name=iranmc_tracking_code]").show();
		                           $("#iranmc_tracking_button").show();
			
			                       if(request.status==0){
			                         $("#iranmc_tracking_status_error_holder").html(js_text_ajax_offline_mode);
			                       }else if(request.status==404){
			                         $("#iranmc_tracking_status_error_holder").html(js_text_status_ajax_url_not_found);
			                       }else if(request.status==500){
			                         $("#iranmc_tracking_status_error_holder").html(js_text_ajax_internal_server_error);
			                       }else if (errorType == "timeout") {
		   	                         $("#iranmc_tracking_status_error_holder").html(js_text_status_ajax_timeout);
		   	                       }else {
		   	                         $("#iranmc_tracking_status_error_holder").html(js_text_status_ajax_unknown_error);
		   	                       }

		   	                       $("#iranmc_tracking_status_error_holder").show();
		                         }

		 });
	});


 /* account_history_info.php iranmc tracking */
  $("#history_info_iranmc_tracking_button").click(function(event){
	event.preventDefault();
	$("#history_info_iranmc_tracking_status_holder").parent().parent().show();
	$("#history_info_iranmc_tracking_status_holder").hide();
	$("#history_info_iranmc_tracking_status_inprocess").show();
	$("#history_info_iranmc_tracking_button").hide();
	$("#history_info_iranmc_tracking_status_error_holder").hide();
	
	iranmc_tracking_code_value = $("input[name=history_info_iranmc_tracking_code]").attr("value");
	$("#history_info_iranmc_tracking_button").hide();
	
	$.ajax({
			type: "GET",
            url: "iranmc_tracking_system.php",
            data: "iranmc_tracking_code=" + iranmc_tracking_code_value + "&Vsid=" + session_id,
            timeout: 60000,
			dataType:'json',
			success: function(data){
				                    $("#history_info_iranmc_tracking_status_inprocess").hide();		

		                            if(data['error']==1){
			                          $("#history_info_iranmc_tracking_status_error_holder").show();
			                          $("#history_info_iranmc_tracking_status_error_holder").html(data['error_description'] );
		                            }else{
			                          $("#history_info_iranmc_tracking_status_holder").show();
			                          $("#history_info_iranmc_tracking_status_holder").html(data['iranmc_order_status_description']);
		                            }
                                  },
            error: function(request, errorType, errorThrown){
		   	                       $("#history_info_iranmc_tracking_status_inprocess").hide();

								   if(request.status==0){
			                         $("#history_info_iranmc_tracking_status_error_holder").html(js_text_ajax_offline_mode);
			                       }else if(request.status==404){
			                         $("#history_info_iranmc_tracking_status_error_holder").html(js_text_status_ajax_url_not_found);
			                       }else if(request.status==500){
			                         $("#history_info_iranmc_tracking_status_error_holder").html(js_text_ajax_internal_server_error);
			                       }else if (errorType == "timeout") {
		   	                         $("#history_info_iranmc_tracking_status_error_holder").html(js_text_status_ajax_timeout);
		   	                       }else {
		   	                         $("#history_info_iranmc_tracking_status_error_holder").html(js_text_status_ajax_unknown_error);
		   	                       }

		   	                       $("#history_info_iranmc_tracking_status_error_holder").show();
		                         }
	 });
   });	
// iranmc END

// compare
$(".add_compare_button").click(function(){	
$(".in_processing").show();

   $.get("compare_list_script.php", {product_id: $(this).attr("id"), Vsid: session_id}, function(data){
   		$(".in_processing").hide();																							
		if(data == 'too_many'){
			alert(text_too_many_products_added);
		}else if(data == 'exist'){
			
		}else if(data == 'not_found'){
			alert(text_not_found_products);
		}else{
			$("#compare_list_holder").replaceWith(data);
			$(".clear_compare_list_button").show();
			$(".button_compare").show();
		} 										 																		
	});	

 });

	$(".clear_compare_list_button").click(function(){	
   		$(".in_processing").show();
		$.get("compare_list_script.php", {clear_compare_list: true, Vsid: session_id }, function(data){	
				$(".in_processing").hide();		 
				if (data == 'empty') {
						$("#compare_list_holder").replaceWith('<div id="compare_list_holder" style="clear:both;"><span>' + text_no_compare_products_added + '</span></div>');
						$(".clear_compare_list_button").hide();
						$(".button_compare").hide();						
				}
				
		 });
	  })
})
/**************************************************************************************/

/*
  $Id: shopping_card.js,v 1.0 2009/07/26  Samad Kushan Exp $
  
  @author 	Samad kushan (samad1983@gmail.com) 		
  @copyright 	Copyright 2009, Tavrizh	I.T	
  
  Virtu, Open Source E-Commerce
  http://www.e-virtu.com/  
  
  Copyright (c) 2007-2009 Virtu E-Commerce
  Released under the GNU General Public License
  powered by JQuery
*/

function add_shopping_card(id, redirect_url){
					
$("#shopping_card_list_holder").hide();
$(".in_processing_add_shopping_card").show();
   $.get("add_to_shopping_card_script.php", {ajax: 'true', action: 'buy_now', products_id: id, Vsid: session_id}, function(data){
   $(".in_processing_add_shopping_card").hide();
   if(data == 'has_product_attributes'){
   	 window.location = redirect_url;   	 
   }else if(data == 'too_qty_in_cart'){
   	  $.modaldialog.error(text_too_many_qty_in_cart, { title:text_too_many_qty_in_cart_header, width:200, height:200 });
	  return false;   	
	}else{
   	 $("#ja_shopping_cart_content_holder").replaceWith(data);	
	 $.modaldialog.success(text_success_add_to_cart, {  title: text_success_add_to_cart_header, width:200,  height:200 }); 	 
   }		
   return false;	
});	
return false;
}

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
 // The index() method calculates the index from a
 // given index who is out of the actual item range.
 var idx = carousel.index(i, mycarousel_itemList.length);
 carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};
function mycarousel_itemVisibleInCallback2(carousel, item, i, state, evt)
{
 // The index() method calculates the index from a
 // given index who is out of the actual item range.
 var idx = carousel.index(i, mycarousel_itemList2.length);
 carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList2[idx - 1]));
};
function mycarousel_itemVisibleInCallback3(carousel, item, i, state, evt)
{
 // The index() method calculates the index from a
 // given index who is out of the actual item range.
 var idx = carousel.index(i, mycarousel_itemList3.length);
 carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList3[idx - 1]));
};
function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
 carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
 return '<div class="new_products_list_item">' + item.list_items + '</div>';
};
 
function mycarousel_initCallback(carousel)
{
        carousel.clip.hover(function() {		 		
                carousel.stopAuto();
        }, function() {
                carousel.startAuto();
        });
};


/* superfish */
$(document).ready(function(){ 

        $("ul.sf-menu").superfish({
			disableHI:     true,
			dropShadows:   false,    
			delay:       1000,                            // one second delay on mouseout 
            animation:   {height:'show'},  // fade-in and slide-down animation           
			speed:       300,            		
			autoArrows:  false                          // disable generation of arrow mark-up
		}); 
    });

	