var copay_service_url = SITEROOT  + "/webservices/soapservicecopay";
var loader = SITEROOT + "/images/shell/loader2.gif";		

var stream = "";
var base_stream = "";
var step = "";
var pcardid = "";

var a_lert = function(msg) {
    //a_lert('a_lert: ' + msg);
}

var rfTrack = function(rfCode) {    // Razorfish tracking
    var rf_scr=document.createElement('script');
    var proto = window.location.protocol;
    rf_scr.setAttribute('src',proto+'//view.atdmt.com/jaction/'+rfCode);
    document.getElementsByTagName('head')[0].appendChild(rf_scr);
}

$.fn.clearForm = function() {
    $('.error_container').removeClass('error_on');
    var inputs = this.find('input');
    return inputs.each(function() {
        var type = this.type;
        var tag = this.tagName.toLowerCase();
        if (type == 'text' || type == 'password' || tag == 'textarea') {
            this.value = '';
        } else if (type == 'checkbox' || type == 'radio') {
            this.checked = false;
            $(this).prev('.radio, .checkbox').css('background-position','0px 0px')
        } else if (tag == 'select') {
            this.selectedIndex = -1;
        }
    });
};

var resetForm = function(formid) {
    $('#' + formid).clearForm();
}

var showStream = function(strm) {
    a_lert('showStream : ' + strm);
    $('.'+strm+'Stream').show();
    $('#'+strm+'Header').show();
    $('#'+strm+'HeaderStep2').show();
}

var showContinuum = function(step) {
    a_lert('showContinuum step : ' + step);
    $("div[id^='continuumStep']").not('div#continuumStep'+step).hide();
    $('div#continuumStep'+step).show();
    $('#breadCrumbs').removeClass();
    $('#breadCrumbs').addClass('step'+step+'On');
    
    if ($('[name=frm_c1_Q_IN_MILITARY]:checked').val() == 'Y') {
        $('#militaryQ1').show();
    }
    
}

var hideContainers = function() {
    $("div[id^='continuumStep']").hide();
    $("div[id^='error_']").hide();
}

var showMessage = function(msg) {
    a_lert('showMessage :' +  msg + " for stream :" + stream);

    hideContainers();
    var msgID = '';
    
    switch(msg) {    
        case 'complete':
            if(stream == 'activate') {
                msgID = 'activateComplete';
            } else if (stream == 'enroll') {
                msgID = 'enrollComplete';
            } else {
                msgID = 'renewComplete';
            }            
            break;
        case 'replace':
            msgID = 'replaceComplete';
            break;
    
        case 'error':
            if(stream == 'activate' || stream == 'activate_retry') {

                msgID = 'error_invalidCard';

            } else if (stream == 'eligibility') {

                a_lert("error in enroll: will show error_notEligible");
                msgID = 'error_notEligible';

            } else if( stream == 'yourinfo') {

                //should not even go here unless js validation let's it through
                msgID = 'error_accountProblem';
            } else if( stream == 'renew') {

                //should not even go here unless js validation let's it through
                msgID = 'eerror_cardExpired';
            } else if( stream == 'enroll') {
                if( step == 1) {
                    msgID = 'error_notEligible';
                }

            } 
            break;
            
        case 'error_patientalreadyexists':
                a_lert("WILL SHOW error_accountExists");
                msgID = 'error_accountExists';
            break;
    
        default:
            msgID = '';
    }
    
    $('#'+msgID).show();
}


