/*
GetAnnounce (bid, max, force)

sendCevap(bid) 
- Cevap kullaniyor


*/
var smallArray = new Array();
var bigArray = new Array();

function getannounce(bid,max,force,getdeleted) 
{
    if (getdeleted != true)
     getdeleted = false;
    //This sets a variable with the URL (and query strings) to our PHP script
    if (max == 'show') {
        // INCREASE VIEW COUNT;
        new Request({method: 'get', url: 'ajax.php'}).send("action=increaseviewcount&id=" + bid);
    }
    
    if (!force)
    {
        if (max == 'show') {
            //big array
            smallArray[bid] = $('t'+bid).innerHTML;
            if (bigArray[bid] != null) {
                $('t'+bid).set('html', bigArray[bid]);
                
            }
        } else {
            bigArray[bid] = $('t'+bid).innerHTML;
            if (smallArray[bid] != null) { 
                $('t'+bid).set('html', smallArray[bid]);
                
            }
        }
    }
    else
    {
    if (max == 'show') {
        new Request({method: 'get', url: 'ajax.php', onComplete: function(request) {
        $('t'+bid).set('html', request);
        bigArray[bid] = request;
        if (UnTip)
            UnTip();
        }
        }).send("action=getannounce&did="+bid+"&max="+max+"&getdeleted="+getdeleted);
    } else {
        new Request({method: 'get', url: 'ajax.php', onComplete: function(request) {
        $('t'+bid).set('html', request);
        smallArray[bid] = request;
        if (UnTip)
            UnTip();
        }
        }).send("action=getannounce&did="+bid+"&max="+max+"&getdeleted="+getdeleted);
    }
    }
    $$('img.lnk').each(function(img) {
        var src = img.getProperty('src');
        img.removeEvents('mouseenter');
        img.removeEvents('leave');
        img.addEvent('mouseenter', function() { img.setProperty('src',src.replace('0','1')); });
        img.addEvent('mouseleave', function() { img.setProperty('src',src); });
    });
}

function togglesearchbox()
{
    var vis = $('searchbox').getStyle('display');
    if (vis == 'none')
    {
        $('drpcategory').setStyle('display', 'none'); //ie6 fix
        $('searchbox').setStyle('display', 'block');
        $('h-ara').set('class', 'finger swap h-ara1');
    }
    if (vis == 'block')
    {
        $('searchbox').setStyle('display', 'none');
        $('drpcategory').setStyle('display', 'block'); //ie6 fix
        $('h-ara').set('class', 'finger swap h-ara0');
    }
}
function getDuyuruIntoDiv(divid, duyuruid)
{
    $(divid).set('html', '<div class="entry0" id=\"t' + duyuruid + '\"></div>');
    getannounce(duyuruid,'show',true, true);
}

function checkUserToDelete()
{
    
    poststr = $('modUserForm').toQueryString();
    new Request({method: 'post', url: 'ajax.php?action=checkUserToDelete', onComplete:
        function(request)
        {
            $('modUser').set('html', request);
        }
    }).send(poststr);
}

function deleteUser(userid)
{
    new Request({method: 'get', url: 'ajax.php', onComplete: function(request) {
        $('modUser').set('html', request);
        }
    }).send("action=deleteUser&userid=" + userid);
}
function getUserEmail()
{

    poststr = $('userEmailForm').toQueryString();
    new Request({method: 'post', url: 'ajax.php?action=getUserEmail', onComplete: function(request) {
        $('userEmail').set('html', request);
        }
    }).send(poststr);
}

function sendCevap(cid) {
    $('cvpSubmit').setProperty('disabled','true');
    poststr = $('myform' + cid).toQueryString();
    new Request({method: 'post', url: 'ajax.php?action=setAnswer', onComplete: function(request) {
        getannounce(cid, 'show', true, false);
        }
    }).send(poststr);
}

var verifydelete;

