// holds an instance of XMLHttpRequest ///////////////////////////
var xmlHttp		= createXmlHttpRequestObject();	// core http object panel
var xmlHttp1	= createXmlHttpRequestObject();	// secondary segment div
var xmlHttp2	= createXmlHttpRequestObject();	// primary segment div
var xmlHttp3	= createXmlHttpRequestObject();	// Course summary div
var xmlHttp4	= createXmlHttpRequestObject();	// resources
var xmlHttp5	= createXmlHttpRequestObject();	// eGuide Meta Data
var xmlHttp6	= createXmlHttpRequestObject();	// check user
var xmlHttp7	= createXmlHttpRequestObject();	// update resource list for specific objective
var xmlHttp8	= createXmlHttpRequestObject();	// delete IGS
var xmlHttp9	= createXmlHttpRequestObject();	// Get all Stats
var xmlHttp10	= createXmlHttpRequestObject();	// Store page access into DB
var xmlHttp11	= createXmlHttpRequestObject();	// Get template location data
var xmlHttp12	= createXmlHttpRequestObject();	// Update Secondary Segment title
var xmlHttp13	= createXmlHttpRequestObject();	// generate MySQL Session ID
var xmlHttp14	= createXmlHttpRequestObject();	// get resource types for course for loading into drop down

// Global variables

var MySQLSessionID = generateSQLSessionId();    

var directLinkedCategory = "";
var directLinkedCategoryQuarter = 1;
var directLinkedCategorySecSeg = ''; // added by Iriny Assanassios on 7/23/10

getDirectLinkedCategoryValues();  // check for directly linked categories.

var sessionID = "";
var adminAuthority = -1;    // 1 - admin user; 2 - regular user; 3 -  account manager
var userid = "";
var useridDepartment = "";
var globalObjectiveIndex = 0;

var eGuideObjectiveArray = new Array();

// template variables

	var templatePageId = "";
	var templatePageTitle = "";
	var templatePrimarySegmentSectionArray = new Array("");
	var templateSecondarySegment = "";
	var templateCourseSummary = "";

	var templatePrimarySegment = "";
	var templateColumn1Title = "";
	var templateColumn2Title = "";
	var templateColumn3Title = "";
	var templateColumn4Title = "";
    
    var templateCourseResourceTypes = new Array("");

// creates an XMLHttpRequest /////////////////////////////////////
function createXmlHttpRequestObject()
{

	// will store the reference to the XMLHttpRequest object
	var xmlHttp;

	// this should work for all browsers except IE6 and older
	try
	{
		// try to create XMLHttpRequest object
		xmlHttp  = new XMLHttpRequest();
	}
	catch (e)
	{
    
        // assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"); 
		// try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				// try to create XMLHttpRequest object
				xmlHttp  = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch (e) {}
		}

	}
	// return the created object or display an error message
	if (!xmlHttp)
		alert ("Error Creating the XMLHttpRequest object(s).");
	else 
		return xmlHttp;
}

//////////////////////////////////////////////////////////////////

function generateSQLSessionId() // this mysql session value will be generated once each time the page is first accessed.  It is used to access the database.  It will be stored as a global variable and passed to each url.  If it cannot be generated an error will be reported.
{

	// only continue if xmlHttp isn't void
	if(xmlHttp13)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp13.open("GET", "php/getMySQLSessionId.php", true);
			xmlHttp13.onreadystatechange = handleRequestStateChangeMySQLSessionId;
			xmlHttp13.setRequestHeader("Content-Type", "text/xml");
			xmlHttp13.send(null);

		}
		// display the error in case of failure
		catch (e)
		{
			alert("Can't connect to server:\n" + e.toString());
		}
	}

}

function handleRequestStateChangeMySQLSessionId()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp13.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp13.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseMySQLSessionId();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp13.statusText);
		}
	}
}

function handleServerResponseMySQLSessionId()
{

	// read the message from the server
	var xmlResponse = xmlHttp13.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	MySQLSessionIdArray = xmlRoot.getElementsByTagName("mysqlsessionid");

	// Generate Results output
	
	if(MySQLSessionIdArray.length > 0)
	{
        return MySQLSessionIdArray.item(0).firstChild.data;
    }
    else
    {
        alert("Unable to establish a connection to the database.");
    }

}

//////////////////////////////////////////////////////////////////

function getDirectLinkedCategoryValues()
{

    var urlquery=location.href.split("?");
    if(urlquery.length > 1)
    {
        var urlterms = urlquery[1].split("&");
        
        if(urlterms.length > 0)
        {
            var argument1 = urlterms[0].split("=");
            if(argument1[0] == 'c')
                directLinkedCategory = argument1[1];
        }
        
        if(urlterms.length > 1)
        {
            var argument2 = urlterms[1].split("=");
            if(argument2[0] == 'q')
                directLinkedCategoryQuarter = argument2[1];
        }
	  // added by Iriny Assanassios on 7/23/10
        if(urlterms.length > 2)
        {
            var argument3 = urlterms[2].split("=");
            if(argument3[0] == 's')
                directLinkedCategorySecSeg = argument3[1].replace("%20", " ");
        }

    }
    
}

//////////////////////////////////////////////////////////////////

function runPopulationScripts()
{

	PageTitle();
	PagePurpose();
	PageOptions();
} 

function PageTitle()
{

	document.getElementById("eGuideTitle").innerHTML = "eGuides 2.0";
	document.getElementById("primarySegmentName").innerHTML = "";
	document.getElementById("primarySegmentDescription").innerHTML = "";

}

function PagePurpose()
{

	var title = "";
	var sectionTitle = "";
	var message = "";
	var sectionMessage = "";
	var string = "";
	var string2 = "";

	title = "Purpose";
	sectionTitle = "<br><span style=\"font-size: 15px; color:black; font-family: Arial;\" >" + title + "</span>";

	message = "The eGuides are an online tool to help teachers effectively deploy instruction to their students.<br><br><br>";

	message = message + "<span style=\"font-size: 15px; color:black; font-family: Arial;\" >History</span><br><br>The eGuides are a direct extension of the Electronic Mathematics Instructional Guides (e-MIGS).  The e-MIGS were created seven years ago by Jon Wray to give teachers an easy to use and highly effective tool to deliver specifc targeted objective-based instruction.  Two years ago, in collaboration with the Office of Media and Educational Technology (OMET) and e-Learning, it was modernized into an online interactive database still primarily used by mathematics, but with interest from other departments such as Secondary Science and Elementary Language Arts.  The current form has been fully realized into a full Web 2.0 application, which has scaled beyond mathematics and the other early adopters to include all the disciplines.</span>";


	sectionMessage = "<span style=\"font-size: 13px; color:Grey; font-family: Arial;\" >" + message + "</span>";

	string = sectionTitle + "<p>" + sectionMessage;

	var informationDivTag = "<div id=informationDivTag style=\"float: left; width: 400px; font-family: Arial;\">" + string + "</div>";
 
	string2 = string2 + "<br><span style=\"font-size: 15px; color:black; font-family: Arial;\" >Technical Recommendations</span><br><table cellpadding=10><tr><td><a href=\"http://www.spreadfirefox.com/node&id=0&t=319\"><img border=\"0\" alt=\"Foxkeh\" title=\"Foxkeh\" src=\"http://images.spreadfirefox.com/affiliates/Buttons/firefox3/foxkeh-fx3-120x60.png\"></a></td><td>Currently this application runs best using <span class=eGuideLink><a href=http://www.firefox.com target=_blank>FireFox 2.0.0.16+</a></span>.  If you have any questions or error reports please feel free to send them to Richard de los Santos.</td></tr></table><br></span>";

	string2 = string2 + "<span style=\"font-size: 15px; color:black; font-family: Arial;\" >Statistical Summary</span>";
	string2 = string2 + "<br><br><span style=\"font-size: 13px; color:grey; font-family: Arial;\" >There are over <b>200</b> courses loaded into the eGuides with over <b>18,000</b> objectives and nearly <b>25,000</b> resources.<br><br>The eGuides have been viewed over <b>373,000</b> times resulting in <b>250,000</b> downloaded resources.</span>";

//    string2 = string2 + "<br><br><span style=\"font-size: 15px; color: red; font-family: Arial;\" ><b>Section Lengths</b></span>";
//    string2 = string2 + "<br><br><span style=\"font-size: 13px; color: red; font-family: Arial;\" >A character length limit has been discovered.  Text fields cannot currently go beyond 4000 characters.  If you try to submit a text string longer than this limit it will not accept the data.  I am working on a fix.</span><br>";


//   string2 = string2 + "<br><br><span style=\"font-size: 13px; color: red; font-family: Arial;\" >Due to the exceptional efforts of the HCPSS curricular areas development of the eGuides is progressing as a very rapid rate.  The current load on the eGuides server is exceeding its capabilities.  In an effort to meet this demand the eGuides are being migrated to a new system.  The following are the next steps:<br><ul><li class=Checked><b>Migrate the eGuides 2.0 application and support files</b></li><li class=Checked><b>Point the migrated application to the old database</b></li><li class=Checked><b>Re-direct users to the new address (<a href=\"http://www.hcpsseduapps.org/eGuides\">http://www.hcpsseduapps.org/eGuides</a>)</b></li><li class=Checked><b>Migrate the eGuides 2.0 database to the new hardware</b></li><li class=Checked><b>Point the new Application to the new database location</b></li></ul></span>";
   
    var profiledDataDivTag = "<div id=profiledDataDivTag style=\"float: left; width: 350px; margin-left: 150px; font-family: Arial;font-size: 13px; color:grey;\">" + string2 + "</div>";


	document.getElementById("Purpose").innerHTML = informationDivTag + profiledDataDivTag;

}

function PageOptions()
{

	var options = "";
	
	if(1 == 1)
	{
		var stringLogin = "";
		
		stringLogin = stringLogin + "<span style=\"font-family: Arial; color: grey; font-size: 10px\"><a href=http://www.hcpsseduapps.org/DRPassword/DRPassword.php target=_blank>What is my DR login?</a></span> <input type=text id=Login value=\"Enter your DR Login\" style=\"font-family: Arial; color: black; font-size: 12px; width: 150px; border: 1px solid grey\" onclick=\"clearField('Login')\">"; 
		stringLogin = stringLogin + " <input type=password id=Password value=\"password\" style=\"font-family: Arial; color: black; font-size: 12px; width: 75px; border: 1px solid grey\"  onclick=\"clearField('Password')\">"; 
		stringLogin = stringLogin + " <input type=button id=submitLogin value=\"Login\" style=\"font-family: Arial; color: black; font-size: 11px; width: 75px; border: 1px solid grey\"  onclick=\"depressButton('submitLogin');athenticate('Password')\">"; 

		options = stringLogin;
	}

	document.getElementById("Options").innerHTML = options;

}

function athenticate()
{

	checkUser();

}

//////////////////////////////////////////////////////////////
// check user status /////////////////////////////////////////

function checkUser()
{

	// only continue if xmlHttp isn't void
	if(xmlHttp6)
	{
		// try to connect to the server
		try
		{

			var accountID = "";
			var accountUserid = document.getElementById("Login").value;
			var accountPassword = document.getElementById("Password").value;

			// initiate reading the Books from the server
			xmlHttp6.open("GET", "php/getSpecificAccountData.php?MySQLSessionID=" + MySQLSessionID + "&accountID=" + accountID + "&accountUserid=" + accountUserid + "&accountPassword=" + accountPassword, true);
			xmlHttp6.onreadystatechange = handleRequestStateChangeGetRole;
			xmlHttp6.setRequestHeader("Content-Type", "text/xml");
			xmlHttp6.send(null);

		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function handleRequestStateChangeGetRole()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp6.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp6.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseRole();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp6.statusText);
		}
	}
}

function handleServerResponseRole()
{

	// read the message from the server
	var xmlResponse = xmlHttp6.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray				= xmlRoot.getElementsByTagName("id");
	useridArray			= xmlRoot.getElementsByTagName("userid");
	passwordArray		= xmlRoot.getElementsByTagName("password");
	firstNameArray		= xmlRoot.getElementsByTagName("first_name");
	lastNameArray		= xmlRoot.getElementsByTagName("last_name");
	phoneArray			= xmlRoot.getElementsByTagName("phone");
	emailArray			= xmlRoot.getElementsByTagName("email");
	organizationArray	= xmlRoot.getElementsByTagName("organiztion");
	roleArray			= xmlRoot.getElementsByTagName("role");
	notesArray			= xmlRoot.getElementsByTagName("notes");
	departmentArray     = xmlRoot.getElementsByTagName("department");
	dateCreatedArray	= xmlRoot.getElementsByTagName("date_created");

	// Generate Results output
	
	if(idArray.length > 0)
	{
		// load global variables for user
		adminAuthority = roleArray.item(0).firstChild.data;
		userid = useridArray.item(0).firstChild.data;
		IHE = organizationArray.item(0).firstChild.data;
		email = emailArray.item(0).firstChild.data;
		useridDepartment = departmentArray.item(0).firstChild.data;
		
        $otherAppLinks = "<a href=\"http://media.hcpss.org/newcode/strategies/strategies.php\" target=_blank class=eGuideLink style=\"font-size: 12px; color:black; font-family: Arial;\">Instructional Strategies Database</a> <a href=\"http://media.hcpss.org/newcode/ekits/ekits.php\" target=_blank class=eGuideLink style=\"font-size: 12px; color:black; font-family: Arial;\">eKits</a>";
        
		// update the login div
		if(adminAuthority == 1)
			document.getElementById("Options").innerHTML = $otherAppLinks + " <span class=\"eGuideLink\" style=\"font-size: 12px; color: black; font-family: Arial;\" onclick=\"mainListofeGuides()\" >eGuides</span> <span class=\"eGuideLink\" style=\"font-size: 12px; color: black; font-family: Arial;\"><a href=http://doc.hcpss.org:8080/docushare/dsweb/Get/Document-98340/eGuides.doc target=_blank>Documentation</a></span> <span style=\"font-size: 12px; color:Grey; font-family: Arial;\" >" + userid + "</span> <span style=\"font-size: 12px; color: grey; font-family: Arial;\"><a href=\"index.html\">Logout</a></span>";
        else
			document.getElementById("Options").innerHTML = $otherAppLinks + " <span class=\"eGuideLink\" style=\"font-size: 12px; color: black; font-family: Arial;\" onclick=\"mainListofeGuides()\" >eGuides</span> <span style=\"font-size: 12px; color:Grey; font-family: Arial;\" >" + userid + "</span> <span style=\"font-size: 12px; color: grey; font-family: Arial;\"><a href=\"index.html\">Logout</a></span>";

		// generate session id
		// sessionId();
	
        // hide some divs
        document.getElementById("Purpose").style.display = "none";


        if(directLinkedCategory)
        {
            document.getElementById("ListeGuides").style.display = "none";
            displayeGuide(directLinkedCategory, "", directLinkedCategoryQuarter); 
        }
        else
        {
            
            // populate the list of eGuides
            populateeGuideList();

            document.getElementById("eGuideContent").style.display = "none";
            document.getElementById("eGuideOptions").style.display = "none";

            // display some divs
            document.getElementById("ListeGuides").style.display = "";
        
        }


	}
	else
	{
	
		alert("No user found");
		authenticationValue = 0;
	
	}
	
}

