	var whitespace = " \t\n\r";

	// this function will return the browser info as a int
	// the int format will be OS|BrowserName|BrowserVersion
	// OS	
    //		windows		= 1
	// BrowserName 
	//		MSIE		= 1
	//      Netscape	= 2
	// BrowserVersion	
	//		3.x			= 3
	//		4.x			= 4	 	 
	//		5.x			= 5
	// 
	// so for windows IE 3.02 the return value will be 003
	//    for windows Netscae4.07                      014	
	function GetBrowserInfo()
	{
		var szBrowserInfo = "";
		var szVersion = "";
		szPlatform = navigator.appVersion;
		if( szPlatform.indexOf( "Win" ) != -1 )
			szBrowserInfo += "1" ;

		szBrowsername = navigator.appName;
		if( szBrowsername.indexOf( "Microsoft" ) != -1 )
		{
			szBrowserInfo += "1" ;
			szVersion += "MSIE ";
		}
		else if( szBrowsername.indexOf( "Netscape" ) != -1 )
			szBrowserInfo += "2" ;

		if( navigator.appVersion.indexOf( szVersion + "3.")!=-1 ) 
			szBrowserInfo += "3" ;
		else if( navigator.appVersion.indexOf( szVersion + "4." )!=-1 ) 
			szBrowserInfo += "4" ;
		else if( navigator.appVersion.indexOf( szVersion + "5.")!=-1 ) 
			szBrowserInfo += "5" ;
		else if( navigator.appVersion.indexOf( szVersion + "6.")!=-1 ) 
			szBrowserInfo += "6" ;
		return parseInt( szBrowserInfo, 10 );
	}
	function isEmpty(s)
	{ 
	 return ((s == null) || (s.length == 0))
	}
	function isWhitespace (s)
	{  var i;
	  // Is s empty?
	  if (isEmpty(s)) return true;

	   // Search through string's characters one by one
	   // until we find a non-whitespace character.
	   // When we do, return false; if we don't, return true.
	   for (i = 0; i < s.length; i++)
	   {   
 		   // Check that current character isn't whitespace.
 		   var c = s.charAt(i);

 		   if (whitespace.indexOf(c) == -1) return false;
	   }

	   // All characters are whitespace.
		return true;
	}
	//HasWhiteSpace() function checks if there are any spaces in the given string
	function HasWhiteSpace(s)
	{  
		// Is s empty?
		if (isEmpty(s)) 
			return true;

		if( s.indexOf( " " ) != -1) 
			return true ;
		else
			return false ;
	}

	function isEmail (s)
	{
	   // is s whitespace?
	   if (isWhitespace(s)) return false;

	   // there must be >= 1 character before @, so we
	   // start looking at character position 1
	   // (i.e. second character)
	   var i = 1;
	   var sLength = s.length;

	   // look for @
	   while ((i < sLength) && (s.charAt(i) != "@"))
	   { i++
	   }

	   if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	   else i += 2;

	   // look for .
	   while ((i < sLength) && (s.charAt(i) != "."))
	   { i++
	   }

	   // there must be at least one character after the .
	   if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	   else return true;
	}
	
	function isEmailEx(s)
	{
	   if (HasWhitespace(s)) 
			return false;

		if( !isCharsInBag( s , "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%^&-_.@[]+=" ) ) //[] chars r there in mailIDs having IP addrs.
			return false ;

		var idxAT = s.indexOf( "@" ) ;

		//The character '@' can not be more than one and 
		//it should not be the 1st character in an Email ID
		if( idxAT <= 0 || idxAT != s.lastIndexOf( "@" ) )
		{
			return false ;	
		}

		//After character '@' there should be atleast one character
		//betn '@' and'.' 
		var idxDOT = s.indexOf( ".", idxAT+2 ) ;

		//After '.' there should be atleast one character.
		if( idxDOT == -1 || idxDOT == s.length-1 )
		{
			return false ;
		}

		return true ;
	}

	function HasWhitespace (s)
	{  var i;
	  // Is s empty?
	  if (isEmpty(s)) 
			return true;
	   // Search through string's characters one by one
	   // until we find a non-whitespace character.
	   // When we do, return false; if we don't, return true.
	   for (i = 0; i < s.length; i++)
	   {   
 		   // Check that current character isn't whitespace.
 		   var c = s.charAt(i);

 		   if (whitespace.indexOf(c) != -1) 
				return true;
	   }
	   // no whitespaces
		return false;
	}

	/*
the following function "GetEmailIDFromStringEx(s)" 
can extract email id in these cases:-
 . user@mithi.com
 . name surname <user@mithi.com>
 . name surname<user@mithi.com>
 . "name surname" <user@mithi.com>
 . <user@mithi.com>
 . user.name@mithi.com
-returns null if
 . <user@mithi.com 
 . user@mithi.com>
 . <>
 .<<user@mithi.com>
 .pankaj c<pankaj@mailjol.com> <pankaj@mailjol.com>
 .'pankaj' <<pankaj@mailjol.com> 
 .<pankaj@mailjol.com>'pankaj' 
 .'pankaj' <#$@4pankaj@mailjol.com> 
 .<pan@kaj@mailjol.com> 
*/
	function GetEmailIDFromStringEx( s )
	{
		if( s != null )
			s = TrimTrailing( s ) ;
		if( s != null )
			s = TrimLeading( s ) ;
		
		if( s == null )
			return null ;

		var idx1 = s.indexOf( "<" ) ;
		var idx2 = s.indexOf( ">", idx1+1 ) ;
		
		//indexOf() returns -1, if the search string is not found.
		//there should not be any characters after the valid email id.
		if( idx1 != -1 && idx2 != -1 && idx2 == s.length-1 )
		{
			if( idx1 == s.lastIndexOf( "<" ) && idx2 == s.lastIndexOf( ">" ) )
				s = s.substring( idx1+1, idx2 ) ;
			else
				return null ;
		}
		else if( idx1 == -1 && idx2 == -1 )
		{
			return s ;
		}
		else
			s = null ;
		return s ;
	}

	function TrimTrailing( s )
	{
		var i = 0, nLen = 0;
		var temp = "";

		if( s != null )
		{		
			nLen = s.length;
			if( nLen == 0 )
				return "";

			for( i = nLen - 1 ; i >= 0 && isWhitespace(s.charAt(i)); i-- );
			
			if( i < 0 ) // the whole string is white space
				return "";
			else
			{
				temp = s.substring( 0, i + 1 );
				return temp;
			}
		}
		else
			return null ;
	}
	function isCharsInBag(s, String)
	{  
		var i;
		// Search through string's characters one by one.
		// If character is in String, append to returnString.

		for (i = 0; i < s.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (String.indexOf(c) == -1) return false;
		}
		return true;
	}
	function isValidBirthYear(s)
	{
		var iBDYear = parseInt( s, 10 ) ;
		if( 2000 - iBDYear <= 140 &&  2000 - iBDYear >= 8 )
			return true

		return false;
	}	
	function BuildStr(s, s1)
	{
		if (s.length > 0) s = s + ", ";
		s = s + s1;
		return s;
	}
	function Help(daLink) 
	{
		var helpWnd=window.open(daLink,"help","width=400,height=500,scrollbars=yes,dependent=yes");
	}

	function isValidLength(s, minLength)
	{
		return( s.length >= minLength );
	}
	function TrimLeading( s )
	{
		var i = 0, nLen = 0;
		var temp = "";
		
		if( s != null )
		{
			nLen = s.length;
			if( nLen == 0 )
				return "";

			for( i = 0; i < nLen && isWhitespace(s.charAt(i)); i++ );

			if( i == nLen ) // the whole string is white space
				return "";
			else
			{
				temp = s.substring( i, nLen );
				return temp;
			}
		}
		else
			return null ;
	}

	function IsSupportedOSBrowser()
	{
		var iBrowserCode = GetBrowserInfo() ;


		if( !( iBrowserCode == 113 || iBrowserCode == 114 || iBrowserCode == 115 || iBrowserCode == 124 || iBrowserCode == 125 || iBrowserCode == 116 ) )
		{
			//alert( "Our email service for Indian languages is currently not supported on this browser. To access our service please use Internet Explorer 3/4/5 or Netscape Communicator 4.04 onwards, running on Windows (95/98/NT4/2000)." ) ;
			return false ;
		}
		return true ;
	}

	function convert( ExpertName ) 
	{
		// This method converts all spaces in the ExpertName to %20
		// this is needed as we need to pass this value in the href link
		var convertedName = "";
		var bFound = false;
		var nStartIndex = 0;
		var nEndIndex   = 0;
		
		while( nStartIndex < ExpertName.length ) {
			nEndIndex = ExpertName.indexOf( " ", nStartIndex );
			//alert( "nEndIndex = " + nEndIndex );

			if( nEndIndex == -1 ) {
				nEndIndex = ExpertName.length + 1;
				bFound    = false;	
			}
			else
				bFound = true;
			
			convertedName += ExpertName.slice( nStartIndex, nEndIndex );
			//alert( "convertedName = " + convertedName );

			if( bFound == true )
				convertedName += "%20";

			//alert( "after adding convertedName = " + convertedName );
			nStartIndex = nEndIndex + 1;
			//alert( "nStartIndex = " + nStartIndex );
			//alert( "Length = " + ExpertName.length );
		}

		//alert( "convertedName finally= " + convertedName );
		return convertedName;
	}

	function openwnd( szUrl )
	{
		if( szUrl.indexOf("?") == -1 ) szUrl = szUrl + "?jsr=" + Math.random() ;
		else szUrl = szUrl + "&jsr=" + Math.random() ;
		
		var wnd=window.open(szUrl,"wnd","resizable,scrollbars,height=400,width=400");
		wnd.focus();
	}
	function openRelPathWindow( szPath, szWnd, szParameters )
	{	
		// this function opens the relative path in another window
		if( szPath.indexOf("?") == -1 ) szPath = szPath + "?jsr=" + Math.random() ;
		else szPath = szPath + "&jsr=" + Math.random() ;
		
		var wnd=window.open( makeAbsPath( szPath ) , szWnd, szParameters ) ;
		wnd.focus();
		return wnd;
	}
	function makeAbsPath( svRelPath ) 
	{
		// this function opens the relative path in another window.
		// If there is no port specified in the location object, then it means 
		// the default 80. So in that case, the port number need not be specified.
		if(window.location.port=="")
			return window.location.protocol + "//" + window.location.hostname + svRelPath ;
		else
			return window.location.protocol + "//" + window.location.hostname + ":" + window.location.port + svRelPath ;
	}
	function getNormalisedString( szField )
	{
		var prevIndex = -1 ;
		var index ;
		var szDelimiters = ";," ;
		var regExp = /;{1,}/g ; // replace all semicolons
		szField = szField.replace( regExp,","); // by a comma
		
		regExp = /,{2,}/g ; // replace consecutive commas with
		szField = szField.replace( regExp,",");// single comma

		regExp = /^[;,]/; //remove semicolons and commas at the start of string
		szField = szField.replace( regExp,"");

		regExp = /[;,]$/;//remove semicolons and commas at the end of string
		szField = szField.replace( regExp,"");

		return szField;
	}
	function makeJSyncCmd( svJITSyncCmdLine, svSrcFolderRelPath, svParam )
	{
		return svJITSyncCmdLine+ " " + makeAbsPath( svSrcFolderRelPath ) + " " +svParam ;
	}

