﻿var numPages = 4;
this.appData = new AppData();
var topPos = '800';

var strNotAsked = '10009001';  //Question not asked (QNA)


// When the page is reloaded, re-evaluate the inputs so that the continue buttons and divs 
//  are enabled/shown if they should be

addLoadEvent(checkCookie);

/////// COMMON
function addLoadEvent(objFunc) {
  var objOldOnload = window.onload;
  if (typeof window.onload != 'function') {
      window.onload = objFunc;
  } else {
      window.onload = function() {
          if (objOldOnload) {
              objOldOnload();
          }
          objFunc();
      }
  }
}


function setCookie(name,value,days){
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var ck = name+"="+value+expires+"; path=/";
//	if (days != -1) alert('Cookie\n' + ck + '\ncreated');
	document.cookie = ck;
}




//standard image rollover
function imgSwap(img, src1) {
  img.src = src1; 
}
function btnSwap(btn,src) {
  var thisID=btn.id;
  var thisClass=btn.className;
  var thisButton=document.getElementById(btn.id);
  thisClass.indexOf('Over')!=-1 ? thisClass=thisClass.replace('Over','') : thisClass=thisClass+'Over';
  thisButton.className=thisClass;
  return;
}

/////////////common end



/////////////POP up
function getX(e)
{
    var mX = 0
    
    if (IE) {
        var arrScrollXY = getScrollXY();
        mX = event.clientX + arrScrollXY[0]
    } else {  
        mX = e.pageX;
    }  

    if (mX < 0){mX = 0}

    return mX;
}

function getY(e)
{
    var mY = 0
    
    if (IE) {
        var arrScrollXY = getScrollXY();
        mY = event.clientY + arrScrollXY[1]
    } else {  
        mY = e.pageY;
    }  

    if (mY < 0){mY = 0} 
    
    return mY;
}


function openDisplayUtil_position(container, e, addTop, addLeft){
    var popup = document.getElementById(container);
    var mX = getX(e);
    var mY = getY(e);

    var iLeft=76;
    var browserName=navigator.appName;
    if(browserName=="Microsoft Internet Explorer")iLeft=66;

    popup.style.left = addLeft + "px"; 

    popup.style.top = addTop + "px";

    // Show the popup
    popup.style.display = "block";

    switchToPage(5);

    return false;
}


function closeDisplaysUtil(container)
{

    var popup = document.getElementById(container);
    if (popup != null) popup.style.display = "none";
}
////////// end pop up


function writeYearOptions() 
{
    var date = new Date();
    var year = date.getYear();
    if (year < 2000) year = year + 1900;
    
    var options = "";

    for(y=year-98; y<=year-18; y++)
    {
        options += "<option value=\"" + y + "\">" + y + "</option>"
    }
 
    document.write(options);
}


// if the user has already registered, forward them to the success page
// else show the first page of the form
function checkCookie(){
    var thisUser=''; 
    if(thisUser){
        changeVisibility("calloutDeliveryOnline", true);
        if (thisUser == "hcp") {
            window.location = "SignUPConfirm_HCP.aspx"; //not used
        } else if(thisUser && thisUser!="hcp") {
            window.location = "SignUPConfirm_Caregiver.aspx";
        }
    }
    else{
        
        changeVisibility("page1", true);

        checkConditionReceived(); 
        //checkConditionTaking(); 
        //checkTakingAbilify();      
    }
    
    
}


