﻿
/*******************************************************************
Created By: Dharminder Singh
Created Date: 07 Sep 2007

* All the validations are checked on IE and Mozrilla Firefox 

* A <Validation.CSS> Style Sheet is used for displaying the style of 
  validation Message 
  To change  'style of validation message' or 'Images of successful and error'
  we can change into style sheeet  

* Every function of javascript file we used two input parameters >...
  First Parameter is 'object' of any element
  Second parameter is 'Id' of any element 
  Basically Second Parameter is used for displaying error message into any label
  control or span
  
* for check validtaion on onkeyup ,onblur  events of any control we use validation method 
  such as e.g. onblur="OnlyInteger(this,'integerstatus')"
   here  'this' is element object and 'integerstatus' is span Id
   
* To check validations on any control button ,firstly you set onkeyup property of every object 
   so the all validation error message display on the page 
   e.g.   var obj1=document.getElementById('<%=txtNumeric.ClientID%>');
          var obj2=document.getElementById('<%=txtfirstname.ClientID%>');
          obj1.onkeyup();
          obj2.onkeyup();
          if (OnlyInteger(obj1,'integerstatus')&&OnlyNumeric(obj7,'NumericStatus'))
          {return true}else{return false}}
          
* To display error style of textbox,Please add CssClass <inboxSuccess> to every input Types 
  e.g. 	<asp:TextBox CssClass =" inboxSuccess" runat ="server"  id="txtpassword" ></asp:TextBox>

  
*******************************************************************/
// JScript File

/*******************************************************************
Function to Check for Empty value 
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function SetErrorSuccessCheckBoxList(Flag,span,msz)
{
    var obj = document.getElementById(span);
    if(Flag==false)
    {
         setError(obj,msz);
         return false;
    }
    else
    {
        setSuccess(obj);
        return true;
    }
}


/*******************************************************************
Function to Check for Middle Name Empty value 
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function IsMiddleNameEmpty(em,id,msz)
{

  var obj2 = document.getElementById(id);
  if( em.value.trim().length > 0 )
    {
        
//        var blnResult =false;
//        var StrInValidChars='{}[]`,.<>~!@#$%^&*()-+=:;"?/\|'
//        var Space=" ";
//        for (i = 0; i < em.value.length && blnResult == false; i++)
//        {   
//            strChar = em.value.charAt(i);
//            if (StrInValidChars.indexOf(strChar) >=0)
//            {
//                 blnResult = true;
//            }
//           
//        }
//        if(blnResult == true)
//        {
//            setErrorColor(em);
//            msz='Field cannot contain special characters';
//            setError(obj2,msz);
//            obj2.style.visibility="visible";
//            return false;        
//        }
//        else
//        {
            setSuccessColor(em);
            setSuccess(obj2);
            obj2.style.visibility="visible";
            return true;
      //  }
    }
    else
    {
        obj2.style.visibility="hidden";
        return true;
    }
  }
  /*****************************************************************/
function IsDateEmpty(em,id,msz)
{

  var obj2 = document.getElementById(id);
  if( em.value.trim().length==0 )
    {
        setErrorColor(em);
        setError(obj2,msz);
        return false;
    }
   else
   {
     return true;
   }
}

/*******************************************************************
Function to Check for Empty value 
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
/********************************************************************/

function IsEmpty(em,id,msz)
{

  var obj2 = document.getElementById(id);
  if( em.value.trim().length==0 )
    {
        setErrorColor(em);
        setError(obj2,msz);
        return false;
    }
    else
    {
//        var blnResult =false;
//        var StrInValidChars='{}[]`,<>~!@#$%^&*()-+=:;"?/\|'
//        var Space=" ";
//        for (i = 0; i < em.value.length && blnResult == false; i++)
//        {   
//            strChar = em.value.charAt(i);
//            if (StrInValidChars.indexOf(strChar) >=0)
//            {
//                 blnResult = true;
//            }
//           
//        }
//        if(blnResult == true)
//        {
//            setErrorColor(em);
//            msz='Field cannot contain special characters';
//            setError(obj2,msz);
//            return false;        
//        }
//        else
//        {
            setSuccessColor(em);
            setSuccess(obj2);
            return true;
       // }
    }
  }
  /*******************************************************************
Function to Check Login in Database
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function LoginStatus(id,msz,flag)
{       
        var obj2 = document.getElementById(id);
        if(flag==0)
        {
            
            setError(obj2,msz);
            return false;
        }
  }
  
  /*********************************************************************/
  function DateStatus(em,id,msz)
  {
        var obj2 = document.getElementById(id);
        setErrorColor(em);
        setError(obj2,msz);
  }
