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; }

}

MM_preloadImages('/images/login_dropdown_bak.png','/images/nav7_logout.png');

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 change_file(){
	if($('mainfile').value != '' || file_temp != $('mainfile').value){
		s = $('mainfile').value;
		if(navigator.userAgent.indexOf("Windows") > -1){
			t = '\\';
		}else{
			t = '/';
		}
		s = s.substring(s.lastIndexOf(t)+1);
		if(s.substring(s.length-3) == 'doc'){
			i = 'word_ico';
		}else if(s.substring(s.length-3) == 'pdf'){
			i = 'pdf_ico';
		}else if(s.substring(s.length-3) == 'gif' || s.substring(s.length-3) == 'jpg' || s.substring(s.length-3) == 'png' || s.substring(s.length-3) == 'jpeg'){
			i = 'icon_jpg';
		}else{
			i = 'text_ico';
		}
		$('file_selected').update('<img src="/images/'+i+'.gif" border="0" align="top" style="margin:-3px 3px 0 0;"> <strong>'+ s +'</strong><a href="javascript:;" onclick="reset_file(); return false;"><img src="/images/article_close_bt.gif" width="12" height="12" border="0" align="top" style="margin:1px 0 0 5px"></a>');
		file_temp = $('mainfile').value;
	}
}

function reset_file(){
	$('main_file_span').update('<input type="file" name="mainfile" id="mainfile" class="flush-right" onchange="change_file();" style="width:auto;" align="right" />');
	$('file_selected').update('no file selected');
}


function textCounter(field) {
	maxlimit = 150;
	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);
}
