var loading_text = '<b>Please wait. Loading...</b> <img src="/images/indicator.gif" />'
var current_pm_id = 0;
var current_z = 2000;
var panelheight;
var panelwidth;
var header_height = 35;
var toolbar_height = 40;
var currentPresentationArray;
var currentPresentationIndex;
var currentPresentationId;

var currentCODArray;
var currentCODIndex;
var currentCODId;

var currentVideoId;
var currentCaseId;

var tabs;


function detectHeight() {
        var wh = 0;
        if (typeof(window.innerHeight)=="number") {
                wh = window.innerHeight;
        }
        else {
                if (document.documentElement && document.documentElement.clientHeight) {
                        wh = document.documentElement.clientHeight;
                }
                else {
                        if (document.body && document.body.clientHeight) {
                                wh = document.body.clientHeight;
                        }
                }
        }
        return wh;

} 


function detectWidth() {
        var wh = 0;
        if (typeof(window.innerWidth)=="number") {
                wh = window.innerWidth;
        }
        else {
                if (document.documentElement && document.documentElement.clientWidth) {
                        wh = document.documentElement.clientWidth;
                }
                else {
                        if (document.body && document.body.clientWidth) {
                                wh = document.body.clientWidth;
                        }
                }
        }
        return wh;

} 

var adjustWidth = 60;


function initPage(){
	

	//alert(document.getElementById('layout').style.height);

	var layout_height = (detectHeight());
	panelheight = layout_height - header_height ;
	panelwidth = detectWidth()-5;
	//alert('set panelwidth: ' + panelwidth);
}

function executeJavascript(divid){
			//alert('execute do');
			//alert(divid);
			try{
			var d=document.getElementById(divid).getElementsByTagName("script");
			
			for(var x=0;x<d.length;x++) {
				//with(window) {
					//alert(d[x]);
					eval(d[x].text);
				//}// end with
			}// end for		
			}
			catch(e) {}
			
}




function resizePresentationView(target,h,w){
	
	//pad th width by 10
	w = w -10;
	
	newH = (h - toolbar_height).toFixed(2);

	
	
	newW = (newH * 1.33).toFixed(2);
	
	if(newW > w){newW = w; newH = (newW * .75);}
	//alert('w: ' + w + ' newW: ' + newW);
	
	
	newX = ((w-newW)/2).toFixed(2);
	
	//alert('newX: ' + newX.toFixed(2));
	document.getElementById(target).style.left = newX + 'px';
	document.getElementById(target).style.width = newW + 'px';
	document.getElementById(target).style.height = newH + 'px';
	
// resize the background	
	//document.getElementById(target + 'BG').style.left = newX + 'px';
	document.getElementById(target + 'BG').style.width = newW + 'px';
	document.getElementById(target+ 'BG').style.height = newH + 'px';
	
// resize the ppt	
	//document.getElementById(target + 'PPT').style.left = newX + 'px';
	document.getElementById(target + 'PPT').style.width = newW + 'px';
	document.getElementById(target+ 'PPT').style.height = newH + 'px';	
	
	
// resize the layers	
	//document.getElementById(target + 'LAYERS').style.left = newX + 'px';
	document.getElementById(target + 'LAYERS').style.width = newW + 'px';
	document.getElementById(target+ 'LAYERS').style.height = newH + 'px';		
	
	
	//resize the tools
	
	document.getElementById(target+ 'TOOLS').style.left = newX + 'px';
	document.getElementById(target+ 'TOOLS').style.width = newW + 'px';
	document.getElementById(target+ 'TOOLS').style.height = toolbar_height + 'px';
	document.getElementById(target+ 'TOOLS').style.display='';

	
	
	 width_delta = (newW / 800).toFixed(2);
	 height_delta = (newH /600).toFixed(2);

	//showSlide(ps_id)
	//getResizeBuild(pm_id,ps_id,newW,newH,width_delta,height_delta,'N',target);
	
	
}



function presentationFullScreen(pm_id,ps_id){
				
				
	var id = 'fullscreen_' + pm_id;
	var fullscreenlayer = document.createElement('div');
	fullscreenlayer.setAttribute('id',id);
	var temp_style = 'position:absolute;z-index:9;width:' + detectWidth() + 'px; height:' + detectHeight() + 'px;  top:0px; left:0px; background: #FFFFFF;';
	fullscreenlayer.style.cssText= temp_style;
	fullscreenlayer.setAttribute('style',temp_style);				
	
	document.body.appendChild(fullscreenlayer);	
	
	
	//document.getElementById(id).innerHTML = '<a href="Javascript:removeFullScreen(' + id + ');">CLOSE</a>';
	
	
		var url = 'fullscreenDisplayPanel.cfm?ps_id=' + ps_id + '&pm_id=' + pm_id;
	
	 AjaxRequest.get(
		    {
		      'url':url
		      ,'onSuccess':function(req){
			  		
					document.getElementById(id).innerHTML = req.responseText;
					executeJavascript(id);

					}
		    }
		  );
}


function removeFullScreen(target){
	document.body.removeChild(target);	
	
}

//function drawPresentationBackground(bg_id, bg_url, bgtarget, bg_frametoplay){
	//alert("drawbg");
	//drawFlashBG(bgtarget,bg_url,bg_frametoplay, bg_id);
	
//}





function getPresentationAnimations(target,ps_id,animtarget){
	
	var url = 'slideanimations.cfm?ps_id=' + ps_id + "&animtarget=" + animtarget;
	
	 AjaxRequest.get(
		    {
		      'url':url
		      ,'onSuccess':function(req){
			  		
					document.getElementById(target).innerHTML = req.responseText;
					executeJavascript(target);

					}
		    }
		  );
	
}