var continuumBegin = function(strm,step) {

    a_lert("BASE_STREAM = " + base_stream);
    a_lert('continuumBegin : [ strm=' + strm + '] step : ' + step);

    if(( strm == "activate") || ( strm == "activate_retry"))
    {
        a_lert("ACTIVATE");
        if( step == 1)
        {  
            a_lert("ACTIVATE:step1");
             call_cardvalidate_service(strm);
        } 
        if( step == 2)
        {  
            a_lert("ACTIVATE:step2");
             call_eligibility_service(strm);
        }
        if( step == 3)
        {  
            a_lert("ACTIVATE:step3");
             call_userinfo_service(strm);
        }

    } else if(strm == "enroll"){
        a_lert("ENROLL");
        if( step == 1)
        {  
            a_lert("ENROLL:step1");
                            step = 1;
                            hideContainers();
                            showStream(strm);   
                            showContinuum(step);                 
        } 
        if( step == 2)
        {  
            a_lert("ENROLL:step2");
             showStream('enroll');   
             showContinuum('2');         
        }
        if( step == 3)
        {  
            a_lert("ENROLL:step3");
             showStream('enroll');   
             showContinuum('3');         
        }


    } else if(( strm == "renew"  ||  strm == "renew_retry")){


        if( step == 1 ) 
        {
            a_lert("ACTIVATE:RENEW:step1");
             call_cardvalidaterenew_service(strm);
        
        }

        if( step == 2 ) 
        {
            a_lert("ACTIVATE:RENEW:step2");
             call_eligibility_service(strm);

        }
        if( step == 3 ) 
        {
            a_lert("ACTIVATE:RENEW:step3");
             call_userinfo_service(strm);
        }
    }else if(strm == "replace"){

  if( step == 1 ) 
        {
            a_lert("ACTIVATE:REPLACE:step1");
             replace_card(strm);
        }
    }
} 




var procForm1 = function() {
        a_lert("procForm1");
         var cardval = $('input#cardID').val();
 try {
        $('#mainForm\\:card_id').val(cardval);
     } catch(error) {
         a_lert('error:' + error);
    }
}


var call_cardvalidate_service = function(strm)
{
        $('div#loader').html("<img src=\"" + loader + "\"\/>"); 

                    a_lert("call_cardvalidate_service strm = " + strm);
                    
                    var val = "";
                    if( strm == "activate")
                    {
                        a_lert('will get cardid val');
                        //set propagate cardid to next step which is eigibility : set_v_card()
                        val = $('input#cardID').val();
                        pcardid = val;

                        a_lert('will asign to frm_c2_Q_CARD_ID this value from pcardid : ['+pcardid + ']');

                        $('input#frm_c2_Q_CARD_ID').val(pcardid);

                    } else { 
                        a_lert('will get cardIDRetry val');
                        val = $('input#cardIDRetry').val();


                        pcardid = val;
                        a_lert('will asign to frm_c2_Q_CARD_ID this value: from pcardid : ' + pcardid + ']');
                        $('input#frm_c2_Q_CARD_ID').val(pcardid);

                    }
                    a_lert("val : " + val);
                        $('input#cardID1').value = "test";


                    var paramset ="cardid=" + val;
                    var q = "?activity_type=validatecard&base_stream=" + base_stream + "&step=1&" + paramset;
                    //a_lert("will call this url :" + copay_service_url + q);
                    //$.getJSON(copay_service_url + q,function(data) {
                    $.getJSON(copay_service_url+ q,function(data){

                         $('div#loader').html(""); 

                        var status_obj = data.meta_header;
                        
                        if( status_obj.status_code == 0) {
                            hideContainers();
                            showStream('activate');   
                            showContinuum('1');                 
                        }else {                
                        a_lert("status code =" +  status_obj.status_code);
                        a_lert("status message =" +  status_obj.status_qualification);
                            a_lert("bad cardid");
                            $('input#cardID').val(val);
                                pcardid = val;
                            showMessage("error");

                        }
                  });    
}


