function d_rechaptcha(id,con){
   var capca = $('#'+id).attr('src')+'reload/';
   $('#'+con).hide('');
   if(capca.length  > 34) {
      var currentTime = new Date();
      capca = capca.substring(0,26)+currentTime.getTime();
   }
   $('#'+id).attr('src',capca);
   $('#'+con).show('');
}

function add_basket(){  
   var id_item = $('#id_item').val();
   var sum = $('#sum_order').val();
   var act = $('#shop_add').attr('action');
   act = act +"/"+id_item +"/"+sum;
    
   $.ajax({
      type: "POST",
      url: act,
      success: function(msg){
         var res = msg.split('||');
         $('#jax_rslt').html(res[1]);
         if(res[0]=='TRUE'){
            $('#jax_rslt').html(res[1]).addClass('sipDiv');
            $('#button_add').attr('disabled','disabled');
            $('#form_con').html('');
         }else{
            $('#jax_rslt').html(res[1]).addClass('errDiv');
         }
      }
   });
}

function onDelete(){
   if(confirm("Are You sure?")){
      return true;
   }else{
      return false;
   }
}

function get_destination(){
   //alert($('#destination').val()); //id selected
   $.ajax({
      type: "POST",
      url: "/index.php/json/shipping/index/"+$('#destination').val()+"/"+$('#total_mass_hide').html(),
      success: function(msg){
         //alert(msg);
         var tot_shop = $("#total_shop_hide").html();
         $('#shipping_price_hide').html(msg);
         $('#shipping_price').html(to_rupiah(msg));
         
         var tot_transfer = msg - (-tot_shop);
         $('#total_transfer_hide').val(tot_transfer);
         $('#total_transfer').html(to_rupiah(tot_transfer));
      }
   });
}

//$(document).ready(function() {
//   if($( ".dialog" )){
//      $( ".dialog" ).dialog({
//         autoOpen: false,
//         show: "drop",
//         hide: "explode",
//         position: "top",
//         width:425
//      });
//   
//      $( ".img_link" ).click(function() {
//         var id_link = "#"+$(this).attr('id')+"_dia";      
//         $(id_link).html("<img  src='"+$(this).attr('href')+"' />");      
//         $( id_link ).dialog({title:$(this).attr('alt'),position:"center"}).dialog("open");
//         var img_x = $(id_link+" img").width();
//         if(img_x>300){
//            $( id_link ).dialog({width:(img_x-(-25))});
//         }
//         return false;
//      });
//   }
//});

function to_rupiah(nom){
   return "Rp. " + number_format(nom,2,",",".");
}

/* Made by Mathias Bynens <http://mathiasbynens.be/> */
function number_format(a, b, c, d) {
   /*
      value,sen,sen separator,thousand separator
      number_format(msg,2,",",".") ==> Indonesia
   */
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}

function story(){
   $('#img_pop').append('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum');
   
   setTimeout("$('#story').remove()",50);
}

//modal
$(document).ready(function() {	
                                 
	//select all the a tag with name equal to modal
	$('a[name^=popimg]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
            var path_img = $(this).attr('id');
            var alt_img = $(this).attr('alt');
            var arr_alt = alt_img.split('_');
            
            //Store Img
            
            $(id).width(parseFloat(arr_alt[0]));
            
            $('#img_pop').html('<img src="/images/'+arr_alt[2]+'/show/'+path_img+'" alt="image show"/>');
            //$('#img_pop').append('<a id="story" href="#story" onClick="story()" >Read Story</a>');
            
         
		//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(1000);	
		$('#mask').fadeTo("slow",0.8);
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
            $(id).css('top',  0);               
		$(id).css('left', winW/2-arr_alt[0]/2);
	
		//transition effect
		$(id).fadeIn(2000);
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});


