﻿//  window.history.forward(1);
        
        document.onmousedown="if (event.button==2) return false"; 
        document.oncontextmenu=new Function("return false"); 
            
       


// Regular Expression Variables

var String_AlphaSpace = /^([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]+( )?)+$/;
var String_AlphaSpace_N = /^([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]+( )?)+$|^$/;
var String_AlphaNumeric = /^([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_])+$/;
var String_AlphaNumericSpaceSpecialCharecters = /^([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.()+-_,%@&]+( )?)+$/;
var String_AlphaNumericSpaceSpecialCharecters_N = /^([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.()+-_,%@&]+( )?)+$|^$/;
var String_Alpha = /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]+$/;
var String_Alpha_N = /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]+$|^$/;
var String_AlphaNumeric1 = /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]+$/;
var String_AlphaNumeric1_N = /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]+$|^$/;
var Number = /^[0123456789]+$/;
var Number_N = /^[0123456789]+$|^$/;
var PinCode = /^(\d{6})$/;
var PinCode_N = /^(\d{6})$|^$/;
var PhoneNumber = /^\d{8,}$/;
var PhoneNumber_N = /^\d{8,}$|^$/;
var Email_N = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$|^$/;
var Code_Employee = /^(IP)(\d{2})(\-)(\d{5})$/;
var Code_AccounHead = /^([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]+\-)+([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])+$/;
var Code_SingleAlpha = /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]$/;
var Code_CapitalAlphaAndNumber = /^[ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]+$/;
var Code_Date = /^(\d{2})(\/)(\d{2})(\/)(\d{4})$/;
var Bit =/^[01]$/;
var Code_DeductionHead = /^([0-9]+\-)+([0-9])+$/;



function SelectRegularExpression(type)
{
    if(type == "String_AlphaSpace")
    {
        return String_AlphaSpace;
    }
    
    else if(type == "String_AlphaSpace_N")
    {
        return String_AlphaSpace_N;
    }
    
    else if(type == "String_AlphaNumeric")
    {
        return String_AlphaNumeric;
    }
        
    else if(type == "String_AlphaNumericSpaceSpecialCharecters")
    {
        return String_AlphaNumericSpaceSpecialCharecters;
    }
    
    else if(type == "String_AlphaNumericSpaceSpecialCharecters_N")
    {
       return String_AlphaNumericSpaceSpecialCharecters_N; 
    }
    
    else if(type == "String_Alpha")
    {
        return String_Alpha;
    }
    
    else if(type == "String_Alpha_N")
    {
        return String_Alpha_N;
    }
    
    else if(type == "String_AlphaNumeric1")
    {
        return String_AlphaNumeric1;
    }
    
    else if(type == "String_AlphaNumeric1_N")
    {
        return String_AlphaNumeric1_N;
    }
    
    else if(type == "Number")
    {
        return Number;
    }
    else if(type == "Number_N")
    {
        return Number_N;
    }
    
    else if(type == "PinCode")
    {
        return PinCode;
    }
    
    else if(type == "PinCode_N")
    {
        return PinCode_N;
    }
    
    else if(type == "PhoneNumber")
    {
        return PhoneNumber;
    }
    
    else if(type == "PhoneNumber_N")
    {
        return PhoneNumber_N;
    }
            
    else if(type == "Email_N")
    {
        return Email_N;
    }
    
    else if(type == "Code_Employee")
    {
        return Code_Employee;
    }
    
    else if(type == "Code_AccounHead")
    {
        return Code_AccounHead;
    }
    
    else if(type == "Code_SingleAlpha")
    {
        return Code_SingleAlpha;
    }
    
    else if(type == "Code_CapitalAlphaAndNumber")
    {
        return Code_CapitalAlphaAndNumber;
    }
    
    else if(type == "Date")
    {
        return Code_Date;
    }
    
    else if(type == "Bit")
    {
        return Bit;
    }
     else if(type == "Code_DeductionHead")
    {
        return Code_DeductionHead;
    }     
}

