var debug_enabled 				= true;
var debug_size 					= 0;

function ajaxpage(url, containerid, tmp)
{
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
		try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e){}
		}
	}
	else
		return false
	if (tmp)
		document.getElementById(containerid).innerHTML = "<img src='images/loading.gif' />"
		
	page_request.onreadystatechange = function()
	{
		loadpage(page_request, containerid)
	}
	page_request.open('GET', url, true)
	page_request.send(null)
}

function loadpage(page_request, containerid)
{
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(containerid).innerHTML=page_request.responseText
}


var body= new Array(3)
body[0]="images/avatars/human/avatar_body1b.gif";
body[1]="images/avatars/human/avatar_body2b.gif";
body[2]="images/avatars/human/avatar_body3b.gif";
 
var bodymolecule= new Array(3) 
bodymolecule[0]="images/gui/bodymolecule1.gif"; 
bodymolecule[1]="images/gui/bodymolecule2.gif"; 
bodymolecule[2]="images/gui/bodymolecule3.gif"; 

var hair = new Array(4)
hair[0]="images/avatars/hair/avatar_haira1.gif";
hair[1]="images/avatars/hair/avatar_hairb1.gif";
hair[2]="images/avatars/hair/avatar_hairc1.gif";
hair[3]="images/avatars/hair/avatar_haird1.gif";
	
var hairmolecule= new Array(4) 
hairmolecule[0]="images/gui/bodymolecule1.gif"; 
hairmolecule[1]="images/gui/bodymolecule2.gif"; 
hairmolecule[2]="images/gui/bodymolecule3.gif"; 
hairmolecule[3]="images/gui/bodymolecule4.gif"; 
	
