//------------------------------
//-- Registered user default configuration
//------------------------------
function $(_id){
  return document.getElementById(_id);
  }

function lnkOutQual(){
  if($('inpSelFormat').options[$('inpSelFormat').selectedIndex].value=='jpg'){
    $('inpTxtOutQual').disabled=false;
  }
  else{
    $('inpTxtOutQual').disabled=true;
  }
}

function explainAccess(){
  if($('contExplainAccess').style.display=="none"){
    $('contExplainAccess').style.display="block";
  }
  else{
    $('contExplainAccess').style.display="none";
  }
}

function accessList(){
  if($('inpSelAccessPol').options[$('inpSelAccessPol').selectedIndex].value=="open"){
    $('contIpList').style.display="none";
  }
  else{
    $('contIpList').style.display="block";
  }
}
//------------------------------

//------------------------------
//-- User logged in :> display welcome notice
//------------------------------
function getWelcome(){
  var _url="/libs/xml/welcome.php";
  var pars="hash="+Math.random();
  var trg=$('welcome');
  
  
  var req="action=getValue&hash="+Math.random();
  var ajx = new xHttpRequest2();
  var ret = ajx.send('post', _url, pars, 1000, null, false, function(req, rsp){
    if(rsp && rsp.responseText){
      trg.innerHTML=rsp.responseText;
    }
  });
  
  //setTimeout(getWelcome, 2000)
}

function getCountShots(){
    var _url="/libs/xml/admin.php";
    var pars="action=getshotcnt&hash="+Math.random();
    var trg=$('shotCnt');
    
    var ajx = new xHttpRequest2();
    var ret = ajx.send('post', _url, pars, 1000, null, false, function(req, rsp){
      if(rsp && rsp.responseText){
        trg.innerHTML=rsp.responseText;
      }
    });
    
    setTimeout(getCountShots, 10000)
}

//------------------------------

//-------------------------------------
//-- Generator
function initGenerator(){
  showQual();
  genTag();
  var aryInp=document.getElementsByTagName('input');
  for(var i=0;i<aryInp.length;i++){
    try{
      aryInp[i].addEventListener('change', genTag, true);
      aryInp[i].addEventListener('blur', genTag, true);
      aryInp[i].addEventListener('keyup', genTag, true);
    }
    catch(r){
      aryInp[i].attachEvent('onchange', genTag);
      aryInp[i].attachEvent('onblur', genTag);
      aryInp[i].attachEvent('onkeyup', genTag);
    }
  }
  var arySel=document.getElementsByTagName('select');
  for(var i=0;i<arySel.length;i++){
    try{
      arySel[i].addEventListener('change', genTag, true);
      arySel[i].addEventListener('blur', genTag, true);
      arySel[i].addEventListener('keyup', genTag, true);
    }
    catch(r){
      arySel[i].attachEvent('onchange', genTag);
      arySel[i].attachEvent('onblur', genTag);
      arySel[i].attachEvent('onkeyup', genTag);
    }
  }
}

function showQual(){
  var sel=$('inpSelType');
  var imgType=sel.options[sel.selectedIndex].value;
  if(imgType=='jpg'){
    try{
      $('trQual').style.display="table-row";
      }
    catch(r){}
  }
  else{
    try{
      $('trQual').style.display="none";
    }
    catch(r){}
  }
}

function genTag(){
  var trg=$('inpTaRes');
  var s=$('inpTxtSize').value;
  var q=$('inpTxtQual').value;
  var bs=$('inpTxtBrowserSize').value;
  if($('inpChkCache1').checked==true){
    var cache=1;
  }
  else{
    var cache=0;
  }
  var sel=$('inpSelType');
  var t=sel.options[sel.selectedIndex].value;
  var lw=$('inpTxtLw').value;
  var to=$('inpTxtTo').value;
  var url=$('inpTxtUrl').value;
  var tag="&lt;img  src=\"http://www.web-screenshots.com/get.php?uid="+uid;
  
  //crop
  var cl=$('inpCropLeft').value
  var ct=$('inpCropTop').value
  var cr=$('inpCropRight').value
  var cb=$('inpCropBottom').value
  if(cl!=0 && ct!=0 && cr!=0 && cb!=0){
    var crop=cl+","+ct+","+cr+","+cb;
  }
  
  if(t!='')
    tag+="&amp;t="+t;
  if(cache)
    tag+="&amp;cache="+cache;
  if(s)
    tag+="&amp;size="+s;
  if(q)
    tag+="&amp;q="+q
  if(lw)
    tag+="&amp;lw="+lw;
  if(to)
    tag+="&amp;to="+to;
  if(bs)
    tag+="&amp;bs="+bs;
  if(crop)
    tag+="&amp;crop="+crop
  if(url)
    tag+="&amp;url="+url;
  tag+="\" alt=\"Screenshot by www.web-screenshots.com\" title=\"Screenshot by www.web-screenshots.com\"/&gt;";
  
  if(!url){
    $('inpTxtUrl').style.borderColor="red";
  }
  else{
    $('inpTxtUrl').style.borderColor="";
  }
  trg.innerHTML=tag;
  
  
}
//-------------------------------------

