var note_trigger_tab_ob

function go_menu(targ){
	var loc=document.location.toString()
	if(loc.indexOf("?")!=-1){
		var params=loc.split("?")[1]	
	}else{
		var params=""	
	}
	if(params!=""){
		if(targ.split("?").length>1){
			targ=targ+"&"+params	
		}else{
			targ=targ+"?"+params
		}
	}
	
	document.location=pthstr+targ	
}

function call_show_note(tab_ob){
	note_trigger_tab_ob=tab_ob
	if(note_viewed==""){
		var ob=document.getElementById("note_link")
		show_note(null,ob)
	
	}
}

function note_onresize(){
	var ob=document.getElementById("note_link")
	if(browser.isIE){
		var ob_win=window.frames["note_iframe"]
		ob_win.document.location.reload()
	}
	show_note(null,ob)	
}

function close_note(){
		blank_ob.hide()
		var ob=document.getElementById("note_iframe")
		var ob_win=window.frames["note_iframe"]
		ob.style.visibility="hidden"
		

		
		if(document.removeEventListener){
			document.removeEventListener('mouseup',close_note,false)
		
		}else{
			if(document.detachEvent) {
				document.detachEvent('onmouseup',close_note,false);
			
			}
		}
		//if(ob_win.check_agreement()==0){
//			
//			if(confirm("Please confirm that you have read and understand the experimental nature of the statistics")){
//			}else{
//				if(typeof note_trigger_tab_ob!="undefined" && !!note_trigger_tab_ob){
//					ob.style.visibility="hidden"
//				}else{
//					if(document.location.toString().indexOf("/statistics.asp")!=-1){
//						document.location="index.asp"	
//					}else{
//						ob.style.visibility="hidden"
//					}
//				}
//			}
//		}else{
//			if(note_viewed==""){
//				
//				if(typeof note_trigger_tab_ob!="undefined" && !!note_trigger_tab_ob){
//					ob_win.set_redirect()
//				}
//				ob_win.call_submit()
//				note_viewed="1"
//			}else{
//				if(typeof note_trigger_tab_ob!="undefined" && !!note_trigger_tab_ob){
//					setTimeout(delay_note_trigger_change_tab,500)
//				}	
//			}
//			ob.style.visibility="hidden"
//			
//		}
}

function delay_note_trigger_change_tab(){
	note_trigger_tab_ob.change_tab()
}

function show_note(event,clickob){
	init_blank_ob()
	blank_ob.show()
	if(typeof event!="undefined" && !!event){
	if (browser.isIE){	
		var click_item=(event.srcElement);    
	}
	if (browser.isNS){
		var click_item=(event.target);
	}
	}else{
		click_item=clickob
	}
	
	var ob=document.getElementById("note_iframe")

	var content_h=findPosY(window.frames["note_iframe"].document.getElementById("close_popup"))+30
	
	ob.style.height=content_h+"px"
	
	if(true){ //(ob.style.visibility!="visible"){
		//GET ELEMENT THAT HAS BEEN CLICKED ON
		
			
			
			
		//GET LOCATION OF THE ELEMENT THAT'S BEEN CLICKED ON 
		x=findPosX(click_item)
		y=findPosY(click_item)
				
		//GET DIMENSIONS OF ELEMENT THAT'S BEEN CLICKED ON
		w=click_item.offsetWidth
		h=click_item.offsetHeight
			
		//GET PAGE PROPERTIES, DEPENDENT ON BROWSER
		//PAGE WIDTH AND HEIGHT
		if(browser.isIE){	
			page_clientWidth=(window.document.documentElement.clientWidth==0)? window.document.body.clientWidth : window.document.documentElement.clientWidth
			page_clientHeight=(window.document.documentElement.clientHeight==0)? window.document.body.clientHeight : window.document.documentElement.clientHeight
		}else{
			page_clientWidth= window.document.body.clientWidth
			page_clientHeight= window.document.body.clientHeight
		}
		//PAGE SCROLL LEFT AND SCROLLTOP
		if(browser.isIE){
			page_scrollTop=(window.document.documentElement.scrollTop==0)? window.document.body.scrollTop : window.document.documentElement.scrollTop
			page_scrollLeft=(window.document.documentElement.scrollLeft==0)? window.document.body.scrollLeft : window.document.documentElement.scrollLeft
		}else{
			page_scrollTop= window.document.body.scrollTop
			page_scrollLeft= window.document.body.scrollLeft
		}
		
		//GET BOTTOM AND RIGHT EDGES OF PAGE	
		var page_right=page_clientWidth+page_scrollLeft
		var page_bottom=page_clientHeight+page_scrollTop
				
		ob.style.position="absolute"
		ob.style.zIndex="15"
		
		//ADJUST POSITION OF BOX RELATIVE TO CLICKED ITEM
		//TOP OF BOX ALIGNS WITH BOTTOM OF CLICKED ITEM
		y=y+h
		
		//RIGHT OF BOX ALIGNS WITH LEFT OF CLICKED ITEM
		x=x-(ob.offsetWidth)
		
		//POTENTIAL RIGHT OVERLAP IS CALCULATED BY ADDING THE ADJUSTED X TO THE WIDTH OF THE POPUP AND SUBTRACTING THE PAGE_RIGHT FROM THE TOTAL
			right_overlap=(x+ob.offsetWidth)-page_right
			
			//POTENTIAL LEFT OVERLAP IS CALCULATED BY SUBTRACTING THE PAGE_SCROLLLEFT FROM THE ADJUSTED X 
			left_overlap=x-page_scrollLeft
			
			if(right_overlap>0){
				//IF THERE IS A RIGHT OVERLAP, LEFT OVERLAP CAN BE IGNORED
				left_overlap=0
				
				//THEN ADJUST THE X COORDINATE
				right_overlap+=10
				x=x-right_overlap
				ob.style.top=x+"px"
			}else{
				//IF THERE ISN'T A RIGHT OVERLAP IT CAN BE IGNORED	
				right_overlap=0
			
				if(left_overlap<0){
					//IF LEFT_OVERLAP IS NEGATIVE THE PANEL WILL NEED TO BE REPOSITIONED
					left_overlap=left_overlap-10
					x=x-left_overlap
					
					
				}
			}
			
			
			//POTENTIAL BOTTOM OVERLAP IS CALCULATED BY ADDING THE ADJUSTED Y TO THE HEIGHT OF THE POPUP AND SUBTRACTING THE PAGE_BOTTOM FROM THE TOTAL
			bottom_overlap=(y+ob.offsetHeight)-page_bottom
			
			//POTENTIAL TOP OVERLAP IS CALCULATED BY SUBTRACTING THE PAGE_SCROLLTOP FROM THE ADJUSTED Y 
			top_overlap=y-page_scrollTop

			if(bottom_overlap>0){
				//IF THERE IS A BOTTOM OVERLAP, TOP OVERLAP CAN BE IGNORED
				top_overlap=0
				
				//THEN ADJUST THE Y COORDINATE
				bottom_overlap+=10
				y=y-bottom_overlap
				ob.style.top=y+"px"
			}else{
				//IF THERE ISN'T A BOTTOM OVERLAP IT CAN BE IGNORED	
				bottom_overlap=0
				
				if(top_overlap<0){
					//IF TOP_OVERLAP IS NEGATIVE THE PANEL WILL NEED TO BE REPOSITIONED
					top_overlap=top_overlap-10
					y=y-top_overlap
					
					
				}
			}
				
		//IF CLICKED ITEM IS ROUND THEN IT MIGHT BE GOOD TO ADJUST THE POSITIONING BY A COUPLE OF PIXELS, TO MOVE IT CLOSER TO THE EDGE OF THE CIRCLE
		//y=y-3
		//x=x+3
		
		ob.style.left=x+"px"
		ob.style.top=y+"px"
		ob.style.visibility="visible"
		
		//if(typeof help_text=="undefined" || !help_text){
//				var matching_nodes=criteria_xml.selectNodes("//output[@criteria_type_ID="+criteria_type_ID+"]")
//				if(matching_nodes.length>0){
//					help_text=matching_nodes[0].getAttribute("help_text")	
//				}
//			}
		//ob.innerHTML=help_text
//		just_opened=1
		if(document.addEventListener){
			document.addEventListener('mouseup',close_note,false);
			//window.addEventListener('resize',check_close_help,false);
		}else{
			if(document.attachEvent) {
				document.attachEvent('onmouseup',close_note,false);
				//window.attachEvent('onresize',check_close_help,false);
			}
		}
		
	}else{
		
		//ob.style.visibility="hidden"
		close_note()
	}

	
}


