var objXML;
var arrMenu;

//Draw Date
function drawDate(){
	var now = new Date();
    var days = new Array(
      'Sunday','Monday','Tuesday',
      'Wednesday','Thursday','Friday','Saturday');
    var months = new Array(
      'January','February','March','April','May',
      'June','July','August','September','October',
      'November','December');
    var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
    function fourdigits(number)	{
      return (number < 1000) ? number + 1900 : number;
	}
    today =  days[now.getDay()] + ", " +  months[now.getMonth()] + " " +  date + ", " +  (fourdigits(now.getYear()));
    document.write(today);
}

// Draws HTML for Top Right Menu
function drawHeaderMenu1(){
		document.write('<a href="/">HOME</a> | <a href="/index.cfm?fa=siteMap">SITE MAP</a> | <a href="/index.cfm?fa=contact">CONTACT US</a>');
}

// Draws HTML for Dropdown Menu
function drawHeaderMenu2(){
		document.write('<div style="font-family:arial; color:#ffffff;font-size:12px;text-align:center;"><a href="/">Home</a>&nbsp; &nbsp;|&nbsp;&nbsp; <a href="/about_us">About Us</a>&nbsp;&nbsp; |&nbsp;&nbsp; <a href="/personal">Personal Insurance</a>&nbsp;&nbsp; |&nbsp;&nbsp; <a href="/commercial">Commercial Insurance</a>&nbsp;&nbsp;|&nbsp;&nbsp; <a href="/client_services">Client Services</a></div>');
}
// Draws HTML for Right Footer Links 
function drawFooterLinks(){
	document.write('<a href="/index.cfm?fa=privacyPolicy">Privacy Policy</a>');
}

// get the XML document from a file name
function getXmlDocument(sFile) {
	var xmlHttp, oXML;
	
	// try to use the native XML parser
	try {
		xmlHttp = new XMLHttpRequest();
		xmlHttp.open("GET", sFile, false); // Use syncronous communication
		xmlHttp.send(null);
		oXML = xmlHttp.responseXML;
	} catch(e) {
		// can't use the native parser, use the ActiveX instead
		xmlHttp = getXMLObject();
		xmlHttp.async = false;            // Use syncronous communication
		xmlHttp.resolveExternals = false;
		xmlHttp.load(sFile);
		oXML = xmlHttp;
	}
	
	// return the XML document object
	return oXML;
}

// get the best ActiveX object that can read XML
function getXMLObject() {
	// create an array with the XML ActiveX versions
	var aVersions = new Array("Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0");
	
	// loop through the array until we can create an activeX control
	for (var i=0; i<aVersions.length; i++) {
		// return when we can create the activeX control
		try {
			var oXML = new ActiveXObject(aVersions[i]);
			return oXML;
		} catch(e) {
		}
	}
	
	// could not create an activeX, return a null
	return null;
}

// get XML data within an element tag
function getElementData(oXML, sElement) {
	return oXML.getElementsByTagName(sElement)[0].firstChild.data;
}

function init(){
	objXML = getXmlDocument("../data/menu.xml");
	//get the menu that matches the filename (location)	
	drawLeftMenu();
}

function drawLeftMenu(){
	
	var vMenus = objXML.getElementsByTagName("menu");
	var vHTML = "";
	for(var i=0; i<vMenus.length;i++){
		
		var file = unescape(String(document.location));
		var marker = unescape(String(vMenus[i].getAttribute("file")));
		//alert('file: ' +file + '|| marker: ' + marker);
		if(file.indexOf(marker) != -1){
			var vMenuItems = vMenus[i].getElementsByTagName("menuItem");
			vHTML += "<div id='dMenuItem'>";
			vHTML += " <div><img src='../media/menu_top.jpg'/></div>";
			for(var j=0; j<vMenuItems.length;j++){
				var vURL = String(vMenuItems[j].getAttribute("url"));
				var vIMG = String(vMenuItems[j].getAttribute("img"));
				var vTitle = String(vMenuItems[j].getAttribute("title"));
				
				vHTML += "<div class='menuItem'><a onclick='drawLeftMenu()' href='"+ vURL +"'>"+ vTitle +"</a></div>";

				if(j+1 != vMenuItems.length){
					vHTML += "<div class='menuDivide'></div>";	
				}
			}
			vHTML += "<div><img src='../media/menu_bottom.jpg' /></div>";
			vHTML += "</div>";
			document.getElementById("dContentItem1").innerHTML = vHTML;
		}else{
			//document.getElementById("dContentItem1").innerHTML = "";
		}
	}	
}

function term(){
	objXML = null;
}