
/**
 * @depreciated
 */
function _fetchGLSalesStructure()
{
	var argv = _fetchGLSalesStructure.arguments;

	var xmlHttp = getXmlHttpRequest();

	var countryValue 	= _getGLCountry().value;
	var regionValue 	= _getGLRegion().value;
	var subRegionValue 	= _getGLSubRegion().value;
	var industryValue 	= _getGLIndustry().value;
	var divisionValue 	= _getGLDivision().value;

	var url = ctrlUrl + 'ajax/sales-structure-results' 	+
						'/countrycode/' + countryValue + // Country
						'/statecode/' 	+ regionValue + // Region
						'/countycode/' 	+ subRegionValue + // Sub Region
						'/industryKey/' 	+ industryValue + // Industry
						'/divisionKey/' 	+ divisionValue // Division
						;

	xmlHttp.open("GET", url, true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4){
			if (xmlHttp.status == 200){

				// Fetch the response tag
				var rspXML = xmlHttp.responseXML;

				// Fetch the error tag
				RSS_errTag = rspXML.getElementsByTagName('error');
				RSS_LocalOffices = new Array();
				RSS_RegionalOffices = new Array();
				RSS_NationalOffices = new Array();

				// Was there an error?
				if (RSS_errTag.length != 0){

				}else{

					// Results found
					// Local Offices
					RSS_LocalOffices = rspXML.getElementsByTagName('officeLocal');

					// Regional Offices
					RSS_RegionalOffices = rspXML.getElementsByTagName('officeRegional');

					// National Offices
					RSS_NationalOffices = rspXML.getElementsByTagName('officeNational');
				}
				if(1 == argv[0]){ // Do we need to retrieve both sets of results?
					_fetchGLIntialResults();
				}

			}else{
				// Non 200 HTTP status
			}
		}
	}
}


function _runGLSalesStructure()
{
	// Firstly we clear all children from the results div
	var len = ajaxResDiv.childNodes.length;
	while (ajaxResDiv.hasChildNodes()){
		ajaxResDiv.removeChild(ajaxResDiv.firstChild);
	}

	// Clear all children from the contacts div
	var len = ajaxContactsDiv.childNodes.length;
	while (ajaxContactsDiv.hasChildNodes()){
		ajaxContactsDiv.removeChild(ajaxContactsDiv.firstChild);
	}

	// Hide the contacts div
	hideDiv('ajaxContactsDiv');
	ajaxContactsDiv.style.height = '1px';
	ajaxContactsDiv.style.margin = '0';
	ajaxContactsDiv.style.padding = '0';
	ajaxContactsDiv.style.lineHeight = '0';

	// Show the results div
	showDiv('ajaxResDiv');

	ajaxResDiv.style.height = 'auto';
	ajaxResDiv.style.margin = 'auto';
	ajaxResDiv.style.lineHeight = '18px';

	if (RSS_errTag.length != 0){

					// Heading
					conH1 = document.createElement('h1');
					conH1.innerHTML = noSalesStructureText;
					ajaxResDiv.appendChild(conH1);

					// *No* results found
					var pEle = document.createElement('p');
					pEle.innerHTML = generalSearchSuggestionsText;
					ajaxResDiv.appendChild(pEle);

	}else{

		// Results found

		// back button
		var conBackDiv = document.createElement('div');

		if (backText.length > 5) {
			conBackDiv.className = 'back-large';
		} else {
			conBackDiv.className = 'back';
		}

		conBackDiv.style.cssFloat = 'right';
		var conBackLink = document.createElement('a');
		conBackLink.innerHTML = backText;
		conBackLink.title = backText;
		conBackLink.href = 'javascript:_runGL();';
		conBackDiv.appendChild(conBackLink);
		ajaxResDiv.appendChild(conBackDiv);

		// Heading
		conH1 = document.createElement('h1');
		conH1.innerHTML = rotorkSalesStructureText;
		ajaxResDiv.appendChild(conH1);

		var ins = document.createElement('p');
		ins.innerHTML = clickOnOfficeNameText + '.<br />';
		ajaxResDiv.appendChild(ins);

		// Global table child
		tableChild = document.createElement('table');
		tableChild.cellSpacing = 0;
		tableChild.cellPadding = 0;
		tableChild.border = 0;
		tableChild.className = 'gLResTable';

		// Create tbody as this is required for correct display in IE
		// Must be global.
		tableBody = document.createElement('tbody');

		// Local Offices
		for(var i = 0, j = RSS_LocalOffices.length; i < j; i++){

			// Calculate the row class name
			var accountClassName = 'gLAccountRow_even';

			if (0 == i){
				// Add the heading
				_addTableHeading(localOfficesText + ' (' + RSS_LocalOffices.length + ')');
			}

			// Add details
			_addAccounts(RSS_LocalOffices, i, ajaxResDiv, accountClassName, 'salesStructure', true);

			if ((i + 1) == RSS_LocalOffices.length){
				_addSpacerRow(ajaxResDiv);
				_addSpacerRow(ajaxResDiv);
			}else{
				_addSpacerRow2(ajaxResDiv);
			}
		}

		// Regional Offices
		for(var i = 0, j = RSS_RegionalOffices.length; i < j; i++){

			// Calculate the row class name
			var accountClassName = 'gLAccountRow_even';

			if (0 == i){
				// Add the heading
				_addTableHeading(regionalOfficesText + ' (' + RSS_RegionalOffices.length + ')');
			}

			// Add details
			_addAccounts(RSS_RegionalOffices, i, ajaxResDiv, accountClassName, 'salesStructure', true);

			if ((i + 1) == RSS_RegionalOffices.length){
				_addSpacerRow(ajaxResDiv);
				_addSpacerRow(ajaxResDiv);
			}else{
				_addSpacerRow2(ajaxResDiv);
			}
		}

		// National Offices
		for(var i = 0, j = RSS_NationalOffices.length; i < j; i++){

			// Calculate the row class name
			var accountClassName = 'gLAccountRow_even';

			if (0 == i){
				// Add the heading
				_addTableHeading(nationalOfficesText + ' (' + RSS_NationalOffices.length + ')');
			}

			// Add details
			_addAccounts(RSS_NationalOffices, i, ajaxResDiv, accountClassName, 'salesStructure', true);

			if ((i + 1) == RSS_NationalOffices.length){
				_addSpacerRow(ajaxResDiv);
				_addSpacerRow(ajaxResDiv);
			}else{
				_addSpacerRow2(ajaxResDiv);
			}
		}
	}

	// Clear all
	var clearMe = document.createElement('div');
	clearMe.className = 'clearMe';
	ajaxResDiv.appendChild(clearMe);

	var ssBr = document.createElement('br');
	ajaxResDiv.appendChild(ssBr);

	var ssHr = document.createElement('div');
	ssHr.className = 'fakeHr';
	ajaxResDiv.appendChild(ssHr);

	var ssBr = document.createElement('br');
	ajaxResDiv.appendChild(ssBr);

	// back button
	var conBackDiv = document.createElement('div');
	if (backText.length > 5) {
		conBackDiv.className = 'back-large';
	} else {
		conBackDiv.className = 'back';
	}

	var conBackLink = document.createElement('a');
	conBackLink.innerHTML = backText;
	conBackLink.title = backText;
	conBackLink.href = 'javascript:_runGL();';
	conBackDiv.appendChild(conBackLink);
	ajaxResDiv.appendChild(conBackDiv);


	//_handleGLCountrySelection();
}

