function ClickTicketTab(divtohide, tabid, ajaxFuse, ajaxView)
{
    for (var i = 0; i < tabDivs.length; i++) {
        Element.hide('div_'+tabDivs[i]);
        Element.removeClassName('tab_'+tabDivs[i] , "current" );
    }

    Element.toggle( divtohide );
    Element.addClassName( tabid , "current" );

    if((ajaxView != null)&&(ajaxView != "")){
        new Ajax.Updater(divtohide, 'index.php?fuse='+ajaxFuse+'&view='+ajaxView,
                         {onLoading : function(request){resetStatus(lang('Loading'))},
                          onComplete: function(request){unsetStatus(lang('Loaded'), 1000)}});
    }
}

function ToggleSecondOptionsPanel()
{
    //0 normal reply , 1 internal commment
    if ($('replytype').selectedIndex == 0){
        $('secondOptionsPanel').style.visibility = 'visible';
        $('private').value = 0;
    }else{
        $('secondOptionsPanel').style.visibility = 'hidden';
        $('private').value = 1;
    }
}

function assignTicketSuccess(responseObj)
{
    var responseArr = responseObj.responseText.split('|');
    if (typeof responseArr[1] == 'undefined' || responseArr[0] != 'OK') {
        alert(responseObj.responseText.stripTags());
        return;
    }
    $('assignedtoname').innerHTML = "<a class='liveupdate' href=\"javascript:ShowEditBox('assignedtoname','support','GetReassignDropdown_Async','assignee');\">"+responseArr[1]+"</a>";
    unsetStatus('', 1);
    
    var assignedToId = $('assignedToId');
    var userId = $('userId')
    
    if(assignedToId != null && userId != null && typeof responseArr[2] != 'undefined') {
        assignedToId.value = responseArr[2];
        if(assignedToId.value == userId.value) {
            $("notificationButton").style.display = "none";
        }  else  {
            $("notificationButton").style.display = "inline";
        }
    }	
}

function assignTicket(ticketId, adminId, reassign)
{
    if (adminId == 0) {
        return;
    }
    setStatus('Assigning Ticket...');
    if (reassign) {
        new Ajax.Request(   'index.php?fuse=support&action=ReasignTicket_Async&from=ViewTicketDetails',
                            {
                                postBody    : 'ticket='+ticketId+'&adminid='+adminId,
                                onSuccess   : assignTicketSuccess
                            }
        );
    } else {
        new Ajax.Request(   'index.php?fuse=support&action=AssignTickets_Async&from=ViewTicketDetails',
                            {
                                postBody    : 'items=' + ticketId + '&adminid=' + adminId,
                                onSuccess   : assignTicketSuccess
                            }
        );
    }
}

function ChangePrioritySuccess(t){

    if(t.responseText=='1'){
    	priorityTxt =  lang('High');
    	//$('tdPriority').className = "innerPriorityOne";
    }
    if(t.responseText=='2'){
    	priorityTxt =  lang('Medium'); 
    	//$('tdPriority').className = "innerPriorityTwo";
    }
    if(t.responseText=='3'){ 
    	priorityTxt =  lang('Low');
    	//$('tdPriority').className = "formField";
    }

    $('tdPriority').innerHTML = "<a class='liveupdate' href=\"javascript:ShowEditBox('tdPriority','support','SetPriority_Async','priority');\">"+priorityTxt+"</a>";    
    $('originalPriority').value = t.responseText;    
    unsetStatus('', 1);
}

function ChangePriority(ticket,fuse,action){
    var priority = $('chPriority').value;
	setStatus('Changing Ticket Priority...');
	var opt = {
		method: 'post',
		postBody: 'ticket='+ticket+'&priority='+priority,			
		onSuccess: ChangePrioritySuccess
	}		
	new Ajax.Request('index.php?fuse='+fuse+'&action='+action, opt);
}