var replace_card = function(strm)
{
                    a_lert('replace_card');

                    var val_card = "";
                    var val_phone = "";
                    var val_dob = "";
                    a_lert('STRM : ' + strm);
                    if( strm == "replace")
                    {
                        a_lert('will get cardid , phone and dob');
                        //set propagate cardid to next step which is eigibility : set_v_card()
                        val_card = $('input#cardIDReplace').val();
                        val_phone = $('input#cardPhone1Replace').val() + $('input#cardPhone2Replace').val() + $('input#cardPhone3Replace').val();
                        val_dob = $('input#cardDOB1Replace').val() + "/" + $('input#cardDOB2Replace').val() + "/" + $('input#cardDOB3Replace').val();
                        pcardid = val_card;
    
                    } else { 
                        a_lert('will get cardIDRepalceRetry val');
                        val_card = $('input#cardIDReplaceRetry').val();
                        val_phone = $('input#cardPhone1ReplaceRetry').val() + $('input#cardPhone2ReplaceRetry').val() + $('input#cardPhone3RenewRetry').val();
                        val_dob = $('input#cardDOB1ReplaceRetry').val() + "/" + $('input#cardDOB1ReplaceRetry').val() + "/" + $('input#cardDOB1RenewRetry').val();
                        pcardid = val_card;
                    }
                    a_lert("val_card : " + val_card);
                    a_lert("val_phone : " + val_phone);
                    a_lert("val_dob : " + val_dob);

                    $("div#cardnum").html(val_card);
                    $("div#cardnum").val(val_card);

                    var paramset ="cardid=" + val_card;
                    var q = "?activity_type=replace&phone=" + val_phone + "&dob=" + val_dob + "&base_stream=" + base_stream + "&step=1&" + paramset;
                    //a_lert("will call this url :" + copay_service_url + q);
                    //$.getJSON(copay_service_url + q,function(data) {
                    $.getJSON(copay_service_url+ q,function(data){
                        var status_obj = data.meta_header;
                        //a_lert("status code =" +  status_obj.status_code);
                        //a_lert("status message =" +  status_obj.status_qualification);
     
     
                        if( status_obj.status_code == 0) {
                           // a_lert("status code =" +  status_obj.status_code);
                            step = 1;
                            a_lert('success?');
                            a_lert('cardid from ui=' + pcardid);
                            pcardid = status_obj.status_qualification; //this is the card id
                            a_lert('cardid from service=' + pcardid);
                            $('span#precardid').html(pcardid);

                            showStream('replaceComplete');   
                            
                        }else {                
                            a_lert("bad cardid");
                           //showMessage("error");
                            hideContainers();
                            a_lert("will show error_accountProblem");
                            
                            $('div#replaceComplete').hide();
                            $('div#error_accountProblem').show();
                        }
                    
                  });    
}



var call_cardvalidaterenew_service = function(strm)
{
                    a_lert("call_cardvalidaterenew_service ");
  
                    var val_card = "";
                    var val_phone = "";
                    var val_dob = "";

                    if( strm == "renew")
                    {
                        a_lert('will get cardid , phone and dob');
                        //set propagate cardid to next step which is eigibility : set_v_card()
                        val_card = $('input#cardIDRenew').val();
                        val_phone = $('input#cardPhone1Renew').val() + $('input#cardPhone2Renew').val() + $('input#cardPhone3Renew').val();
                        val_dob = $('input#cardDOB1Renew').val() + "/" + $('input#cardDOB2Renew').val() + "/" + $('input#cardDOB3Renew').val();
                    } else { 
                        a_lert('will get cardIDRenewRetry val');
                        val_card = $('input#cardIDRenewRetry').val();
                        val_phone = $('input#cardPhone1RenewRetry').val() + $('input#cardPhone2RenewRetry').val() + $('input#cardPhone3RenewRetry').val();
                        val_dob = $('input#cardDOB1RenewRetry').val() + "/" + $('input#cardDOB2RenewRetry').val() + "/" + $('input#cardDOB3RenewRetry').val();
                    }
                        pcardid = val_card;
                    
                    
                   $('input#frm_c2_Q_CARD_ID').val(pcardid);
                    
                    a_lert("val_card : " + val_card);
                    a_lert("val_phone : " + val_phone);
                    a_lert("val_dob : " + val_dob);

                    var paramset ="cardid=" + val_card;
                    var q = "?activity_type=validatecardrenew&phone=" + val_phone + "&dob=" + val_dob + "&base_stream=" + base_stream + "&step=1&" + paramset;
                    a_lert("will call this url :" + copay_service_url + q);
                    //$.getJSON(copay_service_url + q,function(data) {
                    $.getJSON(copay_service_url+ q,function(data){
                        var status_obj = data.meta_header;
                        //a_lert("status code =" +  status_obj.status_code);
                        //a_lert("status message =" +  status_obj.status_qualification);
     
                        //force if mckesson services are down:     status_obj.status_code = 0;
                        if( status_obj.status_code == 0) {
                           // a_lert("status code =" +  status_obj.status_code);
                            pcardid = status_obj.status_qualification; //this is the card id
                            a_lert("pcardid after validation=" +pcardid);
                            hideContainers();
                            step = 1;
                            showStream('renew');   
                            showContinuum('1');                 

                        }else {                
                            a_lert("status code =" +  status_obj.status_code + " : status message = " + status_obj.status_qualification);
                            a_lert("bad cardid");
                            $('input#cardIDRenew').val(val_card);
                            pcardid = val_card;
                            //showMessage("error");
                            hideContainers();


                            $('div#error_cardExpired').show();
                        }
                    
                  });    

}