function loadCommunityContent(atm_code){
	try{
		$('##JT, ##JT_arrow_left, ##JT_arrow_right').hide().remove();
	} catch(e){}
	var url = 'communities_content.cfm?atm_code=' + atm_code + '&height=' + communitypanel.getSize().height;
	communitypanel.load({url:url, scripts:true});

}


function showPresentation(pm_id,ps_id,em_public_id){
		var url = 'presentation.cfm?pm_id=' + pm_id + "&ps_id=" + ps_id + '&em_public_id=' + em_public_id;
		tabs.setActiveTab('tab_presentation');
		tabs.getItem('tab_presentation').load({url:url, scripts:true});
		//tabs.load({url: 'presentation.cfm?height=' + tabs.getInnerHeight(), scripts:true});
	
}

/*

function presentationSearch(target,searchtype,dorefresh,sort,sortorder,sortfield,atm_code,filter,fPoster,fEducation){
	
	var sendheight = document.getElementById(target).style.height.split("px")[0];
	//alert(sendheight);
	document.getElementById(target).innerHTML = '<b>Searching...</b> <img src="/images/indicator.gif" />'
	
	//alert(sendheight);
	var url="searchResults.cfm?target=" + target + "&searchtype=" + searchtype + "&dorefresh=" + dorefresh + "&sort=" + sort + "&sortorder=" + sortorder + "&sortfield=" + sortfield + "&atm_code="+atm_code +"&height=" +sendheight + "&filter=" + filter + "&fPoster=" +fPoster + "&fEducation=" + fEducation ;
	 AjaxRequest.get(
		    {
		      'url':url
		      ,'onSuccess':function(req){
			  		document.getElementById(target).innerHTML = req.responseText;
					executeJavascript(target);

					}
		    }
		  );	

}

function videoSearch(target,searchtype,dorefresh,sort,sortorder,sortfield,atm_code,filter,fPoster,fEducation){
	
	var sendheight = document.getElementById(target).style.height.split("px")[0];
	//alert(sendheight);
	document.getElementById(target).innerHTML = '<b>Searching...</b> <img src="/images/indicator.gif" />'
	
	//alert(sendheight);
	var url="videoSearchResults.cfm?target=" + target + "&searchtype=" + searchtype + "&dorefresh=" + dorefresh + "&sort=" + sort + "&sortorder=" + sortorder + "&sortfield=" + sortfield + "&atm_code="+atm_code +"&height=" +sendheight + "&filter=" + filter + "&fPoster=" +fPoster + "&fEducation=" + fEducation ;
	 AjaxRequest.get(
		    {
		      'url':url
		      ,'onSuccess':function(req){
			  		document.getElementById(target).innerHTML = req.responseText;
					executeJavascript(target);

					}
		    }
		  );	

}

*/


function doAdvanceSlide(form,delta,ps_id){
	
		//try catch for the popups
		try{
		//alert(sortfield);
		
		//alert(delta);
		
		
		if(form.delta.value != undefined){
			form.delta.value = delta;
		}
		
		var test = document.getElementById(form.loadtarget.value);

		if(form.loadtarget.value.length > 0){
			document.getElementById(form.loadtarget.value).innerHTML='<img src="/images/indicator.gif" />';
		}
		
		if(ps_id != undefined){
			form.ps_id.value = ps_id;	
		} else {
			form.ps_id.value = '';
		}
		
		
		form.dheight.value = document.getElementById(form.basetarget.value).style.height.split('px')[0];
		form.dwidth.value = document.getElementById(form.basetarget.value).style.width.split('px')[0];


		if(form.onsubmit())
		 {//this check triggers the validations
			form.submit();
		 }		
		} catch(e) {}	
}

function ValidateAdvanceSlide(theform){

var resultTarget = theform.loadtarget.value;
 var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ 
	  	//alert('advance');
		try{
		document.getElementById(resultTarget).innerHTML = req.responseText;
		executeJavascript(resultTarget);
		}catch(e){}
			
		}
    }
  );
 
//	var url = "draw_slide_bookmark.cfm?ps_id=" + escape(theform.ps_id.value);
//	var url = "draw_slide_bookmark.cfm?ps_id=" + escape(currentPresentationIndex);
//	
//	AjaxRequest.get(
//		{
//		  'url':url
//		  ,'onSuccess':function(req){
//			document.getElementById(theform.loadtarget.value).innerHTML =  req.responseText;
//			}
//		}
//	)	 
 
//	if(theform.loadtarget.value.length > 0){
//		document.getElementById(theform.loadtarget.value).innerHTML='<cfinclude template="draw_slide_bookmark.cfm">';
//	} 
  return status;


}

function ValidateSlideSearch(theform){

if(theform.slideSearchText.value.length < 2){
	alert('Please enter some search text');
	return false;
}
 var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ 
	  //	alert('advance');
		document.getElementById('resultsPresenationSlideSearch').innerHTML = req.responseText;
			
		}
    }
  );
  return status;


}



function ValidateCODSearch(theform){
	if(theform.diagnosis.value.length <= 2){
		alert('Please enter your diagnosis');
		return false;
	}
 var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ 
	  //	alert('advance');
		document.getElementById('results').innerHTML = req.responseText;
			
		}
    }
  );
  return status;
}


function setVideoSort(form,sortfield,sortorder){
		//alert(sortfield);
		form.sort.value = 'Y';
		form.sortfield.value = sortfield;
		form.sortorder.value = sortorder;
		
		if(form.onsubmit())
		 {//this check triggers the validations
			form.submit();
		 }		
				
		
	
}


