function preload_image(filename)
{
  image1 = new Image();
  image1.src = filename;
}

function swap_image(control, filename)
{
  control.src = filename;
}
  
function popup(theURL,winName,features) 
{
  window.open(theURL,winName,features);
}

function set_time(span_id)
{
  var spn_to_fill = document.getElementById(span_id);
  var time = new Date();
  var year = time.getFullYear();
  var month = format_leading_zero(time.getMonth() + 1);
  var day = format_leading_zero(time.getDate());
  var hours = format_leading_zero(time.getHours());
  var minutes = format_leading_zero(time.getMinutes());
  var seconds = format_leading_zero(time.getSeconds());
  var clock = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
  spn_to_fill.innerHTML = clock;
  timeout = setTimeout("set_time('"+span_id+"')",1000);
}

function set_date(textbox_id)
{
  var txt_to_fill = document.getElementById(textbox_id);
  var time = new Date();
  var year = time.getFullYear();
  var month = format_leading_zero(time.getMonth() + 1);
  var day = format_leading_zero(time.getDate());
  var hours = format_leading_zero(time.getHours());
  var minutes = format_leading_zero(time.getMinutes());
  var seconds = format_leading_zero(time.getSeconds());
  var clock = day + "-" + month + "-" + year;
  txt_to_fill.value = clock;
}

function format_leading_zero(int_value)
{
  var str_return = int_value;
  if (int_value < 10){str_return = '0'+int_value;}
  return (str_return);
}

function handle_bold(txt_name)
{
  popup('popup.php?node=workbook_message&action=bold_popup&textarea='+txt_name,'delete','scrollbars=yes,resizable=yes,width=275,height=150')
}

function insert_bold(txt_name, str_text)
{
  var txt_to_edit = document.getElementById(txt_name);
  txt_to_edit.value = txt_to_edit.value+'<b>'+str_text+'</b>';
}

function handle_italic(txt_name)
{
  popup('popup.php?node=workbook_message&action=italic_popup&textarea='+txt_name,'delete','scrollbars=yes,resizable=yes,width=275,height=150')
}

function handle_subtitle(txt_name)
{
  popup('popup.php?node=workbook_message&action=subtitle_popup&textarea='+txt_name,'delete','scrollbars=yes,resizable=yes,width=275,height=150')
}

function handle_email_subtitle(txt_name)
{
  popup('popup.php?node=workbook_message&action=email_subtitle_popup&textarea='+txt_name,'delete','scrollbars=yes,resizable=yes,width=275,height=150')
}

function insert_italic(txt_name, str_text)
{
  var txt_to_edit = document.getElementById(txt_name);
  txt_to_edit.value = txt_to_edit.value+'<i>'+str_text+'</i>';
}

function insert_subtitle(txt_name, str_text)
{
  var txt_to_edit = document.getElementById(txt_name);
  txt_to_edit.value = txt_to_edit.value+'<p class="bold">'+str_text+'</p>';
}

function check_email(id_email)
{
  var txt_email_address = document.getElementById(id_email);
  var str_email_address = txt_email_address.value;
  var bln_return = true;
  if (str_email_address.indexOf('@') == -1)
  {
    bln_return = false;
    alert('U moet een geldig emailadres invullen');
  }
  return bln_return;
}

function insert_email_subtitle(txt_name, str_text)
{
  var txt_to_edit = document.getElementById(txt_name);
  txt_to_edit.value = txt_to_edit.value+'<br><font color="#000066" size="-3" face="Verdana, Arial, Helvetica, sans-serif"><b>'+str_text+'</b></font><br>';
}

function handle_link(txt_name)
{
  popup('popup.php?node=url&action=popup&textarea='+txt_name,'delete','scrollbars=yes,resizable=yes,width=275,height=150')
}

function handle_email_link(txt_name)
{
  popup('popup.php?node=url&action=email_popup&textarea='+txt_name,'delete','scrollbars=yes,resizable=yes,width=275,height=150')
}

function insert_link(txt_name, str_text, str_url)
{
  var txt_to_edit = document.getElementById(txt_name);
  
  if (str_url.substr(0,7) != 'http://')
  {
    str_url = 'http://'+str_url;
  }
  txt_to_edit.value = txt_to_edit.value+'<a href="'+str_url+'" target="_blank" class="default">'+str_text+'</a>';
}

function insert_email_link(txt_name, str_text, str_url)
{
  var txt_to_edit = document.getElementById(txt_name);
  
  if (str_url.substr(0,7) != 'http://')
  {
    str_url = 'http://'+str_url;
  }
  txt_to_edit.value = txt_to_edit.value+'<a href="'+str_url+'"><font color="#000000" size="-3" face="Verdana, Arial, Helvetica, sans-serif">'+str_text+'</font></a>';
}

function textarea_character_limit(ta_to_check, int_length)
{
  var str_value = ta_to_check.value;
  if (str_value.length >= int_length)
  {
    ta_to_check.value = str_value.substring(0, int_length-1);
  }
}