function addActionPanel(){
	actionLabel = document.getElementById('actionLabel');
	actionLabel.focus();
	InsertContent('actions_edit');
	RemoveContent('actions');
}

function addAction(){
	actionPanel = document.getElementById('actions');
	actionPanel.focus();
	
	actionLabel = document.getElementById('actionLabel');
	actionNotifyEmail = document.getElementById('actionNotifyEmail');
	actionAdminNotes = document.getElementById('actionAdminNotes');
	actionUserNotes = document.getElementById('actionUserNotes');
	actionConfirmNotes = document.getElementById('actionConfirmNotes');
	actionNotifyURL = document.getElementById('actionNotifyURL');
	actionIncludeURLParams = document.getElementById('actionIncludeURLParams');
	
	action_requireEmailCheck = document.getElementById('action_requireEmailCheck');
	action_requireEmail = 'false';
	if (action_requireEmailCheck.checked){
		action_requireEmail = 'true';
	}
	action_requireNameCheck = document.getElementById('action_requireNameCheck');
	action_requireName = 'false';
	if (action_requireNameCheck.checked){
		action_requireName = 'true';
	}
	action_requireTelCheck = document.getElementById('action_requireTelCheck');
	action_requireTel = 'false';
	if (action_requireTelCheck.checked){
		action_requireTel = 'true';
	}
	action_requireCompanyCheck = document.getElementById('action_requireCompanyCheck');
	action_requireCompany = 'false';
	if (action_requireCompanyCheck.checked){
		action_requireCompany = 'true';
	}
	
	

	document.getElementById('actionForm_error').innerHTML='';
	if(!actionLabel.value.replace(/^\s*|\s*$/g,'')){
		//alert('Please Enter A Button Label');
		//alertBlock('<span style="font-size: 14px;">Please Enter A Button Label</span>');
		document.getElementById('actionForm_error').innerHTML='Please Enter A Button Label';
		actionLabel.focus();	
		$.colorbox.resize();
		return false;
	}
	
	
	
	if(!actionNotifyEmail.value.replace(/^\s*|\s*$/g,'') && !actionNotifyURL.value.replace(/^\s*|\s*$/g,'') ){
		//alertBlock('<span style="font-size: 14px;">Please Enter An Email Address or Notification URL</span>');
		document.getElementById('actionForm_error').innerHTML='Please Enter An Email Address or Destination URL';
		$.colorbox.resize();
		actionNotifyEmail.focus();
		return false;
	} else {
		if(validateURL('actionNotifyURL',1) == false){
			
		document.getElementById('actionForm_error').innerHTML='Please Enter A Valid Full URL <em>eg: http://www.yourdomain.com</em>';	
		$.colorbox.resize();
		actionNotifyURL.focus();
		return false;
		}	
	}
	//alert(actionIncludeURLParams.checked)
	actionIncludeURLParams = actionIncludeURLParams.checked;
	
	
	//RemoveContent('actions_edit');
		
	list = document.getElementById('actionList');
	calltoactionList = list.value;
	
	if(actionLabel.value){
		if (calltoactionList != ''){
		calltoactionList += ',';
		//attachedFilesText += ', '; 
		}
		
	calltoactionList += escape(actionLabel.value)+'|'+escape(actionNotifyEmail.value)+'|'+escape(actionAdminNotes.value)+'|'+escape(actionUserNotes.value)+'|'+escape(actionConfirmNotes.value)+'|'+escape(actionNotifyURL.value)+'|'+escape(actionIncludeURLParams)+'|'+escape(action_requireEmail)+'/'+escape(action_requireName)+'/'+escape(action_requireTel)+'/'+escape(action_requireCompany);
	calltoactionList = calltoactionList.replace(/["']{1}/gi,"");
	}
	//alert(calltoactionList)
	list.value=calltoactionList;
	//alert(calltoactionList)
	clearActionForm();
	makeActionsList();
	changeField('event');
	$.colorbox.close();
	//window.scrollTo(0,0);
}

function cancelAddAction(){
	clearActionForm();
	makeActionsList();
	$.colorbox.close();
}

function clearActionForm(){
	actionLabel = document.getElementById('actionLabel');
	actionNotifyEmail = document.getElementById('actionNotifyEmail');
	actionAdminNotes = document.getElementById('actionAdminNotes');
	actionUserNotes = document.getElementById('actionUserNotes');
	actionConfirmNotes = document.getElementById('actionConfirmNotes');
	actionNotifyURL = document.getElementById('actionNotifyURL');
	actionIncludeURLParams = document.getElementById('actionIncludeURLParams');
	
	action_requireEmail = document.getElementById('action_requireEmailCheck');
	action_requireName = document.getElementById('action_requireNameCheck');
	action_requireTel = document.getElementById('action_requireTelCheck');
	action_requireCompany = document.getElementById('action_requireCompanyCheck');
	
	
	actionLabel.value = '';
	actionNotifyEmail.value = '';
	actionAdminNotes.value = '';
	actionUserNotes.value = '';
	actionConfirmNotes.value = '';
	actionNotifyURL.value = '';
	actionIncludeURLParams.checked=true;
	action_requireEmail.checked=true;
	action_requireName.checked=true;
	action_requireTel.checked=false;
	action_requireCompany.checked=false;
	//RemoveContent('reqd_Options');
	InsertContent('actionCancelButton');
}

function removeActionFromList(id,edit){
	RemoveContent('actions');
	actionsArray = document.getElementById('actionList').value;
	actions = actionsArray.split(',');
	//alert(files.length)
	NewactionsList = '';
	
	for (i=0;i<actions.length;i++){
		actionsInfoArray = actions[i];
		actionsInfo = actionsInfoArray.split('|');
		
		if(i != id){
			if(NewactionsList!=''){NewactionsList += ',';}
			NewactionsList += actionsInfo[0]+'|'+actionsInfo[1]+'|'+actionsInfo[2]+'|'+actionsInfo[3]+'|'+actionsInfo[4]+'|'+actionsInfo[5]+'|'+actionsInfo[6]+'|'+actionsInfo[7];
			//if(fileInfo[2]){
			//	NewfileList += fileInfo[2];
			//}
		} else {
			if(edit == 1){
				RemoveContent('actionCancelButton');
				InsertContent('actions_edit');
				actionLabel = document.getElementById('actionLabel');
				actionNotifyEmail = document.getElementById('actionNotifyEmail');
				actionAdminNotes = document.getElementById('actionAdminNotes');
				actionUserNotes = document.getElementById('actionUserNotes');
				actionConfirmNotes = document.getElementById('actionConfirmNotes');
				actionNotifyURL = document.getElementById('actionNotifyURL');
				actionIncludeURLParams = document.getElementById('actionIncludeURLParams');
				
				action_requireEmail = document.getElementById('action_requireEmailCheck');
				action_requireName = document.getElementById('action_requireNameCheck');
				action_requireTel = document.getElementById('action_requireTelCheck');
				action_requireCompany = document.getElementById('action_requireCompanyCheck');
				
				actionLabel.value=unescape(actionsInfo[0]);
				actionNotifyEmail.value=unescape(actionsInfo[1]);
				actionAdminNotes.value=unescape(actionsInfo[2]);
				actionUserNotes.value=unescape(actionsInfo[3]);
				actionConfirmNotes.value=unescape(actionsInfo[4]);
				actionNotifyURL.value=unescape(actionsInfo[5]);
				actionIncludeURLParams.checked = false;
				//alert(unescape(actionsInfo[6]))
				if (unescape(actionsInfo[6]) == 'true'){
					//alert(unescape(actionsInfo[6]))
					actionIncludeURLParams.checked = true;
				}
				
				requiredInfoArray = unescape(actionsInfo[7]);
				if(actionsInfo[7] === undefined){
					requiredInfoArray = 'true/true/false/false';
				}
				requiredInfo = requiredInfoArray.split('/');
				//alert(action_requireCompany.checked)
				action_requireEmail.checked=false;
				if (requiredInfo[0]==='true'){action_requireEmail.checked=true;} 
				action_requireName.checked=false;
				if (requiredInfo[1]==='true'){action_requireName.checked=true;} 
				action_requireTel.checked=false;
				if (requiredInfo[2]==='true'){action_requireTel.checked=true;} 
				action_requireCompany.checked=false;
				if (requiredInfo[3]==='true'){action_requireCompany.checked=true;} 
				
				
				actionsPopUp();
				
				actionLabel.focus();
				
	
				
			} else {
				
			}
		}
		
	}
	document.getElementById('actionList').value=NewactionsList;
	makeActionsList(edit);
	
}


function makeActionsList(edit){
	actionsArray = document.getElementById('actionList').value;
	var actions = actionsArray.split(',');
	//alert(files.length)
	actionsLinks = '';
	
	for (i=0;i<actions.length;i++){
	
		actionsInfoArray = actions[i];
		actionsInfo = actionsInfoArray.split('|');
		
		requiredInfoArray = unescape(actionsInfo[7]);
		if(actionsInfo[7] === undefined){
		requiredInfoArray = 'true/true/false/false';
		}
		requiredInfo = requiredInfoArray.split('/');
		//alert(requiredInfoArray)
		if (actionsInfo[0] != ''){
				
			if(actionsLinks==''){actionsLinks += '<ul class="list" style="font-size:1em; border: none;" >';}
			
						
			var actionsUserNotes = '';
			//Set Tooltip
			var actionstooltip = '<strong>'+addslashes(unescape(actionsInfo[0]))+'</strong>';
			if(actionsInfo[3]){
				actionstooltip += '<br />'+addslashes(unescape(actionsInfo[3])).replace(/\n/g,'<br />');
				//actionsUserNotes = '<br /><span style="font-size:1.2em;">'+unescape(actionsInfo[2])+'</span>';
			}
			//filetooltip += '<br />Link: '+decodeURIComponent(fileInfo[0]);
		fromEmail = document.getElementById('action_fromEmail').value;
		fromName = document.getElementById('action_fromName').value;
		fromCompany = document.getElementById('action_fromCompany').value;
		fromTel = document.getElementById('action_fromTel').value;
		
		notifyURLAction = '';
		if (unescape(actionsInfo[5]) != ''){
			//confirmMsg += '<br /><strong style="font-size:11px;">(NOTE: You may need to \'Allow Popups\' to complete the call to action)</strong>';
			notifyURLAction = unescape(actionsInfo[5]);
			if (unescape(actionsInfo[6]) == 'true'){
				notifyURLAction += '?email='+fromEmail+'&name='+fromName+'&company='+fromCompany+'&tel='+fromTel;
			}
		}
		if (notifyURLAction != '' && (fromEmail != '' || fromName != '')){
		//alert(unescape(actionsInfo[5]))
			href = 'href="'+notifyURLAction+'" target="_blank"';
		} else {
			href = 'href="javascript:;"'
		}
		actionsLinks += '<input type="hidden" name="action_requireEmail_'+i+'" id="action_requireEmail_'+i+'" value="'+requiredInfo[0]+'" />';
		actionsLinks += '<input type="hidden" name="action_requireName_'+i+'" id="action_requireName_'+i+'" value="'+requiredInfo[1]+'" />';
		actionsLinks += '<input type="hidden" name="action_requireTel_'+i+'" id="action_requireTel_'+i+'" value="'+requiredInfo[2]+'" />';
		actionsLinks += '<input type="hidden" name="action_requireCompany_'+i+'" id="action_requireCompany_'+i+'" value="'+requiredInfo[3]+'" />';
		
		actionsLinks += '<li id="Action_'+i+'X" onmouseover="InsertContent(\'removeAction'+i+'X\');" onmouseout="RemoveContent(\'removeAction'+i+'X\');" style="border:none;">';
		if (edit_access){
		actionsLinks += '<span id="removeAction'+i+'X" style="display:none; float:right; margin-top: 8px; margin-right:8px;"><a href="javascript:;" onclick="removeActionFromList('+i+');changeField(\'event\');UnTip();"><img src="images/icons/cross.png" style="" border="0" width="16" onmouseover="ToolTip(\'Click Here To Remove '+addslashes(unescape(actionsInfo[0]))+'\');" onmouseout="UnTip();" /></a> <a href="javascript:;" onclick="removeActionFromList('+i+',1);UnTip();" class=""><img src="images/icons/pencil.png" style="" border="0" width="16" onmouseover="ToolTip(\'Click Here To Edit '+addslashes(unescape(actionsInfo[0]))+'\');" onmouseout="UnTip();" /></a> </span>';
		}
		actionsLinks += '<span style=" font-size:1.2em;">';
		
		//actionsLinks += '<form id="actionForm" name="actionForm" action="response.php"><input name="actionEmail" type="hidden" id="actionEmail" value="'+unescape(actionsInfo[1])+'" /><input name="submitAction" type="submit" class="button" id="submitAction" value="GO" /></form>';
		actionsLinks += '<a class="button" '+href+' onclick="SubmitCallToAction('+i+',\''+addslashes(unescape(actionsInfo[1]))+'\',\''+addslashes(unescape(actionsInfo[0]))+'\',\''+addslashes(unescape(actionsInfo[2]))+'\',\''+addslashes(unescape(actionsInfo[3]))+'\',\''+addslashes(unescape(actionsInfo[4]))+'\',\''+addslashes(unescape(actionsInfo[5]))+'\',\''+addslashes(unescape(actionsInfo[6]))+'\')" onmouseover="ToolTipBox(\''+actionstooltip+'\',250);" onmouseout="UnTip();" style="display:block; padding-left:15px; padding-right: 15px;" ><img id="ActionCompleted_'+i+'" src="images/icons/tick.png" style="margin-right:5px; display:none;" border="0" width="16" /><strong id="actionLabel_'+i+'">'+unescape(actionsInfo[0])+'</strong></a></span>';
		actionsLinks += '</li>';
		
		//actionsLinks += '<li id="ActionCompleted_'+i+'" onmouseover="InsertContent(\'removeAction'+i+'\');" onmouseout="RemoveContent(\'removeAction'+i+'\');" style="border:none; display:none;">';
		if (edit_access){
		//actionsLinks += '<span id="removeAction'+i+'" style="display:none; float:right; margin-top: 8px; margin-right:8px;"><a href="javascript:;" onclick="removeActionFromList('+i+');changeField(\'event\');UnTip();"><img src="images/icons/cross.png" style="" border="0" width="16" onmouseover="ToolTip(\'Click Here To Remove '+unescape(actionsInfo[0])+'\');" onmouseout="UnTip();" /></a> <a href="javascript:;" onclick="removeActionFromList('+i+',1);UnTip();" class=""><img src="images/icons/pencil.png" style="" border="0" width="16" onmouseover="ToolTip(\'Click Here To Edit '+unescape(actionsInfo[0])+'\');" onmouseout="UnTip();" /></a> </span>';
		}
		//actionsLinks += '<span style=" font-size:1.2em;">';
		
		//actionsLinks += '<form id="actionForm" name="actionForm" action="response.php"><input name="actionEmail" type="hidden" id="actionEmail" value="'+unescape(actionsInfo[1])+'" /><input name="submitAction" type="submit" class="button" id="submitAction" value="GO" /></form>';
		
		//actionsLinks += '<a class="button" '+href+' onclick="SubmitCallToAction('+i+',\''+unescape(actionsInfo[1])+'\',\''+unescape(actionsInfo[0])+'\',\''+unescape(actionsInfo[2])+'\',\''+unescape(actionsInfo[3])+'\',\''+unescape(actionsInfo[4])+'\',\''+unescape(actionsInfo[5])+'\',\''+unescape(actionsInfo[6])+'\')" onmouseover="ToolTipBox(\''+actionstooltip+'\',250);" onmouseout="UnTip();" style="display:block;">';
		//actionsLinks += '<img src="images/icons/tick.png" style="" border="0" width="16" align="absmiddle" /> ';
		//actionsLinks += '<strong>'+unescape(actionsInfo[0])+'</strong>';
		//actionsLinks += '<br /><span style="font-size:12px;">'+unescape(actionsInfo[4])+'</span>';
		//actionsLinks += '</a></span>';
		//actionsLinks += '</li>';
		
	}
	
	}
	
	if (actionsLinks != ''){
		actionsLinks += '</ul>';
		//InsertContent('attachedBox');
		
	} else {
		//RemoveContent('attachedBox');
		
	}
	document.getElementById('actions').innerHTML=actionsLinks;
	if(!edit){
	InsertContent('actions');
	}
	return actionsLinks;
}


$(document).ready(function(){
	
	


var actionFormOptions = { 
        
		
		//Set 'ajax' variable as form being processed with ajax form query
		//IE doesn't work with live.submit, so this will redirect on save
		data: { ajax: '1' },
	   
 		beforeSubmit:  actionFormRequest,
		success:       actionFormResponse  
	
    }; 
 
    // bind to the form's submit event 
	
    $('.actionForm').live('submit',function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(actionFormOptions); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
	
	$('.submit').live('click',function(event){
     // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(actionFormOptions); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
	});
	
	
	


}); 
 
// pre-submit callback 
function actionFormRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    //alert('About to submit: \n\n' + queryString); 
 
 			actionLabel = document.getElementById('actionLabel');
			actionNotifyEmail = document.getElementById('actionNotifyEmail');
			actionNotifyURL = document.getElementById('actionNotifyURL');
			
			
 			
			document.getElementById('actionForm_error').innerHTML='';
			if(!actionLabel.value.replace(/^\s*|\s*$/g,'')){
				//alert('Please Enter A Button Label');
				//alertBlock('<span style="font-size: 14px;">Please Enter A Button Label</span>');
				document.getElementById('actionForm_error').innerHTML='Please Enter A Button Label';
				actionLabel.focus();	
				$.colorbox.resize();
				return false;
			}
			if(!actionNotifyEmail.value.replace(/^\s*|\s*$/g,'') && !actionNotifyURL.value.replace(/^\s*|\s*$/g,'') ){
				//alertBlock('<span style="font-size: 14px;">Please Enter An Email Address or Notification URL</span>');
				document.getElementById('actionForm_error').innerHTML='Please Enter An Email Address or Notification URL';
				$.colorbox.resize();
				actionNotifyEmail.focus();
				return false;
			} else {
				if(validateURL('actionNotifyURL',1) == false){
					
				document.getElementById('actionForm_error').innerHTML='Please Enter A Valid Full URL <em>eg: http://www.yourdomain.com</em>';	
				$.colorbox.resize();
				actionNotifyURL.focus();
				return false;
				}	
			}
			
			
				textResponseToggle = document.getElementById('action_textResponseCheck');
				requireTextResponse = document.getElementById('action_requireTextResponseCheck').value;
				textResponseLabel = document.getElementById('action_textResponseLabel');
				
				//alert(textResponseToggle.checked);
				textResponseLabelText = document.getElementById('action_textResponseLabel').value;
					if(textResponseToggle.checked === true && textResponseLabelText.replace(/^\s*|\s*$/g,'') == ''){
						document.getElementById('actionForm_error').innerHTML='Please Enter A Label For The Written Response';
						textResponseLabel.focus();	
						$.colorbox.resize();
						return false;
					}
			
			savingDialog(); 
			clearActionForm();
			$.colorbox.close();
           // $.blockUI({ message: '<h1><img src="images/active_bar_trans.gif" /><br /> Saving Changes...</h1>' });
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function actionFormResponse(responseText, statusText, xhr, $form)  { 


    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
   //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.'); 
	$.colorbox.close();
	if (responseText === 'OK'){
		$.blockUI({ 
			css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#fff',
				fontSize: '2em'
				},
			message: '<img src="images/icons/tick_lrg.png"  /> Saved'	
		}); 
		//setTimeout('window.location.reload();', 1000); 
		//restoreEventsBanner()
		setTimeout('$.unblockUI();', 2000); 
		
		
		refreshActions();
		
		//$.colorbox.close()
	} else {
		$.blockUI({ 
			css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#fff',
				fontSize: '2em'
				},
			message: '<img src="images/icons/cross.png"  /> Save Failed'	
		}); 
		//setTimeout('window.location.reload();', 2000); 
		//setTimeout('$.unblockUI();', 3000); 
		setTimeout('$.unblockUI();', 2000); 
		setTimeout('actionsPopUp();', 3000); 
	}
} 

function refreshActions(){
	var content = $("#calltoactions_box");
	//window.scrollTo(0,0);
	content.fadeOut('slow');
	var value = $('#eventID').val(); 
//alert('The event is: ' + value); 
	content.load("actions_panel.php?eventID="+value+"&page="+page+"&pageNumber="+pageNumber, content.fadeIn('slow'));
	   content.fadeIn('slow');
	   
	//Reset the form for an insert
		var content = $("#actionsPopup_content");
		content.load("control_panel/actions_popup.php?eventID="+value+"&pageNumber="+pageNumber+ " #actionsPopup_content");
		
		
}

function buttonColorMenuSelect(){
	buttonColorMenu = document.getElementById('actionButtonColor');
	buttonColorMenu.style.backgroundColor=buttonColorMenu.options[buttonColorMenu.selectedIndex].getAttribute('rel');
	//alert(buttonColorMenu.options[buttonColorMenu.selectedIndex].getAttribute('rel'))
}

function editAction(id){
	
		var content = $("#actionsPopup_content");
		//window.scrollTo(0,0);
		//alert('The event is: ' + value); 
		//InsertContent('actions_box');
		actionsPopUp();
		content.load("control_panel/actions_popup.php?actionID="+id+" #actionsPopup_content");
		
	   // content.fadeIn('slow');
	   
	   
}


//Delete A Room
function deleteAction(uid,id,name){
	var r=confirm("Are You Sure You Want To Remove The Button?");
	if (r==true)
	  {
	  //alert("You pressed OK!");
	  savingDialog();
	  url = 'scripts/php/actions.php';
		type = 'DeleteAction';
		params = 'uid='+uid+'&';
		params += 'id='+id+'&';
		params += ''+type+'=type&';
		
		
		httpRequestPOST(url,params,type);
		$.colorbox.close();
	  }
	else
	  {
	  //alert("Cancelled Delete!");
	  }
}		
	


//Submit Call To Action
var curAction;
var notifyURLAction;
var confirmMsg;
var storedAction; 
function SubmitCallToAction(id,toEmail,subject,adminNotes,userNotes,confirmNotes,notifyURL,includeURLParams,retry){

	$.blockUI({ 
			css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#fff',
				fontSize: '2em'
				},
			message: '<img src="images/icons/hourglass.png"  /> Please Wait...'	
		}); 
	
		attemptedAction(id,toEmail,subject,adminNotes,userNotes,confirmNotes,notifyURL,includeURLParams)
	
	roomID = document.getElementById('eventID').value;
	
	//fromEmail = '<?php // echo $row_rsUserLoggedIn['email']; ?>';
	//fromName = '<?php // echo $row_rsUserLoggedIn['userForename']; ?> <?php // echo $row_rsUserLoggedIn['userSurname']; ?>';
	//fromCompany = '<?php // echo $row_rsUserLoggedIn['company']; ?>';
	//fromTel = '<?php // echo $row_rsUserLoggedIn['tel']; ?>';
	 
	fromEmail = document.getElementById('action_fromEmail').value;
	fromName = document.getElementById('action_fromName').value;
	fromCompany = document.getElementById('action_fromCompany').value;
	fromTel = document.getElementById('action_fromTel').value;
	textResponse = document.getElementById('action_textResponse').value;
	if(id == 'email'){
		requireEmail = 1;
		requireName = 1;
		requireTel = 0;
		requireCompany = 0;
		textResponseToggle = 1;
		requireTextResponse = 1;
		textResponseLabel = 'Message';
	} else {
		requireEmail = document.getElementById('action_requireEmail_'+id).value;
		requireName = document.getElementById('action_requireName_'+id).value;
		requireTel = document.getElementById('action_requireTel_'+id).value;
		requireCompany = document.getElementById('action_requireCompany_'+id).value;
		textResponseToggle = document.getElementById('action_textResponse_'+id).value;
		requireTextResponse = document.getElementById('action_requireTextResponseCheck_'+id).value;
		textResponseLabel = document.getElementById('action_textResponseLabel_'+id).value;
	}
	
	
	
	var fail = 0;
	var reqd = '';
	
	//storedAction = SubmitCallToAction(id,toEmail,subject,adminNotes,userNotes,confirmNotes,notifyURL,includeURLParams);
	
	RemoveContent('action_EmailReqd');
	RemoveContent('action_NameReqd');
	RemoveContent('action_TelReqd');
	RemoveContent('action_CompanyReqd');
	RemoveContent('action_TextResponseReqd');
	
	
	//
	//alert(requireEmail)
	//alert('k')
	if(fromEmail.replace(/^\s*|\s*$/g,'') == '' && (requireEmail == 'true' || requireEmail == '1') ){
		reqd += 'Email';
		InsertContent('action_EmailReqd');
		fail = 1;
	}
	if(fromName.replace(/^\s*|\s*$/g,'') == '' && (requireName == 'true' || requireName == '1')){
		if (reqd!=''){reqd+=', ';}
		reqd += 'Name';
		InsertContent('action_NameReqd');
		fail = 1;
	}
	if(fromTel.replace(/^\s*|\s*$/g,'') == '' && (requireTel == 'true' || requireTel == '1')){
		if (reqd!=''){reqd+=', ';}
		reqd += 'Telephone Number';
		InsertContent('action_TelReqd');
		fail = 1;
	} 
	if(fromCompany.replace(/^\s*|\s*$/g,'') == '' && (requireCompany == 'true' || requireCompany == '1')){
		if (reqd!=''){reqd+=', ';}
		reqd += 'Company Name';
		InsertContent('action_CompanyReqd');
		fail = 1;
	}
	//alert(requireTextResponse)
	//alert(textResponse)
	if(textResponseToggle == '1'){
	document.getElementById('action_textResponseLabel').innerHTML=textResponseLabel;
	InsertContent('textResponse_box');
		if(textResponse.replace(/^\s*|\s*$/g,'') == '' && (requireTextResponse == 'true' || requireTextResponse == '1')){
			if (reqd!=''){reqd+=', ';}
			reqd += textResponseLabel;
			InsertContent('action_TextResponseReqd');
			fail = 1;
		}
	} else {
	RemoveContent('textResponse_box');	
	}
	
	//alert(reqd)
	//alert(fail)
	if (fail == 1){
		//RemoveContent('actions');
		InsertContent('actions_userEdit');
		//setTimeout('userDetails_PopUp();',2500);
		$.unblockUI();
		if(id != 'email'){
			if(document.getElementById('actionLabel_'+id)){
		document.getElementById('userDetails_selectedActionText').innerHTML=document.getElementById('actionLabel_'+id).innerHTML;
			} else if(document.getElementById('actionLabelHidden_'+id)){
		document.getElementById('userDetails_selectedActionText').innerHTML=document.getElementById('actionLabelHidden_'+id).value;
				
			}
		} else {
			document.getElementById('userDetails_selectedActionText').innerHTML='Send Us A Message';
		}
		//alertBlock('<span style="font-size:12px">Please Enter The Required Information and Try Again<br />(Required: '+reqd+')</span>');
		userDetails_PopUp();
		return false;	
	} else {
		stored_id = '';
		stored_toEmail = '';
		stored_subject = '';
		stored_adminNotes = '';
		stored_userNotes = '';
		stored_confirmNotes = '';
		stored_notifyURL = '';
		stored_includeURLParams = '';
		//return true
		RemoveContent('actions_userEdit'); 
		$.colorbox.close();
		document.getElementById('action_textResponse').value='';
		
	}
	
	curAction = id;
	notifyURLAction = '';
	confirmMsg = confirmNotes;
	if (notifyURL != ''){
		//confirmMsg += '<br /><strong style="font-size:11px;">(NOTE: You may need to \'Allow Popups\' to complete the call to action)</strong>';
		notifyURLAction = notifyURL;
		if (includeURLParams == 'true'){
			notifyURLAction += '?email='+fromEmail+'&name='+fromName+'&company='+fromCompany+'&tel='+fromTel+'&textResponse='+textResponse;
		}
	}
	requestParams = '&subject='+subject+'&eventID='+roomID+'&fromName='+fromName+'&fromCompany='+fromCompany+'&fromTel='+fromTel+'&fromEmail='+fromEmail+'&adminNotes='+adminNotes+'&userNotes='+userNotes+'&'+'&confirmNotes='+confirmNotes+'&textResponseLabel='+textResponseLabel+'&textResponse='+textResponse;
	if (toEmail != ''){	
	requestParams += '&toEmail='+toEmail;
	}
	if (notifyURL != ''){
	requestParams += '&notifyURL='+encodeURIComponent(notifyURLAction);	
	}

	if(fail != 1 && notifyURLAction!=''){
		window.open(decodeURIComponent(notifyURLAction));	
	}
	urlRequest('SubmitCallToAction', requestParams, 'scripts/php/calltoaction.php');	
}


