//<!-- Justin Voels, Student Academic Conference - Student Assistant -->


var uniqueID = (function() {
   var id = 0; // This is the private persistent value
   // The outer function returns a nested function that has access
   // to the persistent value.  It is this nested function we're storing
   // in the variable uniqueID above.
   return function() { return id++; };  // Return and increment
})(); // Invoke the outer function after defining it.


function addMember(aTable,memberIndex)
{
    memberIndex = memberIndex + uniqueID();

    aRow = aTable.insertRow(aTable.rows.length);
    numCells=4
//    var col_dir = ["<input type='text' name='dragonId_" + memberIndex + ">",
//   "<label><input type='radio' " + "checked='checked'" + " name='mealChoice_" + memberIndex + "' value='noMeal' /></label>Not Attenting Luncheon<label><input type='radio' name='mealChoice_" + memberIndex + "' value='chicken' /></label>Chicken<label><input type='radio' name='mealChoice_" + memberIndex + "' value='vegetarian' /></label>Vegetarian"]

    var col_dir = ["<input type='text' size='8' maxlength='8' name='dragonId_" + memberIndex + "' />",

                   "<label><input type='radio' checked='checked' name='mealChoice_" +
		   memberIndex +
		   "' value='noMeal' /></label>Not Attenting Luncheon<label><input type='radio' name='mealChoice_" +
		   memberIndex +
		   "' value='chicken' /></label>Chicken<label><input type='radio' name='mealChoice_" +
		   memberIndex +
		   "' value='vegetarian' /></label>Vegetarian",

		   "<label><input type='radio' checked='checked' name='honors_" +
		   memberIndex +
		   "' value='false' /></label>No<label><input type='radio' name='honors_" +
		   memberIndex +
		   "' value='true' /></label>Yes",

		   "<label><input type='radio' checked='checked' name='graduate_" +
		   memberIndex +
		   "' value='false' /></label>No<label><input type='radio' name='graduate_" +
		   memberIndex +
		   "' value='true' /></label>Yes"]


    //aCell = aRow.insertCell(0);
    //aCell.innerHTML='<input type="text" name="dragonId_' + memberIndex + '>'
    for (i=0;i<numCells;i++)
    {
        aCell = aRow.insertCell(i);
        aCell.innerHTML = col_dir[i];
    }
}

function removeMember(obj)
{
    obj=document.getElementById(obj);
    rws=obj.getElementsByTagName('TR');
    if(rws.length > 1)
    {
	obj.removeChild(rws[rws.length-1]);
    }
}


function textLimit(field, maxlen)
{
    if (field.value.length > maxlen + 1)
        window.alert('your input has been truncated!');
    if (field.value.length > maxlen)
        field.value = field.value.substring(0, maxlen);
}

function clearTitle()
{
    document.presentationApplication.title.value = "";
}

function clearSpecialNeeds()
{
    document.presentationApplication.specialNeeds.value = "";
}

function radioCheck(isOther)
{
    if(isOther)
    {
        document.presentationApplication.otherFormat.disabled = false;
	document.presentationApplication.otherFormat.focus();
    }
    else
    {
        document.presentationApplication.otherFormat.value = "";
	document.presentationApplication.otherFormat.disabled = true;
    }
}

function changeAddGroupMember()
{
    if(document.presentationApplication.indi.checked)
    {
        document.presentationApplication.one.value="";
        document.presentationApplication.one.disabled=true;
        document.presentationApplication.two.value="";
        document.presentationApplication.two.disabled=true;
        document.presentationApplication.three.value="";
        document.presentationApplication.three.disabled=true;
        document.presentationApplication.four.value="";
        document.presentationApplication.four.disabled=true;
        document.presentationApplication.five.value="";
        document.presentationApplication.five.disabled=true;
    }
    else
    {
        document.presentationApplication.one.disabled=false;
    }
}