function setVideoFilter(form,filterfield,filtervalue){
		//alert(sortfield);
		form.filter.value = 'Y';

		
		if(filterfield == 'fEducation'){
			form.fEducation.value = filtervalue;

		}
		if(filterfield == 'fPoster'){
			form.fPoster.value = filtervalue;

		}		
		
		if(filterfield == 'fScience'){
			form.fScience.value = filtervalue;

		}		
		
		//form.filterfield.value = sortfield;
		//form.sortorder.value = sortorder;
		
		if(form.onsubmit())
		 {//this check triggers the validations
			form.submit();
		 }		
				
		
	
}

function setALLCOMFilter(form,filterform){
	
	//alert(filterform.com_code.length);
	
	if(filterform.com_code.length == 0)
	{
		alert('Please pick at least 1 community.');
		return false;
	}
	document.getElementById('searchallCommunityForm').style.display = 'none';
	var comList = '';
	for(var i =0; i<filterform.com_code.length; i++){
		if(filterform.com_code[i].checked){
			if(comList == ''){
				comList = "'" + filterform.com_code[i].value + "'";
			} else {
				comList = 	"'" + filterform.com_code[i].value + "'," + comList;
			}// end (comList == '')
		}// end (filterform.com_code[i].checked)
		
	}// end for
	
	
	form.filter.value = 'Y';
	form.fCOM.value = 'Y';
	form.fCOMList.value=comList;
	form.startrow.value = 1;
		if(form.onsubmit())
		 {//this check triggers the validations
			form.submit();
		 }		
	
}

function setVideoCOMFilter(form,filterform){
	
	//alert(filterform.com_code.length);
	
	if(filterform.com_code.length == 0)
	{
		alert('Please pick at least 1 community.');
		return false;
	}
	document.getElementById('videoCommunityForm').style.display = 'none';
	var comList = '';
	for(var i =0; i<filterform.com_code.length; i++){
		if(filterform.com_code[i].checked){
			if(comList == ''){
				comList = "'" + filterform.com_code[i].value + "'";
			} else {
				comList = 	"'" + filterform.com_code[i].value + "'," + comList;
			}// end (comList == '')
		}// end (filterform.com_code[i].checked)
		
	}// end for
	
	
	form.filter.value = 'Y';
	form.fCOM.value = 'Y';
	form.fCOMList.value=comList;
	form.startrow.value = 1;
		if(form.onsubmit())
		 {//this check triggers the validations
			form.submit();
		 }		
	
}

function videoClearBookmark(form){
	form.fbookmark.value = 'N';
	form.mm_id.value = 0;
			if(form.onsubmit())
		 {//this check triggers the validations
			form.submit();
		 }	
}



function validateVideoSearch(theform){

 var resultTarget = theform.target.value;
document.getElementById('videoSearchStatus').innerHTML = '<b>Searching...</b> <img src="/images/indicator.gif" />'

  var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ 
	  	//alert('search complete');
			document.getElementById(resultTarget).innerHTML = req.responseText;
			
		}
    }
  );
  return status;


}

function setVideoSearchRange(theform,start){
	document.getElementById('videoSearchStatus').innerHTML = '<b>Searching...</b> <img src="/images/indicator.gif" />'
	theform.startrow.value = start;
	theform.dorefresh.value  = 'N';
		if(theform.onsubmit())
		 {//this check triggers the validations
			theform.submit();
		 }	
	
}




function setPresentationSort(form,sortfield,sortorder){
		//alert(sortfield);
		form.sort.value = 'Y';
		form.sortfield.value = sortfield;
		form.sortorder.value = sortorder;
		
		if(form.onsubmit())
		 {//this check triggers the validations
			form.submit();
		 }		
				
		
	
}


function setPresentationFilter(form,filterfield,filtervalue){
		//alert(sortfield);
		form.filter.value = 'Y';

		
		if(filterfield == 'fEducation'){
			form.fEducation.value = filtervalue;

		}
		if(filterfield == 'fPoster'){
			form.fPoster.value = filtervalue;

		}		
		
		//form.filterfield.value = sortfield;
		//form.sortorder.value = sortorder;
		
		if(form.onsubmit())
		 {//this check triggers the validations
			form.submit();
		 }		
				
		
	
}

function setPresentationSearch(tempform, form, clear){
		
		
		if (clear){
			tempform.tempPresentationSearchText.value = '';
			form.presentationSearchText.value = '';
			form.dorefresh.value ='Y';				
			
			if(form.onsubmit()) {//this check triggers the validations
				form.submit();
				
				 }									
		} else {
		
		if(tempform.tempPresentationSearchText.value.length < 2){
				alert('Please enter search text of at least 2 characters');
		}
			else{
				
				form.presentationSearchText.value = tempform.tempPresentationSearchText.value;
				//alert(form.presentationSearchText.value);
				form.dorefresh.value ='Y';
					if(form.onsubmit())
							 {//this check triggers the validations
								form.submit();
							 }			
							}
							
		}
		
	
}



function setVideoSearch(tempform, form, clear){
		
		
		if (clear){
			tempform.tempVideoSearchText.value = '';
			form.videoSearchText.value = '';
			form.dorefresh.value ='Y';
			
			if(form.onsubmit()) {//this check triggers the validations
				form.submit();
				 }			

		} else {
		
		if(tempform.tempVideoSearchText.value.length < 2){
				alert('Please enter search text of at least 2 characters');
		}
			else{
				
				form.videoSearchText.value = tempform.tempVideoSearchText.value;
				//alert(form.presentationSearchText.value);
				form.dorefresh.value ='Y';
					if(form.onsubmit())
							 {//this check triggers the validations
								form.submit();
							 }			
							}
							
		}
		
	
}