function checkConditionReceived()
{
    if(d("conditionReceived1").checked)
    {
        //alert(d("conditionReceived1").value);
        //changeVisibility("ConditionTaking", true)
        //changeVisibility("ddlConditionTaking", true)
            changeVisibility("Page2", true)
            changeVisibility("ddlHowLongBP", true)
            changeVisibility("ddlHowLongDEP", false)
            changeVisibility("ddlHowLongSZ", false)
            changeVisibility("rblTakingAbilifyBP", true)
            changeVisibility("rblTakingAbilifyDEP", false)
            changeVisibility("rblTakingAbilifySZ", false)
            changeVisibility("TakingMedsBP", true)
            changeVisibility("TakingMedsSZ", false)
            changeVisibility("TakingMedsDEP", false)
            changeVisibility("TakingMedsSetBP", true)
            changeVisibility("TakingMedsSetSZ", false)
            changeVisibility("TakingMedsSetDEP", false)
            changeVisibility("PractitionerBP", true)
            changeVisibility("PractitionerSZ", false)
            changeVisibility("PractitionerDEP", false)
        changeVisibility("Page3", false)
        changeVisibility("Page4", false)
        
        checkTakingAbilify();
    }
    else if(d("conditionReceived2").checked)
    {
        //alert(d("conditionReceived2").value);
        //changeVisibility("ConditionTaking", true)
        //changeVisibility("ddlConditionTaking", true)
            changeVisibility("Page2", true)
            changeVisibility("ddlHowLongBP", false)
            changeVisibility("ddlHowLongDEP", false)
            changeVisibility("ddlHowLongSZ", true)
            changeVisibility("rblTakingAbilifyBP", false)
            changeVisibility("rblTakingAbilifyDEP", false)
            changeVisibility("rblTakingAbilifySZ", true)
            changeVisibility("TakingMedsBP", false)
            changeVisibility("TakingMedsSZ", true)
            changeVisibility("TakingMedsDEP", false)
            changeVisibility("TakingMedsSetBP", false)
            changeVisibility("TakingMedsSetSZ", true)
            changeVisibility("TakingMedsSetDEP", false)
            changeVisibility("PractitionerBP", false)
            changeVisibility("PractitionerSZ", true)
            changeVisibility("PractitionerDEP", false)   
        changeVisibility("Page3", false)
        changeVisibility("Page4", false)
        
        checkTakingAbilify();
        
    }
    else if(d("conditionReceived3").checked)
    {
        //alert(d("conditionReceived3").value);
        //changeVisibility("ConditionTaking", true)
        //changeVisibility("ddlConditionTaking", true)
            changeVisibility("Page2", true)
            changeVisibility("ddlHowLongBP", false)
            changeVisibility("ddlHowLongDEP", true)
            changeVisibility("ddlHowLongSZ", false)
            changeVisibility("rblTakingAbilifyBP", false)
            changeVisibility("rblTakingAbilifyDEP", true)
            changeVisibility("rblTakingAbilifySZ", false)
            changeVisibility("TakingMedsBP", false)
            changeVisibility("TakingMedsSZ", false)
            changeVisibility("TakingMedsDEP", true)
            changeVisibility("TakingMedsSetBP", false)
            changeVisibility("TakingMedsSetSZ", false)
            changeVisibility("TakingMedsSetDEP", true)
            changeVisibility("PractitionerBP", false)
            changeVisibility("PractitionerSZ", false)
            changeVisibility("PractitionerDEP", true)    
        changeVisibility("Page3", false)
        changeVisibility("Page4", false)
        
        checkTakingAbilify();        
    }
    else if(d("conditionReceived4").checked)
    {
        //alert(d("conditionReceived4").value);
        //changeVisibility("ConditionTaking", false)
        //changeVisibility("ddlConditionTaking", true)
        changeVisibility("Page2", false)      
        changeVisibility("Page3", false)
        changeVisibility("Page4", true);
    }
    else
    {
        //changeVisibility("ConditionTaking", false)
        //changeVisibility("ddlConditionTaking", false)
        changeVisibility("Page2", false)
        changeVisibility("Page3", false)
        changeVisibility("Page4", false)
    }

}


