function linkOn(divid){
	document.getElementById(divid).style.backgroundColor = '770000';
	document.getElementById(divid).style.fontWeight = 'bold';
	document.getElementById(divid).style.color = 'ffffff';
}
function linkOff(divid,change){
	if (change == 'renew'){
		document.getElementById(divid).style.backgroundColor = 'ffaaaa';
	} else {
		document.getElementById(divid).style.backgroundColor = 'cccccc';
	}
	document.getElementById(divid).style.fontWeight = 'normal';
	document.getElementById(divid).style.color = '000000';
}
function gameLinkOn(divid){
	document.getElementById(divid).style.backgroundColor = '111111';
	document.getElementById(divid).style.color = 'ffffff';
}
function gameLinkOff(divid){
	document.getElementById(divid).style.backgroundColor = 'cccccc';
	document.getElementById(divid).style.color = '000000';
}
function viewFight(id){
	window.location="showfight.php?fight="+id;
}
function changeAttire(order,type,color,id,id2){
	if (type == 'tattoos'){
		type = 'tattoo';
	}
	if (type == 'pants'){
		type='attire';
	}
	if (order == '1'){
		url = 'game_images/'+type+'/'+type+id+'_'+color+'.png';
	} else {
		url = 'game_images/'+type+'/'+type+id+'_second/second'+id2+'_'+color+'.png';
	}
	
	z=type+order;
	parent.avatar.document.getElementById(z).src=url;
}
function changeLook(type,id){
	if (type == 'frame'){
		url = 'game_images/frames/frame'+id+'.png';
		z= 'frame';
	} else if (type == 'physique'){
		url = 'game_images/physiques/phys'+id+'.png';
		z= 'physique';		
	} else if (type == 'eyes'){
		url = 'game_images/eyes/eyes'+id+'.png';
		z= 'eyes';		
	} else if (type == 'face'){
		url = 'game_images/faces/face'+id+'.png';
		z= 'face';		
	} else if (type == 'mouth'){
		url = 'game_images/mouth/mouth'+id+'.png';
		z= 'mouth';		
	} else if (type == 'nose'){
		url = 'game_images/nose/nose'+id+'.png';
		z= 'nose';		
	} else if (type == 'hair_type'){
		if (id == 0){
			//parent.frames['avatar'].document.getElementById('hair').style.visibility='hidden';
			parent.avatar.document.getElementById('hair').style.visibility='hidden';
		} else {
			//parent.frames['avatar'].document.getElementById('hair').style.visibility='visible';
			parent.avatar.document.getElementById('hair').style.visibility='visible';
		}
		color = document.getElementById('hair_color').value;
		url = 'game_images/hair/hair'+id+'_'+color+'.png';
		z= 'hair';
	} else if (type == 'fhair'){
		if (id == 0){
			//parent.frames['avatar'].document.getElementById('fhair').style.visibility='hidden';
			parent.avatar.document.getElementById('fhair').style.visibility='hidden';
		} else {
			//parent.frames['avatar'].document.getElementById('fhair').style.visibility='visible';
			parent.avatar.document.getElementById('fhair').style.visibility='visible';
		}
		color = document.getElementById('hair_color').value;
		url = 'game_images/fhair/fhair'+id+'_'+color+'.png';
		z= 'fhair';
	} else if (type == 'hair_color'){
		type = document.getElementById('hair_type').value;
		url = 'game_images/hair/hair'+type+'_'+id+'.png';
		z= 'hair';
		
		type = document.getElementById('fhair').value;
		url2 = 'game_images/fhair/fhair'+type+'_'+id+'.png';
		//parent.frames['avatar'].document.getElementById('fhair').src=url2;
		parent.avatar.document.getElementById('fhair').src=url2;	
	}
	//parent.frames['avatar'].document.getElementById(z).src=url;
	parent.avatar.document.getElementById(z).src=url;
}
function textcheck()
{
	if(document.commentform.comments.value.length > 500){
		document.commentform.comments.value = document.commentform.comments.value.substring(0,500)
	}
	document.getElementById("charleft").innerHTML= 500-(document.commentform.comments.value.length) 
}
window.latestClick = '';
function isNotDblClick(objectID) {
	if(window.latestClick != objectID) {
		window.latestClick = objectID;
		window.location = "recruit.php";
	} else {
		return false;
	}
}
function retireFighter(){
	var answer = confirm("Retire this fighter?")
	if (answer){
		document.retire.submit();
	} else {
		alert("Your fighter was not retired")
	}


}
function buyOutContract(){
	var answer = confirm("Do you want to buy out this fighters contract?")
	if (answer){
		document.buyOut.submit();
	} else {
		alert("The contract was not bought out.")
	}


}

