﻿function excludedArray(sourceArray, excludeArray) {
    var tempArray = new Array();
    if (sourceArray && excludeArray) {
        if (sourceArray.length <= 0 || excludeArray.length <= 0) return sourceArray;
        for (var i = 0; i < sourceArray.length; i++) {
            var mNot = false;
            for (var x = 0; x < excludeArray.length; x++) {
                if (sourceArray[i].id == excludeArray[x].id) {
                    mNot = true;
                }
            }
            if (mNot == false)
                tempArray.push(sourceArray[i]);
        }
    }
    else {
        return sourceArray;
    }
    return tempArray;
}

function aylar() {
    var mReturn = new Array();
    for (var i = 0; i < 12; i++) {
        mReturn.push({ "id": i + 1, "name": AyAdi(i) });
    }
    return mReturn;
}
function yillar() {
    var mReturn = new Array();
    var mDate = new Date();
    var mYil = mDate.getFullYear();
    for (var i = mYil - 10; i <= mYil  ; i++) {
        mReturn.push({ "id": i, "name": i });
    }
    return mReturn;
    
}
function AyAdi(ay) {

    switch (ay) {
        case 0:
            return "Ocak";
            break;
        case 1:
            return "Şubat";
            break;
        case 2:
            return "Mart";
            break;
        case 3:
            return "Nisan";
            break;
        case 4:
            return "Mayıs";
            break;
        case 5:
            return "Haziran";
            break;
        case 6:
            return "Temmuz";
            break;
        case 7:
            return "Ağustos";
            break;
        case 8:
            return "Eylül";
            break;
        case 9:
            return "Ekim";
            break;
        case 10:
            return "Kasım";
            break;
        case 11:
            return "Aralık";
            break;
        default:
            break;
    }

}

function onWindowResize(e) {

    pageScrollTop = window.pageYOffset || document.documentElement.scrollTop || 0;
    pageScrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;
}

function findPos(obj) {
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft - obj.scrollLeft;
            curtop += obj.offsetTop - obj.scrollTop;
            var position = '';
            if (obj.style && obj.style.position)
                position = obj.style.position.toLowerCase();
            if ((position == 'absolute') || (position == 'relative'))
                break;
            while (obj.parentNode != obj.offsetParent) {
                obj = obj.parentNode; curleft -= obj.scrollLeft;
                curtop -= obj.scrollTop;
            }
            obj = obj.offsetParent;
        }
    }
    else {
        if (obj.x) curleft += obj.x;
        if (obj.y) curtop += obj.y;
    }
    return { x: curleft, y: curtop };
}




function addEvent(el, eType, fn, uC) {
    uC = uC == null ? false : uC;
    if (el.addEventListener) {
        el.addEventListener(eType, fn, uC);
        return true;
    } else if (el.attachEvent) {
        return el.attachEvent('on' + eType, fn);
    } else {
        el['on' + eType] = fn;
    }
}
function getEventTarget(evt) {
    var targ = (evt.target) ? evt.target : evt.srcElement;

    if (targ != null) {
        if (targ.nodeType == 3)
            targ = targ.parentNode;
    }

    return targ;
}
function queryString(Deger, url) {
    if (url == null)
        url = location.href;
    if (Deger != null) {
        var regEx = new RegExp("(\\?|&)(" + Deger + "=)(.*?)(&|$|#)", "i")
        var exec = regEx.exec(url)
        var Sonuc = RegExp.$3
    } else {
        var regEx = new RegExp("(\\?)(.*?)($)", "i")
        var exec = regEx.exec(url)
        var Sonuc = RegExp.$2
    }

    return (Sonuc)
}
function anchorQueryString(Deger, url) {
    if (url == null)
        url = location.href;
    url = url.split("#")[1];
    if (Deger != null) {
        var regEx = new RegExp("(\\?|&)(" + Deger + "=)(.*?)(&|$|#)", "i")
        var exec = regEx.exec(url)
        var Sonuc = RegExp.$3
    } else {
        var regEx = new RegExp("(\\?)(.*?)($)", "i")
        var exec = regEx.exec(url)
        var Sonuc = RegExp.$2
    }

    return (Sonuc)
}
function keyPress(e) {
    var evt = e ? e : window.event;
    if (evt.keyCode == 27) {

        document.getElementById("btnCancel").click();
        return false;
    }
    else if (evt.keyCode == 13) {
        mBtnKaydet = document.getElementById("btnKaydet");
        mBtnInsert = document.getElementById("btnInsert");
        mBtnGonder = document.getElementById("btnGonder");
        var ToElement;

        if (evt.target) {
            ToElement = evt.target;
        }
        else if (evt.srcElement) {
            ToElement = evt.srcElement;
        }
        if (ToElement.nodeType == 3) // defeat Safari bug
        {
            ToElement = targ.parentNode;
        }
        if ((ToElement.id == "txtMailTemp") || (ToElement.id == "txtSpot") || (ToElement.id == "txtOlay")) {
            return true;
        }

        if ((mBtnKaydet != null) && mBtnKaydet.style.visibility == "visible") {
            mBtnKaydet.click();
            return false;
        }
        else if ((mBtnInsert != null) && mBtnInsert.style.visibility == "visible") {
            mBtnInsert.click();
            return false;
        }
        else if ((mBtnGonder != null) && mBtnGonder.style.visibility == "visible") {
            mBtnGonder.click();
            return false;
        }
        else {
            return false;
        }

    }

}

