
jQuery(function($){    
	/*jQuery("#gmxEditor_phototitle").gmxeditor({
		'css_url':'gmxEditor.css'
	});*/
	
	$('.gmxEditor').parent("div").css("position","relative");
	$('.gmxEditor').gmxeditor({'css_url':'./misc/css/gmxEditor.css'});
	jQuery('.gmxEditorBut').click(function(e) {
       e.stopPropagation();
  	});
	jQuery('.webmarttitleBut').click(function(e) {
       e.stopPropagation();
  	});
	jQuery('.content_title').click(function(e) {
       e.stopPropagation();
  	});
	jQuery(document).click(function() { //sblock_content
		
		$(".gmxFont").remove();
		$(".gmxAlign").remove();
		$(".gmxColor").remove();
		jQuery(".ColorPickerBox").remove();
		jQuery(".gmxEditorAlignmentheader").remove();
		jQuery(".gmxEditorColorheader").remove();
		jQuery(".gmxEditorFontheader").remove();
		jQuery(".gmxMore").remove();
		jQuery(".gmxEditorMoreheader").remove();
		$(".gmxEditorBut").remove();	
		
		$(".titleFont").remove();
		$(".titleAlign").remove();
		$(".titleColor").remove();
		jQuery(".webmarttitleAlignmentheader").remove();
		jQuery(".webmarttitleColorheader").remove();
		jQuery(".webmarttitleFontheader").remove();
		$(".webmarttitleBut").remove();	
	});


	
	
	jQuery("#product_content").gmxeditor({
		'css_url':'gmxEditor.css'
	});
	jQuery("#Eproduct_content").gmxeditor({
		'css_url':'gmxEditor.css'
	});
	jQuery("#view_product_srchopt").change(function() {
		if($(this).val()=='price_range') {
			jQuery("#view_productsearch").hide();
			jQuery("#view_productRangesearch").show();
		} else {
			jQuery("#view_productsearch").show();
			jQuery("#view_productRangesearch").hide();
		}
	});
	
	jQuery("#productlist_category").change(function() {
		document.productCategory.submit();										   
	});
});