function validatePresentationSearch(theform,searchType){

document.getElementById('presentationSearchStatus' + searchType).innerHTML = '<b>Searching...</b> <img src="/images/indicator.gif" />'
 var resultTarget = theform.target.value;
 //document.getElementById(resultTarget).innerHTML = '<b>Searching...</b> <img src="/images/indicator.gif" />'

  var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ 
	  	//alert('search complete');
			document.getElementById(resultTarget).innerHTML = req.responseText;
			executeJavascript(resultTarget);
		}
    }
  );
  //return status;
  return false;


}


/*
################################################################
RESIZED SLIDE functions
#################################################################
*/	

function poptest(target){
	//alert(target);
	document.getElementById(target).innerHTML='test';
		
}


 function getResizeBuild(pm_id,ps_id,width,height,dwidth,dheight,thumbnail,target, displaytype){
 			//alert('ps_id: ' + ps_id);
	 		try{
				clearInterval(stopAnimationInterval);
			}
			catch(e){}
			var url = "resize_layers.cfm?pm_id=" + pm_id + "&ps_id=" + ps_id + "&width=" + width + "&height=" + height + "&dwidth=" + dwidth + "&dheight=" + dheight + "&thumbnail=" + thumbnail + '&target=' + target + '&displaytype=' + displaytype;

			
		  AjaxRequest.get(
		    {
		      'url':url
		      ,'onSuccess':function(req){
				  	//document.getElementById(target).innerHTML = 'getResizebuild succerss';
				//do a try around this for the jtip highlight popup.. if people move to fast this element will be destroyed before it renders.
				try{					
			  		document.getElementById(target).innerHTML = req.responseText;
					executeJavascript(target);
				} catch(e){}

					}
		    }
		  );		 


}// end function	



function showResizeLayer(x,y,width, height, index, mm_id, psl_id, ps_id,psl_locked,thumbnail,dwidth,dheight,target,displaytype){
	
	//alert('showResizeLayer: ' + psl_id);
	
	var url = "resize_draw_layer.cfm?psl_id=" + psl_id + "&width=" + width + "&height=" + height + "&target=" + target + '_' + psl_id + "&x=" + x + "&y=" + y +"&thumbnail=" + thumbnail + '&dwidth=' + dwidth + '&dheight=' + dheight + '&displaytype=' + displaytype;
	
	
	  AjaxRequest.get(
	    {
	      'url':url
	      ,'onSuccess':function(req)
		  	{
				
				var id = target + '_' + psl_id;
				var contentlayer = document.createElement('div');
				contentlayer.setAttribute('id',id);
				var temp_style = 'position:absolute;z-index:' + index + ';width:' + width + 'px; height:' + height + 'px;  top:' + y + 'px; left:' + x + 'px;';
				contentlayer.style.cssText= temp_style;
				contentlayer.setAttribute('style',temp_style);				
				
				//do a try around this for the jtip highlight popup.. if people move to fast this element will be destroyed before it renders.
				try{
				document.getElementById(target).appendChild(contentlayer);	
				document.getElementById(id).innerHTML = req.responseText;
				executeJavascript(id);
				} catch(e) {}
				
			}
	    }
	  );	
	
	//alert(document.getElementById('resize_slide_' + ps_id));
	
	//loadResizeMedia(psl_id, width, height, id,x,y,thumbnail,dwidth,dheight);
	
}


function loadResizeMedia(psl_id, width, height, target, x, y,thumbnail,dwidth,dheight){
	
	
	 var url = "resize_draw_layer.cfm?psl_id=" + psl_id + "&width=" + width + "&height=" + height + "&target=" + target + "&x=" + x + "&y=" + y +"&thumbnail=" + thumbnail + '&dwidth=' + dwidth + '&dheight=' + dheight;

	  AjaxRequest.get(
	    {
	      'url':url
	      ,'onSuccess':function(req)
		  	{
				//alert('loadmedia');
				//document.getElementById(target).innerHTML = 'DOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO';
				//alert(target);
				//document.getElementById(target).innerHTML = req.responseText;
				//executeJavascript(target);

				
				
			}
	    }
	  );	

}

function resizeTextLayer(pm_id,psl_id, target, dwidth,dheight){
	 var url = "resize_text_layer.cfm?psl_id=" + psl_id + '&pm_id=' + pm_id +  '&dwidth=' + dwidth + '&dheight=' + dheight;

	  AjaxRequest.get(
	    {
	      'url':url
	      ,'onSuccess':function(req)
		  	{
				document.getElementById(target).innerHTML = req.responseText;

			}
	    }
	  );	

}	

/*
################################################################
END RESIZED SLIDE functions
#################################################################
*/	


