var calwURL = "dreams/includes/widgets/calendar/calendar_server.php";
var filter = "";

//alert(new Date('2009-06-07 13:56:00'.replace(/-/g, "/")));


function getWidgetCalendar()
	{
		//$('#widget-wrapper-blue').empty();
		$('#calendar-data-container').empty();
		$.post(calwURL,
			{ 
				request:"getfullcalendar"
			},
		function(res)  
			{
				//alert(res);
				var info = $.json.deserialize(res); 
				var response = false;
				var inforesults = "";
				//var is_myevent = false;
				for(key in info)
					{ 
						response = info[key].response;
						is_myevent = info[key].is_myevent;
						if(response)
							{	
								
								date_inarray = searchForDateInArray("date",info[key].date_begin,inforesults);
								if(!date_inarray)
									{
										inforesults += '<tr><td class="cal-date">';
										inforesults += dateFormat(new Date(info[key].date_begin.replace(/-/g, "/")),"fullDate")+'</td></tr>';
									}
								
								inforesults += '<tr><td';
								if(is_myevent)
									{
										inforesults += ' class="ismyevent"';	
									}
								inforesults += '>';
								inforesults += dateFormat(new Date(info[key].date_begin.replace(/-/g, "/")),"shortTime")+' EST';
								inforesults += ' <a href=calendar.php?event='+info[key].cal_event_id+'>'+info[key].event_name+'</a>';
								inforesults += '</td></tr>';
							}
					}
				//alert(inforesults);
				$('#calendar-data-container').append(inforesults);
				$('#calendar-data-container tr').css({'background-color':'#dceaff','text-align':'left','font-size':'1.1em'});
				//$('#calendar-data-container tr:odd').css({'background-color':'#efefef','text-align':'left','font-size':'1.1em'});
				$('.ismyevent').css({'background-color':'#efefef'});
				$('.cal-date').css({'background-color':'#FFF','font-weight':'bolder'});
			});
	}
function searchForDateInArray(request,param,existingarray)
	{
		if(request == "date")
			{
				date = dateFormat(new Date(param.replace(/-/g, "/")),"fullDate");
				//alert(date);
				var array_string = existingarray.toString();  //Converting the String content to String
				response = array_string.search(date);
			}
		else if(request == "time")
			{
				
			}
		
		if(response == "-1")
			{
				return false;	
			}
		else
			{
				return true;	
			}
	}
function getMentoringCalendar(groupid)
	{
		//$('#widget-wrapper-blue').empty();
		$('#calendar-data-container').empty();
		$.post(calwURL,
			{ 
				request:"getmentoringcalendar",
				group_id:groupid
			},
		function(res)  
			{
				var info = $.json.deserialize(res); 
				var response = false;
				var inforesults = "";
				//var is_myevent = false;
				for(key in info)
					{ 
						response = info[key].response;
						is_myevent = info[key].is_myevent;
							
						date_inarray = searchForDateInArray("date",info[key].date_begin,inforesults);
						if(!date_inarray)
							{
								inforesults += '<tr><td class="cal-date">';
								inforesults += dateFormat(new Date(info[key].date_begin.replace(/-/g, "/")),"fullDate")+'</td></tr>';
							}
						inforesults += '<tr><td';
						if(is_myevent)
							{
								inforesults += ' class="ismyevent"';	
							}
						inforesults += '>';
						inforesults += dateFormat(new Date(info[key].date_begin.replace(/-/g, "/")),"shortTime")+' EST';
						inforesults += ' <a href=calendar.php?event='+info[key].cal_event_id+'>'+info[key].event_name+'</a>';
						inforesults += '</td></tr>';
					}
				//alert(inforesults);
				$('#calendar-data-container').append(inforesults);
				$('#calendar-data-container tr').css({'background-color':'#dceaff','text-align':'left','font-size':'1.1em'});
				//$('#calendar-data-container tr:odd').css({'background-color':'#efefef','text-align':'left','font-size':'1.1em'});
				$('.ismyevent').css({'background-color':'#efefef'});
				$('.cal-date').css({'background-color':'#FFF','font-weight':'bolder'});
			});
	}
function searchForDateInArray(request,param,existingarray)
	{
		if(request == "date")
			{
				date = dateFormat(new Date(param.replace(/-/g, "/")),"fullDate");
				//alert(date);
				var array_string = existingarray.toString();  //Converting the String content to String
				response = array_string.search(date);
			}
		else if(request == "time")
			{
				
			}
		
		if(response == "-1")
			{
				return false;	
			}
		else
			{
				return true;	
			}
	}