var call_eligibility_service = function(strm)
{
            a_lert('PCARDID so far = ' + pcardid);

            a_lert("strm=" + strm);
            a_lert('call_eligibility_service');

            var copayfield = get_copay_fields("frm_c1");
            a_lert("copay field"+copayfield);
            var paramset = "cardid=" + pcardid +"&"+copayfield;           
            var q = "?activity_type=eligibility&step=2&base_stream=" + base_stream + "&" + paramset;
            a_lert("will call this url paramset:"  + q);
            $.getJSON(copay_service_url+ q,function(data){
            //a_lert('CALLBACK inline function for eligibility');
            var status_obj = data.meta_header;
            //a_lert("status code =" +  status_obj.status_code);
            //a_lert("status message =" +  status_obj.status_qualification);
            
            if( status_obj.status_code == 0 ) {
                showStream(strm);
                showContinuum('2');              
            }else {                
                a_lert("not eligibile - will show error state");
                hideContainers();
                a_lert("will show error_notEligible");
                $('div#error_notEligible').show();
            }
        
      });    
}


var call_userinfo_service = function(strm)
{
   a_lert('call_userinfo_service ');
   a_lert('BASE STREAM = ' + base_stream);
   a_lert(' PCARDID so far = ' + pcardid);

     var cardval = $('input#cardID').val();
     a_lert(" cardval = " + cardval);
     try {
        $('#mainForm\\:card_id').val(pcardid);
     } catch(error) {
         a_lert('error:' + error);
     }
            a_lert("strm=" + strm);

            //--: get eligibility fields again for inclusion in yourinfo step
            var copayfield_eligibility = get_copay_fields("frm_c1");
            
            //--: get yourinfo form elements
            var copayfield_enroll = get_copay_fields("frm_c2");

            var paramset = "";
            var q ="";
                a_lert("BASE STREAM = " + base_stream);
            if(base_stream == "activate") {
                paramset = "base_stream=" + base_stream + "&" + copayfield_enroll + "&" + copayfield_eligibility;           
                q = "?activity_type=enrollment&step=3&" + paramset;
            } else if (base_stream == "renew") {
                paramset = "frm_c2_Q_CARD_ID=" + pcardid + "&cardid=" + pcardid + "&base_stream=" + base_stream + "&" + copayfield_enroll + "&" + copayfield_eligibility;           
                q = "?activity_type=updateaccount&step=3&" + paramset;
                a_lert("q=" + q);
            }  else if (base_stream == "enroll") {
                paramset = "base_stream=" + base_stream + "&" + copayfield_enroll + "&" + copayfield_eligibility;           
                q = "?activity_type=enrollment&step=3&" + paramset;
            }

            var v_areacode = $('input#frm_c2_Q_PHONE_AREACODE').val();
            var v_phonepart1 = $('input#frm_c2_Q_PHONE_PART1').val();
            var v_phonepart2 = $('input#frm_c2_Q_PHONE_PART2').val();
            var frm_c2_Q_PHONE =  v_areacode + v_phonepart1 +v_phonepart2;
            q += "&frm_c2_Q_PHONE=" +  frm_c2_Q_PHONE;
            var v_bdmm = $('input#frm_c2_Q_DOB_MM').val();
            var v_bdd = $('input#frm_c2_Q_DOB_DD').val();
            var v_bdyyy = $('input#frm_c2_Q_DOB_YYYY').val();
            var frm_c2_Q_DOB =  v_bdmm + "/"+v_bdd +"/"+v_bdyyy;
            
            q += "&frm_c2_Q_DOB=" +  frm_c2_Q_DOB;
            
            var v_smm = $('input#frm_c2_Q_STARTDATE_MM').val();
            var v_sdd = $('input#frm_c2_Q_STARTDATE_DD').val();
            var v_syyy = $('input#frm_c2_Q_STARTDATE_YYYY').val();
            var frm_c2_Q_ENBREL_START_DATE =  v_smm + "/"+v_sdd +"/"+v_syyy;
            q += "&frm_c2_Q_ENBREL_START_DATE=" +  frm_c2_Q_ENBREL_START_DATE;

            a_lert(" will call this service url with paramset :"  + q);
            $.getJSON(copay_service_url+ q,function(data) {

            a_lert('callback inline function for yourinfo');
            var status_obj = data.meta_header;
            a_lert("status code =" +  status_obj.status_code + " status message =" +  status_obj.status_qualification);

            if( status_obj.status_code == 0) {
                if((pcardid == "") || (pcardid == "empty") || (pcardid == null)) {
                    pcardid = status_obj.status_qualification;
                }

                a_lert("NEW CARD ID =" +  pcardid);
                a_lert("status code =" +  status_obj.status_code);
                $('div#error_alreadyActivated"').hide();                    
                a_lert('showStream : ' + 'activateComplete');
                 $('div#activateComplete').show();
                showContinuum('3');        
                 a_lert('Card id at this point is  = '+pcardid);
                 try {
                    $('#mainForm\\:card_id').val(pcardid);

                 } catch(error) {
                     a_lert('error:' + error);
                 }
                 
            } else {                

                a_lert("ERROR: cannot enroll/renewal");
                var err_qual = status_obj.status_qualification;
                a_lert("err_qual : " + err_qual);
                
                if( err_qual.substring(0,4) == "E541") {
                    a_lert("E541");
                    showMessage("error_patientalreadyexists");
                } else if( err_qual.substring(0,4) == "E542") {
                    a_lert("E542");
                a_lert("Patient is not eligible to enroll");
                hideContainers();
                $('div#error_alreadyActivated"').show();                    
               } 
                
                
                else {
                a_lert("not enrollable - will show error state");
                hideContainers();
                //--: there should be a different error message that is system related.
                $('div#error_notEligible').show();
                }
            }
        
      });    
 }

