function e(id) {return document.getElementById(id);}

function isDefined(variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}


function ImageOn(which) {
	return which + '-on.png';
	}
function ImageOff(which) {
	return which + '-off.png';
	}
	
function copyText(theSel) {
	if (!document.all) return; // IE only
	theForm = theSel.form;
	theForm.copyArea.value=theSel.options[theSel.selectedIndex].value;
	r=theForm.copyArea.createTextRange();
	r.select();
	r.execCommand('copy');
	} 
	
function createCookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}

function getSelected(ob) { 
	/*
	selected = new Array(); 
	for (var i = 0; i < ob.options.length; i++) if (ob.options[ i ].selected) selected.push(ob.options[ i ].value);
	return selected;
	*/
	selected = '';
	for (var i = 0; i < ob.options.length; i++) if (ob.options[ i ].selected) selected = selected + ',' + ob.options[ i ].value;
	return selected;
	}
	
function insertBookmarks() {
	document.write('<a href="http://del.icio.us/post?url='+window.location+'&amp;title='+document.title+'" title="del.icio.us" rel="nofollow" ><img src="/Assets/delicious.png" alt="del.icio.us" title="del.icio.us" /></a><a href="http://digg.com/submit?phase=2&amp;url='+window.location+'&amp;title='+document.title+'"" title="digg" rel="nofollow" ><img src="/Assets/digg.png" alt="digg" title="digg" /></a><a href="http://www.facebook.com/share.php?u='+window.location+'"" title="facebook" rel="nofollow" ><img src="/Assets/facebook.png" alt="facebook" title="facebook" /></a><a href="http://www.newsvine.com/_tools/seed&amp;save?u='+window.location+'&amp;h='+document.title+'"" title="NewsVine" rel="nofollow" ><img src="/Assets/newsvine.png" alt="NewsVine" title="NewsVine" /></a><a href="http://reddit.com/submit?url='+window.location+'&amp;title='+document.title+'"" title="Reddit" rel="nofollow" ><img src="/Assets/reddit.png" alt="Reddit" title"Reddit" /></a><a href="http://tailrank.com/share/?text=&amp;link_href='+window.location+'&amp;title='+document.title+'"" title="TailRank" rel="nofollow" ><img src="/Assets/tailrank.png" alt="TailRank" title="TailRank" /></a><a href="http://technorati.com/faves?add='+window.location+'" title="'+document.title+'"" rel="nofollow" ><img src="/Assets/technorati.png" alt="Technorati" title="Technorati"/></a><a href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+window.location+'&amp;='+document.title+'"" title="YahooMyWeb" rel="nofollow" ><img src="/Assets/yahoomyweb.png" alt="YahooMyWeb" title="YahooMyWeb" /></a>');
	}
	
function replaceChars(entry,inStr,outStr) {
	temp = "" + entry;

	while (temp.indexOf(inStr)>-1) {
		pos= temp.indexOf(inStr);
		temp = "" + (temp.substring(0, pos) + outStr + temp.substring((pos + inStr.length), temp.length));
		}
	return temp;
	}

function slideOpen(id) {
	var element = document.getElementById(id);
	Effect.toggle(element,'slide');
	}
function editDesc(id) {
	}
function editModule(id) {
	}

function setGroupMgmtAction(action) {
	var obj = document.getElementById('form_GroupMgmt');
	obj.MGMT_ACTION.value = action;
	}
function setEventAction(action) {
	var obj = document.getElementById('form_GroupMgmt');
	obj.EVENT_ACTION.value = action;
	}
	
function popup(url,h,w) {
	var load = 	window.open(url,'','scrollbars=yes,menubar=no,height='+h+',width='+w+',resizable=yes,toolbar=no,location=no,status=no');
	return false;
	}

function toggleDisplay(nr) {
	if (document.layers) {
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
		}
	else if (document.all)	{
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
		}
	else if (document.getElementById) {
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
		}
	}



function createMarker(point,icon,content) {
  var marker = new GMarker(point, icon);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(content);
  });
  return marker;
}