function showSlide(ps_id){
	
		clearAnimations();
		
		currentPresentationIndex = currentPresentationArray.indexOf(ps_id+'');
	
		dwidth=document.getElementById('PresentationDisplayPanelSlide').style.width.split('px')[0];
		dheight = document.getElementById('PresentationDisplayPanelSlide').style.height.split('px')[0];
		
		width_delta = (document.getElementById('PresentationDisplayPanelSlide').style.width.split('px')[0] / 800).toFixed(2);
	 	height_delta = (document.getElementById('PresentationDisplayPanelSlide').style.height.split('px')[0] /600).toFixed(2);	
	
		getResizeBuild(currentPresentationId,ps_id,dwidth,dheight,width_delta,height_delta,'N','PresentationDisplayPanelSlide');
		getPresentationAnimations('presentationSlideAnimations',ps_id,'PresentationDisplayPanelSlide');
		document.getElementById('presentationSlideCount').innerHTML = currentPresentationIndex + 1 + ' / ' + currentPresentationArray.length;
		
		try{doSlideTop(currentPresentationIndex + 1)}catch(e){}
		
		updateSlideBookmark(currentPresentationId,ps_id,currentPresentationIndex+1);
	}

	function advanceSlide(delta){

		var tempCurrent = currentPresentationIndex + delta;
		
		if(tempCurrent > (currentPresentationArray.length - 1))
			{
				tempCurrent = 0; 
			}
			
		if(tempCurrent < 0)
			{
				tempCurrent = currentPresentationArray.length - 1; 
			}	
			
		currentPresentationIndex = tempCurrent	;
		
		showSlide(currentPresentationArray[currentPresentationIndex]);	
		
			
	}
	
	
	
	
	
function doSlideTop(sortorder){
		var newtop =  ((sortorder -1) * 260);
	document.getElementById('presentationSlideScroll').scrollTop = newtop;
	 //alert(newtop);
}

function updateSlideBookmark(deltarow){
	var url = "draw_slide_bookmark.cfm?slide_num=" + escape(deltarow);
	AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById('PresentationDisplayPanelSlideLoading').innerHTML =  req.responseText;
			}
		}
	)	
}


function loadCODHistory(pm_id, ps_id){
	CODDisplayPanel.load({url:'CODDisplayPanel.cfm?pm_id=' + pm_id + '&ps_id=' + ps_id, scripts:true});
}

function PassCODHistoryPMID(pm_id) {
	CODDiagnosisPanel.load({url:'CODDiagnosis.cfm?pm_id=' + pm_id , scripts:true});
}

function PassCODDiscussionPMID(pm_id) {
	CODDiagnosisPanel.load({url: 'CODDiscussionPanel.cfm?pm_id=' + pm_id, scripts:true});
}
function reloadCODHistoryList(pm_id,ps_id) {
	CODHistoryList.load({url: 'CODHistory.cfm?pm_id=' + pm_id + '&ps_id=' + ps_id, scripts:true});
}
function reloadDiagnosisPanel(pm_id) {
	CODDiagnosisPanel.load({url:'CODDiagnosis.cfm?pm_id=' + pm_id, scripts:true});
	//document.getElementById(target).innerHTML='test';
}

function loadHelpPages(id) {
	helppanel.load({url: 'help_main.cfm?id=' + id, scripts:true});
}

function loadHelp(id) {
	helppanel.load({url: 'help_main.cfm?id=' + id, scripts:true});
}function showCODSlide(ps_id){
	
		clearAnimations();
	
		//currentPresentationIndex = currentPresentationArray.indexOf(ps_id);
	
		dwidth=document.getElementById('CODDisplayPanelSlide').style.width.split('px')[0];
		dheight = document.getElementById('CODDisplayPanelSlide').style.height.split('px')[0];
		
		width_delta = (document.getElementById('CODDisplayPanelSlide').style.width.split('px')[0] / 800).toFixed(2);
	 	height_delta = (document.getElementById('CODDisplayPanelSlide').style.height.split('px')[0] /600).toFixed(2);	
	
		getResizeBuild(currentCODId,ps_id,dwidth,dheight,width_delta,height_delta,'N','CODDisplayPanelSlide');
		//getPresentationAnimations('CODSlideAnimations',ps_id,'PresentationDisplayPanelSlide');
		//document.getElementById('CODSlideCount').innerHTML = currentPresentationIndex + 1 + ' / ' + currentPresentationArray.length;
		
		//try{doSlideTop(currentPresentationIndex + 1)}catch(e){}
		
	}

function resizeCODView(target,h,w,pm_id,ps_id,tools){
	currentCODId = pm_id;
	//pad th width by 10
	w = w -10;
	
	newH = (h - toolbar_height).toFixed(2);

	
	
	newW = (newH * 1.33).toFixed(2);
	
	if(newW > w){newW = w; newH = (newW * .75);}
	//alert('w: ' + w + ' newW: ' + newW);
	
	
	newX = ((w-newW)/2).toFixed(2);
	
	//alert('newX: ' + newX.toFixed(2));
	document.getElementById(target).style.left = newX + 'px';
	document.getElementById(target).style.width = newW + 'px';
	document.getElementById(target).style.height = newH + 'px';
	//resize the tools
	
	document.getElementById(tools).style.left = newX + 'px';
	document.getElementById(tools).style.width = newW + 'px';
	document.getElementById(tools).style.height = toolbar_height + 'px';

	
	
	 width_delta = (newW / 800).toFixed(2);
	 height_delta = (newH /600).toFixed(2);

	showCODSlide(ps_id);
	//getResizeBuild(pm_id,ps_id,newW,newH,width_delta,height_delta,'N',target);
	
	
}


function loadVideoPresentationPanel2(pm_id, ps_id, mm_id,rtmp_stream){
	//if(videoTabs.getActiveTab().id == 'tab_videoPresentation'){
		//alert(videoDisplayPanel.getInnerWidth());

		
		videoTabs.setActiveTab('tab_videoPresentation');
		var dourl='videoPresentationPanel.cfm?pm_id=' + pm_id + '&ps_id=' + ps_id + '&mm_id=' + mm_id + '&rtmp_stream=' + rtmp_stream ;
		videoPresentationPanel.load({url:dourl, scripts:true});
		
		videoTabs.setActiveTab('tab_videomyfeedbackPanel');
		videomyfeedbackPanel.load({url:'presentationFeedbackPanel.cfm?pm_id=' + pm_id + '&ps_id=' + ps_id + '&mm_id=' + mm_id + '&fb_source=video', scripts:true});
		
		videoTabs.setActiveTab('tab_videoPresentation');
		

	//}
}


