﻿var htmlObj = new Object();

function Get(getID){
	return document.getElementById(getID);
};

$(
	function ()
	{
        SplitStandardContent();
        //
        var listener = new Object();
        listener.onresize = function (size) {
            //alert(htmlObj.downloadContainer.length);
            htmlObj.overlay = $('div#overlay');
            htmlObj.overlayContainer = $('div#overlay_container');
            //
            if (htmlObj.overlayContainer.length != 0) {
                htmlObj.overlayContainer.css('top', (size.height - htmlObj.overlayContainer.height()) / 2);
                htmlObj.overlayContainer.css('left', (size.width - htmlObj.overlayContainer.width()) / 2);
            }
        };
        //
        resizeManager.addListener(listener);
        resizeManager.onresize();
	}
);

function SplitStandardContent()
{
	var columnLeft = $('div#columnLeft');
    var columnRight = $('div#columnRight');
    if(columnLeft.length != 0 && columnRight.length != 0)
    {
        // alert(columnLeft.height());
        var columnLeft_content = $('div#columnLeft_content');
        if(columnLeft_content.height() > columnLeft.height())
        {
            // alert(columnLeft.height().toString());
            var heightToCut = columnLeft.height().toString();
            htmlObj.columnRight_content =  columnLeft_content.clone();
            htmlObj.columnRight_content.appendTo(columnRight).css('margin-top', '-' + heightToCut + 'px');
        };
	};
};

//
/* - MDS - */
//
//
function SetPublictionsList()
{
	$('div#adminPublicationsList div[id^="pl_"]').css('opacity', 0.0);
	ShowPublicationList('0');
}

function ShowPublicationList(ID)
{
	$('div#adminPublicationsList div[id^="pl_"]').not("div#pl_" + ID).animate({'opacity':0.0}, {duration:1000, queue:false, complete:function(){
		$(this).css('z-index', '0').hide();
	}});
	$("div#pl_" + ID).show().animate({'opacity':1.0}, {duration:1000, queue:false}).css('z-index', '50');
	//
	$('div#adminPublicationsList div[id^="y_"]').removeClass().addClass('year');
	$("div#y_" + ID).removeClass().addClass('yearSelected');
};

function FormatValue(obj)
{
	var fieldValue = obj.value;
	//alert(fieldValue);
	//delete all %
	fieldValue = fieldValue.replace(/%/gi, '');
	//relpace all , with .
	fieldValue = fieldValue.replace(/,/gi, '.');
	//alert(fieldValue);
	//if is a number put in the wright format
	if(!isNaN(fieldValue))
	{
		//alert(fieldValue);
		//
		if(fieldValue == 0)
		{
			alert('Attenzione!\nIl valore 0 va indicato come N.D.!');
			fieldValue = "N.D.";
		}
		else
		{
			fieldValue = fieldValue.replace(/\,/gi, '.');
			//fieldValue = fieldValue + "%";
		}
	}
	//if not, alert and set N.D.  
	else
	{
		if(fieldValue != "N.D.")
		{
            alert('Attenzione!\nIl valore inserito non è numerico!');
		    fieldValue = "N.D.";
        }
	}
	//alert(fieldValue);
	//
	obj.value = fieldValue;
};

function FirstUp(obj)
{
	var str = obj.value.toLowerCase();
	var newStr = new String();
	var previousWasBlank = true;
	for(var i = 0; i < str.length; i++)
	{
		if(str.charAt(i) == ' ')
		{
			previousWasBlank = true;
			newStr += ' ';
		}
		else
		{
			if(previousWasBlank)
				newStr += str.charAt(i).toUpperCase();
			else
				newStr += str.charAt(i).toLowerCase();
				previousWasBlank = false;
		}
	} 
 
	obj.value = newStr;
};

function CalculateLength(sender, maxLength)
{
	sender.value = sender.value.substring(0, maxLength);
	//alert(sender.value.length);
};


function MessageBoxOpen(action, parameter)
{
    document.location.hash = "#";
    //
    if($('div#overlay').length != 0)
        MessageBoxClose();
    //
    htmlObj.overlay = $('<div id="overlay" onclick="MessageBoxClose();"></div>');
    htmlObj.overlay.appendTo(document.body);
    htmlObj.overlay.css('height', $('div#main').height()).css('opacity', 0.9);
    htmlObj.overlay_container = $('<div id="overlay_container"></div>');
    htmlObj.overlay_iframe = $('<iframe src="MessageBox.Aspx?action=' + action + '&parameter=' + parameter + '" frameborder="0" scrolling="auto"></iframe>');
    htmlObj.overlay_container.appendTo(document.body);
    htmlObj.overlay_iframe.appendTo(htmlObj.overlay_container);
    //
	resizeManager.onresize();
};

function MessageBoxClose()
{
    $('div#overlay').remove();
    $('div#overlay_container').remove();
};
