var JsonHelper = JsonHelper || {};
JsonHelper.prefix="/main/json/";
JsonHelper.getChildFields=function(entityId, fieldId, parentDicTypeId, async, func){
    this.request('getChildFields', func, {entityId:entityId, fieldId:fieldId, parentDicTypeId:parentDicTypeId}, async);
};
JsonHelper.getFieldById=function(id, async, func){
    this.request('getFieldById', func, {id:id}, async);
};
JsonHelper.getFieldsByEntityId=function(entityId, async, func){
    this.request('getFieldsByEntityId', func, {entityId:entityId}, async);
};
JsonHelper.getFieldsByEntityIdAndTypeId=function(entityId, typeId, async, func){
    this.request('getFieldsByEntityIdAndTypeId', func, {entityId:entityId,typeId:typeId}, async);
};
JsonHelper.getDictionaryItemsByTypeId=function(typeId, async, func){
    this.request('getDictionaryItemsByTypeId', func, {typeId:typeId}, async);
};
JsonHelper.getDictionaryItemsByFieldId=function(fieldId, async, func){
    this.request('getDictionaryItemsByFieldId', func, {fieldId:fieldId}, async);
};
JsonHelper.getDictionaryItemsByOwnerIds=function(childFieldId, ownerIds, async, func){
    this.request('getDictionaryItemsByOwnerIds', func, {childFieldId:childFieldId,ownerIds:ownerIds}, async);
};
JsonHelper.getChildCriteria=function(searchId, criterionId, fieldId, async, func){
    this.request('getChildCriteria', func, {searchId:searchId,criterionId:criterionId,fieldId:fieldId}, async);
};
JsonHelper.getSearchDictionaryItemsByOwnerIds=function(childCriterionId, ownerIds, async, func){
    this.request('getSearchDictionaryItemsByOwnerIds', func, {childCriterionId:childCriterionId,ownerIds:ownerIds}, async);
};
JsonHelper.setSessionAttribute=function(attrName, attrValue, async, func){
    this.request('setSessionAttribute', func, {attrName:attrName,attrValue:attrValue}, async);
};
JsonHelper.getSessionAttribute=function(attrName, func){
    this.request('getSessionAttribute', func, {attrName:attrName}, false);
};
JsonHelper.removeSessionAttribute=function(attrName, async, func){
    this.request('removeSessionAttribute', func, {attrName:attrName}, async);
};
JsonHelper.appendToSessionList=function(listName, value, async, func){
    this.request('appendToSessionList', func, {listName:listName,value:value}, async);
};
JsonHelper.removeFromSessionList=function(listName, value, async, func){
    this.request('removeFromSessionList', func, {listName:listName,value:value}, async);
};
JsonHelper.clearSessionList=function(listName, async, func){
    this.request('clearSessionList', func, {listName:listName}, async);
};
JsonHelper.checkUserPermissions=function(paidItemType, async, func){
    this.request('checkUserPermissions', func, {paidItemType:paidItemType}, async);
};
JsonHelper.checkVacancyPostingPermissions=function(vacancyIds, async, func){
    this.request('checkVacancyPostingPermissions', func, {vacancyIds:vacancyIds}, async);
};
JsonHelper.getAjaxDataTableBeanFromSession=function(sessionAtributeName, async, func){
    this.request('getAjaxDataTableBeanFromSession', func, {sessionAtributeName:sessionAtributeName}, async);
};
JsonHelper.isExternalJobsLoaded=function(enableSimplyHiredJobs, enableIndeedJobs, page, async, func){
    this.request('isExternalJobsLoaded', func, {enableSimplyHiredJobs:enableSimplyHiredJobs,enableIndeedJobs:enableIndeedJobs,page:page}, async);
};
JsonHelper.transliterate=function(value, func){
    this.request('transliterate', func, {value:value}, false);
};
JsonHelper.facebookCheckUserExists=function(uid, func){
    this.request('facebookCheckUserExists', func, {uid:uid}, false);
};
JsonHelper.changeSourceStatus=function(id){
    this.request('changeSourceStatus', null, {id:id}, true);
};
JsonHelper.saveAppMessageByKey=function(key, value){
    this.request('admin/'+'saveAppMessageByKey', null, {key:key,value:value}, true);
};
JsonHelper.request=function(link, func, data, async){
    var params='';
    if(data){
        var hash = new Hash(data);
        hash.each(function(value, key){
            if(value != "undefined" && value!=null){
                if(value instanceof Array){
                    value.each(function(item){params+=key+'='+encodeURIComponent(item)+'&';});
                } else {
                    params+=key+'='+encodeURIComponent(value)+'&';
                }
            }
        });
    }
    new Request.JSON({url: this.prefix+link, noCache:true, headers:{'SpecialAjaxRequest':'true'}, method:'post', data:params, async:async, onSuccess: function(o){
        if(func){
            func(o?o.data:null);
        }
    }}).send();
};
JsonHelper.keepAlive=function(func){
    this.request('keepAlive', func, {}, true);
};

