function popUp(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=250,height=400,left = 770,top = 320');");
}

function createBookmarkLink(title,url) {
	if (window.sidebar) { 
		// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title,url,"");
	} else if( window.external ) { 
		// IE Favorite
		window.external.AddFavorite(url,title); 
	} else if(window.opera && window.print) { 
		// Opera Hotlist
		return true; 
	}
}

function matchHeight(){
	var divs,contDivs,maxHeight,divHeight,d;
	// get all <div> elements in the document
	divs=document.getElementsByTagName('div');
	contDivs=[];
	// initialize maximum height value
	maxHeight=0;
	// iterate over all <div> elements in the document
	for(var i=0;i<divs.length;i++){
		// make collection with <div> elements with class attribute 'matchedheight'
		if(/\bmatchedheight\b/.test(divs[i].className)){
			d=divs[i];
			contDivs[contDivs.length]=d;
			// determine height for <div> element
			if(d.offsetHeight){
				divHeight=d.offsetHeight;
			}else if(d.style.pixelHeight){
				divHeight=d.style.pixelHeight;
			}
			// calculate maximum height
			maxHeight=Math.max(maxHeight,divHeight);
		}
	}
	if(!maxHeight || maxHeight < 20) maxHeight = 20;
	//alert(contDivs.length+' : '+maxHeight);
	// assign maximum height value to all of container <div> elements
	for(var i=0;i<contDivs.length;i++){
		contDivs[i].style.height=maxHeight+'px';
	}
}

function matchHeightByClass(classid){
	var divs,contDivs,maxHeight,divHeight,d;
	contDivs=[];
	// initialize maximum height value
	maxHeight=0;
	// iterate over all <div> elements in the document
	var divs = document.getElementsByClassName(classid);
	for (var i=0; i < divs.length; i++) {
		var d=divs[i];
		contDivs[contDivs.length]=d; // copy object to contDivs
		// determine height for <div> element
		d.style.height = 'auto';  //reset the content elements height
		if(d.offsetHeight){
			divHeight=d.offsetHeight;
		}else if(d.style.pixelHeight){
			divHeight=d.style.pixelHeight;
		}
		// calculate maximum height
		maxHeight=Math.max(maxHeight,divHeight);
	}//end for
	if(!maxHeight || maxHeight < 20) maxHeight = 20;
	//alert(contDivs.length+' : '+maxHeight);
	// assign maximum height value to all of container <div> elements
	for(var i=0;i<contDivs.length;i++){
		contDivs[i].style.height=maxHeight+'px';
	}//end for
}//end func


function setTableRowColors(){
	if (!document.getElementsByTagName) return false;
	var tables = document.getElementsByTagName("table");
	for (var i=0; i < tables.length; i++) {
		var rows = tables[i].getElementsByTagName("tr");  
		for(r = 0; r < rows.length; r++){ 
			if(r % 2 == 0){
       		rows[r].className = "r0";
			}else{
				rows[r].className = "r1";
			}//end if
		}//end for
	}//end for
}//end func

function doPopupImage() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		if (links[i].className.match("popupimage")) {
			//add mag icon
			oMag = document.createElement("div");
			oMag.className = "mag";
			links[i].appendChild(oMag);
			//add onclick code
			links[i].onclick = function() {
				var w = this.getAttribute('w');
				var h = this.getAttribute('h');
				//alert('w='+w+' h='+h);
				window.open(this.href,'','toolbar=0,resizable=1,menubar=0,scrollbars=1,width='+w+',height='+h);
				return false;
			}//end func
		}//end if
	}//end if
}//end func

function doTextareaLimits() {
	if (!document.getElementsByTagName) return false;
	var aTextareas = document.getElementsByTagName("textarea");
	for (var i=0; i < aTextareas.length; i++) {
		if (aTextareas[i].getAttribute('maxchars')) {
			oTextarea = aTextareas[i];
			oTextarea.onkeyup = function(){
				this.iMaxchars = parseInt(this.getAttribute('maxchars'));
				if(this.value.length > this.iMaxchars) this.value = this.value.substr(0, this.iMaxchars);	
				var iRemain = this.iMaxchars - this.value.length;
				this.oCtr.innerHTML = ' (' + iRemain +') chars remaining';
				};
	
			var oHint = document.getElementsByClassName('hint',$('container_' + oTextarea.id))[0];
			if(oHint){
				oTextarea.oCtr = document.createElement("span");
				var iRemain = parseInt(oTextarea.getAttribute('maxchars')) - oTextarea.value.length;
				oTextarea.oCtr.innerHTML = ' (' + iRemain +') chars remaining';
				oHint.appendChild(oTextarea.oCtr);
			}

		}//end if
	}//end if
}//end func


var dbg = {
	init: function() {
		var oBody = document.getElementsByTagName("body")[0];
		oDebug = document.createElement("div");
		oDebug.id = 'debug';
		oDebug.style.position='absolute';
		oDebug.rememberPos = dbg.storePos;
		oBody.appendChild(oDebug);
		dbg.clr();
		//Check to see if we have cookieLib, attempt to load it if not found
		this.cookieLib = true;
		if(typeof cookieLib=='undefined' || typeof cookieLib=='Scriptaculous'){
			dbg.p('cookieLib OR Scriptaculous not found');
			this.cookieLib = false;
		}
		if(this.cookieLib){
			var posData = cookieLib.get('debugposdata');
			if(posData){
				//new Effect.Move(oDebug,{ x: posData.split(",")[0], y: posData.split(",")[1], mode: 'absolute',starteffect:null,reverteffect:null,endeffect:null});
				new Draggable('debug',{revert:this.storePos,handle:this.firstChild,starteffect:null,reverteffect:null,endeffect:null}); //scriptaculous
				oDebug.style.left = posData.split(",")[0] + 'px';
				oDebug.style.top = posData.split(",")[1] + 'px';
			}
		}
	},
	h: function(str){
		//bold header
		var oDbg = $('debug');
		if(oDbg) oDbg.innerHTML += '<h2>' + str + '</h2>';
	},
	p: function(str){
		//paragraph
		var oDbg = $('debug');
		if(oDbg) oDbg.innerHTML += '<p>' + str + '</p>';
	},
	s: function(str){
		//string
		var oDbg = $('debug');
		if(oDbg) oDbg.innerHTML += str;
	},
	clr: function(){
		var oDebug = $('debug');
		oDebug.innerHTML = '<h1>Debug</h1>';
		var btnClr = document.createElement("a");
		//btnClr.onclick = function(){alert('yo');};
		//btnClr.onclick = dbg.clr;
		btnClr.innerHTML = 'CLR';
		btnClr.href = 'javascript:dbg.clr();';
		oDebug.firstChild.appendChild(btnClr);
	},
	storePos: function(){
		//store current position in a cookie for later recall
		//Keeps the debug panel where you left it!
		if(this.cookieLib){
			cookieLib.set('debugposdata',Position.cumulativeOffset($('debug')).toString());
		}
	}
};


/***** WINDOW ONLOADER ****/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(function() {
  /* more code to run on page load */ 
	//dbg.init();
	if(document.getElementsByTagName){
		matchHeightByClass('mhcolumns');
	}
	doTextareaLimits();
	//doPopupGeneral();
});