function noerror(){
    //return true
}
function handleIt (msg, url, line) {
    alert ('An error occurred:\nmessage: ' + msg + '\nurl: ' + url +'\nline: ' + line);
    return true;
}
onerror = handleIt;
//window.onerror=noerror;
function SubmitForm($form){
    $namevalue=$form.elements.name.value;
    $emailvalue=$form.elements.email.value;
    $websitevalue=$form.elements.website.value;
    $countryvalue=$form.elements.country.value;
    $commentvalue=$form.elements.comment.value;
    $seccodevalue=$form.elements.seccode.value;
    $form.elements.submitform.disabled=true;
    if(($namevalue=="")||($commentvalue=="")||($seccodevalue=="")){
        alert("Complete the Form Then Submit Form");
        document.getElementById("submitform").disabled=false;
    }else{
        document.getElementById("loading").style.display="inline";
        new Ajax.Request('ajax.php?request=postnew&seccode='+$seccodevalue+'&name='+encodeURI($namevalue)+'&email='+$emailvalue+'&website='+$websitevalue+'&country='+$countryvalue+'&comment='+encodeURI($commentvalue),{method:'get',onComplete:checkresponse});
    }
}
function checkresponse(data){
    document.getElementById("submitform").disabled=false;
    if(parseInt(data.responseText)==1){
        var $form=document.getElementById("dataform");
        $form.elements.name.value="";
        $form.elements.email.value="";
        $form.elements.website.value="";
        $form.elements.country.value="";
        $form.elements.comment.value="";
        $form.elements.seccode.value="";
        document.getElementById("loading").style.display="none";
        new Effect.toggle('newcomment','appear');
        window.location="index.php";
    }else if(parseInt(data.responseText)==2){
        document.getElementById("loading").style.display="none";
        alert("Security Code is invalid");
    }else {
        var $splited=data.responseText.split("_");
        if(parseInt($splited[0])==3){
            document.getElementById("loading").style.display="none";
            alert("Error i found illegaly word ("+$splited[1]+") in your comment remove it first");
        }else{
            document.getElementById("loading").style.display="none";
            alert("Unknown Error"+data.responseText);
        }
    }
}
function Login(){
    var $form=document.getElementById("loginform");
    var $username=$form.elements.username.value;
    var $password=$form.elements.password.value;
    if(($username==" ")||($password==" ")){
        alert("Complete Form");
    }else{
        var $data="username="+$username+"&password="+$password;
        new Ajax.Request('ajax.php?request=adminlogin',{method:'post',parameters:$data,onComplete:checkLogin});
    }
}
function checkLogin($data){
    if(parseInt($data.responseText)==1){
        window.location="index.php";
    }else if(parseInt($data.responseText)==0){
        alert("Username or Password is wrong")
    }else{
        alert("Unknown Error");
    }
}
function deleteComment($id){
    if(confirm("Are You Sure ?")){
        new Ajax.Request('ajax.php?request=deletecomment&id='+$id,{method:'get',onComplete:deleteDiv});
    }
}
function deleteDiv($data){
    if(parseInt($data.responseText)==0){
        alert("Error In Deleting Comment");
    }else{
        var $array=$data.responseText.split("_");
        if(parseInt($array[0])==1){
            new Effect.Fade('comment_'+$array[1]);
        }else{
            alert("Unknown Error");
        }
    }

}