function checkTakingAbilify()
{

        if(d("rbTakingAbilifyYes").checked)
        {
            changeVisibility("Page3", true)
            if(d("conditionReceived1").checked)// BP
            {     
                    changeVisibility("TakingMedsBP", true)
                    changeVisibility("TakingMedsSZ", false)
                    changeVisibility("TakingMedsDEP", false)
                    changeVisibility("TakingMedsSetBP", true)
                    changeVisibility("TakingMedsSetSZ", false)
                    changeVisibility("TakingMedsSetDEP", false)
                    changeVisibility("PractitionerBP", true)
                    changeVisibility("PractitionerSZ", false)
                    changeVisibility("PractitionerDEP", false)
            }
            else if(d("conditionReceived2").checked)// SZ
            {
                    changeVisibility("TakingMedsBP", false)
                    changeVisibility("TakingMedsSZ", true)
                    changeVisibility("TakingMedsDEP", false)
                    changeVisibility("TakingMedsSetBP", false)
                    changeVisibility("TakingMedsSetSZ", true)
                    changeVisibility("TakingMedsSetDEP", false)
                    changeVisibility("PractitionerBP", false)
                    changeVisibility("PractitionerSZ", true)
                    changeVisibility("PractitionerDEP", false)
            }
            else if(d("conditionReceived3").checked)// DEP
            {
                    changeVisibility("TakingMedsBP", false)
                    changeVisibility("TakingMedsSZ", false)
                    changeVisibility("TakingMedsDEP", true)
                    changeVisibility("TakingMedsSetBP", false)
                    changeVisibility("TakingMedsSetSZ", false)
                    changeVisibility("TakingMedsSetDEP", true)
                    changeVisibility("PractitionerBP", false)
                    changeVisibility("PractitionerSZ", false)
                    changeVisibility("PractitionerDEP", true)
            }
            else
            {
                    changeVisibility("TakingMedsBP", false)
                    changeVisibility("TakingMedsSZ", false)
                    changeVisibility("TakingMedsDEP", false)
                    changeVisibility("TakingMedsSetBP", false)
                    changeVisibility("TakingMedsSetSZ", false)
                    changeVisibility("TakingMedsSetDEP", false)
                    changeVisibility("PractitionerBP", false)
                    changeVisibility("PractitionerSZ", false)
                    changeVisibility("PractitionerDEP", false)
            }
            changeVisibility("Page4", true)
        }
        else if(d("rbTakingAbilifyNo").checked)
        {
            changeVisibility("Page3", false)
            changeVisibility("Page4", true)
        }
        else
        {
            changeVisibility("Page3", false)
            changeVisibility("Page4", false)
        }
}

function showOnState(thisOn,thisOff){
    changeVisibility2(thisOn, true);
    changeVisibility2(thisOff, false);
    
}



function switchToPage(page)
{
    var error = false;
    // Handle any special cases
    switch (page) 
    {
        case 2:    
        case 3:     
        case 4:
            error = true;
            break;
        case 5:     // Call to action page
            // Display conditional message
            var bRegistration = myValidator.validateRegistration();
            var bRegistration2 = true;
            var bRegistration3 = true;
            if(d("conditionReceived1").checked || d("conditionReceived2").checked || d("conditionReceived3").checked)
            {
                bRegistration2 = myValidator.validateRegistration2();
            }
            if((d("conditionReceived1").checked || d("conditionReceived2").checked || d("conditionReceived3").checked) && d("rbTakingAbilifyYes").checked)
            {
                bRegistration3 = myValidator.validateRegistration3();
            }
            
            if (!bRegistration || !bRegistration2 || !bRegistration3)
            {
            
                error = true;
                closeDisplaysUtil('popup');
            }
            else {
                // Clear out appData object
                this.appData = new AppData();
                
                // Save user's input
                saveInput();
           
                //setCookie("cookUserType",d("ddlUserType").value,730);
                
                reportData();                
            }
            
            break;
    }
   
}


