var quotesDelay;
var interval;
var quotes_query = 0;
var quotesStarted = false;
var fx4u_update_delay;

function initQuotes(delayInSec) {
	fx4u_update_delay=delayInSec;
	quotesDelay = delayInSec * 1000;
	if (get_cookie('no_quotes_update')) {
		stopQuotes();
	} else {
		startQuotes();
	}
}

function stopQuotes() {
	if (typeof fx4u_update_timer!='undefined') clearInterval(fx4u_update_timer);
	quotesStarted = false;
	var quotesSwitch = document.getElementById('qd-playPause');
	if (quotesSwitch) quotesSwitch.className = 'qd-play';
}

function startQuotes() {
	setTimeout("if (!quotes_query) {quotes_query=1;r_sc('http://www.forex4you.org:81/gq2.js',1);quotes_query=0;}",10);
	quotesStarted = true;
	var quotesSwitch = document.getElementById('qd-playPause');
	if (quotesSwitch) quotesSwitch.className = 'qd-pause';
}

function toggleQuotes() {
	if (quotesStarted) {
		stopQuotes();
		set_cookie('no_quotes_update', 1);
	} else {
		startQuotes();
		delete_cookie('no_quotes_update');
	}
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )  {
    var expires = new Date ( exp_y, exp_m, exp_d );
  } else {
	var expires = new Date ( );  // current date & time
	expires.setDate ( expires.getDate() + 365 );
  }

  cookie_string += "; expires=" + expires.toGMTString();

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );

  if ( secure )
        cookie_string += "; secure";

  document.cookie = cookie_string;
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

// Динамический вызов скрипта
function r_sc(href,rnd)
{
    if (rnd) href+=(/\?/.test(href)?'&':'?')+"rnd="+(Math.floor((new Date().getTime())/rnd))
    var script = document.createElement('SCRIPT')
    script.type='text/javascript'
    script.src=href
    document.documentElement.firstChild.appendChild(script)
}
