Array.prototype.has=function(v)
{
	for (i=0;i<this.length;i++)
	{
		if (this[i]==v) 
		{
			return true;
		}
	}
	return false;
}


String.prototype.strpad=function(len,pad,dir)
{
	var str = this;
	if(str.length >= len || pad.length > 1)
	{
		return str;
	}
	else if(dir == 'left')
	{
		while(str.length < len)
		{
			str = pad + str;
		}
	}
	else
	{
		while(str.length < len)
		{
			str = str + pad;
		}
	}
	
	return str;
}


/** This following snippet of code copied from http://www.codeproject.com/KB/scripting/dom-element-abs-pos.aspx,
	originally written by Sergiy Korzh. It is Licenced under the CPOL Licence. **/

var __isIE =  navigator.appVersion.match(/MSIE/);
var __userAgent = navigator.userAgent;
var __isFireFox = __userAgent.match(/firefox/i);
var __isFireFoxOld = __isFireFox && 
   (__userAgent.match(/firefox\/2./i) || __userAgent.match(/firefox\/1./i));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;

function __parseBorderWidth(width) {
    var res = 0;
    if (typeof(width) == "string" && width != null 
                && width != "" ) {
        var p = width.indexOf("px");
        if (p >= 0) {
            res = parseInt(width.substring(0, p));
        }
        else {
             //do not know how to calculate other 
             //values (such as 0.5em or 0.1cm) correctly now
             //so just set the width to 1 pixel
            res = 1; 
        }
    }
    return res;
}


//returns border width for some element
function __getBorderWidth(element) {
    var res = new Object();
    res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;
    if (window.getComputedStyle) {
        //for Firefox
        var elStyle = window.getComputedStyle(element, null);
        res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));  
        res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));  
        res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));  
        res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));  
    }
    else {
        //for other browsers
        res.left = __parseBorderWidth(element.style.borderLeftWidth);
        res.top = __parseBorderWidth(element.style.borderTopWidth);
        res.right = __parseBorderWidth(element.style.borderRightWidth);
        res.bottom = __parseBorderWidth(element.style.borderBottomWidth);
    }
   
    return res;
}


//returns absolute position of some element within document
function getElementAbsolutePos(element) {
    var res = new Object();
    res.x = 0; res.y = 0;
    if (element !== null) {
        res.x = element.offsetLeft;
        res.y = element.offsetTop;
        
        var offsetParent = element.offsetParent;
        var parentNode = element.parentNode;
        var borderWidth = null;

        while (offsetParent != null) {
            res.x += offsetParent.offsetLeft;
            res.y += offsetParent.offsetTop;
            
            var parentTagName = offsetParent.tagName.toLowerCase();    

            if ((__isIE && parentTagName != "table") || 
                (__isFireFoxNew && parentTagName == "td")) {            
                borderWidth = __getBorderWidth(offsetParent);
                res.x += borderWidth.left;
                res.y += borderWidth.top;
            }
            
            if (offsetParent != document.body && 
                offsetParent != document.documentElement) {
                res.x -= offsetParent.scrollLeft;
                res.y -= offsetParent.scrollTop;
            }

            //next lines are necessary to support FireFox problem with offsetParent
               if (!__isIE) {
                while (offsetParent != parentNode && parentNode !== null) {
                    res.x -= parentNode.scrollLeft;
                    res.y -= parentNode.scrollTop;
                    
                    if (__isFireFoxOld) {
                        borderWidth = __getBorderWidth(parentNode);
                        res.x += borderWidth.left;
                        res.y += borderWidth.top;
                    }
                    parentNode = parentNode.parentNode;
                }    
            }

            parentNode = offsetParent.parentNode;
            offsetParent = offsetParent.offsetParent;
        }
    }
    
    return res;
}
/** End code snippet **/



function pushFooter(pushingElement)
{
	pushingElement = $(pushingElement);
	$(pushingElement.parentNode).setStyle({height: (document.all ? '100%' : 'auto') });
	var pushingDim = pushingElement.getDimensions();	
	var parentDim = $(pushingElement.parentNode).getDimensions();
	var extraPadding = 60;
	if((pushingDim.height + extraPadding) > parentDim.height)
	{
		var newHeight = (pushingDim.height + extraPadding) +  'px';
		$(pushingElement.parentNode).setStyle({height: newHeight});
	}
}


