// JScript File


function fnSaveCodeConfirmation(CodeDescritptionTextBox, IsValueField, DescriptionValueTextBox, DisplayMessage)
 {
    // //debugger;
     var returnValue;
        
//      var bResult = confirm(DisplayMessage);
//      
//     if (bResult) 
//     {
       
       returnValue =  fnIsAnyMandatoryFieldsFilled(CodeDescritptionTextBox, IsValueField, DescriptionValueTextBox);
      
       if( returnValue == true)
       {
        return true;
       }
       else
       {
        return false;
       }
//     }
//     else 
//     {
//         return false;
       //     }

}

////////////////////////////////////////////////////////////////////////
function fnIsAnyMandatoryFieldsFilled(CodeDescritptionTextBox,IsValueField,DescriptionValueTextBox)
{

   // //debugger;
 var Result="true";
    //__doPostBack("HelpButton", "");
   if(IsValueField == 'False')
   {
        with (CodeDescritptionTextBox)
        {
        if (value==null||value=="")
        {
            //  SetMessageBox('Enter Code','Info'); MessageVars
            SetMessageBox(MessageVars.COM_0026, 'Info');
          Result= "false";
          return false;
        }
       
       }
       with (DescriptionValueTextBox)
        {
        if (value==null||value=="")
        {
            //SetMessageBox('Enter Description','Info');
            SetMessageBox(MessageVars.COM_0027, 'Info');
          Result= "false";
           return false;
        }
             
      }
      if(Result=="true")
      {
         return true;
      }
      else
      {
      return false;
      }
  
    }
  else
  {
      with (CodeDescritptionTextBox)
        {
        if (value==null||value=="")
        {
            // SetMessageBox('Enter Description','Info');
            SetMessageBox(MessageVars.COM_0027, 'Info');
          Result= "false";
          return false;
        }
       
       }
       with (DescriptionValueTextBox)
        {
        if (value==null||value=="")
        {
            //SetMessageBox('Enter Value','Info');
            SetMessageBox(MessageVars.COM_0028, 'Info');
          Result= "false";
           return false;
        }
             
      }
      if(Result=="true")
      {
         return true;
      }
      else
      {
      return false;
      }
  }
  
  
 }



