var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}

var timeOut = null;

var loggedIn = false;

// global flag
var isIE = false;
if (window.ActiveXObject) {
    isIE = true;
}

// global request and XML document objects
var req;

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function checkMessages() {
    if(loggedIn) {
        // branch for native XMLHttpRequest object
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = messageStateChange;
            req.open("GET", "my.php?checkMessages", true);
            req.send(null);
        // branch for IE/Windows ActiveX version
        } else if (window.ActiveXObject) {
            isIE = true;
            req = new ActiveXObject("Microsoft.XMLHTTP");
            if (req) {
                req.onreadystatechange = messageStateChange;
                req.open("GET", "my.php?checkMessages", true);
                req.send();
            }
        }
        
        if(timeOut) {
            window.clearTimeout(timeOut);
        }
        timeOut = window.setTimeout("checkMessages()",60000);
    }
}

function messageStateChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            eval(req.responseText);
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}

function newMessage(newCount, unreadCount) {
    if(document.getElementById("messageAlert")) {
        closeMessageAlert();
    }
    
    if(newCount > 0) {
        var bodyElement = document.getElementsByTagName("body")[0];
        var divElement = document.createElement("div");
        divElement.setAttribute("class", "alertBox");
        divElement.setAttribute("id", "messageAlert");
        bodyElement.appendChild(divElement);

        if(!isIE) {
            var y = (document.height - 150) / 2;
            var x = (document.width - 250) / 2;
            divElement.style.top = y + 'px';
            divElement.style.left = x + 'px';
        } else {
            var y = (document.body.offsetHeight - 150) / 2;
            var x = (document.body.offsetWidth - 250) / 2;
            divElement.style.posTop =  y;
            divElement.style.posLeft = x;
            divElement.style.position = 'absolute';
            divElement.style.width = '250px';
            divElement.style.height = '150px';
            divElement.style.backgroundColor = '#FFFFFF';
            divElement.style.border = '2px solid #000000';
        }
        
        var tbl = document.createElement("table");
        tbl.setAttribute("width", "100%");
        tbl.setAttribute("border", "0");
        tbl.setAttribute("cellspacing", "0");
        tbl.setAttribute("cellpadding", "3");
        
        var tbody = document.createElement("tbody");
        tbl.appendChild(tbody);
        
        var row1 = document.createElement("tr");
        tbody.appendChild(row1);
        var row11 = document.createElement("td");
        row1.appendChild(row11);
        row11.setAttribute("align", "center");
        var img1 = document.createElement("img");
        img1.setAttribute("src", "images/mesajvar.gif");
        img1.setAttribute("width", "200");
        img1.setAttribute("height", "44");
        img1.setAttribute("alt", "Mesajınız var");
        row11.appendChild(img1);
        
        var row2 = document.createElement("tr");
        tbody.appendChild(row2);
        var row21 = document.createElement("td");
        row2.appendChild(row21);
        row21.setAttribute("align", "center");
        row21.setAttribute("style", "padding-top:20px;");
        var messageText = document.createTextNode("Posta kutunuzda "
        + newCount + " yeni, "
        + unreadCount + " okunmamış mesajınız var.");
        row21.appendChild(messageText);
        
        var row3 = document.createElement("tr");
        tbody.appendChild(row3);
        var row31 = document.createElement("td");
        row3.appendChild(row31);
        row31.setAttribute("align", "center");
        row31.setAttribute("style", "padding-top:20px;");
        
        var button1 = document.createElement("input");
        button1.setAttribute("name", "pk");
        button1.setAttribute("value", "Posta Kutusu");
        button1.setAttribute("type", "button");
        if(isIE) {
            button1.attachEvent("onclick", gotoMailBox);
        } else {
            button1.addEventListener("click", gotoMailBox, false);
        }
        row31.appendChild(button1);

        var button2 = document.createElement("input");
        button2.setAttribute("name", "cl");
        button2.setAttribute("value", "Kapat");
        button2.setAttribute("type", "button");

        if(isIE) {
            button2.attachEvent("onclick", closeMessageAlert);
        } else {
            button2.addEventListener("click", closeMessageAlert, false);
        }

        row31.appendChild(button2);
        
        divElement.appendChild(tbl);
    }
}

function gotoMailBox() {
    self.location = 'my.php';
}

function closeMessageAlert() {
    var bodyElement = document.getElementsByTagName("body")[0];
    var divElement = document.getElementById("messageAlert");
    bodyElement.removeChild(divElement);
}

function bookmarksite(title, url){
    if (document.all)
    window.external.AddFavorite(url, title);
    else if (window.sidebar)
    window.sidebar.addPanel(title, url, "")
}