//  /***********
    /*******************************************************************
Function to Check Availablity of User Name in Database
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function AvailabilityUserName(em,id,msz,flag)
{
    
    var obj2 = document.getElementById(id);

      if( em.value.trim().length==0 )
        {
            setErrorColor(em);
            setError(obj2,"Required");
            return false;
        }
        else
        {
            if(flag==0)
            {
                setErrorColor(em);
                setError(obj2,msz);
                return false;
            }
            else
            {
                if (ValidateEmailAddress(em,id)== true)
                {
                    setSuccessColor(em);
                    setSuccess(obj2);
                    return true;    
                }
                else
                {
                    return false;
                }    
            }
            
        }

  }
      /*******************************************************************
Function to Check Availablity of Reseller User Name in Database
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function Availability(em,id,msz,flag)
{
    var obj2 = document.getElementById(id);
    
//    if(path==0)
//    {
        if( em.value.trim().length==0 )
        {
            setErrorColor(em);
            setError(obj2,"Required");
            return false;
        }
        else
        {
           
            if(flag > 0)
            {
               
                setErrorColor(em);
                setError(obj2,msz);
                return false;
            }
            else
            {
                setSuccessColor(em);
                setSuccess(obj2);
                return true;    
            }
            
        }
    
//    }
//    else
//    {
//        if( em.value.trim().length==0 )
//        {
//            return true;
//        }
//        else
//        {
//            if(flag > 0)
//            {
//               
//                setErrorColor(em);
//                setError(obj2,msz);
//                return false;
//            }
//            else
//            {
//                setSuccessColor(em);
//                setSuccess(obj2);
//                return true;    
//            }
//        
//        }
//    
//    }
    
    
  }
      /*******************************************************************
Function to Check Availablity of Referral Code in Database
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function AvailabilityReferralCode(em,id,msz,flag)
{

    var obj2 = document.getElementById(id);
      if( em.value.trim().length==0 )
        {
            setSuccessColor(em);
            obj2.innerHTML="";
            obj2.className="RefferalSuccess";
        return true;    
        }
    else
    {
        if(flag==0)
        {
            setErrorColor(em);
            setError(obj2,msz);
            return false;
        }
        else
        {
        setSuccessColor(em);
        setSuccess(obj2);
        return true;    
        }
        
    }
    
  }
/*****************************************************************
Function  Check for valid Email or not 
          Output: function give error message return false if input is not valid
                    else it return successful message
Here emailID >>Any textbox object
          id >>Any span Id or label Id for Display Validation Message  
******************************************************************/
function ValidateEmailAddress(emailID,id)
 {
    var obj2 = document.getElementById(id);
   if(emailID.value!='' &&  checkMail(emailID.value))
    {
       setSuccessColor(emailID);
       setSuccess(obj2);
       return true;
     }
            else
             {
                if(emailID.value.trim().length==0)
                {
                  setErrorColor(emailID);
                 setError(obj2,"Required");
                 return false;
                }
               else
                {
                 setErrorColor(emailID);
                setError(obj2,("Invalid Email Address"));
                return false;
                }
                return true;
                
             }
}

/*****************************************************************
Function  Check for selecting item in DropDown list 
          Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any DropDown object
     id >>Any span Id or label Id for Display Validation Message
*******************************************************************/  
 function ValidateDropDown(em,id,msz)
       {
         var obj2= document.getElementById(id);
           if (em.selectedIndex == 0||em.value =='00'||em.value == ''||em.value=='-- Please Select --'||em.value=='All') 
           {
              setErrorColor(em);
              setError(obj2,msz);
              return false;
              
           }
           else
           {
                 setSuccessColor(em);
                setSuccess(obj2);
                window.focus();
                return true;
           }
       }

