﻿function utf8(wide) {
  //  //debugger;
    var c, s;
    var enc = "";
    var i = 0;
    while (i < wide.length) {
        c = wide.charCodeAt(i++);
        // handle UTF-16 surrogates
        if (c >= 0xDC00 && c < 0xE000) continue;
        if (c >= 0xD800 && c < 0xDC00) {
            if (i >= wide.length) continue;
            s = wide.charCodeAt(i++);
            if (s < 0xDC00 || c >= 0xDE00) continue;
            c = ((c - 0xD800) << 10) + (s - 0xDC00) + 0x10000;
        }
        // output value
        if (c < 0x80) enc += String.fromCharCode(c);
        else if (c < 0x800) enc += String.fromCharCode(0xC0 + (c >> 6), 0x80 + (c & 0x3F));
        else if (c < 0x10000) enc += String.fromCharCode(0xE0 + (c >> 12), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
        else enc += String.fromCharCode(0xF0 + (c >> 18), 0x80 + (c >> 12 & 0x3F), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
    }
    return enc;
}
var hexchars = "0123456789ABCDEF";
function UseTrustConnection(ID1, ID2) {
    ////debugger;
    try {
        var obj = document.getElementById(ID1);
        var obj1 = document.getElementById(ID2);
        if (obj.checked == true) {
            obj1.style.display = "None";
        }
        else {
            obj1.style.display = "Block";
        }
    }
    catch (ex) {
        BambooErrors("ChangeImages", ex.message);
    }
}
function DisplayColumnInView(ID1, ID2) {
    ////debugger;
    try {
        var obj = document.getElementById(ID1);
        var obj1 = document.getElementById(ID2);
        if (obj.checked == true) {
            obj1.style.display = "Block";
        }
        else {
            obj1.style.display = "None";
        }
    }
    catch (ex) {
        BambooErrors("ChangeImages", ex.message);
    }
}
function ShowAndHiddenControl(ID1, ID2, ID3) {
    ////debugger;
    try {
        var obj = document.getElementById(ID1);
        var obj1 = document.getElementById(ID2);
        var obj2 = document.getElementById(ID3);
        if (obj.checked == true) {
            obj1.style.display = "Block";
            obj2.style.display = "Block";
        }
        else {
            obj1.style.display = "None";
            obj2.style.display = "None";
        }
    }
    catch (ex) {
        BambooErrors("ChangeImages", ex.message);
    }
}

function toHex(n) {
    ////debugger;
    return hexchars.charAt(n >> 4) + hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
    ////debugger;
    var s = utf8(s);
    var c;
    var enc = "";
    for (var i = 0; i < s.length; i++) 
    {
        if (okURIchars.indexOf(s.charAt(i)) == -1)
            enc += "%" + toHex(s.charCodeAt(i));
        else
            enc += s.charAt(i);
    }
    return enc;
}
function Bamboo_Encode(s) {
    ////debugger;
    if (typeof encodeURIComponent == "function") 
    {
        // Use JavaScript built-in function
        // IE 5.5+ and Netscape 6+ and Mozilla
        return encodeURIComponent(s);
    }
    else 
    {
        // Need to mimic the JavaScript version
        // Netscape 4 and IE 4 and IE 5.0
        return encodeURIComponentNew(s);
    }
}
function Bamboo_AddEvent(obj, evType, fn, useCapture) {
    ////debugger;
    if (obj.addEventListener) 
    {
        obj.addEventListener(evType, fn, useCapture);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        alert("Bamboo_AddEvent could not add event!");
    }
}
function Bamboo_GetXMLHttpRequest() {
    ////debugger;
    if (window.XMLHttpRequest) 
    {
        return new XMLHttpRequest();
    } else {
    if (window.Bamboo_XMLHttpRequestProgID)
        {
            return new ActiveXObject(window.Bamboo_XMLHttpRequestProgID);
        }
        else 
        {
            var progIDs = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
            for (var i = 0; i < progIDs.length; ++i) 
            {
                var progID = progIDs[i];
                try 
                {
                    var x = new ActiveXObject(progID);
                    window.Bamboo_XMLHttpRequestProgID = progID;
                    return x;
                } 
                catch (e) 
                {
                }
            }
        }
    }
    return null;
}
function Bamboo_CallBack(url, target, id, method, args, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {
    ////debugger;
    if (window.Bamboo_PreCallBack) {
        var preCallBackResult = Bamboo_PreCallBack();
        if (!(typeof preCallBackResult == "then " || preCallBackResult)) {
            if (window.Bamboo_CallBackCancelled) {
                Bamboo_CallBackCancelled();
            }
            return null;
        }
    }
    var x = Bamboo_GetXMLHttpRequest();
    var result = null;
    if (!x) {
        result = { "value": null, "error": "NOXMLHTTP" };
        Bamboo_DebugError(result.error);
        if (window.Bamboo_Error) {
            Bamboo_Error(result);
        }
        if (clientCallBack) {
            clientCallBack(result, clientCallBackArg);
        }
        return result;
    }
    x.open("POST", url ? url : Bamboo_DefaultURL, clientCallBack ? true : false);
    x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
    x.setRequestHeader("Accept-Encoding", "gzip, deflate");
    if (clientCallBack) {
        x.onreadystatechange = function() {
            if (x.readyState != 4) {
                return;
            }
            Bamboo_DebugResponseText(x.responseText);
            result = Bamboo_GetResult(x);
            if (result.error) {
                Bamboo_DebugError(result.error);
                if (window.Bamboo_Error) {
                    Bamboo_Error(result);
                }
            }
            if (updatePageAfterCallBack) {
                Bamboo_UpdatePage(result);
            }
            Bamboo_EvalClientSideScript(result);
            clientCallBack(result, clientCallBackArg);
            x = null;
            if (window.Bamboo_PostCallBack) {
                Bamboo_PostCallBack();
            }
        }
    }
    var encodedData = "";
    if (target == "Page") {
        encodedData += "&Bamboo_PageMethod=" + method;
    } else if (target == "MasterPage") {
        encodedData += "&Bamboo_MasterPageMethod=" + method;
    } else if (target == "Control") {
        encodedData += "&Bamboo_ControlID=" + id.split(":").join("_");
        encodedData += "&Bamboo_ControlMethod=" + method;
    }
    if (args) {
        for (var argsIndex = 0; argsIndex < args.length; ++argsIndex) {
            if (args[argsIndex] instanceof Array) {
                for (var i = 0; i < args[argsIndex].length; ++i) {
                    encodedData += "&Bamboo_CallBackArgument" + argsIndex + "=" + Bamboo_Encode(args[argsIndex][i]);
                }
            } else {
                encodedData += "&Bamboo_CallBackArgument" + argsIndex + "=" + Bamboo_Encode(args[argsIndex]);
            }
        }
    }
    if (updatePageAfterCallBack) {
        encodedData += "&Bamboo_UpdatePage=true";
    }
    if (includeControlValuesWithCallBack) {
        var form = document.getElementById(Bamboo_FormID);
        if (form != null) {
            for (var elementIndex = 0; elementIndex < form.length; ++elementIndex) {
                var element = form.elements[elementIndex];
                if (element.name) {
                    var elementValue = null;
                    if (element.nodeName.toUpperCase() == "INPUT") {
                        var inputType = element.getAttribute("type").toUpperCase();
                        if (inputType == "TEXT" || inputType == "PASSWORD" || inputType == "HIDDEN") {
                            elementValue = element.value;
                        } else if (inputType == "CHECKBOX" || inputType == "RADIO") {
                            if (element.checked) {
                                elementValue = element.value;
                            }
                        }
                    } else if (element.nodeName.toUpperCase() == "SELECT") {
                        if (element.multiple) {
                            elementValue = [];
                            for (var i = 0; i < element.length; ++i) {
                                if (element.options[i].selected) {
                                    elementValue.push(element.options[i].value);
                                }
                            }
                        } else if (element.length == 0) {
                            elementValue = null;
                        } else {
                            elementValue = element.value;
                        }
                    } else if (element.nodeName.toUpperCase() == "TEXTAREA") {
                        elementValue = element.value;
                    }
                    if (elementValue instanceof Array) {
                        for (var i = 0; i < elementValue.length; ++i) {
                            encodedData += "&" + element.name + "=" + Bamboo_Encode(elementValue[i]);
                        }
                    } else if (elementValue != null) {
                        encodedData += "&" + element.name + "=" + Bamboo_Encode(elementValue);
                    }
                }
            }
            // ASP.NET 1.1 won't fire any events if neither of the following
            // two parameters are not in the request so make sure they're
            // always in the request.
            if (typeof form.__VIEWSTATE == "undefined") {
                encodedData += "&__VIEWSTATE=";
            }
            if (typeof form.__EVENTTARGET == "undefined") {
                encodedData += "&__EVENTTARGET=";
            }
        }
    }
    Bamboo_DebugRequestText(encodedData.split("&").join("\n&"));
    x.send(encodedData);
    if (!clientCallBack) {
        Bamboo_DebugResponseText(x.responseText);
        result = Bamboo_GetResult(x);
        if (result.error) {
            Bamboo_DebugError(result.error);
            if (window.Bamboo_Error) {
                Bamboo_Error(result);
            }
        }
        if (updatePageAfterCallBack) {
            Bamboo_UpdatePage(result);
        }
        Bamboo_EvalClientSideScript(result);
        if (window.Bamboo_PostCallBack) {
            Bamboo_PostCallBack();
        }
    }
    return result;
}
function Bamboo_GetResult(x) {
    ////debugger;
    var result = { "value": null, "error": null };
    var responseText = x.responseText;
    try {
        result = eval("(" + responseText + ")");
    } catch (e) {
        if (responseText.length == 0) {
            result.error = "NORESPONSE";
        } else {
            result.error = "BADRESPONSE";
            result.responseText = responseText;
        }
    }
    return result;
}
function Bamboo_SetHiddenInputValue(form, name, value) {
    ////debugger;
    var input = null;
    if (form[name]) {
        input = form[name];
    } else {
        input = document.createElement("input");
        input.setAttribute("name", name);
        input.setAttribute("type", "hidden");
    }
    input.setAttribute("value", value);
    var parentElement = input.parentElement ? input.parentElement : input.parentNode;
    if (parentElement == null) {
        form.appendChild(input);
        form[name] = input;
    }
}
function Bamboo_RemoveHiddenInput(form, name) {
    ////debugger;
    var input = form[name];
    var parentElement = input.parentElement ? input.parentElement : input.parentNode;
    if (input && parentElement == form) {
        form[name] = null;
        form.removeChild(input);
    }
}
function Bamboo_FireEvent(eventTarget, eventArgument, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {
    ////debugger;
    var form = document.getElementById(Bamboo_FormID);
    Bamboo_SetHiddenInputValue(form, "__EVENTTARGET", eventTarget);
    Bamboo_SetHiddenInputValue(form, "__EVENTARGUMENT", eventArgument);
    Bamboo_CallBack(null, null, null, null, null, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack);
    form.__EVENTTARGET.value = "";
    form.__EVENTARGUMENT.value = "";
}
function Bamboo_UpdatePage(result) {
    ////debugger;
    var form = document.getElementById(Bamboo_FormID);
    if (result.viewState) {
        Bamboo_SetHiddenInputValue(form, "__VIEWSTATE", result.viewState);
    }
    if (result.viewStateEncrypted) {
        Bamboo_SetHiddenInputValue(form, "__VIEWSTATEENCRYPTED", result.viewStateEncrypted);
    }
    if (result.eventValidation) {
        Bamboo_SetHiddenInputValue(form, "__EVENTVALIDATION", result.eventValidation);
    }
    if (result.controls) {
        for (var controlID in result.controls) {
            var containerID = "Bamboo_" + controlID.split("$").join("_") + "__";
            var control = document.getElementById(containerID);
            if (control) {
                control.innerHTML = result.controls[controlID];
                if (result.controls[controlID] == "") {
                    control.style.display = "none";
                } else {
                    control.style.display = "block";
                }
            }
        }
    }
    if (result.pagescript) {
        Bamboo_LoadPageScript(result, 0);
    }
}
// Load each script in order and wait for each one to load before proceeding
function Bamboo_LoadPageScript(result, index) {
    ////debugger;
    if (index < result.pagescript.length) {
        try {
            var script = document.createElement('script');
            script.type = 'text/javascript';
            if (result.pagescript[index].indexOf('src=') == 0) {
                script.src = result.pagescript[index].substring(4);
            } else {
                if (script.canHaveChildren) {
                    script.appendChild(document.createTextNode(result.pagescript[index]));
                } else {
                    script.text = result.pagescript[index];
                }
            }
            document.getElementsByTagName('head')[0].appendChild(script);
            if (typeof script.readyState != "undefined") {
                script.onreadystatechange = function() {
                    if (script.readyState != "complete" && script.readyState != "loaded") {
                        return;
                    } else {
                        Bamboo_LoadPageScript(result, index + 1);
                    }
                }
            } else {
                Bamboo_LoadPageScript(result, index + 1);
            }
        } catch (e) {
            Bamboo_DebugError("Error adding page script to head. " + e.name + ": " + e.message);
        }
    }
}
function Bamboo_EvalClientSideScript(result) {
    ////debugger;
    if (result.script) {
        for (var i = 0; i < result.script.length; ++i) {
            try {
                eval(result.script[i]);
            } catch (e) {
                alert("Error evaluating client-side script!\n\nScript: " + result.script[i] + "\n\nException: " + e);
            }
        }
    }
}
function Bamboo_DebugRequestText(text) {
}

function Bamboo_DebugResponseText(text) {
}

function Bamboo_DebugError(text) {
}
//Fix for bug #1429412, "Reponse callback returns previous response after file push".
//see http://sourceforge.net/tracker/index.php?func=detail&aid=1429412&group_id=151897&atid=782464
function Bamboo_Clear__EVENTTARGET() {
    ////debugger;
    var form = document.getElementById(Bamboo_FormID);
    Bamboo_SetHiddenInputValue(form, "__EVENTTARGET", "");
}
function Bamboo_InvokePageMethod(methodName, args, clientCallBack, clientCallBackArg) {
    ////debugger;
    Bamboo_Clear__EVENTTARGET(); // fix for bug #1429412
    return Bamboo_CallBack(null, "Page", null, methodName, args, clientCallBack, clientCallBackArg, true, true);
}
function Bamboo_InvokeMasterPageMethod(methodName, args, clientCallBack, clientCallBackArg) {
    ////debugger;
    Bamboo_Clear__EVENTTARGET(); // fix for bug #1429412
    return Bamboo_CallBack(null, "MasterPage", null, methodName, args, clientCallBack, clientCallBackArg, true, true);
}
function Bamboo_InvokeControlMethod(id, methodName, args, clientCallBack, clientCallBackArg) {
    Bamboo_Clear__EVENTTARGET(); // fix for bug #1429412
    return Bamboo_CallBack(null, "Control", id, methodName, args, clientCallBack, clientCallBackArg, true, true);
}
function Bamboo_PreProcessCallBack(
    control,
    e,
    eventTarget,
    causesValidation,
    validationGroup,
    imageUrlDuringCallBack,
    textDuringCallBack,
    enabledDuringCallBack,
    preCallBackFunction,
    callBackCancelledFunction,
    preProcessOut
) {
    ////debugger;
    preProcessOut.Enabled = !control.disabled;
    var preCallBackResult = true;
    if (preCallBackFunction) {
        preCallBackResult = preCallBackFunction(control);
    }
    if (typeof preCallBackResult == "undefined" || preCallBackResult) {
        var valid = true;
        if (causesValidation && typeof Page_ClientValidate == "function") {
            valid = Page_ClientValidate(validationGroup);
        }
        if (valid) {
            var inputType = control.getAttribute("type");
            inputType = (inputType == null) ? '' : inputType.toUpperCase();
            if (inputType == "IMAGE" && e != null) {
                var form = document.getElementById(Bamboo_FormID);
                if (e.offsetX) {
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".x", e.offsetX);
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".y", e.offsetY);
                } else {
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".x", e.clientX - control.offsetLeft + 1);
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".y", e.clientY - control.offsetTop + 1);
                }
            }
            preProcessOut.OriginalText = control.innerHTML;
            if (imageUrlDuringCallBack || textDuringCallBack) {
                if (control.nodeName.toUpperCase() == "INPUT") {
                    if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {
                        preProcessOut.OriginalText = GetLabelText(control.id);
                        SetLabelText(control.id, textDuringCallBack);
                    } else if (inputType == "IMAGE") {
                        if (imageUrlDuringCallBack) {
                            preProcessOut.OriginalText = control.src;
                            control.src = imageUrlDuringCallBack;
                        } else {
                            preProcessOut.ParentElement = control.parentElement ? control.parentElement : control.parentNode;
                            if (preProcessOut.ParentElement) {
                                preProcessOut.OriginalText = preProcessOut.ParentElement.innerHTML;
                                preProcessOut.ParentElement.innerHTML = textDuringCallBack;
                            }
                        }
                    } else if (inputType == "SUBMIT") {
                        preProcessOut.OriginalText = control.value;
                        control.value = textDuringCallBack;
                    }
                } else if (control.nodeName.toUpperCase() == "SELECT") {
                    preProcessOut.OriginalText = GetLabelText(control.id);
                    SetLabelText(control.id, textDuringCallBack);
                } else {
                    control.innerHTML = textDuringCallBack;
                }
            }
            control.disabled = (typeof enabledDuringCallBack == "undefined") ? false : !enabledDuringCallBack;
            return true;
        } else {
            return false;
        }
    } else {
        if (callBackCancelledFunction) {
            callBackCancelledFunction(control);
        }
        return false;
    }
}
function Bamboo_PreProcessCallBackOut() {
    // Fields
    this.ParentElement = null;
    this.OriginalText = '';
    this.Enabled = true;
}
function Bamboo_PostProcessCallBack(
    result,
    control,
    eventTarget,
    clientCallBack,
    clientCallBackArg,
    imageUrlDuringCallBack,
    textDuringCallBack,
    postCallBackFunction,
    preProcessOut
) {
    ////debugger;
    if (postCallBackFunction) {
        postCallBackFunction(control);
    }
    control.disabled = !preProcessOut.Enabled;
    var inputType = control.getAttribute("type");
    inputType = (inputType == null) ? '' : inputType.toUpperCase();
    if (inputType == "IMAGE") {
        var form = document.getElementById(Bamboo_FormID);
        Bamboo_RemoveHiddenInput(form, eventTarget + ".x");
        Bamboo_RemoveHiddenInput(form, eventTarget + ".y");
    }
    if (imageUrlDuringCallBack || textDuringCallBack) {
        if (control.nodeName.toUpperCase() == "INPUT") {
            if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {
                SetLabelText(control.id, preProcessOut.OriginalText);
            } else if (inputType == "IMAGE") {
                if (imageUrlDuringCallBack) {
                    control.src = preProcessOut.OriginalText;
                } else {
                    preProcessOut.ParentElement.innerHTML = preProcessOut.OriginalText;
                }
            } else if (inputType == "SUBMIT") {
                control.value = preProcessOut.OriginalText;
            }
        } else if (control.nodeName.toUpperCase() == "SELECT") {
            SetLabelText(control.id, preProcessOut.OriginalText);
        } else {
            control.innerHTML = preProcessOut.OriginalText;
        }
    }
    if (clientCallBack) {
        clientCallBack(result, clientCallBackArg);
    }
}
function Bamboo_FireCallBackEvent(
	control,
	e,
	eventTarget,
	eventArgument,
	causesValidation,
	validationGroup,
	imageUrlDuringCallBack,
	textDuringCallBack,
	enabledDuringCallBack,
	preCallBackFunction,
	postCallBackFunction,
	callBackCancelledFunction,
	includeControlValuesWithCallBack,
	updatePageAfterCallBack
) {
    ////debugger;
    if (control.type == "radio") {
        Bamboo_GetValueControl(control.id);
    }
    var preProcessOut = new Bamboo_PreProcessCallBackOut();
    var preProcessResult = Bamboo_PreProcessCallBack(
	    control,
	    e,
	    eventTarget,
	    causesValidation,
	    validationGroup,
	    imageUrlDuringCallBack,
	    textDuringCallBack,
	    enabledDuringCallBack,
	    preCallBackFunction,
	    callBackCancelledFunction,
	    preProcessOut
	);
    if (preProcessResult) {
        Bamboo_FireEvent(
		    eventTarget,
		    eventArgument,
		    function(result) {
		        Bamboo_PostProcessCallBack(
                    result,
                    control,
                    eventTarget,
                    null,
                    null,
                    imageUrlDuringCallBack,
                    textDuringCallBack,
                    postCallBackFunction,
                    preProcessOut
                );
		    },
		    null,
		    includeControlValuesWithCallBack,
		    updatePageAfterCallBack
	    );
    }
}
function BambooListControl_OnClick(
    e,
	causesValidation,
	validationGroup,
	textDuringCallBack,
	enabledDuringCallBack,
	preCallBackFunction,
	postCallBackFunction,
	callBackCancelledFunction,
	includeControlValuesWithCallBack,
	updatePageAfterCallBack
) {
   ////debugger;
    var target = e.target || e.srcElement;
    if (target.nodeName.toUpperCase() == "LABEL" && target.htmlFor != '')
        return;
    var eventTarget = target.id.split("_").join("$");
    Bamboo_FireCallBackEvent(
	    target,
	    e,
	    eventTarget,
	    '',
	    causesValidation,
	    validationGroup,
	    '',
	    textDuringCallBack,
	    enabledDuringCallBack,
	    preCallBackFunction,
	    postCallBackFunction,
	    callBackCancelledFunction,
	    true,
	    true
	);
}

