/**
  These are the collections of my js lib.

*/



/*  Array:: Multi dimension array sorting.
	Example:
var DVD = [
['DVD Title 2','label2','releasedate2','details2'],
['DVD Title 1','label1','releasedate1','details1'],
['DVD Title n','labeln','releasedaten','detailsn'],
['DVD Title a','labela','releasedatea','detailsa']
];

alert(DVD.multiSort(1)); // SORTS BY LABEL \\;
alert(DVD.multiSort(2)); // SORTS BY RELEASE DATE \\;
ORDER WILL NOT CHANGE.   also, it iwll handle number sorting
*/

Array.prototype.multiSort = function(index, asc){ 
	if (index == undefined || index == null) index = 0;
	Array.prototype.multiSortIndex = index;
	if (asc == undefined || asc == null)
	{
		asc = true;
	} 
	
	if (asc)
	{
		return this.sort( function(a,b){
				if(isFinite(Number(a[Array.prototype.multiSortIndex])) && isFinite(Number(b[Array.prototype.multiSortIndex])))
				{
					return a[Array.prototype.multiSortIndex]- b[Array.prototype.multiSortIndex];
				} else
				{
					if (a[Array.prototype.multiSortIndex]<b[Array.prototype.multiSortIndex]) return -1;
					if (a[Array.prototype.multiSortIndex]>b[Array.prototype.multiSortIndex]) return 1;
					return 0;
				}
			}
		);
	} else
	{
		return this.sort( function(a,b){
				if(isFinite(Number(a[Array.prototype.multiSortIndex])) && isFinite(Number(b[Array.prototype.multiSortIndex])))
				{
					return b[Array.prototype.multiSortIndex]- a[Array.prototype.multiSortIndex];
				} else
				{
					if (a[Array.prototype.multiSortIndex]>b[Array.prototype.multiSortIndex]) return -1;
					if (a[Array.prototype.multiSortIndex]<b[Array.prototype.multiSortIndex]) return 1;
					return 0;
				}
			}
		);
	}
}


/*	Array:: Numeric Sorting
	Example:
var tmp = [5,9,12,18,56,1,10,42,30,7,97,53,33,35,27];    tmp=tmp.sortNum(); 
// returns 1,5,7,9,10,12,18,27,30,33,35,42,53,56,97 
*/

	Array.prototype.sortNum = function() {   
		return this.sort( function (a,b) { return a-b; } );
	}

	Array.prototype.clone = function () 
	{
		var a = new Array(); 
		for (var property in this) 
		{
			a[property] = typeof (this[property]) == 'object' ? this[property].clone() : this[property];
		} 
		return a;
	}

/*	Array:: Search
	Example:
	var tmp = [5,9,12,18,56,1,10,42,'blue',30, 7,97,53,33,30,35,27,30,'35','Ball', 'bubble'];
		//         0/1/2 /3 /4/5 /6 /7     /8  /9/10/11/12/13/14/15/16/17/  18/    19/      20
	var thirty=tmp.find(30);   			// Returns 9, 14, 17
	var thirtyfive=tmp.find('35');   	// Returns 18
	var thirtyfive=tmp.find(35);     	// Returns 15
	var haveBlue=tmp.find('blue');     	// Returns 8
	var notFound=tmp.find('not there!'); // Returns false
	var regexp1=tmp.find(/^b/);          // returns 8,20    (first letter starts with b)var regexp1=tmp.find(/^b/i);         // returns 8,19,20 (same as above but ignore case)
*/
	Array.prototype.find = function(searchStr) {  
		var returnArray = false;  
		for (i=0; i<this.length; i++) {    
			if (typeof(searchStr) == 'function') {      
				if (searchStr.test(this[i])) {        
					if (!returnArray) { 
						returnArray = []; 
					}        
					returnArray.push(i);      
				}    
			} else {      
				if (this[i]===searchStr) {        
					if (!returnArray) { 
						returnArray = []; 
					}        
					returnArray.push(i);      
				}    
			}  
		}  
		return returnArray;
	}