/******************************************************************
Function  Check for  password value in DropDown list
          Output: function give error message return false if input is not valid
                    else it return successful message 
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
here password length is minimum 5 character
********************************************************************/
function checkFirstPassword(em,id)
{
        var strValidChars = "0123456789"; 
        var strChar;
        var blnResult = false;
        var obj2 = document.getElementById(id);
        if(em.value.trim().length==0)
        {
            setErrorColor(em);
            setError(obj2,"Required");
            return false;
        }
        else
        {
//                var blnResult =false;
//                var StrInValidChars='{}[]`,.<>~!@#$%^&*()-+=:;"?/\|'
//                var Space=" ";
//                for (i = 0; i < em.value.length && blnResult == false; i++)
//                {   
//                    strChar = em.value.charAt(i);
//                    if (StrInValidChars.indexOf(strChar) >=0)
//                    {
//                         blnResult = true;
//                    }
//                   
//                    if(Space.indexOf(strChar) >=0)
//                    {
//                        setErrorColor(em);
//                        msz='Password cannot contain SPACE.';
//                        setError(obj2,msz);
//                        return false;     
//                    }
//                }
//                if(blnResult == true)
//                {
//                    setErrorColor(em);
//                    msz='Field cannot contain special characters.';
//                    setError(obj2,msz);
//                    return false;        
//                }
                if(em.value.trim().length < 6)
                {
                    setErrorColor(em);
                    setError(obj2,"Minimum 6 characters.");
                    return false;
                }
                else
                {
                    for (i = 0; i < em.value.length ; i++)
                    { 
                     strChar = em.value.charAt(i);
                      if (strValidChars.indexOf(strChar) >=0)
                      {
                           blnResult = true; 
                      }
                    }
                    if(blnResult==false)
                    {
                        setErrorColor(em);
                        setError(obj2,"Must contain a number.");
                        return false;
                    }
                    else
                    
                    {
                        setSuccessColor(em);
                        setSuccess(obj2);
                        return true;
                    }
                }
        }
} 
/*********************************************************************************************
Function  Check for match password value of two elements 
          Output: function give error message return false if input is not valid
                  else it return successful message
Here em1 >>first password textbox object
     em2 >>second password textbox object
     id1 >>Any span Id or label Id for Display Validation Message for first password textbox
     id2 >>Any span Id or label Id for Display Validation Message for second password textbox   
here password length is minimum 5 character
***********************************************************************************************/
function checkPassword(emA,emB,id1,id2)
{
    
    
    var obj1 = document.getElementById(id1); 
    var obj3 = document.getElementById(id2); 
    if(emA.value==emB.value)
    {
        setSuccessColor(emA);
        setSuccessColor(emB);
        setSuccess(obj1);
        setSuccess(obj3);
        return true;
    }
    else
    {
       
        setErrorColor(emB);
        setError(obj3,"Passwords do not match");
        return false;
        
    }
}
function checkEmail(emA,emB,id1,id2)
{
    
    
    var obj1 = document.getElementById(id1); 
    var obj3 = document.getElementById(id2); 
    if(emA.value==emB.value)
    {
        setSuccessColor(emA);
        setSuccessColor(emB);
        setSuccess(obj1);
        setSuccess(obj3);
        return true;
    }
    else
    {
       
        setErrorColor(emB);
        setError(obj3,"Emails do not match");
        return false;
        
    }
}
/********************************************************************
Function  Validate Zip Code 
          Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
*********************************************************************/
function ValidateZip(em,id)
{
    var obj1 = document.getElementById(id);
     var strValidChars = "0123456789"; 
               var strChar;
               var blnResult = true;
                if(em.value.trim().length==0)
                {
                    setErrorColor(em);
                    setError(obj1,"Please insert Zip Code");
                    return false;
                }
                else
                {
                if(em.value.trim().length!=5)
                {
                    setErrorColor(em);
                    setError(obj1,"Invalid Zip Code");
                    return false;
                }
                 else
                {
               for (i = 0; i < em.value.length && blnResult == true; i++)
                { 
                 strChar = em.value.charAt(i);
                  if (strValidChars.indexOf(strChar) == -1)
                    {
                       
                       blnResult = false; 
                     }
                }
               if(blnResult==false)
                {
                 setErrorColor(em);
                 setError(obj1,"Invalid Zip Code");
                 return false;
                }
                else
                {
                    setSuccessColor(em);
                    setSuccess(obj1); 
                    return true;
                  }
                  }
                }
               
  }

/********************************************************************
Function  Check for  integer value  
          Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
*********************************************************************/
function OnlyInteger(em,id,msz)
{
    var obj1 = document.getElementById(id);
     var strValidChars = "0123456789"; 
               var strChar;
               var blnResult = true;
                if(em.value.trim().length==0)
                {
                    setErrorColor(em);
                    setError(obj1,"Required");
                    return false;
                }
                else
                {
               for (i = 0; i < em.value.length && blnResult == true; i++)
                { 
                 strChar = em.value.charAt(i);
                  if (strValidChars.indexOf(strChar) == -1)
                    {
                       
                       blnResult = false; 
                     }
                }
               if(blnResult==false)
                {
                 setErrorColor(em);
                 setError(obj1,msz);
                 return true;
                }
                else
                {
                    setSuccessColor(em);
                    setSuccess(obj1); 
                    return true;
                  }
                  }
  }
