function download()
{
  location.href = '/main_page/download/?file=' + $('image_result').src;
}

function generate()
{
  showLoader();

  $('download').style.display = 'none';

  document.image_form.submit();
}

function showLoader()
{
  $('ajaxLoader').style.display = '';

  $('inner_result').style.display = 'none';
}
function hideLoader()
{
  $('ajaxLoader').style.display = 'none';

  $('inner_result').style.display = '';
}

function iframeLoaded()
{
  var splitted = $('image_target').contentWindow.document.body.innerHTML.split(",");

  if(splitted[0] == 'OK')
  {
    $('image_result').src = splitted[1] + "?" + new Date().valueOf();

    setEvent($('image_result'), 'load',
      function(){
        $('image_result').style.display = '';
        $('text_result').style.display = 'none';
        $('download').style.display = '';
        hideLoader();
      }
    );
  }
  else
  {
    if(trim(splitted[0]) == '')
    {
      splitted[0] = 'Select an image URL or pick a local file';
    }

    $('text_result').innerHTML = splitted[0];

    $('image_result').style.display = 'none';
    $('text_result').style.display = '';

    hideLoader();
  }
}

function setBgColor(color)
{
  $('bgColor').style.background = '#' + color;

  $('bgColor_input').value = color;
}

function initialize()
{
//	setEvent($('image_target'), 'load', iframeLoaded);

  loadSV();

  /*$('bgColor').onmousedown = showColorPicker;
  $('bgColor_input').onblur = function(){parseColorFromInput('bgColor');};
  $('bgColor_input').onfocus = function(){pickerInputFocus('bgColor_input');};*/
}
window.onload = initialize;