/*	Array:: Function Mapping
	Example:
	function trim(str) {  
		return str.replace(/^\s+|\s+$/g,'');
	}
	var tmp = ['now', 'is', '   the   ', 'time    ', '    for ',  ' all', ' good ', '   men   '];
	var test = tmp.map(trim);  	// returns now,is,the,time,for,all,good,men
*/
	Array.prototype.map = function(f) {  
		var returnArray=[];  
		for (i=0; i<this.length; i++) {    
			returnArray.push(f(this[i]));  
		}  
		return returnArray;
	}

/*	Object:: isArray?
	Example:
	alert( [].isArray() ); // true
	alert( {}.isArray() ); // false
*/
	Object.prototype.isArray = function() 
	{   
		return this.constructor == Array;
	}

	Object.prototype.clone = function () 
	{
		var o = new Object(); 
		for (var property in this) 
		{
			o[property] = typeof (this[property]) == 'object' ? this[property].clone() : this[property];
		} 
		return o;
	}

	function isArray(testObject) {       
		return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
	}

/*  String:: Trim 
	Example:
	var test = "   Test   ";
	var test1 = test.ltrim();   //	returns "Test   "
	var test2 = test.rtrim();   // returns "   Test"
	var test3 = test.trim();    // returns "Test"
*/
	function trim(s)
	{
		if (typeof s != 'string') return "";
		return s.trim();
	}

	String.prototype.trim = function() {   
		return this.replace(/^\s+|\s+$/g,"");
	}
	
	String.prototype.ltrim = function() {   
		return this.replace(/^\s+/g,"");
	}
	
	String.prototype.rtrim = function() 
	{   
		return this.replace(/\s+$/g,"");
	}

/* 	HTML:: Entities : convert & < > to code
	Example:
	var tmp = '<html><head></head>';
	var safe= tmp.htmlEntities(); // Returns â€œ&lt;html&gt;&lt;head&gt;&lt;/head&gt;â€
*/
	String.prototype.htmlEntities = function () {   
		return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
	}

/*	HTML:: Entities : remove HTML tags
	Example:
	var tmp = '<a href="htpp://somespammer.com">Some Link</a>';
	var safe= tmp.stripTags(); // Returns â€œSome Linkâ€;
*/
	String.prototype.stripTags = function () {   
		return this.replace(/<([^>]+)>/g,'');
	}

/*	DOM:: GetElementByClass
	Example:
	// returns all objects with a class name of "fancyStyle"
	els=document.getElementsByClass('fancyStyle');
	// returns all the objects with a class name of "fancyStyle" for paragraphs
	els=document.getElementsByClass('fancyStyle','p');
*/
	Object.prototype.getElementByClass = function (searchClass, tag) 
	{         
		var returnArray = [];   
		tag = tag || '*';   
		var els = this.getElementsByTagName(tag);   
		var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');   
		for (var i = 0; i < els.length; i++) {      
			if ( pattern.test(els[i].className) ) {         
				returnArray.push(els[i]);      
			}   
		}   
		return returnArray;
	}

