/**********************************************
  Funzioni Alix
**********************************************/

function alx_isMozilla()
{
	return (document.all) ? false : true;
}

function alx_getElementById(objid)
{
	if(typeof objid == 'string')
	{
  		if(document.all)
  		{
  			return document.all[objid];
  		}

	  	if(document.getElementById)
	  	{
	  		return document.getElementById(objid);
	  	}
    }
	return null;
}

function alx_getElementsByClassName(classname, node)
{
	if (!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName('*');
    for (var i = 0; i < els.length; i++)
    {
    	if (re.test(els[i].className)) a.push(els[i]);
    }    
    
    return a;
}

function alx_csvOverlaps(csv1, csv2, separator)
{
	csv1 = csv1.split(separator);
	csv2 = csv2.split(separator);
	
	for (var i = 0; i < csv1.length; i++)
	{
		var e1 = csv1[i].replace(/^\s+/, '').replace(/\s+$/, ''); //trim
		for (var j = 0; j < csv2.length; j++)
		{
			e2 = csv2[j].replace(/^\s+/, '').replace(/\s+$/, ''); //trim
			if (e1 == e2) return true;
		}
	}
	return false;
}

function alx_xmlDecode(txt)
{
    txt = txt.replace(/&amp;/g, '&');
    txt = txt.replace(/&lt;/g, '<');
    txt = txt.replace(/&gt;/g, '>');
    txt = txt.replace(/&apos;/g, "'");
    txt = txt.replace(/&quot;/g, '"');
    
    return txt;
}

function alx_getQueryStringValue(parameterName)
{ 
	var params = location.search.substring(1, location.search.length).split("&");
	for (var i = 0; i < params.length; i++)
	{
		if (params[i].substring(0, params[i].indexOf('=')) == parameterName)
		{
			return params[i].substring(params[i].indexOf('=') + 1);
		}
	}
	return '';
}

function alx_isEditMode()
{
	return document.getElementById("alx_authenticatedUserBox") ? true : false;
	/*
	if (document.forms['aspnetForm']['MSOLayout_InDesignMode'] != null)
	{
		if(document.forms['aspnetForm']['MSOLayout_InDesignMode'].value == 1)
		{
			return true;
		}
	}
	return false;
	*/
}

function alx_isUserAuthenticated()
{
	return alx_getElementById('alx_authenticatedUserBox') ? true : false;
}

function alx_DropDownLostAddOption(selectbox, text, value )
{
	var optn = document.createElement('option');
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function alx_ArrayIndexOf(array, value)
{
	for (var i = 0; i < array.length; i++)
    {
    	if (array[i] == value) return i;
	}
	return -1;
}

function alx_DropDownListSelectedValue(ddlist)
{
	return ddlist.selectedIndex != -1 ? ddlist.options[ddlist.selectedIndex].value : null;
}

function alx_DropDownListSelectValue(ddlist, value)
{
	for (var i = 0; i < ddlist.length; i++)
	{
		if (ddlist[i].value == value)
		{
			ddlist[i].selected = true;
			return;
		}
	}
}

function alx_DropDownListInit(ddlist, firstText, firstValue)
{
	ddlist.options.length = 0;
	alx_DropDownLostAddOption(ddlist, firstText, firstValue);
}


/**********************************************
  Funzioni WeDoo
**********************************************/


function openRadio(page)
{
/*
	var width = 471;
	var height = 412;
		
	if (alx_isEditMode())
	{
		width = 640;
		height = 640;
	}

	var left = Math.round((screen.width / 2) - (width / 2));
	var top = Math.round((screen.height / 2) - (height / 2));
	
	var options = 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',location=no,menubar=no,toolbar=no,status=no,resizable=no';
  	var radio = window.open(page, '_radio', options);
	if (radio != null) radio.focus();
	*/
	
	openPopUp(page, 471, 412);
}

function openPopUp(page, width, height)
{
	if (alx_isEditMode())
	{
		width = screen.width - 8;
		height = screen.height - 40;
	}

	var left = Math.round((screen.width / 2) - (width / 2));
	var top = Math.round((screen.height / 2) - (height / 2));
	
	var options = 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',location=no,menubar=no,toolbar=no,status=no,resizable=no';
  	var w = window.open(page, '', options);
	if (w != null) w.focus();
}


function openPopupImage(imgPath)
{	  
		var win = window.open(imgPath,'imagePopup','width=792,height=535,toolbar=no,scrollbars=no,resizable=yes');      
		win.focus();	
}

function openForm() {

	var y=screen.height;
	var x=screen.width;
	var width=390;
	var height=450;
	var page="home.html";

	y=Math.round((y/2)-(height/2));
	x=Math.round((x/2)-(width/2));

    strto="";
   var wind=window.open(page + strto, "_new",
			"Width=" +
				width +
			",Height=" +
				height +
			",left=" +
				x +
			",top=" +
				y +
			"location=no,menubar=no,toolbar=no,status=no,resizable=no");

	if(wind!=null) 	wind.focus();
}





function openNews(page,w,h) {

	var y=screen.height;
	var x=screen.width;
	var width=w;
	var height=h;

	y=Math.round((y/2)-(height/2));
	x=Math.round((x/2)-(width/2));

    strto="";
   var wind=window.open(page + strto, "news",
			"Width=" +
				width +
			",Height=" +
				height +
			",left=" +
				x +
			",top=" +
				y +
			"location=no,menubar=no,toolbar=no,status=no,resizable=no");
		wind.focus();
}

function displayEditModeElements()
{
	var EditBlockLinks = alx_getElementsByClassName('EditModeBlock');
	for (var i = 0; i < EditBlockLinks.length; i++)
	{
		EditBlockLinks[i].style.display = alx_isUserAuthenticated() ? 'block' : 'none';
	}

}