var intervalId;

function get_chart_options()
{
  var chart_params="";

  if ($("chart_show_underlying").checked)
  {
    chart_params+="&show_underlying=1";
    $("chart_relative_scale").checked=true;
    $("chart_relative_scale").disabled=true;
  } else {
    $("chart_relative_scale").disabled=false;
  }

  if ($("chart_relative_scale").checked)
    chart_params+="&scaling=rel";

  var now = new Date();
  chart_params+='&time='+now.getTime();

  return (chart_params);
}

/**
* Refreshes the given image
* @param string ID of image
* @param string new image url
*/

function reload_chart(image_id,newurl) {

	//alert('Image Id: [' + image_id + '] newurl: [' + newurl + ']' );
	//document.write( 'Image Id: [' + image_id + '] newurl: [' + newurl + ']' );

    if (!newurl)
      newurl=current_chart_base_url;
      // TODO: Double-check if this is required or not.
//	  $(image_id).src = '/images/icons/spacer.gif';
    // With chart options

    //newurl = newurl + get_chart_options();
    var tmp_image= new Image();
    tmp_image.src=newurl;
    window.setTimeout("displayImage('"+image_id+"','"+newurl+"')",10);

/*
	if ( intervalId != null )
	{
		window.clearInterval (intervalId);
	}
		
    window.setInterval("displayImage('"+image_id+"','"+newurl+"')",1000); 
*/
}

function displayImage(image_id,url)
{
  $(image_id).src = url;
}

function image_tab(el, image_id, newurl){

 		var s = $(el).parentNode.parentNode;

		if(s.hasChildNodes())
		{
			var children = s.getElementsByTagName("LI");

			for ( var i=0; i< children.length; i++ )
			{
				children[i].firstChild.className = '';
			}
		}
		else
		{
			//No Children (Wrong formatting or whatever)
		}
		$(el).className = 'selected';
	  reload_chart(image_id,newurl);
		current_chart_base_url=newurl;
    return true;
}


/**
* Reloads the given image, new image can be passed by a reload_src attribute in the image tag
* @param object this reference to the image
*/
function reload_image(image)
{
   var now = new Date();
   if (typeof image == "string")
    image = $(image);

   if (image)
   {
    if (!image.getAttribute('reload_src'))
      image.setAttribute('reload_src',image.src);
      if (image.src=image.getAttribute('reload_src').indexOf('?')>0)
        image.src=image.getAttribute('reload_src')+"&id="+now.getTime();
      else
        image.src=image.getAttribute('reload_src')+"?id="+now.getTime();
   }
}

function detectFlash()
{
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
	{
				
	}
}

function PopoutWindow(sURL)
{
    if (isPopupBlockerDetected())
    {
        alert('Please disable your popup blocker.');
    }
    else
    {
        window.open(sURL,'_blank');
    }
}

function isPopupBlockerDetected() {
  var myTest = window.open("about:blank","","directories=no,height=10,width=10,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no");
  if (!myTest) {
    return(true);
  } else {
    myTest.close();
    return(false);
  }
}



