	var browser;
	var xmlHttp;
	var response;
	var IntervalId;
	var loginToken = false;
	
	initajax();
	var ent = new PopupWindow('populate');
	var smw = new PopupWindow('sigmapwindow');
	ent.autoHide();
	
	
	document.onkeypress = checkCR;
	jQuery('ul#itemSearchList li').live("hover", function()
	 {$("ul#itemSearchList li").removeClass("itemHover");});
	
function initajax()
{
	try
	{
		xmlHttp=new XMLHttpRequest();
		browser = "STD";
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			browser = "IE";
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				browser = "IE";
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
}

function AjaxRequest(post, element, type)
{
		
		$.ajax({
			url: './script/ajax_interface.php',
			type: "POST",
			data: post,
			success : function(data) {
				switch(type)
				{
					case "innerHTML":
						$("#"+element).html(data);
						break;
					case "SRC":
						$("#"+element).attr("src",data);
						break;
					case "DATA":
						$("#"+element).html(data);
						break;
					case "EVAL":
						eval(data);
						break;
					case "TYPE":
						break;
					case "DEBUG":
						alert(post+"\n"+data);
						//return xmlHttp.responseText;
						break;
						
				}
			}
		});
}

function ConstellationMap(constellationID,constellationName)
{
		document.getElementById('populate').innerHTML = '<img src="./images/wait.gif">';
		ent.showPopup(constellationName);
		AjaxRequest('map=1&search='+constellationID, 'populate', 'innerHTML');
		
}

function RegionMap(regionID)
{
		$('#populate').html('<center><div id="routeMessage"></div></center><div id="SVGdiv"><object id="SVGobj" data="/svg/svgMap.php" type="image/svg+xml" width="900" height="600" style="background-color:#999999; " oncontextmenu="return false;"></object></div>');
		ent.showPopup(regionID);
		focusRegionMap(regionID);

		
}

function focusRegionMap(regionID)
{
		 if (document.SVGobj.getSVGDocument() == null) {
        	setTimeout("focusRegionMap("+regionID+");", 300);
		} else {
			SVG.init(document.SVGobj.getSVGDocument());
			
			$.ajax({
			url	: 	"ajax/region/ajax.show.region.php",
			type: 	"GET",
			data:	{	regionID : regionID},
			success : function(data) {
				var json = eval('('+data+')');
				var route = Array();
				SVG.Route(null, json.sys);
				SVG.focusScreen(json.display.minX,json.display.minZ,json.display.scale);
			}});
		}
}

function LoadSystemInfo(solarSystemName)
{
		AjaxRequest('solarSystemName='+solarSystemName, 'SystemDiv', 'innerHTML');
}

function ShowKills(system,anch)
{
		document.getElementById('populate').innerHTML = '<img src="./images/wait.gif"><br>Loading kills in '+system+' from the last 48 hours';
		ent.showPopup(anch);
		AjaxRequest('systemKills='+system, 'populate', 'innerHTML');
		
}

function CheckLength(control, anch, len)
{
	if(typeof(len) == 'number')
	{
		if (control.value.length > len)
		{
			ent.showPopup(anch);
			AjaxRequest(control.name+'='+control.value, 'populate', 'innerHTML');
		}
	}
	 else
	{
		ent.showPopup(anch);
		AjaxRequest(control.name+'='+control.value+'&class='+len, 'populate', 'innerHTML');
	}
}

function FindSystem(control, anch, len, evt)
{
	if(evt.keyCode == 38)
	{
		NavigateList(38);
		ActivateSystemInfo();
	} else if (evt.keyCode == 40){
		NavigateList(40);
		ActivateSystemInfo();
	} else if (evt.keyCode == 13){
		ActivateClickAction()
	} else {
		if (control.value.length >= len)
		{
			ent.showPopup(anch);
			var start = '';
			if(anch == 'destination')
			{
				start = "&alliance="+document.getElementById('allianceID').value;
				start += "&startSystemID="+document.getElementById('startSystemID').value;
			}
			/*if(anch == 'pathSource')
			{
				SVG.sID = null;
				SVG.removeElements('startRoute');
				SVG.removeElements('endRoute');
			}*/
			setLastWaypoint();
			if(SVG.sID != null)
			{
				start = "&startSystemID="+SVG.sID;
			}
			if(anch == 'sigAnc')
				start="&class="+len;
			$.ajax({
				url: "/ajax/findSystem.php",
				type: "POST",
				data: 'type=findSystemName&system='+control.value+'&field='+control.name+'&prefix='+anch+start,
				success : function(data){
					$('#populate').html(data);
			}});
		}
	}
	for(var i = 0; i < $("ul#itemSearchList li").size(); i++) {
		$("ul#itemSearchList li").eq(i).data("number", i);}
}

function PopPlanet(systemID,planet)
{
	AjaxRequest('planets='+systemID+'&prefix='+planet, planet+'p', 'innerHTML');
}

function PopMoon(systemID,prefix)
{
	AjaxRequest('moons='+systemID+'&prefix='+prefix, prefix+'m', 'innerHTML');
}

function StaticDisplay(control, anch, RVal, SVal)
{
	control.value = control.value.replace(RVal, SVal);
	if(control.name == 'sigstatic')
	{
		ent.hidePopup();
	} else {
		$.ajax({
			url: "/ajax/ajax.info.static.php",
			type: "POST",
			data: control.name+'='+SVal+'&info=1',
			success : function(data){
				$('#populate').html(data);
		}});
	}
}

function StatisticTable(img, sysid, anch, control)
{
	document.getElementById('populate').innerHTML = '<img src="./images/wait.gif">';
	ent.showPopup(anch);
	duration = control.options[control.selectedIndex].value;
	AjaxRequest('table=1&range='+duration+'&sysid='+sysid+'&type='+img, 'populate', 'innerHTML');
}

function ChangeRange(control, img, sysid)
{
	document.getElementById(img).src = './images/wait.gif';
	duration = control.options[control.selectedIndex].value;
	AjaxRequest('img=1&range='+duration+'&sysid='+sysid+'&type='+img,img, 'SRC');
}

function PopulateType(control, Type, Class)
{
		AjaxRequest('SigGroup='+Type+'&class='+Class, control, 'innerHTML');
}

function SigMap(CorpId, SysId, UserId)
{
	
	document.getElementById('sigmapwindow').innerHTML = '<img src="./images/wait.gif">';
	smw.showPopup('SigMap');
	AjaxRequest('sigmap=1&corpid='+CorpId+'&sysid='+SysId+'&userid='+UserId, 'sigmapwindow', 'innerHTML');
}

function SaveSigId(sigid, newid, CorpId, SysId, UserId)
{
	Status = document.getElementById('editSigStatus').options[document.getElementById('editSigStatus').selectedIndex].value;
	AjaxRequest('newsigid=1&corpid='+CorpId+'&sysid='+SysId+'&sigid='+sigid+'&newid='+newid+'&userid='+UserId+"&status="+Status, 'SigMapDiv', 'innerHTML');
	CheckRefresh(document.getElementById('Refresh'), CorpId, SysId, UserId);
}


function SaveDestination(mapid,destinationsystem, CorpId, SysId, UserId)
{
	AjaxRequest('savedestination=1&mapid='+mapid+'&destinationsystem='+destinationsystem+'&corpid='+CorpId+'&sysid='+SysId+'&userid='+UserId, 'SigMapDiv', 'innerHTML');
	CheckRefresh(document.getElementById('Refresh'), CorpId, SysId, UserId);
}

function MakeEditable(sigid, CorpId, SysId, UserId)
{
	AjaxRequest('editsig='+sigid+'&corpid='+CorpId+'&sysid='+SysId+'&userid='+UserId, 'SigMapDiv', 'innerHTML');
}

function DeleteSig(sigid, CorpId, SysId, UserId)
{
	AjaxRequest('deletesig='+sigid+'&corpid='+CorpId+'&sysid='+SysId+'&userid='+UserId, 'SigMapDiv', 'innerHTML');
}

function AddSig(CorpId, SysId, UserId)
{
	Signame = document.newsig.ID.value;
	Group = document.getElementById('Group').options[document.getElementById('Group').selectedIndex].value;
	Status = document.getElementById('sigStatus').options[document.getElementById('sigStatus').selectedIndex].value;
	if (Group == '5')
		Type = document.getElementById('sigstatic').value;
	else
		Type = document.getElementById('Type').options[document.getElementById('Type').selectedIndex].value;
	//alert('Addsig='+Signame+'&corpid='+CorpId+'&sysid='+SysId+'&group='+Group+'&type='+Type+'&userid='+UserId);
	AjaxRequest('Addsig='+Signame+'&corpid='+CorpId+'&sysid='+SysId+'&group='+Group+'&type='+Type+'&userid='+UserId+"&status="+Status, 'SigMapDiv', 'innerHTML');
	document.getElementById('TypeDiv').innerHTML = "";
	document.newsig.ID.value = "";
	document.getElementById('Group').selectedIndex = 0;
	document.getElementById('sigStatus').selectedIndex = 0;
	document.newsig.Add.disabled = true;
}

function ActiveEdit(control)
{
		control.select();
		clearInterval(IntervalId);
}

function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function CheckRefresh(control, CorpId, SysId, UserId)
{
		if(control.checked == true)
		{
			IntervalId = setInterval ("AjaxRequest('sigmap=1&corpid="+CorpId+"&sysid="+SysId+"&userid="+UserId+"&refresh=1', 'SigMapDiv', 'innerHTML');", 15000);
		} else {
			clearInterval(IntervalId)
		}
}

function ManualEntry(locus, systemid)
{
	document.forms['manual'].SYSTEM.value = locus;
	document.forms['manual'].SYSID.value = systemid;
	document.forms['manual'].submit();
}

function ManualDelete(systemid)
{
		alert("I will be removing " + systemid);
}

function checkCheck(field, checker)
{
	if (checker.checked == true)
		checkAll(field);
	else
		uncheckAll(field);
}

function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}

