﻿/*
    Author: Jeffrey Gordillo
    Date: 5/5/2009
    Description: Functions required in the website
*/

function getObj(objName) {
    if (document.getElementById) {
        return document.getElementById(objName);
    }
    else if (document.all) {
        return document.all[objName];
    }
    else if (document.layers) {
        return document.layers[objName];
    }
}

function openExternalLink(strURL) {
    var bResponse = confirm('You are about to be redirected to an external website. Do you want to continue?');
    if (bResponse) { window.open(strURL); }
}


function openPopupPic(strPicture) {
    window.open("../content/PopupPicture.html?" + strPicture, "Picture", "resizable=1,height=50,width=50");
}

function cleanField(nameField) {
    objField = getObj(nameField);

    if (objField)
        if (objField.value == 'Search')
            objField.value = "";
}

function isNumber(field) {
    var re = /^[0-9-'.'-',']*$/;
    if (!re.test(field.value)) {
        field.value = field.value.replace(/[^0-9-'.'-',']/g, "");
    }
}

function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
    else {
        //		limitCount.value = limitNum - limitField.value.length;
    }
}

function ValidateDate(oSrc, args) {
    var objDay = getObj(nameDdlDay);
    var objMonth = getObj(nameDdlMonth);
    var objYear = getObj(nameDdlYear);

    var txtDate = objMonth.value + '/' + objDay.value + '/' + objYear.value;

    if (!Date.isValid(txtDate))
        args.IsValid = false;
    else
        args.IsValid = true;
}

function ValidateLengthPassword(oSrc, args) {
    var oTxtPass = getObj(nameTxtPassword);
    var pass = oTxtPass.value;

    if (pass.length < 6) {
        args.IsValid = false;
    }
}

function ValidateTermUse(oSrc, args) {
    var oChk = getObj(nameChkTermsUse);
    if (oChk.checked == false) {
        args.IsValid = false;
    }
}

function showHideOverlay(objID, bShow) {
    this._popup = $find(objID);
    if (bShow) { this._popup.show(); }
    else { this._popup.hide(); }
}

function disableButton(oButton, strCssClass) {
    oButton.disabled = true;
    oButton.className = strCssClass;
}

function verifyValidators(objButton, strValGroup) {
    if (typeof (Page_ClientValidate) == 'function') {
        if (Page_ClientValidate(strValGroup) == true) {
            disableButton(objButton);
            return true;
        }
        else {
            // Validation not Passed
            return false;
        }
    }
    else {
        disableButton(objButton);
        return true;
    }
}

function displayCenterPopup(url, name, width, height, scrollbar, toolbar, statusbar) {
    var properties = 'scrollbars=' + scrollbar + ',toolbar=' + toolbar + ',status=' + statusbar;
    var iLeft = (window.screen.width - width) / 2;
    var iTop = (window.screen.height - height) / 2;

    window.open(url, name, properties + ',width=' + width + ',height=' + height + ',left=' + iLeft + ',top=' + iTop);
}

function displayAlertMessage(strMessage) { alert(strMessage); }