function mainListofeGuides()
{

//        break populateeGuideResources;

		PageTitle();  // resets the eGuide Title when listing all eguides

        templateCourseSummary = "";

		document.getElementById("eGuideContent").style.display = "none";
		document.getElementById("eGuideOptions").style.display = "none";

		// generate session id
		// sessionId();
	
		// hide some divs
		document.getElementById("Purpose").style.display = "none";

		// populate the list of eGuides
		populateeGuideList();

		// display some divs
		document.getElementById("ListeGuides").style.display = "";

}

// Populate eGuide List ///////////////////////////////////

// called to read data from the server
function populateeGuideList()
{

    document.getElementById("Progress").innerHTML = "";

	// only continue if xmlHttp isn't void
	if(xmlHttp)
	{
		// try to connect to the server
		try
		{        
			// initiate reading the Books from the server
			xmlHttp.open("GET", "php/geteGuideLists.php?MySQLSessionID=" + MySQLSessionID + "&DepartmentToView=" + useridDepartment, true);
			xmlHttp.onreadystatechange = handleRequestStateChangeeGuideList;
			xmlHttp.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function  handleRequestStateChangeeGuideList()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideList();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function handleServerResponseeGuideList()
{

	// read the message from the server
	var xmlResponse = xmlHttp.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray				= xmlRoot.getElementsByTagName("id");
	categoriesArray		= xmlRoot.getElementsByTagName("categories");
	sub_titleArray		= xmlRoot.getElementsByTagName("sub_title");
	descriptionArray	= xmlRoot.getElementsByTagName("description");
	departmentArray		= xmlRoot.getElementsByTagName("department");

	// Generate Results output
	
	if(idArray.length > 0)
	{

		document.getElementById("ListeGuides").innerHTML = "";

		var eGuides = "";
		var previousCurricularArea = "";
		var neweGuideFormString = "";
		var addNewCourseString = "";

		
		eGuides = eGuides + "<div class = curricularTitle>eGuides Statistics</div>";
		eGuides = eGuides + "<ul>";
		eGuides = eGuides + "<li class=eGuidStats><span class=eGuideLink style=\"font-size: 14px; color:black; font-family: Arial;\">Total # of eGuides: <span id=TotaleGuides>" + + "</span></li>";
		eGuides = eGuides + "<li class=eGuidStats><span class=eGuideLink style=\"font-size: 14px; color:black; font-family: Arial;\">Total # of Resources: <span id=TotalResources>" + + "</span></li>";
		eGuides = eGuides + "<li class=eGuidStats><span class=eGuideLink style=\"font-size: 14px; color:black; font-family: Arial;\">Total # of Objectives: <span id=TotalObjectives>" + + "</span></li>";
		eGuides = eGuides + "<li class=eGuidStats><span class=eGuideLink style=\"font-size: 14px; color:black; font-family: Arial;\">Total # of Downloaded Resources: <span id=TotalDownloads>" + + "</span></li>";
		eGuides = eGuides + "<li class=eGuidStats><span class=eGuideLink style=\"font-size: 14px; color:black; font-family: Arial;\">Total # of Viewed Pages: <span id=TotalPageViews>" + + "</span></li>";
		eGuides = eGuides + "</ul>";

		eGuides = eGuides + "<div class = curricularTitle>Associated Applications</div>";
		eGuides = eGuides + "<ul>";
		eGuides = eGuides + "<li class=PrimarySegments><a href=\"http://media.hcpss.org/newcode/strategies/strategies.php\" target=_blank class=eGuideLink style=\"font-size: 14px; color:black; font-family: Arial;\">Instructional Strategies Database</a></li>";
		eGuides = eGuides + "<li class=PrimarySegments><a href=\"http://media.hcpss.org/newcode/ekits/ekits.php\" target=_blank class=eGuideLink style=\"font-size: 14px; color:black; font-family: Arial;\">eKits</a></li>";
		eGuides = eGuides + "</ul>";

		for(var i=0; i < idArray.length; i++)
		{

			if(descriptionArray.item(i).firstChild.data.length == 1)
				description = "Please provide a course description";
			else
				description = descriptionArray.item(i).firstChild.data;

			if(departmentArray.item(i).firstChild.data.length == 1)
				curr_off = "Experiemental Course Testing Platform";
			else
				curr_off = departmentArray.item(i).firstChild.data;

			if((previousCurricularArea != departmentArray.item(i).firstChild.data || i == idArray.length) && i > 0)
			{			
				eGuides = eGuides + "</ul></div></td><td width=550><span id='neweGuideForm" + departmentArray.item(i-1).firstChild.data.replace(/ /gi, '') + "' style=\"font-size: 14px; color:black; font-family: Arial;\"></span></td></tr></table>";			
			}

			if(previousCurricularArea != departmentArray.item(i).firstChild.data)
			{
				eGuides = eGuides + "<div class = curricularTitle>" + curr_off + "</div>";
				eGuides = eGuides + "<table border=0>";	
				
				if(adminAuthority == 1)					
					eGuides = eGuides + "<tr valign=top><td width=400><ul><li class=EditResources><span class=eGuideLink style=\"font-size: 14px; color:black; font-family: Arial;\" onclick=\"displayNewCourseForm(0, 'neweGuideForm" + departmentArray.item(i).firstChild.data.replace(/ /gi, '') + "', '" + departmentArray.item(i).firstChild.data + "')\">Add New Course</span></li></ul>";

					eGuides = eGuides + "<tr valign=top><td width=400><ul><li class=EditResources></li></ul>";


				eGuides = eGuides + "<div id=courseList" + i + ">";
				eGuides = eGuides + "<ul>";			
			}

			if(adminAuthority == 1)					
            {
                if(departmentArray.item(i).firstChild.data == " ")
                    eGuides = eGuides + "<li class=PrimarySegments><span class=eGuideLink id = '" + departmentArray.item(i).firstChild.data.replace(/ /gi, '') + "' style=\"font-size: 14px; color:black; font-family: Arial;\" onclick=\"displayeGuide(" + idArray.item(i).firstChild.data + ", '" + categoriesArray.item(i).firstChild.data + "', '" + 1 + "')\">" + categoriesArray.item(i).firstChild.data + "</span> <span style=\"font-size: 7px; font-family: Ariel; font-color: grey\">" + (idArray.item(i).firstChild.data) + "</span> <img src=\"images/customEdit.png\" onclick=\"editTemplate('"+ idArray.item(i).firstChild.data + "', '" + departmentArray.item(i).firstChild.data + "')\"> <img src=\"images/deleteItem.png\" onclick=\"deleteIGS('" + idArray.item(i).firstChild.data + "')\"><br>";
                else
                    eGuides = eGuides + "<li class=PrimarySegments><span class=eGuideLink id = '" + departmentArray.item(i).firstChild.data.replace(/ /gi, '') + "' style=\"font-size: 14px; color:black; font-family: Arial;\" onclick=\"displayeGuide(" + idArray.item(i).firstChild.data + ", '" + categoriesArray.item(i).firstChild.data + "', '" + 1 + "')\">" + categoriesArray.item(i).firstChild.data + "</span> <span style=\"font-size: 7px; font-family: Ariel; font-color: grey\">" + (idArray.item(i).firstChild.data) + "</span> <img src=\"images/customEdit.png\" onclick=\"editTemplate('"+ idArray.item(i).firstChild.data + "', '" + departmentArray.item(i).firstChild.data + "')\"> <br>";
            }
			else
				eGuides = eGuides + "<li class=PrimarySegments><span class=eGuideLink id = '" + departmentArray.item(i).firstChild.data.replace(/ /gi, '') + "' style=\"font-size: 14px; color:black; font-family: Arial;\" onclick=\"displayeGuide(" + idArray.item(i).firstChild.data + ", '" + categoriesArray.item(i).firstChild.data + "', '" + 1 + "')\">" + categoriesArray.item(i).firstChild.data + "</span><br>";
	
			eGuides = eGuides + "<span style=\"font-size: 14px; color:grey; font-family: Arial;\" >" + description + "<br><br></span></li>";

			previousCurricularArea = departmentArray.item(i).firstChild.data;

		}

        eGuides = eGuides + "</ul></div></td><td width=550><span id='neweGuideForm" + departmentArray.item(idArray.length-1).firstChild.data.replace(/ /gi, '') + "' style=\"font-size: 14px; color:black; font-family: Arial;\"></span></td></tr></table>";			

		document.getElementById("ListeGuides").innerHTML = eGuides;
		
		geteGuidesStatistics();

	}

}

// Get eGuides Statistics ///////////////////////////////////

function geteGuidesStatistics()
{

	// only continue if xmlHttp isn't void
	if(xmlHttp9)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp9.open("GET", "php/geteGuideStatistics.php?MySQLSessionID=" + MySQLSessionID, true);
			xmlHttp9.onreadystatechange = handleRequestStateChangeeGuideStatistics
			xmlHttp9.send(null);

		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function  handleRequestStateChangeeGuideStatistics()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp9.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp9.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuidesStatistics();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp9.statusText);
		}
	}
}

function handleServerResponseeGuidesStatistics()
{

	// read the message from the server
	var xmlResponse = xmlHttp9.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	toteGuidesArray = xmlRoot.getElementsByTagName("totaleguides");
	totResourcesArray = xmlRoot.getElementsByTagName("totalresources");
	totObjectivesArray = xmlRoot.getElementsByTagName("totalplacedobjectives");
	totDownloadsArray = xmlRoot.getElementsByTagName("totaldownloads");
	totPageViewsArray = xmlRoot.getElementsByTagName("totalpageviews");

	document.getElementById("TotaleGuides").innerHTML = toteGuidesArray.item(0).firstChild.data;
	document.getElementById("TotalResources").innerHTML = totResourcesArray.item(0).firstChild.data;
	document.getElementById("TotalObjectives").innerHTML = totObjectivesArray.item(0).firstChild.data;
	document.getElementById("TotalDownloads").innerHTML = totDownloadsArray.item(0).firstChild.data;
	document.getElementById("TotalPageViews").innerHTML = totPageViewsArray.item(0).firstChild.data;

}

// Get eGuide Template data //////////////////////////////////
// This is used for populating the template for update and for updating the eGuides themselves

function populateeGuideTemplateData(eGuideId)
{

	// only continue if xmlHttp isn't void
	if(xmlHttp5)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp5.open("GET", "php/geteGuideTemplateData.php?MySQLSessionID=" + MySQLSessionID + "&eGuideId=" + eGuideId, true);
			xmlHttp5.onreadystatechange = handleRequestStateChangeeGuideTemplateData;
			xmlHttp5.send(null);

		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function  handleRequestStateChangeeGuideTemplateData()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp5.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp5.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideTemplateData();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp5.statusText);
		}
	}
}