//Javascript file
function ValidateTextBox(str,messagenull,message,type)
{
    type = SelectRegularExpression(type);
    if(messagenull == "" && document.getElementById(str).value=="")
    {
        return true;
    }
    else if(messagenull == "" && document.getElementById(str).value!="")
    {
        if (type.test(document.getElementById(str).value) == true)
        {
          return true;        
        }           
        else
        {
            alert(message);
            document.getElementById(str).select();
            return false;
        }    
    }
    else if((messagenull) != "" && (document.getElementById(str).value)=="")
    {
        alert(messagenull);
        document.getElementById(str).select();
        return false;
    }
    else if((messagenull) != "" && (document.getElementById(str).value)!="")
    {
        if (type.test(document.getElementById(str).value) == true)
        {
            return true;        
        }           
        else
        {
            alert(message);
            document.getElementById(str).select();
            return false;  
        } 
    }
}

//Validate Drop Down
function ValidateDropdown(str,message)
{
    if(document.getElementById(str).selectedIndex==0)
    {
        alert(message);
        document.getElementById(str).focus();
        return false;
    }
    return true;
}

function ValidateRadioButton(str,message,count)
{
    var i=0;
    for (i=0;i<count;i++)
    {
        if(document.getElementById(str+'_'+i).checked)
        {
            return true;
        }
    }
    alert(message);
    
    document.getElementById(str+'_'+0).focus();
    return false;
}

function ValidateBirthDate(strServerDate,strBirthDate,message)
{
   var serverDate=new Date(document.getElementById(strServerDate).value);
   var birthDate=new Date(document.getElementById(strBirthDate).value);
   var dateDiff=((serverDate - birthDate)/86400000);
   if(dateDiff<6574)
   {
     alert(message);
     document.getElementById(strBirthDate+'_Day_ID').focus();
     return false;
   }
   return true;

}

function ValidateJoiningDate(strJoiningDate,strBirthDate,strServerDate,message)
{
   var joiningDate=new Date(document.getElementById(strJoiningDate).value);
   var birthDate=new Date(document.getElementById(strBirthDate).value);
   var serverDate=new Date(document.getElementById(strServerDate).value);
   var dateDiff=((joiningDate - birthDate)/86400000);
   if((dateDiff<6574) || (joiningDate>serverDate))
    {
       alert(message);
       document.getElementById(strJoiningDate+'_Day_ID').focus();
       return false;
    }
   
      return true;
}

function ValidateCurrentOfficeDate(strCurrentOfficeDate,strJoiningDate,strServerDate,message)
{
   var currentOfficeDate=new Date(document.getElementById(strCurrentOfficeDate).value);
   var joiningDate=new Date(document.getElementById(strJoiningDate).value);
   var serverDate=new Date(document.getElementById(strServerDate).value);
   if((currentOfficeDate < joiningDate) || (currentOfficeDate > serverDate))
   {
    alert(message);
    document.getElementById(strCurrentOfficeDate+'_Day_ID').focus();
    return false;
   }
    return true;
    
}

function ValidateIncrementDate(strIncrementDate,strCurrentOfficeDate,strServerDate,message)
{
   var incrementDate=new Date(document.getElementById(strIncrementDate).value);
   var currentOfficeDate=new Date(document.getElementById(strCurrentOfficeDate).value);
   var serverDate=new Date(document.getElementById(strServerDate).value);
   //Updated start
   var dd=parseInt(currentOfficeDate.getDate());
   dd--;
   currentOfficeDate.setDate(currentOfficeDate.getDate()- dd);
   // Updated end
   
   var dateDiff=((incrementDate - currentOfficeDate)/86400000);
     
   if((dateDiff<365) || (incrementDate < serverDate))
   {
    alert(message);
    document.getElementById(strIncrementDate+'_Day_ID').focus();
    return false;
   }
    return true;
    
    
}

function ValidateFromDate(strFromDate,strJoiningDate,strServerDate,message)
{
  var fromDate=new Date(document.getElementById(strFromDate).value);
  var joiningDate=new Date(document.getElementById(strJoiningDate).value);
  var serverDate=new Date(document.getElementById(strServerDate).value);
   if((fromDate > serverDate) || (fromDate < joiningDate))
   {
    alert(message);
    document.getElementById(strFromDate+'_Day_ID').focus();
    return false;
   }
//alert(strFromDate);
//alert(strJoiningDate);
//alert(strServerDate);
    return true;
}