function doFormAction(formID,task) {
	var obj = document.getElementById(formID);
	obj.task.value = task;
	obj.submit();
	}
function setWindowStatus(msg)
	{
	if (msg) window.status=msg;
	else window.status='RinkTime.com';
	}	
	
function NumbersOnly(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	/*
	http://www.asciitable.com/
	if the key is the:
		8:		backspace (allow for editing)
		45:		dash (allow for zip+4 or phone numbers)
		9:		tab key (allow for form navigation)
		48-57:	any number 0-9
		46:		period (decimal place)
		37,39:	Left/Right Arrow
	then allow
	*/
	if (unicode!=8 && unicode!=45 && unicode!=9 && (unicode<48||unicode>57) && unicode!=46 && unicode!=37 && unicode!=39 ) { 
		return false //otherwise, disable key press
		}
	}

function NumbersLettersOnly(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	/*
	http://www.asciitable.com/
	if the key is the:
		8:		backspace (allow for editing)
		45:		dash (allow for zip+4 or phone numbers)
		9:		tab key (allow for form navigation)
		48-57:	any number 0-9
		46:		period (decimal place)
		37,39:	Left/Right Arrow
	then allow
	*/
	if (unicode!=8 && unicode!=45 && unicode!=9 && (unicode<48||unicode>57) && (unicode<65||unicode>90) && (unicode<97||unicode>122) && unicode!=46 && unicode!=37 && unicode!=39 ) { 
		return false //otherwise, disable key press
		}
	}
	
function OpenCalendar(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=425,height=180,left = 125,top = 262.5');");
	}

function OpenContact(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=425,height=180,left = 125,top = 262.5');");
	}

	
/* ---------------------------------------------------------------------------------
START: Move option items between two selects 
---------------------------------------------------------------------------------*/
/* Compare two options within a list by VALUES -*/
function compareOptionValues(a, b) { 
	/* Radix 10: for numeric values -*/
	/* Radix 36: for alphanumeric values -*/
	var sA = parseInt( a.value, 36 );  
	var sB = parseInt( b.value, 36 );  
	return sA - sB;
	}

/* Compare two options within a list by TEXT -*/
function compareOptionText(a, b) { 
	/* Radix 10: for numeric values -*/
	/* Radix 36: for alphanumeric values -*/
	var sA = parseInt( a.text, 36 );  
	var sB = parseInt( b.text, 36 );  
	return sA - sB;
	}

/* Dual list move function -*/
function moveDualList( srcList, destList, moveAll ) {
	/* Do nothing if nothing is selected -*/
	if (( srcList.selectedIndex == -1 ) && ( moveAll == false )) {
		return;
		}
	newDestList = new Array( destList.options.length );
	var len = 0;

	for( len = 0; len < destList.options.length; len++ ) {
		if ( destList.options[ len ] != null ) {
				newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
				}
			}
	for( var i = 0; i < srcList.options.length; i++ ) { 
		if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) ) {
			/*- Statements to perform if option is selected -*/
			/* Incorporate into new list -*/
			newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected/* , srcList.options[i].selected -*/ );
			len++;
			}
		}
	/* Sort out the new destination list -*/
	newDestList.sort( compareOptionValues );   /*  BY VALUES -*/

	/* newDestList.sort( compareOptionText );   // BY TEXT -*/
	/* Populate the destination with the items from the new array -*/
	for ( var j = 0; j < newDestList.length; j++ ) {
		if ( newDestList[ j ] != null ) {
			destList.options[ j ] = newDestList[ j ];
			}
		}
	/* Erase source list selected elements -*/
	for( var i = srcList.options.length - 1; i >= 0; i-- ) { 
		if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) ) {
			/* Erase Source -*/
			/* 
			//srcList.options[i].value = "";
			//srcList.options[i].text  = "";
			-*/
			srcList.options[i]       = null;
			}
		}
	} /* End of moveDualList() -*/

	function placeInHidden(delim, selStr, hidStr) {
	  var selObj = document.getElementById(selStr);
	  var hideObj = document.getElementById(hidStr);
	  if (selObj == null) return;
	  hideObj.value = '';
	  for (var i=0; i<selObj.options.length; i++) {
	    hideObj.value = hideObj.value ==
	      '' ? selObj.options[i].value : hideObj.value + delim + selObj.options[i].value;
	  }
	}
