/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

var editorWeb;
function loadScript(){
    editorWeb = ace.edit("editor");
//    editorWeb.setTheme("ace/theme/Clouds"); 
    /*
     * Text
     * Text(text/plain) - mode-text
     * JSON(application/json) - mode-json
     * javascript(application/javascript) - mode-javascript
     * XML(application/xml) - 
     * XML(text/xml)
     * HTML(text/html)
    */
    editorWeb.getSession().setMode("ace/mode/text");

}
/* OLD STARTS */
function validate()
{
    var templateType = getRadioSelectedVal();
    if (document.AJAX.name.value.trim() === ""){
        alert("Please provide template name");
        document.AJAX.name.value="";
        document.AJAX.name.focus();
        return;
    }
    if (document.AJAX.name.value.trim().length>65){
        alert("Please limit Template Name content less than or equal to 65 characters");
        document.AJAX.name.focus();
        return;
    }
    
    if( templateType === "PDF"){
        var ed_desc = CKEDITOR.instances.template;
        $("#sqlTemplateContent").attr("disabled", true );
        $("textarea#template").html( ed_desc.getData() );         
        if(document.AJAX.attachmentName.value == ""){
            alert("Please provide attachment name");
            document.AJAX.attachmentName.focus();
            return;
        }        
        
        if(document.AJAX.attachmentName.value.length>65){
            alert("Please limit Attachment Name content less than or equal to 65 characters");
            document.AJAX.attachmentName.focus();
            return;
        }
        if(document.AJAX.attachmentName.value.indexOf("pdf") == -1 ){
            alert("Please provide attachment name extension as .pdf ");
            document.AJAX.attachmentName.focus();
            return;
        }
        if (document.AJAX.template.value == ""){
            alert("Please provide template");            
            CKEDITOR.instances.template.focus();
            return;
        }    
        if (ed_desc.getData().trim().length>65535){
        alert("Please limit Template content less than or equal to 65,535 characters");
            CKEDITOR.instances.template.focus();
        return;
    }
        if (!isDoubleQuoteExist("name", "Name")){
            return;
        }
    } else if(templateType === "WEBHOKS_BODY"){
        var paramsQueryString = $('#paramsQueryString').val();
        if( paramsQueryString === "" ){
            alert("Please provide request URL");            
            document.AJAX.paramsQueryString.focus();
            return;
        }
        var headerValuesWithDelimiter = getValuesWithDelimiter('headerKey','headerValue');
        var httpMethodType = $('#httpMethodType').val();
        var authType = "";
        if(httpMethodType === 'GET'){
            $('#formBlockKeyValList').val('');
        }else{
            var formDataValuesWithDelimiter = getValuesWithDelimiter('formDataKey','formDataValue');
            var checkFormdataOrRawDataSelected = getIsFormDataOrRawDataSelected();
            if( checkFormdataOrRawDataSelected === "KEY_VALUE" ){
                $('#formBlockKeyValList').val('');
                $('#formBlockKeyValList').val(formDataValuesWithDelimiter);
            }else if( checkFormdataOrRawDataSelected === "STRING" ){
                var rawData = editorWeb.getValue();
                $('#formBlockKeyValList').val(rawData);
            }
        }
        $('#headerBlockKeyValList').val(headerValuesWithDelimiter);            
        authType = $('#authType').val();
        if( authType === 'noAuth' ){
            $('#authKey').val('');
            $('#authValue').val('');
        }
    } else if (templateType == "SQL_QUERY") {
        var ed_desc = ace.edit("sqlTemplate");
        document.AJAX.template.value = ed_desc.getValue();  
         $("#sqlTemplateContent").val(  ed_desc.getValue() );    
               
        
        if ( $("#sqlTemplateContent").val() == ""){
            alert("Please provide template");            
            CKEDITOR.instances.template.focus();
            return;
        }    
        if ($("#sqlTemplateContent").val().trim().length>65535){
            alert("Please limit Template content less than or equal to 65,535 characters");
            document.AJAX.template.focus();
            return;
        }
        if (!isDoubleQuoteExist("name", "Name")){
            return;
        }
    } else if ( templateType == "EMAIl_BODY" ) {
        var ed_desc = CKEDITOR.instances.template;
        $("#sqlTemplateContent").attr("disabled", true );
        $("textarea#template").html( ed_desc.getData() );  
        if (ed_desc.getData().trim().length>65535){
            alert("Please limit Template content less than or equal to 65,535 characters");
            CKEDITOR.instances.template.focus();
            return;
        }
    }
    $("#addbutton").attr("disabled","true");         
    var data = $("#velocityModelForm").serializeArray();
    var actionURL = $("#velocityModelForm").attr("action");
    $.post( actionURL , data, function( result ) 
    {
        if (result.trim() != "SUCCESS")
        {
            alert("Unable to process your request now. It's failed with the exception \""+result.trim()+"\".");
            $("#addbutton").removeAttr("disabled"); 
            return false;
        }
        else
        {
            var projectId = $("#projectId").val();
            var assetModuleId=$("#assetModuleId").val();
            var isCMDB=$("#isCMDB").val();
            window.location.href = "sdFormTemplateList.do?projectId="+projectId+"&assetModuleId="+assetModuleId+"&isCMDB="+isCMDB+"&isNewUIAvailable=yes";
        }
    });
}