function deleteSelectedMessages()
{
    var s = false;
    $$('.messagecb').each(function(el) { if (el.checked) s = true; } );
    if (s)
    {
    $('deleteimg').setProperty('src','img/spinner.gif');
    poststr = $('inboxform').toQueryString();
    new Request({method: 'post',
        url: 'ajax.php?action=messageDelete',
        onComplete: function(request) {
        $('checkall').checked = 0;
        $('deleteimg').setProperty('src','img/del.png');
        $$('.messagecb').each(function(el) {
            if (el.checked) { el.checked = 0; $('tr' + el.getProperty('value')).dispose(); }
        } );
        
        }
    }).send(poststr);
    }
}

function deleteMessage(now, hash, where)
{
    if (verifydelete == null)
    {
    verifydelete = new Element('span', {
        'text': 'gerçekten mi?',
        'class': 'finger underline',
        'style': 'width: 200px; display: block;',
        'events' : {
        'click' : function() {
            $('deleteimg').setProperty('src','img/spinner.gif');
            new Request({
            method: 'post',
            url: 'ajax.php?action=messageDelete',
            onComplete: function(request) {
                $('deleteimg').setProperty('src','img/del.png');
                window.location = 'index.php?m=mbi';
            }}).send('now=' + now + '&sel[0]=' + hash);
        },
        'mouseover' : function() {
            this.setProperty('text', 'evet, sil!')
        },
        'mouseout' : function() {
            this.setProperty('text', 'gerçekten mi?')
        }
        }
    });
    verifydelete.inject(where, 'after');
    (function () {verifydelete.dispose();}).delay(5000);
    }
}

var verifymal;

function mallarSurusuneEkle(malid, where) {
    if (verifymal == null)
    {
    verifymal = new Element('span', {
        'text': 'gerçekten mi?',
        'class': 'finger underline',
        'style': 'width: 200px; display: block;',
        'events' : {
        'click' : function() {
            $('malimg').setProperty('src','img/spinner.gif');
            new Request({
            method: 'post',
            url: 'ajax.php?action=messageMalSet',
            onComplete: function(request) {
                $('malimg').setProperty('src','img/del.png');
                $('error').set('text', 'mallar sürüsüne eklendi. sizden gelen mesajları görebilir, ama hiç birine cevap veremez.').setStyle('display','block');
            }}).send('userid=' + malid);
        },
        'mouseover' : function() {
            this.setProperty('text', 'evet, maldır kendisi!')
        },
        'mouseout' : function() {
            this.setProperty('text', 'gerçekten mi?')
        }
        }
    });
    verifymal.inject(where, 'after');
    (function () {verifymal.dispose();}).delay(5000);
    }
}
function mallarFormRemoveMal() {
    var s = false;
    $$('.messagecb').each(function(el) { if (el.checked) s = true; } );
    if (s)
    {
    $('deleteimg').setProperty('src','img/spinner.gif');
    poststr = $('mallarform').toQueryString();
    new Request({method: 'post',
        url: 'ajax.php?action=messageMalDelete',
        onComplete: function(request) {
        $('checkall').checked = 0;
        $('deleteimg').setProperty('src','img/del.png');
        $$('.messagecb').each(function(el) { if (el.checked) { el.checked = 0; $('td' + el.getProperty('value')).dispose(); } } );
        
        }}).send(poststr);
    }
}