function ChangeStatusSuccess(t){
    //var statusImg="";

    if(t.responseText=='-1'){
    	StatusTxt =  lang('Closed');
        //statusImg = "../images/ticket_status_closed.gif";
    }
    if(t.responseText=='1'){
    	StatusTxt =  lang('Open');
        //statusImg = "../images/ticket_status_open.gif";
    }
    if(t.responseText=='2'){
    	StatusTxt =  lang('Waiting on tech');
        //statusImg = "../images/ticket_status_waitingontech.gif";
    }
    if(t.responseText=='3'){ 
    	StatusTxt =  lang('Waiting on customer');
        //statusImg = "../images/ticket_status_waitingoncustomer.gif";
    }

    $('ticket_status_link').innerHTML = "<a class='liveupdate' href=\"javascript:ShowEditBox('ticket_status_link','support','SetStatus_Async','status');\">"+StatusTxt+"</a>";
    //$('ticket_status_link').innerHTML = "<a class='liveupdate' href=\"javascript:ShowEditBox('ticket_status_link','support','SetStatus_Async','status');\"><img src="+statusImg+" border=0 /></a>";
    $('originalStatus').value = t.responseText;    
    unsetStatus('', 1);
}

function ChangeStatus(ticket,fuse,action){
   var status = $('chStatus').value;
	setStatus('Changing Ticket Status...');
	var opt = {
		method: 'post',
		postBody: 'ticket='+ticket+'&status='+status,			
		onSuccess: ChangeStatusSuccess
	}		
	new Ajax.Request('index.php?fuse='+fuse+'&action='+action, opt);
}

