// DarkEye JScript File
// Developed by KoreLogic - http://www.korelogic.co.uk
window.onload = function()
{
    addView();
    loadComments();
    init();
}
function loadComments() {
  AjaxRequest.get(
    {
      'url':'comments.aspx?site='+ document.getElementById('siteID').value
      ,'onLoading':function() { document.getElementById('comms').innerHTML='<div class="loader"><p><img src=images/load.gif /><br/>Loading...</p></div>'; Effect.Appear('comms') }
      ,'onSuccess':function(req){document.getElementById('comms').innerHTML=req.responseText; Effect.BlindDown('comms');}
    }
  );
}
function addView() {
  AjaxRequest.get(
    {
      'url':'stats.aspx?siteID='+ document.getElementById('siteID').value + '&type=view'
      ,'onSuccess':function(req){}
    }
  );
}

function addVote(rating){
  var element = document.getElementById('rating')
  //Effect.Fade(element);
  AjaxRequest.get(
    {
      'url':'addVote.aspx?vote='+ rating + '&site='+ document.getElementById('siteID').value
      ,'onLoading':function() {element.innerHTML='<p>Submitting...<p>';}
      ,'onSuccess':function(req){element.innerHTML=req.responseText; Effect.Appear(element);}
      //,'timeout':2000
      //,'onTimeout':function(req){document.getElementById('container-submit').innerHTML='<div class="loader"><p><img src=images/error.gif /><br/>Error: Server Busy...</p></div>'; Effect.Appear('container-results'); }
    }
  );
}

function submitForm(theform) {
  var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){errorCheck(req.responseText);}
      ,'onLoading':function() { document.getElementById('errorTag').innerHTML='<p>Saving...</p></div>';}
    }
  );
  return status;
}

function errorCheck(state) {
    if(state == "OK"){
        Effect.BlindUp(document.getElementById('subComment'));
        loadComments();
    }else{
        document.getElementById('errorTag').innerHTML=state;
        Recaptcha.reload();
        Effect.Pulsate(document.getElementById('errorTag'));
    }
}
