// Array of month Names
var monthNames = new Array(
"January","February","March","April","May","June","July",
"August","September","October","November","December");

function acceptWar(){
	document.getElementById('media2choose').style.display = "block";
   	//document.getElementById('youtubeStatus').innerHTML = "(please copy and paste the embed code or permalink for the video into the box above...)";
	document.getElementById("sub").style.display = "inline"; //show submit button
	document.getElementById("fightimg2").style.display = "inline";
	document.getElementById("btnYoutube").style.display = "none";
	document.getElementById("fightimg1").style.display = "none";
}

function defendWar(){
    if(!document.form1.url2.value){
	alert('Please select media to send into battle.');
    }else if(document.form1.cat1.value=='default'){
	alert('Please choose a category.');
    }else{
	document.form1.submit();
    }
}

function checkWar(){
    if(DOM('cat1').value=='default'){
	alert('Please choose a category');
    }else if(document.form1.newbie && document.form1.newbie.value) {
	if(document.form1.newbie.value && (document.form1.newbie.value.indexOf('@')==0 || document.form1.newbie.value.indexOf('@')==-1) ){
	    alert('That does not appear to be a proper email address. Please double check. at'+document.form1.newbie.value.indexOf('@'));
	}
    }else if(document.form1.warChest && document.form1.warChest.value != '' && !isNumeric(document.form1.warChest.value) ){
	alert('Please only enter numbers for the war chest amount.');
    }else {
	document.form1.submit();
    }
}

function addComment(warid,username,type){ //type: 1 = war comment, 2 = player
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	var comment = document.getElementById('comment').value;

	if (comment == ''){alert('Please enter a comment.');return;}
	//variables
	objList = document.getElementById('commentList');
	//create the new nodes
	objListElement = document.createElement('li');
	objBreak = document.createElement('br');
	objTextNode = document.createTextNode(comment);
	var timestamp = new Date();
	var minutes = timestamp.getMinutes();
	if (minutes < 10){
		minutes = "0" + minutes
	}
	var dateNum = timestamp.getDate();
	if (dateNum < 10){
		dateNum = "0" + dateNum
	}
	objTextNodeName = '- by '+username+' at '+timestamp.getHours()+':'+minutes+' on '+dateNum+' '+monthNames[timestamp.getMonth()]+' '+timestamp.getFullYear();
	objSpan = document.createElement('span');	
	objSpan.style.fontSize="10px";
	objSpan.innerHTML = objTextNodeName;
	//now connect them to the list
	objListElement.appendChild(objTextNode);
	objListElement.appendChild(objBreak);
	objListElement.appendChild(objSpan);
	objList.appendChild(objListElement);
	
	// receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.getElementById('debug').innerHTML = 'TARNATION!';
			document.getElementById('comment').value = "";
			if(document.getElementById('noComment')){
				document.getElementById('noComment').style.display='none';
			}
			if(ajaxRequest.responseText == 'over'){
				alert('You have reached your maximum comment limit for this war.');
				document.commentForm.subComment.disabled='true';	
			}
			//alert(ajaxRequest.responseText);			
		}
	}
	var params = "warid="+warid+"&comment="+comment+"&type="+type;
	if(document.getElementById('user')){
		params = params+"&user="+document.getElementById('user').value;
	}
		//Send the proper header information along with the request
	
	ajaxRequest.open("POST", "process.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", params.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(params);	

}

function negotiateWar(warid, username) {

    var subRate1 = document.getElementById('subRate1').value;
    var subRate2 = document.getElementById('subRate2').value;
    
    var callback = function (text, xml) {
		var scores = text.split(',');
	
	    if(!subRate1 || !subRate2 || subRate1 == 0 || subRate2 == 0) {
	    	alert('You must give a score to both media');
			return;
		}
	    if(subRate1==subRate2){
			alert("There are no stalemates, draws or ties in Media Wars.  Therefore you may not give each media the same rating.  Please select another rating");
			return;
		} 
		
		if(document.getElementById('checkboxes')) {
		    document.getElementById('checkboxes').style.display='none';
		}
	
		if(scores[2]) {
		    //document.getElementById('score1neg').innerHTML=scores[2];
		    //document.getElementById('score2neg').innerHTML=scores[3];
		}
	  
		if(scores[4] && scores[4] != "...") {
		    document.getElementById('score1overall').innerHTML=scores[4];
		    document.getElementById('score2overall').innerHTML=scores[5];	
		}
		
		document.getElementById('rateStatus').innerHTML='Thank you! Your negotiation has been recorded.';
		if (document.getElementById('diplomacyDiv')) {
		    document.getElementById('diplomacyDiv').style.display = "none";
		}
    }    
    submitWarRating(warid, username, subRate1, subRate2, 'negotiate_war.php', callback);
}