function ShowEditBox(id,fuse,action,field){
 
    if (field=='priority'){
    	oldvalue = $('originalPriority').value;
    
        content = "<select style='width:100px' id='chPriority' name='chPriority' onChange=\"ChangePriority('"+$('ticketid').value+"','"+fuse+"','"+action+"');\">";
        if(oldvalue == 3){
        	content += "<option value=3 SELECTED>"+lang('Low')+"</option>";
        }else{
        	content += "<option value=3>"+lang('Low')+"</option>";
        }
        
        if(oldvalue == 2){
        	content += "<option value=2 SELECTED>"+lang('Medium')+"</option>";
        }else{
        	content += "<option value=2>"+lang('Medium')+"</option>";
        }
        
        if(oldvalue == 1){
        	content += "<option value=1 SELECTED>"+lang('High')+"</option>";
        }else{
        	content += "<option value=1>"+lang('High')+"</option>";
        }                      
        content += "</select>";
        $(id).innerHTML = content;
	    $('chPriority').focus();
    }
    
    if (field=='status'){
    	oldvalue = $('originalStatus').value;
    
        content = "<select style='width:150px;' id='chStatus' name='chStatus' onChange=\"ChangeStatus('"+$('ticketid').value+"','"+fuse+"','"+action+"');\">";        
        if(oldvalue == 3){
        	content += "<option value=3 selected='selected'>"+lang('Waiting on customer')+"</option>";
        }else{
        	content += "<option value=3>"+lang('Waiting on customer')+"</option>";
        }
        
        if(oldvalue == 2){
        	content += "<option value=2 selected='selected'>"+lang('Waiting on tech')+"</option>";
        }else{
        	content += "<option value=2>"+lang('Waiting on tech')+"</option>";
        }
        
        if(oldvalue == 1){
        	content += "<option value=1 selected='selected'>"+lang('Open')+"</option>";
        }else{
        	content += "<option value=1>"+lang('Open')+"</option>";
        }                      

        if(oldvalue == -1){
        	content += "<option value=\"-1\" selected='selected'>"+lang('Closed')+"</option>";
        }else{
        	content += "<option value=\"-1\" >"+lang('Closed')+"</option>";
        }                      

        content += "</select>";
        $(id).innerHTML = content;
	    $('chStatus').focus();
    }    
   
    if (field=='subject'){
        $(id).innerHTML = "<input type='text' size='40' id='chSubject' name='chSubject' value='"+$('originalSubject').value+"' /> <input type=button value='"+lang('go')+"' onClick=\"ChangeSubject('"+$('ticketid').value+"','"+fuse+"','"+action+"');\" class='button_small' />";
        $('chSubject').focus();
    }

    /*
    if (field == 'owner') {
        $(id).innerHTML = lang("Migrate to user ID:") + "<form style='display:inline;padding-left:27px;' method='post' action='index.php?fuse="+ fuse +"&action=" + action + "'><input type='hidden' name='oldview' value='"+oldview+"' /><input type='hidden' name='ticket' value='"+ $("ticketid").value +"' /><input type='text' size='10' name='userId' value='' /> <input style='position:relative;top:-2px;' type='submit' value='" + lang("go") + "' class='button_small' onclick='return confirmChangeOwnership();' /></form>";
        $('chOwner').focus();
    }
    */

    if (field=='log'){
        $(id).innerHTML = "<textarea class='textbox' wrap='virtual' rows=5 cols=53 id='ch"+id+"'>"+rmbr($(id).innerHTML)+"</textarea>";
        $('editLinks_'+id).innerHTML = "<a class='liveupdate' style='font-size:11px;' href=\"javascript:SaveEditMessage('"+id+"','"+fuse+"','"+action+"');\">"+lang('Save')+"</a>&nbsp;&nbsp;<a class='liveupdate' style='font-size:11px;' href=\"javascript:CancelEditMessage('"+id+"','"+fuse+"');\">"+lang('Cancel')+"</a>";
        $('ch'+id).focus();
    }

    if (field=='assignee'){
    	setStatus('Retrieving List...');
        new Ajax.Request('index.php?fuse=support&action='+action+'&ticketId='+$('ticketid').value+'&clientId='+$('ticket_owner_id').value +'&execute=load',{
                                    onComplete    : setAssignee});
    }

    if (field=='type'){

        oldvalue = $('originalType').value;
    
        var select = "<select style='width:123px;' onChange=\"ChangeType('"+$('ticketid').value+"','"+fuse+"','"+action+"');\" id='chType' name='chType'>";
        typeHash.each(function(pair) {
        	if(oldvalue == pair.key){
        	  selected="SELECTED";
        	}else{
        	  selected="";
        	}
            select = select+"<option "+selected+" value='"+pair.value+"'>"+varLang(pair.key)+"</option>";
        });
        $(id).innerHTML = select+"</select>";
        $('chType').focus();
    }

    if (field =='domain'){
    	setStatus('Retrieving List...');    
        new Ajax.Request('index.php?fuse=support&selectedDomain='+$('originalDomain').value+'&action=SetDomain_Async&clientId='+$('ticket_owner_id').value +'&execute=load',{
                                    onComplete    : setDomains});
    }
}

function setDomains(t){
   $('tdDomain').innerHTML = t.responseText;
   unsetStatus('', 1);  
}

function setAssignee(t){
    var responseArr = t.responseText.split('|');
    if (typeof responseArr[1] == 'undefined' || responseArr[0] != 'OK') {
        alert(t.responseText.stripTags());
        return;
    }

   $('assignedtoname').innerHTML = responseArr[1];   
    unsetStatus('', 1);     
}

function ChangeDomain()
{
    new Ajax.Request('index.php?fuse=support&action=SetDomain_Async&ticketId='+$('ticketid').value+'&clientId='+$('ticket_owner_id').value +'&domainId='+$('domainId').value+'&execute=save',{
                                onLoading     : function(request) {resetStatus(lang('Loading'))},
                                onComplete    : changeDomainsSuccess});
}

