
function IsNumeric(strString)
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
   {
	strChar = strString.charAt(i);
      	if (strValidChars.indexOf(strChar) == -1)
        {
        	blnResult = false;
        }
   }
  	
	return blnResult;
}

// check if a number is an integer
function isInt(myNum) 
{
	// get the modulus: if it's 0, then it's an integer
         var myMod = myNum % 1;

         if (myMod == 0) {
                 return true;
         } else {
                 return false;
         }
}

// check if positive int
function isIntPositive(numvalue)
{	
	if(isInt(numvalue) && numvalue > 0)
	{
		return true;
	}
	else
	{
		return false;
	}

}

function isFloatPositive(numvalue)
{
	if(!isNaN(numvalue) && numvalue > 0)
	{
		return true;
	}
	else
	{
		return false;
	}

}



// trim a string for IE 3.0 or less
function trim(str) {
  while (str.charAt(0) == ' ')
    str = str.substring(1);
  while (str.charAt(str.length - 1) == ' ')
    str = str.substring(0, str.length - 1);
  return str;
}

// trim string
function trimString(str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

// Pop up help box
function HideHelp(div)
{
	div.style.display = 'none';
}

function ShowHelp(div, title, desc)
{
	div.style.display = 'inline';
	div.style.position = 'absolute';
	div.style.width = '170';
	div.style.backgroundColor = 'lightyellow';
	div.style.border = 'dashed 1px black';
	div.style.padding = '10px';
	div.innerHTML = '<b>' + title + '</b><br><img src=../images/blank.gif width=1 height=5><br>' +
			'<div style="padding-left:10; padding-right:5">' + desc + '</div>';
}
	
function ShowTaxHelp(div, title, desc, width)
{
	div.style.display = 'inline';
	div.style.position = 'absolute';
	div.style.width = width;
	div.style.backgroundColor = 'lightyellow';
	div.style.border = 'dashed 1px black';
	div.style.padding = '10px';
	div.innerHTML = '<b>' + title + '</b><br><img src=../images/blank.gif width=1 height=5><br>' +
			'<div style="padding-left:10; padding-right:5">' + desc + '</div>';
}	

//filenane checking - returns true if no illegal chars
function CheckFilename(filename)
{	

	myregexp = /[\\/:*?"<>|]/
		
	if(filename.match(myregexp))
	{
		//alert('match')
		return false;
	}
	else
	{
		//alert('no match')
		return true;
	}


}

function CheckStrongPassword(password)
{
	myregexp1 = /[a-zA-Z]+/;
	myregexp2 = /[0-9]+/;
		
	if(password.match(myregexp1) && 
	   password.match(myregexp2) && 
    	   password.length >= 6)
	{
		//alert('match');
		return true;
		
	}
	else
	{
		//alert('no match')
		return false
		
	}

}

	//checks a proper login id 
	//	i. must contain ['a to z','A to Z','0-9','_','-','.'] characters only,
	
	function CheckLoginID(strInput)
	{
		myReg = /[^a-zA-Z0-9_\-\.]/;	//if matches any characters outside of these, then error.
		
		if(strInput.match(myReg))
		{
			return false;
		}
		else
		{
			return true;
		}
	}


/*
HTMLEncode - Encode HTML special characters.
Copyright (c) 2006 Thomas Peri, http://www.tumuski.com/
*/

/**
 * HTML-Encode the supplied input
 * 
 * Parameters:
 *
 * (String)  source    The text to be encoded.
 * 
 * (boolean) display   The output is intended for display.
 *
 *                     If true:
 *                     * Tabs will be expanded to the number of spaces 
 *                       indicated by the 'tabs' argument.
 *                     * Line breaks will be converted to <br />.
 *
 *                     If false:
 *                     * Tabs and linebreaks get turned into &#____;
 *                       entities just like all other control characters.
 *
 * (integer) tabs      The number of spaces to expand tabs to.  (Ignored 
 *                     when the 'display' parameter evaluates to false.)
 *
 * v 0.3 - January 4, 2006
 */
function htmlEncode(source, display, tabs)
{
	function special(source)
	{
		var result = '';
		for (var i = 0; i < source.length; i++)
		{
			var c = source.charAt(i);
			if (c < ' ' || c > '~')
			{
				c = '&#' + c.charCodeAt() + ';';
			}
			result += c;
		}
		return result;
	}
	
	function format(source)
	{
		// Use only integer part of tabs, and default to 4
		tabs = (tabs >= 0) ? Math.floor(tabs) : 4;
		
		// split along line breaks
		var lines = source.split(/\r\n|\r|\n/);
		
		// expand tabs
		for (var i = 0; i < lines.length; i++)
		{
			var line = lines[i];
			var newLine = '';
			for (var p = 0; p < line.length; p++)
			{
				var c = line.charAt(p);
				if (c === '\t')
				{
					var spaces = tabs - (newLine.length % tabs);
					for (var s = 0; s < spaces; s++)
					{
						newLine += ' ';
					}
				}
				else
				{
					newLine += c;
				}
			}
			// If a line starts or ends with a space, it evaporates in html
			// unless it's an nbsp.
			newLine = newLine.replace(/(^ )|( $)/g, '&nbsp;');
			lines[i] = newLine;
		}
		
		// re-join lines
		var result = lines.join('<br />');
		
		// break up contiguous blocks of spaces with non-breaking spaces
		result = result.replace(/  /g, ' &nbsp;');
		
		// tada!
		return result;
	}

	var result = source;
	
	// ampersands (&)
	result = result.replace(/\&/g,'&amp;');

	// less-thans (<)
	result = result.replace(/\</g,'&lt;');

	// greater-thans (>)
	result = result.replace(/\>/g,'&gt;');
	
	if (display)
	{
		// format for display
		result = format(result);
	}
	else
	{
		// Replace quotes if it isn't for display,
		// since it's probably going in an html attribute.
		result = result.replace(new RegExp('"','g'), '&quot;');
	}

	// special characters
	result = special(result);
	
	// tada!
	return result;
}


/*** check browser ***/
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
	
	function CheckBrowser()
	{
		
		//alert(detect);
		if (checkIt('konqueror'))
		{
			browser = "Konqueror";
			OS = "Linux";
		}
		else if (checkIt('safari')) browser = "Safari"
		else if (checkIt('omniweb')) browser = "OmniWeb"
		else if (checkIt('opera')) browser = "Opera"
		else if (checkIt('webtv')) browser = "WebTV";
		else if (checkIt('icab')) browser = "iCab"
		else if (checkIt('msie')) browser = "Internet Explorer"
		else if (checkIt('firefox')) 
		{
			
			browser = "Firefox"
			version = detect.substring(place + thestring.length);
		}
		else if (!checkIt('compatible'))
		{
			browser = "Netscape Navigator"
			version = detect.charAt(8);
		}
		else browser = "An unknown browser";

		if (!version) version = detect.charAt(place + thestring.length);

		if (!OS)
		{
			if (checkIt('linux')) OS = "Linux";
			else if (checkIt('x11')) OS = "Unix";
			else if (checkIt('mac')) OS = "Mac"
			else if (checkIt('win')) OS = "Windows"
			else OS = "an unknown operating system";
		}

		//alert(browser)	
		//alert(version)	
		if (browser != 'Internet Explorer' || version < 5 )
		{
			alert('Warning\nwebShaper control panel is only compatible with Microsoft Internet Explorer 5.0\+')
		}
		

	}
	
	function checkIt(string)
	{
		place = detect.indexOf(string) + 1;
		thestring = string;
		return place;
	}