function GetLabelText(id) {
    var labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {
        if (labels[i].htmlFor == id) {
            return labels[i].innerHTML;
        }
    }
    return null;
}
function SetLabelText(id, text) {
    var labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {
        if (labels[i].htmlFor == id) {
            labels[i].innerHTML = text;
            return;
        }
    }
}
function Bamboo_SetCursor() {
    document.body.style.cursor = "wait";
}
function Bamboo_RemoveCursor() {
    document.body.style.cursor = "auto";
}

/* AJAX object */

function GetXmlHttp() {
    var xmlhttp = false;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest()
    }
    else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
            } catch (E) {
                xmlhttp = false;
            }
        }
    }
    return xmlhttp;
}


/* Sending error */
function SendErrorScript(address) {
    var xmlhttp = GetXmlHttp();
    var ctl00_m_g_8bd8af26_6979_417f_ab2e_f8be0db106b3MapurlError = '&report=error&message=' + address;
    if (xmlhttp) {
        xmlhttp.open("POST", window.location.href, true);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        xmlhttp.setRequestHeader("Accept-Encoding", "gzip, deflate");
        xmlhttp.send(ctl00_m_g_8bd8af26_6979_417f_ab2e_f8be0db106b3MapurlError);
    }
}

///////////////////--Bamboo G Map View for other countries--////////////////////////
var countryNames = new Array();
countryNames[0] = 'uk';
countryNames[1] = 'united kingdom';
countryNames[2] = 'england';
countryNames[3] = 'britain';
countryNames[4] = 'china';
var isMapNull = false;

function CheckCountryNames(country) {
    var flagCountry = false;
    //alert('what country here is :::'+country);
    for (var i = 0; i < countryNames.length; i++) {
        if (country.toLowerCase() == countryNames[i]) {
           // alert('country::::' + countryNames[i]);
            flagCountry = true;
            break;
        }
    }
    return flagCountry;
}
function GetPostCode(arrayAddress, stringName) {
    ////debugger;
    var arr = arrayAddress.split(";=;");
    var resultString = "";
    switch (stringName) {
        case "address":
            {
                resultString = arr[0] + ', ' + arr[1] + ', ' + arr[3];
                break;
            }
        case "citycountry":
            {
                resultString = arr[1] + ', ' + arr[3];
                break;
            }
        case "country":
            {
                resultString = arr[3];
                break;
            }
        default: break;
    }
    return resultString;
}

function ShowAddressForOtherCountries(mapID, arrayAdress, markID, flag, idCSS, CallbackFunction) {
    try {
        ////debugger;
        //alert("ShowAddressForOtherCountries:: " + eval(mapID + "MyCountAddress"));
        var postCode = GetPostCode(arrayAdress, "address");
        var localSearch = new GlocalSearch();
        localSearch.setSearchCompleteCallback(null, function() {
            if (localSearch.results[0]) {
                var resultLat = localSearch.results[0].lat;
                var resultLng = localSearch.results[0].lng;
                var point = new GLatLng(resultLat, resultLng);
                CallbackFunction(mapID, point, arrayAdress, markID, flag, idCSS);
            }
            else {
                ShowCityCountryForOtherCountries(mapID, localSearch, arrayAdress, markID, flag, idCSS, CallbackFunction);
            }
        });

        localSearch.execute(postCode);
    }
    catch (ex) {
        BambooErrors("ShowAddressForOtherCountries::", ex.message);
    }
}
function ShowCityCountryForOtherCountries(mapID, localSearch, arrayAdress, markID, flag, idCSS, CallbackFunction) {
    ////debugger;
    try {
        var postCode = GetPostCode(arrayAdress, "citycountry");
        localSearch.setSearchCompleteCallback(null, function() {
            if (localSearch.results[0]) {
                var resultLat = localSearch.results[0].lat;
                var resultLng = localSearch.results[0].lng;
                var point = new GLatLng(resultLat, resultLng);
                CallbackFunction(mapID, point, arrayAdress, markID, flag, idCSS);
            }
            else {
                ShowCountryForOtherCountries(mapID, localSearch, arrayAdress, markID, flag, idCSS, CallbackFunction);
            }
        });
        localSearch.execute(postCode);
    }
    catch (ex) {
        BambooErrors("ShowCityCountryForOtherCountries::", ex.message);
    }
}
function ShowCountryForOtherCountries(mapID, localSearch, arrayAdress, markID, flag, idCSS, CallbackFunction) {
    ////debugger;
    try {
        var postCode = GetPostCode(arrayAdress, "country");

        localSearch.setSearchCompleteCallback(null, function() {
            if (localSearch.results[0]) {
                var resultLat = localSearch.results[0].lat;
                var resultLng = localSearch.results[0].lng;
                var point = new GLatLng(resultLat, resultLng);

                CallbackFunction(mapID, point, arrayAdress, markID, flag, idCSS);
            }
            else {
                //alert(postCode + " not found");
            }
        });
        localSearch.execute(postCode);
    }
    catch (ex) {
        BambooErrors("ShowCountryForOtherCountries::", ex.message);
    }
}
function PlaceMarkerAtPoint(mapID, point, arrayAdress, markID, flag, idCSS) {
    ////debugger;
    try {

        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }

        var arr = arrayAdress.split(";=;");
        var markerLocation = arr[(arr.length - 3)];
        var markerWidth = arr[(arr.length - 2)];
        var markerHeight = arr[(arr.length - 1)];
        icons = CreateIcon(markerLocation, markerWidth, markerHeight);

        var marker = new GMarker(point, icons);
        marker.Id = markID;
        marker.Title = arrayAdress;

        if (!flagSetCenter) {
            if (typeof map.setCenter == "function") {
                map.setCenter(point, parseInt(zoomLevel, 0));
                flagSetCenter = true;
            }
        }

        eval(mapID + "MyCountAddress++");

        var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
        if (loadingPage && eval(mapID + "MyCountAddress <= " + mapID + "ItemsOnPage")) {
            loadingPage.style.display = "";
            loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + eval(mapID + "MyCountAddress") + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "ItemsOnPage") + " ...";
        }

        OpenInfoWindowTabsForOtherCountries(mapID, arrayAdress, marker, idCSS);

        //var totalItems = map.getOverlays().length;
        //if (flag == totalItems)	SetMapBestZoom(mapID);

        if (eval(mapID + "MyCountAddress >= " + mapID + "ItemsOnPage")) {
            //if (loadingPage)
            //{
            //  setTimeout(function() { loadingPage.style.display = "none"; }, 2000);
            //  eval(mapID + "MyCountAddress = 0;");
            //}
            SendReport(mapID);
        }

    }
    catch (ex) {
        BambooErrors("PlaceMarkerAtPoint::", ex.message);
    }
}
function OpenInfoWindowTabsForOtherCountries(mapID, arrayAdress, marker, idCSS) {
    try {
        ////debugger
        var styles = document.getElementsByTagName("STYLE");
        var extract = extractStyleSheet(styles, '.VirtualMapViewInfoBox-' + idCSS);

        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        var gTabTitles = fixArray(eval(mapID + "GTabTitles"));
        var arrayTabs = fixArray(eval(mapID + "ArrayTabs"));
        var arr = arrayAdress.split(";=;");
        var htm = new Array();
        var n = 4;
        for (var j = 0; j < gTabTitles.length; j++) {
            var contenTab = arrayTabs[j].split(";@#@;");
            htm[j] = "<table class='VirtualMapViewInfoWindowTabs-" + idCSS + "'>";
            for (var i = 0; i < contenTab.length; i++) {
                if (contenTab[i] != '') {
                    htm[j] += "<tr><td style='" + extract.styleSheet + "' " + (extract.noWrap ? "nowrap='true'" : "") + ">" + contenTab[i] + ":</td><td style='" + extract.styleSheet + "' " + (extract.noWrap ? "nowrap='true'" : "") + ">" + Trim(arr[n]) + "</td></tr>";
                    n++;
                }
            }
            htm[j] += "</table>";
        }
        var infoTabs = null;
        if ((gTabTitles.length == 0) || (gTabTitles.length == 1)) {
            infoTabs = [new GInfoWindowTab(gTabTitles[0], htm[0])];
        }
        if (gTabTitles.length == 2) {
            infoTabs = [new GInfoWindowTab(gTabTitles[0], htm[0]), new GInfoWindowTab(gTabTitles[1], htm[1])];
        }
        if (gTabTitles.length == 3) {
            infoTabs = [new GInfoWindowTab(gTabTitles[0], htm[0]), new GInfoWindowTab(gTabTitles[1], htm[1]),
						new GInfoWindowTab(gTabTitles[2], htm[2])];
        }
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowTabsHtml(infoTabs, { maxWidth: 300 });
        });
        map.addOverlay(marker);
    }
    catch (ex) {
        BambooErrors("OpenInfoWindowTabsForOtherCountries::", ex.message);
    }
}
///////////////////--Bamboo G Map View --////////////////////////
var icons; var arrAddr = new Array();
var iNode = new Array();
iNode[0] = new Array(); iNode[0][0] = "http://www.google.com/mapfiles/marker.png";
iNode[0][1] = 32; iNode[0][2] = 32;
var flagSetCenter = false; var mapIsLoad = false; var arrayTabs = new Array();

function fixArray(src) {
    ////debugger;
    var re = "";
    var s = src.split(";#;|");
    for (var i = 0; i < s.length; i++) {
        if (s[i].length == 0 || s[i] == '') {
        }
        else {
            re += s[i] + ";#;|";
        }
    }
    return re;
}
function GetNumberOfTabs(tViewField, tabTitles) {
    ////debugger;
    try {
        tViewField = unescape(tViewField.toString());

        var gTabTitles = new Array();
        var arrayFieldTemp = tViewField.split(";#;|");

        var arrayTabTemp = tabTitles.split(";#;|");

        return tabTitles.split(";#;|");
    }
    catch (ex) {
        BambooErrors("GetNumberOfTabs::", ex.message);
    }
}
/////////////////---Send error report ---///////////////////////////////////////////////
function SendReport(mapID) {
    ////debugger;
    map = eval(mapID);
    if (map == null) {
        if (!isMapNull) alert(eval("notLoadMap_" + mapID));
        isMapNull = true;
        return;
    }

    var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
    if (loadingPage) {
        if (typeof map.getOverlays == 'function' && map.getOverlays().length == eval(mapID + "ItemsOnPage")) {
            SetMapBestZoom(mapID);
            setTimeout(function() { loadingPage.style.display = "none"; }, 2000);
        }
        else {
            setTimeout(function() { loadingPage.style.display = "none"; SetMapBestZoom(mapID);  }, 2000);
            
        }
        //eval(mapID + "MyCountAddress = 0;"); 
    }
    //send report

    if (eval(mapID + "MyErrorAddress") != "") {
        SendErrorScript(eval(mapID + "MyErrorAddress"));
    }
}

