// JavaScript Document

/********************************
** DROP DOWN MENU ITEM CONTROL **
********************************/
function findPosX(obj)  {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
        	if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}
				
function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function dropDown(button, mode, drop_down, tag) {
	var menu = document.getElementById(drop_down);
	if(mode == "expand") {
		menu.style.top = findPosY(button) + 15 + "px";
		menu.style.left = findPosX(button) - 10 + "px";
		menu.style.visibility="visible";
	} else {
		menu.style.visibility="hidden";
	}
	document.onclick = function (e) {
		if (!e) var e = window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if(targ.id != tag) {
			dropDown("", "close", drop_down, tag);
		}
	}
}

/*************************
** MENU REFRESH CONTROL **
*************************/
function menuRefresh(menu) {
	switch(menu) {
		case 'right':
			parent.rightmenu.location.href = "rightmenu.php";
		break;
		case 'left':
			parent.leftmenu.location.href = "leftmenu.php";
		break;
		case 'both':
			parent.rightmenu.location.href = "rightmenu.php";
			parent.leftmenu.location.href = "leftmenu.php";
		break;
	}
}


/***************************
** POPUP BOX FOR LOCATION **
***************************/
function showBox(city, jump) {
	if(city != "unknown") {
	var objBody = document.getElementsByTagName("body").item(0);
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','city_box_overlay');
	objOverlay.style.display = 'block';
	objOverlay.style.position = 'absolute';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '300px';
	objOverlay.style.height = '200px';
	objOverlay.style.background = 'url(../../images/city_box.png) no-repeat center';
	objBody.insertBefore(objOverlay, objBody.firstChild);

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	objOverlay.style.left = (((arrayPageSize[0] - 300) / 2) + 'px');
	objOverlay.style.top = (((arrayPageSize[1] - 200) / 2) + 'px');
	
	var objBox = document.createElement("div");
	objBox.setAttribute('id','city_box_content');
	objBox.style.marginTop = '50px';
	objBox.style.padding = '5px 5px 5px 5px';
	objOverlay.insertBefore(objBox, objOverlay.firstChild);
	
	var objContent = document.getElementById("city_box_content");
	objContent.innerHTML = "<center>It looks like you are in<br><b>"+ city +"</b><br>would you like to go there now?<br><br><button onclick='javascript:cityJump(\""+ jump +"\");'>yes</button>&nbsp;<button onclick='javascript:hidebox();'>no</button>&nbsp;<button onclick='javascript:showNoBox();'>where2nite?</button>";
	} else {
	var objBody = document.getElementsByTagName("body").item(0);
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','city_box_overlay');
	objOverlay.style.display = 'block';
	objOverlay.style.position = 'absolute';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '300px';
	objOverlay.style.height = '200px';
	objOverlay.style.background = 'url(../../images/city_box.png) no-repeat center';
	objBody.insertBefore(objOverlay, objBody.firstChild);

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	objOverlay.style.left = (((arrayPageSize[0] - 300) / 2) + 'px');
	objOverlay.style.top = (((arrayPageSize[1] - 200) / 2) + 'px');
	
	var objBox = document.createElement("div");
	objBox.setAttribute('id','city_box_content');
	objBox.style.marginTop = '50px';
	objBox.style.padding = '5px 5px 5px 5px';
	objOverlay.insertBefore(objBox, objOverlay.firstChild);
	
	var objContent = document.getElementById("city_box_content");
	objContent.innerHTML = "<center>On2nite is going everywhere!<br>To open up in your area<br>let us know<br><br><form action='newarea.php' method='post'><input onclick='javascript:if(this.value==\"enter the new area\"){this.value=\"\"}' type='text' name='new_area' value='enter the new area'><br><br><input type='submit' value='go'></form></center>";
	}
}

function showThanksBox() {
	var objBody = document.getElementsByTagName("body").item(0);
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','city_box_overlay');
	objOverlay.style.display = 'block';
	objOverlay.style.position = 'absolute';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '300px';
	objOverlay.style.height = '200px';
	objOverlay.style.background = 'url(../../images/city_box.png) no-repeat center';
	objBody.insertBefore(objOverlay, objBody.firstChild);

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	objOverlay.style.left = (((arrayPageSize[0] - 300) / 2) + 'px');
	objOverlay.style.top = (((arrayPageSize[1] - 200) / 2) + 'px');
	
	var objBox = document.createElement("div");
	objBox.setAttribute('id','city_box_content');
	objBox.style.marginTop = '50px';
	objBox.style.padding = '5px 5px 5px 5px';
	objOverlay.insertBefore(objBox, objOverlay.firstChild);
	
	var objContent = document.getElementById("city_box_content");
	objContent.innerHTML = "<center><br><br>Thanks for the request<br><button onclick='javascript:hidebox();'>ok</button></center>";
}

function showNoBox() {
	var objContent = document.getElementById("city_box_content");
	objContent.style.marginTop = '70px';
	objContent.innerHTML = "<br><center>"+ parent.header.document.getElementById("where2nite").innerHTML +"<br></center>";
}

function hidebox() {
	var objOverlay = document.getElementById("city_box_overlay");
	objOverlay.style.display = 'none';
}

function cityJump(location) {
	if (location != "none") {
		//ref = window.location.href.split(".com");
		window.open("http://www.on2nite.com/"+location, "_parent");
	}
}

//
// hideLightbox()
//
function hideLightbox()
{
	// get objects
	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox');

	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	
	// disable keypress listener
	document.onkeypress = '';
}

//
// getPageSize()
// Returns array with page width, height and window width, height
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