function loadVideoPresentationPanel(pm_id, ps_id, mm_id){
	//if(videoTabs.getActiveTab().id == 'tab_videoPresentation'){
		videoTabs.setActiveTab('tab_videoPresentation');
		var dourl='videoPresentationPanel.cfm?pm_id=' + pm_id + '&ps_id=' + ps_id + '&mm_id=' + mm_id;
		videoPresentationPanel.load({url:dourl, scripts:true});
		
		videoTabs.setActiveTab('tab_videomyfeedbackPanel');
		videomyfeedbackPanel.load({url:'presentationFeedbackPanel.cfm?pm_id=' + pm_id + '&ps_id=' + ps_id + '&mm_id=' + mm_id + '&fb_source=video', scripts:true});
		
		videoTabs.setActiveTab('tab_videoPresentation');
		

	//}
}

/*function loadVideoFeedbackPanel(pm_id, ps_id, mm_id){
	if(videoTabs.getActiveTab().id == 'tab_videomyfeedbackPanel'){
		
		
		videoTabs.setActiveTab('tab_videoPresentation');
		videoPresentationPanel.load({url:'videoPresentationPanel.cfm?pm_id=' + pm_id + '&ps_id=' + ps_id + '&mm_id=' + mm_id, scripts:true});
		
		videoTabs.setActiveTab('tab_videomyfeedbackPanel');
		videomyfeedbackPanel.load({url:'presentationFeedbackPanel.cfm?pm_id=' + pm_id + '&ps_id=' + ps_id + '&mm_id=' + mm_id + '&fb_source=video', scripts:true});
		
	}
}*/


function videoHighlight(mm_id){
	var oldtarget = 'videoSelected_' + currentVideoId;
	try{document.getElementById(oldtarget).className = 'lakeside_video_normal';}catch(e){}
	var newtarget = 'videoSelected_' + mm_id;
	document.getElementById(newtarget).className = 'lakeside_video_selected';
	currentVideoId = mm_id;
}

function caseHighlight(pm_id){
	var oldtarget = 'caseSelected_' + currentCaseId;
	try{document.getElementById(oldtarget).className = 'lakeside_case_normal';}catch(e){}
	var newtarget = 'caseSelected_' + pm_id;
	document.getElementById(newtarget).className = 'lakeside_case_selected';
	currentCaseId = pm_id;
}

function helpHighlight(id){
	var oldtarget = 'caseSelected_' + currentCaseId;
	try{document.getElementById(oldtarget).className = 'lakeside_help_normal';}catch(e){}
	var newtarget = 'caseSelected_' + id;
	document.getElementById(newtarget).className = 'lakeside_help_selected';
	currentCaseId = id;
}



function initRSNAVideoPlayer(rtmp_stream,preloader){
	
	 
	 var hasversion = 'N';
	 if(DetectFlashVer(9, 0, 115)){hasversion = 'Y'}
	 
	
	 
	 var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	 var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	 var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
	 if (isIE && isWin && !isOpera){
		 	 var embedtype = 'object';
	 }else {
		 var embedtype = 'embed'; 
	 }
	 var vw=videoDisplayPanel.getInnerWidth() - 10;
	var vh=videoDisplayPanel.getInnerHeight() - 10;
	 videoDisplayPanel.load({url:'videoDisplayPanel.cfm?rtmp_stream=' + rtmp_stream + '&hasversion=' + hasversion + '&embedtype=' + embedtype  + '&width=' + vw + '&height=' + vh, scripts:true}); 
	 //alert(hasversion);

}




function initVideoSearch(filter,fbookmark,mm_id){
	var url = 'videoSearchResults.cfm?height=' + videoListPanel.getInnerHeight() + '&width=' + videoListPanel.getInnerWidth() + '&loadfirst=Y&filter=' + filter +'&fbookmark=' + escape(fbookmark) + '&mm_id=' + escape(mm_id);
	//alert(url);
	AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById('videoSearch').innerHTML =  req.responseText;
			executeJavascript('videoSearch');
			}
		}
	)		
	
	
	
}

function initAwardSearch(target,atm_code,award){
	var url = 'searchResults.cfm?dorefresh=Y&height=' + awardPanel.getInnerHeight() + '&width=' + awardPanel.getInnerWidth() + '&atm_code=' + atm_code + '&target=' + target + '&searchType=AWARD&award=' + award;
	AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById(target).innerHTML =  req.responseText;
			executeJavascript(target);
			}
		}
	)	
}

function initAllSearch(target,atm_code,searchtext){
	var url = 'searchResults.cfm?dorefresh=Y&height=' + searchContentPanel.getInnerHeight() + '&width=' + searchContentPanel.getInnerWidth() + '&atm_code=' + atm_code + '&target=' + target + '&searchType=ALL';
	if(searchtext != "")
	{
		url = url + "&presentationSearchText=" + escape(searchtext);
	}
	AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById(target).innerHTML =  req.responseText;
			executeJavascript(target);
			}
		}
	)	
}