function handleQuantityChange(e) 
{
	var allowedKeys = new Array(Event.KEY_BACKSPACE,Event.KEY_TAB,Event.KEY_LEFT,Event.KEY_RIGHT,Event.KEY_ESC,Event.KEY_RETURN,Event.KEY_DELETE,Event.KEY_HOME,Event.KEY_END,Event.KEY_PAGEUP,Event.KEY_PAGEDOWN); 

	var allowSign = $(this).hasClassName('signed');

	var value = getValue(this); 
	var keynum = e.keyCode; 

	var modifierKeyPressed = (e.shiftKey || e.ctrlKey || e.altKey); 

	if(allowedKeys.has(keynum) || isNumericKey(keynum, modifierKeyPressed, allowSign)) 
	{ 
		return true; 
		// do nothing 
	} 
	else 
	{ 
		e.stop(); 
	} 
}


function isNumericKey(keynum, modKey, allowSign)
{
	var isDotKey = (keynum == 110 || keynum == 190);
	var isMinusKey = (navigator.userAgent.indexOf('MSIE') != -1 || navigator.userAgent.indexOf('Safari') != -1) ? (keynum == 189) : (keynum == 109);

	if (!modKey && ((keynum >= 48 && keynum <=57) || (keynum >= 96 && keynum <=105) || isDotKey || (isMinusKey && allowSign)))
	{
		return true;
	}
	else
	{
		return false;
	}
}



function getPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function getPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getPosXDepth(obj,depth)
{
	var curleft = 0;
	var counter = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if(counter > depth)
				break;
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
			counter++;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function getPosYDepth(obj,depth)
{
	var curtop = 0;
	var counter = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if(counter > depth)
				break;
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
			counter++;
		}
	}
	else if (obj.x)
		curleft += obj.y;
	return curtop;
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all ? true : false;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE)
	document.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var cursorX = 0;
var cursorY = 0;
var act;
// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		cursorX = event.clientX + document.body.scrollLeft;
		cursorY = event.clientY + document.body.scrollTop;
		act = event;
	} else {  // grab the x-y pos.s if browser is NS
		cursorX = e.pageX;
		cursorY = e.pageY;
		act = e;
	}  
	// catch possible negative values in NS4
	if (cursorX < 0){cursorX = 0;}
	if (cursorY < 0){cursorY = 0;}  
	return true;
}

function addCSSRule(element, rule)
{
	var slist, style;
	if(IE)
		slist = document.styleSheets;
	else
		slist = document.getElementsByTagName("style");
	if(slist.length > 0)
		style = slist.item(slist.length - 1);
	else
	{
		style = document.createElement("style");
		style.type = "text/css";
		document.getElementsByTagName('head')[0].appendChild(style);
	}

	if(style.sheet && style.sheet.insertRule) //Mozilla
		style.sheet.insertRule(element + "{" + rule + "}", 0);
	else if(style.addRule) // IE
		style.addRule(element, rule);
}

function showOptions(elem,optionsElementId)
{
	new Effect.SlideDown(document.getElementById(optionsElementId));
	elem.onclick=function onclick(event){hideOptions(this,optionsElementId);};
	elem.className="options_expanded";
}

function hideOptions(elem,optionsElementId)
{
	new Effect.SlideUp(document.getElementById(optionsElementId));
	elem.onclick=function onclick(event){showOptions(this,optionsElementId);};
	elem.className="options_collapsed";
}
var screenY = screen.height;
var screenX = screen.width;

//compensate for IE < 7's inability to set max-height CSS rule
function forceMaxHeight(elem_id, height_px, overflow)
{
	if(!document.all)
		return;
	var e = document.all(elem_id);
	if(typeof(e) == "undefined")
		return;
	var ht = e.clientHeight;
	if(ht > height_px)
	{
		e.style.height = height_px + "px";
		e.style.overflow = overflow;
	}
}

function showDiv(id)
{
	var sdiv = document.getElementById(id);
	sdiv.style.visibility = 'visible';
	sdiv.style.left = cursorX;
	sdiv.style.top = cursorY;
	sdiv.style.position='absolute';
}
	
