﻿var searchFrameVisible;

function degreesToDegreeMinuteSecond(degree, latlon) {
    var degreeIntegerPart = parseInt(degree);
    var degreeFloatPart = degree - degreeIntegerPart;

    var minute = 60 * degreeFloatPart;
    var minuteIntegerPart = parseInt(minute);
    var minuteFloatPart = minute - minuteIntegerPart;

    var secondFloat = 60 * minuteFloatPart;
    var second = parseInt(secondFloat * 100) / 100;

    var sign;

    //LATIDUE = ENLEM
    var resultIsSmallerThanZero = false;

    if (latlon == "latitude") {
        if (degree < 0) {
            sign = "G"; // longitude = North : Boylam = Kuzey;
        }
        else {
            sign = "K"; // longitude = North : Boylam = Kuzey;
        }
    }
    //LONGITUDE = BOYLAM
    else {
        if (degree < 0) {
            sign = "B"; // latitude = West : Enlem = Batı;
        }
        else {
            sign = "D"; // latitude = East : Enlem = Doğu;
        }
    }

    degreeIntegerPart = Math.abs(degreeIntegerPart);
    minuteIntegerPart = Math.abs(minuteIntegerPart);
    second = Math.abs(second);
    var dms = (degreeIntegerPart += '') + " " + (minuteIntegerPart += '') + "' " + (second += '') + "'' " + sign;
    return dms;
}

function getWindowLeft() {
    return (typeof window.screenLeft != 'undefined') ? window.screenLeft : window.screenX;
}

function getWindowTop() {
    return (typeof window.screenTop != 'undefined') ? window.screenTop : window.screenY;
}

function getViewportWidth() {
    return (typeof window.innerWidth != 'undefined') ? innerWidth :
            (typeof document.body.clientWidth != 'undefined') ? document.body.clientWidth :
            (typeof document.documentElement.offsetWidth != 'undefined') ? document.documentElement.offsetWidth : null;
}

function getViewportHeight() {
    return (typeof window.innerHeight != 'undefined') ? innerHeight :
            (typeof document.body.clientHeight != 'undefined') ? document.body.clientHeight :
            (typeof document.documentElement.offsetHeight != 'undefined') ? document.documentElement.offsetHeight : null;
}

function getViewportLeft() {
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :
    document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft :
    document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function getViewportTop() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset :
    document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop :
    document.body.scrollTop ? document.body.scrollTop : 0;
}

function getViewportRight() {
    return getViewportLeft() + getViewportWidth();
}

function getViewportBottom() {
    return getViewportTop() + getViewportHeight();
}

function findPosition(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }

    return [curleft, curtop];
}

function ShowMessage(message) {
    alert(message);
}

function SetTextBoxText(id, text) {
    var control = document.getElementById(id);
    control.value = text;
}

function OpenWindow(url) {
    window.open(url, "NewWindow", "status=0,toolbar=0,menubar=0,resizable=1,width=800,height=600");
}

function ShowSearchFrame(show) {

    if (show) {
        document.getElementById("AramaSonuclariHeaderLeft").style.width = "0px";
        document.getElementById("AramaSonuclariHeaderLeft").style.visibility = "hidden";
        document.getElementById("AramaSonuclariFrame").style.visibility = "visible";
        document.getElementById("AramaSonuclariFrame").style.width = "450px";
        document.getElementById("earth_container").style.marginLeft = "456px";
    }
    else {

        document.getElementById("earth_container").style.marginLeft = "17px";
        document.getElementById("AramaSonuclariFrame").style.width = "0px";
        document.getElementById("AramaSonuclariFrame").style.visibility = "hidden";        
        document.getElementById("AramaSonuclariHeaderLeft").style.width = "15px";
        document.getElementById("AramaSonuclariHeaderLeft").style.visibility = "visible";        
    }
    
    searchFrameVisible = show;
}

function PrepareForFly(sender) {
    var senderId = sender.id.substring(5);
    var coordControl = document.getElementById("COORD" + senderId);
    var coords = coordControl.title;
    if (coords != null && coords != "") {
        var latlon = coords.split("/");
        flyTo(parseFloat(latlon[0]), parseFloat(latlon[1]));
    }
    else {
        ShowMessage("Koordinatlar Tanımlı Değil!");
    }
}

function ShowModalPopup(modalPopupID) {
    ShowSearchFrame(true);
    $find(modalPopupID).show();
}

function ShowMemberSearchWindow(memberGroup) {
    ShowSearchFrame(true);
    var ddlMemberGroup = document.getElementById("DDL_RSW_UyeGrubu");
    for (var i = 0; i < ddlMemberGroup.length; i++) {
        if (ddlMemberGroup.options[i].value == memberGroup) {
            ddlMemberGroup.selectedIndex = i
        }
    }
    $find('MPE_MemberSearchWindow').show();
}        

