﻿// JScript File
function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
//it allowed only char.and dot,space---------------------------------
 function isChar(evt)  // onkeypress="return isChar(event)" onpaste="return false;"

    {  
     //alert('sdfsdf');
     
          var charCode = (evt.which) ? evt.which : event.keyCode  
          
        if (charCode ==8 ||(charCode >= 65  && charCode <= 90 ) ||(charCode >= 97  && charCode <= 122 )|| charCode ==32 ||charCode == 9 || charCode == 46)
            return true;  
         else
           alert("Invalid Character");
           return false;  
          // return false;
     }  
// ------------------------------------------------------------------   
 // it  allowed char And number only------------------       
function isAlphNumericEvt(evt)  // onkeypress="return isAlphNumericEvt(event)" onpaste="return false;"

    {  
          var charCode = (evt.which) ? evt.which : event.keyCode  
        // if ((charCode > 31 && charCode < 48 ) || (charCode > 57  && charCode < 65 ) || (charCode > 90  && charCode < 97) || (charCode > 122))  
        if ((charCode >= 48 && charCode <= 57 ) || (charCode >= 65  && charCode <= 90 ) ||(charCode >= 97  && charCode <= 122 )|| charCode ==32 ||charCode == 9 ||charCode == 8)
            return true;  
         return false;  
     }          
//---------------------------------------------
 // --------it  allowed char ,number and allowed symbol(-,_. space) only------------------       

