<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page language="java" import="java.io.*, java.sql.*,IMSPackage.*" %>
<%@ page import="java.util.Date,java.sql.*,java.util.Vector,sapphire.reports.*" %>
<%@page import="org.apache.commons.logging.Log,org.apache.commons.logging.LogFactory" %>
<%@page import="org.xnap.commons.i18n.I18n"%>
	<%!
		private static final Log logger = LogFactory.getLog("teckno.log"); %>
<%
    I18n i18n = Sapphire.LANGUAGE_MAP.get((String) session.getAttribute("LANGUAGE_UNICODE"));
%>
<jsp:include page="emailTemplateDesignerComponets.jsp">
    <jsp:param name="fromMainSettings" value="yes" />
</jsp:include>
<%@ page import="java.io.Serializable"%>



<%@ taglib uri="/WEB-INF/ajaxtld/ajaxtags.tld" prefix="ajax" %>
<%  String messageIn ="",messageIn1 ="";
%>
 <%@ include file="topPane.jsp" %>

<div id="sample">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="JavaScript" src="calendar.js"></script>
<script language="JavaScript" src="overlib_mini.js"></script>
<script language="JavaScript" src="TrimClass.js"></script>
<script type="text/javascript" src="DateTimeValidator.js"></script>
<SCRIPT LANGUAGE="JavaScript" SRC="CalendarPopup_combined.js"></SCRIPT>
	<SCRIPT LANGUAGE="JavaScript">

	var cal_from = new CalendarPopup(); 
	cal_from.showNavigationDropdowns();

	var cal_to = new CalendarPopup(); 
	cal_to.showNavigationDropdowns();

</SCRIPT>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="sapphire.css" rel="stylesheet" type="text/css">
<link href="sap.css" rel="stylesheet" type="text/css">
 <script type="text/javascript" src="js/overlibmws.js"></script> 


  <script type="text/javascript" src="<%=request.getContextPath()%>/js/prototype.js"></script>
        <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
        <%if(session.getAttribute("SERVICEDESK_NEWUI_PAGE")!=null){%> 
            <script type="text/javascript" src="assets/js/jquery.min.js" ></script>
    <script type="text/javascript" src="assets/js/i18n/messages_${LANGUAGE_UNICODE}.js"></script>
    <script type="text/javascript" src="assets/js/i18n/i18n.js"></script>
    <script type="text/javascript" src="assets/js/multiple-select.min.js"></script>
    <%}%>
        <jsp:include page="emailTemplateDesignerComponets.jsp">
            <jsp:param name="fromMainSettings" value="yes" />
        </jsp:include>
  <script type="text/javascript" src="js/scriptaculous.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/js/ajaxtags-1.2-beta1.js"></script>
  <link rel="stylesheet" type="text/css" href="css/ajaxtags.css" />
  <link rel="stylesheet" type="text/css" href="css/displaytag.css" />
<%
    String telantName= (String)session.getAttribute("TELANTNAME");
if(new Sapphire().checkModuleAccess((String)session.getAttribute("login"),"Settings",telantName)== 0){
%>
<jsp:forward page="login_page.htm"></jsp:forward>
<%} %>
<%@ include file="AJAXPopup.jsp" %>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script language="JavaScript" type="text/JavaScript">
var count=0;

