﻿function AgentLogin() {
    try {
        window.location.hash = 'Top';
        document.getElementById('divGray').style.visibility = 'visible';
        document.getElementById('divAgentLogin').style.visibility = 'visible';
        document.getElementById('ddlPropertyType').style.visibility = 'hidden';
        document.getElementById('ddlBeds').style.visibility = 'hidden';
        document.getElementById('ddlBaths').style.visibility = 'hidden';
        document.getElementById('ddlRadius').style.visibility = 'hidden';
    } catch (e) { }
    try {
        document.getElementById('ddlStates').style.visibility = 'hidden';
        document.getElementById('ddRadius').style.visibility = 'hidden';
    } catch (e) { }
    try { document.getElementById('tbMode').value = '1'; } catch (e) { }
}

var IEBrowserVer = {
    Version: function() {
        var version = 999;
        // we assume a sane browser    
        if (navigator.appVersion.indexOf("MSIE") != -1)
        // bah, IE again, lets downgrade version number
            version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        return version;
    }
}

function HideLogin() {
    try {
        window.location.hash = 'Top';
        document.getElementById('divAgentLogin').style.visibility = 'hidden';
        document.getElementById('divGray').style.visibility = 'hidden';
        document.getElementById('ddlPropertyType').style.visibility = 'visible';
        document.getElementById('ddlBeds').style.visibility = 'visible';
        document.getElementById('ddlBaths').style.visibility = 'visible';
        document.getElementById('ddlRadius').style.visibility = 'visible';
    } catch (e) { }
    try {
        document.getElementById('ddlStates').style.visibility = 'visible';
        document.getElementById('ddRadius').style.visibility = 'visible';
    } catch (e) { }
    try { document.getElementById('tbMode').value = '0'; } catch (e) { }
}

function LoadedPropertySearch() {
    document.form1.action = '/PropertySearch.aspx';
    try {
        document.getElementById('SearchOptions').style.visibility = 'visible';
    } catch (e) { }

    try {
        document.getElementById('ddlPage').style.visibility = 'visible';
        document.getElementById('ddlPage2').style.visibility = 'visible';
    } catch (e) { }


    try {
        var obj2 = document.getElementById('tbStreetAddress');
        setsearchlabel(obj2, 'e.g. \'123 Main Ave\' or \'555 S State St\'')
    } catch (e) { }

    setupmenu();
}

function setupmenu() {
    if (IEBrowserVer.Version() == 6) {
        if (document.all && document.getElementById) {
            navRoot = document.getElementById("nav");
            for (i = 0; i < navRoot.childNodes.length; i++) {
                node = navRoot.childNodes[i];
                if (node.nodeName == "LI") {
                    node.onmouseover = function() {
                        this.childNodes[1].style.display = "block";
                        this.childNodes[2].style.display = "block";
                        this.childNodes[0].style.backgroundImage = "url('/images/Menuitems/" + this.childNodes[0].className.replace("div", "") + ".gif')";

                    }
                    node.onmouseout = function() {
                        this.childNodes[1].style.display = "";
                        this.childNodes[0].style.backgroundImage = "";
                        this.childNodes[2].style.display = "";

                    }
                }
            }
        }
    }
}
function getdd(value) {
    var i;
    var id;
    var key;
    var split;

    if (value == "") {

        document.getElementById('lblKey1').innerHTML = "";
        document.getElementById('lblKey2').innerHTML = "";
        document.getElementById('lblKey3').innerHTML = "";
        document.getElementById('tbKey1').style.display = 'none';
        document.getElementById('tbKey1').value = '';
        document.getElementById('tbKey2').style.display = 'none';
        document.getElementById('tbKey2').value = '';
        document.getElementById('tbKey3').style.display = 'none';
        document.getElementById('tbKey3').value = '';

    } else {
        var h = new String(document.location.href);

        if ((value >= 31 && value <= 38) && h.indexOf("listEditItem.aspx") != -1) {
            document.location = NewProperty
        }

        if ((value >= 31 && value <= 38) && h.indexOf(".aspx") == -1) {
            //divSearchProperty
            document.getElementById("divSearchProperty").style.display = "";
            document.getElementById("divSearchItems").style.display = "none";
        } else if ((value < 31 || value > 38) && h.indexOf(".aspx") == -1) {
            //divSearchItem
            document.getElementById("divSearchProperty").style.display = "none";
            document.getElementById("divSearchItems").style.display = "";
        }

        for (i = 1; i < document.getElementById('gvKey').rows.length; i++) {
            key = document.getElementById('gvKey').rows[i].cells[1].childNodes[0].data;
            id = document.getElementById('gvKey').rows[i].cells[0].childNodes[0].data;
            if (id == value) {
                split = key.split("|");
                document.getElementById('lblKey1').innerHTML = split[0];
                document.getElementById('lblKey2').innerHTML = split[1];
                document.getElementById('lblKey3').innerHTML = split[2];
                if (split[0].length == 0) {
                    document.getElementById('tbKey1').style.display = 'none';
                    document.getElementById('tbKey1').value = '';
                } else {
                    document.getElementById('tbKey1').style.display = '';
                }
                if (split[1].length == 0) {
                    document.getElementById('tbKey2').style.display = 'none';
                    document.getElementById('tbKey2').value = '';
                } else {
                    document.getElementById('tbKey2').style.display = '';
                }
                if (split[2].length == 0) {
                    document.getElementById('tbKey3').style.display = 'none';
                    document.getElementById('tbKey3').value = '';
                } else {
                    document.getElementById('tbKey3').style.display = '';
                }
            }
        }
    }
}
function ismaxlength(obj) {
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length > mlength)
        obj.value = obj.value.substring(0, mlength)
}