var get_copay_fields = function(prefix){

       a_lert("get_copay_fields for group PREFIX=" + prefix);
        var serialized_frm = "";
        var delimiter = "&";
        inputs = document.getElementsByTagName("input");
        for (var b = 0; b < inputs.length; b++) {
            
           if( inputs[b].name.substr(0,6) == prefix) { 
            
                if (inputs[b].type == "hidden" ){
                  //a_lert("hidden : " + inputs[b].name + "=" + inputs[b].value);
                    serialized_frm += delimiter+ inputs[b].name + "=" + inputs[b].value;
               } else  if (inputs[b].type == "text" && inputs[b].value.length > 0){
                    serialized_frm += delimiter + inputs[b].name + "=" + inputs[b].value;
                     //a_lert("adding pair=" + delimiter  +inputs[b].name + "=" + inputs[b].value );
                } else if (inputs[b].type == "checkbox" && inputs[b].checked == true ) {
                    serialized_frm +=  delimiter + inputs[b].name + "=" + inputs[b].value;
                } else if (inputs[b].type == "radio" && inputs[b].checked == true ) {
                    var name = inputs[b].name;
                    serialized_frm +=  delimiter + name + "=" + inputs[b].value;
                   // a_lert("adding pair=" + delimiter  +inputs[b].name + "=" + inputs[b].value );
                }
            }
        }
        selects = document.getElementsByTagName("select");

        for (var b1 = 0; b1 < selects.length; b1++) {
            if( selects[b1].name.substr(0,6) == prefix && selects[b1].selectedIndex > 0) { 
                    var selectitem = selects[b1].options[selects[b1].options.selectedIndex].value
                    serialized_frm +=  delimiter +  selects[b1].name + "=" +selectitem;
                    a_lert("serialized_frm so far=" + serialized_frm);
            }

        }
        return (serialized_frm.substr(1));
}





