var FontColorId 		= 4;
var FontId				= 1;
var BannerColorId		= 4;
var BackgroundColorId	= 0;
var EventName			= "John Foster's Event";
var BackgroundColors	= new Array();
var ThemeId				= 1;
var PreviewType			= 'theme';
var FontColor			= 'ffffff';
var BannerColor			= '060606';
var Alignment			= 'center';
var FontSize			= 30;

String.prototype.stripSpaces = function( ){ return this.replace( /\s/g, "" ); };

// Step 3 Variables
var CurrentActivity		  = 0;
var CurrentName			  = "";
var CurrentDescription	  = "";
var CurrentConsiderations = "";
var data = "";
// Step 4 Variables
var CurrentParticipant	  = 0;
var CurrentDate			  = 0;
var CurrentEvent		  = 0;


updateMyCalendar = function()
{
	sendurl = webroot+'users/my_calendar';
	if($("MyCalendarFrame")!=undefined)
	{
		start = new Date;
		time = start.getTime()
		$("MyCalendarLoading").className = '';
		$("MyCalendarFrame").src = sendurl+'?q='+time;
		$("MyCalendarFrame").onload = function(){$("MyCalendarLoading").className = 'hidden';}
	}
}
/* Volunteer To Help */
loadParticipantDatesVolunteer = function(id,type,activity_title,event_id)
{
	CurrentEvent = event_id;
	CurrentParticipant 	= id;


	new Ajax.Request(webroot+'dates_users/load_participant_data.json?user_id='+id+'&event='+event_id, {
		method:'get',
		onSuccess: function(transport){
			data = transport.responseText.evalJSON();
			dataToInsert = '';

			for(i=0;i<data.length;i++)
			{
				GroupName = data[i].Name;
				//alert("Group:" + GroupName);
				if( i==0 || (i>0 && GroupName!=data[i-1].Name))
				{
					dataToInsert += '<div class="clear" style="padding-top:5px;"></div><div class="leftfloat" style="padding-left:2px;"><strong>[-]</strong></div><div class="leftfloat" style="padding-left:9px; padding-top:4px;"><span class="normaltext"><strong>'+ GroupName +'</strong></span></div>';
				}
				GroupData = data[i].Data;
				for(j=0;j<GroupData.length;j++)
				{
					if(GroupData[j].Date!=undefined)
					{
						//alert("AD"+GroupData[j].Date);
						Dates = GroupData[j].Date;
						for(k=0;k<Dates.length;k++)
						{
							if(Dates[k].checked=="yes")
							{
								checkedstring = ' checked="checked"';
							}
							else
							{
								checkedstring = '';
							}
							dataToInsert += '<div class="clear" style="padding-top:5px;"></div><div id="activity_'+Dates[k].id+'_li" style="cursor:pointer;cursor:hand;padding-left:10px;" class="activity_li"><div class="leftfloat"><input name="date_'+Dates[k].id+'_checkbox" type="checkbox" id="date_'+Dates[k].id+'_checkbox" onclick="addDateUser(\''+Dates[k].id+'\',\''+CurrentParticipant+'\',\'checkbox\')" '+checkedstring+'/></div><div class="leftfloat" onclick="addDateUser(\''+Dates[k].id+'\',\''+CurrentParticipant+'\',\'span\')" style="padding-left:7px;width:110px;"><span id="activity_'+Dates[k].id+'_title" class="normaltext">'+GroupData[j].Name+' '+ Dates[k].start_time +'</span></div><div class="clear" style="padding-top:0px;"></div></div>';
						}
					}
				}
			}


			colorSuggestedParticipants(id);

			// Show Content Divs
			$("SchedulingWaiting").className = $("SchedulingWaiting").className +' hidden';
			$("ActivitySchedulingContent").className = '';

			$("ActivitySchedulingContent").innerHTML = dataToInsert;

		}
	});
}

display_timezone = function(timezone)
{

}

showDatesVolunteer = function(activity_id,event_id, user_id)
{
	$('ActivitySchedulingContent').innerHTML = '<div class="normaltext">Loading Dates...</div>';
	new Ajax.Request(webroot+'dates/load_dates.json?event='+event_id+'&activity='+activity_id+'&user='+user_id, {
		method:"get",
		onSuccess: function(transport){
			data = transport.responseText.evalJSON();
			var dataToInsert = '';
			if(data.length==0)
			{
				dataToInsert = '<div class="normaltext">No Available Dates</div>';
			}
			else
			{
				for(i=0;i<data.length;i++)
				{
					if(data[i].checked=="yes")
					{
						checkedstring = ' checked="checked"';
					}
					else
					{
						checkedstring = '';
					}


					var fordate = data[i].start_time.split(" ");
					var onlydate = fordate[0].split("/");
					var dateDisp = onlydate[0] + "/" + onlydate[1] + "/20" + onlydate[2] + " " + fordate[1];

					if(timezone_abbreviations[data[i].start_timezone]!=undefined)
					{
						var start_timezone = ' ('+timezone_abbreviations[data[i].start_timezone]+')';
					}
					else
					{
						var start_timezone = '';
					}
					dateDisp += start_timezone;


					if(data[i].end_time===null)
					{
						var endDateDisp = '';
					}
					else
					{
						var endFordate = data[i].end_time.split(" ");
						var endOnlydate = endFordate[0].split("/");
						var endDateDisp = endOnlydate[0] + "/" + endOnlydate[1] + "/20" + endOnlydate[2] + " " + endFordate[1];

						if(timezone_abbreviations[data[i].end_timezone]!=undefined)
						{
							var end_timezone = ' ('+timezone_abbreviations[data[i].end_timezone]+')';
						}
						else
						{
							var end_timezone = '';
						}

						endDateDisp = '<span style="display:block;text-align:center;font-size:10px;line-height:10px;" class="greytext">To</span>'+endDateDisp+end_timezone;
					}




					dataToInsert += '<div class="clear" style="padding-top:5px;"></div><div id="activity_'+data[i].id+'_li" style="cursor:pointer;cursor:hand;padding-left:2px;" class="activity_li"><div class="leftfloat"><input name="date_'+data[i].id+'_checkbox" type="checkbox" id="date_'+data[i].id+'_checkbox" onclick="addDateUser(\''+data[i].id+'\',\''+user_id+'\',\'volunteer\')" '+checkedstring+'/></div><div class="leftfloat" onclick="addDateUser(\''+data[i].id+'\',\''+user_id+'\',\'spanvolunteer\')" style="padding-left:4px;width:140px;"><span id="activity_'+data[i].id+'_title" class="normaltext">'+ dateDisp+endDateDisp+'</span></div><div class="clear" style="padding-top:0px;"></div></div>';

				}

			}

			$('ActivitySchedulingContent').innerHTML = dataToInsert;
		}
	});
}

loadActivityDescriptionVolunteer = function(id,type,activity_title,event_id,user_id)
{
	CurrentEvent = event_id;
	if(id==CurrentActivity && type!="checkbox")
	{
		//alert("You Already Have That One Selected");
		return false;
	}
	CurrentActivity 	= id;


	new Ajax.Request(webroot+'activities/load_activity_data.json?id='+id+'&event='+event_id, {
		method:'get',
		onSuccess: function(transport){
			data = transport.responseText.evalJSON();

			// Show Content Divs
			$("ActivitySchedulingContent").className = '';
			$("ActivityDescriptionContent").className = '';

			// Hide Waiting Divs
			$("SchedulingWaiting").className = $("SchedulingWaiting").className +' hidden';
			$("DescriptionWaiting").className = $("DescriptionWaiting").className +' hidden';

			// Add Color To Current Activity
			colorSuggestedActivity(id);


			//$("ActivityName").value = "Type the name for your Activity here. For example: \"John Foster's "+data.name+" Activity\"";
			$("ActivityName").innerHTML = data.name;
			
			if(data.description == '') {
				$("ActivityDescriptionHeading").className = $("ActivityDescriptionHeading").className +' hidden';
				$("ActivityDescription").className = $("ActivityDescription").className +' hidden';
			} else {
				$("ActivityDescriptionHeading").className = 'leftfloat normaltext';
				$("ActivityDescription").className = 'leftfloat normaltext';
				$("ActivityDescription").innerHTML = data.description;    }
			if(data.considerations == '') {
				$("ActivityConsiderationHeading").className = $("ActivityConsiderationHeading").className +' hidden';
				$("ActivityConsiderations").className = $("ActivityConsiderations").className +' hidden';
			} else {
				$("ActivityConsiderationHeading").className = 'leftfloat normaltext';
				$("ActivityConsiderations").className = 'leftfloat normaltext';
				$("ActivityConsiderations").innerHTML = data.considerations; }
				
			//		$("ActivityTitle").innerHTML = activity_title+": " + data.name;

			CurrentName			  = data.name;
			CurrentDescription	  = data.description;
			CurrentConsiderations = data.considerations;

			Resources 			  = data.resources;

			ResourceContent = '';
			for(i=0;i<Resources.length;i++)
			{
				if(Resources[i].website=='')
				{
					a_link_beg = '';
					a_link_end = '';
				}
				else
				{
					a_link_beg = '<a target="_blank" class="bluetext" href="'+Resources[i].website+'">';
					a_link_end = '</a>';
				}
				ResourceContent +='<div id="resource_link_'+Resources[i].id+'" style="padding-bottom:5px;">'+a_link_beg+'<span style="font-size:11px;">'+Resources[i].name+'</span>'+a_link_end+'</div>';
			}
			$("AddNewResource").href = webroot+'event/'+event_id+'/resources/list/'+data.id;
			$("ActivityResources").innerHTML = ResourceContent;

			showDatesVolunteer(CurrentActivity,event_id,user_id);
		}
	});
}

