var main_init = function()
{
    evokeModalDialog.eventLoad();
    query_init();
    tab_init();	
    Custom.init();
    video_init();
    validate_init();
    interstitial_init();
    email_page_init();
    print_init();
    text_size_persist();
    slide_select_init();
}

var query_init = function() {
    var pre_open = getQueryValue("pop");
    if(pre_open != "") {
        if (pre_open == "ra_video") {
            var vid = getQueryValue("video");   
            try {       
                pop_ratalks_video(vid);
            }  catch(e) {
                //alert("error popping RA Talks videos");
            }  
        }    
    }     
}

var tab_init = function()
{
    $("ul.tab_list li").each( function()
    {	
        //alert (this.id);
        $(this).click(show_tab);
        if($(this).hasClass('active'))
        {	
            $(this).click();
        }
    });
}

var show_tab = function()
{
    //alert (this.id);
    $("ul.tab_list li").each( function()
    {	
        if($(this).hasClass('active'))
        {
            $(this).removeClass('active');
        }
    });
    $(this).addClass('active');
    
    $("div.tab_area").each( function()
    {	
        if($(this).hasClass('active'))
        {
            $(this).removeClass('active');
        }
    });
    $("div#" + this.id + "_area").addClass('active');
}

// function to capture all styled form element clicks
var styleFormChecked = function(element) {
    //alert(element.id + "-" + element.checked + "-" + element.name);

    if (element.id.indexOf("cb_enbrel_treatment") > -1) toggleTreatmentDiv(element);
    if (element.id.indexOf("cb_enbrel_sup_treatment") > -1) toggleSupportTreatmentDiv(element);
    if (element.id.indexOf('psa_doc') > -1) togglePSATreatment(element);
    if (element.id.indexOf('cb_select_cond') > -1) set_cond(element);
}

var togglePSATreatment = function(el)
{
        toggle_psa_meds(el.value);
}

var toggleTreatmentDiv = function(el)
{
	var ind = $('input[name="frm_sel_indication"]').val();
        //var ind = document.forms['indication'].indication.value;
	var frm = 'div#dyn_' + ind + '_form';
	
	if (el.value == 'Y') 
	{
		$(frm + ' tr.enbrel_treatment_formdiv').show();
		req_form_status = "taking";
	} 
	else
	{
		$(frm + ' tr.enbrel_treatment_formdiv').hide();
		req_form_status = "nottaking";
	}
}

var toggleSupportTreatmentDiv = function(el)
{
	var ind = $('input[name="frm_sel_indication"]').val();
        //var ind = document.forms['indication'].indication.value;
	var frm = 'div#dyn_' + ind + '_form';

	if (el.value == 'Y') 
	{
		$(frm + ' tr.enbrel_treatment_treatstart').show();
		$(frm + ' tr.enbrel_treatment_nottaking').hide();
		sup_form_status = "taking";
	} 
	else
	{
		$(frm + ' tr.enbrel_treatment_treatstart').hide();
		$(frm + ' tr.enbrel_treatment_nottaking').show();
		sup_form_status = "nottaking";
	}	
}

var print_init = function()
{
    $('ul#utility_nav li.print').click(function() {
        window.print();
    });
}
var textStatus = "small";

var textSizeArray = new Array(11,12,14,16);
var defaultSizeIndex = 1;
var containerDiv = "pageContent";
//document.cookie = "textSizeCookie=1; 0; path=/"
var text_size = function(direction) {
    if(direction == 'up')
    {
        set_text_size(currentSizeIndex + 1);
    }
    else if(direction == 'down')
    {
        set_text_size(currentSizeIndex-1);
    }
}

var set_text_size = function( sizeIndex )
{
    if (sizeIndex > textSizeArray.length - 1)
    {
        sizeIndex = textSizeArray.length - 1;
    }
    else if (sizeIndex < 0)
    {
        sizeIndex = 0;
    }
    var text_container = false;
    if (document.getElementById(containerDiv) != null) {
        text_container = document.getElementById(containerDiv);
        text_container.style.fontSize = textSizeArray[sizeIndex] + "px";
        currentSizeIndex = sizeIndex;
        document.cookie = "textSizeCookie=" + sizeIndex + "; 0; path=/";
    }
}

var text_size_persist = function()
{
    $('ul#utility_nav li.size_icons a.size_up').click(function()
    {	
        text_size("up");
    });
    $('ul#utility_nav li.size_icons a.size_dn').click(function()
    {
        text_size("down");
    });
    c_start = (document.cookie.indexOf("textSizeCookie=")) + 15;
    size = document.cookie.substring(c_start);
    if(isNaN(size))
    {
        currentSizeIndex = defaultSizeIndex;
    }
    else
    {
        size = parseInt(size);
        //alert (isNaN(0));
        if(isNaN(size))
        {
            currentSizeIndex = defaultSizeIndex;
        }
        else
        {
            currentSizeIndex = size;
        }
    }
    set_text_size(currentSizeIndex);	
}

/* pass in name to get value */
var getQueryValue = function( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return "";
    else
        return results[1];
}

var condi_rice = function() {
    indy = 'no';
    maindiv = $('div#container');
    if (maindiv.hasClass('PSO')) {
            indy = 'pso';
    }
    else if (maindiv.hasClass('PSA')) {
            indy = 'psa';
    }
    else if (maindiv.hasClass('RA')) {
            indy = 'ra';
    }
    else if (maindiv.hasClass('AS')) {
            indy = 'as';
    }
    else if (maindiv.hasClass('JIA')) {
            indy = 'jia';
    }
    return indy;
}

jQuery().ready(main_init);