function fightWar(warid, username) {    
    if(username == 'Guest') {
	//we allow visitors to fight wars if
	//border control is set to Allow Foreign Arms
	//alert('You must login to fight wars!');
	//return false;
    }

    var rate1 = document.getElementById('mediaCheckbox1').checked;
    var rate2 = document.getElementById('mediaCheckbox2').checked;
    
    if(!rate1 && !rate2){
	alert('Please select media to fight war!');
	return false;
    } else if (rate1) {
	rate1 = 10;
	rate2 = 1;
    } else if (rate2) {
	rate1 = 1;
	rate2 = 10;
    }

    var callback = function(response, responseData) {
		var scores = response.split(',');
	
		document.getElementById('checkboxes').style.display='none';	
	
		if(scores[0]) {
		    document.getElementById('score1overall').innerHTML=scores[4];
		    document.getElementById('score2overall').innerHTML=scores[5];	
		    document.getElementById('score1').innerHTML=scores[0];
		    document.getElementById('score2').innerHTML=scores[1]; 
		}
		document.getElementById('rateStatus').innerHTML='Thank you! Your war support has been recorded.';
		
		if (document.getElementById('diplomacyDiv')) {
		    document.getElementById('diplomacyDiv').style.display = "none";
		}
    }

    submitWarRating(warid, username, rate1, rate2, "rate_war.php", callback);
}

function submitWarRating (warid, username, rate1, rate2, fileName, callback) {
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser does not support this action!");
				return false;
			}
		}
	}	
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){			
			var response = ajaxRequest.responseText;
			var xml      = ajaxRequest.responseXML;			
			if(callback) {
			    callback(response, xml);
			}
		}
	}

	var params = "warid="+warid+"&score1="+rate1+"&score2="+rate2+"&user="+username;

	ajaxRequest.open("POST", fileName, true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", params.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(params); 
}

function rateWars(warid, user){
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	//var ratings = parseFloat(document.getElementById('ratings').value);
	var rate1 = parseFloat(document.getElementById('subRate1').value);
	var rate2 = parseFloat(document.getElementById('subRate2').value);
	//var score1 = parseFloat(document.getElementById('score1').innerHTML);
	//var score2 = parseFloat(document.getElementById('score2').innerHTML);
	//var newScore1 = ((score1*ratings)+rate1)/(ratings+1);
	//var newScore2 = ((score2*ratings)+rate2)/(ratings+1);
	
	//newScore1=newScore1.toFixed(2);
	//newScore2=newScore2.toFixed(2);
	
	if(!rate1 || !rate2){
		alert('Please rate both media...');
		return;
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.getElementById('debug').innerHTML = 'TARNATION!';
			var response = ajaxRequest.responseText;
			var score1 = response.substr(0,response.search(','));
			var score2 = response.substr(response.search(',')+1);
			document.getElementById('submitRatings').style.display='none';
			document.getElementById('rate1').style.display='none';
			document.getElementById('rate2').style.display='none';	
			document.getElementById('score1').innerHTML=score1;
			document.getElementById('score2').innerHTML=score2;
			document.getElementById('rateStatus').innerHTML='Thank you! Your ratings have been tallied.';
			//document.getElementById('debug').innerHTML = ajaxRequest.responseText;
		}
	}
	
	var params = "warid="+warid+"&score1="+rate1+"&score2="+rate2+"&user="+user;
		
		//Send the proper header information along with the request
	
	ajaxRequest.open("POST", "rate_war.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", params.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(params);	
}

