// JavaScript Document
function showCity() {
	document.getElementById('city_selection').style.display = 'inline';
}

function hideCity() {
	document.getElementById('city_selection').style.display = 'none';
}

function hideDiv(div) {
	document.getElementById(div).style.display = 'none';
}

function showDiv(div) {
	var target = document.getElementById(div).style;
	if(target.display == 'inline') target.display = 'none';
	else target.display = 'inline';
}

function checkInput() {
	if(document.getElementById('countyList').value == 'XX') {
		document.getElementById('selectLoc').style.background = '#FF0000';
	}
	else {
		document.data.submit();
	}
}

function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
}

function copyVals(source) {
	var target = source + "F";
	document.getElementById(target).innerHTML = document.data[source].value;
}

function showCounty() {
	var county = document.getElementById('countyList').value;
	document.getElementById('county').innerHTML = county;
}

function noBookmark() {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*180);

	document.cookie = "bookmark=NO;expires=" + expire.toGMTString();
	document.getElementById('bookmark1').style.display = 'none';
}

var xmlhttp=false;

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}

@else
	xmlhttp = false;
@end @*/

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
}



function doThatThing2() {
	if (xmlhttp) {
	xmlhttp.open("GET", "/keeptrack.php?q=gb", true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var nothing = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null)
	}
	noBookmark();
	return true;
}

function doThatThing() {
	if (xmlhttp) {
	xmlhttp.open("GET", "/keeptrack.php?q=fv", true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var nothing = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null)
	}
	var url = "http://www.telephonenumber.com";
	var title = "TelephoneNumber.com - Directory Listings, Reverse Lookup and more";
	if(window.sidebar){ // Firefox
          window.sidebar.addPanel(title, url,'');
    }else if(window.opera){ //Opera
          var a = document.createElement("A");
          a.rel = "sidebar";
          a.target = "_search";
          a.title = title;
          a.href = url;
          a.click();
    } else if(document.all){ //IE
          window.external.AddFavorite(url, title);
    }
	noBookmark();
}

function listCounties() {
	if (xmlhttp) {
	var state = document.getElementById('advertState').value;
	var sURL = "/listCounty.php?state=" + state;
	xmlhttp.open("GET", sURL, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.getElementById('advertCounty').innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null)
	}
}

function listCounties2() {
	if (xmlhttp) {
	var state = document.getElementById('advertState').value;
	var sURL = "/listCounty2.php?state=" + state;
	xmlhttp.open("GET", sURL, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.getElementById('advertCounty').innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null)
	}
}

function toCheckout() {
	var flag = "NO";
	if(document.getElementById('keyword1').value != '') {
		if(document.getElementById('ch1').value != 'GOOD') {
			window.alert("Please Verify Your keywords before proceeding...");
			flag = "YES";
			return false;
		}
	}
	if(document.getElementById('keyword2').value != '') {
		if(document.getElementById('ch2').value != 'GOOD') {
			window.alert("Please Verify Your keywords before proceeding...");
			flag = "YES";
			return false;
		}
	}
	if(document.getElementById('keyword3').value != '') {
		if(document.getElementById('ch3').value != 'GOOD') {
			window.alert("Please Verify Your keywords before proceeding...");
			flag = "YES";
			return false;
		}
	}

    if(flag == "NO") document.getElementById('data').submit();
}

function checkAvailability(val) {
	if (xmlhttp) {
		var keyword = document.getElementById('keyword' + val).value;
		var word = escape(keyword);
		var sURL = "/checkAvailability.php?county=<?php echo $countyID; ?>&keyword=" + word;
		xmlhttp.open("GET", sURL, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var response = xmlhttp.responseText;
				if(response == "X") {
					document.getElementById('keyword' + val).value = "";
					alert('Keyword -- ' + keyword + ' -- is already taken for this county...');
					document.getElementById('mark' + val).style.display = 'none';
				}
				else {
					document.getElementById('mark' + val).style.display = 'inline';
					document.getElementById('ch' + val).value = 'GOOD';
				}
			}
		}
		xmlhttp.send(null)
	}
}

function showUpload() {
	document.getElementById('uploadLink').style.display = 'none';
	document.getElementById('uploadField').style.display = 'inline';
}

function closeRef() {
	document.getElementById('referafriend').style.display = 'none';
}

function setLocation() {
	if(document.getElementById('locaddr').value.length < 2) {
		alert("Please type in your address");
		return false;
	}
	if(document.getElementById('loccity').value.length < 2) {
		alert("Please type in your City");
		return false;
	}
	if(document.getElementById('locstate').value.length < 2) {
		alert("Please select your State");
		return false;
	}
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*180);
	var location = document.getElementById('locaddr').value + ":" + document.getElementById('loccity').value + ":" + document.getElementById('locstate').value;

	document.cookie = "tnlocation=" + escape(location) + ";expires=" + expire.toGMTString();
	window.location.reload();
}

function personalize(dir) {
	if(dir == "x") {
		document.getElementById('loc').style.display = 'none';
		document.getElementById('mapContainer').style.display = 'inline';
	}
	else {
		document.getElementById('mapContainer').style.display = 'none';
		document.getElementById('loc').style.display = 'inline';
	}
}

function lightImage(image) {
	if(document.getElementById("self")) {
		var page = document.getElementById("self").value;
		if(image != page) {
			document.getElementById(page + "i").style.opacity = '1.0';
			document.getElementById(page + "i").style.filter = 'alpha(opacity=100)';
			document.getElementById(page + "t").style.color = '#043C75';
		}
	}
}

function darkImage(image) {
	if(document.getElementById("self")) {
		var page = document.getElementById("self").value;
		if(image != page) {
			document.getElementById(page + "i").style.opacity = '0.4';
			document.getElementById(page + "i").style.filter = 'alpha(opacity=40)';
			document.getElementById(page + "t").style.color = '#869EB6';
		}
	}
}

function setupPageMap() {
	var page = document.getElementById("self").value;
	document.getElementById(page + "i").style.opacity = '1.0';
	document.getElementById(page + "i").style.filter = 'alpha(opacity=100)';
	document.getElementById(page + "t").style.color = '#043C75';
	loadMap();
}

function setupPage() {
	var page = document.getElementById("self").value;
	document.getElementById(page + "i").style.opacity = '1.0';
	document.getElementById(page + "i").style.filter = 'alpha(opacity=100)';
	document.getElementById(page + "t").style.color = '#043C75';
}