﻿/// <reference path="jquery.intellisense.js"/>

///<summary></summary>
///<param name=""></param>
///<returns></returns>

window.j$ = $telerik.$;


j$.fn.center = function (options) {
    /// <summary>Centers the selected items in the browser window. Takes into account scroll position.
    /// Ideally the selected set should only match a single element.
    /// </summary>    
    /// <param name="fn" type="Function">Optional function called when centering is complete. Passed DOM element as parameter</param>    
    /// <param name="forceAbsolute" type="Boolean">if true forces the element to be removed from the document flow 
    ///  and attached to the body element to ensure proper absolute positioning. 
    /// Be aware that this may cause ID hierachy for CSS styles to be affected.
    /// </param>
    /// <returns type="jQuery" />
    var opt = { forceAbsolute: false,
        container: window,    // selector of element to center in
        completeHandler: null
    };
    j$.extend(opt, options);

    return this.each(function (i) {
        var el = j$(this);
        var jWin = j$(opt.container);
        var isWin = opt.container == window;

        // force to the top of document to ENSURE that 
        // document absolute positioning is available
        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        // have to make absolute
        el.css("position", "absolute");

        // height is off a bit so fudge it
        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        el.css("left", x + jWin.scrollLeft());
        el.css("top", y + jWin.scrollTop());
        el.css("z-index", 100000);

        // if specified make callback and pass element
        if (opt.completeHandler)
            opt.completeHandler(this);
    });


};



j$.fn.fadeRed = function () {
    ///<summary>jQuery plugin that fades the element from red to white</summary>
    ///<returns>Return element itself.</returns>
    _processFadeRed(this.selector, 0);
    return this;
};




var _redFadeSteps = ["d0", "b0", "a0", "90", "98", "a0", "a8", "b0", "b8", "c0", "c8", "d0", "d8", "e0", "e8", "f0", "f8", "ff"];

function _processFadeRed(ele, colorIndex) {

    var o = j$(ele);
    if (colorIndex < _redFadeSteps.length) {
        o.css("backgroundColor", "#ff" + _redFadeSteps[colorIndex] + _redFadeSteps[colorIndex]);
        setTimeout("_processFadeRed('" + ele + "'," + (colorIndex + 1) + ")", 100);
    }
    else {
        o.css("border-color", "Red");
    }
};


function GetRadWindow() {
    ///<summary>Gets the current rad window</summary>
    ///<returns>window object</returns>
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
};


function Close() {
    ///<summary>Closes the current window</summary>
    GetRadWindow().close();
};



function CloseWithArg(original, contextName) {
    ///<summary>Closes the popup window passing user entered data</summary>
    ///<param name="original">object with user entered data as properties</param>
    var obj = CaptureDataObject(original);

    obj["contextName"] = contextName;

    delete original;
    GetRadWindow().close(obj);
};









function StoreManager(t) {
    ///<summary>Store manager stores the values in the user defined store (which should be hidden fields in most cases).
    ///Stored values will be posted back to the server as a JSON string.
    //</summary>
    ///<param name="">Target store, usually should be hidden field but it can be anything that have value property.</param>


    this.store = j$("#" + t);
    this.storeName = t;
    this._getObj = function () {
        ///<summary>Returns always fresh deserialized object from the store</summary>
        ///<returns>deserialized object or empty object if store is empty</returns>
        if (this.store.val().length > 0)
            return Sys.Serialization.JavaScriptSerializer.deserialize(this.store.val());
        else
            return [];
    };

    this.Add = function (key, val) {
        ///<summary>Adds key/value pair to the store</summary>
        ///<param name="key">key for the value</param>
        ///<param name="val">value to be stored</param>
        var obj = this._getObj();
        var update = false;
        j$.each(obj, function (i, v) {
            if (this.id == key) {
                obj[i] = val;
                update = true;
            }
        });
        if (!update)
            obj.push(val);

        this.store.val(Sys.Serialization.JavaScriptSerializer.serialize(obj));
    };

    this.Remove = function (key) {
        ///<summary>Removes the value from the store</summary>
        ///<param name="key">Key for value to remove</param>

        var obj = this._getObj();
        var arr = j$.grep(this._getObj(), function (e, i) { return e.id != key; });
        this.store.val(Sys.Serialization.JavaScriptSerializer.serialize(arr));
    };

    this.Get = function (key) {
        ///<summary>Returns the value from the store</summary>
        ///<param name="key">Key for the value</param>
        ///<returns>value object</returns>d

        var arr = j$.grep(this._getObj(), function (e, i) { return e.id == key; });

        if (arr && arr.length > 0)
            return arr[0];

    };

    this.toString = function () {
        return this.store.val();
    }
};

