function numbersonly(e,a)
{	
	var unicode=e.charCode? e.charCode : e.keyCode	
	if (unicode!=8 && unicode!=46 && unicode!=9 && unicode!=13)
	{ 
		if (unicode<48||unicode>57) //if not a number
		{
			alert("Please enter numeric value only.");
			return false ;//disable key press
		}
		
	}
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}
/********************Blank space Validation*******************/
function dotandspace(txtboxvalue)
{
 var flag=0;
 var strText = txtboxvalue;
 if (strText!="")
 {
 var strArr = new Array();
 strArr = strText.split(" ");
 for(var i = 0; i < strArr.length ; i++)
 {
 if(strArr[i] == "")
 {
  flag=1;              
  break;
 }
 } 
 if (flag==1)
 {
 //alert("No space is allowed");
 return false;
  }
 }        
}

/**********Search Box**************/
function srch()
{
	if(document.searchfrm.searchtxt.value=='')
	{
		document.searchfrm.searchtxt.focus();
		return false;
	}
	if(dotandspace(document.searchfrm.searchtxt.value)==false)
	{
		document.searchfrm.searchtxt.focus();
		return false;
	}

}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
function isAllCharacters(objValue)
{
		var characters="' -abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}

/*************************************************************************************************************
*
* isValidEmail it checks the Email-Id is Valid or Not 
*
**************************************************************************************************************/
	function isValidEmail(emailStr)
{
		if(emailStr=="")
		{
				alert("Please enter email address.");
				 return false;
				
		}
			/* The following pattern is used to check if the entered e-mail address
			   fits the user@domain format.  It also is used to separate the username
			   from the domain. */
			var emailPat=/^(.+)@(.+)$/
			/* The following string represents the pattern for matching all special
			   characters.  We don't want to allow special characters in the address. 
			   These characters include ( ) < > @ , ; : \ " . [ ]    */
			//var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			var specialChars="\\(\\)<>@,`';:~!#$%^&*+=|{}?\\\\\\\"\\.\\[\\]"
			
			/* The following string represents the range of characters allowed in a 
			   username or domainname.  It really states which chars aren't allowed. */
			var validChars="\[^\\s" + specialChars + "\]"
			/* The following pattern applies if the "user" is a quoted string (in
			   which case, there are no rules about which characters are allowed
			   and which aren't; anything goes).  E.g. "sg cricket"@disney.com
			   is a legal e-mail address. */
			var quotedUser="(\"[^\"]*\")"
			/* The following pattern applies for domains that are IP addresses,
			   rather than symbolic names.  E.g. sg@[123.124.233.4] is a legal
			   e-mail address. NOTE: The square brackets are required. */
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			/* The following string represents an atom (basically a series of
			   non-special characters.) */
			var atom=validChars + '+'
			/* The following string represents one word in the typical username.
			   For example, in sg.sg@somewhere.com, sg and sg are words.
			   Basically, a word is either an atom or quoted string. */
			var word="(" + atom + "|" + quotedUser + ")"
			// The following pattern describes the structure of the user
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			/* The following pattern describes the structure of a normal symbolic
			   domain, as opposed to ipDomainPat, shown above. */
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


			/* Finally, let's start trying to figure out if the supplied address is
			   valid. */

			/* Begin with the coarse pattern to simply break up user@domain into
			   different pieces that are easy to analyze. */
			var matchArray=emailStr.match(emailPat)
			if (matchArray==null) {
			  /* Too many/few @'s or something; basically, this address doesn't
			     even fit the general mould of a valid e-mail address. */
				alert("Opps.. it looks like you didn't enter a valid email address. Please correct your email and try again.")
				return false
			}
			var user=matchArray[1]
			var domain=matchArray[2]

			// See if "user" is valid 
			if (user.match(userPat)==null) {
			    // user is not valid
			    alert("Opps.. it looks like you didn't enter a valid email address. Please correct your email and try again.")
			    return false
			}

			/* if the e-mail address is at an IP address (as opposed to a symbolic
			   host name) make sure the IP address is valid. */
			var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null) {
			    // this is an IP address
				  for (var i=1;i<=4;i++) {
				    if (IPArray[i]>255) {
				        alert("Opps.. it looks like you didn't enter a valid email address. Please correct your email and try again.")
					return false
				    }
			    }
			    return true
			}

			// Domain is symbolic name
			var domainArray=domain.match(domainPat)
			if (domainArray==null) {
			alert("Opps.. it looks like you didn't enter a valid email address. Please correct your email and try again.")
			    return false
			}

			
			var atomPat=new RegExp(atom,"g")
			var domArr=domain.match(atomPat)
			var len=domArr.length
			if (domArr[domArr.length-1].length<2 || 
			    domArr[domArr.length-1].length>5) {
			   // the address must end in a two letter or three letter word.
			   alert("Opps.. it looks like you didn't enter a valid email address. Please correct your email and try again.")
			   return false
			}

			// Make sure there's a host name preceding the domain.
			if (len<2) {
			   var errStr="Opps.. it looks like you didn't enter a valid email address. Please correct your email and try again."
			  // alert(errStr)
			   return false
			}

			// If we've gotten this far, everything's valid!
			return true;
}
/************************************************Valid Url******************************************************************************/


function validUrl(url)                                 // Link Tracker : To check whether URL is Valid OR Not
{
  var i;
  var result=1;
  var urlPart;
  var urlCheck=url;
 
  if(urlCheck.length<5)
	 result=2;

  urlPart=urlCheck.split(":");

  if(urlPart[0]=="http" || urlPart[0]=="https")
	{
	 
	  urlPart=urlPart[1].split(".");
	 if((urlPart[urlPart.length-1].length < 2) || urlPart.length < 2)//|| (urlPart[urlPart.length-2].length < 2)
		  result=2;
      else
		  result=1;
	}
  else
	{
	  result=2;
	}

	if(result==2)
		return false;
	else 
	 {
		return true;
 	 }
 }