function ShowScans(anch, system)
{
		document.getElementById('populate').innerHTML = '<img src="./images/wait.gif" alt="Loading information">';
		ent.showPopup(anch);
		AjaxRequest('systemscans='+system, 'populate', 'innerHTML');
}

function SetStandings(anch, alliance)
{
		document.getElementById('populate').innerHTML = '<img src="./images/wait.gif" alt="Loading information">';
		ent.showPopup(anch);
		AjaxRequest('setstandings='+alliance, 'populate', 'innerHTML');
}

function DeleteStanding(identiy, corp, control)
{
	li = control.parentNode;
	li.parentNode.removeChild(li);
	AjaxRequest('deletestandings='+identiy+"&corp="+corp, '', 'NONE');
}

function SetHeaderColour(div, prefix)
{
	var red = document.getElementById(prefix+'red').value;
	var green = document.getElementById(prefix+'green').value;
	var blue = document.getElementById(prefix+'blue').value;
	
	document.getElementById(div).style.backgroundImage="url('images/dynamicheader.php?red="+red+"&green="+green+"&blue="+blue+"')";
}

function ResetColour()
{
	document.getElementById('hred').value = 29;
	document.getElementById('hgreen').value= 39;
	document.getElementById('hblue').value= 48;
	document.getElementById('ored').value= 39;
	document.getElementById('ogreen').value= 49;
	document.getElementById('oblue').value= 58;
		
}

function AdminChar(charName, status, lastaccess, corpName, allianceName, corpID, allianceID, charID)
{
	document.getElementById('charName').value = charName;
	document.getElementById('charID').innerHTML = charID;
	document.getElementById('charPicture').innerHTML = "<img src=\"http://image.eveonline.com/Character/"+charID+"\_128.jpg\" alt=\""+charName+"\" align=\"right\">";
	document.getElementById('corpName').innerHTML = corpName+" <img src=\"http://image.eveonline.com/Corporation/"+corpID+"\_32.png\" alt=\""+corpName+"\" align=\"absmiddle\">";
	if (allianceID != 0) {
		document.getElementById('allianceName').innerHTML = allianceName+" <img src=\"http://image.eveonline.com/Alliance/"+allianceID+"_32.png\" alt=\""+allianceName+"\" align=\"absmiddle\">";
	} else {
		document.getElementById('allianceName').innerHTML = "";
	}
	document.getElementById('lastaccess').innerHTML = lastaccess+" ";
	
	var UserAccess = status.split(",");
	document.getElementById('Normal').checked = false;
	document.getElementById('Debug').checked = false;
	document.getElementById('Admin').checked = false;
	for(i=0; i<UserAccess.length;i++)
	{
		 document.getElementById(UserAccess[i]).checked = true;
	}
}