function handleServerResponseeGuideTemplateData()
{

	// read the message from the server
	var xmlResponse = xmlHttp5.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray					= xmlRoot.getElementsByTagName("id");
	departmentArray			= xmlRoot.getElementsByTagName("department");
	categoriesArray			= xmlRoot.getElementsByTagName("categories");
	descriptionArray		= xmlRoot.getElementsByTagName("description");
	primary_segmentArray	= xmlRoot.getElementsByTagName("primary_segment");
	primary_segment_1_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_1_description");
	primary_segment_2_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_2_description");
	primary_segment_3_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_3_description");
	primary_segment_4_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_4_description");
	primary_segment_5_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_5_description");
	primary_segment_6_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_6_description");
	primary_segment_7_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_7_description");
	primary_segment_8_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_8_description");
	primary_segment_9_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_9_description");
	primary_segment_10_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_10_description");
	secondary_segmentArray	= xmlRoot.getElementsByTagName("secondary_segment");
	column_1_titleArray		= xmlRoot.getElementsByTagName("column_1_title");
	column_2_titleArray		= xmlRoot.getElementsByTagName("column_2_title");
	column_3_titleArray		= xmlRoot.getElementsByTagName("column_3_title");
	column_4_titleArray		= xmlRoot.getElementsByTagName("column_4_title");
	date_createdArray		= xmlRoot.getElementsByTagName("date_created");
	date_editArray			= xmlRoot.getElementsByTagName("date_edit");
	userid_createdArray		= xmlRoot.getElementsByTagName("userid_created");
	userid_editArray		= xmlRoot.getElementsByTagName("userid_edit");

// load template values into global variables

	templatePageId = idArray.item(0).firstChild.data;
	templatePageTitle = categoriesArray.item(0).firstChild.data;
	templatePrimarySegment = primary_segmentArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[0]  = primary_segment_1_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[1]  = primary_segment_2_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[2]  = primary_segment_3_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[3]  = primary_segment_4_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[4]  = primary_segment_5_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[5]  = primary_segment_6_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[6]  = primary_segment_7_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[7]  = primary_segment_8_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[8]  = primary_segment_9_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[9] = primary_segment_10_descriptionArray.item(0).firstChild.data;
		
	templateSecondarySegment = secondary_segmentArray.item(0).firstChild.data;
	templateCourseSummary = descriptionArray.item(0).firstChild.data;
	
	templateColumn1Title = column_1_titleArray.item(0).firstChild.data;
	templateColumn2Title = column_2_titleArray.item(0).firstChild.data;
	templateColumn3Title = column_3_titleArray.item(0).firstChild.data;
	templateColumn4Title = column_4_titleArray.item(0).firstChild.data;
	
	var eGuideOptions = "";
	
	eGuideOptions = eGuideOptions + "<span style=\"font-size: 13px; color: black; font-family: Arial; font-weight:bold;\">" + templatePrimarySegment + "s</span><ul>";

	for(var i=1; i < templatePrimarySegmentSectionArray.length+1; i++)
	{
		var tempString = templatePrimarySegmentSectionArray[i-1];
		
		if(tempString.substring(0,15) != "Primary Segment")
		{
			eGuideOptions = eGuideOptions + "<li class=PrimarySegments><span class=eGuideLink id=\""  + templatePrimarySegment + i + "\" style=\"font-size: 12px; color: black; font-family: Arial;\" onclick=\"populateeGuideContent('" + templatePageId + "', " + i + ", '');populateeGuideOptionsSecondarySegments('" + templatePageId + "', " + i + ")\">" + templatePrimarySegment + " " + i + "</span><br>";
			eGuideOptions = eGuideOptions + "<span style=\"font-size: 12px; color: grey; font-family: Arial;\" >" + templatePrimarySegmentSectionArray[i-1] + "</span></li>";
		}
		
	}

	eGuideOptions = eGuideOptions + "</ul>";

	document.getElementById("eGuideOptionsPrimarySegments").innerHTML = eGuideOptions;

}

// Get Course Resource Types /////////////////////////////
// This function gets the list of resource types for the given class and then builds up the resource type list for use in the drop down menus //
// this function only runs if in admin mode ///

function populateeGuideTemplateResourceTypeData(eGuideId)
{

	// only continue if xmlHttp isn't void
	if(xmlHttp14)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp14.open("GET", "php/geteGuideTemplateResourceTypeData.php?MySQLSessionID=" + MySQLSessionID + "&eGuideId=" + eGuideId, true);
			xmlHttp14.onreadystatechange = handleRequestStateChangeeGuideTemplateResourceTypeData;
			xmlHttp14.send(null);

		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function  handleRequestStateChangeeGuideTemplateResourceTypeData()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp14.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp14.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideTemplateResourceTypeData();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp14.statusText);
		}
	}
}

function handleServerResponseeGuideTemplateResourceTypeData()
{

	// read the message from the server
	var xmlResponse = xmlHttp14.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray             = xmlRoot.getElementsByTagName("id");
    resourceTypeArray   = xmlRoot.getElementsByTagName("resourcetype");

// load template values into global variables

    for(var i=0; i< idArray.length; i++)
    {
        templateCourseResourceTypes[i] = resourceTypeArray.item(i).firstChild.data;
	}

}


// Load eGuide Template //////////////////////////////////
// This is used for populating the template for update and for updating the eGuides themselves

function populateeGuideTemplate(eGuideId)
{

	// only continue if xmlHttp isn't void
	if(xmlHttp5)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp5.open("GET", "php/geteGuideTemplateData.php?MySQLSessionID=" + MySQLSessionID + "&eGuideId=" + eGuideId, true);
			xmlHttp5.onreadystatechange = handleRequestStateChangeeGuideTemplate;
			xmlHttp5.send(null);

		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function  handleRequestStateChangeeGuideTemplate()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp5.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp5.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideTemplate();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp5.statusText);
		}
	}
}

function handleServerResponseeGuideTemplate()
{

	// read the message from the server
	var xmlResponse = xmlHttp5.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray					= xmlRoot.getElementsByTagName("id");
	departmentArray			= xmlRoot.getElementsByTagName("department");
	categoriesArray			= xmlRoot.getElementsByTagName("categories");
	descriptionArray		= xmlRoot.getElementsByTagName("description");
	primary_segmentArray	= xmlRoot.getElementsByTagName("primary_segment");
	primary_segment_1_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_1_description");
	primary_segment_2_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_2_description");
	primary_segment_3_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_3_description");
	primary_segment_4_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_4_description");
	primary_segment_5_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_5_description");
	primary_segment_6_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_6_description");
	primary_segment_7_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_7_description");
	primary_segment_8_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_8_description");
	primary_segment_9_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_9_description");
	primary_segment_10_descriptionArray	= xmlRoot.getElementsByTagName("primary_segment_10_description");
	secondary_segmentArray	= xmlRoot.getElementsByTagName("secondary_segment");
	column_1_titleArray		= xmlRoot.getElementsByTagName("column_1_title");
	column_2_titleArray		= xmlRoot.getElementsByTagName("column_2_title");
	column_3_titleArray		= xmlRoot.getElementsByTagName("column_3_title");
	column_4_titleArray		= xmlRoot.getElementsByTagName("column_4_title");
	date_createdArray		= xmlRoot.getElementsByTagName("date_created");
	date_editArray			= xmlRoot.getElementsByTagName("date_edit");
	userid_createdArray		= xmlRoot.getElementsByTagName("userid_created");
	userid_editArray		= xmlRoot.getElementsByTagName("userid_edit");

// load template values into global variables

	templatePageId = idArray.item(0).firstChild.data;
	templatePageTitle = categoriesArray.item(0).firstChild.data;
	templatePrimarySegment = primary_segmentArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[0]  = primary_segment_1_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[1]  = primary_segment_2_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[2]  = primary_segment_3_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[3]  = primary_segment_4_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[4]  = primary_segment_5_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[5]  = primary_segment_6_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[6]  = primary_segment_7_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[7]  = primary_segment_8_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[8]  = primary_segment_9_descriptionArray.item(0).firstChild.data;
	templatePrimarySegmentSectionArray[9] = primary_segment_10_descriptionArray.item(0).firstChild.data;
		
	templateSecondarySegment = secondary_segmentArray.item(0).firstChild.data;
	templateCourseSummary = descriptionArray.item(0).firstChild.data;
	
	templateColumn1Title = column_1_titleArray.item(0).firstChild.data;
	templateColumn2Title = column_2_titleArray.item(0).firstChild.data;
	templateColumn3Title = column_3_titleArray.item(0).firstChild.data;
	templateColumn4Title = column_4_titleArray.item(0).firstChild.data;
	
    // load template

	document.getElementById("newCourseTitle" + templatePageId).value = templatePageTitle;
	document.getElementById("newCoursePrimarySegment" + templatePageId).value = templatePrimarySegment;
	document.getElementById("newCoursePrimarySegmentIDescription" + templatePageId).value = templatePrimarySegmentSectionArray[0];
	document.getElementById("newCoursePrimarySegmentIIDescription" + templatePageId).value = templatePrimarySegmentSectionArray[1];
	document.getElementById("newCoursePrimarySegmentIIIDescription" + templatePageId).value = templatePrimarySegmentSectionArray[2];
	document.getElementById("newCoursePrimarySegmentIVDescription" + templatePageId).value = templatePrimarySegmentSectionArray[3];
	document.getElementById("newCoursePrimarySegmentVDescription" + templatePageId).value = templatePrimarySegmentSectionArray[4];
	document.getElementById("newCoursePrimarySegmentVIDescription" + templatePageId).value = templatePrimarySegmentSectionArray[5];
	document.getElementById("newCoursePrimarySegmentVIIDescription" + templatePageId).value = templatePrimarySegmentSectionArray[6];
	document.getElementById("newCoursePrimarySegmentVIIIDescription" + templatePageId).value = templatePrimarySegmentSectionArray[7];
	document.getElementById("newCoursePrimarySegmentIXDescription" + templatePageId).value = templatePrimarySegmentSectionArray[8];
	document.getElementById("newCoursePrimarySegmentXDescription" + templatePageId).value = templatePrimarySegmentSectionArray[9];
	document.getElementById("newCourseSecondarySegment" + templatePageId).value = templateSecondarySegment;
	document.getElementById("newCourseSummary" + templatePageId).value = templateCourseSummary;
	document.getElementById("newCourseCol1" + templatePageId).value = templateColumn1Title;
	document.getElementById("newCourseCol2" + templatePageId).value = templateColumn2Title;
	document.getElementById("newCourseCol3" + templatePageId).value = templateColumn3Title;
	document.getElementById("newCourseCol4" + templatePageId).value = templateColumn4Title

}