function addAvailableGroupMember(groupMemberNext,groupMemberNow)
{
    if(groupMemberNow.value == "")
    {
        if(groupMemberNow != document.presentationApplication.five)
           groupMemberNext.disabled=true;
    }
    else
    {
        groupMemberNext.disabled=false;
    }
}

function switchAbstract()
{
    if(document.presentationApplication.abstractTextarea.disabled == true)
    {
        document.presentationApplication.abstractFile.value = "";
        document.presentationApplication.abstractFile.disabled = true;
        document.presentationApplication.abstractTextarea.disabled = false;
    }
    else
    {
        document.presentationApplication.abstractTextarea.value = "";
        document.presentationApplication.abstractTextarea.disabled = true;
        document.presentationApplication.abstractFile.disabled = false;
    }
}

function sureReset()
{
  //  document.presentationApplication.abstractTextarea.disabled=true;
 //   document.presentationApplication.abstractFile.disabled=false;
    document.presentationApplication.indi.checked=true;
    document.presentationApplication.one.value="";
        document.presentationApplication.one.disabled=true;
        document.presentationApplication.two.value="";
        document.presentationApplication.two.disabled=true;
        document.presentationApplication.three.value="";
        document.presentationApplication.three.disabled=true;
        document.presentationApplication.four.value="";
        document.presentationApplication.four.disabled=true;
        document.presentationApplication.five.value="";
        document.presentationApplication.five.disabled=true;
}

