




var my_base_url='http://www.usofearth.com/';
var my_pligg_base='/community';


dochref = document.location.href.substr(document.location.href.search('/')+2, 1000);
if(dochref.search('/') == -1){
	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref;
} else {
	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref.substr(0, dochref.search('/'));
}
$thisurl = $thisurl + '/community';

var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
  try {
	xmlhttp = new XMLHttpRequest ();
  }
  catch (e) {
  xmlhttp = false}
}

function myXMLHttpRequest ()
{
  var xmlhttplocal;
  try {
  	xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}
  catch (e) {
	try {
	xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}
	catch (E) {
	  xmlhttplocal = false;
	}
  }

  if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
	try {
	  var xmlhttplocal = new XMLHttpRequest ();
	}
	catch (e) {
	  var xmlhttplocal = false;
	}
  }
  return (xmlhttplocal);
}

var mnmxmlhttp = Array ();
var xvotesString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;

function getPrefecture(val,id)
{
  	showMapCounty(false);
	if (xmlhttp) 
	{
	    url = "getPrefecture.php";	
		var mycontent = "val=" + val;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
					if(response) 
					{ 
                    	var temp = val.split('-');
                        PrefectureName = temp[2];
                        LongName = temp[3];
                    	var obj = response.split('$');
                        p1 = obj[0];
                        p2 = obj[1];
                        p3 = obj[2];
						currentState = obj[5];
                        showMap('Prefecture',asMapBoxWidth,asMapBoxHeight,0,id);
                        document.getElementById("inner_content_div5").innerHTML = obj[6];
                        //document.getElementById("rightoflogo").innerHTML = obj[7] + "'s History";
                        document.getElementById("historyTab").innerHTML = obj[7] + "'s News";
                        if(obj[7].indexOf("Free") != -1)
                        	topLeft(false);
                        stateId = obj[8];
                        PrefectureId = obj[9];
                        getTopPlayer('ArmySize',stateId,PrefectureId,'');
                        getPrefectureHistory();
					} 
				} 
			}  
		}
	}
}

function setChallenge(challengeId, time1, time2, time3, defenderId) {
  if (xmlhttp) {
    url = "setChallenge.php"; 
    var mycontent = "currentClick=" + currentClick 
      + "&challengeId=" + challengeId 
      + "&time1=" + time1
      + "&time2=" + time2
      + "&time3=" + time3
      + "&defenderId=" + defenderId;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
            if(response) { 
                if(mnmxmlhttp.responseText != 'done') {
                  alert(mnmxmlhttp.responseText);
                } else {
                  alert("The challenge has been set.");
                  clearTargetInfo();
                  showMapCounty();
                }
          } 
        } 
      }  
    }
  }
}

function getTroops(val)
{
	if (xmlhttp) 
	{
	    document.getElementById("troopsDiv").innerHTML = "<p align='center'><img src='templates/yget/images/loader.gif' /></p>";
	    document.getElementById("light").value = 0;
	    document.getElementById("medium").value = 0;
	    document.getElementById("heavy").value = 0;
    	url = "gettroops.php";	
		var mycontent = "val=" + val;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
					if(response) 
					{ 
                        document.getElementById("troopsDiv").innerHTML = response;
                        getResultLog(val);
					} 
				} 
			}  
		}
	}

}

function getPoints(val) {
  if (xmlhttp)   {
    url = "getPoints.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            var data = mnmxmlhttp.responseText.split('|||');
            attackerCommunity = data[0];
            attackerKnowledge = data[1];
          } 
        } 
      }  
    }
  }
}

function getCommunityPost(val) {
  if (xmlhttp)   {
    url = "getCommunityPost.php";  
    var mycontent = "category=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            document.getElementById("communityContents").innerHTML = response;
            setSelected('communityTabs',val) 
          } 
        } 
      }  
    }
  }
}

function getTopPlayer(val,stateId,PrefectureId,searchUser) {
  if (xmlhttp)   {
    url = "getTopPlayer.php";  
    var mycontent = "val=" + val + "&stateId="+stateId + "&PrefectureId=" + PrefectureId+"&searchUser="+searchUser;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            document.getElementById("topPlayersContents").innerHTML = response;
            setSelected('topPlayersTabs',val) 
            currentTab = val;
            if(searchUser == '')
            {
                document.getElementById("topPlayersTabs").style.visibility = "visible";
            }
            else
            {
                document.getElementById("topPlayersTabs").style.visibility = "hidden";
            }
          } 
        } 
      }  
    }
  }
}