function AddJumpBridgeConnections(button)
{
		var sSID = document.getElementById('startSystemID');
		var dSID = document.getElementById('destinationSystemID');
		var sS = document.getElementById('startSystem');
		var dS = document.getElementById('destinationSystem');
		var sM = document.getElementById('startMoon');
		var dM = document.getElementById('destinationMoon');
		var sP = document.getElementById('startPassword');
		var dP = document.getElementById('destinationPassword');
		var divS = document.getElementById('startm');
		var divD = document.getElementById('destinationm');
		var nI = document.getElementById('mapID');
		var cI = document.getElementById('connectionID');
		var aI = document.getElementById('allianceID');
		var nN = document.getElementById('networkName');
		var sC = document.getElementById('selectConnection');
		//alert(button.name);
		switch(button.name)
		{
			case 'Add':
			{
				var dataString = 'SaveConnection='+nI.value;
				dataString += '&startSystem='+sSID.value;
				dataString += '&destinationSystem='+dSID.value;
				dataString += '&startMoon='+sM.value;
				dataString += '&destinationMoon='+dM.value;
				dataString += '&startPassword='+sP.value;
				dataString += '&destinationPassword='+dP.value;
				dataString += '&networkName='+nN.value;
				if(cI.value != '') { dataString += '&connectionID='+cI.value; }
				AjaxRequest(dataString, 'SVGdiv', 'DATA');
				break;
			}
			case 'Delete':
			{
				dataString = '&networkName='+nN.value;
				sC.remove(sC.selectedIndex);
				AjaxRequest('SaveConnection=Delete&connectionID='+cI.value+dataString, 'SVGdiv', 'DATA');
			}
		}
		sS.value='';
		dS.value='';
		sSID.value='';
		dSID.value='';
		sP.value='';
		dP.value='';
		divS.innerHTML = '';
		divD.innerHTML = '';
		cI.value = '';
		aI.value = '';
		svgClearChildren(75);
		svgClearChildren(76);
		
		//lert(dataString);
		
}

function EditConnection(connectionID)
{
	document.getElementById('connectionID').value = connectionID;
	document.getElementById('ConnectionDiv').innerHTML = '<center><img src="./images/wait.gif"></center>';
	
	AjaxRequest('connectionID='+connectionID, 'ConnectionDiv', 'innerHTML');
	//alert(result);
}

function AddMapAccess(type)
{
		var a = document.getElementById(type+'Search');
		var i = document.getElementById(type+'ID');
		var t = document.getElementById(type+'Type');
		var m = document.getElementById('mapID');
		
		var u = document.getElementById(type+'List');
		
		var newLi = document.createElement('li');
		var newImg = document.createElement('img');
		switch(t.value)
		{
			case 'Character':
				//var img = '<img src="http://image.eveonline.com/Character/'+i.value+'_128.jpg" alt="'+a.value+'" align="right">';
				newImg.setAttribute("src", "http://image.eveonline.com/Character/"+i.value+"_32.jpg");
				newImg.setAttribute("align", "absmiddle");
				newImg.setAttribute("alt",a.value);
				break;
			case 'Corporation':
				//var img = '\<img src="http://image.eveonline.com/Corporation/'+i.value+'_32.png" alt="'+a.value+'" align="absmiddle">';
				newImg.setAttribute("src", "http://image.eveonline.com/Corporation/"+i.value+"_32.png");
				newImg.setAttribute("align", "absmiddle");
				newImg.setAttribute("alt",a.value);
				break;
			case 'Alliance':
				//var img = '\<img src="http://image.eveonline.com/Alliance/'+i.value+'_32.png" alt="'+a.value+'" align="absmiddle"\'>';
				newImg.setAttribute("src", "http://image.eveonline.com/Alliance/"+i.value+"_32.png");
				newImg.setAttribute("align", "absmiddle");
				newImg.setAttribute("alt",a.value);
				break;
		}
		AjaxRequest('mapAccess='+type+'&identity='+i.value+'&jumpMap='+m.value, 'none', 'NONE');
		newLi.setAttribute("value",i.value);
		newLi.setAttribute("class","highsec");
		newLi.setAttribute("style","text-align:left; padding-left:25px;");
		identityName = document.createTextNode(' ' +a.value);
		identityType = document.createTextNode(' (' +t.value+')');
		newLi.appendChild(newImg);
		newLi.appendChild(identityName);
		newLi.appendChild(identityType);
		u.appendChild(newLi);
		a.value = '';
		i.value = '';
		t.value = '';
}

function RemoveAccess(charID, mapID, thisLi)
{
	thisLi.parentNode.removeChild(thisLi);
	AjaxRequest('removeAccess='+charID+'&mapID='+mapID, 'none', 'NONE');
}

function SwapTextBox(controlName,ctrl)
{
	var c = document.getElementById(controlName);
	var val = ctrl.innerHTML;
	c.innerHTML = '<input type="text" id="textBox" value="'+val+'" onBlur="RestoreText(\''+controlName+'\',this);"  size="30">'
	document.getElementById('textBox').focus();
}
		
function RestoreText(controlName,ctrl)
{
	var val = ctrl.value;
	var c = document.getElementById(controlName);
	var mapID = document.getElementById('mapID').value;
	c.innerHTML = '<a onClick="SwapTextBox(\''+controlName+'\',this);" style="cursor:pointer;">'+val+'</a>';
	AjaxRequest('changeNetworkName='+val+'&mapID='+mapID, 'none', 'NONE');
}
		