var submitContinuumStep1 = function() {
    showContinuum('2');
}

var submitContinuumStep2 = function() {
    showMessage('complete');
    showContinuum('3');
}

var supportCard = {
	beginActivation: function(mode) {

            a_lert('mode: ' + mode);
            base_stream = "activate";
            if (validate_activateBegin_form()) {
                
                rfTrack('ifrenb_ENB20100101ActivateSavingsCardStep1_2');                
                copayTrack(base_stream, 'step1_complete');
                
                stream = base_stream;
                step = 1;

                if( mode == 'retry') {
                        pcardid = $('input#cardIDRetry').val();
                        a_lert('pcard id from Retry : ' + pcardid);
                        continuumBegin('activate_retry',step);
                } else {
                        continuumBegin(base_stream,step);
                }
            }
	},

	beginRenewalActivation: function(mode) {
        a_lert('mode: ' + mode);
            base_stream = "renew";



            a_lert("beginRenewalActivation");
            if (validate_renewBegin_form()) {
                stream = base_stream;
                step = 1; 
                if( mode == 'retry') {
                        pcardid = $('input#cardIDRenewRetry').val();
                        a_lert('pcard id from Retry : ' + pcardid);
                        continuumBegin('renew_retry',step);
                } else {
                        continuumBegin(base_stream,step);
                }
            }
	},

	beginActivationInvalidRetry: function() {
            //base_stream = "activate_retry";
            if (validate_activateBegin_form()) {
                a_lert("beginActivationInvalidRetry");
                stream = 'activate_retry';
                step = 1;
                showContinuum('1');                 
                continuumBegin('activate_retry',1);
            }
	},

	beginEligibility: function() {
        
            if (validate_form()) {
                try {
                        a_lert("beginEligibility");
        
                        a_lert("base_stream="  + base_stream);
                        stream = base_stream;
                        step = 2;
                        //continuumBegin('activate',2);
                        if( base_stream == "enroll") {
                            rfTrack('ifrenb_ENB20100101ConsumerSpprtCardEnrollestep_2');                            
                            call_eligibility_service(base_stream);
                        } 
                        if( base_stream == "activate") {
                            rfTrack('ifrenb_ENB20100101ActiviateSavingsCardStep2_2');
                            continuumBegin(base_stream,2);
                        }
                        if( base_stream == "renew") {
                            rfTrack('ifrenb_ENB20100101RenewSavingsCardStep2_2');
                            continuumBegin(base_stream,2);
                        }
                        copayTrack(base_stream, 'step2_complete');
                        
                } catch (error) {
                    a_lert('error:' + error);
                }
            }
	},



	beginYourInfo: function() {
            if (validate_form()) {
                    a_lert("beginYourInfo");
                    stream = base_stream;
                    //stream = 'yourinfo';
                    //continuumBegin('yourinfo');
                    
                    if( base_stream == "enroll") {
                            rfTrack('ifrenb_ENB20100101ConsumerSpprtCardEnrollStep3_2');
                            call_eligibility_service(base_stream);
                        } 
                        if( base_stream == "activate") {
                            rfTrack('ifrenb_ENB20100101ActivateSavingsCardStep3_3');
                            continuumBegin(base_stream,2);
                        }
                        if( base_stream == "renew") {
                            rfTrack('ifrenb_ENB20100101RenewSavingsCardStep3_3');
                            continuumBegin(base_stream,2);
                        }                    
                        copayTrack(base_stream, 'step3_complete');
                    
                     call_userinfo_service(stream);
  
            }      
	},




	beginEnroll: function() {
            
            base_stream = "enroll";
            
                rfTrack('ifrenb_ENB20100101ConsumerSupportCardEnrollste_2');
                copayTrack(base_stream, 'step1_complete');            
            
                a_lert("beginEnroll");
                stream = 'enroll';
                continuumBegin('enroll',1); 
                step = 1;
                continuumBegin(base_stream,step);    
	},

	beginRenew: function() {            
            base_stream = "renew";
                a_lert("beginRenew");
            if (validate_renewBegin_form()) {
                
                rfTrack('ifrenb_ENB20100101RenewSavingsCardStep1_2');
                copayTrack(base_stream, 'step1_complete');  
                
                stream = 'renewal';
                step = 1;
                continuumBegin(base_stream,step);
            }
	},

	beginReplace: function() {
            base_stream = "replace";
                a_lert("beginReplace");
            if (validate_replaceBegin_form()) {
                
                rfTrack('ifrenb_ENB20100101ReplaceCard_2');
                copayTrack(base_stream, 'step1_complete');  
                
                stream = 'replace';
                showMessage('replace');
                replace_card(base_stream);
            }
	}
};