function getCombatLogs(type,page) 
{
    currentTab = val;
    if (xmlhttp)   
    {
        url = "getCombatLogs.php";  
        var mycontent = "type=" + type + "&page=" + page;
        var mnmxmlhttp = new myXMLHttpRequest ();
        if (mnmxmlhttp) 
        {
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
            {
                if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                { 
                    var response = mnmxmlhttp.responseText;
                    if(response) 
                    { 
                    	var data = response.split('$');
                        document.getElementById("logsContents").innerHTML = data[0];
                        document.getElementById("logFulList").innerHTML = "";
                        if(type == "CombatLogs")
                        {
                        	if(response.indexOf("No") == -1)
	                        	document.getElementById("logFulList").innerHTML = '<table border="0"><tr><td style="vertical-align:bottom;text-align:right">' + data[1] + '</td><td style="vertical-align:top;text-align:right;width:60px"><a href="viewmsg.php" id="fullHistory">Full History</a></td></tr></table></div>';
                        }
                        else
                        {
                        	if(response.indexOf("No") == -1)
	                            document.getElementById("logFulList").innerHTML = '<table border="0"><tr><td style="vertical-align:top;text-align:right">' + data[1] + '</td><td style="vertical-align:top;text-align:right;width:50px"><a href="viewmsg.php?op=news" id="fullHistory">Full List</a></td></tr></table></div>';
                        }
                        setSelected('combatTabs',type) 
                    } 
		        } 
      		}  
    	}
  	}
}

function addprefecturecomment(logid)
{
	if (xmlhttp)   
    {
	    url = "addprefecturecomment.php";  
    	var mycontent = "logid=" + logid;
	    var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
        {
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
            {
        		if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                { 
                    var response = mnmxmlhttp.responseText;
                    if(response) 
                    {
	                    document.getElementById("addPrefectureComments").innerHTML = response;
                        document.getElementById("commentTabs").innerHTML = '<b>The Victor Writes The News!</b>';
                    } 
                } 
            }  
        }
    }
}

function addPComment()
{
	if (xmlhttp)   
    {
	    url = "addprefecturecomment.php";  
        headLine = document.prefectureForm.headLine.value;
        comments = document.prefectureForm.comments.value;
        logid = document.prefectureForm.logid.value;
    	var mycontent = "submit=1&headLine=" + headLine + "&comments="+ comments + "&logid=" + logid + "&stateid=" + stateId + "&PrefectureId=" + PrefectureId;
	    var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
        {
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
            {
        		if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                { 
                    var response = mnmxmlhttp.responseText;
                    if(response) 
                    {
                    	document.getElementById("addPrefectureComments").innerHTML = '<img src="templates/yget/images/bcomment.png" />';
                        document.getElementById("commentTabs").innerHTML = '<b>WIN A BLITZKRIEG TO UNLOCK THIS FEATURE</b>';
                        getCombatLogs('CombatLogs',1);
                        getPrefectureHistory();
                    } 
                } 
            }  
        }
    }
}

function getPrefectureHistory()
{
	if (xmlhttp)   
    {
	    url = "getPrefectureHistory.php";  
    	var mycontent = "stateid=" + stateId + "&PrefectureId=" + PrefectureId;
	    var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
        {
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
            {
        		if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                { 
                    var response = mnmxmlhttp.responseText;
                    if(response) 
                    {
	                    document.getElementById("prectureContents").innerHTML = response;
                    } 
                } 
            }  
        }
    }
}

function getTargetInfoByMId(mapId)
{
	if (xmlhttp)   
    {
	    url = "getTargetInfoByMId.php";  
    	var mycontent = "mapid=" + mapId;
	    var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
        {
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
            {
        		if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                { 
                    var response = mnmxmlhttp.responseText;
                    if(response == "NOT OK") 
                    {
	                    alert("You are not allowed to attack your district.");
                    } 
                    else
                    {
                        getPrefecture(response);
                    	myCounty(mapId,1);
                    }
                } 
            }  
        }
    }
}