function check_formdate(mode)
{
	var e_date_day = document.getElementById("end_dateDay");
	var e_date_month = document.getElementById("end_dateMonth");
	var e_date_year = document.getElementById("end_dateYear");
	var e_show_end_date = document.getElementById("show_end_date");
	var s_date_day = document.getElementById("start_dateDay");
	var s_date_month = document.getElementById("start_dateMonth");
	var s_date_year = document.getElementById("start_dateYear");
	var no_valuter =	document.getElementById("no_volunter").value;
	var tmpStatus = true;

	if(no_valuter == '')
	{
		alert("Please Enter no of Volunteer");
		tmpStatus = false;
	}

	/*
	if(e_show_end_date.checked && tmpStatus == true)
	{

	var today = new Date();
	var st_date=new Date();
	st_date.setFullYear(s_date_year.value,s_date_month.value-1,s_date_day.value);
	var ed_date=new Date();
	ed_date.setFullYear(e_date_year.value,e_date_month.value-1,e_date_day.value);

	if (st_date>ed_date)
	{
	alert('Please ensure that the End Date is greater than or equal to the Start Date.');
	tmpStatus = false;
	}

	if(mode != 'edit')
	{
	if (st_date < today)
	{
	alert('Please ensure that the Start Date is greater than or equal to the Today Date.');
	tmpStatus = false;
	}
	}
	}
	*/

	if(tmpStatus == false)
	{
		return false;
	}
	else
	{
		Modalbox.hide();
		return true;
	}
	//showDates(activity_id,event_id);
}

/* STEP 4b */
sendInvite = function(event_id,type)
{
	
	
	SendOk = false;
	List = '';
	InviteeArray = new Array();

	if(type=="all")
	{
		Invitees = $("ParticipantList").getElementsByClassName('ParticipantList');
		k = 0;
		for(i=0;i<Invitees.length;i++)
		{
			SendOk = true;
			buffer = Invitees[i].id.replace('activity_','').replace('_checkbox','');
			if(k>0)
			{
				List += ',';
			}
			List += buffer;
			InviteeArray[k]=buffer;
			k++;
		}
	}
	else
	{
		Invitees = $("ParticipantList").getElementsByClassName('particiapant_check');

		k = 0;
		for(i=0;i<Invitees.length;i++)
		{
			if(Invitees[i].checked)
			{
				SendOk = true;
				buffer = Invitees[i].id.replace('activity_','').replace('_checkbox','');
				if(k>0)
				{
					List += ',';
				}
				List += buffer;
				InviteeArray[k]=buffer;
				k++;
			}
		}

	}
	// if user comes for edit time get user id from parameter is numeric in type = user_id.
	if(parseInt(type))
	{
		SendOk = true;
		List = type
	}
	

	if(SendOk)
	{
		Subject = $("EmailSubject").value;
		Message = $("EmailMessage").value;
		copy_email = document.getElementById("copy_email");
		if(copy_email.checked == true)
		{
			copymail = 1;
		}
		else
		{
			copymail = 0;
		}

		if(Subject.replace(" ","").replace("\r\n","").replace("\n","") == "")
		{
			alert("Need To Enter A Subject");
			$("EmailSubject").focus();
			return;
		}

		/*if(Message.replace(" ","").replace("\r\n","").replace("\n","") == "")
		{
		alert("Need To Enter A Message");
		$("EmailMessage").focus();
		return;
		}*/


		Subject = cleanString(Subject);

		
		sendurl = webroot+'events/send_invites_outbox.json?event='+event_id+'&users='+List+'&subject='+Subject+'&copy_mail='+copymail;

		new Ajax.Request(sendurl, {
			method:'post',
			parameters: 'message='+cleanString(Message),
			onSuccess: function(transport){
				data = transport.responseText.evalJSON();
				var cnt = transport.responseText.evalJSON().length;
				// call globle function for print user list of column b on event 4 step.
				sort_user_list(event_id,'status','Desc');
			
			} 
		}
		);
		
		
	}
	else
	{
		alert("Need To Choose User To Send Invite To");
	}
}

sort_user_list = function(event_id,type,order_sort)
{
	
	sendurl = webroot+'events/sort_participant_list.json?event='+event_id+'&type='+type+'&ordersort='+order_sort;

		new Ajax.Request(sendurl, {
			method:'get',
			onSuccess: function(transport){
				data = transport.responseText.evalJSON();
				var cnt = transport.responseText.evalJSON().length;
				
				// call globle function for print user list of column b on event 4 step.
				print_edit_event_4_user(data,cnt,event_id);
				
				NameSortingID = $("namesorting");
				StatusSortingID = $("statusdiv");
				if(type=="name")
				{
					if(order_sort == "Asc")
					{
						NameSortingID.innerHTML = NameSortingID.innerHTML.replace('arrow_up.gif', 'arrow_down.gif').replace("'Asc'", "'Desc'");
						new Effect.Highlight("namesorting");
					}
					else
					{	
						NameSortingID.innerHTML = NameSortingID.innerHTML.replace('arrow_down.gif', 'arrow_up.gif').replace("'Desc'", "'Asc'");
						new Effect.Highlight("namesorting");
					}
				}
				else
				{
					if(order_sort == "Asc")
					{
						StatusSortingID.innerHTML = StatusSortingID.innerHTML.replace('arrow_up.gif', 'arrow_down.gif').replace("'Asc'", "'Desc'");
						new Effect.Highlight("statusdiv");
					}
					else
					{	
						StatusSortingID.innerHTML = StatusSortingID.innerHTML.replace('arrow_down.gif', 'arrow_up.gif').replace("'Desc'", "'Asc'");
						new Effect.Highlight("statusdiv");
					}
				}
				
			} 
		}
		
	);
		
}

// global function for print user list on edit event 4 step.
print_edit_event_4_user = function(data,cnt,event_id)
{
		// initialize variable for print
		participant_list = new Array();
		participant_list = data;
		var data_to_insert = '';
		
		ParticipantListID = $("ParticipantList");

		
		for(i=0; i<cnt; i++)
		{
			
			if(i%2 == 0)
			{
				var backgroundcolor = '#F5F4F5';
			}
			else
			{
				var backgroundcolor = '#FFFFFF';
			}
			
			data_to_insert +='<div class="clear" style="padding-top:5px;"></div>';
			data_to_insert +='<div id="activity_'+participant_list[i].id+'_li" style="background-color:'+backgroundcolor+'" class="activity_li people_life_event_box">';

			if(participant_list[i].status == 'readytosend')
			{
				data_to_insert +='<div class="leftfloat box_select_blank" id="activity_'+participant_list[i].user_id+'_user_'+participant_list[i].user_id+'_id">';
			}
			else
			{
				data_to_insert +='<div class="leftfloat box_select_blank" id="activity_'+participant_list[i].id+'_user_'+participant_list[i].user_id+'_id">';
			}

			// print icon and check box as per user type.
			switch(participant_list[i].status)
			{
				case "tobeinvited":
				{
					data_to_insert +='<div id="activity_'+participant_list[i].id+'_trash"><input class="particiapant_check" id="activity_'+participant_list[i].user_id+'_checkbox" type="checkbox" name="activity_'+participant_list[i].id+'_user_'+participant_list[i].user_id+'_id"></div></div>';
					break;
				}
				case "readytosend":
				{
						data_to_insert +='<div class="invitee_out" id="activity_'+participant_list[i].user_id+'_trash" ><img src="'+webroot+'img/icon_invitation_ready_send.gif"></div></div>';
						break;
				}
				case "invited":
				{
						data_to_insert +='<div id="activity_'+participant_list[i].id+'_trash"><img src="'+webroot+'img/icon_invitation_already_send.gif"></div></div>';
						break;
				}
				case "lifeeventmemeber":
				{
						data_to_insert +='<div id="activity_'+participant_list[i].id+'_trash"><img src="'+webroot+'img/icon_life_event_member.gif"></div></div>';
						break;
				}
			}
			

			data_to_insert +='<div class="box_email">';
			if(participant_list[i].disabled == "true")
			{
				data_to_insert +='<span id="activity_'+participant_list[i].user_id+'_title" class="bluetext1" style="padding-left:0px;">'+participant_list[i].name+'</span>';
			}
			else
			{
				data_to_insert +='<span id="activity_'+participant_list[i].user_id+'_title" class="normaltext">'+participant_list[i].name+'</span>';
			}
			data_to_insert +='</div>';
			data_to_insert +='<div class="box_role">';					


			data_to_insert +='<select id="eventsUserRole_'+participant_list[i].user_id+'"  name="userrole"';
			if(participant_list[i].disabled == "true")
			{
				data_to_insert +=' disabled=true';
			}
			if(participant_list[i].role == "Participant")
			{
				data_to_insert +=' selected="seleted" style="color:blue;"';
			}
			else if(participant_list[i].role == "Recipient")
			{
				data_to_insert +=' selected="seleted" style="color:green;"';
			}
			else if(participant_list[i].role == "Organizer")
			{
				data_to_insert +=' selected="seleted" style="color:red;"';
			}
			data_to_insert +=' onChange="changeUserRole(\''+event_id+'\',\''+participant_list[i].user_id+'\',this.value)">';

			data_to_insert +='<option name="Participant"';
			if(participant_list[i].role == "Participant")
			{
				data_to_insert += ' selected ="seleted" style="color:blue;"';	
			}
			
			data_to_insert += ' style="color:blue;">Participant</option>';
			
			data_to_insert +='<option name="Recipient"';
			
			if(participant_list[i].role == "Recipient")
			{
					data_to_insert += ' selected ="seleted" style="color:green;"';	
			}
			
			data_to_insert += ' style="color:green;">Recipient</option>';
			
			data_to_insert +='<option name="Organizer"';
			
			if(participant_list[i].role == "Organizer")
			{
					data_to_insert += ' selected ="seleted" style="color:red;"';	
			}
			
			data_to_insert += ' style="color:red;">Organizer</option>';
			
			data_to_insert +='</select></div>'; 
								
			data_to_insert +='<div class="box_action darkbluetext" id="resend_'+participant_list[i].user_id+'" >';

			// print link for participant remove or resend.
			switch(participant_list[i].status)
			{
				case "tobeinvited":
				{
					var activity_id =''; 								
					data_to_insert +='<a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="removeParticipantFromTobeinvited(\''+participant_list[i].id+'\',\''+event_id+'\')">remove</a>';
					break;
				}
				case "readytosend":
				{
					
					data_to_insert +='<a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="showMyEventInvitationBox(); edit_email_message(\''+event_id+'\', \''+participant_list[i].user_id+'\')">Edit</a>';
					data_to_insert +='<span class="leftfloat normaltext"> &nbsp;|&nbsp; </span>';
					data_to_insert +='<a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="unsend_outbox(\''+event_id+'\', \''+participant_list[i].user_id+'\')">remove</a>';			
					break;
				}
				case "invited":
				{
					data_to_insert +='<a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="resend_invite(\''+event_id+'\', \''+participant_list[i].user_id+'\')">resend</a>';
					break;
				}
				case "lifeeventmemeber":
				{
					data_to_insert +='<a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="resend_invite(\''+event_id+'\', \''+participant_list[i].user_id+'\')">resend</a>';
					break;
				}
	
			}			

			data_to_insert +='</div><div class="clear" style="padding-top:0px;"></div></div>';
											
		}
		
		ParticipantListID.innerHTML = data_to_insert;
	//	new Effect.Highlight("ParticipantList");
}