function initPresentationSearch(target,atm_code,searchtext){
	var url = 'searchResults.cfm?dorefresh=Y&height=' + communitypanel.getInnerHeight() + '&width=' + communitypanel.getInnerWidth() + '&atm_code=' + atm_code + '&target=' + target;
	if(searchtext != "")
	{
		url = url + "&presentationSearchText=" + escape(searchtext);
	}
	AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById(target).innerHTML =  req.responseText;
			executeJavascript(target);
			}
		}
	)	
}

function commitPresentationSearch(atm_code,searchtext) {
	var mainform = document.getElementById("fpresentationSearch");
	mainform.target.value = "communitySearch";
	mainform.atm_code.value = atm_code;
	mainform.presentationSearchText.value = searchtext;
	if(mainform.onsubmit())
	{
		mainform.submit();	
	}				
}



function drawSlide(basetarget, bg_id, bg_url, bg_frame, ppt_id, ppt_url,ppt_autoplay,slidetype,haslayers){

var slideBG = basetarget + 'BG';
var slidePPT = basetarget + 'PPT';

if(bg_id > 0){
	//alert(bg_url);
	drawFlashBG(slideBG,bg_url,bg_frame, bg_id);
} else {
	document.getElementById(slideBG).innerHTML = '';
}
if(ppt_id > 0){
	drawFlashPPT(slidePPT,ppt_url, ppt_id,ppt_autoplay,'PPT SLIDE',slidetype);
} else {
	document.getElementById(slidePPT).innerHTML = '';
}


}


				
function drawMediaLayer(layertarget, psl_id, height, width, top, left, zindex){
		
		
		
		var id = layertarget + '_' + psl_id;	
		var contentlayer = document.createElement('div');


		contentlayer.setAttribute('id',id);

		var temp_style = 'position:absolute;z-index:' + zindex + ';width:' + width + 'px; height:' + height + 'px;  top:' + top + 'px; left:' + left + 'px;';

		contentlayer.style.cssText= temp_style;

		contentlayer.setAttribute('style',temp_style);

		
		//do a try around this for the jtip highlight popup.. if people move to fast this element will be destroyed before it renders.
		

		document.getElementById(layertarget).appendChild(contentlayer);	
		
					
	

}


function UpdateMyRating(rating, add_args) {
	var url = "presentationFeedbackPanel.cfm?rating=" + escape(rating) + "&update=Y";
	if(add_args != "" && add_args != undefined) {
		 url = url + "&" + add_args;		
	}	
		AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById('my_rating').innerHTML =  req.responseText;
			}
		}
	)
}

function updateVideoBookmark(mm_id) {
	var divid = "video_bookmark_" + mm_id;
	var test = document.getElementById(divid);
	debugger;
	var url = "draw_slide_bookmark.cfm?mm_id=" + escape(mm_id);	
		AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById(divid).innerHTML =  req.responseText;
			}
		}
	)		
}

function SubmitFeedbackForm(type,fb_source,mm_id,fb_rating) {
	var divname = "myfeedback_" + fb_source + "_panel";
	if(type == "question") {
		var theform = document.getElementById(fb_source + "_feedback_question");
		
		// require at least one radio button be selected
		var radioSelected = false;
		for (i = 0;  i < theform.feedback_answer.length;  i++)
		{
			if (theform.feedback_answer[i].checked)
				{
					radioSelected = true;
					var answer = theform.feedback_answer[i].value;
				}
		}
		if (!radioSelected)
		{
			alert("Please select your answer before submitting.");
		} else {

			var url = "presentationFeedbackPanel.cfm?fb_source=" + escape(fb_source) + "&mm_id=" + escape(mm_id) + "&answer=" + escape(answer);
				AjaxRequest.get(
				{
				  'url':url
				  ,'onSuccess':function(req){
					document.getElementById(divname).innerHTML =  req.responseText;
					}
				}
			)
			alert('Your answer has been submitted');
		}
	} else if (type == "notes") {
		var theform = document.getElementById('my_notes_' + fb_source);
		var notes = theform.feedback_notes.value;
		
			var url = "presentationFeedbackPanel.cfm?fb_source=" + escape(fb_source) + "&mm_id=" + escape(mm_id) + "&notes=" + escape(notes);
				AjaxRequest.get(
				{
				  'url':url
				  ,'onSuccess':function(req){
					  alert('"My Notes" for this ' + fb_source +' have been submitted');
					document.getElementById(divname).innerHTML =  req.responseText;
					executeJavascript(divname);
					var widget_exists = document.getElementById('my_rsna_notes');
					if (widget_exists != undefined && widget_exists != "") {
						ReloadMyNotes();
						}						
					}
				}
			)		
			
	} else if (type == "comments") {
		var theform = document.getElementById('my_comments_' + fb_source);
		var comments = theform.feedback_comments.value;
			var url = "presentationFeedbackPanel.cfm?fb_source=" + escape(fb_source) + "&mm_id=" + escape(mm_id) + "&comments=" + escape(comments);
				AjaxRequest.get(
				{
				  'url':url
				  ,'onSuccess':function(req){
					document.getElementById(divname).innerHTML =  req.responseText;
					}
				}
			)
			alert('"My Comments" for this presentation have been submitted');
	} else if (type == "rating" && fb_rating != "" && fb_rating != undefined) {
			var url = "presentationFeedbackPanel.cfm?fb_source=" + escape(fb_source) + "&mm_id=" + escape(mm_id) + "&rating=" + escape(fb_rating);
				AjaxRequest.get(
				{
				  'url':url
				  ,'onSuccess':function(req){
					document.getElementById(divname).innerHTML =  req.responseText;
					executeJavascript(divname);
					var widget_exists = document.getElementById('my_ratings');
					if (widget_exists != undefined && widget_exists != "") {
						ReloadMyRatings();
						}	
						
					//We reload the Notes widget since it also displays any ratings
					var notes_widget_exists = document.getElementById('my_notes');
					if (notes_widget_exists != undefined && widget_exists != "") {
						ReloadMyNotes();
						}							
					
						
					}
				}
			)	
	}
}

