
InfoUtils = {
	infoURL: "mvinfo.cgi",
	dataInfoURL: "mvdatainfo.cgi",
	
	BuildInfoLoaded: "Utils.BuildInfoLoaded",
	BuildInfoFailed: "Utils.BuildInfoFailed",
	OrgNotesLoaded: "Utils.OrgNotesLoaded",
	OrgNotesFailed: "Utils.OrgNotesFailed",
	ChromInfoLoaded: "Utils.ChromInfoLoaded",
	ChromInfoFailed: "Utils.ChromInfoFailed",
	AsmbInfoLoaded: "Utils.AsmbInfoLoaded",
	AsmbInfoFailed: "Utils.AsmbInfoFailed",

	getBuildInfo: function(taxid, build, env)
	{
		var rq = {taxid:taxid, build:build, env:env, rq:"org"};
		var onLoad = function(el){
			var build = new Utils.XMLObject(el, InfoUtils.model.BuildInfo);
			Notification.postNotification(InfoUtils.BuildInfoLoaded, this, {request:rq, object:build});
		}
		var onError = function(error, arg){
			Notification.postNotification(InfoUtils.BuildInfoFailed, this, {request:rq, errorCode:error, errorInfo:arg});
		}
		Utils.sendHTTPRequest(Utils.dir + "/" + InfoUtils.infoURL, rq, this, onLoad, onError);
	},
	getOrgNotes: function(taxid)
	{
		var rq = {taxid:taxid, rq:"org-notes"};
		var onLoad = function(el){
			var info = null;
			try{
				info = new Utils.XMLObject(el, InfoUtils.model.OrgNotes);
			}catch(e){
				
			}
			Notification.postNotification(InfoUtils.OrgNotesLoaded, this, {request:rq, object:info.org_note});
		}
		var onError = function(error, arg)
		{
			Notification.postNotification(InfoUtils.OrgNotesFailed, this, {request:rq, errorCode:error, errorInfo:arg});
		}
		Utils.sendHTTPRequest(Utils.dir + "/" + InfoUtils.infoURL, rq, this, onLoad, onError);
	},
	getChromosomes: function(taxid, build, env)
	{
		var rq = {taxid:taxid, build:build, env:env, rq:"chr"};
		var onLoad = function(el){
			var object = null;
			try{
				object = new Utils.XMLObject(el, InfoUtils.model.ChromInfo);
			}catch(e){
				
			}
			Notification.postNotification(InfoUtils.ChromInfoLoaded, this, {request:rq, object:object});
		}
		var onError = function(error, arg)
		{
			Notification.postNotification(InfoUtils.ChromInfoFailed, this, {request:rq, errorCode:error, errorInfo:arg});
		}
		Utils.sendHTTPRequest(Utils.dir + "/" + InfoUtils.dataInfoURL, rq, this, onLoad, onError);
	},
	getAssemblies: function(taxid, build, env)
	{
		var rq = {taxid:taxid, build:build, env:env, rq:"asmb"};
		var onLoad = function(el){
			var object = null;
			try{
				object = new Utils.XMLObject(el, InfoUtils.model.AsmbInfo);
			}catch(e){
			
			}
			Notification.postNotification(InfoUtils.AsmbInfoLoaded, this, {request:rq, object:object});
		}
		var onError = function(error, arg)
		{
			Notification.postNotification(InfoUtils.AsmbInfoFailed, this, {request:rq, errorCode:error, errorInfo:arg});
		}
		Utils.sendHTTPRequest(Utils.dir + "/" + InfoUtils.dataInfoURL, rq, this, onLoad, onError);
	}
};

InfoUtils.model = {
	BuildInfo: {
		org: {objectClass:Utils.XMLObject, entity:"InfoUtils.model.BuildInfo_Org"},
		build: {objectClass:Utils.XMLObject, entity:"InfoUtils.model.BuildInfo_Build"},
		urls: {objectClass:Utils.XMLObject, entity:"InfoUtils.model.BuildInfo_Urls"}
	},

	BuildInfo_Org: {
		"internal-name": {name: "internalName"},
		"common-name": {name: "commonName"},
		"sc-name": {name: "scname"},
		attributes: {taxid:Number}
	},

	BuildInfo_Build: {
		"short-name": {name: "shortName"},
		name: {name: "commonName"},
		attributes: {taxid:Number, build:Number, previous:Utils.Boolean, current:Utils.Boolean, version:Number}
	},
	BuildInfo_Urls: {


	},
	
	OrgNotes: {
		org_note: {objectClass:Utils.XMLObject, entity:"InfoUtils.model.OrgNotes_Note"},
		error: {objectClass:Utils.String}
	},
	OrgNotes_Note: {
		attributes: {taxid:Number, title:String},
		text: { }
	},
	
	
	ChromInfo: {
		chromosomes: {objectClass:Utils.XMLObject, entity:"InfoUtils.model.ChromInfo_ChrList"},
		build: {objectClass:Utils.XMLObject, entity:"InfoUtils.model.ChromInfo_Build"}
	},
	ChromInfo_ChrList: {
		chr: {objectClass: Utils.XMLObject, array:true, entity:"InfoUtils.model.ChromInfo_Chr"}
	},
	ChromInfo_Chr: {
		attributes: {chr:String, order:Number, chr_name:String, is_mt:Utils.Boolean, is_un:Utils.Boolean, nodata:Utils.Boolean, length:{name:"l", objectClass:Number}},
		seq: {objectClass: Utils.XMLObject, array:true, entity:"InfoUtils.model.ChromInfo_Seq"}
	},
	ChromInfo_Seq: {
		attributes: {"assembly-id":{objectClass:Number, name:"uid"}, length:{objectClass:Number, name:"l"}, accession:String, gi:String}
	},
	ChromInfo_Build: {
		attributes:{available:Utils.Boolean, has_chrs:Utils.Boolean, new_schema_text:Utils.Boolean, taxid:Number, build:Number, version:Number}
	},
	AsmbInfo: {
		org: {objectClass:Utils.XMLObject, entity: "InfoUtils.model.AsmbInfo_Org"},
		build: {objectClass:Utils.XMLObject, entity:"InfoUtils.model.AsmbInfo_Build"},
		assemblies: {objectClass:Utils.XMLObject, entity:"InfoUtils.model.AsmbInfo_AssemblyList"}
	},
	AsmbInfo_Org: {
		attributes: {taxid:String}
	},
	AsmbInfo_Build: {
		attributes: {taxid:Number, build:Number, version:Number}
	},
	AsmbInfo_AssemblyList: {
		assembly: {objectClass:Utils.XMLObject, array:true, entity:"InfoUtils.model.AsmbInfo_Assembly"}
	},
	AsmbInfo_Assembly: {
		attributes: {"assembly-id":{objectClass:String, name:"uid"}, complete:Utils.Boolean, description:String, name:String, reference:Utils.Boolean, "short-name":{objectClass:String, name:"shortName"}}
	}
	
};