function reportData() { 
    var i;
    
    
    var strParticipant = '';
    var strAnswers = '';
    var strOpenAns = '';
    
    var arrayParticipant = new Array();
    var arrayAnswers = new Array();
    var arrayOpenAns = new Array();

    var currDate = new Date()
    var shortDate = (currDate.getMonth()+1) + "/" + (currDate.getDate()) + "/" + (currDate.getFullYear());
    
    arrayParticipant[0] = ""; //respondentid
    arrayParticipant[1] = ""; //returnMailDisp
    arrayParticipant[2] = ""; //whiteMail
    arrayParticipant[3] = ""; //salutation
    arrayParticipant[4] = this.appData.firstName; //firstName
    arrayParticipant[5] = ""; //middleName
    arrayParticipant[6] = this.appData.lastName; //lastName
    arrayParticipant[7] = ""; //suffix
    arrayParticipant[8] = this.appData.street; //address1
    arrayParticipant[9] = ""; //address2
    arrayParticipant[10] = this.appData.city; //city
    arrayParticipant[11] = this.appData.state; //state
    arrayParticipant[12] = this.appData.zip; //zip
    arrayParticipant[13] = this.appData.tc; //treatementCode
    arrayParticipant[14] = shortDate //datetime

    arrayAnswers[0] = this.appData.takingAbilify_BP_SZ; //HAVE YOU OR A LOVED ONE BEEN TAKING ABILIFY (FOR BIPOLAR | DISORDER, SCHIZO) FOR AT LEAST 9 MONTHS?"
    arrayAnswers[1] = this.appData.takingAbilify_DEP;   //HAVE YOU OR A LOVED ONE BEEN TAKING ABILIFY AS AN ADD ON TREATMENT TO ANTI-DEPRESSANTS FOR MAJOR DEPRESSIVE DISORDER FOR AT LEAST 6 MONTHS?"
    arrayAnswers[2] = this.appData.gender;              //GENDER OF PARTICIPANT"
    arrayAnswers[3] = this.appData.conditionReceived;   //FOR WHICH CONDITION HAVE YOUR OR YOUR LOVED ONE RECEIVED A DIAGNOSIS AND TAKING ABILIFY?"
    arrayAnswers[4] = this.appData.howLongDiagnosed;    //HOW LONG AGO WERE YOU OR YOUR LOVED ONE DIAGNOSED (WITH BIPOLAR | DISORDER, SCHIZO, MDD)?"
    arrayAnswers[5] = this.appData.userType;            //PERSON TYPE"
    arrayAnswers[6] = this.appData.eighteen;            //ARE YOU 18 YEARS OF AGE OR OLDER?"
    arrayAnswers[7] = this.appData.medABILIFY;          //TAKING ABILIFY"
    arrayAnswers[8] = this.appData.medGEODON;           //TAKING GEODON?"
    arrayAnswers[9] = this.appData.medRISPERDAL;        //TAKING RISPERDAL?"
    arrayAnswers[10] = this.appData.medSEROQUEL;         //TAKING SEROQUEL?"
    arrayAnswers[11] = this.appData.medZYPREZA;         //TAKING ZYPREZA?"
    arrayAnswers[12] = this.appData.medINVEGA;          //TAKING INVEGA?"
    arrayAnswers[13] = this.appData.medZOLOFT;          //TAKING ZOLOFT?"
    arrayAnswers[14] = this.appData.medCELEXA;          //TAKING CELEXA?"
    arrayAnswers[15] = this.appData.medCYMBALTA;        //TAKING CYMBALTA?"
    arrayAnswers[16] = this.appData.medLEXAPRO;         //TAKING LEXAPRO?"
    arrayAnswers[17] = this.appData.medPROZAC;          //TAKING PROZAC?"
    arrayAnswers[18] = this.appData.medWELLBUTRIN;      //TAKING WELLBUTRIN?"
    arrayAnswers[19] = this.appData.medREMERON;         //TAKING REMERON?"
    arrayAnswers[20] = this.appData.medPAXIL;           //TAKING PAXIL?"
    arrayAnswers[21] = this.appData.medPRISTIQ;         //TAKING PRISTIQ?"
    arrayAnswers[22] = this.appData.medEFFEXOR;         //TAKING EFFEXOR?"
    arrayAnswers[23] = this.appData.medOTHER;           //TAKING OTHER?"
    arrayAnswers[24] = this.appData.practitioner;       //WHAT TYPE OF PHYSICIAN PRESCRIBES YOUR MEDICATION?"
    arrayAnswers[25] = this.appData.diagWithDesp;       //HAVE YOU BEEN DIAGNOSED AS HAVING DEPRESSION?"
    arrayAnswers[26] = this.appData.takingAntidep;       //ARE YOU CURRENTLY TAKING AN ANTIDEPRESSANT?"
    
    arrayOpenAns[0] = strNotAsked;    //PHONE NUMBER?"
    arrayOpenAns[1] = this.appData.dob;    //DATE OF BIRTH"
    arrayOpenAns[2] = this.appData.email;    //EMAIL ADDRESS?"
    arrayOpenAns[3] = d("pageSessionID").value;    //Session(ID)"
    arrayOpenAns[4] = "ABLF_SHARE_WEB09";    //VENDOR(QUEST_SET_ID)
    arrayOpenAns[5] = d("webregpagename").value;    //WEB-REG PAGE NAME :"
    arrayOpenAns[6] = this.appData.otherMedName;     //IF OTHER, WHAT IS THE MEDICATION?"
    

    var Participant = {
        'respondentid':arrayParticipant[0],
        'returnMailDisp':arrayParticipant[1],
        'whiteMail':arrayParticipant[2],
        'salutation':arrayParticipant[3],
        'firstName':arrayParticipant[4],
        'middleName':arrayParticipant[5],
        'lastName':arrayParticipant[6],
        'suffix':arrayParticipant[7],
        'address1':arrayParticipant[8],
        'address2':arrayParticipant[9],
        'city':arrayParticipant[10],
        'state':arrayParticipant[11],
        'zip':arrayParticipant[12],
        'treatementCode':arrayParticipant[13],
        'datetime':arrayParticipant[14]};

    var Answers = {
        'takingAbilify_BP_SZ':arrayAnswers[0],
        'takingAbilify_DEP':arrayAnswers[1],
        'gender':arrayAnswers[2],
        'conditionReceived':arrayAnswers[3],
        'howLongDiagnosed':arrayAnswers[4],
        'userType':arrayAnswers[5],
        'eighteen':arrayAnswers[6],
        'medABILIFY':arrayAnswers[7],
        'medGEODON':arrayAnswers[8],
        'medRISPERDAL':arrayAnswers[9],
        'medSEROQUEL':arrayAnswers[10],
        'medZYPREZA':arrayAnswers[11],
        'medINVEGA':arrayAnswers[12],
        'medZOLOFT':arrayAnswers[13],
        'medCELEXA':arrayAnswers[14],
        'medCYMBALTA':arrayAnswers[15],
        'medLEXAPRO':arrayAnswers[16],
        'medPROZAC':arrayAnswers[17],
        'medWELLBUTRIN':arrayAnswers[18],
        'medREMERON':arrayAnswers[19],
        'medPAXIL':arrayAnswers[20],
        'medPRISTIQ':arrayAnswers[21],
        'medEFFEXOR':arrayAnswers[22],
        'medOTHER':arrayAnswers[23],
        'practitioner':arrayAnswers[24],
        'diagWithDesp':arrayAnswers[25],
        'takingAntidep':arrayAnswers[25]};
    
    var OpenAns = {
        'phone':arrayOpenAns[0],                    //PHONE NUMBER?"
        'dob':arrayOpenAns[1],                      //DATE OF BIRTH"
        'email':arrayOpenAns[2],                    //EMAIL ADDRESS?"
        'sessionID':arrayOpenAns[3],                //Session(ID)"
        'questSetID':arrayOpenAns[4],               //VENDOR(QUEST_SET_ID)
        'webRegPageName':arrayOpenAns[5],           //WEB-REG PAGE NAME :"
        'otherMed':arrayOpenAns[6],                 //IF OTHER, WHAT IS THE MEDICATION?"
        'utm_medium':getUTMValue("utm_medium"),     //UTM_MEDIUM"
        'utm_campaign':getUTMValue("utm_campaign"), //UTM_CAMPAIGN"
        'utm_term':getUTMValue("utm_term"),         //UTM_TERM"
        'utm_content':getUTMValue("utm_content"),   //UTM_CONTENT"
        'utm_source':getUTMValue("utm_source"),     //UTM_SOURCE""
        'channel':getUTMValue("channel"),           //CHANNEL"
        'dfa_id':getUTMValue("dfa_id")};            //DFA ID"
        
    var ws_share = new share();
    var result = ws_share.shareStory(Participant, Answers, OpenAns);
    
    if(result.substring(0, 4) != 'True') 
    {
        window.location = "/error.aspx";
    }
    else
    {
        var x = createCookie('BMS_Story','true',0);
        
        if (d("conditionReceived1").checked)        // BP
        {
            window.location.href = 'sign-up-confirm-BP.aspx';
        }  
        else if (d("conditionReceived2").checked)   // SZ
        {
            window.location.href = 'sign-up-confirm-SZ.aspx';
        }
        else if (d("conditionReceived3").checked)   // DEP
        {
            window.location.href = 'sign-up-confirm-DEP.aspx';
        }
        else
        {
            window.location.href = 'sign-up-confirm.aspx';
        }  
    }
    
}