Array.prototype.remove = function (element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            this.splice(i, 1);
            break;
        }
    }
}
Array.prototype.bulOnceki = function (element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            if (i >= 1) {
                return this[i - 1];
            }
            else {
                return null;
            }
        }
    }
    return null;
}
Array.prototype.bulSonraki = function (element, circular) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            if (i <= this.length - 2) {
                return this[i + 1];
            }
            else if (circular && this.length > 0) {
                return this[0];
            }
            else {
                return null;
            }
        }
    }
    return null;
}
Array.prototype.filter = function (fun) {
    var mUserContext = arguments[1];
    if (typeof fun != "function")
        throw new TypeError();
    var filteredResult = new Array();
    for (var i = 0; i < this.length; i++) {
        if (fun(this[i], mUserContext)) {
            filteredResult.push(this[i]);
        }
    }
    return filteredResult;
}
function createSL(source,id,controlHost,version,onload) {
    Silverlight.createObjectEx({
        source: source,
        parentElement: controlHost,
        id: id,
        properties: {
            width: "300px",
            height: "25",
            background: "transparent",
            alt: "<!--not installed-->",
            version: version != null ? version : "4.0.50401.0", //"3.0.40624.0",
            windowless:"true"
        },
        events: {
            //onError: onSLError,
        onLoad: onload
    }, initParams: "nodrag=true", context: "row4"
});
}
function getNextHighestZindex(obj){   
   var highestIndex = 0;   
   var currentIndex = 0;   
   var elArray = Array();   
   if(obj){ elArray = obj.getElementsByTagName('*'); }else{ elArray = document.getElementsByTagName('*'); }   
   for(var i=0; i < elArray.length; i++){   
      if (elArray[i].currentStyle){   
         currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);   
      }else if(window.getComputedStyle){   
         currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue('z-index'));   
      }   
      if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }   
   }   
   return(highestIndex+1);   
}
if (!window.Silverlight) window.Silverlight = {}; Silverlight._silverlightCount = 0; Silverlight.__onSilverlightInstalledCalled = false; Silverlight.fwlinkRoot = "http://go2.microsoft.com/fwlink/?LinkID="; Silverlight.__installationEventFired = false; Silverlight.onGetSilverlight = null; Silverlight.onSilverlightInstalled = function () { window.location.reload(false) }; Silverlight.isInstalled = function (b) { if (b == undefined) b = null; var a = false, m = null; try { var i = null, j = false; if (window.ActiveXObject) try { i = new ActiveXObject("AgControl.AgControl"); if (b === null) a = true; else if (i.IsVersionSupported(b)) a = true; i = null } catch (l) { j = true } else j = true; if (j) { var k = navigator.plugins["Silverlight Plug-In"]; if (k) if (b === null) a = true; else { var h = k.description; if (h === "1.0.30226.2") h = "2.0.30226.2"; var c = h.split("."); while (c.length > 3) c.pop(); while (c.length < 4) c.push(0); var e = b.split("."); while (e.length > 4) e.pop(); var d, g, f = 0; do { d = parseInt(e[f]); g = parseInt(c[f]); f++ } while (f < e.length && d === g); if (d <= g && !isNaN(d)) a = true } } } catch (l) { a = false } return a }; Silverlight.WaitForInstallCompletion = function () { if (!Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled) { try { navigator.plugins.refresh() } catch (a) { } if (Silverlight.isInstalled(null) && !Silverlight.__onSilverlightInstalledCalled) { Silverlight.onSilverlightInstalled(); Silverlight.__onSilverlightInstalledCalled = true } else setTimeout(Silverlight.WaitForInstallCompletion, 3e3) } }; Silverlight.__startup = function () { navigator.plugins.refresh(); Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null); if (!Silverlight.isBrowserRestartRequired) { Silverlight.WaitForInstallCompletion(); if (!Silverlight.__installationEventFired) { Silverlight.onInstallRequired(); Silverlight.__installationEventFired = true } } else if (window.navigator.mimeTypes) { var b = navigator.mimeTypes["application/x-silverlight-2"], c = navigator.mimeTypes["application/x-silverlight-2-b2"], d = navigator.mimeTypes["application/x-silverlight-2-b1"], a = d; if (c) a = c; if (!b && (d || c)) { if (!Silverlight.__installationEventFired) { Silverlight.onUpgradeRequired(); Silverlight.__installationEventFired = true } } else if (b && a) if (b.enabledPlugin && a.enabledPlugin) if (b.enabledPlugin.description != a.enabledPlugin.description) if (!Silverlight.__installationEventFired) { Silverlight.onRestartRequired(); Silverlight.__installationEventFired = true } } if (!Silverlight.disableAutoStartup) if (window.removeEventListener) window.removeEventListener("load", Silverlight.__startup, false); else window.detachEvent("onload", Silverlight.__startup) }; if (!Silverlight.disableAutoStartup) if (window.addEventListener) window.addEventListener("load", Silverlight.__startup, false); else window.attachEvent("onload", Silverlight.__startup); Silverlight.createObject = function (m, f, e, k, l, h, j) { var d = {}, a = k, c = l; d.version = a.version; a.source = m; d.alt = a.alt; if (h) a.initParams = h; if (a.isWindowless && !a.windowless) a.windowless = a.isWindowless; if (a.framerate && !a.maxFramerate) a.maxFramerate = a.framerate; if (e && !a.id) a.id = e; delete a.ignoreBrowserVer; delete a.inplaceInstallPrompt; delete a.version; delete a.isWindowless; delete a.framerate; delete a.data; delete a.src; delete a.alt; if (Silverlight.isInstalled(d.version)) { for (var b in c) if (c[b]) { if (b == "onLoad" && typeof c[b] == "function" && c[b].length != 1) { var i = c[b]; c[b] = function (a) { return i(document.getElementById(e), j, a) } } var g = Silverlight.__getHandlerName(c[b]); if (g != null) { a[b] = g; c[b] = null } else throw "typeof events." + b + " must be 'function' or 'string'"; } slPluginHTML = Silverlight.buildHTML(a) } else slPluginHTML = Silverlight.buildPromptHTML(d); if (f) f.innerHTML = slPluginHTML; else return slPluginHTML }; Silverlight.buildHTML = function (a) { var b = []; b.push('<object type="application/x-silverlight" data="data:application/x-silverlight,"'); if (a.id != null) b.push(' id="' + Silverlight.HtmlAttributeEncode(a.id) + '"'); if (a.width != null) b.push(' width="' + a.width + '"'); if (a.height != null) b.push(' height="' + a.height + '"'); b.push(" >"); delete a.id; delete a.width; delete a.height; for (var c in a) if (a[c]) b.push('<param name="' + Silverlight.HtmlAttributeEncode(c) + '" value="' + Silverlight.HtmlAttributeEncode(a[c]) + '" />'); b.push("</object>"); return b.join("") }; Silverlight.createObjectEx = function (b) { var a = b, c = Silverlight.createObject(a.source, a.parentElement, a.id, a.properties, a.events, a.initParams, a.context); if (a.parentElement == null) return c }; Silverlight.buildPromptHTML = function (b) { var a = "", d = Silverlight.fwlinkRoot, c = b.version; if (b.alt) a = b.alt; else { if (!c) c = ""; a = "<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>"; a = a.replace("{1}", c); a = a.replace("{2}", d + "108181") } return a }; Silverlight.getSilverlight = function (e) { if (Silverlight.onGetSilverlight) Silverlight.onGetSilverlight(); var b = "", a = String(e).split("."); if (a.length > 1) { var c = parseInt(a[0]); if (isNaN(c) || c < 2) b = "1.0"; else b = a[0] + "." + a[1] } var d = ""; if (b.match(/^\d+\056\d+$/)) d = "&v=" + b; Silverlight.followFWLink("149156" + d) }; Silverlight.followFWLink = function (a) { top.location = Silverlight.fwlinkRoot + String(a) }; Silverlight.HtmlAttributeEncode = function (c) { var a, b = ""; if (c == null) return null; for (var d = 0; d < c.length; d++) { a = c.charCodeAt(d); if (a > 96 && a < 123 || a > 64 && a < 91 || a > 43 && a < 58 && a != 47 || a == 95) b = b + String.fromCharCode(a); else b = b + "&#" + a + ";" } return b }; Silverlight.default_error_handler = function (e, b) { var d, c = b.ErrorType; d = b.ErrorCode; var a = "\nSilverlight error message     \n"; a += "ErrorCode: " + d + "\n"; a += "ErrorType: " + c + "       \n"; a += "Message: " + b.ErrorMessage + "     \n"; if (c == "ParserError") { a += "XamlFile: " + b.xamlFile + "     \n"; a += "Line: " + b.lineNumber + "     \n"; a += "Position: " + b.charPosition + "     \n" } else if (c == "RuntimeError") { if (b.lineNumber != 0) { a += "Line: " + b.lineNumber + "     \n"; a += "Position: " + b.charPosition + "     \n" } a += "MethodName: " + b.methodName + "     \n" } alert(a) }; Silverlight.__cleanup = function () { for (var a = Silverlight._silverlightCount - 1; a >= 0; a--) window["__slEvent" + a] = null; Silverlight._silverlightCount = 0; if (window.removeEventListener) window.removeEventListener("unload", Silverlight.__cleanup, false); else window.detachEvent("onunload", Silverlight.__cleanup) }; Silverlight.__getHandlerName = function (b) { var a = ""; if (typeof b == "string") a = b; else if (typeof b == "function") { if (Silverlight._silverlightCount == 0) if (window.addEventListener) window.addEventListener("onunload", Silverlight.__cleanup, false); else window.attachEvent("onunload", Silverlight.__cleanup); var c = Silverlight._silverlightCount++; a = "__slEvent" + c; window[a] = b } else a = null; return a }; Silverlight.onRequiredVersionAvailable = function () { }; Silverlight.onRestartRequired = function () { }; Silverlight.onUpgradeRequired = function () { }; Silverlight.onInstallRequired = function () { }; Silverlight.IsVersionAvailableOnError = function (d, a) { var b = false; try { if (a.ErrorCode == 8001 && !Silverlight.__installationEventFired) { Silverlight.onUpgradeRequired(); Silverlight.__installationEventFired = true } else if (a.ErrorCode == 8002 && !Silverlight.__installationEventFired) { Silverlight.onRestartRequired(); Silverlight.__installationEventFired = true } else if (a.ErrorCode == 5014 || a.ErrorCode == 2106) { if (Silverlight.__verifySilverlight2UpgradeSuccess(a.getHost())) b = true } else b = true } catch (c) { } return b }; Silverlight.IsVersionAvailableOnLoad = function (b) { var a = false; try { if (Silverlight.__verifySilverlight2UpgradeSuccess(b.getHost())) a = true } catch (c) { } return a }; Silverlight.__verifySilverlight2UpgradeSuccess = function (d) { var c = false, b = "2.0.31005", a = null; try { if (d.IsVersionSupported(b + ".99")) { a = Silverlight.onRequiredVersionAvailable; c = true } else if (d.IsVersionSupported(b + ".0")) a = Silverlight.onRestartRequired; else a = Silverlight.onUpgradeRequired; if (a && !Silverlight.__installationEventFired) { a(); Silverlight.__installationEventFired = true } } catch (e) { } return c }

