/* 
	BSG Online Games - http://www.bsgonlinegames.com/
	Copyright © 2005, BSG ONLINE GAMES
	
	The following javascript is copyrighted and you 
	DO NOT 	have permission to copy or alter it in 
	any way.
	
	v1.0.1
	Last Revised: December 08, 2005 
	--------------------------------------------------
	--	BSG Online Games: admin@bsgonlinegames.com  --
	--												--
	-- domain: .bsgonlinegames.com					--
	--------------------------------------------------
:	
*/

var bsgid_focus = false;
var bsgid_mouse = false;
var inside = false;
var hoverid = null, xml_loaded = new Array();
var xmlhttp = false;
var openedmenu = null;

/**/
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
}
/**/

function setOpacity(id, alpha) {

	id.style.opacity = (alpha / 100); 
    id.style.filter = "alpha(opacity=" + alpha + ")"; 		
		
}

function goUrl(url, anc, reldir) {
	
	if (reldir == null) { reldir = 'http://www.bsgonlinegames.com'; }
	reldir = reldir + '/';
	url = reldir + url;
	
	if (anc != null && anc != '') {
		url = url + '#' + anc;
	}
	
	if (window.open(url, '_parent')) {
	
		return false;
			
	} else {
	
		return true;
		
	}
	
}

function goExternalUrl(url) {
	
	window.open(url, '_parent');
	
	return false;
	
}

function openWindow(url) {
	
	window.open(url);
	
	return false;
	
}

/* */

function In(id) {

	if (hoverid == id) {
		
		inside = true;
		
	} else {
	
		if (hoverid != null) {
			hoverid.className = 'product';
		}
		
		inside = true;
		id.className = 'product_hover product';
		
	}
		
}

function Out(id) {
	
	inside = false;
	hoverid = id;
	
	setTimeout('OutDelayed()', 5);
	
}

function OutDelayed() {
	if (inside == false && hoverid != null) {
		hoverid.className = 'product'; 
		hoverid = null;
	}
}

function doShow(id) {
	return document.getElementById(id).style.visibility = 'visible';
}

function doHide(id) {
	return document.getElementById(id).style.visibility = 'hidden';
}

/* */
function menu_open(idname, visible) {
	
	if (openedmenu != idname) {
	
		openedmenu = idname;
		
		if (visible == 1) {
		
			id = getId('menu_' + idname);
						
			id.className = 'submenu submenu_hover';
			id.style.zIndex = 3;
			
			idimg = getId('menuhover_' + idname);
			idimg.style.zIndex = 3;
			
		}
		
	}
	
}

function menu_close(idname) {

	openedmenu = null;
	menu_out = true;
	
	setTimeout('menu_delay(\'' + idname + '\')', 10);
	
}

function menu_delay(idname) {
	
	if (openedmenu != idname || openedmenu == null) {
		
		id = getId('menu_' + idname);
		id.className = 'submenu';
		id.style.zIndex = 2;
		
		idimg = getId('menuhover_' + idname);
		idimg.style.zIndex = 1;
		
	}
	
}

/* */
function closePopup() {
	id = getId('popup_container');
	
	setOpacity('content', 100);
	setTimeout('fadeOut(\'popup_container\', 99, 25)', 200);
	
	return false;
}

function openAlert(header, content) {
	
	id_header = getId('popup_header');
	id_content = getId('popup_content');
	
	id_header.innerHTML = header;
	
	if (content != null) {
		id_content.innerHTML = content;
	}
	
	moveCenter('popup_container');
	
	setVisible('popup_container');
	
}

function moveCenter(idname) {
	id = getId(idname);
	
	var m_width = id.offsetWidth;
	var m_height = id.offsetHeight;
	
	if ( typeof (window.innerWidth) == 'number' ) {
		var m_screenx = window.innerWidth;
		var m_screeny = window.innerHeight;
	} else {
		var m_screenx = document.body.offsetWidth;
		var m_screeny = document.body.offsetHeight;
	}
	
	if (m_screenx < m_width) {
		id.style.left = '0px';
	} else {
		id.style.left = parseInt(m_screenx / 2 - (m_width / 2)) + 'px';
	}
	if (m_screeny < m_height) {
		id.style.top = '0px';
	} else {
		id.style.top = parseInt(m_screeny / 2 - (m_height / 2)) + 'px';
	}
	
}

function openXML(idname, open_action, idno) {
	id = getId(idname);
	
	if (xmlhttp == null) {
		return true;
	} else {
	
		if (xml_loaded[idname] != open_action + ':' + idno) {
			
			var url = 'manage.php?t=openXML&a=' + escape(open_action);
			if (idno != null) {
				url = url + '&id=' + escape(idno);
			}
			
			id.innerHTML = 'Loading...';	
			xmlhttp.open('GET', url);
		    xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					buffer =  xmlhttp.responseText;
					xml_loaded[idname] = open_action + ':' + idno;
					id.innerHTML = buffer;
				}
			}
			xmlhttp.send(null);	
			
		}
		
		return false;
		
	}
}

function openXML_Alert(desc, open_action, idno) {
	id_header = getId('popup_header');
	
	if (xmlhttp == null) {
		alert('null');
		return true;
	} else {
	
		if (xml_loaded['popup_content'] != (open_action + ':' + idno)) {
			
			moveCenter('popup_container');
			
			id_header.innerHTML = desc;	
			xmlhttp.open('GET', 'manage.php?t=openXML&a=' + escape(open_action) + '&id=' + escape(idno));
		    xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					id_content = getId('popup_content');
					
					buffer =  xmlhttp.responseText;
					xml_loaded['popup_content'] = (open_action + ':' + idno);
					id_content.innerHTML = buffer;
					
					moveCenter('popup_container');
					
					setVisible('popup_container');
					
				}
			}
			xmlhttp.send(null);	
			
		} else {
			setVisible('popup_container');
		}
		
		return false;
	}
	
}

/* */
function fadeOut(idname, alpha, speed) {
	
	id = getId(idname);
	
	alpha = alpha - speed;
	if (alpha < 0) {
		alpha = 0;
		id.style.visibility='hidden';
	} else {
		setOpacity(idname, alpha);
		setTimeout('fadeOut("' + idname + '", ' + alpha + ', ' + speed + ')', 50);
	}
}

function setOpacity(idname, alpha) {
	id = getId(idname);
	
	id.style.opacity = (alpha / 100); 
	id.style.MozOpacity = (alpha / 100); 
    id.style.KhtmlOpacity = (alpha / 100); 
    id.style.filter = "alpha(opacity=" + alpha + ")"; 		
}

function setVisible(idname) {
	getId(idname).style.visibility='visible';
	setOpacity(idname, 100);
}

function getId(idname) {
	return document.getElementById(idname);
}
