function draw_grid(id,custom_options)
{
	var options={
	datatype: "json",
	rowNum:config_grid_records_per_page,	
	imgpath: config_grid_images_path,
	viewrecords: true, 
	sortorder: "desc",
	width:500,
	height:350,	

	viewrecords: true, 
	sortorder: "desc",
	pager: jQuery('#pager2')
	}
	
	options=jQuery.extend(options,custom_options);	
	jQuery(id).jqGrid(options);	
} 



function add_tocart(pid)
{	
  if(document.getElementById("txt_quantity_"+pid).value=="")
  {
    alert("Please Insert Quantity");
    return false;
  }
  var url="ajax.request.php";
  var qty=jQuery('#txt_quantity_'+pid).val();  
  var params={"case":"add_cart","pid":pid,"qty":qty};
  jQuery.getJSON(url,params,add_tocart_result);
}
function add_tocart_result(arr)
{
  jQuery('#qty').html(arr['totalquantity']);	
}


/*function currency_price(ctype,reloadpg)
{	
	if(ctype=='U')
	{
		jQuery('#txt_price_1').html('$32.10 US');
		jQuery('#txt_price_2').html('$15.25 US');
		jQuery('#txt_price_3').html('$15.25 US');
		jQuery('#txt_price_4').html('$15.25 US');
		jQuery('#txt_price_5').html('$19.00 US');
		jQuery('#txt_price_6').html('$10.49 US');
	}
	else if(ctype=='C')
	{
		jQuery('#txt_price_1').html('$34.99 CAD');
		jQuery('#txt_price_2').html('$15.99 CAD');
		jQuery('#txt_price_3').html('$15.99 CAD');
		jQuery('#txt_price_4').html('$15.99 CAD');
		jQuery('#txt_price_5').html('$19.99 CAD');
		jQuery('#txt_price_6').html('$11.99 CAD');
	}
	var url="ajax.request.php";
	var params={"case":"currency_handler","ctype":ctype};
	jQuery.getJSON(url,params,function(){
	
		if(reloadpg!='')
		{
			window.location.href=reloadpg;
		}
	});
}*/

/*function cartupdate(pid)
{
	var qty=jQuery('#cart_quan_'+pid).val();
		
	var url="ajax.request.php";
	var params={"case":"cartupdate","productid":pid,"qty":qty};
	jQuery.getJSON(url,params,function(arr){
		var quan=jQuery('#cart_quan_'+pid).val();
		var amt=jQuery('#cart_each_'+pid).html();		
		var total=quan*amt;		
		jQuery('#cart_amt_'+pid).text(total.toFixed(2));
		jQuery('#qty').html(arr['totalquantity']);	
		jQuery('#cart_total').text(arr['totalamount'].toFixed(2));
	});
}*/


function cartupdate(pid)
{
	var oldqty=Number(jQuery('#cart_quan_'+pid).attr('oldqty'));
	var qty=Number(jQuery('#cart_quan_'+pid).val());	
	if(!(qty>=0))
	{
		alert('Invalid Quantity');
		return;
	}
	if(oldqty==qty || qty==NaN)
	{
		return;
	}
	
	var country=jQuery('#sel_country').val();	
	var zip=jQuery('#txt_zipto').val();	
	var service=jQuery('#selectservice').val();	
	var url="ajax.request.php";
	var params={"case":"cartupdate","productid":pid,"qty":qty,"country":country,"zip":zip,"service":service};
	jQuery.getJSON(url,params,function(arr){
		var quan=jQuery('#cart_quan_'+pid).val();
		jQuery('#cart_quan_'+pid).attr('oldqty',quan);
		var amt=jQuery('#cart_each_'+pid).html();		
		var total=quan*amt;		
		jQuery('#cart_amt_'+pid).text(total.toFixed(2));
		jQuery('#qty').html(arr['totalquantity']);	
		jQuery('#cart_total').text(arr['totalamount'].toFixed(2));
		jQuery('#shipping_amount').html(arr['shippingamount'].toFixed(2));
		jQuery('#pst_tax').html(arr['pst_tax'].toFixed(2));
		jQuery('#gst_tax').html(arr['gst_tax'].toFixed(2));
		jQuery('#grand_total').html(arr['gtotal'].toFixed(2));
	});
}

function delete_product(cid)
{	
	var url="ajax.request.php";
	var params={"case":"deleteproduct","cartid":cid};
	jQuery.getJSON(url,params,function(arr){
	
	if(arr['id']!=undefined)
		{
				var oRow = document.getElementById("cart_"+arr['id']);	
				var objtbl=oRow.parentNode;
				objtbl.deleteRow(oRow.rowIndex);
							
		}
		
	//jQuery('#cart_'+cid).remove();
		jQuery('#qty').html(arr['totalquantity']);	
		jQuery('#cart_total').text(arr['totalamount'].toFixed(2));
		
			if(parseInt(document.getElementById("cart_total").innerHTML)=="0")
			{				
				document.getElementById("tbl_cart").style.display="none";
				document.getElementById("tbl_cart_child").style.display="none";
				document.getElementById("div_cartblank").style.display="";
			}
			
	});
}