function hideDiv(id)
{
	var e = act;	
	var tg = (IE) ? e.srcElement : e.target; 
	if (tg.nodeName.toLowerCase() != 'div')
		return;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement; 
	while (reltg != tg && reltg.nodeName.toLowerCase() != 'body') 
		reltg = reltg.parentNode; 
	if (reltg == tg)
		return;     
	var	hdiv = document.getElementById(id);
	hdiv.style.visibility = 'hidden';
}

function openWindow(url, w, h)
{
	window.open(url, 'winEmailFriend', 'width='+w+',height='+h+',scrollbars=1,resizable=1');
}

function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function addLoadEvent(func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	} 
	else 
	{
		window.onload = function() {
			oldonload();
			func();
	
		}
	}
}

function addUnloadEvent(func) 
{
	var oldunload = window.unload;
	if (typeof window.unload != 'function') 
	{
		window.unload = func;
	} 
	else 
	{
		window.unload = function() {
			oldunload();
			func();
	
		}
	}
}

/*
	The following two functions were adapted from
	http://www.quirksmode.org/dom/maxlength.html
	They are used for setting max-length on a textarea.
*/
function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'textarea_charcounter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	this.value = this.value.substr(0, maxLength);
	var currentLength = this.value.length;
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

/**
 * The following was taken from stringFunctions.js
 * a library taken from http://www.dieterraber.net/jsStringFuncs.htm
 *
 * This file contains a collection of string functions for javascript.
 * Most of them are inspired by their PHP equivalent.
 *
 * This source file is subject to version 2.1 of the GNU Lesser
 * General Public License (LPGL), found in the file LICENSE that is
 * included with this package, and is also available at
 * http://www.gnu.org/copyleft/lesser.html.
 * @package     Javascript
 *
 * @author      Dieter Raber <dieter@dieterraber.net>
 * @copyright   2004-12-27
 * @version     1.0
 * @license     http://www.gnu.org/copyleft/lesser.html
 *
 */

/**
 * TOC
 *
 * - hex2rgb
 * - htmlentities
 * - numericEntities
 * - trim
 * - ucfirst
 * - strPad
 */

/**
 * hex2rgb
 *
 * Convert hexadecimal color triplets to RGB
 *
 * Expects an hexadecimal color triplet (case insensitive)
 * Returns an array containing the decimal values
 * for r, g and b.
 *
 * example:
 *   test = 'ff0033'
 *   test.hex2rgb() //returns the array (255,00,51)
 */

String.prototype.hex2rgb = function()
{
  var red, green, blue;
  var triplet = this.toLowerCase().replace(/#/, '');
  var rgbArr  = new Array();

  if(triplet.length == 6)
  {
    rgbArr[0] = parseInt(triplet.substr(0,2), 16)
    rgbArr[1] = parseInt(triplet.substr(2,2), 16)
    rgbArr[2] = parseInt(triplet.substr(4,2), 16)
    return rgbArr;
  }
  else if(triplet.length == 3)
  {
    rgbArr[0] = parseInt((triplet.substr(0,1) + triplet.substr(0,1)), 16);
    rgbArr[1] = parseInt((triplet.substr(1,1) + triplet.substr(1,1)), 16);
    rgbArr[2] = parseInt((triplet.substr(2,2) + triplet.substr(2,2)), 16);
    return rgbArr;
  }
  else
  {
    throw triplet + ' is not a valid color triplet.';
  }
}


/**
 * htmlEntities
 *
 * Convert all applicable characters to HTML entities
 *
 * object string
 * return string
 *
 * example:
 *   test = 'äöü'
 *   test.htmlEntities() //returns '&auml;&ouml;&uuml;'
 */

String.prototype.htmlEntities = function()
{
  var chars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
                         'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
                         'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
                         'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
                         'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
                         'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','ß','<',
                         '>','¢','£','¤','¥','¦','§','¨','©','ª','«',
                         '¬','­','®','¯','°','±','²','³','´','µ','¶',
                         '·','¸','¹','º','»','¼','½','¾');

  var entities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
                            'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
                            'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
                            'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
                            'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
                            'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
                            'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
                            'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
                            'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','szlig',
                            'lt','gt','cent','pound','curren','yen','brvbar','sect','uml',
                            'copy','ordf','laquo','not','shy','reg','macr','deg','plusmn',
                            'sup2','sup3','acute','micro','para','middot','cedil','sup1',
                            'ordm','raquo','frac14','frac12','frac34');

  newString = this;
  for (var i = 0; i < chars.length; i++)
  {
    myRegExp = new RegExp();
    myRegExp.compile(chars[i],'g')
    newString = newString.replace (myRegExp, '&' + entities[i] + ';');
  }
  return newString;
}


