<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page language="java" import="java.io.*,IMSPackage.*,java.util.Date" %>
<%@page import="org.xnap.commons.i18n.I18n"%>
<%@ include file="SapphireStdIncludes.jsp" %>
<%@ include file="AJAXPopup.jsp" %>
<%@ include file="SapphireStdCSS.jsp" %>
<%  I18n i18n = Sapphire.LANGUAGE_MAP.get((String) session.getAttribute("LANGUAGE_UNICODE"));
    String messageIn ="",messageIn1 ="";
%>
<jsp:include page="SapphireStdJs.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>
<%String telantName2= (String)session.getAttribute("TELANTNAME");
if(new Sapphire().checkModuleAccess((String)session.getAttribute("login"),"Settings",telantName2) == 0){
    response.setDateHeader ("Expires", 0);

%>
<jsp:forward page="login_page.htm"></jsp:forward>
<%} %>

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
        <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script language="JavaScript" type="text/JavaScript">

var count=0; 
var istemplateUpdated = 0;
function validatePage()
{
    var UpdateButton = document.querySelector('input[value="Update"]');
    UpdateButton.disabled = true;
       document.AJAX.surveyName.value=document.AJAX.surveyName.value.trim();
        if(document.AJAX.surveyName.value=="")
        {
            alert("Enter the survey name ");
            UpdateButton.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 ');
            UpdateButton.disabled = false;
            return;
        }        
        if( document.getElementById("surveyData").checked == false && document.getElementById("feedbackData") == false ){
            alert(" Please select Survey type ");
            UpdateButton.disabled = false;
            return
        }
        if( document.getElementById("isSurveyOrFeedback").value == 0 ){
            if(document.AJAX.starttime.value.trim()==""){
                alert("Enter the start time");
                UpdateButton.disabled = false;
                document.AJAX.starttime.value==""
                return;         
            }
            if(document.AJAX.endtime.value.trim()==""){
                alert("Enter the end time");
                UpdateButton.disabled = false;
                document.AJAX.starttime.value==""
                return;         
            } 
            if(!(checkDateTime(document.AJAX.starttime.value))){
                UpdateButton.disabled = false;
                return;
            }
            if(!(checkDateTime(document.AJAX.endtime.value))){
                UpdateButton.disabled = false;
                return;
            }
            var isValidTimeDiff = checkDiff(document.AJAX.starttime.value,document.AJAX.endtime.value); 
            if(isValidTimeDiff==false){
                UpdateButton.disabled = false;
                return;
            }

            <% messageIn = i18n.tr("Date");%>
                var isValidTimeDiff1 = CurrentDateValidation(document.AJAX.starttime.value.trim(),'<%= messageIn%>'); 
                if(isValidTimeDiff1==false){
                    UpdateButton.disabled = false;
                     document.AJAX.starttime.focus();
                      return;
                }

        } else {
            if( document.getElementById("feedbackImageName").value === '' ){
                alert("Please upload image");
                UpdateButton.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");
                    UpdateButton.disabled = false;
                    document.getElementById("procedureName").focus();
                    return;
                }
            }else if( isCustomClassChecked.checked ){
                if( document.getElementById("customClassName").value == '' ){
                    alert("Please provide custom class name");
                    UpdateButton.disabled = false;
                    document.getElementById("customClassName").focus();
                    return;
                }
            }
        }
        var commentSize ='<%=application.getAttribute((String)session.getAttribute("TELANTNAME")+"_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");
            UpdateButton.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");
               UpdateButton.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");
                   UpdateButton.disabled = false;
                   document.getElementById("levelOneIntervalDays").focus();
                   return;
               }
               if(document.getElementById("levelOneIntervalDays").value < 0){
                   alert("Please enter interval day as greater than zero");
                   UpdateButton.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");
                   UpdateButton.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");
               UpdateButton.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");
                   UpdateButton.disabled = false;
                   document.getElementById("levelTwoIntervalDays").focus();
                   return;
               }
               if(document.getElementById("levelTwoIntervalDays").value < 0 ){
                   alert("Please enter interval day as greater than zero");
                   UpdateButton.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");
                   UpdateButton.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');
                            UpdateButton.disabled = false;
                            return;
                        }

                    }
                }
		   /* var selectedLoc=0;
		    var selectedDept=0;
		    var selectedRole=0;
		    var selectedUser=0;
		    var loc=document.AJAX.location;
		   	var dept=document.AJAX.department;
		    var roles=document.AJAX.roles;
		    var users=document.AJAX.users;
		    
		    for(var i=0;i<loc.length;i++){
		    	if(loc[i].selected){
		    		selectedLoc=1;
		    		break;
		    	}
		    }
		    for(var i=0;i<dept.length;i++){
		    	if(dept[i].selected){
		    		selectedDept=1;
		    		break;
		    	}
		    }
		    for(var i=0;i<roles.length;i++){
		    	if(roles[i].selected){
		    		selectedRole=1;
		    		break;
		    	}
		    }
		    for(var i=0;i<users.length;i++){
		    	if(users[i].selected){
		    		selectedUser=1;
		    		break;
		    	}
		    }
		    
		    if((selectedLoc==0) && (selectedDept==0) && (selectedRole==0) && (selectedUser==0)){
		    	alert("Please select any one of the Location,Department,Roles or Users ");
		    	document.AJAX.location.focus();
		    	return;
		    }*/
        if(document.getElementById("ruleCount").value == 0){
                        alert('Please select atleast one rule');
                        UpdateButton.disabled = false;
                        return;
                    }
		    
		                   
           if( document.AJAX.count.value==0)
               {
               alert("Please enter atleast one question");
               UpdateButton.disabled = false;
               document.AJAX.question.focus();
		        return;
               }
            if(istemplateUpdated == 1){
               var confirmFlag = confirm("Editing question from active survey will impact on user participated survey(s), Do you really want to reconfigure?");            
                if(confirmFlag == false){
                    UpdateButton.disabled = false;
                    return;
                }
            }
        if(document.getElementById('delete_feedbackIcon')!=null && document.getElementById('delete_feedbackIcon')!=undefined){  
        if(document.getElementById('delete_feedbackIcon').value == 1 || 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("delete_feedbackIcon");
                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;
                console.log(i);
                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";
     popUpPage(url,779,350,'&nbsp;');
 }
 function updateQuestion(questName,htmlType,questId){
  var url="SurveyDetails.jsp?questName="+questName+"&htmlType="+htmlType+"&questId="+questId+"&isEdit=yes&surveyType="+document.getElementById("isSurveyOrFeedback").value+"&isNewUIPopupAvailable=yes";
 
     popUpPage(url,779,200,'&nbsp;');
  }
  function updateTitle(questName,questId){
     var url="SurveyDetails.jsp?IsTitle=yes&questName="+questName+"&questId="+questId+"&isEdit=yes&isNewUIPopupAvailable=yes";
     popUpPage(url,779,200,'&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\" width=\"12\" height=\"12\" class=\"deleteRule\"></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>";	  	
	  
	   var count=parseInt(document.AJAX.count.value);
           count++;
           document.AJAX.count.value=count;
	  ni.appendChild(newdiv);
          istemplateUpdated = 1;
 }
 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 ){
            if( document.getElementById("emailTemplate").value == '' ){                
                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{
            if( document.getElementById("emailTemplate").value == '' ){                
                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 ){
            if( document.getElementById("ackemailTemplate").value == '' ){                
                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{
            if( document.getElementById("ackemailTemplate").value == '' ){                
                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 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 count=parseInt(document.AJAX.count.value);
 count++;
 document.AJAX.count.value=count;
 
 
  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 align=\"center\" width=\"60%\" class=\"gen\"><input type=\"hidden\" name=\"questions\" id=\"questions\" value=\""+questionValue+"\">"+document.AJAX.question.value+"</td><td width=\"20%\"></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 align=\"center\" width=\"60%\" class=\"gen\"><input type=\"hidden\" name=\"questions\" id=\"questions\" value=\""+titleValue+"\"><b>"+document.AJAX.title.value+"</b></td><td width=\"20%\"></td><tr></table>";
 }
 
  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,questionID)
{
 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){
    var count=parseInt(document.AJAX.count.value);
    count--;
    document.AJAX.count.value=count;
 }
 var temp = questionID;
 if(temp =!undefined){
     var question = document.getElementById("deleteQuestion");
    if(question.value != "0"){
        question.value = question.value+","+questionID;
    }else{
        question.value = questionID;
    }
 }
 d.removeChild(olddiv);

}

function removeEvent1(divNum,deletedquestionid)
{
var count=parseInt(document.AJAX.count.value);
 count--;
 document.AJAX.count.value=count;
 var d = document.getElementById('dynamicRow');
 var olddiv = document.getElementById(divNum);
 var num=document.getElementById("rowCount").value;
 num=num-1;
 document.getElementById("rowCount").value=num;
 
  document.getElementById("delete_div").innerHTML=document.getElementById("delete_div").innerHTML+"<input type='hidden' value='"+deletedquestionid+"' id='deletedquestionid' name='deletedquestionid'>"
 
 d.removeChild(olddiv);

}

		
function Preview()
{
	var url="SurveyPreview.jsp?SurveyID="+document.AJAX.SurveyID.value;
       popUpPage(url,779,350,'Survey Preview');			
}

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 editQuestion(surveyID,quesID,title){
	var url="SurveyQuestion_Edit.jsp?surveyID="+surveyID+"&questionID="+quesID;
	popUpPage(url,779,330,title);	
}
function enableQuesBlock(){
	document.getElementById("question").disabled=false;
	document.getElementById("addTitle").disabled=false;
	document.getElementById("addbutton").disabled=false;
	
}
function reloadPage(){

	window.location.reload();
}
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,detailsID){

    var  deletedRules = document.getElementById('deleted_rules').value;
    if(detailsID != undefined){
        if(deletedRules == ""){
            deletedRules=detailsID;
        }
        else{
            deletedRules=deletedRules+" , "+detailsID;
        }
     }
    
    document.getElementById('deleted_rules').value= deletedRules;    

    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(){
        isSurveyChecked = document.getElementById("surveyData");
        if( isSurveyChecked.checked ){
            document.getElementById("surveyTimeConstraintDiv").style.display = "";
            document.getElementById("preNotificationOneDiv").style.display = "";
            document.getElementById("preNotificationTwoDiv").style.display = "";
            document.getElementById("feedbackImageUploadDiv").style.display = "none";
            document.getElementById("isSurveyOrFeedback").value = 0;            
        }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("isSurveyOrFeedback").value = 1;            
        }
    }
    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){
            if(document.getElementById('filenames_forward')!=null && document.getElementById('filenames_forward')!=undefined)
                var path =  document.getElementById('uniqueString_forward').value + "_"+ document.getElementById('filenames_forward').value;
            else
                var path =  row.closest('#uniqueString').value + "_"+ row.closest('#filenames').value;
             var input = document.createElement('input');
            input.type = "hidden";
            input.id = "pathForDeleteAttachement";
            input.value= path;
              row.closest('td').appendChild(input);
             var input1 = document.createElement('input');
            input1.type = "hidden";
            input1.id = "attachmentType";
            input1.value = "6";
              row.closest('td').appendChild(input1);
            var input2 = document.createElement('input');
            input2.type = "hidden";
            input2.id = "delete_feedbackIcon";
            input2.value = "1";
          
            row.closest('td').appendChild(input2);
            document.getElementById('feedbackImageAttachTable').rows[1].style.display = "none";
           
            document.getElementById("feedbackImageUpload").style.display="";
            document.getElementById("imgTab").style.display="";
            document.getElementById("feedbackImageName").value = "";
        }
   }
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 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('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="";  
      }
  	window.location.href="SurveyList.jsp?isNewUIAvailable=yes";
}
    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>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="sendMailOption();ackMailOption();">


  <form  name="AJAX" method="post" action="Survey?Update=true" >
<security:csrfInput/>
<%@ include file="toptable.jsp" %>

<div id="mainContentArea1">
<table width="100%" height="70%" border="0" align-"center" cellpadding="0" cellspacing="0">

            <tr>
			
                      <td valign="top" align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top">

    <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>
			        <table width="140" border="0" cellspacing="0" cellpadding="0">
			            <tr>
				     	 <td>
                                             <ul><li class="selected"><a href="#" style="white-space:nowrap;">
                                           <%= i18n.tr("User Surveys") %>
                                             </a><span></span></li></ul>
				     	 </td>
                        </tr>
					   </table>
					  </td>
					 </tr>
			
            </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 valign="top" > 
                       <div class="contentBlock noMargin"> 
                        <div class="widgetOuterWrapper"> 
                        <div class="widgetInnerWrapper"> 

   <table width="100%" border="0" cellspacing="0" cellpadding="0">	
    <%
		int SurveyID=0;
                String telantName= (String)session.getAttribute("TELANTNAME");
		connection myConn = null;
		Connection conn   = null;
		PreparedStatement pst    = null,pst1   = null;
		ResultSet rs      = null,rs1      = null;	
		String starttime="",endtime="";	
		DateFormat dateformate=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String current_dbTime="";
		SurveyID=Integer.parseInt(request.getParameter("SurveyID"));
		String locations="";
		String departments="";
		String roles="";
		String users="";
                String email_Template="";
                int ccManager = 0 ;
                String displayLevelOne = "none";
                String displayLevelTwo = "none";
                String levelOneCheck = "";
                String levelTwoCheck = "";
                String levelOneIntervalDays="";
                String levelOneIntervalHours="0";
                String levelOneIntervalMins="0";
                String levelTwoIntervalDays="";
                String levelTwoIntervalHours="0";
                String levelTwoIntervalMins="0";
                String levelOneInterval="0";
                String levelTwoInterval="0";
                String intervalOneInDays="";
                String intervalTwoInDays=""; 
                int ackmailcheckstatus=0,isSurveyOrFeedback=0,isProcedureOrCustomcalss=0;
                String ackemail_Template="",imagePath="",showTimeConstraints="none",showFeedbackImage="none",isProcedureNameOrCustomcalssName="";
                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();	
                    int mailcheckstatus=0;
                    pst1 = conn.prepareStatement("SELECT SurveyName, CreationTime, ClosedTime,SendMail,EmailTemplate,CCManager,PreNotificationOneInterval,PreNotificationTwoInterval,SurveyDescription,AcknowledgementMail,AcknowledgementMailTemplate,surveyType,Image,isProcedureOrCustomClass,isProcedureNameOrClassName,HtmlTemplateId FROM survey_master where SurveyID =?");
                    pst1.setInt(1, SurveyID);
                    rs1=pst1.executeQuery();			
                    while(rs1.next()){
                        Object objstarttime=(Object)rs1.getTimestamp(2);
                        Object objendtime=(Object)rs1.getTimestamp(3);
                        isSurveyOrFeedback = rs1.getInt(12);
                        if( isSurveyOrFeedback == 0 ){
                            starttime=dateformate.format(objstarttime); 
                            endtime=dateformate.format(objendtime);
                        }
                        mailcheckstatus=rs1.getInt("SendMail");
                        email_Template=rs1.getString(5);
                        ccManager = rs1.getInt(6);
                        levelOneInterval = rs1.getString(7);
                        levelTwoInterval = rs1.getString(8); 
                        ackmailcheckstatus=rs1.getInt(10); 
                        ackemail_Template=rs1.getString(11);
                        imagePath = rs1.getString(13);
                        isProcedureOrCustomcalss = rs1.getInt(14);                            
                        isProcedureNameOrCustomcalssName = rs1.getString(15);
                        request.setAttribute("templateDesignId", rs1.getInt("HtmlTemplateId"));
			%>  	    
   	  
               <tr>
			     <td align="right" bgcolor="#FFFFFF" width="20%" class="formtext"><%= i18n.tr("Survey Name")%>
			     </td>
			     <td width="100%" height="35" bgcolor="#FFFFFF" class="formfield"> 
			     <input type="text" id="surveyName" name="surveyName"  size="40"  value="<%=rs1.getString(1)%>"  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"><%=rs1.getString(9)%></textarea>
                     </td>
                 </tr>
               <%}
              rs1.close(); 
              pst1.close();
              GetConfigurationData configObj = new GetConfigurationData();
               if(!levelOneInterval.equals("0")){
                     displayLevelOne = "";
                     levelOneCheck = "checked";
                }
                if(!levelTwoInterval.equals("0")){
                      displayLevelTwo  = "";
                      levelTwoCheck = "checked";
                }
               if((!levelOneInterval.trim().equals("0")) && (!levelOneInterval.trim().equals(""))){                                        
                    intervalOneInDays=configObj.getIntervalDays(Long.parseLong(levelOneInterval));
                }

                if((!levelTwoInterval.trim().equalsIgnoreCase("0")) && (!levelTwoInterval.trim().equalsIgnoreCase(""))){                                      
                    intervalTwoInDays=configObj.getIntervalDays(Long.parseLong(levelTwoInterval));
                }
              if(!intervalOneInDays.trim().equalsIgnoreCase("")){
                    String intervalArr[]=intervalOneInDays.split(",");                    
                    levelOneIntervalDays=intervalArr[0];
                    levelOneIntervalHours=intervalArr[1];
                    levelOneIntervalMins=intervalArr[2];                    
                }
                if(!intervalTwoInDays.trim().equalsIgnoreCase("")){
                    String intervalArr[]=intervalTwoInDays.split(",");
                    levelTwoIntervalDays=intervalArr[0];
                    levelTwoIntervalHours=intervalArr[1];
                    levelTwoIntervalMins=intervalArr[2];                    
                }
              if(levelOneIntervalDays.trim().equals("0")){
                    levelOneIntervalDays = "";
                    
                }
                if(levelTwoIntervalDays.trim().equals("0")){
                    levelTwoIntervalDays   = "";
                }
                if( isSurveyOrFeedback == 0 ){
                    showTimeConstraints = "";
                }else{
                    showFeedbackImage = "";
                }                
              %>
              <!-- Feedback 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")%></td>
                                <td width="5%" height="35" bgcolor="#FFFFFF" class="formfield">
                                    <% if( isSurveyOrFeedback == 0 ){ %>
                                    <input type="radio" id="surveyData" name="surveyType" onclick="showSurveyTimeConstraint();" checked="checked" disabled />
									<label class="customRadCheck" for="surveyData"><span><span></span></span></label><span class="notifyLabel">Survey</span>
                                    <% } else { %>
                                    <input type="radio" id="surveyData" name="surveyType" onclick="showSurveyTimeConstraint();" disabled />
									<label class="customRadCheck" for="surveyData"><span><span></span></span></label><span class="notifyLabel">Survey</span>
                                    <% } %>
                                </td>
                                <td width="75%" height="35" bgcolor="#FFFFFF" class="formfield">
                                    <% if( isSurveyOrFeedback == 1 ){ %>
                                        <input type="radio" id="feedbackData" name="surveyType" onclick="showSurveyTimeConstraint();" checked="checked" disabled />
										<label class="customRadCheck" for="feedbackData"><span><span></span></span></label><span class="notifyLabel">Feedback</span>
                                    <% } else { %>
                                        <input type="radio" id="feedbackData" name="surveyType" onclick="showSurveyTimeConstraint();" disabled />
										<label class="customRadCheck" for="feedbackData"><span><span></span></span></label><span class="notifyLabel">Feedback</span>
                                    <% } %>
                                </td>
                                <input type="hidden" id="isSurveyOrFeedback" name="isSurveyOrFeedback" value="<%= isSurveyOrFeedback %>" />
                            </tr>
                        </table>
                    </td>
                </tr>   
                <tr id="feedbackImageUploadDiv" style="display:<%= showFeedbackImage %>;">
                    <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")%></td>
                                <% if( !imagePath.isEmpty() ){ %>
                                    <td class="formfield"><img src='attachment.gif' id='imgTab'  class="icon" style='display:none' /><input  type="button"  id="feedbackImageUpload" name="feedbackImageUpload" onClick="doFileBrowse()" value="Upload Image"  class="addbuttons attachbtn" style='display:none'>
                                <% } else { %>
                                    <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">
                                <% } %>
                                
                                        <table id="feedbackImageAttachTable" class="attachedList">
                                            <tr><td></td><td></td></tr>
                                            <% 
                                                if( isSurveyOrFeedback == 1 && !imagePath.isEmpty() ){
                                                    String imageName = imagePath.substring((imagePath.lastIndexOf("_")+1),imagePath.length());                                                    
                                                    String uniqueString = imagePath.substring( 0 , (imagePath.length()-imageName.length())-1 );    
                                                    String path = uniqueString +"_" +imageName;
                                            %>
                                            <tr>
                                                <td>
                                                    <input type="hidden" value="<%= imageName %>" id="filenames_forward" name="filenames_forward" />
                                                    <input type="hidden" value="<%= uniqueString %>" id="uniqueString_forward" name="uniqueString_forward"/>
                                              <!--       <input type='hidden' name='pathForDeleteAttachement' id='pathForDeleteAttachement' value="<%=path%>">
                                                    <input type='hidden' name='attachmentType' id='attachmentType' value='6'/>
                                                    <input type='hidden' name='delete_feedbackIcon' id='delete_feedbackIcon' value='0'/>    -->
                                                        <a onclick="deleteImage(this)" class="domains" href="#"><img width="12" height="12" border="0" title="Remove attachment" src="remove.jpg"></a>&nbsp;
                                                </td>
                                                <td>
                                                    <span class="domains" style="opacity: 1;"><%= imageName %></span>&nbsp;&nbsp;&nbsp;&nbsp;
                                                </td>
                                            </tr>
                                            <input type="hidden" id="feedbackImageName" name="feedbackImageName" value="<%= imageName %>" />
                                            <%  } %>
                                        </table>
                                </td>
                                
                            </tr>
                        </table>
                    </td>
                </tr>
                <!-- Feedback Ends here -->
               <tr id="surveyTimeConstraintDiv" style="display:<%= showTimeConstraints %>;">
                    <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")%></td>
                                <td width="30%" height="35" bgcolor="#FFFFFF" class="formfield">                
                                <input class="mcopy" id="starttime" type="text" name="starttime" size="20" value="<%=starttime %>"  onfocus="showCalendarControl(this);">
                                </td>
                                <td align="right" bgcolor="#FFFFFF" width="10%" class="formtext bPadding2 topMargin10"><%= i18n.tr("End Time")%></td>
                                <td width="40%" height="35" bgcolor="#FFFFFF" class="formfield">                                                       
                                <input class="mcopy" id="endtime" type="text" name="endtime" size="20" value="<%=endtime %>"  onfocus="showCalendarControl(this);">
                                    <input type="hidden" value="<c:out value="<%=SurveyID %>"/>" id="SurveyID" name="SurveyID">
                                </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">
                                  <%
                                    if(locations.equals(","+"0"+",")){
                                            %>
                                                    <option value="0" selected>All</option>
                                            <%
                                            }else{
                                            %>
                                                    <option value="0">All</option>	      		

                                            <%
                                            }
                                            pst = conn.prepareStatement("SELECT LocationID,LocationName FROM servicedesklocationmaster");
                                            rs=pst.executeQuery();
                                            while(rs.next()){
                                            if(locations.contains(","+rs.getString(1)+",")){
                                            %>
                                                    <option value="<%=rs.getInt(1) %>" selected><%=rs.getString(2) %></option>
                                            <%
                                            }else{
                                            %>
                                                    <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">
                                  <%
                                    if(departments.equals(","+"0"+",")){
                                            %>
                                                    <option value="0" selected>All</option>
                                            <%
                                            }else{
                                            %>
                                                    <option value="0">All</option>

                                            <%
                                            }
                                            pst = conn.prepareStatement("SELECT DepartmentID,DepartmentName FROM departmentmaster");
                                            rs=pst.executeQuery();
                                            while(rs.next()){
                                            if(departments.contains(","+rs.getString(1)+",")){
                                            %>
                                                    <option value="<%=rs.getInt(1) %>" selected><%=rs.getString(2) %></option>
                                            <%
                                            }else{
                                            %>
                                                    <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 bPadding2"><%= i18n.tr("Roles")%></td>
                                    <td width="30%" bgcolor="#FFFFFF" class="formfield">
                                      <select name="roles" id="roles" class="gen" style="width:270px;display:none" multiple size="4" defaultText="All">
                                      <%
                                        if(roles.equals(","+"0"+",")){
                                                %>
                                                        <option value="0" selected>All</option>
                                                <%
                                                }else{
                                                %>
                                                        <option value="0">All</option>	      		

                                                <%
                                                }
                                                 pst = conn.prepareStatement("SELECT AccessID,AccessType FROM usermgmt_details");
                                                rs=pst.executeQuery();
                                                while(rs.next()){
                                                if(roles.contains(","+rs.getString(1)+",")){
                                                %>
                                                        <option value="<%=rs.getInt(1) %>" selected><%=rs.getString(2) %></option>
                                                <%
                                                }else{
                                                %>
                                                        <option value="<%=rs.getInt(1) %>"><%=rs.getString(2) %></option>
                                                <%
                                                }
                                                }rs.close(); 
                                                pst.close();
                                         %>
                                      </select>

                                    </td>
		   
                                    <td align="right" bgcolor="#FFFFFF" width="10%" class="formtext topMargin8 bPadding2"><%= i18n.tr("Users")%></td>
                                    <td width="40%" bgcolor="#FFFFFF" class="formfield">
                                        <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>                          
                    <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 colspan="2" class="wid100">
                           <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">
                               <%
                                            pst = conn.prepareStatement("Select DetailsID from survey_details where  SurveyID=?");
                                            pst.setInt(1, SurveyID);
                                            rs=pst.executeQuery();
                                            int ruleCount=0;
                                            int detailsID=0;
                                            
                                            while(rs.next()){
                                                
                                                ruleCount++;
                                                String locationValues="";
                                                String departmentValues="";
                                                String rolesValues="";
                                                String usersValues="";
                                                detailsID = rs.getInt(1);
                                                pst1 = conn.prepareStatement("Select ScopeValue from survey_details_lookup where ScopeID=? and DetailsID=?");
                                                pst1.setInt(1, 1);
                                                pst1.setInt(2, detailsID);
                                                rs1=pst1.executeQuery();
                                                while(rs1.next()){
                                                    if(locationValues == ""){
                                                        locationValues = rs1.getString(1);
                                                    }else{
                                                        locationValues = locationValues+" , "+rs1.getString(1);
                                                    }
                                                }
                                                rs1.close(); 
                                                pst1.setInt(1, 2);
                                                pst1.setInt(2, detailsID);
                                                rs1=pst1.executeQuery();
                                                while(rs1.next()){
                                                    if(departmentValues == ""){
                                                        departmentValues = rs1.getString(1);
                                                    }else{
                                                        departmentValues = departmentValues+" , "+rs1.getString(1);
                                                    }
                                                }
                                                rs1.close();
                                                pst1.setInt(1, 3);
                                                pst1.setInt(2, detailsID);
                                                rs1=pst1.executeQuery();
                                                while(rs1.next()){
                                                    if(rolesValues == ""){
                                                        rolesValues = rs1.getString(1);
                                                    }else{
                                                        rolesValues = rolesValues+" , "+rs1.getString(1);
                                                    }
                                                }
                                                rs1.close();
                                                pst1.setInt(1, 4);
                                                pst1.setInt(2, detailsID);
                                                rs1=pst1.executeQuery();
                                                while(rs1.next()){
                                                    if(usersValues == ""){
                                                        usersValues = rs1.getString(1);
                                                    }else{
                                                        usersValues = usersValues+" , "+rs1.getString(1);
                                                    }
                                                }
                                                rs1.close(); pst1.close();
                                                
                                                String[] locationParams = locationValues.split("\\,");
                                                String locationDisplayNames="";
                                                if(locationValues.trim().equals("0")){
                                                    locationDisplayNames="All";
                                                }
                                                else if(!locationParams[0].trim().equals("")){
                                                    for(int i=0; i<locationParams.length; i++){
                                                        pst1 = conn.prepareStatement("Select LocationName from servicedesklocationmaster where LocationID=?");
                                                        pst1.setString(1, locationParams[i]);
                                                        rs1=pst1.executeQuery();
                                                        while(rs1.next()){
                                                            if(locationDisplayNames == ""){
                                                                locationDisplayNames = rs1.getString(1);
                                                            }else{
                                                                locationDisplayNames = locationDisplayNames+"<br>"+rs1.getString(1);
                                                            }
                                                        }rs1.close();  pst1.close();
                                                    }
                                                }else{
                                                    locationDisplayNames="--";
                                                }
                                                
                                                String[] departmentParams = departmentValues.split("\\,");
                                                String departmentDisplayNames="";
                                                if(departmentValues.trim().equals("0")){
                                                    departmentDisplayNames="All";
                                                }
                                                else if(!departmentParams[0].trim().equals("")){
                                                    for(int i=0; i<departmentParams.length; i++){
                                                        pst1 = conn.prepareStatement("Select DepartmentName from departmentmaster where DepartmentID=?");
                                                        pst1.setString(1,departmentParams[i]);
                                                        rs1=pst1.executeQuery();
                                                        while(rs1.next()){
                                                            if(departmentDisplayNames == ""){
                                                                departmentDisplayNames = rs1.getString(1);
                                                            }else{
                                                                departmentDisplayNames = departmentDisplayNames+"<br>"+rs1.getString(1);
                                                            }
                                                        }rs1.close(); pst1.close();
                                                    }
                                                }else{
                                                    departmentDisplayNames="--";
                                                }
                                                
                                                String[] rolesParams = rolesValues.split("\\,");
                                                String rolesDisplayNames="";
                                                if(rolesValues.trim().equals("0")){
                                                    rolesDisplayNames="All";
                                                }
                                                else if(!rolesParams[0].trim().equals("")){
                                                    for(int i=0; i<rolesParams.length; i++){
                                                        pst1 = conn.prepareStatement("SELECT AccessType FROM usermgmt_details where AccessID=?");
                                                        pst1.setString(1,rolesParams[i]);
                                                        rs1=pst1.executeQuery();
                                                        while(rs1.next()){
                                                            if(rolesDisplayNames == ""){
                                                                rolesDisplayNames = rs1.getString(1);
                                                            }else{
                                                                rolesDisplayNames = rolesDisplayNames+"<br>"+rs1.getString(1);
                                                            }
                                                        }rs1.close();pst1.close();
                                                    }
                                                }else{
                                                    rolesDisplayNames="--";
                                                }
                                                
                                                String[] usersParams = usersValues.split("\\,");
                                                String userFullNames="";
                                                if(usersValues.trim().equals("0")){
                                                    userFullNames="All";
                                                }
                                                else if(!usersParams[0].equals("")){
                                                    for(int i=0; i<usersParams.length; i++){
                                                        if(userFullNames == ""){
                                                            userFullNames = Sapphire1.getUserFullNameAlongWithOnBehalfField(NumberUtils.toInt(usersParams[i].trim(), 0)).replace("<br>", " ");
                                                        }else{
                                                            userFullNames = userFullNames+"<br>"+Sapphire1.getUserFullNameAlongWithOnBehalfField(NumberUtils.toInt(usersParams[i].trim(), 0)).replace("<br>", " ");
                                                        }
                                                    }
                                                }else{
                                                    userFullNames="--";
                                                }
                                                
                                                String divName="Div_"+ruleCount+"_Rule";
                                                if(!locationDisplayNames.equals("--")&&!departmentDisplayNames.equals("--")&&!rolesDisplayNames.equals("--")&&userFullNames.equals("")){
                                                userFullNames="--";    
                                                }
                                                if(locationDisplayNames.equals("--")&&departmentDisplayNames.equals("--")&&rolesDisplayNames.equals("--")&&userFullNames.equals("")){
                                                    
                                                }else{
                                                %>
                                                <div id="<%=divName%>" >

                                                  <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('<%=divName%>','<%=detailsID%>')"><img border="0" src="fault_x.gif" class="deleteRule" width="12" height="12"></a>
                                                        <input type="hidden" name="existinglocation_values" id="existinglocation_values" value="<%=locationValues%> ">
                                                        <input type="hidden" name="existingdepartment_values" id="existingdepartment_values" value="<%= departmentValues%> ">
                                                        <input type="hidden" name="existingroles_values" id="existingroles_values" value="<%= rolesValues%> ">   
                                                         <input type="hidden" name="existingusers_values" id="existingusers_values" value="<%= usersValues%> ">   
                                                      </td>
                                                      <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"><%= userFullNames%></td>
                                                      
                                                    </tr>
                                                  </table>
                           </div> 
                                                      <%}} rs.close(); 
                                                      pst.close(); %>  
                                                      
                           <input type="hidden" id="ruleCount" name="ruleCount" value="<%= ruleCount %>" >
                               <input type="hidden"  id="deleted_rules" name="deleted_rules" value="">
                         </td>
		       </tr> 
                       <tr class="hiddenDisplay">
                          <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 colspan="2">
                              &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>
                                      <td>
                                          &nbsp;
                                      </td>
                                  </tr>
                                  <tr>
                                      <td width="5%">&nbsp;</td>
                                      <td class="border wid100">
                                          <div id="SurveyTempalteDetailsDiv" >
                                            <%  int questionCount = 1 ;
                                                int count1 = 0;
                                                pst = conn.prepareStatement("SELECT QuestionID, Question, HtmlType , CommentBox FROM survey_questions where SurveyID = ? and status=0 order by DisplayOrder");
                                                pst.setInt(1,SurveyID);
                                                rs=pst.executeQuery();
                                                   while(rs.next())
                                                   {
                                                       String question= rs.getString(2);
                                                       String htmlType= rs.getString(3);
                                                       String commentRequired= rs.getString(4);
                                                       count1++;
                                                       String divIdName="my"+count1+"Div";	
                                                       if(htmlType.equals("0")){
                                            %> 
                                                        <div id="<%= divIdName %>">
                                                            <table width="100%" border="0" cellspacing="2" cellpadding="1">
                                                                <tr class='mcopy'>
                                                                    <td align="left" width="90%" class="copyhdr">
                                                                        <b><%=question.replace("MACRO_TITLE$$$$","")%></b>
                                                                    </td>
                                                                    <td align="right" width="10%" class="gen posAbso">
                                                                        <a href="javascript:;" title="Delete" onclick="removeEvent('<%=divIdName%>',0,<%=rs.getString(1)%>)"><img border="0" src="fault_x.gif" class="deleteRule" width="12" height="12"></a>
                                                                        
                                                                         <a href="javascript:;" title="Edit" onclick="updateTitle('<%=rs.getString(2)%>','<%=rs.getString(1)%>')"><img border="0" src="Note.gif" width="12" height="12" class="comSprite edit"></a>
                                                                         
                                                                    </td>
                                                                 <tr>
                                                             </table>
                                                        </div>
                                                        <%}else{%>
                                                        <div id="<%= divIdName %>">
                                                            <table width="100%" border="0" cellspacing="2" cellpadding="1">
                                                                <tr class='mcopy'>
                                                                    <td align="left" width="90%" class="gen">
                                                                        <table width="100%" border="0" cellspacing="2" cellpadding="1">
                                                                            <tr> <td width="100%" class="domains"><%=questionCount%> . <%=question%></td></tr>
                                                                            <tr> <td width="100%" class="mcopy">&nbsp;&nbsp;&nbsp;&nbsp;
                                                                            <%  questionCount++;
                                                                            pst1 = conn.prepareStatement("select optionvalue from survey_options where questionid=?");
                                                                            pst1.setString(1,rs.getString(1));
                                                                            rs1=pst1.executeQuery();
                                                                           while(rs1.next())
                                                                                   {   
                                                                                        if(htmlType.equals("1")){
                                                                            %>
                                                                                        <input type="radio" id="dummy" name="dummy" value="<%=rs1.getString(1)%>" />
																						<label class="customRadCheck"><span><span></span></span></label><span class="notifyLabel"><%=rs1.getString(1)%></span>&nbsp;&nbsp;
                                                                                        <%}else{
                                                                                       
                                                                                        %>
                                                                                         
                                                                                        <input type="checkbox" id="dummy" name="dummy" value="<%=rs1.getString(1)%>" />
																						<label class="customRadCheck"><span><span></span></span></label><span class="notifyLabel"><%=rs1.getString(1)%></span>&nbsp;&nbsp;
                                                                                        <%}%>
                                                                            <%}rs1.close();pst1.close();%>
                                                                                </td>
                                                                            </tr>
                                                                            <%if(commentRequired.equals("1")){%>
                                                                            <tr><td class="domains">&nbsp;&nbsp;<%= i18n.tr("Additional Comments")%></td></tr>
                                                                            <tr><td class="gen">&nbsp;&nbsp;<textarea cols="90" rows="6" id="comment" name="comment" class="gen"></textarea></td></tr>
                                                                            <%}%>
                                                                        </table>
                                                                  </td>
                                                                  <td align="right" width="10%" class="gen">
                                                                        <a href="javascript:;" title="Delete" onclick="removeEvent('<%=divIdName%>',1,<%=rs.getString(1)%>)"><img border="0" src="fault_x.gif" width="12" height="12" class="deleteRule"></a>
                                                                 <a href="javascript:;" title="Edit" class="posAbso edit"><img border="0" src="Note.gif" width="12" height="12" onclick="updateQuestion('<%=rs.getString(2)%>','<%=htmlType%>','<%=rs.getString(1)%>')" class="comSprite edit"></a>
                                                                  </td>
                                                                </tr>
                                                            </table>
                                                        </div>
                                            <%}}rs.close(); 
                                            pst.close();%>
                                          </div>
                                          <input type="hidden" value="0" id="layoutCount" name="layoutCount">
                                          <input type="hidden" id="count" name="count" value='<%=count1 %>'>
                                          <input type="hidden" value="0" id="deleteQuestion" name="deleteQuestion">
                                      </td>
                                      <td width="5%">&nbsp;</td>
                                  </tr>
                              </table>
                          </div>
                      </td>
                </tr>
                <tr class="hiddenDisplay">
                      <td colspan="2">
                          &nbsp;
                      </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;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">
                                            <% if(mailcheckstatus==1) { %>
                                                <input type="checkbox" name="sendmail" id="sendmail" value="1" checked="checked" onclick="sendMailOption();"/>
												<label class="customRadCheck" for="sendmail"><span><span></span></span></label>
                                            <% }else{%>
                                                <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>
                                                <% if(ccManager==1) { %>
                                                <input type="checkbox" name="ccManager" id="ccManager" value="1" checked="checked"/>
												<label class="customRadCheck" for="ccManager"><span><span></span></span></label>
                                                <% }else{%>
                                                <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"><%= i18n.tr("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">--choose--</option>
                                                <option value="MACRO_SURVEYUSER">User ID</option>
                                                <option value="MACRO_USER_FULLNAME">Full name</option>
                                                <option value="MACRO_SURVEYTITLE ">Title</option>
                                                <option value="MACRO_SURVEYENDTIME">End time</option>                                                            
                                            </select> <input  type="button"  name="addMacro" id="addMacro" onClick="addMacroToEditor()" value="Add Macro"  class="addbuttons greenBtn" />
                                        </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"><%=email_Template%></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>
                                    <% if( isSurveyOrFeedback == 0 ){ %>            
                                    <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()" <%= levelOneCheck %>/>                                         
											<label class="customRadCheck" for="preNotificationOne"><span><span></span></span></label>											 
                                         </td>
                                    </tr>
                                    <tr id="levelOneInterval" style="display:<%= displayLevelOne %>">
                                        <td width="20%" align="right" bgcolor="#FFFFFF" class="formtext"><%= i18n.tr("Notify before")%>&nbsp;<font color="red">*</font></td>
                                        <td width="80%" align="left" bgcolor="#FFFFFF" class="formfield">
                                            <input type="text" id="levelOneIntervalDays" name="levelOneIntervalDays" value="<%= levelOneIntervalDays %>" class="gen" 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++){
                                                if(Integer.parseInt(levelOneIntervalHours) == i){%>
                                                    <option value="<%=i%>" selected><%=i%></option>
                                                <%}else{%>
                                                    <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){
                                                    if(Integer.parseInt(levelOneIntervalMins) == i){%>
                                                        <option value="<%=i%>" selected><%=i%></option>
                                                    <%}else{%>
                                                        <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()" <%= levelTwoCheck %>/>                                     
											<label class="customRadCheck" for="preNotificationTwo"><span><span></span></span></label>											 
                                           </td>
                                        </tr>
                                        <tr id="levelTwoInterval" style="display:<%= displayLevelTwo %>">
                                          <td width="20%" align="right" bgcolor="#FFFFFF" class="formtext"><%= i18n.tr("Notify before")%>&nbsp;<font color="red">*</font></td>
                                          <td width="80%" align="left" bgcolor="#FFFFFF" class="formfield">
                                             <input type="text" id="levelTwoIntervalDays" name="levelTwoIntervalDays" value="<%= levelTwoIntervalDays %>" class="gen" 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++){
                                                    if(Integer.parseInt(levelTwoIntervalHours)==i){%>
                                                        <option value="<%=i%>" selected><%=i%></option>
                                                    <%}else{%>
                                                        <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){
                                                    if(Integer.parseInt(levelTwoIntervalMins) == i){%>
                                                        <option value="<%=i%>" selected><%=i%></option>
                                                    <%}else{%>
                                                        <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">
                                            <% if(ackmailcheckstatus==1) { %>
                                            <input type="checkbox" name="acksendmail" id="acksendmail" value="1" onclick="ackMailOption();" checked/>
											<label class="customRadCheck" for="acksendmail"><span><span></span></span></label>											 
                                          <% }else{ %>
                                          <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"><%=ackemail_Template%></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>
                <% if( isSurveyOrFeedback == 1 ){ // isProcedureOrCustomcalss,isProcedureNameOrCustomcalssName   %>                           
                <tr id="hookHeaderDiv" >                        
                    <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;<%= i18n.tr("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"><%= i18n.tr("Hook Type")%></td>
                                                    <td width="10%" height="35" bgcolor="#FFFFFF" class="formfield">
                                                        <% if( isProcedureOrCustomcalss == 1 ){ %>
                                                        <input type="radio" id="procedureId" name="pcrocedure" onclick="isProcedureOrCustomclasschecked(this);" checked/>
														<label class="customRadCheck" for="procedureId"><span><span></span></span></label><span class="notifyLabel">Procedure</span>
                                                        <% } else { %>
                                                        <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">
                                                        <% if( isProcedureOrCustomcalss == 2 ){ %>
                                                        <input type="radio" id="customClassId" name="customClass" onclick="isProcedureOrCustomclasschecked(this);" checked/>
														<label class="customRadCheck" for="customClassId"><span><span></span></span></label><span class="notifyLabel">Custom Class(java class)</span>
                                                        <% } else { %>
                                                        <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="<%= isProcedureOrCustomcalss%>" />
                                                </tr>
                                                <tr>
                                                    <td colspan="4">
                                                        <% if (isProcedureOrCustomcalss == 1) { %>
                                                        <div id="procedureNameDiv">
                                                            <% } else { %>
                                                            <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"><%= i18n.tr("Procedure Name")%><font color="red">*</font></td>
                                                                        <td width="80%" bgcolor="#FFFFFF" class="formfield">
                                                                            <% if (isProcedureOrCustomcalss == 1) {%>
                                                                            <input type="text" id="procedureName" name="procedureName" class="mcopy" size="40" value="<%= isProcedureNameOrCustomcalssName%>" />
                                                                            <% } else { %>
                                                                            <input type="text" id="procedureName" name="procedureName" class="mcopy" size="40" value="" />
                                                                            <% } %>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="4">
                                                        <% if (isProcedureOrCustomcalss == 2) { %>
                                                        <div id="customClassNameDiv">
                                                            <% } else { %>
                                                            <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"><%= i18n.tr("Custom Class Name")%><font color="red">*</font></td>
                                                                        <td width="25%" bgcolor="#FFFFFF" class="formfield">
                                                                            <% if (isProcedureOrCustomcalss == 2) {%>
                                                                            <input type="text" id="customClassName" name="customClassName" class="mcopy" size="40" value="<%= isProcedureNameOrCustomcalssName%>" />
                                                                            <% } else { %>
                                                                            <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"><%= i18n.tr("Note:Please provide fully qualified class name Ex: sapphire.servicedesk.utils.DummyFeedbackClass")%></font></img>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </div>
                                                    </td>
                                                </tr>
                                             </table>
                                         </div>
                                     </td>
                                 </tr>
                             </table>
                         </div>
                     </td>
                </tr>               
                <% } %>
		   
      
       <!--<tr>                        
           <td  colspan="2" align="left"  class="copyhdr"  id="minus">
                  Questions                        
           </td>
           <td>&nbsp;
           </td>
       </tr>            
       <tr>
       	<td colspan="2">
       	 <div id="quesBlock">
       		<table width="100%" cellpadding="0" cellspacing="0">
       		<tr >
	         <td  align="right" bgcolor="#FFFFFF" width="20%" class="formtext">Question
	         </td>
	        <td  height="35" width="80%" bgcolor="#FFFFFF" class="formfield"> 
	        <input  type="text" id="question" name="question"  size="80"   class="mcopy" value=""  maxlength="100">
	        <input  type="button"  value="ADD" onclick="addEvent('ques');"  class="addbuttons"  id="addbutton" name="addbutton"> 
	        <input  type="button"  id="addTitle" name="addTitle" value="ADD TITLE" onclick="showTitle();"  class="addbuttons" >
	        </td>
	      </tr> 
       		</table>
       	</div>
       	</td>
       </tr>
        <tr>
        	<td colspan="2">
        	<div id="quesTitle" style="display:none">
        		<table width="100%" cellpadding="0" cellspacing="0">
        			 <tr >
			       <td  align="right" bgcolor="#FFFFFF" width="20%" class="formtext">Title
			       </td>
			       <td  height="35" width="80%" bgcolor="#FFFFFF" class="formfield"> 
			        <input  type="text" id="title" name="title"  size="80"   class="mcopy" value=""  maxlength="100">
			        <input  type="button"  value="ADD" onclick="addEvent('title');"  class="addbuttons"  id="addbutton1" name="addbutton1">  
			        <input  type="button"  id="addQues" name="addQues" value="ADD QUES" onclick="showQues();"  class="addbuttons" >
			       </td>
			    </tr> 
        		</table>
        		</div>
        	</td>
        </tr>
       
      
    <tr> 
      <td colspan="2" width="100%" >
      <table cellspacing="2" cellpadding="2" width="100%" >
		    <tr>
		      <td width="20%" align="center" bgcolor="#666666" class="disk">
		         Delete
		      <input type="hidden" value="0" id="rowCount" name="rowCount">			 
		     </td>
		     <td width="60%" align="center" bgcolor="#666666" class="disk">
		       Question
		     </td>
		     <td width="20%" align="center" bgcolor="#666666" class="disk">
		       Display Order
		     </td>	
		   </tr>
	   </table>
    </td>
  </tr>
       <tr>
     	 <td class="gen" colspan="2">
     <div id="dynamicRow">
     <%	
     		         				
	      int count=0;		
	      int questionid=0;
	      String divIdName=null; 
              pst = conn.prepareStatement("SELECT QuestionID,Question,DefaultOption, DisplayOrder FROM survey_questions where SurveyID = ? order by DisplayOrder");
              pst.setInt(1,SurveyID);
	      rs=pst.executeQuery();
           while(rs.next())
           {
	       String title="Edit Question";	
           count++;	
           questionid=rs.getInt(1);		           
     	   divIdName="my"+count+"Div";		        			       
      %>
      <div id="<%= divIdName %>">
      <table width="100%" border="0" cellspacing="2" cellpadding="1" bordercolor="#E2E2E2">
          <tr class='formfield'>
          <td align="center" width="20%" class="gen">
          <a href="javascript:;" title="Delete" onclick="removeEvent1('<%=divIdName %>','<%=questionid %>')"><img border="0" src="fault_x.gif" width="12" height="12"></a>
          </td>
          <%
          	if(rs.getString(2).contains("MACRO_TITLE$$$$")){
          		title=" Edit Title";
          	}
           %>
           <td align="center" width="60%" class="gen" style="cursor:pointer;" onclick="editQuestion('<%=SurveyID %>','<%=questionid %>','<%=title %>')" title="<%=title %>"><%if(rs.getString(2).contains("MACRO_TITLE$$$$")){%><b><%=rs.getString(2).replace("MACRO_TITLE$$$$","")%></b><%}else{ %><%= rs.getString(2)%><%} %>
           </td>
           <td align="center" width="20%" class="gen" ><%=rs.getInt(4) %>
           </td>			       
       
          <tr>
      </table>
      </div>
      <%} 
      rs.close(); pst.close();
      %>
     
     </div>
      <div id="delete_div"></div>
     		 <input type="hidden" id="count" name="count" value='<%=count %>'>
     </td>
</tr> -->
                <tr align="center" class="basicButtonFooter">                        
                    <td colspan="2" bgcolor="#FFFFFF" class="domains noTopMargin" align="center">		  
                          <br><input  type="button"  onClick="javascript:validatePage()" value="Update"  class="addbuttons greenBtn" />
                           <input  type="button"  onclick="javascript:back()" value="Cancel"  class="addbuttons" />
                           
                    </td>
                </tr>
      <% 			
	 
             
           }
      catch(Exception e){
      
	          	logger.error("Survey_Edit.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 (pst1 != null) {
                      pst1.close();
                  }
                  if (conn != null) {
                      conn.close();
                  }

              } catch (Exception e) 
              {
                  logger.error("In finally catch of Survey_Edit.jsp ::" + e.getMessage());
                  StackTraceElement[] stackTrace = null;
                  stackTrace = e.getStackTrace();
                  for (int i = 0; i < stackTrace.length; i++) {
                      logger.error("---- " + stackTrace[i].toString());
                  }
              }
          }
			%>  
                  
         
         </table>
                        </div></div></div>
       </td>
      </tr>
    </table>
         <div class="widgetFooter"></div>       
          </td>
<td width="17" valign="top">
</td>
</tr>
        
</table>
</td>
</tr>


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

        </td>
        </tr>
      </table>
      </td>
     </tr>
   </table>
  
           <td width="8" valign="top" ><img src="spacer.gif" width="8" height="1"class="hiddenDisplay">
           </td>
        



</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, '', '<%=roles%>');
          $j('#roles').multipleSelect({filter: true,selectAll: false});
          $j('#users').multipleSelect({filter: true,selectAll: false,onAfterCreate: function() { loadOnbehalfUser('${ContextPath}','users','', '<%= i18n.tr("All")%>', 1); } });
      </script>
<%@ include file="Sapphire_Footer.jsp" %>
</form>
</body>
</html>
    <jsp:include page="emailTemplateDesignerComponets.jsp">
        <jsp:param name="fromMainSettings" value="yes" />
    </jsp:include>
	 <%if(session.getAttribute("SERVICEDESK_NEWUI_PAGE")!=null){%> 
            <script type="text/javascript">
			jQuery(function(){
				var isMsLoaded=setInterval(function(){
					if(jQuery("select").is(":visible")==true){					
					jQuery("select.templateDesign").multipleSelect({
						single:true,
						width:350
					});
					clearInterval(isMsLoaded);
					}
				},100);
			});
			</script>
    <%}%>
</div>