//// SCRIPT by Jonas Lorenz aka brain.worm ////

function setup_form()
  {
  document.form.date.value=js_date;
  document.form.bgcolor.value=js_bgcolor;
  document.form.color.value=js_color;
  document.form.sound.value=js_sound;
  document.form.font.value=js_font;
  document.form.bg.value=js_bg;
  document.form.size.value=js_size;
  document.form.bgeffect.value=js_bgeffect;
  if(document.form.javaeffect) {document.form.javaeffect.value=js_javaeffect;}
  document.form.preview.checked=js_preview;
  document.form.confirm.checked=js_confirm;

  if(document.getElementById('preview').checked==true) {document.form.send.value="  Vorschau >>>";} else {document.form.send.value="  Karte senden >>>";}

  if(document.form.to.value=="") {document.getElementById('cardto').innerHTML="Empfänger";}
  if(document.form.to_mail.value=="") {document.getElementById('cardto').href="mailto:Empfängeraddresse";}
  if(document.form.from.value=="") {document.getElementById('cardfrom').innerHTML="Absender";}
  if(document.form.from_mail.value=="") {document.getElementById('cardfrom').href="mailto:Absenderaddresse";}
  if(document.form.message.value=="") {document.getElementById('cardtitle').innerHTML="Titel";document.getElementById('cardmessage').innerHTML="Nachricht"}
  }

function refresh_to() {document.getElementById('cardto').href="mailto:"+document.form.to_mail.value.replace(/</g,"&lt").replace(/>/g,"&gt");document.getElementById('cardto').innerHTML=document.form.to.value.replace(/</g,"&lt").replace(/>/g,"&gt");}
function refresh_to_mail() {document.getElementById('cardto').href="mailto:"+document.form.to_mail.value.replace(/</g,"&lt").replace(/>/g,"&gt");document.getElementById('cardto').innerHTML=document.form.to.value.replace(/</g,"&lt").replace(/>/g,"&gt");}
function refresh_from() {document.getElementById('cardfrom').href="mailto:"+document.form.from_mail.value.replace(/</g,"&lt").replace(/>/g,"&gt");document.getElementById('cardfrom').innerHTML=document.form.from.value.replace(/</g,"&lt").replace(/>/g,"&gt");}
function refresh_from_mail() {document.getElementById('cardfrom').href="mailto:"+document.form.from_mail.value.replace(/</g,"&lt").replace(/>/g,"&gt");document.getElementById('cardfrom').innerHTML=document.form.from.value.replace(/</g,"&lt").replace(/>/g,"&gt");}
function refresh_title() {document.getElementById('cardtitle').innerHTML=document.form.title.value.replace(/</g,"&lt").replace(/>/g,"&gt");}
function refresh_message() {document.getElementById('cardmessage').innerHTML=document.form.message.value.replace(/</g,"&lt").replace(/>/g,"&gt").replace(/\n/g,"<br>").replace(/\[u\](.+?)\[\/u\]/gi,"<u>$1</u>").replace(/\[i\](.+?)\[\/i\]/gi,"<i>$1</i>").replace(/\[b\](.+?)\[\/b\]/gi,"<b>$1</b>").replace(/\[url\](.+?)\[\/url\]/gi,"<a href='$1' target='_blank'>$1</a>").replace(/:([a-zA-z0-9_-]+?):/gi,"<img src='http://www.sheerascardshopmitherz.de/smileys/$1.gif'>");document.getElementById('cardtitle').innerHTML=document.form.title.value;}

function refresh_address() {document.form.to.value=document.form.address.value.substring(0,document.form.address.value.indexOf("%"));document.form.to_mail.value=document.form.address.value.substring(document.form.address.value.indexOf("%")+1,document.form.address.value.length);refresh_to();refresh_to_mail();}

function refresh_bgcolor() {document.body.style.backgroundColor=document.form.bgcolor.value.substring(1,7);document.getElementById('cardbody').style.backgroundColor=document.form.bgcolor.value.substring(1,7);}
function refresh_color() {document.getElementById('cardbody').style.color=document.form.color.value.substring(1,7);document.getElementById('cardbody').style.borderColor=document.form.color.value.substring(1,7);}
function refresh_sound() {document.getElementById('bgsound').src="http://www.sheerascardshopmitherz.de/musik/"+document.form.sound.value;}
function refresh_font() {document.getElementById('cardbody').style.fontFamily=document.form.font.value;}
function refresh_bg() {document.body.style.backgroundImage="url(http://www.sheerascardshopmitherz.de/hintergrund/"+document.form.bg.value+")";}
function refresh_size() {document.getElementById('cardmessage').style.fontSize=document.form.size.value;}
function refresh_javaeffect() {document.form.submit();}
function refresh_bgeffect() {effectoptions=document.form.bgeffect.value.replace(/'/,"").split(",");setup_effect();}
function refresh_preview() {if(document.getElementById('preview').checked==true){document.form.send.value="  Vorschau >>>";}else{document.form.send.value="  Karte senden >>>";}}

function button_u() {insert("[u]","[/u]");}
function button_i() {insert("[i]","[/i]");}
function button_b() {insert("[b]","[/b]");}
function button_smileys() {popup=window.open("http://www.sheerascardshopmitherz.de/php/smileys.htm","popup","width=320,height=400,left=20,top=50,dependent=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");popup.focus();}
function button_help() {popup=window.open("http://www.sheerascardshopmitherz.de/hilfe/postkartenhilfe.htm","popup","width=720,height=600,left=20,top=50,dependent=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");popup.focus();}
function button_manage() {popup=window.open("http://www.sheerascardshopmitherz.de/php/addressbooksmall.php","popup","width=320,height=400,left=20,top=50,dependent=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");popup.focus();document.form.address.value="none";}

function insert_address(name,mail) {document.form.to.value=name;document.form.to_mail.value=mail;document.form.address,value=name+"%"+mail;popup.close();refresh_to();refresh_to_mail();}

function insert_smiley(tag) {insert(tag,"");popup.focus();refresh_message();}

function insert(atag, etag)
  {
  document.form.message.focus();
  if(document.selection)
    {
    range=document.selection.createRange();
    text=range.text;
    range.text=atag+text+etag;

    range=document.selection.createRange();
    if(text.length==0) {range.move('character',-etag.length);} else {range.moveStart('character',atag.length+text.length+etag.length);}
    range.select();
    }
  else if(document.form.message.selectionStart)
    {
    start=document.form.message.selectionStart;
    end=document.form.message.selectionEnd;
    text=document.form.message.value.substring(start, end);
    document.form.message.value=document.form.message.value.substr(0,start)+atag+text+etag+document.form.message.value.substr(end);

    if(text.length==0) {pos=start+atag.length;} else {pos=start+atag.length+text.length+etag.length;}
    document.form.message.selectionStart=pos;
    document.form.message.selectionEnd=pos;
    }
  else
    {
    document.form.message.value=document.form.message.value+atag+"ihr Text"+etag;
    }
  refresh_message();
  }

