
	function 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,j=els.length; i<j; i++)
		if(re.test(els[i].className))
			a.push(els[i]);
		return a;
	}

	function getCookie( check_name ) {
		var a_all_cookies = document.cookie.split( ';' );
		var a_temp_cookie = '';
		var cookie_name = '';
		var cookie_value = '';
		var b_cookie_found = false; // set boolean t/f default f

		for ( i = 0; i < a_all_cookies.length; i++ )
		{
			// now we'll split apart each name=value pair
			a_temp_cookie = a_all_cookies[i].split( '=' );


			// and trim left/right whitespace while we're at it
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

			// if the extracted name matches passed check_name
			if ( cookie_name == check_name )
			{
				b_cookie_found = true;
				// we need to handle case where cookie has no value but exists (no = sign, that is):
				if ( a_temp_cookie.length > 1 )
				{
					cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				}
				// note that in cases where cookie is initialized but no value, null is returned
				return cookie_value;
				break;
			}
			a_temp_cookie = null;
			cookie_name = '';
		}
		if ( !b_cookie_found )
		{
			return null;
		}
	}				

	
	function AddToMyCalendar(evtId)
	{
		$.post( '/web/addtocalendar.aspx', 'evtId='+evtId ,function(data){
		    if($('#calendareventcount').size() == 1)
			    $('#calendareventcount')[0].innerHTML="<strong>" + data + "</strong>";
			    alert(eventoaggiunto);
	    });
	    return false;
	}

	function removeEventCalendar(evtId)
	{
		if(window.confirm(agenda_confirm_delete))
		{
			$.post( '/web/deletefromcalendar.aspx', 'evtId='+ evtId ,function(data){
		        if($('#calendareventcount').size() === 1)
			        $('#calendareventcount')[0].innerHTML="<strong>" + data + "</strong>";
			});
			if($('#'+evtId).size() === 1)
				$('#'+evtId).hide();
		}
	}		
	function parseEventHTML(){
		//this.eventsHTML=$('#tablecal');
		this.eventsHTML=null;

		if (document.getElementById('tablecal')!=null)
		
		this.eventsHTML=document.getElementById('tablecal').rows;
		this.addImage_myCalendar=function(){
				AddImage_myCalendar()
			}
		
	}	
	function AddImage_myCalendar()
	{
		var i=0;
		while (i<ev.eventsHTML.length) 
		{
			arrdata=getElementsByClassName("dataora",ev.eventsHTML[i])
			if (arrdata.length>0)
			{	
				var eventdate=null;
				var stringdate=null;
				var inputs =arrdata[0].getElementsByTagName('input')
				if (inputs ==null)
					return false;
				for(var k=0;k<inputs.length;k++) 
					evtId=(inputs[k].getAttribute('type')=='hidden' && inputs[k].getAttribute('id')=='evtid')?inputs[k].getAttribute('value'):evtId;

				if (evtId!=null)
					$('.dataora', ev.eventsHTML[i]).prepend("<a href='#"+evtId+"' onclick='javascript:return AddToMyCalendar("+evtId+");'><img src='/includes/img/prefer.gif' border='0' align='left' style='margin-right:5px;'></a>");
			}
			i+=1;	
		}		
	}	
	var ev=null;
	window.onload=function(){
		if (getCookie("laScala")!=null)
		{
			ev=new parseEventHTML();
			if (ev.eventsHTML!=null)
			ev.addImage_myCalendar();
		}
		
	}
	
			