function editTemplate(eGuideId,departmentName)
{

	// the template form needs to be drawn into the page when the page is rendered
	// it will be populated and displayed by this function when a specific course is chosen for editing

	displayNewCourseForm(eGuideId, "neweGuideForm" + departmentName.replace(/ /gi, ''), departmentName);
	populateeGuideTemplate(eGuideId);
    loadResourceAllocationIntoTemplate(eGuideId);

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function displayeGuide(eGuideId,eGuideTitle,eGuideQuarter)
{
   // break populateeGuideResources;

	// update the viewed eguides table
//	putPageAccessIntoDB(eGuideId,eGuideQuarter);

	// hide eGuides List
	document.getElementById("ListeGuides").style.display = "none";

	// popuate eGuide content
	populateeGuideTemplateData(eGuideId);  // stores the template variables globally
    
//    if(adminAuthority == 1)
        populateeGuideTemplateResourceTypeData(eGuideId);  // stores the course resource types list globally

	document.getElementById("eGuideContent").style.display = "";
	
	// if statement added by Iriny Assanassios on 7/23/10
	if(directLinkedCategorySecSeg != '') {
		populateeGuideContent(eGuideId,eGuideQuarter,directLinkedCategorySecSeg);
	} else {
		populateeGuideContent(eGuideId,eGuideQuarter,'');	// draws table
	}
	populateeGuideOptions(eGuideId,eGuideQuarter);		// draws template for primary and segment information, title and column titles, places the resource types into the specified columns

	// display eguide content
	document.getElementById("eGuideOptions").style.display = "";

}

// Put Page Access into tracking table /////////////////////////

function putPageAccessIntoDB(eGuideId,eGuideQuarter)
{

	// only continue if xmlHttp isn't void
	if(xmlHttp10)
	{
		// try to connect to the server
		try
		{
		
			// initiate reading the Books from the server
			xmlHttp10.open("POST", "php/putIGSTrackingData.php?MySQLSessionID=" + MySQLSessionID + "&eGuideId=" + eGuideId + "&UserID=" + userid + "&eGuideQuarter=" + eGuideQuarter, true);
			xmlHttp10.send(null);

		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}
}

//// Get eGuide Content /////////////////////////////////////////
// called to read data from the server
function populateeGuideContent(eGuideId,eGuideQuarter,eGuideSecondarySegment)
{

    putPageAccessIntoDB(eGuideId,eGuideQuarter);

	document.getElementById("eGuideContent").innerHTML = "<br><br><br><br><br><center><img src=images/AjaxLoadingIcon.gif></center>"; // draws a loading icon while data is being processed

//	document.getElementById("primarySegmentName").innerHTML = "<span style=\"font-size: 20px; color: black; font-family: Arial;\">" + templatePrimarySegmentSectionArray[eGuideQuarter] + "</span>";
//	document.getElementById("primarySegmentDescription").innerHTML = " <span style=\"font-size: 15px; color: grey; font-family: Arial;\">Description for Primary Segment " + eGuideQuarter + "</span>";

	// only continue if xmlHttp isn't void
	if(xmlHttp)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server			
			xmlHttp.open("GET", "php/geteGuideContent.php?MySQLSessionID=" + MySQLSessionID + "&eGuideID=" + eGuideId + "&eGuideQuarter=" + eGuideQuarter + "&eGuideSecondarySegment=" + eGuideSecondarySegment, true);
			xmlHttp.onreadystatechange = handleRequestStateChangeeGuideContent;
			xmlHttp.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
		
	}
}

// function that handles the HTTP response
function  handleRequestStateChangeeGuideContent()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideContent();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function handleServerResponseeGuideContent()
{

	// read the message from the server
	var xmlResponse = xmlHttp.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	IGSIdArray			= xmlRoot.getElementsByTagName("id");
	category_idArray	= xmlRoot.getElementsByTagName("category_id");
	categoryArray	= xmlRoot.getElementsByTagName("category");
	quarterArray	= xmlRoot.getElementsByTagName("quarter");
	sub_topicsArray	= xmlRoot.getElementsByTagName("sub_topics");
	objectivesArray	= xmlRoot.getElementsByTagName("objectives");
	limitsArray	= xmlRoot.getElementsByTagName("limits");
	examplesArray	= xmlRoot.getElementsByTagName("examples");
	resourcesArray	= xmlRoot.getElementsByTagName("resources");
	date_submittedArray	= xmlRoot.getElementsByTagName("date_submitted");
	objectiveArray	= xmlRoot.getElementsByTagName("objective");
	last_date_editedArray	= xmlRoot.getElementsByTagName("last_date_edited");
	sub_topic_orderArray	= xmlRoot.getElementsByTagName("sub_topic_order");

	// Generate Results output
	
	var addObjective = "";

/*	if(adminAuthority == 1)
	{
		addObjective = "<ul>";
		addObjective = addObjective + "<li class=EditResources><span class=eGuideLink style=\"font-family: Arial; color: black; font-size: 13px;\" onclick=\"displayAddObjectiveForm('AddObjective" + 0 + "');\">Add Objective</span><br><span ID=AddObjective" + 0 + " style=\"display: none;\">" + 0 + "</span></li>";
		addObjective = addObjective + "</ul>";
	}
*/

	if(IGSIdArray.length > 0)
	{

		document.getElementById("ListeGuides").innerHTML = "";
		
		var eGuide = "";
		var limitsString = new String("");
		var examplesString = new String("");
		var previousTopic = new String("");
		var addResourceTitle = "";
		var adminResourceString = "";
		var addObjectiveLimit = "";
		var addObjectiveExample = "";
		var editObjective = "";

		eGuideObjectiveArray = new Array("");
		globalObjectiveIndex = 0;
		
		eGuide = eGuide + "<table class=\"eGuide\">";
	
		// header template related
		
		for(var i=0; i < IGSIdArray.length; i++)
		{

			limitsString = limitsArray.item(i).firstChild.data;
			limitsString = limitsString.replace(/%3C/g, "<");
			limitsString = limitsString.replace(/%3E/g, ">");
			limitsString = limitsString.replace(/%26/g, "&");

			examplesString = examplesArray.item(i).firstChild.data;
			examplesString = examplesString.replace(/%3C/g, "<");
			examplesString = examplesString.replace(/%3E/g, ">");
			examplesString = examplesString.replace(/%26/g, "&");

			objectivesString = objectivesArray.item(i).firstChild.data;
			objectivesString = objectivesString.replace(/%3C/g, "<");
			objectivesString = objectivesString.replace(/%3E/g, ">");
			objectivesString = objectivesString.replace(/%26/g, "&");

			if(previousTopic != sub_topicsArray.item(i).firstChild.data)
			{

				eGuide = eGuide + "<tr><th class=\"eGuide\" colspan=4>" + unescape(sub_topicsArray.item(i).firstChild.data) + "</th></tr>";
				eGuide = eGuide + "<tr><th class=\"eGuide\" width=\"200\"><span id=eGuideContentColumn1>" + templateColumn1Title + "</span></th><th class=\"eGuide\" width=\"250\"><span id=eGuideContentColumn2>" + templateColumn2Title + "</span></th><th class=\"eGuide\" width=\"350\"><span id=eGuideContentColumn3>" + templateColumn3Title + "</span></th><th class=\"eGuide\"  width=\"200\"><span  id=eGuideContentColumn4>" + templateColumn4Title + "</span></th></tr>";								
			}

			if(adminAuthority == 1)
			{
			
				addResourceTitle = "<input class=inputFormInternDataReadOnly type=text id=addResourceID" + objectiveArray.item(i).firstChild.data + " value=\"ID Not Assigned\"><br>";
				addResourceTitle = addResourceTitle + "<input class=eGuideInputForm type=text id=addResourceTitle" + objectiveArray.item(i).firstChild.data + " value=\"Title\"><br>";
				addResourceTitle = addResourceTitle + "<input class=eGuideInputForm type=text id=addResourceLink" + objectiveArray.item(i).firstChild.data + " value=\"Link (http://www.link.com)\"><br>";
				addResourceTitle = addResourceTitle + "<textarea class=eGuideInputForm id=addResourceDescription" + objectiveArray.item(i).firstChild.data + ">Description</textarea><br>";

                addResourceTitle = addResourceTitle + "<select class=eGuideInputForm id=addResourceType" + objectiveArray.item(i).firstChild.data + "><option value=''>Resource Type</option>";
                for(var j=0; j < templateCourseResourceTypes.length; j++)
                {
                
                    addResourceTitle = addResourceTitle + "<option value='" + templateCourseResourceTypes[j] + "'>" + templateCourseResourceTypes[j] + "</option>";
                    
                }
                addResourceTitle = addResourceTitle + "</select>";

//				addResourceTitle = addResourceTitle + "<select class=eGuideInputForm id=addResourceType" + objectiveArray.item(i).firstChild.data + "><option value=''>Resource Type</option><option value='Activities'>Activities</option><option value='Animation'>Animation</option><option value='Audiocasts'>Audiocasts</option><option value='Constructed Response Items'>Constructed Response Items</option><option value='DR'>DR</option><option value='eText'>eText</option><option value='eTools'>eTools</option><option value='Exemplary Lessons'>Exemplary Lessons</option><option value='Games'>Games</option><option value='Graphing Calculator'>Graphing Calculator</option><option value='Illustration'>Illustration</option><option value='Images'>Images</option><option value='Labs'>Labs</option><option value='Lesson Seeds'>Lesson Seeds</option><option value='Maps'>Maps</option><option value='MISC'>MISC</option><option value='Projects'>Projects</option><option value='Quizzes and Tests'>Quizzes and Tests</option><option value='Reviews'>Reviews</option><option value='Song'>Song</option><option value='Student Activities'>Student Activities</option><option value='Teacher Support'>Teacher Support</option><option value='Technology Based Activity'>Technology Based Activity</option><option value='Text'>Text</option><option value='Tutorials'>Tutorials</option><option value='Video Segments'>Video Segments</option><option value='Videocasts'>Videocasts</option><option value='Warm-ups'>Warm-ups</option><option value='Web'>Web</option><option value='Objectives'>Objectives</option><option value='Listening'>Listening</option><option value='Speaking'>Speaking</option><option value='Writing'>Writing</option><option value='Reading'>Reading</option><option value='Health'>Health</option><option value='Mathematics'>Mathematics</option><option value='Social Studies'>Social Studies</option><option value='Science'>Science</option><option value='Unit Overview'>Unit Overview</option><option value='Literature'>Literature</option><option value='Rubric'>Rubric</option><option value='Practice Items'>Practice Items</option><option value='Check Lists'>Check Lists</option><option value='Peer Assessments'>Peer Assessments</option><option value='Modified Student Resources'>Modified Student Resources</option></select><br>";

				addResourceTitle = addResourceTitle + "<input class=eGuideInputFormCheckBox type=checkbox id=addResourceHide" + objectiveArray.item(i).firstChild.data + ">Hidden?";
				addResourceTitle = addResourceTitle + " <input type=button id=submitNewResource" + objectiveArray.item(i).firstChild.data + " value=\"Add Resource\" style=\"font-family: Arial; color: black; font-size: 10px; width: 75px; border: 1px solid grey\"  onclick=\"storeNewResource('" + objectiveArray.item(i).firstChild.data + "', '" + quarterArray.item(i).firstChild.data + "', '" + category_idArray.item(i).firstChild.data + "')\">";

				addObjectiveExample = "<textarea class=eGuideInputFormTall id=addObjectiveExample" + objectiveArray.item(i).firstChild.data + ">Example</textarea><br>";
				addObjectiveExample = addObjectiveExample + "<input type=button id=submitNewExample" + objectiveArray.item(i).firstChild.data + " value=\"Edit " + templateColumn3Title + "\" style=\"font-family: Arial; color: black; font-size: 10px; width: 75px; border: 1px solid grey\" onclick=\"storeNewExample('" + objectiveArray.item(i).firstChild.data + "')\">";

				addObjectiveLimit = "<textarea class=eGuideInputFormTall id=addObjectiveLimit" + objectiveArray.item(i).firstChild.data + ">Limits</textarea><br>";
				addObjectiveLimit = addObjectiveLimit + "<input type=button id=submitNewLimit" + objectiveArray.item(i).firstChild.data + " value=\"Edit " + templateColumn2Title + "\" style=\"font-family: Arial; color: black; font-size: 10px; width: 75px; border: 1px solid grey\" onclick=\"storeNewLimit('" + objectiveArray.item(i).firstChild.data + "')\">";
                
                editObjectiveText = "<textarea class=eGuideInputFormTall id=editObjectiveText" + objectiveArray.item(i).firstChild.data + ">Objective</textarea><br>";
                editObjectiveText = editObjectiveText + "<input type=button id=submitNewObjectiveText" + objectiveArray.item(i).firstChild.data + " value=\"Edit " + templateColumn1Title + "\" style=\"font-family: Arial; color: black; font-size: 10px; width: 75px; border: 1px solid grey\" onclick=\"storeNewObjectiveText('" + objectiveArray.item(i).firstChild.data + "')\">";

				adminResourceString = "<ul>";
				adminResourceString = adminResourceString + "<li class=EditResources><span class=eGuideLink onclick=\"displayAddResourceForm('AddResourceForObjective" + objectiveArray.item(i).firstChild.data + "');\">Add/Edit Resource</span><br><span ID=AddResourceForObjective" + objectiveArray.item(i).firstChild.data + " style=\"display: none;\">" + addResourceTitle + "</span></li>";
				adminResourceString = adminResourceString + "<li class=EditResources><span class=eGuideLink onclick=\"displayAddResourceForm('AddLimitForObjective" + objectiveArray.item(i).firstChild.data + "');updateLimitTextarea('" + objectiveArray.item(i).firstChild.data + "')\">Edit " + templateColumn2Title + " Text</span><br><span ID=AddLimitForObjective" + objectiveArray.item(i).firstChild.data + " style=\"display: none;\">" + addObjectiveLimit + "</span></li>";
				adminResourceString = adminResourceString + "<li class=EditResources><span class=eGuideLink onclick=\"displayAddResourceForm('AddExampleForObjective" + objectiveArray.item(i).firstChild.data + "');updateExampleTextarea('" + objectiveArray.item(i).firstChild.data + "')\">Edit " + templateColumn3Title + " Text</span><br><span ID=AddExampleForObjective" + objectiveArray.item(i).firstChild.data + " style=\"display: none;\">" + addObjectiveExample + "</span></li>";
				adminResourceString = adminResourceString + "<li class=EditResources><span class=eGuideLink onclick=\"displayAddResourceForm('EditObjectiveText" + objectiveArray.item(i).firstChild.data + "');updateObjectiveTextarea('" + objectiveArray.item(i).firstChild.data + "')\">Edit " + templateColumn1Title + " Text</span><br><span ID=EditObjectiveText" + objectiveArray.item(i).firstChild.data + " style=\"display: none;\">" + editObjectiveText + "</span></li>";
				adminResourceString = adminResourceString + "</ul>";
				
			}

            if(limitsString.length > 3)
                limitsString = unescape(limitsString) + "";
            if(examplesString.length > 3)
                examplesString = unescape(examplesString) + "";

			if(adminAuthority == 1)
                eGuide = eGuide + "<tr valign=\"top\"><td class=\"eGuide\"><span ID=ColumnOne" + objectiveArray.item(i).firstChild.data + "><i>" + objectiveArray.item(i).firstChild.data + "</i><br><span ID=ColumnOneText" + objectiveArray.item(i).firstChild.data + ">" + objectivesString + "</span><br>" + adminResourceString + "</span></td><td class=\"eGuide\"><span ID=ColumnTwoText" + objectiveArray.item(i).firstChild.data + ">" + limitsString + "</span><span ID=ColumnTwo" + objectiveArray.item(i).firstChild.data + "></span><span ID=ColumnTwoTextFromLPG" + objectiveArray.item(i).firstChild.data + "></span></td><td class=\"eGuide\"><span ID=ColumnThreeText" + objectiveArray.item(i).firstChild.data + ">" + examplesString + "</span><span ID=ColumnThree" + objectiveArray.item(i).firstChild.data + "></span></td><td class=\"eGuide\"><span ID=\"ColumnFour" + objectiveArray.item(i).firstChild.data + "\"></span></td></tr>";
            else
                eGuide = eGuide + "<tr valign=\"top\"><td class=\"eGuide\"><span ID=ColumnOne" + objectiveArray.item(i).firstChild.data + "><span ID=ColumnOneText" + objectiveArray.item(i).firstChild.data + ">" + objectivesString + "</span><br>" + adminResourceString + "</span></td><td class=\"eGuide\"><span ID=ColumnTwoText" + objectiveArray.item(i).firstChild.data + ">" + limitsString + "</span><span ID=ColumnTwoTextFromLPG" + objectiveArray.item(i).firstChild.data + "></span><span ID=ColumnTwo" + objectiveArray.item(i).firstChild.data + "></span></td><td class=\"eGuide\"><span ID=ColumnThreeText" + objectiveArray.item(i).firstChild.data + ">" + examplesString + "</span><span ID=ColumnThree" + objectiveArray.item(i).firstChild.data + "></span></td><td class=\"eGuide\"><span ID=\"ColumnFour" + objectiveArray.item(i).firstChild.data + "\"></span></td></tr>";

			eGuideObjectiveArray[i] = objectiveArray.item(i).firstChild.data;

			previousTopic = sub_topicsArray.item(i).firstChild.data;

            document.getElementById("Progress").innerHTML = "<span style=\"font-size: 12px; font-family: Ariel\">eGuide Loading: " + parseInt(100*(i/(IGSIdArray.length-1)), 10) + "% Done</span>";

		}

		eGuide = eGuide + "</table>";

		populateeGuideOptions(category_idArray.item(0).firstChild.data,quarterArray.item(0).firstChild.data);		// draws template for primary and segment information, title and column titles, places the resrouce types into the specified columns

		populateeGuideResources();		// populates the eGuide with resources

		document.getElementById("eGuideContent").innerHTML = addObjective + "<br>" + eGuide + "<br>";

	}
	else
	{
		var eGuide = "";

		eGuide = eGuide + "<table class=\"eGuide\">";
		eGuide = eGuide + "<tr><th class=\"eGuide\" width=\"200\"><span id=eGuideContentColumn1>" + templateColumn1Title + "</span></th><th class=\"eGuide\" width=\"250\"><span id=eGuideContentColumn2>" + templateColumn2Title + "</span></th><th class=\"eGuide\" width=\"350\"><span id=eGuideContentColumn3>" + templateColumn3Title + "</span></th><th class=\"eGuide\"  width=\"200\"><span  id=eGuideContentColumn4>" + templateColumn4Title + "</span></th></tr>";
		eGuide = eGuide + "<tr height=200 valign=top><td class=eGuide>This Electronic Guide currently has no objectives assigned to it. </td><td class=eGuide> </td><td class=eGuide> </td><td class=eGuide> </td></tr>";
		eGuide = eGuide + "</table>";
	
		document.getElementById("eGuideContent").innerHTML = addObjective + "<br>" + eGuide + "<br>";

		populateeGuideOptions(templatePageId,0);		// draws template for primary and segment information, title and column titles, places the resrouce types into the specified columns

	}

}

////////////////////////////////////////////////////////////////

// populate the eGuide options units section //////////////////

function populateeGuideOptions(eGuideId,eGuideQuarter)
{

//	populateeGuideOptionsPrimarySegments(eGuideId,eGuideQuarter);
	populateeGuideOptionsSecondarySegments(eGuideId,eGuideQuarter);
	populateeGuideOptionsCourseDescription(eGuideId,eGuideQuarter);

	// update eGuide title
	document.getElementById("eGuideTitle").innerHTML = "<span style=\"font-size: 25px; color: black; font-family: Arial;\">" + templatePageTitle + "</span><br>";

}

/// populate primary segments ///////////////////////////////

function populateeGuideOptionsPrimarySegments()
{

	var eGuideOptions = "";

	eGuideOptions = eGuideOptions + "<span style=\"font-size: 13px; color: black; font-family: Arial; font-weight:bold;\">" + templatePrimarySegment + "s</span><ul>";

//	if(quarterArray.length > 0)
//	{

	for(var i=1; i < templatePrimarySegmentSectionArray.length+1; i++)
	{
		eGuideOptions = eGuideOptions + "<li id=primarySegment" + i + " class=PrimarySegments><span class=eGuideLink id=\"PrimarySegment" + i + "\" style=\"font-size: 12px; color: black; font-family: Arial;\" onclick=\"populateeGuideContent('" + templatePageId + "', " + i + ", '');populateeGuideOptionsSecondarySegments('" + templatePageId + "', " + i + ")\">" + templatePrimarySegment + " " + i + "</span><br>";
		eGuideOptions = eGuideOptions + "<span style=\"font-size: 12px; color: grey; font-family: Arial;\" >" + templatePrimarySegmentSectionArray[i-1] + "</span></li>";
	}

	eGuideOptions = eGuideOptions + "</ul>";

	document.getElementById("eGuideOptionsPrimarySegments").innerHTML = eGuideOptions;

//	}

}

function DEPpopulateeGuideOptionsPrimarySegments(eGuideId,eGuideQuarter)
{

	// only continue if xmlHttp isn't void
	if(xmlHttp2)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp2.open("GET", "php/geteGuidePrimarySegments.php?MySQLSessionID=" + MySQLSessionID + "&eGuideID=" + eGuideId + "&eGuideQuarter=" + eGuideQuarter, true);
			xmlHttp2.onreadystatechange = handleRequestStateChangeeGuidePrimarySegments;
			xmlHttp2.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function handleRequestStateChangeeGuidePrimarySegments()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp2.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp2.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuidePrimarySegments();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp2.statusText);
		}
	}
}