function getUTMValue(query){
    var value = getQueryVariable(query);
    if(value)return value;
    return strNotAsked;
}

function hideAllPages()
{
    for (var i=1; i<=numPages; i++) {
        changeVisibility("page" + i, false);
    }
}

function changeVisibility(id, show)
{
   if (show) { 
        document.getElementById(id).style.display = "block"; 
   } else { 
        document.getElementById(id).style.display = "none"; 
   } 
}
function changeVisibility2(id, show)
{
   if (show) { 
        document.getElementById(id).style.display = "inline"; 
   } else { 
        document.getElementById(id).style.display = "none"; 
   } 
}

function toggle_other_meds1()
{
    if(document.getElementById('chkMed6').checked)
    {
        document.getElementById('otherMed1').disabled=false;
    }
    else
    {
        document.getElementById('otherMed1').value = "";
        document.getElementById('otherMed1').disabled=true;  
    }
}
function toggle_other_meds2()
{
    if(document.getElementById('chkMed16').checked)
    {
        document.getElementById('otherMed2').disabled=false;
    }
    else
    {
        document.getElementById('otherMed2').value = "";
        document.getElementById('otherMed2').disabled=true;  
    }
}
function toggle_other_meds3()
{
    if(document.getElementById('chkMed26').checked)
    {
        document.getElementById('otherMed3').disabled=false;
    }
    else
    {
        document.getElementById('otherMed3').value = "";
        document.getElementById('otherMed3').disabled=true;  
    }
}