// i identified here code to need fix  
function OnLoadMarkerByAddress(mapID, arrayAddress, markID, flag, idCSS) {
    try {
        ////debugger;
        if (mapID != null) {
            if (arrayAddress == '') {
                //map.setCenter(new GLatLng(34, 0), 2);
                alert(eval("AddressNull_" + mapID));
            }
            else {
                if (markID != '') {
                    //alert(markID);
                    //document.getElementById("mmm").value += markID + "\n";  
                   
                    var arrayCountries = arrayAddress.split(";=;");
                    var country = arrayCountries[3].toLowerCase();
                    // alert('this country is :::'+arrayCountries[3].toLowerCase());
                    if (CheckCountryNames(country)) {
                        ShowAddressForOtherCountries(mapID, arrayAddress, markID, flag, idCSS, PlaceMarkerAtPoint);
                    }
                    else {
                        ShowAddress(mapID, arrayAddress, markID, flag, idCSS);
                    }
                }
            }
        }
    }
    catch (ex) {
        BambooErrors("OnLoadMarkerByAddress::", ex.message);
    }
}

function CreateIcon(markerLocation, markerWidth, markerHeight) {
    ////debugger;
    var icon = new GIcon();
    icon.image = markerLocation;
    //icon.iconSize = new GSize(markerWidth, markerHeight);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(10, 20);
    return icon;
}

/* My customize style sheet */
function extractStyleSheet(styleElements, className) {
    ////debugger;
    var ret = new Object();

    ret.styleSheet = "";

    ret.noWrap = false;

    var endIndex, startIndex, arr, pair, tmp;

    for (var elem = 0; elem < styleElements.length; elem++) {
        var styleContent = styleElements[elem].innerHTML;
        startIndex = styleContent.indexOf(className);

        if (startIndex >= 0) {
            tmp = styleContent.substring(startIndex + className.length + 1);
            tmp = tmp.replace('{', '');

            endIndex = tmp.indexOf('}');
            ret.styleSheet = tmp.substring(0, endIndex);

            arr = ret.styleSheet.split(';');
            for (var j = 0; j < arr.length; j++) 
            {
                pair = arr[j].split(':');
                pair[0] = Trim(pair[0].toLowerCase());
                if (pair.length == 2) 
                {
                    pair[1] = Trim(pair[1].toLowerCase());
                    if ((pair[0] == "white-space" && pair[1].indexOf('nowrap') >= 0) || (pair[0] == "nowrap" && pair[1] == "true")) 
                    {
                        ret.noWrap = true;
                    }
                }
            }
        }
    }
    return ret;
}

function fixArray(src) {
    ////debugger;
    var s = "";
    for (var i = 0; i < src.length; i++)//tab 1 s
    {
        if (Trim(src[i]) != '') {
            s += (s.length > 0 ? ";#;" : "") + src[i];
        }
    }
    return s.split(";#;");
}

//This function is idendtifed by Son

var str = "";
function FormatString(stringFormat) 
{
    var temp = stringFormat;
    var widthSize = stringFormat.length;
    if (widthSize > 45) {
        str = "<div>" + stringFormat.substring(0, 44) + "</div>";
        var strSub = stringFormat.substring(44);
        if (strSub.length > 45) {
            str += FormatString(strSub);
        }
        else {
            str += "<div>" + strSub + "</div>";
        }
        return str;
    }
    return "<div>" + stringFormat + "</div>";
}
//end

function IsCustomBreakLine(arr, n) {
    for (var index = n; index < arr.length; index++) 
    {
        var widthSize = arr[index].length;
        if (widthSize > 70) 
        {
            return true;
        }
    }
    return false;
}

function OpenInfoWindowTabs(mapID, fullAddress, marker, condition, markerIsAdded, idCSS) {
    ////debugger;
    try 
    {
        var styles = document.getElementsByTagName("STYLE");
        var extract = extractStyleSheet(styles, '.VirtualMapViewInfoBox-' + idCSS);
        map = eval(mapID);
        if (map == null) 
        {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        var arrayTabs = fixArray(eval(mapID + "ArrayTabs"));
        var gTabTitles = fixArray(eval(mapID + "GTabTitles"));
        
        if (condition == 'address') 
        {
            var arr = fullAddress.split(";=;");
            var htm = new Array();
            var n = 4;
            var width = "100%";
            for (var j = 0; j < gTabTitles.length; j++)//info 1, info 2, info 3(count =3)
            {
                if (gTabTitles[j] != '') 
                {
                    var contenTab = arrayTabs[j].split(";@#@;");
                    width = IsCustomBreakLine(arr[n]) ? "600px" : "100%";
                    //htm[j] = "<table class='VirtualMapViewInfoWindowTabs-" + idCSS + "' style='table-layout:fixed;width:1000px";
                    htm[j] = "<table class='VirtuanMapViewInfoWindowTabs-" + idCSS +"'>";
                    for (var i = 0; i < contenTab.length; i++) 
                    {
                        if (contenTab[i] != '') 
                        {
                           // var stringConvert = FormatString(arr[n]);
                             htm[j] += "<tr><td style='"+extract.styleSheet+"' "+(extract.noWrap ? "nowrap='true'" : "")+">" + contenTab[i] + ":</td><td style='"+extract.styleSheet+"' "+(extract.noWrap ? "nowrap='false'" : "")+">" + Trim(arr[n]) + "</td></tr>";
                            // Son repair  here
                           // htm[j] += "<tr><td width='15%' style='" + extract.styleSheet + "' " + (extract.noWrap ? "nowrap='true'" : "") + ">" + contenTab[i] + ":</td><td width='85%' style='" + extract.styleSheet + "' " + (extract.noWrap ? "nowrap='true'" : "") + ">" + stringConvert + "</td></tr>";
                            // end
                            n++;
                        }
                    }
                    htm[j] += "</table>";
                }
            }
            var infoTabs = null;
            if ((gTabTitles.length == 0) || (gTabTitles.length == 1)) 
            {
                infoTabs = [new GInfoWindowTab(gTabTitles[0], htm[0])];
            }
            if (gTabTitles.length == 2) 
            {
                infoTabs = [new GInfoWindowTab(gTabTitles[0], htm[0]), new GInfoWindowTab(gTabTitles[1], htm[1])];
            }
            if (gTabTitles.length == 3) 
            {
                infoTabs = [new GInfoWindowTab(gTabTitles[0], htm[0]), new GInfoWindowTab(gTabTitles[1], htm[1]),
							new GInfoWindowTab(gTabTitles[2], htm[2])];
            }
            if (!markerIsAdded) 
            {
                GEvent.addListener(marker, "click", function() 
                {
                    marker.openInfoWindowTabsHtml(infoTabs, { maxWidth: 300 });
                });
                map.addOverlay(marker);
            }
            else 
            {
                marker.openInfoWindowTabsHtml(infoTabs, { maxWidth: 300 });
            }
        }
        else 
        {
            var arr = fullAddress.split(";=;");
            var htm = new Array();
            var n = 3;
            for (var j = 0; j < gTabTitles.length; j++) 
            {
                var contenTab = arrayTabs[j].split(";@#@;");
                htm[j] = "<table class='VirtualMapViewInfoWindowTabs-" + idCSS + "'>";
                for (var i = 0; i < contenTab.length; i++) 
                {
                    if (contenTab[i] != '') 
                    {
                        htm[j] += "<tr><td width='15%' style='" + extract.styleSheet + "' " + (extract.noWrap ? "nowrap='true'" : "") + ">" + contenTab[i] + ":</td><td width='85%' style='" + extract.styleSheet + "' " + (extract.noWrap ? "nowrap='true'" : "") + ">" + Trim(arr[n]) + "</td></tr>";
                        n++;
                    }
                }
                htm[j] += "</table>";
            }
            var infoTabs = null;
            if ((gTabTitles.length == 0) || (gTabTitles.length == 1)) 
            {
                infoTabs = [new GInfoWindowTab(gTabTitles[0], htm[0])];
            }
            if (gTabTitles.length == 2) 
            {
                infoTabs = [new GInfoWindowTab(gTabTitles[0], htm[0]), new GInfoWindowTab(gTabTitles[1], htm[1])];
            }
            if (gTabTitles.length == 3) 
            {
                infoTabs = [new GInfoWindowTab(gTabTitles[0], htm[0]), new GInfoWindowTab(gTabTitles[1], htm[1]),
							new GInfoWindowTab(gTabTitles[2], htm[2])];
            }
            if (!markerIsAdded) 
            {
                GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowTabsHtml(infoTabs, { maxWidth: 300 });
                });
                map.addOverlay(marker);
            }
            else {
                marker.openInfoWindowTabsHtml(infoTabs, { maxWidth: 300 });
            }
        }
    }
    catch (ex) {
        BambooErrors("OpenInfoWindowTabs::", ex.message);
    }
}

/////////////////---According to the Address, the City, the State and the Country to display marker---///////////////////////

function ShowAddress(mapID, fullAddress, markID, flag, idCSS) {
    try {
        ////debugger;
        //alert("ShowAddress:: " + eval(mapID + "MyCountAddress"));//null (0)
        map = eval(mapID);
        //alert(map);
        if (map == null) {
            //alert('alo alo');
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        var geocoder = eval(mapID + "Geocoder");
        // alert('value of geocoder is::'+geocoder);  //[object Object] 
        if (geocoder) {
            var arr = fullAddress.split(";=;");
            //alert('value of arr array is::'+arr);		
            var fullAddr = FixAddressText(arr[0]) + ' ' + arr[1] + ' ' + arr[2] + ' ' + arr[3];
            // alert('value of fullAddre is::::'+fullAddr);
            var markerLocation = arr[(arr.length - 3)];
            //alert('value markerLocation is :::'+markerLocation);
            var markerWidth = arr[(arr.length - 2)];
            //alert('value of markerWidth is :::'+markerWidth);
            var markerHeight = arr[(arr.length - 1)];
            //alert ('value of markerHeight is ::'+markerHeight);
            geocoder.getLatLng(fullAddr, function(point) 
            {
                //geocoder.getLatLng("bamboo", function(point) {
                if (!point) {
                    //alert('alo ola');
                    ShowCityStateCountry(mapID, fullAddress, markID, flag, idCSS);
                }
                else {
                    if (!flagSetCenter) {
                        if (typeof map.setCenter == "function") {
                            map.setCenter(point, parseInt(zoomLevel, 0));
                            flagSetCenter = true;
                        }
                    }
                    //alert(markID);
                    //document.getElementById("mmm").value += markID + ":: ShowAddress :: " + eval(mapID + "MyCountAddress") + "::" +  fullAddr + "\n";  

                    icons = CreateIcon(markerLocation, markerWidth, markerHeight);
                    eval(mapID + "MyCountAddress++");
                    var marker = new GMarker(point, icons);
                    marker.Id = markID;
                    marker.Title = fullAddress;
                    var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
                    if (loadingPage && eval(mapID + "MyCountAddress <= " + mapID + "ItemsOnPage")) 
                    {
                        loadingPage.style.display = "";
                        loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + eval(mapID + "MyCountAddress") + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "ItemsOnPage") + " ...";
                    }
                    // ////debugger
                    OpenInfoWindowTabs(mapID, fullAddress, marker, 'address', false, idCSS);
                    if (eval(mapID + "MyCountAddress >= " + mapID + "ItemsOnPage")) 
                    {
                        SendReport(mapID);
                    }
                }
            });
        }
    }
    catch (ex) 
    {
        BambooErrors("ShowAddress::", ex.message);
    }
}

/////////////////---According to the City, the State and the Country to display marker---///////////////////////

function ShowCityStateCountry(mapID, cityStateCountry, markID, flag, idCSS) {
    ////debugger;
    try 
    {
        map = eval(mapID);
        if (map == null) 
        {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }

        var geocoder = eval(mapID + "Geocoder");
        if (geocoder) {
            var arr = cityStateCountry.split(";=;");
            fullAddr = arr[1] + ' ' + arr[2] + ' ' + arr[3];
            var markerLocation = arr[(arr.length - 3)];
            var markerWidth = arr[(arr.length - 2)];
            var markerHeight = arr[(arr.length - 1)];
            geocoder.getLatLng(fullAddr, function(point) 
            {
                if (!point) 
                {
                    ShowCityCountry(mapID, cityStateCountry, markID, flag, idCSS);
                }
                else 
                {
                    if (!flagSetCenter) 
                    {
                        if (typeof map.setCenter == "function") 
                        {
                            map.setCenter(point, parseInt(zoomLevel, 0));
                            flagSetCenter = true;
                        }
                    }
                    icons = CreateIcon(markerLocation, markerWidth, markerHeight);

                    //document.getElementById("mmm").value += markID + ":: ShowCityStateCountry :: " + eval(mapID + "MyCountAddress") + "::" +  fullAddr + "\n";  

                    eval(mapID + "MyCountAddress++");
                    var marker = new GMarker(point, icons);
                    marker.Id = markID;
                    marker.Title = cityStateCountry;
                    var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
                    if (loadingPage && eval(mapID + "MyCountAddress <= " + mapID + "ItemsOnPage")) 
                    {
                        loadingPage.style.display = "";
                        loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + eval(mapID + "MyCountAddress") + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "ItemsOnPage") + " ...";
                    }
                    OpenInfoWindowTabs(mapID, cityStateCountry, marker, 'address', false, idCSS);
                    if (eval(mapID + "MyCountAddress >= " + mapID + "ItemsOnPage")) 
                    {
                        SendReport(mapID);
                    }

                }
            });
        }

    }
    catch (ex) 
    {
        BambooErrors("ShowCityStateCountry::", ex.message);
    }
}

/////////////////---According to the City and the Country to display marker---///////////////////////

function ShowCityCountry(mapID, cityCountry, markID, flag, idCSS) {
    ////debugger;
    try 
    {
        map = eval(mapID);
        if (map == null) 
        {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        var geocoder = eval(mapID + "Geocoder");
        if (geocoder) 
        {
            var arr = cityCountry.split(";=;");
            fullAddr = arr[1] + ' ' + arr[3];
            var markerLocation = arr[(arr.length - 3)];
            var markerWidth = arr[(arr.length - 2)];
            var markerHeight = arr[(arr.length - 1)];
            geocoder.getLatLng(fullAddr, function(point) 
            {
                if (!point) 
                {
                    ShowCountry(mapID, cityCountry, markID, flag, idCSS);
                }
                else 
                {
                    if (!flagSetCenter) 
                    {
                        if (typeof map.setCenter == "function") 
                        {
                            map.setCenter(point, parseInt(zoomLevel, 0));
                            flagSetCenter = true;
                        }
                    }
                    icons = CreateIcon(markerLocation, markerWidth, markerHeight);

                    //document.getElementById("mmm").value += markID + ":: ShowCityCountry :: " + eval(mapID + "MyCountAddress") + "::" +  fullAddr + "\n";  
                    eval(mapID + "MyCountAddress++");
                    var marker = new GMarker(point, icons);
                    marker.Id = markID;
                    marker.Title = cityCountry;

                    var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
                    if (loadingPage && eval(mapID + "MyCountAddress <= " + mapID + "ItemsOnPage")) 
                    {
                        loadingPage.style.display = "";
                        loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + eval(mapID + "MyCountAddress") + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "ItemsOnPage") + " ...";
                    }
                    OpenInfoWindowTabs(mapID, cityCountry, marker, 'address', false, idCSS);
                    if (eval(mapID + "MyCountAddress >= " + mapID + "ItemsOnPage")) 
                    {
                        SendReport(mapID);
                    }

                }
            });
        }
    }
    catch (ex) 
    {
        BambooErrors("ShowCityCountry::", ex.message);
    }
}