function showResourcesRecruits() {
  if (xmlhttp)   {
    url = "showResourcesRecruits.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) {
            setRightSideSelected("Resources");
            document.getElementById("topRightBox").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showResourcesBorrowPoints() {
  if (xmlhttp)   {
    url = "showResourcesBorrowPoints.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) {
            document.getElementById("topRightBox").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showResourcesLogs() {
  if (xmlhttp)   {
    url = "showResourcesLogs.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) {
            document.getElementById("topRightBox").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showResourcesStartBank() {
  if (xmlhttp)   {
    url = "showResourcesStartBank.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) {
            document.getElementById("topRightBox").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showAssembleOffensive() {
  if (xmlhttp)   {
    url = "showAssembleOffensive.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) {
            setRightSideSelected("Assemble");
            document.getElementById("topRightBox").innerHTML = response;
            loadAssembledTroops();
          } 
        } 
      }  
    }
  }
}

function showAssembleDefensive() {
  if (xmlhttp)   {
    url = "showAssembleDefensive.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            document.getElementById("topRightBox").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showAssembleMoveTroops() {
  if (xmlhttp)   {
    url = "showAssembleMoveTroops.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) {
            document.getElementById("topRightBox").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showAssembleOnDuty() {
  if (xmlhttp)   {
    url = "showAssembleOnDuty.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            document.getElementById("topRightBox").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showAttacks() {
  if (xmlhttp)   {
    url = "showAttacks.php";  
    var mycontent = "val=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            setRightSideSelected("Assemble");
            document.getElementById("topRightBox").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showCombatLog(animationType) {
  if (xmlhttp)   {
    url = "showCombatLog.php";  
    var mycontent = "animationType=" + animationType 
      + "&val=" + val
      + "&currentClick=" + currentClick
      + "&light=" + offLight
      + "&med=" + offMed
      + "&heavy=" + offHeavy
      + "&district=" + offDistrict;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            document.getElementById("topRightBox").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showBlitzNegotiation() {
  if (xmlhttp)   {
    url = "showBlitzkrieg.php";  
    var mycontent = "currentClick=" + currentClick;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            document.getElementById("attackAnimation").innerHTML = response;
          } 
        } 
      }  
    }
  }
}

function showConquestNegotiation() {
  if (xmlhttp)   {
    url = "showConquest.php";  
    var mycontent = "id=" + founderUserId
      + "&type=" + founderEntityType;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            if (response.substr(0,5) == "ERROR") {
              alert(response.substr(5));
              clearTargetInfo();
              showMapCounty();
            } else {
              document.getElementById("attackAnimation").innerHTML = response;
            }
          } 
        } 
      }  
    }
  }
}

function showEradicationNegotiation() {
  if (xmlhttp)   {
    url = "showEradication.php";  
    var mycontent = "currentClick=" + currentClick;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            if (response.substr(0,5) == "ERROR") {
              alert(response.substr(5));
              clearTargetInfo();
              showMapCounty();
            } else {
              document.getElementById("attackAnimation").innerHTML = response;
            }
          } 
        } 
      }  
    }
  }
}

function showPrefectConflictNegotiation() {
  if (xmlhttp)   {
    url = "showPrefectConflict.php";  
    var mycontent = "currentClick=" + currentClick;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) { 
          var response = mnmxmlhttp.responseText;
          if(response) { 
            if (response.substr(0,5) == "ERROR") {
              alert(response.substr(5));
              clearTargetInfo();
              showMapCounty();
            } else {
              document.getElementById("attackAnimation").innerHTML = response;
            }
          } 
        } 
      }  
    }
  }
}

function getCountyXML(county,state,width,height,divName,clickURL)
{
	if (xmlhttp) 
	{
    	document.getElementById(divName).innerHTML = "<img src='templates/yget/images/loader.gif' />";
		url = "getCounty.php";	
		var mycontent = "width=" + width + "&county=" + county + "&state=" + state + "&clickURL=" + clickURL;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
					if(response) 
					{ 
                    	if(divName== '')
                        	divName = "mapdiv";
                        
                        var data = mnmxmlhttp.responseText.split('-');
                        var map = new FusionMaps("flash/USA/"+state+"/" + county + ".swf", "Map1Id1", width, height, "0", "0");
                        map.setDataXML(data[0]);
                        map.render(divName);
                        
                        if(document.getElementById("mapNameDiv") != null && divName=='mapdiv')
							document.getElementById("mapNameDiv").innerHTML = data[1];
                        
                        if(document.getElementById("prefecturehistory") != null && divName=='mapdiv')
              			document.getElementById("prefecturehistory").style.visibility = "hidden";    
                        
                        
					} 
				} 
			}  
		}
	}
}

function getStateXML(currentState,width,height,divName)
{
	if (xmlhttp) 
	{
    	document.getElementById(divName).innerHTML = "<img src='templates/yget/images/loader.gif' />";
		url = "getState.php";	
		var mycontent = "currentState=" + currentState;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
                    if(response) 
					{ 
                        var data = mnmxmlhttp.responseText.split('-');
                        var map = new FusionMaps("flash/USA/" + currentState + ".swf", "Map1Id1", width, height, "0", "0");
                        map.setDataXML(data[0]);
                        map.render(divName);
                        
                        if(document.getElementById("mapNameDiv") != null)
							document.getElementById("mapNameDiv").innerHTML = data[1];
							
                         if(document.getElementById("prefecturehistory") != null)
              document.getElementById("prefecturehistory").style.visibility = "hidden";
					} 
				} 
			}  
		}
	}
}

function getNewAttackResult(type)
{
    if (xmlhttp) 
    {
        url = "getNewAttackResult.php";
        var mycontent = "val=" + type
          + "&attacker=" + val 
          + "&currentClick=" + currentClick
          + "&light=" + offLight
          + "&medium=" + offMed
          + "&heavy=" + offHeavy
          + "&dtroopsValue=" + offDistrict
          + "&entity=" + offEntities;
        var mnmxmlhttp = new myXMLHttpRequest ();
        if (mnmxmlhttp) 
        {
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
            {
                if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                { 
                    var response = mnmxmlhttp.responseText;
                    if(response) 
                    { 
	                    alert(response);
	                    clearTargetInfo();
	                    getUserInfo();
	                    showMapCounty();
                        getCombatLogs('CombatLogs',1);
	                 }
          		} 
        	} 
      	}  
  	}
}

