// JavaScript Document

/*=====================================================================================
# BROWSER RELATED FUNCTIONS
=====================================================================================*/
/**
* getBrowserType() 			-- Detect Browser type (Netscape, MSIE, Opera, Safari, Firefox, AOL etc.)
*
* @param	isMinor Boolean -- For Minor or Major Verson Number
* 
* @return	string			-- Browser type with Version Number
*/
function getBrowserType(isMinor)
{
    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
	//alert(navigator.appVersion);
    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1); 

    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if (is_opera5up) is_js = 1.3;
    else if (is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
    else if (is_hotjava3up) is_js = 1.4;
    else if (is_nav6 || is_gecko) is_js = 1.5;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (is_nav6up) is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else is_js = 0.0;

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) || 
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
               (agt.indexOf("windows 16-bit")!=-1) );  

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 || 
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) || 
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||   
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || 
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || 
                                (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);    
    var is_aix2  = (agt.indexOf("aix 2") !=-1);    
    var is_aix3  = (agt.indexOf("aix 3") !=-1);    
    var is_aix4  = (agt.indexOf("aix 4") !=-1);    
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1); 
    var is_mpras    = (agt.indexOf("ncr")!=-1); 
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || 
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || 
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux || 
                 is_sco ||is_unixware || is_mpras || is_reliant || 
                 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

	var browserType; 

	var detected = true;
	
	/*** Browser Check ***/
	if(is_nav)					// if the product of Navigator...
	{
		if(is_gecko)			// if like gecko (mozilla, safari etc. follows gecko style)...
		{
			browserType = navigator.userAgent.search("afari") > 0 ? 'Safari ' : 'Mozilla Firefox ';
		}
		else
		{
			browserType = 'Netscape Navigator ';
		}
	}
	else if(is_ie)				// if the product of MSIE...
	{
		browserType = (is_ie) ? 'Internet Explorer' : '';
		browserType = (is_ie3) ? 'Internet Explorer 3' : '';
		browserType = (is_ie4) ? 'Internet Explorer 4' : '';
		browserType = (is_ie4up) ? 'Internet Explorer 4 Up' : '';
		browserType = (is_ie5up) ? 'Internet Explorer 5' : '';
		browserType = (is_ie6) ? 'Internet Explorer 6' : '';
		
		/*** special ie7 check ***/
		var ie7_check = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true : false;

		if (ie7_check == true) {
			browserType = 'Internet Explorer 7';
		}
		//browserType = (is_ie6up) ? 'Internet Explorer 6 Up' : '';
	}
	else if(is_opera)			// Opera Check...
	{
		browserType = 'Opera ';	
	}
	else if(is_hotjava)			// hotjava Check		
	{
		browserType = 'Hotjava ';	
	}
	else if(is_webtv)			// webtv Check		
	{
		browserType = 'Webtv ';	
	}
	else if(is_TVNavigator)		// TVNavigator Check		
	{
		browserType = 'TVNavigator ';	
	}		
	else if(is_AOLTV)			// AOL Check		
	{
		browserType = 'AOL ';	
	}
	else 						// No Detection!
	{
		browserType = 'Sorry Not Detected!';
		detected = false;	
	}
	
	/*** Version Check ***/
	if(!is_ie && detected)		// If browser type if detected and it's not IE series...
	{
		if(isMinor)
		{
			browserType = browserType + is_minor;
		}
		else
		{
			browserType = browserType + is_major;
		}
	}

	return browserType;
}

/*=====================================================================================
# EVENT RELATED FUNCTIONS
=====================================================================================*/

/*
Disable Right Click feature : To use uncomment the following code between "DISABLE RIGHT CLICK"
*/

//------------------------------------------------------------------------DISABLE RIGHT CLICK
/*
var message="Right Click Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")
*/
//------------------------------------------------------------------------DISABLE RIGHT CLICK

/*=====================================================================================
# STRING FUNCTIONS
=====================================================================================*/

/**
* LTrim() 					-- Removing Leading whitespaces
*
* @param	string string 	-- source string

* @return	string			-- String with leading whitespaces removed
*/
function LTrim( string ) {
	if(string==null || string.length==0)
	{
		return false;
	}
	else
	{
		var rex = /\s*((\S+\s*)*)/;
		return string.replace(rex, "$1");
	}
}

/**
* RTrim() 					-- Removing Trailing whitespaces
*
* @param	string string 	-- source string

* @return	string			-- String with ending whitespaces removed
*/
function RTrim( string ) {
	if(string==null || string.length==0)
	{
		return false;
	}
	else
	{
		var rex = /((\s*\S+)*)\s*/;
		return string.replace(rex, "$1");
	}
}