function dynamicInput()
{
            var departments = '<option selected value="ACCT"> ACCT -- Accounting                      </option>' +
                              '<option  value="AMCS"> AMCS -- American Multicultural Studies Departmen</option>' +
                              '<option  value="ANTH"> ANTH -- Anthropology                            </option>' +
                              '<option  value="ART "> ART  -- Art and Design                          </option>' +
                              '<option  value="AST "> AST  -- Astronomy                               </option>' +
                              '<option  value="AT  "> AT   -- Athletic Training                       </option>' +
                              '<option  value="ATHL"> ATHL -- Athletics                               </option>' +
                              '<option  value="BIOL"> BIOL -- Biology                                 </option>' +
                              '<option  value="BUS "> BUS  -- Business                                </option>' +
                              '<option  value="CCGE"> CCGE -- Corrick Center for General Education    </option>' +
                              '<option  value="CHEM"> CHEM -- Chemistry                               </option>' +
                              '<option  value="CHIN"> CHIN -- Chinese                                 </option>' +
                              '<option  value="CJ  "> CJ   -- Criminal Justice                        </option>' +
                              '<option  value="CM  "> CM   -- Construction Management                 </option>' +
                              '<option  value="CMST"> CMST -- Communication Studies                   </option>' +
                              '<option  value="CNSA"> CNSA -- Counseling & Student Affairs            </option>' +
                              '<option  value="COMH"> COMH -- Community Health                        </option>' +
                              '<option  value="CSIS"> CSIS -- Computer Science and Information Systems</option>' +
                              '<option  value="CST "> CST  -- Continuing Studies                      </option>' +
                              '<option  value="ECON"> ECON -- Economics                               </option>' +
                              '<option  value="ED  "> ED   -- Education                               </option>' +
                              '<option  value="EECE"> EECE -- Elementary and Early Childhood Education</option>' +
                              '<option  value="EHS "> EHS  -- Environmental Health and Safety         </option>' +
                              '<option  value="ENG "> ENG  -- Engineering                             </option>' +
                              '<option  value="ENGL"> ENGL -- English                                 </option>' +
                              '<option  value="EXCH"> EXCH -- Exchange Studies                        </option>' +
                              '<option  value="EXST"> EXST -- External Studies                        </option>' +
                              '<option  value="FILM"> FILM -- Film Studies                            </option>' +
                              '<option  value="FINC"> FINC -- Finance                                 </option>' +
                              '<option  value="FREN"> FREN -- French                                  </option>' +
                              '<option  value="FYE "> FYE  -- Freshman Year Experience                </option>' +
                              '<option  value="GCOM"> GCOM -- Graphic Communications                  </option>' +
                              '<option  value="GDEV"> GDEV -- Game Development                        </option>' +
                              '<option  value="GEOS"> GEOS -- Geoscience                              </option>' +
                              '<option  value="HIST"> HIST -- History                                 </option>' +
                              '<option  value="HLTH"> HLTH -- Health                                  </option>' +
                              '<option  value="HON "> HON  -- Honors                                  </option>' +
                              '<option  value="HUM "> HUM  -- Humanities                              </option>' +
                              '<option  value="INTL"> INTL -- International Studies                   </option>' +
                              '<option  value="JAPN"> JAPN -- Japanese                                </option>' +
                              '<option  value="LANG"> LANG -- Languages                               </option>' +
                              '<option  value="LAT "> LAT  -- Latin                                   </option>' +
                              '<option  value="LBST"> LBST -- Liberal Studies                         </option>' +
                              '<option  value="LEAD"> LEAD -- Leadership                              </option>' +
                              '<option  value="LGST"> LGST -- Legal Studies                           </option>' +
                              '<option  value="MAED"> MAED -- Math Education                          </option>' +
                              '<option  value="MATH"> MATH -- Mathematics                             </option>' +
                              '<option  value="MBA "> MBA  -- Masters in Business Administration      </option>' +
                              '<option  value="MC  "> MC   -- Mass Communications                     </option>' +
                              '<option  value="MDS "> MDS  -- Multidisciplinary Studies               </option>' +
                              '<option  value="MFA "> MFA  -- Master of Fine Arts                     </option>' +
                              '<option  value="MGMT"> MGMT -- Management                              </option>' +
                              '<option  value="MKTG"> MKTG -- Marketing                               </option>' +
                              '<option  value="MLA "> MLA  -- Master in Liberal Arts                  </option>' +
                              '<option  value="MUS "> MUS  -- Music                                   </option>' +
                              '<option  value="NTC "> NTC  -- Northwest Technical College - Moorhead  </option>' +
                              '<option  value="NURS"> NURS -- Nursing                                 </option>' +
                              '<option  value="PARA"> PARA -- Paralegal                               </option>' +
                              '<option  value="PDEV"> PDEV -- Personal Development                    </option>' +
                              '<option  value="PE  "> PE   -- Physical Education                      </option>' +
                              '<option  value="PHIL"> PHIL -- Philosophy                              </option>' +
                              '<option  value="PHSA"> PHSA -- Public and Human Service Administration </option>' +
                              '<option  value="PHYS"> PHYS -- Physics                                 </option>' +
                              '<option  value="POL "> POL  -- Political Science                       </option>' +
                              '<option  value="POOK"> POOK -- Pooks Test                              </option>' +
                              '<option  value="PSCI"> PSCI -- Physical Science                        </option>' +
                              '<option  value="PSY "> PSY  -- Psychology                              </option>' +
                              '<option  value="REC "> REC  -- Recreation                              </option>' +
                              '<option  value="SCI "> SCI  -- Science                                 </option>' +
                              '<option  value="SLHS"> SLHS -- Speech, Language & Hearing Science      </option>' +
                              '<option  value="SLP "> SLP  -- Speech and Language Pathology           </option>' +
                              '<option  value="SOC "> SOC  -- Sociology                               </option>' +
                              '<option  value="SPAN"> SPAN -- Spanish                                 </option>' +
                              '<option  value="SPCH"> SPCH -- Speech                                  </option>' +
                              '<option  value="SPED"> SPED -- Special Eduation                        </option>' +
                              '<option  value="SW  "> SW   -- Social Work                             </option>' +
                              '<option  value="SWED"> SWED -- Swedish                                 </option>' +
                              '<option  value="TECH"> TECH -- Technology                              </option>' +
                              '<option  value="TESL"> TESL -- Teaching English as a Second Language   </option>' +
                              '<option  value="THTR"> THTR -- Theatre Arts                            </option>' +
                              '<option  value="WS  "> WS   -- Women\'s Studies                        </option>';

            var rooms = '<option selected value="CMU 101">CMU 101</option>' +
                        '<option  value="CMU">CMU Main Lounge</option>' +
                        '<option  value="CMU 203">CMU 203</option>' +
                        '<option  value="CMU 204">CMU 204</option>' +
                        '<option  value="CMU 205">CMU 205</option>' +
                        '<option  value="CMU 207">CMU 207</option>' +
                        '<option  value="CMU 208">CMU 208</option>' +
                        '<option  value="CMU 214">CMU 214</option>' +
                        '<option  value="CMU 216">CMU 216</option>' +
                        '<option  value="CMU 218">CMU 218</option>' +
                        '<option  value="CMU 227">CMU 227</option>' +
                        '<option  value="CMU UG">CMU Underground</option>' +
                        '<option  value="CMU 200A">CMU 200A</option>' +
                        '<option  value="CMU 200B">CMU 200B</option>' +
                        '<option  value="CMU 200C">CMU 200C</option>' +
                        '<option  value="CMU 200D">CMU 200D</option>' +
                        '<option  value="CMU 200E">CMU 200E</option>' +
                        '<option  value="CMU 200F">CMU 200F</option>';

            var sessions = '<option selected value="4">All</option>' +
                           '<option value="1">Session 1</option>' +
                           '<option value="2">Session 2</option>' +
                           '<option value="3">Session 3</option>';

            var div = document.getElementById('dynamic');
            var select = document.getElementById('criteriaGeneral');

            if(select.value == 'presentationRoom')
            {
                div.innerHTML = '<label>Is:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select id="criteriaSpecific" name="criteriaSpecific" size="1">' +
                rooms + '</select></label><br />' +
                '<label>Session:&nbsp;<select id="session" name="session" size="1">' +
                sessions + '</select></label> <input type="submit" value="Submit" />';
            }
            else if(select.value == 'department')
            {
                div.innerHTML = '<label>Is:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select id="criteriaSpecific" name="criteriaSpecific" size="1">' +
                departments + '</select></label> <input type="submit" value="Submit" />';
            }
            else if(select.value == 'bad')
            {
                div.innerHTML = ''
            }
            else if(select.value == 'showAll')
            {
                div.innerHTML = '<input type="hidden" disabled="true" id="criteriaSpecific" name="criteriaSpecific" value="all" /><input type="submit" value="Submit" />';

            }
            else
            {
                div.innerHTML = '<label>Is:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="criteriaSpecific" id="criteriaSpecific" size="20" maxlength="50" /></label> <input type="submit" value="Submit" />';
            }
}