function ReloadMyRatings(add_args) {
	var url = "myrsna/plugins/my_ratings/my_ratings.cfm";
	if(add_args != "" && add_args != undefined) {
		 url = url + "?" + add_args;		
	}	
		AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById('my_ratings').innerHTML =  req.responseText;
			}
		}
	)
}

function ReloadMyNotes(add_args) {
	if(document.getElementById('my_rsna_notes') != undefined){
	var url = "myrsna/plugins/my_notes/my_notes.cfm";
	if(add_args != "" && add_args != undefined) {
		 url = url + "?" + add_args;		
	}	
		AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			 // alert('notes reloaded');
			document.getElementById('my_rsna_notes').innerHTML =  req.responseText;
			}
		}
	);
	}
		
}

function ReloadMySearch(add_args) {
	var url = "myrsna/plugins/my_search/my_search.cfm";
	if(add_args != "" && add_args != undefined) {
		 url = url + "?" + add_args;		
	}	
		AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById('my_search').innerHTML =  req.responseText;
			}
		}
	)
}

function validateSurveyForm(theform)
{
	var Q1A = false;
	var Q1B = false;
	var Q1C = false;
	for (var i=0; i<theform.sc.length; i++) {
		if (theform.sc[i].checked )
			Q1A = true;
		if (theform.ev[i].checked)
			Q1B = true;
		if (theform.gl[i].checked)
			Q1C = true;
	}
	
	var Q3 = false;
	var Q4 = false;
	if (theform.overall[0].checked || theform.overall[1].checked) 
		Q3 = true;
	if (theform.content[0].checked || theform.content[1].checked)
		Q4 = true;
	
	if(!Q1A) {
		alert('Please select an answer for the "Scientific content" topic of question 1.');
	}else if (!Q1B) {
		alert('Please select an answer for the "Educational value" topic of question 1.');
	}else if (!Q1C) {
		alert('Please select an answer for the "General learning environment" topic of question 1.');
	}else if (!Q3) {
		alert('Please select an answer for question 3.');
	}else if (!Q4) {
		alert('Please select an answer for question 4.');
	}else{
//		alert("Thank you for taking the survey! \n You may edit survey responses through Friday.");
		alert("Thank you for taking the survey!");
		
		 var status = AjaxRequest.submit(
			theform
			,{
			  'onSuccess':function(req){ 
				document.getElementById('dps_survey_div').innerHTML = req.responseText;
				}
			}
		  );
	}
}


 function getSlideMedia(target, ps_id, pm_id, hasanimations, hasvideo, hasflash, hasaudio, highlight,fullscreen){

			var url= 'slidemultimedia.cfm?ps_id=' + ps_id + '&pm_id=' + pm_id + '&hasanimations=' + hasanimations + '&hasvideo=' +  hasvideo + '&hasflash=' + hasflash + '&hasaudio=' + hasaudio + '&highlight=' + highlight + '&fullscreen=' + fullscreen;

		  AjaxRequest.get(
		    {
		      'url':url
		      ,'onSuccess':function(req){
								
			  		document.getElementById(target).innerHTML = req.responseText;

					}
		    }
		  );		 


}// end function	


function getFlashMessage(target){
	var url = 'flashmessage.html';	
		  AjaxRequest.get(
		    {
		      'url':url
		      ,'onSuccess':function(req){
								
			  		document.getElementById(target).innerHTML = req.responseText;

					}
		    }
		  );		
}


function videoCommunityFilter(){
	
	if(document.getElementById('videoCommunityForm').style.display=='')
	{
		document.getElementById('videoCommunityForm').style.display='none';
	} else {
		
		document.getElementById('videoCommunityForm').style.display='';	
	}
	
}



function allCommunityFilter(){
	
	if(document.getElementById('searchallCommunityForm').style.display=='')
	{
		document.getElementById('searchallCommunityForm').style.display='none';
	} else {
		
		document.getElementById('searchallCommunityForm').style.display='';	
	}
	
}

function ClearNotes(formfield, defaulttext){
	
	if(formfield.value == defaulttext){
		formfield.value = '';
	}
}


function launchScreenSaver(){
		var url = 'screensaverhighlights.cfm';
	
	 AjaxRequest.get(
		    {
		      'url':url
		      ,'onSuccess':function(req){
			  		
					document.getElementById('black').innerHTML = req.responseText;
					executeJavascript('black');

					}
		    }
		  );



}





function initHighlightSearch(target){
	var url = 'searchResults.cfm?dorefresh=Y&height=' + tabs.getInnerHeight() + '&width=' + tabs.getInnerWidth()+ '&target=' + target + '&searchType=HIGHLIGHTS';
	AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById(target).innerHTML =  req.responseText;
			executeJavascript(target);
			}
		}
	)	
}


function initDSSSearch(target){
	var url = 'searchResults.cfm?dorefresh=Y&height=' + tabs.getInnerHeight() + '&width=' + tabs.getInnerWidth()+ '&target=' + target + '&searchType=DSS';
	AjaxRequest.get(
		{
		  'url':url
		  ,'onSuccess':function(req){
			document.getElementById(target).innerHTML =  req.responseText;
			executeJavascript(target);
			}
		}
	)	
}