/*	Cookies::
	Example:
	// Check if cookies are allowed in this browser.
	if cookiesAllowed() {   
		alert('you can set cookies');
	} else {  
		alert("This browser doesn't allow cookies.");
	}
	// Create a cookie named myCookie with a value of 'Peanut Butter'
	// The cookie will expire in 10 days.
	setCookie('myCookie','Peanut Butter', 10);
	// Retreive the value of 'myCookie'
	var userCookie = getCookie('myCookie');
	// Delete 'myCookie'
	deleteCookie('myCookie'); 
*/
	function cookiesAllowed() {   
		setCookie('checkCookie', 'test', 1);   
		if (getCookie('checkCookie')) {      
			deleteCookie('checkCookie');      
			return true;   
		}   
		return false;
	}
	
	function setCookie(name,value,expires, options) {   
		if (options===undefined) { 
			options = {}; 
		}   
		if ( expires ) {      
			var expires_date = new Date();      
			expires_date.setDate(expires_date.getDate() + expires);   
		}   
		document.cookie = name+'='+escape( value ) +      
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) +       
		( ( options.path ) ? ';path=' + options.path : '' ) +      
		( ( options.domain ) ? ';domain=' + options.domain : '' ) +      
		( ( options.secure ) ? ';secure' : '' );
	}
		
	function getCookie( name ) {   
		var start = document.cookie.indexOf( name + "=" );   
		var len = start + name.length + 1;   
		if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) 
		{      
			return null;   
		}   
		if ( start == -1 ) return null;   
		var end = document.cookie.indexOf( ';', len );   
		if ( end == -1 ) end = document.cookie.length;   
		return unescape( document.cookie.substring( len, end ) );
	}
	
	function deleteCookie( name, path, domain ) {   
		if ( getCookie( name ) ) {
			document.cookie = name + '=' +      
			( ( path ) ? ';path=' + path : '') +      
			( ( domain ) ? ';domain=' + domain : '' ) +      
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
		}
	}

/*  CSS:: Control
	Example:
	// returns the object for the CSS class "fancyStyle"      
	fancyStyleObject=getCSSRule('fancyStyle');
	
	// applies underline to the fancyStyle class. 
	fancyStyleObject.style.textDecoration='underline'
	
	// Deletes the class "fancyStyle" unstyling any objects that used it. 
	killCSSRule('fancyStyle');
	
	// Creates a new stylesheet rule (P for paragraphs in this instance)
	newStyle=addCSSRule('p');
	
	// Gives all paragraphs blue text.
	newStyle.style.color='blue';
	
	// creates a new CSS class called 
	fancyStyle.newStyle=addCSSRule('.fancyStyle');
	
	// Gives all objects with a class of fancyStyle a green background.  
	newStyle.backgroundColor='green';
*/
	function getCSSRule(ruleName, deleteFlag) {   
		ruleName=ruleName.toLowerCase();    
		if (document.styleSheets) {
			for (var i=0; i<document.styleSheets.length; i++) {          
				var styleSheet=document.styleSheets[i];         
				var ii=0;                                       
				var cssRule=false;                               
				do {                                               
					if (styleSheet.cssRules) {                         
						cssRule = styleSheet.cssRules[ii];           
					} else {                                            
						cssRule = styleSheet.rules[ii];                
					}                                                
					if (cssRule)  {                                     
						if (cssRule.selectorText.toLowerCase()==ruleName) {                   
							if (deleteFlag=='delete') {                         
								if (styleSheet.cssRules) {                          
									styleSheet.deleteRule(ii);                     
								} else {                                             
									styleSheet.removeRule(ii);                     
								}                                                 
								return true;                                   
							} else {                                             
								return cssRule;                                
							}                                              
						}                                              
					}                                                 
					ii++;                                          
				} while (cssRule)                              
			}                                              
		}                                                 
		return false;                                  
	}                                                  
	
	function killCSSRule(ruleName) {       
		return getCSSRule(ruleName,'delete');  
	}                                         
	
	function addCSSRule(ruleName) {         
		if (document.styleSheets) {            
			if (!getCSSRule(ruleName)) {          
				if (document.styleSheets[0].addRule) {               
					document.styleSheets[0].addRule(ruleName, null,0);      
				} else {                           
					document.styleSheets[0].insertRule(ruleName+' { }', 0);      
				}            
			}             
		}                
		return getCSSRule(ruleName);   
	} 

/*	Number Formatting
	Example
var test1 = formatNumber('5123456789.25'); 
// returns 5,123,456,789.25
var test2 = formatNumber(1234.15,'$');     
// returns $1,234.15
var test3 = unformatNumber('$1,234.15');   
// returns 1234.15
*/
	function formatNumber(num,prefix){   
		prefix = prefix || '';   
		num += '';   
		var splitStr = num.split('.');   
		var splitLeft = splitStr[0];   
		var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';   
		var regx = /(\d+)(\d{3})/;   
		while (regx.test(splitLeft)) {      
			splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');   
		}   
		return prefix + splitLeft + splitRight;
	}
	
	function unformatNumber(num) {   
		return num.replace(/([^0-9\.\-])/g,'')*1;
	}