function placeBid(side){
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	var user2 = document.getElementById('bidOpponent'+side).value;
	var bidAmt = document.getElementById('bidAmt'+side).value;
	var mediaCode = document.getElementById('mediaCode'+side).value;
	var warID = document.getElementById('warID').value;
	
	if (user2 == '(please choose)'){
		alert("Please select a friend to bid against.");
		return;
	}else if (bidAmt == '' || bidAmt < 10 ){
		alert("Please bid at least 10 points.");
		return;
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			alert(ajaxRequest.responseText);
			if(ajaxRequest.responseText.search("Suc") != -1){
				document.getElementById('bidForm'+side).style.display = 'none';
				document.getElementById('bidLink'+side).style.display = 'block';
				document.getElementById('bidLink'+side).innerHTML = 'Success! <a href="javascript:preBid('+side+')">Bid Again On This Media</a>';
			}else if(ajaxRequest.responseText.search("limit") != -1){
				//location.reload("true");
			}
		}
	}
	
	var params = "warID="+warID+"&mediaCode="+mediaCode+"&user2="+user2+"&bidAmt="+bidAmt;
		
	//Send the proper header information along with the request
	
	ajaxRequest.open("POST", "bid_war.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", params.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(params);	
}

function acceptBid(wagerID){
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}		
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(ajaxRequest.responseText.search("accepted") != -1){
				alert(trim(ajaxRequest.responseText));
				document.getElementById('wager'+wagerID).innerHTML = 'Bid accepted! Good Luck!';
			}else{
				alert(ajaxRequest.responseText);
			}
		}
	}
	var params = "wagerID="+wagerID+"&action=accept";
	//Send the proper header information along with the request
	ajaxRequest.open("POST", "bid_war.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", params.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(params);	
}

function rejectBid(wagerID){
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}		
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(ajaxRequest.responseText.search("declined") != -1){
				document.getElementById('wager'+wagerID).innerHTML = 'Bid rejected!';
			}else{
				alert(ajaxRequest.responseText);
			}
		}
	}
	var params = "wagerID="+wagerID+"&action=decline";
	//Send the proper header information along with the request
	ajaxRequest.open("POST", "bid_war.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", params.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(params);	
}

var hasVoted = 0;
function rateSet(side,score){
	var otherSide;
	if (side==1){ otherSide = 2;} else { otherSide = 1;}
	//console.log(document.getElementById('subRate1').value + ":" + document.getElementById('subRate2').value);
	document.getElementById('subRate'+side).value = score;
	var score1=document.getElementById('subRate1').value;
	var score2=document.getElementById('subRate2').value;
	if(1) {
		for(i = 1; i<11;i++){
			document.getElementById('rate'+side+'-'+i).innerHTML = '<a href="javascript:rateSet('+side+','+i+')" style="font-size:12px">'+i+'</a>';
			if (hasVoted==0){
				document.getElementById('rate'+otherSide+'-'+i).innerHTML = '<a href="javascript:rateSet('+otherSide+','+i+')" style="font-size:12px">'+i+'</a>';
			}
		}	
		document.getElementById('rate'+side+'-'+score).innerHTML = '<a href="javascript:rateSet('+side+','+score+')" style="font-size:22px">'+score+'</a>';
		if (hasVoted==0){
			document.getElementById('rate'+otherSide+'-'+(11-score)).innerHTML = '<a href="javascript:rateSet('+otherSide+','+(11-score)+')" style="font-size:22px">'+(11-score)+'</a>';
			document.getElementById('subRate'+otherSide).value = (11-score);
		}
	}
	hasVoted = 1;
}

function preBid(side){
	document.getElementById('bidForm'+side).style.display = 'block';
	document.getElementById('bidLink'+side).style.display = 'none';
}

var flagVis = 0;
function showFlag(){
	if(flagVis == 0){
		document.getElementById('flagArea').style.display = 'block';
		flagVis = 1;
	}else if(flagVis == 1){
		document.getElementById('flagArea').style.display = 'none';
		flagVis = 0;
	}		
}

function flagMedia(warid){
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.getElementById('debug').innerHTML = 'TARNATION!';
			//document.getElementById('flag'+side).innerHTML='Successfully flagged, thank you.';
			document.getElementById('flag').innerHTML=ajaxRequest.responseText;
			alert(ajaxRequest.responseText);
			document.getElementById('flagArea').style.display = 'none';
			//alert(document.getElementById('flagComment').value);		
		}
	}
	
	var params = "warid="+warid+"&comment="+escape(document.getElementById('flagComment').value);
	//Send the proper header information along with the request
	ajaxRequest.open("POST", "flag_media.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", params.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(params);	
}

function showSupport(num) {
	if(num==1){var side='left';}
	else if(num==2){var side='right';}
	document.getElementById(side+'MediaSupB').style.display = "none";
	document.getElementById(side+'MediaSupC').style.display = "block";
}
function hideSupport(num) {
	if(num==1){var side='left';}
	else if(num==2){var side='right';}
	document.getElementById(side+'MediaSupC').style.display = "none";
	document.getElementById(side+'MediaSupB').style.display = "block";
}

