﻿// JScript File

$(document).ready(function() {
    var useragent = navigator.userAgent.toLowerCase();
    var isMsIe6 = /msie 6./.test(useragent) && !/opera/.test(useragent);

    if (isMsIe6) { window.onload = function() { e("/common/images/") } }
});


// external links disclosure
$(document).ready(function() {

    // Create Custom :external selector
    $.expr[':'].external = function(obj) {
        return !obj.href.match(/^mailto\:/)
            && !obj.href.match(/^javascript\:/)
            && (obj.hostname != location.hostname)
            && (obj.hostname != "secure.intercreditbank.com");
    };

    // Add 'external' CSS class to all external links
    $('a:external').addClass('external');
    $('.external').click(function() {
        var link = $(this).attr('href');

        var disclosureMessage = "<div>";
        disclosureMessage += "<p>The website you have selected: <br />(<strong>" + link + "</strong>)<br /> Is an external one located on another server.</p>";
        disclosureMessage += "<p>Intercredit Bank has <strong>no responsibility for any external Web Site</strong>. It neither endorses the information, content, presentation, or accuracy nor makes any warranty, express or implied, regarding any external site.</p>";
        disclosureMessage += "<p><strong>Are you sure you want to proceed?</strong></p>";
        disclosureMessage += "</div>";
        //disclosureMessage +=  "<p>Thank you for visiting Intercredit Banks Web Site.</p>";

        $(disclosureMessage).dialog({
            title: "You are leaving Intercredit Bank\'s\ Website.",
            modal: true,
            overlay: {
                backgroundcolor: '#000',
                opacity: 0.8
            },
            buttons: {
                'Yes': function() {
                    $(this).dialog('close').remove();
                    window.open(link);
                },
                'Cancel': function() {
                    $(this).dialog('close').remove();
                    return false;
                }
            }
        });

        return false;
    });
});

// Help Flyout
function addHelp() { $('a.help').addClass("active"); $('#help_detail').addClass("helphovering").show(); }
function removeHelp() { $('a.help').removeClass("active"); $('#help_detail').removeClass("helphovering").hide(); }

$(document).ready(function() {

    var helpConfig = {
        interval: 50,
        sensitivity: 4,
        over: addHelp,
        timeout: 200,
        out: removeHelp
    };

    $('.helpover').hoverIntent(helpConfig);
});

