﻿//function fbs_click(u,t) {
//    //u = location.href;
//    //t = document.title;
//    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&#38;t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
//    return false;
//    //TODO REMOVE: http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsantamail.com%2F1fz06&38;t=bubba%27s%20Letter%20and%20Wish%20List%20to%20Santa%20|%20SantaMail.com
//}

//function newwin(n, h, w) {
//    var newwin = window.open(eval("n"),
//        'Legal', 'height=' + h + ',width=' + w + ',left=0,top=0,directories=no,location=no,menubar=no,scrollbars=yes,resizable=yes,status=no,toolbar=no');
//}

//function twitter(n, h, w) {
//    var newwin = window.open(eval("n"),
//        'Twitter', 'height=' + h + ',width=' + w + ',left=0,top=0,directories=no,location=no,menubar=no,scrollbars=yes,resizable=yes,status=no,toolbar=no');
//}

function validateEmail(email) {
    var regex = /^[A-Za-z0-9!#\$%&''\*\+\-\/=\?\^_`{\|}~]+(\.[A-Za-z0-9!#\$%&''\*\+\-\/=\?\^_`{\|}~]+)*@[A-Za-z0-9!#\$%&''\*\+\-\/=\?\^_`{\|}~]+(\.[A-Za-z0-9!#\$%&''\*\+\-\/=\?\^_`{\|}~]+)*\.[A-Za-z0-9!#\$%&''\*\+\-\/=\?\^_`{\|}~]+$/;
    return regex.test(email);
}

function validateUSZip(zip) {
    var regex = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
    return regex.test(zip);
}

function ValidateFormHtmlTags(input) {
    var regex = /[\<\>]/;
    return !regex.test(input);
}

function ValidateRegisterForm() {
    
    var errorCount = 0;
    var mode = document.getElementById('hdnEntryMode').value;

    if (mode == 'zip') {
        var zip = document.getElementById('tb_ZipCode').value;

        // Remove begin/end whitespace
        zip = zip.replace(/^\s*|\s*$/g, '');

        if (zip.length == 0 || zip == 'enter zip code') {
            errorCount++;
            document.getElementById('zipVal').innerHTML = 'please provide a zip or postal code';
            document.getElementById('zipVal').style.display = 'block';

            if (document.getElementById('containerEmailInput') != null) {
                document.getElementById('containerEmailInput').style.height = '90px';
                document.getElementById('modEmailContainer').style.height = '230px';
            }
            else {
                document.getElementById('containerEmailHomeInput').style.height = '90px';
                document.getElementById('modEmailHomeContainer').style.height = '640px';
            }
        }
        /*
        else if (zip.length > 5) {
            errorCount++;
            document.getElementById('zipVal').innerHTML = 'please limit the zip code to 5 digits';
            document.getElementById('zipVal').style.display = 'block';

            if (document.getElementById('containerEmailInput') != null) {
                document.getElementById('containerEmailInput').style.height = '90px';
                document.getElementById('modEmailContainer').style.height = '230px';
            }
            else {
                document.getElementById('containerEmailHomeInput').style.height = '90px';
                document.getElementById('modEmailHomeContainer').style.height = '640px';
            }
        }
        else if (!validateUSZip(zip)) {
            errorCount++;
            document.getElementById('zipVal').innerHTML = 'please provide a 5-digit zip code';
            document.getElementById('zipVal').style.display = 'block';

            if (document.getElementById('containerEmailInput') != null) {
                document.getElementById('containerEmailInput').style.height = '90px';
                document.getElementById('modEmailContainer').style.height = '230px';
            }
            else {
                document.getElementById('containerEmailHomeInput').style.height = '90px';
                document.getElementById('modEmailHomeContainer').style.height = '640px';
            }
        }
        */
        else {
            document.getElementById('zipVal').innerHTML = '';
            document.getElementById('zipVal').style.display = 'none';

            if (document.getElementById('containerEmailInput') != null) {
                document.getElementById('containerEmailInput').style.height = '70px';
                document.getElementById('modEmailContainer').style.height = '210px';
            }
            else {
                document.getElementById('containerEmailHomeInput').style.height = '70px';
                document.getElementById('modEmailHomeContainer').style.height = '640px';
            }
        }
    }
    //alert("test2");
    var email = document.getElementById('txtEmail').value;

    // Remove begin/end whitespace
    email = email.replace(/^\s*|\s*$/g, '');

    if (email.length == 0) {
        errorCount++;
        if (document.getElementById('emailMessageNote') != null) {
            document.getElementById('emailMessageNote').style.display = 'none';
        }
        document.getElementById('lblEmailError').innerHTML = 'invalid email address';
        document.getElementById('emailErrorNote').style.display = 'block';
    }
    else if (!validateEmail(email)) {
        errorCount++;
        if (document.getElementById('emailMessageNote') != null) {
            document.getElementById('emailMessageNote').style.display = 'none';
        }
        document.getElementById('lblEmailError').innerHTML = 'invalid email address';
        document.getElementById('emailErrorNote').style.display = 'block';
    }
    else {
        document.getElementById('lblEmailError').innerHTML = '';
        document.getElementById('emailErrorNote').style.display = 'none';
        if (document.getElementById('emailMessageNote') != null) {
            document.getElementById('emailMessageNote').style.display = 'block';
        }
    }

    if (errorCount > 0) {
        return false;
    } else {
        return true;
    }
}

function ValidateQuickForm() {
    var errorCount = 0;
    var email = document.getElementById('txtEmail2').value;

    if (email.length == 0) {
        errorCount++;
        //document.getElementById('emailNote').style.display = 'none';
        document.getElementById('lblEmailError2').innerHTML = 'invalid email address';
        document.getElementById('lblEmailError2').style.display = '';
    }
    else if (!validateEmail(email)) {
        errorCount++;
        //document.getElementById('emailNote').style.display = 'none';
        document.getElementById('lblEmailError2').innerHTML = 'invalid email address';
        document.getElementById('lblEmailError2').style.display = '';
    }
    else {
        document.getElementById('lblEmailError2').innerHTML = '';
        document.getElementById('lblEmailError2').style.display = 'none';
    }

    if (errorCount > 0) {
        return false;
    } else {
        return true;
    }
}

