﻿function sendemail(encodedEmail) {
	// do the mailto: link
	location.href = "mailto:" + decodeEmail(encodedEmail);
}

// return the decoded email address
function decodeEmail(encodedEmail) {
	// holds the decoded email address
	var email = "";

	// go through and decode the email address
	for (i = 0; i < encodedEmail.length; ) {
		// holds each letter (2 digits)
		var letter = "";
		letter = encodedEmail.charAt(i) + encodedEmail.charAt(i + 1)

		// build the real email address
		email += String.fromCharCode(parseInt(letter, 16));
		i += 2;
	}

	return email;
}

function sendemail(encodedEmail) {
	// do the mailto: link
	location.href = "mailto:" + decodeEmail(encodedEmail);
}

// return the decoded email address
function decodeEmail(encodedEmail) {
	// holds the decoded email address
	var email = "";

	// go through and decode the email address
	for (i = 0; i < encodedEmail.length; ) {
		// holds each letter (2 digits)
		var letter = "";
		letter = encodedEmail.charAt(i) + encodedEmail.charAt(i + 1)

		// build the real email address
		email += String.fromCharCode(parseInt(letter, 16));
		i += 2;
	}

	return email;
}

function paging(sFormID, nPage) {
	var oForm = document.getElementById(sFormID);
	var oPage = document.getElementById('PaginaCorrente');
	var oSubmitPaging = document.getElementById('SubmitPaging');
	if (oSubmitPaging) oSubmitPaging.value = '1';
	if (oPage) oPage.value = nPage;
	if (oForm) oForm.submit();
}

function autoPostSelect(oSelect) {
	if (oSelect) {
		var oForm = oSelect.form;
		if (oForm) {
			var oHidden = document.getElementById(oSelect.id + '_autopost');
			if (oHidden) oHidden.value = '1';
			oForm.submit();
		}
	}
}

function SelezionaMeseCalendario(id, value) {
	if (!document.getElementsByTagName) return;
	var tbf = document.getElementById(id);
	if (!tbf) return;
	for (var i = 0; i < tbf.getElementsByTagName('span').length; i++) {
		var spa = tbf.getElementsByTagName('span')[i];
		if (spa.className == 'mesecorrente') {
			for (var k = 0; k < spa.getElementsByTagName('input').length; k++) {
				var inp = spa.getElementsByTagName('input')[k];
				if (inp) inp.checked = value;
			}
		}
	}
}

function RedirectLoginSpWeb() {
	window.open('ftp://' + document.getElementById('txtUsr').value + ':' + document.getElementById('txtPwd').value + '@ftp.scuolaer.it/');
}


function submitForm(sFormName) {
	var oForm = document.getElementById(sFormName);
	if (oForm) oForm.submit();
}

function submitFormNewWindow(sFormName, sWindowName, sHref) {
	var oForm = document.getElementById(sFormName);
	if (oForm) {
		var oldTarget = oForm.target;
		var oldAction = oForm.action;
		oForm.target = sWindowName;
		if (sHref != '') oForm.action = sHref;
		oForm.submit();
		oForm.action = oldAction;
		oForm.target = oldTarget;
	}
}

function votaArticolo(shRef) {
	jx.load(shRef, cbVotaArticolo);
}

function cbVotaArticolo(data) {
	if (data.length > 0) {
		var aData = data.split(',');
		var sSel = '';
		if (aData[1] == '-1') alert('E\' possibile votare solamente una volta al giorno.');
		var ulVoti = document.getElementById('votaarticoloul');
		if (ulVoti) ulVoti.className = 'sel' + data[0];
		for (i = 1; i <= 5; i++) {
			var liVoto = document.getElementById('votaarticolo' + i);
			if (liVoto) {
				sSel = '';
				if (data[0] == i) sSel = ' sel';
				liVoto.className = 'mediavoti' + i + sSel;
			}
		}
	}
}

/* Shop */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	jQuery("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		jQuery("body").append("<p id='tooltip'>"+ this.t +"</p>");
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		jQuery("#tooltip").remove();
    });	
	jQuery("a.tooltip").mousemove(function(e){
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
jQuery(document).ready(function(){
	tooltip();
});

function shopCmd( shRef ) {
	jQuery.getJSON(shRef, function(data) {
		if (data) {
			if (data.returnValue = 1) {
				for (var i = 0; i < data.divReload.length; i++) {
					var odiv = document.getElementById(data.divReload[i].divId);
					if (odiv) odiv.innerHTML = jQuery.ajax({url: data.divReload[i].reload,async: false}).responseText;
				}
				alert(data.msgok);
			}
			else
				alert(data.msgno);
		}
	}
	);
}