/*

	NOTES
		Country listing from spreadsheet drives the condition
*/
var testing = false;
var globalStateChoice = '';
var globalRegionChoice = 'US';

function getState(stateAbr){
	var HTMLDisp = '';
	var results = document.getElementById('clickMapResults');
	results.innerHTML = '<h1>' + stateAbr + '</h1>';
	globalStateChoice = stateAbr;
	importXML('/xml/content/locator_usDistributors.xml','parseXml');
	return false;
}
function loadMapLocator() {
	/* same as explodeMapLocator() function at homePage.js */
	document.getElementById('locatorExplodeMap').style.display = 'block';
	xmlhttpPost('/O2Net/Applications/TransformDoc/default.aspx?XmlDoc=/xml/content/locator_usDistributors.xml&XsltDoc=/xslt/salesRepsUsImgMap.xslt','locatorExplodeMap');
}
function parseXml(xmlDoc) {
	var HTMLDisp = '';
	var x = xmlDoc.getElementsByTagName('listing');
	var listingState = window.globalStateChoice;
	var results = document.getElementById('clickMapResults');
	var stateListing = '';
	var region = window.globalRegionChoice;
	// xml node vars
	var locateMatchState = '';
	var salesRepName = '';
	var salesRepPhone = '';
	var salesRepEmail = '';
	var techRepName = '';
	var techRepPhone = '';
	var techRepEmail = '';
	var countListings = 0;
	var browser=navigator.appName;

	for (i=0;i<x.length;i++)
	{	
		if(i == 0){
			HTMLDisp = HTMLDisp + '<div id=\"closeMapListing\"><a href=\"#\" onClick=\"compressExplodedMap();return false\"><img alt=\"Close\" id=\"closeMapImg\" src=\"/images/trans.gif\" /></a></div>';
			HTMLDisp = HTMLDisp + '<div id=\"returnMap\" onClick=\"backToMap();return false\">';
			if(browser == 'Netscape'){
				HTMLDisp = HTMLDisp + '<h3>';
			}
			HTMLDisp = HTMLDisp + '<a href=\"#\">';
			HTMLDisp = HTMLDisp + 'Back to map';
			HTMLDisp = HTMLDisp + '</a>';
			if(browser == 'Netscape'){
				HTMLDisp = HTMLDisp + '</h3>';
			}			
			HTMLDisp = HTMLDisp + '</div>';
			HTMLDisp = HTMLDisp + '<div id=\"stateChoosen\">' + listingState + '</div>';
		}	
		for (j=0;j<x[i].childNodes.length;j++)
		{
			if (x[i].childNodes[j].nodeType != 1) continue;
			stateListing = x[i].childNodes[0].firstChild.nodeValue;
			if(stateListing == listingState){
				if(testing){
					HTMLDisp = HTMLDisp + '<li>' + j + '=========' + '</li>';
					HTMLDisp = HTMLDisp + '<li>' + j + '---' + x[i].childNodes[j].firstChild.nodeValue + '</li>';
				}
				// xml node vars
				locateMatchState = x[i].childNodes[0].firstChild.nodeValue;
				salesRepName = x[i].childNodes[1].firstChild.nodeValue;
				salesRepPhone = x[i].childNodes[2].firstChild.nodeValue;
				salesRepEmail = x[i].childNodes[3].firstChild.nodeValue;
				techRepName = x[i].childNodes[4].firstChild.nodeValue;
				techRepPhone = x[i].childNodes[5].firstChild.nodeValue;
				techRepEmail = x[i].childNodes[6].firstChild.nodeValue;
				countListings ++;
			}
		}
		if(stateListing == listingState){
			/* Cannnot place this within the J loop */	
			HTMLDisp = HTMLDisp + '<div class=\"company\">';
			HTMLDisp = HTMLDisp + 	'<div class=\"category\">Sales Rep</div>';
			HTMLDisp = HTMLDisp + 	'<div class=\"contactName\">';
			HTMLDisp = HTMLDisp + 		salesRepName;
			HTMLDisp = HTMLDisp + 	'</div>';
			HTMLDisp = HTMLDisp + 	'<div class=\"companyContactPhone\">';
			HTMLDisp = HTMLDisp + 		salesRepPhone;
			HTMLDisp = HTMLDisp + 	'</div>';
			HTMLDisp = HTMLDisp + 	'<div class=\"companyAddress1\">';
			HTMLDisp = HTMLDisp + 		'<a href=\"MailTo:\"' + salesRepEmail + '\">' + salesRepEmail + '</a>';
			HTMLDisp = HTMLDisp + 		'<div class=\"category\">Tech Rep</div>';
			HTMLDisp = HTMLDisp + 		'<div class=\"contactName\">';
			HTMLDisp = HTMLDisp + 			techRepName;
			HTMLDisp = HTMLDisp + 		'</div>';
			HTMLDisp = HTMLDisp + 		'<div class=\"companyContactName\">';
			HTMLDisp = HTMLDisp + 			techRepPhone;
			HTMLDisp = HTMLDisp + 		'</div>';
			HTMLDisp = HTMLDisp + 		'<div class=\"companyAddress1\">';
			HTMLDisp = HTMLDisp + 			'<a href=\"MailTo:\"' + techRepEmail + '\">' + techRepEmail + '</a>';
			HTMLDisp = HTMLDisp + 		'</div>';
			HTMLDisp = HTMLDisp + 	'</div>';
			HTMLDisp = HTMLDisp + '</div>';
		}
	}
	if(testing){
		HTMLDisp = HTMLDisp + "countListings " + countListings;
	}
	/* ~~~~~~~~~~~~~~~~~~~~[ default for no state found ] ~~~~~~~~~~~~~~~~~~ */
	if(countListings == 0){
		if(window.globalStateChoice != 'XX'){
			globalStateChoice = 'XX';
			parseXml(xmlDoc);
		}else{	
			HTMLDisp = HTMLDisp + 'NO LISTING';
			results.innerHTML = HTMLDisp;
		}	
	}else{
		results.innerHTML = HTMLDisp;
	}

	document.getElementById('locatorExplodeMapShell').style.display = 'none';
	document.getElementById('clickMapResults').style.display = 'block';
	reDrawSifr();

}
function changeMap(mapType){
	var results = document.getElementById('clickMapResults');
	if(mapType == 'US'){
		document.getElementById('locatorExplodeMapShell').style.display = 'block';
		document.getElementById('locatorExplodeMapShellCan').style.display = 'none';
		globalRegionChoice = 'US';
	}else{
		alert('mapType not set');
		globalRegionChoice = 'US';
	}
	results.innerHTML = 'Click above to see reps for your area.';
}
function backToMap(){
		document.getElementById('locatorExplodeMapShell').style.display = 'block';
		document.getElementById('clickMapResults').style.display = 'none';
}
function reDrawSifr(){
     
	 sIFR.replace(sifrFont1, {
     selector: 'h2'
     ,css: [
       '.sIFR-root { text-align: left; font-weight: bold; }'
     ]
     ,
  	wmode: 'transparent'	  
   });
     sIFR.replace(sifrFont1, {
	selector: 'h3'
    ,css: [
    	'.sIFR-root { text-align: center; font-weight: bold; }'
		,'a { text-decoration: underline; }'
		,'a:link { color: #f89b1c; }'
		,'a:hover { color: #f89b1c; text-decoration: underline;}'
	]
    ,
  	wmode: 'transparent'	  
   });   
}

