﻿var _Date;
var GameSWF;
var _GameID;
var bUrl = document.URL;
var w;
var h;

function aramakontrol(formarama)
{
var aramaboyu = 4;
var yaziboyu = formarama.arama.value ;
if (formarama.arama.value == ""){
alert("Aramak istediğiniz oyun adını yazınız !","Hata");
formarama.arama.focus();
return false;
}
if (yaziboyu.length < aramaboyu){
alert("Girilen oyun adı  en az 4 harf olmalıdır !","Hata");
formarama.arama.focus();
return false;
}
};

function yorumgonder() {
if (yorumform.yorumisim.value == ""){
alert("Lütfen bir isim giriniz !","Hata");
yorumform.yorumisim.focus();
return false;
}
if (yorumform.yorumum.value == ""){
alert("Lütfen bir yorum giriniz !","Hata");
yorumform.yorumum.focus();
return false;
};
jQuery.ajax({
type: 'POST',//Bu kisim POST ve GET degerlerinden birini alabilir
url: 'yorumal.php',//Verinin gönderilecegi sayfa
data: $('#yorumform').serialize(),
error:function(){ $('#yorumtamam').html("Bir hata algılandı tekrar deneyiniz."); }, //Hata alinirsa ekrana bastirilacak veri
success: function(veri) { $('#yorumtamam').html("Yorumunuz alınmıştır teşekkür ederiz");}//Basarili olursa ekrana bastirilacak veri
});
yorumform.yorumisim.value = "" ;
yorumform.yorumum.value = "" ;
}; 


