﻿// JScript File

var textButtonTab="tabFontList";
var styleButtonTab="tabVista";

var curStyleButton="tdVista1";
var prevStyleButton="";

function ajaxFunction()
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
          document.getElementById('divRender').innerHTML=xmlHttp.responseText;
          document.getElementById('aDownload').style.display='';
        }
      }
      
    var f=document.getElementById('hfFont').value;
    var fs=document.getElementById('hfFontSize').value;
    var fst=document.getElementById('hfBold').value + "," + document.getElementById('hfItalic').value + "," + document.getElementById('hfUnderline').value;
    var c=document.getElementById('txtCaption').value;
    var fc=document.getElementById('hfFontColor').value;
    var bg=document.getElementById('hfBgColor').value;
    var b=document.getElementById('hfTheme').value;
    
    var res=window.screen.width + 'x' + window.screen.height;
    
    var qstring="?font=" + encodeURIComponent(f) + "&caption=" + encodeURIComponent(c) + "&fsize=" + encodeURIComponent(fs) + "&fstyle=" + encodeURIComponent(fst) + "&fc=" + encodeURIComponent(fc) + "&bg=" + encodeURIComponent(bg) + "&t=" + encodeURIComponent(b) + "&res=" + encodeURIComponent(res);
 
    xmlHttp.open("GET","buttonGenerator.aspx" + qstring,true);
    document.getElementById('divRender').innerHTML=document.getElementById('rotator').innerHTML;
    xmlHttp.send(null);
  }
  
  function onstart()
  {
    document.getElementById('textContainer').innerHTML=document.getElementById('divFontList').innerHTML;
    restore();
    
    var c=document.getElementById('tabVista');
    switchSBTab(c);
    document.getElementById('hfTheme').value='Vista1-59-25';
    
    document.getElementById('hfBgColor').value="#ffffff";
    
  }
  
  function restore()
  {
    document.getElementById('ddlTextSize').value="12";
    document.getElementById('chBold').checked=false;
    document.getElementById('chItalic').checked=false;
    document.getElementById('chUnderline').checked=false;
  
    document.getElementById('hfFont').value='Arial';
    document.getElementById('hfFontSize').value="12";
    document.getElementById('hfBold').value='';
    document.getElementById('hfItalic').value='';
    document.getElementById('hfUnderline').value='';
    document.getElementById('hfFontColor').value='#000000';
    
    document.getElementById('txtCaption').style.fontFamily='Arial';
    document.getElementById('txtCaption').style.fontSize="12";
    document.getElementById('txtCaption').style.fontWeight='normal'
    document.getElementById('txtCaption').style.fontStyle='normal';
    document.getElementById('txtCaption').style.textDecoration='none';
    document.getElementById('txtCaption').style.color='#000000';
    
    setStatus();
  }
  
  function setStatus()
  {
    var text=document.getElementById('hfFont').value;
    text= text + ";" + document.getElementById('hfFontSize').value + "px";
    text= text + ";" + document.getElementById('hfBold').value;
    text= text + "," + document.getElementById('hfItalic').value;
    text= text + "," + document.getElementById('hfUnderline').value;
    text= text + ";" + document.getElementById('hfFontColor').value;
    document.getElementById('textResult').innerHTML=text;
  }
  
  function setTextFamily(t)
  {
    var fml=t.style.fontFamily;
    document.getElementById('txtCaption').style.fontFamily=fml;
    document.getElementById('hfFont').value=fml;
    setStatus();
    document.getElementById(divTxtFamCur).style.backgroundColor='#ddeeff';
    divTxtFamCur=t.id;
  }
  
  function setTextF(tf)
  {
    document.getElementById('txtCaption').style.fontFamily=tf;
    document.getElementById('hfFont').value=tf;
    setStatus();
    //document.getElementById(divTxtFamCur).style.backgroundColor='#ddeeff';
    //divTxtFamCur=t.id;
  }
  
  function flySBTab(t)
  {
    t.style.cursor='pointer';
    t.style.backgroundColor='#00ccff';
  }
  
  function flyOutSBTab(t)
  {
    if(styleButtonTab!='tabVista')
        document.getElementById('tabVista').style.backgroundColor='#a1b1c1';
    if(styleButtonTab!='tabMac')
        document.getElementById('tabMac').style.backgroundColor='#a1b1c1';
    if(styleButtonTab!='tabGel')
        document.getElementById('tabGel').style.backgroundColor='#a1b1c1';
    if(styleButtonTab!='tabPlastic')
        document.getElementById('tabPlastic').style.backgroundColor='#a1b1c1';
    
    document.getElementById(styleButtonTab).style.backgroundColor='#bbccdd';
  }
  
  
  function switchSBTab(t)
  {
    var prev_id=textButtonTab.replace(/tab/,'div');
    var control_id=t.id.replace(/tab/,'div');
    document.getElementById(prev_id).innerHTML=document.getElementById('button_style').innerHTML;
    document.getElementById('button_style').innerHTML=document.getElementById(control_id).innerHTML;

    styleButtonTab=t.id;
  }
  
  function switchTextTab(t)
  {
    var prev_id=textButtonTab.replace(/tab/,'div');
    var control_id=t.id.replace(/tab/,'div');
    document.getElementById(prev_id).innerHTML=document.getElementById('textContainer').innerHTML;
    document.getElementById('textContainer').innerHTML=document.getElementById(control_id).innerHTML;
    
    textButtonTab=t.id;
  }
  
  function flyButtonTab(t)
  {
    t.style.cursor='pointer';
    t.style.backgroundColor='#00ccff';
  }
  
  function flyOutButtonTab(t)
  {
    if(textButtonTab!='tabFontList')
        document.getElementById('tabFontList').style.backgroundColor='#a1b1c1';
    if(textButtonTab!='tabFontSize')
        document.getElementById('tabFontSize').style.backgroundColor='#a1b1c1';
    if(textButtonTab!='tabFontStyle')
        document.getElementById('tabFontStyle').style.backgroundColor='#a1b1c1';
    if(textButtonTab!='tabFontColor')
        document.getElementById('tabFontColor').style.backgroundColor='#a1b1c1';
    
    document.getElementById(textButtonTab).style.backgroundColor='#bbccdd';
  }
  
  function flyTextFamily(t)
  {
    t.style.backgroundColor='#ffffcc';
  }
  
  function flyOutTextFamily(t)
  {
    if(t.id!=divTxtFamCur)
    t.style.backgroundColor='#ddeeff';
  }
  
  function changeTextSize(val)
  {
    document.getElementById('hfFontSize').value=val;
    document.getElementById('txtCaption').style.fontSize=val;
    setStatus();
  }
  
  function CheckBold(t)
  {
    if(t.checked)
    {
        document.getElementById('txtCaption').style.fontWeight='bold';
        document.getElementById('hfBold').value='bold';
    }
    else
    {
        document.getElementById('txtCaption').style.fontWeight='normal';
        document.getElementById('hfBold').value='normal';
    }
    setStatus();
  }
  
  function CheckItalic(t)
  {
    if(t.checked)
    {
        document.getElementById('txtCaption').style.fontStyle='italic';
        document.getElementById('hfItalic').value='italic';
    }
    else
    {
        document.getElementById('txtCaption').style.fontStyle='normal';
        document.getElementById('hfItalic').value='normal';
    }
    setStatus();
  }
  
 function CheckUnder(t)
  {
    if(t.checked)
    {
        document.getElementById('txtCaption').style.textDecoration='underline';
        document.getElementById('hfUnderline').value='underline';
    }
    else
    {
        document.getElementById('txtCaption').style.textDecoration='none';
        document.getElementById('hfUnderline').value='none';
    }
    setStatus();
  }
  
  function setBgColor(v)
  {
        document.getElementById('hfBgColor').value=v;
        document.getElementById('bgIndicator').innerHTML= v + '&nbsp;&nbsp;&nbsp;';
        document.getElementById('bgIndicator').style.backgroundColor=v;
  }
  
  function setTextColor(v)
  {
        document.getElementById('txtCaption').style.color=v;
        document.getElementById('hfFontColor').value=v;
        setStatus();
  }
  
  function setB(t,v)
  {
        prevStyleButton=curStyleButton;
        curStyleButton=t.id;
        t.style.backgroundColor="#fffacd";
        document.getElementById(prevStyleButton).style.backgroundColor="#ccddee";
        document.getElementById('hfTheme').value=v;
  }
  
  function setB_in(t)
  {
    if(t.id!=curStyleButton)
        t.style.backgroundColor='#ddeeff';
  }
  
  function setB_out(t)
  {
    if(t.id!=curStyleButton)
        t.style.backgroundColor='#ccddee';
  }
  
  function checkBgTr(t)
  {
    if(t.checked)
    {
        document.getElementById('hfBgColor').value="Transparent";
        document.getElementById('divBBC').style.display='none';
        document.getElementById('bgIndicator').innerHTML= 'Transparent&nbsp;';
        document.getElementById('bgIndicator').style.backgroundColor='#ffffff';
    }
    else
    {
        document.getElementById('hfBgColor').value="#ffffff";
        document.getElementById('divBBC').style.display='';
        document.getElementById('bgIndicator').innerHTML= '#ffffff&nbsp;&nbsp;&nbsp;';
        document.getElementById('bgIndicator').style.backgroundColor='#ffffff';
    }
  }
  
  function download()
  {
    if(document.getElementById('imgFin')!=null)
    {
        var zip=document.getElementById('imgFin').src.split('/')[document.getElementById('imgFin').src.split('/').length-1];
        zip=zip.replace(/f/,'');
        zip=zip.replace(/png/,'zip');
        window.open('output/' + zip);
    }
  }
