
function openPopup(parent, message, id) {
    if ($(id)) {
        $('container').removeChild($(id));
    }
    var div = document.createElement('div');
    div.style.display = 'none';
    $('container').appendChild(div);
    div.className = 'popup';
    div.id = id;
    var loc = parent.getBoundingClientRect();
    $(id).style.left = (loc.left + 50) + "px";
    $(id).style.top = (loc.top + 5) + "px";
    $(id).innerHTML = "<p>" + message + "</p>";
    new Effect.Appear(id);
    new Effect.Fade(id, {
        duration: 6.0
    });
}

// determine if the radio button is valid
function validateRadio(obj_name){
    var list = Form.getInputs('form','radio', obj_name);
    for (var i = 0; i < list.length; i++) {
        if (list[i].checked)
            return true;
    }
    return false;
}


function isValidPhone(area, prefix, last4) {
    return isNumber(area) && isNumber(prefix) && isNumber(last4) && validLength(area, 3, 3) && validLength(prefix, 3, 3) && validLength(last4, 4, 4)
}

function isNumber(i) {
    return /^\d+$/.test(i)
}

// determine whether this email is valid
function isValidEmail(email) {
    return (email && email.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i))
}

function validLength(pw, min, max) {

    if (pw.length < min || pw.length > max)
        return false;
    return true;
}

function validExp(pw, regex) {
    if (!pw.match(regex))
        return false;
    return true;
}

/*
# determine if the social security number is valid AAA-GG-SSSS, AAAGGSSSS,
# AAA-GGSSSS, AAAGG-SSSS AAA:  area number GG:   group number SSSS: serial
# number http://www.usrecordsearch.com/ssn.htm
*/
function isValidSSN(ssn) {
    var valid = false;
    if (ssn) {
        // area_number - group_number - serial_number
        var m = /^(\d{3})[- ]?(\d{2})[- ]?(\d{4})$/.exec(ssn);

        if (m && m.length == 4)
            valid = (m[1] != "000" && m[1] < 800 && m[2] != "00" && m[3] != "0000");
    }
    return valid;
}

function isValidSSNLast4(ssn) {
    return (ssn && ssn.length == 4 && ssn != "0000")
}

//show the div with extra phone numbers in it (and hide the image)
function displayDiv(cell) {
    try
    {
        element = cell.firstChild;
        while (element != null)
        {
            if (element.tagName == "SPAN")
            {
                element.style.display = "inline";
            }

            if (element.tagName == "IMG")
            {
                element.style.display = "none";
            }
            element = element.nextSibling;
        }
    }
    catch (err) {}
}

//hide the div with extra phone numbers in it (and show the image)
function hideDiv(cell) {
    try
    {
        element = cell.firstChild;
        while (element != null)
        {
            if (element.tagName == "SPAN")
            {
                element.style.display = "none";
            }

            if (element.tagName == "IMG")
            {
                element.style.display = "inline";
            }

            element = element.nextSibling;
        }
    }
    catch (err) {}
}

//highlight the search result row
function highlightRow(row) {
    try
    {
        cell = row.firstChild;
        while (cell != null)
        {
            if (cell.tagName == "TD")
            {
                if (cell.className == "search_results_light_l" || cell.className == "search_results_dark_l")
                    cell.className = "search_results_highlight_l";
                else if (cell.className == "search_results_light_r" || cell.className == "search_results_dark_r")
                    cell.className = "search_results_highlight_r";
                else if (cell.className == "search_results_light_bg" || cell.className == "search_results_dark_bg")
                    cell.className = "search_results_highlight_bg";

                displayDiv(cell);
            }

            cell = cell.nextSibling;
        }
    }
    catch (err) {}
}

//unhighlight the search result row
function unhighlightRow(row) {
    try
    {
        cell = row.firstChild;
        while (cell != null)
        {
            if (cell.tagName == "TD")
            {
                if (cell.className == "search_results_highlight_l")
                    cell.className = "search_results_" + cell.parentNode.className + "_l";
                else if (cell.className == "search_results_highlight_r")
                    cell.className = "search_results_" + cell.parentNode.className + "_r";
                else if (cell.className == "search_results_highlight_bg")
                    cell.className = "search_results_" + cell.parentNode.className + "_bg";

                hideDiv(cell);
            }

            cell = cell.nextSibling;
        }
    }
    catch (err) {}
}





function GetCount(year, month, day){

    date_future = new Date(year,month,day);

    date_now = new Date();
    amount = date_future.getTime() - date_now.getTime();
    delete date_now;

    // time is already past
    if(amount > 0){
        days = 0;
        hours = 0;
        mins = 0;
        secs = 0;

        amount = Math.floor(amount/1000); //kill the "milliseconds" so just secs

        days = Math.floor(amount/86400); //days
        amount = amount%86400;

        hours = Math.floor(amount/3600); //hours
        amount = amount%3600;

        mins = Math.floor(amount/60); //minutes
        amount = amount%60;

        secs = Math.floor(amount); //seconds

        document.getElementById('count_days').innerHTML = days;
        document.getElementById('count_hours').innerHTML = hours;
        document.getElementById('count_minutes').innerHTML = mins;
        document.getElementById('count_seconds').innerHTML = secs;

        setTimeout("GetCount(date_future.getFullYear(), date_future.getMonth(), date_future.getDate())", 1000);
    }
}