function openNotepad(styleOp){
	if (document.getElementById('noteContent').style.display == 'none'){
		document.getElementById('noteContent').style.display = 'block'
		document.getElementById('noteImg').src = 'core_images/'+styleOp+'/mini.png';
		setCookie('notepadOpen', 1);
	} else {
		document.getElementById('noteContent').style.display = 'none';
		document.getElementById('noteImg').src = 'core_images/'+styleOp+'/max.png';
		setCookie('notepadOpen', 0);
	}
}
function setCookie(name, value){
	var expdate = new Date ();
	expires = expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 1365);
	document.cookie = name + "=" + escape(value) + "; expires=Thu, 2 Aug 2020 20:47:11 UTC; path=/";
}

var oldSpar
function spar(id){
	id = document.getElementById('idref'+id).value
	sparOff(oldSpar)
	sparOn(id)
}
function sparOn(id){
	document.getElementById('wr_spar'+id).style.display = 'block';
	document.getElementById('sm_spar'+id).style.display = 'block';
	document.getElementById('jj_spar'+id).style.display = 'block';
	document.getElementById('jd_spar'+id).style.display = 'block';
	document.getElementById('bx_spar'+id).style.display = 'block';
	document.getElementById('ma_spar'+id).style.display = 'block';
	document.getElementById('mt_spar'+id).style.display = 'block';
	document.getElementById('br_spar'+id).style.display = 'block';
	document.getElementById('cn_spar'+id).style.display = 'block';
	document.getElementById('st_spar'+id).style.display = 'block';
	document.getElementById('ft_spar'+id).style.display = 'block';
	document.getElementById('sp_spar'+id).style.display = 'block';
	document.getElementById('fl_spar'+id).style.display = 'block';
	document.getElementById('bl_spar'+id).style.display = 'block';
	document.getElementById('rf_spar'+id).style.display = 'block';
	document.getElementById('pw_spar'+id).style.display = 'block';
	oldSpar=id
}
function sparOff(id){
	document.getElementById('wr_spar'+id).style.display = 'none';
	document.getElementById('sm_spar'+id).style.display = 'none';
	document.getElementById('jj_spar'+id).style.display = 'none';
	document.getElementById('jd_spar'+id).style.display = 'none';
	document.getElementById('bx_spar'+id).style.display = 'none';
	document.getElementById('ma_spar'+id).style.display = 'none';
	document.getElementById('mt_spar'+id).style.display = 'none';
	document.getElementById('br_spar'+id).style.display = 'none';
	document.getElementById('cn_spar'+id).style.display = 'none';
	document.getElementById('st_spar'+id).style.display = 'none';
	document.getElementById('ft_spar'+id).style.display = 'none';
	document.getElementById('sp_spar'+id).style.display = 'none';
	document.getElementById('fl_spar'+id).style.display = 'none';
	document.getElementById('bl_spar'+id).style.display = 'none';
	document.getElementById('rf_spar'+id).style.display = 'none';
	document.getElementById('pw_spar'+id).style.display = 'none';

}
function sparLoad(){
	id = document.getElementById('partner').value
	id = document.getElementById('idref'+id).value
	sparOn(id)
}
function styleSwap(type,num){
	document.getElementById(type+document.getElementById(type+'Hidden').value).style.display='none';
	document.getElementById(type+num).style.display='block';
	document.getElementById(type+'Hidden').value = num;
}  

noteOn=1;
function noteSave(){
	if (noteOn ==1){
		noteChange();
		noteOn=0;
	}
}
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		document.getElementById('p_status').innerHTML = 
		'Status: Cound not create XmlHttpRequest Object.' +
		'Consider upgrading your browser.';
	}
}
var noteReq = getXmlHttpRequestObject();

function noteChange() {
	if (noteReq .readyState == 4 || noteReq .readyState == 0) {
		var newValue = document.getElementById('notepad').value.replace(new RegExp( "\\n", "g" ),'<br>');
		noteReq.open("GET", 'noteSave.php?type='+document.getElementById('padType').value+'&num='+document.getElementById('padNum').value+'&value='+newValue, true);
		noteReq.onreadystatechange = handleNoteChange; 
		noteReq.send(null);
	}			
}

function handleNoteChange() {
	if (noteReq .readyState == 4) {
		alert(noteReq.responseText);
		noteOn=1;
	}
}