/**
* Trim() 					-- Removing Leading and Trailing whitespaces
*
* @param	string string 	-- source string

* @return	string			-- String with leading and ending whitespaces removed
*/
function Trim( string ) {
	if(string==null || string.length==0)
	{
		return false;
	}
	else
	{
		var rex = /^\s+|\s+$/g;
		return string.replace(rex, "");
	}
}

/**
* stringLength() 				-- returns a length of the string
*
* @param	string string 		-- source string

* @return	Integer				-- Length of the string
*/
function stringLength(string)
{
	  if(string==null)
      {
	  	return false;
	  }
	  else
	  {
      	return (Trim(string)).length;
	  }
}

/**
* subString() 						-- returns a sub-string from a source string
*
* @param	string string 			-- source string
* @param	startindex numeric 		-- starting position of the sub string, use negetive to extract characters from the end of the string
* @param	length +integer 		-- number of characters to return in sub-string, must be positive integer
* @param	whitespacebit boolean 	-- if true, remove the leading and trailing whitespaces before operation, not otherwise

* @return	string					-- Substring of the string
*/
function subString(string, startindex, length, whitespacebit)
{
	  if(string==null || string.length==0 || !isInteger(startindex) || !isPositiveInteger(length))
      {
	  	return false;
	  }
	  else
	  {
	  	if(whitespacebit)
	  	{
			string = Trim(string);
		}
		
	  	var browserCheck = getBrowserType();	
		if(browserCheck.indexOf('Internet Explorer') != -1 && startindex < 0)		// check for ie, since ie doesn't support negetive startindex
		{
			var offsetValue = stringLength(string) + startindex;
			return string.substr(offsetValue,length);
		}
		else
		{
      		return string.substr(startindex,length);
		}
	  }	
}

/**
* strToUppercase() 					-- Coverting String to Uppercase
*
* @param	string string 			-- source string

* @return	string					-- returns the string converted in uppercase
*/
function strToUppercase(string)
{
	 if(string==null || string.length==0)
      {
	  	return false;
	  }
	  else
	  {
      	return string.toUpperCase();
	  }
}

/**
* strToLowercase() 					-- Coverting String to Lowercase
*
* @param	string string 			-- source string

* @return	string					-- returns the string converted in lowercase
*/
function strToLowercase(string)
{
	 if(string==null || string.length==0)
      {
	  	return false;
	  }
	  else
	  {
      	return string.toLowerCase();
	  }
}


/**
* searchString() 					-- Searches a specific string in the given string
*
* @param	srcstring string 		-- source string
* @param	searchstring string 	-- search string
* @param	casesensitive string 	-- if 1, performs casesensitive search and in the case of 0 performs caseinsensitive search..

* @return	+integer				-- returns the position of the search string in the source string
*/
function searchString(srcstring, searchstring, casesensitive)
{
	 if(srcstring==null || srcstring.length==0 || searchstring==null || searchstring.length==0 )
      {
	  	return false;
	  }
	 else
	 {
		if(casesensitive == 0)
		{
			rExp = eval('/' + searchstring + '/gi');
		}
		else
		{
			rExp = eval('/' + searchstring + '/g');
		}

		return srcstring.search(rExp);
	}
}