function getFounderAttackResult(val,currentClick,troops,entity,entityVal,attacker,dtroopsValue,negData,founderUserId,founderAllainceId)
{
	if (xmlhttp) 
	{
		url = "getFounderAttackResult.php";	
		var mycontent = "val=" + val + "&currentClick=" + currentClick+"&troops=" + troops+"&dtroopsValue="+dtroopsValue+"&attacker="+attacker+"&entity="+entity+"&entityVal="+entityVal+"&negData="+negData+"&founderUserId="+founderUserId+"&founderAllainceId="+founderAllainceId;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
                  	if(response) 
					{ 
                    	if(mnmxmlhttp.responseText == 'You have already attacked this territory today.')
                        {
                    		alert(mnmxmlhttp.responseText);
                        }
                        else
                        {
							getChart(0); 
                        	getResultLog(attacker);
	                        if(val == '6' || val =='7' || val == '8')
                            {
                            	getTroops(attacker);
                            }
                        }
					} 
				} 
			}  
		}
	}
}

function getInfo()
{
	if (xmlhttp) 
	{
		url = "getInfo.php";	
		var mycontent = "currentClick=" + currentClick
            + "&founderUserId=" + founderUserId
            + "&founderEntityType=" + founderEntityType
            + "&userId=" + targetUserId
            + "&targetArr=" + targetArr.toString()
            + "&curTargetIndex=" + curTargetIndex;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var data = mnmxmlhttp.responseText.split('|||');
					defenderLightTroops = data[0];
					defenderMedTroops = data[1];
					defenderHeavyTroops = data[2];
					defenderCommunity = data[3];
					defenderKnowledge = data[4];
					document.getElementById("targetCommander").innerHTML = data[5];
					document.getElementById("targetTable").innerHTML = data[6];
					//document.getElementById("targetLinks").innerHTML = data[7];
                    document.getElementById("addfriend").innerHTML = data[9];
                    currentClick = data[8];
				} 
			}  
		}
	}
}

function getUserInfo() {
  if (xmlhttp) {
    url = "getUserInfo.php";  
    var mycontent = "";
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) 
      {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() 
      {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
        { 
          var data = mnmxmlhttp.responseText.split('|||');
          document.getElementById("userTable").innerHTML = data[0];
          userChart1 = data[1];
          userChart2 = data[2];
          userChart3 = data[3];
          userChart4 = data[4];
          points = data[5];
          
          viewUserCharts();
        } 
      }  
    }
  }
}

function setBlitz() {
  if (xmlhttp) {
    var url = "getBlitzkriegResult.php";
    isdistrict = 0;

	if(document.negotiation.isdistrict != null)
    {
		if(document.negotiation.isdistrict.checked)
			isdistrict = 1;
    }
    
    var mycontent = "currentClick=" + currentClick
      + "&light=" + offLight
      + "&med=" + offMed
      + "&heavy=" + offHeavy
      + "&entity=" + offEntities
      + "&district=" + offDistrict
      + "&attacker=" + val
      + "&points=" + document.negotiation.points.value
      + "&homagePoints=" + document.negotiation.homagePoints.value
      + "&homagePeriod=" + document.negotiation.homagePeriod.value
      + "&isdistrict=" + isdistrict;
      
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() 
      {
        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
        {
            var response = mnmxmlhttp.responseText;
            if(response) 
            { 
                alert(response);
                clearTargetInfo();
                showMapCounty();
                getCombatLogs('CombatLogs',1);
            }  
        }
      }
    }
  }
}

function setConquest() {
  if (xmlhttp) {
    var url = "getConquestResult.php";
    var mycontent = "currentClick=" + currentClick
      + "&light=" + offLight
      + "&med=" + offMed
      + "&heavy=" + offHeavy
      + "&district=" + offDistrict
      + "&entity=" + offEntities
      + "&attacker=" + val
      + "&defender=" + founderUserId
      + "&defenderType=" + founderEntityType
      + "&points=" + document.negotiation.points.value
      + "&homagePoints=" + document.negotiation.homagePoints.value
      + "&homagePeriod=" + document.negotiation.homagePeriod.value;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {

        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) {
          var response = mnmxmlhttp.responseText;
          if(response) { 
            alert(response);
            clearTargetInfo();
            showMapCounty();    
            getCombatLogs('CombatLogs',1);    
           }  
        }
      }
    }
  }
}

function setEradication() {
  if (xmlhttp) {
    var url = "getEradicationResult.php";
    var mycontent = "currentClick=" + currentClick
      + "&attacker=" + val
      + "&points=" + document.negotiation.points.value
      + "&homagePoints=" + document.negotiation.homagePoints.value
      + "&homagePeriod=" + document.negotiation.homagePeriod.value;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {

        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
        {
            var response = mnmxmlhttp.responseText;
            if(response) 
            { 
                  alert(response);
                  clearTargetInfo();
                  showMapCounty();
                  getCombatLogs('CombatLogs',1);
            }  
        }
      }
    }
  }
}