function _runGLSalesStructure_old()
{
	// Firstly we clear all children from the results div
	var len = ajaxResDiv.childNodes.length;
	while (ajaxResDiv.hasChildNodes()){
		ajaxResDiv.removeChild(ajaxResDiv.firstChild);
	}

	// Clear all children from the contacts div
	var len = ajaxContactsDiv.childNodes.length;
	while (ajaxContactsDiv.hasChildNodes()){
		ajaxContactsDiv.removeChild(ajaxContactsDiv.firstChild);
	}

	// Hide the contacts div
	hideDiv('ajaxContactsDiv');
	ajaxContactsDiv.style.height = '1px';
	ajaxContactsDiv.style.margin = '0';
	ajaxContactsDiv.style.padding = '0';
	ajaxContactsDiv.style.lineHeight = '0';

	// Show the results div
	showDiv('ajaxResDiv');

	ajaxResDiv.style.height = 'auto';
	ajaxResDiv.style.margin = 'auto';
	ajaxResDiv.style.lineHeight = '18px';

	// Show the results

	var countryValue 	= _getGLCountry().value;
	var regionValue 	= _getGLRegion().value;
	var subRegionValue 	= _getGLSubRegion().value;
	var industryValue 	= _getGLIndustry().value;
	var divisionValue 	= _getGLDivision().value;

	var xmlHttp = getXmlHttpRequest();

	var url = ctrlUrl + 'ajax/sales-structure-results' 	+
						'/countrycode/' + countryValue + // Country
						'/statecode/' 	+ regionValue + // Region
						'/countycode/' 	+ subRegionValue + // Sub Region
						'/industryKey/' 	+ industryValue + // Industry
						'/divisionKey/' 	+ divisionValue // Division
						;

	xmlHttp.open("GET", url, true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4){
			if (xmlHttp.status == 200){

				// Fetch the response tag
				var rspXML = xmlHttp.responseXML;

				// Fetch the error tag
				var errTag = rspXML.getElementsByTagName('error');

				// Was there an error?
				if (errTag.length != 0){

					// Heading
					conH1 = document.createElement('h1');
					conH1.innerHTML = noSalesStructureText;
					ajaxResDiv.appendChild(conH1);

					// *No* results found
					var pEle = document.createElement('p');
					pEle.innerHTML = generalSearchSuggestionsText;
					ajaxResDiv.appendChild(pEle);

				}else{

					// Results found

					// Heading
					conH1 = document.createElement('h1');
					conH1.innerHTML = rotorkSalesStructureText;
					ajaxResDiv.appendChild(conH1);

					var ins = document.createElement('p');
					ins.innerHTML = clickOnOfficeNameText +'.<br />';
					ajaxResDiv.appendChild(ins);

					// Global table child
					tableChild = document.createElement('table');
					tableChild.cellSpacing = 0;
					tableChild.cellPadding = 0;
					tableChild.border = 0;
					tableChild.className = 'gLResTable';

					// Create tbody as this is required for correct display in IE
					// Must be global.
					tableBody = document.createElement('tbody');

					// Agents Reps
					var agentRep = rspXML.getElementsByTagName('agentRep');

					var lastAccountNumber = 0;
					for(var i = 0, j = agentRep.length; i < j; i++){

						// Calculate the row class name
						if (lastAccountNumber != nodeValue(agentRep[i].getElementsByTagName('accountnumber')[0])){
							var accountClassName = 'gLAccountRow_even';
						}else{
							var accountClassName = 'gLAccountRow_odd';
						}

						if (0 == i){
							// Add the heading
							_addTableHeading(rotorkAgentsRepsText + ' (' + agentRep.length + ')');
						}

						// Add details
						_addAccounts(agentRep, i, ajaxResDiv, accountClassName, 'salesStructure', true);

						lastAccountNumber = nodeValue(agentRep[i].getElementsByTagName('accountnumber')[0]);

						if ((i + 1) == agentRep.length){
							_addSpacerRow(ajaxResDiv);
						}

					}

					// Distributors
					var distributor = rspXML.getElementsByTagName('distributor');
					for(var i = 0, j = distributor.length; i < j; i++){

						// Calculate the row class name
						var accountClassName = 'gLAccountRow_even';

						if (0 == i){
							// Add the heading
							_addTableHeading(distributorsText + ' (' + distributor.length + ')');
						}

						// Add details
						_addAccounts(distributor, i, ajaxResDiv, accountClassName, 'salesStructure', true);

						if ((i + 1) == distributor.length){
							_addSpacerRow(ajaxResDiv);
						}

					}

					// Local Offices
					var officeLocal = rspXML.getElementsByTagName('officeLocal');
					for(var i = 0, j = officeLocal.length; i < j; i++){

						// Calculate the row class name
						var accountClassName = 'gLAccountRow_even';

						if (0 == i){
							// Add the heading
							_addTableHeading(localOfficesText + ' (' + officeLocal.length + ')');
						}

						// Add details
						_addAccounts(officeLocal, i, ajaxResDiv, accountClassName, 'salesStructure', true);

						if ((i + 1) == officeLocal.length){
							_addSpacerRow(ajaxResDiv);
						}
					}

					// Regional Offices
					var officeRegional = rspXML.getElementsByTagName('officeRegional');
					for(var i = 0, j = officeRegional.length; i < j; i++){

						// Calculate the row class name
						var accountClassName = 'gLAccountRow_even';

						if (0 == i){
							// Add the heading
							_addTableHeading(regionalOfficesText + ' (' + officeRegional.length + ')');
						}

						// Add details
						_addAccounts(officeRegional, i, ajaxResDiv, accountClassName, 'salesStructure', true);

						if ((i + 1) == officeRegional.length){
							_addSpacerRow(ajaxResDiv);
						}
					}

					// National Offices
					var officeNational = rspXML.getElementsByTagName('officeNational');
					for(var i = 0, j = officeNational.length; i < j; i++){

						// Calculate the row class name
						var accountClassName = 'gLAccountRow_even';

						if (0 == i){
							// Add the heading
							_addTableHeading(nationalOfficesText + ' (' + officeNational.length + ')');
						}

						// Add details
						_addAccounts(officeNational, i, ajaxResDiv, accountClassName, 'salesStructure', true);

						if ((i + 1) == officeNational.length){
							_addSpacerRow(ajaxResDiv);
						}
					}
				}

			}else{
				// Non 200 HTTP status
			}

			// Clear all
			var clearMe = document.createElement('div');
			clearMe.className = 'clearMe';
			ajaxResDiv.appendChild(clearMe);

			var ssBr = document.createElement('br');
			ajaxResDiv.appendChild(ssBr);

			var ssHr = document.createElement('div');
			ssHr.className = 'fakeHr';
			ajaxResDiv.appendChild(ssHr);

			var ssBr = document.createElement('br');
			ajaxResDiv.appendChild(ssBr);

			// back button
			var conBackDiv = document.createElement('div');
			conBackDiv.className = 'back2';

			var conBackLink = document.createElement('a');
			conBackLink.innerHTML = backText;
			conBackLink.title = backText;
			conBackLink.href = 'javascript:_runGL();';
			conBackDiv.appendChild(conBackLink);
			ajaxResDiv.appendChild(conBackDiv);
		}
	}



	//_handleGLCountrySelection();
}