function TrustRefresh(host,anch)
{
	if(navigator.userAgent.toLowerCase().indexOf('eve-igb') >= 0)
	{
		document.getElementById('trustRefresh').innerHTML = '<center><h2>Reloading Page<h2><p>Please wait a few moments</p><img src="./images/wait.gif"></center>';
		CCPEVE.requestTrust('http://'+host); 
		setTimeout('location.reload(true);',6000);
	}
	else
	{
		document.getElementById('trustRefresh').innerHTML = '<center><h2>This feature is only available in the In Game Browser<h2><p>Reloading</p><img src="./images/wait.gif"></center>';
		setTimeout('location.reload(true);',3000);
	}
		
	//ent.showPopup(anch);
}

function AvoidRoute(system)
{
	$.ajax({
		url	: 	"ajax/route/ajax.waypoint.php",
		type: 	"GET",
		data:	{solarSystemName :system},
		success : function(data) {
			$('#avoidable').append(data);
			WaitMessage('mapArea','Calculating Route');
			CalculateRoute();
		}
	});
}

function UnAvoidRoute(system)
{
	var avoid = $('#avoid').val().split(":");
	for (var key in avoid) {
		if (key == system) {avoid.splice(key, 1);}
	}
	$('#avoid').val(avoid.join(':'));
	WaitMessage('mapArea','Calculating Route');
	CalculateRoute();
}

function WaitMessage(divArea, message)
{
	document.getElementById(divArea).innerHTML = '<center><p>'+message+'</p><img src="/images/wait.gif"></center>';
}
		
					  /* SOURCE FILE: AnchorPosition.js */