/******************************************************************   
 Function  Check for Numeric value
           Output: function give error message return false if input is not valid
                    else it return successful message
 Here em >>Any textbox object
      id >>Any span Id or label Id for Display Validation Message  
*******************************************************************/
function OnlyNumeric(em,id)
{
  
    var obj1 = document.getElementById(id);
     var strValidChars = "0123456789."; 
               var strChar;
               var blnResult = true;
             if(em.value.trim().length==0)
                {
                    setErrorColor(em);
                    setError(obj1,"Insert numeric value");
                    return false;
                }
                else
                {
                   for (i = 0; i < em.value.length && blnResult == true; i++)
                    { 
                     strChar = em.value.charAt(i);
                      if (strValidChars.indexOf(strChar) == -1)
                        {
                           blnResult = false; 
                         }
                    }
                   if(blnResult==false)
                    {
                     setErrorColor(em);
                     setError(obj1,"Value is not numeric");
                     return false;
                    }
                    else
                    {
                        setSuccessColor(em);
                        setSuccess(obj1); 
                        return true;
                    }
              }
  }
function OnlyNumericWithMessage(em,id,msg)
{
  
    var obj1 = document.getElementById(id);
     var strValidChars = "0123456789."; 
               var strChar;
               var blnResult = true;
             if(em.value.trim().length==0)
                {
                    setErrorColor(em);
                    setError(obj1,"");
                    return false;
                }
                else
                {
                   for (i = 0; i < em.value.length && blnResult == true; i++)
                    { 
                     strChar = em.value.charAt(i);
                      if (strValidChars.indexOf(strChar) == -1)
                        {
                           blnResult = false; 
                         }
                    }
                   if(blnResult==false)
                    {
                     setErrorColor(em);
                     setError(obj1,msg);
                     return false;
                    }
                    else
                    {
                        setSuccessColor(em);
                        setSuccess(obj1); 
                        return true;
                    }
              }
  }
/*******************************************************************    
  Function  Check for  Alphabets value
            Output: function give error message return false if input is not valid
                    else it return successful message
  Here em >>Any textbox object
       id >>Any span Id or label Id for Display Validation Message 
********************************************************************/  
function OnlyAlphabets(em,id)
{
   
    var obj1 = document.getElementById(id);
     var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "; 
               var strChar;
               var blnResult = true;
             if(em.value.trim().length==0)
                {
                    setErrorColor(em);
                    setError(obj1,"Insert alphabetic value");
                    return false;
                }
                else
                {
                   for (i = 0; i < em.value.length && blnResult == true; i++)
                    { 
                     strChar = em.value.charAt(i);
                      if (strValidChars.indexOf(strChar) == -1)
                        {
                           blnResult = false; 
                         }
                    }
                   if(blnResult==false)
                    {
                     setErrorColor(em);
                     setError(obj1,"Value is not alphabetic");
                     return true;
                    }
                    else
                    {
                        setSuccessColor(em);
                        setSuccess(obj1); 
                        return true;
                    }
              }
  }   
 
