var req_form_status = "nottaking";
var sup_form_status = "taking";
var sharps_taking_status = "taking";
var sharps_enrolled_status = "enrolled";

var clear_error_states = function() 
{
    $('.error_on').each(function() {
        $(this).removeClass('error_on');
    })
    $('#error_msg').css('display','none');
}

var slide_select_init = function()
{
	 // add click events
	 var current_condition = "";
	if( $("div#main").hasClass("pso")) {
		current_condition = "pso"
	} else if( $("div#main").hasClass("psa")) {
		current_condition = "psa"
	} else if( $("div#main").hasClass("ra")) {
		current_condition = "ra"
	}  else if( $("div#main").hasClass("as")) {
		current_condition = "as"
	}  else if( $("div#main").hasClass("jia")) {
		current_condition = "jia"
	} 
	
	if(current_condition != "")
	{
		if($("img#cond_select_button").length)
		{
			$("img#cond_select_button")[0].src = "/images/shell/slide_selector/selected/" + current_condition + ".gif";
			$('input[name="frm_sel_indication"]').val(current_condition);
			show_complete_form();
		}
	}
	
	 $('div.select_slide a.wide_sel').click(toggle_slide);
	$('div.selectors img').click(set_cond);

	$('a#show_support_details').click(function(e)
	{
		e.preventDefault();
		$('div#support_details').slideToggle('fast');
	});
        
        $('#year_born').focus(function() {
             if ($(this).val() == "yyyy") {
                $(this)
                    .css('color','#009999')
                    .val('');
             }
        });
        $('#year_born').blur(function() {
            if ($(this).val() == "") {
                $(this)
                    .css('color','#999999')
                    .val('yyyy');
            }
        });
}

var toggle_slide = function(event)
{
	$(this).next("div.selectors").slideToggle('fast');
    //validate_init();
    event.preventDefault();
}

var set_cond = function()
{
	//alert(this.id);
/*	$(this).parent().prev("a").children("img")[0].src = "/images/shell/slide_selector/selected/" + this.id + ".gif";*/
	$('input[name="frm_sel_indication"]').val(this.id);
	submit_indication();
/*	$(this).parent().slideToggle('fast')*/
}

var submit_indication = function() 
{
        if($('input[name="frm_sel_indication"]').val() != "")
	{
		show_complete_form();
	}
}

var show_complete_form = function()
{
	ind = $('input[name="frm_sel_indication"]').val()
	
        indXML = ind+'Condition';
        $('input[name="frm_c_med_condition"]').val(indXML);
        //alert(indXML);
        
	$('div#full_form').removeClass();
	$('div#full_form').addClass("gray_container form_container");
	$('div#full_form').addClass($('input[name="frm_sel_indication"]').val() + '_form');
	$('#indication_area').hide();
	$('#full_form').show();

	tbl = $('#dyn_' + ind + '_form table.striped_rows');
	make_form_stripes(tbl);
        
        $('#year_born')
            .css('color','#999999')
            .val('yyyy');

	$('#congratulations_info').hide();
	$('#congratulations_support').hide();
        $('#thanks_safety_info').hide();
	$('#ready_start_saving').show();	
	$('#request_info').show();	
	$('#vibrant_lives_large').hide();
	$('#vibrant_lives_small').show();
        $('#already_taking').show();
        
        var frmName = $('input[name=frm_h_formname]').val();
        var frm = '';
        if (frmName == 'enbrelRequestInformationForm') {
            frm = 'RequestInfo';
        } else if (frmName == 'enbrelSupportProgramForm') {
            frm = 'EnbrelSupport';
        }
        
        formTrack(frm, ind, "select");
        
}
var show_indication_form = function(whichForm)
{        
        clear_error_states();
        $('#indication_area').show();
	$('#full_form').hide();
	$('#congratulations_info').hide();
	$('#congratulations_support').hide();
        $('#thanks_safety_info').hide();
	$('#ready_start_saving').show();	
	$('#request_info').show();	
	$('#vibrant_lives_large').hide();
	$('#vibrant_lives_small').show();
	scroll(0,0);
}