/**
 * returns the object with the passed id
 * or throws an error dialogue if the field isn"t found
 * this is mostly to speed up building and debugging
 */
function d(fieldName){
    var x;
    return (x = document.getElementById(fieldName)) ? x : alert(fieldName + " not found");
}

/**
 * Class structure that holds app data fields
 */
function AppData() {
    
    this.userType = null;   //
    
    this.firstName = null;
    this.lastName = null;
    this.email = null;
    this.street = null;
    this.city = null;
    this.state = null;
    this.zip = null;
    this.dob = null;
    this.eighteen = null;
    this.gender = null;

    this.conditionReceived = null;  //
    this.howLongDiagnosed = null;
    this.takingAbilify_BP_SZ = null;
    this.takingAbilify_DEP = null;
    
    this.diagWithDesp = null;
    this.takingAntidep = null;
    
    this.medABILIFY = null;
    this.medGEODON = null;
    this.medRISPERDAL = null;
    this.medSEROQUEL = null;
    this.medZYPREZA = null;
    this.medINVEGA = null;
    this.medZOLOFT = null;
    this.medCELEXA = null;
    this.medCYMBALTA = null;
    this.medLEXAPRO = null;
    this.medPROZAC = null;
    this.medWELLBUTRIN = null;
    this.medREMERON = null;
    this.medPAXIL = null;
    this.medPRISTIQ = null;
    this.medEFFEXOR = null;
    this.medOTHER = null;
    this.otherMedName = null;
    this.practitioner = null;
}

function resetFields() { 
    // Clear out appData object
    this.appData = new AppData();
    
    // Reset input fields
    d("txtFirstName").value = ""; 
    d("txtLastName").value = ""; 
    d("txtEmail").value = ""; 
    d("txtStreet").value = ""; 
    d("txtCity").value = ""; 
    d("ddlState").value = ""; 
    d("txtZip").value = ""; 
    d("chkEighteen").checked = false;
    
    d("ddlMonth").selectedIndex = 0;
    d("ddlDay").selectedIndex = 0;
    d("ddlYear").selectedIndex = 0;
    
    d("male").checked = false;
    d("female").checked = false;
    
    d("conditionReceived1").checked = false;
    d("conditionReceived2").checked = false;
    d("conditionReceived3").checked = false;
    d("conditionReceived4").checked = false;
    
    //d("ddlConditionTaking").selectedIndex = 0;
    d("ddlAreYou").selectedIndex = 0;
    
    d("ddlHowLong").selectedIndex = 0;
    
    d("rbTakingAbilifyYes").checked = false;
    d("rbTakingAbilifyNo").checked = false;
    
    d("chkMed1").checked = false;
    d("chkMed2").checked = false;
    d("chkMed3").checked = false;
    d("chkMed4").checked = false;
    d("chkMed5").checked = false;
    d("chkMed6").checked = false;
    d("chkMed11").checked = false;
    d("chkMed12").checked = false;
    d("chkMed13").checked = false;
    d("chkMed14").checked = false;
    d("chkMed15").checked = false;
    d("chkMed16").checked = false;
    d("chkMed17").checked = false;
    d("chkMed21").checked = false;
    d("chkMed22").checked = false;
    d("chkMed23").checked = false;
    d("chkMed24").checked = false;
    d("chkMed25").checked = false;
    d("chkMed26").checked = false;
    d("chkMed27").checked = false;
    d("chkMed28").checked = false;
    d("chkMed29").checked = false;
    d("chkMed30").checked = false;
    d("chkMed31").checked = false;
    
    d("otherMed1").value = null;
    d("otherMed2").value = null;
    d("otherMed3").value = null;
    
    d("ddlPractitioner").selectedIndex = 0;
        
    // Run all the action* functions so that the states of the buttons/divs will be reset
    checkConditionReceived(); 
    //checkTakingAbilify();
}