function GetMailIDInStandardFormat( s )
{
	if( s != null )
		s = TrimTrailing( s ) ;
	if( s != null )
		s = TrimLeading( s ) ;
	
	s = RemoveDupChars( s ) ;
	s = RepairEmailID( s ) ;
	s = MakeMailID( s ) ;
	s = RemoveDupChars( s ) ;

	// RemoveDupChars may remove the quotes at the start of the string 
	// so we add them again.
	//If in mailID the Name b4 the Id is null then ''<mailid@mithi.com>
	if( s != null && s.indexOf( "'<" ) == 0 )
	{
		regExp = new RegExp( "'<", "gi" ); 
		s = s.replace( regExp, "<" );
	}
	if( s != null && s.indexOf( "''<" ) == 0 )
	{
		regExp = new RegExp( "''<", "gi" ); 
		s = s.replace( regExp, "<" );
	}
	
	return s ;
}

function RemoveDupChars( s )
{
	if( s != null )
	{
		var regExp = /'{2,}/g ; // replace consecutive quots with  
		s = s.replace( regExp,"'");// single quot
			
		regExp = /<{2,}/g ;		// Delimiter '<'
		s = s.replace( regExp,"<");

		regExp = />{2,}/g ;		// Delimiter '>'
		s = s.replace( regExp,">");

		regExp = / {2,}/g ;		// Extra Spaces 
		s = s.replace( regExp," ");
	}
	return s ;
}

