var SendStaf = "/hobbycenter/wp-content/plugins/sendtoafriend/sendtoafriend.php?staf=true";
var staffrm = "";

function initStaf() {
	oRemovedNode = document.getElementById("stafBlock");
	oRemovedNode.parentNode.removeChild(oRemovedNode);
	document.getElementById('product-menu').appendChild(oRemovedNode);
	
	stafLnk = document.getElementById('stafLink');
	staffrm = document.getElementById('stafForm').innerHTML;
	if(stafLnk) {
		stafLnk.onclick = function() {
			document.getElementById('stafUrl').value = document.URL;
			document.getElementById('stafBlock').style.display = 'block';
//			document.getElementById('stafBlock').style.visibility = 'visible';
			/*ws = staf_windowsize();
			w = parseInt(document.getElementById('stafBlock').offsetWidth);
			h = parseInt(document.getElementById('stafBlock').offsetHeight);
			stafTopOffset =0;
			if(document.body.scrollTop) {
				stafTopOffset = document.body.scrollTop;
			} else if(document.documentElement.scrollTop){ 
				stafTopOffset = document.documentElement.scrollTop;
			}
			document.getElementById('stafBlock').style.top =  (stafTopOffset + ((ws.y/2)-(h/2)))+"px" ;
			document.getElementById('stafBlock').style.left =  ((ws.x/2)-(w/2))+"px";*/
			return false;
		}
	}
}


function staf_Close() {
	document.getElementById('stafBlock').style.display = 'none';
//	document.getElementById('stafBlock').style.visibility = 'hidden';		
	return false;
}
function staf_Reset() {

	document.getElementById('stafBlock').style.display = 'none';
//	document.getElementById('stafBlock').style.visibility = 'hidden';
	$("#stafLink").css("fontWeight","normal");
	document.getElementById('stafForm').innerHTML = staffrm;
}
function staf_Error(stafErrorArr) {	
	for(i = 0; i < stafErrorArr.length; i++) {
//		document.getElementById(stafErrorArr[i]).style.color = '#F00';
		$("#"+stafErrorArr[i]).css({'color':'#F00','border':'1px solid #F00'});
	}
	
}

function staf_Submit() {
	params = 'url='+document.getElementById('stafUrl').value;
	params+= '&fromname='+document.getElementById('stafFromName').value;
	params+= '&frommail='+document.getElementById('stafFromMail').value;
	params+= '&toname='+document.getElementById('stafToName').value;
	params+= '&tomail='+document.getElementById('stafToMail').value;
	$.ajax({
		type: "POST",
		url: SendStaf,
		data: params,
		success: function(msg) {
			if(msg.substring(0,5) == "Array") {
				results = eval(msg);
				staf_Error(results);
			} else {
				document.getElementById("stafForm").innerHTML = "<p>"+staf_confirmtext+"</p>";
				setTimeout('staf_Reset()', 3000);
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			document.getElementById("stafForm").innerHTML = "<p>Recomendação enviada com sucesso!</p>";
			setTimeout('staf_Reset()', 3000);
//alert('Erro: '+textStatus);
		}
	});
	return false;
}