// clear default value in forms
function doClear(theText) {
	if (theText.value == theText.defaultValue) {
		theText.value = "";
	}
}
// undo clear of default value
function undoClear(theText) {
	if (theText.value == "") {
		theText.value = theText.defaultValue;
	}
}
// show an element
function show(id) {
	if (document.getElementById) {
		var el = document.getElementById(id);
		el.style.display = "block";
	}
}
// hide an element
function hide(id) {
	if (document.getElementById) {
		var el = document.getElementById(id);
		el.style.display = "none";
	}
}
// open external links in a new window ("target" is not valid XHTML strict)
function externallinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		anchor.tabindex = i;
		if (anchor.getAttribute("href")) {
			if (anchor.getAttribute("rel") == "external")
				anchor.target = "_blank";
			else if (anchor.getAttribute("rel") == "parent")
				anchor.target = "_parent";
			else if (anchor.getAttribute("rel") == "top")
				anchor.target = "_top";
			else if (anchor.getAttribute("rel") == "popup")
                $('a[rel="popup"]').click(function(){return $.dbPopWin( $(this).attr('href'));}
				);	
		}
	}
}
// dbPopWin: db Popup Windows Plugin for JQuery - 04 Jul 08
jQuery.dbPopWin = function(url, options)
{options = jQuery.extend(
		{
			/* default options */
			dbPopWinWidth:      450,
			dbPopWinHeight:     300,
			dbPopWinTarget:     'dbPopWin',
			dbPopWinScrollbars: 'yes',
			dbPopWinResizable:  'no',
			dbPopWinMenuBar:    'no',
			dbPopWinAddressBar: 'no'
		},
		options
	);
	/* center the window by default. */
	if (!options.dbPopWinY){options.dbPopWinY = screen.height / 2 - options.dbPopWinHeight / 2;};
	if (!options.dbPopWinX){options.dbPopWinX = screen.width / 2 - options.dbPopWinWidth / 2;};
	open(
		url,
		options['dbPopWinTarget'],
		'width= '      + options.dbPopWinWidth +
		',height='     + options.dbPopWinHeight + 
		',top='        + options.dbPopWinY + 
		',left='       + options.dbPopWinX + 
		',scrollbars=' + options.dbPopWinScrollbars +
		',resizable='  + options.dbPopWinResizable +
		',menubar='    + options.dbPopWinMenuBar +
		',location='   + options.dbPopWinAddressBar
	);
	return false;
};
// jumpmenu (macromedia)
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/* TextLimit - jQuery plugin for counting and limiting characters for input and textarea fields
 * pass '-1' as speed if you don't want slow char deletion effect. (don't just put 0)
 * Example: jQuery("Textarea").textlimit('span.counter',256)
 * $Version: 2007.10.24 +r1
 * Copyright (c) 2007 Yair Even-Or
 */
jQuery.fn.textlimit=function(counter_el, thelimit, speed) {
	var charDelSpeed = speed || 15;
	var toggleCharDel = speed != -1;
	var toggleTrim = true;	
	var that = this[0];
	updateCounter();	
	function updateCounter(){jQuery(counter_el).text(thelimit - that.value.length);};	
	this.keypress (function(e){ if( this.value.length >= thelimit && e.charCode != '0' ) e.preventDefault() })
	.keyup (function(e){
		updateCounter();
		if( this.value.length >= thelimit && toggleTrim ){
			if(toggleCharDel){
				// first, trim the text a bit so the char trimming won't take forever
				that.value = that.value.substr(0,thelimit+100);
				var init = setInterval
					(function(){if(that.value.length <= thelimit){ init = clearInterval(init); updateCounter()}
					else{that.value=that.value.substring(0,that.value.length-1); jQuery(counter_el).text('trimming...  '+(thelimit - that.value.length)); };
						} ,charDelSpeed 
					);}
			else this.value = that.value.substr(0,thelimit);}
	});	
};

// return an object with key/values pairs
function objectParams(s){
	var objURL = new Object();
	// Use the String::replace method to iterate over each name-value pair in the query string.
	// For each matched query string pair, add that pair to the URL object
	s.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"), function($0, $1, $2, $3){
		objURL[$1] = $3;
	});
	return objURL;
}