function isAlphNumericSymbols(evt)  // onkeypress="return isAlphNumericSymbols(event)" onpaste="return false;"

    {  
          var charCode = (evt.which) ? evt.which : event.keyCode  
        // if ((charCode > 31 && charCode < 48 ) || (charCode > 57  && charCode < 65 ) || (charCode > 90  && charCode < 97) || (charCode > 122))
          if ((charCode >= 48 && charCode <= 57) || (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || charCode == 32 || charCode == 9 || charCode == 46 || charCode == 44 || charCode == 45 || charCode == 95 || charCode == 8 || charCode == 43 || charCode == 35)
            return true;  
            else
             alert("Invalid Character");
         return false;  
     }          

//---------------------------------------------

// it  allowed char ,number and allowed symbol(-,/. space) only------------------       

function isAlphNumericAddress(evt)  // onkeypress="return isAlphNumericAddress(event)" onpaste="return false;"

    {  
          var charCode = (evt.which) ? evt.which : event.keyCode  
        // if ((charCode > 31 && charCode < 48 ) || (charCode > 57  && charCode < 65 ) || (charCode > 90  && charCode < 97) || (charCode > 122))  
        if (charCode ==8 || (charCode >= 48 && charCode <= 57 ) || (charCode >= 65  && charCode <= 90 ) ||(charCode >= 97  && charCode <= 122 )|| charCode ==32 || charCode == 9 || charCode == 46 || charCode == 44 || charCode == 45 ||charCode == 47 )
            return true;  
            else
             alert("Invalid Character");
         return false;  
     }          

//---------------------------------------------
// Date validation----------(greter than current date is not valid)-------------------------------

 function CheckDate(toDate)   //   
 {  
   var dt = new Date();
   dt.setHours(0,0,0,0);  
   
    var date1 = new Date(dt);
	var date2 = new Date(toDate);

	var sec = date2.getTime() - date1.getTime();
	if (isNaN(sec))
	{
		alert("Input data is incorrect!");
		return false; 
	}

	var second = 1000, minute = 60 * second, hour = 60 * minute, day = 24 * hour;

    var days = Math.floor(sec / day);

    if(days>0)
     return false ;
    else  
     return true ;
  }

//-----------------------------------------------------


// -------- Please enter more than 5 and less than 15 digit-----
function mobile(mobno)
{

   if( mobno.length >= 5 && mobno.length <= 15)
     return true;   

  else
  
  // alert("Please enter more than 5 and less than 15 digit");
   return false;
   
}
//===============================================


//------------Date validation ----(From date should be less than current date) --------------------------------------------------------------------
function CheckTodateFromdate(objToDate,objFromDate,fromname,toname) // Eg==> <script type ="text/javascript" language ="javascript"> function IsValidate(){var objFromDate=document.getElementById("<%=txtEventDate.ClientID%>").value; var objToDate = document.getElementById("<%=txtIntimation.ClientID%>").value;  var event_date="Event date"; var intimate_date= "Intimation date"; if(!CheckTodateFromdate(objToDate,objFromDate,event_date,intimate_date)){ return false ; } return true; }</script>                                                                    // than code create page_laod(){ btnSubmit.Attributes.Add("onclick", "return IsValidate();");  } 
                                                               
{  
    var FromDate = new Date(objFromDate); 
    var ToDate = new Date(objToDate); 
    var valCurDate = new Date(); 
    valCurDate = valCurDate.getMonth()+1 + "/" + valCurDate.getDate() + "/" + valCurDate.getYear(); 
    var CurDate = new Date(valCurDate); 
  
    if(FromDate < ToDate) 
    { 
        alert(fromname + " should be less than " + toname); 
        return false;  
    } 
    else if(FromDate > CurDate) 
    { 
        alert("From date should be less than current date"); 
        return false;  
    } 
    else if(ToDate > CurDate) 
    { 
        alert("To date should be less than current date"); 
        return false; 
    }
}


function CheckEventsDate(objToDate, objFromDate, fromname, toname) // Eg==> <script type ="text/javascript" language ="javascript"> function IsValidate(){var objFromDate=document.getElementById("<%=txtEventDate.ClientID%>").value; var objToDate = document.getElementById("<%=txtIntimation.ClientID%>").value;  var event_date="Event date"; var intimate_date= "Intimation date"; if(!CheckTodateFromdate(objToDate,objFromDate,event_date,intimate_date)){ return false ; } return true; }</script>                                                                    // than code create page_laod(){ btnSubmit.Attributes.Add("onclick", "return IsValidate();");  }
{
    alert("sdfasdfasD");
    var FromDate = new Date(objFromDate);
    var ToDate = new Date(objToDate);
    var valCurDate = new Date();
    alert(valCurDate)
    valCurDate = valCurDate.getMonth() + 1 + "/" + valCurDate.getDate() + "/" + valCurDate.getYear();
    var CurDate = new Date(valCurDate);
    alert(valCurDate);
    if (FromDate < ToDate) {
        alert(fromname + " should be less than " + toname);
        return false;
    }
    else if (FromDate < CurDate) {
        alert("From date should not be less than current date");
        return false;
    }
    else if (ToDate < CurDate) {
        alert("To date should not be less than current date");
        return false;
    }
}

//Event Date Validation

function ValidateFromToDate(fromDate,toDate,message,mesage2) //to date Should be less then from date
{
  
   
    fromDate=fromDate.substring(3,5) +"/"+ fromDate.substring(0,2)+"/"+ fromDate.substring(6,10)

    var FromDate = new Date(fromDate);
   

    toDate=toDate.substring(3,5) +"/"+ toDate.substring(0,2)+"/"+ toDate.substring(6,10)


    var ToDate = new Date(toDate);
  
    var valCurDate = new Date(); 
    valCurDate = valCurDate.getMonth()+1 + "/" + valCurDate.getDate() + "/" + valCurDate.getYear();
    var CurDate = new Date(valCurDate);
   
    if (FromDate < CurDate) {
       
       
        alert(message + " date should be future date"); 
        return false;  
    }
    
    if(ToDate<CurDate)
    {
        alert(message2 + " date should be future date"); 
        return false;  
    }

    if(FromDate<ToDate)
    {  
        alert(mesage2 + " date should be less then "+ message +" date"); 
        return false;  
    }

   
    
} 

//Chekc Current Date
function WithCurrentDate(dtDate,mesage) //to date Should be less then from date                                                               
{  
  dtDate=dtDate.substring(3,5) +"/"+ dtDate.substring(0,2)+"/"+ dtDate.substring(6,10)
    var FromDate = new Date(dtDate); 
    var valCurDate = new Date(); 
    valCurDate = valCurDate.getMonth()+1 + "/" + valCurDate.getDate() + "/" + valCurDate.getYear(); 
    var CurDate = new Date(valCurDate); 
    
    if(FromDate<CurDate)
    {
        alert(mesage + " date should be future date"); 
        return false;  
    }
    return true;  
} 
//--------------------------------------------------------------------------------------------------------------------------------------------------
 function checkDropDownListIsNull(val) 
 
 {
    if(val == "0")
      return false;
    else
     return true;  
 }
//================================================
function isNumberKey(evt)//onkeypress="return isNumberKey(event)" onpaste="return false;"
        {
       
        var charCode = (evt.which) ? evt.which : event.keyCode
     
        if( (charCode >= 48 && charCode <= 57 )||charCode == 9 || (charCode== 8))
           return true; 
         else
          alert("Only enter number"); 
           return false; 
        
 }
        
      //--validation only for numeric value
        function isNumber(evt)//onkeypress="return isNumber(event)" onpaste="return false;"
        {
       
        var charCode = (evt.which) ? evt.which : event.keyCode
        //alert(charCode);   
        if ( (charCode>47 &&  charCode<58)||charCode==8)
           return true; 
         else
         alert("Only enter number"); 
           return false; 
        
        }

function validate_required(field,alerttxt)
{
 with (field)
  {  
  
  if (value==null||value=="")
    {
     alert('Please enter '+ alerttxt);return false;
     focus();
    }
  else
  if(trim(value)=="")
  {
   alert('Invalid '+ alerttxt);return false;
   focus();
  }  
  else
    {
    return true;
    }
  }
}

function chkemail(email) {

    if (email == "") {
        alert('Please enter  E-mail Id');
        return false;
    }
    if (email.length < 9) {
        alert("Minimum length of E-mail Id should be 9");
        return false;
    }

    var test = email.split("@");
    var test1 = test[0];

    if ((isNaN(test1)) == false) {
        alert(" Invalid E-mail Id");
        return false;

    }


    var reg = /^([A-Za-z0-9_\-\.]{3,50})+\@([A-Za-z0-9\.]{2,50})+\.([A-Za-z]{2,4})$/;
    var address = email;
    if (reg.test(address) == false) {
        alert(' Invalid E-mail Id');
        return false;
    }
}
/*






function chkemail(email)
{
                            
if(email=="")
{
alert('Please enter email id');
return false;
}
if(email.length < 9)
{
alert("Minimum email length should be 9");									
return false ;
}
                                
if(email !="")
{
                                
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)))   
{
alert('Invalid email id');
return false; 
}
else
{     
var i = email.indexOf("@",0);
for (var x = i+1;x<email.length;x++)
{
var charid  = email.charCodeAt(x);
if(!((charid >= 65 && charid <= 90) || (charid >= 97 && charid <= 122)||(charid ==46 )))
{
alert('Invalid email id'); 
return false;                 
}          
}   
}    
}
                                  
return true; 
}
                                                        
                            
*/
    function DateFromToDateValidation(txtStartDate, txtEndDate) 
    {

        //alert("hiiiiii");
        var SDate = document.getElementById(txtStartDate).value;
        var EDate = document.getElementById(txtEndDate).value;

        var firstIndex = SDate.indexOf("/");
        var secondIndex = SDate.lastIndexOf("/");

        var d1 = SDate.substring(0, firstIndex);
        var m1 = SDate.substring(firstIndex + 1, secondIndex);
        var y1 = SDate.substring(secondIndex + 1, SDate.length);
        var SDateFull = m1 + "/" + d1 + "/" + y1;
        
        
        var d2 = EDate.substring(0, firstIndex);
        var m2 = EDate.substring(firstIndex + 1, secondIndex);
        var y2 = EDate.substring(secondIndex + 1, EDate.length);
        var EDateFull = m2 + "/" + d2 + "/" + y2;
        
        
        var startDate = new Date(SDateFull);
        var endDate = new Date(EDateFull);

        if (SDate != '' && EDate != '' && startDate > endDate) 
            {
              alert('TO date must be greater than FROM date.');
              return false;
            }
            return true;
    }
    
 
    function isPassValidate(evt)   // onkeypress="return isPassValidate(event)" onpaste="return false;"
      {  
      var charCode = (evt.which) ? evt.which : event.keyCode  
      if ((charCode >= 48 && charCode <= 57 ) || (charCode >= 65  && charCode <= 90 ) ||(charCode >= 97  && charCode <= 122 ))
       { 
         return true;
       }
      if ( charCode ==38 ||charCode == 59 || charCode== 39 || charCode==34) 
       {
       alert("Invalid Input");
         return false;
        }
     }
     
      function isLoginName(evt)  // onkeypress="return isLoginName(event)" onpaste="return false;"
      {  
      var charCode = (evt.which) ? evt.which : event.keyCode  
      if ((charCode >= 48 && charCode <= 57 ) || (charCode >= 65  && charCode <= 90 ) ||(charCode >= 97  && charCode <= 122 ))
       { 
         return true;
       }
      if ( charCode ==38 ||charCode == 59 || charCode== 39 || charCode==34 || charCode==32) 
       {
       alert("Invalid Input");
         return false;
        }
     }
     
     function isAlphaSymbol(evt)  // onkeypress="return isAlphaSymbol(event)" onpaste="return false;"

    {  
          var charCode = (evt.which) ? evt.which : event.keyCode  
        // if ((charCode > 31 && charCode < 48 ) || (charCode > 57  && charCode < 65 ) || (charCode > 90  && charCode < 97) || (charCode > 122))  
        if ((charCode >= 65  && charCode <= 90 ) ||(charCode >= 97  && charCode <= 122 )||charCode == 9|| charCode ==43|| charCode == 45 ||charCode == 47)
            return true;  
         else
           alert("Invalid Character");
           return false;   
     }
     
     
     //it allowed only char ---------------------------------
 function isCharonly(evt)  // onkeypress="return isCharonly(event)" onpaste="return false;"
 
    {  
     //alert('sdfsdf');
     
          var charCode = (evt.which) ? evt.which : event.keyCode  
          
        if (charCode ==8 ||(charCode >= 65  && charCode <= 90 ) ||(charCode >= 97  && charCode <= 122 )|| charCode ==32)
            return true;  
         else
           alert("Invalid Character");
           return false;  
          // return false;
     }  
   
// === validation to check the minimum length 2 ====///  
   
   function CheckMinimumLengthOfName(objName,msg)   
   {
    if(objName.value.length < 2)
      {
          alert("Minimum length of " + msg + " should be 2");
        objName.focus();
        return false ;
      }
   }
   
//=== validation to check the minimum length 6 ====///   

   function CheckMinimumLengthOfpassword(objpassword,msg)   
   {
    if(objpassword.value.length < 6)
      {
          alert("Minimum length of " + msg + " should be 6");
        objpassword.focus();
        return false ;
      }
   }
// ------------------------------------------------------------------                

//=== validation to check the minimum length 4 ====///   

   function CheckMinimumLengthOfzip(objpassword,msg)   
   {
    if(objpassword.value.length < 4)
      {
          alert("Minimum  length of  " + msg + " should be 4");
        objpassword.focus();
        return false ;
      }
   }
// ------------------------------------------------------------------    


//=== validation to check the minimum length 5 ====///   

   function CheckMinimumLengthOfcontactno(objpassword,msg)   
   {
    if(objpassword.value.length < 5)
      {
          alert("Minimum length of " + msg + " should be 5");
        objpassword.focus();
        return false ;
      }
   }
// ------------------------------------------------------------------    

 // --------it  allowed char ,number and allowed symbol(-,_.) only------------------       

function isAlphNumericsymbolspacenotallow(evt)  // onkeypress="return isAlphNumericsymbolspacenotallow(event)" onpaste="return false;"

    {  
          var charCode = (evt.which) ? evt.which : event.keyCode  
        // if ((charCode > 31 && charCode < 48 ) || (charCode > 57  && charCode < 65 ) || (charCode > 90  && charCode < 97) || (charCode > 122))  
        if ((charCode >= 48 && charCode <= 57 ) || (charCode >= 65  && charCode <= 90 ) ||(charCode >= 97  && charCode <= 122 ) || charCode == 46 || charCode == 44 || charCode == 45 ||charCode == 95 || charCode==8 )
            return true;  
            else
             alert("Invalid Character");
         return false;  
     }
     
     
//=== validation to check the minimum length 100 ====///   

   function CheckMinimumLengthOfdescription(objpassword,msg)   
   {
    if(objpassword.value.length < 100)
      {
        alert("Minimum "+ msg +" length should be 100");
        objpassword.focus();
        return false ;
      }
   }
// ------------------------------------------------------------------    
  
  //=== validation to check Email Id Of minimum length 9 ====///   

   function CheckMinimumLengthOfcontactemail(objpassword,msg)   
   {
    if(objpassword.value.length < 9)
      {
          alert("Minimum length  of" + msg + "should be 9");
        objpassword.focus();
        return false ;
      }
   }
function isDecription(evt)  // for Decription field it allows all the character except ; '

    {  
          var charCode = (evt.which) ? evt.which : event.keyCode  
          if (charCode == 59||charCode == 39 )
        {
           alert("Invalid Character");
            return false;
         }  
            else
             return true;  
     } 
     
 
  function isCharDot(evt)  // onkeypress="return isLoginName(event)" onpaste="return false;"
      {  
      var charCode = (evt.which) ? evt.which : event.keyCode  

      if ( charCode==8 ||(charCode >= 65  && charCode <= 90 ) ||(charCode >= 97  && charCode <= 122 ))
       { 
         return true;
       }
      else      
       {
         alert("Invalid Input");
         return false;
        }
     }
     
      function DateValidate(SDate, EDate,curr_date)
 {
 var firstIndex = SDate.indexOf("/");
            var secondIndex = SDate.lastIndexOf("/");
            
            var d1 = SDate.substring(0,firstIndex);
            var m1 = SDate.substring(firstIndex+1,secondIndex);
            var y1 = SDate.substring(secondIndex+1,SDate.length);
            var SDateFull=m1 + "/" + d1 + "/" +y1;
            var d2 = EDate.substring(0,firstIndex);
            var m2 = EDate.substring(firstIndex+1,secondIndex);
            var y2 = EDate.substring(secondIndex+1,EDate.length);
            var EDateFull=m2 + "/" + d2 + "/" +y2;
           
            
            if(SDateFull > EDateFull)
            {
             alert('End date must be greater than start date.');
                return false;
            }
           
           if(EDateFull > curr_date)
           {
            alert('End date should  be less than current Date');
            return false;
           }
           }
           
    function checkSpaceFirstChar(val,TextName)
    {
		if(val.substring(0,1)==" ")
		{
			alert("Invalid "+ TextName +" please remove space from first character")
			return false;
		}
     
    }
    
  // it  allowed all keyboard  (;,' not allowed)    

function isAlphNumericAddressaddorg(evt)  // onkeypress="return isAlphNumericAddress(event)" onpaste="return false;"

    {  
          var charCode = (evt.which) ? evt.which : event.keyCode  
        // if ((charCode > 31 && charCode < 48 ) || (charCode > 57  && charCode < 65 ) || (charCode > 90  && charCode < 97) || (charCode > 122))  
     if (charCode ==8 || charCode ==59 || charCode == 39)
     {
      alert("Invalid Character");
            return false; 
      }
  }


  function checkDotFirstChar(val, TextName) {
      if (val.substring(0, 1) == ".") {
          alert("Invalid " + TextName + " please remove dot from first character")
          return false;
      }

  }
  function checkSpecialChar(val, TextName) {
      var first = val.substring(0, 1);
      var check = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
      var i = check.indexOf(first, 0);
   
      if (i < 0)
          {
              alert("Invalid " + TextName + " please remove special character from first position")
  return false ;
  }
  }
