var isLoadingContent=false;
var loadedContent='';
var loadedTitle='';
var menusopennames=new Array();
var menusopendepths=new Array();
var menutimerid=0;
var popupwindowobject=null;
function addAddressLine() {
	var countfield=document.getElementById('addresslinecount');
	var addbutton=document.getElementById('addaddresslinebutton');
	if ((countfield!=null) && (addbutton!=null)) {
		var newvalue=(parseInt(countfield.value)+1).toString();
		addbutton.outerHTML='<input class="text" type="text" name="BusinessAddressLine'+newvalue+'" size="30" style="width:300px;" maxlength="100" value=""><br />'+addbutton.outerHTML;
		countfield.value=newvalue;
		return true;
	}
	return false;
}
function addDeveloperLine() {
	var countfield=document.getElementById('developercount');
	var addbutton=document.getElementById('adddevelopersbutton');
	if ((countfield!=null) && (addbutton!=null)) {
		var newvalue=(parseInt(countfield.value)+1).toString();
		addbutton.outerHTML='<input class="text" type="text" name="DeveloperName'+newvalue+'" size="30" style="width:300px;" maxlength="100" value=""><br />'+addbutton.outerHTML;
		countfield.value=newvalue;
		return true;
	}
	return false;
}
function addSoftwarePackageLine() {
	var countfield=document.getElementById('softwarecount');
	var addbutton=document.getElementById('addsoftwarebutton');
	var softwarelist=document.getElementById('softwarelist');
	if ((countfield!=null) && (addbutton!=null) && (softwarelist!=null)) {
		var newvalue=(parseInt(countfield.value)+1).toString();
		var addhtml=softwarelist.outerHTML;
		addhtml=addhtml.replace(/\s+[Ii][Dd]\s*=\s*([\"\'])?softwarelist([\"\'])?/gi, '');
		addhtml=addhtml.replace(/SoftwarePackage1/gi, 'SoftwarePackage'+newvalue);
		addbutton.outerHTML=addhtml+'<br />'+addbutton.outerHTML;
		countfield.value=newvalue;
		return true;
	}
	return false;
}
function clearMenuTimeout() {
	if (menutimerid!=0) {
		clearTimeout(menutimerid);
		menutimerid=0;
	}
	return true;
}
function clickMenu(obj, uri) {
	clearMenuTimeout();
	loadContent(uri);
	closeMenus(0);
	return true;
}
function closeMenus(depth) {
	var newnames=new Array();
	var newdepths=new Array();
	for(var i=0;i<menusopennames.length;i++) {
		if (menusopendepths[i]>=depth) {
			document.getElementById(menusopennames[i]).style.visibility='hidden';
		}
		else {
			newnames.push(menusopennames[i]);
			newdepths.push(menusopendepths[i]);
		}
	}
	menusopennames=newnames;
	menusopendepths=newdepths;
	return true;
}
function displayContent() {
	if (isLoadingContent) setTimeout('displayContent();', 50);
	else {
		if (document.title!=loadedTitle) document.title=loadedTitle;
		document.getElementById('content').innerHTML=loadedContent;
		fadeIn(0.0);
	}
	return true;
}
function fadeIn(opacity) {
	setOpacity(document.getElementById('content'), opacity);
	if (opacity<1.0) setTimeout('fadeIn('+(opacity+0.125).toString()+');', 50);
	return true;
}
function fadeOut(opacity) {
	setOpacity(document.getElementById('content'), opacity);
	if (opacity>0.0) setTimeout('fadeOut('+(opacity-0.125).toString()+');', 50);
	else setTimeout('displayContent();', 150);
	return true;
}
function loadContent(uri) {
	if (!isLoadingContent) {
		isLoadingContent=true;
		var xmlhttp=null;
		if (window.XMLHttpRequest) {
			xmlhttp=new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		}
		if (typeof(xmlhttp)=='object') {
			fadeOut(1.0);
			try {
				xmlhttp.onreadystatechange=function () {loadContentReady(xmlhttp, uri)};
				xmlhttp.open('GET', uri, true);
				xmlhttp.send(null);
				return true;
			}
			catch(e) {
				//ignore error
			}
		}
		document.location.href=uri;
		return true;
	}
	return false;
}
function loadContentReady(xmlhttp, uri) {
	if (xmlhttp.readyState==4) {
		var response=(xmlhttp.responseText==null) ? '' : xmlhttp.responseText.replace(/\n/g, ' ');
		if ((xmlhttp.status==200) || ((xmlhttp.status==0) && (response.length>0))) {
			var matchContent=response.match(/\<div id="content"\>.*\<\/div\>/gi);
			var matchTitle=response.match(/\<title\>.*?\<\/title\>/gi);
			if ((matchContent!=null) && (matchTitle!=null)) {
				if ((matchContent.length>0) && (matchTitle.length>0)) {
					loadedContent=matchContent[0].replace(/\<(?:div id="content"|\/div)\>/gi, '');
					loadedTitle=matchTitle[0].replace(/\<(?:\/)?title\>/gi, '');
					isLoadingContent=false;
				}
				else document.location.href=uri;
			}
			else document.location.href=uri;
			return true;
		}
		else if ((xmlhttp.status==0) || (xmlhttp.status==2) || (xmlhttp.status==404) || (xmlhttp.status==410)) loadedContent='Resource not found: \''+uri+'\'';
		else if ((xmlhttp.status==400) || (xmlhttp.status==405) || (xmlhttp.status==406) || (xmlhttp.status==412) || (xmlhttp.status==414) || (xmlhttp.status==415)) loadedContent='Invalid resource request: \''+uri+'\'';
		else if ((xmlhttp.status==401) || (xmlhttp.status==403) || (xmlhttp.status==407)) loadedContent='Access denied: \''+uri+'\'';
		else if (xmlhttp.status>=500) loadedContent='Resource unavailable: \''+uri+'\'';
		else loadedContent='HTTP error '+xmlhttp.status.toString()+': \''+uri+'\'';
		loadedTitle='Notequalsoft';
		isLoadingContent=false;
	}
	return false;
}
function outMenu(obj, color) {
	clearMenuTimeout();
	if (color.length>0) obj.style.backgroundColor=color;
	obj.style.fontWeight='normal';
	menutimerid=setTimeout('closeMenus(0);', 100);
	return true;
}
function overMenu(obj, color, depth) {
	clearMenuTimeout();
	closeMenus(depth);
	if (color.length>0) obj.style.backgroundColor=color;
	obj.style.fontWeight='bold';
	switch (obj.id) {
		case 'about':
			document.getElementById('about_submenu').style.visibility='visible';
			menusopennames.push('about_submenu');
			menusopendepths.push(depth);
			break;
		case 'games':
			document.getElementById('games_submenu').style.visibility='visible';
			menusopennames.push('games_submenu');
			menusopendepths.push(depth);
			break;
		case 'productivity':
			document.getElementById('productivity_submenu').style.visibility='visible';
			menusopennames.push('productivity_submenu');
			menusopendepths.push(depth);
			break;
		case 'web':
			document.getElementById('web_submenu').style.visibility='visible';
			menusopennames.push('web_submenu');
			menusopendepths.push(depth);
			break;
	}
	return true;
}
function popupWindow(title, url, width, height) {
	var left=50,top=50,windowWidth=0,windowHeight=0;
	if (typeof(screen.width)=='number') {
		windowWidth=screen.width;
		windowHeight=screen.height;
	}
	else if (typeof(window.innerWidth)=='number') {
		windowWidth=window.innerWidth;
		windowHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientWidth && document.body.clientHeight) {
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	if ((windowWidth>0) && (windowHeight>0)) {
		left=parseInt((windowWidth-width)/2);
		if (left<0) left=0;
		top=parseInt((windowHeight-height)/2);
		if (top<0) top=0;
	}
	if (popupwindowobject!=null) {
		popupwindowobject.close();
		popupwindowobject=null;
	}
	popupwindowobject=window.open(url,'window_'+title.replace(/\W+/g, '_').toLowerCase(),'left='+left.toString()+',top='+top.toString()+',screenX='+left.toString()+',screenY='+top.toString()+',width='+width.toString()+',height='+height.toString()+',resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
	if (popupwindowobject!=null) {
		if (window.focus) popupwindowobject.focus();
	}
	return false;
}
function renderMenu() {
	var menudiv=document.getElementById('menu');
	if (menudiv==null) setTimeout('renderMenu();', 100);
	else {
		var menuhtml='<div id="about" class="menuhot" onmouseover="return overMenu(this, \'#c2c2f4\', 1);" onmouseout="return outMenu(this, \'#cbcbcb\');" onclick="return clickMenu(this, \'/index.html\');">About</div>'
			+'<div id="games" class="menuhot" onmouseover="return overMenu(this, \'#c2c2f4\', 1);" onmouseout="return outMenu(this, \'#cbcbcb\');" onclick="return clickMenu(this, \'/games/index.html\');">Games</div>'
			+'<div id="productivity" class="menuhot" onmouseover="return overMenu(this, \'#c2c2f4\', 1);" onmouseout="return outMenu(this, \'#cbcbcb\');" onclick="return clickMenu(this, \'/productivity/index.html\');">Productivity</div>'
			+'<div id="web" class="menuhot" onmouseover="return overMenu(this, \'#c2c2f4\', 1);" onmouseout="return outMenu(this, \'#cbcbcb\');" onclick="return clickMenu(this, \'/web/index.html\');">Web</div>'
			+'<div id="about_submenu">'
				+'<div id="about_purchase" class="submenuhot" onmouseover="return overMenu(this, \'#d4d4ff\', 2);" onmouseout="return outMenu(this, \'#e4e4e4\');" onclick="return clickMenu(this, \'/purchase/index.html\');">Purchase</div>'
				+'<img class="submenucap" src="/capplus.gif" width="100" height="52" alt="" onmouseover="return overMenu(this, \'\', 2);" onmouseout="return outMenu(this, \'\');" />'
			+'</div>'
			+'<div id="games_submenu">'
				+'<div id="games_henjin" class="submenuhot" onmouseover="return overMenu(this, \'#d4d4ff\', 2);" onmouseout="return outMenu(this, \'#e4e4e4\');" onclick="return clickMenu(this, \'/games/henjin/index.html\');">Henjin</div>'
				+'<img class="submenucap" src="/capcircle.gif" width="100" height="52" alt="" onmouseover="return overMenu(this, \'\', 2);" onmouseout="return outMenu(this, \'\');" />'
			+'</div>'
			+'<div id="productivity_submenu">'
				+'<img class="submenucap" src="/capbar.gif" width="100" height="52" alt="" onmouseover="return overMenu(this, \'\', 2);" onmouseout="return outMenu(this, \'\');" />'
			+'</div>'
			+'<div id="web_submenu">'
				+'<div id="web_design" class="submenuhot" onmouseover="return overMenu(this, \'#d4d4ff\', 2);" onmouseout="return outMenu(this, \'#e4e4e4\');" onclick="return clickMenu(this, \'/web/design/index.html\');">Design</div>'
				+'<div id="web_services" class="submenuhot" onmouseover="return overMenu(this, \'#d4d4ff\', 2);" onmouseout="return outMenu(this, \'#e4e4e4\');" onclick="return clickMenu(this, \'/web/services/index.html\');">Services</div>'
				+'<img class="submenucap" src="/capx.gif" width="100" height="52" alt="" onmouseover="return overMenu(this, \'\', 2);" onmouseout="return outMenu(this, \'\');" />'
			+'</div>';
		menudiv.innerHTML=menuhtml;
	}
	return true;
}
function setOpacity(obj, value) {
	if (obj!=null) {
		obj.style.opacity=value;
		obj.style.MozOpacity=value;
		if ((obj.filters) && (obj.filters.alpha)) {
			obj.filters.alpha.opacity=parseInt(100*value);
		}
		return true;
	}
	return false;
}