// JavaScript Document

/* ---------------------------- GLOBALS ---------------------------- */
var tpm = false;
var current_tpm = 0;

jQuery(document).ready(function() {
	
	/* ---------------------------- TOPMENU ---------------------------- */
	// Cerco il top menu padre di questa sezione registrato nei cookie
	jQuery("#topmenu #mainlevel-nav li a").each(function(index) {
		if (jQuery(this).attr("id") == "active_menu-nav") {
			jQuery.ajax({url:"common_ajax.php?tpm=" + index});
			tpm = true;
		}
	});	
	// Se non l'ho già attivato cliccandoci, attivo l'eventuale top menu padre
	if (!tpm) {
		jQuery("#topmenu #mainlevel-nav li").eq(current_tpm).children().attr("id", "active_menu-nav");
	}
	
	
	/* ---------------------------- FOTO SOPRA_TITOLO ---------------------------- */	
	if (jQuery("img.sopra_titolo").attr("src") != undefined) {
		jQuery("img.sopra_titolo").hide();
		var imago = "<img class='sopra_titolo' src='" + jQuery("img.sopra_titolo").attr("src") + "'>";
		if (jQuery("div.componentheading")) {jQuery("div.componentheading").prepend(imago);}
		if (jQuery("td.contentheading")) {jQuery("td.contentheading").prepend(imago);}
	}
	
	/* ---------------------------- News Show Pro GK4 CUSTOMIZATION --------------------------- */	
	jQuery(".nsp_art").each(function(index) {
		jQuery(this).css("width","290px");
		if (jQuery(this).css("clear") == "both") {
			jQuery(this).before('<div style="clear:both;"></div>').css("margin-right","20px");
			}
		}
	);
	jQuery(".news .nsp_info").each(function(index) {jQuery(this).removeClass("fleft");});
	jQuery(".focus .nsp_art").each(function(index) {jQuery(this).css("width","auto");});
	
	// correggo struttura FOCUS
	if (jQuery(".focus .nsp_art img.nsp_image").attr("src") != undefined) {
		jQuery(".focus .nsp_art img.nsp_image").hide();
		var imago = "<img class='lato_titolo' src='" + jQuery(".focus .nsp_art img.nsp_image").attr("src") + "'>";
		jQuery(".focus .nsp_art").prepend(imago);
		jQuery(".focus .nsp_art div").addClass("lato_titolo");
	}
	
	// correggo link read-more
	jQuery(".focus").css("margin","0px");
//	17-02-2011 * read more
//	jQuery(".nsp_art .nsp_readmore").html(" continua");
//	jQuery(".nsp_art .readon").html(" continua");
//	jQuery(".news .nsp_readmore").html(" leggi la news");
//	jQuery(".news .readon").html(" leggi la news");
//	jQuery(".magazines .nsp_readmore").html(" vai al sommario");
//	jQuery(".magazines .readon").html(" vai al sommario");
	
	// cambio gli eventuali link con classe popup
	jQuery("a.popup").each(function(index) {
		linko = jQuery(this).attr("href");
		jQuery(this).attr("href","javascript:openpopup('" + linko + "');");		
	});	
});

//  funzione che apre una popup
function openpopup(linko) {
	window.open(linko,'mywindow','status=0,menubar=0,resizable=1,scrollbars=1,width=600,height=650');
}

//  funzione che verifica che una stringa sia scritta in forma di 'numero'
function isnumeric(sText)
{
	var ValidChars = "0123456789.,";
	var IsNumber=(sText.length > 0);
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {IsNumber = false;}
	}
	if (IsNumber) {
		var nv = sText.split(",");	
		if (nv.length > 2) {IsNumber = false;}
		var np = sText.split(".");	
		if (np.length > 2) {IsNumber = false;}
		var pp = sText.indexOf(".");
		var pv = sText.indexOf(",");
		if ((pp > -1) && (pv >-1) && ((pv < (pp + 4)) || (pv > (pp + 4)) || (pp > pv))) {IsNumber = false;}
	}
	
	return IsNumber;
}