/* for unsend outbox list*/
unsend_outbox = function(event_id,user_id)
{
	var r_u_sure= confirm("Do you really want to Unsend the selected User?");
	if(r_u_sure!=true) return;


	new Ajax.Updater('ParticipantList',webroot+'events/unsendfromoutbox/?event_id='+event_id+'&users='+user_id,{frequency: 0,
	onLoading:function(){document.getElementById('ParticipantList').innerHTML = '<table align ="left" width="90%" style="height:300px"><tr><td align="right"><img src="'+webroot+'img/spinner.gif"></td><td>Loading...</td></tr></table>';},
	onComplete:function(){},
	asynchronous:true, evalScripts:true
	});

}
/* for updating outbox list*/
function newfunction(event_id)
{

	new Ajax.Updater('OutboxInviteeslist',webroot+'events/display_outboxlist/?event_id='+event_id,{frequency: 0,
	onLoading:function(){document.getElementById('OutboxInviteeslist').innerHTML = '<table align ="left" width="30%" style="height:100px"><tr><td align="right"><img src="'+webroot+'img/spinner.gif"></td><td>Loading...</td></tr></table>';},
	onComplete:function(){},
	asynchronous:true, evalScripts:true
	});
}
/* STEP 4 */
removeParticipants = function(event_id)
{
	alert("Remove Checked Part from Event: "+event_id);
}
reloadMyCommitmentsRightSidebar = function(event_id)
{
	sendurl = webroot+'events/my_commitments_right_sidebar/'+event_id;

	new Ajax.Request(sendurl, {
		method:'get',
		onSuccess: function(transport){
			data = transport.responseText;
			$('MyCommitmentsRightSidebar').innerHTML = data;
			updateMyCalendar();
		}
	});

	sendurl1 = webroot+'events/my_commitments_right_sidebar_heading/'+event_id;

	new Ajax.Request(sendurl1, {
		method:'get',
		onSuccess: function(transport){
			data1 = transport.responseText;
			$('rightsidebarmyheading').innerHTML = data1;
			updateMyCalendar();
		}
	});
	/*
	new Ajax.Updater('rightsidebarmyheading',webroot+'events/my_commitments_right_sidebar_heading/'+event_id,{frequency: 0,
	onLoading:function(){},
	onComplete:function(){
	},
	asynchronous:true, evalScripts:true
	});
	*/
}

edit_outbox = function(event_id,user_id)
{

	new Ajax.Updater('EventInvitaion',webroot+'events/edit_possible_invitation/'+event_id+'/'+user_id,{frequency: 0,
	onLoading:function(){document.getElementById('EventInvitaion').innerHTML = '<table align ="left" width="30%" style="height:100px"><tr><td align="right"><img src="'+webroot+'img/spinner.gif"></td><td>Loading...</td></tr></table>';},
	onComplete:function(){
		edit_email_message(event_id,user_id);
	//	display_outbox_complete(event_id,user_id);
	},
	asynchronous:true, evalScripts:true
	});
}

display_outbox_complete = function (event_id,user_id)
{
	new Ajax.Updater('OutboxInviteeslist',webroot+'events/edit_outboxlist/'+event_id+'/'+user_id,{frequency: 0,
	onLoading:function(){document.getElementById('OutboxInviteeslist').innerHTML = '<table align ="left" width="30%" style="height:100px"><tr><td align="right"><img src="'+webroot+'img/spinner.gif"></td><td>Loading...</td></tr></table>';},
	onComplete:function(){
		edit_email_message(event_id,user_id);
	},
	asynchronous:true, evalScripts:true
	});
}

edit_email_message = function (event_id,user_id)
{
	new Ajax.Updater('EventInvitaion',webroot+'events/edit_message_email/'+event_id+'/'+user_id,{frequency: 0,
	onLoading:function(){
		document.getElementById('EventInvitaion').innerHTML = '<table bgcolor="#24B0EB" align ="left" width="100%" style="height:480px"><tr><td align="right"><img src="'+webroot+'img/spinner.gif"></td><td>Loading...</td></tr></table>';
		
	},
	onComplete:function(){},
	asynchronous:true, evalScripts:true
	});
}
addDateUserUrgentNeed = function(date_id, user_id, event_id)
{
	CurrentEvent = event_id;
	addDateUser(date_id, user_id, "urgent_needs");

}

addDateUserRightSidebar = function(date_id, user_id, type, event_id)
{
	CurrentEvent = event_id;
	addDateUser(date_id, user_id, type);

	if(!$('my_commitment_'+date_id+'_checkbox').checked)
	{
		$("RightNumCommits").innerHTML = parseInt($("RightNumCommits").innerHTML) -1;
	}
	else
	{
		$("RightNumCommits").innerHTML = parseInt($("RightNumCommits").innerHTML) +1;
	}
}
addDateUser = function(date_id, user_id, type)
{
	truetype = type;
	if(type=="volunteer")
	{
		type = "checkbox";
	}
	if(type=="spanvolunteer")
	{
		type = "span";
	}
	if(type=="commitment_right_sidebar")
	{
		checkbox_element = $('my_commitment_'+date_id+'_checkbox');
		type = "checkbox";
	}
	else if(type=="urgent_needs")
	{
		checkbox_element = $('urgent_needs_'+date_id+'_checkbox');
		type = "checkbox";
	}
	else
	{
		checkbox_element = $('date_'+date_id+'_checkbox');
	}
	if(checkbox_element.checked && type=="span")
	{
		// Clicked Div Again
		return;
	}
	else if(!checkbox_element.checked && type=="checkbox")
	{
		// Unchecked Checkbox (Remove DateUser)
		// Checked Box or Clicked on Div
		checkbox_element.checked = false;
		sendurl = webroot+'dates_users/add_date_user?event='+CurrentEvent+'&user_id='+user_id+'&date='+date_id+'&type=remove';

		new Ajax.Request(sendurl, {
			method:'get',
			onSuccess: function(transport){
				data = transport.responseText;
				checkbox_element.blur();
				if(truetype=="volunteer" || truetype=="spanvolunteer" || truetype=="urgent_needs")
				{
					reloadMyCommitmentsRightSidebar(CurrentEvent);
				}
				else
				{
					updateMyCalendar();
				}
			}
		});
	}
	else
	{
		// Checked Box or Clicked on Div
		checkbox_element.checked = true;
		sendurl = webroot+'dates_users/add_date_user?event='+CurrentEvent+'&user_id='+user_id+'&date='+date_id+'&type=add';

		new Ajax.Request(sendurl, {
			method:'get',
			onSuccess: function(transport){
				data = transport.responseText;
				if(truetype=="volunteer" || truetype=="spanvolunteer" || truetype=="urgent_needs")
				{
					reloadMyCommitmentsRightSidebar(CurrentEvent);
				}
				else
				{
					updateMyCalendar();
				}

			}
		});

	}

}
colorSuggestedParticipants = function(id)
{
	// Add Color To Current Activity
	list_items = document.getElementsByClassName("activity_li");

	for(i=0;i<list_items.length; i++)
	{
		list_items[i].className = 'activity_li';
	}

	$("activity_" + id + "_li").className = "activity_li selected_activity";
}

hideRecord = function(dataid)
{
	var imagename = dataid.substr(5,1);
	//alert(image_name);
	var newvalue = dataid;
	document.getElementById(dataid).style.display = 'none';
	var tmp = document.getElementById('hide_image'+imagename);

	tmp.innerHTML = '<a href="javascript:void(0);" onclick="ShowRecord(\''+newvalue+'\')" ><img width="13" height="13" src="'+webroot+'img/expand.gif"/></a>';
}
ShowRecord = function(dataid)
{

	var imagename = dataid.substr(5,1);

	document.getElementById(dataid).style.display = 'block';
	var tmp = document.getElementById('hide_image'+imagename);

	tmp.innerHTML = '<a href="javascript:void(0);" onclick="hideRecord(\''+dataid+'\')" ><img width="13" height="13" src="'+webroot+'img/collapse.gif"/></a>';
}

hideTip = function()
{
	$("moretips").style.display = 'none';
	var more_info = $('moreinfoshow');

	more_info.innerHTML = '<a href="javascript:void(0);" onclick="ShowTip()" ><span class="lightblueboldtext">More tips..</span></a>';
}
ShowTip = function()
{

	document.getElementById("moretips").style.display = 'block';
	var more_info = document.getElementById('moreinfoshow');

	more_info.innerHTML = '';
}