function setPrefectConflict() {
  if (xmlhttp) {
	  var chForm = document.negotiation;
	  var time0 = getFullTime(chForm.day0, chForm.hour0, chForm.min0);
	  var time1 = getFullTime(chForm.day1, chForm.hour1, chForm.min1);
	  var time2 = getFullTime(chForm.day2, chForm.hour2, chForm.min2);
	  
	  var url = "getPrefectConflictResult.php";
	  var mycontent = "currentClick=" + currentClick
	    + "&attacker=" + val
	    + "&light=" + offLight
	    + "&med=" + offMed
	    + "&heavy=" + offHeavy
	    + "&entity=" + offEntities
	    + "&district=" + offDistrict
	    + "&points=" + chForm.points.value
	    + "&homagePoints=" + chForm.homagePoints.value
	    + "&homagePeriod=" + chForm.homagePeriod.value
	    + "&challengeId=" + chForm.challenge.value 
	    + "&time0=" + time0
	    + "&time1=" + time1
	    + "&time2=" + time2;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {

        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) {
                  var response = mnmxmlhttp.responseText;
                    if(response) 
          { 
                      alert(response);
                      clearTargetInfo();
                      showMapCounty();
           }  
        }
      }
    }
  }
}

function setNetInfo() {
  
  if (xmlhttp) {
    var url = "getNetInfoResult.php";
    var mycontent = "currentClick=" + currentClick
      + "&attacker=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {

        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) {
          var response = mnmxmlhttp.responseText;
          if(response) { 
            alert(response);
            clearTargetInfo();
            getUserInfo();
            showMapCounty();
          }  
        }
      }
    }
  }
}

function setProtestRiot() {
  
  if (xmlhttp) {
    var url = "getProtestRiotResult.php";
    var mycontent = "currentClick=" + currentClick
      + "&attacker=" + val;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {

        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) {
          var response = mnmxmlhttp.responseText;
          if(response) { 
            alert(response);
            clearTargetInfo();
            getUserInfo();
            showMapCounty();
          }  
        }
      }
    }
  }
}

function setAssembleDefensive(entity, defenceType, fortification) 
{  
    if (xmlhttp) 
    {
    	var url = "setAssembleDefensive.php";
    	var mycontent = "attacker=" + val
        + "&entity=" + entity
        + "&defenceType=" + defenceType
        + "&fortification=" + fortification;
	    var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
        {
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
            {
            	if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                {
				    var response = mnmxmlhttp.responseText;
				    if(response) 
                    { 
                        alert(response);
                        showAssembleDefensive();
                        getUserInfo();
				    }  
    			}
    		}
    	}
    }
}

function setAssembleMoveTroops(entity, light, med, heavy, district, to) {
  
  if (xmlhttp) {
    var url = "setAssembleMoveTroops.php";
    var mycontent = "attacker=" + val
      + "&entity=" + entity
      + "&light=" + light
      + "&med=" + med
      + "&heavy=" + heavy
      + "&district=" + district
      + "&to=" + to;
    var mnmxmlhttp = new myXMLHttpRequest ();
    if (mnmxmlhttp) {
      mnmxmlhttp.open ("POST", url, true);
      mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
      mnmxmlhttp.send (mycontent);
      mnmxmlhttp.onreadystatechange = function() {

        if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) {
          var response = mnmxmlhttp.responseText;
          if(response) { 
            alert(response);
            showAssembleMoveTroops();
          }  
        }
      }
    }
  }
}

function setResourcesRecruits(entity, light, med, heavy) 
{
    if (xmlhttp) 
    {
        var url = "setResourcesRecruits.php";
        var mycontent = "attacker=" + val
        + "&entity=" + entity
        + "&light=" + light
        + "&med=" + med
        + "&heavy=" + heavy;
	    var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
        {
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
            {
    		    if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                {
					var response = mnmxmlhttp.responseText;
					if(response) 
                    { 
                        alert(response);
                        showResourcesRecruits();
                        getUserInfo();
					}  
				}
                document.getElementById("submitbtn").disabled=false;
			}
		}
	}
}

function setResourcesBorrowPoints(id, amount) 
{
    if (xmlhttp) 
    {
    	var url = "setResourcesBorrowPoints.php";
    	var mycontent = "attacker=" + val
                        + "&bank_id=" + id
                        + "&amount=" + amount;
	    var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
        {
            mnmxmlhttp.open ("POST", url, true);
            mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
            mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
            {
    			if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                {
					var response = mnmxmlhttp.responseText;
					if(response) 
                    { 
                        alert(response);
                        showResourcesBorrowPoints();
                        getUserInfo();
					}  
				}
			}
		}
	}
}

