// JavaScript Document
//Global Vars
//Declare XMLHttpRequest object;
var xmlHttp;
//Declare IE vs. Everyone else CSS "class" attribute
var cssClass

/*Functions*/
function WindowOnload(f) {
	var prev=window.onload;
	window.onload=function(){ if(prev)prev(); f(); }
	//window.onload=function(){ if(prev)prev(); f; }
}

function newWin(url,w,h,scrollStatus) {
	window.open(url,"popup","toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=" +scrollStatus+ ", resizable=no, width=" +w+ ", height=" +h);	
}

function whichBrowser() {
	var theBrowser;
	if (window.ActiveXObject) {
		theBrowser = "IE";
	} 
	else if (window.XMLHttpRequest) {
		theBrowser = "Moz";
	}	
	return theBrowser;
}
function getNextSibling(startBrother){
  endBrother=startBrother.nextSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}

function displayFlash(myDiv, objSwf, myWidth, myHeight, name, varValue, myTrans, myLoop) {
	if (myTrans == null || myTrans == '') {
		myTrans = 'transparent';
	}
	if (myLoop == null || myLoop == '') {
		myLoop = 'false';
	}
	var swfText = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	swfText += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ';
	swfText += 'width="' + myWidth + '" height="' + myHeight + '" id="' + name + '" align="middle">';
	swfText += '<param name="allowScriptAccess" value="always" />';
	swfText += '<param name="movie" value="' + objSwf + '" />';
	swfText += '<param name="menu" value="false" />';
	swfText += '<param name="quality" value="high" />';
	swfText += '<param name="wmode" value="' + myTrans + '" />';
	swfText += '<param name="bgcolor" value="#000000" />';
	swfText += '<param name="loop" value="' + myLoop + '" />';
	swfText += '<param name="FlashVars" value="' + varValue + '">';
	swfText += '<embed src="' + objSwf + '" menu="false" quality="high" wmode="' + myTrans + '" bgcolor="#000000"';
	swfText += ' FlashVars="' + varValue + '"';
	swfText += ' loop="' + myLoop + '"';
	swfText += 'width="' + myWidth + '" height="' + myHeight + '" name="' + name + '" align="middle" ';
	swfText += 'allowScriptAccess="always" ';
	swfText += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	swfText += '</object>';	
	
	var swfDiv = document.getElementById(myDiv);
	swfDiv.innerHTML = swfText;
}

function showHideDiv(hiddenDiv, numRows) {
	//first hide any divs already showing except the one clicked
	var hiddenDivNum = hiddenDiv.slice(8,10);
	for (i=0; i<numRows; i++) {
		if (i != hiddenDivNum) {
			document.getElementById('listDiv_'+i).style.display = 'none';
		}
	}
	var activeDiv = document.getElementById(hiddenDiv);
	if (activeDiv.style.display == 'block') {
		activeDiv.style.display = 'none';
	} else {
		activeDiv.style.display = 'block';
	}
}
function hideDiv(hiddenDiv) {
	var activeDiv = document.getElementById(hiddenDiv);
	activeDiv.style.display = 'none';
}
function showDiv(hiddenDiv) {
	var activeDiv = document.getElementById(hiddenDiv);
	activeDiv.style.display = 'block';
}
//ADMIN STUFF
function showBorder(theDiv) {
	theDiv.style.border = '2px solid #333333';
}
function hideBorder(theDiv) {
	theDiv.style.border = 'none';
}
function editSection(theSection) {	
	window.location = 'adminTool.php?section='+theSection;
}
function editNews(theSection, theId) {	
	window.location = 'adminTool.php?section='+theSection+'&id='+theId;
}
function editMain(theSection, secType, selType) {	
	window.location = 'adminTool.php?section='+theSection+'&secType='+secType+'&selType='+selType;
}

//AJAX STUFF
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		cssClass = "className";
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
		cssClass = "class";
    }
}

function getProfile(thePerson) { 
	createXMLHttpRequest();
	var url = "js/getData.php?";
	var queryString = 'thePerson='+thePerson; 
  
	xmlHttp.open("POST", url, true);
	xmlHttp.onreadystatechange = callback;
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
	xmlHttp.send(queryString);
}

function callback() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {	
			parseResults();	
		}
	}
}

function parseResults() {
	var theResponse = xmlHttp.responseText;
	var contentDiv = document.getElementById('profile');
	var containerDiv = document.getElementById('profileContainer');
	
	contentDiv.innerHTML = '<div class="btnRight"><a href="javascript:void(0)" onclick="hideDiv(\'profileContainer\');">close</a></div><br /><br />'+theResponse;
	containerDiv.style.display = 'block';
}