function objectSize(obj,childPlus,onlyExtras) {
    
    var borderWidth = (obj.style.borderLeftWidth != null ? parseInt(obj.style.borderLeftWidth) : 0) + (obj.style.borderRightWidth != null ? parseInt(obj.style.borderRightWidth) : 0);
    borderWidth = isNaN(borderWidth) ? 0 : borderWidth;
    var paddingWidth = (obj.style.paddingLeft != null ? parseInt(obj.style.paddingLeft) : 0) + (obj.style.paddingRight != null ? parseInt(obj.style.paddingRight) : 0);
    paddingWidth = isNaN(paddingWidth) ? 0 : paddingWidth;
    var marginWidth = (obj.style.marginLeft != null ? parseInt(obj.style.marginLeft) : 0) + (obj.style.marginRight != null ? parseInt(obj.style.marginRight) : 0);
    marginWidth = isNaN(marginWidth) ? 0 : marginWidth;
    var width = onlyExtras ? marginWidth + borderWidth + paddingWidth : obj.scrollWidth + marginWidth + borderWidth + paddingWidth;

    var borderHeight = (obj.style.borderTopWidth != null ? parseInt(obj.style.borderTopWidth) : 0) + (obj.style.borderBottomWidth != null ? parseInt(obj.style.borderBottomWidth) : 0);
    borderHeight = isNaN(borderHeight) ? 0 : borderHeight;
    var paddingHeight = (obj.style.paddingTop != null ? parseInt(obj.style.paddingTop) : 0) + (obj.style.paddingBottom != null ? parseInt(obj.style.paddingBottom) : 0);
    paddingHeight = isNaN(paddingHeight) ? 0 : paddingHeight;
    var marginHeight = (obj.style.margingTop != null ? parseInt(obj.style.marginTop) : 0) + (obj.style.marginBottom != null ? parseInt(obj.style.marginBottom) : 0);
    marginHeight = isNaN(marginHeight) ? 0 : marginHeight;
    var height = onlyExtras ? marginHeight + borderHeight + paddingHeight : obj.scrollHeight + marginHeight + borderHeight + paddingHeight;
    if (obj.firstChild.firstChild && childPlus) {
        var childSize = objectSize(obj.firstChild.firstChild, false, true);
        height += childSize.Height;
        width += childSize.Width;
    }
    return { Width: width, Height: height};
}