/////////////////---According to the Country to display marker---///////////////////////

function ShowCountry(mapID, country, markID, flag, idCSS) {
    ////debugger;
    try 
    {
        map = eval(mapID);
        if (map == null) 
        {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }

        var geocoder = eval(mapID + "Geocoder");
        if (geocoder) {
            var arr = country.split(";=;");
            fullAddr = arr[3];
            var markerLocation = arr[(arr.length - 3)];
            var markerWidth = arr[(arr.length - 2)];
            var markerHeight = arr[(arr.length - 1)];
            geocoder.getLatLng(fullAddr, function(point) 
            {
                if (!point) 
                {
                    eval(mapID + "MyErrorAddress += \";@;" + arr[0] + ";=;" + arr[1] + ";=;" + arr[2] + ";=;" + arr[3] + "\";");
                    //map.setZoom(parseInt(zoomLevel, 0));
                    eval(mapID + "MyCountAddress++");
                    var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
                    if (loadingPage && eval(mapID + "MyCountAddress <= " + mapID + "ItemsOnPage")) 
                    {
                        loadingPage.style.display = "";
                        loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + eval(mapID + "MyCountAddress") + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "ItemsOnPage") + " ...";
                    }
                    if (eval(mapID + "MyCountAddress >= " + mapID + "ItemsOnPage")) 
                    {
                        SendReport(mapID);
                    }
                }
                else 
                {
                    if (!flagSetCenter) 
                    {
                        if (typeof map.setCenter == "function") 
                        {
                            map.setCenter(point, parseInt(zoomLevel, 0));
                            flagSetCenter = true;
                        }
                    }
                    icons = CreateIcon(markerLocation, markerWidth, markerHeight);

                    //document.getElementById("mmm").value += markID + ":: ShowCountry :: " + eval(mapID + "MyCountAddress") + "::" +  fullAddr + "\n";  
                    eval(mapID + "MyCountAddress++");
                    var marker = new GMarker(point, icons);
                    marker.Id = markID;
                    marker.Title = country;
                    var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
                    if (loadingPage && eval(mapID + "MyCountAddress <= " + mapID + "ItemsOnPage")) 
                    {
                        loadingPage.style.display = "";
                        loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + eval(mapID + "MyCountAddress") + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "ItemsOnPage") + " ...";
                    }
                    OpenInfoWindowTabs(mapID, country, marker, 'address', false, idCSS);

                    //var totalItems = map.getOverlays().length;
                    //if (flag == totalItems)	SetMapBestZoom(mapID);
                    if (eval(mapID + "MyCountAddress >= " + mapID + "ItemsOnPage")) 
                    {
                        SendReport(mapID);
                    }

                }
            });
        }
    }
    catch (ex) 
    {
        BambooErrors("ShowCountry::", ex.message);
    }
}

///////////////////////////--Show the map with data marker by using the Coordinates--///////////////////////////////////////

function OnLoadMarkerByCoordinates(mapID, fullCoordinates, markID, flag, eastWard, idCSS) 
{
    try 
    {
        ////debugger;
        if (mapID != null) 
        {
            if (fullCoordinates == '') 
            {
                //map.setCenter(new GLatLng(34, 0), 2);
                alert('Empty');
            }
            else
                ShowCoordinates(mapID, fullCoordinates, markID, flag, eastWard, idCSS);
        }
    }
    catch (ex) 
    {
        BambooErrors("OnLoadMarkerByCoordinates::", ex.message);
    }
}
function ShowCoordinates(mapID, fullCoordinates, markID, flag, eastWard, idCSS) {
    ////debugger;
    try {
        map = eval(mapID);
        if (map == null) 
        {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        if (eval(mapID + "Geocoder")) 
        {
            var arr = fullCoordinates.split(";=;");
            var latTude = arr[0]; var alTude = arr[2]; var markerLocation = arr[(arr.length - 3)];
            var markerWidth = arr[(arr.length - 2)]; var markerHeight = arr[(arr.length - 1)];
            var lngTude = arr[1];
            var point = null;
            
            if (IsNumber(latTude) && IsNumber(lngTude)) {
                if (eastWard != null)
                    point = new GLatLng(latTude, ConvertLongitude(lngTude), alTude);
                else
                    point = new GLatLng(latTude, lngTude, alTude);
            }
            
            if (!point)  
            {
                eval(mapID + "MyErrorAddress += \";@;" + arr[0] + ";=;" + arr[1] + ";=;" + arr[2] + ";=;" + arr[3] + "\";");
                //map.setZoom(parseInt(zoomLevel, 0));
                eval(mapID + "MyCountAddress++");
                //alert("Error: can not locate this address ...\n" + country + "\nNum: " + eval(mapID + "MyCountErrorAddress"));
                //alert("Error");
                //document.getElementById("mmm").value += markID + ":: ShowCountry-NoPoint :: " + eval(mapID + "MyCountAddress") + "::" +  fullAddr + "\n";  
                var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
                if (loadingPage && eval(mapID + "MyCountAddress <= " + mapID + "ItemsOnPage")) 
                {
                    loadingPage.style.display = "";
                    loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + eval(mapID + "MyCountAddress") + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "ItemsOnPage") + " ...";
                }
                if (eval(mapID + "MyCountAddress >= " + mapID + "ItemsOnPage")) 
                {
                    SendReport(mapID);
                }
                map.setZoom(parseInt(zoomLevel, 0));
            }
            else 
            {
                if (!flagSetCenter) 
                {
                    if (typeof map.setCenter == "function") 
                    {
                        map.setCenter(point, parseInt(zoomLevel, 0));
                        flagSetCenter = true;
                    }
                }
                icons = CreateIcon(markerLocation, markerWidth, markerHeight);
                var pt = null;
                if (eastWard != null)
                    pt = new GLatLng(latTude, ConvertLongitude(lngTude));
                else
                    pt = new GLatLng(latTude, lngTude);

                eval(mapID + "MyCountAddress++")
                var marker = new GMarker(point, icons);
                marker.Id = markID;
                marker.Title = fullCoordinates;
                var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
                if (loadingPage && eval(mapID + "MyCountAddress <= " + mapID + "ItemsOnPage")) 
                {
                    loadingPage.style.display = "";
                    loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + eval(mapID + "MyCountAddress") + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "ItemsOnPage") + " ...";
                }

                OpenInfoWindowTabs(mapID, fullCoordinates, marker, 'coordinates', false, idCSS);
                if (eval(mapID + "MyCountAddress >= " + mapID + "ItemsOnPage")) 
                {
                    SendReport(mapID);
                }
            }
        }
    }
    catch (ex) {
        BambooErrors("ShowCoordinates::", ex.message);
    }
}



function ConvertLongitude(myLng) {
    ////debugger;
    var result = Trim(myLng);
    try {
        result = parseFloat(result) - 180;

    }
    catch (ex) {
        BambooErrors("ConvertLongitude::", ex.message);
    }

    return result; 
}

function IsNumber(myLng) {
    var result = Trim(myLng);
    if ( result == "" || result == undefined || result == null || isNaN(result)) 
       return false ;
    return true;
}
 


function ShowLocationByMarkerId(mapID, markerId, idCSS) 
{
    debugger;
    try 
    {
        //alert(mapID);
        map = eval(mapID);
        if (map == null) 
        {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }

        for (var i = 0; i < map.getOverlays().length; i++) 
        {
            var marker = map.getOverlays(i);
            var point = marker[i].getPoint();
            if (markerId == marker[i].Id) {
                if (typeof map.setCenter == "function") 
                {
                    map.setCenter(point);
                }
                OpenInfoWindowTabs(mapID, marker[i].Title, marker[i], eval(mapID + "StrOption"), true, idCSS);
                break;
            }
        }
    }
    catch (ex) 
    {
        BambooErrors("ShowLocationByMarkerId::", ex.message);
    }
}

///////////////////////////--Set Zoom Level and Map type--///////////////////////////////////////

function SetMapTypeAndZoomLevelCurrent(mapID, mapTypeID, option) {
    ////debugger;
    try 
    {
        map = eval(mapID);
        if (map == null) 
        {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        //alert("ok 1");
        //mapTypeID = mapTypeID.substring(0, mapTypeID.length - 3);
        var mapType = document.getElementById(mapTypeID).value;
        //alert(parseInt(mapType) + "="+ option + "=" + typeof(map.SetMapStyle) + "=" + typeof(map.setMapType));
        
        if (typeof(map.setMapType) == 'function') 
        {
             if (parseInt(mapType) == 0)
             {
                map.setMapType(G_NORMAL_MAP);
             }
             else if (parseInt(mapType) == 1)
             {
                map.setMapType(G_SATELLITE_MAP);
             }
             else if (parseInt(mapType) == 2)
             {
                map.setMapType(G_HYBRID_MAP);
             }
        }
        else 
        {
            //var mapType = map.getCurrentMapType().getName().toLowerCase();
            //map.SetMapStyle(VEMapStyle.Aerial);
            /*
            if (parseInt(mapType) == 0) 
            {
                map.SetMapStyle(VEMapStyle.Road);
            }
            else if (parseInt(mapType) == 1) 
            {
                map.SetMapStyle(VEMapStyle.Aerial);
            }
            else if (parseInt(mapType) == 2)
            { 
                map.SetMapStyle(VEMapStyle.Birdseye);
            }*/
        }
    }
    catch (ex) 
    {
        BambooErrors("SetMapTypeAndZoomLevelCurrent::", ex.message);
    }
}

function GetMapTypeAndZoomLevel(mapID, mapTypeID, zoomLevelID) {
    ////debugger;
    try 
    {
        map = eval(mapID);
        if (map == null) 
        {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        var mapType = map.getCurrentMapType().getName().toLowerCase();
        document.getElementById(mapTypeID).value = mapType;
        document.getElementById(zoomLevelID).value = map.getZoom();
    }
    catch (ex) 
    {
        BambooErrors("GetMapTypeAndZoomLevel::", ex.message);
    }
}
function GetMapTypeAndZoomLevelVE(mapID, mapTypeID, zoomLevelID) {
    ////debugger;
    try 
    {
        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }

        var mapType = map.GetMapStyle();
        document.getElementById(mapTypeID).value = mapType;
        document.getElementById(zoomLevelID).value = map.GetZoomLevel();
    }
    catch (ex) {
        BambooErrors("GetMapTypeAndZoomLevelVE::", ex.message);
    }
}

function SetValueForHiddenField(hiddenID, hiddenValue) {
    //debugger;
    try {
        var hiddenField = document.getElementById(hiddenID).value;
        if (hiddenField != null) {
            document.getElementById(hiddenID).value = hiddenValue;
        }
    }
    catch (ex) {
        BambooErrors("SetValueForHiddenField::", ex.message);
    }
}
function CheckOnChanged(sourceID, destinationId) {
    //debugger;
    try {
        var tempDestination = document.getElementById(destinationId).value;
        var tempSource = document.getElementById(sourceID).value;

        if ((tempDestination != null) && (tempSource != null)) {
            document.getElementById(destinationId).value = tempSource;
        }
    }
    catch (ex) {
        BambooErrors("CheckOnChanged::", ex.message);
    }
}
function SetMapTypeAndZoomLevel(mapID, mapTypeID, zoomLevelID) {
    //debugger;
    try {
        map = eval(mapID);
        if (map != null) {
            var mapType = document.getElementById(mapTypeID).value;

            switch (mapType) {
                case "map":
                    {
                        map.setMapType(G_NORMAL_MAP);
                        break;
                    }
                case "satellite":
                    {
                        map.setMapType(G_SATELLITE_MAP);
                        break;
                    }
                case "hybrid":
                    {
                        map.setMapType(G_HYBRID_MAP);
                        break;
                    }
                default: break;
            }
        }
    }
    catch (ex) {
        BambooErrors("SetMapTypeAndZoomLevel::", ex.message);
    }
}
function ClearImages(objid) {
    if (objid == '')
        map.clearOverlays();
}
//---------------------------------------------------------------------------------------
function addOnLoadEvent(func) {
    //debugger;
    try {

        var oldOnLoad = window.onload;
        if (typeof window.onload != 'function') {
            //alert("Hello");
            window.onload = func;
        }
        else {
            window.onload = function() {
                //alert("Goodbye");
                oldOnLoad();
                func();
            }
        }
        //window.attachEvent('onload', func);       
    }
    catch (ex) {
        //alert(ex.message);
        BambooErrors("addOnLoadEvent::", ex.message);
    }
}
function VirtualMapView_OnUnLoaded() {
    //debugger;
    try {
        GUnload();
    }
    catch (ex) { }
}
function ShowPopupSourceEdit(idObjData, btnSave, btnCancel) {
    debugger;
    window.open("wpresources/Bamboo.VirtualMapView/PopupVirtualMapView.html?ContainID=" + escape(idObjData) + "&s=" + btnSave + "&c=" + btnCancel, 'FullScreen', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=665,height=530');
    return false;
}
function IsBlank(val) {
    //debugger;
    if (val == null) {
        return true;
    }
    for (var i = 0; i < val.length; i++) {
        if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n") && (val.charAt(i) != "\r")) {
            return false;
        }
    }
    return true;
}
function StartWithZero(val) {
    //debugger;
    if (val.charAt(0) == '0')
        return true;
    else
        return false;
}
function IsInteger(val) {
    if (StartWithZero(val)) {
        return false;
    }
    for (var i = 0; i < val.length; i++) {
        if (!IsDigit(val.charAt(i))) {
            return false;
        }
    }
    return true;
}
function IsDigit(num) {
    if (num.length > 1) {
        return false;
    }
    var string = "1234567890";
    if (string.indexOf(num) != -1) {
        return true;
    }
    return false;
}
function CheckInteger(validatorID, mapID) {
    //debugger;
    try {
        var num = document.getElementById(validatorID).value;

        if (!IsInteger(num)) {
            alert(eval("enterNumberValue_" + mapID));
            document.getElementById(validatorID).focus();
            document.getElementById(validatorID).select();
        }
        if (IsBlank(num)) {
            alert(eval("enterNumberRow") + mapID);
            document.getElementById(validatorID).focus();
            document.getElementById(validatorID).select();
        }
    }
    catch (ex) {
        BambooErrors("CheckInteger::", ex.message);
    }
}
//--------------------------------------VIRTUAL EARTH--------------------------------------------

var infoBox = null;
//------------------
function ShapeInfo(e, mapID, idCSS) {
    //debugger;
    try {
        if (infoBox && infoBox == eval("infoBox_" + mapID)) infoBox.style.display = "none";

        infoBox = eval("infoBox_" + mapID);

        map = eval(mapID);

        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }

        map.HideInfoBox();


        if (e.elementID != null) {
            layer = eval(mapID + "layer");
            var _s = map.GetShapeByID(e.elementID).GetPhotoURL(); //map.GetShapeByID(e.elementID).GetZIndex();

            for (var j = 0; j < layer.GetShapeCount(); j++) {
                var shape = layer.GetShapeByIndex(j);
                var shapeID = shape.GetPhotoURL(); //shape.GetZIndex();

                if (shapeID == _s) {
                    map.PanToLatLong(shape.GetPoints()[0]);
                    window.setTimeout(function() { map.ShowInfoBox(shape); }, 500);
                    break;
                }
            }
        }
    }
    catch (ex) {
        BambooErrors("ShapeInfo::", ex.message);
    }
}
function AddShapeLayerOnMap(mapID, latLong, fullAddress, n, myShapeID, index, idCSS) {
    //debugger;
    try {
    
        map = eval(mapID);
        layer = eval(mapID + "layer");

        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        var arr = fullAddress.split(";=;");
        var iconLocation = arr[(arr.length - 3)];
        var iconWidth = arr[(arr.length - 2)];
        var iconHeight = arr[(arr.length - 1)];
        var shape = new VEShape(VEShapeType.Pushpin, latLong);
        
       // var titles = GetTitleOfTabs(mapID,n, eval(mapID + "GTabTitles"));
        var details = GetContentOfTabs(fullAddress, n, eval(mapID + "GTabTitles"), eval(mapID + "ArrayTabs"), idCSS);
        var titles = GetTitleOfTabs(fullAddress, n, eval(mapID + "GTabTitles"), eval(mapID + "ArrayTabs"), idCSS);        

        var newShapeID = parseInt(idCSS) + index;
        //shape.SetZIndex(newShapeID);
        shape.SetPhotoURL(newShapeID);

        var customIcon = new VECustomIconSpecification;
        customIcon.Image = iconLocation;
        shape.SetCustomIcon(customIcon);
        shape.SetTitle(titles);
        shape.SetDescription(details);

        layer.AddShape(shape);

        map.AddShapeLayer(layer);
    }
    catch (ex) 
    {
        //BambooErrors("AddShapeLayerOnMap::", ex.message);
    }
}
function SetMapBestView(mapID, option) {
    //debugger;
    try {
        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        if (option == "VE") {
            var points = eval(mapID + "MyViewPoints");
            var arrayPoints = new Array();
            for (var i = 0; i < points.length; i = i + 2) {
                var pt = new VELatLong(points[i], points[i + 1]);
                arrayPoints.push(pt);
            }
            map.SetMapView(arrayPoints);
        }
    }
    catch (ex) {
        BambooErrors("SetMapBestView::", ex.message);
    }
}
function SetMapBestZoom(mapID) {
    //debugger;
    try {
        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        
        if (typeof(map.setZoom) == 'function')
        {
            var bounds = eval(mapID + "MyViewPoints");
            for (var i = 0; i < map.getOverlays().length; i++) {
                var marker = map.getOverlays(i);
                var point = marker[i].getPoint();
                bounds.extend(point);
            }
            map.setZoom(map.getBoundsZoomLevel(bounds));
            if (typeof map.setCenter == "function") {
                map.setCenter(bounds.getCenter());
            }
            var myCountTime = eval(mapID + "mySetTimeOut");
            if (myCountTime < 2) {
                //setTimeout("SetMapBestZoom('" + mapID + "')", 1000); 
                eval(mapID + "mySetTimeOut++");
            }
        }
    }
    catch (ex) {
        //BambooErrors("SetMapBestZoom::", ex.message);
    }
}