function getList(val,isFileName)
{
	if(document.getElementById("founder") != null)
	{
        if (xmlhttp) 
        {
            document.getElementById("founder").innerHTML = "<img src='templates/yget/images/loader.gif' />";
            url = "getList.php";	
            var mycontent = "val=" + val+ "&isFileName="+isFileName + "&currentState="+currentState;
            var mnmxmlhttp = new myXMLHttpRequest ();
            if (mnmxmlhttp) 
            {
                mnmxmlhttp.open ("POST", url, true);
                mnmxmlhttp.setRequestHeader ('Content-Type',
                               'application/x-www-form-urlencoded');
                mnmxmlhttp.send (mycontent);
                mnmxmlhttp.onreadystatechange = function() 
                {
                    if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
                    { 
                        var response = mnmxmlhttp.responseText;
                        if(response) 
                        { 
                            document.getElementById("founder").innerHTML = mnmxmlhttp.responseText ;
                        } 
                    } 
                }  
            }
        }
	}
}

function getResultLog(val)
{
	if (xmlhttp) 
	{
		url = "getResultLog.php";	
		var mnmxmlhttp = new myXMLHttpRequest ();
        var mycontent = "val=" + val;
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
            mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
					if(response) 
					{ 
                    	if(document.getElementById("attackerlogs") != null)
	                        document.getElementById("attackerlogs").innerHTML = mnmxmlhttp.responseText;    
					} 
				} 
			}  
		}
	}
}

function getChart(p)
{
	if (xmlhttp) 
	{
		url = "getChart.php";	
		var mycontent = "p=" + p 
                            + "&currentClick=" + currentClick
                            + "&founderUserId=" + founderUserId
                            + "&founderEntityType=" + founderEntityType
                            + "&userId=" + targetUserId;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
					if(response) 
					{ 
                    	if(response != 'You are not authorized to view the information.')
                        {
                        	var data = mnmxmlhttp.responseText.split('$');
                            targetChart1 = data[0];
                            targetChart2 = data[1];
                            targetChart3 = data[2];
                            targetChart4 = data[3];
                            viewTargetCharts(targetChart1, targetChart2, targetChart3, targetChart4);
                            if (p == 100 || p == 2)
                            {
                                getUserInfo();
							}
                        }
                        else
                        {
                            alert(response);
                        }
					} 
				} 
			}  
		}
	}
}

function getPrefectureStats(prefecture,p)
{
	if (xmlhttp) 
	{
		url = "getPrefectureStats.php";	
		var mycontent = "p="+ p + "&prefecture=" + prefecture;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
					if(response) 
					{ 
                        document.getElementById("chart1").innerHTML = mnmxmlhttp.responseText;
                        if(document.getElementById("chartData") != null)
	                        document.getElementById("chartData").innerHTML = escape(response);
					} 
                    
				} 
			}  
		}
	}
}

function getPollChart(id,type,div)
{
	if (xmlhttp) 
	{
		url = "getPollChart.php";	
		var mycontent = "id="+ id + "&type=" + type;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
					if(response) 
					{ 
                        if(mnmxmlhttp.responseText != 'No Data')
	                        document.getElementById(div).innerHTML = mnmxmlhttp.responseText;
					}                    
				} 
			}  
		}
	}
}

function getIndividualStats(County,id,p,username)
{
	if (xmlhttp) 
	{
		url = "getIndividualStats.php";	
		var mycontent = "p="+p+"&County=" + County + "&id=" + id + "&username=" + username;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
					if(response) 
					{ 
            document.getElementById("chart1").innerHTML = mnmxmlhttp.responseText;
          }

				} 
			}  
		}
	}
}

function getPrefectureList()
{
	if (xmlhttp) 
	{
		url = "getPrefectureList.php";	
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.onreadystatechange = function() 
			{
            	if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
                    if(response) 
					{ 
                        document.getElementById("p1").innerHTML = response;
					} 
				} 
			}  
		}
	}
}


function getCountyStats(County,p)
{
	if (xmlhttp) 
	{
		url = "getCountyStats.php";	
		var mycontent = "p="+p+"&County=" + County;
		var mnmxmlhttp = new myXMLHttpRequest ();
    	if (mnmxmlhttp) 
		{
    		mnmxmlhttp.open ("POST", url, true);
			mnmxmlhttp.setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
			mnmxmlhttp.send (mycontent);
			mnmxmlhttp.onreadystatechange = function() 
			{
				if (mnmxmlhttp.readyState == 4 && mnmxmlhttp.status == 200) 
				{ 
					var response = mnmxmlhttp.responseText;
                    if(response) 
					{ 
             document.getElementById("chart1").innerHTML = mnmxmlhttp.responseText;
					} 
				} 
			}  
		}
	}
}

