function display_flag(ad_id,parity){
	on_flag=document.getElementById("flag_"+ad_id+"_on")
	off_flag=document.getElementById("flag_"+ad_id+"_off")
	out_flag=document.getElementById("flag_"+ad_id+"_out")
	if(on_flag==null || off_flag==null || out_flag==null){//flagged ad is not on this page
		if(!(on_flag==null && off_flag==null && out_flag==null)){
			alert("werid error")
		}
		return
	}
	on_flag.style.position="absolute"
	on_flag.style.visibility="hidden"
	off_flag.style.position="absolute"
	off_flag.style.visibility="hidden"
	out_flag.style.position="absolute"
	out_flag.style.visibility="hidden"
	if(parity=="on"){
		//turn flag on
		on_flag.style.position="relative"
		on_flag.style.visibility="visible"
	}
	else if(parity=="off"){
		//turn flag off
		off_flag.style.position="relative"
		off_flag.style.visibility="visible"
	}
	else if(parity=="out"){
		//turn flag out - ERROR
		out_flag.style.position="relative"
		out_flag.style.visibility="visible"
	}
}

function flag(ad_id,parity){
	xmlhttp=new_xmlhttp()
	xmlhttp.open("GET","/unified_adboard-xmlhttp.php?ad_id="+ad_id+"&flag="+parity,true)
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			if(xmlhttp.responseText=="success"){
				display_flag(ad_id,parity)
			}
			else{
				alert("There was a problem flagging this ad, your login may have timed out.")
				display_flag(ad_id,"out")
			}
		}
	}
	xmlhttp.send(null)
}
function new_xmlhttp(){
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if(@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E){
			xmlhttp = false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp
}
