﻿function ShowEventDetails(selectedDate, title_with_apos, location_with_apos, starttime, duration, description, link, contactfirstname, contactlastname, contactemail, insertiontime, eventadmin) 
{
   var title = 	title_with_apos.replace("&apos", "'");
   var location = location_with_apos.replace("&apos", "'");
   var layer, box;
   create_lightbox_layer(layer);
   var div = create_lightbox_div(box);
   
	//var top_bar_box = create_top_border(div);
   
    var event_title = document.createElement('p');
    event_title.style.backgroundColor = '#FFF8C6';
    event_title.style.textAlign = 'center';
    event_title.innerHTML ='"' + title + '"';
    div.appendChild(event_title);
    
    var event_description = document.createElement('p');
    event_description.innerHTML = '<b>Description: </b>' + description;
    div.appendChild(event_description);  
    
    var location_time = document.createElement('p');
    location_time.innerHTML = '<b>Location:</b> ' + location + '<br /><br />' + '<b>Starting Time:</b> ' + starttime + '<br /><br /><b>Duration: </b>' + duration   ;
    div.appendChild(location_time);
    
    var links = document.createElement('p');
    links.innerHTML = '<b>Event URL:</b> ' + '<a href="' + link + '"' + 'target="_blank">' + link + "</a>" ;
    div.appendChild(links);
    
    var firstname_lastname = document.createElement('p');
    firstname_lastname.innerHTML = '<b>Event contact:</b> ' + contactfirstname + ' ' + contactlastname + ' ' + '<a href="mailto:' + contactemail + '">' + contactemail + "</a>";
    div.appendChild(firstname_lastname);
    
    var rsvp = document.createElement('img');
    rsvp.src = 'icons/reply.gif';
    rsvp.title = 'RSVP'; 
    rsvp.style.cursor = 'pointer';
    //rsvp.href = 'javascript:void(0)';
    rsvp.onclick = function()
    {
		
		
		document.body.removeChild(document.getElementById(box));
		
		var box_rsvp;
		var div_rsvp = create_lightbox_div(box_rsvp);
		
		var rsvp_instruction = document.createElement('p');
		//rsvp_instruction.style.backgroundColor = '#FFF8C6';
		rsvp_instruction.innerHTML = 'Please complete the information below and press the next button. All fields are needed.';
		div_rsvp.appendChild(rsvp_instruction);
		
		var rsvp_instruction_name = document.createElement('p');
		rsvp_instruction_name.innerHTML = '<b>Your Name:</b>';
		div_rsvp.appendChild(rsvp_instruction_name);
		
		var rsvp_name_from = document.createElement('input');
		rsvp_name_from.id = 'rsvp_from_username';
		div_rsvp.appendChild(rsvp_name_from);
		
	
		var rsvp_instruction_email = document.createElement('p');
		rsvp_instruction_email.innerHTML = '<b>Your Email Address:</b>';
		div_rsvp.appendChild(rsvp_instruction_email);
		
		var rsvp_email_from = document.createElement('input');
		rsvp_email_from.id = 'rsvp_from';
		div_rsvp.appendChild(rsvp_email_from);
		
		var rsvp_instruction = document.createElement('p');
		rsvp_instruction.innerHTML = '<b>RSVP: </b>';
		div_rsvp.appendChild(rsvp_instruction);
		
		var rsvp_options = document.createElement('select');
		rsvp_options.id = 'list_of_rsvp_options';
		div_rsvp.appendChild(rsvp_options);
		
		var op_0 = document.createElement('option');
		op_0.innerHTML = 'Choice';
		rsvp_options.appendChild(op_0);
		
		var op1 = document.createElement('option');
		op1.innerHTML = 'Attending';
		rsvp_options.appendChild(op1);
		
		var op2 = document.createElement('option');
		op2.innerHTML = 'Not Attending';
		rsvp_options.appendChild(op2);
		
		var op3 = document.createElement('option');
		op3.innerHTML = 'Maybe Attending';
		rsvp_options.appendChild(op3);
		
		var newline4 = document.createElement('p');
		newline4.innerHTML = "<br><br><br>";
		div_rsvp.appendChild(newline4);
		
		
		
		var next_button_rsvp = document.createElement('img');
		next_button_rsvp.style.cursor = 'pointer';
		next_button_rsvp.src = 'icons/next.gif';
		next_button_rsvp.title =  'Next';
		
		next_button_rsvp.onclick = function()
		{
			//review screen
			if (document.getElementById("rsvp_from_username").value == "")
			window.alert("Please enter your name.");
			else if (document.getElementById("rsvp_from").value == "")
			window.alert("Please enter your email address.");
			else if (document.getElementById("list_of_rsvp_options").options.selectedIndex == 0 )
			window.alert("Please select an RSVP option");
			else 
				{
			
					document.body.removeChild(document.getElementById(box_rsvp));
					
					var box_rsvp_final;
					var div_rsvp_final_review =  create_lightbox_div(box_rsvp_final);
					
					var selected_option = document.getElementById("list_of_rsvp_options");
					var selected_option_text = selected_option.options[selected_option.selectedIndex].text;
					/*
					var selected_option;
					if (selected_index_rsvp_list == 1 ) selected_option = "Attending";
					else if (selected_index_rsvp_list == 2 ) selected_option = "Not Attending";
					else if (selected_index_rsvp_list == 3 ) selected_option = "Maybe Attending";
					*/
					
					var message_rsvp_review = document.createElement('p');
					message_rsvp_review.innerHTML = "The following RSVP message will be sent to the event contact " + contactfirstname + " " + contactlastname + "<br><br>";
					message_rsvp_review.innerHTML += "<b>Message title:</b> RSVP for event " + '"' + title + '"' + " (" + selected_option_text + ")" + "<br><br>";
					message_rsvp_review.innerHTML += "<b>Meessage body:</b> " + document.getElementById("rsvp_from_username").value + " [" + document.getElementById("rsvp_from").value + "] is " + selected_option_text + " the following event:<br><br>";
					message_rsvp_review.innerHTML += "'" + title + "'";
					div_rsvp_final_review.appendChild(message_rsvp_review);
					
					var rsvp_email_title = "RSVP for event " + '"' + title + '"' + " (" + selected_option_text + ")" ;
					var rsvp_email_body  =  document.getElementById("rsvp_from_username").value + " [" + document.getElementById("rsvp_from").value + "] is " + selected_option_text + " the following event:\n\n";
					rsvp_email_body += "'" + title + "'";
					
					var send_button_rsvp = document.createElement('input');
					send_button_rsvp.style.cursor = 'pointer';
					send_button_rsvp.setAttribute("type", "button");
					send_button_rsvp.setAttribute("value", "Click here to send the above message.");
					send_button_rsvp.onclick = function()
					{
						
						PageMethods.Email(document.getElementById("rsvp_from").value, contactemail, rsvp_email_title , rsvp_email_body );
						send_button_rsvp.setAttribute("value", "Message sent. You can close this window now.");
						send_button_rsvp.setAttribute("disabled", "disabled");
						
						
										
					}
					div_rsvp_final_review.appendChild(send_button_rsvp);
					
					var p_break = document.createElement('p');
					p_break.innerHTML = '<br /><br />';					 
					div_rsvp_final_review.appendChild(p_break);
		
					var a = document.createElement('img');
					a.id = 'close_window_rsvp_final_review';
					a.style.cursor = 'pointer';
					a.src = 'icons/close.gif';
					a.title = 'Close Window';
					//a.style.verticalAlign = 'bottom';
					//a.href = '';
					div_rsvp_final_review.appendChild(a);
					
					var a_text = document.createElement('span');
					a_text.innerHTML = 'Close window';	
					a_text.style.color = "#800517";
					div_rsvp_final_review.appendChild(a_text);
						
					a.onclick = function()
						{
							document.body.removeChild(document.getElementById(box_rsvp_final));
							document.body.removeChild(document.getElementById(box_rsvp_final));
						}
					
			}
			  
		}
		div_rsvp.appendChild(next_button_rsvp);
		
		var next_text = document.createElement('span');
		next_text.innerHTML = '   Next<br /><br />';
		next_text.style.color = "#800517";
		div_rsvp.appendChild(next_text);
		
		
		var a = document.createElement('img');
		a.id = 'close_window_rsvp_main';
		a.src = 'icons/close.gif';
		a.title = 'Close Window';
		a.style.cursor = 'pointer';
		//a.style.verticalAlign = 'bottom';
		//a.href = '';
		div_rsvp.appendChild(a);
		
		var a_text = document.createElement('span');
		a_text.innerHTML = '   Close window';
		a_text.style.color = "#800517";
		div_rsvp.appendChild(a_text);	
	 
		a.onclick = function()
		{
			document.body.removeChild(document.getElementById(box_rsvp));
			document.body.removeChild(document.getElementById(box_rsvp));
		}
		
    };     
    div.appendChild(rsvp);
    
    //RSVP Title 
    
    var rsvp_text = document.createElement('span');
    rsvp_text.innerHTML = '   RSVP';
    rsvp_text.style.color = "#800517";
    div.appendChild(rsvp_text);  
    
    var newline1 = document.createElement('p');
    newline1.innerHTML = " ";
    div.appendChild(newline1);
    
	var remind = document.createElement('img');
	remind.src = 'icons/time.gif';
	remind.title = 'Remind Me';
	remind.style.cursor = 'pointer';
	//remind.href = 'javascript:void(0)';
	remind.onclick = function ()
	{
		document.body.removeChild(document.getElementById(box));
		var box_remind_me;
		var div_remind_me = create_lightbox_div(box_remind_me);
		
		var remind_form_header = document.createElement('p');
		
		remind_form_header.innerHTML = "We will send you an email so that you don't miss our event. Please fill out the information below and click the " + "'" + "Send Email" + "'" + " button.";
		
		div_remind_me.appendChild(remind_form_header);
		
		
		
		var remind_form_header2 = document.createElement('p');
		remind_form_header2.innerHTML = "Your Email:";
		div_remind_me.appendChild(remind_form_header2);
		
		var remind_form_email = document.createElement('input');
		remind_form_email.id = "remind_email";
		div_remind_me.appendChild(remind_form_email);
		
		var newline3 = document.createElement('p');
		newline3.innerHTML = "<br><br><br>";
		div_remind_me.appendChild(newline3);
		
		//var to = document.getElementById("remind_email").value;
		
		
		
		var next_button = document.createElement('input');
		next_button.setAttribute("type", "button");
		next_button.setAttribute("value", "Click here to send the Email.");
		next_button.onclick = function()
		{
			if ( document.getElementById("remind_email").value == "" ) window.alert("Please enter your email address.");
			else 
			{
				var email_remind_content = "Don't forget to attend the following Commonwealth College Event!\n\n";
				email_remind_content += "'" + title + "'\n";
				email_remind_content += description + "\n\n";
				email_remind_content += "Location: " + location + "\n";
				email_remind_content += "Starting Time: " + starttime + "\n";
				email_remind_content += "Event URL: " + link + "\n\n";
				email_remind_content += "See you there!\n\n";
				email_remind_content += contactfirstname + " " + contactlastname + "\n";
				email_remind_content += contactemail + "\n";
				email_remind_content += "Commonwealth College";
				PageMethods.Email(contactemail, document.getElementById("remind_email").value , "Commonwealth College Event Reminder", email_remind_content);
				
				next_button.setAttribute("value", "Message sent. You can close this window now");
				next_button.setAttribute("disabled", "disabled");
				
			}
		
		}
		div_remind_me.appendChild(next_button);
		
		var p_break =  document.createElement('p');
		p_break.innerHTML = " ";
		div_remind_me.appendChild(p_break);
		
		var a = document.createElement('img');
		a.id = 'close_window_remind_main';
		a.src = 'icons/close.gif';
		a.style.cursor = 'pointer';
		a.onclick = function()
		{
			document.body.removeChild(document.getElementById(box_remind_me));
			document.body.removeChild(document.getElementById(box_remind_me));
		}		 
		div_remind_me.appendChild(a);
		
		var a_text = document.createElement('span');
		a_text.innerHTML = '   Close window';
		a_text.style.color = "#800517";
		div_remind_me.appendChild(a_text);
		 
		
		
		
		
		
	};
	div.appendChild(remind);
	
	var remind_text = document.createElement('span');
    remind_text.innerHTML = '   Remind Me';
    remind_text.style.color = "#800517";
    div.appendChild(remind_text);
	
	var newline2 = document.createElement('p');
    newline2.innerHTML = " ";
    div.appendChild(newline2);
	
	
	var invite = document.createElement('img');
	invite.src = 'icons/user.gif';
	invite.title = 'Invite a friend';
	invite.style.cursor = 'pointer';
	//invite.href = 'javascript:void(0)';
	invite.onclick = function()
	{
		
		document.body.removeChild(document.getElementById(box));
		
		var layer2, box2;
		//create_lightbox_layer(layer2);
		var div2 = create_lightbox_div(box2);
		
		var message = document.createElement('p');
		message.innerHTML = 'Please fill out the information below and click the next button. All fields are required. <br><br><b>Your name: </b><br>';
		div2.appendChild(message);		
		
		
		var sendername = document.createElement('input');
		sendername.id = "sender_name";
		div2.appendChild(sendername);
		
		var from_address_label = document.createElement('p');
		from_address_label.innerHTML = '<b>Your email address:</b> ';
		div2.appendChild(from_address_label);
		
		var from_address_box = document.createElement('input');
		from_address_box.id = "from";
		div2.appendChild(from_address_box); 
    
		var to_address_label = document.createElement('p');
		to_address_label.innerHTML = '<b>Your friend' + "'s email address:</b>";
		div2.appendChild(to_address_label);
		
		var to_address_box = document.createElement('input');
		to_address_box.id = 'sendto';
		div2.appendChild(to_address_box); 
		
		//document.write("<br>");
		
		var newline3 = document.createElement('p');
		newline3.innerHTML = "<br><br><br>";
		div2.appendChild(newline3);
		
		var next_button = document.createElement('img');
		next_button.src = 'icons/next.gif';
		next_button.style.cursor = 'pointer';
		next_button.title = 'Next';
		next_button.onclick = function()
		{
			
			
			if (document.getElementById("sender_name").value == "")
			window.alert ("Please enter your name");
			else if(document.getElementById("from").value == "")
			window.alert("Please enter your email address");
			else if (document.getElementById("sendto").value == "")
			window.alert("Please enter your friend\'s email address");
		 
			else{
				
				//document.body.removeChild(document.getElementById(layer2));
				//document.body.removeChild(document.getElementById(box2));
				document.body.removeChild(document.getElementById(box2));
				var layer3, box3;
				var div3 = create_lightbox_div(box3);
				
				var lbl1 = document.createElement('p');
				lbl1.innerHTML = '<b>The following message will be sent to ' + document.getElementById("sendto").value + '</b><br><br>';
				div3.appendChild(lbl1);
				
				var message_body = document.createElement('p');
				message_body.id = 'email_body';			
			
				message_body.innerHTML = 'You have been invited by ' + document.getElementById("sender_name").value  + ' to the following event :<br><br>';
				message_body.innerHTML += '"' + title + '"' + '<br>' + description + '<br><br>' + '<b>Date:</b> ' + selectedDate + '<br><b>Time:</b> ' + starttime + '<br><b>Location:</b> ' + location + '<br><b>More Information:</b> ' + link + '<br><br>' ;
				div3.appendChild(message_body);
				
				var email_content = 'You have been invited by ' + document.getElementById("sender_name").value  + ' to the following event :\n\n';
				email_content += '\"' + title + '\"' + '\n' + description + '\n\n' + 'Date: ' + selectedDate + '\nTime: ' + starttime + '\nLocation: ' + location + '\nMore Information: ' + link + '\n\n' ;
				
				var send_button = document.createElement('input');
				send_button.setAttribute("type", "button");
				send_button.setAttribute("value", "Click here to send the above message.");
				div3.appendChild(send_button);
				send_button.onclick = function()
					{	 
						PageMethods.Email(document.getElementById("from").value, document.getElementById("sendto").value, "Commonwealth College invites you", email_content );
						//document.body.removeChild(document.getElementById(box3));
						send_button.setAttribute("value", "Message sent. You can close this window now.")
						send_button.setAttribute("disabled", "disabled");
					
					}
					
					var p_break = document.createElement('p');
					p_break.innerHTML = '<br /><br /><br />';
					div3.appendChild(p_break);
					
					var a = document.createElement('img');
					a.id = 'close_window_invite';
					a.style.cursor = 'pointer';
					a.src = 'icons/close.gif';
					a.title = 'Close window'; 
					div3.appendChild(a); 
					
					a.onclick = function()
					{
						document.body.removeChild(document.getElementById(box3));
						document.body.removeChild(document.getElementById(box3));
					}
					
					var a_text = document.createElement('span');
					a_text.innerHTML = '   Close window';
					a_text.style.color = "#800517";
					div3.appendChild(a_text);	  
				} 
		}
		
			div2.appendChild(next_button);
			
			var next_button_text = document.createElement('span');
			next_button_text.innerHTML = '   Next<br /><br />';
			next_button_text.style.color = "#800517";
			div2.appendChild(next_button_text);
			
			
			var a = document.createElement('img');
			a.id = 'close_window_invite';
			a.style.cursor = 'pointer';
			a.src = 'icons/close.gif';
			a.title = 'Close window';			 
			div2.appendChild(a); 
			a.onclick = function()
			{
				document.body.removeChild(document.getElementById(box2));
				document.body.removeChild(document.getElementById(box2));
			}
			
			var a_text = document.createElement('span');
			a_text.innerHTML = '   Close window';
			a_text.style.color = "#800517";
			div2.appendChild(a_text);	  
		
	}
	
	div.appendChild(invite);
	
	var invite_text = document.createElement('span');
    invite_text.innerHTML = '   Invite a friend';
    invite_text.style.color = "#800517";
    div.appendChild(invite_text);
	
	var newline3 = document.createElement('p');
    newline3.innerHTML = " ";
    div.appendChild(newline3);
    
    var a = document.createElement('img');
    a.id = 'close_window';
    a.src = 'icons/close.gif';
    a.style.cursor = 'pointer';
    a.title = 'Close Window';
   
	a.onclick = function()
		{
			document.body.removeChild(document.getElementById(box));
			document.body.removeChild(document.getElementById(layer));
		 }
		   
    div.appendChild(a);
    var close_main_text = document.createElement('span');
     close_main_text.innerHTML = '   Close window';
     close_main_text.style.color = "#800517";
    div.appendChild(close_main_text);
     
}