StoreManager.GetStoreByName = function (target) {
    ///<summary>Gets the store by target name</summary>
    ///<param name="target">Target name</param>
    ///<returns>Instance of new StoreManager</returns>
    return new StoreManager(target);
};

function HandleDataCycle(context) {
    ///<summary>Determines if display of object and object itself should be updated 
    ///  or new entry should be created in the store and display</summary>
    ///<param name="obj">User entered data object</param>
    ///<param name="target">Html target where new entry should be diplayed</param>
    ///<param name="disp">function callback that returns text that should be displayed in the target</param>
    ///<param name="wndName">target window name</param>
    ///<param name="store">Instance of the store manager.</param>

    if (context.isRestore) {
        AddDisplayItem(context);
        return;
    }

    var d = context.storeManager.Get(context.data.id);
    //check if this object exist
    //if yes means that object is in edit mode right now.
    //update new text and data.
    if (d) {
        j$("#" + context.data.id).text(context.formatCallback(context.data));
        context.storeManager.Add(context.data.id, context.data);
        return;
    }
    // create new object and display it
    else {
        context.storeManager.Add(context.data.id, context.data);
        AddDisplayItem(context);
    }
};




function ShowWndByName(wndName) {
    ///<summary>Shows window by name</summary>
    ///<param name="wndName">Name of window as defined in window manager</param>
    ///<returns>returns content object of the new opened window, ready to manipulate.</returns>
    if (typeof (wndName) === "string") {
        var wnd = $find(wndName);
        var url = wnd.GetUrl();
        var originalUrl = new RegExp(/(\S{1,})\?/).exec(url);
        if (originalUrl) {
            wnd.setUrl(originalUrl[1]);
        }
        wnd.show();
        wnd.setUrl(url);

    }

};




function CallEdit(context) {
    ///<summary>Invokes edit function on current window</summary>
    ///<param name="wndName">Name of the window</param>
    ///<param name="data">data object to be passed to edit function</param>

    var wnd = $find(context.windowName);
    wnd.setUrl(context.windowUrl + "?edit=" + context.data.id + "&storeName=" + context.storeManager.storeName);
    wnd.show();

};



function AddDisplayItem(context) {
    ///<summary>Add entry to the target display</summary>
    ///<param name="obj">User entered data object</param>
    ///<param name="target">Html target where new entry should be diplayed</param>
    ///<param name="getDisplay">function callback that returns text that should be displayed in the target</param>
    ///<param name="wndName">target window name</param>
    ///<param name="store">Instance of the store manager.</param>
    ///<returns>returns newly created display item</returns>


    var disp = (context.data.display) ? context.data.display : context.formatCallback(context.data);
    if (disp.length == 0) return;
    context.data.display = disp;

    var unit = j$("<div>").css({ 'clear': 'left', 'padding': '10px 0', 'float': 'left', 'width': '700px' });
    var eLnk = j$("<a>").attr("href", "#").text("Edit").click(function () { CallEdit(context); return false; }).css({ 'padding-left': '5px' }).addClass("c" + context.data.id);
    var dLnk = j$("<a>").attr("href", "#").text("Delete").click(function () { context.storeManager.Remove(context.data.id); unit.fadeOut("slow", function () { j$(".c" + context.data.id).replaceWith(""); }); /*context.target.height(context.target.height() - j$("#" + context.data.id).height());*/return false; }).css({ 'padding-left': '5px', 'float': 'left' }).addClass("c" + context.data.id);

    unit.addClass("c" + context.data.id).css("float", "left").append(j$("<div>").attr("id", context.data.id).text(disp).css("float", "left")).append(dLnk).append(eLnk);
    context.target.append(unit.css({ "width": "100%", "float": "left" }));
    context.target.append(j$("</br>").addClass("c" + context.data.id));
    return unit;
};