$(document).ready(function () {
    $("#MemberLoginBtn").click(function () {

        $("#MemberLoginMsgMain").show("normal");
        $("#MemberLoginMsgMainTxt").text("İşleminiz yapılıyor lütfen bekleyiniz...");

        var StrUserName = $("#MemberLoginKAdi").val();
        var StrPassword = $("#MemberLoginSifre").val();
        var StrRemember = $("#MemberLoginRemember:checked").val();

        if (StrUserName != "" && StrPassword != "") {
            if (StrUserName.length < 3) {
                $("#MemberLoginMsgMainTxt").text("Kullanıcı adınız en az 3 karakter olmalıdır.");
            } else {
                $.ajax({
                    type: 'GET',
                    url: '/AjaxIslemler/uyegiriskontrol.aspx',
                    data: 'UserName=' + StrUserName + '&Password=' + StrPassword + '&Remember=' + StrRemember,
                    success: function (ajaxCevap) {
                        $("#MemberLoginMsgMainTxt").html(ajaxCevap);
                    },
                    error: function () {
                        $("#MemberLoginMsgMainTxt").text("Olmadı! sanırım yoğunuz! sonra deneyin :(");
                    }
                });
            }
        } else {
            $("#MemberLoginMsgMainTxt").text("Kullanıcı adı ve Şifrenizi yazınız.");
        }
    });
    $("#MemberLoginSifre").keypress(function (e) {
        if (e.which == 13) {
            $("#MemberLoginBtn").click();
        }
    });
    $("#MemberLoginMsgClose").click(function () {
        $("#MemberLoginMsgMain").hide("normal");
    });
    $(".btnUyeSayfam").click(function () {
        window.open("/oyuncu/uyesayfam.aspx", "_self");
    });
    $("#btnMesajlarim").click(function () {
        window.open("/oyuncu/mesajlarim.aspx", "_self");
    });
    $("#btnTaleplerim").click(function () {
        window.open("/oyuncu/taleplerim.aspx", "_self");
    });
    $("#btnOyunlarim").click(function () {
        window.open("/oyuncu/oyunlarim.aspx", "_self");
    });
    $("#btnArkadaslarim").click(function () {
        window.open("/oyuncu/arkadaslarim.aspx", "_self");
    });
    $("#btnYorumlarim").click(function () {
        window.open("/oyuncu/yorumlarim.aspx", "_self");
    });

    var username = getCookie('KAdijs');
    if (username != null && username != "") {
        $("#MemberLoginKAdi").val(username);
    }

    $("#WhatismypassBtn").click(function () {
        $("#Whatismypasscon").slideToggle("normal");
    });
    $("#WhatismypassconClose").click(function () {
        $("#Whatismypasscon").slideToggle("normal");
    });

    $("#WhatismypassconBtn").click(function () {

        $("#MemberLoginMsgMain").show("normal");
        $("#MemberLoginMsgMain").css("z-index", "2");
        $("#MemberLoginMsgMainTxt").text("İşleminiz yapılıyor lütfen bekleyiniz...");

        var WhatismypassInput = $("#WhatismypassInput").val();

        if (WhatismypassInput != "" && WhatismypassInput != "") {
            $.ajax({
                type: 'GET',
                url: '/AjaxIslemler/mailsifregonder.aspx',
                data: 'Mail=' + WhatismypassInput,
                success: function (ajaxCevapM) {
                    $("#MemberLoginMsgMainTxt").html(ajaxCevapM);
                }
            });
        } else {
            $("#MemberLoginMsgMainTxt").text("E-mail adresinizi yazınız.");
        }
    });
    $("#btnOyunukucult").click(function () {
        PlaySwf(GameSWF, '650', '500', 'SwfPlay');
        $("#btnOyunukucult").hide();
        $("#btnOyunubuyult").show();
    });
    $("#btnOyunubuyult").click(function () {
        PlaySwf(GameSWF, '728', '559', 'SwfPlay');
        $("#btnOyunukucult").show();
        $("#btnOyunubuyult").hide();
    });
    //    $("#btnTamekran").click(function () {
    //        //$(document).width();
    //        //$(document).height();

    //        $("#FullScreenWin").css("width", $(document).width());
    //        $("#FullScreenWin").css("height", $(document).height());
    //        $("#FullScreenMain").show();
    //        $("#FullScreenWin").slideToggle("normal");
    //    });
    $("#btnfacebook").click(function () {
        window.open("http://www.facebook.com/sharer.php?u=" + bUrl, "_blank");
    });
    $("#btndigg").click(function () {
        window.open("http://digg.com/submit?url=" + bUrl, "_blank");
    });
    $("#btngoogle").click(function () {
        window.open("http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=" + bUrl, "_blank");
    });
    $("#btnmyspace").click(function () {
        window.open("http://www.myspace.com/Modules/PostTo/Pages/?u=" + bUrl, "_blank");
    });
    $("#btngmail").click(function () {
        window.open("http://mail.google.com/mail/?view=cm&fs=1&to&su=" + document.title + "&ui=2&tf=1&body=" + bUrl, "_blank");
    });
    $("#btnhotmail").click(function () {
        window.open("http://www.hotmail.msn.com/secure/start?action=compose&to=&subject=" + document.title + "&body=" + bUrl, "_blank");
    });
    $("#btntwitter").click(function () {
        window.open("http://twitthis.com/twit?title=" + document.title + "&url=" + bUrl, "_blank");
    });
    $("#btnyahoo").click(function () {
        window.open("http://compose.mail.yahoo.com/?To=&Subject=" + document.title + "&body=" + bUrl, "_blank");
    });
    $("#btnbuzla").click(function () {
        window.open("http://www.buzla.com/save_news_step1.php?news_url=" + bUrl, "_blank");
    });
    $(".CommentHeaderLink").click(function () {
        $("#CommentWritePopup").slideToggle("normal");
    });
    $("#btnCommentP").click(function () {
        var StrCom = TrConvert($("#CommentWriteTxt").val());

        if (StrCom.length < 3 && StrCom.length != 0) {
            $("#GetComMsg").text("Yorumunuz 3 karakterden az olamaz!");
        } else if (StrCom.length == 0) {
            $("#GetComMsg").text("Lütfen yorum alanını boş bırakmayınız.");
        } else if (StrCom.length > 400) {
            $("#GetComMsg").text("Yorumunuz çok uzun! 400 karakteri geçmemelidir.");
        }
        else {
            $("#GetComMsg").text("Yorumunuz kayıt ediliyor...");
            $('#btnCommentP').attr('disabled', 'true');
            $.ajax({
                type: 'GET',
                url: '/AjaxIslemler/oyunyorumgonder.aspx',
                data: 'OyunID=' + _GameID + '&TxtMsg=' + StrCom,
                success: function (ajaxCevap) {
                    $("#GetComMsg").html(ajaxCevap);
                },
                error: function () {
                    $("#GetComMsg").text("Yorumu kayıt edemedik! sanırım yoğunuz! sonra deneyin :(");
                }
            });
        }
    });

    $("#ctl00_ContentPlaceHolder1_ddlUlkeler").change(function () {
        $("#ctl00_ContentPlaceHolder1_ddlUlkeler option:selected").each(function () {
            if ($(this).val() != "10221") {
                $('#ctl00_ContentPlaceHolder1_ddlSehirler').attr('disabled', 'disabled');
            } else {
                $("#ctl00_ContentPlaceHolder1_ddlSehirler").removeAttr("disabled");
            }
        });
    }).trigger('change');

    $("#DvGameAddPgClose").click(function () {
        $("#DvGameAddPg").hide("normal");
    });
    //
    w = $(document).width();
    h = $(document).height();
    //
    if (w > 1120) {
        $("#AdvMain120x600").show();
    }
    $(window).bind('resize',
    function () {
        w = $(document).width();

        if (w > 1120) {
            $("#AdvMain120x600").show();
        } else {
            $("#AdvMain120x600").hide();
        }
    });
    //
    $("#ChatInputText").keypress(function (e) {
        if (e.which == 13) {
            $("#ChatInputSubmit").click();
        }
    });
    $("#ChatInputSubmit").click(function () {
        var StrChatInputText = Trim($("#ChatInputText").val(), " ");
        if (StrChatInputText == "") {
            $("#ChatInputText").attr("value", "");
            $("#ChatInputText").focus();
        } else {
            $("#ChatInputSubmit").attr("disabled", "true");
            $.ajax({
                type: "POST",
                url: "/AjaxIslemler/chatkayit.aspx",
                data: { Mesaj: StrChatInputText },
                cache: false,
                success: function (html) {
                    $("#ChatInputText").attr("value", "");
                    $("#ChatInputText").focus();
                    $("#ChatInputSubmit").removeAttr("disabled");
                }
            });
        }
    });
    //
});