function getIsFormDataOrRawDataSelected(){
    var selectedVal = "";
    var radioArrVal = document.getElementsByName("sdIntegrationConfigDTO.bodyType");        
    for(var i=0;i<radioArrVal.length;i++){
        if( radioArrVal[i].checked ){
            selectedVal = radioArrVal[i].value;                
        }
    }
    return selectedVal;
}

function loadSummary(){
    var isSummaryIncluded = "";
    isSummaryIncluded = document.getElementById("includesummary");
    if (isSummaryIncluded.checked == true){
        document.getElementById("messagesummarylist").style = "display: visible";
        document.getElementById("messageSummaryTitle").style = "display: visible";
    }else{
        document.getElementById("messagesummarylist").style = "display: none";
        document.getElementById("messageSummaryTitle").style = "display: none";
    }
}
function showSettings() {
    document.getElementById("settingstd").style.width = "9%";
    document.getElementById("settingsdiv").style.display = "";
    document.getElementById("settingscollapsediv").style.display = "none";
}
function collapseSettings(){
    document.getElementById("settingstd").style.width = "1px";
    document.getElementById("settingsdiv").style.display = "none";
    document.getElementById("settingscollapsediv").style.display = "";
}

function getRadioSelectedVal(){         
    var selectedVal = "";
    var radioArrVal = document.getElementsByName("sdTemplateDTO.type");        
    for(var i=0;i<radioArrVal.length;i++){
        if( radioArrVal[i].checked ){
            selectedVal = radioArrVal[i].value;                
        }
    }
    return selectedVal;
}
function showHideData(){        
    var templateType = "";
    templateType = getRadioSelectedVal();
    if(templateType === "PDF" ){
		$('#sqlTemplateDiv > .formfield #sqlTemplateContent').remove();
        document.getElementById("attachmentDiv").style.display = "";
        document.getElementById("templateDiv").style.display = "";
        document.getElementById("webhookDiv").style.display = "none";
        document.getElementById("macroDiv").style.display = "none";        
        document.getElementById("template").removeAttribute("disabled");
        document.getElementById("formBlockKeyValList").setAttribute("disabled","disabled");
        document.getElementById("sqlTemplateDiv").style.display = "none";
    }
    else if(templateType === "SQL_QUERY" ){
		$('#sqlTemplateDiv > .formfield').prepend('<input type="hidden" id="sqlTemplateContent" path="sdTemplateDTO.template"  name="template"/>');
        document.getElementById("attachmentDiv").style.display = "none";
        document.getElementById("templateDiv").style.display = "none";
        document.getElementById("webhookDiv").style.display = "none";
        document.getElementById("macroDiv").style.display = "none";        
        document.getElementById("template").setAttribute("disabled",false);
        document.getElementById("sqlTemplateDiv").style.display = "";
        
        document.getElementById("formBlockKeyValList").setAttribute("disabled","disabled");
    }
    else if(templateType === "EMAIl_BODY" ){
		$('#sqlTemplateDiv > .formfield #sqlTemplateContent').remove();
        document.getElementById("attachmentDiv").style.display = "none";
        document.getElementById("templateDiv").style.display = "";
        document.getElementById("webhookDiv").style.display = "none";
        document.getElementById("macroDiv").style.display = "none";        
        document.getElementById("template").removeAttribute("disabled");
        document.getElementById("formBlockKeyValList").setAttribute("disabled","disabled");
        document.getElementById("sqlTemplateDiv").style.display = "none";
    }
    
    else{
		$('#sqlTemplateDiv > .formfield #sqlTemplateContent').remove();
        $('#httpMethodType').val("GET");
        document.getElementById("webhookDiv").style.display = "";
        document.getElementById("macroDiv").style.display = "";  
        document.getElementById("attachmentDiv").style.display = "none";
        document.getElementById("templateDiv").style.display = "none";            
        document.getElementById("template").setAttribute("disabled","disabled");
        document.getElementById("formBlockKeyValList").removeAttribute("disabled");
        document.getElementById("sqlTemplateDiv").style.display = "none";
    }
}
/* OLD Ends */