function create_lightbox_layer(layer_id)
{
	var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;

    var layer = document.createElement('div');
    layer.style.zIndex = 2;
    layer.id = layer_id;
    layer.style.position = 'absolute';
    layer.style.top = '0px';
    layer.style.left = '0px';
    layer.style.height = document.documentElement.scrollHeight + 'px';
    layer.style.width = width + 'px';
    layer.style.backgroundColor = 'black';
    layer.style.opacity = '.6';
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
    document.body.appendChild(layer); 
}

function create_lightbox_div(div_id)
{
	var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
	
	var div = document.createElement('div');
    div.style.zIndex = 3;
    div.id = div_id;
    div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
    //div.style.position = 'relative';
    div.style.top = '150px';
    //div.style.top = '100px';
    
    div.style.left = (width / 2) - (500 / 2) + 'px'; 
    
    div.style.width = '600px';
    div.style.height = '500px';
    
    div.style.backgroundColor = 'white';
    div.style.border = '5px solid silver';
    /*
    div.style.borderTopWidth = "20px";
    div.style.borderBottomWidth = "0px";
    div.style.borderLeftWidth = "0px";
    div.style.borderRightWidth = "0px";
    
    div.style.borderTopColor = 'gray';
    div.style.borderBottomColor = 'gray';
    div.style.borderLeftColor = 'gray';
    div.style.borderRightColor = 'gray';
    
    div.style.borderTopStyle = 'solid';
    div.style.borderBottomStyle = 'solid';
    div.style.borderLeftStyle = 'solid';
    div.style.borderRightStyle = 'solid';
    */
    div.style.padding = '5px';
    /*
    var arg = "#" + div_id;
		//$('arg').animate({top: "200px"}, 4000);
		//$('arg').animate({left: "200px"}, 4000);
		$('arg').animate({width: "400px"}, 4000);
		$('arg').animate({height : "400px"}, 4000);
		
	*/	
    document.body.appendChild(div); 
    /*
     var a = document.createElement('a');
    a.id = 'close_window' + '_' + div_id;
    a.innerHTML = 'Close window ';
    a.href = '';
	div.appendChild(a);	
    var argument_a = '#' + 'close_window' + '_' + div_id ;
    var argument_div = '#' + div_id;
    // $(function() {
      $('argument').click(function() {
		
		$('argument_div').empty("slow");
		// });
    */
    return div;
}

function create_top_border(div_tag)
{
	var top_bar = div_tag + "_border";
	top_bar = document.createElement('div');
	top_bar.style.position = 'relative';
	top_bar.style.top = '0px';
	top_bar.style.padding = '0px';
	top_bar.style.left = '0px';
	top_bar.style.height = '20px';
	top_bar.style.backgroundColor = 'gray';
	div_tag.appendChild(top_bar);
	return top_bar;
	
}


