

var ie5  = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);
var request_id=0;
var dest = new Array();
var layers= new Array();
var opac=0;
var pageWidth;
var taskbar_offset=0;
var requested_ids = new Array()
var xmlHttp = new Array();
var currentActiveWindow;
var lastActiveWindow;
var currentHighZ=0;
var current_destination;
var updated=0;
var dosave = true;

if (self.innerWidth)
{
    var frameWidth = self.innerWidth;
    var frameHeight = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientWidth)
{
    var frameWidth = document.documentElement.clientWidth;
    var frameHeight = document.documentElement.clientHeight;
}
else if (document.body)
{
    var frameWidth = document.body.clientWidth;
    var frameHeight = document.body.clientHeight;
}


function phoenixXHRequest()
{
    try
    {
        this.request = new XMLHttpRequest();
    } catch (trymicrosoft)
    {
        try
        {
            this.request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (othermicrosoft)
        {
            try
            {
                this.request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (failed)
            {
                this.request = false;
            }
        }
    }
    if (!this.request)
    alert("Error initializing XMLHttpRequest!");

    //                        return request
}

function processStateChange()
{
    for(var request_ids in xmlHttp)
    {
        var i=0;

        //


        if (xmlHttp[request_ids].readyState==4 && requested_ids[request_ids]!=request_ids)
        {
            if(i<=request_ids && request_ids!=0)
            {
                if(document.getElementById(dest[request_ids]))
                {
                    contentDiv = document.getElementById(dest[request_ids]);
                }else{
                    if(window.opener)
                    {
                        contentDiv = window.opener.document.getElementById(dest[request_ids]);
                    }else{
                        if(document.getElementById(current_destination))
                        {
                            contentDiv = document.getElementById(current_destination);
                        }else{
                            alert('layer "'+current_destination+'" does not exist!');
                        }
                    }
                }
                try
                {
                    if (xmlHttp[request_ids].status == 200)
                    {
                        contentDiv.innerHTML = "";
                        var response = xmlHttp[request_ids].responseText;
                        contentDiv.innerHTML = response;
                        requested_ids[request_ids] = request_ids;
                        //                                        xmlHttp.splice(request_id);
                        //                    request_id++;
                    }else
                    {
                        //                    xmlHttp.splice(i,1); i--;
                        //                    request_id--;
                        throw new Error('An Error Occured. The requested page was not found or returned error: ' + xmlHttp[request_ids].status);
                    }
                }
                catch(e)
                {
                    throw new Error(e);
                }
            }
            i++;
        }
    }
}


/**
* load the html with small indicator
*/
function loadHTML (URL, destination)
{
    request_id++;
    dest[request_id] = destination;
    this.xmlreq = new Array();
    progressIndicatorOn(dest[request_id]);

    if(document.getElementById(dest[request_id]))
    {
        this.xmlreq[dest[request_id]] = new phoenixXHRequest();
        if(this.xmlreq[dest[request_id]].request)
        {
            xmlHttp[request_id] = this.xmlreq[dest[request_id]].request;
            xmlHttp[request_id].open("GET", URL, true);
            xmlHttp[request_id].onreadystatechange = processStateChange;
            xmlHttp[request_id].send(null);
        }else
        {
            throw new Error('request does not exist');
        }
    }
}

/**
* just load the html with no indicator
*/
function loadBareHTML (URL, destination)
{
    request_id++;
    dest[request_id] = destination;
    this.xmlreq = new Array();

    if(document.getElementById(dest[request_id]))
    {
        document.getElementById(dest[request_id]).style.visibility='visible';
    }else{
        window.opener.document.getElementById(dest[request_id]).style.visibility='visible';
    }
    //    opac=0;
    //    fadeIn(dest[request_id]);

    if(document.getElementById(dest[request_id]))
    {
        this.xmlreq[dest[request_id]] = new phoenixXHRequest();
        if(this.xmlreq[dest[request_id]].request)
        {
            xmlHttp[request_id] = this.xmlreq[dest[request_id]].request;
            xmlHttp[request_id].open("GET", URL, true);
            xmlHttp[request_id].onreadystatechange = processStateChange;
            xmlHttp[request_id].send(null);
        }else
        {
            throw new Error('no request available');
        }
    }
}

/**
* load the html with large indicator
*/
function loadHTMLLarge (URL, destination)
{
    request_id++;
    dest[request_id] = destination;
    this.xmlreq = new Array();
    largeProgressIndicatorOn(destination);

    if(document.getElementById(dest[request_id]))
    {
        this.xmlreq[dest[request_id]] = new phoenixXHRequest();
        if(this.xmlreq[dest[request_id]].request)
        {
            xmlHttp[request_id] = this.xmlreq[dest[request_id]].request;
            xmlHttp[request_id].open("GET", URL, true);
            xmlHttp[request_id].onreadystatechange = processStateChange;
            xmlHttp[request_id].send(null);
            //

        }else
        {
            throw new Error('request does not exist');
        }
    }
}

/**
* POST html with small indicator
*/
function loadPOSTHTML (URL, destination, vars)
{
    request_id++;
    dest[request_id] = destination;
    this.xmlreq = new Array();

    if(document.getElementById(dest[request_id]))
    {
        document.getElementById(dest[request_id]).style.visibility='visible';
    }else{
        window.opener.document.getElementById(dest[request_id]).style.visibility='visible';
    }

    //progressIndicatorOn(dest[request_id]);

    this.xmlreq[dest[request_id]] = new phoenixXHRequest();

    if(this.xmlreq[dest[request_id]].request)
    {
        xmlHttp[request_id] = this.xmlreq[dest[request_id]].request;

        vars='check_source_key=1919190909098&'+vars;

        xmlHttp[request_id].open("POST", URL, true);
        xmlHttp[request_id].onreadystatechange = processStateChange;
        xmlHttp[request_id].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlHttp[request_id].send(vars);

    }else
    {
        throw new Error('no request available');
    }
}
/**
* POST html with no indicator
*/
function loadBarePOSTHTML (URL, destination, vars)
{
    request_id++;
    dest[request_id] = destination;
    this.xmlreq = new Array();

    if(document.getElementById(dest[request_id]))
    {
        document.getElementById(dest[request_id]).style.visibility='visible';
    }else{
        window.opener.document.getElementById(dest[request_id]).style.visibility='visible';
    }


    //    progressIndicatorOn(dest[request_id]);

    this.xmlreq[dest[request_id]] = new phoenixXHRequest();

    if(this.xmlreq[dest[request_id]].request)
    {
        xmlHttp[request_id] = this.xmlreq[dest[request_id]].request;

        vars='check_source_key=1919190909098&'+vars;

        xmlHttp[request_id].open("POST", URL, true);
        xmlHttp[request_id].onreadystatechange = processStateChange;
        xmlHttp[request_id].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlHttp[request_id].send(vars);

    }else
    {
        throw new Error('no request available');
    }
}





function startResize(id, height_amount, width_amount)
{
    resizePage(id,height_amount,width_amount);
    resizing = setTimeout("startResize('"+id+"','"+height_amount+"','"+width_amount+"')",50);
}
function stopResize()
{
    clearTimeout(resizing);
}

function resizePage (id,height_amount,width_amount)
{
    current_height=parseInt(document.getElementById(id).style.height);
    current_width=parseInt(document.getElementById(id).style.width);
    new_height=current_height+parseInt(height_amount);
    new_width=current_width+parseInt(width_amount);
    current_inner_height=parseInt(document.getElementById(id+'_inner').style.height);
    current_inner_width=parseInt(document.getElementById(id+'_inner').style.width);
    new_inner_height=current_inner_height+parseInt(height_amount);
    new_inner_width=current_inner_width+parseInt(width_amount);

    document.getElementById(id+'_maximize').src='graphics/restore_clear.png';
    document.getElementById(id).style.width=new_width+'px';
    document.getElementById(id+'_inner').style.height=new_inner_height+'px';
    document.getElementById(id+'_inner').style.width=new_inner_width+'px';
    misc_base_id=id.replace("_container","");
    document.getElementById(misc_base_id+'_misc_info_container').innerHTML=new_inner_width+"px,"+new_inner_height+"px";
}

function fitPageToWindow (id)
{
    new_height=(frameHeight-170);
    new_width=(frameWidth-10);

    getStyle(id).width=new_width+'px';
    getStyle(id+'_inner').height=(new_height)+'px';
    getStyle(id+'_inner').width=(new_width-5)+'px';
    misc_base_id=id.replace("_container","");
    getStyle(id).top="100px";
}



function createDiv (id)
{

    if(document.getElementById(id))
    {
        this.layer=document.getElementById(id);
        document.body.removeChild(this.layer)
    }else
    {
        currentHighZ++;
        this.layer = document.createElement("div");
        this.layer.style.visibility = "visible";
        this.layer.style.position = "absolute";
        this.layer.style.zIndex=currentHighZ;
        this.layer.style.width = (frameWidth-20)+'px';
        this.layer.style.height = '200px';
        //                this.layer.style.cursor = 'move';
        this.layer.id = id;

        //keep track of our active containers
        active_pages.value = active_pages.value + id + ',';

        //add layer to phoenix window
        document.body.appendChild(this.layer);
    }
    return true;
}



function fadeIn (id)
{
    if(opac != 100){
        opac+=5;
        if(ie5) document.getElementById(id).style.filter='alpha(opacity='+opac+')';
        if(ns6) document.getElementById(id).style.MozOpacity = opac/100;
        setTimeout("fadeIn('"+id+"')", 50);
    }
}
function fadeOut (id)
{
    if(opac > 0 )
    {
        opac-=10;
        if(ie5) document.getElementById(id).style.filter='alpha(opacity='+opac+')';
        if(ns6) document.getElementById(id).style.MozOpacity = opac/100;
        setTimeout("fadeOut('"+id+"')", 50);
    }
}
function progressIndicatorOn (id)
{
    if(document.getElementById(id))
    {
        document.getElementById(id).innerHTML="<div width=100% id='progress_indicator'><img src='radar-transparent.gif' align='center' border=0/></div>";
    }else{
        window.opener.document.getElementById(id).innerHTML="<div width=100% id='progress_indicator'><img src='radar-transparent.gif' align='center' border=0/></div>";
    }
}

function largeProgressIndicatorOn (id)
{
    if(document.getElementById(id))
    {
        document.getElementById(id).innerHTML="<div width=100% style='text-align:center' id='progress_indicator'><img src='phoenix_3d_2_med.gif' align='center' border=0/></div>";
    }else{
        window.opener.document.getElementById(id).innerHTML="<div width=100% style='text-align:center' id='progress_indicator'><img src='phoenix_3d_2_med.gif' align='center' border=0/></div>";
    }
}

function in_array(val, arr)
{
    for (i in arr)
    {
        if(arr[i] == val)
        {
            return i;
        }
    }
    return false;
}
function getValue(id)
{
    val = document.getElementById(id).value;
    val_new = encodeURIComponent(val);
    val_new = val_new.replace(/&/g,"%26");
    return val_new;
}
function getV(id)
{
    val = document.getElementById(id).value;
    val_new = encodeURIComponent(val);
    val_new = val_new.replace(/&/g,"%26");
    return val_new;
}
function getO(id)
{
    val = document.getElementById(id);

}
function is_checked(id)
{
    val = document.getElementById(id).checked;
    if(val == true)
    {
        return 'on';
    }
    return 'off';
}

function getStyle(id)
{

    val = document.getElementById(id).style;
    return val;
}
function setValue(id,val)
{
    if(document.getElementById(id) != null)
    {
        document.getElementById(id).value=val;
    }
}
function set_target(id, targ)
{
    document.getElementById(id).target = targ;
}
function set_action(id, act)
{
    document.getElementById(id).action = act;
}
function submit_form(id)
{
    document.getElementById(id).submit();
}
function setInnerHTML(id,val)
{
    document.getElementById(id).innerHTML=val;
}
function getInnerHTML(id)
{
    return document.getElementById(id).innerHTML;
}

function onloadFunction()
{
    //    updateTime('phoenix_clock_inner');
    //    updateUsersOnline('phoenix_users_online_container');
    keepAlive();
    //    checkForAlerts();

}
function submit_login(login_button_id)
{
    if(getV('username') != '' && getV('password') != '')
    {
        setValue(login_button_id, 'Logging you in... Please wait.');
        loadPOSTHTML('form.php?action[0]=output_application_contents','app_table','submit_login=Login&username='+getV('username')+'&password='+getV('password')+'');
    }else{
        alert('The Username and Password fields cannot be blank!');
        return false;
    }
}
function hide_non_amcas()
{
    alert('Please email AMCAS applicant copy to admissions@saba.edu or fax to 978-632-2168.');
    for(i=1;i<=3;i++)
    {
        document.getElementById('non_amcas_'+i).style.visibility='hidden';
        document.getElementById('non_amcas_'+i).style.position='absolute';
    }
}
function show_non_amcas()
{
    for(i=1;i<=3;i++)
    {
        document.getElementById('non_amcas_'+i).style.visibility='visible';
        document.getElementById('non_amcas_'+i).style.position='relative';
    }
}
function total_mcat(rownum, ins)
{
    var num1 = 0;
    var num2 = 0;
    var num3 = 0;
    var num4 = 0;
    var sum = 0;
    if(ins == true)
    {
        field_add = "[insert]";
        total_add = "insert"
    }else{
        field_add = "";
        total_add = "";
    }
    if(document.getElementById('mcat' + field_add + '['+rownum+'][verbal_reasoning]').value && !isNaN(document.getElementById('mcat' + field_add + '['+rownum+'][verbal_reasoning]').value))
    {
        num1 = parseInt(document.getElementById('mcat' + field_add + '['+rownum+'][verbal_reasoning]').value);
    }
    if(document.getElementById('mcat' + field_add + '['+rownum+'][biological_sciences]').value && !isNaN(document.getElementById('mcat' + field_add + '['+rownum+'][biological_sciences]').value))
    {
        num2 = parseInt(document.getElementById('mcat' + field_add + '['+rownum+'][biological_sciences]').value);
    }
    if(document.getElementById('mcat' + field_add + '['+rownum+'][physical_sciences]').value && !isNaN(document.getElementById('mcat' + field_add + '['+rownum+'][physical_sciences]').value))
    {
        num3 = parseInt(document.getElementById('mcat' + field_add + '['+rownum+'][physical_sciences]').value);
    }
    if(document.getElementById('mcat' + field_add + '['+rownum+'][writing_sample]').value && !isNaN(document.getElementById('mcat' + field_add + '['+rownum+'][writing_sample]').value))
    {
        num4 = parseInt(document.getElementById('mcat' + field_add + '['+rownum+'][writing_sample]').value);
    }
    sum = num1 + num2 + num3 + num4;

    document.getElementById('mcat_total_' + total_add + '' + rownum).value = sum;
}
function hide_element(id)
{
    document.getElementById(id).style.visibility = 'hidden';
    document.getElementById(id).style.position = 'absolute';
}
function show_element(id)
{
    document.getElementById(id).style.visibility = 'visible';
    document.getElementById(id).style.position = 'relative';
}
function show_hide_element(id)
{
    if(document.getElementById(id).style.visibility == 'visible')
    {
        document.getElementById(id).style.visibility = 'hidden';
        document.getElementById(id).style.position = 'absolute';
        document.getElementById(id).style.zIndex = '-3';
    }else{
        document.getElementById(id).style.visibility = 'visible';
        document.getElementById(id).style.position = 'absolute';
        document.getElementById(id).style.zIndex = '40';
    }
}

String.prototype.trim = function()
{
    return this.replace(/^\s+|\s+$/g,"");
}
function unhide_app_table()
{
    document.getElementById('dark_background').zIndex = '-2';
    document.getElementById('app_table').style.visibility = 'visible';
    document.getElementById('app_table').style.position = 'relative';
    document.getElementById('app_table').zIndex = '20';
}
function hide_app_table()
{
    document.getElementById('app_inner_table').style.visibility = 'visible';
    document.getElementById('app_inner_table').style.position = 'relative';
    document.getElementById('app_inner_table').zIndex = '-2';
    document.getElementById('dark_background').zIndex = '35';
}
function unhide_report_table()
{
    document.getElementById('report_table').style.visibility = 'visible';
    document.getElementById('report_table').style.position = 'relative';
    document.getElementById('dark_background').zIndex = '-2';
}
function hide_noscript_message()
{
    document.getElementById('noscript_message').style.visibility = 'hidden';
    document.getElementById('noscript_message').style.position = 'absolute';
    document.getElementById('noscript_message').style.height = '1px';
    document.getElementById('noscript_message').style.width = '1px';
}
function hide_app_message()
{
    document.getElementById('application_errors').style.visibility = 'hidden';
    document.getElementById('application_errors').style.position = 'absolute';
    document.getElementById('application_errors').style.height = '1px';
    document.getElementById('application_errors').style.width = '1px';
    document.getElementById('dark_background').zIndex = '2';
    unhide_app_table();
}
function get_e(fldname)
{
    return document.getElementById(fldname);
}
function check_required(fld, txt)
{
    val = getValue(fld);
    if(val == null || val == "")
    {
        alert(txt);
        setValue(fld, "");
        document.getElementById(fld).focus();
        return false;
    }
    return true;
}
function check_date(fld)
{
    val = getValue(fld);
    val.trim();
    var regcheck = /(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])/
    //check for length > 0 so user does not get error when leaving field, triggering focus event on clicking the calendar
    if (!regcheck.test(val) && val.length > 0)
    {
        alert(val+' is not a valid date!');
        setValue(fld, "");
        return false;
    }else{
        if( val.length > 0)
        {
            var yval = val.split("-")[0];
            var mval = val.split("-")[1];
            var dval = val.split("-")[2];
            var dateval = new Date(yval, mval-1, dval);

            if ((dateval.getMonth() + 1 != mval) || (dateval.getDate() != dval) || (dateval.getFullYear() != yval))
            {
                alert(val+' is not a valid date!');
                setValue(fld, "");
                return false;
            }

        }
    }
    return true;

}
function check_num(fld, txt)
{
    val = getValue(fld);
    if(isNaN(val))
    {
        alert(txt);
        setValue(fld, "");
        return false;
    }
    return true;
}
function check_alpha_num(fld, txt)
{
    val = getValue(fld);
    regcheck = /^[a-zA-Z0-9]{0,255}$/
    if(!regcheck.test(val))
    {
        alert(txt);
        setValue(fld, "");
        return false;
    }
    return true;
}
function check_alpha(fld, txt)
{
    val = getValue(fld);
    regcheck = /^[a-zA-Z]{0,255}$/
    if(!regcheck.test(val))
    {
        alert(txt);
        setValue(fld, "");
        return false;
    }
    return true;
}
function check_email(fld, txt)
{
    val = getValue(fld);
    regcheck = /^(([a-z0-9!#$%&*+-=?^_`{|}~][a-z0-9!#$%&*+-=?^_`{|}~.]*[a-z0-9!#$%&*+-=?^_`{|}~])|[a-z0-9!#$%&*+-?^_`{|}~]|("[^"]+"))[@]([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/i
    if(!regcheck.test(val))
    {
        alert(txt);
        setValue(fld, "");
        return false;
    }
    return true;
}
function preg_match(regcheck, value)
{
    if(regcheck.test(value))
    {
        return true;
    }
    return false;
}
function create_cal_button(iteration, fieldname, calname)
{
    var caldoc = new CalendarPopup(iteration + '_' + calname + '_caldiv');
    caldoc.showNavigationDropdowns();
    caldoc.setYearSelectStartOffset(20);
    caldoc.select(document.getElementById(fieldname), iteration + '_' + calname + '_datebutton','yyyy-MM-dd');
    return false;
}
function create_button(fieldname, value, width)
{
    var el = document.createElement('input');
    el.type = 'button';
    el.id = fieldname;
    el.name = el.id;
    el.value = value;
    el.style.width = width;
    return el;
}
function create_cal_button_2(fieldname)
{
    var caldoc = new CalendarPopup('caldiv' + fieldname);
    caldoc.showNavigationDropdowns();
    caldoc.setYearSelectStartOffset(20);
    caldoc.select(document.getElementById(fieldname), 'datebutton' + fieldname,'yyyy-MM-dd');
    return false;
}

function create_text_input(fieldname, width)
{
    var el = document.createElement('input');
    el.type = 'text';
    el.name = fieldname;
    el.id = el.name;
    el.style.width = width;

    return el;
}
/*
 * value_is_key set to true means option value = key num, otherwise option value = displayed value
 * */
function create_select_list(fieldname, width, list_options, value_is_key)
{
    var sel = document.createElement('select');
    sel.name = fieldname;
    sel.id = sel.name;
    sel.style.width = width;
    if(value_is_key == true)
    {
        for(i in list_options)
        {
            sel.options[i] = new Option(list_options[i], i);
        }
    }else{
        for(i in list_options)
        {
            sel.options[i] = new Option(list_options[i], list_options[i]);
        }
    }
    return sel;
}

function create_calendar_field(fieldname, width, alignment)
{
    if(alignment == 'right')
    {
        button_className = 'date_button';
    }else{
        button_className = 'date_button'
    }
    var cd = document.createElement('div');
    cd.id = "caldiv" + fieldname;
    cd.style.display = "inline";
    cd.style.position = "absolute";
    cd.style.visibility = "hidden";


    var ib = document.createElement('input');
    ib.type = "button";
    ib.title = "Select Date";
    ib.name = "datebutton" + fieldname;
    ib.className = button_className;
    ib.style.border = "0px";
    ib.style.padding = "0px 2px 0px 0px";
    ib.id = ib.name;



    var el = document.createElement('input');
    el.type = 'text';
    el.name = fieldname;
    el.id = el.name;
    el.style.width = width;


    ib.onclick = function(){ return create_cal_button_2(fieldname); }
    el.onfocus = function(){ return create_cal_button_2(fieldname); }
    el.onblur = function(){ return check_date(fieldname,""); }

    var pieces = new Array();
    pieces[0] = cd;
    pieces[1] = ib;
    pieces[2] = el;
    return pieces;
}
function create_txt_span(txt)
{
    el = document.createElement('span');
    el.className = 'error_notice';

    el.innerHTML = txt;
    return el;
}

function add_mcat_row(error_fields, errors)
{
    var table = document.getElementById('mcat_table');
    var lastrow = (table.rows.length-1);
    var iteration = lastrow;
    var row = table.insertRow(lastrow);
    row.className = "new_row";
    row.id = "insert[" + iteration + "][insert]";


    var cell0 = row.insertCell(0);
    cell0.className = "h_new_input_td";

    var cell0 = row.insertCell(1);
    cell0.className = "h_new_input_td";
    var cal = create_calendar_field('mcat[insert][' + iteration + '][date_taken]', '75px');
    cell0.appendChild(cal[0]);
    cell0.appendChild(cal[1]);
        cal[1].style.border = "0px";
        cal[1].style.margin = "0px 5px 0px 0px";
    cell0.appendChild(cal[2]);

    var cell1 = row.insertCell(2);
    cell1.className = "h_new_input_td";
    var el = create_text_input('mcat[insert][' + iteration + '][verbal_reasoning]', '50px');
    el.onblur = function(){ return total_mcat(iteration, true); }
    cell1.appendChild(el);


    var cell1 = row.insertCell(3);
    cell1.className = "h_new_input_td";
    var el = create_text_input('mcat[insert][' + iteration + '][physical_sciences]', '50px');
    el.onblur = function(){ return total_mcat(iteration, true); }
    cell1.appendChild(el);

    var cell1 = row.insertCell(4);
    cell1.className = "h_new_input_td";
    var el = create_text_input('mcat[insert][' + iteration + '][writing_sample]', '50px');
    el.onblur = function(){ return total_mcat(iteration, true); }
    cell1.appendChild(el);

    var cell1 = row.insertCell(5);
    cell1.className = "h_new_input_td";
    var el = create_text_input('mcat[insert][' + iteration + '][biological_sciences]', '50px');
    el.onblur = function(){ return total_mcat(iteration, true); }
    cell1.appendChild(el);

    var cell1 = row.insertCell(6);
    cell1.className = "h_new_input_td";
    var el = create_text_input('mcat_total_insert' + iteration, '50px');
    cell1.appendChild(el);

}
function add_table_row(table_id, row_id, insert_after_num)
{
    var table = document.getElementById('premed_table');
    var row = table.insertRow(insert_after_num);
    row.className = "new_row";
    row.id = row_id;
}
function add_premed_row(error_fields, errors)
{
    var pmct = new Array();
        pmct[0] = "Biological Sciences";
        pmct[1] = "Anatomy and Physiology";
        pmct[2] = "Chemistry";
        pmct[3] = "Physics";
        pmct[4] = "Mathematics, Statistics and Related";
        pmct[5] = "Psychology, Sociology and Related";
        pmct[6] = "Other";
    var yn = new Array();
        yn[0] = "No";
        yn[1] = "Yes";
    var grad = new Array();
        grad[0] = "Graduate";
        grad[1] = "Undergraduate";
    var years = new Array();
    var i;
    for(i = 0; i < 38; i ++)
    {
        years[i] = (1980 + i);
    }
    var table = document.getElementById('premed_table');
    var lastrow = (table.rows.length-1);
    var iteration = lastrow;
    var row = table.insertRow(lastrow);
    row.className = "new_row";
    row.id = "insert[" + iteration + "][insert]";

    var cell0 = row.insertCell(0);
    cell0.className = "h_new_input_td";

    var cell0 = row.insertCell(1);
    cell0.className = "h_new_input_td";
    var el = create_select_list('premed[insert][' + iteration + '][area_of_study]', '115px', pmct, false);
    // see if this field is in the error array and if so, border it in red and append error text
    idx = in_array(el.id, error_fields);
    if(idx != false)
    {
        el.style.border = '1px solid red';
    }

    cell0.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell0.appendChild(el2);
    }

    var cell1 = row.insertCell(2);
    cell1.className = "h_new_input_td";
    var el = create_text_input('premed[insert][' + iteration + '][title]', '100px');
    var thisFld = el.id;
    el.onblur = function(){ return check_required(thisFld, "The Course Title is Required!"); }
    cell1.appendChild(el);

    var cell2 = row.insertCell(3);
    cell2.className = "h_new_input_td";
    var el = create_select_list('premed[insert][' + iteration + '][schoolyear]', '110px', years, false);
    cell2.appendChild(el);

    var cell3 = row.insertCell(4);
    cell3.className = "h_new_input_td";
    var el = create_text_input('premed[insert][' + iteration + '][gradereceived]', '40px');
    cell3.appendChild(el);

    var cell4 = row.insertCell(5);
    cell4.className = "h_new_input_td";
    var el = create_select_list('premed[insert][' + iteration + '][currently_enrolled]', '115px', yn, true);
    cell4.appendChild(el);

    var cell5 = row.insertCell(6);
    cell5.className = "h_new_input_td";
    var cal = create_calendar_field('premed[insert][' + iteration + '][date_of_completion]', '75px');
    cell5.appendChild(cal[0]);

    cell5.appendChild(cal[1]);
        cal[1].style.border = "0px";
        cal[1].style.margin = "0px 5px 0px 0px";
    cell5.appendChild(cal[2]);

    var cell6 = row.insertCell(7);
    cell6.className = "h_new_input_td";
    var el = create_text_input('premed[insert][' + iteration + '][institution]', '100px');
    el.onblur = function(){ return check_required('premed[insert][' + iteration + '][institution]', "The Course Institution is Required!"); }
    cell6.appendChild(el);

    var cell7 = row.insertCell(8);
    cell7.className = "h_new_input_td";
    var el = create_select_list('premed[insert][' + iteration + '][graduate_or_undergraduate]', '115px', grad, false);
    cell7.appendChild(el);

}

function add_transcript_row(error_fields, errors)
{
    var states = new Array();
        states[1] ="AK";
        states[2] ="AL";
        states[3] ="AR";
        states[4] ="AZ";
        states[5] ="CA";
        states[6] ="CO";
        states[7] ="CT";

        states[8] ="DC";
        states[9] ="DE";
        states[10] ="FL";
        states[11] ="GA";
        states[12] ="HI";
        states[13] ="IA";
        states[14] ="ID";
        states[15] ="IL";
        states[16] ="IN";

        states[17] ="KS";
        states[18] ="KY";
        states[19] ="LA";
        states[20] ="MA";
        states[21] ="MD";
        states[22] ="ME";
        states[23] ="MI";
        states[24] ="MN";
        states[25] ="MO";

        states[26] ="MS";
        states[27] ="MT";
        states[28] ="N/A";
        states[29] ="NC";
        states[30] ="ND";
        states[31] ="NE";
        states[32] ="NH";
        states[33] ="NJ";
        states[34] ="NM";

        states[35] ="NV";
        states[36] ="NY";
        states[37] ="OH";
        states[38] ="OK";
        states[39] ="OR";
        states[40] ="PA";
        states[41] ="RI";
        states[42] ="SC";
        states[43] ="SD";

        states[44] ="TN";
        states[45] ="TX";
        states[46] ="UT";
        states[47] ="VA";
        states[48] ="VT";
        states[49] ="WA";
        states[50] ="WI";
        states[51] ="WV";
        states[52] ="WY";

    var table = document.getElementById('transcript_table');
    var lastrow = (table.rows.length-1);
    var iteration = lastrow;
    var row = table.insertRow(lastrow);
    row.className = "new_row";
    row.id = "insert[" + iteration + "][insert]";

    var cell0 = row.insertCell(0);
    cell0.className = "h_new_input_td";


    var cell0 = row.insertCell(1);
    cell0.className = "h_new_input_td";
    var el = create_text_input('transcript[insert][' + iteration + '][school]', '100px');
    cell0.appendChild(el);

    var cell0 = row.insertCell(2);
    cell0.className = "h_new_input_td";
    var el = create_text_input('transcript[insert][' + iteration + '][city]', '100px');
    cell0.appendChild(el);

    var cell1 = row.insertCell(3);
    cell1.className = "h_new_input_td";
    var el = create_select_list('transcript[insert][' + iteration + '][state]', '115px', states, false);
    cell1.appendChild(el);

    var cell2 = row.insertCell(4);
    cell2.className = "h_new_input_td";
    var cal = create_calendar_field('transcript[insert][' + iteration + '][start_date]', '75px');
    cell2.appendChild(cal[0]);
    cell2.appendChild(cal[1]);
        cal[1].style.border = "0px";
        cal[1].style.margin = "0px 5px 0px 0px";
    cell2.appendChild(cal[2]);

    var cell3 = row.insertCell(5);
    cell3.className = "h_new_input_td";
    var cal = create_calendar_field('transcript[insert][' + iteration + '][end_date]', '75px');
    cell3.appendChild(cal[0]);
    cell3.appendChild(cal[1]);
        cal[1].style.border = "0px";
        cal[1].style.margin = "0px 5px 0px 0px";
    cell3.appendChild(cal[2]);

    var cell4 = row.insertCell(6);
    cell4.className = "h_new_input_td";
    var el = create_text_input('transcript[insert][' + iteration + '][major]', '100px');
    cell4.appendChild(el);

    var cell5 = row.insertCell(7);
    cell5.className = "h_new_input_td";
    var el = create_text_input('transcript[insert][' + iteration + '][degrees_earned]', '100px');
    cell5.appendChild(el);

    var cell6 = row.insertCell(8);
    cell6.className = "h_new_input_td";
    var el = create_text_input('transcript[insert][' + iteration + '][transcript_gpa]', '20px');
    // see if this field is in the error array and if so, border it in red and append error text
    idx = in_array(el.id, error_fields);
    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    el.onblur = function(){ return check_num('transcript[insert][' + iteration + '][transcript_gpa]', "The gpa field must be a number!"); }

    cell6.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell6.appendChild(el2);
    }

    var cell7 = row.insertCell(9);
    cell7.className = "h_new_input_td";
    var el = create_text_input('transcript[insert][' + iteration + '][transcript_credit_hours]', '20px');
    // see if this field is in the error array and if so, border it in red and append error text
    idx = in_array(el.id, error_fields);
    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    el.onblur = function(){ return check_num('transcript[insert][' + iteration + '][transcript_credit_hours]', "The credit hours field must be a number!"); }

    cell7.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell7.appendChild(el2);
    }


}

function add_transfer_transcript_row(error_fields, errors)
{
    var states = new Array();
        states[1] ="AK";
        states[2] ="AL";
        states[3] ="AR";
        states[4] ="AZ";
        states[5] ="CA";
        states[6] ="CO";
        states[7] ="CT";

        states[8] ="DC";
        states[9] ="DE";
        states[10] ="FL";
        states[11] ="GA";
        states[12] ="HI";
        states[13] ="IA";
        states[14] ="ID";
        states[15] ="IL";
        states[16] ="IN";

        states[17] ="KS";
        states[18] ="KY";
        states[19] ="LA";
        states[20] ="MA";
        states[21] ="MD";
        states[22] ="ME";
        states[23] ="MI";
        states[24] ="MN";
        states[25] ="MO";

        states[26] ="MS";
        states[27] ="MT";
        states[28] ="N/A";
        states[29] ="NC";
        states[30] ="ND";
        states[31] ="NE";
        states[32] ="NH";
        states[33] ="NJ";
        states[34] ="NM";

        states[35] ="NV";
        states[36] ="NY";
        states[37] ="OH";
        states[38] ="OK";
        states[39] ="OR";
        states[40] ="PA";
        states[41] ="RI";
        states[42] ="SC";
        states[43] ="SD";

        states[44] ="TN";
        states[45] ="TX";
        states[46] ="UT";
        states[47] ="VA";
        states[48] ="VT";
        states[49] ="WA";
        states[50] ="WI";
        states[51] ="WV";
        states[52] ="WY";

    var table = document.getElementById('transfer_transcript_table');
    var lastrow = (table.rows.length-1);
    var iteration = lastrow;
    if(lastrow == 0 || lastrow == null || lastrow == '')
    {
        lastrow = 1;
    }
    var row = table.insertRow(lastrow);
    row.className = "new_row";
    row.id = "insert[" + iteration + "][insert]";

    var cell0 = row.insertCell(0);
    cell0.className = "h_new_input_td";


    var cell0 = row.insertCell(1);
    cell0.className = "h_new_input_td";
    var el = create_text_input('transfer_transcript[insert][' + iteration + '][school]', '100px');
    idx = in_array(el.id, error_fields);
    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    cell0.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell0.appendChild(el2);
    }

    var cell0 = row.insertCell(2);
    cell0.className = "h_new_input_td";
    var el = create_text_input('transfer_transcript[insert][' + iteration + '][city]', '100px');
    cell0.appendChild(el);

    var cell1 = row.insertCell(3);
    cell1.className = "h_new_input_td";
    var el = create_select_list('transfer_transcript[insert][' + iteration + '][state]', '115px', states, false);
    cell1.appendChild(el);

    var cell2 = row.insertCell(4);
    cell2.className = "h_new_input_td";
    var cal = create_calendar_field('transfer_transcript[insert][' + iteration + '][start_date]', '75px');
    cell2.appendChild(cal[0]);
    cell2.appendChild(cal[1]);
        cal[1].style.border = "0px";
        cal[1].style.margin = "0px 5px 0px 0px";
    cell2.appendChild(cal[2]);

    var cell3 = row.insertCell(5);
    cell3.className = "h_new_input_td";
    var cal = create_calendar_field('transfer_transcript[insert][' + iteration + '][end_date]', '75px');
    cell3.appendChild(cal[0]);
    cell3.appendChild(cal[1]);
        cal[1].style.border = "0px";
        cal[1].style.margin = "0px 5px 0px 0px";
    cell3.appendChild(cal[2]);

    var cell4 = row.insertCell(6);
    cell4.className = "h_new_input_td";
    var el = create_text_input('transfer_transcript[insert][' + iteration + '][major]', '100px');
    cell4.appendChild(el);

    var cell5 = row.insertCell(7);
    cell5.className = "h_new_input_td";
    var el = create_text_input('transfer_transcript[insert][' + iteration + '][degrees_earned]', '100px');
    cell5.appendChild(el);

    var cell6 = row.insertCell(8);
    cell6.className = "h_new_input_td";
    var el = create_text_input('transfer_transcript[insert][' + iteration + '][transcript_gpa]', '20px');
    // see if this field is in the error array and if so, border it in red and append error text
    idx = in_array(el.id, error_fields);
    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    el.onblur = function(){ return check_num('transfer_transcript[insert][' + iteration + '][transcript_gpa]', "The gpa field must be a number!"); }

    cell6.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell6.appendChild(el2);
    }


    var cell7 = row.insertCell(9);
    cell7.className = "h_new_input_td";
    var el = create_text_input('transfer_transcript[insert][' + iteration + '][transcript_credit_hours]', '20px');
    // see if this field is in the error array and if so, border it in red and append error text
    idx = in_array(el.id, error_fields);
    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    el.onblur = function(){ return check_num('transfer_transcript[insert][' + iteration + '][transcript_credit_hours]', "The credit hours field must be a number!"); }

    cell7.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell7.appendChild(el2);
    }


}