function userDetails_PopUp() {
	$.colorbox({opacity:0.1, width:'500px', inline:true, href:"#actions_userEdit", overlayClose: false, onComplete: $.colorbox.resize()});
	$('#cboxClose').css('display','none');	
	
}	

function actionsPopUp(){ 
$.colorbox({width:'700px',opacity:0.1, inline:true, href:"#actions_edit", overlayClose: false, onComplete: $.colorbox.resize()});
$('#cboxClose').css('display','none'); 
}

function closeActionsPopup(){
	clearActionForm();
	$.colorbox.close();
	//Reset the form for an insert
	id = document.getElementById('eventID').value;
	var content = $("#actionsPopup_content");
	content.load("control_panel/actions_popup.php?eventID="+id+"&pageNumber="+pageNumber+" #actionsPopup_content");	
}


//Function to catch submit call to action of not all reqd detals completed
var stored_id = '';
var stored_toEmail = '';
var stored_subject = '';
var stored_adminNotes = '';
var stored_userNotes = '';
var stored_confirmNotes = '';
var stored_notifyURL = '';
var stored_includeURLParams = '';
function attemptedAction(id,toEmail,subject,adminNotes,userNotes,confirmNotes,notifyURL,includeURLParams){
	
	stored_id = id;
	stored_toEmail = toEmail;
	stored_subject = subject;
	stored_adminNotes = adminNotes;
	stored_userNotes = userNotes;
	stored_confirmNotes = confirmNotes;
	stored_notifyURL = notifyURL;
	stored_includeURLParams = includeURLParams;
}
//Function to retry call to action once reqd details have been entered
function retryAction(){
	
	if (stored_id != ''){
		SubmitCallToAction(stored_id,stored_toEmail,stored_subject,stored_adminNotes,stored_userNotes,stored_confirmNotes,stored_notifyURL,stored_includeURLParams,1)
		
	} else {
		return false	
	}
	
	
}


function textResponseCheck(){
	textResponseCheckBox = document.getElementById('action_textResponseCheck');
	//alert(textResponseCheckBox.checked)
	if(textResponseCheckBox.checked === true){
		InsertContent('textResponseDetails');
	} else {
		RemoveContent('textResponseDetails');	
	}
	$.colorbox.resize();
}