/*	AJAX:: with callback function
	Example:
	// Just a stub function we'll tell ajaxObject to call when it's done
	// callback functions get responseText, and responseStat respectively
	// in their arguments.
	function fin(responseTxt,responseStat) {  
		alert(responseStat+' - '+responseTxt);
	}
	
	// create a new ajaxObject, give it a url it will be calling and
	// tell it to call the function "fin" when its got data back from the server.
	var test1 = new ajaxObject('http://someurl.com/server.cgi',fin);    test1.update();                
	// create a new ajaxObject, give it a url and tell it to call fin when it
	// gets data back from the server.  When we initiate the ajax call we'll
	// be passing 'id=user4379' to the server.              
	var test2 = new ajaxObject('http://someurl.com/program.php',fin);    
	test2.update('id=user4379');                
	// create a new ajaxObject but we'll overwrite the callback function inside
	// the object to more tightly bind the object with the response hanlder.
	var test3 = new ajaxObject('http://someurl.com/prog.py', fin);    
	test3.callback = function (responseTxt, responseStat) {      
		// we'll do something to process the data here.      
		document.getElementById('someDiv').innerHTML=responseTxt;    
	}    
	test3.update('coolData=47&userId=user49&log=true');                 
	// create a new ajaxObject and pass the data to the server (in update) as
	// a POST method instead of a GET method.
	var test4 = new ajaxObject('http://someurl.com/postit.cgi', fin);    
	test4.update('coolData=47&userId=user49&log=true','POST'); 
*/
	function ajaxObject(url, callbackFunction) {  
		var that=this;        
		this.updating = false;  
		this.abort = function() {    
			if (that.updating) {      
				that.updating=false;      
				that.AJAX.abort();      
				that.AJAX=null;    
			}  
		}  
		this.update = function(passData,postMethod) {     
			if (that.updating) { 
				return false; 
			}    
			that.AJAX = null;                              
			if (window.XMLHttpRequest) {                    
				that.AJAX=new XMLHttpRequest();                  
			} else {                                        
				that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");    
			}                                                 
			if (that.AJAX==null) {                                   
				return false;                                   
			} else {      
				that.AJAX.onreadystatechange = function() {          
					if (that.AJAX.readyState==4) {                       
						that.updating=false;                          
						that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);                  
						that.AJAX=null;                                                 
					}                                                            
				}                                                              
				that.updating = new Date();                                    
				if (/post/i.test(postMethod)) {        
					var uri=urlCall+'?'+that.updating.getTime();        
					that.AJAX.open("POST", uri, true);        
					that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");        
					that.AJAX.send(passData);      
				} else {        
					var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime());         
					that.AJAX.open("GET", uri, true);                                     
					that.AJAX.send(null);                                               
				}                    
				return true;                                                 
			}                                                                             
		}  
		var urlCall = url;          
		this.callback = callbackFunction || function () { };
	}