loadParticipantDates = function(id,type,activity_title,event_id)
{
	//alert("dev");
	
	// temprary put for hide Event invitation
	document.getElementById("EventInvitaion").style.display = 'none';
	// end temp code
	CurrentEvent = event_id;
	CurrentParticipant 	= id;
	var total = new Array();
	var activity_name = new Array();
	var xx = 0;
	new Ajax.Request(webroot+'dates_users/load_participant_data.json?user_id='+id+'&event='+event_id, {
		method:'get',
		onSuccess: function(transport){
			data = transport.responseText.evalJSON();
			dataToInsert = '';
			//alert(transport.responseText);

			for(i=0;i<data.length;i++)
			{
				total[i] = 0;
				GroupData = data[i].Data;
				activity_name[i] = 0;
				//				alert(GroupData.length);
				for(j=0;j<GroupData.length;j++)
				{
					if(GroupData[j].Date!=undefined)
					{
						Dates = GroupData[j].Date;
						total[i] = parseInt(total[i]) + parseInt(Dates.length);
						activity_name[i] = GroupData[j].Name;
						var len = activity_name[i].length;
						if(len > 21)
						{
							var newname = activity_name[i].substring(0,19);
							activity_name[i] = newname + '...';
						}
						else
						{
							activity_name[i] = GroupData[j].Name;
						}
					}
				}
			}

			for(k=0;k<total.length;k++)
			{
				//alert(data.length);
			}
			for(i=0;i<data.length;i++)
			{
				//alert("Group:" + GroupName);
				// code for Heading on date display and select all and select none.
				if(i == 0)
				{
					dataToInsert += '<div class="darkbluetext" style="font-style:italic; padding-left:50px;padding-top:10px;font-size:14px;">Assign an Activity Date to those selected in B:</div><div class="darkbluetext" style=" padding-left:100px;padding-top:2px;padding-bottom:10px;">(see Calender below for reference)</div>';
				
					dataToInsert += '<div style="padding-left:10px"><div class="leftfloat normaltext" style="color:#0071B7;"><span class="normaltext"><a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="removeDate4step()"><img src="'+webroot+'img/trash.gif" /></a></span><span class="normaltext">&nbsp;Select&nbsp;</span></div><div class="leftfloat normaltext" style="color:#0071B7;"><a style="padding-top:2px;" href="javascript:void(0)" onclick="select_all_four(\'ActivitySchedulingContent\',\'date_four_selection\')">All</a></span><span class="normaltext">&nbsp; | &nbsp; <a style="padding-top:2px;" href="javascript:void(0)" onclick="select_none_four(\'ActivitySchedulingContent\',\'date_four_selection\')">None</a></span></span> </div><span class="normaltext rightfloat" style="padding-right: 30px;" >[# volunteers needed]</span></div>';
				}


				GroupData = data[i].Data;


				for(j=0;j<GroupData.length;j++)
				{
					GroupName = GroupData[j].Name;
					GroupLength = 0;
					if(GroupData[j].Date!=undefined)
					{
						GroupLength = GroupData[j].Date.length;
					}
					if( (j==0 || (j>0 && GroupName!=GroupData[j-1].Name)) && GroupLength>0)
					{
						xx = xx + 1;
						dataToInsert += '<div id= "name_'+GroupData[j].Id+'" class="clear" />';
						dataToInsert += '<div class="clear" style="padding-top:5px;"></div><div class="leftfloat" style="padding-left:12px;"><div id="hide_image'+xx+'" ><a href="javascript:void(0);" onclick="hideRecord(\'main_'+xx+'\')" <img width="13" height="13" src="'+webroot+'img/collapse.gif"/></a></div></div><div class="leftfloat" style="padding-left:9px;line-height:14px;"><span class="normaltext"><strong>'+ GroupName +'</strong><strong>('+GroupLength+')</strong></span></div></div>';
					}
					Activity_id = GroupData[j].Id;
					if(GroupData[j].Date!=undefined)
					{
						//alert("AD"+GroupData[j].Date);
						Dates = GroupData[j].Date;
						for(k=0;k<Dates.length;k++)
						{
							if(Dates[k].checked=="yes")
							{
								checkedstring = ' checked="checked"';
							}
							else
							{
								checkedstring = '';
							}

							newNumber = i+1;

							var fordate = Dates[k].start_time.split(" ");
							var timestring = '';
							var onlydate = fordate[0].split("/");
							var startonlydate = fordate[0].split("-");
							var starttime = fordate[1].split(":");
							var hours = starttime[0];

							if(hours > 11){
								timestring = "PM";
								if(hours != 12)
								{
									starttime[0] =	starttime[0] - 12;
								}
							} else {
								timestring = "AM";
							}
							var finaltime = starttime[0] +":"+ starttime[1] +" "+ timestring;
							var dateDisp = startonlydate[1] + "/" + startonlydate[2] + "/" + startonlydate[0]+ " " + finaltime;


							if(timezone_abbreviations[Dates[k].start_timezone]!=undefined)
							{
								var start_timezone = ' ('+timezone_abbreviations[Dates[k].start_timezone]+')';
							}
							else
							{
								var start_timezone = '';
							}
							dateDisp += start_timezone;


							if(Dates[k].end_time == null)
							{
								var endDateDisp = '  To  (No End Time)';
							}
							else if(Dates[k].start_time == Dates[k].end_time)
							{
								var endDateDisp = '  To  (No End Time)';
							}
							else
							{
								var timesting = '';
								var endFordate = Dates[k].end_time.split(" ");
								var endOnlydate = endFordate[0].split("/");
								var endOnlydate_new = endFordate[0].split("-");
								var starttime = fordate[1].split(":");
								var hours = starttime[0];
								if(hours > 11){
									timestring = "PM";
									if(hours != 12)
									{
										starttime[0] =	starttime[0] - 12;
									}
								} else {
									timestring = "AM";
								}
								var finaltime = starttime[0] +":"+ starttime[1] +" "+ timestring;

								var endDateDisp = endOnlydate_new[1] + "/" + endOnlydate_new[2] + "/" + endOnlydate_new[0]+ " " + finaltime;

								if(timezone_abbreviations[Dates[k].end_timezone]!=undefined)
								{
									var end_timezone = ' ('+timezone_abbreviations[Dates[k].end_timezone]+')';
								}
								else
								{
									var end_timezone = '';
								}

								endDateDisp = '  To  '+endDateDisp+end_timezone;
							}

							if(k==0)
							{
								dataToInsert += '<div id= "main_'+xx+'" class="clear" >';
							}
							dataToInsert += '<div class="clear" style="padding-top:5px;"></div><div id="activity_'+Dates[k].id+'_li" style="cursor:pointer;cursor:hand;padding-left:20px;" class="activity_li"><div class="leftfloat"><a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="removeDate4step(\''+Activity_id+'\',\''+event_id+'\',\''+id+'\')"><img src="'+webroot+'img/trash.gif" /></a>&nbsp;<input class="date_four_selection" name="date_'+Dates[k].id+'_checkbox" type="checkbox" id="date_'+Dates[k].id+'_checkbox" onclick="addDateUser(\''+Dates[k].id+'\',\''+CurrentParticipant+'\',\'checkbox\')" '+checkedstring+'/></div><div class="leftfloat" onclick="addDateUser(\''+Dates[k].id+'\',\''+CurrentParticipant+'\',\'span\')" style="padding-left:7px;width:310px;"><span id="activity_'+Dates[k].id+'_title" class="normaltext">'+ dateDisp+endDateDisp +'</span></div><div class="clear" style="padding-top:0px;"></div></div>';

							var activity_counter = "";
							activity_counter = k +1;
							if(GroupLength==activity_counter)
							{
								dataToInsert += '</div>';
							}
							//				alert(dateDisp+endDateDisp);

							//dataToInsert += '<div style="padding-left:7px;">'+ GroupData[j].Name +' '+ Dates[k].start_time +'</div>';

						}

					}

				}dataToInsert += '</div>';

			}


			//	alert('Hey');

			colorSuggestedParticipants(id);

			// Show Content Divs
			$("SchedulingWaiting").className = $("SchedulingWaiting").className +' hidden';

			$("ActivitySchedulingContent").className = 'whiteborder';

			$("ActivitySchedulingContent").innerHTML = dataToInsert;

		}
	});
}

removeDate4step = function(activity_id,event_id,user_id)
{
	var currentuserid  = user_id;
	var currentactivity_id = activity_id;
	var currentevent_id = event_id;

	datesToRemove = new Array();
	n = 0;
	inputs 		  = $('ActivitySchedulingContent').getElementsByTagName('input');
	for(i=0;i<inputs.length;i++)
	{
		if(inputs[i].type=="checkbox" && inputs[i].checked)
		{
			date_id = inputs[i].name.replace("date_","").replace("_checkbox","");
			datesToRemove[n]=date_id;
			n++;
		}
	}
	if(activity_id==0)
	{
		alert("Please Select Activity First");
	}
	else if(datesToRemove.length==0)
	{
		alert("Please Select Date First");
	}
	else
	{
		var r_u_sure= confirm("Do you really want to DELETE the selected Dates?");
		if(r_u_sure!=true) return;

		dateString = '';
		for(i=0;i<datesToRemove.length;i++)
		{
			if(dateString!='') dateString = dateString+',';

			dateString = dateString+datesToRemove[i];
		}

		new Ajax.Request(webroot+'dates/remove_date.json?event='+event_id+'&activity='+activity_id+'&date='+dateString, {
			method:"get",
			onSuccess: function(transport){

				loadParticipantDates(currentuserid,'','',currentevent_id);
			//	showDates4step(currentuserid,currentevent_id);
			}
		});
	}
}

checkEmail = function(str)
{

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail ID")
		return false
	}

	return true
}

loadParticipants = function(event_id)
{
	new Ajax.Request(webroot+'events_users/load_participants.json?event='+event_id, {
		method:"get",
		onSuccess: function(transport){
			data = transport.responseText;
			//alert(data);
		}
	});
	//alert(url);
}

addParticipantRequest = function(event_id,nick_name,email_address,type,user_id,last_name)
{

	ParticipantListID = $("ParticipantList");

	if(type=='normal')
	{
		url = webroot+'events_users/add_participant.json?event='+event_id+'&name='+nick_name+'&email='+email_address+'&lastname='+last_name;
	}
	else
	{
		url = webroot+'events_users/add_participant.json?event='+event_id+'&name='+nick_name+'&email='+email_address;
	}

	new Ajax.Request(url, {
		method:"get",
		onSuccess: function(transport){
			data = transport.responseText.evalJSON();


			if(data.status)
			{
				alert(data.status);
				return;
			}

			var activity_id = '';
			sort_user_list(event_id,'status','Desc');
			


			new Element.scrollTo('ParticipantList', 0, $('ParticipantList').offsetTop);

			var select_field = $("ParticipantList").getElementsByClassName('particiapant_check');
			if(select_field.length > 0)
			{
				$('Trash_Particiapnt_List').className = '';
			}

			if(type=='suggested')
			{
				$('suggested_'+data.user_id).remove();
			}
			if(type=='normal')
			{
				ParticipantEmail.value = '';
				ParticipantFirstname.value  = '';
				ParticipantLastname.value  = '';
				ParticipantNotes.value = '';
				ParticipantEmail.focus();
			}
		}
	});
}

addParticipantFromSuggested = function(event_id,email_address,user_id,name)
{
	if(confirm("Are you sure you want to add this user to your event?"))
	{
		addParticipantRequest(event_id, name, email_address,'suggested',user_id,'');
	}
}