function create() {
	var Gsex = document.creation.Gsex.value;
	var molecule = document.creation.molecule.value;
	var strand = document.creation.strand.value;
	var Ghair = document.creation.Ghair.value;
	var Gskin = document.creation.Gskin.value;
	var Gstat1 = document.creation.Gstat1.value;
	var Gstat2 = document.creation.Gstat2.value;
	var Gstat3 = document.creation.Gstat3.value;
	var Gstat4 = document.creation.Gstat4.value;
	var Gstat5 = document.creation.Gstat5.value;
	var Gstat6 = document.creation.Gstat6.value;
	var characterName = document.creation.characterName.value;
	var values = "characterName=" + characterName + "&Gsex=" + Gsex + "&molecule=" + molecule + "&strand=" + strand + "&Ghair=" + Ghair + "&Gskin=" + Gskin + "&Gstat1=" + Gstat1 + "&Gstat2=" + Gstat2 + "&Gstat3=" + Gstat3 + "&Gstat4=" + Gstat4 + "&Gstat5=" + Gstat5 + "&Gstat6=" + Gstat6;
	
	var action = "javascript:ajaxpage('game.php?section=lobby&a=create&a1=submit&" + values + "', 'mainbody')";
		
	document.creation.action = action;
	document.creation.submit();
}
function doHair() {
    document.getElementById('createtip').innerHTML="You have selected the hair DNA strand. <br><br>Select a molecule from the left to splice into the strand. <br><br>You can see your choice on the little display on the left and what it will do to your Canadian.";
	unselect();
    document.gHairS.src="images/gui/sel.gif";
	document.M1.style.visibility="visible";
	document.M1.src=hairmolecule[0];
	document.M2.style.visibility="visible";
	document.M2.src=hairmolecule[1];
	document.M3.style.visibility="visible";
	document.M3.src=hairmolecule[2];
	document.M4.style.visibility="visible";
	document.M4.src=hairmolecule[3];
	document.creation.strand.value="h";
	if (document.creation.Ghair.value != "" ) { document.Strand.src="images/gui/strand"+document.creation.Ghair.value+".gif"; } else {document.Strand.src = "images/gui/strand.gif";}
	}
	function doSkin() {
        document.getElementById('createtip').innerHTML="You have selected the skin DNA strand.<br><br>Select a molecule from the left to splice into the strand. <BR><BR> You can see your choice on the little display on the left and what it will do to your Canadian.";
        unselect();
        document.gSkinS.src="images/gui/sel.gif";
	document.M1.style.visibility="visible";
	document.M1.src=bodymolecule[0];
	document.M2.style.visibility="visible";
	document.M2.src=bodymolecule[1];
	document.M3.style.visibility="visible";
	document.M3.src=bodymolecule[2];
	document.M4.style.visibility="hidden";
	document.creation.strand.value="s";
	if (document.creation.Gskin.value != "" ) { document.Strand.src="images/gui/strand"+document.creation.Gskin.value+".gif"; } else {document.Strand.src = "images/gui/strand.gif";}
	}
	function doSex(x) {
	document.creation.Gsex.value=x;
	if (document.creation.Gsex.value == "m" ) { document.MALE.src="images/gui/male_on.gif"; document.FEMALE.src="images/gui/female.gif";}
	if (document.creation.Gsex.value == "f" ) { document.FEMALE.src="images/gui/female_on.gif"; document.MALE.src="images/gui/male.gif";}
	}
	function doStat(x) {
        document.getElementById('createtip').innerHTML="You have selected a statistic DNA strand. <br><br>Choose a molecule on the left to augment your Canadians starting statistics.<br><br>From top to bottom, they are Strength, Dexterity, Speed and Vitality.";
        unselect();
        if (x == "1" ) {document.gStat1S.src="images/gui/sel.gif";  }
        if (x == "2" ) {document.gStat2S.src="images/gui/sel.gif";  }
        if (x == "3" ) {document.gStat3S.src="images/gui/sel.gif";  }
        if (x == "4" ) {document.gStat4S.src="images/gui/sel.gif";  }
        if (x == "5" ) {document.gStat5S.src="images/gui/sel.gif";  }
        if (x == "6" ) {document.gStat6S.src="images/gui/sel.gif";  }

	if (document.creation.Gstat1.value == "" && x=="1") { document.Strand.src = "images/gui/strand.gif"; }
	if (document.creation.Gstat2.value == "" && x=="2") { document.Strand.src = "images/gui/strand.gif"; }
	if (document.creation.Gstat3.value == "" && x=="3") { document.Strand.src = "images/gui/strand.gif"; }
	if (document.creation.Gstat4.value == "" && x=="4") { document.Strand.src = "images/gui/strand.gif"; }
	if (document.creation.Gstat5.value == "" && x=="5") { document.Strand.src = "images/gui/strand.gif"; }
	if (document.creation.Gstat6.value == "" && x=="6") { document.Strand.src = "images/gui/strand.gif"; }
	document.M1.style.visibility="visible";
	document.M2.style.visibility="visible";
	document.M3.style.visibility="visible";
	document.M4.style.visibility="visible";
	document.creation.strand.value=x;
	if (document.creation.Gstat1.value != ""  && x=="1") { document.Strand.src="images/gui/strand"+document.creation.Gstat1.value+".gif"; }
	if (document.creation.Gstat2.value != ""  && x=="2") { document.Strand.src="images/gui/strand"+document.creation.Gstat2.value+".gif"; }
	if (document.creation.Gstat3.value != ""  && x=="3") { document.Strand.src="images/gui/strand"+document.creation.Gstat3.value+".gif"; }
	if (document.creation.Gstat4.value != ""  && x=="4") { document.Strand.src="images/gui/strand"+document.creation.Gstat4.value+".gif"; }
	if (document.creation.Gstat5.value != ""  && x=="5") { document.Strand.src="images/gui/strand"+document.creation.Gstat5.value+".gif"; }
	if (document.creation.Gstat6.value != ""  && x=="6") { document.Strand.src="images/gui/strand"+document.creation.Gstat6.value+".gif"; }
	}
	function doMolecule(x) {
	document.creation.molecule.value=x;
	if (document.creation.strand.value == "h") { document.pichair.src=hair[x-1]; document.creation.Ghair.value=x; document.gHair.src="images/gui/full.gif";}
	if (document.creation.strand.value == "s") { document.picbody.src=body[x-1]; document.creation.Gskin.value=x; document.gSkin.src="images/gui/full.gif";}
	if (document.creation.strand.value == "1")  { document.creation.Gstat1.value=x; document.gStat1.src="images/gui/full.gif";}
	if (document.creation.strand.value == "2")  { document.creation.Gstat2.value=x; document.gStat2.src="images/gui/full.gif";}
	if (document.creation.strand.value == "3")  { document.creation.Gstat3.value=x; document.gStat3.src="images/gui/full.gif";}
	if (document.creation.strand.value == "4")  { document.creation.Gstat4.value=x; document.gStat4.src="images/gui/full.gif";}
	if (document.creation.strand.value == "5")  { document.creation.Gstat5.value=x; document.gStat5.src="images/gui/full.gif";}
	if (document.creation.strand.value == "6")  { document.creation.Gstat6.value=x; document.gStat6.src="images/gui/full.gif";}
	document.Strand.src="images/gui/strand"+x+".gif";
	}
    function unselect() {
        document.gHairS.src="images/gui/sel_none.gif";
        document.gSkinS.src="images/gui/sel_none.gif";
        document.gStat1S.src="images/gui/sel_none.gif";
        document.gStat2S.src="images/gui/sel_none.gif";
        document.gStat3S.src="images/gui/sel_none.gif";
        document.gStat4S.src="images/gui/sel_none.gif";
        document.gStat5S.src="images/gui/sel_none.gif";
        document.gStat6S.src="images/gui/sel_none.gif";
    }
	function reset() {
	document.creation.characterName.value=""
	document.creation.molecule.value=""
	document.creation.strand.value=""
	document.creation.Ghair.value=""
	document.creation.Gskin.value=""
	document.creation.Gstat1.value=""
	document.creation.Gstat2.value=""
	document.creation.Gstat3.value=""
	document.creation.Gstat4.value=""
	document.creation.Gstat5.value=""
	document.creation.Gstat6.value=""
	document.creation.Gsex.value=""
	document.picbody.src="images/avatars/human/avatar_body1b.gif";
	document.pichair.src="images/avatars/hair/avatar_haira1.gif";
	document.gHair.src="images/gui/empty.gif";
	document.gSkin.src="images/gui/empty.gif";
	document.gStat1.src="images/gui/empty.gif";
	document.gStat2.src="images/gui/empty.gif";
	document.gStat3.src="images/gui/empty.gif";
	document.gStat4.src="images/gui/empty.gif";
	document.gStat5.src="images/gui/empty.gif";
	document.gStat6.src="images/gui/empty.gif";
	document.MALE.src="images/gui/male.gif";
	document.FEMALE.src="images/gui/female.gif";
	document.Strand.src="images/gui/strand.gif";
	doHair();
	}