/* ajax method
    @param:  url - server script name
					method - POST or GET
					asyn - true for asynchronize
					data - null for nothing, or any data to pass to the server script.  If the method
					outputObj - DOM object for data to be returned.
	Example:
	var temp = "userid=" + "12345";
	ajaxFunction("myserver.php", "GET", true, temp, document.getElementById("showdiv"), "html");
	ajaxFunction("myserver.php", "GET", true, temp, document.getElementById("textfield01"), "value");
*/
	function ajaxFunction(url, method, asyn, data, outputObj, fieldType)
	{
		var xmlHttp;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		
		if( method.toUpperCase() == "POST")
		{
			xmlHttp.onreadystatechange= function ()
			{
				stateChanged(xmlHttp, outputObj, fieldType);
			}
			xmlHttp.open("POST", url ,asyn);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", data.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.send(data);  
	
		} else if (method.toUpperCase() == "GET")
		{
			if (data==null) data = "";
			url = url + "?" + data;
			xmlHttp.onreadystatechange= function()
			{
				stateChanged(xmlHttp, outputObj, fieldType);
			}
			xmlHttp.open("GET", url ,asyn);
			xmlHttp.send(null);  
		} else
		{
			// do nothing.
		}
		
		
	}
	
	function GetXmlHttpObject()
	{
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
			if (xmlHttp.overrideMimeType) 
			{
				// set type accordingly to anticipated content type
				//http_request.overrideMimeType('text/xml');
				xmlHttp.overrideMimeType('text/html');
			 }
	
		}catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}catch (e)
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}	
		return xmlHttp;
	}
	
	function stateChanged(xmlHttp, obj, fieldType) 
	{ 
		if (xmlHttp.readyState==4)
		{ 
			if (xmlHttp.status == 200 || xmlHttp.status == 304)
			{
				
				if (obj != null)
				{				
					obj[fieldType] = xmlHttp.responseText;
				}
			} else
			{
				alert ("Error.");
			}
		}
	}


/*
	Auto Select
*/
	function autoSelect (el) {
		if(el && (el.tagName === "TEXTAREA" || (el.tagName === "INPUT" && el.type === "text"))) {
			el.select();
			return;
		}
		try
		{
			if (el && window.getSelection) { // FF, Safari, Opera
				var sel = window.getSelection();
				var range = document.createRange();
				range.selectNodeContents(el);
				sel.removeAllRanges();
				sel.addRange(range);
			} else if (el) { // IE
				document.selection.empty();
				var range = document.body.createTextRange();
				range.moveToElementText(el);
				range.select();
			}
		} catch (e)
		{
		}
	}

/* Copy text to Clipboard
	** FX has to set in client browser for permission
*/
	function copyToClipboard(s)
	{
		if( window.clipboardData && clipboardData.setData )
		{
			clipboardData.setData("Text", s);
		}
		else
		{
			try
				{
				// You have to sign the code to enable this or allow the action in about:config by changing
				user_pref("signed.applets.codebase_principal_support", true);
				netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		
				var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
				if (!clip) return;
		
				// create a transferable
				var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
				if (!trans) return;
		
				// specify the data we wish to handle. Plaintext in this case.
				trans.addDataFlavor('text/unicode');
		
				// To get the data from the transferable we need two new objects
				var str = new Object();
				var len = new Object();
		
				var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);
		
				var copytext=meintext;
		
				str.data=copytext;
		
				trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);
		
				var clipid=Components.interfaces.nsIClipboard;
		
				if (!clip) return false;
		
				clip.setData(trans,null,clipid.kGlobalClipboard);	   
			} catch (e) {}
		}
	}