function vote (user, id, htmlid, md5, value)
{
  	if (xmlhttp) {
		url = $thisurl + "/vote.php";
		var mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;
        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");    
    			target1 = document.getElementById ('xvotes-' + htmlid);    
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
							changemnmvalues (htmlid, value, true);    					} else {
														if (xvotesString[htmlid].substring (1, 6) == "ERROR") { alert(xvotesString[htmlid]);  } else {changemnmvalues (htmlid, value, false); }     					}
    				}
    			}
    		}
    	}
	}
}


function evote (user, id, htmlid, md5, value, type, pos)
{
  	if (xmlhttp) {
		url = $thisurl + "/evote.php";
		var mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value + "&type=" + type;
		anonymous_vote = false;
        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");    
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) 
                    {
                    	if(type == "poll")
             	           getPollChart(id,pos,'chart'+pos)
                        else if(type == "topiclinks")
                        {
                        	document.getElementById("topiclink"+id).innerHTML = '<div class="votesAlready">VOTED</div>';
                            document.getElementById("topiclinkcount"+id).innerHTML = mnmxmlhttp[htmlid].responseText;
                        }
                        else
                        {
                        	document.getElementById("advote"+id).innerHTML = '<div class="votesAlready">VOTED</div>';
                            document.getElementById("adcounter"+id).innerHTML = mnmxmlhttp[htmlid].responseText;
                        }
    				}
    			}
    		}
    	}
	}
}


function unvote (user, id, htmlid, md5, value)
{
  	if (xmlhttp) {
		url = $thisurl + "/vote.php";
		var mycontent = "unvote=true&id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;
        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");    
				target1 = document.getElementById ('xvotes-' + htmlid);
  				target2 = document.getElementById ('xvote-' + htmlid);    
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						 xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
							changemnmvalues (htmlid, value, true);target2.innerHTML = "<span>Vote</span>";						} else {
							if (xvotesString[htmlid].substring (1, 6) == "ERROR") { alert(xvotesString[htmlid]);  } else {target2.innerHTML = "<span>Vote</span>";changemnmvalues (htmlid, value, false); }							
    					}
    				}
    			}
    		}
    	}
	}
}


function cvote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = $thisurl + "/cvote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;

        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);        
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
    						changecvotevalues (htmlid, true);							
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "Thank you for rating this comment.";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function etvote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = $thisurl + "/etvote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;

        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);        
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
                        if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
    						changecvotevalues (htmlid, true);							
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "Thank you for rating this comment.";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function eavote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = $thisurl + "/eavote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;

        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);        
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
                        if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
    						changecvotevalues (htmlid, true);							
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "Thank you for rating this comment.";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function epvote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = $thisurl + "/epvote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;

        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);        
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
                        if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
    						changecvotevalues (htmlid, true);							
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "Thank you for rating this comment.";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function ckvote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = $thisurl + "/ckvote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;

        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);        
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
    						changecvotevalues (htmlid, true);							
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "Thank you for rating this comment.";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function cavote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = $thisurl + "/cavote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;

        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);        
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
    						changecvotevalues (htmlid, true);							
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "Thank you for rating this comment.";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function chvote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = $thisurl + "/chvote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;

        if (anonymous_vote == false && user == '0') {
            window.location="http://www.usofearth.com//community/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);        
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
    						changecvotevalues (htmlid, true);							
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "Thank you for rating this comment.";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function changemnmvalues (id, value, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	//alert(id);
	target1 = document.getElementById ('xvotes-' + id);
	target2 = document.getElementById ('xvote-' + id);
	target3 = document.getElementById ('xreport-' + id);
	target4 = document.getElementById ('xnews-' + id);
	if (error) {
		if (value > 0) { target2.innerHTML = "<span>Voted</span> "; }
		else if (value < 0) { target2.innerHTML = "<span>Buried</span> "; }
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
		new Effect.Fade(target3);
		if (value > 0) { target2.innerHTML = "<span>Voted</span> "; }
		else if (value < 0 ) { target2.innerHTML = "<span>Buried</span> ";
													new Effect.Opacity(target4, {duration:0.8, from:1.0, to:0.3}); }
	}
	return false;
}

function changecvotevalues (id, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	target1 = document.getElementById ('cvote-' + id);
	if (error) {
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
	}
	return false;
}


function enablebutton (button, button2, target)
{
	var string = target.value;
	button2.disabled = false;
	if (string.length > 0) {
		button.disabled = false;
	} else {
		button.disabled = true;
	}
}

function checkfield (type, form, field)
{
	url = $thisurl + '/checkfield.php?type='+type+'&name=' + field.value;
	checkitxmlhttp = new myXMLHttpRequest ();
	checkitxmlhttp.open ("GET", url, true);
	checkitxmlhttp.onreadystatechange = function () {
		if (checkitxmlhttp.readyState == 4) {
		responsestring = checkitxmlhttp.responseText;
			if (responsestring == 'OK') {
				document.getElementById (field.name+'checkitvalue').innerHTML = '<span style="color:black">"' + field.value + 
						'": ' + responsestring + '</span>';
				form.submit.disabled = '';
			} else {
				document.getElementById (field.name+'checkitvalue').innerHTML = '<span style="color:red">"' + field.value + '": ' +
				responsestring + '</span>';
				form.submit.disabled = '';
			}
		}
	}
  checkitxmlhttp.send (null);
  return false;
}

function emailto (original_id, htmlid, instpath, address_count)
{
	email_message = document.getElementById('email_message' + htmlid).value;
	email_address = document.getElementById('email_address_1_' + htmlid).value;
	if (address_count > 1){ 
		for ($i = 2; $i <= address_count; $i++) {
			if(document.getElementById('email_address_' + $i + '_' + htmlid).value != "") {
				email_address = email_address + ', ' + document.getElementById('email_address_' + $i + '_' + htmlid).value;
			}
		}
	}
	
	if (xmlhttp) {
		url = $thisurl + "/recommend.php";
		mycontent = "email_address=" + escape(email_address) + "&email_to_submit=submit&email_message=" + escape(email_message) + "&original_id=" + original_id + "&backup=0";
		target2 = document.getElementById ('emailto-' + htmlid);
		target2.innerHTML = "<br>Sending, please wait....";
		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
			
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];						
					} else {
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
		}
	}
}