addMultiParticipant = function(event_id)
{
	ParticipantEmail = $("ParticipantEmailAll");
	if(ParticipantEmail.value=='')
	{
		alert("Please Enter Email Addresses");
		ParticipantEmail.focus();
	}
	else
	{
		var str = ParticipantEmail.value;
		var brokenstring=str.split(',');


		for(var i = 0 ; i < brokenstring.length ; i++)
		{
			if(checkEmail(brokenstring[i])!=true)
			{
				alert("Email Address is not valid");
				ParticipantEmail.focus();
				ParticipantEmail.select();
			}
			else
			{
				addParticipantRequest(event_id, brokenstring[i], brokenstring[i],'notNormal','','');
			}
		}
	}
	//new Ajax.Updater('ParticipantList',webroot+'users/delete_user_activity/'+chk_act+'/'+strval,{frequency: 0,
	//		onLoading:function(){},
	//		onComplete:function(){},
	//		asynchronous:true, evalScripts:true
	//	});

}


addParticipant = function(event_id)
{
	ParticipantEmail = $("ParticipantEmail");
	ParticipantFirstname  = $("ParticipantFirstname");
	ParticipantLastname  = $("ParticipantLastname");
	ParticipantNotes  = $("ParticipantNotes");

	if(ParticipantEmail.value=='')
	{
		alert("Please Enter Email Address2");
		ParticipantEmail.focus();
	}
	else if(checkEmail(ParticipantEmail.value)!=true)
	{
		alert("Email Address is not valid");
		ParticipantEmail.focus();
		ParticipantEmail.select();
	}
	else
	{
		addParticipantRequest(event_id, ParticipantFirstname.value, ParticipantEmail.value,'normal','',ParticipantLastname.value);

	}
}
/* STEP 3 */
send = function(url,post_params)
{
	if(post_params && post_params.length > 0)
	{
		new Ajax.Request(url, {
			method:"post",
			params:post_params,
			onSuccess: function(transport){
				data = transport.responseText;
			}
		});
	}
	else
	{
		new Ajax.Request(url, {
			method:"get",
			onSuccess: function(transport){
				data = transport.responseText;
			}
		});
	}
}

sendJSON = function(url,post_params)
{
	if(post_params && post_params.length > 0)
	{
		new Ajax.Request(url, {
			method:"post",
			params:post_params,
			onSuccess: function(transport){
				data = transport.responseText.evalJSON();
			}
		});
	}
	else
	{
		new Ajax.Request(url, {
			method:"get",
			onSuccess: function(transport){
				data = transport.responseText.evalJSON();
			}
		});
	}
}

removeDate = function(activity_id,event_id)
{


	datesToRemove = new Array();
	n = 0;
	inputs 		  = $('ActivitySchedulingContent').getElementsByTagName('input');
	for(i=0;i<inputs.length;i++)
	{
		if(inputs[i].type=="checkbox" && inputs[i].checked)
		{
			date_id = inputs[i].name.replace("date_","");
			datesToRemove[n]=date_id;
			n++;
		}
	}
	if(activity_id==0)
	{
		alert("Please Select Activity First");
	}
	else if(datesToRemove.length==0)
	{
		alert("Please Select Date First");
	}
	else
	{
		var r_u_sure= confirm("Do you really want to DELETE the selected Dates?");
		if(r_u_sure!=true) return;

		dateString = '';
		for(i=0;i<datesToRemove.length;i++)
		{
			if(dateString!='') dateString = dateString+',';

			dateString = dateString+datesToRemove[i];
		}

		new Ajax.Request(webroot+'dates/remove_date.json?event='+event_id+'&activity='+activity_id+'&date='+dateString, {
			method:"get",
			onSuccess: function(transport){
				showDates(activity_id,event_id);
			}
		});
	}
}
showDates = function(activity_id,event_id)
{
	$('ActivitySchedulingContent').innerHTML = '<div class="normaltext">Loading Dates...</div>';
	//$('ActivityNamecolumnc').innerHTML = '<div class="clear" style="padding-top: 1px; width:240px; padding-left:10px;border: 1px solid rgb(204, 204, 204);"><span>Loading Activity Name...</span></div>';
	$('add_date_button').onclick = function() {
		addDate(activity_id, event_id);
	}
	$('TrashSelectAll').className = 'hidden';

	var activity_name = document.getElementById('ActivityName').value;
	new Ajax.Request(webroot+'dates/load_dates.json?event='+event_id+'&activity='+activity_id, {
		method:"get",
		onSuccess: function(transport){
			data = transport.responseText.evalJSON();
			var dataToInsert = '';
			//dataToInsert = dataToInsert+'<div class="normaltext" align="center" style="padding-top:15px; padding-bottom:15px;"><a href="javascript:void(0)" style="color:#0071B7;" onclick="addDate('+activity_id+','+event_id+')">Add New Date</a></div>';
			if(data.length==0)
			{
				$('ActivityNameDisplay').className = '';
				//$('ActivityNamecolumnc').innerHTML = activity_name;
				dataToInsert = '<div class="normaltext" align="center" style="padding-top:15px; padding-bottom:15px;font-size:16px;color:#9d9e9f;"><strong>When is this Activity?</strong></div>';
			}
			else
			{
				for(i=0;i<data.length;i++)
				{
					newNumber = i+1;
					var fordate = data[i].start_time.split(" ");
					var onlydate = fordate[0].split("/");
					var dateDisp = onlydate[0] + "/" + onlydate[1] + "/20" + onlydate[2] + " " + fordate[1];

					if(timezone_abbreviations[data[i].start_timezone]!=undefined)
					{
						var start_timezone = ' ('+timezone_abbreviations[data[i].start_timezone]+')';
					}
					else
					{
						var start_timezone = '';
					}
					dateDisp += start_timezone;


					if(data[i].end_time===null)
					{
						var endDateDisp = '';
					}
					else
					{
						var endFordate = data[i].end_time.split(" ");
						var endOnlydate = endFordate[0].split("/");
						var endDateDisp = endOnlydate[0] + "/" + endOnlydate[1] + "/20" + endOnlydate[2] + " " + endFordate[1];

						if(timezone_abbreviations[data[i].end_timezone]!=undefined)
						{
							var end_timezone = ' ('+timezone_abbreviations[data[i].end_timezone]+')';
						}
						else
						{
							var end_timezone = '';
						}

						endDateDisp = '<span style="display:block;text-align:center;font-size:10px;line-height:10px;" class="greytext">To</span>'+endDateDisp+end_timezone;
					}

					if(i == 0)
					{
						$('ActivityNameDisplay').className = '';
						
						$('TrashSelectAll').className = '';
						$('TrashSelectAll').innerHTML = '<div id="select_all_dates"><div class="leftfloat normaltext" style="color:#0071B7;"><span class="normaltext"><a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="removeDate(\''+activity_id+'\',\''+event_id+'\')"><img src="'+webroot+'img/trash.gif" /></a></span><span class="normaltext">&nbsp;Select&nbsp;</span></div><div class="leftfloat normaltext" style="color:#0071B7;"><a style="padding-top:2px;" href="javascript:void(0)" onclick="select_all_date()">All</a></span><span class="normaltext">&nbsp; | &nbsp; <a style="padding-top:2px;" href="javascript:void(0)" onclick="select_none_date()">None</a></span></span> </div>';
						//$('ActivityNamecolumnc').innerHTML = activity_name;
					
					}


					dataToInsert = dataToInsert+'<div style="padding-left:15px; width:215px; "><div class="ActivityDate" style="width: 215px; padding-left: 25px; padding-top:3px; padding-bottom:3px; border-bottom: 1px solid rgb(204, 204, 204); " id="Date_'+data[i].id+'"><div class="leftfloat"><span class="normaltext"><a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="removeDate(\''+activity_id+'\',\''+event_id+'\')"><img src="'+webroot+'img/trash.gif" /></a></span>&nbsp;<input type="checkbox" class="dateselect" value="" name="date_'+data[i].id+'"/></div><div style="padding-left: 4px;" class="leftfloat"><span class="normaltext"><strong><a style="color:#0071B7; font-weight:normal;" onclick="Modalbox.show(this.href, {title: this.title, height: 270,width: 645}); return false;" title="Choose Date: Date '+newNumber+'" href="'+webroot+'dates/choose_activity_date?event='+event_id+'&activity='+activity_id+'&date='+data[i].id+'" style="font-size:11px;">'+dateDisp+endDateDisp+'</a></strong></span></div><div class="clear" style="height:1px;overflow:hidden;line-height:1px;"></div></div></div><div class="clear"></div>';

				}

			}

			$('ActivitySchedulingContent').innerHTML = dataToInsert;
			new Effect.Highlight('step_c_flash', {endcolor: '#f2f6f9'});
		}
	});
}
addDate = function(activity_id,event_id)
{
	if(activity_id==0)
	{
		alert("Please Select Activity First");
	}
	else
	{
		url = webroot+'dates/choose_activity_date?event='+event_id+'&activity='+activity_id;
		Modalbox.show(url, {title: "Add New Date",height: 270, width: 645});
	}
}
sendActivityUpdate = function(type,field,value,event_id)
{
	NeedToUpdate = false;
	switch(field)
	{
		case "name":
		if(value!=CurrentName) NeedToUpdate = true;
		CurrentName = value;
		break;
		case "description":
		if(value!=CurrentDescription) NeedToUpdate = true;
		CurrentDescription = value;
		break;
		case "considerations":
		if(value!=CurrentConsiderations) NeedToUpdate = true;
		CurrentConsiderations = value;
		break;
	}
	//alert("CurrentName: "+CurrentName+"\nCurrentDescription: "+CurrentDescription+"\nCurrentConsiderations: "+CurrentConsiderations);
	if(NeedToUpdate==true)
	{
		if(field=="name")
		{
			titletag = $('activity_'+CurrentActivity+'_title');
			titletag.innerHTML = value;
		}
		new Ajax.Request(webroot+'activities/update_activity_data.json?id='+CurrentActivity+'&field='+field+'&event='+event_id+'&type=update', {
			method:'post',
			parameters: 'value='+cleanString(value),
			onSuccess: function(transport){
				// alert("Removed "+id);
			}
		});
		// alert("Activity: "+CurrentActivity+"\nField: "+field+"\nValue: "+value);
	}
}
add_new_activity = function(event_id)
{
	if(name = prompt("Enter Name of your New Activity:"))
	{
		if(name.stripSpaces()!="")
		{
					
			new Ajax.Request(webroot+'activities/create_activity.json?event='+event_id+'&name='+name, {
				method:'get',
				onSuccess: function(transport){
					data = transport.responseText.evalJSON();
					var NewHTML = '';
					var user_field = $("name_0");
					var i = '0';	
					
				    if(user_field==undefined)
					{
						NewHTML += '<div id="CustomActivityList">';
						NewHTML += '<div class="clear" style="padding-top:5px;"></div><div class="leftfloat" style="padding-left:2px;width:13px;"><div class="clear" id="hide_image'+i+'" ><a href="javascript:void(0);" onclick="hideRecord(\'name_'+i+'\')" > <img width="13" height="13" src="'+webroot+'img/collapse.gif"/></a></div></div><div class="CustomActivities" style="margin-left:15px;padding-left:9px; padding-top:1px; line-height:12px;"><span class="normaltext" style="color:#006DB2;"><strong>Custom Activities</strong></span></div><div id= "name_'+i+'" class="clear" style="padding-left:11px;">'; 
					}
					
						
					NewHTML += '<div class="clear" style="padding-top:5px;"></div>';
					NewHTML +='<div id="activity_'+data.id+'_li" style="cursor:pointer;cursor:hand;" class="activity_li">';
					NewHTML +='<div class="leftfloat">';
					NewHTML +='<input name="activity_'+data.id+'_checkbox" type="checkbox" checked="checked" id="activity_'+data.id+'_checkbox" onclick="loadActivityDescription(\''+data.id+'\',\'checkbox\',\'Custom Activities\',\''+event_id+'\')"  />';
					NewHTML +='</div>';
					NewHTML +='<div class="leftfloat" style="padding-left:7px;">';
					NewHTML +='<span id="activity_'+data.id+'_title" class="normaltext" onclick="loadActivityDescription(\''+data.id+'\',\'span\',\'Custom Activities\',\''+event_id+'\')">'+data.name+'</span>';
					NewHTML +='</div>';
					NewHTML +='<div class="clear" style="padding-top:0px;"></div>';
					NewHTML +='</div></div>';
					
					
					if(user_field==undefined)
					{
						NewHTML += '</div>';
						$("activity_list_ul").innerHTML = NewHTML + $("activity_list_ul").innerHTML  ;
					}
					else
					{
						$("name_0").innerHTML = $("name_0").innerHTML+NewHTML;
					}
					
					loadActivityDescription(data.id,'span','User Created',event_id);

				}
			});

		}
		else
		{
			alert("Invalid Name");	
		}
	}
}
colorSuggestedActivity = function(id)
{
	// Add Color To Current Activity
	list_items = $("activity_list_ul").getElementsByClassName("activity_li");

	for(i=0;i<list_items.length; i++)
	{
		list_items[i].className = 'activity_li';
	}

	$("activity_" + id + "_li").className = "activity_li selected_activity";
}
loadActivityDescription = function(id,type,activity_title,event_id)
{
	if(id==CurrentActivity && type!="checkbox")
	{
		//alert("You Already Have That One Selected");
		return false;
	}
	CurrentActivity 	= id;

	if(!$("activity_" + id + "_checkbox").checked && type=="checkbox")
	{
		$("activity_" + id + "_li").className = '';
		$("activity_" + id + "_checkbox").blur();
		
		// Show Content Divs
		$("ActivitySchedulingContent").className = 'hidden';
		$("ActivityDescriptionContent").className = 'hidden';
		$("ActivityNameDisplay").className = 'hidden';
		$("select_all_dates").className = 'hidden';
			
		// $("date_description_border").className =$("date_description_border").className.replace(' new_step_blue_box_active', '');
		// $("date_list_border").className =$("date_list_border").className.replace(' new_step_blue_box_active', '');

		// Show Waiting Divs
		$("SchedulingWaiting").className = $("SchedulingWaiting").className.replace(' hidden', '');
		$("DescriptionWaiting").className = $("DescriptionWaiting").className.replace(' hidden', '');
			
		new Ajax.Request(webroot+'activities/load_activity_data.json?id='+id+'&event='+event_id+'&remove=1', {
			method:'get',
			onSuccess: function(transport){
				//alert("Removed "+id);
			}
		});
		return false;
	}

	if($("activity_" + id + "_checkbox").checked && type=="checkbox")
	{
		colorSuggestedActivity(id);
		//return false;
	}

	//return false;

	new Ajax.Request(webroot+'activities/load_activity_data.json?id='+id+'&event='+event_id, {
		method:'get',
		onSuccess: function(transport){
			data = transport.responseText.evalJSON();

			// Show Content Divs
			$("ActivitySchedulingContent").className = '';
			$("ActivityDescriptionContent").className = '';
			
			// $("date_description_border").className +=' new_step_blue_box_active';
			// $("date_list_border").className +=' new_step_blue_box_active';

			// Hide Waiting Divs
			$("SchedulingWaiting").className = $("SchedulingWaiting").className +' hidden';
			$("DescriptionWaiting").className = $("DescriptionWaiting").className +' hidden';

			// Add Color To Current Activity
			colorSuggestedActivity(id);
			$("activity_" + id + "_checkbox").checked = true;


			//$("ActivityName").value = "Type the name for your Activity here. For example: \"John Foster's "+data.name+" Activity\"";
			$("ActivityName").value = data.name;
			$("ActivityDescription").value = data.description;
			$("ActivityConsiderations").value = data.considerations;
			//	$("ActivityTitle").innerHTML = activity_title+": " + data.name;

			CurrentName			  = data.name;
			CurrentDescription	  = data.description;
			CurrentConsiderations = data.considerations;
			Resources 			  = data.resources;

			ResourceContent = '';
			for(i=0;i<Resources.length;i++)
			{
				ResourceContent +='<div id="resource_link_'+Resources[i].id+'"><a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="removeResource(\''+data.id+'\',\''+Resources[i].id+'\',\'remove\')"><img src="'+webroot+'img/trash.gif" /></a><div class="bluetext" style="font-size:11px;margin-left:15px;">'+Resources[i].name+'</div></div>';
			}
			$("AddNewResource").href = webroot+'event/'+event_id+'/resources/add/'+data.id;
			$("ActivityResources").innerHTML = ResourceContent;
			new Effect.Highlight('step_b_flash', {endcolor: '#f2f6f9'});
			showDates(CurrentActivity,event_id);
		}
	});
}