function CaptureDataObject(orig) {
    ///<summary>Determines if the user data is in edit or new state.</summary>
    ///<param name="orig">If popup window is in edit state orig will be object with previous entered data.
    /// Otherwise new object will be created and values from inputs will be attached to it. 
    ///</param>

    if (orig)
        var obj = orig;
    else {
        var obj = {};
        obj.id = new Date().getTime().toString();
    }


    j$("*").each(function (i) {
        var regExp = new RegExp(/(___\S*)/);

        if (this.className.match(regExp)) {
            var m = regExp.exec(this.className);
            var prop = m[0].replace("___", "").replace(" ", "");
            var val = j$("#" + this.id).val();
            if (obj[prop] != val) {
                obj[prop] = val;
            }

            var elm = j$("#" + this.id);
            // Get radio buttons if any
            if (elm && elm[0].tagName == 'SPAN') {
                j$("input:[name=" + this.id + "]:checked").each(function () {
                    obj[prop] = this.value;
                });
            }

            // Get combo box if any
            if (elm && elm[0].tagName == 'DIV') {
                var tObj = $find(this.id.toString());
                if (tObj instanceof Telerik.Web.UI.RadComboBox) {
                    obj[prop] = tObj.get_selectedItem().get_value();
                }
            }

            // Get RadDatePickers if any
            if (this.id.endsWith("_wrapper")) {
                var cntlName = this.id.substring(0, this.id.lastIndexOf("_wrapper"));
                var tObj = $find(cntlName);
                if (tObj instanceof Telerik.Web.UI.RadDatePicker) {
                    var sDate = tObj.get_selectedDate(obj[prop]);
                    if (sDate) {
                        obj[prop] = sDate.format("MM/dd/yyyy");
                    }
                }
            }
        }
    });

    return obj;
};



function Bind(obj) {
    ///<summary>Bind object properties to the html elements</summary>
    ///<param name="obj">Object to bind to the html</param>
    Sys.Application.add_load(function () {
        j$("*").each(function (i) {
            var regExp = new RegExp(/(___\S*)/);
            if (this.className.match(regExp)) {
                var m = regExp.exec(this.className);
                var prop = m[0].replace("___", "").replace(" ", "");
                for (p in obj) {
                    if (p == prop) {
                        var elm = j$("#" + this.id);
                        if (elm && elm[0].tagName == 'DIV') {
                            if (this.id.endsWith("_wrapper")) {
                                var cntlName = this.id.substring(0, this.id.lastIndexOf("_wrapper"));
                                var tObj = $find(cntlName);
                            }
                            else {
                                var tObj = $find(this.id.toString());
                            }
                            if (tObj) {
                                try {
                                    if (tObj instanceof Telerik.Web.UI.RadDatePicker) {
                                        if (obj[prop] && obj[prop].length > 0)
                                            tObj.set_selectedDate(new Date(obj[prop]));
                                    }
                                } catch (e) { }


                                if (tObj instanceof Telerik.Web.UI.RadComboBox) {
                                    var item = tObj.findItemByValue(obj[prop]);
                                    item.select();
                                }

                            }
                        }
                        else if (elm && elm[0].tagName == 'SPAN') {
                            j$("input:[name=" + this.id + "]:radio").each(function () {
                                if (this.value == obj[prop]) this.checked = true;
                            });
                        }
                        else {
                            elm.val(obj[prop]);
                        }
                    }
                }
            }
        });
    });
};

function RadComboBoxes() {
    var allRadTextBoxes = [];
    var allRadControls = $telerik.radControls;

    for (var i = 0; i < allRadControls.length; i++) {
        var element = allRadControls[i];
        var isRadTextBox = element instanceof Telerik.Web.UI.RadComboBox;
        if (isRadTextBox) {
            Array.add(allRadTextBoxes, element);
        }
    }
    return allRadTextBoxes;
}