/***************************************date function************************************************************/
function isValidDate(checkDate)              // Check for valid date

{

  var datePart,datePart1,result,flag;

  now = new Date();

  

  var year =  now.getYear();

  var month = now.getMonth();

    if(month<10) month="0"+month;

  var nowdate = now.getDate();

    if(nowdate<10) nowdate="0"+nowdate;

  

  var todaysdate = year+"-"+month+"-"+nowdate;

  



  if(checkDate!="") // Process : Check Date Field Is Not Blank

  {

    datePart1=checkDate.split(' ');

      

    if(datePart1[0].indexOf("-")>0)    // Process : To Check Date Is Separated by . or / or - characters only

      var sp_char="-";

    else if (datePart1[0].indexOf("/")>0)

      var sp_char="/";

    else if (datePart1[0].indexOf(".")>0)

      var sp_char=".";

    else

    {

      alert("Please Enter Date in Specified format");

      return false;

    }

    

    datePart=datePart1[0].split(sp_char);

    

    var userdate = datePart[0]+"-"+datePart[1]+"-"+datePart[2];

    

    if(todaysdate>=userdate)

    {

      alert("Please enter Future date only");

      return false;

    }

    else

    {

      if(datePart.length==3)

      {



        if(datePart[1].length==1)

        {

          alert("Please enter month in 'mm' format. e.g. 02 or 07");

          return false;

        }

    

        if(datePart[2].length==1)

        {

          alert("Please enter date in 'dd' format. e.g. 02 or 07");

          return false;

        }

      }

      else

      {

        alert("Please Enter Date in Specified format");

        return false;

      }



      if(datePart[1]=="08")

        datePart[1]="8";

    

      if(datePart[1]=="09") 

        datePart[1]="9";

    

    

      if(datePart[2]=="08")

        datePart[2]="8";

      

      if(datePart[2]=="09") 

        datePart[2]="9";

    

    

      if((Number(datePart[0])) && (Number(datePart[1])) && (Number(datePart[2]))) //Process : Whether Date Entered Has Numeric Entries 

      {

        if( (parseInt(datePart[0])<2101) && (parseInt(datePart[0])>year-1) && (parseInt(datePart[1])<13) && (parseInt(datePart[1])>0) && (parseInt(datePart[2])<32) && (parseInt(datePart[2])>0) ) //Process : Range Of Date Values

        {

          if(parseInt(datePart[1])==2) // Process : Check For February Month

          {

            if(parseInt(datePart[2]) > 28)

            {

              if((parseInt(datePart[0]) % 4 !=0)) //Leap Year Checking 

              {

                alert("Year "+parseInt(datePart[0]) +" : February 28 Days Only!");

                return false;

              }

              else if(parseInt(datePart[2]) == 29)

              {

                var subdatePart=datePart[0];

                subdatePart = subdatePart.substring(2);

                if(subdatePart=="00")        //check for centuary years not divisible by 400

                {

                  if((parseInt(datePart[0]) % 400 !=0))

                  {

                    alert("No Leap Year "+parseInt(datePart[0]) +" : February 28 Days Only!");

                    return false;

                  }

                  else

                    return true;

                }

                else

                  return true;

                alert("Leap Year "+parseInt(datePart[0]) +" : February 29 Days Only!");

                return false;

              }

              else if(parseInt(datePart[2]) > 29)

              {

                alert("February Month Cannot Have more than 29 days !");

                return false;

              }

            }

            else

              return true;

          } //End Of February Check

          else if((parseInt(datePart[1])==4 || parseInt(datePart[1])==6 || parseInt(datePart[1])==9 || parseInt(datePart[1])==11 ) && datePart[2] > 30)// || parseInt(datePart[1])==6 || parseInt(datePart[1])==9 || parseInt(datePart[1])==11)) //Check For Apr,Jun,Sep,Nov.

          {

            alert("This Month Has 30 Days"); 

            return false;

          }

          else

            return true;

        }

        else

        {

          alert('Invalid Year OR Month OR Day value !');

          return false;

        }

      }

      else   //Execute : When Date Field Is With Irrelavent Data [Like Char,special Char etc other than numbers ]

      {

        alert('Please Enter date in specified format');

        return false;

      }

      return true;

    } 

  }

  else   // Execute : When Date Field Is Blank

  {

    alert('Date field cannot be left blank');

    return false;

  }
}




function is_valid_image(file_name)
{
  if(file_name !="")
    {
     //var file_name=val.file.value ;
          //var ext=substr(ext_val,".");
          var file_length=file_name.split(".");
          var count_str=file_length.length;
          var ext_name=count_str-1;
          var ext =file_length[ext_name];
          var ext_all=new Array(10);     
            ext_all[1]="jpg";ext_all[2]="gif";ext_all[3]="png";
            ext_all[4]="jpeg";ext_all[5]="JPEG";ext_all[6]="JPG"; ext_all[7]="GIF";ext_all[8]="bmp";ext_all[9]="BMP";ext_all[10]="PNG";
             
     if(ext !=ext_all[1]&&ext !=ext_all[2]&&ext !=ext_all[3]&&ext !=ext_all[4]&&ext !=ext_all[5]&&ext !=ext_all[6]&&ext !=ext_all[7]&&ext !=ext_all[8]&&ext !=ext_all[9]&& ext!=ext_all[10])
        return false;
     else
         return true;
   }
 else
   return false;
}