//add fields for additional group members as needed by http://binnyva.blogspot.com/2006/01/dynamic-form-field-generation-in.html
function addField(field,area,limit)
{
    if(!document.getElementById)
    {
        return; //Prevent older browsers from getting any further.
    }

    var field_area = document.getElementById(area);
    var all_inputs = field_area.getElementsByTagName("input"); //Get all the input fields in the given area.
    //Find the count of the last element of the list. It will be in the format '<field><number>'. If the
    //  field given in the argument is 'friend_' the last id will be 'friend_4'.
    var last_item = all_inputs.length - 1;
    var last = all_inputs[last_item].id;
    var count = Number(last.split("_")[1]) + 1;

    //If the maximum number of elements have been reached, exit the function.
    //  If the given limit is lower than 0, infinite number of fields can be created.
    if(count > limit && limit > 0)
    {
        return;
    }

    if(document.createElement)
    { //W3C Dom method.
        var li = document.createElement("li");
        var input = document.createElement("input");
        input.id = field+count;
        input.name = field+count;
        input.type = "text"; //Type of field - can be any valid input type like text,file,checkbox etc.
        li.appendChild(input);
        field_area.appendChild(li);
    }
    else
    { //Older Method
        field_area.innerHTML += "<li><input name='"+(field+count)+"' id='"+(field+count)+"' type='text' /></li>";
    }
}