/*******************************************************************         
  Function  Check for  AlphaNumeric value
            This function accepts s as any control element object and verifies the
            Alphanumeric value 
            Output: function give error message return false if input is not valid
                    else it return successful message
  Here em >>Any textbox object
       id >>Any span Id or label Id for Display Validation Message
********************************************************************/    
function OnlyAlphaNumeric(em,id)
{
   
    var obj1 = document.getElementById(id);
     var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .";
               var strChar;
               var blnResult = true;
             if(em.value.trim().length==0)
                {
                    setErrorColor(em);
                    setError(obj1,"Insert alphanumeric value");
                    return false;
                }
                else
                {
                   for (i = 0; i < em.value.length && blnResult == true; i++)
                    { 
                     strChar = em.value.charAt(i);
                      if (strValidChars.indexOf(strChar) == -1)
                        {
                           blnResult = false; 
                         }
                    }
                   if(blnResult==false)
                    {
                     setErrorColor(em);
                     setError(obj1,"Value is not alphanumeric");
                     
                     return false;
                    }
                    else
                    {
                        setSuccessColor(em);
                        setSuccess(obj1); 
                        return true;
                    }
              }
  }     
  /****************************************************************
   Function  Check for  Phone number value of USA like <123 456 456456>
             This function accepts s as any control element object and verifies the
              phone number.
              Output: function give error message return false if input is not valid
                    else it return successful message 
   Here em >>Any textbox object
        id >>Any span Id or label Id for Display Validation Message  
  ******************************************************************/
  function checkphoneformat(s,id)
{
   
    var obj1 = document.getElementById(id);
    
     if(s.value.trim().length==0)
        {
            setErrorColor(s);
            setError(obj1,"Required");
            return false;
        }
       if(OnlyInteger(s,id,'Only 11 or 12 digits required')==false) 
       {
            return false;
       } 
	if(s.value.trim().length > 12 || s.value.trim().length < 11)
	{
		 setErrorColor(s);
            setError(obj1,"Only 11 or 12 digits required");
		 return false;
	}
//	if ((s.value.charAt(4)!=" ")||(s.value.charAt(8)!=" "))
//	{
//	  setError(objTd,objSpan,"Use Format 01234 567 890");
//	  return false;
//	}
	
//	for(var i=0;i < s.value.length;i++)
//	{
//	    if(s.value.charAt(i)== "-")
//	    {
//	        setError(objTd,objSpan,"Use Format 01234 567 890");
//	        return false;
//	    }
//	}
//	if ( isNaN(s.value.charAt(0))==true || isNaN(s.value.charAt(1))==true || isNaN(s.value.charAt(2))==true || isNaN(s.value.charAt(3))==true || isNaN(s.value.charAt(5))==true || isNaN(s.value.charAt(6))==true || isNaN(s.value.charAt(7))==true || isNaN(s.value.charAt(9))==true || isNaN(s.value.charAt(10))==true || isNaN(s.value.charAt(11))==true )
//	{
//		 setError(objTd,objSpan,"Use Format 01234 567 890");
//	     return false;
//	}
       
	   setSuccessColor(s);
	   setSuccess(obj1); 
       return true;
}

/****************************************************************
   Function  Check the File Extensions
              This function accepts s as any control element object and verifies the
              extension of file.
               Output: function give error message return false if input is not valid
                    else it return successful message
   Here s >>Any textbox object
        id >>Any span Id or label Id for Display Validation Message  
******************************************************************/

	function ValidExtension(s,id) 
	{
	    var obj1 = document.getElementById(id);
	    var item =s.value
	    if(item.trim().length==0)
        {
            setErrorColor(s);
            setError(obj1,"Insert  value");
            return false;
        }
		else if (item.indexOf ('.jpg', 0)>0 || item.indexOf ('.JPG', 0)>0)
		{
		   setSuccessColor(s);
		   setSuccess(obj1); 
		   return true;
		}
		else if (item.indexOf ('.jpeg', 0) >0 || item.indexOf ('.JPEG', 0) >0)
		{
		   setSuccessColor(s);
		   setSuccess(obj1); 
           return true;
      
		}
		else if (item.indexOf ('.png', 0) >0 || item.indexOf ('.PNG', 0) >0)
		{
		   setSuccessColor(s);
		   setSuccess(obj1); 
           return true;
       
		}
		
		else if (item.indexOf ('.gif', 0) >0 || item.indexOf ('.GIF', 0) >0)
		{
		   setSuccessColor(s);
		   setSuccess(obj1); 
           return true;
		}

		else
		{
		setErrorColor(s);
		setError(obj1,"Invalid file extension");
		return false;
		}
	}