function tutorialLoad(tutPosition){
	if (document.getElementById('tutorialBox'+tutPosition) != null){
		document.getElementById('tutorialBox'+tutPosition).style.display='block';
		tutChange(tutPosition);
	}
}

function tutorialClose(tutPosition){
	tutPosition = parseInt(tutPosition);
	document.getElementById('tutorialBox'+tutPosition).style.display='none';
	if (document.getElementById('tutorialBox'+(tutPosition+1)) != null){
		document.getElementById('tutorialBox'+(tutPosition+1)).style.display='block';
		tutChange(tutPosition);
	}
}

var tutReq = getXmlHttpRequestObject();

function tutChange(tutPos) {
	if (tutReq .readyState == 4 || tutReq .readyState == 0) {
		tutReq.open("GET", 'tutSave.php?position='+tutPos, true);
		tutReq.onreadystatechange = handleTutChange; 
		tutReq.send(null);
	}			
}

function handleTutChange() {
	if (tutReq .readyState == 4) {
	}
}

var fightListReq = getXmlHttpRequestObject();
var numHold=0;
function fightList(id,classType) {
	if (fightListReq .readyState == 4 || fightListReq .readyState == 0) {
		if (document.getElementById('fightList'+id).innerHTML.search("Loading...") != -1){
			numHold=id;
			fightListReq.open("GET", 'fightList.php?id='+id+'&class='+classType, true);
			fightListReq.onreadystatechange = handleFightList; 
			fightListReq.send(null);
		}
	}			
}

function handleFightList() {
	if (fightListReq .readyState == 4) {
		document.getElementById('fightList'+numHold).innerHTML=fightListReq.responseText;
	}
}

function expandChalRow(id,classType){
	fightList(id,classType);
	document.getElementById('row'+id).style.display='block';
	document.getElementById('chalButton'+id).style.display='none';
	document.getElementById('collapseButton'+id).style.display='block';
}

function collapseChalRow(id){
	document.getElementById('row'+id).style.display='none';
	document.getElementById('chalButton'+id).style.display='block';
	document.getElementById('collapseButton'+id).style.display='none';
}

var chalReq = getXmlHttpRequestObject();
var holdId = '';
function challenge(id) {
	if (chalReq .readyState == 4 || chalReq .readyState == 0) {
		holdId=id;
		var fighterId=document.getElementById('fighterId').value;
		var pri=document.getElementById('pri'+id).value;
		var sec=document.getElementById('sec'+id).value;
		chalReq.open("GET", 'sendChallenge.php?id='+fighterId+'&recipient='+id+'&pri='+pri+'&sec='+sec, true);
		chalReq.onreadystatechange = handleChallenge; 
		chalReq.send(null);
	}			
}

function handleChallenge() {
	if (chalReq .readyState == 4) {
		var chalResult = chalReq.responseText.split("-");
		if (chalResult[0]=='sent'){
			document.getElementById('chalButton'+holdId).className = 'sent'; 
			document.getElementById('chalButton'+holdId).value='sent';
			document.getElementById('collapseButton'+holdId).className = 'sent'; 
			
			document.getElementById('send'+holdId).style.display='none';
			document.getElementById('retract'+holdId).style.display='block';			
			
			document.getElementById('chalId'+holdId).value=chalResult[1];			
		} else {
			alert(chalResult[1]);
		}
	}
}

var chalRemReq = getXmlHttpRequestObject();
function chalRemove(id,type) {
	if (chalRemReq .readyState == 4 || chalRemReq .readyState == 0) {
		holdId=id;
		var chalId=document.getElementById('chalId'+id).value;
		chalRemReq.open("GET", 'retractChallenge.php?id='+chalId+'&type='+type, true);
		chalRemReq.onreadystatechange = handleChalRemove; 
		chalRemReq.send(null);
	}			
}



function handleChalRemove() {
	if (chalRemReq .readyState == 4) {
		var chalResult = chalRemReq.responseText.split("-");
		if (chalResult[0]=='retracted'){
			document.getElementById('chalButton'+holdId).className = 'challenge'; 
			document.getElementById('chalButton'+holdId).value='challenge';
			document.getElementById('collapseButton'+holdId).className = 'challenge'; 
			
			document.getElementById('send'+holdId).style.display='block';
			document.getElementById('retract'+holdId).style.display='none';	
			document.getElementById('accept'+holdId).style.display='none';	
			document.getElementById('deny'+holdId).style.display='none';			
			
			document.getElementById('chalId'+holdId).value='0';			
		} else {
			alert(chalResult[1]);
		}
	}
}