/**
	Round corner. Niftycheck()
*/
	function NiftyCheck() {
	  if(!document.getElementById || !document.createElement) {
		return false;
	  }
	  var b = navigator.userAgent.toLowerCase();
	  if (b.indexOf("msie 5") > 0 && b.indexOf("opera") == -1) {
		return false;
	  }
	  return true;
	}
	
	function Rounded(elementName, sizex, sizey, sizex_b, sizey_b) {
		var bk;
		if (!NiftyCheck()) return;
		if (typeof(sizex_b) == 'undefined')
			sizex_b = sizex;
		if (typeof(sizey_b) == 'undefined')
			sizey_b = sizey;
		var v = getElements(elementName);
		var l = v.length;
		for (var i = 0; i < l; i++) {
			color = get_current_style(v[i],"background-color","transparent");
			bk = get_current_style(v[i].parentNode,"background-color","transparent");
			AddRounded(v[i], bk, color, sizex, sizey, true);
			AddRounded(v[i], bk, color, sizex_b, sizey_b, false);
		}
	}
	
	Math.sqr = function (x) {
	  return x*x;
	};
	
	function Blend(a, b, alpha) {
	
	  var ca = Array(
		parseInt('0x' + a.substring(1, 3)), 
		parseInt('0x' + a.substring(3, 5)), 
		parseInt('0x' + a.substring(5, 7))
	  );
	  var cb = Array(
		parseInt('0x' + b.substring(1, 3)), 
		parseInt('0x' + b.substring(3, 5)), 
		parseInt('0x' + b.substring(5, 7))
	  );
	  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)
				 + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)
				 + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);
	
	  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)
				 + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)
				 + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);
	}
	
	function AddRounded(el, bk, color, sizex, sizey, top) {
	  if (!sizex && !sizey)
		return;
	  var i, j;
	  var d = document.createElement("div");
	  d.style.backgroundColor = bk;
	  var lastarc = 0;
	  for (i = 1; i <= sizey; i++) {
		var coverage, arc2, arc3;
		// Find intersection of arc with bottom of pixel row
		arc = Math.sqrt(1.0 - Math.sqr(1.0 - i / sizey)) * sizex;
		// Calculate how many pixels are bg, fg and blended.
		var n_bg = sizex - Math.ceil(arc);
		var n_fg = Math.floor(lastarc);
		var n_aa = sizex - n_bg - n_fg;
		// Create pixel row wrapper
		var x = document.createElement("div");
		var y = d;
		x.style.margin = "0px " + n_bg + "px";
		x.style.height='1px';
		x.style.overflow='hidden';
		// Make a wrapper per anti-aliased pixel (at least one)
		for (j = 1; j <= n_aa; j++) {
		  // Calculate coverage per pixel
		  // (approximates circle by a line within the pixel)
		  if (j == 1) {
			if (j == n_aa) {
			  // Single pixel
			  coverage = ((arc + lastarc) * .5) - n_fg;
			}
			else {
			  // First in a run
			  arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
			  coverage = (arc2 - (sizey - i)) * (arc - n_fg - n_aa + 1) * .5;
			  // Coverage is incorrect. Why?
			  coverage = 0;
			}
		  }
		  else if (j == n_aa) {
			// Last in a run
			arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
			coverage = 1.0 - (1.0 - (arc2 - (sizey - i))) * (1.0 - (lastarc - n_fg)) * .5;
		  }
		  else {
			// Middle of a run
			arc3 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j) / sizex)) * sizey;
			arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
			coverage = ((arc2 + arc3) * .5) - (sizey - i);
		  }
		  
		  x.style.backgroundColor = Blend(bk, color, coverage);
		  if (top)
			  y.appendChild(x);
		  else
			  y.insertBefore(x, y.firstChild);
		  y = x;
		  var x = document.createElement("div");
			x.style.height='1px';
			x.style.overflow='hidden';
		  x.style.margin = "0px 1px";
		}
		x.style.backgroundColor = color;
		if (top)
			y.appendChild(x);
		else
			y.insertBefore(x, y.firstChild);
		lastarc = arc;
	  }
	  if (top)
		  el.insertBefore(d, el.firstChild);
	  else
		  el.appendChild(d);
	}

	function getElements(elementName) {
		var elements = [];
		
		elements.push(document.getElementById(elementName));
		/*
		var el = document.getElementsByTagName('DIV');  
		var regexp=new RegExp("\\b"+className+"\\b");
		for (var i = 0; i < el.length; i++) 
	
		{
			if (regexp.test(el[i].className)) 
				elements.push(el[i]);
		}
		*/
		return elements;
	}
	
	function get_current_style(element,property,not_accepted)
	{
	  var ee,i,val,apr;
	  try
	  {
		var cs=document.defaultView.getComputedStyle(element,'');
		val=cs.getPropertyValue(property);
	  }
	  catch(ee)
	  {
		if(element.currentStyle)
		{
			apr=property.split("-");
			for(i=1;i<apr.length;i++) apr[i]=apr[i].toUpperCase();
			apr=apr.join("");
			val=element.currentStyle.getAttribute(apr);
	   }
	  }
	  if((val.indexOf("rgba") > -1 || val==not_accepted) && element.parentNode)
	  {
		 if(element.parentNode != document) 
			 val=get_current_style(element.parentNode,property,not_accepted);
		 else
			 val = '#FFFFFF';
	  }
	  if (val.indexOf("rgb") > -1 && val.indexOf("rgba") == -1)
		  val = rgb2hex(val);
	  if (val.length == 4)
		  val = '#'+val.substring(1,1)+val.substring(1,1)+val.substring(2,1)+val.substring(2,1)+val.substring(3,1)+val.substring(3,1);
	  return val;
	}
	
	function rgb2hex(value)
	{
		var x = 255;
		var hex = '';
		var i;
		var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
		var array=regexp.exec(value);
		for(i=1;i<4;i++) hex += ('0'+parseInt(array[i]).toString(16)).slice(-2);
		return '#'+hex;
	}

