// function gets specified parameter from URL
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = parent.content.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    //alert('aQueryString = '+aQueryString);

    for (var iParam = 0; iParam < aQueryString.length; iParam++ ){
    	if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){    	  
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}

// function refreshes the content frame
function RefreshContentFrame(location)
{
	parent.content.location.href = location;
	return false;
}

// function loads chart view as PNG or FLASH
function loadChartView(chartName,showFlash)
{
	if(showFlash!=undefined)
	{
		flash = showFlash;
	}
	else
	{
		var flash=getURLParam("flash");
		if(flash=="") flash="true";
	}
	
	var WIDTH = "550";
	var HEIGHT = "450";
	var divEl = document.getElementById('chart');
	
	var alternativeFlashContentHTML = 				
				'<p>'+
					'<br/>'+
					'<span class="header">FLASH ERROR</span>'+
					'<br/><br/>'+
					'</p><p class="flashmessage">'+
					'You are seeing this message, as you do not seem to have the Flash plugin installed or enabled.'+
					'<br/>'+
					'Please download the latest Flash plugin '+
					'<a target="_blank" href="http://get.adobe.com/flashplayer/">here</a> or switch the gallery to PNG format in the left hand panel.'+
					'<br/>'+
					'<br/>'+
				'</p>';
	
	var navigationPanelHTML = 
        '<div style="height:20px;width:'+WIDTH+'px;text-align:center">'+
        '<span><a href="javascript:void(0);" onclick="history.back();return false;">&lt;&lt; BACK</a></span>'+
        ' | <span><a href="javascript:void(0);" onclick="loadChartView(\''+chartName+'\',\'true\');return false;">REPLAY</a></span>'+
        ' | <span><a href="javascript:void(0);" onclick="loadChartView(\''+chartName+'\',\'false\');return false;">PNG</a></span>'+
        '</div>';
	
	var myErrorContentDiv = document.getElementById('auxiliaryDiv');
	
	if(flash=="true" || flash=="")
	{	
		//swfobject.registerObject("myFlashContent", "8");
		// code for flash
		divEl.innerHTML = 	'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+WIDTH+'" height="'+HEIGHT+'" id="myFlashContent">'+
								'<param name="movie" value="Flash/'+chartName+'.swf" />'+
							'<!--[if !IE]>-->'+
								'<object type="application/x-shockwave-flash" data="Flash/'+chartName+'.swf" width="'+WIDTH+'" height="'+HEIGHT+'">'+
							'<!--<![endif]-->'+
								alternativeFlashContentHTML+
							'<!--[if !IE]>-->'+
								'</object>'+
							'<!--<![endif]-->'+
							'</object>'+
							navigationPanelHTML;	
		
		// for IE6 - display alternative Flash content
		if(divEl.innerHTML=="")
		{
	
			if(myErrorContentDiv==undefined)
			{
				myErrorContentDiv = document.createElement('div');
				myErrorContentDiv.id="auxiliaryDiv";
				myErrorContentDiv.innerHTML = alternativeFlashContentHTML+navigationPanelHTML;
				document.body.appendChild(myErrorContentDiv);
			}
			else
			{
				myErrorContentDiv.innerHTML = alternativeFlashContentHTML+navigationPanelHTML;
			}
		}	

	}
	else
	{
		if(myErrorContentDiv!=undefined)
		{
			myErrorContentDiv.innerHTML = "";
		}
		
		// code for png
		divEl.innerHTML = '<img src="Images/'+chartName+'.png" width="'+WIDTH+'" height="'+HEIGHT+'" usemap="#'+chartName+'" border="0">'+
						  '<div style="height:20px;width:'+WIDTH+'px;text-align:center">'+
						  '<span><a href="javascript:void(0);" onclick="history.back();return false;">&lt;&lt; BACK</a></span>'+
                          ' | <span><a href="javascript:void(0);" onclick="loadChartView(\''+chartName+'\',\'true\');return false;">FLASH</a></span>'+
                          '</div>'	
	}
}

//function adds the flash parameter to the page link and calls refresh of the content frame
function UpdateLink(page)
{
	var flash=getURLParam("flash");
	if(flash=="") flash="true";
	RefreshContentFrame(page+"?flash="+flash);
	return false;
}
