$(function() {
	$('.blank').click(function() {
		window.open($(this).attr('href'));
		return false;
	});
});

function trim(stringa){
    while (stringa.substring(0,1) == ' ') {
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' ') {
        stringa = stringa.substring(0,stringa.length-1);
    }

    return stringa;
}

function validEmail(text) {

	if(text.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/))
		return true;

	return false;
}

function validDouble(text) {

	if(text.match(/^\+?[0-9\.,]+$/))
		return true;

	return false;
}

function validIntervallo(text) {

	if(text.match(/^[0-9\:\-\ ]+$/))
		return true;

	return false;
}

function validPhone(text) {

	if(text.match(/^\+?[0-9\.-\/ ]+$/))
		return true;

	return false;
}


function validNumeric(text) {
	if(text.match(/^[0-9]+$/))
		return true;

	return false;
}

// Verifico se il campo è solo letterale (a-zA-Z)
function validString(text) {
	if(text.match(/^[a-zA-Z]+$/))
		return true;

	return false;
}

function validPassword(text) {
	if(text.length < 8)
		return false;
		
	if(text.match(/^[a-zA-Z0-9]+$/))
		return true;
	
	return false;
}

// Evidenzio l'input come errore
function error(id) {
	$(id).attr('style', 'border:1px solid red;');
}

// Tolgo l'errore per gli input non vuoti
function errorNo(obj) {

	if($(obj).val().length > 0)
		$(obj).removeAttr('style');
}

// Tolgo l'errore per gli input validi come campo telefonico
function errorNoPhone(obj) {

	if(validPhone($(obj).val()))
		$(obj).removeAttr('style');
}

// Tolgo l'errore per gli input validi come e-mail
function errorNoEmail(obj) {

	if(validEmail($(obj).val()))
		$(obj).removeAttr('style');
}

function errorNoNumeric(obj) {
	
	if(validNumeric($(obj).val()))
		$(obj).removeAttr('style');
}

function errorNoPassword(obj) {
	
	if(($(obj).val()).length > 8) {
		if(($(obj).val()).match(/^[a-zA-Z0-9]+$/))
			$(obj).removeAttr('style');
	}
}

function setCookie(sNome, sValore, iGiorni) {
	var dtOggi = new Date()
	var dtExpires = new Date()
	if($.trim(iGiorni) != '') {
		dtExpires.setTime(dtOggi.getTime() + 24 * iGiorni * 3600000);
		document.cookie = sNome + "=" + escape(sValore) + "; expires=" + dtExpires.toGMTString();
	}
	else {
		document.cookie = sNome + "=" + escape(sValore);
	}
}

function getCookie(sNome) {
	var asCookies = document.cookie.split("; ");
	for (var iCnt = 0; iCnt < asCookies.length; iCnt++) {
		var asCookie = asCookies[iCnt].split("=");
		if (sNome == asCookie[0]) {
	  	return (unescape(asCookie[1]));
		}
	}
	return("");
}

function delCookie(sNome) {
	setCookie(sNome, "");
}