﻿var ISIE;
if (navigator.appName=="Microsoft Internet Explorer")
    ISIE = true;
else
    ISIE = false;

 
    
        function Delete()
        {
            var auth = document.getElementById('ctl00_hdnAuth').value;
            if(auth.substring(2,3) == '0')
            {
                alert('You are not Authorized to Delete Record');
                return false;
            }
            else
            {
                return confirm('Are you sure want to Delete this Record');
            }
        }
        function OpenPopup(heading,txtID,TableName,Field1,Field2, where)
        {
            var url ="../SelectList.aspx?txtID=" + txtID + "&TableName=" +TableName +"&Field1=" +Field1 + "&Field2=" + Field2+"&Where=" + where;				
				GB_showCenter(heading,url,450,750);
				return false;	
        }

        function OpenSection(TestID,SectionID)
        {
            var url ="../TestSection.aspx?TestID=" + TestID + "&SectionID=" +SectionID ;				
			GB_showCenter("Test Section Entry",url,350,550);
			return false;	
        }
        function OpenPage(Link)
        {
            
            window.open(Link,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=1000, height=600");
            return false;
        
        }
        function OpenFixPage(Link)
        {
            window.open(Link,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=800, height=600");
            return false;
        }
        function OpenQuestion(TestID,SectionNo,QuestionNo)
        {
            var url ="../TestQuestion.aspx?TestID=" + TestID + "&SectionID=" +SectionNo + "&QuestionID=" + QuestionNo ;				
            GB_showCenter("Test Question Entry",url,350,550);
            return false;
        }
        function OpenServiceQuestionForm(ServiceID,SeqNo)
        {
            var url ="../ServiceQuestionForm.aspx?ServiceID=" + ServiceID + "&SeqNo=" +SeqNo ;				
            GB_showCenter("Test Question Entry",url,350,550);
            return false;
        }
        function ValidateNumericWithLength(strElement,Length)
               {
                      if(strElement.value !='' )
                        {
                            if(strElement.value.length == Length)
                            {
                              return false;
                            }                        
                       }                       
                       else
                       {                      
                           if(event.keyCode >= 48 && event.keyCode <= 57)
                            {
                              return true;
                            }
                            else
                            {
                             return false;
                            }
                     }             
                }               
                
                function ValidateNumericOnly(strElement)
                     {
                    
                       if(event.keyCode >= 48 && event.keyCode <= 57)
                        {
                          return true;
                        }
                        else
                        {
                         return false;
                        }
                     }
                     
             function ValidateNumericPlusCommaOnly(strElement)
                     {
                      
                       if((event.keyCode >= 48 && event.keyCode <= 57)){
                            return true;
                        }                        
                        if(event.keyCode == 44){
                            return true;
                        }
                        return false;
                        
                     }
                
        
        /// Javascript Validation For Decimal Field  ... Done By Chirag Patel...//   
              
      function AllowDecimal(strElement,Length,DigitAfterDecimal)
        {
        
          var DigitBeforeDecimal = parseInt(Length) - parseInt(DigitAfterDecimal) ;
                
                 // First element cannot be '.'
                        if(strElement.value =='' )
                        {
                             if(event.keyCode >= 48 && event.keyCode <= 57)
                             {
                               return true;
                             }
                             else
                             {
                             return false;
                             }
                        }
                               
                    else
                    {
                      //if total length of text box equals length parameter + 1
                        if(strElement.value.length == Length + 1)
                        {
                          return false;
                        }
                         else
                         {
                          // if '.' is pressed
                             if(event.keyCode == 46)
                              {
                               // if there is already one '.'
                               if(strElement.value.indexOf('.') >= 0)
                                {
                                  return false;
                                }
                                else
                                {
                                return true;
                                }
                               } 
                             
                             
                            if(event.keyCode >= 48 && event.keyCode <= 57)
                              {
                                //if  '.' is already entered..
                                  if(strElement.value.indexOf('.') >= 0)
                                   {
                                     //if digits after '.' are equal to  DigitAfterDecimal parameter...
                                       if(strElement.value.length == (strElement.value.indexOf('.')+ 1 + DigitAfterDecimal))
                                        {
                                          return false;
                                        }
                                        else
                                        {
                                        return true;
                                        }
                                   
                                   }
                                 //if textbox contais digits and not '.', and length of digits has reached to DigitBeforeDecimal parameter
                                 if(strElement.value.length == DigitBeforeDecimal && strElement.value.indexOf('.') < 0 )
                                   {
                                    return false;
                                   } 
                                   else
                                   {
                                   return true;
                                  }
                               }
                              else
                              {
                               return false;
                              }
                         }
                   }
        }
        



// for Budding Page


        var values=new Array();
        var lastIndex;
        var txtValues = new Array();
        var ctlIds= new Array();
        var divIds =new Array();
        function validateInput(ctlid,row,col)
        {
       
            var startVal=txtValues[0];    
            var EndVal=txtValues[1];
            var ctlval =document.getElementById(ctlid).value;
            var index= (2 * row ) + col;
            //check for first and last cell
            if(row != 0 && row != values.length-1 && ctlval != "")
            {
                         var prevValue= document.getElementById(ctlIds[row-1]).value;     
                         var currValue= document.getElementById(ctlIds[row]).value;
                         if( (parseInt(currValue)>= parseInt(startVal)) && (parseInt(currValue)<= parseInt(EndVal)) )
                         {
                             if(col =="2")
                             {
                                if(parseInt(currValue) >= parseInt(EndVal) )
                                {
                                    document.getElementById(ctlid).value="";
                                    alert("Enter Valid Row Range Value");
                                }
                             }
                             if(col == "1")
                             {
                                if( (parseInt(currValue) == parseInt(prevValue) + 1) || (parseInt(currValue) == parseInt(prevValue)))
                                {
                                    
                                }
                                else
                                {
                                    document.getElementById(ctlid).value="";
                                    alert("Enter Valid Row Range Value");
                                }
                             }
                        }
                        else
                        {
                             document.getElementById(ctlid).value="";
                             alert('Value Must Be (Greater than or Equal to) Start Row & (Less than or Equal to) End Row');                             
                        }
            }//end of if(index != 0 && index != values.length-1)
        }//end of validateInput()
        
        function validateInputOnButtonClick()
        {
            var i=0;
           
            for(i=0;i< ctlIds.length ;i++)
            {
                if(i != 0 && i != ctlIds.length-1 )
                {
                    var prevVal = document.getElementById(ctlIds[i-1]).value;
                    var currVal = document.getElementById(ctlIds[i]).value;
                    if((parseInt(currVal) < parseInt(prevVal)))
                    {
                      alert("Please Check your Row Range Sequence");
                      return false;
                    }
                    if(i%2==0)
                    {
                        if(!( (parseInt(currVal) == parseInt(prevVal)) || (parseInt(currVal) ==  parseInt(prevVal) +1) ))
                        {
                             alert("Please Check your Row Range Sequence");
                             return false;
                        }
                    }
                }
            }return true;
        }
       
     // ***************** Transplantation Script *****************
     
     function validateTransInput(index,ctlNo)
        {
        
            var ctlid1;
            var ctlid2;
            var divid1;
            var divid2;
            var startVal;    
            var EndVal;
            
            if(ctlNo=="1")
            {
                divid1 = divIds[index];
                divid2 = divIds[index + 1];
                startVal= document.getElementById(divid1).innerHTML;
                EndVal= document.getElementById(divid2).innerHTML; 
            }
            else
            {
                divid1 = divIds[index-1];
                divid2 = divIds[index];
                startVal= document.getElementById(divid1).innerHTML;
                EndVal= document.getElementById(divid2).innerHTML; 
            }           
                        
            if(ctlNo=="1")
            
            {ctlid1=ctlIds[index];ctlid2=ctlIds[index+1]; }
            else{ctlid1=ctlIds[index-1];ctlid2=ctlIds[index];}
            
            //alert(ctlid1 +' ' + ctlid2  );
            
            var ctlval1 =document.getElementById(ctlid1).value;
            var ctlval2 =document.getElementById(ctlid2).value;
            
                        
            if((ctlval1 !="" && ctlNo==1) || (ctlval2 !="" && ctlNo==2))
            {
                
               
                var bol=false;
                
                if(ctlNo=="1")
                {
                    if((parseInt(ctlval1) >= parseInt(startVal)) && (parseInt(ctlval1) <= parseInt(EndVal)))
                    {bol=true;}else{bol=false;}
                }
                else if(ctlNo=="2")
                {
                    if((parseInt(ctlval2) >= parseInt(startVal)) && (parseInt(ctlval2) <= parseInt(EndVal)) && (parseInt(ctlval1) <= parseInt(ctlval2)))
                    {bol=true;}else {bol=false;}                 
                }
                
                if(bol)
                {
                    if(ctlNo=="1")
                    {
                        //Cheack Previous index Value must be greater than current Index Value.
//                        if(parseInt(index) != 0)
//                        {                            
//                            if(parseInt(values[parseInt(index)-1])  >= parseInt(ctlval1))
//                            {
//                                alert('Enter greater value than Previous End Row Value');
//                                values[index]=0;
//                                document.getElementById(ctlid1).value="";
//                                document.getElementById(ctlid1).focus();
//                                return false;                                
//                            }   
//                            else
//                            values[index]=document.getElementById(ctlid1).value;
//                        }    
                        values[index]=document.getElementById(ctlid1).value;                
                    }
                    else if(ctlNo=="2")
                    {
                        
                        values[index]=document.getElementById(ctlid2).value;
                    }
                }
                else
                {
                    if(ctlNo==1)
                    {
                        document.getElementById(ctlid1).value="";
                        document.getElementById(ctlid1).focus();
                    }
                    else
                    {
                        document.getElementById(ctlid2).value="";
                        document.getElementById(ctlid2).focus();
                    }
                    values[index]=0;
                    
                    alert('Value Must Be (Greater than or Equal to) Start Row & (Less than or Equal to) End Row');
                    return false;
                }
                
          }//end if(ctlval !="")
     
     }// ***************** End of Transplantation Script ************
     
        
// ************************** End script ***************************

 function CheckMaxLength(e, txt,max) 
       {       
         if (txt.value.length >= max && e.keyCode != 8)
         {
           txt.value = txt.value.slice(0,max);
           return false;
           }
           else
           {
           return true;
           }
       }
       
       function AllowNumericWithLength(strElement,Length)
                     {
                                
                      if(strElement.value !='' )
                        {
                    
                    
                        if(strElement.value.length == Length)
                        {
                          return false;
                        }
                        else
                        {
                        
                         if(event.keyCode >= 48 && event.keyCode <= 57)
                        {
                          return true;
                        }
                        else
                        {
                         return false;
                        }
                        
                        }
                        
                       }
                       
                        else
                       { 
                     
                       if(event.keyCode >= 48 && event.keyCode <= 57)
                        {
                          return true;
                        }
                        else
                        {
                         return false;
                        }
                     }
             
                }
                

var weekList=new Array();

function validateWeekEntry(weekStr)
{
    //don't allow to enter "0"
    if((event.keyCode==48) && (weekStr.value.length == 0))
        return false;
   
   //dont allow to enter "," at start
    if((event.keyCode==44) && (weekStr.value.length == 0))
        return false;
       
    if(ValidateNumericPlusCommaOnly(weekStr))
    {   
        if(event.keyCode==44)
        {
           
            
            var orgStr=weekStr.value; 
            
            orgStr = orgStr.replace(",0",",");
            
            weekList= orgStr.split(",");
            
            //first remove duplicate week from string
            var i=0;
            if(weekList.length-1==0)
            {
                if(parseInt(weekList[0])>52){
                    document.getElementById(weekStr.id).value ="";
                    return false;
                }
            }
            else
            {
               //debugger;
                for(i=0;i<weekList.length;i++)
                {
                    //Get last Value for comparision
                    var compStr=weekList[weekList.length-1];
                    var strToComp = orgStr.substring(0,orgStr.length -compStr.length);
                   
                    var curr =parseInt(weekList[i]);
                     
                    var j=0;
                    for(j=0;j<weekList.length;j++)
                    {
                        
                        var compVal =parseInt(weekList[j]);    
                        if((curr == compVal) && (j!=i))
                        {
                            document.getElementById(weekStr.id).value = orgStr.substring(0, strToComp.length);
                            return false;
                        }
                    }                    
                }
                 document.getElementById(weekStr.id).value = orgStr;
            }
           
                      
       }
       return true;
    }
    else
    {        
        return false;
    }
}

function onblurWeekComp(weekStr)
{
            //debugger;
            var orgStr=weekStr.value;
            // Remove "," from last position
            var temp =orgStr.substring(orgStr.length-1);
            
             if(temp == ",")
             {
                orgStr = orgStr.substring(0,orgStr.length-1);
             }
             // end of 
             
            orgStr = orgStr.replace(",0,",",");
            orgStr = orgStr.replace(",0",",");
            
            weekList= orgStr.split(",");
            //first remove duplicate week from string
            var i=0;
            if(weekList.length-1==0)
            {  
                if(parseInt(weekList[0]) > 52){
                    document.getElementById(weekStr.id).value ="";
                    return false;
                }
            }
            else
            {
                var newStr="";
                for(i=0;i<weekList.length;i++)
                {
                    //Get last Value for comparision                    
                    var curr =parseInt(weekList[i]);
                     
                    var j=0;
                    for(j=0;j<weekList.length;j++)
                    {
                        
                        var compVal =parseInt(weekList[j]);    
                        if((curr == compVal) && (j!=i) && (curr != 0) )
                        {
                            weekList[j]=0;                            
                        }                        
                    }                    
                }
                 for(i=0;i<weekList.length;i++)
                {
                    if(weekList[i] != 0)
                    newStr = newStr + weekList[i] +",";
                }
                
                newStr = newStr.substring(0,newStr.length-1);
                orgStr  = newStr ;
                
            }     
            
            document.getElementById(weekStr.id).value = orgStr;
    
}

function onKeyUpWeekValidation(ctl)
{
    var ctlVal=ctl.value;
    ctl.value = ctlVal.replace(",,","");
    return false;
}

function isDecimal(ctl,max,decPoint)
{

    var str = "^\\d{0," + max + "}(\\.\\d{0," + decPoint + "})?$";
    var re=new RegExp(str);
    if(!(re.test(ctl.value)))
    {   
        //negative + positive value validation
        //return /^[-+]?\d{3,5}(\.\d{1,3})?$/.test(str);        
        ctl.value="";
        //alert("not match");
    }    
}
function isNumeric(ctl)
{
   
   var str="^[-+]?\\d{0,10}$";
   var re=new RegExp(str);
    if(!(re.test(ctl.value)))
    {   
        //negative + positive value validation
        //return /^[-+]?\d{3,5}$/.test(str);
        ctl.value="";
        //alert("not match");
    }    
}

function isZerotoNine(ctl)
{
    var str="^[-+]?\\d{0,10}$";
    var re=new RegExp(str);
    if(!(re.test(ctl.value)))
    {
        ctl.value = '';
        return false;      
    }
    
    var vl = ctl.value;
    if(vl < 0 && vl > 99999)
    {
        ctl.value = '';
        return false;
    }
    return true;
}
 // this is used to Enter only numeric values in the text box 
    //Ex. onkeypress="return isNumberKey(this,3,event)"
    function isNumberKey(ctl,evt)
    {
        if(evt)
        {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
         return true;
         }
    } 
    
    function isFloatKey(ctl,evt)
    {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode == 46)
            return true;
         
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
         return true;
    } 
    
    
    function isFloat(ctl)
    {
         var str = "^\\d{0,18}(\\.\\d{0,2})?$";
        var re=new RegExp(str);
        if(!(re.test(ctl.value)))
        {
            ctl.value = '';
            return false;      
        }
        
        var vl = ctl.value;
        if(vl < 0 && vl > 99999)
        {
            ctl.value = '';
            return false;
        }
        return true;
    }
 
    
      

 
function CheckMaxLength(e, txt,max) 
{       
    if (txt.value.length >= max && e.keyCode != 8)
    {
        txt.value = txt.value.slice(0,max);
        return false;
    }
    else
    {
        return true;
    }
} 
// onkeyup="return CheckMaxLength(onkeyup,this,500);" onblur="return CheckMaxLength(onblur,this,500)" 



// Dont Allow Paste In textbox while text box is Readonly
function doReadOnly(control)
{
   event.returnValue = false;
}


function AllowDecimal(strElement,Length,DigitAfterDecimal)
{
    var DigitBeforeDecimal = parseInt(Length) - parseInt(DigitAfterDecimal) ;

     // First element cannot be '.'

            if(strElement.value =='' )
            {
                 if(event.keyCode >= 48 && event.keyCode <= 57)
                 {
                   return true;
                 }
                 else
                 {
                 return false;
                 }
            }

        else
        {
          //if total length of text box equals length parameter + 1
            if(strElement.value.length == Length + 1)
            {
              return false;
            }
             else
             {
              // if '.' is pressed

                 if(event.keyCode == 46)
                  {
                   // if there is already one '.'
                   if(strElement.value.indexOf('.') >= 0)
                    {
                      return false;
                    }
                    else
                    {
                    return true;
                    }
                   } 




                if(event.keyCode >= 48 && event.keyCode <= 57)
                  {
                    //if  '.' is already entered..
                      if(strElement.value.indexOf('.') >= 0)
                       {
                         //if digits after '.' are equal to  DigitAfterDecimal parameter...
//                           if(strElement.value.length == (strElement.value.indexOf('.')+ 1 + DigitAfterDecimal))
//                            {
//                              return false;
//                            }
//                            else
//                            {
//                            return true;
//                            }

                       }
                     //if textbox contais digits and not '.', and length of digits has reached to DigitBeforeDecimal parameter
                     if(strElement.value.length == DigitBeforeDecimal && strElement.value.indexOf('.') < 0 )
                       {
                        return false;
                       } 
                       else
                       {
                       return true;
                      }
                   }
                  else
                  {
                   return false;
                  }
             }
       }
} 

function dollarAmount(form, field) 
{  
    Num = "" + eval("document." + form + "." + field + ".value");
    dec = Num.indexOf(".");
    end = ((dec > -1) ? "" + Num.substring(dec,Num.length) : ".00");
    if(Num!='')
    {      
    Num = "" + parseFloat(Num.replace('$','').replace(',',''));

    var temp1 = "";
    var temp2 = "";


        if (end.length == 2) end += "0";
        if (end.length == 1) end += "00";
        if (end == "") end += ".00";

        var count = 0;
        for (var k = Num.length-1; k >= 0; k--) {
        var oneChar = Num.charAt(k);
        if (count == 3) {
        temp1 += "";
        temp1 += oneChar;
        count = 1;
        continue;
    }
    else 
    {
        temp1 += oneChar;
        count ++;
    }
    }
    for (var k = temp1.length-1; k >= 0; k--) 
    {
        var oneChar = temp1.charAt(k);
        temp2 += oneChar;
    }
    temp2 = "" + temp2 + end; //temp2 = "$" + temp2 + end;
    eval("document." + form + "." + field + ".value = '" + temp2 + "';");

     } 
} 
