


    function BuildBoatRowHTML(boat, alt,stringBuffer)
    {
        var str = '';
        var style = '';
        

        if(boat.IsNewBrokerageBoat)
        {
            style="style='background-color:#ffffff;'";
        }
        
        if (alt)
        {
            stringBuffer.append("<tr class=\"alt\" >");
        }
        else
        {
            stringBuffer.append("<tr>");
        }
        
        stringBuffer.append("<td class=\"col1\" "+style+" >");
        stringBuffer.append("<input id=\"CheckBoxBoat" + boat.Id + "\" type=\"checkbox\" value=\"" + boat.Id + "\" />");
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col2\" "+style+" >");
        stringBuffer.append("<a onclick=\"window.open('/boats/Details.aspx?BoatId=" + boat.Id + "','EditBoat" + boat.Id + "','height=710,width=1015,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes')\" style=\"cursor:hand;\">");
        stringBuffer.append( boat.Id);
        stringBuffer.append("</a></td>");
        stringBuffer.append("<td class=\"col3\" "+style+" title=\"" + boat.Name + "\">");
        stringBuffer.append("<a onclick=\"window.open('/boats/Details.aspx?BoatId=" + boat.Id + "','EditBoat" + boat.Id + "','height=710,width=1015,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes')\" style=\"cursor:hand;\">");        
        stringBuffer.append(boat.Name);
        stringBuffer.append("</a></td>");
        stringBuffer.append("<td class=\"col4\" "+style+" title=\"" + boat.MakeModel + "\">");
        stringBuffer.append( boat.MakeModel);
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col5\" "+style+" title=\"" + formatNumber(boat.YearBuilt) + "\">");
        stringBuffer.append(formatNumber(boat.YearBuilt) + "&nbsp;");
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col6\" "+style+" title=\"" + boat.CurrencyDescription + " " + boat.Price + "\">");
        stringBuffer.append(boat.CurrencyCode + " " + boat.Price);
        stringBuffer.append("</td>");  
        stringBuffer.append("<td class=\"col7\" "+style+" title=\"" + boat.TaxComment + "\">");
        stringBuffer.append(boat.TaxComment + "&nbsp;");
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col8\" "+style+" title=\"" + boat.Located + "\">");
        stringBuffer.append(boat.Located + "&nbsp;");
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col9\" "+style+" title=\"" + boat.BoatStatusCode + "\">");
        stringBuffer.append(boat.BoatStatusCode + "&nbsp;");
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col10\" "+style+" title=\"" + boat.OfficeCode + "\">");
        stringBuffer.append(boat.OfficeCode + "&nbsp;");
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col11\" "+style+" title=\"" + formatNumber(boat.LengthFeet) + "\">");
        stringBuffer.append(formatNumber(boat.LengthFeet) + "&nbsp;");
        stringBuffer.append("</td>");
        stringBuffer.append("<tr><td colspan='12' style=\"display:none\" class=\"search_detail\" id=\"Detail" + boat.Id + "\"></td>");
        stringBuffer.append("</tr>");

        //return str;
    }
    
    function BuildMatchToBoatsRowHTML(boat, alt)
    {
        var str = '';
        
        if(boat.IsNewBrokerageBoat)
        {
            str="<tr style=\"background-color:#ffffff;\">"
        }
        else if (alt)
        {
            str = "<tr class=\"alt\" >";
        }
        else
        {
            str = "<tr>";
        }
        
        str += "<td class=\"col1\">";
        str += "<input id=\"CheckBoxBoat" + boat.Id + "\" type=\"checkbox\" value=\"" + boat.Id + "\" />";
        str += "</td>";
        str += "<td class=\"col2\" title=\"Spec Sent\">";
        str += "<div id='DivSpecSent" + boat.Id + "'>&nbsp;</div>";
        str += "<td class=\"col3\">";
        str += "<a onclick=\"window.open('/boats/Details.aspx?BoatId=" + boat.Id + "','EditBoat" + boat.Id + "','height=710,width=1015,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes')\" style=\"cursor:hand;\">";
        str += boat.Id;
        str += "</a></td>";
        str += "<td class=\"col4\" title=\"" + boat.OfficeCode + "\">";
        str += boat.OfficeCode + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col5\" title=\"" + boat.Name  + "\">";
        str += "<a onclick=\"window.open('/boats/Details.aspx?BoatId=" + boat.Id + "','EditBoat" + boat.Id + "','height=710,width=1015,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes')\" style=\"cursor:hand;\">";        str += boat.Name;
        str += "</a></td>";
        str += "<td class=\"col6\" title=\"" + boat.MakeModel + "\">";
        str += boat.MakeModel + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col7\" title=\"" + boat.BoatStatusCode + "\">";
        str += boat.BoatStatusCode + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col8\" title=\"" + formatNumber(boat.YearBuilt) + "\">";
        str += formatNumber(boat.YearBuilt) + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col9\" title=\"" + boat.CurrencyDescription + " " + boat.Price + "\">";
        str += boat.CurrencyCode + " " + boat.Price;
        str += "</td>";  
        str += "<td class=\"col10\" title=\"" + boat.TaxComment + "\">";
        str += boat.TaxComment + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col11\" title=\"" + boat.DriveCode + "\">";
        str += boat.DriveCode + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col12\" title=\"" + boat.RigCode + "\">";
        str += boat.RigCode + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col13\" title=\"" + boat.LayoutCode + "\">";
        str += boat.LayoutCode + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col14\" title=\"" + boat.KeelCode + "\">";
        str += boat.KeelCode + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col15\" title=\"" + boat.ClassCode + "\">";
        str += boat.ClassCode + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col16\" title=\"" + boat.EngineCode + "\">";
        str += boat.EngineCode + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col17\" title=\"" + boat.HullCode + "\">";
        str += boat.HullCode + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col18\" title=\"" + formatNumber(boat.LengthFeet) + "\">";
        str += formatNumber(boat.LengthFeet) + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col19\" title=\"" + formatNumber(boat.LengthMetre) + "\">";
        str += formatNumber(boat.LengthMetre) + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col20\" title=\"" + boat.Located + "\">";
        str += boat.Located + "&nbsp;";
        str += "</td></tr>";        

        return str;
    }

    function BuildClientRowHTML(client, alt)
    {
        var str = '';
        
        if (alt)
        {
            str = "<tr id=\"listItem" + client.Id + "\" class=\"alt\" >";
        }
        else
        {
            str = "<tr id=\"listItem" + client.Id + "\" >";
        }
        
        str += "<td class=\"col1\">";
        str += "<input id=\"CheckBoxClient" + client.Id + "\" type=\"checkbox\" value=\"" + client.Id + "\" />";
        str += "</td>";
        //str += "<td title=\"View more details\" id=\"Open" + client.Id + "\" onclick=\"OpenItem(" + client.Id + ")\" class=\"col0\">&nbsp;</td>"; 
        str += "<td class=\"col2\">";
        str += "<a onclick=\"window.open('ContactDetails.aspx?ClientId=" + client.Id + "','EditClient" + client.Id + "','height=710,width=1015,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes')\" style=\"cursor:hand;\">";
        str += client.Id;
        str += "</a></td>";
        str += "<td class=\"col3\">";
        str += "<a onclick=\"window.open('ContactDetails.aspx?ClientId=" + client.Id + "','EditClient" + client.Id + "','height=710,width=1015,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes')\" style=\"cursor:hand;\">";
        str += client.FirstName + "&nbsp;";
        str += "</a></td>";
        str += "<td class=\"col4\">";
        str += "<a onclick=\"window.open('ContactDetails.aspx?ClientId=" + client.Id + "','EditClient" + client.Id + "','height=710,width=1015,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes')\" style=\"cursor:hand;\">";
        str += client.LastName + "&nbsp;";
        str += "</a></td>";
        str += "<td class=\"col5\" title=\"" + client.Email + "\">";
        str += client.Email + "&nbsp;";
        str += "</td>";
        
        var addressStr = client.Address1;
         
        if(client.Address2!=null && client.Address2!="")
        addressStr += "\n" + client.Address2 
        if(client.Address3!=null && client.Address3!="")
        addressStr += "\n" + client.Address3;
        if(client.Town!=null && client.Town!="")
        addressStr += "\n" + client.Town;
        
        str += "<td class=\"col6\" title=\"" + addressStr + "\">";
        str += client.Address1;
        if(client.Address2!=null && client.Address2!="")
        str += "<br>" + client.Address2 
        if(client.Address3!=null && client.Address3!="")
        str += "<br>" + client.Address3;
        if(client.Town!=null && client.Town!="")
        str += "<br>" + client.Town;
        str += "&nbsp;</td>";
        
//        str += "<td class=\"col6\" title=\"" + client.Address1 + "\n" + client.Address2 + "\n" + client.Address3 + "\">";
//        str += client.Address1 + "<br>" + client.Address2 + "<br>" + client.Address3;
//        str += "</td>";  
        str += "<td class=\"col7\" title=\"" + client.DaytimeTelephone + "\">";
        str += client.DaytimeTelephone + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col8\" title=\"" + client.Mobile + "\">";
        str += client.Mobile + "&nbsp;";
        str += "</td>";
        str += "<td class=\"col9\" >";
        str += client.IsVendor==true?"Yes":"No";
        str += "</td>";
        str += "<td class=\"col10\" >";
        str += client.IsEnquirer==true?"Yes":"No" ;
        str += "</td>";
        str += "<td class=\"col11\">";
        str += client.GeneralContact.toLowerCase()=="true"?"Yes":"No";
        str += "</td>";
        str += "<td class=\"col12\">";
        str += client.StatusDescription + "&nbsp;";
        str += "</td>";
        
        str += "<td class=\"col13\" title=\"" + client.DateEditedString + "\">";
        str += client.DateEditedString + "&nbsp;";
        str += "</td></tr>";
        str += "<tr style=\"display:none\" class=\"search_detail\" id=\"Detail" + client.Id + "\"><td></td>"
        str += "</tr>";
        
        return str;
    }
    
    function BuildMatchToClientRowHTML(client, alt, stringBuffer)
    {
        
        if (alt)
        {
            stringBuffer.append("<tr id=\"listItem" + client.Id + "\" class=\"alt\" >");
        }
        else
        {
            stringBuffer.append("<tr id=\"listItem" + client.Id + "\" >");
        }
        
        stringBuffer.append("<td class=\"col1\">");
        stringBuffer.append("<input id=\"CheckBoxClient" + client.Id + "\" type=\"checkbox\" value=\"" + client.Id + "\">");
        stringBuffer.append("</td>");
        //str += "<td title=\"View more details\" id=\"Open" + client.Id + "\" onclick=\"OpenItem(" + client.Id + ")\" class=\"col0\"></td>"; 
        stringBuffer.append("<td class=\"col2\">");
        stringBuffer.append("<a href=\"#\"  onclick=\"window.open('/clients/ContactDetails.aspx?ClientId=" + client.Id + "','EditClient" + client.Id + "','height=710,width=1015,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes')\">" + client.Id + "</a>");
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col3\" title=\"" + client.Name + "\">");
        stringBuffer.append("<a href=\"#\"  onclick=\"window.open('/clients/ContactDetails.aspx?ClientId=" + client.Id + "','EditClient" + client.Id + "','height=710,width=1015,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes')\">" + client.Name + "</a>");
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col4\" title=\"" + client.Email + "\">&nbsp;");
        stringBuffer.append( client.Email);
        stringBuffer.append("</td>");
        stringBuffer.append("<td class=\"col12\" title=\"" + client.Mobile + "\">&nbsp;");
        stringBuffer.append(client.Mobile);
        stringBuffer.append("</td>");
        stringBuffer.append( "<td class=\"col5\" title=\"Spec Sent\"><div id='SpecSent"+client.Id+"'>&nbsp;</div>");
        stringBuffer.append( "</td>");  
        stringBuffer.append( "<td class=\"col6\" title=\"" + formatNumber(client.MinBudget) + "\">");
        stringBuffer.append( formatNumber(client.MinBudget));
        stringBuffer.append( "</td>");  
        stringBuffer.append( "<td class=\"col7\" title=\"" + formatNumber(client.MaxBudget) + "\">");
        stringBuffer.append( formatNumber(client.MaxBudget));
        stringBuffer.append( "</td>");
        stringBuffer.append( "<td class=\"col8\" title=\"" + formatNumber(client.MinHullLength) + "\">");
        stringBuffer.append( formatNumber(client.MinHullLength));
        stringBuffer.append( "</td>");
        stringBuffer.append( "<td class=\"col9\" title=\"" + formatNumber(client.MaxHullLength) + "\">");
        stringBuffer.append( formatNumber(client.MaxHullLength));
        stringBuffer.append( "</td>");
        stringBuffer.append( "<td class=\"col10\" title=\"" + formatNumber(client.YearBuilt) + "\">");
        stringBuffer.append( formatNumber(client.YearBuilt));
        stringBuffer.append( "</td>");
        stringBuffer.append( "<td class=\"col11\" title=\"" + client.Models + "\">&nbsp;");
        stringBuffer.append( client.Models);
        stringBuffer.append( "</td>");
        stringBuffer.append( "</tr>");
        
       // return stringBuffer;
    }