function cleartextbox(o, v) {
    if (o.value == v) {
        o.value = '';
        o.style.color = "#000000";
    }
}

function setsearchlabel(o, v) {
    if (o.value == '') {
        o.value = v;
        o.style.color = "#a0a0a0";
    } else {
        o.style.color = "#000000";
    }
}


function removeHTMLTags(t) {

    var strInputCode = t.innerHTML;

    strInputCode = strInputCode.replace(/&(lt|gt);/g, function(strMatch, p1) {
        return (p1 == "lt") ? "<" : ">";
    });
    var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
    t.innerHTML = strTagStrippedText;

}

function detectEvent(o, e) {
    var evt = e || window.event;
    alert('keyCode is ' + evt.keyCode + ' ' + o);

}

function CatchEnterPress(e) {
    var evt = e || window.event;
    var Sender = evt.srcElement || evt.target;
    var btnToBeClicked = null;
    if (evt.keyCode == '13') {
        var ButtonName = Sender.getAttribute("TargetButton");
        if (ButtonName == null) return;
        RemoveEnterEscEvents(evt);
        btnToBeClicked = document.getElementById(ButtonName);
        if (btnToBeClicked) {
            btnToBeClicked.click();
        }
    }
}

function RemoveEnterEscEvents(evt) {
    //if (event.keyCode == 13 || event.keyCode == 27)
    if (evt.keyCode == 13) {
        evt.cancelBubble = true; evt.returnValue = false;
    }
}


//Array.prototype.remove = function(from, to) {
//   var rest = this.slice((to || from) + 1 || this.length);
//   this.length = from < 0 ? this.length + from : from;
//   return this.push.apply(this, rest);
//   };



