var bl = {
    oldHJ:function (id) {
        var id = id.split('-')
        var req = mint.Request();
        req.method = 'POST';
        req.OnSuccess = function() {
            location.reload();
        }
        req.AddParam('oldhj',id[1]);
        req.Send(location.href);
    },
    tinymce:function(){
        tinyMCE.init({
            // General options
            mode : "textareas",
            theme : "simple"
        });
    },
    userOptions: function (mod, mail, admin) {
        var content, wallet, settings/*,servers*/;
        if (mod == 'wallet') wallet = 'red'; else wallet = 'grey';
        if (mod == 'settings') settings = 'red'; else settings = 'grey';
        //if (mod == 'your_servers') servers = 'red'; else servers = 'grey';
        if (mail > 0) mail = 'new_'; else mail = '';
        content = "<table width='135' cellpadding='5' cellspacing='0' style='font-family:Arial, Verdana;'>";
        content += '<tr><td style="padding-right:0;"><img src="gfx/icons/mail_'+mail+'32.png" alt="" hspace="0" vspace="0" /></td><td><a href="http://forum.blacklisted.pl?index.php?app=members&amp;module=messaging" title="Wiadomości">Wiadomości</a></td></tr>';
        content += '<tr><td style="padding-right:0;"><img src="img/theme/menu/'+wallet+'-dot.png" alt="" hspace="0" vspace="0" /></td><td><a href="wallet.html" title="Portfel">Portfel</a></td></tr>';
        content += '<tr><td style="padding-right:0;"><img src="img/theme/menu/'+settings+'-dot.png" alt="" hspace="0" vspace="0" /></td><td><a href="settings.html" title="Twoje ustawienia">Ustawienia</a></td></tr>';
        //content += '<tr><td style="padding-right:0;"><img src="img/theme/menu/'+servers+'-dot.png" alt="" hspace="0" vspace="0" /></td><td><a href="your_servers.html" title="Twoje ustawienia">Twoje serwery</a></td></tr>';
        if (admin == 1) content += '<tr><td style="padding-right:0;"><img src="img/theme/menu/yellow-dot.png" alt="" hspace="0" vspace="0" /></td><td><a href="admin.php" title="Panel administratora" target="_blank"><b>Panel admina</b></a></td></tr>';       
        content += "</table>";
        if ($('userOptions')) RemoveElement('userOptions'); else CreateDiv('userOptions',0,0,'userSetOptions','Menu',content,'',-5,15); 
    }
}
function focus_password( e ) {
    if ( e.value == "------" ) 
    {
        e.value = '';
        return false;
    }
}
function focus_username( e ) {
    if ( e.value == "Nazwa użytkownika" ) {
        e.value = '';
        return false;
    }
}
function focus_field( e, info ) {
    if ( $(e).value == info ) {
        $(e).value = '';
        return false;
    }
    return false;
}
function popImage(imageURL,imageTitle) {
    PositionX = 10;
    PositionY = 10;
    defaultWidth  = 800;
    defaultHeight = 600;
    var AutoClose = false;

    var imgWin = window.open('','_blank','scrollbars=no,resizable=no,status=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
    if( !imgWin ) { return true; } //popup blockers should not cause errors
    imgWin.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2" /><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
        'function resizeWinTo() {\n'+
        'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
        'var oH = document.images[0].height, oW = document.images[0].width;\n'+
        'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
        'window.doneAlready = true;\n'+ //for Safari and Opera
        'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
        'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
        'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
        'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
        'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
        'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
        'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
        'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
        'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
        'x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2));\n'+
        '}\n'+
        '<\/script>'+
        '<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
        (document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;">'))+
        '<img src='+imageURL+' alt="Trwa Ĺ�dowanie grafiki..." title="" onload="resizeWinTo();" onclick="window.close();">'+
        (document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
    imgWin.document.close();
    if( imgWin.focus ) { imgWin.focus(); }
    return false;
}
function fadeaction(obj,type) {
if (type == 'in') {
    //SetOpacity(obj, 0);
    $(obj).style.opacity = 1;
    $(obj).style.filter = 'alpha(opacity=10)';
    mint.fx.Fade(obj, 100, 20, 1000);
    }else if (type == 'out') mint.fx.Fade(obj, 0, 20, 1000);
}
function Tabs() {
    // TOP MENU
    var tabs = mint.gui.CreateTabWidget("drk_tabsContent");
    tabs.reqConfig = {
        evalScripts: true
    }
    tabs.useSaving = true;
    tabs.fading = false;
    tabs.selectFirstItem = false;
    tabs.activeClass = "drk_menuitem-active";
    tabs.hoverClass = "hover";
    tabs.useCache = false;
    tabs.link = "index.ajax.php";
    tabs.itemParam = "adm";

    tabs.AddItem("news", "news", "text");
    tabs.AddItem("apps", "apps", "text");
    tabs.AddItem("users", "users", "text");
    tabs.AddItem("sections", "sections", "text");
    tabs.AddItem("admins", "admins", "text");
    tabs.AddItem("settings", "settings", "text");
    tabs.AddItem("payments", "payments", "text");
    tabs.AddItem("todo", "todo", "text");
    tabs.AddItem("profits", "profits", "text");
    tabs.AddItem("logs", "logs", "text");
    
    /* AddItem for all $_GET elements 
    var exp = location.hash.replace("#","");
    exp = exp.split('&');
    for(var i = 0; i < exp.length; i++) {
            if(brk[0] != 'adm') {
                [brk[0],brk[1]];
            }
        }
    }    */
    
    tabs.OnUpdate = function(item) {
        leftMenu();
    }
    tabs.OnSelect = function(item) {
        location.hash = 'adm='+item.name;
        $('drk_tabsContent').innerHTML = Preloader('100%',200);
    }
    selected = getLocationHash('adm');
    if (selected) {
        var obj = tabs.GetItem(selected);
    tabs.OpenItem(obj);
    }
    bl.tinymce();
}
function leftMenu() {
    var req = mint.Request();
    req.OnSuccess = function() {
        $('left_menu').innerHTML = this.responseText;
    }
    req.AddParam('adm',getLocationHash('adm'));
    req.Send('leftmenu.ajax.php');
}
function SubMenuToggle(obj) {
    // hide all divs
    $('sm_index').style.display = 'none';
    $('sm_apps').style.display = 'none';
    $('sm_recalls').style.display = 'none';
    $('sm_forum').style.display = 'none';
    // show selected div
    $('sm_'+obj).style.display = 'block';
}
function in_array( what, where ) {
    var a = false;
    for(var i=0;i<where.length;i++) {
        if(what == where[i]) {
            a = true;
            break;
        }
    }
    return a;
}
/*function geHashAndSend() {
    /* AddItem for all $_GET elements*/ 
    /*var exp = location.hash.replace("#","");
    exp = exp.split('&');
    var values=
    for(var i = 0; i < exp.length; i++) {
       if(i>0) 
    }
    setLocationHash('array',values);
    SendRequest();
}*/
function getLocationHash(type,data) {
    if (data)
        var exp = data.replace("#","");
    else
        var exp = location.hash.replace("#","");

    exp = exp.split('&');
    for(var i = 0; i < exp.length; i++) {
        var brk = exp[i].split('=');
        if (type == brk[0]) return brk[1];
    }
}
function setLocationHash(type,value) {
    var exp = location.hash.replace("#","");
    var sethash = '';
    exp = exp.split('&');
    for(var i = 0; i < exp.length; i++) {
        var brk = exp[i].split('=');
        /*if(brk[0] != type) {
            var sethash = sethash + brk[0] + '=' + brk[1] + '&';
        }*/
        if(brk[0] == 'adm') sethash = 'adm=' + brk[1];
        break;
    }
    if(type == 'array') {
        arr = value.split(",");
        for(var i = 0; i < arr.length; i++) {
            var brk = arr[i].split('&');
            for(var j = 0; j < brk.length; j++) {
                var itm = brk[j].split('=');
                if(itm[0] != 'adm') sethash = sethash + '&' + itm[0] + '=' + itm[1];
            }
        }
    }else if(type == 'remove') {
        var arr = value.split(",");
        for(var j = 0; j < exp.length; j++) {
            var itm = exp[j].split('=');
            if(in_array(itm[0],arr) == false && itm[0] != 'adm') {
                sethash = sethash + '&' + itm[0] + '=' + itm[1];    
            }    
        }
    }else{
        sethash = sethash + '&' + type + '=' + value;
    }
    location.hash = sethash;    
}
function SendRequest(form,phpfile) {
    if (form) tinyMCE.triggerSave();
    var req = mint.Request();
    req.evalScripts = true;
    req.OnSuccess = function() {
        $('drk_tabsContent').innerHTML = this.responseText;
        bl.tinymce();
    }
    if(!form) {
       req.OnLoading = function() {
          $('drk_tabsContent').innerHTML = Preloader('100%',200);
       }
    }
    /** Catch all $_GET in location.hash **/
    var exp = location.hash.replace("#","");
    exp = exp.split('&');
    for(var i = 0; i < exp.length; i++) {
        var brk = exp[i].split('=');
        req.AddParam(brk[0],brk[1]);
    }
    if (form) req.SendForm(form);else if (phpfile) req.Send(phpfile);else req.Send('index.ajax.php');
}
function Preloader(x,y) {
    return '<table width=\''+x+'\' height=\''+y+'\'><tr><td align=\'center\'><img src=\'/gfx/preloader.gif\' /></td></tr></table>';
}
function judgesMenu() {
   var req = mint.Request();
    req.AddParam('opt','judgesMenu');
    req.Send('options.ajax.php'); 
}
function WalletSMS(id) {
    var req = mint.Request();
    req.AddParam('sms_type',id);
    req.AddParam('opt','WalletSMS');
    req.Send('options.ajax.php');
    req.OnSuccess = function() {
        $('sms_content_change').innerHTML = this.responseText;
    }
}
function EditComment(id) {
    $('com'+id+'div').toggle();
    $('com'+id+'inputs').toggle();
}

function EditCommentEnd(id) {
    $('com'+id+'divtxt').innerHTML = $('com'+id+'text').value;
    $('com'+id+'div').toggle();
    $('com'+id+'inputs').toggle();
}

function commentQuote(cid) {
    var req = mint.Request();
    req.AddParam('quoteid',cid);
    req.AddParam('opt','quotebyid');
    req.Send('options.ajax.php');
    var PosX = getXpos($('text'));
    var PosY = getYpos($('text'));
    //$('text').value = cid;
    req.OnSuccess = function() {
        window.scrollTo(PosX,PosY);
        $('text').value = this.responseText;
    }
}
function commentBbcode(code) {
    /*if(StartSelect != EndSelection) {
        var str = $('text').value.substring(StartSelect,EndSelect);
        str.replace(str, '['+code+']'+str+'[/'+code+']');*/
    var exp = code.split('=');
    if(exp.length == 2) {
        if ($('text').selection) { // for IE
            //alert($('text').selection.createRange().text);
            var str = $('text').selection.createRange().text;
            var content = $('text').value.replace(str, '['+exp[0]+'='+exp[1]+']'+str+'[/'+exp[0]+']');
            $('text').value = content;
        } else if (typeof $('text').selectionStart != 'undefined') { // for FF, Opera etc...
            //$('text').value.substring($('text').selectionStart, $('text').selectionEnd);
            var str = $('text').value.substring($('text').selectionStart, $('text').selectionEnd);
            var content = $('text').value.replace(str, '['+exp[0]+'='+exp[1]+']'+str+'[/'+exp[0]+']');
            $('text').value = content;
        } else {
            $('text').value = $('text').value + '['+exp[0]+'='+exp[1]+'][/'+exp[0]+']';
        }
    }else{
        if ($('text').selection) { // for IE
            //alert($('text').selection.createRange().text);
            var str = $('text').selection.createRange().text;
            var content = $('text').value.replace(str, '['+code+']'+str+'[/'+code+']');
            $('text').value = content;
        } else if (typeof $('text').selectionStart != 'undefined') { // for FF, Opera etc...
            //$('text').value.substring($('text').selectionStart, $('text').selectionEnd);
            var str = $('text').value.substring($('text').selectionStart, $('text').selectionEnd);
            var content = $('text').value.replace(str, '['+code+']'+str+'[/'+code+']');
            $('text').value = content;
        } else {
            $('text').value = $('text').value + '['+code+'][/'+code+']';
        }
    }
    /*
    if($('text').getSelection) {
        $('text').getSelection.replace(str, '['+code+']'+$('text').getSelection+'[/'+code+']');
    }else{
        $('text').value = $('text').value + '['+code+'][/'+code+']';
    }
    alert($('text').getSelection);
    */
}
/* WALLET */
function showMe(it, box) {
    var vis = (box.checked) ? "block" : "none";
    document.getElementById(it).style.display = vis;
}
/* ADMIN */
function todoShow(id) {
    var req = mint.Request();
    req.AddParam('type','todoShow');
    req.AddParam('todoID',id);
    req.OnSuccess = function() {
       RemoveElement('showTODO');
       CreateDiv('showTODO',400,0,'showTODO'+id,'Podgląd',this.responseText,100,-430);
    }
    req.Send('admin.ajax.php');
}
function validateWallet(method) {
        var error = false;
        if(method == 'pp') {
            // isEmpty
            if (isEmpty('name_surname')==false) {error = true; isEmpty('name_surname');}
            if (isEmpty('street_address')==false) {error = true; isEmpty('street_address');}
            if (isEmpty('city_code')==false) {error = true; isEmpty('city_code');}
            if (isFloat('data4', 'Podaj kwotę!')==false) {error = true; isFloat('data4', 'Podaj kwotę!');}
        }
        // ELSE
        //if(error) return false;else return true;
        if(error == true) return false;else if(error == false) return true;
}
/* VALIDATE FORM FIELDS */
function validateApp2(admin) {
    return validateApp(admin);
}
function validateApp(admin) {
        var error = false;
        // isDate
        if (isDate('cheat_date','Stosuj format daty (DD/MM/RRRR)')==false) { var error = true; isDate('cheat_date','Stosuj format daty (DD/MM/RRRR)'); }
        // isSID
        if (isSID('steamid')==false) { var error = true; isSID('steamid'); }
        // isEmpty
        if (isEmpty('server_ip')==false) {var error = true; isEmpty('server_ip');}
        if (isEmpty('nick')==false) {var error = true; isEmpty('nick');}
        //if (isEmpty('cheater_profil')==false) {isEmpty('cheater_profil'); var error;}
        if (isEmpty('status_link')==false) {var error = true; isEmpty('status_link');}
        if (isEmpty('what_cheat')==false) {var error = true; isEmpty('what_cheat');}
        if (isEmpty('cheat_time')==false) {var error = true; isEmpty('cheat_time');}
        //if (isEmpty('demo_link')==false && isEmpty('other_link')==false) {var error = true; isEmpty('demo_link');isEmpty('other_link');}
        if(admin) {
            $('appid-judge_mid').style.display = 'none';
            if ($('judge_mid').value == 0) {
                var error = true;
                if($('appid-judge_mid').style.display == 'none') $('appid-judge_mid').style.display = 'block';
                $('appid-judge_mid').innerHTML = 'Wybierz sędziego!';
            }
        }
        /*$('appid-judge_mid').style.display = 'none';
        if ($('judge_mid').value == 0) {
            var error = true;
            if($('appid-judge_mid').style.display == 'none') $('appid-judge_mid').style.display = 'block';
            $('appid-judge_mid').innerHTML = 'Wybierz sędziego!';
        }*/
        /*if (isEmpty('proofs_demo')) {if(!isEmpty('proofs_links')) var error = false;else {var error = true;isEmpty('proofs_demo')}}
        if (isEmpty('proofs_links')) {if(!isEmpty('proofs_demo')) var error = false;else {var error = true;isEmpty('proofs_links')}}
        if (isEmpty('proofs_demo')==false && (!isEmpty('proofs_links'))) { var error = false;}
        if (isEmpty('proofs_links')==false && (!isEmpty('proofs_demo'))) { var error = false;}*/
        // ELSE
        $('appid-league_link').style.display == 'none';
        $('appid-league_link').innerHTML = '';
        $('league_link').className = 'bl_light_input';
        $('appid-profile_link').style.display == 'none';
        $('appid-profile_link').innerHTML = '';
        $('profile_link').className = 'bl_light_input';
        if ($('league_type').value > 0) { if(isEmpty('league_link')==false) { var error = true; isEmpty('league_link')}if(isEmpty('profile_link')==false) { var error = true; isEmpty('profile_link')}isLeague('league_type')}
        else if ($('league_type').value == 0) { var error = true; isLeague('league_type');}
        if(error == true) return false;else if(error == false) return true;
}
function validateAppEdition(admin) {
        var error = false;
        // isDate
        if (isDate('cheat_date','Stosuj format daty (DD/MM/RRRR)')==false) { var error = true; isDate('cheat_date','Stosuj format daty (DD/MM/RRRR)'); }
        // isSID
        if (isSID('steamid')==false) { var error = true; isSID('steamid'); }
        // isEmpty
        if (isEmpty('server_ip')==false) {var error = true; isEmpty('server_ip');}
        if (isEmpty('nick')==false) {var error = true; isEmpty('nick');}
        //if (isEmpty('cheater_profil')==false) {isEmpty('cheater_profil'); var error;}
        if (isEmpty('status_link')==false) {var error = true; isEmpty('status_link');}
        if (isEmpty('what_cheat')==false) {var error = true; isEmpty('what_cheat');}
        if (isEmpty('cheat_time')==false) {var error = true; isEmpty('cheat_time');}
        //if (isEmpty('demo_link')==false && isEmpty('other_link')==false) {var error = true; isEmpty('demo_link');isEmpty('other_link');}
        if(admin) {
            $('appid-judge_mid').style.display = 'none';
            if ($('judge_mid').value == 0) {
                var error = true;
                if($('appid-judge_mid').style.display == 'none') $('appid-judge_mid').style.display = 'block';
                $('appid-judge_mid').innerHTML = 'Wybierz sędziego!';
            }
        }
        /*if (isEmpty('proofs_demo')) {if(!isEmpty('proofs_links')) var error = false;else {var error = true;isEmpty('proofs_demo')}}
        if (isEmpty('proofs_links')) {if(!isEmpty('proofs_demo')) var error = false;else {var error = true;isEmpty('proofs_links')}}
        if (isEmpty('proofs_demo')==false && (!isEmpty('proofs_links'))) { var error = false;}
        if (isEmpty('proofs_links')==false && (!isEmpty('proofs_demo'))) { var error = false;}*/
        // ELSE
        $('appid-league_link').style.display == 'none';
        $('appid-league_link').innerHTML = '';
        $('league_link').className = 'bl_light_input';
        $('appid-profile_link').style.display == 'none';
        $('appid-profile_link').innerHTML = '';
        $('profile_link').className = 'bl_light_input';
        if ($('league_type').value > 0) { if(isEmpty('league_link')==false) { var error = true; isEmpty('league_link')}if(isEmpty('profile_link')==false) { var error = true; isEmpty('profile_link')}}
        else if ($('league_type').value == 0) { var error = true; isLeague('league_type');}
        if(error == true) return false;else if(error == false) return true;
}
function isFloat(elem,helperMsg) {
    var floatExpression = /^[0-9-,.]+$/;
    if($(elem).value.match(floatExpression)) {
        if($('appid-'+elem).style.display == 'block') {
            $('appid-'+elem).style.display == 'none';
            $('appid-'+elem).innerHTML = '';
        }
        if($(elem).className = 'bl_input-error radius') {
            $(elem).className = 'bl_light_input radius';
        }
        //return true;
    }else if($(elem).value == '') {
        $('appid-'+elem).style.display = 'block';
        $('appid-'+elem).innerHTML = 'Uzupełnij pole.';
        $(elem).className = 'bl_input-error radius';
        $(elem).focus();
        return false;
    }else{
        $('appid-'+elem).style.display = 'block';
        $('appid-'+elem).innerHTML = helperMsg;
        $(elem).className = 'bl_input-error radius';
        $(elem).focus();
        return false;
    }
}
function isEmpty(elem) {
    if($(elem).tagName == 'TEXTAREA') {
        var classNameStyle = 'bl_appform_white_textarea radius';
        var classNameStyleError = 'bl_appform_white_textarea_red radius';
    }else{
        var classNameStyle = 'bl_light_input radius';
        var classNameStyleError = 'bl_input-error radius';
    }
    if($(elem).value.length == 0 || $(elem).value == 0) {
        $('appid-'+elem).style.display = 'block';
        $('appid-'+elem).innerHTML = 'Uzupełnij.';
        $(elem).className = classNameStyleError;
        $(elem).focus();
        return false;
    }else{
       if($('appid-'+elem).style.display == 'block') {
            $('appid-'+elem).style.display == 'none';
            $('appid-'+elem).innerHTML = '';
        }
        if($(elem).className = classNameStyleError) {
            $(elem).className = classNameStyle;
        }
        //return true;
    }
}
function isLeague(elem) {
    if($(elem).value == 0) {
        $('appid-'+elem).style.display = 'block';
        $('appid-'+elem).innerHTML = 'Wybierz.';
        $(elem).focus();
        return false;
    }else{
       if($('appid-'+elem).style.display == 'block') {
            $('appid-'+elem).style.display == 'none';
            $('appid-'+elem).innerHTML = '';
        }
        //return true;
    }
}
function isNumeric(elem, helperMsg) {
    var numericExpression = /^[0-9]+$/;
    if($(elem).value.match(numericExpression)) {
        if($('appid-'+elem).style.display == 'block') {
            $('appid-'+elem).style.display == 'none';
            $('appid-'+elem).innerHTML = '';
        }
        if($(elem).className = 'bl_input-error radius') {
            $(elem).className = 'bl_light_input radius';
        }
        //return true;
    }else if($(elem).value == '') {
        $('appid-'+elem).style.display = 'block';
        $('appid-'+elem).innerHTML = 'Uzupełnij pole.';
        $(elem).className = 'bl_input-error radius';
        $(elem).focus();
        return false;
    }else{
        $('appid-'+elem).style.display = 'block';
        $('appid-'+elem).innerHTML = helperMsg;
        $(elem).className = 'bl_input-error radius';
        $(elem).focus();
        return false;
    }
}
function isDate(elem, helperMsg) {
    var lowerCaseValue = $(elem).value.toLowerCase();
    // check for empty or default
    if(lowerCaseValue == '') {
        var info = 'Uzupełnij datę';
    }else{
        var exp = lowerCaseValue.split('/');
        // check for invalid date
        if(exp.length == 3) {
            var numericExpression = /^[0-9]+$/;
            var currentTime = new Date()
            var year = currentTime.getFullYear();
            var month = currentTime.getMonth() + 1;
            var day = currentTime.getDate();
            
            if(exp[0] > 31  || exp[0].match(numericExpression) == null) var info = 'Nieprawidłowa data.';
            if(exp[1] > 12 || exp[1].match(numericExpression) == null) var info = 'Nieprawidłowa data.';
            if(exp[2] < year-2 || exp[2] > year || exp[2].match(numericExpression) == null) var info = 'Nieprawidłowa data.';
        }else{
            var info = 'Błędny format daty.';
        }
    }
    // INFO
    if(info) {
        $('appid-'+elem).style.display = 'block';
        $('appid-'+elem).innerHTML = info+'<br />'+helperMsg;
        $(elem).className = 'bl_input-error radius';
        if(lowerCaseValue == '')
            $(elem).value = 'DD/MM/RRRR';
        $(elem).focus();
        return false;
    }else{
        if($('appid-'+elem).style.display == 'block') {
            $('appid-'+elem).style.display == 'none';
            $('appid-'+elem).innerHTML = '';
        }
        if($(elem).className = 'bl_input-error radius') {
            $(elem).className = 'bl_light_input radius';
        }
        //return true;
    } 
}
function isSID(elem) {
    var lowerCaseValue = $(elem).value.toLowerCase();
    if(lowerCaseValue == '') var info = 'Uzupełnij.';
    else{
        //STEAM_0:1:17538332
        lowerCaseValue = lowerCaseValue.replace("steam_","");
        exp = lowerCaseValue.split(':');
        if(exp.length == 3) {
            var numericExpression = /^[0-9]+$/;
            for(i=0;i<exp.length;i++) {
                if(exp[i].match(numericExpression) == null) var info = 'Niepoprawny SID.';
            }
        }else{
            var info = 'Niepoprawny SID';
        }
    }
    if(info) {
        $('appid-'+elem).style.display = 'block';
        $('appid-'+elem).innerHTML = info;
        $(elem).className = 'bl_input-error radius';
        $(elem).focus();
        return false;
    }else{
        if($('appid-'+elem).style.display == 'block') {
            $('appid-'+elem).style.display == 'none';
            $('appid-'+elem).innerHTML = '';
        }
        if($(elem).className = 'bl_input-error radius') {
            $(elem).className = 'bl_light_input radius';
        }
        //return true;
    }
}
// main function to process the fade request //
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}
function ScrollToElement(id) {
    if ($(id)) {
        window.scrollTo(GetX($(id)),GetY($(id)));
    }
    return false;
}
// UPLOADER
function startUpload(layer) {
    document.getElementById(layer).style.visibility = 'visible';
    return true;
}
function stopUpload(success,layer,process,id,page) {
      var upload_result = '';
      if (success == 1) {
        setLocationHash('array','adm=news,action=edit,id='+id+',page='+page);
        SendRequest();
        /* document.getElementById(layer).innerHTML =
           '<span>Plik został wgrany!<\/span>';*/
      }else if (success == 2) {
        //setLocationHash('array','adm=news,action=edit,id='+id+',page='+page);
        //SendRequest();
        ScrollToElement(layer);
        document.getElementById(process).style.visibility = 'hidden';
        document.getElementById(layer).innerHTML = '<span>Niedozwolone rozszerzenie pliku!<\/span>';
      }else{
        ScrollToElement(layer);
        document.getElementById(process).style.visibility = 'hidden';
         document.getElementById(layer).innerHTML = 
           '<span>Wystąpił błąd!<\/span>';      
      }
      return true;   
}
function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
}

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
} 
function mousePosition(e) {
    var pozX = 0;
    var pozY = 0;
   if (!e) var e = window.event;
   if (e.pageX || e.pageY) { //Firefox
    pozX = e.pageX;
    pozY = e.pageY;
   } else if (e.clientX || e.clientY) { //IE
    pozX = e.clientX + document.body.scrollLeft;
    pozY = e.clientY + document.body.scrollTop;
   }
   return [pozX,pozY]
}
function moveDiv(id,evt) {
    $(id).onmousemove = function() {
        var pos = mousePosition(evt);
        if($(id)) {
            $(id).style.position = 'relative';
            $(id).style.left = pos[0];
            $(id).style.top = pos[1];
        }
    };
}
function RemoveElement(divNum) {
    if ($(divNum)) {
    //var d = document.getElementById('myDiv');
    var olddiv = document.getElementById(divNum);
    document.body.removeChild(olddiv);
    }
}
function CreateDiv(id,width,height,obj,title,inner,opacity,leftab,topab) {
    var newdiv = document.createElement('div');
    var left = getXpos($(obj))+5;
    var top = getYpos($(obj))+5;
    newdiv.setAttribute('id', id);
    if (left || top) {
        if(leftab) left = left + leftab;
        if(topab) top = top + topab;
        newdiv.style.position = "absolute";
        newdiv.style.left = left+"px";
        newdiv.style.top = top+"px";
    }
    if (width > 0) {
       newdiv.style.width = width+"px";
       var width100 = 'style="width:100%;"';
    }else var width100 = '';
    var htmldiv;
    htmldiv = '<div class="bl_dialogwindow radius" '+width100+'>';
    /*
    if (title != 'Menu') {
        htmldiv += '<div class="bl_dialogwindow-t" id="'+id+'topmove"><div class="bl_dialogwindow-tpad">'+title;
        htmldiv += '<img src="/gfx/window/cross.png" alt="" vspace="1" style="cursor:pointer;" onclick=\'RemoveElement("'+id+'");\' hspace="0" title="Zamknij okno" align="right" />'
        htmldiv += '</div></div>';
    }
    */
    htmldiv += '<a onclick=\'RemoveElement("'+id+'");\' title="Zamknij okno" class="close">X</a>'
    
    htmldiv += '<div class="bl_dialogwindow-c" id="'+id+'asdcontentdiv">'+inner+'</div></div>';
    if (inner) newdiv.style.zIndex = 999; else newdiv.style.zIndex = 0;
    newdiv.innerHTML = htmldiv;
    document.body.appendChild(newdiv);
    //fadeaction(id,'in');
    // drag and drop
    /*
    var box = mint.gui.RegisterDragObject(id); // object which we want to move
    box.AddGrip(id+"topmove"); // object by which we can move
    */
}
function CreateElement(id,type,width,height,obj,bg,border,inner,opacity,leftab,topab) {
    var newdiv = document.createElement(type);
    var left = getXpos($(obj))+20;
    var top = getYpos($(obj))+20;
    /*var getMouse = getMouseXY(e);
    mouse = getMouse.split(',');
    var mouseX = mouse[0];
    var mouseY = mouse[1];*/
    newdiv.setAttribute('id', id);
    if (left || top) {
        if(leftab) left = left + leftab;
        if(topab) top = top + topab;
        newdiv.style.position = "absolute";
        newdiv.style.left = left+"px";
        newdiv.style.top = top+"px";
    }
    /*if (left || top) {
        newdiv.style.position = "absolute";
        newdiv.style.left = mouseX+"px";
        newdiv.style.top = mouseY+"px";
    }*/
    if (width > 0) newdiv.style.width = width+"px";
    if (height > 0) newdiv.style.height = height+"px";

    if(opacity > 0) {
        newdiv.style.opacity = opacity/100;
        newdiv.style.filter = 'alpha(opacity='+opacity+')';
    }
    if (bg) newdiv.style.background = bg;
    if (border) newdiv.style.border = border;
    if (inner) newdiv.style.zIndex = 999; else newdiv.style.zIndex = 0;
    newdiv.innerHTML = inner;
    
    document.body.appendChild(newdiv);
}
function showPayment(id) {
    var req = mint.Request();
    req.AddParam('opt','showPayment');
    req.AddParam('id',id);
    req.OnSuccess = function() {
       RemoveElement('showPayment');
       CreateDiv('showPayment',300,0,'pay'+id,'Szczegóły',this.responseText);
    }
    req.Send('options.ajax.php');
}
function judgeOptions(aid,status) {
    var content = "<div style='padding:5px;text-align:center;' id='judges_option_divtxt'><div id='rejectApptxt'></div>";
    if(status == 0 || status == 3)
        content += "<a title='Zatwierdź' onclick=\"judgeOptionsSend('"+aid+"','1');RemoveElement('judge_options');\" class='confirm'>Zatwierdź</a>";
    if(status == 0 || status == 1)
        content += "<a title='Odrzuć' onclick=\"rejectApp('"+aid+"',this);RemoveElement('judge_options');\" class='disagree'>Odrzuć</a>";
    if(status == 0 || status == 1 || status == 3)
        content += "<a title='Edytuj' onclick=\"window.location = 'applications,edit,"+aid+".html';RemoveElement('judge_options');\" class='edit'>Edytuj</a>";
    if(status == 0 || status == 1 || status == 3)
        content += "<a title='Usuń' onclick=\"judgeOptionsSend('"+aid+"','5');RemoveElement('judge_options');\" class='remove'>Usuń</a>";
    content += "</div>";
    
    if ($('judge_options')) RemoveElement('judge_options'); else CreateDiv('judge_options',0,0,'applicationid'+aid,'opcje',content,'',-10,15);
}
function judgeOptionsSend(aid,status) {
    //alert(status);
    var req = mint.Request();
    req.AddParam('opt','appOptions');
    req.AddParam('aid',aid);
    req.AddParam('status',status);
    req.AddParam('comment',$('rejectApptxt').value);
    
    req.OnLoading = function() {
        $('judge_optionsasdcontentdiv').innerHTML = Preloader(200,50);
    }
    req.OnSuccess = function() {
        //window.location = window.location;
        setTimeout("location.reload(true);",1);
    }
    req.Send('options.ajax.php');
}
function JudgeVote(vote,id,grade,recall,action) {
    if(grade == 0 && action == 1) {
        if(vote == 1) var divId = 'votehJudgeyes';else var divId = 'votehJudgenot';
        var content = "<div style='padding:5px;text-align:center;' id='JudgeVote_divtxt'><textarea rows='5' cols='30' name='comment' id='JudgeCommenttxt' class='bl_appform_white_textarea' style='float:none;'></textarea><br /><img src='/gfx/icons/add-button.png' alt='' vspace='0' hspace='0' onclick=\"JudgeVote('"+vote+"','"+id+"','"+grade+"','"+recall+"');RemoveElement('JudgeVote');return false;\" style='cursor:pointer;' /></div>";
        RemoveElement('JudgeVote');
        CreateDiv('JudgeVote',0,0,divId,'Uzasadnienie',content);
    }else{
        var req = mint.Request();
        req.AddParam('opt','JudgeVote');
        req.AddParam('aid',id);
        req.AddParam('grade',grade);
        req.AddParam('vote',vote);
        if(grade == 0 && $('JudgeCommenttxt').value) req.AddParam('text',$('JudgeCommenttxt').value);
        if(recall == 'recall') req.AddParam('recall','recall');
           req.OnLoading = function() {
            $('JudgeVoteasdcontentdiv').innerHTML = Preloader(200,50);
           }
           req.OnSuccess = function() {
                //alert(this.responseText);
                //window.location = this.responseText;
                setTimeout("location.reload(true);",1);
            }
        req.Send('options.ajax.php');
    }
}
function rejectApp(aid,obj) {
    var content = '<div style="padding:5px;text-align:center;" id="rejectApp_divtxt">Podaj powód odrzucenia zgłoszenia:<br /><br /><textarea rows="5" cols="30" name="comment" id="rejectApptxt" class="bl_appform_white_textarea" style="float:none;"></textarea><br /><img src="/img/theme/content/wallet/button-accept.png" alt="" vspace="0" hspace="0" onclick=\'judgeOptionsSend("'+aid+'","3");RemoveElement("rejectApp");\'style="cursor:pointer;" /></div>';
    
    RemoveElement('rejectApp');
    CreateDiv('rejectApp',0,0,obj,'Powód odrzucenia zgłoszenia',content,'',-200,10);
}
function missVote(appid,recall) {
    var req = mint.Request();
    req.AddParam('opt','missVote');
    req.AddParam('appid',appid);
    if(recall == 'recall') req.AddParam('recall','recall');
    req.OnSuccess = function() {
        //alert(this.responseText);
        //window.location = this.responseText;
        setTimeout("location.reload(true);",1);
    }
    req.Send('options.ajax.php');
}
function showEditLog(id,obj) {
    var req = mint.Request();
    req.AddParam('opt','showEditLog');
    req.AddParam('id',id);
    req.OnSuccess = function() {
        RemoveElement('showEditLog');
        CreateDiv('showEditLog',500,0,obj,'Szczegóły edycji',this.responseText);
    }
    req.Send('options.ajax.php');
}
function statisticsHelp(obj) {
    var content = '<div style="width:100%;text-align:center;"><strong>1/2/3/4/5/6</strong></div>'+
                  '<ul style="list-style-type:decimal;margin:0;padding:0;margin-top:5px;padding-top:5px;padding-left:15px;">'+
                  '<li style="margin-bottom:7px;">zbanowanych cheaterów<br /><span class="bl_span_gray">(dotyczy sędziów)</span></li>'+
                  '<li style="margin-bottom:7px;">osób uniewinnionych, czyli rozpatrzonych pozytywnie podczas odwołania<br /><span class="bl_span_gray">(dotyczy sędziów)</span></li>'+
                  '<li style="margin-bottom:7px;">osób, których podania zostały odrzucone przez sędziów<br /><span class="bl_span_gray">(dotyczy sędziów)</span></li>'+
                  '<li style="margin-bottom:7px;">zgłoszonych oraz pozytywnie rozpatrzonych cheaterów podczas głosowania nad zbanowaniem</li>'+
                  '<li style="margin-bottom:7px;">celnych głosów podczas głosowania nad zbanowaniem</li>'+
                  '<li>chybionych głosów podczas głosowania nad zbanowaniem</li>'+
                  '</ul>';
    if ($('statisticsHelp')) RemoveElement('statisticsHelp'); else CreateDiv('statisticsHelp',200,0,obj,'Statystyki - pomoc',content,'',-10,15);
}
function memberRecall(aid,act) {
    var req = mint.Request();
    req.AddParam('aid',aid);
    var content = '<div style="text-align:center;" id="memberRecall_divtxt"><form action="options.ajax.php" method="post" id="Recallform"><input type="hidden" name="opt" value="memberRecall" /><input type="hidden" name="aid" value="'+aid+'" /><textarea rows="5" cols="30" name="comment" id="recallCommenttxt" class="bl_appform_white_textarea radius" style="float:none;"></textarea><br />'+
	'<a class="bl_button_gray radius" onclick=\'memberRecall("'+aid+'","1");return false;\'>AKCEPTUJ</a>'+
    '<br /><span style="font-size:10px;color:gray;">Koszt odwołania to podwójny koszt zgłoszenia</span><div id="memberRecallpackages"></div><div id="memberRecallinfo"></div></div>';
    if(!act) {
        RemoveElement('memberRecall');
        CreateDiv('memberRecall',325,0,'memberRecallimg','Powód odwołania',content);
        req.AddParam('opt','memberPaymentsForm');
        req.OnSuccess = function() {
            $('memberRecallpackages').innerHTML = this.responseText;
        }
        req.Send('options.ajax.php');
        return false;
    }else if(act == 1) {
       req.AddParam('opt','memberRecall');
       req.AddParam('comment',$('recallCommenttxt').value);
       req.AddParam('pay_method',$('pay_method').value);
       req.OnSuccess = function() {
        var returnText = this.responseText;
        if(returnText.indexOf('error.') >= 0) {
            returnText = returnText.replace('error.','');
            $('memberRecallinfo').innerHTML = returnText;
        }else $('memberRecall_divtxt').innerHTML = returnText;
       }
       req.Send('options.ajax.php');
	   setTimeout('location.reload(true);',1000);
       return false;
    }
}
function delVote(vid,status) {
    var req = mint.Request();
    req.AddParam('opt','delVote');
    req.AddParam('voteid',vid);
    req.AddParam('status',status);
    req.OnSuccess = function() {
        //alert(this.responseText);
        //window.location = this.responseText;
        setTimeout("location.reload(true);",1);
    }
    req.Send('options.ajax.php');
}
function getXpos(obj) {
    var x = 0;
    if (obj) {
        while(obj.offsetParent) {
            x += obj.offsetLeft;
            obj = obj.offsetParent;
        }
        return x;
    }
}
function getYpos(obj) {
    var y = 0;
    if (obj) {
        while(obj.offsetParent) {
            y += obj.offsetTop;
            obj = obj.offsetParent;
        }
        return y;
    }
}
function keyCheck(evt) {
    return evt.keyCode;
}