/**
* replaceSubstring() 				-- Finds occurances of fromString in specified inputString and replaces with toString
*
* @param	inputString string 		-- Input string
* @param	fromString string 		-- string to be replaced
* @param	toString string 		-- string which would replace fromString

* @return	string					-- string after replacement
*/
function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == null || fromString.length == 0 || toString == null || inputString == null) {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function


/**
* Split() 							-- Splits the strvalue by separator specified, And returns array of strings
*
* @param	strvalue string 		-- Input string
* @param	separator string 		-- separator might be Character Or Sub-string
* @param	numberoftimes +integer 	-- specifies how many times split should occur use value > 0, use 0 if you want split until end of string 

* @return	array					-- Array of strings after split, in case not split returns whole string as array
*/
function Split(strvalue, separator, numberoftimes) {
	if(strvalue == null || strvalue.length == 0 || separator == null || !isPositiveInteger(numberoftimes) || separator.length == 0)
	{
		return false;
	}
	else
	{
		  /*** 
		  /* Alternative solution if inbuilt split needs to get overridded	
		  var tempArray = Array();	
		  var n = 0;
		 
		  while (strvalue.indexOf(separator) != -1) {
			 var toTheLeft = strvalue.substring(0, strvalue.indexOf(separator));
			 var toTheRight = strvalue.substring(strvalue.indexOf(separator)+separator.length, strvalue.length);
			 tempArray[n] = toTheLeft; n++;
			 strvalue = toTheRight;
			 
			 if(n == numberoftimes && numberoftimes != 0) { return tempArray; }
		  }
		  if(n>0) {tempArray[n] = toTheRight;}
		  
		  return (tempArray.length>0?tempArray:false);
		  */
		  if(numberoftimes == 0)
		  {
			  	return strvalue.split(separator);	
		  }
		  else
		  {
			  	return strvalue.split(separator,numberoftimes);		
		  }
	}
}

/**
* isContainSpacesOrTab() 			-- check whether input string contains any space or tab (\t)
*
* @param	val string 				-- Input string

* @return	boolean					-- returns true if found, false otherwise
*/
function isContainSpacesOrTab(val){
      if(val==null){return false;}
      if(val.length==0) {return false;}
      for(var i=0;i<val.length;i++) {
            if ((val.charAt(i)==" ") || (val.charAt(i)=="\t")) {return true;}
			else {return false;}
	  }	
}

/**
* reverseString() 					-- Reverse the string
*
* @param	string string			-- source string

* @return	string					-- returns reversed string
*/
function reverseString(string)
{
	  if(string==null || string.length==0)
      {
	  	return false;
	  }
	  else
	  {
		var reversedStr = "";
		var strArray = string.split("");
		
		for(var i = string.length -1 ; i >= 0 ; i--) { reversedStr += strArray[i]; }
		return reversedStr;
	  }	
}

/*=====================================================================================
# NUMERIC VALIDATION FUNCTIONS
=====================================================================================*/
/**
* isPositiveInteger() 				-- check whether the number is positive integer (number >= 0) Or not 
*
* @param	val input 				-- source input string/number

* @return	boolean					-- true if val is positive integer, false otherwise
*/
function isPositiveInteger(val){
      if(val==null){return false;}
      if (val.length==0){return false;}

	  val = "" + val + "";	
	  
      for (var i = 0; i < val.length; i++) {
            var ch = val.charAt(i);
            if (ch < "0" || ch > "9") {
            return false;
            }
      }
      return true;
}


/**
* isInteger() 						-- check whether the number is integer or not
*
* @param	val input 				-- source input string/number

* @return	boolean					-- true if val is integer, false otherwise
*/
function isInteger(val){
      if(val==null){return false;}
      if (val.length==0){return false;}
	  
	  val = "" + val + "";	

      for (var i = 0; i < val.length; i++) {
            var ch = val.charAt(i);
            if (i == 0 && ch == "-") {
            continue;
            }
            if (ch < "0" || ch > "9") {
                  return false;
            }
	}
	return true;
}

/**
* isValidNumber() 					-- check for valid Number
*
* @param	val string 				-- source input string/number

* @return	boolean					-- returns true if valid number, false otherwise
*/
function isValidNumber(val){
      if(val==null){return false;}
      if (val.length==0){return false;}
	   val = "" + val + ""; 
      var DecimalFound = false;
      for (var i = 0; i < val.length; i++) {
            var ch = val.charAt(i)
            if (i == 0 && ch == "-") {
                  continue;
            }
            if (ch == "." && !DecimalFound) {
                  DecimalFound = true;
                  continue
            }
            if (ch < "0" || ch > "9") {
                  return false;
            }
      }
      return true;
}

/*=====================================================================================
# COMMON VALIDATION FUNCTIONS
=====================================================================================*/
/**
* isValidEmail() 				-- check for valid Email
*
* @param	val string 				-- Input string

* @return	boolean					-- returns true if valid, false otherwise
*/
function isValidEmail(val){
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!val.match(re)) {
        return false;
    } else {
        return true;
    }
}