function GetChatText() {
    clearInterval("stGetChatText");
    _Date = new Date();
    $.get("/AjaxIslemler/chatlistele.aspx?d=" + _Date,
		function (_StrChatText) {
		    $("#ChatMessageListLI").html(_StrChatText);
		});		
		stGetChatText = setTimeout('GetChatText();', 1200);
}

function GetLoginOk() {
    $("#MemberPanel").show('normal', function () {
        $("#MemberLoginMsgMain").hide("normal");

        $(".btnUyeKayit").hide();
        $(".btnUyeSayfam").show();
    });
    clearInterval("GetLoginOkST");
}

function GetLoginOkT(KAdi) {
    clearInterval("GetLoginOkST");
    $("#MemberLogin").hide("normal");
    GetLoginOkST = setTimeout('GetLoginOk();', 1500);

    GetMemberPanelint();
    //
    if (KAdi != "Null") {
        setCookie('KAdijs', KAdi, 365);
    } else {
        setCookie('KAdijs', '', 365);
    }
}

function GetMemberPanelint() {
    _Date = new Date();
    var _StrOne = new Array();
    $.get("/AjaxIslemler/uyepanelsayibilgileri.aspx?d=" + _Date,
		function (_StrOne) {
		    var sp = _StrOne.split(",");

		    if (sp.length == 1) {
		        $("#MemberLoginMsgMain").show("normal");
		        $("#MemberLoginMsgMainTxt").html("Lütfen tekrar üye girişi yapınız.");
		        $("#MemberLogin").show("normal");
		        $("#MemberPanel").hide("normal");
		    } else {
		        $("#intMesajlarim").text(sp[0].toString());
		        $("#intTaleplerim").text(sp[1].toString());
		        $("#intOyunlarim").text(sp[2].toString());
		        $("#intArkadaslarim").text(sp[3].toString());
		        $("#intYorumlarim").text(sp[4].toString());
		    }
		});
    clearInterval("GetMemberPanelintTim");
    GetMemberPanelintTim = setTimeout('GetMemberPanelint();', 30000);
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function BookMarkSite(title, url) {
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
}
function PlaySwf(SwfUrl, W, H, DivName) {
    var so = new SWFObject(SwfUrl, "Game_Flash", W, H, "8.0.23", "", true);
    so.addParam("wmode", "opaque");
    so.write(DivName);
    GameSWF = SwfUrl;

    GameInters = setInterval("refreshProgress()", 50);
}

function MyoyunAdsClose() {
    //clearInterval("MyoyunAds");
    $("#MyoyunAds").hide();
    $("#SwfPlay").show();
    $("#Mov").hide();
}

function MyoyunAdsOpen() {
    $("#MyoyunAds").show();
    $("#SwfPlay").hide();
    //MyoyunAdsTim = setTimeout('MyoyunAdsClose();', 9000);
    //clearInterval("MyoyunAdsOpenTim");
}

function refreshProgress() {

    var movie = getFlashMovieObject("Mov");

    if (movie) {
        if (movie.PercentLoaded() < 100) {
            $("#BarTxt").text("%" + movie.PercentLoaded() + "");
        }
        else {
            $("#BarTxt").text("");
            clearInterval("GameInters");
            MyoyunAdsClose();
        }

        $("#BarPercent").css("width", movie.PercentLoaded() + "%");
    }
}

function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else {
        return document.getElementById(movieName);
    }
}	