function sendNewMessage(close) {
    if ($('toid').getProperty('value') == '')
    {
	$('error').set('text',"Kime göndereceğinizi İnsan ara'dan seçiniz. Eğer İnsan ara'da sonuç gelmiyorsa ekşi duyuru'da bu kullanıcı yoktur.").setStyle('display','block');
	return;
    }
    else if ($('body').getProperty('value') == '' && $('subject').getProperty('value') == '')
    {
	$('error').set('text',"Konusu veya Olay'ı olmayan mesaj, mesaj değildir.").setStyle('display','block');
	return;
    }
    
    $('submit').setProperty('disabled','true');
    poststr = $('composeForm').toQueryString();
    new Request({method: 'post',
	url: 'ajax.php?action=sendNewMessage',
	onComplete: function(request) {
	    var el = new Element('div');
	    el.addClass('error');
	    if (request == 'true')
	    {
		el.set('html', 'mesajınız gönderildi');
		(function(){ if (close) self.close(); else window.location="index.php?m=mbi"; }).delay(1500);
	    }
	    else if (request == 'err_blocked')
	    {
		el.set('html', $('tousername').innerHTML + ' kullanıcısına mesaj gönderemezsiniz');
	    }
	
	    $('submit').setProperty('disabled',0);
	    el.inject('composeForm', 'top');
	}
    }).send(poststr);
}
function colorMessage()
{
    $$('div.unread').each(function (el) {
    var myFx = new Fx.Tween(el.getElement('.body'), { duration: 8000 });
    myFx.start('background-color', '#EEEEEE');
    el.removeClass('unread');
    });
    
}
        
function sendMessageCevap () {
    $('cvpSubmit').setProperty('disabled','true');
    poststr = $('messageCevapForm').toQueryString();
    new Request({method: 'post',
        url: 'ajax.php?action=messageCevap',
        onComplete: function(request) {
            if (request == 'err_blocked')
            {
            var el = new Element('div');
            el.addClass('error');
            el.set('html', $('touser').innerHTML + ' kullanıcısına mesaj gönderemezsiniz');
            el.inject('messageCevapForm', 'top');
            }
            else
            {
            var arr = JSON.decode(request);
            var messages = $('messages');
            for(var index in arr) {
                if (index != 'lastid')
                {
                var el = new Element('div');
                el.addClass('message unread');
                el.set('html', arr[index]);
                el.inject(messages);
                }
            }
            colorMessage();
            $('cvpSubmit').setProperty('disabled',0);
            $('lastid').set('value', arr['lastid']);
            $('rbody').set('value',"");
            }
        }
    }).send(poststr);
}
function setfav(id)
{
    new Request({method: 'get', url: 'ajax.php', onComplete: function(request) {
        $('fav'+id).setProperty('src','img/b_fav' + request + '.gif');
        }
    }).send("action=fav&id=" + id);
}

function setanswervisible (imgid, id, visible)
{
    new Request({method: 'get', url: 'ajax.php', onComplete: function(request) {
        newvisible = (visible == 0)?1:0;
        $('ci'+imgid).set('html', '<img src="css/edv3/img/b_check' + visible + '.gif" class="finger" onclick="setanswervisible('+imgid+','+id+','+newvisible+')">');
        }
    }).send("action=setanswervisible&did=" + id + "&cid=" + imgid + "&value=" + visible);
}

function cevap(cevapid, cid, warning)
{
    buttons = '<div align="right"><input type="button" class="button1" onclick="javascript:hen(\'body\', \'(bkz: \',\')\')" value="(bkz: )"></input><input type="button" class="button1"  onclick="javascript:hen(\'body\', \'`\',\'`\')" value="``"></input><input type="button" class="button1" onclick="javascript:hen(\'body\', \'(git: \',\')\')" value="(git: )"></input></div>';
    warningstr = (warning) ? '<strong>Bu soruya verdiğiniz cevap ekşi sözlük yazarı olmayan kişiler tarafından da okunabilecektir.</strong><br />' : '';
    $('c'+cevapid).setStyle('display','block');
    if (cid == 0)
    {
        s = '<form action="javascript:sendCevap(' + cevapid +');" name="myform'+cevapid+'" id="myform'+cevapid+'"><input name="id" type="hidden" value="'+cevapid+'" />' + buttons + '<textarea class="answertextbox" id="body" name="body" cols="50" rows="7"></textarea><br />' + warningstr + '<input type="submit" class="button1" id="cvpSubmit" name="cvpSubmit" value="Gönder" /><input type="button" class="button1" name="gizle" value="Gizle" onclick="cevapgizle('+cevapid+')"/></form>';
        $('c'+cevapid).set('html', s);
    }
    else
    {
        new Request({method: 'get', url: 'ajax.php', onComplete: function(request) {
                s = '<form action="javascript:sendCevap(' + cevapid + ');" name="myform'+cevapid+'" id="myform'+cevapid+'">' +
                '<input name="id" type="hidden" value="' + cevapid + '" /><input name="cid" type="hidden" value="' + cid + '" />' + buttons +
                '<textarea class="answertextbox" id="body" name="body" cols="50" rows="7">' + request + '</textarea><br />' +
                warningstr + '<input class="button1" type="submit" id="cvpSubmit" name="cvpSubmit" value="Gönder" />' +
                '<input class="button1" type="button" name="gizle" value="Gizle" onclick="cevapgizle(' + cevapid + ')"/></form>';
                $('c'+cevapid).set('html', s);
                }
            }).send("action=getanswertext&cevapid="+cid);
    }
}