function addMacroToEditor(){    
    var templateType = getRadioSelectedVal();
    var macroToBeReplaced = $('#macroList').val(); 
    if( macroToBeReplaced == 0 ){
        alert("Please choose a macro");
        $('#macroList').focus();
        return;
    }
    $('#selectMacro').val(macroToBeReplaced);
    if( templateType === 'WEBHOKS_BODY'){
        editorWeb.insert(macroToBeReplaced);
    }else if( templateType === 'PDF' ){        
        CKEDITOR.instances['template'].insertText(macroToBeReplaced);
    }
    else if( templateType === 'EMAIl_BODY' ){        
        CKEDITOR.instances['template'].insertText(macroToBeReplaced);
    }
    else if( templateType === 'SQL_QUERY' ){  
        var editor = ace.edit("sqlTemplate");
        editor.insert(macroToBeReplaced);
    }
}

$(document).on("click",".methodSelectBox", function(e){ 
    if($(this).hasClass("opened")){
    	$(this).siblings(".expandMethodSelectBox").slideUp();
    	$(this).removeClass("opened");
    } else{
    	$(this).siblings(".expandMethodSelectBox").slideDown();
    	$(this).addClass("opened");
    }
    e.stopPropagation();
});

$(document).on("click","#paramsBtn", function(){ 
	if($(this).hasClass("active")){
    	$("#paramsBlk").slideUp();
    	$(this).removeClass("active");
    } else{
    	$("#paramsBlk").slideDown();
    	$(this).addClass("active");
    }
}); 

$(document).on("click",".dahboardNav a.navLnk", function(){ 
    event.preventDefault();
    $(this).parent().addClass("selected");
    $(this).parent().siblings().removeClass("selected");
    var tab = $(this).attr("href");
    $(".tab-content").not(tab).css("display", "none");    
    $(tab).fadeIn();
    if( tab === "#bodyBlk" ){
        checkContentType();
    }
});

$(document).click(function(e) {
   if (!$(e.target).is('.expandMethodSelectBox,#headersBlk .tableContent li input')) {
       $(".expandMethodSelectBox").slideUp();
       $(".methodSelectBox").removeClass("opened");
   }
});
 
$(document).on("click","input[type='radio'].radioClk", function(){ 
    var inputValue = $(this).attr("value");
    getFrormOrRawDataView(inputValue);
});