function clientCoords() {
    if (window.innerHeight || window.innerWidth) {
        return { w: window.innerWidth, h: window.innerHeight }
    }
    return {
        w: document.documentElement.clientWidth,
        h: document.documentElement.clientHeight
    }
}

function Getcomments(GameID, Pg) {
    _GameID = GameID
    _Date = new Date();
    clearInterval("GetcommentsTim");
    $.ajax({
        type: 'GET',
        url: '/AjaxIslemler/oyunyorumlar.aspx',
        data: 'OyunID=' + GameID + "&p=" + Pg + "&d=" + _Date,
        success: function (ajaxGetCom) {
            $("#GetGameComments").html(ajaxGetCom);
        }
    });
    GetcommentsTim = setTimeout('Getcomments(' + GameID + ', ' + Pg + ');', 60000);
}

function GetCommentsAfterWr(GetGameID) {
    Getcomments(GetGameID, 1);
    $('#btnCommentP').removeAttr("disabled");
    $("#CommentWritePopup").slideToggle("normal");
    $("#GetComMsg").text("");
    $("#CommentWriteTxt").text("");
    clearInterval("GetcommentsAfterAutoTim");
}

function maxLength(obj) {
    var iTxt = obj.value.length;

    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && iTxt > mlength) {
        obj.value = obj.value.substring(0, mlength);
        $("#GetComMsg").text("Yorumunuz şuanda " + mlength + " karakterdir.");
    } else {
        $("#GetComMsg").text("Yorumunuz " + iTxt + " karakterdir. Max: " + mlength);
    }
}

function TrConvert(Str) {
    Str = Str.replace(/[ü]/g, "[u]");
    Str = Str.replace(/[Ü]/g, "[U]");
    Str = Str.replace(/[ğ]/g, "[g]");
    Str = Str.replace(/[Ğ]/g, "[G]");
    Str = Str.replace(/[ş]/g, "[s]");
    Str = Str.replace(/[Ş]/g, "[S]");
    Str = Str.replace(/[ç]/g, "[c]");
    Str = Str.replace(/[Ç]/g, "[C]");
    Str = Str.replace(/[ö]/g, "[o]");
    Str = Str.replace(/[Ö]/g, "[O]");
    Str = Str.replace(/[ı]/g, "[i]");
    Str = Str.replace(/[İ]/g, "[I]");
    return Str;
}

