if( !console ) { var console = { log: function(msg) { alert(msg); } } }

/*js-to-flash*/
function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}
function collectText() {
    getFlashMovie("sotester").hidePollenCounter();
}
/*end*/

/*pollen counter*/
var pc_zip;
var COOKIE_NAME = 'zip_code';

function pollenCounterCookie(pc_zip){
    $.cookies.set(COOKIE_NAME, pc_zip, { expires: 7 });
}
function pollenCounterGet(sendziptoflash) {
    var text = sendziptoflash;
    getFlashMovie("sotester").testFunction();
    getFlashMovie("sotester").pollenCounterZip(text);
}
/*end*/

/*
var slide;
var num = 1;

var sliderIntervalId = setInterval ( "rotateSlideShow(slide)", 5000 );

function setIntervalAnimationTime(){
    setInterval ( "rotateSlideShow(slide)", 5000 );
}
function clearIntervalAnimationTime(){
    clearInterval(sliderIntervalId);
}

function rotateSlideShow(slide)
{
    if (slide == null){ slide = num; }
    var numOfSlide = $('.pagination li img').length;
    if(slide < numOfSlide){
        //console.log("slide",slide)
        $('.pagination li img:lt(3)').each(function(r,img){
            var thisImgSrc = $(img).attr('src');
            $(img).removeClass("active");
            if (thisImgSrc.match(/_on\.gif/i) && !$(img).hasClass('active')) {
                $(img).attr('src', thisImgSrc.replace(/_on.gif/i, ".gif"));
            }//if condition
        });//change to off
        var thisImg = $('.pagination li img').eq(slide);
        var thisImgSrc = $('.pagination li img').eq(slide).attr('src');
        if (!thisImgSrc.match(/_on\.(.+)$/i)){
            $(thisImg).addClass("active");
            $(thisImg).attr('src', thisImgSrc.replace(/\.gif/i, "_on.gif"));
        }//if condition

        if(slide > 0){$('.pagination .back').empty().append("Back"); $('.pagination .next').empty().append("Next"); }
        if(slide <= 0){$('.pagination .back').empty().append("&nbsp;"); $('.pagination .next').empty().append("Next"); }
        if((slide+1) >= (numOfSlide)){ $('.pagination .next').empty().append("&nbsp;"); }

        var slidePosition = (slide) * 640;
        if(slide == numOfSlide){
            var slidePosition = 0;
            $('.symptomsSlider .slide-container').stop().animate({left:"-"+slidePosition+"px"}, { easing:"swing" });
        } else {
            $('.slide-container').stop().animate({left:"-"+slidePosition+"px"}, {easing:"swing"});
        }
    }
    if(slide == numOfSlide){ num = -1; }
    num = num + 1;
}
*/
/* this is 0.3 (Tell a Friend) */
function tell(){
    document.getElementById("fill_thanks").style.display="none";//reset
    t = document.getElementById("tell_friend")
    if (t.style.display!="block"){
        t.style.position="absolute";
        t.style.display="block";
        t.style.top=($('.btn_tell').offset().top - 548)+"px";
        t.style.left=($('.btn_tell').offset().left)+"px";
    } else {
        t.style.display="none";
    }

    document.getElementById("fill").style.display="block";

}
/* this is 0.3.1 */
function tell_thanks(){
    document.getElementById("fill").style.display="none";
    document.getElementById("fill_thanks").style.display="block";
}

/*Tell a friend for ALLERGIES*/
function tell_AR(){
    document.getElementById("fill_thanks_AR").style.display="none";//reset
    t = document.getElementById("tell_friend_AR")
    if (t.style.display!="block"){
        t.style.position="absolute";
        t.style.display="block";
        t.style.top=($('.btn_tell').offset().top - 548)+"px";
        t.style.left="0px";
    } else {
        t.style.display="none";
    }

    document.getElementById("fill_AR").style.display="block";

}
/* this is 0.3.1 */
function tell_thanks_AR(){
    document.getElementById("fill_AR").style.display="none";
    document.getElementById("fill_thanks_AR").style.display="block";
}

