
function Employee(app){
	this.app = app
	//hacks
	this.conf = new JSON.Document('xmldata', {});
	this.conf.xmldata.options = {title: 'Window', name:'window'};
    this.conf.xmldata.style = {width:'350px', height:'350px', position: 'absolute'};
}

Employee.prototype.open = function(parent){
    var block = new Block(this.app, this.conf);
    var doc = new JSON.Document('packet', JSON.DefaultPacket('employee', 'list'));
    block.loadContent({employee_list:'employee/list.js'},doc,function(){});
}

Employee.prototype._add = function(){
	var conf = new XML.Document('xmldata', {})
	conf.xmldata.options = {title:'Add new employee', modale:"0", name:'newEmployee'}
	conf.xmldata.button = [{image:'close.gif', action:'close'}]
    conf.xmldata.style = {width:'450px', height:'400px', position: 'absolute'}
	var win = new Window(this.app, conf)
	var doc = new XML.Document('packet',  XML.DefaultPacket('employee','get'))
	win.loadContent('employee/add.xsl', doc, function(response){
			var box = new ComboBox($('countryList'), response.xmldata.countryList)
			var box1 = new ComboBox($('languageList'), response.xmldata.language_list,'lid')			
		}.bind(this)
	)
}

Employee.prototype.add = function(form){
	var doc = new XML.Document('packet', XML.DefaultPacket('employee', 'add'))
	doc.packet.xmldata = this.app.parseForm(form).form
	doc.packet.xmldata.country.cdata = $('countryList').getAttribute('param')
	var req = new XML.Request( function(response){
		if(response.packet.type == "response"){
			this.app.getWindowByName('newEmployee').close()
			this.app.status("new employee has been added")
			this.app.getWindowByName('employeeList').refresh()
		} else {
			var conf = new XML.Document('xmldata', {})
		conf.xmldata.options = {title: 'Error', modale:"1"}
			conf.xmldata.button = [{image:'close.gif', action:'close'}]
		    conf.xmldata.style = {width:'300px', height:'150px', position: 'absolute'}

			var win = new Window(this.app, conf)
			var doc = new XML.Document('xmldata', response.packet.xmldata)
			win.setContent('error.xsl', doc)

		}
	}.bind(this))
	req.send(this.app.server, doc)
}

Employee.prototype._edit = function(uid, name){
	var win = new Window(this.app, this.conf)
	var doc = new JSON.Document('packet', JSON.DefaultPacket('employee', 'get'))
	doc.packet.query.uid = uid
	doc.packet.query.info = 'true';
	win.loadContent({employee_edit:'employee/edit.js'},doc,function(){});
}

Employee.prototype.edit = function(uid, form){
	var doc = new XML.Document('packet', XML.DefaultPacket('employee', 'update'))
	doc.packet.xmldata = this.app.parseForm(form).form
	doc.packet.xmldata.country.cdata = $('countryList').getAttribute('param')
	var req = new XML.Request( function(response){
		if(response.packet.type == "response"){
			this.app.status("employee has been updated")
			this.app.getWindowByName('employeeList').refresh()
			this.app.getWindowByName('employee_'+uid).close()
		} else {
			this.app.showError(response.packet.xmldata)
		}
	}.bind(this))
	req.send(this.app.server, doc)
}

Employee.prototype._remove = function(uid){
	var doc = new XML.Document('packet', XML.DefaultPacket('employee', 'remove'))
	doc.packet.xmldata.uid = uid
	var req = new XML.Request( function(response){
		if(response.packet.type == "response"){
			this.app.getWindowByName('employee_'+uid).close()
			this.app.status("employee has been removed")
			this.app.getWindowByName('employeeList').refresh()
		} else {
			var conf = new XML.Document('xmldata', {})
			conf.xmldata.options = {title: 'Error', modale:"1"}
			conf.xmldata.button = [{image:'close.gif', action:'close'}]
		    conf.xmldata.style = {width:'300px', height:'150px', position: 'absolute'}

			var win = new Window(this.app, conf)
			var doc = new XML.Document('xmldata', response.packet.xmldata)
			win.setContent('error.xsl', doc)
		}
	}.bind(this))
	req.send(this.app.server, doc)
}

Employee.prototype.uploadPhoto = function(uid,id){
	var box = new uploadBox(this.app, [{name:'uid', value:uid}, {name:'module', value:'employee'}], function(url){		
		$('employee_photo').src = url+'?'+random();
		if(id){
			$(id+'_pic').value='1';
		}
		this.app.getWindowByName('uploadBox').close()
	}.bind(this))
}