function add_employment_row(clinical, error_fields, errors)
{
    if(clinical == true)
    {
        field = "clinical";
    }else{
        field = "employment";

    }

    var table = document.getElementById(field + '_table');
    var lastrow = (table.rows.length-1);
    if(lastrow == null || lastrow == '')
    {
        lastrow = 0;
    }
    var iteration = lastrow;
    var row = table.insertRow(lastrow);
    row.className = "new_row";
    row.id = "insert[" + iteration + "][insert]";

    var cell0 = row.insertCell(0);
    cell0.className = "h_new_input_td";


    var cell0 = row.insertCell(1);
    cell0.className = "h_new_input_td";
    var el = create_text_input(field + '[insert][' + iteration + '][title]', '100px');

    // see if this field is in the error array and if so, border it in red and append error text
    idx = in_array(field + '[insert][' + iteration + '][title]', error_fields);

    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    el.onblur = function(){ return check_required(field + '[insert][' + iteration + '][title]', "The job title field is required!"); }
    cell0.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell0.appendChild(el2);
    }

    var cell1 = row.insertCell(2);
    cell1.className = "h_new_input_td";
    var el = create_text_input(field + '[insert][' + iteration + '][job_position]', '100px');
    idx = in_array(field + '[insert][' + iteration + '][job_position]', error_fields);

    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    cell1.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell1.appendChild(el2);
    }

    var cell2 = row.insertCell(3);
    cell2.className = "h_new_input_td";
    var el = create_text_input(field + '[insert][' + iteration + '][name_of_employer]', '100px');
    idx = in_array(field + '[insert][' + iteration + '][name_of_employer]', error_fields);

    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    cell2.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell2.appendChild(el2);
    }

    var cell3 = row.insertCell(4);
    cell3.className = "h_new_input_td";
    var el = create_text_input(field + '[insert][' + iteration + '][address]', '100px');
    idx = in_array(field + '[insert][' + iteration + '][address]', error_fields);

    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    cell3.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell3.appendChild(el2);
    }

    var cell4 = row.insertCell(5);
    cell4.className = "h_new_input_td";
    var el = create_text_input(field + '[insert][' + iteration + '][phone]', '100px');
    idx = in_array(field + '[insert][' + iteration + '][phone]', error_fields);

    if(idx != false)
    {
        el.style.border = '1px solid red';
    }
    cell4.appendChild(el);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell4.appendChild(el2);
    }

    var cell5 = row.insertCell(6);
    cell5.className = "h_new_input_td";
    var cal = create_calendar_field(field + '[insert][' + iteration + '][startdate]', '54px');
    idx = in_array(field + '[insert][' + iteration + '][startdate]', error_fields);

    if(idx != false)
    {
        cal.style.border = '1px solid red';
    }
    cell5.appendChild(cal[0]);
    cell5.appendChild(cal[1]);
        cal[1].style.border = "0px";
        cal[1].style.margin = "0px 5px 0px 0px";
    cell5.appendChild(cal[2]);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell5.appendChild(el2);
    }

    var cell6 = row.insertCell(7);
    cell6.className = "h_new_input_td";
    var cal = create_calendar_field(field + '[insert][' + iteration + '][enddate]', '54px');
    idx = in_array(field + '[insert][' + iteration + '][enddate]', error_fields);

    if(idx != false)
    {
        cal.style.border = '1px solid red';
    }
    cell6.appendChild(cal[0]);
    cell6.appendChild(cal[1]);
        cal[1].style.border = "0px";
        cal[1].style.margin = "0px 5px 0px 0px";
    cell6.appendChild(cal[2]);
    if(idx != false)
    {
        var el2 = create_txt_span(errors[idx]);
        cell6.appendChild(el2);
    }


}

function remove_blank_insert_rows(tableId)
{
    var table = document.getElementById(tableId);
    var rowCount = table.rows.length;

    for(var i=0; i<rowCount; i++)
    {
        var row = table.rows[i];
        if(row.id == 'row_id_' || row.id == 'row_id_remove')
        {
            table.deleteRow(i);
            rowCount--;
            i--;
        }

    }
}

function keep_alive()
{
    loadBareHTML('keep_alive.php', 'keep_alive', '');
    self.setTimeout('keep_alive()', 10000);
}
function autosave()
{
    if(document.getElementById('autosave_button') != null && dosave == true)
    {
        document.getElementById('autosave_button').click();
        self.setTimeout('autosave()', 10000);
    }
}
function stop_autosave()
{
    dosave = false;
}