function ShowVEByAddress(mapID, newMyArray, strShapeID, idCSS) {
   // debugger;
    try {
    
        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        eval(mapID + "MyArray = newMyArray");
        eval(mapID + "MyShapeID = strShapeID");
        index = eval(mapID + "Index");

        var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
        if (loadingPage) 
        {
            loadingPage.style.display = "";
            loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + index + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "MyArray.length") + " ...";
        }

        if (eval("index < " + mapID + "MyArray.length")) 
        {
            eval(mapID + "TmpFullAddress = " + mapID + "MyArray[index]");
            var whereResult = GetStringAddress(eval(mapID + "TmpFullAddress"), 0);
           //  map.Find(null, whereResult, null, map.GetShapeLayerByIndex(0), 0, 1, null, true, false, false, "");
              map.Find(null, whereResult, null, map.GetShapeLayerByIndex(0), 0, 1, null, true, false, false, function() {
                    ShowPushPinByAddress(arguments[0], arguments[1], arguments[2], arguments[3], mapID, idCSS);
                });
          
            map.ShowMessageBox = false;
        }
        else {
            if (loadingPage) {
                setTimeout(function() { loadingPage.style.display = 'none'; }, 2000);
            }

            SetMapBestView(mapID, "VE");
            return false;

        }

        if (eval(mapID + "Index >= " + mapID + "ItemsOnPage")) {
            SendReport(mapID);
        }
    }
    catch (ex) {
        BambooErrors("ShowVEByAddress::", ex.message);
    }
}
function ShowPushPinByAddress(layer, whatResults, whereResults, hasMore, mapID, idCSS) {
   //debugger;
    try {
    
        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        if (whereResults != null) {
            eval(mapID + "MyViewPoints.push(" + whereResults[0].LatLong + ")");
            AddShapeLayerOnMap(mapID, whereResults[0].LatLong, eval(mapID + "TmpFullAddress"), 4, eval(mapID + "MyShapeID"), eval(mapID + "Index"), idCSS);
            eval(mapID + "Index++");
            ShowVEByAddress(mapID, eval(mapID + "MyArray"), eval(mapID + "MyShapeID"), idCSS);
        }
        else {
            var whereResult = GetStringAddress(eval(mapID + "TmpFullAddress"), 1);
            map.Find(null, whereResult, null, map.GetShapeLayerByIndex(0), 0, 1, null, true, false, false, function() { ShowPushPinByCityStateCountry(arguments[0], arguments[1], arguments[2], arguments[3], mapID, idCSS); });
         
        }
        if (eval(mapID + "Index >= " + mapID + "ItemsOnPage")) {
            SendReport(mapID);
        }
    }
    catch (ex) {
        BambooErrors("ShowPushPinByAddress::", ex.message);
    }
}
function ShowPushPinByCityStateCountry(layer, whatResults, whereResults, hasMore, mapID, idCSS) {
    //debugger;
    try {
        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        if (whereResults != null) {
            eval(mapID + "MyViewPoints.push(" + whereResults[0].LatLong + ")");
            AddShapeLayerOnMap(mapID, whereResults[0].LatLong, eval(mapID + "TmpFullAddress"), 4, eval(mapID + "MyShapeID"), eval(mapID + "Index"), idCSS);
            eval(mapID + "Index++");
            ShowVEByAddress(mapID, eval(mapID + "MyArray"), eval(mapID + "MyShapeID"), idCSS);
        }
        else {
            //alert("find another country !");
            var whereResult = GetStringAddress(eval(mapID + "TmpFullAddress"), 2);
            map.Find(null, whereResult, null, map.GetShapeLayerByIndex(0), 0, 1, null, true, false, false, function() { ShowPushPinByCityCountry(arguments[0], arguments[1], arguments[2], arguments[3], mapID, idCSS); });
         
            }
        if (eval(mapID + "Index >= " + mapID + "ItemsOnPage")) {
            SendReport(mapID);
        }
    }
    catch (ex) {
        BambooErrors("ShowPushPinByCityStateCountry::", ex.message);
    }
}
function ShowPushPinByCityCountry(layer, whatResults, whereResults, hasMore, mapID, idCSS) {
    //debugger;
    try {
        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        if (whereResults != null) {
            eval(mapID + "MyViewPoints.push(" + whereResults[0].LatLong + ")");
            AddShapeLayerOnMap(mapID, whereResults[0].LatLong, eval(mapID + "TmpFullAddress"), 4, eval(mapID + "MyShapeID"), eval(mapID + "Index"), idCSS);
            eval(mapID + "Index++");
            ShowVEByAddress(mapID, eval(mapID + "MyArray"), eval(mapID + "MyShapeID"), idCSS);
        }
        else {
            //alert("find another city country");
            var whereResult = GetStringAddress(eval(mapID + "TmpFullAddress"), 3);
            map.Find(null, whereResult, null, map.GetShapeLayerByIndex(0), 0, 1, null, true, false, false, function() { ShowPushPinByStateCountry(arguments[0], arguments[1], arguments[2], arguments[3], mapID, idCSS); });
        }
        if (eval(mapID + "Index >= " + mapID + "ItemsOnPage")) {
            SendReport(mapID);
        }
    }
    catch (ex) {
        BambooErrors("ShowPushPinByCityCountry::", ex.message);
    }
}
function ShowPushPinByStateCountry(layer, whatResults, whereResults, hasMore, mapID, idCSS) {
    //debugger;
    try {
        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }

        if (whereResults != null) {

            eval(mapID + "MyViewPoints.push(" + whereResults[0].LatLong + ")");
            AddShapeLayerOnMap(mapID, whereResults[0].LatLong, eval(mapID + "TmpFullAddress"), 4, eval(mapID + "MyShapeID"), eval(mapID + "Index"), idCSS);
            eval(mapID + "Index++");
            ShowVEByAddress(mapID, eval(mapID + "MyArray"), eval(mapID + "MyShapeID"), idCSS);
        }
        else {
           // eval(mapID + "MyViewPoints.push(" + whereResults[0].LatLong + ")");
           // AddShapeLayerOnMap(mapID, whereResults[0].LatLong, eval(mapID + "TmpFullAddress"), 4, eval(mapID + "MyShapeID"), eval(mapID + "Index"), idCSS);
            eval(mapID + "Index++");
            ShowVEByAddress(mapID, eval(mapID + "MyArray"), eval(mapID + "MyShapeID"), idCSS);
        }
        

        if (hasMore == null) {

            var dv = document.createElement("DIV");
            dv.innerHTML = eval(mapID + "TmpFullAddress");

            eval(mapID + "MyErrorAddress += \";@;" + dv.innerText + "\";");
            //eval(mapID + "MyCountAddress++");

            var loadingPage = document.getElementById(mapID.substring(0, mapID.length - 3) + "_loadingPage");
            if (loadingPage && eval(mapID + "Index <= " + mapID + "ItemsOnPage")) {
                loadingPage.style.display = "";
                loadingPage.innerHTML = eval("loadingMarker_" + mapID) + " " + eval(mapID + "Index") + " " + eval("ofMarker_" + mapID) + " " + eval(mapID + "ItemsOnPage") + " ...";
            }
        }

        if (eval(mapID + "Index >= " + mapID + "ItemsOnPage")) {
            SendReport(mapID);
        }
        //alert(hasMore);
    }
    catch (ex) {
        BambooErrors("ShowPushPinByStateCountry::", ex.message);
    }
}

/* My custom Content of VE */
function redrawContentWithStyleSheet(content, idCSS) {
    //debugger;
    var dv, tables, _table;
    var titleStyle, contentStyle, styles, classNameTitle, classNameContent;

    styles = document.getElementsByTagName("STYLE");

    dv = document.createElement("DIV");
    dv.innerHTML = content;
    tables = dv.getElementsByTagName("TABLE");
    //return content;;
    if (tables.length > 0) 
    {
        _table = tables[0];

        // detect browser 
        var isFF = window.navigator.appName.indexOf('Netscape') >= 0;

        // Extract stylesheet;
        classNameTitle = '.VirtualMapViewTitle-' + idCSS;
        titleStyle = extractStyleSheet(styles, classNameTitle);
        classNameContent = '.VirtualMapViewInfoBox-' + idCSS;
        contentStyle = extractStyleSheet(styles, classNameContent);
        // Fetch style sheet
        var row, tableContent = '<table class="VirtualMapViewInfoBox-' + idCSS + '" cellspacing="0" cellpadding="0" style="margin-right: 10px">';
        for (var iRow = 0; iRow < _table.rows.length; iRow++) 
        {
            row = _table.rows[iRow];
            if (row.cells.length == 1) 
            {
                // For title
                tableContent += '<tr><td colspan="2" class="VirtualMapViewTitle-' + idCSS + '" style="' + titleStyle.styleSheet + '" ' + (titleStyle.noWrap ? 'nowrap="true"' : '') + '>' + (isFF ? row.cells[0].textContent : row.cells[0].innerText) + '</td></tr>';
            }
            else {
                //for content
                tableContent += '<tr>';
                tableContent += '	<td style="' + contentStyle.styleSheet + '" ' + (contentStyle.noWrap ? 'nowrap="true"' : '') + '>' + (isFF ? row.cells[0].textContent : row.cells[0].innerText) + '</td>';

                var srcText = isFF ? row.cells[1].textContent : row.cells[1].innerText;
                var hyperlink = srcText.substring(0, srcText.indexOf(','));
                var hypertext = srcText.substring(srcText.indexOf(',') + 1);

                var targetText = isURL(hyperlink) ? '<a href="' + hyperlink + '" target="_blank">' + hypertext + '</a>' : row.cells[1].innerHTML;

                tableContent += '	<td style="' + contentStyle.styleSheet + '" ' + (contentStyle.noWrap ? 'nowrap="true"' : '') + '>' + targetText + '</td>';
                //alert(row.cells[1].innerText);
                tableContent += '</tr>';
            }
        }
        tableContent += '</table>';
        return tableContent;
    }
    else
        return content;
}

/* For bug 222 */
function isURL(url) 
{
    var reg = new RegExp("/?([:\/\w\s\d\.]*)/");
    return url.match(reg);
}

/* My custome size */
function resizeShape() {
    //debugger;
    // detect browser 
    var isFF = window.navigator.appName.indexOf('Netscape') >= 0;

    var dv, tables, maxSize, child, stop = false;
    dv = document.getElementById("MSVE_navAction_palette");

    dv = dv.nextSibling;
    // Fixed for FF/Netscape
    while (dv.nodeType != 1) dv = dv.nextSibling;

    // Get real Size:
    tables = dv.getElementsByTagName("TABLE");
    maxSize = 0;
    for (var iTable = 0; iTable < tables.length; iTable++) 
    {
        maxSize = maxSize < tables[iTable].offsetWidth ? tables[iTable].offsetWidth : maxSize;
    }
    if (maxSize > 0) 
    {
        childrenDIV = dv.getElementsByTagName("DIV");
        for (var child = 0; child < childrenDIV.length; child++) 
        {
            // resize Popup
            //if (childrenDIV[child].className != 'ero-beak' && childrenDIV[child].className != 'active' && childrenDIV[child].className != 'deactive')
            //	childrenDIV[child].style.width = maxSize + 25 + 'px';
            // remove DIV if it's empty
            if (childrenDIV[child].className == 'ero-paddingHack' || childrenDIV[child].className == 'ero-actions') 
            {
                var t = isFF ? childrenDIV[child].textContent : childrenDIV[child].innerText;
                if (Trim(t) == '' || t.length == 0) {
                    childrenDIV[child].style.padding = '0px';
                    childrenDIV[child].style.margin = '0px';
                    childrenDIV[child].style.height = '0px';
                }
            }
        }
    }
}

/*
return object has class name is the same of class name by arguments
*/
function getTagByClassName(tags, className) {
    //debugger;
    var o = null;
    for (var id = 0; id < tags.length; id++)
        if (tags[id].className == className) 
        {
            o = tags[id]; break; 
        }

    return o;
}

