


var debug_notice = false;
function debug(i,notice){
	if(!notice) notice = true;

	if(window.console.firebug){
		console.debug(i);
		if(notice && !debug_notice){
			var sp1 = document.createElement('div');
			sp1.setAttribute("id", "console_error_div");
			var sp1_content = document.createTextNode('Javascript Debug');
			sp1.appendChild(sp1_content);
			if(sp2 = document.body.firstChild){ //make sure there is a container div layer ie: <div id="container"></div>
				sp2.parentNode.insertBefore(sp1,sp2);

				// set the style to the new layer
				sp1.style.position = 'fixed';
				sp1.style.top = '0';
				sp1.style.left = window.innerWidth/2 - 50 +'px';
				sp1.style.fontSize = '10px';
				sp1.style.fontWeight = 'bold';
				sp1.style.color = '#FFF';
				sp1.style.backgroundColor = 'red';
				sp1.style.fontFamily = 'verdana';
				sp1.style.padding = '3px';
				sp1.style.zIndex = '100000';
			}
			debug_notice = true;
		}
		return true;
	}
	return false;
}

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}



function MM_showHideLayers() { //v3.0

var i,p,v,obj,args=MM_showHideLayers.arguments;

for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }

obj.visibility=v; }

}



function MM_displayLayers() { //v3.0

var i,p,v,obj,args=MM_displayLayers.arguments;

for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v='hide')?'none':v; }

obj.display=v; }

}


set_horz_scroll = function(){
	dim = document.viewport.getDimensions();
	w = dim.width;
	h = dim.height;
	if(w <= 923){
		$('body-id').setStyle({
		  'overflowX': 'visible'
		});
	}else{
		$('body-id').setStyle({
		  'overflowX': 'hidden'
		});
	}

}
window.onresize = set_horz_scroll;


function findPos(obj) {
	var curleft = curtop = 0;
	if(obj){
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
		return [curleft,curtop];
	}else{
		return false;
	}

}


function check_all(class_name, flag) {
	checks = $$('input[class="'+class_name+'"]');
	if(typeof(checks)=="object"){
		checks.each(function(s) {
			$(s).checked = flag;
		});
	}
}

function is_numeric( value ){
	return isFinite( (value * 1.0) );
}



function textCounter(field) {
	maxlimit = 500;
	if ($(field).value.length > maxlimit){ // if too long...trim it!
		$(field).value = $(field).value.substring(0, maxlimit);
	}
	t = $(field).id+'_count';
	$(t).update(maxlimit - $(field).value.length);
}

/*------------------- IS NUMERIC for text form feilds-------------------------------*/

//how to use: onkeypress="return numbersonly(this, event)"

function numbersonly(myfield, e, dec){
	var key;
	var keychar;

	if (window.event){
		key = window.event.keyCode;
	}else if (e){
		key = e.which;
	}else{
		return true;
	}

	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ){
		return true;
	}else if ((("0123456789").indexOf(keychar) > -1)) {// numbers
		return true;
	}else if (dec && (keychar == ".")) {  // decimal point jump
		myfield.form.elements[dec].focus();
		return false;
	}else{
		return false;
	}
}

function num_letter_only(myfield, e, dec){
	var illegalChars = /\W/; // allow letters, numbers, and underscores
	var key;
	var keychar;

	if (window.event){
		key = window.event.keyCode;
	}else if (e){
		key = e.which;
	}else{
		return true;
	}

	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ){
		return true;
	}else if (!illegalChars.test(keychar)) {// numbers
		return true;
	}else if (dec && (keychar == ".")) {  // decimal point jump
		myfield.form.elements[dec].focus();
		return false;
	}else{
		return false;
	}


}


function autojump(field, e){  //Must have a maxLength set to use this function
	key = get_key_code(e);
	n = $(field).nextSiblings();
	if(key==46 || key==8 || key==9 || key==16 || key==37 || key==39){
		return false;
	}else{
		if($(field).value.length >= $(field).maxLength){
			$(n[0]).select();
		}
	}

}

function get_key_code(e){
	var key;
	var keychar;

	if (window.event){
		key = window.event.keyCode;
	}else if (e){
		key = e.which;
	}else{
		return true;
	}

	keychar = String.fromCharCode(key);
	return key;
}


function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (
			aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return unescape(strReturn);
}

function popup(url,x,y) {

	xMax = screen.width;
	yMax = screen.height;

	var xOffset = (xMax - x)/2, yOffset = (yMax - y)/2;

	windowHandle = window.open(url,'','top='+yOffset+',left='+xOffset+',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+x+'px,height='+y+'px');
}

function urlencode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}

function urldecode(str) {
	str = str.replace('+', ' ');
	str = unescape(str);
	return str;
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function addslashes(str) {
	//str=str.replace(/\'/g,'\\\'');
	//str=str.replace(/\"/g,'\\"');
	//str=str.replace(/\\/g,'\\\\');
	//str=str.replace(/\0/g,'\\0');
	//return str;
	return str.replace(/(["'\\])/g, "\\$1").replace(/\0/g, "\\0");
}

function stripslashes(str) {
	//str=str.replace(/\\'/g,'\'');
	//str=str.replace(/\\"/g,'"');
	//str=str.replace(/\\\\/g,'\\');
	//str=str.replace(/\\0/g,'\0');
	//return str;
	return str.replace(/\\0/g, '\0').replace(/\\(.)/g, '$1');
}