﻿// JScript File

function CountText(TextBoxID, LabelID, CharacterLimit) {

    var count = document.getElementById(TextBoxID).value.length;
    if (count > CharacterLimit) {
        document.getElementById(TextBoxID).value = document.getElementById(TextBoxID).value.substring(0, CharacterLimit);
        var label = document.getElementById(LabelID);
        label.style.display = "block";
        label.innerHTML = "0 characters remaining.";
    }
    else {
        var left = CharacterLimit - count;
        var label = document.getElementById(LabelID);
        label.style.display = "block";
        label.innerHTML = left + " characters remaining.";
    }
    return false;
}

function LimitDataEntry(TextBoxID, CharacterLimit) {

    var count = document.getElementById(TextBoxID).value.length;

    if (count > CharacterLimit) {
        document.getElementById(TextBoxID).value = document.getElementById(TextBoxID).value.substring(0, CharacterLimit);

    }
    if (document.getElementById("ctl00_siteBgColorValue") != null) {
        document.getElementById(TextBoxID).style.backgroundColor = document.getElementById("ctl00_siteBgColorValue").value;
    }

    return false;
}

function trim(str) {
    while ('' + str.charAt(0) == ' ')
        str = str.substring(1, str.length);
    while ('' + str.charAt(str.length - 1) == ' ')
        str = str.substring(0, str.length - 1);
    return str;
}


function CheckIfNumber(num) {
    if (/^-?\d+$/.test(num)) {
        return true;
    }
    else {
        return false;
    }
}

function CheckForNumber(num) {
    if (isNaN(num)) {
        return false;
    }
    else {
        return true;
    }
}

function HomePageLinkClicked(link, isInternalLink) {
    if (isInternalLink == "True") {
        location.href = link;
    }
    else {
        window.open(link, "", "height=700,width=780,left=200,top=100,directories=no,location=no,menubar=yes,toolbar=yes,resizable=yes,status=yes,scrollbars=yes");
    }
    return false;
}


function CheckContentHeight(homePageHeight) {
    var content = document.getElementById("ctl00_StoreContentPage");
    contentheight = content.offsetHeight;
    var productHeight = document.getElementById("ctl00_Main_divProductDetail");
    if (productHeight != null) {
        //        if (productHeight.offsetHeight > contentheight) {
        //            contentheight = productHeight.offsetHeight;
        //        }

    }
    else {
        if (contentheight < homePageHeight) {
            content.style.height = homePageHeight + "px";
            contentheight = homePageHeight;
        }

        var divAboutUs = document.getElementById("ctl00_Main_divAboutUsContent");
        if (divAboutUs != null) {
            //        var divAboutUsContent = document.getElementById("ctl00_Main_divAboutUsContent");
            //        var aboutUsHeight = divAboutUs.offsetHeight + divAboutUsContent.offsetHeight;
            var aboutUsHeight = divAboutUs.offsetHeight + 100;
            if (aboutUsHeight > contentheight) {
                content.style.height = aboutUsHeight + "px";
                contentheight = aboutUsHeight;
            }
        }
        var divContactUs = document.getElementById("ctl00_Main_divContactUsContent");
        if (divContactUs != null) {
            //        var divContactUsContent = document.getElementById("ctl00_Main_divContactUsContent");
            //        var contactUsHeight = divContactUs.offsetHeight + divContactUsContent.offsetHeight;
            var contactUsHeight = divContactUs.offsetHeight + 100;
            if (contactUsHeight > contentheight) {
                content.style.height = contactUsHeight + "px";
                contentheight = contactUsHeight;
            }
        }
    }

    return false;
}

function isValidURL(url) {
    var index = url.indexOf('?');
    if (index >= 0) {
        url = url.substring(0, index);
    }
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if (RegExp.test(url)) {
        return true;
    }
    else {
        return false;
    }
}

function SetLocation(url) {
    if (url != null) {
        location.href = url;
        return false;
    }
}

function fnTrapKD(btn, event) {

    if (document.all) {

        if (event.keyCode == 13) {

            event.returnValue = false;

            event.cancel = true;

            btn.click();

        }

    }

    else if (document.getElementById) {

        if (event.which == 13) {

            event.returnValue = false;

            event.cancel = true;

            btn.click();

        }

    }

    else if (document.layers) {

        if (event.which == 13) {

            event.returnValue = false;

            event.cancel = true;

            btn.click();

        }

    }

}