function GetEditObjectById(storeName, objectId) {
    ///<summary>Returns object by its ID and store name</summary>
    ///<param name="objectId">Object id</param>
    ///<returns>Returns object by its ID and store name</returns>
    return StoreManager.GetStoreByName(storeName).Get(objectId);
}


function Restore(arr) {
    ///<summary>Restores values after postback. This is function to restore all that values and javascript after postback</summary>
    ///<param name="obj">Array to restore</param>
    if (arr)
        j$.each(arr, function () { Handle(this, true) });
}

function Handle(obj, isRestore) {
    ///<summary>Hanles data object</summary>
    ///<param name="obj">Object/data to handle</param>
    ///<param name ="isRestore">True if in 'restore' mode, othewise false</param>
    if (obj) {
        var context = GetContext(obj, isRestore);
        HandleDataCycle(context);
    }
}

function onWindowClientClose(sender, eventArgs) {
    ///<summary>Called when window is closed</summary>
    ///<param name="sender">Calling object</param>
    ///<param name="eventArgs">Event arguments</returns>
    var arg = eventArgs.get_argument();
    Handle(arg, false);
}


function GetContext(obj, isRestore) {

    if (obj.contextName === 'BuildingProperty') {
        return {
            "data": obj,
            "target": j$("#" + DivPropertyDisplay),
            "formatCallback": formatPropertyDisplayText,
            "windowName": ___AddPropertyWindow,
            "storeManager": new StoreManager(CntrBuildingProperty),
            "isRestore": isRestore,
            "windowUrl": "Dialogs/AddBuildingPropertyWindow.aspx"
        };
    }
    else if (obj.contextName === "OtherVehicle") {
        return {
            "data": obj,
            "target": j$("#" + DivOtherVehicleDisplay),
            "formatCallback": formatVehicleDisplayText,
            "windowName": ___AddVehicleWindowOther,
            "storeManager": new StoreManager(CntrlOtherVehicles),
            "isRestore": isRestore,
            "windowUrl": "Dialogs/AddOtherVehicleWindow.aspx"
        };
    }
    else if (obj.contextName === "InsuredVehicle") {
        return {
            "data": obj,
            "target": j$("#" + DivInsuredVehicleDisplay),
            "formatCallback": formatVehicleDisplayText,
            "windowName": ___AddVehicleWindow,
            "storeManager": new StoreManager(CntrlInsuredVehicles),
            "isRestore": isRestore,
            "windowUrl": "Dialogs/AddVehicleWindow.aspx"
        };
    }
    else if (obj.contextName === "InjuredParties") {
        return {
            "data": obj,
            "target": j$("#" + DivInjuredPartyDisplay),
            "formatCallback": formatInjuredPartyDisplayText,
            "windowName": ___AddInjuredParty,
            "storeManager": new StoreManager(CntrInjuredParties),
            "isRestore": isRestore,
            "windowUrl": "Dialogs/AddInjuredParty.aspx"
        };
    }
}

/*--------------------------------------------------------------------------------------------------------------------------------------------
Injuries.ascx
---------------------------------------------------------------------------------------------------------------------------------------------*/
function formatInjuredPartyDisplayText(obj) {

    return obj.FirstName + " " + obj.LastName;
};

/*--------------------------------------------------------------------------------------------------------------------------------------------
BuildingProperty.ascx
---------------------------------------------------------------------------------------------------------------------------------------------*/


function formatPropertyDisplayText(prop) {
    var disp = "";
    var del = ", ";

    if (prop.DamageDesc.length > 0) {
        disp += prop.DamageDesc;
    }
    if (prop.PropertyDesc.length > 0) {
        if (disp.length > 0) {
            disp += del + prop.PropertyDesc;
        }
        else {
            disp += prop.PropertyDesc;
        }
    }
    if (prop.Owner.length > 0) {
        if (disp.length > 0) {
            disp += del + prop.Owner;
        }
        else {
            disp += prop.Owner;
        }
    }
    if (prop.City.length > 0) {
        if (disp.length > 0) {
            disp += del + prop.City;
        }
        else {
            disp += prop.City;
        }
    }
    if (prop.State.length > 0 && prop.State != "-1") {
        if (disp.length > 0) {
            disp += del + prop.State;
        }
        else {
            disp += prop.State;
        }
    }
    if (prop.PropertyType.length > 0 && prop.PropertyType != "-1") {
        if (disp.length > 0) {
            disp += del + prop.PropertyType;
        }
        else {
            disp += prop.PropertyType;
        }
    }
    return disp;
}