function redrawContentTab(content, idCSS) {
    //debugger;
    var dv, tables, _table, retTable, row;
    var titleStyle, contentStyle, styles, classNameTitle, classNameContent;
    var arrTitle = new Array();
    var arrContent = new Array();

    styles = document.getElementsByTagName("STYLE");
    dv = document.createElement("DIV");
    dv.innerHTML = content;
    tables = dv.getElementsByTagName("TABLE");

    if (tables.length > 0 && tables[0].id != "tab2007") 
    {
        _table = tables[0];
        // detect browser 
        var isFF = window.navigator.appName.indexOf('Netscape') >= 0;

        // Extract stylesheet;
        classNameTitle = '.VirtualMapViewTitle-' + idCSS;
        titleStyle = extractStyleSheet(styles, classNameTitle);
        classNameContent = '.VirtualMapViewInfoBox-' + idCSS;
        contentStyle = extractStyleSheet(styles, classNameContent);

        var json = '( { "O" : [] ';
        for (var iRow = 0; iRow < _table.rows.length; iRow++) {
            row = _table.rows[iRow];
            if (row.cells.length == 1) {
                // For Title or Breakline
                // Add Title
                var t = isFF ? row.cells[0].textContent : row.cells[0].innerText;
                // close before Tab
                if (iRow > 0 && Trim(t) != '' && t.length > 0) json += '] ';
                if (Trim(t) != '' && t.length > 0) json += ', "' + t + '" : [ "" ';
            }
            else {
                //for Content
                var t0 = isFF ? row.cells[0].textContent : row.cells[0].innerText;
                var t1 = isFF ? row.cells[1].textContent : row.cells[1].innerText;
                json += ', "' + t0 + ':' + t1 + '"';
            }
        }
        // Close tab after
        json += '] })';
        var json = eval(json);
        // JSON Technology
        retTable = '<table cellspacing="0" cellpadding="0" width=\"95%\" id="tab2007" class="VirtualMapViewInfoBox-' + idCSS + '">';

        var titleTab = '<tr class="tbTabTitle">';
        var contentTab = '<tr class="tbTabBody"><td colspan="3">';

        var count = 0; // Number of Tab
        for (var item in json) 
        {
            if (item != 'O') {
                titleTab += '<td class="header"><div class="' + (count == 0 ? 'active' : 'deactive') + '" onclick="settab(this)">' + item + '</div></td>';
                contentTab += '<table id="childTab' + count + '" cellspacing="0" width=\"100%\" cellpadding="0" style="' + (count > 0 ? 'display:none' : '') + '">';
                for (var index in json[item]) 
                {
                    pair = json[item][index];
                    pairs = pair.split('::');
                    if (pairs.length == 2) 
                    {
                        contentTab += '<tr>';
                        contentTab += '		<td style="' + titleStyle.styleSheet + '" ' + (titleStyle.noWrap ? 'nowrap' : '') + '>' + pairs[0] + ':</td>';
                        contentTab += '		<td style="' + contentStyle.styleSheet + '" ' + (contentStyle.noWrap ? 'nowrap' : '') + '>' + pairs[1] + '</td>';
                        contentTab += '</tr>';
                    }
                }
                contentTab += '</table>';
                // More tab
                count++;
            }
        }
        titleTab += '</tr>';
        contentTab += '</td></tr>';

        retTable += titleTab + contentTab + '</table>';
        return NoBreak(retTable);
    }
    else
        return content; // No Rebuild Tab
}

function setTabActive(obj, idCSS) {
    //debugger;
    var tdObject = obj.parentNode; // Slit to TD
    var trObj = tdObject.parentNode; // Slit to TR

    var maxHeight = 0;

    for (var i = 0; i < trObj.cells.length; i++) 
    {
        if (trObj.cells[i].getElementsByTagName("A").length > 0) 
            trObj.cells[i].getElementsByTagName("A")[0].className = "deactive";
        var b = document.getElementById("tab_" + idCSS + "_" + i);
        if (b.tagName == "TABLE") 
        {
            maxHeight = maxHeight < b.offsetHeight ? b.offsetHeight : maxHeight;
        }
        if (b) b.style.display = 'none';
    }

    document.getElementById('tab_' + idCSS + '_' + tdObject.cellIndex).style.display = 'block';
    document.getElementById('tab_' + idCSS + '_' + tdObject.cellIndex).style.height = maxHeight + 'px';
    obj.className = "active";
}

/*
GetPosition(param)
- param: ID of object need to get the position
- return: Position of object
*/
function GetPosition(objectID, shapeId) {
   //debugger;
    var pos = new Object;
    pos.x = 0;
    pos.y = 0;

    var arrShapeID = objectID.split('#');
    var parentShapeId = arrShapeID[0].substring(0, arrShapeID[0].length - 1);
    var parentShapeObject = eval(parentShapeId);
    var arrObjectInparent = parentShapeObject.getElementsByTagName("A");

    var obj = null;

    for (var objIndex = 0; objIndex < arrObjectInparent.length; objIndex++)
        if (arrObjectInparent[objIndex].id.indexOf(shapeId) > 0) {
        obj = arrObjectInparent[objIndex];
        break;
    }

    if (obj != null) {
        while (obj.offsetParent != null) {
            pos.x += obj.offsetLeft - obj.scrollLeft;
            pos.y += obj.offsetTop - obj.scrollTop;
            obj = obj.offsetParent;
        }
    }
    return pos;
}


function ShowShapeLayerById(mapID, myShapeLayerId, idCSS) {
    //debugger;
    try {
        if (infoBox && infoBox == eval("infoBox_" + mapID)) infoBox.style.display = "none";

        infoBox = eval("infoBox_" + mapID);

        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        map.HideInfoBox();
        layer = eval(mapID + "layer");

        var _mid = myShapeLayerId.split('_');

        layer = eval(mapID + "layer");

        for (var j = 0; j < layer.GetShapeCount(); j++) {
            var shape = layer.GetShapeByIndex(j);
            var shapeID = shape.GetPhotoURL(); //shape.GetZIndex();
            var _m = parseInt(_mid[_mid.length - 2]) + parseInt(_mid[_mid.length - 1]);

            if (shapeID == _m) {

                var _sid = shape.GetID().split('_'); // _sid = msftve_1001_200037
                var _idx = parseInt(_sid[_sid.length - 1]) - 200000; // _idx = 37
                var _rid = shape.GetID() + '_' + (10000 + _idx); // _rid = msftve_1001_200037_10037

                map.PanToLatLong(shape.GetPoints()[0]);
                map.StartContinuousPan(20, 20);
                map.EndContinuousPan();
                VEShowVEShapeERO(_rid, map.GUID);
                break;
            }

        }

    }
    catch (ex) {
        //alert(ex.message);
        BambooErrors("ShowShapeLayerById::", ex.message);
    }
}


