﻿/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Konstantin Jagello | http://javascript-array.com/ */
var TimeOut = 300;
var currentLayer = null;
var currentitem = null;
var currentLayerNum = 0;
var noClose = 0;
var closeTimer = null;

function mopen(n) {
    var l = document.getElementById("menu" + n);
    var mm = document.getElementById("mmenu" + n);

    if (l) {
        mcancelclosetime();
        l.style.visibility = 'visible';
        if (currentLayer && (currentLayerNum != n))
            currentLayer.style.visibility = 'hidden';
        currentLayer = l;
        currentitem = mm;
        currentLayerNum = n;
    } else if (currentLayer) {
        currentLayer.style.visibility = 'hidden';
        currentLayerNum = 0;
        currentitem = null;
        currentLayer = null;
    }
}

function mclosetime() {
    closeTimer = window.setTimeout(mclose, TimeOut);
}

function mcancelclosetime() {
    if (closeTimer) {
        window.clearTimeout(closeTimer);
        closeTimer = null;
    }
}

function mclose() {
    if (currentLayer && noClose != 1) {
        currentLayer.style.visibility = 'hidden';
        currentLayerNum = 0;
        currentLayer = null;
        currentitem = null;
    } else {
        noClose = 0;
    }
    currentLayer = null;
    currentitem = null;
}

document.onclick = mclose;

///<reference path="jquery-1.3.2-vsdoc2.js" />
function ListElectionClick() {
    //For ListNetwork   
    var queryStrings = "Net:";
    var network = false, types = false, neighborhood = false;

    var jsonString = '{ "queryString":"' + queryStrings + '" }';
    GetMapPointsInfo(jsonString);
}

function GetMapPointsInfo(jsonString) {
    $.ajax({
        type: 'POST',
        url: 'MapDatas.aspx/jQueryPageMethod',
        data: jsonString,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (result) {
            alert(result);
        },
        error: function () {

            //            alert('Talep esnasında sorun oluştu. Yeniden deneyin');

        }

    });
}


//////////////////////////////////////////

var map;
var baseIcon;

function initialize() {
    if (GBrowserIsCompatible()) {
        var Coordinate1 = document.getElementById('HiddenField1').value.split(",")[0];
        var Coordinate2 = document.getElementById('HiddenField1').value.split(",")[1];

        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(Coordinate1, Coordinate2), 10);
        map.setUIToDefault();

        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.shadow = "";
        baseIcon.iconSize = new GSize(25, 25);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);

        $("#map_canvas").hide("slow");
        $('#loading').show("slow");

        // istek de bulunmak lazım
        if (document.getElementById('WallListingByFilter1_hdnQueryString').value == "") {
            $('#loading').hide("slow");
            $('#map_canvas').show("slow");
        }
        else
            ajax_getir("MapDatas.aspx?Filtre=" + document.getElementById('WallListingByFilter1_hdnQueryString').value);

        //
    }
}

// Creates a marker whose info window displays the letter corresponding
// to the given index.

function createMarker(point, icontype, icerik) {

    // Create a lettered icon for this point using our icon class
    var letter = String.fromCharCode("A".charCodeAt(0) + 1);
    var letteredIcon = new GIcon(baseIcon);
    letteredIcon.image = "http://www.wall.com.tr/google/icon/" + icontype;


    // Set up our GMarkerOptions object
    markerOptions = { icon: letteredIcon };
    var marker = new GMarker(point, markerOptions);


    InfoWindowOptions = { noCloseOnClick: true };
    GEvent.addListener(marker, "click", function () {
        marker.openInfoWindowTabs(icerik, InfoWindowOptions);

    });
    return marker;
}

/* 
-AJAX-XML       
*/
var ajax_istek;

function ajax_getir(url) {
    if (ajax_istek) {
        ajax_istek.abort();
    } else if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        ajax_istek = new XMLHttpRequest();
    }
    if (window.ActiveXObject) {
        // code for IE6, IE5
        ajax_istek = new ActiveXObject("MSXML2.XMLHTTP");
    }
    if (ajax_istek) {
        ajax_istek.onreadystatechange = ajax_takipet;
        ajax_istek.open("GET", url, true);
        ajax_istek.send(null);
    }
}



//////////////////////////////////////////////////////


if (typeof sIFR == "function") {
    sIFR.replaceElement(named({ sSelector: "h1", sFlashSrc: "../../media/swf/h1.swf", sColor: "#244583", sLinkColor: null, sBgColor: null, sHoverColor: "#CCCCCC", nPaddingTop: 0, nPaddingBottom: 0, sFlashVars: null, sWmode: "transparent" }));
};
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
}
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}


////////////////////////////////////////////////////

function OnTreeClick(evt) {
    var src = window.event != window.undefined ? window.event.srcElement : evt.target;
    var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");
    if (isChkBoxClick) {
        var parentTable = GetParentByTagName("table", src);
        var nxtSibling = parentTable.nextSibling;
        //check if nxt sibling is not null & is an element node
        if (nxtSibling && nxtSibling.nodeType == 1) {
            if (nxtSibling.tagName.toLowerCase() == "div") //if node has children
            {
                //check or uncheck children at all levels
                CheckUncheckChildren(parentTable.nextSibling, src.checked);
            }
        }
        //check or uncheck parents at all levels
        CheckUncheckParents(src, src.checked);
    }
}