function show_recommend(htmlid, linkid, instpath)
{
	var emailtodisplay=document.getElementById('emailto-' + htmlid).style.display ? '' : 'none';
	document.getElementById('emailto-' + htmlid).style.display = emailtodisplay;

	if (xmlhttp) {
		url = $thisurl + "/recommend.php";
		mycontent = "draw=small&htmlid=" + htmlid + "&linkid=" + linkid;
		target2 = document.getElementById ('emailto-' + htmlid);
		target2.innerHTML = "<br>Loading, please wait....";		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;			
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];						
					} else {
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
		}
	}
}


function getHourOptions(today) {
  var result = "";
	for(i = 0; i < 24; i++) {
    result += "<option value='" + i + "'";
    if (today.getHours() == i) {
      result += " selected='selected'";
    }
    
    result += ">";
    if (i < 10) {
      result += "0";
    }
    
    result += i + "</option>";
	}
	
	return result;
}

function getDay(day) {
  switch(day) {
    case 0:
      return "Sun";
    case 1:
      return "Mon";
    case 2:
      return "Tue";
    case 3:
      return "Wed";
    case 4:
      return "Thu";
    case 5:
      return "Fri";
    case 6:
      return "Sat";
  }
}

function checkTime(i) {
  var selectHour = document.getElementById("hour" + i.toString());
  var selectMin = document.getElementById("min" + i.toString());
  var defenderTimes = document.getElementById("dTime" + i.toString());
  
  if (selectHour == null || selectMin == null || defenderTimes == null) {
    return;
  }
  
  if (defenderTimes.innerHTML == "Defender is not available this day") {
    selectHour.disabled = true;
    selectMin.disabled = true;
    return;
  }
  
  var selectTime = parseInt(selectHour.value, 10) + (parseInt(selectMin.value, 10) / 60);
  
  var availTimes = defenderTimes.innerHTML.split(", ");
  for(j = 0; j < availTimes.length; j++) {
    thisTime = availTimes[j].replace(/^\s+|\s+$/g,'');  // trim whitespace
    var startTime = getStartTimeNum(thisTime);
    var endTime = getEndTimeNum(thisTime);
    if (startTime <= selectTime && selectTime < endTime) {
      document.getElementById("ok" + i.toString()).innerHTML = "<img src='image/ok.gif' width='19' height='15' alt='Ok' />";
      var submitOk = true;
      for(k = 1; k <= 3; k++) {
        if (document.getElementById("ok" + k.toString()).innerHTML.substr(16, 2) == "no") {
          submitOk = false;
          break;
        }
      }
      
      if (submitOk) {
        document.getElementById("submitChallenge").disabled = false;
      }
      return;
    }
  }
  
  document.getElementById("ok" + i.toString()).innerHTML = "<img src='image/no.gif' width='19' height='15' alt='Not ok' />";
  document.getElementById("submitChallenge").disabled = true;
}

function getStartTimeNum(str) {
  var startTime = parseInt(str.substr(0,2), 10);
  if (str.substr(2,3) == ":30") {
    startTime += .5;
  }
  
  return startTime;

}

function getEndTimeNum(str) {
  var endTime = parseInt(str.substr(8,2), 10);
  if (str.substr(10,3) == ":30") {
    endTime += .5;
  }
  
  return endTime;
}

function checkChallenge() {
  if (document.challenge_form.challenge.value == "") {
    document.getElementById("timedata").style.display = "none";
  } else {
    document.getElementById("timedata").style.display = "block";
  }
}

function getOptions(start, end, step) {
  var strData;
	for(i = start; i <= end; i += step) {
	  strData += "<option value='"+ i +"'>"+i+"</option>";
	}
	
	return strData;
}
