var expandedCompanies = new Array();
var expandedCatagories = new Array();
var subscriptionPage = 0;

function loadSubscriptions() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	subscriptionPage = 1;
	var url="/ajax/loadTxtNetCompanies.php";
	url=url+"?sid="+Math.random();
	url=url+"&subscriptionPage=1";
	showProcessing();
	xmlHttp.onreadystatechange=loadSubscriptionsComplete; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadTxtNetSubscriptions(companyType, companyCategory) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	subscriptionPage = 0;
	var url="/ajax/loadTxtNetCompanies.php";
	url=url+"?sid="+Math.random();
	if (document.getElementById("subscriptionsValidStates").value.length > 0)
		url=url+"&state="+urlEncode(document.getElementById("subscriptionsValidStates").value);
	if (document.getElementById("subscriptionsValidCities").value.length > 0)
		url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
	if (companyType != null)
		url=url+"&compType="+urlEncode(companyType);
	if (companyCategory != null)
		url=url+"&compCat="+urlEncode(companyCategory);	
	showProcessing();
	xmlHttp.onreadystatechange=loadSubscriptionsComplete; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadSubscriptionsComplete() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		xmlDoc=xmlHttp.responseXML;
		closeProcessing();
		if (xmlDoc.getElementsByTagName("txtNetLoadStatus")[0].childNodes[0].nodeValue == 0) {
			document.getElementById("modalmessagebox").style.display = "none";
			modalAlert (xmlDoc.getElementsByTagName("txtNetStatusMessage")[0].childNodes[0].nodeValue, 'Subscription Load Problem');
			return;
		}
		else {
			if (document.getElementById("modalmessagebox").style.display == "") {
				if (document.getElementById("subscriptionEmailEnter") != null)
					document.getElementById("regemail").value = document.getElementById("subscriptionEmailEnter").value;
				if (document.getElementById("subscriptionLandLinePhoneEnter") != null)
					document.getElementById("reglandLineNumber").value = document.getElementById("subscriptionLandLinePhoneEnter").value;
				if (document.getElementById("subscriptionCellPhoneEnter") != null)
					document.getElementById("regmobileNumber").value = document.getElementById("subscriptionCellPhoneEnter").value;
				document.getElementById("modalmessagebox").style.display = "none";
			}
			if (xmlDoc.getElementsByTagName("companyCategory") != null) {
				if (subscriptionPage == 1) {
					document.getElementById("txtNetListArea").innerHTML = '';
					document.getElementById("companyListArea").innerHTML = drawTxtNetCategories(xmlDoc.getElementsByTagName("companyCategory"));
				}
				else {
					document.getElementById("companyListArea").innerHTML = '';
					document.getElementById("txtNetListArea").innerHTML = drawNewTxtNetCategories(xmlDoc.getElementsByTagName("companyCategory"));
				}
			}
		}
		
		if (subscriptionPage == 0 && document.getElementById("subscriptionsValidStates").options.length <= 1)
			loadValidStates();
		else
			closeProcessing();
	}
}

function categoryShow(area) {
	for (var i=0; i<document.getElementsByTagName('*').length; i++) {
		if (document.getElementsByTagName('*')[i].id.indexOf("companyAreaBar") > 0 && document.getElementsByTagName('*')[i].id != (area+"Bar")) {
			if (document.getElementsByTagName('*')[i].style.display != "none") {
				var newarea = document.getElementsByTagName('*')[i].id.substr(0, (document.getElementsByTagName('*')[i].id.length -3));
				expandedCatagories[newarea] = 'no';
				Effect.Fade(newarea);
				document.getElementById(document.getElementsByTagName('*')[i].id).className="";
			}
		}
	}
	if (document.getElementById(area).style.display == "none") {
		expandedCatagories[area] = 'yes';
		Effect.Appear(area);
		document.getElementById(area + "Bar").className="current";
	}
	else { 
		expandedCatagories[area] = 'no';
		Effect.Fade(area);
		document.getElementById(area + "Bar").className="";
	}
}

function groupsShow(index) {	
	if (document.getElementById('subgroups' + index).style.display == "none") {
		expandedCompanies[index] = 'yes';
		Effect.Appear('subgroups' + index);
		document.getElementById("showsublink" + index).innerHTML = '<a href="javascript:groupsShow(\'' + addslashes(index) + '\')">hide subscription groups</a>';
	}
	else {
		expandedCompanies[index] = 'no';
		Effect.Fade('subgroups' + index);
		document.getElementById("showsublink" + index).innerHTML = '<a href="javascript:groupsShow(\'' + addslashes(index)+ '\')">show subscription groups</a>';
	}
}

function drawTxtNetCategories(categories) {
	var html = '';
	if (categories.length == 1) {
		expandedCatagories = new Array();
		if (subscriptionPage == 1)
		    html += html += '<div class="txtnetlink" style="padding: 3px; margin-left: -3px;"><a href="javascript:unsubscribeAll(\'\')">Unsubscribe From All</a></div>';
		html += drawTxtNetCompanies(categories, 0);
	}
	else {
		for (var categoriesIndex = 0; categoriesIndex<categories.length; categoriesIndex++) {
			var indx = stripSpecial(categories[categoriesIndex].childNodes[0].childNodes[0].nodeValue) + 'companyArea';
			var show = true;
			if (expandedCatagories[indx] == undefined || expandedCatagories[indx] == 'no') {
				show = false;
			}
			html += '<div class="optionheading" >';
			html += '<a href="javascript:categoryShow(\'' + stripSpecial(categories[categoriesIndex].childNodes[0].childNodes[0].nodeValue) + 'companyArea\')" id="' + stripSpecial(categories[categoriesIndex].childNodes[0].childNodes[0].nodeValue) + 'companyAreaBar">';
			html += categories[categoriesIndex].childNodes[0].childNodes[0].nodeValue;
			html += '</a></div>';
			html += '<div id="' + stripSpecial(categories[categoriesIndex].childNodes[0].childNodes[0].nodeValue) + 'companyArea" class="txtnetoptionbody" ';
			if (!show)
				html += 'style="display:none;"';
			html += ">";
			html += drawTxtNetCompanies(categories, categoriesIndex);
			html += '</div>';
		}
	}
	return html;
}

function drawNewTxtNetCategories(categories) {
	var html = '';
	if (categories.length == 1) {
		expandedCatagories = new Array();
		html += drawNewTxtNetCompanies(categories, 0);
	}
	return html;
}

