function checkIfEmpty(fields, errors)
{
    for (i = 0; i < fields.length; i++)
    {
        if (fields[i] == 'points') {
            if ($('#points > li').size() == 0 || $('#point_1 :input').val() == '') {
                alert('حقل '+errors[i]+' فارغ');
                return false;
            }
        } else if ($('#'+fields[i]).val() == '') {
            alert('حقل '+errors[i]+' فارغ');
            return false;
        }
    }

    return true;
}

function editComment(comment_id, section, mainID, session_id, edit_salt, delete_salt, base_url)
{
    comment_text = $('#comment_text_'+comment_id).html();
    comment_text = comment_text.replace(/\n/gi, "");
    comment_text2 = comment_text;
    comment_text = comment_text.replace(/<br>/gi, "\n");
    comment_text = comment_text.replace(/<br \/>/gi, "\n");

    $('#comment_text_'+comment_id).html('<textarea id="new_comment_'+comment_id+'" cols="57" rows="5">'+comment_text+'</textarea>');
    $('#control_comment_'+comment_id).html('<input type="button" value="حفظ" onclick="saja_editComment('+comment_id+', \''+section+'\', '+mainID+', \''+session_id+'\', \''+edit_salt+'\', \''+delete_salt+'\', \''+base_url+'\')" /> | <input type="button" value="إلغاء" onclick="cancelEditComment('+comment_id+', \''+comment_text2+'\', \''+section+'\', '+mainID+', \''+base_url+'\', \''+session_id+'\', \''+edit_salt+'\', \''+delete_salt+'\')" />');
}

function cancelEditComment(comment_id, comment_text, section, mainID, base_url, session_id, edit_salt, delete_salt)
{
    comment_text = comment_text.replace(/\n/gi, "<br />");

    $('#comment_text_'+comment_id).html(comment_text);
    $('#control_comment_'+comment_id).html('&nbsp;(<span class="as_link" onclick="editComment('+comment_id+', \''+section+'\', '+mainID+', \''+session_id+'\', \''+edit_salt+'\', \''+delete_salt+'\', \''+base_url+'\')">تعديل</span> | <span class="as_link" onclick="if (confirm(\'هل أنت متأكد من أنك تريد حذف التعليق؟\')) { deleteComment('+comment_id+', '+mainID+', \''+section+'\', \''+session_id+'\', \''+edit_salt+'\', \''+delete_salt+'\', \''+base_url+'\'); }">حذف</span>)');
}

function saja_editComment(comment_id, section, mainID, session_id, edit_salt, delete_salt, base_url)
{
    $('#comment_text_'+comment_id).append('<br /><span class="ajax_text"><img src="'+base_url+'images/ajax-loader.gif" alt="" /> جاري حفظ التعديل ..</span>');
    $('#control_comment_'+comment_id).html('&nbsp;(<span class="as_link" onclick="editComment('+comment_id+', \''+section+'\', '+mainID+', \''+session_id+'\', \''+edit_salt+'\', \''+delete_salt+'\', \''+base_url+'\')">تعديل</span> | <span class="as_link" onclick="if (confirm(\'هل أنت متأكد من أنك تريد حذف التعليق؟\')) { deleteComment('+comment_id+', '+mainID+', \''+section+'\', \''+session_id+'\', \''+edit_salt+'\', \''+delete_salt+'\', \''+base_url+'\'); }">حذف</span>)');

    saja.run(''+saja.Get(comment_id)+','+saja.Get('new_comment_'+comment_id,'value')+','+saja.Get(section)+'','','','',''+session_id+'',''+edit_salt+'',false);
    //saja.run(saja.Get(comment_id),''+saja.Get('new_comment_'+comment_id,'value')+'',''+section+'','','','',''+session_id+'',''+edit_salt+'',false);
}

function deleteComment(comment_id, section, mainID, session_id, edit_salt, delete_salt, base_url)
{
    $('#comment_text_'+comment_id).append('<br /><span class="ajax_text"><img src="'+base_url+'images/ajax-loader.gif" alt="" /> جاري حذف التعليق ..</span>');

    saja.run(''+saja.Get(comment_id)+','+saja.Get(mainID)+','+saja.Get(section)+'','','','',''+session_id+'',''+delete_salt+'',false);
}

function Ajax_loader2(containID, successID, errorID, buttonID)
{
    $('#'+errorID).css('display', 'none');
    $('#'+successID).css('display', 'none');
    $('#'+containID).css('display', '');
    $('#'+buttonID).attr('disabled', 'true');
}