function getAnchorPosition(anchorname){var useWindow=false;var coordinates=new Object();var x=0,y=0;var use_gebi=false, use_css=false, use_layers=false;if(document.getElementById){use_gebi=true;}else if(document.all){use_css=true;}else if(document.layers){use_layers=true;}if(use_gebi && document.all){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_gebi){var o=document.getElementById(anchorname);x=AnchorPosition_getPageOffsetLeft(o);y=AnchorPosition_getPageOffsetTop(o);}else if(use_css){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_layers){var found=0;for(var i=0;i<document.anchors.length;i++){if(document.anchors[i].name==anchorname){found=1;break;}}if(found==0){coordinates.x=0;coordinates.y=0;return coordinates;}x=document.anchors[i].x;y=document.anchors[i].y;}else{coordinates.x=0;coordinates.y=0;return coordinates;}coordinates.x=x;coordinates.y=y;return coordinates;}
function getAnchorWindowPosition(anchorname){var coordinates=getAnchorPosition(anchorname);var x=0;var y=0;if(document.getElementById){if(isNaN(window.screenX)){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else{x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}}else if(document.all){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else if(document.layers){x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}coordinates.x=x;coordinates.y=y;return coordinates;}
function AnchorPosition_getPageOffsetLeft(el){var ol=el.offsetLeft;while((el=el.offsetParent) != null){ol += el.offsetLeft;}return ol;}
function AnchorPosition_getWindowOffsetLeft(el){return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;}
function AnchorPosition_getPageOffsetTop(el){var ot=el.offsetTop;while((el=el.offsetParent) != null){ot += el.offsetTop;}return ot;}
function AnchorPosition_getWindowOffsetTop(el){return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;}/* SOURCE FILE: PopupWindow.js */function PopupWindow_getXYPosition(anchorname){	var coordinates;	if(this.type == "WINDOW")	{		coordinates = getAnchorWindowPosition(anchorname);	}else{		coordinates = getAnchorPosition(anchorname);	}	this.x = coordinates.x;	this.y = coordinates.y+21;}
function PopupWindow_setSize(width,height){this.width = width;this.height = height;}
function PopupWindow_populate(contents){this.contents = contents;this.populated = false;}
function PopupWindow_setUrl(url){this.url = url;}
function PopupWindow_setWindowProperties(props){this.windowProperties = props;}
function PopupWindow_refresh(){if(this.divName != null){if(this.use_gebi){document.getElementById(this.divName).innerHTML = this.contents;}else if(this.use_css){document.all[this.divName].innerHTML = this.contents;}else if(this.use_layers){var d = document.layers[this.divName];d.document.open();d.document.writeln(this.contents);d.document.close();}}else{if(this.popupWindow != null && !this.popupWindow.closed){if(this.url!=""){this.popupWindow.location.href=this.url;}else{this.popupWindow.document.open();this.popupWindow.document.writeln(this.contents);this.popupWindow.document.close();}this.popupWindow.focus();}}}
function PopupWindow_showPopup(anchorname){this.getXYPosition(anchorname);this.x += this.offsetX;this.y += this.offsetY;this.visible = true;if(!this.populated &&(this.contents != "")){this.populated = true;this.refresh();}if(this.divName != null){if(this.use_gebi){document.getElementById(this.divName).style.left = this.x + "px";document.getElementById(this.divName).style.top = this.y + "px";document.getElementById(this.divName).style.visibility = "visible";} else if(this.use_css){document.all[this.divName].style.left = this.x;document.all[this.divName].style.top = this.y;document.all[this.divName].style.visibility = "visible";} else if(this.use_layers){document.layers[this.divName].left = this.x;document.layers[this.divName].top = this.y;document.layers[this.divName].visibility = "visible";}} else{if(this.popupWindow == null || this.popupWindow.closed){if(this.x<0){this.x=0;}if(this.y<0){this.y=0;}if(screen && screen.availHeight){if((this.y + this.height) > screen.availHeight){this.y = screen.availHeight - this.height;}}if(screen && screen.availWidth){if((this.x + this.width) > screen.availWidth){this.x = screen.availWidth - this.width;}}var avoidAboutBlank = window.opera ||( document.layers && !navigator.mimeTypes['*']) || navigator.vendor == 'KDE' ||( document.childNodes && !document.all && !navigator.taintEnabled);this.popupWindow = window.open(avoidAboutBlank?"":"about:blank","window_"+anchorname,this.windowProperties+",width="+this.width+",height="+this.height+",screenX="+this.x+",left="+this.x+",screenY="+this.y+",top="+this.y+"");}this.refresh();}}
function PopupWindow_hidePopup()
{
	if(this.divName != null)
	{
		this.visible=false;
		document.getElementById(this.divName).style.visibility = "hidden";
		if(this.prePopulated == false)
		{
			document.getElementById(this.divName).innerHTML = '<img src="/images/wait.gif" align="absmiddle"> Searching...';
		}
	}
}

function PopupWindow_isClicked(e){		var t = e.target;		try		{			while(t.parentNode != null)			{				if(t.id==this.divName)				{					return true;				}				t = t.parentNode;			}		}		catch(err)		{			return false;		}		return false;}
function PopupWindow_hideIfNotClicked(e){	if(this.autoHideEnabled && !this.isClicked(e)){		this.hidePopup();	}}
function PopupWindow_autoHide(){this.autoHideEnabled = true;}
function PopupWindow_hidePopupWindows(e){for(var i=0;i<popupWindowObjects.length;i++){if(popupWindowObjects[i] != null){var p = popupWindowObjects[i];p.hideIfNotClicked(e);}}}
function PopupWindow_attachListener(){if(document.layers){document.captureEvents(Event.MOUSEDOWN);}window.popupWindowOldEventListener = document.onmousedown;if(window.popupWindowOldEventListener != null){document.onmousedown = new Function("window.popupWindowOldEventListener();PopupWindow_hidePopupWindows();");}else{document.onmouseup = PopupWindow_hidePopupWindows;}}
function PopupWindow(){
	if(!window.popupWindowIndex){
		window.popupWindowIndex = 0;
	}
	if(!window.popupWindowObjects){
		window.popupWindowObjects = new Array();
	}
	if(!window.listenerAttached){
		window.listenerAttached = true;
		PopupWindow_attachListener();
	}
	this.index = popupWindowIndex++;
	popupWindowObjects[this.index] = this;
	this.divName = null;
	this.popupWindow = null;
	this.width=0;
	this.height=0;
	this.populated = false;
	this.prePopulated = false;
	this.visible = false;
	this.autoHideEnabled = true;
	this.contents = "";
	this.url="";
	this.windowProperties="toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no";
	if(arguments.length>0){
		this.type="DIV";
		this.divName = arguments[0];
	}else{
		this.type="WINDOW";
	}
	this.use_gebi = false;
	this.use_css = false;
	this.use_layers = false;
	//if(document.getElementById){
		this.use_gebi = true;
	/*}else if(document.all){
		this.use_css = true;
	}else if(document.layers){
		this.use_layers = true;
	}else{
		this.type = "WINDOW";
	}*/
	this.offsetX = 0;
	this.offsetY = 0;
	this.getXYPosition = PopupWindow_getXYPosition;
	this.populate = PopupWindow_populate;
	this.setUrl = PopupWindow_setUrl;
	this.setWindowProperties = PopupWindow_setWindowProperties;
	this.refresh = PopupWindow_refresh;
	this.showPopup = PopupWindow_showPopup;
	this.hidePopup = PopupWindow_hidePopup;
	this.setSize = PopupWindow_setSize;
	this.isClicked = PopupWindow_isClicked;
	this.autoHide = PopupWindow_autoHide;
	this.hideIfNotClicked = PopupWindow_hideIfNotClicked;
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1))
	{
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function stripCommas(Ctrl)
{
	Ctrl.value = Ctrl.value.replace(/,/g,"");
	Ctrl.select();
}

function inputAddCommas(Ctrl)
{
	Ctrl.value = Ctrl.value.replace(/,/g,"");
	Ctrl.value = addCommas(Ctrl.value);
}

function ItemSearch(control, anch, len, evt)
{
	if(evt.keyCode == 38)
	{
		NavigateList(38);
	} else if (evt.keyCode == 40){
		NavigateList(40);
	} else if (evt.keyCode == 13){
		ActivateClickAction()
	} else {
		CheckLength(control, anch, len);
	}
	for(var i = 0; i < $("ul#itemSearchList li").size(); i++) {
		$("ul#itemSearchList li").eq(i).data("number", i);
	}
}

function ActivateClickAction()
{
	$("ul#itemSearchList li").eq(currentSelection).click();
}

function NavigateList(key)
{
	//alert($('ul#itemSearchList').size());
	if($('ul#itemSearchList li.itemHover').size() == 0)
	{
		currentSelection = -1; 
	} 
	
	var mI = $('ul#itemSearchList li:hover').index();
	var mS = $('ul#itemSearchList li:hover').size();
	var cI = $('ul#itemSearchList li.itemHover').index();
	var cS = $('ul#itemSearchList li.itemHover').size();
	
	//$('#testOutput').html("Mouse Index : "+mI+"<br>Mouse Count : "+mS+"<br>Class Index : "+cI+"<br>Class Size : "+cS+"<br>Current Selection : "+currentSelection);
	
	if(key == 38 && currentSelection != -1) 
	{
		if(currentSelection != 0) 
		{
			currentSelection--;
		}
	} else if (key == 40) {
		if(currentSelection != $("ul#itemSearchList li").size() -1) {
			currentSelection++;
		}
	}
	//cH = $('#testOutput').html() + "<br>Calculated Selection : ";
	//$('#testOutput').html(cH+currentSelection);
	setSelected(currentSelection);
//	
		
}

function setSelected(menuitem) {
   $("ul#itemSearchlist li").eq(menuitem).trigger('mouseover');
   $("ul#itemSearchList li").removeClass("itemHover");
   $("ul#itemSearchList li").eq(menuitem).addClass("itemHover");
}


  function checkCR(evt) {

    var evt  = (evt) ? evt : ((event) ? event : null);

    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}

  }
  
  function networkSystemSelected(field, solarSystemID, prefix, allianceID)
  {
	  document.getElementById(field+'ID').value = solarSystemID;
	  PopMoon(solarSystemID,prefix); 
	  document.getElementById('allianceID').value = allianceID;
  }
	function setCTM(element, matrix) {
		var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
		
		element.setAttribute("transform", s);
	}
	
	
	function GetScale(g)
	{
		var arr = g.getAttribute("transform").split(",");
		var scale = arr[0].replace("scale(","");
		return parseFloat(scale.replace("matrix(","")); 
	}
//	var g = svgRoot.getElementsByTagName('g')[i];

function TestSVGElement()
{
	var svgdoc = document.SVGobj.getSVGDocument();
	var svgRoot = svgdoc.documentElement;
	// 75
	
	var route = svgRoot.getElementsByTagName('g')[76];
	var svgns = 'http://www.w3.org/2000/svg';
	var x = -195;
	var y = 3467
	
	var x2 = -381;
	var y2 = 3221;
	
	svgCreateCircle(x,y,"green",76);
	svgCreateCircle(x2,y2,"red",75);
	
	var line = svgdoc.createElementNS(svgns, "line");
	line.setAttributeNS(null, "x1",x);
	line.setAttributeNS(null, "y1",y);
	line.setAttributeNS(null, "x2",x2);
	line.setAttributeNS(null, "y2",y2);
	line.setAttributeNS(null, "style", "stroke:yellow;stroke-width:4");
	route.appendChild(line);
	
	var t = svgRoot.getElementsByTagName('g');
	var el = svgRoot.getElementsByTagName('g').length;
	var els = '';
	for(i=0;i<el;i++)
	{
		els += i+" : "+t[i].id+" \n";
	}
	alert(els);

}

	function over(b,a)
	{
		$(b).addClass(a?a:"itemHover").find(".go").removeClass("hide")
	}
	function out(b,a)
	{
		$(b).removeClass(a?a:"itemHover").find(".go").addClass("hide")
	}
	
	
	function deleteError(errorID, row)
{
	qString = "errorID="+errorID;
	if(errorID == 'all')
	{
		AjaxRequest(qString, 'errorLog', 'innerHTML');
	} else {
		var tbl = row.parentNode.parentNode.parentNode;
		var r = row.parentNode.parentNode;
		var index = r.rowIndex-3;
		var c = r.getAttribute('class');
		tbl.deleteRow(index);
		tbl.deleteRow(index);
		tbl.deleteRow(index);
		tbl.deleteRow(index);
		AjaxRequest(qString, '', 'NONE');
	}
}

function checkReady() {
    if (document.SVGobj.getSVGDocument() == null) {
        setTimeout("checkReady()", 300);
    } else {
        SVG.init(document.SVGobj.getSVGDocument());
	/*	$(SVG.svgDoc).bind("contextmenu",function(e){
              return false;
       }); 
		$(SVG.root).mousedown(function(e)
		{
			if(e.button == 2)
			{
				$('#svgTool').html(e.button);
				$('#svgTool').dialog();
			} else {
				$('#svgTool').dialog('close');
			}
		});*/
    }
}

function setSysLoc(index)
{
	currentSelection = index;
	SVG.sID = +$('#'+currentSelection+'arr').val();
	sys=SVG.getGDBFromID();
	SVG.x = sys.x;
	SVG.z = sys.z;
}

function setCurrentSelection(index)
{
	currentSelection = index;
}

function previousSystems()
{
	var idArr = $('#sortable li').last().children('div').children('input')
	if(idArr.length != 0)
	{
		var json = eval('('+idArr.val()+')');
	}
}

function ActivateSystemInfo()
{
	if(document.SVGobj)
	{
		
		//var sysID = $('#'+currentSelection+'id').val();
		if(sysID = $('#'+currentSelection+'arr').val())
		{
			svgClearChildren('JumpLines');  
			svgClearChildren('SystemCircles');
			svgClearChildren('systemLables');
			sys = SVG.getGDBFromID(sysID);
			if(sys = GDB.ss[sysID]){}else
			if(sys = GDB.r[sysID]){} else
			if(sys = GDB.c[sysID]){}
			else {return false;}
			if(SVG.sID != null)
			{
				if(last = $('#sortable :last-child').children('div').children('input').val())
				{
					if(f = GDB.ss[last]){}else
					if(f = GDB.r[last]){} else
					if(f = GDB.c[last]){}
					else {return false;}
					SVG.sID = last;
					SVG.x = f.x;
					SVG.z = f.z;
					var g =  $('#startRoute',SVG.svgDoc);
					svgCreateCircle(f.x,f.z,'lawngreen',20, 'startRoute');
					g.append(svgModel.addText(f.x,f.z,f.n,'','',''));
					svgCenterScreen(f.x,f.z,false);
				}
				var element = "endRoute";
				var g =  $('#endRoute',SVG.svgDoc);
				SVG.removeElements(element);
				svgClearChildren('endRoute'); 
				svgCreateCircle(sys.x,sys.z,'red',20,'endRoute'); 
				svgDrawLine(sys.x,sys.z,SVG.x,SVG.z,'DodgerBlue ');
				g.append(svgModel.addText(sys.x,sys.z,sys.n,'','',''));
				svgCenterScreen(sys.x,sys.z,true); 
			}
			 else
			{
				var element = "startRoute";
				var g =  $('#startRoute',SVG.svgDoc);
				svgCreateCircle(sys.x,sys.z,'lawngreen',20, 'startRoute');
				g.append(svgModel.addText(sys.x,sys.z,sys.n,'','',''));
				svgCenterScreen(sys.x,sys.z,false);
			}
		}
	}
}
	var svgns	= 'http://www.w3.org/2000/svg';
	var XLINK	= "http://www.w3.org/1999/xlink";

	/*window.onload = function()
		{
			svgProto.init();
			svgProto.test();
		};*/
function setCTM(element, matrix) {
		var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";	
		element.setAttribute("transform", s);
	}
	
	function svgCenterScreen(x,y,s)
	{
		if(s == true)
		{
			var minX = x, maxX = x;
			var minZ = y, maxZ = y;
			var w, h = 0;
			var scale = 1.4;
			$('#sortable li').each(function(i,e)
			{
				var sysID =$(e).children('div').children('input').val();
				if(sys = GDB.ss[sysID]){}else
				if(sys = GDB.r[sysID]){} else
				if(sys = GDB.c[sysID]){}
				else {return false;}
				var tx = sys.x;
				var tz = sys.z;
				if(tx < minX)
				{
					minX = tx;
				} 
				if(tx > maxX)
				{
					maxX = tx;
				}
				if(tz < minZ)
				{
					minZ = tz;
				}
				if(tz > maxZ)
				{
					maxZ = tz;
				}
			});
			w = SVG.roundNumber(maxX - minX,0);
			h = SVG.roundNumber(maxZ - minZ,0);
			var sW = SVG.roundNumber(800/w,5);
			var sH = SVG.roundNumber(500/h,5);
			y=minZ;
			x=minX;
			if(sW < sH)
			{
				scale = sW;
				var yo = (500-(sW*h));
				y -= yo;
			}
			else
			{
				scale = sH;
				var xo = (800-(sH*w));
				x -= xo;
			}
			y -= (10/scale);
			x -= (10/scale);
		} else {
			
			scale = 1.4;
			y -= (300/scale);
			x -= (450/scale);

		}
		var g = SVG.svgDoc.getElementById('viewport');
		stateTf = g.getCTM().inverse();
		stateTf.a = scale;
		stateTf.d = scale;
		SVG.setCTM(g,stateTf);
		stateTf = g.getCTM().inverse();
		var p = SVG.root.createSVGPoint().matrixTransform(stateTf);
		var scale = GetScale(g);
		SVG.setCTM(g, stateTf.inverse().translate(p.x - x, p.y - y));
		SVG.ScaleSVG(x,y,scale);
		svgModel.AddSystemLables();
	}

function svgClearChildren(elementName)
{
	$('#'+elementName,SVG.svgDoc).empty();
}

function svgCreateCircle(x,y,col,r,insertElement)
{
	var g = $('#'+insertElement,SVG.svgDoc);
	
	svgClearChildren(insertElement);
	
	var shape = SVG.svgDoc.createElementNS(SVG.svgNS, "circle");
	shape.setAttributeNS(null, "cx", x);
	shape.setAttributeNS(null, "cy", y);
	shape.setAttributeNS(null, "r",  r);
	shape.setAttributeNS(null, "fill", col);
	g.append(shape);
}

function svgDrawLine(x1,y1,x2,y2,col)
{
	var g =  $('#endRoute',SVG.svgDoc);
	var line = SVG.svgDoc.createElementNS(SVG.svgNS, "line");
	line.setAttributeNS(null, "x1",x1);
	line.setAttributeNS(null, "y1",y1);
	line.setAttributeNS(null, "x2",x2);
	line.setAttributeNS(null, "y2",y2);
	line.setAttributeNS(null, "style", "stroke:"+col+";stroke-width:4");
	g.append(line);
}

function flipShipCategory(ctrl)
{
	if($(ctrl).val() == 1)
	{
		page = "/ajax/route/ajax.capitalList.php";
		SVG.state = 'jump';
	} else {
		page = "/ajax/route/ajax.subCapList.php";
		SVG.state = 'route';
	}
	var tbl = $('#shipTypeTable');
	$.ajax({
			url: page,
			type: "POST",
			success : function(data) {
				$(tbl).find("tr:gt(0)").remove();
				$(tbl).append(data);
				selectShipType();
			}
	});
	
}

function selectShipType()
{
	var val = $('#shipTypeID').val().split(',');
	$('#typeImage').attr('src','http://img.staticmapper.com/types/'+val[1]+'_32.png');
	if($('#capitals').is(':checked'))
	{
		$('#shipInfo').html($('#jdCal').val()*val[0]);
	} else {
		$('#shipInfo').html(addCommas(val[0]));
	}
	
}

function insertWayPointSortable(arr)
{
	$('#sortable').unbind('sortupdate');
	$('#sortable').unbind('sortstart');
	$(arr).unbind('mouseover');
	$(arr).clone(true).appendTo('#sortable');
	var idArr = $('#sortable li').last().children('div').children('input');
	$('#sortable li').last().children('div').prepend('<img src="/images/cancel.png" style="float:right; padding:2px 0px 0px 5px;" onclick="removeLI(this);"/>');
	idArr.removeAttr('id');
	setLastWaypoint();
	$('#from').val('').focus();
	$('#sortable').bind('sortupdate', function(event,ui){calculateJumpRange();});
	$('#sortable').bind('sortstart', function(event,ui){clearJumpRange();});
}

function removeLI(e)
{
	var li = $(e).closest('li');
	$(li).remove();
	if($('#sortable').children().length != 1)
	{
		calculateJumpRange();
		CalculateRoute();
	}
	
}
function setLastWaypoint()
{
	var elt = '';
	var idArr = $('#sortable li').last().children('div').children('input')
	if(idArr.length != 0)
	{
		SVG.sID = idArr.val();
		$('#endRoute',SVG.svgDoc).children().each(function (i,e)
		{
			//$(e).clone().appentTo('#startRoute',SVG.svgDoc);
			var type = e.tagName;
			var shape = SVG.svgDoc.createElementNS(SVG.svgNS,type);
			$.each($(e.attributes), function(index) {
				shape.setAttributeNS(null, e.attributes[index].name,e.attributes[index].value);
			});
			$('#startRoute',SVG.svgDoc).append(shape);
		});
		svgClearChildren('endRoute');
	} else
		SVG.sID = null;
}

function clearJumpRange()
{
	$('#sortable li').each(function(i,e)
	{
		$('#distance',e).html('');
	});
}

function calculateJumpRange()
{
	var lastX = null, lastY = null, lastZ = null;
	//$('#debugDiv').html('Range<br>');
	$('#sortable li').each(function(i,e)
	{
		var sysID =$(e).children('div').children('input').val();
		//$('#debugDiv').append(sysID+'<br>');
		if(sys = GDB.ss[sysID]){}else
		if(sys = GDB.r[sysID]){} else
		if(sys = GDB.c[sysID]){}
		else {return false;}
		//alert(a.n);
		if(lastX == null)
		{
			lastX = sys.x;
			lastY = sys.y;
			lastZ = sys.z;
			$('#distance',e).html('');
		} else {
			ly = SVG.roundNumber(Math.sqrt(
				((lastX-sys.x)*(lastX-sys.x)
			) + (
				(lastY-sys.y)*(lastY-sys.y)
			) + (
				(lastZ-sys.z)*(lastZ-sys.z)
			))/94.60730472580800,2);
			$('#distance',e).html('('+ly+' ly)');
			lastX = sys.x;
			lastY = sys.y;
			lastZ = sys.z;
		}
	});
	lastX, lastY, lastZ = null;
}

function CalculateRoute()
{
		
	//$('#debugDiv').html($('#sortable').children().length);	
	document.title = 'Staticmapper - Calculating route';
	SVG.removeElements('SystemCircles');
	SVG.removeElements('systemLables');
	SVG.removeElements('JumpLines');
	SVG.removeElements('startRoute');
	SVG.removeElements('endRoute');
	if($('#sortable').children().length == 1)
	{
		return false;
	}
	var route = new Array();
	var avoid = new Array();
	$('#sortable li').each(function(i,e)
	{
		c = route.length;
		SVG.sID =$(e).children('div').children('input').val();
		sys=SVG.getGDBFromID();
		route[c] = sys.n;
	});
	$('#avoidable li').each(function(i,e)
	{
		c = avoid.length;
		SVG.sID =$(e).children('div').children('input').val();
		sys=SVG.getGDBFromID();
		avoid[c] = sys.n;
	});
	if($('#capitals').is(':checked'))
	{
		urlPath = "method=jump&ship="+$('#shipTypeID option:selected').text()+':'+$('#jdCal option:selected').text();
		ajaxUrl = "ajax/route/ajax.calculate.jump.php";
	} else {
		urlPath = "method=route&ship="+$('#shipTypeID option:selected').text();
		ajaxUrl = "ajax/route/ajax.calculate.route.php";
	}
	if($('#stations').is(':checked'))
		urlPath += "&stations=true";
	if($('#highsec').is(':checked'))
		urlPath += "&highsec=true";
	if($('#jumpbridges').is(':checked'))
		urlPath += "&jumpbridges=true";
	urlPath += "&route="+route.join(":");
	if(avoid.length != 0)
		urlPath += "&avoid="+avoid.join(":");
	WaitMessage('mapArea','Calculating Route'); 
	$('#routeMessage').html(route.join(":"));
		$.ajax({
			url: ajaxUrl,
			type: "GET",
			data: urlPath,
			success : function(data) {
				if(json = eval('('+data+')'))
				{
					if(json.code == -1)
						$('#routeMessage').html('Please select 2 systems to calculate a route');
					else
					{
						$('#routeMessage').html('Shortest number of jumps calculated is '+json.code);
						$('#mapArea').html(json.data);
						SVG.focusScreen(json.display.minX,json.display.minZ,json.display.scale);
						SVG.sID = json.sys[0];
						SVG.Route(json.route, json.sys);
						title = 'Route between '+route.join(", ")+' - '+json.code+' jumps';
						document.title = title;
						window.history.pushState({"html":json.data,"pageTitle":title},"", "/index.php?routefinder&"+urlPath);
					}
				}
		},
		statusCode :{
			500 :	function() {
				$('#mapArea').html('<span class="warningMessage"><center>Request timed out!  <br>We are still training the gerbils so to help them out, try adding a couple more waypoints</center></span>');
			}
		}
	});
}

function getWormholeConnections()
{
	SVG.removeElements('SystemCircles');
	SVG.removeElements('systemLables');
	SVG.removeElements('JumpLines');
	$.ajax({
		url	: 	"ajax/route/ajax.wormhole.connections.php",
		type: 	"GET",
		data:	{regionID : $('#regionID').val(),
					hash  : $('#hashKey').val()},
		success : function(data) {
			var json = eval('('+data+')');
			if(json.code == -1)
				$('#routeMessage').html('Please select 2 systems to calculate a route');
			else
			{
				$('#routeMessage').html('W-Space connections '+json.code);
				$('#mapArea').html(json.data);
				if(json.sys.length > 0)
				{
					SVG.sID = json.sys[0];
					SVG.Route(json.route, json.sys);
				}
				title = 'Historical W-Space connections - '+json.code+' logged';
				document.title = title;
				urlPath = "/index.php?routefinder&wspace=true";
				 window.history.pushState({"html":json.data,"pageTitle":title},"", urlPath);
				 SVG.focusScreen(70440,90000,0.07);
			}
		}
	});
}

function restNavi()
{
	$('#sortable').empty();
	$('#avoidable').empty();
	SVG.removeElements('SystemCircles');
	SVG.removeElements('systemLables');
	SVG.removeElements('JumpLines');
	$('#mapArea').html('');
	$('#routeMessage').html('');
	urlPath = "/index.php?routefinder";
	title = "Staticmapper - Navigator";
	window.history.pushState({"pageTitle":title},"", urlPath);
	SVG.focusScreen(-7000,-5000,0.07);
}

function jumpbridgeLoginForm()
{
	var tbl = $('#routeTable');
	var rowCount = $(tbl).children('tbody').children('tr').length;
	//$('#debugDiv').html("TR count : "+rowCount);
	if($('#jumpbridges').is(':checked') && !loginToken && rowCount == 5)
	{
		$.ajax({
			url	: 	"/views/loginForm.php",
			success : function(data) {
				$('#routeTable').append('<tr id="loginTr"><td colspan="2">'+data+'</td></tr>');
			}
		});
	
	} else {
		if(rowCount == 6 && !loginToken)
		{
			$('#loginTr').remove();
		}
	}
}

function checkLogin()
{
	$.ajax({
		url	: 	"ajax/ajax.login.php",
		type: 	"POST",
		data:	{	charName : $('#charName').val(),
					password : $('#password').val()},
		success : function(data) {
			var json = eval('('+data+')');
			if(json.code == -1)
			{
				$('#password').val('').focus();
				$('#loginMessage').attr("class","warningMessage");
				var response = 'Invalid Username or Password';
				var timeout = "$('#loginMessage').fadeOut('slow');"
				$('#loginMessage').html(response);
				$('#loginMessage').fadeIn('fast');
			} else {
				loginToken = json.loginToken;
				$('#loginTr').html('<div class="acceptMessage" style="text-align:center;">Login Successfull</div>');
				var timeout = "$('#loginTr').remove();"
			}
			
			setTimeout(timeout,2500);
		}
	});
}