function handleServerResponseeGuidePrimarySegments()
{

	// read the message from the server
	var xmlResponse = xmlHttp2.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray = xmlRoot.getElementsByTagName("id");
	category_idArray = xmlRoot.getElementsByTagName("category_id");
	quarterArray = xmlRoot.getElementsByTagName("category");

	// Generate Results output

	var eGuideOptions = "";

	eGuideOptions = eGuideOptions + "<span style=\"font-size: 13px; color: black; font-family: Arial; font-weight:bold;\">Primary Segments</span><ul>";

	if(quarterArray.length > 0)
	{

		for(var i=0; i < quarterArray.length; i++)
		{
			eGuideOptions = eGuideOptions + "<li class=PrimarySegments><span class=eGuideLink id=\"PrimarySegment" + quarterArray.item(i).firstChild.data + "\" style=\"font-size: 12px; color: black; font-family: Arial;\" onclick=\"populateeGuideContent('" + category_idArray.item(i).firstChild.data + "', " + quarterArray.item(i).firstChild.data + ", '');populateeGuideOptionsSecondarySegments('" + category_idArray.item(i).firstChild.data + "', " + quarterArray.item(i).firstChild.data + ")\">Primary Segment " + quarterArray.item(i).firstChild.data + "</span><br>";
			eGuideOptions = eGuideOptions + "<span style=\"font-size: 12px; color: grey; font-family: Arial;\" >Description</span></li>";
		}

		eGuideOptions = eGuideOptions + "</ul>";

		document.getElementById("eGuideOptionsPrimarySegments").innerHTML = eGuideOptions;

	}

}

// populate secondary segments ///////////////////////////////

function populateeGuideOptionsSecondarySegments(eGuideId,eGuideQuarter)
{
    
    document.getElementById("primarySegmentName").innerHTML = "<span style=\"font-size: 20px; color: black; font-family: Arial;\">" + templatePrimarySegment +  " " + eGuideQuarter + "</span>";
	document.getElementById("primarySegmentDescription").innerHTML = "";


	// only continue if xmlHttp isn't void
	if(xmlHttp1)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp1.open("GET", "php/geteGuideSecondarySegments.php?MySQLSessionID=" + MySQLSessionID + "&eGuideID=" + eGuideId + "&eGuideQuarter=" + eGuideQuarter, true);
			xmlHttp1.onreadystatechange = handleRequestStateChangeeGuideSecondarySegments;
			xmlHttp1.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function  handleRequestStateChangeeGuideSecondarySegments()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp1.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp1.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideSecondarySegments();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp1.statusText);
		}
	}
}

function handleServerResponseeGuideSecondarySegments()
{

	// read the message from the server
	var xmlResponse = xmlHttp1.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray = xmlRoot.getElementsByTagName("id");
	category_idArray = xmlRoot.getElementsByTagName("category_id");
	quarterArray = xmlRoot.getElementsByTagName("quarter");
	sub_topicsArray = xmlRoot.getElementsByTagName("sub_topics");

	// Generate Results output

	var eGuideOptions = "";

	eGuideOptions = eGuideOptions + "<span id=eguideSecondarySegmentTitle style=\"font-size: 13px; color: black; font-family: Arial; font-weight:bold;\">" + templateSecondarySegment + "s</span><br>";

	eGuideOptions = eGuideOptions + "<ul>";
		
	if(idArray.length > 0)
	{
			
		eGuideOptions = eGuideOptions + "<li class=SecondarySegments><span class=eGuideLink style=\"font-size: 12px; color: black; font-family: Arial;\" onclick=\"populateeGuideContent('" + category_idArray.item(i).firstChild.data + "', " + quarterArray.item(i).firstChild.data + ", '')\">VIEW ALL</span></li>";

		for(var i=0; i < idArray.length; i++)
		{				
            if(adminAuthority == 1)
                eGuideOptions = eGuideOptions + "<li class=SecondarySegments><span class=eGuideLink ID=\"SecondarySegment" + i + "\"style=\"font-size: 12px; color: black; font-family: Arial;\" onclick=\"populateeGuideContent('" + category_idArray.item(i).firstChild.data + "', " + quarterArray.item(i).firstChild.data + ", '" + sub_topicsArray.item(i).firstChild.data + "'); tagButton('sec', " + i + ")\">" + unescape(sub_topicsArray.item(i).firstChild.data) + "</span> <img src=\"images/customEdit.png\" onclick=\"editSecondarySegment('" + sub_topicsArray.item(i).firstChild.data + "', '" + i + "')\"><br id=unitNewline1" + i + " style=\"display: none;\"><TEXTAREA id=secondarySegmentEditBox" + i + " class=eGuideInputFormTall2 style=\"display: none;\"></TEXTAREA><br id=unitNewline2" + i + "  style=\"display: none;\"><input type=button id=submitUpdatedSecondarySegment" + i + " value=\"Edit " + templateSecondarySegment + "\" style=\"display: none; font-family: Arial; color: black; font-size: 10px; width: 75px; border: 1px solid grey\" onclick=\"updateSecondarySegment('" + category_idArray.item(i).firstChild.data + "', '" + i + "', '" + sub_topicsArray.item(i).firstChild.data + "', '" + quarterArray.item(i).firstChild.data + "')\"></li>";
           else
                eGuideOptions = eGuideOptions + "<li class=SecondarySegments><span class=eGuideLink ID=\"SecondarySegment" + i + "\"style=\"font-size: 12px; color: black; font-family: Arial;\" onclick=\"populateeGuideContent('" + category_idArray.item(i).firstChild.data + "', " + quarterArray.item(i).firstChild.data + ", '" + sub_topicsArray.item(i).firstChild.data + "'); tagButton('sec', " + i + ")\">" + unescape(sub_topicsArray.item(i).firstChild.data) + "</span></li>";
		}
		
	}

	if(adminAuthority == 1)
	{
	
//		eGuideOptions = eGuideOptions + "<li class=EditResources><span class=eGuideLink onclick=\"displayUnitForm('AddUnitForCourse" + 0 + "');\" style=\"font-size: 12px; color: black; font-family: Arial;\">Add Unit</span><br><span ID=AddUnitForCourse" + 0 + " style=\"display: none;\">" + 0 + "</span></li>";

//		eGuideOptions = eGuideOptions + " <input type=button id=submitNewUnit value=\"Add Unit\" style=\"font-family: Arial; color: black; font-size: 10px; width: 75px; border: 1px solid grey\"  onclick=\"storeNewUnit('" + 1 + "', '" + 1 + "', '" + 1 + "')\">";
	
	}

	eGuideOptions = eGuideOptions + "</ul>";


		document.getElementById("eGuideOptionsSecondarySegments").innerHTML = eGuideOptions;
}

// Course Summary /////////////////////////////////////////////

function populateeGuideOptionsCourseDescription(eGuideId,eGuideQuarter)
{

	document.getElementById("eGuideOptions").style.margin = "5px";
	document.getElementById("eGuideOptions").style.border = "0px solid black";
	
	var eGuideOptions = "";
	var CourseDescription = "";
	var PrimarySegments = "";
		
	CourseDescription = CourseDescription + "<span style=\"font-size: 13px; color: black; font-family: Arial; font-weight:bold;\">Course Summary</span><br><br>";
	CourseDescription = CourseDescription + "<span style=\"font-size: 12px; color: black; font-family: Arial;\">" + templateCourseSummary + "</span><br>";

	document.getElementById("eGuideOptionsCourseSummary").innerHTML = CourseDescription;

}

///////////////////////////////////////////////////////////////

// Populate updated Resources on page /////////////////////////////////////////////////

function updateeGuideResources(eGuideObjective)	// there is an issue with this routine calling the same functions to update resource lists.  If the resources on the page have not all been displayed.  The solution make it independent code.  Ths key issue is the use of xmlhttp4.  It cannot be called by a separate function while it is still busy.
{

	// only continue if xmlHttp isn't void
	if(xmlHttp7)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp7.open("GET", "php/geteGuideResources.php?MySQLSessionID=" + MySQLSessionID + "&eGuideObjective=" + eGuideObjective, true);
			xmlHttp7.onreadystatechange = handleRequestStateChangeSpecificResource;
			xmlHttp7.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
            // alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function handleRequestStateChangeSpecificResource()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp7.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp7.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideResource();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp7.statusText);
		}
	}
}