/**
 * numericEntities
 *
 * Convert all applicable characters to numeric entities
 *
 * object string
 * return string
 *
 * example:
 *   test = 'äöü'
 *   test.numericEntities() //returns '&#228;&#246;&#252;'
 */

String.prototype.numericEntities = function()
{
  var i;
  var chars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
                         'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
                         'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
                         'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
                         'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
                         'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','ß','<',
                         '>','¢','£','¤','¥','¦','§','¨','©','ª','«',
                         '¬','­','®','¯','°','±','²','³','´','µ','¶',
                         '·','¸','¹','º','»','¼','½','¾');

  var entities = new Array()
  for (i = 0; i < chars.length; i++)
  {
    entities[i] = chars[i].charCodeAt(0);
  }

  newString = this;
  for (i = 0; i < chars.length; i++)
  {
    myRegExp = new RegExp();
    myRegExp.compile(chars[i],'g')
    newString = newString.replace (myRegExp, '&#' + entities[i] + ';');
  }
  return newString;
}



/**
 * trim
 *
 * Strip whitespace from the beginning and end of a string
 *
 * object string
 * return string
 *
 * example:
 *   test = '\nsomestring\n\t\0'
 *   test.trim()  //returns 'somestring'
 */
String.prototype.trim = function()
{
  return this.replace(/^\s*([^ ]*)\s*$/, "$1");
}


/**
 * ucfirst
 *
 * Returns a string with the first character capitalized,
 * if that character is alphabetic.
 *
 * object string
 * return string
 *
 * example:
 *   test = 'john'
 *   test.ucfirst() //returns 'John'
 */

String.prototype.ucfirst = function()
{
  firstLetter = this.charCodeAt(0);
  if((firstLetter >= 97 && firstLetter <= 122)
     || (firstLetter >= 224 && firstLetter <= 246)
     || (firstLetter >= 249 && firstLetter <= 254))
  {
    firstLetter = firstLetter - 32;
  }
  alert(firstLetter)
  return String.fromCharCode(firstLetter) + this.substr(1,this.length -1)
}


/**
 * strPad
 *
 * Pad a string to a certain length with another string
 *
 * This functions returns the input string padded on the left, the right, or both sides
 * to the specified padding length. If the optional argument pad_string is not supplied,
 * the output is padded with spaces, otherwise it is padded with characters from pad_string
 * up to the limit.
 *
 * The optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH.
 * If pad_type is not specified it is assumed to be STR_PAD_RIGHT.
 *
 * If the value of pad_length is negative or less than the length of the input string,
 * no padding takes place.
 *
 * object string
 * return string
 *
 * examples:
 *   var input = 'foo';
 *   input.strPad(9);                      // returns "foo      "
 *   input.strPad(9, "*+", STR_PAD_LEFT);  // returns "*+*+*+foo"
 *   input.strPad(9, "*", STR_PAD_BOTH);   // returns "***foo***"
 *   input.strPad(9 , "*********");        // returns "foo******"
 */

var STR_PAD_LEFT  = 0;
var STR_PAD_RIGHT = 1;
var STR_PAD_BOTH  = 2;