/*
	get URL Parameters
	Example:
	http://www.abc.com/index.html?bob=123&frank=321&tom=213#top

	You want to get the value from the frank parameter so you call the javascript function as follows:

	var frank_param = gup( 'frank' );	// returns 321
*/

	function getURLParameter( name ){  
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
		var regexS = "[\\?&]"+name+"=([^&#]*)";  
		var regex = new RegExp( regexS );  
		var results = regex.exec( window.location.href );  
		if( results == null )    return "";  
		else    return results[1];
	}

/*
	Year / Month manipulation

*/

	var GET_FROM_CONSTANT = false;
	var LAST_MONTH = "";

	function getMonthStr(offset)
	{
		var month=new Array(12);
		month[0]="January";
		month[1]="February";
		month[2]="March";
		month[3]="April";
		month[4]="May";
		month[5]="June";
		month[6]="July";
		month[7]="August";
		month[8]="September";
		month[9]="October";
		month[10]="November";
		month[11]="December";
		
		var todayDate = new Date();
		
		if (offset == null && GET_FROM_CONSTANT) {
			return LAST_MONTH;
		} else if (offset != null && GET_FROM_CONSTANT) {
			var currIndex = 0;
			for (var i=0; i <month.length; i++)
			{
				if (month[i] == LAST_MONTH){
					currIndex = i;
					break;
				}
			}
			offset = (todayDate.getMonth()-1 - currIndex)+ offset;
		}
	
		if (offset == null && (!GET_FROM_CONSTANT )) offset = 1;
		var todayMonth = todayDate.getMonth();
		
		var prevMonth = todayMonth - offset;
	
		if (prevMonth < 0)
		{
			prevMonth = 12 - Math.abs(prevMonth);
		}
		return month[prevMonth];   
	}
	
	function getYearMonthStr(offset)
	{
		var month=new Array(12);
		month[0]="January";
		month[1]="February";
		month[2]="March";
		month[3]="April";
		month[4]="May";
		month[5]="June";
		month[6]="July";
		month[7]="August";
		month[8]="September";
		month[9]="October";
		month[10]="November";
		month[11]="December";
		
		var todayDate = new Date();
		
		if (offset == null && GET_FROM_CONSTANT) {
			return LAST_MONTH;
		} else if (offset != null && GET_FROM_CONSTANT) {
			var currIndex = 0;
			for (var i=0; i <month.length; i++)
			{
				if (month[i] == LAST_MONTH){
					currIndex = i;
					break;
				}
			}
			offset = (todayDate.getMonth()-1 - currIndex)+ offset;
		}
		
		if (offset == null && (!GET_FROM_CONSTANT )) offset = 1;
		var todayMonth = todayDate.getMonth();
		
		var prevMonth = todayMonth - offset;
		var year = todayDate.getFullYear();
		
		if (prevMonth < 0)
		{
			prevMonth = 12 - prevMonth;
			year--;
		}	
		return month[prevMonth] + " " + (year);	
	}
	
	function getCurrMonthStr()
	{
		return getMonthStr(0);
	}
	
	function getCurrYearStr()
	{
		var todayDate = new Date();
		return todayDate.getFullYear();
	}