function cevapgizle(bid)
{
    //$('c'+bid).set('html', '');
    $('c'+bid).setStyle('display','none');
}

function odd(u,w,h,x,y)
{
    if(!w)w=700;if(!h)h=500;if(!x)x=(screen.width-w)/2;if(!y)y=(screen.height-h)/2;
    var w=window.open(u,"_blank","resizable=yes,scrollbars=yes,top="+x.toString()+",left="+y.toString()+",width="+w.toString()+",height="+h.toString());
    w.focus();
}

function od(u,w,h,x,y)
{
    if(!w)w=320;if(!h)h=200;if(!x)x=(screen.width-w)/2;if(!y)y=(screen.height-h)/2;
    var w=window.open(u,"_blank","resizable=yes,scrollbars=yes,top="+x.toString()+",left="+y.toString()+",width="+w.toString()+",height="+h.toString());
    w.focus();
}

function fbshare(id)
{
    title = encodeURIComponent($('h' + id).innerHTML);
    var w=window.open("http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.eksiduyuru.com%2F%3Fm%3Dd%26s%3D1%26id%3D" + id + "&t=" + title,"_blank","resizable=yes,scrollbars=yes,width=600,height=400");
    w.focus();
}

function twitter(id)
{
    title = encodeURIComponent($('h' + id).innerHTML);
    var w=window.open("http://twitter.com/home?status=" + title + "+http%3A%2F%2Fwww.eksiduyuru.com%2F%3Fm%3Dd%26s%3D1%26id%3D" + id + "+%23%24d","_blank","resizable=yes,scrollbars=yes");
    w.focus();
}

function resize() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth - 17;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    
    if (myWidth >= 997)
        toggleDisplay(true);
    else
        toggleDisplay(false);
}
function toggleDisplay(show) { 
    if( show ){
        document.getElementById("sky").style.display = "block"; 
    } else { 
        document.getElementById("sky").style.display = "none";
    }
}
function refresh(id)
{
    $('reft' + id).setProperty('src','img/b_refreshrun.gif');
    if ($('refb' + id) != null)
        $('refb' + id).setProperty('src','img/b_refreshrun.gif');
    new Request({ method: 'get', url: 'ajax.php', onComplete: function(request) {
        $('t'+id).set('html', request);
        bigArray[id] = request;
        }
    }).send("action=getannounce&did=" + id + "&max=show");
    
    new Request({method: 'get', url: 'ajax.php', onComplete: function(request) {
        smallArray[id] = request;
        }
    }).send("action=getannounce&did=" + id + "&max=dontshow");
    
}
function setcategory(id, cat)
{
    $('WzBoDy').set('html', "<b>Lütfen bekleyiniz.</b>");
    new Request({method: 'get', url: 'ajax.php', onComplete: function(request) {
        refresh(id);
        if (UnTip)
            UnTip();
        }
    }).send("action=setcat&id=" + id + "&cat=" + cat);
}
function setinternetvisible(id, visibility)
{
    $('WzBoDy').set('html', "<b>Lütfen bekleyiniz.</b>");
    new Request({method: 'get', url: 'ajax.php', onComplete: function(request) {
        refresh(id);
        if (UnTip)
            UnTip();
        }
    }).send("action=setivis&id=" + id + "&visibility=" + visibility);
}
function rp1(img)  { img.setProperty('src',img.getProperty('src').replace('0','1')); }
function rp0(img)  { img.setProperty('src',img.getProperty('src').replace('1','0')); }