//use this to create custom drop select
function DropSelect(TextBox, ValueBox, SelectList, SelectListContainer, ColumnCount, callback) {
    this.Update = 0;
    this.LastSearch = "";
    this.MaxWidth = 0;
    this.ColumnCount = ColumnCount;
    this.sTextBox = TextBox;
    this.sValueBox = ValueBox;
    this.sSelectList = SelectList;
    this.sSelectListFull = new Array();
    this.callback = callback;
    this.SelectListContainer = SelectListContainer;
    this.SelectedItem = -1;

    this.UpdateFilter = function(e) {
        // get the display list box
        var tbl = document.getElementById(this.sSelectList);

        //Get textbox
        var tb = document.getElementById(this.sTextBox);
        var tbi = document.getElementById(this.sValueBox);

        //get the key pressed
        var evt = e || window.event;

        //prevent calling routeen from a non event from mucking up the code
        if (!evt) {
            evt = -1;
            evt.keyCode = -1;
        }

        //check if up or down arrow was pressed
        var lbo;
        if (evt.keyCode == 13) {
            return;
        } else if (evt.keyCode == 40) {               //if key code 40 (down arrow)
            lbo = this.SelectItem(tbl, 1);
            tb.value = lbo.text;
            tbi.value = lbo.value;
        } else if (evt.keyCode == 38) {             //if key code 438 (up arrow)
            lbo = this.SelectItem(tbl, -1);
            tb.value = lbo.text;
            tbi.value = lbo.value;
        } else {                                  //else process search

            //store textbox value in a string object
            var tt = new String(tb.value);

            // clear table rows
            this.ClearTableRows();

            //if the textbox has a value
            if (tt.length == 3 || (tt.length >= 3 && tt.substring(0, 2) != this.LastSearch)) {
                this.LastSearch = tt.substring(0, 2)
                if (callback && this.Update == 0) {
                    this.Update = 1;
                    callback(tt.substring(0, 2));
                }
            } else if (tt.lenght == 0) {
                this.Update = 0;
            }
            //populate the drop list
            if (this.Update == 0) this.FillListBox();

        }
    }

    this.FillListBox = function() {

        // get the display list box
        var tbl = document.getElementById(this.sSelectList);

        //div holding table
        var div = document.getElementById(this.SelectListContainer);

        //Get textbox
        var tb = document.getElementById(this.sTextBox);

        //store textbox value in a string object
        var tt = new String(tb.value);

        if (tt.length >= 3) {
            //display listbox
            tbl.style.display = "block";
            div.style.display = "block";

            //loop through each item and add to listbox if it contains the search string
            for (var i = 0; i <= this.sSelectListFull.length - 1; i++) {
                var lt = new String(this.sSelectListFull[i][1]);
                if (lt.toLowerCase().indexOf(tt.toLowerCase(), 0) > -1) {
                    this.AddTableRow(tbl, this.sSelectListFull[i]);
                }
            }

            this.SelectedItem = -1;

            //calculate listbox height with min and max constraints
            var ih = tbl.rows.length * 15;
            if (ih > 342)
                ih = 342;
            if (ih < 75)
                ih = 75;
            div.style.height = ih + "px";
        } else {            //if the textbox is empty then hide the listbox
            tbl.style.display = "none";
            div.style.display = "none";
        }
    }


    this.SelectItem = function(tbl, i) {
        //calculate next index
        if (this.SelectedItem == -1)
            i++;

        var newindex = this.SelectedItem + i;

        //if index is before first set to last
        //if index as after last set to first
        if (newindex < 1)
            newindex = tbl.rows.length - 1;
        else if (newindex >= tbl.rows.length)
            newindex = 1;

        //loop throught items and set index
        for (var i = 0; i <= tbl.rows.length - 1; i++) {
            if (i == newindex)
                tbl.rows[i].className = "highlightrow";
            else
                tbl.rows[i].className = "normalrow";
        }
        //set new index
        this.SelectedItem = newindex;

        //keep selected item on screen
        if (tbl.rows.length > 23) {
            var div = document.getElementById(this.SelectListContainer)
            if (this.SelectedItem > 23) {
                div.scrollTop = ((this.SelectedItem - 23) * 15);
            } else if (this.SelectedItem < 23 && div.scrollTop != 0) {
                div.scrollTop = 0;
            }
        }

        //return selected row for vales
        return tbl.rows[newindex];
    }

    //
    this.AddFullArrayItem = function(valuesarray) {
        var l = this.sSelectListFull.length;
        this.sSelectListFull[l] = valuesarray;
        if (this.sSelectListFull[l][1].length > this.MaxWidth)
            this.MaxWidth = this.sSelectListFull[l][1].length;
    }

    this.ClearFullArrayItems = function() {
        //this.sSelectListFull.remove(0, -1);
        this.sSelectListFull = new Array()
    }

    this.AddTableRow = function(tbl, av) {

        //get the number of rows
        var lastRow = tbl.rows.length;

        //create a new row
        var row = tbl.insertRow(lastRow);

        //insert a cell
        var cellFirst = row.insertCell(0);
        //create a text node
        var el = document.createTextNode(av[1]);
        //add node to cell
        cellFirst.appendChild(el);

        //insert another cell
        var cellSecond = row.insertCell(1);
        //create another node
        var el1 = document.createTextNode(av[2])
        cellSecond.appendChild(el1);

        //create a function pointer with correct parameters for row click event in IE
        onclickevt = function() { ds.SelectTableItem(av[0], av[1]); }
        //if IE then do it this way else do the the other way
        if (row.attachEvent) {
            row.attachEvent("onclick", onclickevt);
        } else {
            row.setAttribute("onclick", "ds.SelectTableItem('" + av[0] + "','" + av[1] + "');");
        }

        //set default row calls
        row.className = "normalrow";
        //set custom  attributes for later use
        row.text = av[1];
        row.value = av[0];

    }

    //removes all rows from table
    this.ClearTableRows = function() {
        var tbl = document.getElementById(this.sSelectList);
        while (tbl.rows.length > 1)
            tbl.deleteRow(tbl.rows.length - 1);
    }

    //populates text and value into textboxes for server round trip.
    this.SelectTableItem = function(value, text) {
        var tbl = document.getElementById(this.sSelectList);
        var div = document.getElementById(this.SelectListContainer);
        var tb = document.getElementById(this.sTextBox);
        var tbi = document.getElementById(this.sValueBox);
        tb.value = text;
        tbi.value = value;
        tb.focus();
        tbl.style.display = "none";
        div.style.display = "none";
    }

}







