///////end generic code

/**
 * This function ascertains the outcome of the request to the login servlet. If
 * the result XML will be in the form:
 *   <result>
 *     <login>[REJECTED | DIRECT_ACCESS | OK]</login>
 *   </result>
 */
function myFunction(request) {

   document.myform.reset();

var respRoot = request.responseXML.documentElement;

	printChildNodeNames(respRoot);

	if ( respRoot.childNodes[0].tagName == "result" ) {
		document.getElementById("currentEntryID").innerHTML = "<input type=\"hidden\" name=\"id\" value=\"" + respRoot.childNodes[0].childNodes[0].firstChild.nodeValue + "\">";
		document.getElementById("currentEntryUrl").innerHTML =
		 "<img src=\"" + respRoot.childNodes[0].childNodes[2].firstChild.nodeValue + "\" border=\"0\" height=\"250\" width=\"250\">";


	}

	if ( respRoot.childNodes[1].tagName == "previousresult" ) {

		document.getElementById("previousEntryScore").innerHTML =
		"" + respRoot.childNodes[1].childNodes[1].firstChild.nodeValue + "";

		document.getElementById("previousEntryUrl").innerHTML =
		 "<img src=\"" + respRoot.childNodes[1].childNodes[2].firstChild.nodeValue + "\" height=\"150\" width=\"150\" border=\"0\">";

		document.getElementById("previousEntryVotecount").innerHTML =
		 localize["BASED_ON"] + " " + respRoot.childNodes[1].childNodes[3].firstChild.nodeValue + " " + localize["VOTES"];

	}
}

function printChildNodeNames(element) {

	var buffer = "Child Names: ";

	for (var i=0; i < element.childNodes.length; i++) {
		buffer += element.childNodes[i].nodeName + ",";
	}

	//alert (buffer);

}

function resetButtons(R) {


    if(R.rating.checked == true) { 
        R.rating.checked = false; 
    }

}
//////////////////////

function login () {



   document.myform.reset();

	var url = "/soegamesite/photocomp/score.xml";

        var randomnum=Math.floor(Math.random()*1000000);
	var qs = new Querystring();

	var v1 = qs.get("viewraceface");

	if ( ( v1 == null ) || ( v1.length < 1)  ) {
		url = "/soegamesite/photocomp/score.xml?asdf=" + randomnum;
	} else {
		url = "/soegamesite/photocomp/score.xml?viewraceface=" + v1;
	}

	new ajax (url, {onComplete:myFunction});
}

///////////////////////

function submitScore (example) {

	var url = "/soegamesite/photocomp/score.xml";
    var randomnum = Math.floor(Math.random()*11111111);
    var theid = document.myform.id.value;
	var newurl = url + "?rating=" + example + "&id=" + theid + "&asdf=" + randomnum;


	new ajax (newurl, {onComplete:myFunction});


}


//var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
function loadXML(xmlFile)
{
 xmlDoc.async="false";
 xmlDoc.onreadystatechange=verify;
 xmlDoc.load(xmlFile);
 xmlObj=xmlDoc.documentElement;
}

function verify()
{
 // 0 Object is not initialized
 // 1 Loading object is loading data
 // 2 Loaded object has loaded data
 // 3 Data from object can be worked with
 // 4 Object completely initialized
 if (xmlDoc.readyState != 4)
 {
   return false;
 }
}

//loadXML('http://localhost:8080/en/score.xml');

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=353,height=278,left = 390,top = 162');");
}

function popUpSendFriend(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=353,height=350,left = 390,top = 162');");
}

function goSendFriend() {

	var url = "send_to_friend.html";
	var theid = document.myform.id.value;

	var newurl = url + "?id=" + theid;

  window.location = newurl;
}