function handleServerResponseeGuideResource()
{

	// read the message from the server
	var xmlResponse = xmlHttp7.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray = xmlRoot.getElementsByTagName("id");
	titleArray = xmlRoot.getElementsByTagName("title");
	linkArray = xmlRoot.getElementsByTagName("link");
	descriptionArray = xmlRoot.getElementsByTagName("description");
	objectiveArray = xmlRoot.getElementsByTagName("objective");
	resource_typeArray = xmlRoot.getElementsByTagName("resource_type");
	hideArray = xmlRoot.getElementsByTagName("hide"); // used to store the column allocation value
	dr_itemArray = xmlRoot.getElementsByTagName("dr_item"); // used to store the column allocation value

	// Generate Results output

	var eGuideResourcesTEMP = "";
	var previousResourceType = "";
	var image_src = "";
	var y = 0;

    var lpgAssessmentLimitString = "";
    
    var col2String = "";
    var col3String = "";
    var col4String = "";

	if(idArray.length > 0)
	{
		for(var i=0; i < idArray.length; i++)
		{				
			descriptionString = descriptionArray.item(i).firstChild.data;
			descriptionString = descriptionString.replace(/%3C/g, "<");
			descriptionString = descriptionString.replace(/%3E/g, ">");
			descriptionString = descriptionString.replace(/%26/g, "&");

			titleString = titleArray.item(i).firstChild.data;
			titleString = titleString.replace(/%3C/g, "<");
			titleString = titleString.replace(/%3E/g, ">");
			titleString = titleString.replace(/%26/g, "&");

			linkString = linkArray.item(i).firstChild.data;
			linkString = linkString.replace(/%3C/g, "<");
			linkString = linkString.replace(/%3E/g, ">");
			linkString = linkString.replace(/%26/g, "&");

			if(previousResourceType != resource_typeArray.item(i).firstChild.data && previousResourceType != "")
				eGuideResourcesTEMP = eGuideResourcesTEMP + "</ul>";

			if(previousResourceType != resource_typeArray.item(i).firstChild.data)
			{
				
				image_src = "../Generalfunctions/Images/electronicresources/etools.gif";
			
				eGuideResourcesTEMP = eGuideResourcesTEMP + "<span style=\"font-size: 13px; color: black; font-family: Arial; font-weight:bold;\">" + resource_typeArray.item(i).firstChild.data + "</span><ul>";
			
			}

            var resID = idArray.item(i).firstChild.data;
            var restitle = escape(titleString);
            var resLink = linkString;
            var resDescription = escape(descriptionString);
            var resObjective = objectiveArray.item(i).firstChild.data;
            var resType = resource_typeArray.item(i).firstChild.data;
            var resHide = hideArray.item(i).firstChild.data;
        
            // assess link for file type, domain, etc...

            $identifyString = "";

            if(resLink.search(/\.doc/) > -1)
                $identifyString = " DOC ";
            if(resLink.search(/\.xls/) > -1)
                $identifyString = " XLS ";
            if(resLink.search(/\.ppt/) > -1)
                $identifyString = " PPT ";
            if(resLink.search(/.sirs./) > -1)
                $identifyString = " SIRS ";
            if(resLink.search(/.discoveryeducation./) > -1)
                $identifyString = " Discovery Education ";
            if(resLink.search(/.unitedstreaming./) > -1)
                $identifyString = " Discovery Streaming ";
            if(resLink.search(/.discoverystreaming./) > -1)
                $identifyString = " Discovery Streaming ";
            if(resLink.search(/.abc-clio./) > -1)
                $identifyString = " ABC-CLIO ";
            if(resLink.search(/\.kid/) > -1)
                $identifyString = " Kidspiration ";
            if(resLink.search(/pbskids./) > -1)
                $identifyString = " PBS Kids ";
            if(resLink.search(/kidshealth./) > -1)
                $identifyString = " Kids Health ";
            if(resLink.search(/doc.hcpss.org/) > -1)
                $identifyString = $identifyString + " <b>DR</b> ";
        
            $identifyString = $identifyString.replace(/ /g, ",");

            var resUpdateString = "'" + resID + "', '" + restitle + "', '" + resLink + "', '" + resDescription + "', '" + resObjective + "','" + resType + "','" + resHide + "'"; 
			
            if(linkArray.item(i).firstChild.data == " ")
                var linkString = "<span class=eGuideLink style=\"font-size: 12px; color: black; font-family: Arial;\">" + titleString + "</span>";
            else
                var linkString = "<span class=eGuideLink style=\"font-size: 12px; color: black; font-family: Arial;\"><a href=\"" + resLink + "\" target=_blank onclick=\"trackAccess('" + idArray.item(i).firstChild.data + "', '" + userid + "')\">" + titleString + "</a></span>";
            
            if(adminAuthority == 1)
                eGuideResourcesTEMP = eGuideResourcesTEMP + "<li class=Resources>" + linkString + " <span style=\"font-size: 7px; font-family: Ariel; font-color: grey\">" + (idArray.item(i).firstChild.data) + "</span> <img src=\"images/customEdit.png\" onclick=\"editResource(" + resUpdateString + ")\"> <img src=\"images/deleteItem.png\" onclick=\"deleteItem('" + idArray.item(i).firstChild.data + "', '" + objectiveArray.item(i).firstChild.data + "')\"> <span style=\"font-size: 8px; color: grey\">" + $identifyString + "</span></li>";
            else
                eGuideResourcesTEMP = eGuideResourcesTEMP + "<li class=Resources>" + linkString + " <span style=\"font-size: 8px; color: grey\">" + $identifyString + "</span></li>";
            
			previousResourceType = resource_typeArray.item(i).firstChild.data;
            
            if(dr_itemArray.item(i).firstChild.data == 2)
                col2String = col2String + eGuideResourcesTEMP
            if(dr_itemArray.item(i).firstChild.data == 3)
                col3String = col3String + eGuideResourcesTEMP
            if(dr_itemArray.item(i).firstChild.data == 4)
                col4String = col4String + eGuideResourcesTEMP
                
            eGuideResourcesTEMP = "";
			
		}
		
//		eGuideResourcesTEMP = eGuideResourcesTEMP + "<br>";

//  this code was added to examine why data was not populating its intended field.  The reason is that there are mutliple spans with the same ID due to the same objective entry being listed under a category and not listed.  
//		if(objectiveArray.item(0).firstChild.data == "4.1.26.z")
//			alert("test");
        
        if(resLink.search(/LPG2/) > -1)
        {
            lpgAssessmentLimitString = resDescription;
            document.getElementById('ColumnTwoTextFromLPG' + objectiveArray.item(0).firstChild.data).innerHTML = lpgAssessmentLimitString;
        }
        else
        {
            document.getElementById('ColumnTwoTextFromLPG' + objectiveArray.item(0).firstChild.data).innerHTML = "";
        }
        
		document.getElementById('ColumnTwo' + objectiveArray.item(0).firstChild.data).innerHTML = col2String;
		document.getElementById('ColumnThree' + objectiveArray.item(0).firstChild.data).innerHTML = col3String;
		document.getElementById('ColumnFour' + objectiveArray.item(0).firstChild.data).innerHTML = col4String;

	}
	
//		document.getElementById('ColumnFour' + objectiveArray.item(0).firstChild.data).innerHTML = "";
	
}

//////////////////////////////////////////////////////////////
// Populate all resources on page

function populateeGuideResources()
{

	// only continue if xmlHttp isn't void
	if(xmlHttp4)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp4.open("GET", "php/geteGuideResources.php?MySQLSessionID=" + MySQLSessionID + "&eGuideObjective=" + eGuideObjectiveArray[globalObjectiveIndex], true);
			xmlHttp4.onreadystatechange = handleRequestStateChangeResources;
			xmlHttp4.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
            // alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function handleRequestStateChangeResources()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp4.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp4.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideResources();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp4.statusText);
		}
	}
}

function handleServerResponseeGuideResources()
{

	// read the message from the server
	var xmlResponse = xmlHttp4.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray = xmlRoot.getElementsByTagName("id");
	titleArray = xmlRoot.getElementsByTagName("title");
	linkArray = xmlRoot.getElementsByTagName("link");
	descriptionArray = xmlRoot.getElementsByTagName("description");
	objectiveArray = xmlRoot.getElementsByTagName("objective");
	resource_typeArray = xmlRoot.getElementsByTagName("resource_type");
	hideArray = xmlRoot.getElementsByTagName("hide"); // used to store the column allocation value
	dr_itemArray = xmlRoot.getElementsByTagName("dr_item"); // used to store the column allocation value

	// Generate Results output

	var eGuideResourcesTEMP = "";
	var previousResourceType = "";
	var image_src = "";
	var y = 0;
    
    var col2String = "";
    var col3String = "";
    var col4String = "";

	if(idArray.length > 0)
	{
		for(var i=0; i < idArray.length; i++)
		{				
			descriptionString = descriptionArray.item(i).firstChild.data;
			descriptionString = descriptionString.replace(/%3C/g, "<");
			descriptionString = descriptionString.replace(/%3E/g, ">");
			descriptionString = descriptionString.replace(/%26/g, "&");

			titleString = titleArray.item(i).firstChild.data;
			titleString = titleString.replace(/%3C/g, "<");
			titleString = titleString.replace(/%3E/g, ">");
			titleString = titleString.replace(/%26/g, "&");

			linkString = linkArray.item(i).firstChild.data;
			linkString = linkString.replace(/%3C/g, "<");
			linkString = linkString.replace(/%3E/g, ">");
			linkString = linkString.replace(/%26/g, "&");

			if(previousResourceType != resource_typeArray.item(i).firstChild.data && previousResourceType != "")
				eGuideResourcesTEMP = eGuideResourcesTEMP + "</ul>";

			if(previousResourceType != resource_typeArray.item(i).firstChild.data)
			{
				
				image_src = "../Generalfunctions/Images/electronicresources/etools.gif";
			
				eGuideResourcesTEMP = eGuideResourcesTEMP + "<span style=\"font-size: 13px; color: black; font-family: Arial; font-weight:bold;\">" + resource_typeArray.item(i).firstChild.data + "</span><ul>";
			
			}

            var resID = idArray.item(i).firstChild.data;
            var restitle = escape(titleString);
            var resLink = linkString;
            var resDescription = escape(descriptionString);
            var resObjective = objectiveArray.item(i).firstChild.data;
            var resType = resource_typeArray.item(i).firstChild.data;
            var resHide = hideArray.item(i).firstChild.data;

            $identifyString = "";

            if(resLink.search(/\.doc/) > -1)
                $identifyString = "DOC";
            if(resLink.search(/\.xls/) > -1)
                $identifyString = "XLS";
            if(resLink.search(/.ppt/) > -1)
                $identifyString = "PPT";
            if(resLink.search(/.sirs./) > -1)
                $identifyString = "SIRS";
            if(resLink.search(/.discoveryeducation./) > -1)
                $identifyString = "Discovery Education";
            if(resLink.search(/.unitedstreaming./) > -1)
                $identifyString = "Discovery Streaming";
            if(resLink.search(/.discoverystreaming./) > -1)
                $identifyString = "Discovery Streaming";
            if(resLink.search(/.abc-clio./) > -1)
                $identifyString = "ABC-CLIO";
            if(resLink.search(/.kid/) > -1)
                $identifyString = "Kidspiration";
            if(resLink.search(/.pdf/) > -1)
                $identifyString = "PDF";
            if(resLink.search(/pbskids./) > -1)
                $identifyString = " PBS Kids ";
            if(resLink.search(/kidshealth./) > -1)
                $identifyString = " Kids Health ";
 
            if(resLink.search(/doc.hcpss.org/) > -1)
            {
                if($identifyString == "")
                    $identifyString = $identifyString + "<b>DR</b>";
                else
                    $identifyString = $identifyString + ", <b>DR</b>";

            }
            
            var resUpdateString = "'" + resID + "', '" + restitle + "', '" + resLink + "', '" + resDescription + "', '" + resObjective + "','" + resType + "','" + resHide + "'"; 
	
            if(linkArray.item(i).firstChild.data == " ")
                var linkString = "<span class=eGuideLink style=\"font-size: 12px; color: black; font-family: Arial;\">" + titleString + "</span>";
            else
                var linkString = "<span class=eGuideLink style=\"font-size: 12px; color: black; font-family: Arial;\"><a href=\"" + linkString + "\" target=_blank onclick=\"trackAccess('" + idArray.item(i).firstChild.data + "', '" + userid + "')\">" + titleString + "</a></span>";
            
            if(adminAuthority == 1)
                eGuideResourcesTEMP = eGuideResourcesTEMP + "<li class=Resources>" + linkString + " <span style=\"font-size: 7px; font-family: Ariel; font-color: grey\">" + (idArray.item(i).firstChild.data) + "</span> <img src=\"images/customEdit.png\" onclick=\"editResource(" + resUpdateString + ")\"> <img src=\"images/deleteItem.png\" onclick=\"deleteItem('" + idArray.item(i).firstChild.data + "', '" + objectiveArray.item(i).firstChild.data + "')\"> <span style=\"font-size: 8px; color: grey\">" + $identifyString + "</span></li>";
            else
                eGuideResourcesTEMP = eGuideResourcesTEMP + "<li class=Resources>" + linkString + " <span style=\"font-size: 8px; color: grey\">" + $identifyString + "</span></li>";

			previousResourceType = resource_typeArray.item(i).firstChild.data;
            
            if(dr_itemArray.item(i).firstChild.data == 2)
                col2String = col2String + eGuideResourcesTEMP
            if(dr_itemArray.item(i).firstChild.data == 3)
                col3String = col3String + eGuideResourcesTEMP
            if(dr_itemArray.item(i).firstChild.data == 4)
                col4String = col4String + eGuideResourcesTEMP
                
            eGuideResourcesTEMP = "";
			
		}
		
//		eGuideResourcesTEMP = eGuideResourcesTEMP + "<br>";

//  this code was added to examine why data was not populating its intended field.  The reason is that there are mutliple spans with the same ID due to the same objective entry being listed under a category and not listed.  
//		if(objectiveArray.item(0).firstChild.data == "4.1.26.z")
//			alert("test");
        
        if(resLink.search(/LPG2/) > -1)
        {
            document.getElementById('ColumnTwoTextFromLPG' + objectiveArray.item(0).firstChild.data).innerHTML = descriptionString;
        }
        else
        {
            document.getElementById('ColumnTwoTextFromLPG' + objectiveArray.item(0).firstChild.data).innerHTML = "";
        }

		document.getElementById('ColumnTwo' + objectiveArray.item(0).firstChild.data).innerHTML = col2String;
		document.getElementById('ColumnThree' + objectiveArray.item(0).firstChild.data).innerHTML = col3String;
		document.getElementById('ColumnFour' + objectiveArray.item(0).firstChild.data).innerHTML = col4String;

	}

		globalObjectiveIndex++;
		if(globalObjectiveIndex < eGuideObjectiveArray.length+1)
		{
        	setTimeout('populateeGuideResources()', 5);
            document.getElementById("Progress").innerHTML = "<span style=\"font-size: 12px; font-family: Ariel\">Resources Loading: " + parseInt(100*(globalObjectiveIndex/(eGuideObjectiveArray.length)), 10) + "% Done</span>";
        }
}