String.prototype.strPad = function(pad_length, pad_string, pad_type)
{
  /* Helper variables */
  var num_pad_chars   = pad_length - this.length;/* Number of padding characters */
  var result          = '';                       /* Resulting string */
  var pad_str_val     = ' ';
  var pad_str_len     = 1;                        /* Length of the padding string */
  var pad_type_val    = STR_PAD_RIGHT;            /* The padding type value */
  var i               = 0;
  var left_pad        = 0;
  var right_pad       = 0;
  var error           = false;
  var error_msg       = '';
  var output           = this;

  if (arguments.length < 2 || arguments.length > 4)
  {
    error     = true;
    error_msg = "Wrong parameter count.";
  }


  else if(isNaN(arguments[0]) == true)
  {
    error     = true;
    error_msg = "Padding length must be an integer.";
  }
  /* Setup the padding string values if specified. */
  if (arguments.length > 2)
  {
    if (pad_string.length == 0)
    {
      error     = true;
      error_msg = "Padding string cannot be empty.";
    }
    pad_str_val = pad_string;
    pad_str_len = pad_string.length;

    if (arguments.length > 3)
    {
      pad_type_val = pad_type;
      if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH)
      {
        error     = true;
        error_msg = "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH."
      }
    }
  }

  if(error) throw error_msg;

  if(num_pad_chars > 0 && !error)
  {
    /* We need to figure out the left/right padding lengths. */
    switch (pad_type_val)
    {
      case STR_PAD_RIGHT:
        left_pad  = 0;
        right_pad = num_pad_chars;
        break;

      case STR_PAD_LEFT:
        left_pad  = num_pad_chars;
        right_pad = 0;
        break;

      case STR_PAD_BOTH:
        left_pad  = Math.floor(num_pad_chars / 2);
        right_pad = num_pad_chars - left_pad;
        break;
    }

    for(i = 0; i < left_pad; i++)
    {
      output = pad_str_val.substr(0,num_pad_chars) + output;
    }

    for(i = 0; i < right_pad; i++)
    {
      output += pad_str_val.substr(0,num_pad_chars);
    }
  }

  return output;
}

//end http://www.dieterraber.net/jsStringFuncs.htm
// Replaces all instances of the given substring.
String.prototype.replaceAll = function(
				strTarget, // The substring you want to replace
				strSubString // The string you want to replace in.
 							)
 	{
		var strText = this;
		var intIndexOfMatch = strText.indexOf( strTarget );
		
		// Keep looping while an instance of the target string
		// still exists in the string.
		while (intIndexOfMatch != -1)
		{
			// Relace out the current instance.
			strText = strText.replace( strTarget, strSubString )
			
			// Get the index of any next matching substring.
			intIndexOfMatch = strText.indexOf( strTarget );
		}
		
		// Return the updated string with ALL the target strings
		// replaced out with the new substring.
		return( strText );
    }
    
function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}//end function var_dump

function roundNumber(num, dec) 
{
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

String.prototype.replaceAll = function(expr, replace)
{
	var i = this.search(expr);
	var s = this.replace(expr, replace);
	
	while (i > -1)
	{
		s = s.replace(expr, replace);
		i = s.search(expr);
	}
   return s;
};

function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

function isDate(dateObj)
{
	if (dateObj.toString() == "NaN" || dateObj.toString() == "Invalid Date") 
	{
		return false;
	}
	else
	{
		return true;
	}
}

function formatDate(dateObj, type)
{
	if(type==1)
	{
		return  dateObj.getFullYear() + "-" + (dateObj.getMonth()+1) + "-" + dateObj.getDate();
	}
	else
	{
		return (dateObj.getMonth()+1) + "/" + dateObj.getDate() + "/" + dateObj.getFullYear(); 
	}
}

// takes 2 date strings in yyyy-mm-dd format and compares them.
//  returns -1 if date1 is bigger, 1 if date 2 is bigger, 0 if equal
function dateCompare (date1, date2)
{
	var date1parts = date1.split('-');
	var dateObj1 = new Date();
	dateObj1.setFullYear(new Number(date1parts[0]));
	dateObj1.setMonth(new Number(date1parts[1])-1);
	dateObj1.setDate(new Number(date1parts[2]));
	
	var date2parts = date2.split('-');
	var dateObj2 = new Date();
	dateObj2.setFullYear(new Number(date2parts[0]));
	dateObj2.setMonth(new Number(date2parts[1])-1);
	dateObj2.setDate(new Number(date2parts[2]));
	
	var time1 = dateObj1.getTime();
	var time2 = dateObj2.getTime();
	
	if (time1 > time2)
	{
		return -1;
	}
	else if (time2 > time1)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}