﻿function ShowCenterPopup(popW, popH, theURL, Name) {
	var winleft = (screen.width - popW) / 2
	var winUp = (screen.height - popH) / 2
	winProp = 'width='+ popW +',height='+ popH +',left='+ winleft +',top='+ winUp + ',scrollbars=yes'
	Win = window.open(theURL, Name, winProp)
}

function ShowCalendar(clientControlID) {
	var winleft = (screen.width - 300) / 2
	var winUp = (screen.height - 200) / 2
    window.open('/Calendar.aspx?CallerControlID=' + clientControlID, 'Calendar', 'width=300,height=200,left='+ winleft +',top='+ winUp + ',scrollbars=no');
}

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
	{
        this.value = this.value.substring(0, maxLength);
        alert( 'non è possibile inserire piu\' di ' + maxLength + ' caratteri in questo campo!');
	}
}

function MsgImpossibileRegistrazione() {
    // alert('Siamo spiacenti, i termini per l’iscrizione delle poesie al concorso sono scaduti. Resta sintonizzato! Il Centro Culturale Laurentum ha in serbo nuove iniziative e sarà lieto di ospitare la tua poesia nella prossima edizione del concorso');
    alert('Il termine per le iscrizioni di nuove poesie è scaduto.' + '\n' + 'Continua a leggere, votare, commentare le poesie in gara e segui online le fasi finali della competizione.' + '\n' + 'Il prossimo anno saremo lieti di annoverare la tua poesia tra quelle in gara!');
}

function MsgImpossibileVotazione() {
    // alert('Il termine per le votazioni delle poesie in gara è scaduto. Resta sintonizzato! A breve pubblicheremo i nomi dei vincitori del concorso online e le date dei prossimi appuntamenti.');
    alert('Le votazioni delle poesie in gara si sono concluse il 10 novembre');
}

function RollOver(imgId, imageName) {
    $('#' + imgId).attr('src', imageName);
}

function AddToFavourite() {
    title = "Premio Laurentum";
    url = "http://www.premiolaurentum.eu/";
    if (window.sidebar) {                           // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    }
    else if( window.external ) {                    // IE Favorite
        window.external.AddFavorite( url, title);
    }
    else if(window.opera && window.print) {         // Opera Hotlist
        return true;
    }
}

function SetCurrentNode() {
    $.ajax({   
        type: "POST",   
        url: "/MenuService.asmx/GetCurrentNode",   
        data: "",   
        contentType: "application/json; charset=utf-8",   
        dataType: "json",   
        success: function(msg) {   
            SetCurrentNodeSucceeded(msg);   
        },   
        error: AjaxCallFailed   
    });
}

function GetChildNodes(nodeUrl) {
    $.ajax({   
        type: "POST",   
        url: "/MenuService.asmx/GetChildNodes",   
        data: "{'currentNodeUrl': '" + nodeUrl + "'}",   
        contentType: "application/json; charset=utf-8",   
        dataType: "json",   
        success: function(msg) {
            GetChildNodesSucceeded(msg);   
        },   
        error: AjaxCallFailed   
    });
}

function GetChildNodesSucceeded(result) {
    $('#navL2').css('background-color', '#FFFFFF');
    $('#navL2').html('');
    if(result.d != '')
    {
        $('#navL2').html(result.d);
        $('#navL2').css('background-color', '#CACDE5');
    }
}   

function SetCurrentNodeSucceeded(result) {
    if(result.d != '')
        GetChildNodes(result.d);

}   

function AjaxCallFailed(result) {
    var err = '';
    for(a in result)
        err += a + ': ' + result[a];

    alert(err + '\n' + result.status + ' ' + result.statusText);
}