function PostGameLike(E, H) {
    _Date = new Date();
    $(".GameBottom1GRt").html("<span>İşleminiz yapılıyor lütfen bekleyin.</span>");
    $.ajax({
        type: 'GET',
        url: '/AjaxIslemler/oyunusevdinizmi.aspx',
        data: 'E=' + E + "&H=" + H + "&GID=" + _GameID + "&d=" + _Date,
        success: function (ajaxGetGameLike) {
            $(".GameBottom1GRt").html(ajaxGetGameLike);
        }
    });
}

function GetGameLike(GameID) {
    _Date = new Date();
    $.ajax({
        type: 'GET',
        url: '/AjaxIslemler/oyunusevdinizmi.aspx',
        data: "&d=" + _Date + "&GID=" + GameID,
        success: function (ajaxGetGameLike) {
            $(".GameBottom1GRt").html(ajaxGetGameLike);
        }
    });
}

function LastComUserSide() {
    _Date = new Date();
    $.get("/AjaxIslemler/ensonyorumlananoyunlarkullanicili.aspx?d=" + _Date,
		function (Str01) {
		    $("#LastComUserSideDiv").html(Str01);
		});
    clearInterval("LastComUserSideTim");
    LastComUserSideTim = setTimeout('LastComUserSide();', 35000);
}

function OnlineMembersUSide() {
    _Date = new Date();
    $.get("/AjaxIslemler/onlineoyuncularuyesyf.aspx?d=" + _Date,
		function (Str02) {
		    $("#OnlineGameFriendsListID").html(Str02);
		});
    clearInterval("OnlineMemUserSideTim");
    OnlineMemUserSideTim = setTimeout('OnlineMembersUSide();', 30000);
}

function MsgSend(U1) {
    window.open("/oyuncu/mesajgonder.aspx?uyeID=" + U1, "_self");
}

function SendRecMsgList(i, p) {
    window.open("/oyuncu/mesajlarim.aspx?i=" + i + "&p=" + p, "_self");
}

function AddFriends(UID) {
    $(".AddFriendMsgMain").html("İşleminiz yapılıyor...<br />Lütfen bekleyin.");
    $(".AddFriendMsgMain").show("normal");
    $.ajax({
        type: 'GET',
        url: '/AjaxIslemler/arkadasekle.aspx',
        data: "UID=" + UID,
        success: function (ajaxAddFriends) {
            $(".AddFriendMsgMain").html(ajaxAddFriends);
        }
    });
}

function AvatarClck(gi) {
    for (var i = 0; i <= 38; i++) {
        $("#Avatar" + i).css('background-color', '');
    }
    $("#Avatar" + gi).css('background-color', 'Blue');

    window.open("/oyuncu/avatardegistir.aspx?AID=" + gi, "_self");
}

function GameFavAddPg(FID) {
    $("#DvGameAddPgTxt").html("İşleminiz yapılıyor...<br />Lütfen bekleyin.");
    $("#DvGameAddPg").show("normal");
    $.ajax({
        type: 'GET',
        url: '/AjaxIslemler/oyunufavorimeekle.aspx',
        data: "FID=" + FID,
        success: function (ajaxAddFriends) {
            $("#DvGameAddPgTxt").html(ajaxAddFriends);
        }
    });
}

function LTrim(Str, Chars) {
    Chars = Chars || "\\s";
    return Str.replace(new RegExp("^[" + Chars + "]+", "g"), "");
}
function RTrim(Str, Chars) {
    Chars = Chars || "\\s";
    return Str.replace(new RegExp("[" + Chars + "]+$", "g"), "");
}
function Trim(Str, Chars) {
    return LTrim(RTrim(Str, Chars), Chars);
}
