Current File : /home/tradevaly/demo.tradevaly.com.bd/public/js/custom.js
	// start  remove underscore and camel case
	function removeUnderscoreSetSpaceConvertCamelCase(value)
	{
		var camelCased = value.replace(/_/g, ' '); // remove under score and replace space
						
		camelCased = camelCased.toLowerCase().replace(/\b[a-z]/g, function(letter) {
			return letter.toUpperCase();
		});

		return camelCased;
	}
	// end  remove underscore and camel case
	
	
	
	/// start price validation 
	function pricevalidation()
            {
                var packageName = $('.package_name').val();
                var actionMood = $('.text-heading-bar').html();

                if( packageName != 'Basic' &&  actionMood != 'Edit Product'){


                    var priceFields = [];

                    if ( parseInt(priceType) == 1 ){

                        var priceFields = {"tab-price":['currency','regular_price']};
                        
                        if( $('.offcer_price').val() != '' ){

                            priceFields = {"tab-price":['currency', 'regular_price', 'discount_close_date', 'offer_type']};
                        
                        }  


                    }else if ( parseInt(priceType) == 2 ){
                        
                        priceFields = {"tab-price":['currency', 'form_price', 'to_price']};
                        
                   
                    }else{
                        priceFields = {"tab-price":['price_type']};

                    }

                    
                    formValidation(priceFields);


                }

            }

            
	/// end price validation 
		
		
		
		
	
	// start form valodation
	
			function formValidation(fields)
			{
				//alert(fields);
				var tabError = 0;
				var tabName = 0;

				$.each(fields, function (i, val1) {

		      
					jQuery.each( val1, function( j, val ) {

							
                            if ($('.'+val)[0]) { // check class name exists or not
                                
                            
    							var input = $('.'+val).val();

    							  if( input == null ){   // remove validation message
    								var camelCased = removeUnderscoreSetSpaceConvertCamelCase(val); // set camel case ex: Title Can

    								$('.alert-'+val).html(camelCased+' Can not be Left Blank.');

    								tabError =1;
    								tabName =i;
                                    return false;
    							  }else if( input == '' ){  // show validation message
    								
                        
    								var camelCased = removeUnderscoreSetSpaceConvertCamelCase(val);
    								$('.alert-'+val).html(camelCased+' Can not be Left Blank.');

    								tabError =1;
    								tabName =i;

    							    return false;
    							 
    							  }else if( input == 0 ){  // show validation message
                                    
                                    var camelCased = removeUnderscoreSetSpaceConvertCamelCase(val);
                                    $('.alert-'+val).html(camelCased+' Can not be Left Blank.');

                                    tabError =1;
                                    tabName =i;

                                    return false;
                                 
                                  }else{   // remove validation message
    								//alert(tabError);
    								tabError = 0;
    								tabName =i;
    								$('.alert-'+val).html('');


    							   }

                            }
					
					});

				});

				if( tabError == 1){
					$("."+tabName).removeClass('btn-custom').addClass('btn-danger');

					return 'false';
				
				}else{
					 $("."+tabName).removeClass('btn-danger').addClass('btn-custom');
					 
					 return 'true';
				}


			}
	
	// end form valodation



    // start common form validation

    function formCommonValidation(fields)
            {
                //alert(fields);
                var error = 0;

              
                    jQuery.each( fields, function( j, val ) {
                            
                          
                            
                            if ($('.'+val)[0]) { // check class name exists or not
                                
                            
                                var input = $('.'+val).val();

                                  if( input == null ){   // remove validation message
                                    var camelCased = removeUnderscoreSetSpaceConvertCamelCase(val); // set camel case ex: Title Can

                                    $('.alert-'+val).html(camelCased+' Can not be Left Blank.');
                                     error = 1;
                                    
                                    }else if( input == '' ){  // show validation message
                                    
                        
                                    var camelCased = removeUnderscoreSetSpaceConvertCamelCase(val);
                                   
                                    $('.alert-'+val).html(camelCased+' can not be Left Blank.');

                                    error = 1;

                                  
                                  }else if( input == 0 ){  // show validation message
                                    
                                    var camelCased = removeUnderscoreSetSpaceConvertCamelCase(val);
                                    $('.alert-'+val).html(camelCased+' can not be Left Blank.');

                                    error = 1;
                                   
                                  }else{   // remove validation message
                                    
                                    $('.alert-'+val).html('');


                                   }

                            }
                    
                    });

                    return error;
                   
            }
    
    // end common form valodation
	
	
	
	
	
	//start image validation and view 
            
			function previewImage(className, prvId, alertId){
                
                var file = $('.'+className).get(0).files[0];
                    if(file){

                        var ext = $('.'+className).val().split('.').pop().toLowerCase();
                        var photoSize = file.size/1024; //kilobite

                        
                        if ($.inArray(ext, ['png','jpg','jpeg']) == -1){

                            $('#'+prvId).attr("src", "");
                            $('.alert-'+alertId).html('File formate is not correct.');

                            $('.'+className).val('');

                        }else{

                            if( photoSize <513 ){



                                var reader = new FileReader();
                         
                                reader.onload = function(){
                                     $('#'+prvId)
                                    .attr('src',  reader.result)
                                    .width('64px')
                                    .height('64px');
                                }
                                $('.alert-'+alertId).html(''); 
                                
                                reader.readAsDataURL(file);

                            }else{
                                $('.alert-'+alertId).html('Image size can not accede 512KB.');

                                $('.'+className).val(''); 
                            }
                        }
                    }
            }




            function previewFile(className, prvId, alertId){
                
                var file = $('.'+className).get(0).files[0];
                    if(file){

                        var ext = $('.'+className).val().split('.').pop().toLowerCase();
                        var photoSize = file.size/1024; //kilobite

                        
                        if ($.inArray(ext, ['pdf']) == -1){

                            $('#'+prvId).attr("src", "");
                            $('.alert-'+alertId).html('File formate is not correct.');

                            $('.'+className).val('');

                        }else{

                            if( photoSize <513 ){



                                var reader = new FileReader();
                                
                                reader.onload = function(){
                                     $('#'+prvId)
                                    .attr('src',  reader.result)
                                    .width('380px')
                                    .height('250px');
                                }
                                $('.alert-'+alertId).html(''); 
                                
                                reader.readAsDataURL(file);

                            }else{
                                $('.alert-'+alertId).html('Image size can not accede 512KB.');

                                $('.'+className).val(''); 
                            }
                        }
                    }
            }
      // end image validation and view 
	  
	  
	  
	  
	  
	///////// start product form tab wise form open 
	  
	  function openBasic()
            {
                 // hide form
                $(".gallery-form").hide();
                $(".price-form").hide();
                $(".inventory-form").hide();

                // show form
                $(".basic-form").show();

                // show button
                $(".go-gallery").show();

                // hide button
                $(".go-price").hide();
                $(".go-inventory").hide();

                $(".bak-basic").hide();
                $(".bak-gallery").hide();
                $(".bak-price").hide();
                $(".btn-submit-action").hide();
                $(".btn-submit-next-action").hide();



                // restore tab
                $(".tab-price").removeClass('btn-primary').addClass('btn-default');
                $(".tab-inventory").removeClass('btn-primary').addClass('btn-default');
                $(".tab-gallery").removeClass('btn-primary').addClass('btn-default');

                // change tab
                $(".tab-basic").removeClass('btn-default').addClass('btn-primary');

               
            }



          //  var fields = [basicFields, galleryFields];
           // filter.push(fields);

            function openGallery()
            {
                // hide form
                $(".basic-form").hide();
                $(".gallery-form").hide();
                $(".price-form").hide();
                $(".inventory-form").hide();

                // show form
                $(".gallery-form").show();

                // show button
                $(".bak-basic").show();
                $(".go-price").show();

                // hide button
                $(".go-gallery").hide();
                $(".go-inventory").hide();

                $(".bak-gallery").hide();
                $(".bak-price").hide();
                $(".btn-submit-action").hide();
                $(".btn-submit-next-action").hide();


                // restore tab
                $(".tab-basic").removeClass('btn-primary').addClass('btn-default');
                $(".tab-price").removeClass('btn-primary').addClass('btn-default');
                $(".tab-inventory").removeClass('btn-primary').addClass('btn-default');

                // change tab
                $(".tab-gallery").removeClass('btn-default').addClass('btn-primary');

                
                //console.log(basicFields);
               
                //formValidation(basicFields);

            }



         
            
            function openPrice()
            {
                // hide form
                $(".basic-form").hide();
                $(".gallery-form").hide();
                $(".inventory-form").hide();

                // show form
                $(".price-form").show();

                // show button
                $(".bak-gallery").show();
                $(".go-inventory").show();

                // hide button
                $(".go-gallery").hide();
                $(".go-price").hide();

                $(".bak-basic").hide();
                $(".bak-price").hide();
                $(".btn-submit-action").hide();
                $(".btn-submit-next-action").hide();

                
                // restore tab
                $(".tab-basic").removeClass('btn-primary').addClass('btn-default');
                $(".tab-inventory").removeClass('btn-primary').addClass('btn-default');
                $(".tab-gallery").removeClass('btn-primary').addClass('btn-default');

                // change tab
                $(".tab-price").removeClass('btn-default').addClass('btn-primary');

               
                //formValidation(galleryFields);
            }




             function openInventory()
            {
                 // hide form
                $(".basic-form").hide();
                $(".gallery-form").hide();
                $(".price-form").hide();

                // show form
                $(".inventory-form").show();

                // show button
                $(".bak-gallery").show();
                $(".bak-price").show();
                $(".btn-submit-action").show();
                $(".btn-submit-next-action").show();

                // hide button
                $(".go-gallery").hide();
                $(".go-price").hide();
                $(".go-inventory").hide();

                $(".bak-basic").hide();
                $(".bak-gallery").hide();

              
                // restore tab
                $(".tab-basic").removeClass('btn-primary').addClass('btn-default');
                $(".tab-gallery").removeClass('btn-primary').addClass('btn-default');
                $(".tab-price").removeClass('btn-primary').addClass('btn-default');
                $(".tab-inventory").removeClass('btn-primary').addClass('btn-default');

                // change tab
                $(".tab-inventory").removeClass('btn-default').addClass('btn-primary');

                
            }
			
	  
	///////// end product form tab wise form open 
	
	
	
	
	
	
	
	/// start get auto select data
		
		function getAutoDropdownData(targetShowClass, route, orderEmptyArr)
            {
                
                $.ajax({
                    type: "GET",
                    url: route,
                    dataType: "JSON",


                    beforeSend: function(){
                        $(".ajax-loader-img").css("display", "block");
                            jQuery.each( orderEmptyArr, function( j, field ) {

                                    $("."+field).empty();
                                    $("."+field).append('<option value="">Select</option>');
                            });
                       },
                       complete: function(){
                         $(".ajax-loader-img").css("display", "none");
                       },

                    success: function(data) {
                        
                        if(data)
                        {
							
                            $.each(data,function(key,value){
                                $('.'+targetShowClass).append($("<option/>", {
                                   value: key,
                                   text: value
                                }));
                            });
                        }

                    },

                    error: function() {
                        jQuery.each( orderEmptyArr, function( j, field ) {

                                $("."+field).empty();
                                $("."+field).append('<option value="">Select</option>');
                        });
                    }

                });

                
				
				
            }

        /// end get auto select data      





        /// start get data

        function getSpeceficData(route)
            {
                
                 
                var returnVal = '';
                $.ajax({
                    type: "GET",
                    url: route,
                    dataType: "JSON",
                    async: false,

                    beforeSend: function(){
                        $(".ajax-loader-img").css("display", "block");
                       },
                       complete: function(){
                         $(".ajax-loader-img").css("display", "none");
                       },

                    success: function(data) {
                        
                        returnVal = ''; 
                        
                        if(data)
                        {
                            returnVal = data; 
                        }

                    },

                    error: function() {

                        returnVal = ''; 
                    }

                });

                 return returnVal;
            }

	/// end get data




    /// start diabale back 

         $(document).ready(function() {

              window.history.pushState(null, "", window.location.href);        

              window.onpopstate = function() {

                  window.history.pushState(null, "", window.location.href);

              };

          });   
        
    /// end  diabale back 




    /// start basic package product form
        function productForBasic()
        {
            $('.tab-gallery').attr('disabled', true);
            $('.tab-price').attr('disabled', true);
            $('.tab-inventory').attr('disabled', true);

            $('.btn-submit-next-action').show();

            $('.div_catelog_file').hide();
            $('.div_tds_file').hide();
            $('.div_tentitive_delivery_days').hide();
            $('.div_short_description').hide();
            $('.div_description').hide();

            $('.div_offer').hide();
            $('.div_is_trending').hide();


            basicFields = {"tab-basic":['company_name', 'package_name', 'product_name', 'origin_name', 'product_top_category', 'sub_category']};

            galleryFields = {"tab-gallery":[]};
            
            inventoryFields = {"tab-inventory":[]};

            $('.go-gallery').removeAttr("type").attr("type", "submit");
            $('.go-gallery').html("Submit");
            $('.go-gallery').removeClass("go-gallery btn-primary").addClass("btn-success new-success");


            
        }
    /// end basic package product form




    /// start not basic package product form

        function notProductForBasic()
        {
            $('.tab-gallery').attr('disabled', false);
            $('.tab-price').attr('disabled', false);
            $('.tab-inventory').attr('disabled', false);

            $('.btn-submit-next-action').hide();
            $('.div_catelog_file').show();
            $('.div_tds_file').show();
            $('.div_tentitive_delivery_days').show();
            $('.div_short_description').show();
            $('.div_description').show();
            $('.div_offer').show();
            $('.div_is_trending').show();


            basicFields = {"tab-basic":['company_name', 'product_name', 'origin_name', 'product_top_category', 'sub_category']};

            galleryFields = {"tab-gallery":['product_Feature_image']};
            
            inventoryFields = {"tab-inventory":['unit', 'minimum_order']};

            $('.new-success').removeAttr("type").attr("type", "button");
            $('.new-success').html("Go Gallery");
            $('.new-success').removeClass("btn-success").addClass("go-gallery btn-primary");

        }
    /// end not basic package product form