function changeDomainsSuccess(t)
{
	//get new plan information as well
	var response = t.responseText.split('||');
	var packagelink = response[0].split('--');
	var id = response[0].split(' ');
	id = id[0].substring(1);
	if(packagelink.length > 1){
	    $('tdDomain').innerHTML = "<a class='liveupdate' href=\"javascript:ShowEditBox('tdDomain','support','SetDomain_Async','domain');\">"+packagelink[0]+"</a>&nbsp;&nbsp;"+packagelink[1]+"&nbsp;&nbsp;";
	}else{
	    $('tdDomain').innerHTML = "<a class='liveupdate' href=\"javascript:ShowEditBox('tdDomain','support','SetDomain_Async','domain');\">"+response[0]+"</a>&nbsp;&nbsp;";
	} 
    $('originalDomain').value = id;
    $('ticket_packagename').innerHTML = response[1];
    unsetStatus('', 1);    
}


function ChangeType(ticket, fuse, action)
{
    var type = $('chType').value;
	setStatus('Changing Ticket Type...');
	var opt = {
		method: 'post',
		postBody: 'ticket='+ticket+'&type='+type,			
		onSuccess: ChangeTypeSuccess
	}		
	new Ajax.Request('index.php?fuse='+fuse+'&action='+action, opt);
}

function ChangeTypeSuccess(t)
{
    var response = t.responseText.split('|');
    $('tdType').innerHTML = "<a class='liveupdate' href=\"javascript:ShowEditBox('tdType','support','SetType_Async','type');\">"+varLang(response[1])+"</a>";
    $('originalType').value = response[1];
    unsetStatus('', 1);

    changeTicketType(response[0]);
}

function DeleteLog(log,fuse,action)
{    
    if (fuse == 'support'){
        var logid = log.substring(4,log.length);
    }else{
        var logid = $(log.substring(4)).value;
    }
    strMessage = lang('Click OK if you are sure you want to delete the selected entry.');
    var answer = confirm(strMessage);
    if (!answer)return;
    setStatus('Deleting Log Message...');
    var opt = {
		method: 'post',
		postBody: 'log='+logid+'&logid='+log.substring(4,log.length),			
		onSuccess: DeleteLogSuccess
	}
	new Ajax.Request('index.php?fuse='+fuse+'&action='+action, opt);
}

function DeleteLogSuccess(t)
{        
    ret = t.responseText.split('|');
    $('div_log_'+ret[0]).innerHTML = '';
    unsetStatus('', 1);
}

function CancelEditMessage(id, fuse, action)
{
    $(id).innerHTML = nl2br($('ch'+id).value) + "<br><br>";
    if (fuse == 'support'){
        $('editLinks_'+id).innerHTML = "<a class='liveupdate' style='font-size:11px;' href=\"javascript:ShowEditBox('"+id+"','support','EditTicketLog_Async','log');\">"+lang('Edit')+"</a>&nbsp;&nbsp;<a class='liveupdate' style='font-size:11px;' href=\"javascript:DeleteLog('"+id+"','support','DeleteTicketLog_Async');\">"+lang('Delete')+"</a>";
    }else{
        $('editLinks_'+id).innerHTML = "<a class='liveupdate' style='font-size:11px;' href=\"javascript:ShowEditBox('"+id+"','knowledgebase','KB_UpdateComment_Async','log');\">"+lang('Edit')+"</a>&nbsp;&nbsp;<a class='liveupdate' style='font-size:11px;' href=\"javascript:DeleteLog('"+id+"','knowledgebase','KB_DeleteComment_Async');\">"+lang('Delete')+"</a>";
    }
}

function SaveEditMessage(log,fuse,action)
{ 
    var message = $('ch'+log).value;
    var ticket;
    if (fuse =='support'){
        ticket = $('ticketid').value;
    }else{        
        ticket = $(log.substr(4)).value;
    }        
    var logid = log.substring(4,log.length);
    setStatus('Editing Log Message...');
    var opt = {
		method: 'post',
		postBody: 'log='+logid+'&message='+encodeURIComponent(message)+'&id='+encodeURIComponent(ticket),
		onSuccess: SaveEditMessageSuccess
	}
	new Ajax.Request('index.php?fuse='+fuse+'&action='+action, opt);
}