/****************************************************************
   Function  Check the  date format <dd/mm/yyyy> 
             This function accepts a string variable and verifies if it is a
             proper date or not. It validates format matching either
             mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
             has the proper number of days, based on which month it is.
            Output: function give error message return false if input is not valid
                    else it return successful message     
   Here s >>Any textbox object
        id >>Any span Id or label Id for Display Validation Message  
******************************************************************/
    function isDate(s,id) 
	{
	   
	    dateStr=s.value.trim()
	    if(s.value.trim().length >0)
	    {
	        var obj1 = document.getElementById(id);
	        var datePat = /^(\d{1,2})(\/|)(\d{1,2})(\/|)(\d{4})$/;
	        var matchArray = dateStr.match(datePat); // is the format ok?
		    months= new Array(12);
		    months[0]="Jan";
		    months[1]="Feb";
		    months[2]="Mar";
		    months[3]="Apr";
		    months[4]="May";
		    months[5]="Jun";
		    months[6]="Jul";
		    months[7]="Aug";
		    months[8]="Sep";
		    months[9]="Oct";
		    months[10]="Nov";
		    months[11]="Dec";	
		     if(dateStr.length==0)
            {
                setErrorColor(s);
                setError(obj1,"Insert date");
                return false;
            }
	        if (matchArray == null) 
	        {
		        setErrorColor(s);
		        setError(obj1,"Please enter date as either mm/dd/yyyy");
                return false;
	        }
		    day = matchArray[3];
	        month = matchArray[1];
	        year = matchArray[5];
	        if (day < 1 || day > 31) 
	        {
	            setErrorColor(s);
		        setError(obj1,"Day must be between 1 and 31.");
		        return false;
	        }
		    if (month < 1 || month > 12) // check month range
	        { 
		        setErrorColor(s);
		        setError(obj1,"Month must be between 1 and 12.");
                return false;

	        }
	        if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	        {
	            setErrorColor(s);
	            setError(obj1,"Month "+ months[month-1]+" doesn't have 31 days!");
                return false;
	        }
		    if (year < 1900) 
	        {
	            setErrorColor(s);
	            setError(obj1,"Year must be after 1900");
                return false;

	        }
	        if (month == 2)  // check for february 29th
	        {
	    	    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		        if (day > 29 || (day==29 && !isleap)) 
		        {
		            setErrorColor(s);
		            setError(obj1,"February " + year + " doesn't have " + day + " days!");
                    return false;
        		    
		        }
		     }
		    setSuccessColor(s);
	        setSuccess(obj1); 
	        return true; // date is valid
	    }
	    else
	    {
	            
	        	setErrorColor(s);
	        	
	            setError(obj1,strMsz);
                return false;
	    }
	}
	
/****************************************************************
   Function  verify the IPAddress
              This function accepts s as any control element object and verifies the
               IPAddress.
               Output: function give error message return false if input is not valid
                    else it return successful message
   Here s >>Any textbox object
        id >>Any span Id or label Id for Display Validation Message  
******************************************************************/

	
	function verifyIP(s,id) 
    {
  	    var errorString = "";
	    var theName = "IPaddress";
	    var IPvalue= s.value
        var obj1 = document.getElementById(id);
	    var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	    var ipArray = IPvalue.match(ipPattern); 
         if(IPvalue.trim().length==0)
        {
            setErrorColor(s);
            setError(obj1,"Insert IP address");
            return false;
        }
	    if (IPvalue == "0.0.0.0")
	    errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	    else if (IPvalue == "255.255.255.255")
	    errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	    if (ipArray == null)
	    errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
	    else {
	            for (i = 0; i < 4; i++) {
	            thisSegment = ipArray[i];
	            if (thisSegment > 255) {
	                errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
	                i = 4;
	                }
	                if ((i == 0) && (thisSegment > 255)) {
	                errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
	                i = 4;
		                  }
	             }
	         }
	    extensionLength = 3;
	    if (errorString == "")
	    {
		     setSuccessColor(s);
		     setSuccess(obj1); 
	         return true; 
	    }
	    else
	    {
	          setErrorColor(s);
	          setError(obj1,errorString);
	          return false;
        }
    }	
	
	
	
	
/****************************************************************
   Function  for returning object of any element
   Here n >>Any textbox Id
         
******************************************************************/
function de(n)
{
    return document.getElementById(n);
}

/****************************************************************
   Function  for confirmation about deletion of any item
             OUTPUT: return true if confirmed else false
   
         
******************************************************************/
function ConfirmDelete()
{
    if(confirm("Are You Sure To Delete the Record?"))
        return true;
    else
        return false;
}







//************************************************************************************
//*************************Inner function********************************************
// function for trim
String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");
//function for replacing string
String.prototype.replaceStr=function(find,replace)
{return this.split(find).join(replace);};
//function for check name
function checkName(name){return true;}
//function for validation successful message
function setSuccess(o,m)
{
    if(o.className.indexOf('success_') <0 )
    {
        if(o.className.indexOf('error_') >=0 )
        {
            o.className =  o.className.replace('error_' ,'success_');
        }
        else
        {
            o.className = 'success_' + o.className;
        }    
    }
}

 function addEventListener( element, event_name, observer, capturing ) 
 {  
 if ( element.addEventListener ) // the DOM2, W3C way  
 element.addEventListener( event_name, observer, capturing ); 
 else if ( element.attachEvent ) // the IE way  
 element.attachEvent( "on" + event_name, observer ); 
 }  

 function ShowErrorMessageInBallon( evt ) 
 {  
 //alert(evt); 
 }  
 function listener2( evt ) 
 {  
 alert( "Hello from listener2" ); 
 }
 
