﻿/*
    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, valueField) {
    objField = getObj(nameField);

    if (objField)
        if (objField.value == valueField)
            objField.value = "";
}

function showPasswordField(nameField, passField) {
    objField = getObj(nameField);
    objFieldPass = getObj(passField);

    if (objField)
        objField.style.display = 'none';

    if (objFieldPass) {
        objFieldPass.style.display = '';
        objFieldPass.focus();
    }
}

function isNumber(field) {
    var re = /^[0-9-'.'-',']*$/;
    if (!re.test(field.value)) {
        field.value = field.value.replace(/[^0-9-'.'-',']/g, "");
    }
}

function fixFooter() {
    var objPage = Page.getWindowSize();
    var objFooter = getObj('footer');

    if (objPage.pageHeight > objPage.windowHeight) {
        if (document.all)
            objFooter.style.top = (objPage.pageHeight - 1) + 'px';
        else
            objFooter.style.top = (objPage.pageHeight - objFooter.clientHeight - 1) + 'px';
    }
    else {
        objFooter.style.top = (objPage.windowHeight - objFooter.clientHeight - 1) + 'px';
    }
}

function limitText(limitField, limitCount, limitNum) {
    var objMessage = getObj('message_counter');
    var charsLeft = 0;

    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
    else {
        charsLeft = limitNum - limitField.value.length;
//		limitCount.value = limitNum - limitField.value.length;
    }

    objMessage.innerHTML = charsLeft + ' characters left.';
}

function ValidateDate(oSrc, args) {
    var objDay = getObj(nameDdlDay);
    var objMonth = getObj(nameDdlMonth);
    var objYear = getObj(nameDdlYear);

    var txtDate = objMonth.value + '/' + objDay.value + '/' + objYear.value;

//  alert(Date.isValid(txtDate));

    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); }