$(document).ready(function(){
    $(".tabMenu").each(function(i,ele){
        var menuHeight = $(ele).height()+16;
        $(ele).css({marginBottom: "-"+(menuHeight-37)+"px" })

    });
    $(".tabMenu").hover(
            function() {
                var homeFlash = $().find('.homeMovies').length;
                if(homeFlash){
                    collectText();
                }
                var thisImgSrc = $(this).find("img").attr('src');
                if (!thisImgSrc.match(/_on\.(.+)$/i)){
//                    $(this).find("img").attr('src', thisImgSrc.replace(/\.(.+)$/i, "_on.$1"));
                    $(this).find("img").attr('src', thisImgSrc.replace(/\.(?!.*\.)/,"_on."));
                }
                $(this).addClass("over");
                $(this).stop().show().stop().animate({bottom: ($(this).height()-28)+'px'}, {duration:150, easing:"swing"});
            },
            function() {
                var thisImgSrc = $(this).find("img").attr('src');
//                if (thisImgSrc.match(/_on\.gif/i) && !$(this).hasClass('active')) {
                if (thisImgSrc.match(/_on\.(gif|jpg|jpeg|png)/im) && !$(this).hasClass('active')) {

                    $(this).find("img").attr('src', thisImgSrc.replace(/\_on.(.+)$/i, ".$1"));
                }
                $(this).removeClass("over");
                $(this).stop().show().stop().animate({bottom: 0+'px'}, {duration:110, easing:"swing"});
            }
    );

    var threeColumnsContainers = $().find(".threeColumnsContainers").length;
    if(threeColumnsContainers){
        if ($('.box').length%2) {
            //$('*.box').css("marginRight","0px")
            $("<br clear='all' />").insertAfter('*.box:nth-child(3)');
        }
        else {
            $('*.box').css("marginRight","7px")
            $("<br clear='all' />").insertAfter('*.box:nth-child(2)');
        }

    }
    /*triggers slide*/
    $(".pagination li img").click(function(e){
        $('.pagination li img').each(function(r,img){
            $(img).removeClass('active');
            var thisImgSrc = $(img).attr('src');
            if (thisImgSrc.match(/_on\.jpg/i)) {
                $(img).attr('src', thisImgSrc.replace(/_on.jpg/i, ".jpg"));
            }//if condition
        });//change to off
        $(this).addClass('active');
        $(".pagination li img").each(function(j,ele){
            if( j != 3 ){
                if($(ele).hasClass('active')){ clearInterval(sliderIntervalId); rotateSlideShow(j); }
            }
        })
    });

    $(".pagination .back").click(function(){
        $(".pagination li img").each(function(i,ele){
            if($(ele).hasClass("active")){
                 clearInterval(sliderIntervalId); rotateSlideShow(i-1);
            }
        });
    });
    $(".pagination .next").click(function(){
        $(".pagination li img").each(function(i,ele){
            if($(ele).hasClass("active")){
                 clearInterval(sliderIntervalId); rotateSlideShow(i+1);
                return false;
            }
        });
    });
    /*end*/
    /*once-a-day tabs layout; find div
    if($().find("#onceADayTabs").length){
        $("#onceADayTabs").tabs({
            select: function(event, ui) {
                var findActiveTab = $(this).find('.ui-state-active img');
                var thisImgSrc = $(findActiveTab).attr('src');
                if (thisImgSrc.match(/_on\.gif/i)) {
                    $(findActiveTab).attr('src', thisImgSrc.replace(/_on.gif/i, ".gif"));
                }//if condition
            },
            show: function(event, ui) {
                var findCurentTab = $(ui.tab).find("img");
                var thisImgSrc2 = $(findCurentTab).attr('src');
                $(findCurentTab).attr('src', thisImgSrc2.replace(/\.gif/i, "_on.gif"));
            }

        });
    }
    /*end*/

    /*rmi*/
    if( $("input[name='chk_email']:checked").length ) { $('.emailFormRow').show(); }
    $("input[name='chk_email']:checkbox").click(function(i,ele){
        $('.emailFormRow').toggle();
    });
    if( $("input[name='chk_mail']:checked").length ) { $('.mailFormRow').show(); }
    $("input[name='chk_mail']:checkbox").click(function(i,ele){
        $('.mailFormRow').toggle();
    });
    /*end*/

}); //main document

/* 6.0 special offer */



