var dir = "left";
var alt = 0;

function getHTTP() {
	if (window.XMLHttpRequest) {
        httpXML = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            httpXML = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                httpXML = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }	
    }
	return httpXML;
}

function make_quote() {
	var httpSend = new Array();
	var i = new Date();
	httpSend[i] = getHTTP();
	httpSend[i].open("POST", "gen_quote.php", true);
	httpSend[i].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var co = document.forms['quote'].elements['co_select'].value;
	var expr = document.forms['quote'].elements['expr_select'].value;
	var backd = document.forms['quote'].elements['backdrop_select'].value;
	var line1 = document.forms['quote'].elements['line1'].value;
	var line2 = document.forms['quote'].elements['line2'].value;
	var params = "co=" + co + "&expr=" + expr + "&backd=" + backd + "&line1=" + line1 + "&line2=" + line2 + "&alt=" + alt;
	if (co == "dummy") { co = "will" }
	if (co == "") { co = "will" }
	httpSend[i].send(params);
	document.getElementById("finished").innerHTML = "<img src='working.gif'>";
	httpSend[i].onreadystatechange = function() {
		if ((httpSend[i].readyState == 4) && (httpSend[i].status == 200)) {
			document.getElementById("finished").innerHTML = httpSend[i].responseText;
		}
	}
	return false;
}

function set_preview(opt) {
	if (opt == "backdrop") {
		var backd = document.forms['quote'].elements['backdrop_select'].value;
		document.getElementById("background").innerHTML = "<img src='backdrop/" + backd + ".gif'>";
		return false;
	}
	var co = document.forms['quote'].elements['co_select'].value;
	var expr = document.forms['quote'].elements['expr_select'].value;
	if (co == "dummy") { co = "will"; }
	document.getElementById("portrait").style.background = "url('co/" + co + "-" + dir + ".gif')";
	
	if (expr == "win")
		document.getElementById("portrait").style.backgroundPosition = "96px 0px";
	else if (expr == "lose")
		document.getElementById("portrait").style.backgroundPosition = "48px 0px";
	else
		document.getElementById("portrait").style.backgroundPosition = "0px 0px";
	//document.getElementById("portrait").innerHTML = "<img src='ds_cos/" + co + "-" + expr + ".gif'>";
	
	if (alt == 0)
		document.getElementById("name").innerHTML = "<img src='co/name/" + co + ".gif' />";
	else
		document.getElementById("name").innerHTML = "<img src='co/name/" + co + "_eu.gif' />";
}

function flag_alt()
{
	if (alt == 0)
	{
		document.getElementById("alt").style.backgroundPosition = "0px 11px";
		alt = 1;
	}
	else
	{
		document.getElementById("alt").style.backgroundPosition = "0px 0px";
		alt = 0;
	}
}

function vote(id)
{
	if (id != "")
	{
		var params = "vote=" + id;
		var votezone = "vote" + id;
		var httpSend = new Array();
		var i = new Date();
		httpSend[i] = getHTTP();
		httpSend[i].open("POST", "vote_quote.php", true);
		httpSend[i].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			httpSend[i].send(params);
		document.getElementById(votezone).innerHTML = "<img src='working.gif'>";
		httpSend[i].onreadystatechange = function() {
			if ((httpSend[i].readyState == 4) && (httpSend[i].status == 200)) {
				document.getElementById(votezone).innerHTML = "Sent!";
			}
		}
		return false;
	} else {
			return false;
	}
}