function getValueFromDropDown(fieldName)
{
    var strNoResponse = '10009005';     // REFUSED/NO RESPONSE GIVEN
    var actualValue = strNoResponse;
    
    if (d(fieldName).selectedIndex > 0)
        actualValue = d(fieldName).value;
        
    return actualValue;
}

function getValueFromRadioButton(radioButtonsObj)
{
    var strNoResponse = '10009005';     // REFUSED/NO RESPONSE GIVEN
    var actualValue = strNoResponse;
    
    for (counter = 0; counter < radioButtonsObj.length; counter++)
    {
        if (radioButtonsObj[counter].checked)
        {
            actualValue = radioButtonsObj[counter].value;
            break;
        }
    }
    
    return actualValue;
}

function getValueYesNoFromCheckbox(fieldName)
{
    var strResponseYes = '10001001';
    var strResponseNo = '10001002';
    var actualValue = strResponseNo;
    
    if (d(fieldName).checked)
        actualValue = strResponseYes;
        
    return actualValue;
}

function getValueFromCheckbox_text(checkBoxFieldName, textFieldName)
{
    var actualValue = '10009005';   // REFUSED/NO RESPONSE GIVEN
    if (d(checkBoxFieldName).checked)
    {
        var strText = d(textFieldName).value.replace(/^\s+|\s+$/g, '');
        
        if (strText.length > 1)
            actualValue = strText;
    }
        
    return actualValue;
}

function saveInput() {

    
    this.appData.tc = d("tcid").value;
    
    // Save user data to appData object
    this.appData.userType = getValueFromDropDown("ddlAreYou");

    this.appData.firstName = d("txtFirstName").value;
    this.appData.lastName = d("txtLastName").value;
    this.appData.email = d("txtEmail").value;
    this.appData.street = d("txtStreet").value;
    this.appData.city = d("txtCity").value;
    this.appData.state = d("ddlState").value;
    this.appData.zip = d("txtZip").value;
    this.appData.eighteen = getValueYesNoFromCheckbox('chkEighteen');
    this.appData.dob = d("ddlMonth").value + "/" + d("ddlDay").value + "/" + d("ddlYear").value;
    this.appData.gender = (d("male").checked ? '10002002' : '10002001');
    this.appData.conditionReceived = getValueFromRadioButton(document.signup.conditionReceived);    

    // set default values for page2
    this.appData.howLongDiagnosed = strNotAsked;
    this.appData.takingAbilify_BP_SZ = strNotAsked;
    this.appData.takingAbilify_DEP = strNotAsked;
    
    this.appData.diagWithDesp = strNotAsked;
    this.appData.takingAntidep = strNotAsked;
    
    // set default values for page3
    this.appData.medABILIFY = strNotAsked;
    this.appData.medGEODON = strNotAsked;
    this.appData.medRISPERDAL = strNotAsked;
    this.appData.medSEROQUEL = strNotAsked;
    this.appData.medZYPREZA = strNotAsked;
    this.appData.medINVEGA = strNotAsked;
    this.appData.medZOLOFT = strNotAsked;
    this.appData.medCELEXA = strNotAsked;
    this.appData.medCYMBALTA = strNotAsked;
    this.appData.medLEXAPRO = strNotAsked;
    this.appData.medPROZAC = strNotAsked;
    this.appData.medWELLBUTRIN = strNotAsked;
    this.appData.medREMERON = strNotAsked;
    this.appData.medPAXIL = strNotAsked;
    this.appData.medPRISTIQ = strNotAsked;
    this.appData.medEFFEXOR = strNotAsked;
    this.appData.medOTHER = strNotAsked;
    this.appData.otherMedName = strNotAsked;;
    this.appData.practitioner = strNotAsked;
    
    // taking MED
    if(d("conditionReceived1").checked)         // BP
    {
        this.appData.howLongDiagnosed = getValueFromDropDown('ddlHowLong');
        this.appData.takingAbilify_BP_SZ = getValueFromRadioButton(document.signup.rbTakingAbilify);

        if (d("rbTakingAbilifyYes").checked)
        {
            this.appData.medABILIFY = getValueYesNoFromCheckbox('chkMed1');
            this.appData.medGEODON = getValueYesNoFromCheckbox('chkMed2');
            this.appData.medRISPERDAL = getValueYesNoFromCheckbox('chkMed3');
            this.appData.medSEROQUEL = getValueYesNoFromCheckbox('chkMed4');
            this.appData.medZYPREZA = getValueYesNoFromCheckbox('chkMed5');
            this.appData.medOTHER = getValueYesNoFromCheckbox('chkMed6');
            
            if (d("chkMed6").checked)
            {
                this.appData.otherMedName = getValueFromCheckbox_text('chkMed6', 'otherMed1');
            }
            this.appData.practitioner = getValueFromDropDown('ddlPractitioner');
        }
    }
    else if(d("conditionReceived2").checked)    // SZ
    {       
        this.appData.howLongDiagnosed = getValueFromDropDown('ddlHowLong');
        this.appData.takingAbilify_BP_SZ = getValueFromRadioButton(document.signup.rbTakingAbilify);

        if (d("rbTakingAbilifyYes").checked)
        {
            this.appData.medABILIFY = getValueYesNoFromCheckbox('chkMed11');
            this.appData.medGEODON = getValueYesNoFromCheckbox('chkMed12');
            this.appData.medRISPERDAL = getValueYesNoFromCheckbox('chkMed13');
            this.appData.medSEROQUEL = getValueYesNoFromCheckbox('chkMed14');
            this.appData.medZYPREZA = getValueYesNoFromCheckbox('chkMed15');
            this.appData.medINVEGA = getValueYesNoFromCheckbox('chkMed17');
            this.appData.medOTHER = getValueYesNoFromCheckbox('chkMed16');
            
            if (d("chkMed16").checked)
            {
                this.appData.otherMedName = getValueFromCheckbox_text('chkMed16', 'otherMed2');
            }
            this.appData.practitioner = getValueFromDropDown('ddlPractitioner');
        }
    }
    else if(d("conditionReceived3").checked)    // DEP
    {
        this.appData.howLongDiagnosed = getValueFromDropDown('ddlHowLong');
        this.appData.takingAbilify_DEP = getValueFromRadioButton(document.signup.rbTakingAbilify);

        if (d("rbTakingAbilifyYes").checked)
        {
            this.appData.medZOLOFT = getValueYesNoFromCheckbox('chkMed21');
            this.appData.medCELEXA = getValueYesNoFromCheckbox('chkMed22');
            this.appData.medCYMBALTA = getValueYesNoFromCheckbox('chkMed23');
            this.appData.medLEXAPRO = getValueYesNoFromCheckbox('chkMed24');
            this.appData.medPROZAC = getValueYesNoFromCheckbox('chkMed25');
            this.appData.medWELLBUTRIN = getValueYesNoFromCheckbox('chkMed27');
            this.appData.medREMERON = getValueYesNoFromCheckbox('chkMed28');
            this.appData.medPAXIL = getValueYesNoFromCheckbox('chkMed29');
            this.appData.medPRISTIQ = getValueYesNoFromCheckbox('chkMed30');
            this.appData.medEFFEXOR = getValueYesNoFromCheckbox('chkMed31');
            this.appData.medOTHER = getValueYesNoFromCheckbox('chkMed26');
            
            if (d("chkMed26").checked)
            {
                this.appData.otherMedName = getValueFromCheckbox_text('chkMed26', 'otherMed3');        
            }
            this.appData.practitioner = getValueFromDropDown('ddlPractitioner');
        }
    }
}