$(document).ready(function(){
    $('.errormsg').hide();

    var formLen = document.forms.length;
    for( var i = 0; i < formLen; i++){
        document.forms[i].reset();
    }

    $('.offer-back1').click(function(){
        $('.error1').hide();
        $('input[name=submit_special]').removeAttr('disabled');
        $('#how_pay input[name=pay_prescriptions]').removeAttr('disabled');
        $('#how_fill input[name=choose_prescriptions]').removeAttr('disabled');
        $('#select_state_form').attr('value', '');
        return false;
    });

    $('.offer-back2').click(function(){
        $('.error2').hide();
        $('input[name=submit_special]').removeAttr('disabled');
        $('#select_state_form').removeAttr('disabled');
        $('#how_fill input[name=choose_prescriptions]').removeAttr('disabled');
        $('#how_pay input[name=pay_prescriptions]').attr('checked', false);
        return false;
    });

    $('.offer-back3').click(function(){
        $('.error3').hide();
        $('input[name=submit_special]').removeAttr('disabled');
        $('#select_state_form').removeAttr('disabled');
        $('#how_pay input[name=pay_prescriptions]').removeAttr('disabled');
        $('#how_fill input[name=choose_prescriptions]').attr('checked', false);
        return false;
    });

    $('#select_state_form').removeAttr('disabled');
    $('#how_pay input[name=pay_prescriptions]').removeAttr('disabled');
    $('#how_fill input[name=choose_prescriptions]').removeAttr('disabled');
    $('input[name=submit_special]').removeAttr('disabled');

    $('#select_state_form').change(function(){
        if ($(this).val() == 'CO'){
            $('.error1').show();
            $('input[name=submit_special]').attr('disabled', true);
            $('#how_pay input[name=pay_prescriptions]').attr('disabled', true);
            $('#how_fill input[name=choose_prescriptions]').attr('disabled', true);
        } else if ($(this).val() == 'MA'){
            $('.error1').show();
            $('input[name=submit_special]').attr('disabled', true);
            $('#how_pay input[name=pay_prescriptions]').attr('disabled', true);
            $('#how_fill input[name=choose_prescriptions]').attr('disabled', true);
        } else if ($(this).val() == 'ME'){
            $('.error1').show();
            $('input[name=submit_special]').attr('disabled', true);
            $('#how_pay input[name=pay_prescriptions]').attr('disabled', true);
            $('#how_fill input[name=choose_prescriptions]').attr('disabled', true);
        } else {
            $('.error1').hide();
            $('input[name=submit_special]').removeAttr('disabled');
            $('#how_pay input[name=pay_prescriptions]').removeAttr('disabled');
            $('#how_fill input[name=choose_prescriptions]').removeAttr('disabled');
        }
    });

    $('#how_pay input[name=pay_prescriptions]').click(function(){
        if($('#govt_ins').is(':checked')) {
            $('.error2').show();
            $('input[name=submit_special]').attr('disabled', true);
            $('#select_state_form').attr('disabled', true);
            $('#how_fill input[name=choose_prescriptions]').attr('disabled', true);
        } else {
            $('.error2').hide();
            $('input[name=submit_special]').removeAttr('disabled');
            $('#select_state_form').removeAttr('disabled');
            $('#how_fill input[name=choose_prescriptions]').removeAttr('disabled');
        }
    });
    $('#how_fill input[name=choose_prescriptions]').click(function(){
        if($('#mail_order').is(':checked')) {
            $('.error3').show();
            $('input[name=submit_special]').attr('disabled', true);
            $('#select_state_form').attr('disabled', true);
            $('#how_pay input[name=pay_prescriptions]').attr('disabled', true);
        } else {
            $('.error3').hide();
            $('input[name=submit_special]').removeAttr('disabled');
            $('#select_state_form').removeAttr('disabled');
            $('#how_pay input[name=pay_prescriptions]').removeAttr('disabled');
        }
    });


    // RMI Age error

    $('.rmi-age-error').hide();
    $('#rmi-no').click(function(){
        $('.rmi-age-default').hide();
        $('.rmi-age-error').show();
        return false;
    });
    $('.rmi-age-back').click(function(){
        $('.rmi-age-default').show();
        $('.rmi-age-error').hide();
        return false;
    });

});

/*
function validateSpecial()
{
    var select_state = document.myForm.state
    if (select_state.selectedIndex == 0)
    {
        alert("Please select a state.");
        return false;
    }

    var pay_check = $("input[name=pay_prescriptions]")
        if (!pay_check[0].checked && !pay_check[1].checked && !pay_check[2].checked)
            {   // no radio button is selected
                alert("Please answer question 2.");
                return false;
            }

    var choose_check = $("input[name=choose_prescriptions]")
        if (!choose_check[0].checked && !choose_check[1].checked)
            {   // no radio button is selected
                alert("Please answer question 3.");
                return false;
            }


}
*/

function validateAbove() {

    // if final message is still "" then there was no error
        // each check will add to the message of specific error
        var message = "";
        var obj = document.myForm; // assign form

        if (obj.state.selectedIndex == 0) { message += "Please select a state.\n"; } // check field 1
        if ((obj.pay_prescriptions[0].checked == false) && (obj.pay_prescriptions[1].checked == false) && (obj.pay_prescriptions[2].checked == false)) { message += "Please answer question 2.\n"; } // check field 4
        if (obj.choose_prescriptions[0].checked == false) { message += "Please answer question 3.\n"; }

        // final message
        if (message == "")
        {
            return true; // no error - submit form as button intended
        }
        else
        {
            alert(message); // error - show message and don't submit form
            return false;
        }
}

function validateSpecial()
{
    var error = 0
    var obj = document.myForm;

    if (obj.state.selectedIndex == 0) { error = 1; }
    if (obj.state.selectedIndex == 6) { error = 1; }
    if (obj.state.selectedIndex == 23) { error = 1; }
    if ((obj.pay_prescriptions[0].checked == false) && (obj.pay_prescriptions[2].checked == false)) { error = 1; }
    if (obj.choose_prescriptions[0].checked == false) { error = 1; }

    if (error == 0) {
        document.getElementById('submit-img').src = "/montelukast_sodium/consumer/allergies_v2/images/buttons/btn_submit.jpg";
    }
    else {
        document.getElementById('submit-img').src = "/montelukast_sodium/consumer/allergies_v2/images/buttons/btn_submit_inactive.jpg";
    }
}


//validate 18 years old

$(document).ready(function(){
    $('#error-div').hide();
    $('.error-p').hide();
    $('.error-ls').hide();

});