var showUsers = 0; //set up flag to keep track of soldiers or bidders.

function showBidders(warid,page) {
	resetDisplayLinks(warid);
	var ajaxRequest; //setting up ajax
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	if(page == 'hide'){
		showUsers = 0;
		document.getElementById('soldiersBidders').innerHTML = '';	
		document.getElementById('showBidderLink').innerHTML = 'Show Speculation';	
		document.getElementById('showBidderLink').href= "javascript:showBidders('"+warid+"','1')";
		if(document.getElementById('showSoldierLink')){
			document.getElementById('showSoldierLink').innerHTML = 'Display Soldiers';
			document.getElementById('showSoldierLink').href= "javascript:showSoldiersInit('"+warid+"','show')";
		}
		if(document.getElementById('showDiplomatLink')) {
			document.getElementById('showDiplomatLink').innerHTML = 'Display Diplomats';
			document.getElementById('showDiplomatLink').href= "javascript:showDiplomatsInit('"+warid+"','show')";
		}
		return;
	}else{
		showUsers = 1;
		document.getElementById('showBidderLink').innerHTML = 'Hide Speculation';
		document.getElementById('showBidderLink').href= "javascript:showBidders('"+warid+"','hide')";
		if(document.getElementById('showSoldierLink')){
			document.getElementById('showSoldierLink').innerHTML = 'Display Soldiers';	
			document.getElementById('showSoldierLink').href= "javascript:showSoldiersInit('"+warid+"','show')";
		}
		if(document.getElementById('showDiplomatLink')) {
			document.getElementById('showDiplomatLink').innerHTML = 'Display Diplomats';
			document.getElementById('showDiplomatLink').href= "javascript:showDiplomatsInit('"+warid+"','show')";
		}
		ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4 && page!='hide'){
				document.getElementById('soldiersBidders').innerHTML=ajaxRequest.responseText;//show output of get bidders to soldierBidders box	
			}
		}		
		var params = "warid="+warid+"&page="+page;
		//Send the proper header information along with the request
		ajaxRequest.open("POST", "functions/get-bidders.php", true);
		ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxRequest.setRequestHeader("Content-length", params.length);
		ajaxRequest.setRequestHeader("Connection", "close");
		ajaxRequest.send(params);	
	} //set flag to show or hide users area
}//end showBidders


function resetDisplayLinks(warid) {
    if(document.getElementById('showSoldierLink')) {
	document.getElementById('showSoldierLink').innerHTML = 'Display Soldiers';
	document.getElementById('showSoldierLink').href= "javascript:showSoldiersInit('"+warid+"','show')";
    }

    if(document.getElementById('showDiplomatLink')) {
	document.getElementById('showDiplomatLink').innerHTML = 'Display Diplomats';
	document.getElementById('showDiplomatLink').href= "javascript:showDiplomatsInit('"+warid+"','show')";
    }

    if(document.getElementById('showBidderLink')) {
	document.getElementById('showBidderLink').innerHTML = 'Display Speculation';
	document.getElementById('showBidderLink').href= "javascript:showBidders('"+warid+"','1')";
    }
}

function showSoldiersInit(warid,command){ //this function is just used to open and close the users view area for displaying soldiers. the actual lists are genereated with showSoldiers
    resetDisplayLinks(warid);

	if(command == 'hide'){
		showUsers = 0;
		document.getElementById('soldiersBidders').innerHTML = '';	
		document.getElementById('showSoldierLink').innerHTML = 'Display Soldiers';	
		document.getElementById('showSoldierLink').href= "javascript:showSoldiersInit('"+warid+"','show')";
		if(document.getElementById('showBidderLink')){
			document.getElementById('showBidderLink').innerHTML = 'Show Speculation';	
			document.getElementById('showBidderLink').href= "javascript:showBidders('"+warid+"','1')";
		}
		return;
	}else{
		showUsers = 1;	
		document.getElementById('showSoldierLink').innerHTML = 'Hide Soldiers';
		document.getElementById('showSoldierLink').href= "javascript:showSoldiersInit('"+warid+"','hide')";
		if(document.getElementById('showBidderLink')){
			document.getElementById('showBidderLink').innerHTML = 'Show Speculation';	
			document.getElementById('showBidderLink').href= "javascript:showBidders('"+warid+"','1')";
		}
		document.getElementById('soldiersBidders').innerHTML = '<div class="warLeftSide" id="soldiersSide1"></div><div class="warRightSide" id="soldiersSide2"></div>';
		showSoldiers(warid,1,1); //get lists for interior cells
		showSoldiers(warid,1,2);
	}
}


