var fzout="";
var fzid=0;
var fzwaiting=0;

function fzMenu(zform,zout,zid) {
	if (fzwaiting) return;
	fzout=zout;
	fzid=zid;
	var fzOut=document.getElementById(fzout+fzid);
	var obj=fzOut;
	pX = obj.offsetLeft;
	pY = obj.offsetTop;
	while (obj = obj.offsetParent) {
		pX += obj.offsetLeft;
		pY += obj.offsetTop;
	}
	var fzShow=document.getElementById("fzMenuDiv");
    fzShow.style.left = pX+5;
    fzShow.style.top = pY+5;
	fzShow.innerHTML=fzMenuForm(zform);
	fzShow.style.visibility="visible";
}

function fzMenuSkip(zaction,zout,zid) {
	fzout=zout;
	fzid=zid;
	fzAction(zaction);
}

function fzMenuWait () {
	document.getElementById("fzMenuDiv").innerHTML="Updating...";
	fzwaiting=1;
}

function fzMenuDone (response) {
	document.getElementById("fzMenuDiv").style.visibility="hidden";
	result=response.split("|"); // Split zscore,zcount,html
	document.getElementById(fzout+fzid).innerHTML=result[2];
	zscorebox=document.getElementById("zscore"+fzid);

	if (result[0]>0) { zscorebox.className="ZscoreP"; zscorebox.innerHTML="+"+result[0]; }
		else if (result[1]>0) { zscorebox.className='ZscoreZ'; zscorebox.innerHTML="0"; }
			else { zscorebox.className='ZscoreN'; zscorebox.innerHTML="New"; }

	fzwaiting=0;
}

function fzGetURL(url,doneFunction,waitFunction) {
var req=null;
var READY_STATE_COMPLETE=4;
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (req) {
        req.onreadystatechange = function () {
			if (req.readyState==READY_STATE_COMPLETE) {doneFunction(req.responseText);}
				else {if (waitFunction)	{ waitFunction();}}
		};
        req.open("GET", url, true);
        req.send(null);
    }
}

function fzAction (zaction) {
	var cacheBuster = parseInt( Math.random() * 1000000 );
	var url=localurl+"/web_service/";
	url=url+"?svc=zipzap&zaction="+zaction+"&zid="+fzid+"&cb="+cacheBuster;
	fzGetURL(url,fzMenuDone,fzMenuWait);
}

function fzMenuForm (zform) {
	switch (zform) {
		case 'zap':
			o='<div style="font-size:11px; line-height:12px; font-color:#000; padding:3 0 8 0;">Only Zap <b>BAD</b> Tips, NOT Tips that do not apply to your <a href="'+localurl+'/account/filter/account/" class="SmallLinks">Region/Ages-Stages</a></div><a onclick="fzAction(-1);">&raquo; Zap This Bad Post</a><br />';
			break;
		case 'zip':
			o='<a onclick="fzAction(1);">&raquo; Zip This</a><br /><a onclick="fzAction(2);">Mark as Favorite</a><br />';
			break;
		case 'clear':
			o='<a onclick="fzAction(0);">&raquo; Clear previous choice</a><br /><a onclick="fzAction(2);">&raquo; Favorite This</a><br /><a onclick="fzAction(1);">&raquo; Zip This</a><br />';

	}
	return(o+'<a onclick="document.getElementById(\'fzMenuDiv\').style.visibility=\'hidden\';">&raquo; Close this menu</a>');
}