//function for validation Error Message
function setError(o,m)
{
    if(o.className.indexOf('error_') <0 )
    {
        if(o.className.indexOf('success_') >=0 )
        {
            o.className =  o.className.replace('success_' ,'error_');
        }
        else
        {
            o.className = 'error_' + o.className;
        }    
    }
    
    //For DropDown
    if(o.id.indexOf('DropDown') >= 0 )
    {
        o.className = 'error_DropDown';
    }
    
//addEventListener( o, "mouseover", ShowErrorMessageInBallon, false ); 
}
// function foe set background color for Error Message
function setSuccessColor(inpElem)
{
 //inpElem.className="inboxSuccess";
}	     
// function foe set background color for success Message
function setErrorColor(inpElem)
{
 //inpElem.className="inboxError";
}	     
//Inner function for Email check
function checkMail(email)
{
    var filter=/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(filter.test(email))
    {return true;}
    else{return false;}
}
//************************************************************************************
/********************************************************************
Function  Validate Fax Code 
          Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
*********************************************************************/
function checkFaxformat(s,id)
{
   
    var obj1 = document.getElementById(id);
        
	if(s.value.trim().length != 12)
	{
		 setErrorColor(s);
		 setError(obj1,"Use Format 123-456-7890");
		 return false;
	}
	if ((s.value.charAt(3)!="-")||(s.value.charAt(7)!="-"))
	{
	  setErrorColor(s);
	 setError(obj1,"Use Format 123-456-7890");
	  return false;
	}
	
	for(var i=0;i < s.value.length;i++)
	{
	    if(s.value.charAt(i)== " ")
	    {
	        setErrorColor(s);
	        setError(obj1,"Use Format 123-456-7890");
	        return false;
	    }
	}
	if ( isNaN(s.value.charAt(0))==true || isNaN(s.value.charAt(1))==true || isNaN(s.value.charAt(2))==true || isNaN(s.value.charAt(4))==true || isNaN(s.value.charAt(5))==true || isNaN(s.value.charAt(6))==true || isNaN(s.value.charAt(8))==true || isNaN(s.value.charAt(9))==true || isNaN(s.value.charAt(10))==true || isNaN(s.value.charAt(11))==true )
	{
		 setErrorColor(s);
	     setError(obj1,"Use Format 123-456-7890");
	     return false;
	}
	   setSuccessColor(s);
	   setSuccess(obj1); 
       return true;
}