/*--------------------------------------------------------------------------------------------------------------------------------------------
Vehicles.ascx
--------------------------------------------------------------------------------------------------------------------------------------------*/

function formatVehicleDisplayText(arg) {
    ///<summary>Formats the short vehicle display text</summary>
    ///<param name="arg" type="Object">Vehicle information</param>
    ///<returns>Formated vehicle text</returns>


    var disp = "";
    var del = ", ";

    if (arg.VehicleYear.length > 0) {

        disp += arg.VehicleYear;
    }
    if (arg.VehicleMake.length > 0) {
        if (disp.length > 0) {
            disp += del + arg.VehicleMake;
        }
        else {
            disp += arg.VehicleMake;
        }
    }
    if (arg.VehicleModel.length > 0) {
        if (disp.length > 0) {
            disp += del + arg.VehicleModel;
        }
        else {
            disp += arg.VehicleModel;
        }
    }
    if (arg.Driver.length > 0) {
        if (disp.length > 0) {
            disp += del + arg.Driver;
        }
        else {
            disp += arg.Driver;
        }
    }
    if (arg.City.length > 0) {
        if (disp.length > 0) {
            disp += del + arg.City;
        }
        else {
            disp += arg.City;
        }
    }
    if (arg.State.length > 0 && arg.State != "-1") {
        if (disp.length > 0) {
            disp += del + arg.State;
        }
        else {
            disp += arg.State;
        }
    }

    return disp;
}






/*--------------------------------------------------------------------------------------------------------------------------------------------
Popup windows
--------------------------------------------------------------------------------------------------------------------------------------------*/

var currentObject = null;
function CheckIfEdit() {
    var objid = new RegExp(/edit=([0-9]{1,})/).exec(location.search);
    var store = new RegExp(/storeName=(\S{1,})&/).exec(location.search);
    if (objid && store) {
        var obj = GetRadWindow().BrowserWindow.GetEditObjectById(store[1], objid[1]);
        Bind(obj);
        currentObject = obj;
    }
}

function CloseOnReload() {
    GetRadWindow().close();
}

function Clear() {
    ClearAll();
    currentObject = null;
}

function validateAndClose(obj, contextName) {
    if (isValid(contextName)) {
        CloseWithArg(obj, contextName);
    }
}