function SaveEditMessageSuccess(t)
{
    var ret = t.responseText.split("|");
    var x;
    var message = ret[1];
    $('log_'+ret[0]).innerHTML = nl2br(message)+"<br><br>";
    $('editLinks_log_'+ret[0]).innerHTML = "<a class='liveupdate' style='font-size:11px;' href=\"javascript:ShowEditBox('log_"+ret[0]+"','"+ret[2]+"','"+ret[3]+"','log');\">"+lang('Edit')+"</a>&nbsp;&nbsp;<a class='liveupdate' style='font-size:11px;' href=\"javascript:DeleteLog('log_'"+ret[0]+",'"+ret[2]+"','"+ret[4]+"');\">"+lang('Delete')+"</a>";
    unsetStatus('', 1);
}

function ChangeSubject(ticket,fuse,action)
{
    var subject = $('chSubject').value;
	if(subject==$('originalSubject').value || subject == ''){
	    $('tdSubject').innerHTML = "<a class='liveupdate' href=\"javascript:ShowEditBox('tdSubject','support','SetSubject_Async','subject');\">"+$('originalSubject').value+"</a>&nbsp;&nbsp;&nbsp;";
	    return;
	}
	
	setStatus('Changing Ticket Subject...');
	var opt = {
		method: 'post',
		postBody: 'ticket='+ticket+'&subject='+encodeURIComponent(subject),			
		onSuccess: ChangeSubjectSuccess
	}		
	new Ajax.Request('index.php?fuse='+fuse+'&action='+action, opt);
}

function confirmChangeOwnership()
{
    return confirm(lang("NOTE: This operation will move all the tickets from this E-mail to the user whose ID you just entered.\nAlso, this E-mail will be added as an alternate address for support requests for this user."));
}

function ChangeSubjectSuccess(t)
{
    $('tdSubject').innerHTML = "<a class='liveupdate' href=\"javascript:ShowEditBox('tdSubject','support','SetSubject_Async','subject');\">"+t.responseText+"</a>&nbsp;&nbsp;&nbsp;";
    $('originalSubject').value = t.responseText;
    unsetStatus('', 1);
}

function itemSelected(form){
    strAlertMessage = '\n' + lang("You need to select entry(s) to perform this action on");
    intCount = document.forms['troubletickets'].elements.length;
    bolShowMessage = true;
    for (x=1;x<=intCount;x++)
    {
        if (document.forms['troubletickets'].elements[x-1].checked == true){
             bolShowMessage=false;
        }
    }

    if (bolShowMessage){    
        alert(strAlertMessage);
        document.forms['assignadmin'].elements['adminid'].selectedIndex=0;
        return false;
    }else{
        return true;
    }
}

function submitDelete(myform){
    strMessage = '\n' + lang('Click OK if you are sure you want to delete the selected entries');
    strWorkItems = "";
    intItemChecked=0;

    intCount = document.forms['troubletickets'].elements.length;    
    
    for (x=1;x<=intCount;x++)
    {
        if (document.forms['troubletickets'].elements[x-1].checked == true){
             strWorkItems += document.forms['troubletickets'].elements[x-1].value;
             strWorkItems += " ";
             intItemChecked++;
        }
    }

    var tString;
    String(tString);
    tString = (strWorkItems.substring(0,strWorkItems.length-1));    
    myform.selectedworks.value=tString; 

    var answer=confirm(strMessage);
    if (answer){
        submitonce(myform);
        myform.submit();
    }
}

function submitAdminEntries(myform){
    strWorkItems = "";
    intItemChecked=0;

    for (x=1;x<=intCount;x++)
    {
        if (document.forms['troubletickets'].elements[x-1].checked == true){
             strWorkItems += document.forms['troubletickets'].elements[x-1].value;
             strWorkItems += " ";
             intItemChecked++;
        }
    }

    var tString;
    String(tString);
    tString = (strWorkItems.substring(0,strWorkItems.length-1));
    myform.selectedworks.value=tString;
    submitonce(myform);
    myform.submit();
}