var form_tracking = function(whichForm, event) {
        condClass = $('#full_form').attr('className').match(/[a-z]+_form/);
        cond = new String(condClass);
        cond = cond.replace(/_form/, '');
        
        formTrack(whichForm, cond, event);
}

var submit_requestforinfo = function()
{
//alert("submit_requestforinfo");
   
        condClass = $('#full_form').attr('className').match(/[a-z]+_form/);
        cond = new String(condClass);
        cond = cond.replace(/_form/, '');
        
        $('div#full_form').removeClass();
        //$('div#full_form').addClass(document.forms['indication'].indication.value + '_form');
 
        
        $('#indication_area').hide();
	$('#full_form').hide();
	$('#vibrant_lives_small').hide();
	
	if (req_form_status == 'taking') 
	{
                
                var proto = window.location.protocol;
                
                var rf_scr=document.createElement('script');
                rf_scr.setAttribute('src',proto +'//view.atdmt.com/jaction/ifrenb_ENB20100101ConsumerRequestInfoThankYouE_1');
                document.getElementsByTagName('head')[0].appendChild(rf_scr);

                //rfTrack('ifrenb_ENB20100101ConsumerRequestInfoThankYouE_1');
                form_fields();		
                $('#congratulations_support').show();
	} 
	else
	{
                var proto = window.location.protocol;
                
                var rf_scr=document.createElement('script');
                rf_scr.setAttribute('src',proto +'//view.atdmt.com/jaction/ifrenb_ENB20100101ConsumerRequestInfoThankYouN_3');
                document.getElementsByTagName('head')[0].appendChild(rf_scr);
                
                //rfTrack('ifrenb_ENB20100101ConsumerRequestInfoThankYouN_3');
                form_fields();		                
                $('#congratulations_info').show();
	}
        
        $('#thanks_safety_info').show();
	$('#request_info').hide();	
	$('#vibrant_lives_large').show();
        $('#already_taking').hide();

        formTrack('RequestInfo', cond, 'complete');
        mecTrack('deienb_NEWSignUpThankYou_3');
        
	scroll(0,0);
}

var submit_signupsupport = function()
{
        condClass = $('#full_form').attr('className').match(/[a-z]+_form/);
        cond = new String(condClass);
        cond = cond.replace(/_form/, '');
        
        //document.forms['full_form'].indication.value = document.forms['indication'].indication.value;
	$('div#full_form').removeClass();
        //$('div#full_form').addClass(document.forms['indication'].indication.value + '_form');
	$('#indication_area').hide();
	$('#full_form').hide();
	$('#vibrant_lives_small').hide();
	
	if (sup_form_status == 'taking')
	{
                form_fields();
		$('#congratulations_support').show();
	} 
	else
	{
                form_fields();
		$('#congratulations_info').show();
	}
        $('#thanks_safety_info').show();
	$('#ready_start_saving').hide();	
	$('#request_info').hide();	
	$('#vibrant_lives_large').show();
	
        formTrack('EnbrelSupport', cond, 'complete');
        mecTrack('deienb_NEWEnbrelSupportProgramEnrollment_2');
	
        scroll(0,0);
}

var submit_sharpsContainerForm = function()
{
        formTrack('OrderSharps', '', 'complete');
        $('div#full_form').hide();
        $('div#sharps_container_thanks').show();
        if (sharps_taking_status == "taking" && sharps_enrolled_status == "notenrolled") $('div#sharps_container_signup').show();
}


var toggle_psa_meds = function(doc)
{
	if (doc == "d") {
		$('div#meds_psa_dermonly').show();
		$('div#meds_psa_alldocs').hide();
	} else {
		$('div#meds_psa_dermonly').hide();
		$('div#meds_psa_alldocs').show();
	}
	$('tr.enbrel_treatment_formdiv').hide();
}

var toggle_treatment = function(ind)
{
	$('dyn_'+ind+'_form div#start_enbrel_treatment').show();
}

var make_form_stripes = function(tbl)
{
	row_array = $(tbl).find('tr').not('.enbrel_treatment_treatstart, .enbrel_treatment_nottaking, .enbrel_treatment_formdiv, .header');
	for (i=0; i<row_array.length; i++)
	{
		if (i % 2 != 0) $(row_array[i]).css('background-color','#ebebeb');
	}
}



