function initStaf(imageSrc) {
	vista = (document.getElementById('stafBlock').style.display == 'block') ? 'none' : 'block';

	document.getElementById('stafBlock').style.display = vista;
	document.getElementById('emailForm').style.display = 'block';
	document.getElementById('errorForm').style.display = 'none';
	document.getElementById('stafForm').reset();
	
	if (vista == 'block') {
		var captcha = new Image();
		captcha.src = imageSrc;
		document["captcha"].src = captcha.src + '?rand=' + Math.floor(100000.0 * Math.random ());
	}

	return false;
}

function closeStaf() {
	document.getElementById('emailForm').style.display = 'block';
	document.getElementById('errorForm').style.display = 'none';
	document.getElementById('stafBlock').style.display = 'none';
	document.getElementById('stafForm').reset();
	
	return false;
}

function submitStaf(submitUrl) {
	var xmlHttpReq = false;
    var self = this;
    
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    self.xmlHttpReq.open('POST', submitUrl, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            var text = self.xmlHttpReq.responseText;
		    var response = text.split('|');
		
			document.getElementById('errorMsg').innerHTML = response[1];
			document.getElementById('errorMsg').style.color = 'black';
			document.getElementById('errorForm').style.display = 'block';
		    if(text.indexOf('done') != -1){
				document.getElementById('emailForm').style.display = 'none';
			}

        }
    }
    
	params = 'to='+document.getElementById('to').value;
	params+= '&from='+document.getElementById('from').value;
	params+= '&message='+document.getElementById('message').value;
	params+= '&code='+document.getElementById('code').value;
	params+= '&link='+document.getElementById('link').value;
	params+= '&title='+document.getElementById('title').value;
    
    self.xmlHttpReq.send(params);
    
    return false;
}
