$(document).ready(function() {
    $(".printFriendly").click(function() {
        var thisPage = $("body").html();
        var thisTitle = document.title;
        var fullWindowText = '<head><title>' + thisTitle + '</title><link rel="stylesheet" type="text/css" href="/styles/printwindow.css" media="screen" /><link rel="stylesheet" type="text/css" href="/styles/print.css" media="print" /><script type="text/javascript" src="/scripts/jquery.js"></script></head><body><div id="utils"><h6 class="printThis"><a href="#" onclick="javascript:window.print();return false;">Print this page</a></h6><h6 class="closeThis"><a href="#" onclick="javascript:window.close();return false;">Close this page</a></h6></div>' +
            thisPage + '</body></html>';
        var printWindow = window.open("", "printPreview", "toolbar=0,scrollbars=1,status=0,location=0,width=720,height=600");
        printWindow.document.write(fullWindowText);
        printWindow.document.close();
        printWindow.location.reload(true);
        printWindow.focus();
        return false;
    });

    //if(navigator.userAgent.indexOf("AppleWebKit/419.3") == -1) {
    //$("a").each(function(i,e){$(e).html($(e).html()+"<span class='printOnly'>["+this.href+"]</span>");});
    //}

    $("#logIn").click(function() {
        var visState = $("#loginForm").css("visibility");
        if (visState == "hidden") {
            $("#loginForm").css("display", "none").css("visibility", "visible").toggle("slow");
        }
        else {
            $("#loginForm").toggle("slow");
        }
    });
    $("input#inputMastheadSearch, input#inputKeyword").defaultvalue(
		"Enter Search Term",
		"Enter descriptive term or phase"
	);
    $("input#inputFirstName, input#inputLastName, input#inputAddress1, input#inputAddress2, input#inputCity, input#inputZip, input#inputEmail, input#inputPhone, input#inputIDNum, input#inputGroupName, textarea#textareaComments").defaultvalue(
		"Enter your first name",
		"Enter your last name",
		"Enter your street address",
		"Enter your street address",
		"Enter your city",
		"Enter your ZIP Code",
		"Enter valid email address",
		"Enter phone number",
		"Enter policy/group number",
		"Enter group name",
		"Enter comment, question or feedback"
	);
    $("button, .button").corner("6px");
    $("ul#sectionNav li a.sectionNavItem").corner("8px");
    $("ul.secondaryNav").corner("5px");
    $("#calloutGoTo a").corner("5px");
    $("div.dynamicTableContainer").corner("6px");
    $("img.sectionLandingImage").corner("6px");
    $("#calloutMyProfile .callout").corner("6px");
    $("#calloutMarketingMaterials").corner("6px");
    $(".dynamicTable tr:even td").css("background-color", "#d9ecf4");
    $(".innerCalloutContainer .callout").corner("5px");
    // Increase Font Size
    $("#increaseTextSize").click(function() {
        var currentFontSize = $('body').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        if (currentFontSizeNum <= 18) {
            var newFontSize = currentFontSizeNum * 1.1;
            $('body').css('font-size', newFontSize);
            $("#decreaseTextSize").html("<a href='#'>-</a>");
            $("#decreaseTextSize a").css("display", "inline");
            if (newFontSize > 18) {
                $("#increaseTextSize").html("<span>+</span>");
                $("#increaseTextSize a").css("display", "none");
            }
        }
        else {
            $("#increaseTextSize").html("<span>+</span>");
            $("#increaseTextSize a").css("display", "none");
        }
        return false;
    });
    // Decrease Font Size
    $("#decreaseTextSize").click(function() {
        var currentFontSize = $('body').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        if (currentFontSizeNum >= 14.5) {
            var newFontSize = currentFontSizeNum * 0.9;
            $('body').css('font-size', newFontSize);
            $("#increaseTextSize").html("<a href='#'>+</a>");
            $("#increaseTextSize a").css("display", "inline");
            if (newFontSize < 14.5) {
                $("#decreaseTextSize").html("<span>-</span>");
                $("#decreaseTextSize a").css("display", "none");
            }
        }
        else {
            $("#decreaseTextSize").html("<span>-</span>");
            $("#decreaseTextSize a").css("display", "none");
        }
        return false;
    });
});

function NewWindow(i){

    text = "Your are now leaving the USAble Life website and being linked to the website of an unrelated third party." ;
    text += "\n";
    text += "USAble Life is providing this link solely as a convinience to obtain information and not as an endorsement of the content of the third party site or any products or services offered on that site.";
    text += "\n";
    text += "USAble Life is not responsible for the products or services offered or the content of any linked site or any linked site contained in a linked site and does not make any representations regarding the cost or quality of products or services offered, or the content or accuracy of the materials on such sites.";
    if(confirm(text))
        {window.open(i,"aux_window","height=500,width=600,scrollbars=1,resizable=1,status=yes,toolbar=no,menubar=no,location=no");};
    }

function textCounter(field, countfield, maxsize) {
    if (field.value.length > maxsize) {
        field.value = field.value.substring(0, maxsize);
    }
    else {
        countfield.removeChild(countfield.lastChild);
        countfield.appendChild(document.createTextNode(maxsize - field.value.length));
    }
}
function set_flashmap_state(partN) {
    if (partN != "") {
        display_selected_state(partN);
    }    
    window.document.usa_locator.SetVariable("perem1", "state" + get_state(partN));
}


function display_selected_state(stateName) {
    alert("You have selected " + stateName +
                        ".\nPlease complete the form below with your information, then select " +
                        "the USAble Life products you are intersted in. Click the submit button to send " +
                        "your information to our Representatives who will contact you as soon as possible. " +
                        "Thank you.");

}

function get_state(state_name) {
    var state_array = [['', 0],
                        ['Alabama', 31],
                        ['Alaska', 49],
                        ['Arizona', 23],
                        ['Arkansas', 27],
                        ['California', 15],
                        ['Colorado', 18],
                        ['Connecticut', 43],
                        ['Delaware', 45],
                        ['District of Columbia', 51],
                        ['Florida', 33],
                        ['Georgia', 32],
                        ['Hawaii', 50],
                        ['Idaho', 2],
                        ['Illinois', 12],
                        ['Indiana', 13],
                        ['Iowa', 11],
                        ['Kansas', 20],
                        ['Kentucky', 22],
                        ['Louisiana', 28],
                        ['Maine', 40],
                        ['Maryland', 35],
                        ['Massachusetts', 41],
                        ['Michigan', 7],
                        ['Minnesota', 5],
                        ['Mississippi', 29],
                        ['Missouri', 21],
                        ['Montana', 3],
                        ['Nebraska', 19],
                        ['Nevada', 16],
                        ['New Hampshire', 39],
                        ['New Jersey', 44],
                        ['New Mexico', 24],
                        ['New York', 37],
                        ['North Carolina', 47],
                        ['North Dakota', 4],
                        ['Ohio', 14],
                        ['Oklahoma', 26],
                        ['Oregon', 8],
                        ['Pennsylvania', 36],
                        ['Rhode Island', 42],
                        ['South Carolina', 48],
                        ['South Dakota', 10],
                        ['Tennessee', 30],
                        ['Texas', 25],
                        ['Utah', 17],
                        ['Vermont', 38],
                        ['Virginia', 46],
                        ['Washington', 1],
                        ['West Virginia', 34],
                        ['Wisconsin', 6],
                        ['Wyoming', 9]];
    for (var index = 0; index < state_array.length; index++) {
        if (state_array[index][0] == state_name) {
            return state_array[index][1];
        }        
    }
}
