﻿

var SunNet = {};
SunNet.JsUtil = {};
SunNet.JsUtil.ToolTipID = "SunNet_JsUtil_ToolTipID";
SunNet.JsUtil.DisplayToolTip = function(obj, tooltipHtmlId) {
    var tooltip = SunNet.JsUtil.InstanceToolTip();
    $(tooltip).hide();
    $(tooltip).html($("#" + tooltipHtmlId).html());
    var os = $(obj).offset();
    $(tooltip).css("left", os.left + 20).css("top", os.top + 20);
    $(tooltip).fadeIn("normal");
}
SunNet.JsUtil.HideToolTip = function() {
    var tooltip = SunNet.JsUtil.InstanceToolTip();
    $(tooltip).fadeOut("normal");
}
SunNet.JsUtil.InstanceToolTip = function() {
    var tooltipObj = document.getElementById(SunNet.JsUtil.ToolTipID);
    if (tooltipObj == null) {
        if (document.all) {
            tooltipObj = document.createElement("<div id='" + SunNet.JsUtil.ToolTipID + "' style='position:absolute; width: 270px; padding: 10px; border: 3px solid #a6d5ef; background-color: #f1f9ff;color: #696969; font-size:11px;z-index:9999;'></div>");
        }
        else {
            tooltipObj = document.createElement("div");
            tooltipObj.setAttribute("style", "position:absolute; width: 270px; padding: 10px; border: 3px solid #a6d5ef; background-color: #f1f9ff;color: #696969; font-size:11px;z-index:9999;");
            tooltipObj.setAttribute("id", SunNet.JsUtil.ToolTipID);
        }
        $(tooltipObj).hide();
        document.body.appendChild(tooltipObj);
    }
    return tooltipObj;
}






SunNet.JsUtil.GetLabelByControlID = function(ctlId) {
    var searchKey = "label[for='" + ctlId + "']";
    return $(searchKey);
}

SunNet.JsUtil.ShowObjWithLabel = function(ctlId) {
    $("#" + ctlId).show();
    var lbl = SunNet.JsUtil.GetLabelByControlID(ctlId);
    $(lbl).show();
}
SunNet.JsUtil.HideObjWithLabel = function(ctlId) {
    $("#" + ctlId).hide();
    var lbl = SunNet.JsUtil.GetLabelByControlID(ctlId);
    $(lbl).hide();
}




SunNet.JsUtil.IsExactEqualInString = function(inStr, searchStr) {
    var strs = inStr.split(',');
    for (var i = 0; i < strs.length; i++) {
        if (strs[i] == searchStr)
            return true;
    }
    return false;
}



SunNet.JsUtil.FormatPrice = function(price) {
    var priceStr = price.toFixed(2);
    priceStr = priceStr.replace(".00", "");
    priceStr = "$" + priceStr;
    return priceStr;
}





SunNet.JsUtil.CheckPhone = function(txtObj) {
    var phone = txtObj;
    var digits = phone.value.replace(/[^0-9]/ig, '');
    if (!digits) {
        return;
    }
    if (digits.length > 10) {
        phone.value = digits.substring(0, 10);
    }
    if (digits.length == 10) {
        phone.value = digits.substring(0, 3) + '-' +
                      digits.substring(3, 6) + '-' +
                      digits.substring(6, 10);
    }
    else if (digits.length > 6) {
        phone.value = digits.substring(0, 3) + '-' +
                      digits.substring(3, 6) + '-' +
                      digits.substring(6, digits.length);
    }
    else if (digits.length > 3) {
        phone.value = digits.substring(0, 3) + '-' +
                      digits.substring(3, digits.length);
    }
    else {
        phone.value = digits;
    }
}