function fnValueSaveButtonClick()
{
// //debugger;
  //  alert('Rajendra Patel');
    var himsValidator = [new hims_ctl_val("ctl00_CP_CodeDescriptionTextBox","567374","T","","","",20), new hims_ctl_val("ctl00_CP_DescriptionValueTextBox","567374","T","DC","","",20)];
                           
    if (fnDoValidate(himsValidator))
    {
        return true;
    }
    else
    {

        //SetMessageBox('Cannot save the data','Info');
        SetMessageBox(MessageVars.COM_0031, 'Info');
         //alert ("Can't Save the Data");
         return false;
    }
   
}
////////////////////////////////////////////////////////////////////////////////////////////
function fnEnableDisableTextBox()
{
////debugger;

 // var ctlvalue=gE('ctl00_CP_DescriptionValueTextBox').value;
  //  fnEnableFields(ctlvalue);
  if (document.getElementById("ctl00_CP_ObsoleteCheckBox").disabled == true)
  {
  document.getElementById("ctl00_CP_ObsoleteCheckBox").disabled=false;
  }


 if (document.getElementById("ctl00_CP_DescriptionValueTextBox").disabled == true)
 {
  document.getElementById("ctl00_CP_DescriptionValueTextBox").disabled  = false;
 }


if (document.getElementById("ctl00_EditButton").disabled == false)
 {
  document.getElementById("ctl00_EditButton").disabled  = true;
 }
 if (document.getElementById("ctl00_SaveButton").disabled == true)
 {
  document.getElementById("ctl00_SaveButton").disabled  = false;
 }
  return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////
function fnClearButtonClick()
{

    //fnClearTextBox('ctl00_CP_DescriptionValueTextBox');//,ctl00_CP_DescriptionValueTextBox,ctl00_CP_DescriptionValueTextBox,SearchCodeDescriptionTextBox,SearchDescriptionValueTextBox')
     //fnDisableFields('ctl00_CP_SaveButton');
   fnClearCheckOrRadio('ctl00_CP_ObsoleteCheckBox');
}
/////////////////////////////////////////////////////////////////////////////////////////////////
function fnEnableDisableField()
{

  //  fnEnableFields('ctl00_SaveButton');
  if (document.getElementById("ctl00_SaveButton").disabled == true)
  {
    document.getElementById("ctl00_SaveButton").disabled=false;
   
  }
  return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function fnDecimalValidation(DescriptionValueTextBox)
{  ////debugger;
    var  strName=DescriptionValueTextBox.value;
    var strCharpos = strName.search("[^0-9,.]"); 
    if((strName.length > 0 &&  strCharpos >= 0) || (strName.indexOf('.') != strName.lastIndexOf('.')))
    {
        //SetMessageBox('Invalid Value', 'Info');
        SetMessageBox(MessageVars.COM_0029, 'Info');
          if (document.getElementById("ctl00_SaveButton").disabled == false)
         {
             document.getElementById("ctl00_SaveButton").disabled=true;
         }
        return false; 
    }
    ResetMessageBox();
    fnEnableDisableField();
    return true;
}
/////////////////////////////////////////////////////////////////////////////////
//function fnCheckSpaceValidation(DescriptionValueTextBox) {
//   // debugger;
//    var strParam = DescriptionValueTextBox.value;
//    
//    var strNumaric = fnTrim(strParam);
//    
//        var charParam = strNumaric.charAt(0);
//        var iChar = charParam.charCodeAt(0);
//        if (iChar == 32) {//COM_0008

//            SetMessageBox(MessageVars.COM_0008, 'Info');
//          //  alert("First Character cant be a space");
//            return false;

//        }
//        return true;
//           
//}
//////////////////////////////////////////////////////////////////////////////////////////////////////////// 
 function fnAlphanumericValidation(CodeDescriptionTextBox)
 {
 //debugger;
     var strParam = CodeDescriptionTextBox.value;
    
    var strNumaric = fnTrim(strParam);
    for(var j=0; j<strNumaric.length; j++)
    {
        var charParam = strNumaric.charAt(j);
        var iChar = charParam.charCodeAt(0);
      //  if ((iChar == 32) || (iChar > 47 && iChar < 59) || (iChar > 64 && iChar < 91) || (iChar > 96 && iChar < 123) || (iChar = 45))
            if ((iChar > 64 && iChar < 91) || (iChar > 96 && iChar < 123) || (iChar == 45) || (iChar > 47 && iChar < 58))//if not a number
        {

           
        }
        else
        {
            //  SetMessageBox('Invalid Code','Info');
            SetMessageBox(MessageVars.COM_0030, 'Info');
          if (document.getElementById("ctl00_SaveButton").disabled == false)
           {
             document.getElementById("ctl00_SaveButton").disabled=true;
           }
        return false;
        }
      
    }
    ResetMessageBox();
    fnEnableDisableField();
   return true;
 }
 
 
 ////////////////////////////////////////////////////////////////////
 
 function fnDecimalScaleValidation(DescriptionValueTextBox,Precision,scale)
 {
 //debugger;
       ResetMessageBox();
       fnEnableDisableField();
       var strName = DescriptionValueTextBox.value;
       var strNumaric = fnTrim(strName);
        
        var charParam = strNumaric.charAt(0);
        var iChar = charParam.charCodeAt(0);
       
//        if ((j = 0) && (iChar == 32)) {
//            //  alert("First Character Cant be space");
//          //  SetMessageBox(MessageVars.COM_0008, 'Info');
//             return false;
//            }
       
        var strCharpos = strName.search("[^0-9,.]"); 
         if((strName.length > 0 &&  strCharpos >= 0) || (strName.indexOf('.') != strName.lastIndexOf('.')))
         {
             // SetMessageBox('Invalid Value','Info');
             SetMessageBox(MessageVars.COM_0029, 'Info');
         if (document.getElementById("ctl00_SaveButton").disabled == false)
         {
            document.getElementById("ctl00_SaveButton").disabled=true;
         }
          return false; 
         }
    
       if (strName.indexOf('.') == -1) 
         strName= strName + '.00'; 
       var pointIndex=0;
       var strNameLen=strName.length
       pointIndex = strName.indexOf('.');
     //pointIndex=pointIndex+1;
       var wholeNumber = strName.substring(0,pointIndex); 
       var decimalNumber = strName.substring(pointIndex+1,strNameLen);
      if((wholeNumber.length > Precision)||(decimalNumber.length > scale))
      {
          // SetMessageBox('Invalid Value','Info');
          SetMessageBox(MessageVars.COM_0029, 'Info');
         if (document.getElementById("ctl00_SaveButton").disabled == false)
         {
            document.getElementById("ctl00_SaveButton").disabled=true;
         }
       return false; 
     }
//////string.substring(from,to)
//////returns the substring within string starting at the fromth char 
//////up to the th char

//   
    ResetMessageBox();
    fnEnableDisableField();
    return true;
 }
// //////////////////////////////////////////////////////////////////
// 
//  
//  function fnDecimalScaleValidation(DescriptionValueTextBox)
//  { 
// 
////    var  strName=DescriptionValueTextBox.value;
////    if (string.indexOf('.') == -1) 
////       strName= strName + '.00'; 
////     var pointIndex=string.indexOf('.');
////     
////    var wholeNumber = string.substring(0,pointIndex); 
////    var decimalNumber = string.substring(pointIndex,(strName.length-(wholeNumber.length-1)));
////    if((wholeNumber.length > Precision)||(decimalNumber.length > scale))
////    {
////     SetMessageBox('Invalid Value','Info');
////          if (document.getElementById("ctl00_SaveButton").disabled == false)
////          {
////             document.getElementById("ctl00_SaveButton").disabled=true;
////          }
////        return false; 
////    }
//////string.substring(from,to)
//////returns the substring within string starting at the fromth char 
//////up to the th char

//   
////    ResetMessageBox();
//  //  fnEnableDisableField();
//    return true;
//}
///////////////////////////////////////////////////////////////////////////////////////


     function SaveValidation(CodeDescritptionTextBox,IsValueField,DescriptionValueTextBox)
     {
    
       fnIsAnyMandatoryFieldsFilled(CodeDescritptionTextBox,IsValueField,DescriptionValueTextBox);
       if(IsValueField == 'False')
       {
          fnAlphanumericValidation(CodeDescriptionTextBox);
       }
       else
       {
          fnDecimalValidation(DescriptionValueTextBox);
       }
     }
     ///////////////////////////////////////////////////////////////////////////////////
     
 