/* STEP 1b */
switchParticipantOption = function(type)
{
	switch(type)
	{
		case "me":
		//alert("me");
		$('DifferentThanOrganizer').className = 'profiles form hidden';
		$('SameAsOrganizer').className = '';
		break;
		default:
		//alert("other");
		$('DifferentThanOrganizer').className = 'profiles form';
		$('SameAsOrganizer').className = 'hidden';
		break;
	}
}

/* STEP 1 */
loadEventData = function(id)
{
	//alert(id);
	if(id == -100)
	{
		$("EventName").disabled = false;
		$("EventMessage").disabled = false;
		$("EventName").className = '';
		$("EventMessage").className = '';
		$("EventName").value = '';
	}
	else
	{
		new Ajax.Request(webroot+'events/load_event_data.json?id='+id, {
			method:'get',
			onSuccess: function(transport){
				data = transport.responseText.evalJSON();

				$("EventName").disabled = false;
				$("EventMessage").disabled = false;
				//		$("EventInformation").disabled = false;

				$("EventName").className = '';
				$("EventMessage").className = '';
				//	$("EventInformation").className = '';
				//$("EventName").value = "Type the name for your event here. For example: \"John Foster's "+data.name+" Event\"";
				$("EventName").value = data.name;
				$("EventMessage").value = data.message;
				//	$("EventInformation").value = data.information;
			}
		});
	}



}

custom = function()
{
	$("EventName").disabled = false;
	$("EventInformation").disabled = false;
	$("EventMessage").disabled = false;

	$("EventName").className = '';
	$("EventMessage").className = '';
	$("EventInformation").className = '';

}

regeneratePreview = function()
{

	if (document.getElementById("LoadingDiv"))
	{ 
		$('LoadingDiv').style.display = 'block';
		$('LoadingDiv2').style.display = 'block';
	}
	
	$('LoadingDiv3').style.display = 'block';
	$('LoadingDiv4').style.display = 'block';
	if(EventName=='') EventName = 'An Event To Be Remembered';

	var now = new Date();
	var t 	= now.getTime().toString();
	if($('ThemeType').value=='custom')
	{
		$("Preview_small").src = webroot+"themes/banner_image?font="+FontId+"&font_color="+FontColor+"&banner_color="+BannerColor+"&alignment="+Alignment+"&font_size="+FontSize+"&text="+EventName+"&t="+t;
		$("WebpagePreviewLink").href = webroot+"themes/preview_webpage?font="+FontId+"&font_color="+FontColor+"&banner_color="+BannerColor+"&alignment="+Alignment+"&font_size="+FontSize+"&text="+EventName+"&t="+t;
	}
	else
	{
		$("Preview_small").src = webroot+"themes/banner_image?theme="+ThemeId+"&text="+EventName+"&t="+t;
		$("WebpagePreviewLink").href = webroot+"themes/preview_webpage?theme="+ThemeId+"&text="+EventName+"&t="+t;
	}


}

clearLoadingDiv = function()
{
	
	if (document.getElementById("LoadingDiv"))
	{ 
		$('LoadingDiv').style.display = 'none';
		$('LoadingDiv2').style.display = 'none';
	}
	
	$('LoadingDiv3').style.display = 'none';
	$('LoadingDiv4').style.display = 'none';
}

changeTheme = function(id)
{

	var anchors = $("ThemeListItems").getElementsByTagName('a');
	for(i=0;i<anchors.length;i++)
	{
		anchors[i].style.backgroundColor = '#DFD4B5';
	}
	$("Theme_"+id).style.backgroundColor = '#ff0000';
	$("ThemeId").value = id;
	ThemeId = id;
	$('ThemeType').value = 'theme';
	regeneratePreview();
}