/* ---------------------------------------------------------------------------------
END: Move option items between two selects 
---------------------------------------------------------------------------------*/

function formatNumber(inputValue)
{

var num = new NumberFormat();
num.setInputDecimal('.');
num.setNumber(inputValue);
num.setPlaces('2', false);
num.setCurrencyValue('$');
num.setCurrency(true);
num.setCurrencyPosition(num.LEFT_OUTSIDE);
num.setNegativeFormat(num.LEFT_DASH);
num.setNegativeRed(false);
num.setSeparators(true, ',', ',');
return num.toFormatted();
}

// mredkj.com
function NumberFormat(num, inputDecimal)
{
this.VERSION = 'Number Format v1.5.4';
this.COMMA = ',';
this.PERIOD = '.';
this.DASH = '-'; 
this.LEFT_PAREN = '('; 
this.RIGHT_PAREN = ')'; 
this.LEFT_OUTSIDE = 0; 
this.LEFT_INSIDE = 1;  
this.RIGHT_INSIDE = 2;  
this.RIGHT_OUTSIDE = 3;  
this.LEFT_DASH = 0; 
this.RIGHT_DASH = 1; 
this.PARENTHESIS = 2; 
this.NO_ROUNDING = -1 
this.num;
this.numOriginal;
this.hasSeparators = false;  
this.separatorValue;  
this.inputDecimalValue; 
this.decimalValue;  
this.negativeFormat; 
this.negativeRed; 
this.hasCurrency;  
this.currencyPosition;  
this.currencyValue;  
this.places;
this.roundToPlaces; 
this.truncate; 
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF; 
this.setSeparators = setSeparatorsNF; 
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF; 
this.setNegativeRed = setNegativeRedNF; 
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF; 
this.setCurrencyPosition = setCurrencyPositionNF; 
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.moveDecimalRight = moveDecimalRightNF;
this.moveDecimalLeft = moveDecimalLeftNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.expandExponential = expandExponentialNF;
this.getZeros = getZerosNF;
this.moveDecimalAsString = moveDecimalAsStringNF;
this.moveDecimal = moveDecimalNF;
this.addSeparators = addSeparatorsNF;
if (inputDecimal == null) {
this.setNumber(num, this.PERIOD);
} else {
this.setNumber(num, inputDecimal); 
}
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH); 
this.setNegativeRed(false); 
this.setCurrency(false); 
this.setCurrencyPrefix('$');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num, inputDecimal)
{
if (inputDecimal != null) {
this.setInputDecimal(inputDecimal); 
}
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.COMMA;
if (decimal == null) decimal = this.PERIOD;
if (separator == decimal) {
this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
} else {
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.COMMA, this.PERIOD);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp
}
function setPlacesNF(p, tr)
{
this.roundToPlaces = !(p == this.NO_ROUNDING); 
this.truncate = (tr != null && tr); 
this.places = (p < 0) ? 0 : p; 
}
function addSeparatorsNF(nStr, inD, outD, sep)
{
nStr += '';
var dpos = nStr.indexOf(inD);
var nStrEnd = '';
if (dpos != -1) {
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
nStr = nStr.substring(0, dpos);
}
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + sep + '$2');
}
return nStr + nStrEnd;
}
function toFormattedNF()
{	
var pos;
var nNum = this.num; 
var nStr;            
var splitString = new Array(2);   
if (this.roundToPlaces) {
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum)); 
} else {
nStr = this.expandExponential(Math.abs(nNum)); 
}
if (this.hasSeparators) {
nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue);
} else {
nStr = nStr.replace(new RegExp('\\' + this.PERIOD), this.decimalValue); 
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
} else if (this.currencyPosition == this.LEFT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0) {
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getZerosNF(places)
{
var extraZ = '';
var i;
for (i=0; i<places; i++) {
extraZ += '0';
}
return extraZ;
}
function expandExponentialNF(origVal)
{
if (isNaN(origVal)) return origVal;
var newVal = parseFloat(origVal) + ''; 
var eLoc = newVal.toLowerCase().indexOf('e');
if (eLoc != -1) {
var plusLoc = newVal.toLowerCase().indexOf('+');
var negLoc = newVal.toLowerCase().indexOf('-', eLoc); 
var justNumber = newVal.substring(0, eLoc);
if (negLoc != -1) {
var places = newVal.substring(negLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
} else {
if (plusLoc == -1) plusLoc = eLoc;
var places = newVal.substring(plusLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
}
newVal = justNumber;
}
return newVal;
} 
function moveDecimalRightNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, false);
} else {
newVal = this.moveDecimal(val, false, places);
}
return newVal;
}
function moveDecimalLeftNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, true);
} else {
newVal = this.moveDecimal(val, true, places);
}
return newVal;
}
function moveDecimalAsStringNF(val, left, places)
{
var spaces = (arguments.length < 3) ? this.places : places;
if (spaces <= 0) return val; 
var newVal = val + '';
var extraZ = this.getZeros(spaces);
var re1 = new RegExp('([0-9.]+)');
if (left) {
newVal = newVal.replace(re1, extraZ + '$1');
var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');		
newVal = newVal.replace(re2, '$1$2.$3');
} else {
var reArray = re1.exec(newVal); 
if (reArray != null) {
newVal = newVal.substring(0,reArray.index) + reArray[1] + extraZ + newVal.substring(reArray.index + reArray[0].length); 
}
var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
newVal = newVal.replace(re2, '$1$2$4.');
}
newVal = newVal.replace(/\.$/, ''); 
return newVal;
}
function moveDecimalNF(val, left, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimalAsString(val, left);
} else {
newVal = this.moveDecimalAsString(val, left, places);
}
return parseFloat(newVal);
}
function getRoundedNF(val)
{
val = this.moveDecimalRight(val);
if (this.truncate) {
val = val >= 0 ? Math.floor(val) : Math.ceil(val); 
} else {
val = Math.round(val);
}
val = this.moveDecimalLeft(val);
return val;
}
function preserveZerosNF(val)
{
var i;
val = this.expandExponential(val);
if (this.places <= 0) return val; 
var decimalPos = val.indexOf('.');
if (decimalPos == -1) {
val += '.';
for (i=0; i<this.places; i++) {
val += '0';
}
} else {
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++) {
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
newVal = val + '';
var isPercentage = false;
if (newVal.indexOf('%') != -1) {
newVal = newVal.replace(/\%/g, '');
isPercentage = true; 
}
var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)eE]', 'g');	
newVal = newVal.replace(re, '');
var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
var treArray = tempRe.exec(newVal); 
if (treArray != null) {
var tempRight = newVal.substring(treArray.index + treArray[0].length); 
newVal = newVal.substring(0,treArray.index) + this.PERIOD + tempRight.replace(tempRe, ''); 
}
if (newVal.charAt(newVal.length - 1) == this.DASH ) {
newVal = newVal.substring(0, newVal.length - 1);
newVal = '-' + newVal;
}
else if (newVal.charAt(0) == this.LEFT_PAREN
&& newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN) {
newVal = newVal.substring(1, newVal.length - 1);
newVal = '-' + newVal;
}
newVal = parseFloat(newVal);
if (!isFinite(newVal)) {
newVal = 0;
}
if (isPercentage) {
newVal = this.moveDecimalLeft(newVal, 2);
}
return newVal;
}
