// JavaScript Document

var associates = new Array()

function parseXML (xmlObj, thefunction){
	associatesNode = xmlObj.getElementsByTagName("associate");
	for (e=0; e < associatesNode.length; e++){
		var employee = null
		employee = new Object()
		employee.name = getAttr(associatesNode[e], "name")
		employee.group = getAttr(associatesNode[e], "group")
		employee.shortgroup = getAttr(associatesNode[e], "shortgroup")
		employee.longgroup = getAttr(associatesNode[e], "longgroup")		
		employee.imagethumb = getAttr(associatesNode[e], "imagethumb")
		employee.imagesmall = getAttr(associatesNode[e], "imagesmall")
		employee.imagelarge = getAttr(associatesNode[e], "imagelarge")
		allquotes = associatesNode[e].getElementsByTagName("quote");
		quotearray = null;
		quotearray = new Array();
		for (i = 0; i < allquotes.length; i++){
			thisquote = null;
			thisquote = new Object();
			thisquote.type = getAttr(allquotes[i], "type")
			thisquote.header = getAttr(allquotes[i], "header")
			thisquote.quote = getVal(allquotes[i]);
			quotearray.push(thisquote);
		}
		employee.quote = quotearray;
		associates.push(employee);
	}
	if (window.location.href.toLowerCase().indexOf('associate.html') > -1){
		fillEmp();
	} else {
		fillGrid();
	}
}

function fillGrid(){
	var r = '';
	r += '<table cellpadding="0" cellspacing="0" border="0" width="100%" id="associatestable">';
	for (e=0; e<associates.length; e++){
		imgstyle=' class="rimage"';				
		tdstyle='';
		if (e % 2 ==0){
			imgstyle = '';
			if (e != 0){r+= '</tr>';}
			tdstyle=' class="rborder"';
			r+= '<tr>';
		}
		thisquote = '';
		for (i = 0; i < associates[e].quote.length; i++){
			ourquote = associates[e].quote[i];
			if (ourquote.type == 'short'){
				thisquote = ourquote.quote;
				break;
			}
		}
		r+= '<td' + tdstyle +'><a href="/careers/working_here/associates/associate.html?nm='+ associates[e].name + '&grp=' + associates[e].shortgroup + '&ttl=' + escape(associates[e].longgroup) + '"><img src="/_img/testimonials/' + associates[e].imagesmall +'" alt="' + associates[e].name + '" align="left"' + imgstyle + '></a><p><a href="/careers/working_here/associates/associate.html?nm='+ associates[e].name + '&grp=' + associates[e].shortgroup + '&ttl=' + escape(associates[e].longgroup)  + '">'+ associates[e].name + '</a><br />' + associates[e].longgroup + '</p><p class="shortquote"><em>"' + thisquote + '"</em></p></td>';
	}
	r += '</table>';
	document.getElementById('associategrid').innerHTML = r;
}

function fillEmp(){
	thisassociate = '';
	for (i=0; i<associates.length; i++){
		if (associates[i].name.toLowerCase() == nm.toLowerCase() && associates[i].shortgroup.toLowerCase() == grp.toLowerCase() && associates[i].longgroup.toLowerCase() == ttl.toLowerCase()){
			thisassociate = associates[i];
			break;
		}
	}
	fillList();
	var r = '';
	if (thisassociate != ''){
		for (i = 0; i < thisassociate.quote.length; i++){
			ourquote = thisassociate.quote[i];
			if (ourquote.type == 'full'){
				thisheader = ourquote.header
				thisquote = ourquote.quote;
				if (thisheader != ''){r+= '<h3 style="margin-top:0px;margin-bottom:3px;">' + thisheader + '</h3>';}
				r+= '<p style="margin-top:0;margin-bottom:15px;">' + thisquote + '</p>';
			}
		}	
		document.getElementById('associatePhoto').src = '/_img/testimonials/' + thisassociate.imagelarge;
		document.getElementById('associateName').innerHTML = '<strong>' + thisassociate.name + '</strong><br />' + thisassociate.longgroup + '';
		document.getElementById('associateShortgroup').innerHTML = '<strong>' + thisassociate.shortgroup.toUpperCase()  + ' PROFILE</strong><br />';
		document.getElementById('associateQuote').innerHTML = r;
	}
	if (associates.length > 1){
		document.getElementById('cellSidebar').style.display = '';
	}
}

function fillList(){
	var grabbedStr = '';
	var optionStr = '';
	allOpts = new Array();
	for(k=0;k<associates.length;k++){
		if (grabbedStr.indexOf('|' + associates[k].name + '*' + associates[k].longgroup +'|') == -1){
			for (x=0;x<allOpts.length;x++){
				if (associates[k].name < allOpts[x].name){
					allOpts.splice(x,0,associates[k]);
					break;
				}
			}
			if (x == allOpts.length){
				allOpts.push(associates[k]);	
			}
			grabbedStr += '|' + associates[k].name + '*' + associates[k].longgroup +'|';
		}
	}	
	for(o = 0; o< allOpts.length;o++){
		if (allOpts[o].name.toLowerCase() == nm.toLowerCase() && allOpts[o].shortgroup.toLowerCase() == grp.toLowerCase() && allOpts[o].longgroup.toLowerCase() == ttl.toLowerCase()){
			thisassociate = allOpts[o];
			document.getElementById('associateList').innerHTML += '<p><span style="color:#c4863d;font-weight:bold;">' + allOpts[o].name + '</span><br />' + allOpts[o].longgroup + '</p>';			
		} else {
			document.getElementById('associateList').innerHTML += '<p><strong><a href="/careers/working_here/associates/associate.html?nm=' + allOpts[o].name + '&grp=' + allOpts[o].shortgroup + '&ttl=' + escape(allOpts[o].longgroup) + '">' + allOpts[o].name + '</a></strong><br />' + allOpts[o].longgroup + '</p>';
		}
	}	
	allOpts = '';
}
