﻿ //below function is to validate max length for subcategory description //
function maxLengthValidation(source,args)
 {
    var liLength=$get('ctl00_ContentPlaceHolder1_txtaddress').value.trim().length;
    if(liLength > 100)
        args.IsValid=false;
 }
 
 //below function is to validate max length for subcategory description //
function maxCommentsLength(source,args)
 {
    var liLength=$get('ctl00_ContentPlaceHolder1_txtcomments').value.trim().length;
    if(liLength > 100)
        args.IsValid=false;
}

function maxCommentsContactUs(source, args) {
    var liLength = $get('ctl00_ContentPlaceHolder1_txtcomments').value.trim().length;
    if (liLength > 1000)
        args.IsValid = false;
}
 
 //below function is to display or hide the state dropdown and textbox (for other countries) //  
    function displaystate(fobjcountry,fobjstate,fobjtxtstate)
    {
      var strtext = $get(fobjcountry).options[$get(fobjcountry).selectedIndex].text;
      $get(fobjtxtstate).value = "";  
      $get(fobjstate).selectedIndex = 0;
      if(strtext != "Select")
      {
          if(strtext != "US - United States")
          {
             $get(fobjtxtstate).style.display = ''; 
             $get(fobjstate).style.display = 'none';
          }
          else
          {
             $get(fobjtxtstate).style.display = 'none'; 
             $get(fobjstate).style.display = '';
             $get(fobjstate).disabled = false; 
          }
       }
       else
       {
          $get(fobjtxtstate).style.display = 'none'; 
          $get(fobjstate).style.display = '';
          $get(fobjstate).disabled = true; 
       }
    }

//below function is to validate state//
  function funvalidatestate(source,args)
  {
     var strtext = $get('ctl00_ContentPlaceHolder1_cmbCountry').options[$get('ctl00_ContentPlaceHolder1_cmbCountry').selectedIndex].text;
     if(strtext != "Select")
     {
        if(strtext == "US - United States")
        {
            if($get('ctl00_ContentPlaceHolder1_cmbState').value == "")
            {
                args.IsValid = false;
                source.errormessage = "State.";
            }
        }
        else
        {
           if($get('ctl00_ContentPlaceHolder1_txtstate').value.trim() == "")
           {
              args.IsValid = false;
              source.errormessage = "State.";
           }
        }
    }
    else
    {
        args.IsValid = false;
        source.errormessage = "State.";
    }
}

//function to check the length of username & password //
 function minLengthValidation(source,args)
 {
    if($get('ctl00_ContentPlaceHolder1_txtUserName').value.trim() != "")
    {
        var liLength=parseInt($get('ctl00_ContentPlaceHolder1_txtUserName').value.length);
        if(liLength < 4)
            args.IsValid=false;
    }
 }
    
  //function to check the length of username & password //
 function minPasswordLength(source,args)
 {
    if($get('ctl00_ContentPlaceHolder1_txtpassword').value.trim() != "")
    {
        var liLength=parseInt($get('ctl00_ContentPlaceHolder1_txtpassword').value.length);
        if(liLength < 6)
            args.IsValid=false;
        else
            args.IsValid=true;
    }                                     
 }
 
  //below function is to select all the checkboxes in the grid // 
  function fundeleteall(obj)
  {
     var totalcount = parseInt(document.getElementById('ctl00_ContentPlaceHolder1_hidrowcount').value)
     var count;
     var chkobj = "";
     for(count=0;count<totalcount;count++)
     {
        if(count <= 9)
            chkobj = document.getElementById('ctl00_ContentPlaceHolder1_rptFaouriteProducts_ctl0' + count + '_chkchild'); 
        else
          chkobj = document.getElementById('ctl00_ContentPlaceHolder1_rptWishlist_ctl' + count + '_chkchild'); 
          
        if(chkobj != null)
              chkobj.checked = obj;         
     }
  }
  
   //bewlo function is to check for items deletion //
  function checkitems(fobjid)
  {
     var totalcount = parseInt(document.getElementById('ctl00_ContentPlaceHolder1_hidrowcount').value)
     var count;
     var chkobj = "";
     var lbflag = false;
     for(count=0;count<totalcount;count++)
     {
        if(count <= 9)
            chkobj = document.getElementById('ctl00_ContentPlaceHolder1_rptFaouriteProducts_ctl0' + count + '_chkchild'); 
        else
          chkobj = document.getElementById('ctl00_ContentPlaceHolder1_rptWishlist_ctl' + count + '_chkchild'); 
          
        if(chkobj != null)
        {
            if(chkobj.checked == true)
            {
              lbflag = true;
              break;
            }
        }
     }
     if(!lbflag)
     {
          if(fobjid == "ctl00_ContentPlaceHolder1_imgbtnAddCart")
            alert("Please select atleast one item to add to cart.");
          else
            alert("Please select atleast one item to delete."); 
          return false;
     }
     else
     {
        if(fobjid == "ctl00_ContentPlaceHolder1_imgbtnDelete")
            return confirm('Are you sure you want to delete selected favourite product/s?'); 
     }
  } 
  
  //below function is to validate the title selected or not //
function validateContactTitle(source,args)
 {
    if($get('ctl00_ContentPlaceHolder1_rbtnMr').checked == false && $get('ctl00_ContentPlaceHolder1_rbtnMrs').checked == false && $get('ctl00_ContentPlaceHolder1_rbtnMiss').checked == false)
        args.IsValid=false;
    else
        args.IsValid=true;
 } 
 