function isValid(contextName) {
    var err = [];
    var isValid = true;

    switch (contextName) {
        case "InsuredVehicle":
            {

                if (CmbVehicle) {
                    var vehicle = $find(CmbVehicle);
                }
                var vehYear = j$("#" + TxtVehicleYear);
                var vehMake = j$("#" + TxtVehicleMake);
                var vehModel = j$("#" + TxtVehicleModel);

                if (vehicle) {
                    if (vehicle.get_selectedItem().get_value() == "-1") {
                        err.push({ 'ControlName': CmbVehicle + "_Input", "Label": "Vehicle" });
                    }
                }
                if (vehYear.val().trim().length == 0) {


                    err.push({ 'ControlName': TxtVehicleYear, "Label": "Vehicle Year" });

                }

                var re = new RegExp("^[0-9]{4}$", "");
                var ymatch = vehYear.val().trim().match(re);
                if (!ymatch) { err.push({ 'ControlName': TxtVehicleYear, "Label": "Please enter valid Vehicle Year" }); }


                if (vehMake.val().trim().length == 0) {
                    err.push({ 'ControlName': TxtVehicleMake, "Label": "Vehicle Make" });

                }
                if (vehModel.val().trim().length == 0) {
                    err.push({ 'ControlName': TxtVehicleModel, "Label": "Vehicle Model" });
                }
                break;
            }
        case "InjuredParties":
            {
                var firstName = j$("#" + TxtFirstName);
                var lastName = j$("#" + TxtLastName);

                if (firstName.val().trim().length == 0) {
                    err.push({ 'ControlName': TxtFirstName, 'Label': 'First Name' });
                }
                if (lastName.val().trim().length == 0) {
                    err.push({ 'ControlName': TxtLastName, 'Label': 'Last Name' });
                }
                break;
            }
        case "BuildingProperty":
            {
                var propertyType = $find(CmbPropertyType);
                var objTxtPropertyDesc = j$("#" + TxtPropertyDesc);
                var objTxtPropertySeen = j$("#" + TxtPropertySeen);
                var objTxtPropertyLocation = j$("#" + TxtPropertyLocation);

                var val = propertyType.get_selectedItem().get_value();

                if (val == "0") {
                    err.push({ 'ControlName': CmbPropertyType + "_Input", 'Label': 'Type of Property' });
                }

                if (val == "Dwelling/Contents" || val == "Other Buildings/Structures") {
                    if (objTxtPropertyDesc.val().trim().length == 0)
                        err.push({ 'ControlName': TxtPropertyDesc, 'Label': 'Building/Property Description' });
                    if (objTxtPropertyLocation.val().trim().length == 0)
                        err.push({ 'ControlName': TxtPropertyLocation, 'Label': 'Building Location/Street Address' });
                }
                else if (val == "Farm Machinery/Equipment" || val == "Commercial Machinery/Equipment") {
                    if (objTxtPropertyDesc.val().trim().length == 0)
                        err.push({ 'ControlName': TxtPropertyDesc, 'Label': 'Building/Property Description' });
                    if (objTxtPropertySeen.val().trim().length == 0)
                        err.push({ 'ControlName': TxtPropertySeen, 'Label': 'Where can property can be seen?' });
                }
                else if (val == "Other") {
                    if (objTxtPropertyDesc.val().trim().length == 0)
                        err.push({ 'ControlName': TxtPropertyDesc, 'Label': 'Building/Property Description' });
                }
                break;
            }
    }

    isValid = err.length == 0;

    if (!isValid)
        ShowSummaryErrorMessage(err);

    return isValid;
}



function ShowSummaryErrorMessage(err) {
    var msg = "<b>You must enter a value in the following fields:</b><br/>";
    var alerts = [];
    j$.each(err, function () {
        msg += "<br/>- " + this.Label;
        alerts.push(this.ControlName);
    });
    MarkErrorControls(alerts);
    radalert(msg);

}


function MarkErrorControls(e) {

    j$.each(e, function () {
        var b = j$("#" + this);
        if (b) {
            b.fadeRed();
        }
    });

}


function onBtnSaveForLater() {
    var msg = "<h3>Attention</h3><b>You have selected to save this claim for later.</b><br/>The claim will not be submitted, but the entered information will still be accessible to edit later.<br/><b>Are you sure?</b><br/>";
    var onConfirm = function (r) {
        if (r) {
            window.open("/Pages/MyAccount/MyAccount.aspx", "_self");
        }
    };
    radconfirm(msg, onConfirm);
    return false;
}


function TextInfoControl()
{ };


TextInfoControl.registerFor = function (e, max) {
    var elmnt = document.getElementById(e);
    if (elmnt) {
        elmnt.onkeyup = function () {
            TextInfoControl.count(elmnt, max);
        }
        elmnt.onkeydown = function () {
            TextInfoControl.count(elmnt, max);
        }
        elmnt.onblur = function () {
            TextInfoControl.close();
        }
        elmnt.onfocus = function () {
            TextInfoControl.reset(elmnt, max);
        }
    }
}


TextInfoControl.MSG = " Characters left: ";
TextInfoControl.count = function (elmnt, max) {
    if (elmnt.value.trim().length > max) {
        elmnt.value = elmnt.value.substring(0, max);
    }

    var count = elmnt.value.trim().length;
    var msg = TextInfoControl.MSG + (max - count);
    TextInfoControl._show(elmnt, msg);
};

TextInfoControl.close = function () {
    if (document.getElementById('dZone'))
        document.getElementById('dZone').style.visibility = 'hidden';

};

TextInfoControl.reset = function (elmnt, max) {
    var count = elmnt.value.trim().length;
    var msg = TextInfoControl.MSG + (max - count);
    TextInfoControl._show(elmnt, msg);
};