///////////////////////////////////////////////////////////////

function depressButton(buttonId)
{

//	document.getElementById(buttonId).style.background.color = "blue";

}

function clearField(fieldId)
{

	document.getElementById(fieldId).value = "";

}

function displayAddResourceForm(formId)
{

	document.getElementById(formId).style.display="";

}

function displayAddObjectiveExampleForm(formId)
{

	document.getElementById(formId).style.display="";

}

function displayAddObjectiveLimitForm(formId)
{

	document.getElementById(formId).style.display = "";

}

function displayNewCourseForm(eGuideId,formId,curricularArea)
{
	
	var templateString = "";
        
	templateString = templateString + "<table class=eGuide width=100% >";
	templateString = templateString + "<tr><td><input class=eGuideInputFormLong type=text id=newCourseTitle" + eGuideId + " value=\"Title\"></td><td width=100><img src=images/HCPSSLogoWhite.png width=100></td></tr>";
	templateString = templateString + "<tr><td colspan=2>____________________________________________________________________________</td></tr>";
	templateString = templateString + "<tr><td colspan=2><table ><tr valign=top><td width=40%><input class=eGuideInputForm type=text id=newCoursePrimarySegment" + eGuideId + " value=\"Primary Segment Title\"><ul><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentIDescription" + eGuideId + " value=\"Primary Segment I Description\"></li><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentIIDescription" + eGuideId + " value=\"Primary Segment  II Description\"></li><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentIIIDescription" + eGuideId + " value=\"Primary Segment  III Description\"></li><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentIVDescription" + eGuideId + " value=\"Primary Segment IV Description\"></li><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentVDescription" + eGuideId + " value=\"Primary Segment  V Description\"></li><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentVIDescription" + eGuideId + " value=\"Primary Segment  VI Description\"></li><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentVIIDescription" + eGuideId + " value=\"Primary Segment  VII Description\"></li><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentVIIIDescription" + eGuideId + " value=\"Primary Segment  VIII Description\"></li><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentIXDescription" + eGuideId + " value=\"Primary Segment  IX Description\"></li><li class=PrimarySegments><input class=eGuideInputForm type=text id=newCoursePrimarySegmentXDescription" + eGuideId + " value=\"Primary Segment X Description\"></li></ul><input class=eGuideInputForm type=text id=newCourseSecondarySegment" + eGuideId + " value=\"Secondary Segment Title\"><br><br><textarea class=eGuideInputForm id=newCourseSummary" + eGuideId + ">Course Summary</textarea></td><td width=400><table width=100% class=eGuide><tr><td class=eGuide><input class=eGuideInputForm type=text id=newCourseCol1" + eGuideId + " value=\"Column 1\" style=\"width: 75px\"></td><td class=eGuide><input class=eGuideInputForm type=text id=newCourseCol2" + eGuideId + " value=\"Column 2\" style=\"width: 75px\"></td><td class=eGuide><input class=eGuideInputForm type=text id=newCourseCol3" + eGuideId + " value=\"Column 3\" style=\"width: 75px\"></td><td class=eGuide><input class=eGuideInputForm type=text id=newCourseCol4" + eGuideId + " value=\"Column 4\" style=\"width: 75px\"></td><tr height=300 valign=top><td class=eGuide></td><td class=eGuide><div id=templateCol2" + eGuideId + "></div></td><td class=eGuide><div id=templateCol3" + eGuideId + "></div></td><td class=eGuide><div id=templateCol4" + eGuideId + "></div></td></tr></table><br><input type=button id=submitTemplate value=\"Update Template\" style=\"font-family: Arial; color: black; font-size: 11px; width: 100px; border: 1px solid grey\"  onclick=\"storeCourseTemplate('" + eGuideId + "', '" + curricularArea + "')\"></td></tr></table></td></tr>";
	templateString = templateString + "</table>";

	document.getElementById(formId).innerHTML = templateString;

	document.getElementById(formId).style.display = "";

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Pulls resource organization data and displays the resources in the appropriate layout ////////////////////

function loadResourceAllocationIntoTemplate(eGuideId)
{

	// only continue if xmlHttp isn't void
	if(xmlHttp11)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp11.open("GET", "php/getResourceAllocation.php?MySQLSessionID=" + MySQLSessionID + "&eGuideId=" + eGuideId, true);
			xmlHttp11.onreadystatechange = handleRequestStateChangeResourceAllocation;
			xmlHttp11.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
            // alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function that handles the HTTP response
function handleRequestStateChangeResourceAllocation()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp11.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp11.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideResourceAllocation();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp11.statusText);
		}
	}
}

function handleServerResponseeGuideResourceAllocation()
{

	// read the message from the server
	var xmlResponse = xmlHttp11.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	idArray = xmlRoot.getElementsByTagName("id");
	category_idArray = xmlRoot.getElementsByTagName("category_id");
	resourceTypeArray = xmlRoot.getElementsByTagName("resourcetype");
	columnassignmentArray = xmlRoot.getElementsByTagName("columnassignment");
	useridArray = xmlRoot.getElementsByTagName("userid");
	date_edittedArray = xmlRoot.getElementsByTagName("date_editted");

	// Generate Results output

    // build resource allocation units
    // store data in unique table
    // layout
    // resource type
    // Select: col 1, col 2, col 3, col 4, hidden
    
    // this will load the stored locations of resources if an eGuideId is given.
        
    var col2String = "";
    var col3String = "";
    var col4String = "";
    
    var resourceTypes = new Array();
    
    for(var i=0; i<idArray.length; i++)
    {
    
        if(columnassignmentArray.item(i).firstChild.data == 2)
            col2String = col2String + "<span style=\"font-family: Arial; color: black; font-size: 10px; width: 100px;\">" + resourceTypeArray.item(i).firstChild.data + "<br><select class=eGuideInputFormMini id=resourceColumnAssignment" + idArray.item(i).firstChild.data + " onchange=\"storeResourceAllocation('" + category_idArray.item(0).firstChild.data + "', '" + idArray.item(i).firstChild.data + "')\"><option selected>2</option><option>3</option><option>4</option><option value=1>Hidden</option></select></span><br><br>";

        if(columnassignmentArray.item(i).firstChild.data == 3)
            col3String = col3String + "<span style=\"font-family: Arial; color: black; font-size: 10px; width: 100px;\">" + resourceTypeArray.item(i).firstChild.data + "<br><select class=eGuideInputFormMini id=resourceColumnAssignment" + idArray.item(i).firstChild.data + " onchange=\"storeResourceAllocation('" + category_idArray.item(0).firstChild.data + "', '" + idArray.item(i).firstChild.data + "')\"><option>2</option><option selected>3</option><option>4</option><option value=1>Hidden</option></select></span><br><br>";

        if(columnassignmentArray.item(i).firstChild.data == 4)
            col4String = col4String + "<span style=\"font-family: Arial; color: black; font-size: 10px; width: 100px;\">" + resourceTypeArray.item(i).firstChild.data + "<br><select class=eGuideInputFormMini id=resourceColumnAssignment" + idArray.item(i).firstChild.data + " onchange=\"storeResourceAllocation('" + category_idArray.item(0).firstChild.data + "', '" + idArray.item(i).firstChild.data + "')\"><option>2</option><option>3</option><option selected>4</option><option value=1>Hidden</option></select></span><br><br>";

        if(columnassignmentArray.item(i).firstChild.data == 1)
            col4String = col4String + "<span style=\"font-family: Arial; color: black; font-size: 10px; width: 100px;\">" + resourceTypeArray.item(i).firstChild.data + "<br><select class=eGuideInputFormMini id=resourceColumnAssignment" + idArray.item(i).firstChild.data + " onchange=\"storeResourceAllocation('" + category_idArray.item(0).firstChild.data + "', '" + idArray.item(i).firstChild.data + "')\"><option>2</option><option>3</option><option selected>4</option><option value=1 selected>Hidden</option></select></span><br><br>";

    }
    
    document.getElementById("templateCol2" + category_idArray.item(0).firstChild.data).innerHTML = col2String;
    document.getElementById("templateCol3" + category_idArray.item(0).firstChild.data).innerHTML = col3String;
    document.getElementById("templateCol4" + category_idArray.item(0).firstChild.data).innerHTML = col4String;

    // load temp values now

}

function tagButton(section, option)
{

/*	if(section == "sec")
	{
			document.getElementById("SecondarySegment"+option).style.backgroundColor="#fff799";
	
	}

	if(section == "prim")
	{
			document.getElementById("PrimarySegment"+option).style.backgroundColor="#fff799";
	
	}
*/

}

// Input routines //////////////////////////////////////////////

function storeNewResource(resourceObjective, resourceQuarter, resourceCategoryId)
{

    if(document.getElementById("addResourceType" + resourceObjective).value != "")
    {
        var queryString = "";

        queryString = queryString + "&addResourceID=" + document.getElementById("addResourceID" + resourceObjective).value;
        queryString = queryString + "&addResourceTitle=" + document.getElementById("addResourceTitle" + resourceObjective).value;
        queryString = queryString + "&addResourceType=" + document.getElementById("addResourceType" + resourceObjective).value;
        queryString = queryString + "&addResourceHide=" + document.getElementById("addResourceHide" + resourceObjective).checked;
        queryString = queryString + "&addResourceDescription=" + document.getElementById("addResourceDescription" + resourceObjective).value;
        queryString = queryString + "&addResourceLink=" + escape(document.getElementById("addResourceLink" + resourceObjective).value);

        // only continue if xmlHttp isn't void
        if(xmlHttp)
        {
            // try to connect to the server
            try
            {		
                // initiate reading the Books from the server
                xmlHttp.open("GET", "php/putNeweGuideResource.php?MySQLSessionID=" + MySQLSessionID + "&resourceObjective=" + resourceObjective + "&resourceQuarter=" + resourceQuarter + "&resourceCategoryId=" + resourceCategoryId + queryString, true);
                xmlHttp.onreadystatechange = handleRequestStateChangeStoreResource;
                xmlHttp.send(null);
            }
            // display the error in case of failure
            catch (e)
            {
            // alert("Can't connect to server:\n" + e.toString());
            }
        }
		
    }
    else
        alert("Choose a resource type!");
}

// function that handles the HTTP response
function handleRequestStateChangeStoreResource()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseStoreResource();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}


function handleServerResponseStoreResource()
{

	// read the message from the server
	var xmlResponse = xmlHttp.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	objectiveArray = xmlRoot.getElementsByTagName("objective");

    var resourceObjective = objectiveArray.item(0).firstChild.data

    updateeGuideResources(resourceObjective);

    //clear resource fields

    document.getElementById("addResourceID" + resourceObjective).value = "ID Not Assigned";
    document.getElementById("addResourceTitle" + resourceObjective).value = "Title";
    document.getElementById("addResourceType" + resourceObjective).value = "Resource Type";
    document.getElementById("addResourceHide" + resourceObjective).value = "";
    document.getElementById("addResourceDescription" + resourceObjective).value = "Description";
    document.getElementById("addResourceLink" + resourceObjective).value = "Link (http://www.link.com)";
	
    document.getElementById("AddResourceForObjective" + resourceObjective).style.display="none";

}