var myPopupWindow = '';
function openPopupWindow(url, name, width, height) {
    //Remove special characters from name
    name = name.replace(/\/|\-|\./gi, "");

    //Remove whitespaces from name
    var whitespace = new RegExp("\\s", "g");
    name = name.replace(whitespace, "");

    //If it is already open
    if (!myPopupWindow.closed && myPopupWindow.location) {
        myPopupWindow.location.href = encodeUrl(url);
    }
    else {
        myPopupWindow = window.open(encodeUrl(url), name, "location=no, scrollbars=yes, resizable=yes, toolbar=no, menubar=no, width=" + width + ", height=" + height);
        if (!myPopupWindow.opener) myPopupWindow.opener = self;
    }

    //If my main window has focus - set it to the popup
    if (window.focus) { myPopupWindow.focus() }
}

function encodeUrl(url) {
    if (url.indexOf("?") > 0) {
        encodedParams = "?";
        parts = url.split("?");
        params = parts[1].split("&");
        for (i = 0; i < params.length; i++) {
            if (i > 0) {
                encodedParams += "&";
            }
            if (params[i].indexOf("=") > 0) //Avoid null values
            {
                p = params[i].split("=");
                encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));
            }
            else {
                encodedParams += params[i];
            }
        }
        url = parts[0] + encodedParams;
    }
    return url;
}
function createPlayer(fileName,poster,containerName) {
    createPlayerEx(fileName, poster,containerName, 720, 405,"over");
}
function createPlayerEx(fileName, poster, containerName, width, height, controlBar) {
    
    width = width != null ? width : 720;
    height = height != null ? height : 504;
    var x = jwplayer(containerName).setup({
        flashplayer: "jwplayer/player.swf",
        file: fileName,
        image: poster,
        controlbar:controlBar,
        //streamer: "http://localhost:61444/BilimSanatWeb/mp4-streamer.ashx",
        provider: 'http',
        'http.startparam': 'start',
        'http.fileparam': 'file',
        height: height,
        width: width,
        events: {
            onTime: function (e) {

            }
        }
    });
}
function copyToClipboard(text) {
    var textArea = document.createElement("textarea");
    textArea.innerText = text;
    Copied = textArea.createTextRange();
    Copied.execCommand("Copy");
    //alert("\"" + text + "\" Kopyalandı.");
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return Url._utf8_decode( c.substring(nameEQ.length, c.length));
    }
    return "";
}

var Url = {

    // public method for url encoding
    encode: function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode: function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode: function (string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}


