$(document).ready(function() {
$(".jQNumeric").keydown(function (e) {
        // Allow: backspace, delete, tab, escape, enter and .
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
             // Allow: Ctrl+A
            (e.keyCode == 65 && e.ctrlKey === true) ||
             // Allow: home, end, left, right, down, up
            (e.keyCode >= 35 && e.keyCode <= 40)) {
                 // let it happen, don't do anything
                 return;
        }
        // Ensure that it is a number and stop the keypress
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    });
 });


function validateProductForm()
{
     
                         var productdesc = CKEDITOR.instances.editor1.getData();
			 
                         if($('#txtProductName').val()=='')
                             {
                                 alert(MSG_PRODUCT_NAME);
                                 $('#txtProductName').focus();
                                 return false;
                             }
                             
                             if($('#clsSeller').val()=='')
                               {
                                   var Sellervalue = $('select#cmbSeller option:selected').val();
                                   
                                   if(Sellervalue==null || Sellervalue=='') {
                                    alert(MSG_PRODUCT_SELLER);
                                        return false;
    //whatever code you need
                                     }
                               }
                            
                           
                             if(productdesc=='')
                             {
                                 alert(MSG_PRODUCT_DESCRIPTION);
                                 $('#editor1').focus();
                                 return false;
                             }
                           
                          
                            
                            
                             if($('#txtPrice').val()=='')
                             {
                                 alert(MSG_PRODUCT_PRICE);
                                  $('#txtPrice').focus();
                                 return false;
                             }
                             
                              var stock = document.getElementsByName('product_stock[]');//here rr[] is the name of the textbox

                                for (var i = 0; i < stock.length; i++)
                                {		
                                if (stock[i].value=="")
                                {
                                    alert(MSG_PRODUCT_STOCK + i);
                                        stock[i].focus();
                                        return false;			
                                }
                            }
                             
                             
                             
              // Big Image Validation
                           var image_value = [];
                           var imgCount    =  0;
                            $("input[name='image_big[]']").each(function(index) {                                
                                var value = $(this).val();
                                imgCount = imgCount+1;
                                if (value) {
                                    image_value.push(value);
                                  //  return true;
                                }else{
                                    //index.preventDefault();
                                    //var cnt = index+1;
                                       // alert(MSG_BIG_IMAGE_VALIDATION + cnt);
                                        return false;
                                }
                            });


                       // Product Staock Validation
                       
                       
                     /*  $("input[name='product_stock[]']").each(function() {
                               // alert(index);
                                var value = $(this).val();
                                if (value) {
                                    var stat    =   1;
                                }
                                else{
                               
                                        alert(MSG_PRODUCT_STOCK);
                                        $('.clsProductStock').focus();
                                         return false;
                                    }
                            });*/
                       
                            
                              
                                                      
                            if ($('#txtDigitalProduct').is(":checked"))
                                  {
                                           if($('#txtProductZip').val()=='')
                                       {
                                           alert(MSG_PRODUCT_DIGITAL);
                                            $('#txtProductZip').focus();
                                           return false;
                                       }
                                       
                                       if($('#txtProductZip').val()!='')
                                            {
                                                  var val = $("#txtProductZip").val();
                                                  if (!val.match(/(?:gif|jpg|png|zip|pdf|rar|wma|psd|opf|azw|lit|pdb|pkg|mp3|mpeg|mp4|avi|eps|mpg|3gp|act|aac|flac|m4a|m4p|mpc|wv|ra|rm|tiff|mov|mxf)$/)) {
                                                      // inputted file path is not an image of one of the above types
                                                      alert(MSG_PRODUCT_DIGITAL_TYPES);
                                                      $('#txtProductZip').focus();
                                                       return false;
                                                  }
                                            }
                                       
                                        if($('#txtDownloadTry').val()=='')
                                       {
                                           alert(MSG_PRODUCT_DIGITAL_DOWNLOAD_TRY);
                                            $('#txtDownloadTry').focus();
                                           return false;
                                       }
                                       
                                        if($('#txtDownloadExpiry').val()=='')
                                       {
                                           alert(MSG_PRODUCT_DIGITAL_DOWNLOAD_EXPIRY);
                                            $('#txtDownloadExpiry').focus();
                                           return false;
                                       }
                                  }else{
                                      
                                        if($('.clsShippingWeight').val()=='')
                                      {
                                          alert(MSG_PRODUCT_SHIPPING_WEIGHT);
                                           $('.clsShippingWeight').focus();
                                          return false;
                                      }
                                      
                                        if($('#clsShippingdimension').val()=='Y')
                                      {
                                          
                                                 if($('.clsProductlength').val()=='')
                                              {
                                                  alert(MSG_PRODUCT_SHIPPING_LENGTH);
                                                   $('.clsProductlength').focus();
                                                  return false;
                                              }
                                              
                                                 if($('.clsProductwidth').val()=='')
                                              {
                                                  alert(MSG_PRODUCT_SHIPPING_WIDTH);
                                                   $('.clsProductwidth').focus();
                                                  return false;
                                              }
                                                 if($('.clsProductheight').val()=='')
                                              {
                                                  alert(MSG_PRODUCT_SHIPPING_HEIGHT);
                                                   $('.clsProductheight').focus();
                                                  return false;
                                              }
                                      }
                                      
                                     
                                  }
                             
                                var fieldEmptyCount  = image_value.length;
                                if(fieldEmptyCount==imgCount)
                                {
                                    var fieldToValidate     = fieldEmptyCount;
                                }else{
                                    if(imgCount>fieldEmptyCount)
                                    {
                                       var fieldToValidate         =  imgCount -fieldEmptyCount;
                                    }
                                }
                           
                              if (image_value.length < imgCount) {
                                  for(var i =0;i<=fieldToValidate;i++)
                                  {
                                       var j= imgCount-fieldToValidate;
                                        alert(MSG_BIG_IMAGE_VALIDATION + j);
                                        $("input[name='image_big[]']")[j].focus();
                                        return false;
                                   }
                               }
                               else{
                                        return true;
                                }           
                                     
                                   
                                    
}


function validateFileExtension(fld) {
    if(!/(\.bmp|\.png|\.gif|\.jpg|\.jpeg)$/i.test(fld.value)) {
        alert("Invalid image file type.");
        fld.form.reset();
        fld.focus();
        return false;
    }
    return true;
 }