commit_act_chk = function(chk_act)
{
	var arr_check = new Array();
	var field_act = document.getElementsByName('chk_act[]');
	var status_activity = false;
	var field = document.getElementsByName('cmb_id[]');
	var flag = confirm("Are you sure you would like to no longer perform this activity?");


	if(flag!=true)
	{
		for(var i = 0 ; i < field_act.length ; i++)
		{

			field_act[i].checked = true;
		}
		return;
	}
	else
	{
		for (var i = 0; i < field.length; i++)
		{
			if(field[i].checked == true)
			{
				status_activity = true;
				break;
			}
		}
		if(status_activity == true)
		{
			for (var i = 0, j = 0; i < field.length; i++)
			{
				if(field[i].checked == true)
				{
					arr_check[j] = 	field[i].value;
					j = j + 1;
				}
			}
		}
		else
		{
			for (var i = 0, j = 0; i < field.length; i++)
			{
				arr_check[j] = 	field[i].value;
				j = j + 1;
			}
		}


		var strval = '';
		for (var i = 0; i < arr_check.length ; i++)
		{
			if(strval == '')
			{
				strval = arr_check[i];
			}
			else
			{
				strval = strval+','+arr_check[i];
			}
		}

		new Ajax.Updater('update_activities',webroot+'users/delete_user_activity/'+chk_act+'/'+strval,{frequency: 0,
		onLoading:function(){document.getElementById('update_activities').innerHTML = '<table width="100%" style="height:300px"><tr><td align="right"><img src="'+webroot+'img/spinner.gif"></td><td>Loading...</td></tr></table>';},
		onComplete:function(){},
		asynchronous:true, evalScripts:true
		});
	}
}
hide_directory = function(event_id,user_id)
{
	new Ajax.Request(webroot+'directory/blockuser/?event='+event_id+'&user_id='+user_id, {
		method:'get',
		onSuccess: function(transport){
			data = transport.responseText.evalJSON();
		}
	});
}
event_home_image = function(event_id,id)
{

	new Ajax.Updater('',webroot+'event/'+event_id+'/multimedia/event_home_photo/'+event_id+'/'+id,{frequency: 0,
	onLoading:function(){},
	onComplete:function(){},
	asynchronous:true, evalScripts:true
	});
}
loadActivities = function(frmName)
{
	var arr_check = new Array();
	var field = document.getElementsByName('cmb_id[]');
	var status_activity = false;

	for (var i = 0; i < field.length; i++)
	{
		if(field[i].checked == true)
		{
			status_activity = true;
			break;
		}
	}



	if(status_activity == true)
	{
		for (var i = 0, j = 0; i < field.length; i++)
		{
			if(field[i].checked == true)
			{
				arr_check[j] = 	field[i].value;
				j = j + 1;
			}
		}
	}
	else
	{
		for (var i = 0, j = 0; i < field.length; i++)
		{
			arr_check[j] = 	field[i].value;
			j = j + 1;
		}
	}


	var strval = '';
	for (var i = 0; i < arr_check.length ; i++)
	{
		if(strval == '')
		{
			strval = arr_check[i];
		}
		else
		{
			strval = strval+','+arr_check[i];
		}
	}

	new Ajax.Updater('update_activities',webroot+'users/myevent/'+strval,{frequency: 0,
	onLoading:function() {document.getElementById('update_activities').innerHTML = '<table width="100%" style="height:300px"><tr><td align="right"><img src="'+webroot+'img/spinner.gif"></td><td>Loading...</td></tr></table>';
	loadingMe(field);
	},
	onComplete:function(){},
	asynchronous:true, evalScripts:true
	});


}
sortmyaccountevent = function(sortorder)
{
	document.getElementById('sortevent').innerHTML  ='<div class="leftfloat" style="width:90px" align="center" id="sortevent"><span class="lightblueboldtext">Last Visited </span></div>';
	var activity_link = document.getElementById('sortactivity');



	new Ajax.Updater('update_event',webroot+'users/alleventsort/'+sortorder,{frequency: 0,
	onLoading:function() {document.getElementById('update_event').innerHTML = '<table width="100%" style="height:300px"><tr><td align="right"><img src="'+webroot+'img/spinner.gif"></td><td>Loading...</td></tr></table>';
	loadingMe(field);
	},
	onComplete:function(){
		if(sortorder == 'Asc')
		{
			document.getElementById('sortevent').innerHTML  ='<div class="leftfloat" style="width:90px" align="center" id="sortevent"><span class="lightblueboldtext"><a href="javascript:sortmyaccountevent(\'Desc\');">Last Visited </a></span></div>';

		}

		if(sortorder == 'Desc')
		{
			document.getElementById('sortevent').innerHTML  ='<div class="leftfloat" style="width:90px" align="center" id="sortevent"><span class="lightblueboldtext"><a href="javascript:sortmyaccountevent(\'Asc\');">Last Visited </a></span></div>';

		}
	},
	asynchronous:true, evalScripts:true
	});
}

sortmyaccountactivity = function(sortorder)
{
	document.getElementById('sortactivity').innerHTML  ='<div class="leftfloat" style="width:150px; " align="center" id="sortactivity"><span class="lightblueboldtext" >Day/Time</span></div>';

	new Ajax.Updater('update_activities',webroot+'users/allactivitysort/'+sortorder,{frequency: 0,
	onLoading:function() {document.getElementById('update_activities').innerHTML = '<table width="100%" style="height:300px"><tr><td align="right"><img src="'+webroot+'img/spinner.gif"></td><td>Loading...</td></tr></table>';
	loadingMe(field);
	},
	onComplete:function(){
		if(sortorder == 'Asc')
		{
			document.getElementById('sortactivity').innerHTML  ='<div class="leftfloat" style="width:150px; " align="center" id="sortactivity"><span class="lightblueboldtext" ><a href="javascript:sortmyaccountactivity(\'Desc\');">Day/Time</a></span></div>';
		}
		if(sortorder == 'Desc')
		{
			document.getElementById('sortactivity').innerHTML  ='<div class="leftfloat" style="width:150px;" align="center" id="sortactivity"><span class="lightblueboldtext" ><a href="javascript:sortmyaccountactivity(\'Asc\');">Day/Time</a></span></div>';
		}
	},
	asynchronous:true, evalScripts:true
	});

}

completeTask = function(field)
{
	for(var i = 0; i < field.length; i++)
	{
		field[i].disabled = false;
	}
}

loadingMe = function(field)
{
	for(var i = 0; i < field.length; i++)
	{
		field[i].disabled = true;
	}
}

loaddata_chk = function(frmName)
{
	var arr_check = new Array();
	var field = document.getElementsByName('chk_user[]');
	var status_activity = '';

	for (var i = 0; i < field.length; i++)
	{
		if(status_activity == '')
		{
			if(field[i].checked == true)
			{
				status_activity = field[i].id+'~1';
			}
			else
			{
				status_activity = field[i].id+'~0';
			}
		}
		else
		{
			if(field[i].checked == true)
			{
				status_activity = status_activity +','+ field[i].id+'~1';
			}
			else
			{
				status_activity = status_activity +','+ field[i].id+'~0';
			}
		}
	}


	new Ajax.Updater('',webroot+'users/participantDirectory/'+status_activity,{frequency: 0,
	onLoading:function(){},
	onComplete:function(){},
	asynchronous:true, evalScripts:true
	});

}

// function for select all check box
chk_all_checkbox = function(frmName)
{
	var field = document.getElementsByName('chk_user[]');
	var main_field = document.getElementsByName('main_chk[]');

	var flag = '0';
	if(main_field[0].checked == true)
	{
		flag = '1';
	}


	if(flag == '1')
	{
		for (var i = 0; i < field.length; i++)
		{
			field[i].disabled = false;
		}
	}
	else
	{
		for (var i = 0; i < field.length; i++)
		{
			field[i].disabled = true;
		}
	}

	var show_value = '1';
	show_value = flag;
	new Ajax.Updater('',webroot+'users/update_show_value/'+show_value,{frequency: 0,
	onLoading:function(){},
	onComplete:function(){},
	asynchronous:true, evalScripts:true
	});
}

loadThemeStyles = function(id,themetitle)
{
	if(id=="-100")
	{
		return showCustomTheme();
	}
	$('ThemeType').value = 'theme';
	$('CreateYourOwn').className = 'hidden';
	$('ThemeList').className = '';

	var dataToInsert = '';

	new Ajax.Request(webroot+'themes/load_themes_from_tag.json?id='+id, {
		method:'get',
		onSuccess: function(transport){
			data = transport.responseText.evalJSON();
			
			for(i=0;i<data.length;i++)
			{
				dataToInsert = dataToInsert+'<div><a href="javascript:void(0);" onclick="changeTheme('+data[i].id+')" style="float:left;display:block;height:46px;" class="themeBanner" id="Theme_'+data[i].id+'"><img width="383" height="46" src="'+webroot+'themes/banner_image?theme='+data[i].id+'&text='+themetitle+'""/></a></div><div class="clear" style="padding-top:1px;"></div>';
			}
			$("ThemeListItems").update(dataToInsert);
		}
	});
}

showCustomTheme = function()
{
	$('ThemeType').value = 'custom';
	$('ThemeList').className = 'hidden';
	$('CreateYourOwn').className = '';
}
changeFontColor = function(id)
{
	$("ThemeFontColorId").value = id;
	FontColorId = id;
	regeneratePreview();
}

changeFont = function(id)
{
	$("ThemeFontId").value = id;
	FontId = id;
	regeneratePreview();
}

changeBannerColor = function(id)
{
	$("ThemeBannerColorId").value = id;
	BannerColorId = id;
	regeneratePreview();
}

changeBackgroundColor = function(id)
{
	$("ThemeBackgroundColorId").value = id;
	BackgroundColorId = id;
	regeneratePreview();
}

