/* 
  ------------------------------------
  PVII Menu CSS Express Drop-Down Menu
  by Project Seven Development
  www.projectseven.com
  ------------------------------------
*/
function P7_ExpMenu(){ //v1.1.0.2 by PVII-www.projectseven.com
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='p7menubar';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}


// Functions for showing and hiding elements
/*function showPopUp(tag)
{
	var el;
	el = document.getElementById(tag)
	el.style.display = 'block';
}
function hidePopUp(tag)
{
	var	el;
	el = document.getElementById(tag)
	el.style.display = 'none';
}*/

function OverTab(tabid)
{
	elLI = document.getElementById("nav-" + tabid);
	elA	= document.getElementById("link-" + tabid);
	elLI.style.backgroundPosition = "right -75px";
	elA.style.backgroundPosition = "left -75px";
	elA.style.color = "#A30F0F";
}

function RestoreTab(tabid)
{
	elLI = document.getElementById("nav-" + tabid);
	elA	= document.getElementById("link-" + tabid);
	elLI.style.backgroundPosition = "right top";
	elA.style.backgroundPosition = "left top";
	elA.style.color = "#FFFFFF";
}

function sandcInit() {
	var state = document.getElementById("state");
	var state_other = document.getElementById("state_other");
	var country = document.getElementById("country");
	var country_other = document.getElementById("country_other"); 
	if (state.value != "Other") {
		state_other.disabled = true;
	}
	if (country.value != "Other") {
		country_other.disabled = true;
	}
	state.onchange = function() {
		if (state.value == "Other") {
			state_other.disabled = false;
		} else {
			state_other.disabled = true;
		}
		return;
	};
	country.onchange = function() {
		if (country.value == "Other") {
			country_other.disabled = false;
		} else {
			country_other.disabled = true;
		}
		return;
	};
	return;
}

function violationInit() {
	var violation = document.getElementById("violation");
	var violation_other = document.getElementById("violation_other");
	if (violation.value != "Other") {
		violation_other.disabled = true;
	}
	violation.onchange = function() {
		if (violation.value == "Other") {
			violation_other.disabled = false;
		} else {
			violation_other.disabled = true;
		}
		return;
	};
	return;
}

function charMonitor() {
	var summary = document.getElementById("summary");
	charCntOutput();
	summary.onchange = charCntOutput;	
	summary.onkeydown = charCntOutput;	
	summary.onkeyup = charCntOutput;
	summary.onmousedown = charCntOutput;	
	summary.onmouseup = charCntOutput;
	summary.onblur = charCntOutput;
}

function charCntOutput () {
	var maxChars = Number(document.getElementById("maxChars").value);
	var output = document.getElementById("charCount");
	var summary = Number(document.getElementById("summary").value.length);
	if (summary <= maxChars) {
		var total = Number(maxChars - summary);
		var text = "<i>You have " + total + " Characters Remaining</i>";
	} else {
		var total = Number(summary - maxChars);
		var text = "<i style=\"color: red;\">You're " + total + " Characters Over</i>"
	}
	output.innerHTML = text;
}

function editRollOver () {
	var allDivs = document.getElementsByTagName('div');
	for (var i=0; i < allDivs.length; i++) {
		if (allDivs[i].className == "headline") {
			allDivs[i].onmouseover = function() {
				if (this.getElementsByTagName('span')) {
					var currEl = this.getElementsByTagName('span')[0];
					var leftPos = this.getElementsByTagName('a')[0].offsetWidth + 5;
					currEl.style.left = leftPos + "px";
					currEl.style.display = "block";
				}
			}
			allDivs[i].onmouseout = function() {
				if (this.getElementsByTagName('span')) {
					var currEl = this.getElementsByTagName('span')[0];
					currEl.style.display = "none";
				}
			}
		}
	}
}

//News AJAX
function getHTTPObject() {
	var xhr = false;
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xhr = false;
			}
		}
	}
	return xhr;
}

//NEWS AJAX
function changeCatId() {
	var data = "catid=" + document.getElementById('catid').value + "&iconid=" + document.getElementById('currIconId').value;
	sendIconData("newsicons.php", data);
	document.getElementById('catid').onchange = function() {
		var data = "catid=" + document.getElementById('catid').value + "&iconid=" + document.getElementById('currIconId').value;
		sendIconData("newsicons.php", data);
	};
}

function sendIconData(url, data) {
	var request = getHTTPObject();
	if (request) {
		request.onreadystatechange = function() {
			parseIconResponse(request);
		};
		request.open("POST", url, true);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		request.send(data);
		return true;
	} else {
		return false;
	}
}

function parseIconResponse(request) {
	if (request.readyState == 4) {
		if (request.status == 200 || request.status == 304) {
			var container = document.getElementById('icons');
			container.innerHTML = request.responseText;
		}
	}
}

//window.onload = initialize;

function initialize() {
	P7_ExpMenu();
	if (document.getElementById("state") && document.getElementById("country")) {
		sandcInit();
	}
	if (document.getElementById("violation")) {
		violationInit();
	}
	if (document.getElementById("loginuser")) {
		document.getElementById("loginuser").focus();
	}
	if (document.getElementById("summary") && document.getElementById("charCount")) {
		charMonitor();
	}
	if (document.getElementById("isNews")) {
		editRollOver();
	}
	if (document.getElementById("catid") && document.getElementById("icons")) {
		changeCatId();
	}
}