function search_view_product() {
	jQuery(".searchBox").show("slow");
}
function add_cartproduct(obj) { 
	var item_code=$(obj).parents(".product_details").find(".Cartitem_code").val();	
	var item_name=$(obj).parents(".product_details").find(".Cartitem_name").val();	
	var item_price=$(obj).parents(".product_details").find(".Cartitem_price").val();	
	var item_discount=parseFloat($(obj).parents(".product_details").find(".Cartitem_discount").val());
	var item_qty=$(obj).parents(".product_details").find(".item_qty").val();
	if(item_discount>0) { 
	
	var saveAmt=parseFloat(item_price*item_discount/100);
		 var item_total=parseFloat(item_qty*(item_price-saveAmt));			
		$(obj).parents(".selecteditem_info").find(".Item_total").text(parseFloat(item_total));
		var discount_prize=parseFloat(item_price-(parseFloat(item_price*item_discount)/100));	
		//var discount_prize=parseFloat((item_price*item_discount)/100);
	} else {
		var discount_prize=parseFloat(item_price);
	}
	var path1=$(obj).attr("path");
	jQuery.ajax({ 
		type: "POST",
		url: path1+"php/create_cartSession.php",
		data: "item_code="+item_code+"&item_qty="+item_qty+"&item_name="+item_name+"&item_price="+discount_prize,
		cache: false, 
		beforeSend: function() {
			$.showAlert({message:"Processing..."});
		},
		complete: function() {
			$.hideAlert();
		},
		success: function(t) { 
			var tobj = eval("(" + t + ")");
			if(tobj.output==1) {
			$(obj).parents(".product_details").find(".view_product_Id").attr("checked", "checked");	
			$(obj).parents(".product_details").find(".selection_alert").html("selected product Added cart.");
			$(obj).parents(".product_details").find(".selection_alert").fadeIn(1500);
			$(obj).parents(".product_details").find(".selection_alert").fadeOut(2500);
			} else {
				new Boxy("<p class='width300'>You are not allow to access.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});	
			}
		},
		error:function(t){
		  alert(t);		
		}
	
	});
}
function changeQty(Cobj) {
	var changeqty=parseFloat($(Cobj).val()); 
	var item_code=$(Cobj).attr("item_id");
	var item_name=$(Cobj).attr("item_name");
	var item_price=$(Cobj).attr("item_price");
	var item_discount=parseFloat($(Cobj).attr("item_discount"));
	var path1=$(Cobj).attr("path");
	var selectprice=parseFloat($(Cobj).parents(".selecteditem_info").find(".selectedItem_price").text());
	var ship_charge=parseFloat(jQuery("#ship_charge").text());
	if(item_discount>0) {
	
	   var saveAmt=parseFloat(selectprice*item_discount/100);
		 var item_total=parseFloat(changeqty*(selectprice-saveAmt));
			
			
		$(Cobj).parents(".selecteditem_info").find(".Item_total").text(parseFloat(item_total));
		var discount_price=parseFloat(selectprice-(parseFloat(selectprice*item_discount)/100));
	} else {
		$(Cobj).parents(".selecteditem_info").find(".Item_total").text(parseFloat(changeqty*selectprice));
		var discount_price=parseFloat(selectprice);
	}
	
	var shopping_total=0; 
	var ship_charge=parseFloat(jQuery("#ship_charge").text()); 
	jQuery(".selecteditem_info").each(function() {
		var changeqty=parseFloat($(this).find(".selecteditem_qty").val());
		var discount=parseFloat($(this).find(".selecteditem_qty").attr("item_discount"));
		var selectprice=parseFloat($(this).find(".selectedItem_price").text());
		if(discount>0) {
		  var saveAmt1=parseFloat(selectprice*item_discount/100);
		  var item_total1=parseFloat(changeqty*(selectprice-saveAmt1));
			var itemtotal=parseFloat(item_total1);
		} else {
			var itemtotal=parseFloat(changeqty*selectprice);
		}
		shopping_total+=parseFloat(itemtotal);							   
   });
	jQuery(".Cart_total").text(shopping_total+ship_charge);
	jQuery("#amount").val(shopping_total+ship_charge);

	jQuery.ajax({ 
		type: "POST",
		url: path1+"php/create_cartSession.php",
		data: "item_code="+item_code+"&item_qty="+changeqty+"&item_name="+item_name+"&item_price="+discount_price,
		cache: false, 
		beforeSend: function() {
			$.showAlert({message:"Processing..."});
		},
		complete: function() {
			$.hideAlert();
		},
		success: function(t) { 
			var tobj = eval("(" + t + ")");
			if(tobj.output==1) {
			//$(obj).parents(".product_details").find(".view_product_Id").attr("checked", "checked");	
			} else {
				new Boxy("<p class='width300'>You are not allow to access.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});	
			}
		},
		error:function(t){
		  alert(t);		
		}
	
	});
	
}

function savepay_details() {
	
	var fpath=$('#_fpath').val();
	var rpath=$('#return_path').val();
	var sessId=$('#sessionId').val();
	jQuery.ajax({ 
			type: "POST",
			url: fpath+"php/save_order.php",
			data: "userId="+jQuery("#_user_id").val(),
			cache: false, 			
			success: function(t) {  
				var tobj = eval("(" + t + ")");
				if(tobj.output.result=="1") { 
					  var user_id=tobj.output.id;
					  var user_path='';
					  for(var i=0; i<user_id.length; i++) {
						  user_path+="_"+user_id[i];
					  }
					  var returnpath=rpath+'/'+sessId+'/'+user_path;
					  $('#return').val(returnpath);//alert(returnpath);
					  document.payment.submit();
					
				} else {
					alert("failed to save your Order, Try again");
					 $('#_ordernow').removeAttr('disabled');
					return false;
				}
			},
			error:function(t){
				  alert(t);		
			}
									  
			 });
	
}
function continueShopping(Cobj) {
	var Cpath= $(Cobj).attr("Cpath");
	window.location = Cpath;
}
function finishShopping(Cobj) {
	var Cpath= $(Cobj).attr("Cpath");
	window.location = Cpath;
}