/*=====================================================================================
# MATH FUNCTIONS
=====================================================================================*/
/**
* formatDecimal() 					-- Covert integer to decimal, also used to format decimal
*
* @param	argvalue string			-- input string to be formatted
* @param	addzero boolean 		-- if true, zeros would be added to adjust the decimal number, not otherwise
* @param	decimaln +integer 		-- number of decimal points in the resulted string

* @return	boolean					-- returns true if valid number, false otherwise
*/
function formatDecimal(argvalue, addzero, decimaln) {
  if(argvalue == null || argvalue.length == 0 || !isPositiveInteger(decimaln))	{return false;}	

  var numOfDecimal = (decimaln == null) ? 2 : decimaln;
  var number = 1;

  number = Math.pow(10, numOfDecimal);

  argvalue = Math.round(parseFloat(argvalue) * number) / number;
  // If you're using IE3.x, you will get error with the following line.
  // argvalue = argvalue.toString();
  // It works fine in IE4.
  argvalue = "" + argvalue;

  if (argvalue.indexOf(".") == 0)
    argvalue = "0" + argvalue;

  if (addzero == true) {
    if (argvalue.indexOf(".") == -1)
      argvalue = argvalue + ".";

    while ((argvalue.indexOf(".") + 1) > (argvalue.length - numOfDecimal))
      argvalue = argvalue + "0";
  }

  return argvalue;
}	

/*=====================================================================================
# ARRAY RELATED FUNCTIONS
=====================================================================================*/

/**
* Array.concat(a) 					-- Join two arrays
*
* @param	a array/string 			-- array/string to be concated with source array

* @return	object array			-- concated array
*/
if( typeof Array.prototype.concat==='undefined' ) {
 Array.prototype.concat = function( a ) {
  for( var i = 0, b = this.copy(); i<a.length; i++ ) {
   b[b.length] = a[i];
  }
  return b;
  };
}

/**
* Array.copy() 						-- Copy an array
*
* @return	object array			-- copy of the source array
*/
if( typeof Array.prototype.copy==='undefined' ) {
 Array.prototype.copy = function() {
  var a = [], i = this.length;
  while( i-- ) {
   a[i] = typeof this[i].copy!=='undefined' ? this[i].copy() : this[i];
  }
  return a;
 };
}

/**
* Array.pop() 				-- Remove and return the last element of an array
*
* @return	element			-- last element of an array
*/
if( typeof Array.prototype.pop==='undefined' ) {
 Array.prototype.pop = function() {
  var b = this[this.length-1];
  this.length--;
  return b;
 };
}

/**
* Array.push() 				-- Add an element(s) to the end of an array
*
* @return	+integer		-- new length of an array
*/
if( typeof Array.prototype.push==='undefined' ) {
 Array.prototype.push = function() {
  for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
   this[b+i] = a[i];
  }
  return this.length;
 };
}

/**
* Array.shift() 			-- Remove and return the first element
*
* @return	element			-- first element of an array
*/
if( typeof Array.prototype.shift==='undefined' ) {
 Array.prototype.shift = function() {
  for( var i = 0, b = this[0], l = this.length-1; i<l; i++ ) {
   this[i] = this[i+1];
  }
  this.length--;
  return b;
 };
}

/**
* Array.slice() 			-- Copy and return several elements
*
* @param	a integer 		-- starting index, from where to begin slice
* @param	c integer 		-- trailing index, where to stop slice, upto (c-1) index the elements would get sliced
*
* @return	object array	-- sliced/copied elements of array
*/
if( typeof Array.prototype.slice==='undefined' ) {
 Array.prototype.slice = function( a, c ) {
  var i, l = this.length, r = [];
  if( !c ) { c = l; }
  if( c<0 ) { c = l + c; }
  if( a<0 ) { a = l - a; }
  if( c<a ) { i = a; a = c; c = i; }
  for( i = 0; i < c - a; i++ ) { r[i] = this[a+i]; }
  return r;
 };
}

/**
* Array.splice() 			-- Remove centain elements from array
*
* @param	a integer 		-- starting index, from where to begin splice
* @param	c integer 		-- number of elements to splice
*
* @return	object array	-- spliced/deleted elements from array
*/
if( typeof Array.prototype.splice==='undefined' ) {
 Array.prototype.splice = function( a, c ) {
  var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
  if( !c ) { c = l - a; }
  for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
  for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
  this.length -= c - e.length + 2;
  return d.slice( f, f + c );
 };
}

/**
* Array.unshift() 			-- Add an element(s) to the beginning of an array
*
* @param	arguments 		-- allows one or more than one elements as a agrument here... like array.unshift(ele1,ele2...)
*
* @return	object array	-- array with elements added to the front
*/
if( typeof Array.prototype.unshift==='undefined' ) {
 Array.prototype.unshift = function() {
  this.reverse();
  var a = arguments, i = a.length;
  while(i--) { this.push(a[i]); }
  this.reverse();
  return this.length;
 };
}

/**
* Array.indexOf() 			-- Used to check if element exists in the array or not
*
* @param	value element 	-- element value
* @param	begin +integer	-- start index, from where to begin the search for element supplied
* @param	strict boolean	-- if you want to also check type comparison supply false, true otherwise
*
* @return	+integer		-- return index of the first element that matches value, -1 if not found
*/
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