function back()
{
    if(document.getElementById('filenames') != null && document.getElementById('filenames') != undefined)
      {
        if(window.XMLHttpRequest){
            xmlDoc = new XMLHttpRequest();
        }else if(window.ActiveXObject){
            xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
        }
        var url=null;
        var row = document.getElementById('filenames');
        var path = document.getElementById('uniqueString').value + "_" + document.getElementById('filenames').value;
        url="deleteAttachment.do?path="+path+"&attachmentType=6";
        xmlDoc.open("POST", url, false);
        xmlDoc.setRequestHeader("X-CSRF-TOKEN","${_csrf.token}");
        xmlDoc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlDoc.send(null);
        var i=row.parentNode.parentNode.rowIndex;
        document.getElementById('feedbackImageAttachTable').deleteRow(i);
        document.getElementById("feedbackImageUpload").style.display="";
        document.getElementById("imgTab").style.display="";  
      }
  	window.location.href="SurveyList.jsp?isNewUIAvailable=yes";
}
function validatePage()
{
    var saveButton = document.querySelector('input[value="Save"]');
    saveButton.disabled = true;
        document.AJAX.surveyName.value=document.AJAX.surveyName.value.trim();
        if(document.AJAX.surveyName.value==""){
            alert("Enter the survey name ");
            saveButton.disabled = false;
            document.AJAX.surveyName.focus();
            return;
        }
        var surveyName=document.AJAX.surveyName.value;
        //surveyName=surveyName.replace(/\"/g,"\\&#34");
        document.AJAX.surveyName.value=surveyName;
	if(document.AJAX.surveyDesc.value.length > 2000){
            alert('Please limit your description content to less than 2000 characters ');
            saveButton.disabled = false;
            return;
        }
        if( document.getElementById("surveyData").checked == false && document.getElementById("feedbackData") == false ){
            alert(" Please select Survey type ");
            saveButton.disabled = false;
            return
        }
        if( document.getElementById("isSurveyOrFeedback").value === "" ){
            alert("Please choose survey type ");
            saveButton.disabled = false;
            return;
        }else{
        if( document.getElementById("isSurveyOrFeedback").value == 0 ){
            if(document.AJAX.starttime.value.trim()==""){
                alert("Enter the start time");
                saveButton.disabled = false;
                document.AJAX.starttime.focus();
                return;         
            }
            if(document.AJAX.endtime.value.trim()==""){
                alert("Enter the end time");
                saveButton.disabled = false;
                document.AJAX.endtime.focus();
                return;         
            }         
            if(!(checkDateTime(document.AJAX.starttime.value))){
                saveButton.disabled = false;
                return;
            }            
            if(!(checkDateTime(document.AJAX.endtime.value))){
                saveButton.disabled = false;
                return;
            }             
            var isValidTimeDiff = checkDiff(document.AJAX.starttime.value,document.AJAX.endtime.value); 
            if(isValidTimeDiff==false){
                        saveButton.disabled = false;
                        return;
            }
            <% messageIn = i18n.tr("Date");%>
                var isValidTimeDiff1 = CurrentDateValidation(document.AJAX.starttime.value.trim(),'<%= messageIn%>'); 
                if(isValidTimeDiff1==false){
                    saveButton.disabled = false;
                     document.AJAX.starttime.focus();
                      return;
                }
        } else if(document.getElementById("isSurveyOrFeedback").value == 1 ){
            if( document.getElementById("feedbackImageName").value === '' ){
                alert("Please upload image");
                saveButton.disabled = false;
                return;
            }
            var isProcedureChecked = document.getElementById("procedureId");
            var isCustomClassChecked = document.getElementById("customClassId");            
            if( isProcedureChecked.checked ){
                if( document.getElementById("procedureName").value == '' ){
                    alert("Please provide procedure name");
                    saveButton.disabled = false;
                    document.getElementById("procedureName").focus();
                    return;
                }
            }else if( isCustomClassChecked.checked ){
                if( document.getElementById("customClassName").value == '' ){
                    alert("Please provide custom class name");
                    saveButton.disabled = false;
                    document.getElementById("customClassName").focus();
                    return;
                }
            }
        }
                    if(document.getElementById("ruleCount").value == 0){
                        alert('Please select atleast one rule');
                        saveButton.disabled = false;
                        return;
                    }
                    var commentSize ='${applicationScope.SAPPHIRE_CONFIG_SETTINGS.findBySettingKey("SERVICEDESK_COMMENT_SIZE")}';
                    var ckEditor = CKEDITOR.instances.emailTemplate;
                     if(parseInt(ckEditor.getData().length) > commentSize){
                          alert("Please limit your email template content to less than "+commentSize+" characters");
                         saveButton.disabled = false;
                          return;
                     }
        
                     if( document.getElementById("isSurveyOrFeedback").value == 0 ){
                            if(document.getElementById("preNotificationOne").checked == true){
                                if(document.getElementById("levelOneIntervalDays").value == "" && document.getElementById("levelOneIntervalHours").value == "0" && document.getElementById("levelOneIntervalMins").value == "0"){
                                    alert("Please select time interval");
                                    saveButton.disabled = false;
                                    document.getElementById("levelOneIntervalDays").focus();
                                    return;
                                }else if(document.getElementById("levelOneIntervalDays").value != "" && document.getElementById("levelOneIntervalDays").value != "0"){
                                    if(isNaN(document.getElementById("levelOneIntervalDays").value)){
                                        alert("Please enter interger value in interval days");
                                        saveButton.disabled = false;
                                        document.getElementById("levelOneIntervalDays").focus();
                                        return;
                                    }
                                    if(document.getElementById("levelOneIntervalDays").value < 0){
                                        alert("Please enter interval day as greater than zero");
                                        saveButton.disabled = false;
                                        document.getElementById("levelOneIntervalDays").focus();
                                        return;
                                    }
                                }else if(document.getElementById("levelOneIntervalHours").value == "0" && document.getElementById("levelOneIntervalMins").value == "0"){
                                    if(document.getElementById("levelOneIntervalDays").value == "0"){
                                        alert("Please enter interval day as greater than zero");
                                        saveButton.disabled = false;
                                        document.getElementById("levelOneIntervalDays").focus();
                                        return;
                                    }
                                }
                            }
                             if(document.getElementById("preNotificationTwo").checked == true){
                                if(document.getElementById("levelTwoIntervalDays").value == "" && document.getElementById("levelTwoIntervalHours").value == "0" && document.getElementById("levelTwoIntervalMins").value == "0"){
                                    alert("Please select time interval");
                                    saveButton.disabled = false;
                                    document.getElementById("levelTwoIntervalDays").focus();
                                    return;
                                }else if(document.getElementById("levelTwoIntervalDays").value != "" && document.getElementById("levelTwoIntervalDays").value != "0"){
                                    if(isNaN(document.getElementById("levelTwoIntervalDays").value)){
                                        alert("Please enter interger value in interval days");
                                        saveButton.disabled = false;
                                        document.getElementById("levelTwoIntervalDays").focus();
                                        return;
                                    }
                                    if(document.getElementById("levelTwoIntervalDays").value < 0 ){
                                        alert("Please enter interval day as greater than zero");
                                        saveButton.disabled = false;
                                        document.getElementById("levelTwoIntervalDays").focus();
                                        return;
                                    }
                                }else if(document.getElementById("levelTwoIntervalHours").value == "0" && document.getElementById("levelTwoIntervalMins").value == "0"){
                                    if(document.getElementById("levelTwoIntervalDays").value == "0" ){
                                        alert("Please enter interval day as greater than zero");
                                        saveButton.disabled = false;
                                        document.getElementById("levelTwoIntervalDays").focus();
                                        return;
                                    }

                                }
                            }
                            if(document.getElementById("preNotificationOne").checked == true && document.getElementById("preNotificationTwo").checked == true){
                                var level1Days = document.getElementById("levelOneIntervalDays").value;
                                var level1Hours = document.getElementById("levelOneIntervalHours").value;
                                var level1Mins = document.getElementById("levelOneIntervalMins").value;
                                var level2Days = document.getElementById("levelTwoIntervalDays").value;
                                var level2Hours = document.getElementById("levelTwoIntervalHours").value;
                                var level2Mins = document.getElementById("levelTwoIntervalMins").value;
                                var preNotificationOneInterval = (level1Days*24*60*60)+(level1Hours*60*60)+(level1Mins*60); 
                                var preNotificationTwoInterval =(level2Days*24*60*60)+(level2Hours*60*60)+(level2Mins*60);

                                if(preNotificationTwoInterval>=preNotificationOneInterval){
                                    alert('Pre notification level one time interval should be greater than pre notification level two time interval');
                                    saveButton.disabled = false;
                                    return;
                                }

                            }
                    }
		    
		
	      if(count==0)
              {
               alert("Please enter atleast one question");
                  saveButton.disabled = false;
               document.AJAX.question.focus();
	        return;
            }
        }
        if(document.getElementById('delete_feedbackIcon')!= null && document.getElementById('delete_feedbackIcon').value == "1")
            { 
                if(window.XMLHttpRequest){
                    xmlDoc = new XMLHttpRequest();
                }else if(window.ActiveXObject){
                    xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
                }
                var url=null;
                var row = document.getElementById('pathForDeleteAttachement');
                url="deleteAttachment.do?path="+document.getElementById('pathForDeleteAttachement').value+"&attachmentType="+document.getElementById('attachmentType').value;
                xmlDoc.open("POST", url, false);
                xmlDoc.setRequestHeader("X-CSRF-TOKEN","${_csrf.token}");
                xmlDoc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xmlDoc.send(null);
                var i=row.parentNode.parentNode.rowIndex;
                document.getElementById('feedbackImageAttachTable').deleteRow(i);
                document.getElementById("feedbackImageUpload").style.display="";
                document.getElementById("imgTab").style.display="";  
            }
       
   document.AJAX.submit();
}
var surveyTemplateHide=1;
var mailConfigurationHide=1;
var hookConfigurationHide=1;
function showhidepane(value)
{
    if(value==1){
        if(surveyTemplateHide==1){
          document.getElementById('SurveyTemplateDiv').style.display='none';
          document.getElementById('SurveyTemplatePlusMinusImg').src="icon_plus.gif";
          surveyTemplateHide=0;
        }else{
          document.getElementById('SurveyTemplateDiv').style.display='';
          document.getElementById('SurveyTemplatePlusMinusImg').src="icon_minus.gif";
          surveyTemplateHide=1;
        }
    }else if(value == 2 ){
        if(mailConfigurationHide==1){
          document.getElementById('MailConfigurationDiv').style.display='none';
          document.getElementById('AckMailConfigurationDiv').style.display='none';
          document.getElementById('MailConfigurationPlusMinusImg').src="icon_plus.gif";
          mailConfigurationHide=0;
        }else{
          document.getElementById('MailConfigurationDiv').style.display='';
          document.getElementById('AckMailConfigurationDiv').style.display='';
          document.getElementById('MailConfigurationPlusMinusImg').src="icon_minus.gif";
          mailConfigurationHide=1;
        }
    }else if( value == 3 ){        
        if(hookConfigurationHide==1){
            document.getElementById('actionsHookDiv').style.display='none'; 
            document.getElementById('hookPlusMinusImg').src="icon_plus.gif";
            hookConfigurationHide=0;
        }else{
            document.getElementById('actionsHookDiv').style.display=''; 
            document.getElementById('hookPlusMinusImg').src="icon_minus.gif";
            hookConfigurationHide=1;
        }
    }
}
 function setTitle(){
     var url="SurveyDetails.jsp?IsTitle=yes&isNewUIPopupAvailable=yes";
     popUpPage(url,779,200,'&nbsp;');
 }
 function setQuestion(){
     var url="SurveyDetails.jsp?surveyType="+document.getElementById("isSurveyOrFeedback").value+"&isNewUIPopupAvailable=yes&jqueryWithProtoReq=yes";
     popUpPage(url,779,350,'&nbsp;');
 }
 function addTitle(title){
          var ni = document.getElementById('SurveyTempalteDetailsDiv');
	  var numi = document.getElementById('layoutCount'); 
	  var num = (document.getElementById("layoutCount").value -1)+ 2;
	  numi.value = num;
	  var divIdName = "my"+num+"Div";
	  var newdiv = document.createElement('div');
	  newdiv.setAttribute("id",divIdName);
	  
          newdiv.innerHTML = "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"1\"><tr class='mcopy'><td align=\"left\" width=\"90%\" class=\"copyhdr\"><input type=\"hidden\" name=\"questions\" id=\"questions\" value=\"MACRO_TITLE$$$$"+title+"\"><b>"+title+"</b></td><td align=\"right\" width=\"10%\" class=\"gen posAbso\"><a href=\"javascript:;\" title=\"Delete\" onclick=\"removeEvent(\'"+divIdName+"\',0)\"><img border=\"0\" src=\"fault_x.gif\" class=\"deleteRule\" width=\"12\" height=\"12\"></a></td></td> <tr></table>";	  	
	  
            ni.appendChild(newdiv);
          }
 function addQuestion(design){
          var ni = document.getElementById('SurveyTempalteDetailsDiv');
	  var numi = document.getElementById('layoutCount'); 
	  var num = (document.getElementById("layoutCount").value -1)+ 2;
	  numi.value = num;
	  var divIdName = "my"+num+"Div";
	  var newdiv = document.createElement('div');
	  newdiv.setAttribute("id",divIdName);
	  
          newdiv.innerHTML = "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"1\"><tr class='mcopy'><td align=\"left\" width=\"90%\" class=\"gen\"><b>"+design+"</b></td><td align=\"right\" width=\"10%\" class=\"gen\"><a href=\"javascript:;\" title=\"Delete\" onclick=\"removeEvent(\'"+divIdName+"\',1)\"><img border=\"0\" src=\"fault_x.gif\" width=\"12\" height=\"12\" class=\"deleteRule\"></a></td></td> <tr></table>";	  	
	  
	  count++;
	  ni.appendChild(newdiv);
 }
 function sendMailOption(){
    if(document.getElementById('sendmail').checked == true){
        document.getElementById('mailTemplateDiv').style.display="";
        document.getElementById('ccManagerDIV').style.display="inline";
        var emailTemplate = "";
        if( document.getElementById("isSurveyOrFeedback").value == 0 ){
            emailTemplate = "<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that a new survey titled <b>MACRO_SURVEYTITLE</b> is available and it requires your participation.Please participate in the survey and provide your valuable feedback for enhancing the experience.<br /><br />Please ensure that you participate in the survey on or before <b>MACRO_SURVEYENDTIME</b>.</p>";
            document.getElementById("emailTemplate").value = emailTemplate;
            CKEDITOR.instances["emailTemplate"].setData(emailTemplate);            
        }else{
            emailTemplate = "<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that a new feedback titled <b>MACRO_SURVEYTITLE</b> is available and it requires your participation.Please participate and provide your valuable feedback for enhancing the experience.<br /></p>";
            document.getElementById("emailTemplate").value = emailTemplate;
            CKEDITOR.instances["emailTemplate"].setData(emailTemplate);
        }
        document.getElementById('macroBlock').style.display="";
                    document.getElementById('templateDesignBlock').style.display="";
    }else{
        document.getElementById('mailTemplateDiv').style.display="none";
        document.getElementById('ccManagerDIV').style.display="none";
        document.getElementById('macroBlock').style.display="none";
                    document.getElementById('templateDesignBlock').style.display="none";

    }
}
function ackMailOption(){
    if(document.getElementById('acksendmail').checked == true){
        document.getElementById('ackmailTemplateDiv').style.display="";        
        var ackMailTemplate = "";
        if( document.getElementById("isSurveyOrFeedback").value == 0 ){
            ackMailTemplate = "<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that you have successfully participated in the survey titled <b>MACRO_SURVEYTITLE</b><br /><br />Thanks for your participation</b>.</p>";
            document.getElementById("ackemailTemplate").value = ackMailTemplate;
            CKEDITOR.instances["ackemailTemplate"].setData(ackMailTemplate);
        }else{
            ackMailTemplate = "<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that you have successfully participated in the feedback titled <b>MACRO_SURVEYTITLE</b><br /><br />Thanks for your participation</b>.</p>";
            document.getElementById("ackemailTemplate").value = ackMailTemplate;
            CKEDITOR.instances["ackemailTemplate"].setData(ackMailTemplate);
        }        
      }else{
        document.getElementById('ackmailTemplateDiv').style.display="none";       
      }
}
function isProcedureOrCustomclasschecked(hookType){


    var isProcedureChecked = document.getElementById("procedureId");
    var isCustomClassIdChecked = document.getElementById("customClassId");
    if(hookType.name == 'pcrocedure') {
        if (isProcedureChecked.checked) {
            document.getElementById("customClassId").checked = false;
        document.getElementById('isProcedureOrCustomClass').value = 1;
        document.getElementById('procedureNameDiv').style.display="";
        document.getElementById('customClassNameDiv').style.display="none";
    }else{
            document.getElementById('isProcedureOrCustomClass').value = 0;
            document.getElementById('procedureNameDiv').style.display = "none";
        }
    }else {

        if (isCustomClassIdChecked.checked) {
            document.getElementById("procedureId").checked = false;
        document.getElementById('isProcedureOrCustomClass').value = 2;
        document.getElementById('customClassNameDiv').style.display="";
        document.getElementById('procedureNameDiv').style.display="none";
        } else {
            document.getElementById('isProcedureOrCustomClass').value = 0;
            document.getElementById('customClassNameDiv').style.display = "none";
    }
}
}
function addEvent(element)
{
	if(element=='ques'){
	 if(document.AJAX.question.value.trim()=="")
	 {
	 alert("Enter the question ");
	 document.AJAX.question.value="";
	 document.AJAX.question.focus();
			return;
	 } 
	}else{
		if(document.AJAX.title.value.trim()=="")
		 {
		 alert("Enter the Title ");
		 document.AJAX.title.value="";
		 document.AJAX.title.focus();
				return;
		 }
	}
 	var questionValue='';
 	var titleValue='';
	if(element=='ques'){
	 questionValue=document.AJAX.question.value;
	 questionValue=questionValue.replace(/\"/g,"\\&#34");
	 }else{
	 	titleValue=document.AJAX.title.value;
	 	titleValue=titleValue.replace(/\"/g,"\\&#34");
	 	titleValue="MACRO_TITLE$$$$"+titleValue;
	 }
	
	  var ni = document.getElementById('dynamicRow');
	  var numi = document.getElementById('rowCount'); 
	  var num = (document.getElementById("rowCount").value -1)+ 2;
	  numi.value = num;
	  var divIdName = "my"+num+"Div";
	  var newdiv = document.createElement('div');
	  newdiv.setAttribute("id",divIdName);
	  if(element=='ques'){
	  	newdiv.innerHTML = "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"1\" bordercolorlight=\"#E2E2E2\"><tr class='formfield'><td align=\"center\" width=\"20%\" class=\"gen\"><a href=\"javascript:;\" title=\"Delete\" onclick=\"removeEvent(\'"+divIdName+"\')\"><img border=\"0\" src=\"fault_x.gif\" width=\"12\" height=\"12\" class=\"deleteRule\"></a></td></td> <td align=\"center\" width=\"80%\" class=\"gen\"><input type=\"hidden\" name=\"questions\" id=\"questions\" value=\""+questionValue+"\">"+document.AJAX.question.value+"</td><tr></table>";
	  }else{
		newdiv.innerHTML = "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"1\" bordercolorlight=\"#E2E2E2\"><tr class='formfield'><td align=\"center\" width=\"20%\" class=\"gen\"><a href=\"javascript:;\" title=\"Delete\" onclick=\"removeEvent(\'"+divIdName+"\')\"><img border=\"0\" src=\"fault_x.gif\" width=\"12\" height=\"12\" class=\"deleteRule\"></a></td></td> <td align=\"center\" width=\"80%\" class=\"gen\"><input type=\"hidden\" name=\"questions\" id=\"questions\" value=\""+titleValue+"\"><b>"+document.AJAX.title.value+"</b></td><tr></table>";	  	
	  }
	  count++;
	  ni.appendChild(newdiv);
	  if(element=='ques'){
	  	document.AJAX.question.value="";
	  	document.AJAX.question.focus();
	  }else{
	  	document.AJAX.title.value="";
	  	document.getElementById("quesTitle").style.display="none";
		document.getElementById("addTitle").disabled=false;
		document.getElementById("question").disabled=false;
		document.getElementById("addbutton").disabled=false;
		document.getElementById("quesBlock").style.display="block";
		document.AJAX.question.focus();
	  }
  

}

function removeEvent(divNum,identity)
{
 var d = document.getElementById('SurveyTempalteDetailsDiv');
 var olddiv = document.getElementById(divNum);
 var num=document.getElementById("layoutCount").value;
 num=num-1;
 document.getElementById("layoutCount").value=num;
 if(identity==1){
      count--;
 }
 d.removeChild(olddiv);

}

function showTitle(){
	document.AJAX.question.value="";
	document.getElementById("quesTitle").style.display="block";
	document.getElementById("addTitle").disabled=true;
	document.getElementById("question").disabled=true;
	document.getElementById("addbutton").disabled=true;
	document.AJAX.title.focus();
	
}
function showQues(){
	document.AJAX.title.value="";
	document.getElementById("quesTitle").style.display="none";
	document.getElementById("addTitle").disabled=false;	
	document.getElementById("question").disabled=false;
	document.getElementById("addbutton").disabled=false;
	document.getElementById("quesBlock").style.display="block";
	document.AJAX.question.focus();
}
function enableQuesBlock(){
	document.getElementById("question").disabled=false;
	document.getElementById("addTitle").disabled=false;
	document.getElementById("addbutton").disabled=false;
	
}
function addRule(){
    
    var ruleCount=parseInt(document.getElementById('ruleCount').value);
    ruleCount++;
    
    var parentDiv = document.getElementById('dynamicRow_Rule');
    var divIdName = "Div_"+ruleCount+"_Rule";
    var newdiv = document.createElement('div');
    newdiv.setAttribute("id",divIdName);
     var locationDisplayNames = "";
     var departmentDisplayNames = "";
     var rolesDisplayNames = "";
     var usersDisplayNames = "";
     var locationValues = "";
     var departmentValues = "";
    var rolesValues = "";
    var usersValues = "";
    
    
    var location = document.getElementById('location');
    var department = document.getElementById('department');   
   var roles = document.getElementById('roles');
     var users = document.getElementById('users'); 
     if(location.value == '' && department.value == '' && roles.value == '' &&  users.value == '') {
         alert('Please select atleast one parameter to add rule');
         return;
     }
     if(location.value != ""){
        var selectAll=0;
        var selectOne=0;
        for(var i=0;i<location.length;i++){
            if(location.options[i].selected == true){
                if(location.options[i].value == "0"){
                    selectAll=1;
                }else{
                    selectOne=1;
                }                
            }
        }
        if(selectAll ==1 && selectOne ==1){
            alert("Select either All or any other particular location");
            return;
        }
    }
    
    if(department.value != ""){
        var selectAll=0;
        var selectOne=0;
        for(var i=0;i<department.length;i++){
            if(department.options[i].selected == true){
                if(department.options[i].value == "0"){
                    selectAll=1;
                }else{
                    selectOne=1;
                }
            }
        }
        if(selectAll ==1 && selectOne ==1){
            alert("Select either All or any other particular department");
            return;
        }
    }
     if(roles.value != ""){
        var selectAll=0;
        var selectOne=0;
        for(var i=0;i<roles.length;i++){
            if(roles.options[i].selected == true){
                if(roles.options[i].value == "0"){
                    selectAll=1;
                }else{
                    selectOne=1;
                }
            }
        }
        if(selectAll ==1 && selectOne ==1){
            alert("Select either All or any other particular roles");
            return;
        }
    }
     if(users.value != ""){
        var selectAll=0;
        var selectOne=0;
        for(var i=0;i<users.length;i++){
            if(users.options[i].selected == true){
                if(users.options[i].value == "0"){
                    selectAll=1;
                }else{
                    selectOne=1;
                }
            }
        }
        if(selectAll ==1 && selectOne ==1){
            alert("Select either All or any other particular users");
            return;
        }
    }
     if(location.value != ""){
        for(var i=0;i<location.length;i++){
            if(location.options[i].selected == true){
                if(locationDisplayNames == ""){
                    locationDisplayNames = location.options[i].text;
                   locationValues = location.options[i].value;
                }
                else{
                   locationDisplayNames = locationDisplayNames+"<br>"+location.options[i].text;
                   locationValues = locationValues+" , "+location.options[i].value;
                }
            }
        }
    }
    else{
        locationDisplayNames ="--";
    }
    if(department.value != ""){
        for(var i=0;i<department.length;i++){
            if(department.options[i].selected == true){
                if(departmentDisplayNames == ""){
                    departmentDisplayNames = department.options[i].text;
                   departmentValues = department.options[i].value;
                }
                else{
                   departmentDisplayNames = departmentDisplayNames+"<br>"+department.options[i].text;
                   departmentValues = departmentValues+" , "+department.options[i].value;
                }
            }
        }
    }
    else{
        departmentDisplayNames ="--";
    }
    if(roles.value != ""){
        for(var i=0;i<roles.length;i++){
            if(roles.options[i].selected == true){
                if(rolesDisplayNames == ""){
                    rolesDisplayNames = roles.options[i].text;
                   rolesValues = roles.options[i].value;
                }
                else{
                   rolesDisplayNames = rolesDisplayNames+"<br>"+roles.options[i].text;
                   rolesValues = rolesValues+" , "+roles.options[i].value;
                }
            }
        }
    }
    else{
        rolesDisplayNames ="--";
    }
    if(users.value != ""){
        for(var i=0;i<users.length;i++){
            if(users.options[i].selected == true){
                if(usersDisplayNames == ""){
                    usersDisplayNames = users.options[i].text;
                   usersValues = users.options[i].value;
                }
                else{
                   usersDisplayNames = usersDisplayNames+"<br>"+users.options[i].text;
                   usersValues = usersValues+" , "+users.options[i].value;
                }
            }
        }
    }
    else{
        usersDisplayNames ="--";
    }   
    
    newdiv.innerHTML = "<table width=\"100%\" border=\"0\" class=\"ruleList\"><tr class='formfield importantAutoHt'><td align=\"center\" width=\"10%\" class=\"gen\"><a href=\"javascript:;\" class=\"delete1\" title=\"Delete\" onclick=\"removeRule(\'"+divIdName+"\')\"><img border=\"0\" src=\"fault_x.gif\" width=\"12\" height=\"12\" class='deleteRule'></a></td>"+
                       "<input type=\"hidden\" name=\"location_values\" id=\"location_values\" value=\""+locationValues+"\">"+
                       "<input type=\"hidden\" name=\"department_values\" id=\"department_values\" value=\""+departmentValues+"\">"+
                       "<input type=\"hidden\" name=\"roles_values\" id=\"roles_values\" value=\""+rolesValues+"\">"+
                       "<input type=\"hidden\" name=\"users_values\" id=\"users_values\" value=\""+usersValues+"\">"+
                       "<td align=\"center\" width=\"20%\" class=\"gen\">"+locationDisplayNames+"</td>"+
                       "<td align=\"center\" width=\"20%\" class=\"gen\">"+departmentDisplayNames+"</td>"+
                       "<td align=\"center\" width=\"20%\" class=\"gen\">"+rolesDisplayNames+"</td>"+
                       "<td align=\"center\" width=\"30%\" class=\"gen\">"+usersDisplayNames+"</td>"+
                       "</tr></table>";
    parentDiv.appendChild(newdiv);
    document.getElementById('ruleCount').value = ruleCount;

    jQuery(location).multipleSelect('uncheckAll');
    jQuery(department).multipleSelect('uncheckAll');
    jQuery(roles).multipleSelect('uncheckAll');
    jQuery(users).multipleSelect('uncheckAll');

}
function removeRule(divNum){    

    var ruleCount_remove = parseInt(document.getElementById('ruleCount').value);    
    ruleCount_remove--;
     
    var parentDiv = document.getElementById('dynamicRow_Rule');
    var divToDelete = document.getElementById(divNum);
    parentDiv.removeChild(divToDelete);
    document.getElementById('ruleCount').value = ruleCount_remove;   
    
}
function displayNotificationLevelOne(){
        if(document.getElementById("preNotificationOne").checked == true){
            document.getElementById("levelOneInterval").style.display="";
        }else{
            if(document.getElementById("preNotificationTwo").checked == true){
                var confirmFlag = confirm("Removing pre notification level 1 will also remove pre notification level 2");            
                if(confirmFlag){
                    document.getElementById("preNotificationTwo").checked = false;
                    displayNotificationLevelTwo();
                }else{
                    document.getElementById("preNotificationOne").checked = true;
                    return;
                }
            }
            document.getElementById("levelOneInterval").style.display="none";
        }
    }
    function displayNotificationLevelTwo(){
        if(document.getElementById("preNotificationTwo").checked == true){
            if(!document.getElementById("preNotificationOne").checked){
                alert('Select pre notification level 1 before pre notification level 2');
                document.getElementById("preNotificationTwo").checked = false;
                return;
            }
            document.getElementById("levelTwoInterval").style.display="";
        }else{
            document.getElementById("levelTwoInterval").style.display="none";
        }
    }
    function showSurveyTimeConstraint(){
        var isSurveyChecked = document.getElementById("surveyData");
        if( isSurveyChecked.checked ){
            //preNotificationOneDiv,preNotificationTwoDiv
            document.getElementById("surveyTimeConstraintDiv").style.display = "";
            document.getElementById("preNotificationOneDiv").style.display = "";
            document.getElementById("preNotificationTwoDiv").style.display = "";
            document.getElementById("feedbackImageUploadDiv").style.display = "none";
            document.getElementById("hookHeaderDiv").style.display = "none";
            document.getElementById("hookConfigurationDiv").style.display = "none";
            document.getElementById("procedureNameDiv").style.display = "none";
            document.getElementById("customClassNameDiv").style.display = "none";            
            document.getElementById("isSurveyOrFeedback").value = 0;
            if(document.getElementById('sendmail').checked == true){
                var emailTemplate = "<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that a new survey titled <b>MACRO_SURVEYTITLE</b> is available and it requires your participation.Please participate in the survey and provide your valuable feedback for enhancing the experience.<br /><br />Please ensure that you participate in the survey on or before <b>MACRO_SURVEYENDTIME</b>.</p>";
                document.getElementById("emailTemplate").value = emailTemplate;
                CKEDITOR.instances["emailTemplate"].setData(emailTemplate);
            }
            if(document.getElementById('acksendmail').checked == true){
                var ackMailTemplate = "<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that you have successfully participated in the survey titled <b>MACRO_SURVEYTITLE</b><br /><br />Thanks for your participation</b>.</p>";
                document.getElementById("ackemailTemplate").value = ackMailTemplate;
                CKEDITOR.instances["ackemailTemplate"].setData(ackMailTemplate);
            }
        }else{
            document.getElementById("surveyTimeConstraintDiv").style.display = "none";
            document.getElementById("preNotificationOneDiv").style.display = "none";
            document.getElementById("preNotificationTwoDiv").style.display = "none";
            document.getElementById("feedbackImageUploadDiv").style.display = "";
            document.getElementById("hookHeaderDiv").style.display = "";
            document.getElementById("hookConfigurationDiv").style.display = "";
            document.getElementById("procedureId").checked = false;
            document.getElementById("customClassId").checked = false;
            document.getElementById("isSurveyOrFeedback").value = 1;
            if(document.getElementById('sendmail').checked == true){
                var emailTemplate = "<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that a new feedback titled <b>MACRO_SURVEYTITLE</b> is available and it requires your participation.Please participate and provide your valuable feedback for enhancing the experience.<br /></p>";
                document.getElementById("emailTemplate").value = emailTemplate;
                CKEDITOR.instances["emailTemplate"].setData(emailTemplate);
            }
            if(document.getElementById('acksendmail').checked == true){
                ackMailTemplate = "<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that you have successfully participated in the feedback titled <b>MACRO_SURVEYTITLE</b><br /><br />Thanks for your participation</b>.</p>";
                document.getElementById("ackemailTemplate").value = ackMailTemplate;
                CKEDITOR.instances["ackemailTemplate"].setData(ackMailTemplate);
            }
        }
    }
    function doFileBrowse(){
        var url="UpLoad.jsp?feedbackImage=yes&extensionType=SD_PROJECT_ICON&isNewUIPopupAvailable=yes";
        popUpPage(url,700,230,'&nbsp;'); 
    }
    function displayContent(filepath,access,uniqueGeneratedString){
        if(filepath != ""){ 
            var filename=filepath.split("\\");
            var table_row=document.getElementById('feedbackImageAttachTable').insertRow(1);
            var firstCell=table_row.insertCell(0);
            var secondCell=table_row.insertCell(1);
            var path = uniqueGeneratedString+"_"+filename[filename.length-1];
            secondCell.innerHTML="<span class='domains'>"+filename[filename.length-1]+"</span>&nbsp;&nbsp;&nbsp;&nbsp;";
            firstCell.innerHTML="<input type='hidden' name='filenames' id='filenames' value='"+filename[filename.length-1]+"'/>"+
                                 "<input type='hidden' name='uniqueString' id='uniqueString' value='"+uniqueGeneratedString+"'/>"+
                                 "<a href='#' class='domains' onclick='deleteImage(this)'><img src='remove.jpg' border='0' title='Remove attachment' width='12' height='12'></img></a>&nbsp;"
            document.getElementById("feedbackImageUpload").style.display="none";
            document.getElementById("imgTab").style.display="none";
            document.getElementById("feedbackImageName").value = filename[filename.length-1];
        } 
    }
    function deleteImage(row){
        var k=confirm('Are you sure you want to delete the image'); 
        if(k==true){
            
            document.getElementById('feedbackImageAttachTable').rows[1].style.display = "none";
            if(document.getElementById('delete_feedbackIcon')!= null){
            document.getElementById("delete_feedbackIcon").value = 1;
            }
            document.getElementById("feedbackImageUpload").style.display="";
            document.getElementById("imgTab").style.display="";
            document.getElementById("feedbackImageName").value = "";
        }
   }
   function addMacroToEditor(){
        var macroToBeReplaced = document.getElementById("macroList").value; 
        if( macroToBeReplaced == 0 ){
            alert("Please choose a macro from 'Macro List'");
            document.getElementById("macroList").focus(); 
            return;
        }
        CKEDITOR.instances['emailTemplate'].insertText(macroToBeReplaced);
    }
    function getRadioSelectedVal(){         
        var selectedVal = "";
        var radioArrVal = document.getElementsByName("surveyType");        
        for(var i=0;i<radioArrVal.length;i++){
            if( radioArrVal[i].checked ){
                selectedVal = radioArrVal[i].value;       
            }
        }
        return selectedVal;
    }
</script>


<link href="CalendarControl.css" rel="stylesheet" type="text/css">
<script src="CalendarControl.js" language="JavaScript" type="text/javascript"></script>


<script type="text/javascript" src="cookies.js"></script>

</head>
<%

	response.setDateHeader ("Expires", 0); 


%>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="">
  <form  name="AJAX" method="post" action="Survey" >  
<security:csrfInput/>
<%@ include file="toptable.jsp" %>
<div id="mainContentArea1" class="surveyAddConfig">
<table width="100%" height="70%" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>

   
	   <td rowspan="2" align="center" valign="top" class="inbg">
         <table width="100%" border="0" cellspacing="0" cellpadding="0">
          
               <table width="100%"  border="0" cellpadding="0" cellspacing="0">        
              
				  <tr>
				  	<td colspan="2" align="center" valign="top"> 
				<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
				    <tr>
    	             <td align="center">
			    <table width="100%" border="0" cellspacing="0" cellpadding="0">
       		      <tr>
		  		   <td colspan="3">
				     <table width="100%" border="0" cellspacing="0" cellpadding="0">
		             <tr>
			          <td colspan="3" >	
                                      <div style="width:99.5%" > 
			   		  <table width="100%" border="0" cellspacing="0" cellpadding="0" id="subTabNavigation">
			     		 <tr>
			       			 <td height="24" valign="bottom">
			      			  <table width="140" border="0" cellspacing="0" cellpadding="0">
			          			  <tr>
	     	     			         <td><ul> 
                                                        <li class="selected marginB10"><a href="javascript:void(0)"  style="white-space:nowrap;"><%= i18n.tr("User Surveys")%>
                                                                </a><span></span></li></ul>
	     	     			         </td>
				                   </tr>
				              </table>
				            </td>
				         </tr>
							     <%
							     	connection myConn = null;
									Connection conn   = null;
									PreparedStatement pst    = null;
									ResultSet rs      = null;		
							    	String current_dbTime="";
                                                                String email_Template="<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that a new survey titled <b>MACRO_SURVEYTITLE</b> is available and it requires your participation.Please participate in the survey and provide your valuable feedback for enhancing the experience.<br /><br />Please ensure that you participate in the survey on or before <b>MACRO_SURVEYENDTIME</b>.</p>";
                                                                String ackemail_Template="<p>Dear <b>MACRO_SURVEYUSER</b>,<br /><br />This mail is to notify that you have successfully participated in the survey titled <b>MACRO_SURVEYTITLE</b><br /><br />Thanks for your participation</b>.</p>";
							   try  {
							     	 
								   		myConn = new connection();
								   		conn = myConn.getConnection(telantName);
					  		
								  		pst = conn.prepareStatement("select DATE_FORMAT(now(), '%M %d, %Y %H:%i:%s')");
								  		rs=pst.executeQuery();
										if(rs.next()){
										  current_dbTime=rs.getString(1);
										}
										rs.close(); 
                                                                                pst.close();
						
								
					 		 %>						 	 
            
            </table>
                                      </div>
           </td>
        </tr>
       
        <tr>
           <td width="14">
           </td>
           <td width="100%" align="center" valign="top" >
       
       <table width="100%" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td> <div class="contentBlock noMargin"> 
                            <div class="widgetOuterWrapper"> 
                            <div class="widgetInnerWrapper"> 
                   
       	<table width="100%" border="0" cellspacing="0" cellpadding="0">	    	    
    		<tr>
     			<td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Survey Name") %><font color="red">*</font></td>
     			</td>
     			<td width="80%" height="35" bgcolor="#FFFFFF" class="formfield"> 
 				<input type="text" id="surveyName" name="surveyName"  size="80"   class="mcopy" value=""  maxlength="100">
 		 		<input type="hidden" name="curr_time" id="curr_time" value="<%=current_dbTime%>" />
       			</td>
   		</tr>
                 <tr>
     			<td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Survey Description") %>
     			</td>
                     <td width="80%" height="35" bgcolor="#FFFFFF" class="formfield"> 
                         <textarea class='gen' cols="94" rows="5" id="surveyDesc" name="surveyDesc"></textarea>
                     </td>
                 </tr>
                <!-- Survey Starts here -->
                <tr>
                    <td colspan="4" class="wid100">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Survey Type") %><font color="red">*</font></td></td>
                                <td width="5%" height="35" bgcolor="#FFFFFF" class="formfield">
                                    <input type="radio" id="surveyData" name="surveyType" onclick="showSurveyTimeConstraint();"/>
									<label class="customRadCheck" for="surveyData"><span><span></span></span></label>
									<span>Survey</span>
                                </td>
                                <td width="75%" height="35" bgcolor="#FFFFFF" class="formfield">
                                    <input type="radio" id="feedbackData" name="surveyType" onclick="showSurveyTimeConstraint();"/>
									<label class="customRadCheck" for="feedbackData"><span><span></span></span></label>
									<span>Feedback</span>
                                </td>
                                <input type="hidden" id="isSurveyOrFeedback" name="isSurveyOrFeedback" value="" />
                            </tr>
                        </table>
                    </td>
                </tr>   
                <tr id="feedbackImageUploadDiv" style="display:none">
                    <td colspan="4" class="wid100">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr class="imgSelection">
                                <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Image Upload") %><font color="red">*</font></td></td>
                                <td class="formfield">
                                    <img src='attachment.gif' id='imgTab' class="icon"/><input  type="button"  id="feedbackImageUpload" name="feedbackImageUpload" onClick="doFileBrowse()" value="Upload Image"  class="addbuttons attachbtn">
                                        <table id="feedbackImageAttachTable" class="attachedList">
                                            <tr><td><input type="hidden" id="feedbackImageName" name="feedbackImageName" value="" /></td><td></td></tr>
                                            
                                        </table>
                                </td>
                                
                            </tr>
                        </table>
                    </td>
                </tr>
                <!-- Survey Ends here -->
		<tr id="surveyTimeConstraintDiv" style="display:none;">
                    <td colspan="4" class="wid100">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">	    
                            <tr>
                                <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext bPadding2"><%= i18n.tr("Start Time") %><font color="red">*</font></td></td>
                                <td width="30%" height="35" bgcolor="#FFFFFF" class="formfield">
                                    <input class="mcopy" id="starttime" type="text" name="starttime" size="20" onfocus="showCalendarControl(this);">
                                </td>
                                <td align="right" bgcolor="#FFFFFF" width="10%" class="formtext topMargin10 bPadding2"><%= i18n.tr("End Time") %><font color="red">*</font></td></td>
                                <td width="40%" height="35" bgcolor="#FFFFFF" class="formfield">
                                  <input class="mcopy" id="endtime" type="text" name="endtime" size="20" onfocus="showCalendarControl(this);">
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" class="wid100">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">	    
                            <tr>
                                <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Location") %></td>
                                <td width="30%" bgcolor="#FFFFFF" class="formfield">
                                  <select name="location" id="location" class="gen" style="width:270px" multiple size="4">
                                  <option value="0" >All</option>
                                    <%      pst = conn.prepareStatement("SELECT LocationID,LocationName FROM servicedesklocationmaster");
                                            rs=pst.executeQuery();
                                            while(rs.next()){
                                            %>
                                            <option value="<%=rs.getInt(1) %>"><%=rs.getString(2) %></option>
                                            <%
                                            }rs.close();  pst.close();
                                     %>
                                  </select>
                                </td>
                                  <td align="right" bgcolor="#FFFFFF" width="10%" class="formtext topMargin10"><%= i18n.tr("Department") %></td>
                                   <td width="40%" bgcolor="#FFFFFF" class="formfield">
                                      <select name="department" id="department" class="gen" style="width:270px" multiple size="4">
                                       <option value="0" >All</option>
                                        <%      pst = conn.prepareStatement("SELECT DepartmentID,DepartmentName FROM departmentmaster");
                                                rs=pst.executeQuery();
                                                while(rs.next()){
                                                %>
                                                <option value="<%=rs.getInt(1) %>"><%=rs.getString(2) %></option>
                                                <%
                                                }rs.close(); 
                                                pst.close();
                                         %>
                                      </select>

                                   </td>
                            </tr>
                        </table>
                    </td>
                </tr>
		<tr>
                    <td colspan="4" class="wid100">
                        <table width="100%" border="0" cellspacing="0" cellpadding="4">	    
                            <tr>
                                <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Roles") %></td>
                                <td width="30%" bgcolor="#FFFFFF" class="formfield topPaddingZero">
                                  <select name="roles" id="roles" class="gen" style="width:270px;display:none" multiple size="4" defaultText="All">
                                   <option value="0" >All</option>
                                   </select>

                                </td>
                                  <td align="right" bgcolor="#FFFFFF" width="10%" class="formtext topMargin8"><%= i18n.tr("Users") %></td>
                                   <td width="40%" bgcolor="#FFFFFF" class="formfield topPaddingZero">
                                       <select id='users' name='users' class="userDropDownMultiSelect" multiple data-isMandatory='1' style="width: 270px;" defaultText="<%= i18n.tr("All")%>">
                                           <option value="0"><%= i18n.tr("All")%></option>
                                      </select>

                                   </td>
                            </tr>
                        </table>
                    </td>
                </tr>
               <table id ="noteMsgId"  width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr align="center">
                              <td colspan="1" bgcolor="#FFFFFF" class="domains" align="center">
                        <td width="100%" height="35" bgcolor="#FFFFFF" class="formfield generalNote">
                          <img src='Note.gif' />  <%= i18n.tr("Note that the individual selections of Location, Department, Role and Users would create a union of recipients to whom the notification/mail will be sent. For example if you have selected a Location and two users within that Location, the notification will still go to all users in that Location. Hence care should be taken while making the selections to avoid the notification going out to the entire organization. If you need any further clarification please contact Support team") %>
                        </td>
                      </tr>                             
                    </td>                                      
                </tr>                                      
                <tr>
                          
                              <td colspan="2" class="formfield floatRightAsset" width="20%" align="right">
                                 <input  type='button'   class='addbuttons greenBtn'  value='Add&nbsp;&nbsp;Rule' onClick='addRule()' />
                               </td>
                          
                      </tr>
                      <tr>
                         <td class="wid100" colspan="2">
                           <table width="100%">
                             <tr  class="disk">
                               <td width="10%" align="center"><%= i18n.tr("Delete") %></td>
                               <td width="20%" align="center"><%= i18n.tr("Location")%>(s)</td>
                               <td width="20%" align="center"><%= i18n.tr("Department")%>(s)</td>
                               <td width="20%" align="center"><%= i18n.tr("Role") %>(s)</td>
                               <td width="30%" align="center"><%= i18n.tr("User")%>(s)</td>
                             </tr>
                           </table>
                         </td>
                       </tr>
                      <tr class="noTopMargin">
                         <td colspan="2" class="wid100">
                           <div id="dynamicRow_Rule">
                           </div>
                           <input type="hidden" id="ruleCount" name="ruleCount" value="0" >
                         </td>
		       </tr>
                      <tr>
                          <td colspan="2">
                              &nbsp;
                          </td>
                      </tr>
                                      
                <tr>                        
		   <td  colspan="4" align="left"  class="copyhdr">
                       <a href='javascript:void(0)'  onclick="showhidepane(1)"><img src='icon_minus.gif' border='0' name="SurveyTemplatePlusMinusImg" id="SurveyTemplatePlusMinusImg" /></a></a>&nbsp;&nbsp;<%= i18n.tr("Survey Template")%>                    
		   </td>
		</tr>
                <tr class="hiddenDisplay">
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                      <td colspan="4" class="wid100">
                          <div id="SurveyTemplateDiv">
                              <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                  <tr>
                                      <td colspan="3">
                                          <a class="addbuttons noBg add" href="javascript:void(0)" onclick="setTitle()" >Add Title</a>&nbsp;&nbsp;<a class="addbuttons noBg add" href="javascript:void(0)" onclick="setQuestion()" >Add Question</a>
                                      </td>
                                  </tr>
                                  <tr class="hiddenDisplay">
                                      <td>
                                          &nbsp;
                                      </td>
                                  </tr>
                                  <tr>
                                      <td width="5%">&nbsp;</td>
                                      <td class="wid100">
                                          <div id="SurveyTempalteDetailsDiv" >
                                              
                                          </div>
                                          <input type="hidden" value="0" id="layoutCount" name="layoutCount">
                                          <input type="hidden" value="0" id="titleCount" name="titleCount">    
                                      </td>
                                      <td width="5%">&nbsp;</td>
                                  </tr>
                              </table>
                          </div>
                      </td>
                </tr>
		<tr>                        
		   <td  colspan="4" align="left"  class="copyhdr">
		    <a href='javascript:void(0)'  onclick="showhidepane(2)"><img src='icon_minus.gif' border='0' name="MailConfigurationPlusMinusImg" id="MailConfigurationPlusMinusImg" /></a></a>&nbsp;&nbsp;<%= i18n.tr("Mail Configuration")%>               
		   </td>
		</tr>
                  <tr>
                      <td colspan="4" class="wid100">
                          <div id="MailConfigurationDiv">
                                <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                    <tr>
                                        <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Send Mail") %></td>
                                        <td width="80%" bgcolor="#FFFFFF" class="formfield">
                                          <input type="checkbox" name="sendmail" id="sendmail" value="1" onclick="sendMailOption();"/>
											<label class="customRadCheck" for="sendmail"><span><span></span></span></label>
                                            <div id="ccManagerDIV" style="display : none">
                                                <font class="domains" >&nbsp;&nbsp;CC <%= i18n.tr("Manager")%></font>
                                            <input type="checkbox" name="ccManager" id="ccManager" value="1" />
											<label class="customRadCheck" for="ccManager"><span><span></span></span></label>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr id="macroBlock" style="display : none">
                                        <td width="16%" align="right" class="formtext">Macro List</td>
                                        <td width="84%" height="35" class="formfield wid100">
                                            <select id="macroList" name="macroList" style="margin-right: 10px;width: 200px;">
                                                <option value="0"><%= i18n.tr("--choose--")%></option>
                                                <option value="MACRO_SURVEYUSER"><%= i18n.tr("User")%> ID</option>
                                                <option value="MACRO_USER_FULLNAME"><%= i18n.tr("Full name")%></option>
                                                <option value="MACRO_SURVEYTITLE"><%= i18n.tr("Title") %></option>
                                                <option value="MACRO_SURVEYENDTIME"><%= i18n.tr("End time")%></option>                                                            
                                            </select><input  type="button"  name="addMacro" id="addMacro" onClick="addMacroToEditor()" value="Add Macro"  class="addbuttons greenBtn floatRightAsset" />
                                        </td>
                                    </tr>
                                <tr id="templateDesignBlock" style="display : none" height="auto">
                                    <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext">Select Template Design</td>
                                    <td width="40%" bgcolor="#FFFFFF" class="formfield templateDesignSurvey">
                                        <select class="templateDesign marginTop5" id="templateDesign" name="templateDesign">
                                        </select>
                                        <a class="previewTemplate" title="Preview"></a>
                                    </td>
                                </tr>
                                    <tr id="mailTemplateDiv" style="display : none">
                                        <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Mail Template")%></td>
                                        <td width="30%" bgcolor="#FFFFFF" class="formfield">
                                           <div id="ckeditorDiv">
                                                <textarea class='gen' cols="120" rows="8" id="emailTemplate" name="emailTemplate"></textarea>
                                                <script type="text/javascript">
                                                                var editor;
                                                                function replaceTextarea( textarea )
                                                                {
                                                                    if ( editor )
                                                                        editor.destroy();

                                                                    editor = CKEDITOR.replace( textarea,
                                                                    {
                                                                        enterMode		: Number( 2 ),
                                                                        height                  : 200,
                                                                        width                   : 700


                                                                    });
                                                                }
                                                                replaceTextarea('emailTemplate');
                                                   </script>
                                            </div> 
                                        </td>
                                    </tr>
                                    <tr id="preNotificationOneDiv">
                                         <td width="20%" align="right" bgcolor="#FFFFFF" class="formtext"><%= i18n.tr("Pre Notification Level 1")%></td>
                                         <td width="80%" align="left" bgcolor="#FFFFFF" class="formfield">
                                             <input type="checkbox" id="preNotificationOne" name="preNotificationOne" value="1" onclick="displayNotificationLevelOne()" />                                         
												<label class="customRadCheck" for="preNotificationOne"><span><span></span></span></label>
                                         </td>
                                     </tr>
                                     <tr id="levelOneInterval" style="display:none">
                                        <td width="20%" align="right" bgcolor="#FFFFFF" class="formtext"><%= i18n.tr("Notify before")%> <font color="red">*</font></td>
                                        <td width="80%" align="left" bgcolor="#FFFFFF" class="formfield">
                                            <input type="text" id="levelOneIntervalDays" name="levelOneIntervalDays" value="" class="gen wid70px" size="3"/>&nbsp;&nbsp;<span class="notifyLabel">Days</span>&nbsp;&nbsp;
                                            <select id="levelOneIntervalHours" name="levelOneIntervalHours" class="mcopy" style="width:45px">
                                            <%
                                            for(int i=0;i<=23;i++){%>
                                                <option value="<%=i%>"><%=i%></option>
                                            <%}%>
                                            </select>&nbsp;&nbsp;<span class="notifyLabel">Hours</span>&nbsp;&nbsp;
                                            <select id="levelOneIntervalMins" name="levelOneIntervalMins" class="mcopy" style="width:45px">
                                                <%
                                                for(int i=0;i<60;i=i+5){%>
                                                        <option value="<%=i%>"><%=i%></option>
                                                    <%}%>
                                            </select>&nbsp;&nbsp;<span class="notifyLabel">Mins</span>&nbsp;&nbsp;
                                        </td>
                                    </tr>
                                     <tr id="preNotificationTwoDiv">
                                         <td width="20%" align="right" bgcolor="#FFFFFF" class="formtext"><%= i18n.tr("Pre Notification Level 2")%></td>
                                         <td width="80%" align="left" bgcolor="#FFFFFF" class="formfield">
                                             <input type="checkbox" id="preNotificationTwo" name="preNotificationTwo" value="1" onclick="displayNotificationLevelTwo()" />                                         
												<label class="customRadCheck" for="preNotificationTwo"><span><span></span></span></label>
                                         </td>
                                     </tr>
                                     <tr id="levelTwoInterval" style="display:none">
                                                      <td width="20%" align="right" bgcolor="#FFFFFF" class="formtext"><%= i18n.tr("Notify before")%> <font color="red">*</font></td>
                                                      <td width="80%" align="left" bgcolor="#FFFFFF" class="formfield">
                                                          <input type="text" id="levelTwoIntervalDays" name="levelTwoIntervalDays" value="" class="gen wid70px" size="3"/>&nbsp;&nbsp;<span class="notifyLabel">Days</span>&nbsp;&nbsp;
                                                         <select id="levelTwoIntervalHours" name="levelTwoIntervalHours" class="mcopy" style="width:45px">
                                                            <%
                                                            for(int i=0;i<=23;i++){%>
                                                                    <option value="<%=i%>"><%=i%></option>
                                                                <%}%>
                                                        </select>&nbsp;&nbsp;<span class="notifyLabel">Hours</span>&nbsp;&nbsp;
                                                        <select id="levelTwoIntervalMins" name="levelTwoIntervalMins" class="mcopy" style="width:45px">
                                                            <%
                                                            for(int i=0;i<60;i=i+5){%>
                                                                    <option value="<%=i%>"><%=i%></option>
                                                                <%}%>
                                                        </select>&nbsp;&nbsp;<span class="notifyLabel">Mins</span>&nbsp;&nbsp;
                                                      </td>
                                   </tr>
                            </table>
                          </div>
                      </td>
                  </tr>                    
                  <tr>
                     <td colspan="4" class="wid100">
                         <div id="AckMailConfigurationDiv">
                              <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                    <tr>
                                        <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Acknowledgement Mail") %></td>
                                        <td width="80%" bgcolor="#FFFFFF" class="formfield">
                                          <input type="checkbox" name="acksendmail" id="acksendmail" value="1" onclick="ackMailOption();"/>
										  <label class="customRadCheck" for="acksendmail"><span><span></span></span></label>
                                        </td>
                                    </tr>
                                   <tr id="ackmailTemplateDiv" style="display : none">
                                        <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Mail Template") %></td>
                                        <td width="30%" bgcolor="#FFFFFF" class="formfield">
                                            <div id="ackckeditorDiv">
                                            <textarea class='gen' cols="120" rows="8" id="ackemailTemplate" name="ackemailTemplate"></textarea> 
                                             <script type="text/javascript">
                                                                var ackeditor;
                                                                function replaceTextarea( textarea )
                                                                {
                                                                    if ( ackeditor )
                                                                        ackeditor.destroy();

                                                                    ackeditor = CKEDITOR.replace( textarea,
                                                                    {
                                                                        enterMode		: Number( 2 ),
                                                                        height                  : 200,
                                                                        width                   : 700


                                                                    });
                                                                }
                                                                replaceTextarea('ackemailTemplate');
                                                   </script>
                                            </div>
                                        </td>
                                   </tr>                                  
                              </table>
                         </div> 
                     </td>
                  </tr>
                    <tr class="hiddenDisplay"><td colspan="2">&nbsp;</td></tr>
                    <tr id="hookHeaderDiv" style="display:none">                        
                        <td  colspan="4" align="left"  class="copyhdr">
                            <a href='javascript:void(0)'  onclick="showhidepane(3)"><img src='icon_minus.gif' border='0' name="hookPlusMinusImg" id="hookPlusMinusImg" /></a></a>&nbsp;&nbsp;Actions/Hook               
                        </td>
                    </tr>
                    <tr>
                     <td colspan="4" class="wid100">
                         <div id="actionsHookDiv">
                             <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                 <tr>
                                     <td colspan="4" class="wid100">
                                         <div id="hookConfigurationDiv" style="display:none"> 
                                             <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                                 <tr>
                                                     <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext">Hook Type</td>
                                                     <td width="10%" height="35" bgcolor="#FFFFFF" class="formfield">
                                                         <input type="radio" id="procedureId" name="pcrocedure" onclick="isProcedureOrCustomclasschecked(this);"/>
														 <label class="customRadCheck" for="procedureId"><span><span></span></span></label><span class="notifyLabel">Procedure</span>
                                                     </td>
                                                     <td width="70%" height="35" bgcolor="#FFFFFF" class="formfield">
                                                         <input type="radio" id="customClassId" name="customClass" onclick="isProcedureOrCustomclasschecked(this);"/>
														 <label class="customRadCheck" for="customClassId"><span><span></span></span></label><span class="notifyLabel">Custom Class(java class)</span>
                                                     </td>
                                                     <input type="hidden" id="isProcedureOrCustomClass" name="isProcedureOrCustomClass" value="" />
                                                 </tr>
                                             </table>
                                         </div>
                                     </td>
                                 </tr>
                                 <tr>
                                     <td colspan="4">
                                         <div id="procedureNameDiv" style="display:none">
                                             <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                                 <tr>
                                                     <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext">Procedure Name<font color="red">*</font></td>
                                                     <td width="80%" bgcolor="#FFFFFF" class="formfield">
                                                         <input type="text" id="procedureName" name="procedureName" class="mcopy" size="40" value="" />
                                                     </td>
                                                 </tr>
                                             </table>
                                         </div>
                                     </td>
                                 </tr>
                                 <tr>
                                     <td colspan="4">
                                         <div id="customClassNameDiv" style="display:none"> 
                                             <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                                 <tr>
                                                     <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext">Custom Class Name<font color="red">*</font></td>
                                                     <td width="25%" bgcolor="#FFFFFF" class="formfield">
                                                         <input type="text" id="customClassName" name="customClassName" class="mcopy" size="40" value="" />
                                                         <span class="hotspot visibleOnlyinNewUI" onmouseover=" tooltip.show('Note:Please provide fully qualified class name Ex: sapphire.servicedesk.utils.DummyFeedbackClass')" onmouseout="tooltip.hide();" style="display:none;"><img src="assets/images/question.png" style="margin: 3px 5px;"></span>
                                                     </td>
                                                     <td class="formfield hiddenDisplay" colspan="2" align="left">
                                                         <img src="Note.gif"><font size="1">Note:Please provide fully qualified class name Ex: sapphire.servicedesk.utils.DummyFeedbackClass</font></img>9
                                                     </td>
                                                 </tr>
                                             </table>
                                         </div>
                                     </td>
                                 </tr>
                             </table>
                         </div>
                     </td>
                    </tr>                   
                      
		   
			   <tr align="center"class="basicButtonFooter">                        
			      <td colspan="2" bgcolor="#FFFFFF" class="domains" align="center">		  
			
			          <br class="hiddenDisplay">  <input  type="button"  onClick="javascript:validatePage()" value="Save"  class="addbuttons greenBtn" />
			            <input  type="button"  onclick="back()" value="Cancel"  class="addbuttons" />

			      </td>
			    
			    </tr>
			 </table>
			 <%
			 	}
	             catch(Exception e){
	      
			          	logger.error("Survey_Add.jsp ::"+ e.getMessage());
						StackTraceElement[] stackTrace = null;
						stackTrace = e.getStackTrace();
						for (int i = 0; i < stackTrace.length; i++) {
						logger.error("---- "+ stackTrace[i].toString());
						}

			      
			       	 }
			      finally {

                                     try{ if (pst != null) 
                                     {
                                          pst.close();
                                     }

                                      if (conn != null) 
                                      {
                                          
                                          conn.close();
                                      }

                                  }
                                  catch(Exception e1)
                                  {
                                        logger.error("In finally catch of Survey_Add.jsp ::" + e1.getMessage());
                                        StackTraceElement[] stackTrace = null;
                                        stackTrace = e1.getStackTrace();
                                        for (int i = 0; i < stackTrace.length; i++) 
                                        {
                                            logger.error("---- " + stackTrace[i].toString());
                                        }

                                 }
                                                           }
			  %>
                            </div></div></div>
                          </td>
         </tr>
           </table>
               <div class="widgetFooter"></div>               
         
           </td>
         </tr> 
    </table>
  </td>
 </tr>

		
   </table>
   </td>
  </tr>

      </table>
    </td>
  </tr>
</table>
        

        
          
           </table> 
           </td>
           </tr>
     <tr>
      <td width="8" valign="top"><img class="hiddenDisplay" src="spacer.gif" width="8" height="1">
      </td>
     </tr>              
      </table>
      </td>
        </tr>
        </tr>
      </table>
   
</div>
<%if(session.getAttribute("SERVICEDESK_NEWUI_PAGE")==null){%> 
<script type="text/javascript" src="assets/js/jquery.min.js" ></script>
<%}%>
<script type="text/javascript" src="${ContextPath}/assets/js/userSelectDropdownJqueryConflict.js"/></script>
<script type="text/javascript" src="assets/js/i18n/messages_${LANGUAGE_UNICODE}.js"></script>
<script type="text/javascript" src="assets/js/i18n/i18n.js"></script>
<link rel="stylesheet" type="text/css" href="assets/css/multiple-select.min.css" />
<link rel="stylesheet" type="text/css" href="assets/css/multiple-select-classic.css" />
<script type="text/javascript" src="assets/js/multiple-select.min.js"></script>
<script type="text/javascript">
    $j = jQuery.noConflict();
    $j('#location').multipleSelect({filter: true,selectAll: false});
    $j('#department').multipleSelect({filter: true,selectAll: false});
    loadRolesDropdownList('${ContextPath}','roles',0, 0, '', '');
    $j('#roles').multipleSelect({filter: true,selectAll: false});
    $j('#users').multipleSelect({filter: true,selectAll: false,onAfterCreate: function() { loadOnbehalfUser('${ContextPath}','users','', 'All', 1); } });
</script>
<%@ include file="Sapphire_Footer.jsp" %>
  </form>
</body>
</html>
</div>