function showDiplomatsInit(warid,command){
    resetDisplayLinks(warid);

	if(command == 'hide'){
		showUsers = 0;
		document.getElementById('soldiersBidders').innerHTML = '';
		document.getElementById('showDiplomatLink').innerHTML = 'Display Diplomats';
		document.getElementById('showDiplomatLink').href= "javascript:showDiplomatsInit('"+warid+"','show')";	
		if(document.getElementById('showBidderLink')){		
		    document.getElementById('showBidderLink').innerHTML = 'Show Speculation';
		    document.getElementById('showBidderLink').href= "javascript:showBidders('"+warid+"','1')";
		}
		return;
	}else{
		showUsers = 1;
		document.getElementById('showDiplomatLink').innerHTML = 'Hide Diplomats';
		document.getElementById('showDiplomatLink').href= "javascript:showDiplomatsInit('"+warid+"','hide')";
		if(document.getElementById('showBidderLink')){
			document.getElementById('showBidderLink').innerHTML = 'Show Speculation';
			document.getElementById('showBidderLink').href= "javascript:showBidders('"+warid+"','1')";
		}
		document.getElementById('soldiersBidders').innerHTML = '<div class="warLeftSide" id="diplomatsSide1"></div><div class="warRightSide" id="diplomatsSide2"></div>';
		showDiplomats(warid,1,1);
		showDiplomats(warid,1,2);
	}
}

function showSoldiers(warid,page,side) {
	var ajaxRequest; //setting up ajax
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	

	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4 && page!='hide'){
			document.getElementById('soldiersSide'+side).innerHTML=ajaxRequest.responseText;//show output of get bidders to soldierBidders box	
		}
	}		
	var params = "warid="+warid+"&page="+page+"&side="+side;
	//Send the proper header information along with the request
	ajaxRequest.open("POST", "functions/get-soldiers.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", params.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(params);	
}//end showSoldiers

function showDiplomats(warid,page,side) {
	var ajaxRequest; //setting up ajax
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}

	ajaxRequest.onreadystatechange = function(){
	    if(ajaxRequest.readyState == 4 && page!='hide') {
			document.getElementById('diplomatsSide'+side).innerHTML=ajaxRequest.responseText;
		}
	}	   
	var params = "warid="+warid+"&page="+page+"&side="+side;
	ajaxRequest.open("POST", "functions/get-diplomats.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", params.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(params);
}


function stopRKey(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 howToPopUp(){
	window.open("howtopopup.php","Window1",
	"menubar=no,width=430,height=360,toolbar=no,scrollbars=yes");
}
function deploymentListPopUp(){
	window.open("deploymentlistpop.php","Window1",
	"menubar=no,width=430,height=360,toolbar=no,scrollbars=yes");
}
function durationPopUp(){
	window.open("durationpop.php","Window1",
	"menubar=no,width=430,height=360,toolbar=no,scrollbars=yes");
}
function biddingPopUp(){
	window.open("biddingpop.php","Window1",
	"menubar=no,width=430,height=360,toolbar=no,scrollbars=yes");
}
function warchestPopUp(){
	window.open("warchestpop.php","Window1",
	"menubar=no,width=430,height=360,toolbar=no,scrollbars=yes");
}
function baaderPopUp(){
	window.open("baaderpop.php","Window1",
	"menubar=no,width=430,height=360,toolbar=no,scrollbars=yes");
}
function bidfrequencyPopUp(){
	window.open("bidfrequencypop.php","Window1",
	"menubar=no,width=430,height=360,toolbar=no,scrollbars=yes");
}
function defensefrequencyPopUp(){
	window.open("defensefrequencypop.php","Window1",
	"menubar=no,width=430,height=360,toolbar=no,scrollbars=yes");
}
function intelPopUp(){
	window.open("intelpopup.php","Window1",
	"menubar=no,width=430,height=360,toolbar=no,scrollbars=yes");
}
function trim(str) { return str.replace(/^\s+|\s+$/g, ''); }


function isNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;
}

document.onkeypress = stopRKey;