function getFrormOrRawDataView(inputValue){    
    if( inputValue === 'KEY_VALUE'){
        inputValue = 'formDataBlk';
    }else if( inputValue === 'STRING' ){
        inputValue = 'bodyDataBlk';
    }
   if ( inputValue != "" )
    {
        var targetBox = $("." + inputValue);    
        $(".boxBlk").not(targetBox).hide();
        $(targetBox).show();
        if( inputValue === 'bodyDataBlk' )
        {
          loadScript();      
        }
    }
}

function checkContentType(){
    var headerKeyValues = $('input[name="headerKey"]').map(function(){
       return this.value;
    }).get();    
    
    var headerValValues = $('input[name="headerValue"]').map(function(){
       return this.value;
    }).get();
    
    for(var i=0;i<headerKeyValues.length;i++){
        if( headerKeyValues[i] !== '' && headerKeyValues[i] === 'Content-Type' ){           
            if( headerValValues[i] === 'Text' || headerValValues[i] === 'text/plain' || headerValValues[i] === 'application/json' || headerValValues[i] === 'application/javascript'
                    || headerValValues[i] === 'application/xml' || headerValValues[i] === 'text/xml' || headerValValues[i] === 'text/html'){
                $('#bodyContentType').val(headerValValues[i]);
            }else{
                $('#bodyContentType').val('Text');
            }
            break;
        }
    }
    
}

/* Changing POST and GET */
$(document).on("click",".expandMethodSelectBox a", function(){ 
    var printValue= $(this).text(); 
    $(this).parents(".expandMethodSelectBox").siblings(".methodSelectBox").html(printValue); 
});

function showBasicAuthView(selected){    
    if( selected === 'BASIC'){
        $("#authorizationInnBlk").show();
    }else{
        $("#authorizationInnBlk").hide();
    }    
}

var totalCount = 1;
function addParamsBlkList(){
    var count = 0;
    count = parseInt($('#paramListCount').val());        
    totalCount = parseInt($('#paramListTotalCount').val());
    count = count + 1;     
    var listData = "<ul class='tableContent' id='paramsUl"+count+"'><li class='tableCheckFld'></li>"+
            "<li class='col w33'><input type='text' name='paramsKey' id='' value='' onkeyup='onKeyKeyUp();' /></li><li class='col w33'><input type='text' name='paramsValue' id='' value='' onkeyup='onValueKeyUp();'/></li>"+
            "<div class='rowActionBlk'><a href='javascript:void(0)' class='addRowLnk'><img src='assets/images/addCust.png' alt='' onclick='addParamsBlkList()' /></a>"+
            "<a href='javascript:void(0)' class='deleteRowLnk'><img id='paramsUl"+count+"img' src='assets/images/addCust.png' alt='' onclick='deleteParamsBlkList(this.id)' /></a></div></ul>";
    $('#paramsBlkList').append(listData);
    $('#paramListCount').val(count);    
    totalCount = totalCount+1;
    $('#paramListTotalCount').val(totalCount);
}

function deleteParamsBlkList(paramId){ 
    totalCount = totalCount - 1;   
    paramId = paramId.replace("img","");
    if( totalCount > 0 ){
        $('#paramListTotalCount').val(totalCount);        
        $('#'+paramId).remove();
        formQuryStr();
    }else{
        if( $('#paramListTotalCount').val() == 1 ){
            $('#paramListTotalCount').val(1);           
            var tempId = paramId.replace("paramsUl","");
            $('#paramsKey'+tempId).val("");$('#paramsValue'+tempId).val("");
            formQuryStr();
        }else{
            totalCount = parseInt($('#paramListTotalCount').val());
            totalCount = totalCount - 1;
            $('#paramListTotalCount').val(totalCount);            
            $('#'+paramId).remove();
            formQuryStr();
        }
    }    
}