function getCheckboxLabelText(chkbox)
{
    if (chkbox.checked)
        return d("label_" + chkbox.id).innerHTML + "<br />";
    else
        return "";
}


function preLoad() {
    d("txtFirstName").value = "Firstname";
    d("txtLastName").value = "Lastname";
    d("txtEmail").value = "email@test.com";
    d("txtStreet").value = "123 Any Street";
    d("txtCity").value = "Anytown";
    d("ddlState").value = "IN";
    d("txtZip").value = "12345"
    d("chkEighteen").checked = true;
           
}


//function createCookie(name,value,days) {
//	if (days) {
//		var date = new Date();
//		date.setTime(date.getTime()+(days*24*60*60*1000));
//		var expires = "; expires="+date.toGMTString();
//	}
//	else var expires = "";
//	document.cookie = name+"="+value+expires+"; path=/";
//}

//function readCookie(name) {
//	var nameEQ = name + "=";
//	var ca = document.cookie.split(';');
//	for(var i=0;i < ca.length;i++) {
//		var c = ca[i];
//		while (c.charAt(0)==' ') c = c.substring(1,c.length);
//		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
//	}
//	return null;
//}

//function setCookie() {

//    if(gup('TC') != null && gup('TC') != '')
//    {
//        var x = createCookie('BMSQA',gup('TC'),0);
//    }
//}


//function gup(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];
// }