function hen(d,a,b)
{
  var o=document.getElementById(d);
  var tmp = o.scrollTop;
  o.focus();
  if(document.selection && !window.opera)
  {
      var rg=document.selection.createRange();
      if(rg.parentElement()==o) {
          rg.text = a+rg.text+b;
          rg.select();
        } else alert("lutfen once $eetmek istediginiz metni secin");
  }
  else if(o.selectionStart||o.selectionStart=='0')
  {
    var s = o.value;
    var end = o.selectionEnd;
    var start = o.selectionStart;
    o.value = s.substring(0,start)+a+s.substring(start,end)+b+s.substring(end);
    end += a.length+b.length;
    o.setSelectionRange(end, end);
  } else o.value += a+b;
  o.scrollTop = tmp; 
  return true;
}

hs.graphicsDir = 'cssjs/hs/';
hs.outlineType = 'rounded-white';
hs.lang = { 
    cssDirection: 'ltr',
    loadingText : 'Yükleniyor...',
    loadingTitle : 'Vazgeçmek için tıklayınız',
    focusTitle : 'Öne getirmek için tıklayınız',
    fullExpandTitle : 'Tam boyutları için tıklayınız (f)',
    creditsText : '',
    creditsTitle : '',
    restoreTitle : 'Resmi kapatmak için tıklayınız.'
};
function renderSearchBox()
{
  var searchbox = "<div id=\"searchbox\"><form action=\"index.php\" method=\"get\"><div class=\"stitle\">Pek geli\u015fkin Duyuru arama platformu</div><input type=\"hidden\" name=\"m\" value=\"ara\" /><input type=\"hidden\" name=\"s\" value=\"0\" /><table><tr><td>kelimelerin <strong>t\u00fcm\u00fc</strong></td><td><input type=\"text\" class=\"categorysearchbox\" name=\"araand\" size=\"10\"/></td></tr><tr><td><strong>aynen girildi\u011fi</strong> gibi</td><td><input type=\"text\" class=\"categorysearchbox\" name=\"araexact\" size=\"10\"/></td></tr><tr><td>kelimelerden <strong>herhangi biri</strong></td><td><input type=\"text\" class=\"categorysearchbox\" name=\"araor\" size=\"10\"/></td></tr><tr><td>bu kelimeler <strong>hari\u00e7</strong></td><td><input type=\"text\" class=\"categorysearchbox\" name=\"aranot\" size=\"10\"/></td></tr><tr><td colspan=\"2\"><div style=\"margin-right:6px; float:left;\"><input type=\"checkbox\" name=\"optttl\" value=\"1\" checked=\"checked\" disabled=\"disabled\" />Ba\u015fl\u0131kta ve duyuruda</div></td></tr><tr><td colspan=\"2\"><div class=\"right\"><input type=\"submit\" class=\"button1\" name=\"Submit\" value=\"ara\" /><div class=\"note\">duyuru id\'si aramak i\u00e7in kelimelerin t\u00fcm\u00fc alan\u0131na #1234 giriniz.</div></div><hr style=\"height:1px; border-top:1px; width:%100;\" /></td></tr><tr><td>yazar\u0131</td><td><input type=\"text\" class=\"categorysearchbox\" name=\"araposter\" size=\"10\"/></td></tr><tr><td colspan=\"2\"><div class=\"right\"><input type=\"submit\" class=\"button1\" name=\"Submit\" value=\"ara\" /></div></td></tr></table></form></div>";
  $('newSearch').set({html: searchbox});
}