function formQuryStr(){
    var queryString="";    
    var keyValues = $('input[name="paramsKey"]').map(function(){
       return this.value;
    }).get();    
    var valValues = $('input[name="paramsValue"]').map(function(){
       return this.value;
    }).get();    
    for(var i=0;i<keyValues.length;i++){        
        if( queryString === "" ){
            if( keyValues[i] !== "" ){
                queryString = "?"+keyValues[i]+"="+valValues[i];
            }
        }else{
            if( keyValues[i] !== "" ){
                queryString +="&"+keyValues[i]+"="+valValues[i];
            }
        }
    }    
    var queryStringSplitData = $('#paramsQueryString').val().split("?");    
    $('#paramsQueryString').val(queryStringSplitData[0]+queryString);
}

function getValuesWithDelimiter(keyNameAttribute,valueNameAttribute){
    var delimitedValue="";
    var headerKeyValues = $('input[name="'+keyNameAttribute+'"]').map(function(){
       return this.value;
    }).get();    
    
    var headerValValues = $('input[name="'+valueNameAttribute+'"]').map(function(){
       return this.value;
    }).get();
    
    for(var i=0;i<headerKeyValues.length;i++){
        if( delimitedValue === ""){
            if( headerKeyValues[i] !== '' ){
                delimitedValue = headerKeyValues[i]+"#IM#"+headerValValues[i];
            }
        }else{
           if( headerKeyValues[i] !== '' ){
                delimitedValue +="$SAPP$"+headerKeyValues[i]+"#IM#"+headerValValues[i];
            } 
        }
    }
    return delimitedValue;
}

function onKeyKeyUp(){    
    formQuryStr();
}

function onValueKeyUp(){
    formQuryStr();
}

var headerTotalCount = 1;
function addheadersBlk(){
    var count = 0;
    count = parseInt($('#headerListCount').val());   
    headerTotalCount = parseInt($('#headerListTotalCount').val());    
    count = count + 1;     
    var listData = "<ul class='tableContent' id='headerUl"+count+"'><li class='tableCheckFld'></li>"+
            "<li class='col w33'><input type='text' name='headerKey' id='headerKey"+count+"' value='' onkeyup='getHeaderKeyValueList(this.id,\"key\")' /></li><li class='col w33'><input type='text' class='headerValClass' name='headerValue' id='headerValue"+count+"' value='' onkeyup='getHeaderKeyValueList(this.id,\"value\")'/></li>"+
            "<div class='rowActionBlk'><a href='javascript:void(0)' class='addRowLnk'><img src='assets/images/addCust.png' alt='' onclick='addheadersBlk()' /></a>"+
            "<a href='javascript:void(0)' class='deleteRowLnk'><img id='headerUl"+count+"img' src='assets/images/addCust.png' alt='' onclick='deleteheadersBlk(this.id)' /></a></div></ul>";
    $('#headerBlkList').append(listData);
    $('#headerListCount').val(count);    
    headerTotalCount = headerTotalCount+1;   
    $('#headerListTotalCount').val(headerTotalCount);
}

function deleteheadersBlk(headerId){ 
    headerTotalCount = headerTotalCount - 1;
    headerId = headerId.replace("img","");
    if( headerTotalCount > 0 ){        
        $('#'+headerId).remove();
        $('#headerListTotalCount').val(headerTotalCount);
    }else{
        if( parseInt($('#headerListTotalCount').val()) == 1 ){
            var tempId = headerId.replace("headerUl","");
            $('#headerKey'+tempId).val("");$('#headerValue'+tempId).val("");
            $('#headerListTotalCount').val(1);
        }else{
            headerTotalCount = parseInt($('#headerListTotalCount').val());
            headerTotalCount = headerTotalCount - 1;                       
            $('#'+headerId).remove();
            $('#headerListTotalCount').val(headerTotalCount);
        }
    }    
}