function drawTxtNetCompanies(categories, categoryIndex) {
	companies = categories[categoryIndex];
	var html = '';
		for (var companyIndex=1; companyIndex<companies.childNodes.length; companyIndex++) {
			var company = companies.childNodes[companyIndex];
			var entityName = company.childNodes[0].childNodes[0].nodeValue;
			var addressLine1 = '';
			if (company.childNodes[1].childNodes[0].childNodes.length > 0) 
				addressLine1 = company.childNodes[1].childNodes[0].childNodes[0].nodeValue;
			var indx = '' + (entityName.replace(/ /g,"")).replace(/'/g,"") + ((addressLine1.replace(/ /g,"")).replace(/\./g,"")).replace(/-/g,"") + '';
			html += '<div class="entity">';
			html += '<div class="entityname">' + entityName + '</div>';
			html += '<div class="entityaddress">';
			var address = company.childNodes[1];
			var line = false;
			if (address.childNodes[0].childNodes.length > 0 || address.childNodes[1].childNodes.length > 0) {
				if (line)
					html += ' | ';
				if (address.childNodes[0].childNodes.length > 0)
					html += address.childNodes[0].childNodes[0].nodeValue;
				if (address.childNodes[1].childNodes.length > 0) {
					if (address.childNodes[0].childNodes.length > 0)
						html += ' ';
					html += address.childNodes[1].childNodes[0].nodeValue;
				}
				line = true;
			}
			if (address.childNodes[2].childNodes.length > 0 || address.childNodes[3].childNodes.length > 0 || address.childNodes[4].childNodes.length > 0) {
				if (line)
					html += ' | ';
				if (address.childNodes[2].childNodes.length > 0)
					html += address.childNodes[2].childNodes[0].nodeValue;
				if (address.childNodes[3].childNodes.length > 0) {
					if (address.childNodes[2].childNodes.length > 0)
						html += ', ';
					html += address.childNodes[3].childNodes[0].nodeValue;
				}
				if (address.childNodes[4].childNodes.length > 0) {
					if (address.childNodes[2].childNodes.length > 0 || address.childNodes[3].childNodes.length > 0)
						html += ' ';
					html += address.childNodes[4].childNodes[0].nodeValue;
				}
				line = true;
			}
			if (company.childNodes[2].childNodes.length > 0) {
				if (line)
					html += ' | ';
				html += company.childNodes[2].childNodes[0].nodeValue;
				line = true;
			}
			if (company.childNodes[3].childNodes.length > 0) {
				if (line)
					html += ' | ';
				html += '<a href="http://' + company.childNodes[3].childNodes[0].nodeValue + '" target="_blank">' + company.childNodes[3].childNodes[0].nodeValue + '</a>';
				line = true;
			}
			html += '</div>';
			
			if (company.childNodes.length > 6) {
				html += '<div class="txtnetsublinks">';
				var unsubAllLink = false;
				var subAllLink = false;
				for (var nodeIndex = 5; nodeIndex < company.childNodes.length; nodeIndex++) {
					var node = company.childNodes[nodeIndex];
					if (node.childNodes[2].childNodes[0].nodeValue == 1 || node.childNodes[3].childNodes[0].nodeValue == 1 || (company.childNodes[4].childNodes[0].nodeValue == 1 && node.childNodes[4].childNodes[0].nodeValue == 1) || (company.childNodes[4].childNodes[0].nodeValue == 1 && node.childNodes[5].childNodes[0].nodeValue == 1))
						unsubAllLink = true;
					else if (node.childNodes[2].childNodes[0].nodeValue == 0 || node.childNodes[3].childNodes[0].nodeValue == 0 || (company.childNodes[4].childNodes[0].nodeValue == 1 && node.childNodes[4].childNodes[0].nodeValue == 0) || (company.childNodes[4].childNodes[0].nodeValue == 1 && node.childNodes[5].childNodes[0].nodeValue == 0))
						subAllLink = true;
				}
				if (subAllLink) 
					html += '<a href="javascript:subscribeAll(\'' + stripSpecial(indx) + '\')">Subscribe to all</a>';
				if (unsubAllLink) {
					if (subAllLink) 
						html += ' | ';
					html += '<a href="javascript:unsubscribeAll(\'' + stripSpecial(indx) + '\')">Unsubscribe all</a>';
				}	
				html += '<div id="showsublink' + stripSpecial(indx) + '" class="hidesublink"><a href="javascript:groupsShow(\'' + stripSpecial(indx) +'\')">';
				if (expandedCompanies[indx] == undefined || expandedCompanies[indx] == 'no')
					html += 'show subscription groups';
				else
					html += 'hide subscription groups';
				html += '</a></div>';
				html += '</div>';
				html += '<div id="subgroups' + stripSpecial(indx) + '" class="subgroupsgroup"';

				if (expandedCompanies[indx] == undefined || expandedCompanies[indx] == 'no')
					html +=  'style="display:none;"';
				html += '>';
			}
			else {
				html += '<div id="subgroups' + companyIndex + categoryIndex + '" class="subgroupsgroup">';
			}
			var unsubAllText = "<b>" + entityName + ":</b><br>";
			var subAllText = "<b>" + entityName + ":</b><br>";
			for (var nodeIndex = 5; nodeIndex < company.childNodes.length; nodeIndex++) {
				var node = company.childNodes[nodeIndex];
				html += '<div class="txtnetdivision">';
				if (node.childNodes[2].childNodes[0].nodeValue == 1 || node.childNodes[3].childNodes[0].nodeValue == 1 || node.childNodes[4].childNodes[0].nodeValue == 1 || node.childNodes[5].childNodes[0].nodeValue == 1) {
				//	html += '<div class="subicon"></div>';
					unsubAllText += node.childNodes[1].childNodes[0].nodeValue + "<br>";
				}
				else if (node.childNodes[2].childNodes[0].nodeValue == 0 || node.childNodes[3].childNodes[0].nodeValue == 0 || (company.childNodes[4].childNodes[0].nodeValue == 1 && node.childNodes[4].childNodes[0].nodeValue == 0) || (company.childNodes[5].childNodes[0].nodeValue == 1 && node.childNodes[4].childNodes[0].nodeValue == 0)) {
				//	html += '<div class="unsubicon"></div>';
					subAllText += node.childNodes[1].childNodes[0].nodeValue + "<br>";
				}
				if (node.childNodes[1].childNodes[0].nodeValue != company.childNodes[0].childNodes[0].nodeValue || company.childNodes.length > 5) {
					html += '<div class="divisionname">';
					html += node.childNodes[1].childNodes[0].nodeValue;
					html += '</div>';
				}
				html += '<div id="' + stripSpecial(indx) + 'subGroup' + nodeIndex + '" style="display:none;">' + node.childNodes[0].childNodes[0].nodeValue + '</div>';
				html += '<span class="subunsublinks">';
				if (node.childNodes[2].childNodes[0].nodeValue == 1) 
					html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'2\')" title="Text Message to Cell Phone"><img src="./images/texttocell_green.gif" border=0 /></a>';
				else
					html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'2\')" title="Text Message to Cell Phone"><img src="./images/texttocell_red.gif" border=0 /></a>';
				html += '&nbsp;&nbsp;';
				if (node.childNodes[3].childNodes[0].nodeValue == 1) 
					html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'4\')" title="Email"><img src="./images/texttocomp_green.gif" border=0 /></a>';
				else
					html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'4\')" title="Email"><img src="./images/texttocomp_red.gif" border=0 /></a>';
				if (company.childNodes[4].childNodes[0].nodeValue == 1) {
					html += '&nbsp;&nbsp;';
					if (node.childNodes[4].childNodes[0].nodeValue == 1) 
						html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'3\')" title="Voice Message to Cell Phone"><img src="./images/voicetocell_green.gif" border=0 /></a>';
					else
						html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'3\')" title="Voice Message to Cell Phone"><img src="./images/voicetocell_red.gif" border=0 /></a>';
					html += '&nbsp;&nbsp;';
					if (node.childNodes[5].childNodes[0].nodeValue == 1) 
						html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'1\')"  title="Voice Message to Landline"><img src="./images/voicetoland_green.gif" border=0 /></a>';
					else
						html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'1\')" title="Voice Message to Landline"><img src="./images/voicetoland_red.gif" border=0 /></a>';
				
				}
				html += '</span>';
				html += '</div>';
			}
			html += '<div id=\'' + stripSpecial(indx) + 'unsubAllText\'  style="display:none;">' + unsubAllText + "</div>";
			html += '<div id=\'' + stripSpecial(indx) + 'subAllText\'  style="display:none;">' + subAllText + "</div>";
			html += '</div>';
			html += '</div>';
		}
		return html;
}

function showCompanyDetails(companyId) {
		xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	subscriptionPage = 0;
	var url="/ajax/loadCompanyDetails.php";
	url=url+"?sid="+Math.random();
	url += "&companyId=" + companyId;
	document.getElementById("chosenTxtNetCompany").value = companyId;
	if (document.getElementById("subscriptionsValidStates").value.length > 0)
		url=url+"&state="+urlEncode(document.getElementById("subscriptionsValidStates").value);
	if (document.getElementById("subscriptionsValidCities").value.length > 0)
		url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
	showProcessing();
	xmlHttp.onreadystatechange=showCompanyDetailsComplete; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function showIndividualDetails(id) {
	if (document.getElementById('individualDetails' + id).style.display == "") {
		document.getElementById('individualDetails' + id).style.display = "none";
		document.getElementById('nodeInfo' + id + 'plus').style.display = "";
		document.getElementById('nodeInfo' + id + 'minus').style.display = "none";
	}
	else {
		document.getElementById('individualDetails' + id).style.display = "";
		document.getElementById('nodeInfo' + id + 'plus').style.display = "none";
		document.getElementById('nodeInfo' + id + 'minus').style.display = "";
	}
}

function showCompanyDetailsComplete() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		xmlDoc=xmlHttp.responseXML;
		closeProcessing();
		if (xmlDoc.getElementsByTagName("txtNetLoadStatus")[0].childNodes[0].nodeValue == 0) {
			document.getElementById("modalmessagebox").style.display = "none";
			modalAlert (xmlDoc.getElementsByTagName("txtNetStatusMessage")[0].childNodes[0].nodeValue, 'Subscription Load Problem');
			return;
		}
		else if (document.getElementById("txtNetDetails").style.display == "none"){
			document.getElementById("txtNetDetailsCompanyLogo").innerHTML = '<img src="images/companyIcons/' + xmlDoc.getElementsByTagName("companyIcon")[0].childNodes[0].nodeValue + '" border="0" alt="' + xmlDoc.getElementsByTagName("masterCompanyName")[0].childNodes[0].nodeValue + '"/>';
			if (xmlDoc.getElementsByTagName("company").length == 1) {
				var company = xmlDoc.getElementsByTagName("company")[0];
				var entityName = company.childNodes[0].childNodes[0].nodeValue;
				document.getElementById("txtNetDetailsCompanyName").innerHTML = '<div class="largeboldblue">' + company.childNodes[0].childNodes[0].nodeValue  + '</div>';	
				if (company.childNodes[1].childNodes[0].childNodes.length > 0) 
					addressLine1 = company.childNodes[1].childNodes[0].childNodes[0].nodeValue;
				var indx = '' + (entityName.replace(/ /g,"")).replace(/'/g,"") + ((addressLine1.replace(/ /g,"")).replace(/\./g,"")).replace(/-/g,"") + '';
				var html = '<br><div class="entityaddress">';
				var address = company.childNodes[1];
				var line = false;
				if (address.childNodes[0].childNodes.length > 0 || address.childNodes[1].childNodes.length > 0) {
					if (line)
						html += ' | ';
					if (address.childNodes[0].childNodes.length > 0)
						html += address.childNodes[0].childNodes[0].nodeValue;
					if (address.childNodes[1].childNodes.length > 0) {
						if (address.childNodes[0].childNodes.length > 0)
							html += ' ';
						html += address.childNodes[1].childNodes[0].nodeValue;
					}
					line = true;
				}
				if (address.childNodes[2].childNodes.length > 0 || address.childNodes[3].childNodes.length > 0 || address.childNodes[4].childNodes.length > 0) {
					if (line)
						html += ' | ';
					if (address.childNodes[2].childNodes.length > 0)
						html += address.childNodes[2].childNodes[0].nodeValue;
					if (address.childNodes[3].childNodes.length > 0) {
						if (address.childNodes[2].childNodes.length > 0)
							html += ', ';
						html += address.childNodes[3].childNodes[0].nodeValue;
					}
					if (address.childNodes[4].childNodes.length > 0) {
						if (address.childNodes[2].childNodes.length > 0 || address.childNodes[3].childNodes.length > 0)
							html += ' ';
						html += address.childNodes[4].childNodes[0].nodeValue;
					}
					line = true;
				}
				if (company.childNodes[2].childNodes.length > 0) {
					if (line)
						html += ' <br> ';
					html += company.childNodes[2].childNodes[0].nodeValue;
					line = true;
				}
				if (company.childNodes[3].childNodes.length > 0) {
					if (line)
						html += ' | ';
					html += '<a href="http://' + company.childNodes[3].childNodes[0].nodeValue + '" target="_blank">' + company.childNodes[3].childNodes[0].nodeValue + '</a>';
					line = true;
				}
				html += '</div>';
				document.getElementById("txtNetDetailsCompanyName").innerHTML += html;
				html = '';
				for (var nodeIndex = 5; nodeIndex < company.childNodes.length; nodeIndex++) {
					var node = company.childNodes[nodeIndex];
					html += '<div class="txtnetdivision">';
					//if (node.childNodes[2].childNodes[0].nodeValue == 1 || node.childNodes[3].childNodes[0].nodeValue == 1 || node.childNodes[4].childNodes[0].nodeValue == 1 || node.childNodes[5].childNodes[0].nodeValue == 1) {
					//	html += '<div class="subicon"></div>';
					//	unsubAllText += node.childNodes[1].childNodes[0].nodeValue + "<br>";
					//}
					//else if (node.childNodes[2].childNodes[0].nodeValue == 0 || node.childNodes[3].childNodes[0].nodeValue == 0 || (company.childNodes[4].childNodes[0].nodeValue == 1 && node.childNodes[4].childNodes[0].nodeValue == 0) || (company.childNodes[5].childNodes[0].nodeValue == 1 && node.childNodes[4].childNodes[0].nodeValue == 0)) {
					//	html += '<div class="unsubicon"></div>';
					//	subAllText += node.childNodes[1].childNodes[0].nodeValue + "<br>";
					//}
					if (node.childNodes[1].childNodes[0].nodeValue != company.childNodes[0].childNodes[0].nodeValue || company.childNodes.length > 5) {
						html += '<div class="divisionname">';
						html += node.childNodes[1].childNodes[0].nodeValue;
						html += '</div>';
					}
					html += '<div id="' + stripSpecial(indx) + 'subGroup' + nodeIndex + '" style="display:none;">' + node.childNodes[0].childNodes[0].nodeValue + '</div>';
					html += '<span class="subunsublinks" id="nodeButtons' + node.childNodes[0].childNodes[0].nodeValue + '">';
					if (node.childNodes[2].childNodes[0].nodeValue == 1) 
						html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'2\')" title="Text Message to Cell Phone"><img src="./images/texttocell_green.gif" border=0 /></a>';
					else
						html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'2\')" title="Text Message to Cell Phone"><img src="./images/texttocell_red.gif" border=0 /></a>';
					html += '&nbsp;&nbsp;';
					if (node.childNodes[3].childNodes[0].nodeValue == 1) 
						html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'4\')" title="Email"><img src="./images/texttocomp_green.gif" border=0 /></a>';
					else
						html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'4\')" title="Email"><img src="./images/texttocomp_red.gif" border=0 /></a>';
					if (company.childNodes[4].childNodes[0].nodeValue == 1) {
						html += '&nbsp;&nbsp;';
						if (node.childNodes[4].childNodes[0].nodeValue == 1) 
							html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'3\')" title="Voice Message to Cell Phone"><img src="./images/voicetocell_green.gif" border=0 /></a>';
						else
							html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'3\')" title="Voice Message to Cell Phone"><img src="./images/voicetocell_red.gif" border=0 /></a>';
						html += '&nbsp;&nbsp;';
						if (node.childNodes[5].childNodes[0].nodeValue == 1) 
							html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'1\')"  title="Voice Message to Landline"><img src="./images/voicetoland_green.gif" border=0 /></a>';
						else
							html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'1\')" title="Voice Message to Landline"><img src="./images/voicetoland_red.gif" border=0 /></a>';
					
					}
					if (node.childNodes[6].childNodes.length  > 0) {
						html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript: showMessages(\'' + nodeIndex + '\');"><span id="messageHistoryLink'+ nodeIndex +'">Show Message History</span></a>';
					}
					if (node.childNodes[7].childNodes.length  > 0) {
						html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript: showAutoReplies(\'' + nodeIndex + '\');"><span id="autoReplyLink'+ nodeIndex +'">Show Auto Replies</span></a>';
					}	
					if (node.childNodes[6].childNodes.length  > 0) {	
						html += "<div id='" + nodeIndex + "messages' class='messageContent' style='display:none;'>";
						for (var messageIndex=0; messageIndex<node.childNodes[6].childNodes.length;messageIndex++) {
							html += "<div class='messageContentDate'>" + node.childNodes[6].childNodes[messageIndex].childNodes[0].nodeValue + "</div>";
							messageIndex++;
							html += "<div class='messageContentText'>" + node.childNodes[6].childNodes[messageIndex].childNodes[0].nodeValue + "</div>";
						}
						html += "</div>";
					}
					if (node.childNodes[7].childNodes.length  > 0) {	
						html += "<div id='" + nodeIndex + "autoReplies' class='messageContent' style='display:none;'>";
						for (var messageIndex=0; messageIndex<node.childNodes[7].childNodes.length;messageIndex++) {
							html += "<div class='messageContentDate'>" + node.childNodes[7].childNodes[messageIndex].childNodes[0].nodeValue;
							messageIndex++;
							html += " - " + node.childNodes[7].childNodes[messageIndex].childNodes[0].nodeValue;
							html += "</div>";
							messageIndex++;
							html += "<div class='messageContentText'>" + node.childNodes[7].childNodes[messageIndex].childNodes[0].nodeValue + "</div>";
						}
						html += "</div>";
					}
					html += '</span>';
					html += '</div>';
				}
				document.getElementById("txtNetIndividualDetails").innerHTML = html;
			}
			else {
				document.getElementById("txtNetDetailsCompanyName").innerHTML = '<div class="largeboldblue">' + xmlDoc.getElementsByTagName("masterCompanyName")[0].childNodes[0].nodeValue  + '</div>';
				html = '';
				for (var companyIndex=0; companyIndex<xmlDoc.getElementsByTagName("company").length; companyIndex++) {
					if (companyIndex > 0)
						html += '<div class="greylinespace"></div>';
					var company = xmlDoc.getElementsByTagName("company")[companyIndex];
					var entityName = company.childNodes[0].childNodes[0].nodeValue;
					var addressLine1 = '';
					if (company.childNodes[1].childNodes[0].childNodes.length > 0) 
						addressLine1 = company.childNodes[1].childNodes[0].childNodes[0].nodeValue;
					var indx = '' + (entityName.replace(/ /g,"")).replace(/'/g,"") + ((addressLine1.replace(/ /g,"")).replace(/\./g,"")).replace(/-/g,"") + '';
					html += '<a href="javascript: showIndividualDetails(\''+ companyIndex + '\')" >';
					html += '<img id="nodeInfo' + companyIndex + 'plus" src="../images/tw-greensquare-plus.gif" border="0" >';
					html += '<img id="nodeInfo' + companyIndex + 'minus" src="../images/tw-greensquare-minus.gif" style="display:none;" border="0" >';
					html += '</a>&nbsp;<div class="entityname">' + entityName + '</div>';
					html += '<br><div class="entityaddress">';
					var address = company.childNodes[1];
					var line = false;
					if (address.childNodes[0].childNodes.length > 0 || address.childNodes[1].childNodes.length > 0) {
						if (line)
							html += ' | ';
						if (address.childNodes[0].childNodes.length > 0)
							html += address.childNodes[0].childNodes[0].nodeValue;
						if (address.childNodes[1].childNodes.length > 0) {
							if (address.childNodes[0].childNodes.length > 0)
								html += ' ';
							html += address.childNodes[1].childNodes[0].nodeValue;
						}
						line = true;
					}
					if (address.childNodes[2].childNodes.length > 0 || address.childNodes[3].childNodes.length > 0 || address.childNodes[4].childNodes.length > 0) {
						if (line)
							html += ' | ';
						if (address.childNodes[2].childNodes.length > 0)
							html += address.childNodes[2].childNodes[0].nodeValue;
						if (address.childNodes[3].childNodes.length > 0) {
							if (address.childNodes[2].childNodes.length > 0)
								html += ', ';
							html += address.childNodes[3].childNodes[0].nodeValue;
						}
						if (address.childNodes[4].childNodes.length > 0) {
							if (address.childNodes[2].childNodes.length > 0 || address.childNodes[3].childNodes.length > 0)
								html += ' ';
							html += address.childNodes[4].childNodes[0].nodeValue;
						}
						line = true;
					}
					if (company.childNodes[2].childNodes.length > 0) {
						if (line)
							html += ' <br> ';
						html += company.childNodes[2].childNodes[0].nodeValue;
						line = true;
					}
					if (company.childNodes[3].childNodes.length > 0) {
						if (line)
							html += ' | ';
						html += '<a href="http://' + company.childNodes[3].childNodes[0].nodeValue + '" target="_blank">' + company.childNodes[3].childNodes[0].nodeValue + '</a>';
						line = true;
					}
					html += '</div>';
					html += '<div id="individualDetails' + companyIndex + '"  style="display:none;">';
					for (var nodeIndex = 5; nodeIndex < company.childNodes.length; nodeIndex++) {
					var node = company.childNodes[nodeIndex];
					html += '<div class="txtnetdivision" >';
					//if (node.childNodes[2].childNodes[0].nodeValue == 1 || node.childNodes[3].childNodes[0].nodeValue == 1 || node.childNodes[4].childNodes[0].nodeValue == 1 || node.childNodes[5].childNodes[0].nodeValue == 1) {
					//	html += '<div class="subicon"></div>';
					//	unsubAllText += node.childNodes[1].childNodes[0].nodeValue + "<br>";
					//}
					//else if (node.childNodes[2].childNodes[0].nodeValue == 0 || node.childNodes[3].childNodes[0].nodeValue == 0 || (company.childNodes[4].childNodes[0].nodeValue == 1 && node.childNodes[4].childNodes[0].nodeValue == 0) || (company.childNodes[5].childNodes[0].nodeValue == 1 && node.childNodes[4].childNodes[0].nodeValue == 0)) {
					//	html += '<div class="unsubicon"></div>';
					//	subAllText += node.childNodes[1].childNodes[0].nodeValue + "<br>";
					//}
					if (node.childNodes[1].childNodes[0].nodeValue != company.childNodes[0].childNodes[0].nodeValue || company.childNodes.length > 5) {
						html += '<div class="divisionname">';
						html += node.childNodes[1].childNodes[0].nodeValue;
						html += '</div>';
					}
					html += '<div id="' + stripSpecial(indx) + 'subGroup' + nodeIndex + '" style="display:none;">' + node.childNodes[0].childNodes[0].nodeValue + '</div>';
					html += '<span class="subunsublinks" id="nodeButtons' + node.childNodes[0].childNodes[0].nodeValue + '">';
					if (node.childNodes[2].childNodes[0].nodeValue == 1) 
						html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'2\')" title="Text Message to Cell Phone"><img src="./images/texttocell_green.gif" border=0 /></a>';
					else
						html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'2\')" title="Text Message to Cell Phone"><img src="./images/texttocell_red.gif" border=0 /></a>';
					html += '&nbsp;&nbsp;';
					if (node.childNodes[3].childNodes[0].nodeValue == 1) 
						html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'4\')" title="Email"><img src="./images/texttocomp_green.gif" border=0 /></a>';
					else
						html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'4\')" title="Email"><img src="./images/texttocomp_red.gif" border=0 /></a>';
					if (company.childNodes[4].childNodes[0].nodeValue == 1) {
						html += '&nbsp;&nbsp;';
						if (node.childNodes[4].childNodes[0].nodeValue == 1) 
							html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'3\')" title="Voice Message to Cell Phone"><img src="./images/voicetocell_green.gif" border=0 /></a>';
						else
							html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'3\')" title="Voice Message to Cell Phone"><img src="./images/voicetocell_red.gif" border=0 /></a>';
						html += '&nbsp;&nbsp;';
						if (node.childNodes[5].childNodes[0].nodeValue == 1) 
							html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'1\')"  title="Voice Message to Landline"><img src="./images/voicetoland_green.gif" border=0 /></a>';
						else
							html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'1\')" title="Voice Message to Landline"><img src="./images/voicetoland_red.gif" border=0 /></a>';
					
					}
					if (node.childNodes[6].childNodes.length  > 0) {
						html += '&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript: showMessages(\'' + nodeIndex + '\');"><span id="messageHistoryLink'+ nodeIndex +'">Show Message History</span></a>';
					}
					if (node.childNodes[7].childNodes.length  > 0) {
						html += '&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript: showAutoReplies(\'' + nodeIndex + '\');"><span id="autoReplyLink'+ nodeIndex +'">Show Auto Replies</span></a>';
					}	
					if (node.childNodes[6].childNodes.length  > 0) {	
						html += "<div id='" + nodeIndex + "messages' class='messageContent' style='display:none;'>";
						for (var messageIndex=0; messageIndex<node.childNodes[6].childNodes.length;messageIndex++) {
							html += "<div class='messageContentDate'>" + node.childNodes[6].childNodes[messageIndex].childNodes[0].nodeValue + "</div>";
							messageIndex++;
							html += "<div class='messageContentText'>" + node.childNodes[6].childNodes[messageIndex].childNodes[0].nodeValue + "</div>";
						}
						html += "</div>";
					}
					if (node.childNodes[7].childNodes.length  > 0) {	
						html += "<div id='" + nodeIndex + "autoReplies' class='messageContent' style='display:none;'>";
						for (var messageIndex=0; messageIndex<node.childNodes[7].childNodes.length;messageIndex++) {
							html += "<div class='messageContentDate'>" + node.childNodes[7].childNodes[messageIndex].childNodes[0].nodeValue;
							messageIndex++;
							html += " - " + node.childNodes[7].childNodes[messageIndex].childNodes[0].nodeValue;
							html += "</div>";
							messageIndex++;
							html += "<div class='messageContentText'>" + node.childNodes[7].childNodes[messageIndex].childNodes[0].nodeValue + "</div>";
						}
						html += "</div>";
					}
					html += '</span>';
					html += '</div>';
				}
					html += '</div>';
				}
				document.getElementById("txtNetIndividualDetails").innerHTML = html;
			}
			document.getElementById("txtNetDetails").style.display = "";
			document.getElementById("txtNetStateCitySelection").style.display = "none";
			document.getElementById("blackout").style.display = "";
		}
		else {
		for (var companyIndex=0; companyIndex<xmlDoc.getElementsByTagName("company").length; companyIndex++) {
			var company = xmlDoc.getElementsByTagName("company")[companyIndex];
			for (var nodeIndex = 5; nodeIndex < company.childNodes.length; nodeIndex++) {
				var node = company.childNodes[nodeIndex];
				html = '';
				if (node.childNodes[2].childNodes[0].nodeValue == 1) 
					html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'2\')" title="Text Message to Cell Phone"><img src="./images/texttocell_green.gif" border=0 /></a>';
				else
					html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'2\')" title="Text Message to Cell Phone"><img src="./images/texttocell_red.gif" border=0 /></a>';
				html += '&nbsp;&nbsp;';
				if (node.childNodes[3].childNodes[0].nodeValue == 1) 
					html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'4\')" title="Email"><img src="./images/texttocomp_green.gif" border=0 /></a>';
				else
					html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'4\')" title="Email"><img src="./images/texttocomp_red.gif" border=0 /></a>';
				if (company.childNodes[4].childNodes[0].nodeValue == 1) {
					html += '&nbsp;&nbsp;';
					if (node.childNodes[4].childNodes[0].nodeValue == 1) 
						html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'3\')" title="Voice Message to Cell Phone"><img src="./images/voicetocell_green.gif" border=0 /></a>';
					else
						html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'3\')" title="Voice Message to Cell Phone"><img src="./images/voicetocell_red.gif" border=0 /></a>';
					html += '&nbsp;&nbsp;';
					if (node.childNodes[5].childNodes[0].nodeValue == 1) 
						html += '<a href="javascript:unsubscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'1\')"  title="Voice Message to Landline"><img src="./images/voicetoland_green.gif" border=0 /></a>';
					else
						html += '<a href="javascript:subscribeSingle(\'' + stripSpecial(node.childNodes[0].childNodes[0].nodeValue) + '\', \'1\')" title="Voice Message to Landline"><img src="./images/voicetoland_red.gif" border=0 /></a>';
				
				}
				if (node.childNodes[6].childNodes.length  > 0) {
					html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript: showMessages(\'' + nodeIndex + '\');"><span id="messageHistoryLink'+ nodeIndex +'">Show Message History</span></a>';
				}
				if (node.childNodes[7].childNodes.length  > 0) {
					html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript: showAutoReplies(\'' + nodeIndex + '\');"><span id="autoReplyLink'+ nodeIndex +'">Show Auto Replies</span></a>';
				}	
				if (node.childNodes[6].childNodes.length  > 0) {	
					html += "<div id='" + nodeIndex + "messages' class='messageContent' style='display:none;'>";
					for (var messageIndex=0; messageIndex<node.childNodes[6].childNodes.length;messageIndex++) {
						html += "<div class='messageContentDate'>" + node.childNodes[6].childNodes[messageIndex].childNodes[0].nodeValue + "</div>";
						messageIndex++;
						html += "<div class='messageContentText'>" + node.childNodes[6].childNodes[messageIndex].childNodes[0].nodeValue + "</div>";
					}
					html += "</div>";
				}
				if (node.childNodes[7].childNodes.length  > 0) {	
					html += "<div id='" + nodeIndex + "autoReplies' class='messageContent' style='display:none;'>";
					for (var messageIndex=0; messageIndex<node.childNodes[7].childNodes.length;messageIndex++) {
						html += "<div class='messageContentDate'>" + node.childNodes[7].childNodes[messageIndex].childNodes[0].nodeValue;
						messageIndex++;
						html += " - " + node.childNodes[7].childNodes[messageIndex].childNodes[0].nodeValue;
						html += "</div>";
						messageIndex++;
						html += "<div class='messageContentText'>" + node.childNodes[7].childNodes[messageIndex].childNodes[0].nodeValue + "</div>";
					}
					html += "</div>";
				}
				document.getElementById('nodeButtons' + node.childNodes[0].childNodes[0].nodeValue).innerHTML = html;
			}
			}
		}
	}
}

function showAutoReplies(nodeIndex) {
	if (document.getElementById(nodeIndex + "autoReplies").style.display == "") {
		document.getElementById(nodeIndex + "autoReplies").style.display = "none";
		document.getElementById("autoReplyLink" + nodeIndex).innerHTML = "Show Auto Replies";
	}
	else {
		document.getElementById(nodeIndex + "autoReplies").style.display = "";
		document.getElementById("autoReplyLink" + nodeIndex).innerHTML = "Hide Auto Replies";
	}
}

function showMessages(nodeIndex) {
	if (document.getElementById(nodeIndex + "messages").style.display == "") {
		document.getElementById(nodeIndex + "messages").style.display = "none";
		document.getElementById("messageHistoryLink" + nodeIndex).innerHTML = "Show Message History";
	}
	else {
		document.getElementById(nodeIndex + "messages").style.display = "";
		document.getElementById("messageHistoryLink" + nodeIndex).innerHTML = "Hide Message History";
	}
}

function closeTxtNetDetails() {
	document.getElementById("txtNetDetails").style.display = "none";
	
			document.getElementById("txtNetStateCitySelection").style.display = "";
	document.getElementById("blackout").style.display = "none";
}

function drawNewTxtNetCompanies(categories, categoryIndex) {
	companies = categories[categoryIndex];
	var html = '<table><tr>';
	var column = 0;
	for (var companyIndex=1; companyIndex<companies.childNodes.length; companyIndex++) {
		var company = companies.childNodes[companyIndex];
		if (company.childNodes[1].childNodes[0] != null) {
			html += '<td align="center" class="txtnetcompanyname"><a href="javascript:showCompanyDetails(\'' + company.childNodes[2].childNodes[0].nodeValue + '\')"><img src="images/companyIcons/' + company.childNodes[1].childNodes[0].nodeValue + '" border="0" alt="' + company.childNodes[0].childNodes[0].nodeValue + '"/><br>' + company.childNodes[0].childNodes[0].nodeValue + '</a></td>';
			column++;
			if (column == 3) {
				html += '</tr><tr>';
				column = 0;
			}	
		}
	}
	while (column < 3){
		html += "<td>&nbsp;</td>";
		column++;
	}
	html += '</tr></table>';
	return html;
}

function unsubscribeSingle(nodeId, type) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/ajax/loadTxtNetCompanies.php";
	url=url+"?sid="+Math.random();
	if (subscriptionPage == 1)
		url=url+"&subscriptionPage=1";
	else {
		if (document.getElementById("subscriptionsValidStates").value.length > 0)
			url=url+"&state="+urlEncode(document.getElementById("subscriptionsValidStates").value);
		if (document.getElementById("subscriptionsValidCities").value.length > 0)
			url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
//		if (document.getElementById("subscriptionsValidCompanyTypes").value.length > 0)
//			url=url+"&compType="+urlEncode(document.getElementById("subscriptionsValidCompanyTypes").value);
		
				url=url+"&companyId="+urlEncode(document.getElementById("chosenTxtNetCompany").value);
	}
	url=url+"&unsubnode1=" + nodeId;
	url=url+"&type=" + type;
	showProcessing();
	if (subscriptionPage == 1)
		xmlHttp.onreadystatechange=loadSubscriptionsComplete; 
	else
		xmlHttp.onreadystatechange=showCompanyDetailsComplete; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function subscribeSingle(nodeId, type) {
    if (document.getElementById("loggedinheaderlinks").style.display == "none") {
    	document.getElementById("blackout").style.display = "";
		document.getElementById("modalmessagebox").style.display = "";
		document.getElementById("modalmessagemain").innerHTML = "<b>Before subscribing to promotions or alerts, you must be signed in.</b>  If you don't have an account, creating one is easy and free.  To create an account click <a href=\"javascript:show(\'profile\')\">here</a>";
		document.getElementById("modalmessagesub").style.display = "";
		document.getElementById("modalmessagesub").innerHTML = "<table><tr><td><b>Email or Phone:</b></td><td><input name='modalUsername' id='modalUsername' type='text' TABINDEX=3 size='14' class='logininput' onkeypress=\"javascript:enterPressed(event, 'txtNetArea');\"></td></tr><tr><td><b>Password:</b></td><td><input name='modalPassword' id='modalPassword' type='password' size='14' TABINDEX=4 class='logininput' onkeypress=\"javascript:enterPressed(event, 'txtNetArea');\"></td></tr></table>";
		document.getElementById("modalmessageboxok").innerHTML = '<a href="javascript:doModalLogin(\'txtNetArea\');">Sign in ></a>';
		document.getElementById("modalmessageboxcancel").style.display = "";
		document.getElementById("modalUsername").focus();
    }
    else {
    	if (type == 4 && document.getElementById("regemail").value.length == 0) {
    		document.getElementById("blackout").style.display = "";
			document.getElementById("modalmessagebox").style.display = "";
			document.getElementById("modalmessagemain").innerHTML = "<b>No email address.</b>  If you would like to subscribe to this company's email alerts, please enter your email address.";
			document.getElementById("modalmessagesub").style.display = "";
			document.getElementById("modalmessagesub").innerHTML = "<b>Email Address:</b><input name='subscriptionEmailEnter' id='subscriptionEmailEnter' type='text' >";
			document.getElementById("modalmessageboxok").innerHTML = '<a href="javascript:saveEmailAndSubscribe(\'' + nodeId + '\', \'' + type + '\');">Save ></a>';
			document.getElementById("modalmessageboxcancel").style.display = "";
			document.getElementById("subscriptionEmailEnter").focus();
    	}
    	else if ((type == 2 || type == 3) && document.getElementById("regmobileNumber").value.length == 0) {
    		document.getElementById("blackout").style.display = "";
			document.getElementById("modalmessagebox").style.display = "";
			document.getElementById("modalmessagemain").innerHTML = "<b>No cellular phone number.</b>  If you would like to subscribe to this company's cell-phone alerts, please enter your cell-phone number.";
			document.getElementById("modalmessagesub").style.display = "";
			document.getElementById("modalmessagesub").innerHTML = "<b>Cell-Phone:</b><input name='subscriptionCellPhoneEnter' id='subscriptionCellPhoneEnter' type='text' >";
			document.getElementById("modalmessageboxok").innerHTML = '<a href="javascript:saveCellPhoneAndSubscribe(\'' + nodeId + '\', \'' + type + '\');">Save ></a>';
			document.getElementById("modalmessageboxcancel").style.display = "";
			document.getElementById("subscriptionCellPhoneEnter").focus();
    	}
    	else if (type == 1  && document.getElementById("reglandLineNumber").value.length == 0) {
    		document.getElementById("blackout").style.display = "";
			document.getElementById("modalmessagebox").style.display = "";
			document.getElementById("modalmessagemain").innerHTML = "<b>No land-line phone number.</b>  If you would like to subscribe to this company's land-line phone alerts, please enter your land-line phone number.";
			document.getElementById("modalmessagesub").style.display = "";
			document.getElementById("modalmessagesub").innerHTML = "<b>Land-Line:</b><input name='subscriptionLandLinePhoneEnter' id='subscriptionLandLinePhoneEnter' type='text' >";
			document.getElementById("modalmessageboxok").innerHTML = '<a href="javascript:saveLandLineAndSubscribe(\'' + nodeId + '\', \'' + type + '\');">Save ></a>';
			document.getElementById("modalmessageboxcancel").style.display = "";
			document.getElementById("subscriptionLandLinePhoneEnter").focus();
    	}
    	else {
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null) {
				alert ("Browser does not support HTTP Request");
				return;
			}
			var url="/ajax/loadTxtNetCompanies.php";
			url=url+"?sid="+Math.random();
			if (subscriptionPage == 1)
				url=url+"&subscriptionPage=1";
			else {
				if (document.getElementById("subscriptionsValidStates").value.length > 0)
					url=url+"&state="+urlEncode(document.getElementById("subscriptionsValidStates").value);
				if (document.getElementById("subscriptionsValidCities").value.length > 0)
					url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
				url=url+"&companyId="+urlEncode(document.getElementById("chosenTxtNetCompany").value);
				
//				if (document.getElementById("subscriptionsValidCompanyTypes").value.length > 0)
//					url=url+"&compType="+urlEncode(document.getElementById("subscriptionsValidCompanyTypes").value);
			}
			url=url+"&subnode1=" + nodeId;
			url=url+"&type=" + type;
			showProcessing();
			if (subscriptionPage == 1)
				xmlHttp.onreadystatechange=loadSubscriptionsComplete; 
			else 
				xmlHttp.onreadystatechange=showCompanyDetailsComplete; 
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}
}

function saveEmailAndSubscribe(nodeId, type) {
	if (document.getElementById("subscriptionEmailEnter").value.length == 0) 
		document.getElementById("modalmessagemain").innerHTML = "<b>No email address.</b>  If you would like to subscribe to this company's email alerts, please enter your email address.<br>PLEASE ENTER EMAIL ADDRESS!";
	else {
		if (!emailCheck(document.getElementById("subscriptionEmailEnter").value)) {
			document.getElementById("modalmessagemain").innerHTML = "<b>No email address.</b>  If you would like to subscribe to this company's email alerts, please enter your email address.<br>EMAIL IS NOT VALID!";
			return;
		}
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="/ajax/loadTxtNetCompanies.php";
		url=url+"?sid="+Math.random();
		if (subscriptionPage == 1)
			url=url+"&subscriptionPage=1";
		else {
			if (document.getElementById("subscriptionsValidStates").value.length > 0)
				url=url+"&state="+urlEncode(document.getElementById("subscriptionsValidStates").value);
			if (document.getElementById("subscriptionsValidCities").value.length > 0)
				url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
//			if (document.getElementById("subscriptionsValidCompanyTypes").value.length > 0)
//				url=url+"&compType="+urlEncode(document.getElementById("subscriptionsValidCompanyTypes").value);
		}
		url=url+"&subnode1=" + nodeId;
		url=url+"&type=" + type;
		url=url+"&newEmail=" + urlEncode(document.getElementById("subscriptionEmailEnter").value);
		showProcessing();
		xmlHttp.onreadystatechange=loadSubscriptionsComplete; 
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}			
}

function saveCellPhoneAndSubscribe(nodeId, type) {
	if (document.getElementById("subscriptionCellPhoneEnter").value.length == 0) 
		document.getElementById("modalmessagemain").innerHTML = "<b>No cellular phone number.</b>  If you would like to subscribe to this company's cell-phone alerts, please enter your cell-phone number.<br>PLEASE ENTER CELL-PHONE NUMBER!";
	else {
		var phone = document.getElementById("subscriptionCellPhoneEnter").value;
		phone = phone.replace(/-/g,"");
		phone = phone.replace(/\./g,"");
		phone = phone.replace(/\(/g,"");
		phone = phone.replace(/\)/g,"");
		phone = phone.replace(/ /g,"");
		if (!isNumeric(phone) || phone.length != 10) {
			document.getElementById("modalmessagemain").innerHTML = "<b>No cellular phone number.</b>  If you would like to subscribe to this company's cell-phone alerts, please enter your cell-phone number.<br>PLEASE ENTER 10-DIGET CELL-PHONE NUMBER!";
			return;
		}
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="/ajax/loadTxtNetCompanies.php";
		url=url+"?sid="+Math.random();
		if (subscriptionPage == 1)
			url=url+"&subscriptionPage=1";
		else {
			if (document.getElementById("subscriptionsValidStates").value.length > 0)
				url=url+"&state="+urlEncode(document.getElementById("subscriptionsValidStates").value);
			if (document.getElementById("subscriptionsValidCities").value.length > 0)
				url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
//			if (document.getElementById("subscriptionsValidCompanyTypes").value.length > 0)
//				url=url+"&compType="+urlEncode(document.getElementById("subscriptionsValidCompanyTypes").value);
		}
		url=url+"&subnode1=" + nodeId;
		url=url+"&type=" + type;
		url=url+"&newCellPhone=" + urlEncode(document.getElementById("subscriptionCellPhoneEnter").value);
		showProcessing();
		xmlHttp.onreadystatechange=loadSubscriptionsComplete; 
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}	
}

function saveLandLineAndSubscribe(nodeId, type) {
	if (document.getElementById("subscriptionLandLinePhoneEnter").value.length == 0) 
		document.getElementById("modalmessagemain").innerHTML = "<b>No land-line phone number.</b>  If you would like to subscribe to this company's land-line phone alerts, please enter your land-line phone number.<br>PLEASE ENTER LAND-LINE PHONE NUMBER!";
	else {
		var phone = document.getElementById("subscriptionLandLinePhoneEnter").value;
		phone = phone.replace(/-/g,"");
		phone = phone.replace(/\./g,"");
		phone = phone.replace(/\(/g,"");
		phone = phone.replace(/\)/g,"");
		phone = phone.replace(/ /g,"");
		if (!isNumeric(phone) || phone.length != 10) {
			document.getElementById("modalmessagemain").innerHTML = "<b>No land-line phone number.</b>  If you would like to subscribe to this company's land-line phone alerts, please enter your land-line phone number.<br>PLEASE ENTER 10-DIGET LAND-LINE PHONE NUMBER!";
			return;
		}
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="/ajax/loadTxtNetCompanies.php";
		url=url+"?sid="+Math.random();
		if (subscriptionPage == 1)
			url=url+"&subscriptionPage=1";
		else {
			if (document.getElementById("subscriptionsValidStates").value.length > 0)
				url=url+"&state="+urlEncode(document.getElementById("subscriptionsValidStates").value);
			if (document.getElementById("subscriptionsValidCities").value.length > 0)
				url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
//			if (document.getElementById("subscriptionsValidCompanyTypes").value.length > 0)
//				url=url+"&compType="+urlEncode(document.getElementById("subscriptionsValidCompanyTypes").value);
		}
		url=url+"&subnode1=" + nodeId;
		url=url+"&type=" + type;
		url=url+"&newLandLinePhone=" + urlEncode(document.getElementById("subscriptionLandLinePhoneEnter").value);
		showProcessing();
		xmlHttp.onreadystatechange=loadSubscriptionsComplete; 
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}	
}

function unsubscribeAll(indx) {
	document.getElementById("blackout").style.display = "";
	document.getElementById("modalmessagebox").style.display = "";
	if (indx.length == 0) {
		document.getElementById("modalmessagemain").innerHTML = "Unsubscribe from all TxtWire alerts and promotions?  This cannot be undone.";
		document.getElementById("modalmessagesub").style.display = "none";
	}
	else {
		document.getElementById("modalmessagemain").innerHTML = "Unsubscribe from all the following alerts and promotions?  This cannot be undone.";
		document.getElementById("modalmessagesub").style.display = "";
		document.getElementById("modalmessagesub").innerHTML = document.getElementById(indx + "unsubAllText").innerHTML;
	}
	document.getElementById("modalmessageboxok").innerHTML = '<a href="javascript:unsubscribeAllFinish(\'' + stripSpecial(indx) + '\');">Unsubscribe All</a>';
	document.getElementById("modalmessageboxcancel").style.display = "";
}	
	
function unsubscribeAllFinish(indx) {
	document.getElementById("modalmessagebox").style.display = "none";
	document.getElementById("modalwaiting").style.display = "";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/ajax/loadTxtNetCompanies.php";
	url=url+"?sid="+Math.random();
	if (subscriptionPage == 1)
		url=url+"&subscriptionPage=1";
	else {
		if (document.getElementById("subscriptionsValidStates").value.length > 0)
			url=url+"&state="+urlEncode(document.getElementById("subscriptionsValidStates").value);
		if (document.getElementById("subscriptionsValidCities").value.length > 0)
			url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
//		if (document.getElementById("subscriptionsValidCompanyTypes").value.length > 0)
//			url=url+"&compType="+urlEncode(document.getElementById("subscriptionsValidCompanyTypes").value);
	}
	var divId = indx + 'subGroup';
	var idLength = divId.length;
	urlEnd = '';
	if (idLength > 8) {
		for (var i=0; i<document.getElementsByTagName('*').length; i++) {
			if (document.getElementsByTagName('*')[i].id.substring(0,idLength) == divId) {
				if (document.getElementsByTagName('*')[i].innerHTML != null)
					urlEnd=urlEnd+"&unsubnode"+i+"="+document.getElementsByTagName('*')[i].innerHTML;
			}
		}
	}
	else {
		for (var i=0; i<document.getElementsByTagName('*').length; i++) {
			if (document.getElementsByTagName('*')[i].id.indexOf(divId) > 0) {
				if (document.getElementsByTagName('*')[i].innerHTML != null)
					urlEnd=urlEnd+"&unsubnode"+i+"="+document.getElementsByTagName('*')[i].innerHTML;
			}
		}
	}
	url=url+urlEnd;
	xmlHttp.onreadystatechange=loadSubscriptionsComplete; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function subscribeAll(indx) {
	if (document.getElementById("loggedinheaderlinks").style.display == "none") {
    	document.getElementById("blackout").style.display = "";
		document.getElementById("modalmessagebox").style.display = "";
		document.getElementById("modalmessagemain").innerHTML = "<b>Before subscribing to promotions or alerts, you must be signed in.</b>  If you don't have an account, creating one is easy and free.  To create an account click <a href=\"javascript:show(\'profile\')\">here</a>";
		document.getElementById("modalmessagesub").style.display = "";
		document.getElementById("modalmessagesub").innerHTML = "<table><tr><td><b>Email or Phone:</b></td><td><input name='modalUsername' id='modalUsername' type='text' size='14' TABINDEX=3 class='logininput' onkeypress=\"javascript:enterPressed(event, 'txtNetArea');\"></td></tr><tr><td><b>Password:</b></td><td><input name='modalPassword' id='modalPassword' type='password' size='14' TABINDEX=4 class='logininput' onkeypress=\"javascript:enterPressed(event, 'txtNetArea');\"></td></tr></table>";
		document.getElementById("modalmessageboxok").innerHTML = '<a href="javascript:doModalLogin(\'txtNetArea\');">Sign in ></a>';
		document.getElementById("modalmessageboxcancel").style.display = "";
		document.getElementById("modalUsername").focus();
    }
    else {
		document.getElementById("blackout").style.display = "";
		document.getElementById("modalmessagebox").style.display = "";
		document.getElementById("modalmessagemain").innerHTML = "Subscribe to all the following alerts and promotions?";
		document.getElementById("modalmessagesub").style.display = "";
		document.getElementById("modalmessagesub").innerHTML = document.getElementById(stripSpecial(indx) + "subAllText").innerHTML;
		document.getElementById("modalmessageboxok").innerHTML = '<a href="javascript:subscribeAllFinish(\'' + stripSpecial(indx) + '\');">Subscribe to All</a>';
		document.getElementById("modalmessageboxcancel").style.display = "";
	}
}	

function subscribeAllFinish(indx) {
	document.getElementById("modalmessagebox").style.display = "none";
	document.getElementById("modalwaiting").style.display = "";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/ajax/loadTxtNetCompanies.php";
	url=url+"?sid="+Math.random();
	if (subscriptionPage == 1)
		url=url+"&subscriptionPage=1";
	else {
		if (document.getElementById("subscriptionsValidStates").value.length > 0)
			url=url+"&state="+urlEncode(document.getElementById("subscriptionsValidStates").value);
		if (document.getElementById("subscriptionsValidCities").value.length > 0)
			url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
//		if (document.getElementById("subscriptionsValidCompanyTypes").value.length > 0)
//			url=url+"&compType="+urlEncode(document.getElementById("subscriptionsValidCompanyTypes").value);
	}
	var divId = indx + 'subGroup';
	var idLength = divId.length;
	urlEnd = '';
	for (var i=0; i<document.getElementsByTagName('*').length; i++) {
		if (document.getElementsByTagName('*')[i].id.substring(0,idLength) == divId) {
			if (document.getElementsByTagName('*')[i].innerHTML != null)
				urlEnd=urlEnd+"&subnode"+i+"="+document.getElementsByTagName('*')[i].innerHTML;
		}
	}
	url=url+urlEnd;
	xmlHttp.onreadystatechange=loadSubscriptionsComplete; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadValidStates() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/ajax/loadValidStates.php";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=validStatesLoaded; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function validStatesLoaded() {
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		var selectBox = document.getElementById("subscriptionsValidStates");
    	selectBox.options.length=0;
		xmlDoc=xmlHttp.responseXML;
		selectBox.options[0] = new Option('--SELECT--','');
		var startingState = null;
		for (var i=0; i<xmlDoc.getElementsByTagName("state").length; i++) {
			selectBox.options[i+1] = new Option(xmlDoc.getElementsByTagName("stateName")[i].childNodes[0].nodeValue, xmlDoc.getElementsByTagName("state")[i].childNodes[0].nodeValue);
			if (xmlDoc.getElementsByTagName("selected")[i].childNodes[0].nodeValue == 1)
				startingState = xmlDoc.getElementsByTagName("state")[i].childNodes[0].nodeValue;
		}
		if (startingState != null) {
			document.getElementById("subscriptionsValidStates").value = startingState;
			loadValidCities();
		}
		else {
			loadValidCompanyTypes();
		}
	}
	
}

function loadValidCities() {

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/ajax/loadValidCities.php";
	url=url+"?state="+document.getElementById("subscriptionsValidStates").value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=validCitiesLoaded; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function validCitiesLoaded() {
	var selectBox = document.getElementById("subscriptionsValidCities");
    selectBox.options.length=0;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		xmlDoc=xmlHttp.responseXML;
		selectBox.options[0] = new Option('--SELECT--','');
		var startingCity = null;
		for (var i=0; i<xmlDoc.getElementsByTagName("city").length; i++) {
			selectBox.options[i+1] = new Option(xmlDoc.getElementsByTagName("city")[i].childNodes[0].nodeValue, xmlDoc.getElementsByTagName("city")[i].childNodes[0].nodeValue);
			if (xmlDoc.getElementsByTagName("selected")[i].childNodes[0].nodeValue == 1)
				startingCity = xmlDoc.getElementsByTagName("city")[i].childNodes[0].nodeValue;
		}
		if (selectBox.options.length == 2) {
			document.getElementById("subscriptionsValidCities").value = xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue;
		}
		else if (startingCity != null){
			document.getElementById("subscriptionsValidCities").value  = startingCity;
		}
		document.getElementById("subscriptionsValidCitiesText").style.display = "none";
		document.getElementById("subscriptionsValidCitiesSelect").style.display = "";
		loadValidCompanyTypes();
	}
}


function loadValidCompanyTypes() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/ajax/loadValidCompanyTypes.php";
	url=url+"?state="+document.getElementById("subscriptionsValidStates").value;
	url=url+"&city="+urlEncode(document.getElementById("subscriptionsValidCities").value);
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=validCompanyTypesLoaded; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function expandTxtNetMenu(typeId) {
	if (document.getElementById("compCatAreas" + typeId).style.display == "none") {
		document.getElementById("compCatAreas" + typeId).style.display = "";
		document.getElementById("compType" + typeId + "plus").style.display = "none";
		document.getElementById("compType" + typeId + "minus").style.display = "";
	}
	else {
		document.getElementById("compCatAreas" + typeId).style.display = "none";
		document.getElementById("compType" + typeId + "plus").style.display = "";
		document.getElementById("compType" + typeId + "minus").style.display = "none";
	}
}

function validCompanyTypesLoaded() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		xmlDoc=xmlHttp.responseXML;
		var htmlCode = '';
		for (var i=0; i<xmlDoc.getElementsByTagName("type").length; i++) {
			htmlCode += '<div class="txtnetcategory">&nbsp;&nbsp;';
			htmlCode += '<a href="javascript: expandTxtNetMenu(\''+ xmlDoc.getElementsByTagName("companyTypeId")[i].childNodes[0].nodeValue + '\')" >';
			htmlCode += '<img id="compType' + xmlDoc.getElementsByTagName("companyTypeId")[i].childNodes[0].nodeValue + 'plus" src="../images/tw-greensquare-plus.gif" border="0" >';
			htmlCode += '<img id="compType' + xmlDoc.getElementsByTagName("companyTypeId")[i].childNodes[0].nodeValue + 'minus" src="../images/tw-greensquare-minus.gif" border="0" style="display:none;">';
			htmlCode += '</a>&nbsp;';
			
			htmlCode += '<a href="javascript: loadTxtNetSubscriptions(\'' + xmlDoc.getElementsByTagName("companyTypeId")[i].childNodes[0].nodeValue + '\');">' + xmlDoc.getElementsByTagName("companyType")[i].childNodes[0].nodeValue + ' </a>(' + xmlDoc.getElementsByTagName("companyTypeCount")[i].childNodes[0].nodeValue + ')</div>';
			htmlCode += '<div id="compCatAreas' + xmlDoc.getElementsByTagName("companyTypeId")[i].childNodes[0].nodeValue + '" style="display:none" >';
			for (var ii=0; ii<xmlDoc.getElementsByTagName("companyCategories")[i].childNodes.length; ii++) {
				htmlCode += '<div class="txtnetsubcat"><a href="javascript: loadTxtNetSubscriptions(\'' + xmlDoc.getElementsByTagName("companyTypeId")[i].childNodes[0].nodeValue + '\', \'' + xmlDoc.getElementsByTagName("companyCategories")[i].childNodes[ii].childNodes[0].childNodes[0].nodeValue + '\');">' +  xmlDoc.getElementsByTagName("companyCategories")[i].childNodes[ii].childNodes[1].childNodes[0].nodeValue + '</a> (' + xmlDoc.getElementsByTagName("companyCategories")[i].childNodes[ii].childNodes[2].childNodes[0].nodeValue + ')</div>';
			}
			htmlCode += '</div>';
		}
		document.getElementById("txtNetCategoryList").innerHTML = htmlCode;
		loadTxtNetSubscriptions();
	}
}