var printCard = function() {
    if (!(printCardWin)) {
        a_lert("CURRENT CARDID=" + pcardid);
        var printCardWin = window.open("content/support-card-print.jspx?cardid=" + pcardid,"print_card_window","toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=600");
    }
    window.scrollTo(0,0);
}

var copay_form_init = function() {

    $("#frm_c1_Q_IN_MILITARY_Y").parent().click(function() {
        $("#militaryQ1").show();
    });
    $("#frm_c1_Q_IN_MILITARY_N").parent().click(function() {
        $("#militaryQ1").hide();
    });    
    
    $('#resetStep1').click(function() {
        resetForm('continuumStep1');
        window.scrollTo(0,0);
    });
    
    $('#resetStep2').click(function() {
        resetForm('continuumStep2');
        window.scrollTo(0,0);
    });

    $('input[name=dob_mon], input[name=start_mon]')
        .css('color','#999999')
        .val('mm');

    $('input[name=dob_day], input[name=start_day]')
        .css('color','#999999')
        .val('dd');

    $('input[name=dob_year], input[name=start_year]')
        .css('color','#999999')
        .val('yyyy');        
            
    $('input#frm_c2_Q_DOB_MM, input#frm_c2_Q_STARTDATE_MM').focus(function() {
         if ($(this).val() == "mm") {
            $(this)
                .css('color','#009999')
                .val('');
         }
    });
    $('input#frm_c2_Q_DOB_MM, input#frm_c2_Q_STARTDATE_MM').blur(function() {
        if ($(this).val() == "") {
            $(this)
                .css('color','#999999')
                .val('mm');
        }
    });
            
    $('input#frm_c2_Q_DOB_DD, input#frm_c2_Q_STARTDATE_DD').focus(function() {
         if ($(this).val() == "dd") {
            $(this)
                .css('color','#009999')
                .val('');
         }
    });
    $('input#frm_c2_Q_DOB_DD, input#frm_c2_Q_STARTDATE_DD').blur(function() {
        if ($(this).val() == "") {
            $(this)
                .css('color','#999999')
                .val('dd');
        }
    });
            
    $('input#frm_c2_Q_DOB_YYYY, input#frm_c2_Q_STARTDATE_YYYY').focus(function() {
         if ($(this).val() == "yyyy") {
            $(this)
                .css('color','#009999')
                .val('');
         }
    });
    $('input#frm_c2_Q_DOB_YYYY, input#frm_c2_Q_STARTDATE_YYYY').blur(function() {
        if ($(this).val() == "") {
            $(this)
                .css('color','#999999')
                .val('yyyy');
        }
    }); 
    
    $('input#frm_c2_Q_DOB_MM, input#frm_c2_Q_STARTDATE_MM')
            .css('color','#999999')
            .val('mm');
    
    $('input#frm_c2_Q_DOB_DD, input#frm_c2_Q_STARTDATE_DD')
            .css('color','#999999')
            .val('dd');  
    
    $('input#frm_c2_Q_DOB_YYYY, input#frm_c2_Q_STARTDATE_YYYY')
            .css('color','#999999')
            .val('yyyy');         
            
}