var allow_preset = true;
function show_lang()
{
  document.getElementById('langs').style.display=''; 
  if (window.tm)
  {
  	window.clearTimeout(window.tm);
  }  
  window.tm = window.setTimeout('hide_lang()', 2000)
}
function hide_lang()
{
  document.getElementById('langs').style.display='none'; 
}
function preset(col1, col2, col3)
{
  hide_code();
  if (!allow_preset) return;
  document.getElementById('color1').style.background = '#' + col1;
  document.frm.color1.value = col1;
  document.getElementById('color2').style.background = '#' + col2;
  document.frm.color2.value = col2;
  document.getElementById('color3').style.background = '#' + col3;
  document.frm.color3.value = col3;
}
function frameAction(frame)
{
  if (frame.contentWindow.document.location.href.indexOf('about:blank') != -1) return;
  var content = frame.contentWindow.document.body.innerHTML;
  document.getElementById('code').className = '';
  document.frm.code.value = dehtmlspecialchars(content);
}
function dehtmlspecialchars(str) {
    str = str.replace(/&quot;/g,'"');
    str = str.replace(/&lt;/g,'<');
    str = str.replace(/&gt;/g,'>');
    str = str.replace(/&#039;/g,"'");
    str = str.replace(/&amp;/g,'&');
  return str;
} 
function show_preview()
{
  hide_code();
  var style = 0;
  for(var i=0; i<document.frm.elements.length; i++)
  {
  	if (document.frm.elements[i].name == 'style' && document.frm.elements[i].checked) style = document.frm.elements[i].value;
  }
  
  document.getElementById('example_img').src = 'generate.php?style=' + style + '&color1=' + document.frm.color1.value + '&color2=' + document.frm.color2.value + '&color3=' + document.frm.color3.value + '&color0=' + document.frm.color0.value + '&size=' + document.frm.size.options[document.frm.size.selectedIndex].value + '&font=' + document.frm.font.options[document.frm.font.selectedIndex].value + '&text=' + document.frm.elements['text'].value.replace('&', '%26').replace(' ', '%20') + '&rand=' + Math.random();
  document.getElementById('loading').style.display='';
  document.getElementById('example').style.backgroundColor = '#FFFFFF';
  document.getElementById('example_img').style.visibility = 'hidden';
  setOpacity(document.getElementById('example_img'), 0)
  document.getElementById('example_img2').style.visibility = 'hidden';
  setOpacity(document.getElementById('example_img2'), 0)

}
function example_load(el)
{
  document.getElementById('example_img2').src = document.getElementById('example_img').src;
  document.getElementById('example').style.backgroundColor = '#' + document.frm.example.value;
  document.getElementById('loading').style.display='none';
  document.getElementById('example_img').style.visibility = 'visible';
  smooth_show('example_img');
  document.getElementById('example_img2').style.visibility = 'visible';
  smooth_show('example_img2');
}
function setOpacity(el, per)
{
  el.style.MozOpacity = per/100;
  if(el.filters)
  {
    if(el.filters.length == 0)
    {
      el.style.filter = "alpha()";
    }
    if(el.filters.length == 0)
    {
      el.style.filter = "progid:DXImageTransform.Microsoft.Alpha()";
    }
    if (el.filters && el.filters[0]) el.filters[0].opacity = per;
  }
  stack_perc[el.id] = per;
}
var stack_perc = new Array();
var stack_tm = new Array();
function smooth_show(id)
{
  el = document.getElementById(id);
  if (!el) return;
  if (!stack_perc[id] || isNaN(stack_perc[id]))
  {
    stack_perc[id] = 0;
  }
  stack_perc[id] += 10;
  if (stack_tm[id]) clearTimeout(stack_tm[id]);
  el.style.visibility="visible"; 
  setOpacity(el, Math.min(95, stack_perc[id]));
  if (stack_perc[id] < 95)
  {
    stack_tm[id] = setTimeout(function() { smooth_show(id); }, 100);
  }
}
function checkForm(frm, arr, txt)
{
  el = null;
  err = '';
  if (!txt) txt = 'Please fill in required fields';
  for(i in arr)
  {
    switch(frm.elements[i].type)
    {
      case 'text':
      case 'textarea':
      case 'password':
        if (frm.elements[i].value == '')
        {
          if (!el) el = frm.elements[i];
          err += arr[i] + "\n";
        }
    	break;
      case 'select-one':
        if ((frm.elements[i].selectedIndex == 0) && (!frm.elements[i + '_'] || frm.elements[i + '_'].value == ''))
        {
          if (!el) el = frm.elements[i];
          err += arr[i] + "\n";
        }
    	break;
    }
  }
  if (err == '') return true;
  else
  {
    el.focus();
    alert(txt + ":\n-----------------------------------\n" + err + "-----------------------------------");
    return false;
  }
}
function dopreview (code)
{
  if (!/src="([^"]*)\.js"/.test(code)) return false;
  src = RegExp.$1;
  code = '<img src="' + src + '.gif" border="0" width="150" height="150" style="position:absolute; right:0px; top:0px; margin:0px; padding:0px">';
  if (document.frm.url.value && (document.frm.url.value != 'www.yoursite.com'))
  {
    if (/^http:\/\//.test(document.frm.url.value)) url = document.frm.url.value; else url = 'http://' + document.frm.url.value;
    code = '<a href="'+url+'" target="'+(document.frm.elements['target'].selectedIndex ? '_blank' : '')+'">' + code + '</a>';
  }
  document.getElementById('preview_site').innerHTML = code;
}
function hide_code()
{
  document.getElementById('code').className = 'half_see';
  document.frm.code.value = '';
}

function readfaq(page)
{
	window.open(page,null,
    "height=500,width=400,status=yes,toolbar=no,menubar=no,location=no, resizable=1, left=200,top=200");
}