function ShowShapeLayerByIdCoordinate(mapID, myShapeLayerId, idCSS) {
   // debugger;
    try {
        if (infoBox) infoBox.style.display = "none";
        infoBox = eval("infoBox_" + mapID);

        map = eval(mapID);
        if (map == null) {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        map.HideInfoBox();

        layer = eval(mapID + "layer");

        var _mid = myShapeLayerId.split('_');

        layer = eval(mapID + "layer");

        for (var j = 0; j < layer.GetShapeCount(); j++) {
            var shape = layer.GetShapeByIndex(j);
            var shapeID = shape.GetPhotoURL(); //shape.GetZIndex();
             var _m = parseInt(_mid[_mid.length - 2]) + parseInt(_mid[_mid.length - 1]);
           
            if (shapeID == _m) {
                var _sid = shape.GetID().split('_'); // _sid = msftve_1001_200037
                var _idx = parseInt(_sid[_sid.length - 1]) - 200000; // _idx = 37
                var _rid = shape.GetID() + '_' + (10000 + _idx); // _rid = msftve_1001_200037_10037

                 map.PanToLatLong(shape.GetPoints()[0]);
                
                map.StartContinuousPan(20, 20);
                map.EndContinuousPan();
                VEShowVEShapeERO(_rid, map.GUID);
                break;
            }
        }

    }
    catch (ex) {
        BambooErrors("ShowShapeLayerByIdCoordinate::", ex.message);
    }
}

//this function is added by Son GetHeaderOfTabsForAT
/*
//var titles = GetTitleOfTabs(fullAddress, n, eval(mapID + "GTabTitles"), eval(mapID + "ArrayTabs"), idCSS);
        var titles = GetTitleOfTabs(n, eval(mapID + "GTabTitles"),idCSS);
*/

function GetTitleOfTabs1( n, gTabTitles, idCSS) {
    //debugger;
    try {
        gTabTitles = fixArray(gTabTitles);
        var results = '<div class="tab-container' + idCSS + '"><ul class="tabs">';
        for (var j = 0; j < gTabTitles.length; j++) {
            var className = j == 0 ? "class=tab-active" : "";
            results += "<li><label " + className + "  onMouseOver=\"if(this.className != 'tab-active') this.style.color='#990000'; \" onMouseOut=\"this.style.color=''\" onClick='return ShowPaneForAT(\"" + idCSS + "\", \"" + idCSS + "pane" + eval(j + 1).toString() + "\", this)' id='" + idCSS + "tab" + eval(j + 1).toString() + "'>" + gTabTitles[j] + "</label></li>";
           // results += '<li><a hreg="java' + 'script:void(0)" class="' + (tabIdx == 0 ? 'active' : 'deactive') + '"onclick="setTabActive(this,' + idCss + ')">' + gTabTitles[tabIdx] + '</li>';
        }
        results += '</ul><br></div>';
        return results;
       
    }
    catch (ex) {
        BambooErrors("GetTitleOfTabs", ex.message);
    }
}

function ShowPaneForAT(mapID, paneId, activeTab) {
    //debugger;
  // make tab active class
  // hide other panes (siblings)
  // make pane visible
    eval("panes = " + mapID + "Panes");
  
    for (var con in panes) {
        for(var pane in panes[con])
        {
            var pane = document.getElementById(pane);
            pane.style.display = "none";
        }
        activeTab.blur();
        activeTab.className = "tab-active";
        if (panes[con][paneId] != null) { // tab and pane are members of this container
          var pane = document.getElementById(paneId);
          pane.style.display = "inline";
          var container = document.getElementById(con);
          var tabs = container.getElementsByTagName("ul")[0];
          var tabList = tabs.getElementsByTagName("label")
          for (var i=0; i<tabList.length; i++ )
          {
            var tab = tabList[i];
            if (tab != activeTab) tab.className = "tab-disabled";
          }
          for (var i in panes[con]) {
            var pane = panes[con][i];
            if (pane == undefined) continue;
            if (pane.id == paneId) continue;
            pane.style.display = "none"
          }
        }
    }
    return false;    
}
//end add

function GetTitleOfTabs(fullAddress, n, gTabTitles, arrayTabs, idCSS) {
    //debugger;

    gTabTitles = fixArray(gTabTitles);
    arrayTabs = fixArray(arrayTabs);
    var arr = fullAddress.split(";=;");
    var results = '<table style="width: auto" class="VirtualMapViewTitle-' + idCSS + '"><tr>';
    for (var tabIdx = 0; tabIdx < gTabTitles.length; tabIdx++) 
    {
        results += '<td class="VirtualMapViewTitle-' + idCSS + '" colspan="2" nowrap="true"><a href="java' + 'script:void(0)" class="' + (tabIdx == 0 ? 'active' : 'deactive') + '" onclick="setTabActive(this,' + idCSS + ')">' + gTabTitles[tabIdx] + '</td>';
    }
    results += '</tr></table>';
    return results;
}

var strVE = "";
function FormatStringVE(stringFormat)
 {
    //debugger
    var temp = stringFormat;
    var widthSize = stringFormat.length;
    if (widthSize > 16) 
    {
        strVE = "<div>" + stringFormat.substring(0, 15) + "</div>";
        var st
        rSub = stringFormat.substring(15);
        if (strSub.length > 16) {
            strVE += FormatStringVE(strSub);
        }
        else {
            strVE += "<div>" + strSub + "</div>";
        }
        return strVE;
    }
    return "<div>" + stringFormat + "</div>";
}

function GetContentOfTabs(fullAddress, n, gTabTitles, arrayTabs, idCSS) {
    //debugger;
    gTabTitles = fixArray(gTabTitles);
    arrayTabs = fixArray(arrayTabs);
    var arr = fullAddress.split(";=;");
    var results = "";
    for (var j = 0; j < gTabTitles.length; j++) {

        results += '<table width="100%" id="tab_' + idCSS + '_' + j + '" class="VirtualMapViewInfoBox-' + idCSS + '" style="' + (j > 0 ? 'display: none' : '') + '">';
        // results += '<table id="tab_' + idCSS + '_' + j + '" class="VirtualMapViewInfoBox-' + idCSS + '" style="' + (j > 0 ? 'display: none' : '')  + '">'; +(j>0?'display:none':'')
        // results += '<div id="tab_' + idCSS + '_' + j + '" class="VirtualMapViewInfoBox-' + idCSS + '" style='') + '">';
        var contenTab = arrayTabs[j].split(";@#@;");
        for (var i = 0; i < contenTab.length; i++) 
        {
            //  var str1 = FormatStringVE(arr[n]);	
            var str1 = arr[n];
            // if( (contenTab[i].indexOf(' ')!=-1) && contenTab[i].length > 14) 
            //	{
            //var str2 = fixFormatString(contenTab[i]);
            var str2 = contenTab[i];
            //var strcomplete = str2.replace(str2.EndsWith("</br>"),"");
            results += '<tr><td nowrap width="100px"><div>' + str2 + ':</div></td><td width="110px" style="padding-left: 2px"><div>' + str1 + '</div></td></tr>';
            //}
            // else if((contenTab[i].indexOf(' ')==-1) && contenTab[i].length > 14)
            //{
            //	results += '<tr><td nowrap width="100px"><div>'+ contenTab[i] + ':</div></td><td width="100px" style="padding-left:2px"><div>' +str1 + '</div></td></tr>';
            //SplitString(contenTab[i],10) 
            //}
            // else
            //{
            //      results += '<tr><td nowrap width="100px"><div>' + contenTab[i] + ':</div></td><td width="100px" style="padding-left:2px"><div>' +str1+ '</div></td></tr>';    
            // }

            n++;
        }
            /*
            if (contenTab[i] != '') 
            {
              // var str1 = arr[n];
                // repair here
                var str1 = FormatStringVE(arr[n]);
                var str2 = FormatStringVE(arr[n]);
                //end repair
               // var str2 = arr[n];
                if (str1 == str2) {
                    if (str1.indexOf(' ') != -1) 
                    {
                        if (contenTab[i].indexOf(' ') != -1) 
                        {
                           // var index = contenTab[i].indexOf(contenTab[i].charAt(' '));
                           // var str3 = SplitString(contenTab[i], index);
                              results += '<tr><td nowrap>' + contenTab[i] + ':</td><td style="padding-left: 5px">' + str1 + '</td></tr>';
                            //results += '<tr ><td  colspan="2" style="padding-left:15px"><B>' + contenTab[i] + ':</B></td></tr>';
                            //results += '<tr><td width="10%"></td><td style="padding-left:25px">' + str1 + '</td></tr>';
                          
                        }
                        else
                        {
                             results += '<tr><td nowrap>' + SplitString(contenTab[i], 14) + ':</td><td style="padding-left: 5px">' + str1 + '</td></tr>';
                           // results += '<tr><td colspan="2" style="padding-left:15px"><B>' + SplitString(contenTab[i], 14) + ':</B></td></tr>';
                           // results += '<tr><td width="10%"></td><td style="padding-left:25px">' + str1 + '</td></tr>';
                        
                        }
                    }
                    else 
                    {
                        if (contenTab[i].indexOf(' ') != -1) 
                        {
                            var index1 = contenTab[i].indexOf(contenTab[i].charAt(' '));
                            var str3 = SplitString(contenTab[i], index1);
                              results += '<tr><td nowrap>' + contenTab[i] + ':</td><td style="padding-left: 5px">' + SplitString(str1, 8) + '</td></tr>';
                           // results += '<tr><td colspan="2" style="padding-left:15px"><B>' + contenTab[i] + ':</B></td></tr>';
                           // results += '<tr><td width="10%"></td><td style="padding-left:25px">' + SplitString(str1, 20) + '</td></tr>';
                           
                        }

                        else {
                        //14,20
                             results += '<tr><td nowrap>' + SplitString(contenTab[i], 14) + ':</td><td style="padding-left: 5px">' + SplitString(str1, 8) + '</td></tr>';
                            //results += '<tr><td colspan="2" style="padding-left:15px"><B>' + SplitString(contenTab[i], 14) + ':</B></td></tr>';
                            //results += '<tr><td width="10%"></td><td style="padding-left:25px">' + SplitString(str1, 20) + '</td></tr>';
                        }
                            
                    }
                }
                else
                    results += '<tr><td nowrap style="padding-left:2px">' + SplitString(contenTab[i], 14) + ':</td><td style="padding-left: 5px">' + str2 + '</td></tr>';
                    */
                
            
        // }
        //if (j < (gTabTitles.length - 1))
        //	results += "<tr><td colspan='2' width='100%'><hr style ='height:1px;color:silver;'></td></tr>";			
        results += '</table>';
    }    
    results += '';
    return results;
}
function fixFormatString(stringFormat) {
    //debugger;
    var fixString = stringFormat.split(' ');
    var stringComplet = "";
    for (var i = 0; i < fixString.length; i++) {
        stringComplet +="<div>"+ fixString[i] + "</div>";
    }
    //stringComplet = stringComplet.replace("</br>:", ":");
    return stringComplet;

}


function FixAddressText(address) {
    //debugger;
    //Fix special character
    address = address.replace('/', ' ');
    address = address.replace('&', ' ');
    //Fix abbreviation
    address = address.replace(' hwy. ', ' Highway ');
    address = address.replace(' Hwy. ', ' Highway ');
    address = address.replace(' hwy ', ' Highway ');
    address = address.replace(' Hwy ', ' Highway ');
    address = address.replace(' Bl ', ' Blvd. ');

    return address;
}
function GetStringAddress(fullAddress, option) {
    //debugger;
    var strResult = "";
    var arrayAddress = fullAddress.split(";=;");
    switch (option) {
        case 0: //Street, City, State, Country
            {
                strResult = FixAddressText(arrayAddress[0]) + ', ' + arrayAddress[1] + ', ' + arrayAddress[2] + ', ' + arrayAddress[3];
                break;
            }
        case 1: //City, State, Country
            {
                strResult = arrayAddress[1] + ', ' + arrayAddress[2] + ', ' + arrayAddress[3];
                break;
            }
        case 2: //City, Country
            {
                strResult = arrayAddress[1] + ', ' + arrayAddress[3];
                break;
            }
        case 3: //State, Country
            {
                strResult = arrayAddress[2] + ', ' + arrayAddress[3];
                break;
            }
        case 4: //Country
            {
                strResult = arrayAddress[3];
                break;
            }
        default: break;
    }
    return strResult;
}
function GetShapeID(strShapeID) 
{
    var result = "";
    var tmpArray = strShapeID.toString().split("#");
    result = tmpArray[1];

    return result;
}
//---------------------------------------------------------------------------------------------------------------------
var flagSetCenter = false;
function ShowVEByCoordinates(mapID, newMyArray, strShapeID, flag, eastWard, idCSS) {
    //debugger;
    try 
    {
        //alert(strShapeID);
        map = eval(mapID);
        if (map == null) 
        {
            if (!isMapNull) alert(eval("notLoadMap_" + mapID));
            isMapNull = true;
            return;
        }
        if (!flag) 
        {
            var lat = null;
            var lng = null;
            var latLonArray = newMyArray.split(";=;");
                               
            lat = parseFloat(latLonArray[0]);
            if (eastWard != null)
               lng = ConvertLongitude(latLonArray[1]);
            else
               lng = parseFloat(latLonArray[1]);
            eval(mapID + "MyViewPoints.push(" + lat + ")");
            eval(mapID + "MyViewPoints.push(" + lng + ")");
            var latLong = null;  //new VELatLong(lat, lng);
            if (!isNaN(lat) && !isNaN (lng ))
                var latLong =  new VELatLong(lat, lng);
                
            AddShapeLayerOnMap(mapID, latLong, newMyArray, 3, strShapeID, eval(mapID + 'Index'), idCSS);
            eval(mapID + "Index++");
            map.ShowMessageBox = false;
        }
        else
            SetMapBestView(mapID, "VE");
    }
    catch (ex) 
    {
        BambooErrors("ShowVEByCoordinates::", ex.message);
    }
}
function SplitString(myString, len) {
    //debugger;
    var result = "";
    if (myString.length > len) 
    {
        var n = 0;
        for (var i = 0; i < myString.length; i++) 
        {
            n++;
            result += '' + myString.charAt(i);
            if (n == len) 
            {
                result += '<br>';
                n = 0;
            }
        }
    }
    else
        result = myString;
    return result;
}
var imageTypes = new Array();
imageTypes[0] = ".gif"; imageTypes[1] = ".jpg"; imageTypes[2] = ".jpeg";
imageTypes[3] = ".png"; imageTypes[4] = ".bmp"; imageTypes[5] = ".wmf"; imageTypes[6] = ".dib";

function CheckImage(myString) {
    //debugger;
    var flagResult = false;
    myString = myString.toLowerCase();
    for (var i = 0; i < imageTypes.length; i++) 
    {
        if (myString.indexOf(imageTypes[i]) != -1) 
        {
            var nArray = myString.split(".");
            var eEnd = '.' + nArray[nArray.length - 1];
            if (eEnd == imageTypes[i]) 
            {
                flagResult = true;
                break;
            }
        }
    }
    return flagResult;
}
function CheckURL(myString, myOption) {
    //debugger;
    var myResult = myString;
    //alert(myString + " == " + myOption);
    var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
    try 
    {
        if (regexp.test(myString)) 
        {
            if (myString.toLowerCase().indexOf(",") != -1) 
            {
                // Exist colon
                //var urlArray = myString.split(","); //;@#@;

                var hyperlink = myString.substring(0, myString.indexOf(','));
                var hypertext = myString.substring(myString.indexOf(',') + 1);

                if (!CheckImage(Trim(hyperlink)))
                    myResult = "<a href=\"" + Trim(hyperlink) + "\" target='_blank' title=\"" + Trim(hypertext) + "\" >" + SplitString(hypertext, 20) + "</a>";
                else 
                {
                    if (myOption == 'GM')
                        myResult = "<a href=\"" + Trim(hyperlink) + "\" target='_blank' title =\"" + Trim(hypertext) + "\" ><img src=\"" + Trim(hyperlink) + "\" style='border:0' width='120px'></a>";
                    else
                        myResult = "<a href=\"" + unescape(Trim(hyperlink)) + "\" target='_blank' title =\"" + unescape(Trim(hypertext)) + "\" ><img src=\"" + unescape(Trim(hyperlink)) + "\" style='border:0' width='120px'></a>";
                }
            }
            else {
                if (!CheckImage(Trim(myString)))
                    myResult = "<a href=\"" + unescape(Trim(myString)) + "\" target='_blank' >" + unescape(SplitString(Trim(myString), 20)) + "</a>";
                else {
                    if (myOption == 'GM')
                        myResult = "<a href=\"" + unescape(Trim(myString)) + "\" target='_blank' title =\"" + unescape(Trim(myString)) + "\" ><img src=\"" + unescape(Trim(myString)) + "\" style='border:0' width='120px'></a>";
                    else
                        myResult = "<a href=\"" + unescape(Trim(myString)) + "\" target='_blank' title =\"" + unescape(Trim(myString)) + "\" ><img src=\"" + unescape(Trim(myString)) + "\" style='border:0' width='120px'></a>";
                }
            }
        }
        else {
            if (myString.toLowerCase().indexOf("www.") != -1) {
                if (myString.toLowerCase().indexOf(",") != -1) {
                    //var urlArray = myString.split(",");
                    var hyperlink = myString.substring(0, myString.indexOf(','));
                    var hypertext = myString.substring(myString.indexOf(',') + 1);

                    if (!CheckImage(Trim(hyperlink)))
                        myResult = "<a href=ht" + "tp://" + Trim(hyperlink) + " target='_blank' title=\"" + Trim(hypertext) + "\" > " + Trim(hypertext) + "</a>";
                    else {
                        if (myOption == 'GM')
                            myResult = "<a href=ht" + "tp://" + Trim(hyperlink) + " target='_blank' title=\"" + Trim(hypertext) + "\" ><img src=\"" + Trim(hyperlink) + "\" style='border:0' width='120px'></a>";
                        else
                            myResult = "<a href=ht" + "tp://" + escape(Trim(hyperlink)) + " target='_blank' title=\"" + escape(Trim(hypertext)) + "\" ><img src=\"" + escape(Trim(hyperlink)) + "\" style='border:0' width='120px'></a>";
                    }
                }
                else {
                    if (!CheckImage(Trim(myString)))
                        myResult = "<a href=ht" + "tp://" + Trim(myString) + " target='_blank' title=\"" + Trim(myString) + "\" >" + Trim(myString) + "</a>";
                    else {
                        if (myOption == 'GM')
                            myResult = "<a href=ht" + "tp://" + Trim(myString) + " target='_blank' title=\"" + Trim(myString) + "\" ><img src=\"" + Trim(myString) + "\" style='border:0' width='120px'></a>";
                        else
                            myResult = "<a href=ht" + "tp://" + escape(Trim(myString)) + " target='_blank' title=\"" + escape(Trim(myString)) + "\" ><img src=\"" + escape(Trim(myString)) + "\" style='border:0' width='120px'></a>";
                    }
                }
            }
            else
                myResult = myString;
        }
    }
    catch (ex) {
        BambooErrors("CheckURL::", ex.message);
    }
    return myResult;
}
function NoBreak(value) {
    var reg = /\r\n/g;
    return value.replace(reg, '');
}
function LTrim(value) 
{
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
}
function RTrim(value) 
{
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
}
function Trim(value) 
{
    return LTrim(RTrim(value));
}
function VirtualMapViewShowToolTip(mapID, values, idCSS) {
    //debugger;
    var myResult = null;
    try 
    {
        myResult = unescape(values);
        if (eval(mapID + "StrOption == 'address'"))
            myResult = escape(GetStringForToolTip(mapID, myResult, 4, idCSS));
        else
            myResult = escape(GetStringForToolTip(mapID, myResult, 3, idCSS));
    }
    catch (ex) 
    {
        BambooErrors("VirtualMapViewShowToolTip::", ex.message);
    }
    return myResult;
}

//i 'm found code for tooltip here very funny 2966


function GetStringForToolTip(mapID, fullAddress, n, idCSS) {
    //debugger;
    var gTabTitles = eval(mapID + "GTabTitles");
    var arrayTabs = eval(mapID + "ArrayTabs");
    var arr = fullAddress.split(";=;");
    var results = "<table class='VirtualMapViewToolTipBody-" + idCSS + "' style='z-index:9999'>";
    results += "<tr><td colspan=2 width=100% style=color:gray><b>" + eval("descriptionItem_" + mapID) + "</b><hr style=height:1px;color:silver;></td></tr>";
    for (var j = 0; j < gTabTitles.length; j++) 
    {
        var contenTab = arrayTabs[j].split(";@#@;");
        for (var i = 0; i < contenTab.length; i++) 
        {
            if (contenTab[i] != '') 
            {
                 var str1 = arr[n];

                //var str1 = FormatString(arr[n]);
                
                //Comment here by Son 5/28/2009
                //				if ((str1.indexOf('http://') != -1) || (str1.indexOf('www.') != -1))
                //				{
                //					var str2 = str1.split(",");
                //					str1 = str2[0];
                //	            }
                //end comment


                 results += "<tr><td style=white-space:nowrap>" + contenTab[i] + ":</td><td style=white-space:nowrap>" + str1 + "</td></tr>";
               // results += "<tr><td style=white-space:pre-line>" + contenTab[i] + ":</td><td style=white-space:pre-line>" + str1 + "</td></tr>";
                n++;
            }
        }
    }
    results += "</table>";
    return results;
}


//Tooltip
if (typeof document.attachEvent != 'undefined') {
    window.attachEvent('onload', Init);
    document.attachEvent('onmousemove', MoveMouse);
    document.attachEvent('onclick', IsMove);
}
else {
    window.addEventListener('load', Init, false);
    document.addEventListener('mousemove', MoveMouse, false);
    document.addEventListener('click', IsMove, false);
}

var oDv = document.createElement("div");
var dvHdr = document.createElement("div");
var dvBdy = document.createElement("div");
var windowlock, boxMove, fixposx, fixposy, lockX, lockY, fixx, fixy, ox, oy;
var boxLeft, boxRight, boxTop, boxBottom, evt, mouseX, mouseY, boxOpen, totalScrollTop, totalScrollLeft;
boxOpen = false;
ox = 10;
oy = 10;
lockX = 0;
lockY = 0;

function Init() {
    //debugger;
    oDv.appendChild(dvHdr);
    oDv.appendChild(dvBdy);
    oDv.style.position = "absolute";
    oDv.style.visibility = "hidden";
    oDv.style.border = "solid 1px black";
    //oDv.className = "ms-quickLaunch";
    //oDv.style.width = "1px";
    oDv.style.zIndex = 999;
    //	oDv.style.filter='alpha(opacity=90)'; // IE
    //	oDv.style.opacity='0.9'; // FF
    document.body.appendChild(oDv);
}

function DefHdrStyle() {
    dvHdr.innerHTML = '<img  style="vertical-align:middle"  src="info.gif">&nbsp;&nbsp;' + dvHdr.innerHTML;
    dvHdr.style.fontWeight = 'bold';
    dvHdr.style.fontFamily = 'arial';
    dvHdr.style.border = '1px solid #A5CFE9';
    dvHdr.style.padding = '2';
    dvHdr.style.fontSize = '11';
    dvHdr.style.color = '#FFFFFF';
    dvHdr.style.background = '#4B7A98';
    dvHdr.style.filter = 'alpha(opacity = 85)'; // IE
    dvHdr.style.opacity = '0.85'; // FF
}

function DefBdyStyle() {
    dvBdy.style.borderBottom = '1px solid #A5CFE9';
    dvBdy.style.borderLeft = '1px solid #A5CFE9';
    dvBdy.style.borderRight = '1px solid #A5CFE9';
    dvBdy.style.fontFamily = 'arial';
    dvBdy.style.fontSize = '11';
    dvBdy.style.padding = '3';
    dvBdy.style.color = '#1B4966';
    dvBdy.style.background = '#FFFFFF';
    dvBdy.style.filter = 'alpha(opacity=85)'; // IE
    dvBdy.style.opacity = '0.85'; // FF
}

function IsElemBO(txt) {
    
    if (!txt || typeof (txt) != 'string')
        return false;
    if ((txt.indexOf('header') > -1) && (txt.indexOf('body') > -1) && (txt.indexOf('[') > -1) && (txt.indexOf('[') > -1))
        return true;
    else
        return false;
}

function ScanBO(curNode) {
   
    if (IsElemBO(curNode.title)) {
        curNode.boHDR = GetParam('header', curNode.title);
        curNode.boBDY = unescape(GetParam('body', curNode.title));
        // custom for Virtual map View
        //curNode.boBDY = ShowTooltip(curNode.boBDY);
        //---
        curNode.boCSSBDY = GetParam('cssbody', curNode.title);
        curNode.boCSSHDR = GetParam('cssheader', curNode.title);
        curNode.IEbugfix = (GetParam('HideSelects', curNode.title) == 'on') ? true : false;
        curNode.fixX = parseInt(GetParam('fixedrelx', curNode.title));
        curNode.fixY = parseInt(GetParam('fixedrely', curNode.title));
        curNode.absX = parseInt(GetParam('fixedabsx', curNode.title));
        curNode.absY = parseInt(GetParam('fixedabsy', curNode.title));
        curNode.offY = (GetParam('offsety', curNode.title) != '') ? parseInt(GetParam('offsety', curNode.title)) : 10;
        curNode.offX = (GetParam('offsetx', curNode.title) != '') ? parseInt(GetParam('offsetx', curNode.title)) : 10;
        curNode.fade = (GetParam('fade', curNode.title) == 'on') ? true : false;
        curNode.fadespeed = (GetParam('fadespeed', curNode.title) != '') ? GetParam('fadespeed', curNode.title) : 0.04;
        curNode.delay = (GetParam('delay', curNode.title) != '') ? parseInt(GetParam('delay', curNode.title)) : 0;
        if (GetParam('requireclick', curNode.title) == 'on') {
            curNode.requireclick = true;
            document.all ? curNode.attachEvent('onclick', ShowHideBox) : curNode.addEventListener('click', ShowHideBox, false);
            document.all ? curNode.attachEvent('onmouseover', HideBox) : curNode.addEventListener('mouseover', HideBox, false);
        }
        else {// Note : if requireclick is on the stop clicks are ignored   			
            if (GetParam('doubleclickstop', curNode.title) != 'off') {
                document.all ? curNode.attachEvent('ondblclick', PauseBox) : curNode.addEventListener('dblclick', PauseBox, false);
            }
            if (GetParam('singleclickstop', curNode.title) == 'on') {
                document.all ? curNode.attachEvent('onclick', PauseBox) : curNode.addEventListener('click', PauseBox, false);
            }
        }
        curNode.windowLock = GetParam('windowlock', curNode.title).toLowerCase() == 'off' ? false : true;
        curNode.title = '';
        curNode.hasbox = 1;
    }
    else
        curNode.hasbox = 2;
}


function GetParam(param, list) {
    //debugger;
    var reg = new RegExp('([^a-zA-Z]' + param + '|^' + param + ')\\s*=\\s*\\[\\s*(((\\[\\[)|(\\]\\])|([^\\]\\[]))*)\\s*\\]');
    var res = reg.exec(list);
    var returnvar;
    if (res)
        return res[2].replace('[[', '[').replace(']]', ']');
    else
        return '';
}

function Left(elem) {
    //debugger;
    var x = 0;
    if (elem.calcLeft)
        return elem.calcLeft;
    var oElem = elem;
    while (elem) {
        if ((elem.currentStyle) && (!isNaN(parseInt(elem.currentStyle.borderLeftWidth))) && (x != 0))
            x += parseInt(elem.currentStyle.borderLeftWidth);
        x += elem.offsetLeft;
        elem = elem.offsetParent;
    }
    oElem.calcLeft = x;
    return x;
}

function Top(elem) {
    var x = 0;
    if (elem.calcTop)
        return elem.calcTop;
    var oElem = elem;
    while (elem) {
        if ((elem.currentStyle) && (!isNaN(parseInt(elem.currentStyle.borderTopWidth))) && (x != 0))
            x += parseInt(elem.currentStyle.borderTopWidth);
        x += elem.offsetTop;
        elem = elem.offsetParent;
    }
    oElem.calcTop = x;
    return x;
}

var ah, ab;
function ApplyStyles() {
    //debugger;
    if (ab)
        oDv.removeChild(dvBdy);
    if (ah)
        oDv.removeChild(dvHdr);
    dvHdr = document.createElement("div");
    dvBdy = document.createElement("div");
    CBE.boCSSBDY ? dvBdy.className = CBE.boCSSBDY : DefBdyStyle();
    CBE.boCSSHDR ? dvHdr.className = CBE.boCSSHDR : DefHdrStyle();
    dvHdr.innerHTML = CBE.boHDR;
    dvBdy.innerHTML = CBE.boBDY;
    ah = false;
    ab = false;
    if (CBE.boHDR != '') {
        oDv.appendChild(dvHdr);
        ah = true;
    }
    if (CBE.boBDY != '') {
        oDv.appendChild(dvBdy);
        ab = true;
    }
}

var CSE, iterElem, LSE, CBE, LBE, totalScrollLeft, totalScrollTop, width, height;
var ini = false;

function SHW() {
    //debugger;
    if (document.body && (document.body.clientWidth != 0)) {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
    if (document.documentElement && (document.documentElement.clientWidth != 0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    }
    return [width, height];
}

var ID = null;
function MoveMouse(e) {
   
    //boxMove=true;
    e ? evt = e : evt = event;

    CSE = evt.target ? evt.target : evt.srcElement;

    if (!CSE.hasbox) {
        // Note we need to scan up DOM here, some elements like TR don't get triggered as srcElement
        iElem = CSE;
        while ((iElem.parentNode) && (!iElem.hasbox)) {
            ScanBO(iElem);
            iElem = iElem.parentNode;
        }
    }

    if ((CSE != LSE) && (!IsChild(CSE, dvHdr)) && (!IsChild(CSE, dvBdy))) {
        if (!CSE.boxItem) {
            iterElem = CSE;
            while ((iterElem.hasbox == 2) && (iterElem.parentNode))
                iterElem = iterElem.parentNode;
            CSE.boxItem = iterElem;
        }
        iterElem = CSE.boxItem;
        if (CSE.boxItem && (CSE.boxItem.hasbox == 1)) {
            LBE = CBE;
            CBE = iterElem;
            if (CBE != LBE) {
                ApplyStyles();
                if (!CBE.requireclick)
                    if (CBE.fade) {
                    if (ID != null)
                        clearTimeout(ID);
                    ID = setTimeout("FadeIn(" + CBE.fadespeed + ")", CBE.delay);
                }
                else {
                    if (ID != null)
                        clearTimeout(ID);
                    COL = 1;
                    ID = setTimeout("oDv.style.visibility='visible';ID=null;", CBE.delay);
                }
                if (CBE.IEbugfix) {
                    HideSelects();
                }
                fixposx = !isNaN(CBE.fixX) ? Left(CBE) + CBE.fixX : CBE.absX;
                fixposy = !isNaN(CBE.fixY) ? Top(CBE) + CBE.fixY : CBE.absY;
                lockX = 0;
                lockY = 0;
                boxMove = true;
                ox = CBE.offX ? CBE.offX : 10;
                oy = CBE.offY ? CBE.offY : 10;
            }
        }
        else
            if (!IsChild(CSE, dvHdr) && !IsChild(CSE, dvBdy) && (boxMove)) {
            // The conditional here fixes flickering between tables cells.
            if ((!IsChild(CBE, CSE)) || (CSE.tagName != 'TABLE')) {
                CBE = null;
                if (ID != null)
                    clearTimeout(ID);
                FadeOut();
                ShowSelects();
            }
        }
        LSE = CSE;
    }
    else
        if (((IsChild(CSE, dvHdr) || IsChild(CSE, dvBdy)) && (boxMove))) {
        totalScrollLeft = 0;
        totalScrollTop = 0;

        iterElem = CSE;
        while (iterElem) {
            if (!isNaN(parseInt(iterElem.scrollTop)))
                totalScrollTop += parseInt(iterElem.scrollTop);
            if (!isNaN(parseInt(iterElem.scrollLeft)))
                totalScrollLeft += parseInt(iterElem.scrollLeft);
            iterElem = iterElem.parentNode;
        }
        if (CBE != null) {
            boxLeft = Left(CBE) - totalScrollLeft;
            boxRight = parseInt(Left(CBE) + CBE.offsetWidth) - totalScrollLeft;
            boxTop = Top(CBE) - totalScrollTop;
            boxBottom = parseInt(Top(CBE) + CBE.offsetHeight) - totalScrollTop;
            DoCheck();
        }
    }

    if (boxMove && CBE) {
        // This added to alleviate bug in IE6 w.r.t DOCTYPE
        bodyScrollTop = document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
        bodyScrollLet = document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
        mouseX = evt.pageX ? evt.pageX - bodyScrollLet : evt.clientX - document.body.clientLeft;
        mouseY = evt.pageY ? evt.pageY - bodyScrollTop : evt.clientY - document.body.clientTop;
        if ((CBE) && (CBE.windowLock)) {
            mouseY < -oy ? lockY = -mouseY - oy : lockY = 0;
            mouseX < -ox ? lockX = -mouseX - ox : lockX = 0;
            mouseY > (SHW()[1] - oDv.offsetHeight - oy) ? lockY = -mouseY + SHW()[1] - oDv.offsetHeight - oy : lockY = lockY;
            mouseX > (SHW()[0] - dvBdy.offsetWidth - ox) ? lockX = -mouseX - ox + SHW()[0] - dvBdy.offsetWidth : lockX = lockX;
        }
        oDv.style.left = ((fixposx) || (fixposx == 0)) ? fixposx : bodyScrollLet + mouseX + ox + lockX + "px";
        oDv.style.top = ((fixposy) || (fixposy == 0)) ? fixposy : bodyScrollTop + mouseY + oy + lockY + "px";

    }
}

function DoCheck() {
    //debugger;
    if ((mouseX < boxLeft) || (mouseX > boxRight) || (mouseY < boxTop) || (mouseY > boxBottom)) {
        if (!CBE.requireclick)
            FadeOut();
        if (CBE.IEbugfix) {
            ShowSelects();
        }
        CBE = null;
    }
}

function PauseBox(e) {
    e ? evt = e : evt = event;
    boxMove = false;
    evt.cancelBubble = true;
}

function ShowHideBox(e) {
    oDv.style.visibility = (oDv.style.visibility != 'visible') ? 'visible' : 'hidden';
}

function HideBox(e) 
{
    oDv.style.visibility = 'hidden';
}

var COL = 0;
var stopfade = false;
function FadeIn(fs) 
{
    ID = null;
    COL = 0;
    oDv.style.visibility = 'visible';
    FadeIn2(fs);
}

function FadeIn2(fs) 
{
    COL = COL + fs;
    COL = (COL > 1) ? 1 : COL;
    oDv.style.filter = 'alpha(opacity=' + parseInt(100 * COL) + ')';
    oDv.style.opacity = COL;
    if (COL < 1)
        setTimeout("FadeIn2(" + fs + ")", 20);
}


function FadeOut() 
{
    oDv.style.visibility = 'hidden';
}

function IsChild(s, d) 
{
    while (s) 
    {
        if (s == d)
            return true;
        s = s.parentNode;
    }
    return false;
}

var cSrc;
function IsMove(e)
 {   
    // Hidden infobox
    // if (infoBox) infoBox.style.display = "none";
    e ? evt = e : evt = event;
    cSrc = evt.target ? evt.target : evt.srcElement;

    if ((!boxMove) && (!IsChild(cSrc, oDv))) 
    {
        FadeOut();
        if (CBE && CBE.IEbugfix) {
            ShowSelects();
        }
        boxMove = true;
        CBE = null;
    }
}

function ShowSelects() {
    //debugger;
    var elements = document.getElementsByTagName("select");
    for (i = 0; i < elements.length; i++)
        elements[i].style.visibility = 'visible';
}

function HideSelects() {
    //debugger;
    var elements = document.getElementsByTagName("select");
    for (i = 0; i < elements.length; i++)
        elements[i].style.visibility = 'hidden';
}
//end Tooltip
function BambooErrors(functionName, errorMessage) {
   
}
//Sort data
function SortData(clientID, sourceId) {
    //debugger;
    try 
    {
        var srcOrg = (document.getElementById(sourceId).src).toString();
        var mySRC = srcOrg.split("/");
        var myImage = mySRC[mySRC.length - 1];
        if (myImage.toLowerCase() == "asc.gif") 
        {
            SortOption(clientID, "asc");
            document.getElementById(sourceId).src = srcOrg.substring(0, srcOrg.length - 7) + 'desc.gif';
        }
        else 
        {
            SortOption(clientID, "desc");
            document.getElementById(sourceId).src = srcOrg.substring(0, srcOrg.length - 8) + 'asc.gif';
        }

    }
    catch (ex) 
    {
        BambooErrors("SortData", ex.message);
    }
}
//-------------------- for object hashTable----
function HashTable() {
    //debugger;
	this.id = 0;
	this.value;
	this.text;
	this.bagValue = new Array();
	this.bagText = new Array();
        this.bagHTML = new Array();
	
	this.push = function(text, val, html)
	{
		this.bagText.push(text);
		this.bagValue.push(val);
                this.bagHTML.push(html);
		this.id++;
	}
	
	this.GetCount = function()
	{
		return this.id;
	}
	
	this.ValueOf = function(index)
	{
		return this.bagValue[index];
	}
	
	this.TextOf = function(index)
	{
		return this.bagText[index];
	}
        
        this.HtmlOf = function(index)
        {
		return this.bagHTML[index];
	}
	
	this.Value = this.bagValue;
	
	this.Text = this.bagText;

	this.HTML= this.bagHTML;
	
	this.Sort = function(option)
	{
		//option == 0 for ASC
		if (option == 0)
		{
			for(var i = 0; i < this.bagText.length - 1; i++)
			{
				for(var j = i + 1; j < this.bagText.length; j++)
				{
				    if (this.bagText[j].toLowerCase() < this.bagText[i].toLowerCase())
					{
						var _tmp = this.bagText[i];
						this.bagText[i] = this.bagText[j];
						this.bagText[j] = _tmp;
						
						_tmp = this.bagValue[i];
						this.bagValue[i] = this.bagValue[j];
						this.bagValue[j] = _tmp; 

						_tmp = this.bagHTML[i];
						this.bagHTML[i] = this.bagHTML[j];
						this.bagHTML[j] = _tmp;
					}
				}
			}	
		}
		else
		{
			for(var i = 0; i < this.bagText.length - 1; i++)
			{
				for(var j = i + 1; j < this.bagText.length; j++)
				{
				    if (this.bagText[j].toLowerCase() > this.bagText[i].toLowerCase())
					{
						var _tmp = this.bagText[i];
						this.bagText[i] = this.bagText[j];
						this.bagText[j] = _tmp;
						
						_tmp = this.bagValue[i];
						this.bagValue[i] = this.bagValue[j];
						this.bagValue[j] = _tmp; 

						_tmp = this.bagHTML[i];
						this.bagHTML[i] = this.bagHTML[j];
						this.bagHTML[j] = _tmp;
					}
				}
			}	
		}
	}
}
//-------------------------------------------------

//-----------------
function SortOption(clientID, condition) {
    //debugger;
    try 
    {


        var myObjects = eval(clientID + "ArrayObjects");
        var myResults = new Array();
        var objDa = eval(clientID + "ArrayData");

        var _tmp = new HashTable();
        
    
        for (var i = 0; i < objDa.length; i++) 
        {

            var text = removeHtmlTag(objDa[i])

            var temp = text.split(";=;");
            
            _tmp.push(temp[0], objDa[i], myObjects[i]);
           
         }

         if (condition == "asc")
            _tmp.Sort(0);
         else
            _tmp.Sort(1);
         
	var html = "";
	for(var i = 0; i < _tmp.GetCount(); i++)
        {
		html += ("<div style='width:100%'>" + _tmp.HtmlOf(i) + "</div>");
	}
        
        document.getElementById(clientID).innerHTML = html;
    }
    catch (ex) {
        BambooErrors("SortOption", ex.message);
    }
}

function SortDataTmp(src)
{
    
}

function removeHtmlTag(src) {
    //debugger;
    var d = document.createElement("DIV");
    d.innerHTML = src;
    
    src = Trim(d.innerText);
    
    return src;
}

function ChangeImages(sourceId, condition, imageName) {
    //debugger;
    try 
    {
        var myImage = document.getElementById(imageName).innerText;
        if (condition == 1) {
            document.getElementById(sourceId).style.backgroundImage = "url(~/wpresources/Bamboo.VirtualMapView/spring.gif)";
        }
        else {
            document.getElementById(sourceId).style.backgroundImage = "url(~/wpresources/Bamboo.VirtualMapView/" + myImage + ")";
        }
    }
    catch (ex) {
        BambooErrors("ChangeImages", ex.message);
    }
}
function VirtualMapViewEditItem(optionID, divID, conID) {
    //debugger;
    try 
    {
        var selectedIndex = document.getElementById(optionID).options.selectedIndex;
        var selectedText = document.getElementById(optionID).options[selectedIndex].text;
        if (selectedText.indexOf("--") != -1) 
        {
            var divTag = document.getElementById(divID);
            document.getElementById(conID).value = selectedText.substring(2, selectedText.length);
            divTag.style.display = "block";
            divTag.style.zIndex = 999;
        }
    }
    catch (ex)
    {
        BambooErrors("VirtualMapViewEditItem", ex.message);
    }
}
function SetDisabledControl(id) {
    //debugger;
    //var flag = document.getElementById(id).disabled;
    var flag = document.getElementById(id).disabled;
    document.getElementById(id).disabled = !flag;
}