/**
* Array.insert() 			-- Insert value at index, without overwriting existing keys
*
* @param	index +integer 	-- index at which element would be inserted in the array
* @param	value element	-- element value
*
* @return	object array	-- return the new array with element inserted at specified index
*/
Array.prototype.insert = function( i, v ) {
 if( i>=0 ) {
  var a = this.slice(), b = a.splice( i );
  a[i] = v;
  return a.concat( b );
 }
};

/**
* Array.lastIndexOf() 		-- Return index of the last element that matches value
*
* @param	value element 	-- element value
* @param	begin +integer	-- start index, from where to begin the search for element supplied
* @param	strict boolean	-- if you want to also check type comparison supply false, true otherwise
*
* @return	+integer		-- return index of the last element that matches value, -1 if not found
*/
Array.prototype.lastIndexOf = function( v, b, s ) {
 b = +b || 0;
 var i = this.length; while(i-->b) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

/**
* Array.random() 		-- Return a random element, optionally up to or from range
*
* @param	r			-- index range for random element calculation --optional
*
* @return	element		-- return random element from array
*/
Array.prototype.random = function( r ) {
 var i = 0, l = this.length;
 if( !r ) { r = this.length; }
 else if( r > 0 ) { r = r % l; }
 else { i = r; r = l + r % l; }
 return this[ Math.floor( r * Math.random() - i ) ];
};

/**
* Array.shuffle() 			-- Randomly interchange elements
*
* @param	r				-- index range for random shuffle calculation --optional
*
* @return	object array	-- return array with elements shuffled
*/
Array.prototype.shuffle = function( b ) {
 var i = this.length, j, t;
 while( i ) {
  j = Math.floor( ( i-- ) * Math.random() );
  t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
  this[i] = this[j];
  this[j] = t;
 //alert(this);
 }
 return this;
};

/**
* Array.unique() 			-- Remove duplicate values from array
*
* @param	r				-- if you want to also check type comparison supply false, true otherwise
*
* @return	object array	-- return array with duplicate removed
*/
Array.prototype.unique = function( b ) {
 var a = [], i, l = this.length;
 for( i=0; i<l; i++ ) {
  if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
 }
 return a;
};

/*=====================================================================================
# COOKIES FUNCTIONS
=====================================================================================*/
/**
* SetCookie() 						-- Set a cookie
*
* @param	cookiename string		-- name of the cookie
* @param	cookievalue string		-- value of the cookie
* @param	expires date			-- date of expiration for cookie
* @param	path string				-- path for the cookie
* @param	domain string			-- domain of the cookie
* @param	secure boolean			-- set cookie as a secure cookie, if true cookie can be accessed only from a secure environment

* @return	boolean					-- true if cookie is set, false otherwise
*/
function setCookie(cookiename, cookievalue /*OPTIONAL PARAMETERS--: "expires","path","domain","secure"  :--OPTIONAL PARAMETERS*/ ) {
  var argv = setCookie.arguments;
  var argc = setCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;

  document.cookie = cookiename + "=" + escape(cookievalue) +
    ((expires == null) ? "" 	    : ("; expires=" + expires.toUTCString())) +
    ((path    == null) ? ""	    : ("; path="    + path                 )) +
    ((domain  == null) ? "" 	    : ("; domain="  + domain               )) +
    ((secure  == true) ? "; secure" : "");

   return (getCookie(cookiename)==null?false:true);
}

/**
* GetCookie() 					-- Get the cookie value
*
* @param	check_name string	-- name of the cookie

* @return	string				-- value of the cookie if found, null otherwise
*/
function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}		 

/**
* deleteCookie() 				-- Delete the specific cookie
*
* @param	cookiename string	-- name of the cookie to be deleted

* @return	string				-- true if deleted, false otherwise
*/
function deleteCookie(cookiename) {
  var setExpDate = new Date();

  setExpDate.setDate(setExpDate.getDate() - 30);
  var cookieVal = getCookie(cookiename);
  if (cookieVal != null)
  {
    setCookie(cookiename, cookieVal, setExpDate,"/");
	return true;
  }	
  else
  {
	return false;
  }
}
function check_for_equal(first_id,seconde_value){
	var first_value = document.getElementById(first_id).value;
	if(first_value != seconde_value){
			alert('Your  ' +first_id+  '  does not match');
			document.getElementById(first_id).focus();	
		}
}