function highPriorityWarning(myform){
    if (myform.options[myform.selectedIndex].value=="1"){
        strMessage = '\n' + lang('Click OK to confirm this is a high priority ticket');
        var answer=confirm(strMessage);
        if (!answer){
            myform.selectedIndex=2;
        }
    }
}

var globalNumberFieldCount = 1;

function Clon(clon)
{
    
    var newId;
    var newName;
    var newValue;

    newField = $(clon).cloneNode(true);
    inputField = newField.getElementsByTagName("input");
    linkDelete = newField.getElementsByTagName("a");
    
    newId = clon + globalNumberFieldCount;
    newName = clon + globalNumberFieldCount;
    newValue = '';
    inputField[0].setAttribute("id", newId);
    inputField[0].setAttribute("name", newName);
    inputField[0].value=newValue;
    linkDelete[0].style.visibility = "visible";
    linkDelete[0].setAttribute("href", "javascript:removefilefield('"+"delete_"+globalNumberFieldCount+"');");

    linkDelete[0].setAttribute("id", "delete_"+globalNumberFieldCount);
    $('fileFieldsContainer').appendChild(newField);
    globalNumberFieldCount++;
 }   

function removefilefield(id){
    $(id).parentNode.parentNode.removeChild($(id).parentNode);
}

function remove(element) 
{
    element.parentNode.parentNode.removeChild(element.parentNode);
}

function itemsFilledOut(form){
    strAlertMessage = lang("You must complete all the fields before proceeding");
    bolShowMessage = false;
    
 	if (typeof document.forms['SupportForm'].messagetype != 'undefined' &&  document.forms['SupportForm'].messagetype.value == 0){
         strAlertMessage += '\n' + lang("Select a valid ticket type");
         bolShowMessage = true;
    }

 	if (typeof document.forms['SupportForm'].subject  != 'undefined' && document.forms['SupportForm'].subject.value == ""){
         strAlertMessage += '\n' + lang("You can not leave the subject blank");
         bolShowMessage = true;
    }

 	if ($('fileFieldsContainer')== null || someFilesFieldsEmpty('fileFieldsContainer')){
        if (typeof document.forms['SupportForm'].message != 'undefined' && document.forms['SupportForm'].message.value == ""){
     		 strAlertMessage += '\n' + lang("You can not leave the message blank");
             bolShowMessage = true;
        }
 	 }

    if (bolShowMessage){
        alert(strAlertMessage);
        return false;
    }

    return true;
}

function CheckForTicketResolution(){
    if($('ticketstatus').value == -1){
        //show the add ticket resolution
        $('divTicketResolution').style.display = "";
    }else{
        //do not show the ticket resolution option
        $('divTicketResolution').style.display = "none";
    }
}

function showResultText(btn, text){
    submitClosedTicket(text, true)
}

function submitTicketLog(form, skipSummaryForm)
{
    if (!itemsFilledOut(form)) {
        return false
    }

    if (skipSummaryForm || form.ticketstatus.value != -1 || form.usertype.value == 0) {
        return true;
    }

    //jsPopup($('divTicketSummary').innerHTML, false);
    Ext.MessageBox.show({
           title: 'Ticket Summary',
           msg: 'Please enter your summary of this ticket:',
           width:400,
           buttons: Ext.MessageBox.OKCANCEL,
           multiline: true,
           fn: showResultText,
           animEl: 'mb3'
       });

    return false;
}

function submitClosedTicket(formtext, saveSummary)
{
    if (saveSummary) {
        document.forms['SupportForm'].ticketSummary.value = formtext;
    }
    
    submitonce(document.forms['SupportForm']);
    document.forms['SupportForm'].submit();
}

function someFilesFieldsEmpty(element) 
{
    var emptyEvaluation = true;
    var arrayPosition = 0;
    
    var newElement = $(element);

    var newArrayCollection = newElement.getElementsByTagName("input");
    
    for(var i=0; i < newArrayCollection.length; i++){

        if(newArrayCollection[i].value != ''){
            emptyEvaluation = false;   
        }
    }
    
    return emptyEvaluation;
}