var currentTop=0
var clickCheck=0
var timMoveID=0


window.onscroll=scrollcheck

function timescroll(){
	window.clearInterval(timMoveID)
	timMoveID=0

	scrollcheck()
}
function scrollcheck(){

	if(clickCheck==0){
		if (typeof window.pageYOffset=="undefined"){ //must be ie
			currentTop=document.body.scrollTop
		}else{
			currentTop=window.pageYOffset
	
		}
	}else{

		clickCheck=0
		if (typeof window.pageYOffset=="undefined"){ //must be ie
			document.body.scrollTop=currentTop
		}else{
		
			window.scroll(0,currentTop)
		}

	}

}

function itemClicked(){

	if (typeof window.pageYOffset=="undefined"){ //must be ie
		if(document.body.scrollTop==0){
			clickCheck=0
		}else{
			clickCheck=1
		}
	}else{

		if(window.pageYOffset==0){
		
			clickCheck=0
		}else{
			clickCheck=1
			currentTop=window.pageYOffset
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0 with scroll fix

tp=10
	lft=10
	pos=0
	
	if(typeof window.screenX =="undefined"){
	
		if(typeof window.screenTop !="undefined"){
		
			tp=window.screenTop+10
			lf=window.screenLeft+10
			pos=1
		}
	}else{
	
		tp=window.screenY+10
		lf=window.screenX+10
		pos=1
	}
	
	if(pos==1){
		if(features!=""){
			features=features+",top="+tp+",left="+lf
		}else{
			features=features+"top="+tp+",left="+lf
		}
	}
	
	
	 itemClicked()
  x=window.open(theURL,winName,features);
x.focus()
if (typeof window.pageYOffset!="undefined"){
	timMoveID=setInterval("timescroll()",50)
	}
}

function MM_openBrWindow_nopos(theURL,winName,features) { //v2.0 with scroll fix

	 itemClicked()
  x=window.open(theURL,winName,features);
x.focus()
if (typeof window.pageYOffset!="undefined"){
	timMoveID=setInterval("timescroll()",50)
	}
}

function float_page(thisone){
	
	if(typeof thisone!="undefined"){
		targ=thisone.href
		//if(targ!="javascript:;" && targ!="javascript:;" && targ.substr(0,5)!="http:" && targ.substr(0,4)!="www."){
		if(targ!="javascript:;"){
			thisone.target="floater"
			thisone.href="javascript:;"
			MM_openBrWindow(targ,"floater","status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=726,height=600",1)
			
			thisone.href=targ
			
		}
		
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