function AvailabilityName(em,id,msz,flag)
{

    var obj2 = document.getElementById(id);

      if( em.value.trim().length==0 )
        {
            setErrorColor(em);
            setError(obj2,"Required");
            return false;
        }
        else
        {
            if(flag == 0)
            {
                setErrorColor(em);
                setError(obj2,msz);
                return false;
                
            }
            else
            {
                setSuccessColor(em);
                setSuccess(obj2);
                return true; 
            }
            
        }

  }
    /*******************************************************************
Function to Check Availablity of Company Name in Database
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function AvailabilityCompanyName(em,id,msz,flag,path)
{
    
    var obj2 = document.getElementById(id);
    if(path==0)
    {
      if( em.value.trim().length==0 )
        {
            setErrorColor(em);
            setError(obj2,"Please fill Company Name");
            return false;
        }
        else
        {
            if(flag > 0)
            {
                setErrorColor(em);
                setError(obj2,msz);
                return false;
            }
            else
            {
                setSuccessColor(em);
                setSuccess(obj2);
                return true;    
            }
            
        }
    }
    else
    {
        
        if( em.value.trim().length==0 )
        {
            return true;
        
        }
        else 
        {
            if(flag > 0)
            {
                setErrorColor(em);
                setError(obj2,msz);
                return false;
            }
            else
            {
            setSuccessColor(em);
            setSuccess(obj2);
            return true;    
            }
        }
    }
  }
  
  /*******************************************************************
Function to Check for User Name Empty value 
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function IsUserNameEmpty(em,id,msz)
{

  var obj2 = document.getElementById(id);
  if( em.value.trim().length==0 )
    {
        setErrorColor(em);
        setError(obj2,msz);
        return false;
    }
    else
    {
        var blnResult =false;
        var strValidChars='{}[]`,.<>~!@#$%^&*()-+=:;"?/\|'
        var Space=" ";
        for (i = 0; i < em.value.length && blnResult == false; i++)
        {   
            strChar = em.value.charAt(i);
            if (strValidChars.indexOf(strChar) >=0)
            {
                 blnResult = true;
            }
           
            if(Space.indexOf(strChar) >=0)
            {
                setErrorColor(em);
                msz='User Name cannot contain SPACE';
                setError(obj2,msz);
                return false;     
            }
        }
        if(blnResult == true)
        {
            setErrorColor(em);
            msz='Field cannot contain special characters';
            setError(obj2,msz);
            return false;
        }
        else
        {
            setSuccessColor(em);
            setSuccess(obj2);
            return true;
        }
    }
  }
  
  /*******************************************************************
Function to Check for Address Empty value 
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/  
function IsAddressEmpty(em,id,msz)
{

  var obj2 = document.getElementById(id);
  if( em.value.trim().length==0 )
    {
        setErrorColor(em);
        setError(obj2,msz);
        return false;
    }
    else
    {
//        var blnResult =false;
//        var StrInValidChars='{}[]`<>~!@$%^&*()+=:;"?|'
//        var Space=" ";
//        for (i = 0; i < em.value.length && blnResult == false; i++)
//        {   
//            strChar = em.value.charAt(i);
//            if (StrInValidChars.indexOf(strChar) >=0)
//            {
//                 blnResult = true;
//            }
//           
//        }
//        if(blnResult == true)
//        {
//            setErrorColor(em);
//            msz='Field cannot contain special characters';
//            setError(obj2,msz);
//            return false;        
//        }
//        else
//        {
            setSuccessColor(em);
            setSuccess(obj2);
            return true;
        //}
    }
  }

/*******************************************************************
Function to Check for Address Empty value 
           Output: function give error message return false if input is not valid
                    else it return successful message
Here em >>Any textbox object
     id >>Any span Id or label Id for Display Validation Message  
********************************************************************/  
function IsAddress2Empty(em,id,msz)
{

  var obj2 = document.getElementById(id);
  
  if( em.value.trim().length > 0 )
    {
//        var blnResult =false;
//        var StrInValidChars='{}[]`<>~!@$%^&*()+=:;"?|'
//        var Space=" ";
//        for (i = 0; i < em.value.length && blnResult == false; i++)
//        {   
//            strChar = em.value.charAt(i);
//            if (StrInValidChars.indexOf(strChar) >=0)
//            {
//                 blnResult = true;
//            }
//           
//        }
//        if(blnResult == true)
//        {
//            
//            setErrorColor(em);
//            msz='Field cannot contain special characters';
//            setError(obj2,msz);
//            obj2.style.visibility="visible";
//            return false;        
//        }
//        else
//        {
            setSuccessColor(em);
            setSuccess(obj2);
            obj2.style.visibility="visible";
            return true;
       // }
    }
    else
    {
            obj2.style.visibility="hidden";
            return true;    
    }
  }

//************************************************************************************
//Uk Post Code Format
function checkUKPostCode (toCheck,span) {
    
    var obj = document.getElementById(span);
    
    if( toCheck.value.trim().length==0 )
    {
        setErrorColor(toCheck);
        setError(obj,'Required');
        return false;
    }
    else
    {
              // Permitted letters depend upon their position in the postcode.
      var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
      var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
      var alpha3 = "[abcdefghjkstuw]";                                // Character 3
      var alpha4 = "[abehmnprvwxy]";                                  // Character 4
      var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
      
      // Array holds the regular expressions for the valid postcodes
      var pcexp = new Array ();

      // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
      pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
      
      // Expression for postcodes: ANA NAA
      pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

      // Expression for postcodes: AANA  NAA
      pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
      
      // Exception for the special postcode GIR 0AA
      pcexp.push (/^(GIR)(\s*)(0AA)$/i);
      
      // Standard BFPO numbers
      pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
      
      // c/o BFPO numbers
      pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
      
      // Overseas Territories
      pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

      // Load up the string to check
      var postCode = toCheck.value;

      // Assume we're not going to find a valid postcode
      var valid = false;
      
      // Check the string against the types of post codes
      for ( var i=0; i<pcexp.length; i++) {
        if (pcexp[i].test(postCode)) {
        
          // The post code is valid - split the post code into component parts
          pcexp[i].exec(postCode);
          
          // Copy it back into the original string, converting it to uppercase and
          // inserting a space between the inward and outward codes
          postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
          
          // If it is a BFPO c/o type postcode, tidy up the "c/o" part
          postCode = postCode.replace (/C\/O\s*/,"c/o ");
          
          // Load new postcode back into the form element
          valid = true;
          
          // Remember that we have found that the code is valid and break from loop
          break;
        }
      }
      
      // Return with either the reformatted valid postcode or the original invalid 
      // postcode
      if (valid) 
      {
        return true;
      } 
      else
      {
        alert('Invalid PostCode');
       return false;
      }
   }   
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  
}