function changeTicketType(ticketId, getArgs){
	setStatus(lang('Loading related articles and notes'));
    if (!getArgs) {
        getArgs = '';
    }

	var opt = {
		method: 'post',
		postBody: 'ticketId=' + ticketId,
		onSuccess: applyTicketTabs
	}
	new Ajax.Request('index.php?fuse=support&view=GetTicketTabs&mainView='+gView + getArgs, opt);
}
function applyTicketTabs(t){

	var responseArr = t.responseText.split('|');
    if (typeof responseArr[1] == 'undefined' || responseArr[0] != 'OK') {
        alert(t.responseText.stripTags());
        return;
    }
	var content = responseArr[1];
    $('ajaxTabs').innerHTML += content;
    unsetStatus('', 1);     
}

function loadStaffNotesInSupport(selectedId){
	setStatus('Loading Notes');
	var opt = {
		method: 'post',
		postBody: 'selectedId='+selectedId,
		onSuccess: applyStaffNotes
	}		
	new Ajax.Request('index.php?fuse=support&view=TicketNotes', opt);
}

function applyStaffNotes(t){
	if(t.responseText.substr(0, 11) == "selectedId=") {
		$('tickettab_notes_tab').style.display = 'none';
		$('activetickettab').innerHTML = "";
        var ticketId = t.responseText.substr(11);
		cSelectTab('support','TicketTab_Messages','tickettab_messages','tickettab','activetickettab','selectedId=' + ticketId + '&from=ViewTicketDetails');
	}else{
		$('activetickettab').innerHTML = t.responseText;
	}
	unsetStatus('', 1);  
}

function RateArticle(rate)
{
    var articleId = $('articleId').value;
    new Ajax.Request( 'index.php?fuse=knowledgebase&action=KB_RateArticle&rating=' + rate +'&articleId=' + articleId,
                      {
                          onSuccess     : showResponseRateArticle,
                          onComplete    : function(request) {        setStatus(lang('Article Rated'), 500)}
                      }
                    );
}

function showResponseRateArticle(originalRequest)
{				    
    var response = originalRequest.responseText;
    var arrayResponse = response.split("|");
    if (arrayResponse.length >1){
        $("ratearticle").innerHTML = lang("Thank you for rating this article");
    }else{
        alert (arrayResponse);
    }    		
}

function AddComment()
{
    var articleId = $('articleId').value;
    var user = $('userName').value;
    var email = $('userEmail').value;
    var comment = $('userComment').value;
    var pars = '&articleId=' + articleId 
              + '&user=' + user 
              + '&email='+ email 
              + '&comment=' + comment 
              + '&private=0'
    new Ajax.Request( 'index.php?fuse=knowledgebase&action=KB_AddComment',
                      {
                          method        : 'post',
                          parameters    : pars,
                          onSuccess     : showResponseAddComment,
                          onComplete    : function() {        setStatus(lang('Comment Posted'), 500)}
                      }
                    );
}

function showResponseAddComment(originalRequest)
{				    
    var response = originalRequest.responseText;
    var arrayResponse = response.split("|");
    var html = "";
    for (var i = 0; i < arrayResponse.length -1; i++){
        var arrayComments = arrayResponse[i].split('**');
        html = html + "<tr><td colspan='8' style='padding:5px'><i>["+ arrayComments[0] +"] - " + arrayComments[1] +"</i></td></tr><tr><td colspan='8' style='padding:5px'>"+arrayComments[2]+"</td></tr>";
    }		
    window.location.reload( false );
}

function checkEscalationForm()
{
    var isPrioritySelected = false;
    for (var i = 0; i < $('ticketPriority').options.length; i++)
    {
        if ($('ticketPriority').options[i].selected)
        {
            isPrioritySelected = true;
            break;
        }
    }
    
    if (!isPrioritySelected)
    {
        alert(lang("Please select a ticket priority"));
    } else {
        $('escalationForm').submit();
    }
}