﻿// JScript File
  function DisableControl(cntl)
{
    document.getElementById(cntl).disabled=true;
}
                    
function checkPeriod(objTextbox,objDropDownList)
{

    var txtPeriod=document.getElementById(objTextbox);
    var ddlPeriod=document.getElementById(objDropDownList);
      if(txtPeriod.value.length<6)
    {
        alert('Invalid Period!');
        return false;
    }

    var txtlength= txtPeriod.value.substring(txtPeriod.value.length,4);
    if(txtlength==00)
    {
           alert('Invalid Period(s)!');  
           return false;
           }
    if(ddlPeriod.value==1)
    {
       if(txtlength > 12)
       {
           alert('Invalid Period(s)!');  
           return false;
       }       
    }
    if(ddlPeriod.value==2)
    {
       if(txtlength > 04)
       {
           alert('Invalid Period or not more than 4 Quarter(s)!');  
           return false;
       }    
    }
    if(ddlPeriod.value==3)
    {
    if(txtlength > 02)
       {
           alert('Invalid Period or not more than 2 Semi Annual(s)!');  
           return false;
       }    
    }
    if(ddlPeriod.value==4)
    {
     if(txtlength > 01)
       {
           alert('Invalid Period or only one Annual!');  
           return false;
       }    
    }
}
function Reset()
{
window.location =window.location;
return false;
}

  function EnableDisable(objTextbox,objDropDownList)
    {
            // loop through all elements
       var txtPeriod=document.getElementById(objTextbox);
       var ddlPeriod=document.getElementById(objDropDownList);
//       var gridRebate = document.getElementById("ctl00_ContentPlaceHolder1_CalculateRebate1_gridRebate");
       txtPeriod.disabled=false;
       ddlPeriod.disabled=false;
       
    }  
    
    
     function confirmDeleteMsg(GridviewID)
    {   
        var flag= false;
        var chk;
        
        if(document.getElementById(GridviewID).all!=undefined)
        {
            chk=document.getElementById(GridviewID).all.tags("input");
        }
        else
        {
            chk=document.getElementById(GridviewID).getElementsByTagName("input");
        }
        for(i=0;i<chk.length;i++)
        {
            if(chk[i].type == "checkbox")
            {
                if(chk[i].checked)
                {
                   flag=true;
                }
            }
        }
        
        if(flag== false)
        {
             alert('Please select atleast one record to be deleted!');
             return false;
        }
            else
        {
             return confirm('Are you sure, you want to delete the selected record(s)?');
        } 

    }  
    
    function confirmSelectMsg(GridviewID)
    {   
        var flag= false;
        var chk=document.getElementById(GridviewID).all.tags("input");
        for(i=0;i<chk.length;i++)
        {
            if(chk[i].type == "checkbox")
            {
                if(chk[i].checked)
                {
                   flag=true;
                }
            }
        }
        
        if(flag== false)
        {
             alert('Please select one of check box before Rebate Calculate!');
             return false;
        }
//            else
//        {
//             return confirm('Are you sure want to delete Record(s)?');
//        } 

    }  
    
    function Reset()
    {
      document.forms[0].reset();
   return false;
    }
    
    
function validateQuantity(txtName)
{
   var quantityVal=document.getElementById(txtName).value;

    if(!CheckNull(quantityVal))
    {
        alert("Please enter some quantity.");
         document.getElementById(txtName).focus();
        return false;    
    }
    


   if(IsNumeric(quantityVal))
   {
        if(quantityVal <= 0 || quantityVal > 9999)
        {
            alert("Quantity should be between 1 and 9999.");
            document.getElementById(txtName).value ="";
            document.getElementById(txtName).focus();
            return false;
        }
         return true;
   }
   else
   {
        alert("Quantity should be numeric.");
        document.getElementById(txtName).value ="";
        document.getElementById(txtName).focus();
   }
   return false;
}
function IsNumeric(sText)
{
   var ValidChars = "-0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
   function Ltrim(sStr)
{
 for (i = 0; i < (sStr.length); i++)
   { if (sStr.charAt(i) != ' ')
         return sStr.substring(i)
     else
         sStr.substring(i)
   }
 return ""
}


/* For Checking Null */
function CheckNull(strchecknull)
{	
	if(Rtrim(Ltrim(strchecknull)) == "")
	{
		return false;
	}
	else 
	{	
		return true;
	}
}


/* For Right Trim */
function Rtrim(sStr)
{
 for (i = sStr.length; i != 0; i--)
  {  if (sStr.charAt(i) != ' ')
         return sStr.substring(0,i+1)
     else
         sStr.substring(0,i)
  }
   return ""
}

function ShowToolTip(DivId)
    {
        document.getElementById(DivId).style.display="";
        return false;
    }   
    function HideToolTip(DivId)
    {
        document.getElementById(DivId).style.display="none";
        return false;
    }   

function DisableClick()
{
    return false;
}