var formTotalCount=1;
function addFormDataBlk(){
    var count = 0;
    count = parseInt($('#formDataCount').val());    
    formTotalCount = parseInt($('#formTotalCount').val());    
    count = count + 1;     
    var listData = "<ul class='tableContent' id='formDataUl"+count+"'><li class='tableCheckFld'></li>"+
            "<li class='col w33'><input type='text' name='formDataKey' id='' value='' onkeyup='' /></li><li class='col w33'><input type='text' name='formDataValue' id='' value='' onkeyup=''/></li>"+
            "<div class='rowActionBlk'><a href='javascript:void(0)' class='addRowLnk'><img src='assets/images/addCust.png' alt='' onclick='addFormDataBlk()' /></a>"+
            "<a href='javascript:void(0)' class='deleteRowLnk'><img id='formDataUl"+count+"img' src='assets/images/addCust.png' alt='' onclick='deleteFormdataBlk(this.id)' /></a></div></ul>";
    $('#formDataBlkList').append(listData);
    $('#formDataCount').val(count);    
    formTotalCount = formTotalCount+1;
    $('#formTotalCount').val(formTotalCount);
}

function deleteFormdataBlk(formDataId){
    formTotalCount = formTotalCount - 1;
    formDataId = formDataId.replace("img","");
    if( formTotalCount > 0 ){        
        $('#'+formDataId).remove();
        $('#formTotalCount').val(formTotalCount);
    }else{
        if( parseInt($('#formTotalCount').val()) == 1 ){           
            var tmpId = formDataId.replace("formDataUl","");                       
            $('#formKey'+tmpId).val("");$('#formValue'+tmpId).val("");
            $('#formTotalCount').val(1);
        }else{
            formTotalCount = parseInt($('#formTotalCount').val());
            formTotalCount = formTotalCount - 1;            
            $('#'+formDataId).remove();
            $('#formTotalCount').val(formTotalCount);
        }
    }   
}

var headerKeysMap = {"Accept":"Accept","Accept-Language":"Accept-Language","Authorization":"Authorization","Cache-Control":"Cache-Control","Content-MD5":"Content-MD5",
    "Content-Type":"Content-Type","From":"From","If-Match":"If-Match","If-Modified-Since":"If-Modified-Since","If-None-Match":"If-None-Match","If-Range":"If-Range",
    "If-Unmodified-Since":"If-Unmodified-Since","Max-Forwards":"Max-Forwards","Pragma":"Pragma","Proxy-Authorization":"Proxy-Authorization","Range":"Range",
    "Warning":"Warning","X-Requested-With":"X-Requested-With","X-Do-Not-Track":"X-Do-Not-Track","DNT":"DNT","x-api-key":"x-api-key","Accept-Charset":"Accept-Charset",
    "Accept-Encoding":"Accept-Encoding","Access-Control-Request-Headers":"Access-Control-Request-Headers","Access-Control-Request-Method":"Access-Control-Request-Method",
    "Connection":"Connection","Content-Length":"Content-Length","Cookie":"Cookie","Cookie 2":"Cookie 2","Content-Transfer-Encoding":"Content-Transfer-Encoding",
    "Date":"Date","Expect":"Expect","Host":"Host","Keep-Alive":"Keep-Alive","Origin":"Origin","Referer":"Referer","TE":"TE","Trailer":"Trailer","Transfer-Encoding":"Transfer-Encoding",
    "Upgrade":"Upgrade","User-Agent":"User-Agent","Via":"Via"};