function refreshform() {

	if (document.creation.Gstat1.value != "") {
		document.gStat1.src="images/gui/full.gif"; }
	else { document.gStat1.src="images/gui/empty.gif"; }
	if (document.creation.Gstat2.value != "") {
		document.gStat2.src="images/gui/full.gif"; }
	else { document.gStat2.src="images/gui/empty.gif"; }
	if (document.creation.Gstat3.value != "") {
		document.gStat3.src="images/gui/full.gif"; }
	else { document.gStat3.src="images/gui/empty.gif"; }
	if (document.creation.Gstat4.value != "") {
		document.gStat4.src="images/gui/full.gif"; }
	else { document.gStat4.src="../images/gui/empty.gif"; }
	if (document.creation.Gstat5.value != "") {
		document.gStat5.src="images/gui/full.gif"; }
	else { document.gStat5.src="images/gui/empty.gif"; }
	if (document.creation.Gstat6.value != "") {
		document.gStat6.src="images/gui/full.gif"; }
	else { document.gStat6.src="images/gui/empty.gif"; }
	if (document.creation.Gstat6.value != "") {
		document.gStat6.src="images/gui/full.gif"; }
	else { document.gStat6.src="images/gui/empty.gif"; }
	if (document.creation.Gskin.value != "") {
		document.gSkin.src="images/gui/full.gif";
		document.picbody.src=body[document.creation.Gskin.value-1];  }
	else { document.gSkin.src="images/gui/empty.gif"; }
	if (document.creation.Ghair.value != "") {
		document.gHair.src="images/gui/full.gif"; 
		document.pichair.src=hair[document.creation.Ghair.value-1]; }
	else { document.gHair.src="images/gui/empty.gif"; }
	document.MALE.src="images/gui/male.gif";
	document.FEMALE.src="images/gui/female.gif";
	if (document.creation.Gsex.value=="f") { 
		document.FEMALE.src="images/gui/female_on.gif"; }
	if (document.creation.Gsex.value=="m") { 
		document.MALE.src="images/gui/male_on.gif"; }
}
function doLogin() {
	var username = document.login_form.username.value;
	var password = document.login_form.password.value;
	var action = "javascript:ajaxpage('esAjax.php?a=loginCheck&username=" + username + "&password=" + password + "', 'loginError', true)";
	document.login_form.action = action;
    document.login_form.submit();
}
