setTarget = function() {
		var path = window.location.pathname;
		var lang = getLang().toUpperCase()||'ENG';
		var module ;
		file_name = 'JSON/CENTER_SWAPLANG.json';
		if(path.substring(0, path.lastIndexOf( "/" ))!=='/hr'){
			module = path.substring( path.indexOf( "/" ,1)+1, path.lastIndexOf( "/" ));
		//	console.log("module : "+module);
			if( module =='WORKFLOW' || module =='WORKFLOW_ADMIN' ){
				module = 'CENTER';
			}
			file_name = '../JSON/'+module+'_SWAPLANG.json';
		//	console.log("file_name : "+file_name);
		}
		return file_name;
	};

	setTargetBySite = function() {
		var swlang = getSwapLang().toUpperCase();
		if(swlang!=''){
			swlang = swlang+'/';
		}
		var path = window.location.pathname;
		var lang = getLang().toUpperCase()||'ENG';
		var module ;
		file_name_site = 'JSON/'+swlang+'CENTER_SWAPLANG.json';
		if(path.substring(0, path.lastIndexOf( "/" ))!=='/hr'){
			module = path.substring( path.indexOf( "/" ,1)+1, path.lastIndexOf( "/" ));
			if( module =='WORKFLOW' || module =='WORKFLOW_ADMIN' ){
				module = 'CENTER';
			}
			file_name_site = '../JSON/'+swlang+module+'_SWAPLANG.json';
		//	console.log("file_name_site : "+file_name_site);
		}
		return file_name_site;
	};

	setJSON = function() {
		jsonObj = null;
		if(window.ActiveXObject) {
		/*	objDOM = new ActiveXObject("Msxml.DOMDocument");
			objDOM.async = false;
			objDOM.load(file_name);	*/
		} else if(window.XMLHttpRequest) {
			var jsonDoc = new XMLHttpRequest();
			jsonDoc.open('GET', file_name ,false);
			try { jsonDoc.responseType = 'json'; } catch(e){}
			jsonDoc.send(null);
			jsonData = jsonDoc.response;
			jsonObj = JSON.parse(jsonData);
		//	console.log("jsonObj1 : "+jsonObj["SW100002"]["eng"]);
		}
		return jsonObj;
	};

	setJSONBySite = function() {
		jsonObj_site = null;
		if(file_name != file_name_site){
			if(window.ActiveXObject) {
			/*	objDOM = new ActiveXObject("Msxml.DOMDocument");
				objDOM.async = false;
				objDOM.load(file_name_site);	*/
			} else if(window.XMLHttpRequest) {
				var jsonDoc = new XMLHttpRequest();
				jsonDoc.open('GET', file_name_site ,false);
				try { jsonDoc.responseType = 'json'; } catch(e){}
				jsonDoc.send(null);
				jsonData = jsonDoc.response;
				jsonObj_site = JSON.parse(jsonData);
			//	console.log("jsonObj2 : "+jsonObj_site["SW100002"]["eng"]);
			}
		}
		return jsonObj_site;
	};

	var swaplang = function() {
		var file_name = setTarget();
		var file_name_site = setTargetBySite();
		var jsonObj = setJSON();
		var jsonObj_site = setJSONBySite();
	//	console.log("jsonObj : "+jsonObj);
	//	console.log("jsonObj_site : "+jsonObj_site);
	};

	swaplang.prototype.swap2String = function(code){
		var lang = getLang().toLowerCase()
		var result = "";
		try{
			if(jsonObj_site!=null){
				result = jsonObj_site[code][lang];
			}else{
				result = jsonObj[code][lang];
			}
		}catch(e){
			try{
				result = jsonObj[code][lang];
			}catch(e){
				console.log("can't find code : "+code+" : "+lang);
			}
		}
		return result;
	};

	swaplang.prototype.write = function(code) {
		return this.swap2String(code);
	};

	var mySwapLang = null;
	if(getLang()!=""){
		mySwapLang = new swaplang();
	}

	var myhr = angular.module('myHR', [])

	myhr.controller('Swaplang', swaplang);

  	myhr.directive('swlang', function() {
		var directive = {};
		directive.restrict = 'A';
		directive.template = "";
		directive.compile = function(element, attributes) {
		var linkFunction = function($scope, element, attributes) {
			if(mySwapLang==null){
				mySwapLang = new swaplang();
			}
			element.html(mySwapLang.swap2String(element.attr("code")));
		}
		return linkFunction;
		}
		return directive;
	});

	myhr.directive('swaplang', function() {
		var directive = {};
		directive.restrict = 'E';
		directive.template = "";
		directive.compile = function(element, attributes) {
		var linkFunction = function($scope, element, attributes) {
			if(mySwapLang==null){
				mySwapLang = new swaplang();
			}
			element.html(mySwapLang.swap2String(element.attr("code")));
		}
		return linkFunction;
		}
		return directive;
	});

	myhr.directive('swaplang2', function(){
		var directive = {};
		directive.restrict = 'E';
		directive.template = '';
		directive.compile = function(element, attributes){
			var linkfunc = function($scope, element, attributes){
				if (mySwapLang == null){
					mySwapLang = new swaplang();
				}
				element.html(mySwapLang.swap2String(attributes.code));
			}
			return linkfunc;
		}
		return directive;
	});