addMultiParticipant_ajax = function(event_id)
{
	ParticipantEmail = $("ParticipantEmailAll");
	if(ParticipantEmail.value=='')
	{
		alert("Please Enter Email Addresses");
		ParticipantEmail.focus();
	}
	else
	{
		url = webroot+'events_users/add_participant_ajax/'+event_id;

		params = 'participant_emails='+cleanString(ParticipantEmail.value);
		new Ajax.Request(url, {
			method:"post",
			parameters: params,
			onSuccess: function(transport){
				data = transport.responseText.evalJSON();
				participant_list 	= data.participant_list;
				p_length 			= participant_list.length;
				bad_emails 			= data.bad_emails;
				event_id 			= data.event_id;
				data_to_insert 		= '';

				sort_user_list(event_id,'status','Desc');

				new Element.scrollTo('ParticipantList', 0, $('ParticipantList').offsetTop); 
				//new Effect.Highlight("ParticipantList");

				if(bad_emails.length > 0)
				{
					bad_string = '';
					for(i=0; i<bad_emails.length; i++)
					{
						bad_string = bad_emails[i]+"\n";
					}
					$('participant_email_list').update('<textarea name="data[Participant][email]" id="ParticipantEmailAll" class="whiteborder" style="width:175px;padding:3px;height:100px;">'+bad_string+'</textarea>');
					alert("Some of your emails had problems. Please fix them and try again.");
					$('ParticipantEmailAll').focus();
				}
				else
				{
					$('participant_email_list').update('<textarea name="data[Participant][email]" id="ParticipantEmailAll" class="whiteborder" style="width:175px;padding:3px;height:100px;"></textarea>');
					//alert("Emails Imported Successfully");
				}

			}
		});
	}
}
read_csv_file = function()
{
	url = webroot+'events/choose_csv_file';
	Modalbox.show(url, {title: "Choose csv file", width: 400});
}
select_all_invites = function()
{
	Invitees = $("PossibleInvitees").getElementsByClassName('invitee');

	for(i=0;i<Invitees.length;i++)
	{
		Invitees[i].checked = true;
	}
}
select_none_invites = function()
{
	Invitees = $("PossibleInvitees").getElementsByClassName('invitee');

	for(i=0;i<Invitees.length;i++)
	{
		Invitees[i].checked = false;
	}
}

select_all_date = function()
{
	DateAll = $("ActivitySchedulingContent").getElementsByClassName('dateselect');

	for(i=0;i<DateAll.length;i++)
	{
		DateAll[i].checked = true;
	}
}

select_none_date = function()
{
	DateAll = $("ActivitySchedulingContent").getElementsByClassName('dateselect');

	for(i=0;i<DateAll.length;i++)
	{
		DateAll[i].checked = false;
	}
}


ShowColumnCdiv = function(divid)
{
	if(divid == "DesigntateRole")
	{
		$(divid).className = '';
		$("EventInvitaion").className = 'hidden';
	}
	else if(divid =="EventInvitaion")
	{
		$(divid).className = '';
		$("DesigntateRole").className = 'hidden';
	}

}
// function for select all on edit event four step
select_all_four = function(divid,classsname)
{


	fieldAll = $(divid).getElementsByClassName(classsname);

	for(i=0;i<fieldAll.length;i++)
	{
		fieldAll[i].checked = true;
	}
}

select_none_four = function(divid,classsname)
{
	fieldAll = $(divid).getElementsByClassName(classsname);

	for(i=0;i<fieldAll.length;i++)
	{
		fieldAll[i].checked = false;
	}
}


removeParticipantFromTobeinvited = function(eventuserId,event_id)
{

	if(confirm("Are you sure you want to remove this user from your event?"))
	{
			var trash_remove = "activity_"+eventuserId+"_trash";
			$(trash_remove).innerHTML= '<img src="'+webroot+'img/ajax-loader-arrows.gif">';
			

		url = webroot+'events_users/remove_participant.json?eventuserId='+eventuserId+'&event_id='+event_id;
		new Ajax.Request(url, {
			method:"get",
			onSuccess: function(transport){
				data = transport.responseText.evalJSON();

				removeId = parseInt(eventuserId);
				var str_remove = "activity_"+removeId+"_li";	
				$(str_remove).remove();
				
				ParticipantListSuggested = $("ParticipantListSuggested");

				data_to_insert = '';

				//alert(data);
				/* Only for design sugessted */
				var activity_id = '';
				data_to_insert = '<div class="leftfloat normaltext" style="color:#0071B7;"><span class="normaltext"><a style="display:block;float:left;padding-top:2px;" href="javascript:void(0)" onclick="removeParticipantFromTobeinvited(\''+activity_id+'\',\''+event_id+'\')"><img src="'+webroot+'img/trash.gif" /></a></span><span class="normaltext">&nbsp;Select&nbsp;</span></div><div class="leftfloat normaltext" style="color:#0071B7;"><a style="padding-top:2px;" href="javascript:void(0)" onclick="select_all_four(\'ParticipantList\',\'particiapant_check\')">All</a></span><span class="normaltext">&nbsp; | &nbsp; <a style="padding-top:2px;" href="javascript:void(0)" onclick="select_none_four(\'ParticipantListSuggested\',\'invitee\')">None</a></span></span></div>';

				for(j=0;j<data.length;j++)
				{
					data_to_insert += '<div id="suggested_'+data[j].user_id+'" style="padding-left:5px;"><div class="clear" style="padding-top:5px;"></div><input type="checkbox" id="checkboxarr[]" value='+data[j].id+','+data[j].email+','+data[j].user_id+','+data[j].name+' class="invitee" ><span id="activity_suggested_'+data[j].id+'_title" class="normaltext">&nbsp;'+data[j].name+'</span></div>';
				}

				ParticipantListSuggested.update(data_to_insert);
				new Effect.Highlight("ParticipantListSuggested");

			}
		});

	}

	var select_field = $("ParticipantList").getElementsByClassName('particiapant_check');
	if(select_field.length == 0)
	{
		$('Trash_Particiapnt_List').className = 'hidden';
	}


}

suggestedTobe = function(event_id)
{
	var field = $("ParticipantListSuggested").getElementsByClassName('invitee');

	var arr_check = new Array();
	for (var i = 0, j = 0; i < field.length; i++)
	{
		if(field[i].checked == true)
		{
			arr_check[j] = '';
			arr_check[j] = 	field[i].value;

			j = j + 1;
		}
	}
	for(var k = 0; k < arr_check.length; k++)
	{
		var parameter = '';
		parameter = arr_check[k];
		var mySplitResult = parameter.split(",");
		var str_remove = "suggested_"+mySplitResult[2]+"";
		addParticipantRequest(event_id, mySplitResult[3], mySplitResult[1],'suggested',mySplitResult[2]);
		$(str_remove).remove();
	}
	var select_field = $("ParticipantListSuggested").getElementsByClassName('invitee');
	if(select_field.length == 0)
	{
		$('Trash_Particiapnt_Suggest').className = 'hidden';
	}
}

show_end_date_3 = function()
{
	var	valcheckbox = document.getElementById("show_end_date");
	if(valcheckbox.checked == false)
	{
		document.getElementById("end_date_choice").style.display = 'none';
	}
	if(valcheckbox.checked == true)
	{
		document.getElementById("end_date_choice").style.display = 'block';
	}
}
hide_end_date = function()
{
	document.getElementById("end_date_choice").style.display = 'none';
	var	valcheckbox = document.getElementById("show_end_date");
	valcheckbox.checked = false;
}
select_date_3step = function(mode)
{
	var today = new Date();
	date=today.getDate();
	for(i=1;i<10;i++)
	{
		if(date==i)
		{
			date="0"+date;
		}
	}
	document.getElementById("start_dateDay").value=date;
	document.getElementById("end_dateDay").value=date;
	month=today.getMonth()+1;
	for(i=1;i<10;i++)
	{
		if(month==i)
		{
			month="0"+month;
		}

	}
	var housrs = today.getHours();

	if(housrs > 11){
		start_dateMeridian = "pm";
		end_dateMeridian = "pm";
		if(housrs != 12)
		{
			housrs =	housrs - 12;
		}
	} else {
		start_dateMeridian = "am";
		end_dateMeridian ="am";
	}
	for(i=1;i<10;i++)
	{
		if(housrs==i)
		{
			housrs="0"+housrs;
		}

	}

	document.getElementById("start_dateMeridian").value=start_dateMeridian;
	document.getElementById("end_dateMeridian").value=end_dateMeridian;
	document.getElementById("start_dateHour").value=housrs;
	document.getElementById("start_dateMinute").value=today.getMinutes();
	document.getElementById("start_dateMonth").value=month;
	document.getElementById("start_dateYear").value=today.getFullYear();
	document.getElementById("end_dateMonth").value=month;
	document.getElementById("end_dateYear").value=today.getFullYear();
	document.getElementById("end_dateHour").value=housrs;
	document.getElementById("end_dateMinute").value=today.getMinutes();
}
loadPrefernces_chk = function(eventId)
{
	var field = document.getElementsByName('chk_prefernces[]');
	var prefernces_status = '';

	for (var i = 0; i < field.length; i++)
	{
		if(prefernces_status == '')
		{
			if(field[i].checked == true)
			{
				prefernces_status = field[i].id+'~1';
			}
			else
			{
				prefernces_status = field[i].id+'~0';
			}
		}
		else
		{
			if(field[i].checked == true)
			{
				prefernces_status = prefernces_status +','+ field[i].id+'~1';
			}
			else
			{
				prefernces_status = prefernces_status +','+ field[i].id+'~0';
			}
		}
	}

	new Ajax.Updater('',webroot+'events/preferences/'+eventId+'/'+prefernces_status,{frequency: 0,
	onLoading:function(){},
	onComplete:function(){},
	asynchronous:true, evalScripts:true
	});
	return false;

}
windowguide_chk = function()
{
	var arr_check = new Array();
	var field = document.getElementsByName('chk_window[]');

	var status_value = '';

	for (var i = 0; i < field.length; i++)
	{
		if(status_value == '')
		{
			if(field[i].checked == true)
			{
				status_value = field[i].id+'~1';
			}
			else
			{
				status_value = field[i].id+'~0';
			}
		}
	}


	new Ajax.Updater('',webroot+'users/windowprefernceGuide/'+status_value,{frequency: 0,
	onLoading:function(){},
	onComplete:function(){},
	asynchronous:true, evalScripts:true
	});


}
changeUserRole = function(eventId,UserId,seletedIndex)
{
	var celupdate = "eventsUserRole_"+UserId;
	var seletedRole_value = document.getElementById('eventsUserRole_'+UserId).selectedIndex;
	var seletedRole;
	if(seletedRole_value =='0')	{
		seletedRole = 'Participant';
		document.getElementById(celupdate).style.color = "blue";
	} else if(seletedRole_value == '2')	{
		seletedRole = 'Organizer';
		document.getElementById(celupdate).style.color = "red";
	} else if(seletedRole_value == '1')	{
		seletedRole = 'Recipient';
		document.getElementById(celupdate).style.color = "green";
	}
	
	sendurl = webroot+'events/change_user_role?eventid='+eventId+'&user_id='+UserId+'&userRole='+seletedRole;

		new Ajax.Request(sendurl, {
			method:'post',
			onSuccess: function(transport){
				data = transport.responseText;
				
			}
		});
}