//use this to create custom drop select
function DropSelect2(TextBox, ValueBox, SelectList, SelectListContainer, ColumnCount, callback, sCompanyID, TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, ValueBox2) {
    this.LastSearch = "";
    this.MaxWidth = 0;
    this.ColumnCount = ColumnCount;
    this.sTextBox = TextBox;
    this.sValueBox = ValueBox;
    this.sSelectList = SelectList;
    this.sSelectListFull = new Array();
    this.callback = callback;
    this.SelectListContainer = SelectListContainer;
    this.SelectedItem = -1;
    this.sCompanyID = sCompanyID;
    this.sTextBox1 = TextBox1;
    this.sTextBox2 = TextBox2;
    this.sTextBox3 = TextBox3;
    this.sTextBox4 = TextBox4;
    this.sTextBox5 = TextBox5;
    this.sValueBox2 = ValueBox2;
    this.Update = 0;

    this.UpdateFilter2 = function(e) {

        // get the display list box
        var tbl = document.getElementById(this.sSelectList);

        //Get textbox
        var tb = document.getElementById(this.sTextBox);
        var tbi = document.getElementById(this.sValueBox);
        var tbi2 = document.getElementById(this.sValueBox2);
        var tbci = document.getElementById(this.sCompanyID);
        var div = document.getElementById(this.SelectListContainer);
        var tb1 = document.getElementById(this.sTextBox1);
        var tb2 = document.getElementById(this.sTextBox2);
        var tb3 = document.getElementById(this.sTextBox3);
        var tb4 = document.getElementById(this.sTextBox4);
        var tb5 = document.getElementById(this.sTextBox5);

        //get the key pressed
        var evt = e || window.event;

        //prevent calling routine from a non event from mucking up the code
        if (!evt) {
            evt = -1;
            evt.keyCode = -1;
        }

        //check if up or down arrow was pressed
        var lbo;
        if (evt.keyCode == 13) {
            return;
        } else if (evt.keyCode == 40) {               //if key code 40 (down arrow)
            lbo = this.SelectItem2(tbl, 1);
            tb.value = lbo.text;
            tbi.value = lbo.value;
            tbi2.value = lbo.value;
            tb1.value = lbo.tx1;
            tb2.value = lbo.tx2;
            tb3.value = cleanPhone(lbo.tx3);
            tb4.value = cleanPhone(lbo.tx4);
            tb5.value = cleanPhone(lbo.tx5);
        } else if (evt.keyCode == 38) {             //if key code 438 (up arrow)
            lbo = this.SelectItem2(tbl, -1);
            tb.value = lbo.text;
            tbi.value = lbo.value;
            tbi2.value = lbo.value;
            tb1.value = lbo.tx1;
            tb2.value = lbo.tx2;
            tb3.value = cleanPhone(lbo.tx3);
            tb4.value = cleanPhone(lbo.tx4);
            tb5.value = cleanPhone(lbo.tx5);
        } else {                                  //else process search

            //store textbox value in a string object
            var tt = new String(tb.value);

            // clear table rows
            this.ClearTableRows();

            //if the textbox has a value
            if (tt.length == 3 || (tt.length >= 3 && tt.substring(0, 2) != this.LastSearch)) {
                this.LastSearch = tt.substring(0, 2)
                if (callback && this.Update == 0) {
                    this.Update = 1;
                    callback(tt.substring(0, 2), tbci.value);
                }
            } else if (tt.lenght == 0) {
                this.Update = 0;
            }

            //populate the drop list
            if (this.Update == 0) this.FillListBox2();
        }

    }

    this.tabOff2 = function(e) {
        //get the key pressed
        var evt = e || window.event;
        // get the display list box
        var tbl = document.getElementById(this.sSelectList);

        //div holding table
        var div = document.getElementById(this.SelectListContainer);
        if (evt.keyCode == 9) {
            tbl.style.display = "none";
            div.style.display = "none";
        } 
    }

    this.stopEnter = function(e) {
        var evt = e || window.event;
        if (evt.keyCode == 13) {
            // get the display list box
            var tbl = document.getElementById(this.sSelectList);

            //div holding table
            var div = document.getElementById(this.SelectListContainer);
            tbl.style.display = "none";
            div.style.display = "none";
            evt.cancelBubble = true; evt.returnValue = false; return false;
        } else {
            return true;
        }
    }

    this.FillListBox2 = function() {

        // get the display list box
        var tbl = document.getElementById(this.sSelectList);

        //div holding table
        var div = document.getElementById(this.SelectListContainer);

        //Get textbox
        var tb = document.getElementById(this.sTextBox);

        //store textbox value in a string object
        var tt = new String(tb.value);

        if (tt.length >= 3) {
            //display listbox
            tbl.style.display = "block";
            div.style.display = "block";

            //loop through each item and add to listbox if it contains the search string
            for (var i = 0; i <= this.sSelectListFull.length - 1; i++) {
                var lt = new String(this.sSelectListFull[i][1]);
                if (lt.toLowerCase().indexOf(tt.toLowerCase(), 0) > -1) {
                    this.AddTableRow2(tbl, this.sSelectListFull[i]);
                }
            }

            this.SelectedItem = -1;

            //calculate listbox height with min and max constraints
            var ih = tbl.rows.length * 15;
            if (ih > 240)
                ih = 240;
            if (ih < 75)
                ih = 75;
            div.style.height = ih + "px";
        } else {            //if the textbox is empty then hide the listbox
            tbl.style.display = "none";
            div.style.display = "none";
        }
        this.Update = 0;
    }


    this.SelectItem2 = function(tbl, i) {
        //calculate next index
        if (this.SelectedItem == -1)
            i++;

        var newindex = this.SelectedItem + i;

        //if index is before first set to last
        //if index as after last set to first
        if (newindex < 1)
            newindex = tbl.rows.length - 1;
        else if (newindex >= tbl.rows.length)
            newindex = 1;

        //loop throught items and set index
        for (var i = 0; i <= tbl.rows.length - 1; i++) {
            if (i == newindex)
                tbl.rows[i].className = "highlightrow";
            else
                tbl.rows[i].className = "normalrow";
        }
        //set new index
        this.SelectedItem = newindex;

        //keep selected item on screen
        if (tbl.rows.length > 12) {
            var div = document.getElementById(this.SelectListContainer)
            if (this.SelectedItem > 12) {
                div.scrollTop = ((this.SelectedItem - 12) * 15);
            } else if (this.SelectedItem < 12 && div.scrollTop != 0) {
                div.scrollTop = 0;
            }
        }

        //return selected row for vales
        return tbl.rows[newindex];
    }

    //removes all rows from table
    this.ClearTableRows = function() {
        var tbl = document.getElementById(this.sSelectList);
        while (tbl.rows.length > 1)
            tbl.deleteRow(tbl.rows.length - 1);
    }

    //
    this.AddFullArrayItem = function(valuesarray) {
        var l = this.sSelectListFull.length;
        this.sSelectListFull[l] = valuesarray;
        if (this.sSelectListFull[l][1].length > this.MaxWidth)
            this.MaxWidth = this.sSelectListFull[l][1].length;
    }

    this.ClearFullArrayItems = function() {
        //this.sSelectListFull.remove(0, -1);
        this.sSelectListFull = new Array()
    }

    this.AddTableRow2 = function(tbl, av) {

        //get the number of rows
        var lastRow = tbl.rows.length;

        //create a new row
        var row = tbl.insertRow(lastRow);

        //insert a cell
        var cellFirst = row.insertCell(0);
        //create a text node
        var el = document.createTextNode(Left(av[1],20));
        //add node to cell
        cellFirst.appendChild(el);

        //insert another cell
        var cellSecond = row.insertCell(1);
        //create another node
        var el1 = document.createTextNode(Left(av[2],25));
        cellSecond.appendChild(el1);

        //insert another cell
        var cellThird = row.insertCell(2);
        //create another node
        var el2 = document.createTextNode(Left(av[3],25));
        cellThird.appendChild(el2);

        //create a function pointer with correct parameters for row click event in IE
        onclickevt = function() { ds.SelectTableItem2(av[0], av[1], av[2], av[3], av[4], av[5], av[6]); }
        //if IE then do it this way else do the the other way
        if (row.attachEvent) {
            row.attachEvent("onclick", onclickevt);
        } else {
            row.setAttribute("onclick", "ds.SelectTableItem2('" + av[0] + "','" + av[1] + "','" + av[2] + "','" + av[3] + "','" + av[4] + "','" + av[5] + "','" + av[6] + "');");
        }

        //set default row calls
        row.className = "normalrow";
        //set custom  attributes for later use
        row.text = av[1];
        row.value = av[0];
        row.tx1 = av[2];
        row.tx2 = av[3];
        row.tx3 = av[4];
        row.tx4 = av[5];
        row.tx5 = av[6];

    }


    //populates text and value into textboxes for server round trip.
    this.SelectTableItem2 = function(value, text, text1, text2, text3, text4, text5) {
        var tbl = document.getElementById(this.sSelectList);
        var div = document.getElementById(this.SelectListContainer);
        var tb = document.getElementById(this.sTextBox);
        var tbi = document.getElementById(this.sValueBox);
        var tbi2 = document.getElementById(this.sValueBox2);
        var tb1 = document.getElementById(this.sTextBox1);
        var tb2 = document.getElementById(this.sTextBox2);
        var tb3 = document.getElementById(this.sTextBox3);
        var tb4 = document.getElementById(this.sTextBox4);
        var tb5 = document.getElementById(this.sTextBox5);

        tb.value = text;
        tbi.value = value;
        tbi2.value = value;
        tb1.value = text1;
        tb2.value = text2;
        tb3.value = cleanPhone(text3);
        tb4.value = cleanPhone(text4);
        tb5.value = cleanPhone(text5);


        tb.focus();
        tbl.style.display = "none";
        div.style.display = "none";
    }

}


function cleanPhone(sPhone) {
    var pn = new String;
    newpn = '';

    pn = cleandigits(sPhone)

    if (pn.length > 0) {
        for (x = 0; x <= 9; x++) {
            if (x == 0)
                newpn = '(' + pn.substr(x, 1);
            if ((x >= 1 && x <= 2) || (x >= 4 && x <= 5) || (x >= 7 && x <= 9))
                newpn += pn.substr(x, 1);
            if (x == 3)
                newpn += ') ' + pn.substr(x, 1);
            if (x == 6)
                newpn += '-' + pn.substr(x, 1);
        }
    } else
        newpn = "(   )   -";
    return newpn;
}

function cleandigits(s) {
    var p_new = '';
    var p = new String;
    p = s;
    for (x = 0; x <= p.length - 1; x++) {
        if (IsNumeric(p.substr(x, 1)))
            p_new += p.substr(x, 1);
    }
    p = p_new;
    if (p.length > 10)
        p_new = p.substr(0, 10);
    return p_new;
}

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;

}

function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n) + '...';
}