function CheckUncheckChildren(childContainer, check) {
    var childChkBoxes = childContainer.getElementsByTagName("input");
    var childChkBoxCount = childChkBoxes.length;
    for (var i = 0; i < childChkBoxCount; i++) {
        childChkBoxes[i].checked = check;
    }
}

function CheckUncheckParents(srcChild, check) {
    var parentDiv = GetParentByTagName("div", srcChild);
    var parentNodeTable = parentDiv.previousSibling;
    if (parentNodeTable) {
        var checkUncheckSwitch;
        if (check) //checkbox checked
        {
            var isAllSiblingsChecked = AreAllSiblingsChecked(srcChild);
            if (isAllSiblingsChecked)
                checkUncheckSwitch = true;
            else
                return; //do not need to check parent if any(one or more) child not checked
        }
        else //checkbox unchecked
        {
            checkUncheckSwitch = false;
        }

        var inpElemsInParentTable = parentNodeTable.getElementsByTagName("input");
        if (inpElemsInParentTable.length > 0) {
            var parentNodeChkBox = inpElemsInParentTable[0];
            parentNodeChkBox.checked = checkUncheckSwitch;
            //do the same recursively
            CheckUncheckParents(parentNodeChkBox, checkUncheckSwitch);
        }
    }
}

function AreAllSiblingsChecked(chkBox) {
    var parentDiv = GetParentByTagName("div", chkBox);
    var childCount = parentDiv.childNodes.length;
    for (var i = 0; i < childCount; i++) {
        if (parentDiv.childNodes[i].nodeType == 1) {
            //check if the child node is an element node
            if (parentDiv.childNodes[i].tagName.toLowerCase() == "table") {
                var prevChkBox = parentDiv.childNodes[i].getElementsByTagName("input")[0];
                //if any of sibling nodes are not checked, return false
                if (!prevChkBox.checked) {
                    return false;
                }
            }
        }
    }
    return true;
}

//utility function to get the container of an element by tagname
function GetParentByTagName(parentTagName, childElementObj) {
    var parent = childElementObj.parentNode;
    while (parent.tagName.toLowerCase() != parentTagName.toLowerCase()) {
        parent = parent.parentNode;
    }
    return parent;
}


function cbxAllChangeMethod(cbxAll, code) {
    //Network
    var allChecked = false;
    if (code == 1) {
        if (cbxAll.checked) {
            allChecked = true;
        }
        else
            allChecked = false;

        var cbxNetwork = document.getElementById('WallListingByFilter1_cblNetwork');
        for (i = 0; i < cbxNetwork.childNodes.length; i++) {
            cbxNetworkChild = document.getElementById('WallListingByFilter1_cblNetwork_' + i);
            if (cbxNetworkChild != null) {
                cbxNetworkChild.checked = allChecked;
            }
        }
    } else if (code == 2) {
        //Nei
        if (cbxAll.checked) {
            allChecked = true;
        }
        else
            allChecked = false;

        var cbxNeighborhood = document.getElementById('WallListingByFilter1_cblNeighborhood');
        for (i = 0; i < cbxNeighborhood.childNodes.length; i++) {
            cbxNeighborhoodChild = document.getElementById('WallListingByFilter1_cblNeighborhood_' + i);
            if (cbxNeighborhoodChild != null) {
                if (cbxNeighborhoodChild.type == "checkbox") {
                    cbxNeighborhoodChild.checked = allChecked;
                }
            }
        }
    } else if (code == 3) {
        //Types
        if (cbxAll.checked) {
            allChecked = true;
        }
        else
            allChecked = false;

        var cbxTypes = document.getElementById('WallListingByFilter1_cblTypes');
        for (i = 0; i < cbxTypes.childNodes.length; i++) {
            cbxTypesChild = document.getElementById('WallListingByFilter1_cblTypes_' + i);
            if (cbxTypesChild != null) {
                cbxTypesChild.checked = allChecked;
            }
        }
    }
}


function getQtyCheckedBoxes(cbxList, code) {

    var allChecked = true;

    if (code == 1) {
        //Network
        var cbxAllNetwork = document.getElementById('WallListingByFilter1_cbxAllNetwork');
        for (i = 0; i < cbxList.childNodes.length; i++) {
            cbxNetworkChild = document.getElementById('WallListingByFilter1_cblNetwork_' + i);
            if (cbxNetworkChild != null) {
                if (!cbxNetworkChild.checked) {
                    allChecked = false;
                }
            }
        }
        cbxAllNetwork.checked = allChecked;
    } else if (code == 2) {
        //Nei
        var cbxAllNeighborhood = document.getElementById('WallListingByFilter1_cbxAllNeighborhood');
        for (i = 0; i < cbxList.childNodes.length; i++) {
            cbxNeighborhoodChild = document.getElementById('WallListingByFilter1_cblNeighborhood_' + i);
            if (cbxNeighborhoodChild != null) {
                if (!cbxNeighborhoodChild.checked) {
                    allChecked = false;
                }
            }
        }
        cbxAllNeighborhood.checked = allChecked;
    } else if (code == 3) {
        //Types
        var cbxAllTypes = document.getElementById('WallListingByFilter1_cbxAllTypes');
        for (i = 0; i < cbxList.childNodes.length; i++) {
            cbxTypesChild = document.getElementById('WallListingByFilter1_cblTypes_' + i);
            if (cbxTypesChild != null) {
                if (!cbxTypesChild.checked) {
                    allChecked = false;
                }
            }
        }
        cbxAllTypes.checked = allChecked;
    }
}