var headerValuesMap = {"application/atom+xml":"application/atom+xml","application/ecmascript":"application/ecmascript","application/json":"application/json",
    "application/javascript":"application/javascript","application/octet-stream":"application/octet-stream","application/ogg":"application/ogg","application/pdf":"application/pdf",
    "application/postscript":"application/postscript","application/rdf+xml":"application/rdf+xml","application/rss+xml":"application/rss+xml","application/soap+xml":"application/soap+xml",
    "application/font-woff":"application/font-woff","application/x-yaml":"application/x-yaml","application/xhtml+xml":"application/xhtml+xml","application/xml":"application/xml",
    "application/xml-dtd":"application/xml-dtd","application/xop+xml":"application/xop+xml","application/gzip":"application/gzip","application/zip":"application/zip","application/graphql":"application/graphql",
    "application/x-www-form-urlencoded":"application/x-www-form-urlencoded","audio/basic":"audio/basic","audio/L24":"audio/L24","audio/mp4":"audio/mp4","audio/mpeg":"audio/mpeg","audio/ogg":"audio/ogg","audio/vorbis":"audio/vorbis",
    "audio/vnd.rn-realaudio":"audio/vnd.rn-realaudio","audio/vnd.wave":"audio/vnd.wave","audio/webm":"audio/webm","image/gif":"image/gif","image/jpeg":"image/jpeg","image/pjpeg":"image/pjpeg","image/png":"image/png","image/svg+xml":"image/svg+xml",
    "image/tiff":"image/tiff","message/http":"message/http","message/imdn+xml":"message/imdn+xml","message/partial":"message/partial","message/rfc822":"message/rfc822","multipart/mixed":"multipart/mixed","multipart/alternative":"multipart/alternative",
    "multipart/related":"multipart/related","multipart/form-data":"multipart/form-data","multipart/signed":"multipart/signed","multipart/encrypted":"multipart/encrypted","text/cmd":"text/cmd","text/css":"text/css","text/csv":"text/csv","text/html":"text/html",
    "text/plain":"text/plain","text/vcard":"text/vcard","text/xml":"text/xml"};

function getHeaderKeyValueList(dataId,type){
    var search = $('#'+dataId).val().toLowerCase();    
    var headerKeyValArray=[];
    if( type === 'key' ){
        $.each(headerKeysMap, function(key, value) {
            if( key.toLowerCase().indexOf(search) > -1 ){
                headerKeyValArray.push(value);                
            }
        });
    }
    if( type === 'value' ){
        $.each(headerValuesMap, function(key, value) {
            if( key.toLowerCase().indexOf(search) > -1 ){
                headerKeyValArray.push(value);                
            }
        });
    }    
    $('#'+dataId).siblings('ul.dropDownAuto').remove();
    var isValExist = jQuery.isEmptyObject(headerKeyValArray);
    if( isValExist == false ){
        var datalist = "";
        $.each( headerKeyValArray, function( index, value ){        
            if(datalist === ""){
                datalist = '<li><a href="javascript:void(0);" onclick=\'addValue("'+dataId+'","'+value.trim()+'")\'>'+value.trim()+'</a></li>';
            }else{                
                datalist +='<li><a href="javascript:void(0);" onclick=\'addValue("'+dataId+'","'+value.trim()+'")\'>'+value.trim()+'</a></li>';
            }
        });
        $('#'+dataId).closest('.col').append('<ul class="expandMethodSelectBox dropDownAuto">'+datalist+'</ul>');        
    }        
}

function addValue(dataId,data){
    $('#'+dataId).val(data);    
}

function getBodyBlock(type){
    if(type === "GET" ){
        $('#bodyBlock').addClass("disabled");
        $('#bodyBlock').find("a").attr("href","javascript:void(0);");
        $('#bodyBlock').find("a").attr("class","");
        $('#httpMethodType').val('GET');
        $('#bodyBlk').hide();
    }else{
        $('#bodyBlock').removeClass("disabled");
        $('#bodyBlock').find("a").attr("href","#bodyBlk");
        $('#bodyBlock').find("a").attr("class","navLnk");
        $('#httpMethodType').val(type);
    }
}

/* On Edit view starts */
function showEditView(httpMethod,bodyType,authType){
    showHideData();    
    getBodyBlock(httpMethod);
    showBasicAuthView(authType);    
    if( bodyType === 'KEY_VALUE' ){
        getFrormOrRawDataView(bodyType);
    }else{
        getFrormOrRawDataView(bodyType);
        var bodyData = $('#formBlockKeyValList').val();
        editorWeb.setValue(bodyData);
    }
}
/* On Edit view ends */

function showPassword(){    
    var passValue = $('#authValue').val(); 
    var change = $('#showPassword1').is(":checked") ? "text" : "password";    
    $('#passwordDiv').empty();
    $('#passwordDiv').append(" <input id='authValue' name='sdIntegrationConfigDTO.authValue' value='' type='"+change+"'> ");
    $('#authValue').val(passValue);
}