TextInfoControl._show = function (elmnt, msg) {
    var findPos = function (obj) {
        var curleft = 0;
        var curtop = 0;

        if (obj.offsetParent) {

            curleft = obj.offsetLeft
            curtop = obj.offsetTop
            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
            }
        }

        return [curleft, curtop];
    }

    var dZone = document.getElementById('dZone');
    var pos = findPos(elmnt);

    var newLeft = elmnt.style.width.replace("px", "").trim();
    var lft = parseInt(newLeft);
    var lft1 = parseInt(pos[0]);

    if (!dZone) {

        dZone = document.createElement('div');
        dZone.setAttribute('id', 'dZone');
        dZone.style.position = "absolute";
        dZone.style.zIndex = "1000";
        dZone.style.left = "0px";
        dZone.style.top = "0px";
        dZone.style.width = "100%";
        dZone.style.height = "100%";
        document.body.appendChild(dZone);
        var msgZone = document.createElement('div');
        var img = document.createElement("img")

        img.setAttribute("src", "/Pages/Onlineclaims/Resources/Information.gif");

        msgZone.appendChild(img);
        msgZone.setAttribute('id', 'msgZone');
        // msgZone.className = "TooltipOC";
        msgZone.style.position = "absolute";
        msgZone.style.top = pos[1] + "px";
        msgZone.style.left = pos[0] + "px";
        msgZone.style.background = "#DDE4EC";
        msgZone.style.color = "#134B7B";
        msgZone.style.fontWeight = "bold";
        msgZone.style.fontSize = "xx-small";
        msgZone.style.padding = "4px";
        msgZone.style.paddingLeft = "5px";
        msgZone.style.maxWidth = "100px";
        msgZone.style.left = lft + lft1 + 3 + "px";
        var txt = document.createTextNode(msg);
        msgZone.appendChild(img);
        msgZone.appendChild(txt);
        dZone.appendChild(msgZone);
    }

    else {
        document.getElementById('msgZone').childNodes[1].nodeValue = msg;
        document.getElementById('msgZone').style.top = pos[1] + "px";
        document.getElementById('msgZone').style.left = lft + lft1 + 3 + "px";
        dZone.style.visibility = 'visible';
    }


};


function onTypeOfPropertyChanged(sender, eventArgs) {
    ///<summary>Callback method for CmbTypeOfProperty in new Building/Property window (on selected item changed event)</summary>
    ///<param name="sender">Instance of the RadComboBox</param>
    ///<param name="eventArgs">event argument</param>

    var item = eventArgs.get_item();
    var val = item.get_value();

    var pdm = j$("#LblPropertyDesc_Mandatory");
    var plm = j$("#LblPropertyLocation_Mandatory");
    var psm = j$("#LblPropertySeen_Mandatory");
    var a = j$("#LblPropertyOwner_Mandatory");
    pdm.hide();
    plm.hide();
    psm.hide();
    a.hide();

    if (val == "Dwelling/Contents" || val == "Other Buildings/Structures") {
        pdm.show();
        plm.show();
        a.show();
    }
    else if (val == "Farm Machinery/Equipment" || val == "Commercial Machinery/Equipment") {
        pdm.show();
        psm.show();
    }
    else if (val == "Other") {
        pdm.show();
    }
}

var isTabClicked = "false";



function OnClientTabSelecting(sender, args) {

    if (isTabClicked == "false") {
        //cancel the action 
        args.set_cancel(true);
        //get the tab which is clicked 
        var tab = args.get_tab();

        function CallBackFn(arg) {

            if (arg) {
                var btn = j$("input[id=BtnSave_" + tab.get_tabStrip().get_selectedTab().get_value() + "]");
                if (btn) {
                    btn.trigger("click");
                }
            }
            else {
                tab.click();
                isTabClicked = "true";
            }
        }

        //ask the user for confirmation                
        radconfirm("Save changes?<br/><br/>", CallBackFn);
    }
}


function OnClientTabSelected() {
    //reset the isTabClicked variable 
    isTabClicked = "false";
} 
 