function RepairEmailID( s )
{
	if( s != null )
	{
		regExp = new RegExp( "@ ", "gi" ); // emailaddress@ server.com
		s = s.replace( regExp,"@");

		regExp = new RegExp( " @", "gi" ); // emailaddress @server.com 
		s = s.replace( regExp,"@");

		regExp = /[ ][\.]/;				// emailaddress@server .com 
		s = s.replace( regExp,".");

		regExp = /[\.][ ]/;				// emailaddress@server. com 
		s = s.replace( regExp,".");

		regExp = new RegExp( "< ", "gi" ); 	// "< "
		s = s.replace( regExp,"<");

		regExp = new RegExp( " >", "gi" ); 	// " >"
		s = s.replace( regExp,">");
	}
	return s ;
}

function MakeMailID( s )
{
	//REMOVE COMMENT 
	s = RemoveComments( s )  ; 

	if( s != null )
	{
		//END OF EMAILID
		s = s.concat( ">" ) ;

		//START OF EMAILID
		reg = new RegExp( "' ", "gi" ); //if quot and space, remove the space
		s = s.replace( reg, "'" ) ;
		
		var regExp = /^[']/ ;			//remove quots at the start of the string.
		s = s.replace( regExp,"");

		var idxDelim = 	s.lastIndexOf( "<", s.lastIndexOf( "@" ) ) ;
		if( idxDelim != -1 )
			s = s.substr( 0, idxDelim ).concat( "'<" , s.substr( idxDelim+1 ) ) ;

		var idxQuot  = 	s.lastIndexOf( "'", s.lastIndexOf( "@" ) ) ;
		if( idxQuot != -1  )
			s = s.substr( 0, idxQuot ).concat( "'<" , s.substr( idxQuot+1 ) ) ;

		idxSpace = 	s.lastIndexOf( " ", s.lastIndexOf( "@" ) ) ;
		if( idxSpace != -1  && idxSpace > idxQuot )
			s = s.substr( 0, idxSpace ).concat( "'<" , s.substr( idxSpace+1 ) ) ;

		//If no delimiters then add them at the start of the string.
		if( idxDelim == -1 && idxQuot == -1 && idxSpace == -1 )
		{
			var c = "'<" ;
			s = c.concat( s ) ;
		}

		//START OF THE STRING
		c = "'" ;	
		s = c.concat( s ) ;
	}	
	return s ;
}

function RemoveComments( s ) 
{
	if( s != null )
	{
		do
		{
			var idx1 = s.indexOf( "(" ) ;
			var idx2 = s.indexOf( ")", idx1 ) ;
			if( idx1 != -1 )
			{
				if( idx2 > idx1 )
					s = s.substring( 0, idx1 ).concat( " ", s.substring( idx2+1 ) ) ;
				else
					s = s.substring( 0, idx1 ) ; // if the end parantheisis is missing
			}
			// else if the start paranthesis is missing we skip the end paranthesis, that
			// is we assume that there are no comments. the mail error checking code will
			// fail.

		}while( s.indexOf( "(" ) != -1 ) ;
	}
	if( s != null )
		s = TrimTrailing( s ) ;
	if( s != null )
		s = TrimLeading( s ) ;

	return s ;
}

function Trim( s ) {
	if( s != null ) s = TrimTrailing( s ) ;
	if( s != null ) s = TrimLeading( s ) ;
	return s ;
}

function EncodeURL( s )
{
	if ( s != null)
	{
		// encode all spaces with %20's
		var regExp = /[ ]/g;
		s = s.replace( regExp, "%20" );
	}

	return s;
}

function showAboutUs() {
	var szHref =  "/aboutus.html" + "?Random=" + Math.random();
	window.open(szHref, "", "dependent=no, scrollbars=yes, resizable=no, width=640, height=480");
}