function StringBuffer() 
{ 
   this.buffer = []; 
} 

 StringBuffer.prototype.append = function append(string) { 
   this.buffer.push(string); 
   return this; 
 }; 

 StringBuffer.prototype.toString = function toString() { 
   return this.buffer.join(""); 
 }; 
 
    function formatNumber(num)
    {
        if(new Number(num)<=0)
            return "&nbsp;0";
        else
            return num;    
    }
    
    function SetupPopup(PopupID)
    {
        var w = ($(window).width());
        var h = ($(window).height());
        
        var pw = $("#"+PopupID).width();
        var ph = $("#"+PopupID).height();
        
        var l = (w/2) - (pw/2);
        var t = (h/2) - (ph/1.5);
        
        $(".cover").width(w);
        $(".cover").height(h);
        
        $("#"+PopupID).css({"left":l});
        $("#"+PopupID).css({"top":t});    
    }


// Clients BaseCollection features
// to use these : collection.sort(functionName);
// static
    function sortById(a, b) 
    {
        var x = a.Id;
        var y = b.Id;
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    
    function sortByLastName(a, b) 
    {
        var x = a.LastName.toLowerCase();
        var y = b.LastName.toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    
    function sortByFirstName(a, b) 
    {
        var x = a.FirstName.toLowerCase();
        var y = b.FirstName.toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    
    function sortByEmail(a, b) 
    {
        var x = a.Email.toLowerCase();
        var y = b.Email.toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    
     function sortByAddress(a, b) 
    {
        var x = a.Address1.toLowerCase();
        var y = b.Address1.toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    
    function sortByTelDay(a, b) 
    {
        var x = a.DaytimeTelephone.toLowerCase();
        var y = b.DaytimeTelephone.toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    
    function sortByMobile(a, b) 
    {
        var x = a.Mobile.toLowerCase();
        var y = b.Mobile.toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    
    function sortByVendor(a, b) 
    {
        var x = a.IsVendor.toString().toLowerCase();
        var y = b.IsVendor.toString().toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    
    function sortByEnquirer(a, b) 
    {
        var x = a.IsEnquirer.toString().toLowerCase();
        var y = b.IsEnquirer.toString().toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    
    function sortByUpdated(a, b) 
    {
        var x = a.IsEnquirer.toString().toLowerCase();
        var y = b.IsEnquirer.toString().toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    /*-- Common functions for checkbox lists ---*/
    function countSelected(checkBoxSuffix)
    {
        var checkBoxName;
        var rCheckBox=document.getElementsByTagName("input");
        var intCountChecked=0;
        for (var iLoop=0;iLoop<rCheckBox.length;iLoop++)
        {
            if(rCheckBox[iLoop].type.toLowerCase()=="checkbox")
            {
                checkBoxName=rCheckBox[iLoop].id;
                
                checkBoxName=checkBoxName.substr(0,checkBoxSuffix.length);
                if(rCheckBox[iLoop].checked==true && checkBoxName.toLowerCase()==checkBoxSuffix.toLowerCase())
                {
                    intCountChecked++;
                }
            } 
        }
        return intCountChecked;
    }
    function getSelectedIds(checkBoxSuffix, returnTopItem)
    {
        var selectedIds = "";
        var checkBoxName;
        var rCheckBox=document.getElementsByTagName("input");
        
        for (var iLoop = 0; iLoop < rCheckBox.length; iLoop++)
        {
            if (rCheckBox[iLoop].type.toLowerCase()=="checkbox")
            {
                checkBoxName = rCheckBox[iLoop].id;
                checkBoxName = checkBoxName.substr(0, checkBoxSuffix.length);
                if (rCheckBox[iLoop].checked == true && checkBoxName.toLowerCase()==checkBoxSuffix.toLowerCase())
                {
                    //Return the first client selected
                    if (returnTopItem)
                    {
                        return rCheckBox[iLoop].value;
                    }
                    
                    //Create a string of selected ids
                    if(selectedIds=="")
                    {
                        selectedIds= rCheckBox[iLoop].value;
                    }
                    else
                    {
                        selectedIds+= "," + rCheckBox[iLoop].value;
                    }
                }
            } 
        }
        
        return selectedIds;
    }
    
    function selectOrClearAllCheckbox(checkBoxSuffix, action)
    {
        var rCheckBox=document.getElementsByTagName("input");
        var intCountChecked=0;
        
        for (var iLoop=0;iLoop<rCheckBox.length;iLoop++)
        {
            if(rCheckBox[iLoop].type.toLowerCase()=="checkbox")
            {
                checkBoxName=rCheckBox[iLoop].id;
                checkBoxName=checkBoxName.substr(0,checkBoxSuffix.length);
                
                if(checkBoxName.toLowerCase()==checkBoxSuffix.toLowerCase())
                {
                   switch(action.toLowerCase())
                   {
                        case "select":
                            rCheckBox[iLoop].checked=true;
                            break;
                        case "clear":
                            rCheckBox[iLoop].checked=false;
                            break;                  
                   }
                }
            } 
        }
    }
    
    
    function ClientSelected()
    {
        var checkBoxName;
        var rCheckBox=document.getElementsByTagName("input");
        var intCountChecked=0;
        for (var iLoop=0;iLoop<rCheckBox.length;iLoop++)
        {
            if(rCheckBox[iLoop].type.toLowerCase()=="checkbox")
            {
                checkBoxName=rCheckBox[iLoop].id;
                checkBoxName=checkBoxName.substr(0,14);
                if(rCheckBox[iLoop].checked==true && checkBoxName.toLowerCase()=="checkboxclient")
                {
                    intCountChecked++;
                }
            } 
        }
        return intCountChecked;
    }
    
    function editClient()
    {
        if(ClientSelected()==0)
        {
            alert("Please choose a client to edit");
            return false;
        }
        var ClientId;
        ClientId=getSelectedClientIds(true);
        document.location="ContactDetails.aspx?ClientId="+ClientId;
    }
    
    function selectOrClearAllCheckboxes(action)
    {
        var rCheckBox=document.getElementsByTagName("input");
        var intCountChecked=0;
        
        for (var iLoop=0;iLoop<rCheckBox.length;iLoop++)
        {
            if(rCheckBox[iLoop].type.toLowerCase()=="checkbox")
            {
                checkBoxName=rCheckBox[iLoop].id;
                checkBoxName=checkBoxName.substr(0,14);
                
                if(checkBoxName.toLowerCase()=="checkboxclient")
                {
                   switch(action.toLowerCase())
                   {
                        case "select":
                            rCheckBox[iLoop].checked=true;
                            break;
                        case "clear":
                            rCheckBox[iLoop].checked=false;
                            break;                  
                   }
                }
            } 
        }
    }
    
    function getSelectedClientIds(returnTopItem)
    {
        var selectedClientIds = "";
        var checkBoxName;
        var rCheckBox=document.getElementsByTagName("input");
        
        for (var iLoop = 0; iLoop < rCheckBox.length; iLoop++)
        {
            if (rCheckBox[iLoop].type.toLowerCase()=="checkbox")
            {
                checkBoxName = rCheckBox[iLoop].id;
                checkBoxName = checkBoxName.substr(0, 14);
                if (rCheckBox[iLoop].checked == true && checkBoxName.toLowerCase()=="checkboxclient")
                {
                    //Return the first client selected
                    if (returnTopItem)
                    {
                        return rCheckBox[iLoop].value;
                    }
                    
                    //Create a string of selected ids
                    if(selectedClientIds=="")
                    {
                        selectedClientIds= rCheckBox[iLoop].value;
                    }
                    else
                    {
                        selectedClientIds+= "," + rCheckBox[iLoop].value;
                    }
                }
            } 
        }
        
        return selectedClientIds;
    }
    
    var GlobalClientId = '';
    
    function OpenItem(clientID)
    {
        //close last div
        if($('#Detail' + GlobalClientId))
        {
            $("#listItem" + GlobalClientId + " > dd").css("height", "18px");
            $("#listItem" + GlobalClientId + " > dd").css("border-bottom", "none");
            $("#Detail" + GlobalClientId).slideUp('fast');
            $("#Open" + GlobalClientId).removeClass('opened');
        }
        
        GlobalClientId = clientID;
        $("#listItem" + GlobalClientId + " > dd").css("height", "50px");
        $("#listItem" + GlobalClientId + " > dd").css("border-bottom", "solid 1px #d5d6d8");
        $("#Detail" + GlobalClientId).show();
        $("#Open" + GlobalClientId).addClass('opened');
        
        //if the div has something in it then just open it back up
       
        if($('#Detail' + GlobalClientId).html() != '')
        {
            $("#Detail" + GlobalClientId).slideDown('slow');
        }
        else
        {
            $('#Detail' + clientID).hide();
            $('#Detail' + clientID).html("<span class='loader'><img src='/images/loading.gif'><br />Loading...</span>");
            $("#Detail" + GlobalClientId).slideDown('fast');
            Ancanet.Clients._default.LoadClientInfo(clientID, Callback_OpenItem);
        }
    }
    
    function Callback_OpenItem(response)
    {
        
        var client = response.value;
        
        var str = '';
        str += "More detail";
        
        
        //put div into variable
        var content = $("#Detail" + GlobalClientId);
        //close it up and hide it
        content.slideUp('fast', function(){
            content.hide();
            content.html(str);
        });
        
        //now give it the text
       
        content.slideDown('fast');
    }
    
    function ToogleFtMtr(type,txtBoxFrom,txtBoxTo)
    {
        var valFrom = $("#"+txtBoxFrom).val();
        var valTo = $("#"+txtBoxTo).val();
        switch(type.toLowerCase())
        {
            case "ft-mtr" :
                        if(valFrom!="")
                        {
                           valMtr = new Number(valFrom)* 0.3048;
                           $("#"+txtBoxTo).val(Math.round(valMtr)) 
                        }
                        else
                           $("#"+txtBoxTo).val(""); 
                        break;
            case "mtr-ft" :
                        if(valFrom!="")
                        {
                           valFt = new Number(valFrom)* 3.2808399;
                           $("#"+txtBoxTo).val(Math.round(valFt)) 
                        }
                        else
                            $("#"+txtBoxTo).val("");
                        break;
        }
    }
    
    function HasTypedNumber()
    {
        var intKey = 0;
	    var e= (window.event)? event : e;
	    intKey = (e.keyCode)? e.keyCode: e.charCode;

        return ((intKey >= 48 && intKey <= 57) || (intKey >= 96 && intKey <= 105) || 
                (intKey==8) || (intKey==46) || (intKey==37) || (intKey==39));
    }
    
    
    function jsSafeString(_string)
    {
        var safeString= _string;
        safeString = safeString.replace("'","&#39;");
        return safeString;
    }
    
    function jsCodeApos(_string)
    {
        var pattern = "'";
        var safeString= _string;
        safeString = safeString.replace(pattern,"#`#");
        return safeString;
    }
    
    function jsDecodeApos(_string)
    {
        var safeString= _string;
        safeString = safeString.replace("#`#","'");
        return safeString;
    }