function storeCourseTemplate(eGuideId,curricularArea)
{

//	alert(eGuideId + " " + formId + ", " + curricularArea);

	var queryString = "";

	queryString = queryString + "&CourseID=" + eGuideId;
	queryString = queryString + "&newCourseTitle=" + document.getElementById("newCourseTitle" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegment=" + document.getElementById("newCoursePrimarySegment" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentIDescription=" + document.getElementById("newCoursePrimarySegmentIDescription" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentIIDescription=" + document.getElementById("newCoursePrimarySegmentIIDescription" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentIIIDescription=" + document.getElementById("newCoursePrimarySegmentIIIDescription" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentIVDescription=" + document.getElementById("newCoursePrimarySegmentIVDescription" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentVDescription=" + document.getElementById("newCoursePrimarySegmentVDescription" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentVIDescription=" + document.getElementById("newCoursePrimarySegmentVIDescription" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentVIIDescription=" + document.getElementById("newCoursePrimarySegmentVIIDescription" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentVIIIDescription=" + document.getElementById("newCoursePrimarySegmentVIIIDescription" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentIXDescription=" + document.getElementById("newCoursePrimarySegmentIXDescription" + eGuideId).value;
	queryString = queryString + "&newCoursePrimarySegmentXDescription=" + document.getElementById("newCoursePrimarySegmentXDescription" + eGuideId).value;
	queryString = queryString + "&newCourseSecondarySegment=" + document.getElementById("newCourseSecondarySegment" + eGuideId).value;
	queryString = queryString + "&newCourseSummary=" + document.getElementById("newCourseSummary" + eGuideId).value;

	queryString = queryString + "&newCourseCol1=" + document.getElementById("newCourseCol1" + eGuideId).value;
	queryString = queryString + "&newCourseCol2=" + document.getElementById("newCourseCol2" + eGuideId).value;
	queryString = queryString + "&newCourseCol3=" + document.getElementById("newCourseCol3" + eGuideId).value;
	queryString = queryString + "&newCourseCol4=" + document.getElementById("newCourseCol4" + eGuideId).value;

	// only continue if xmlHttp isn't void
	if(xmlHttp)
	{
		// try to connect to the server
		try
		{
		
//		alert("php/putCourseTemplate.php?MySQLSessionID=" + MySQLSessionID + "&curricularArea=" + curricularArea + queryString);

			// initiate reading the Books from the server
			xmlHttp.open("POST", "php/putCourseTemplate.php?MySQLSessionID=" + MySQLSessionID + "&curricularArea=" + curricularArea + queryString, true);
			xmlHttp.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
            // alert("Can't connect to server:\n" + e.toString());
		}
	}

// close template space
// document.getElementById("AddResourceForObjective" + resourceObjective).style.display= "none";
	
}

//////////////////////////////////////////////////

function updateExampleTextarea(exampleObjective)
{

	document.getElementById("addObjectiveExample" + exampleObjective).value = document.getElementById("ColumnThreeText" + exampleObjective).innerHTML;

}

function updateLimitTextarea(limitObjective)
{

	document.getElementById("addObjectiveLimit" + limitObjective).value = document.getElementById("ColumnTwoText" + limitObjective).innerHTML;

}

function updateObjectiveTextarea(exampleObjective)
{

	document.getElementById("editObjectiveText" + exampleObjective).value = document.getElementById("ColumnOneText" + exampleObjective).innerHTML;

}

/////////////////////////////////////////////////

function storeNewObjectiveText(Objective)
{

	var queryString = "";
    
    var objectiveString = escape(document.getElementById("editObjectiveText" + Objective).value);

	queryString =  "&Objective=" + Objective + "&editObjectiveText=" + objectiveString.replace(/\+/g, "%2B");

	// only continue if xmlHttp isn't void
	if(xmlHttp)
	{
		// try to connect to the server
		try
		{        
            // initiate reading the Books from the server
            xmlHttp.setRequestHeader("Content-type","multipart/form-data");
			xmlHttp.open("POST", "php/putNeweGuideObjectiveText.php?MySQLSessionID=" + MySQLSessionID + queryString, true);
			xmlHttp.onreadystatechange = handleRequestStateChangeUpdateObjectiveText;
			xmlHttp.send(null);
            
//            xmlHttp.send(queryString);
//            xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
//            xmlHttp.setRequestHeader("Content-length",queryString.length);
//            xmlHttp.setRequestHeader("Connection","close");

		}
		// display the error in case of failure
		catch (e)
		{
            // alert("Can't connect to server:\n" + e.toString());
		}
	}

//	document.getElementById("ColumnTwoText" + limitObjective).innerHTML = document.getElementById("addObjectiveLimit" + limitObjective).value;
	document.getElementById("EditObjectiveText" + Objective).style.display="none";
	
}

// function that handles the HTTP response
function handleRequestStateChangeUpdateObjectiveText()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideUpdateObjectiveText();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function handleServerResponseeGuideUpdateObjectiveText()
{

	// read the message from the server
	var xmlResponse = xmlHttp.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	objectiveTextArray = xmlRoot.getElementsByTagName("objectivetext");
	objectiveArray = xmlRoot.getElementsByTagName("objective");

    if(objectiveArray.length > 0)
    {
        document.getElementById("ColumnOneText" + objectiveArray.item(0).firstChild.data).innerHTML = unescape(objectiveTextArray.item(0).firstChild.data);	
    }
    else
    {
        alert("There was an error retrieving the loaded data.");
    }

    // load temp values now

}

//////////////////////////////////////////

function storeNewExample(exampleObjective)
{

	var queryString = "";

    var exampleString = escape(document.getElementById("addObjectiveExample" + exampleObjective).value);
    
	queryString = "&addObjectiveExample=" + exampleString.replace(/\+/g, "%2B");

	// only continue if xmlHttp isn't void
	if(xmlHttp)
	{
		// try to connect to the server
		try
		{
        
            var parameters = "MySQLSessionID=" + MySQLSessionID + "&exampleObjective=" + exampleObjective + queryString;

            // initiate reading the Books from the server
//			xmlHttp.open("GET", "php/putNeweGuideExample.php?MySQLSessionID=" + MySQLSessionID + "&exampleObjective=" + exampleObjective + queryString, true);
			xmlHttp.open("POST", "php/putNeweGuideExample.php", true);
            xmlHttp.setRequestHeader("Content-length", parameters.length);
            xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.onreadystatechange = handleRequestStateChangeUpdateExample;
			xmlHttp.send(parameters);
            
		}
		// display the error in case of failure
		catch (e)
		{
            // alert("Can't connect to server:\n" + e.toString());
		}
	}
	
//	document.getElementById("ColumnThreeText" + exampleObjective).innerHTML = document.getElementById("addObjectiveExample" + exampleObjective).value;	
	document.getElementById("AddExampleForObjective" + exampleObjective).style.display="none";

}

// function that handles the HTTP response
function handleRequestStateChangeUpdateExample()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideUpdateExample();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function handleServerResponseeGuideUpdateExample()
{

	// read the message from the server
	var xmlResponse = xmlHttp.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	exampleArray = xmlRoot.getElementsByTagName("column3text");
	objectiveArray = xmlRoot.getElementsByTagName("objective");

    if(objectiveArray.length > 0)
    {
        document.getElementById("ColumnThreeText" + objectiveArray.item(0).firstChild.data).innerHTML = unescape(exampleArray.item(0).firstChild.data);	
    }
    else
    {
        alert("There was an error retrieving the loaded data.");
    }


    // load temp values now

}

/////////////////////////////////////////

function storeNewLimit(limitObjective)
{

	var queryString = "";
    
    var limitString = escape(document.getElementById("addObjectiveLimit" + limitObjective).value);

	queryString = queryString + "&addObjectiveLimit=" + limitString.replace(/\+/g, "%2B");

	// only continue if xmlHttp isn't void
	if(xmlHttp)
	{
		// try to connect to the server
		try
		{
            var parameters = "MySQLSessionID=" + MySQLSessionID + "&limitObjective=" + limitObjective + queryString;
        
			// initiate reading the Books from the server
			xmlHttp.open("POST", "php/putNeweGuideLimit.php", true);
            xmlHttp.setRequestHeader("Content-length", parameters.length);
            xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.onreadystatechange = handleRequestStateChangeUpdateLimit;
//			xmlHttp.open("POST", "php/putNeweGuideLimit.php?MySQLSessionID=" + MySQLSessionID + "&limitObjective=" + limitObjective + queryString, true);
			xmlHttp.send(parameters);
            
		}
		// display the error in case of failure
		catch (e)
		{
            // alert("Can't connect to server:\n" + e.toString());
		}
	}

//	document.getElementById("ColumnTwoText" + limitObjective).innerHTML = document.getElementById("addObjectiveLimit" + limitObjective).value;
	document.getElementById("AddLimitForObjective" + limitObjective).style.display="none";
	
}

// function that handles the HTTP response
function handleRequestStateChangeUpdateLimit()
{

	// when readyState is 4 we also read the server response
	if (xmlHttp.readyState == 4)
	{
		// continue only if HTTP status is  "ok"
		if(xmlHttp.status == 200)
		{
			try
			{
				// do something with the response from the server
				handleServerResponseeGuideUpdateLimit();
			}
			catch (e)
			{
				// display error
				// alert ("Error reading the response: " + e.toString());
			}
		}
		else
		{
			// display status message
			alert ("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function handleServerResponseeGuideUpdateLimit()
{

	// read the message from the server
	var xmlResponse = xmlHttp.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;
	// obtains arrays with book titles and ISBNs
	limitArray = xmlRoot.getElementsByTagName("column2text");
	objectiveArray = xmlRoot.getElementsByTagName("objective");

    if(objectiveArray.length > 0)
    {
        document.getElementById("ColumnTwoText" + objectiveArray.item(0).firstChild.data).innerHTML = unescape(limitArray.item(0).firstChild.data);	
    }
    else
    {
        alert("There was an error retrieving the loaded data.");
    }


    // load temp values now

}

//////////////////////////////////////////

function trackAccess(itemID, username)
{

	// only continue if xmlHttp isn't void
	if(xmlHttp)
	{
		// try to connect to the server
		try
		{
			// initiate reading the Books from the server
			xmlHttp.open("POST", "php/putResourceTrackingData.php?MySQLSessionID=" + MySQLSessionID + "&ItemID=" + itemID + "&userid=" + username, true);
			xmlHttp.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
            // alert("Can't connect to server:\n" + e.toString());
		}
	}

}

function deleteItem(itemID, resourceObjective)
{

	if(confirm("Are you sure you want to delete item: " + itemID + "?"))
	{
		// only continue if xmlHttp isn't void
		if(xmlHttp)
		{
			// try to connect to the server
			try
			{
				// initiate reading the Books from the server
				xmlHttp.open("POST", "php/removeItem.php?MySQLSessionID=" + MySQLSessionID + "&ItemID=" + itemID, true);
				xmlHttp.send(null);
			}
			// display the error in case of failure
			catch (e)
			{
                // alert("Can't connect to server:\n" + e.toString());
			}
		}
		
		updateeGuideResources(resourceObjective);	// updates the resource section of the eguide for that specific objective
		
	}

}

function deleteIGS(IGSID)
{

	if(confirm("Are you sure you want to delete the electronic instructional guide: " + IGSID + "?"))
	{
		// only continue if xmlHttp isn't void
		if(xmlHttp)
		{
			// try to connect to the server
			try
			{
				// initiate reading the Books from the server
				xmlHttp.open("POST", "php/removeIGS.php?MySQLSessionID=" + MySQLSessionID + "&IGSID=" + IGSID, true);
				xmlHttp.send(null);
			}
			// display the error in case of failure
			catch (e)
			{
                // alert("Can't connect to server:\n" + e.toString());
			}
		}
		
		updateeGuideResources(resourceObjective);	// updates the resource section of the eguide for that specific objective
		
	}

}

function editResource(resID, restitle, resLink, resDescription, resObjective, resType, resHide)
{

	document.getElementById("addResourceID" + resObjective).value = resID;

	document.getElementById("addResourceTitle" + resObjective).value = unescape(restitle);
	document.getElementById("addResourceLink" + resObjective).value = resLink;
	document.getElementById("addResourceDescription" + resObjective).value = unescape(resDescription);
	document.getElementById("addResourceType" + resObjective).value = resObjective;
    
    if(resHide == 1)
        document.getElementById("addResourceHide" + resObjective).checked = true;
    else
        document.getElementById("addResourceHide" + resObjective).checked = false;
	
    document.getElementById("addResourceType" + resObjective).value = resType;	

	document.getElementById("AddResourceForObjective" + resObjective).style.display="";

}

function storeResourceAllocation(eGuideId, resourceAllocationId)
{

	// only continue if xmlHttp isn't void
	if(xmlHttp)
	{
		// try to connect to the server
		try
		{
        
            // get column assigment
            if(resourceAllocationId > 0)
                columnAssignment = document.getElementById("resourceColumnAssignment" + resourceAllocationId).value;
            else
                columnAssignment = 4;

            // get resource type
            resourceType = "eTools";
            
			// initiate reading the Books from the server
			xmlHttp.open("POST", "php/putResourceAllocationData.php?MySQLSessionID=" + MySQLSessionID + "&eGuideId=" + eGuideId + "&ResourceAllocationId=" + resourceAllocationId + "&ResourceType=" + resourceType + "&ColumnAssignment=" + columnAssignment + "&UserID=" + userid, true);
			xmlHttp.send(null);
		}
		// display the error in case of failure
		catch (e)
		{
            // alert("Can't connect to server:\n" + e.toString());
		}
        
            loadResourceAllocationIntoTemplate(eGuideId);

	}    

}

function editSecondarySegment(currentSecondarySegmentTitle, secondarySegmentIndex)
{

    // make elements visible
    document.getElementById("unitNewline1" + secondarySegmentIndex).style.display = ""; 
    document.getElementById("secondarySegmentEditBox" + secondarySegmentIndex).style.display = ""; 
    document.getElementById("unitNewline2" + secondarySegmentIndex).style.display = ""; 
    document.getElementById("submitUpdatedSecondarySegment" + secondarySegmentIndex).style.display = ""; 
    
    // populate elements
    document.getElementById("secondarySegmentEditBox" + secondarySegmentIndex).value = currentSecondarySegmentTitle

}

function updateSecondarySegment(eGuideId, secondarySegmentIndex, oldSecondarySegmentTitle, eGuideQuarter)
{

    // make elements invisible
    document.getElementById("unitNewline1" + secondarySegmentIndex).style.display = "none"; 
    document.getElementById("secondarySegmentEditBox" + secondarySegmentIndex).style.display = "none"; 
    document.getElementById("unitNewline2" + secondarySegmentIndex).style.display = "none"; 
    document.getElementById("submitUpdatedSecondarySegment" + secondarySegmentIndex).style.display = "none"; 

	// Store Secondary Segment title
	if(xmlHttp12)
	{
		// try to connect to the server
		try
		{
            // initiate reading the Books fro   m the server
			xmlHttp12.open("POST", "php/putSecondarySegmentTitle.php?MySQLSessionID=" + MySQLSessionID + "&eGuideId=" + eGuideId + "&SecondarySegmentTitle=" + document.getElementById("secondarySegmentEditBox" + secondarySegmentIndex).value + "&OldSecondarySegmentTitle=" + oldSecondarySegmentTitle, true);
			xmlHttp12.send(null);

		}
		// display the error in case of failure
		catch (e)
		{
			// alert("Can't connect to server:\n" + e.toString());
		}
	}

    // reload eguide to update secondary segment values
	populateeGuideContent(eGuideId,eGuideQuarter,'');	// draws table
	populateeGuideOptions(eGuideId,eGuideQuarter);		// draws template for primary and segment information, title and column titles, places the resrouce types into the specified columns
    
}