function ValidateFromDate1(strFromDate,strJoiningDate,strServerDate,message)
{
  //var fromDate=new Date(document.getElementById(strFromDate).value);
  //var joiningDate=new Date(document.getElementById(strJoiningDate).value);
  //var serverDate=new Date(document.getElementById(strServerDate).value);
   var fromDate=(document.getElementById(strFromDate).value);
   var joiningDate=(document.getElementById(strJoiningDate).value);
   var serverDate=(document.getElementById(strServerDate).value);
   if((fromDate > serverDate) || (fromDate < joiningDate))
   {
    alert(message);
    document.getElementById(strFromDate+'_Day_ID').focus();
    return false;
   }
//alert(strFromDate);
//alert(strJoiningDate);
//alert(strServerDate);
    return true;
}


 //Validation of From Date (should be > MAXPrevToDate or <= Todays Date)
function ValidateFromDateWithPrevToDate(strFromDate,strPrevToDate,strServerDate,message)
{
    
   var fromDate=new Date(document.getElementById(strFromDate).value);
   var prevToDate=new Date(document.getElementById(strPrevToDate).value);
   var serverDate=new Date(document.getElementById(strServerDate).value);
    
   if ((fromDate > serverDate) || (fromDate <= prevToDate))
   {
      alert(message + ' and MAXPrevToDate is ' + document.getElementById(strPrevToDate).value + ' (yyyy/mm/dd) ');
      document.getElementById(strFromDate+'_Day_ID').focus();
      return false;
   }
   
      return true;
   

}


function ValidateSuspentionFromDate(strFromDate,strServerDate,message)
{
  
   var fromDate=new Date(document.getElementById(strFromDate).value);
   var serverDate=new Date(document.getElementById(strServerDate).value);
   if(fromDate > serverDate)
   {
    alert(message);
    document.getElementById(strFromDate+'_Day_ID').focus();
    return false;
   }
    return true;
}

function ValidateSuspentionToDate(strFromDate,strToDate,message)
{
   var fromDate=new Date(document.getElementById(strFromDate).value);
  
   var toDate=new Date(document.getElementById(strToDate).value);
   if((toDate < fromDate))
   {
    alert(message);
    document.getElementById(strToDate+'_Day_ID').focus();
    return false;
   }
    return true;
}


    function ChkEmptyStr(strType)
    {
        var dis=strType.txtPassword.value;//(strType.txtPassword.value).substring((strType.txtPassword.value).length-1);
        strType.esalary.value=ConvertToCode(dis,1);
        
        //document.getElementById('lblError').innerHTML=strType.esalary.value;//strType.txtPassword.value;
        //strType.esalary.value =strType.txtPassword.value;// document.getElementById('txtPassword').innerHTML;
    }
    
    function ConvertToCode(strValue,option)
    {
        
        //Hidden Field Insertion
        if(option==1)
        {
            temp=strValue.length;
            var pwdstr="";
            for(i=0;i<temp;i++)
            {
                abc=strValue.charCodeAt(i)-5;
                pwdstr=pwdstr + String.fromCharCode(abc);
            }
         }
         //Paswword Field Conversion
         else
         {
            temp=strValue.length;
            var pwdstr=0;
                for(i=0;i<temp;i++)
            {
                abc=strValue.charCodeAt(i);
                //document.getElementById('lblSuccess').innerHTML=abc;
                pwdstr=pwdstr + abc;
            }
         }
         return pwdstr;
    }
    
    function SentToServer(strType)
    {
        strType.txtPassword.value=ConvertToCode(strType.txtPassword.value,2);//+"munish";
    }
    
    function ConvertPass(strValue)
    {
        
    }
    
	
//Validatin for length check of value
function ValidateContentLength(str,message,length)
{
	content=document.getElementById(str).value;
    if(content.length<length)
    {
        alert(message);
        document.getElementById(str).focus();
        return false;
    }
    return true;
}

//Validation for length check of value
function ValidateLength(str,message,length)
{
	str = str.trim();
    if(str.length<length)
    {
        alert(message);
        return false;
    }
    return true;
}

//Validate for content
function ValidateControl(str,message,type)
{
     type = SelectRegularExpression(type);

	str  = str.trim();

	if (type.test(str) == true)
    {
          return true;        
    }           
    else
    {
          alert(message);
          return false;
    } 
}

//Trim Function
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