// Mail Links parse
$(document).ready(function() {
    //  var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/;
    var regEx = /(\w+([-+.']\w+)*@intercreditbank.com)/gi;
    var redirFormat = "<a href=\"/contact-us/send-us-a-message.aspx?e=$1\">$1</a>";

    // in secondary Bar modules
    $(".module").filter(function() {
        return $(this).html().match(regEx);
    }).each(function() {
        $(this).html($(this).html().replace(regEx, redirFormat));
    });

    // in main Heading
    $(".mainHeading").filter(function() {
        return $(this).html().match(regEx);
    }).each(function() {
        $(this).html($(this).html().replace(regEx, redirFormat));
    });

    // in Content
    $(".contenttext").filter(function() {
        return $(this).html().match(regEx);
    }).each(function() {
        $(this).html($(this).html().replace(regEx, redirFormat));
    });

    // in Content Block
    $(".block").filter(function() {
        return $(this).html().match(regEx);
    }).each(function() {
        $(this).html($(this).html().replace(regEx, redirFormat));
    });

});

$(document).ready(function() {
    $(".contenttab").tabs();
});

function showDirector(name) {
    $('.dirbox').hide();
    $('.dirItem').hide();
    $('#' + name).fadeIn('fast');
    $('.dirbox').fadeIn('fast');

}

$(document).ready(function() {
    $('#secure_login').click(function() { if(!SignIn()) return false; });
});

function SignIn() {
    if ($('#v1').val() != "") {
        var newForm = "https://secure.intercreditbank.com/cgi-bin/hbproxy.exe/1225/newlogin"
        $('#form1').attr("action", newForm);
        $('#form1').submit();
        return false;
    }
    else { alert('Please enter your login ID');return false;}
}

function ShareOnFacebook(url, title) {
    var url = 'http://www.facebook.com/sharer.php?u=' + url + '&t=' + title;
    window.open(url, 'FacebookSharer', 'width=626, height=436,status=no,toolbar=no');
}

function GetValueFromRadioButton(element) {
    var returnValue;
    var rbl = document.getElementById(element);
    var options = rbl.getElementsByTagName('input');

    for (var i = 0; i < options.length; i++) {
        if (options[i].checked) {

            returnValue = options[i].value;
            break;
        }
    }

    return returnValue;
}

function fixMoney(fld, sep) { // monetary field check
    if (!fld.value.length || fld.disabled) return true; // blank fields are the domain of requireValue 
    var val = fld.value;
    if (typeof (sep) != 'undefined') val = val.replace(new RegExp(sep, 'g'), '');
    if (val.indexOf('$') == 0)
        val = parseFloat(val.substring(1, 40));
    else
        val = parseFloat(val);
    if (isNaN(val)) { // parse error 
        alert("El campo '" + fieldname(fld) + "' debe ser un valor monetario.");
        return false;
    }
    var sign = (val < 0 ? '-' : '');
    val = Number(Math.round(Math.abs(val) * 100)).toString();
    while (val.length < 2) val = '0' + val;
    var len = val.length;
    val = sign + (len == 2 ? '0' : val.substring(0, len - 2)) + '.' + val.substring(len - 2, len + 1);
    fld.value = val;
    return true;
}

function fixInt(fld, sep) { // integer check/complainer 
    if (!fld.value.length || fld.disabled) return true; // blank fields are the domain of requireValue 
    var val = fld.value;
    if (typeof (sep) != 'undefined') val = val.replace(new RegExp(sep, 'g'), '');
    val = parseInt(val);
    if (isNaN(val)) { // parse error 
        alert("El campo '" + fieldname(fld) + "' debe ser un valor numérico.");
        return false;
    }
    fld.value = val;
    return true;
}

function fieldname(fld) { // get the field label text or name
    if (fld.id && document.getElementsByTagName) {
        for (var i = 0, lbl = document.getElementsByTagName('LABEL'); i < lbl.length; i++)
            if (lbl[i].htmlFor == fld.id) return lbl[i].nodeValue || lbl[i].textContent || lbl[i].innerText;
        for (var i = 0, lbl = document.getElementsByTagName('label'); i < lbl.length; i++)
            if (lbl[i].htmlFor == fld.id) return lbl[i].nodeValue || lbl[i].textContent || lbl[i].innerText;
    }
    return fld.name;
}

function OpenIMC() {
    window.open('/Common/Themes/Tonisa/html/calculadoraImc.html', 'CalculadoraIMC', 'width=605,height=555,scrollbars=no,status=yes,resizable=no,titlebar=yes,toolbar=no');
}

function SendToFriend(pageId) {
    window.open('/utility/sendtofriend.aspx?p=' + pageId, 'EmailShare', 'width=540,height=550,scrollbars=yes,status=yes,resizable=yes,titlebar=yes,toolbar=no');
}

function PopulateDaysCombo(sourceYear, month, target) {
    var elem = document.getElementById(sourceYear);
    var year = elem.options[elem.selectedIndex].value;
    var days = 0;
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
        days = 31;
    }
    else {
        if (month != 2)
            days = 30;
        else {
            if (isLeapYear(year))
                days = 29;
            else days = 28;
        }
    }
    elem = document.getElementById(target);
    elem.options.length = 0;
    for (i = 0; i < days; i++) {
        elem.options[i] = new Option(i + 1, i + 1);
    }

}

function isLeapYear(Year) {
    if (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0)) {
        return (true);
    } else { return (false); }
}

