// Lewjax character info widget stuff
// dependencies: lewjax.xmlwriter.js, lewpops.js

function charpop(e,id) {
return false;
	if (arguments.length==3) {
		var posx = arguments[2][0];
		var posy = arguments[2][1];
	}
	else {
		var posx = mousex(e);
		var posy = mousey(e);
	}
	
	this.loadcheck=[0,0,0,0];  //skills , profs, items, char

	this.charstats = new ljDialog(null, 260, 350, posy+10, posx+10 );
	this.charstats.constructGraphical('/images/charpopbg.png');
	this.charstats.setTitle('Character details','bold 12px Verdana', '18px');
	this.itempopup = new ljDialog(null, 50, 50);
	this.itempopup.bgcolor='000000';
	this.itempopup.bordercolor='cccccc';
	this.itempopup.titlebgcolor='000000';
	this.itempopup.bgopacity='80';
	this.itempopup.titlebordercolor='000000';
	this.itempopup.titleopacity='80';
	this.itempopup.titleborderopacity='80';
	this.itempopup.constructTitleless();
	this.itempopup.loader = new lewjax();
	var xbtn = newElement('div',[],'position: absolute; top: 3px; left: 229px; overflow: hidden; width: 28px; height: 15px; x-background: url(/images/charpopxbtn.gif);',[newElement('img',[['src', '/images/charpopxbtn.gif']],'')],[['click',associateObjWithEvent(this,'destroy',null)],['mouseover', function() {xbtn.childNodes[0].style.marginLeft='-28px';}],['mouseout', function() {xbtn.childNodes[0].style.marginLeft='0px';}]]);
	this.charstats.dialog.appendChild(xbtn);
	this.charstats.show();
	this.charloader =  new lewjax();
	this.skillloader =  new lewjax();
	this.profloader =  new lewjax();
	this.itemloader =  new lewjax();
	
	this.characterid = id;
	this.skillloader.onstart = associateObjWithEvent(this,'loadstart',null);
	this.skillloader.handler = 'simpledata';
//	this.skillloader.debug = true;
	this.skillloader.callback = associateObjWithEvent(this,'loadskills',null);
	var xmldoc = new xmlWriter('query');
	xmldoc.writeAttribute('src', 'characterskills');
	xmldoc.startElement('queryparams');
	xmldoc.startElement('param');
	xmldoc.writeAttribute('name','characterid');
	xmldoc.writeText(id);
	xmldoc.endElement('param');
	xmldoc.endElement('queryparams');
	xmldoc.startElement('fieldset');
	addfields(xmldoc, ['category_key', 'category_name', 'key', 'name', 'value', 'max']);
	this.skillloader.send(xmldoc.compile());

	this.profloader.handler = 'simpledata';
//	this.profloader.debug = true;
	this.profloader.callback = associateObjWithEvent(this,'loadprofs',null);
	var xmldoc = new xmlWriter('query');
	xmldoc.writeAttribute('src', 'characterprofs');
	xmldoc.startElement('queryparams');
	xmldoc.startElement('param');
	xmldoc.writeAttribute('name','characterid');
	xmldoc.writeText(id);
	xmldoc.endElement('param');
	xmldoc.endElement('queryparams');
	xmldoc.startElement('fieldset');
	addfields(xmldoc, ['key', 'name', 'skill', 'maxskill']);
	this.profloader.send(xmldoc.compile());

	this.itemloader.handler = 'simpledata';
//	this.itemloader.debug = true;
	this.itemloader.callback = associateObjWithEvent(this,'loaditems',null);
	var xmldoc = new xmlWriter('query');
	xmldoc.writeAttribute('src', 'characteritems');
	xmldoc.startElement('queryparams');
	xmldoc.startElement('param');
	xmldoc.writeAttribute('name','characterid');
	xmldoc.writeText(id);
	xmldoc.endElement('param');
	xmldoc.endElement('queryparams');
	xmldoc.startElement('fieldset');
	addfields(xmldoc, ['durability', 'gem0id', 'gem1id', 'gem2id', 'icon', 'id', 'maxdurability', 'permanentenchant', 'randompropertiesid', 'seed', 'slot']);
	this.itemloader.send(xmldoc.compile());

	
	this.charloader.handler = 'simpledata';
//	this.charloader.debug = true;
	this.charloader.callback = associateObjWithEvent(this,'loadchar',null);
	var xmldoc = new xmlWriter('query');
	xmldoc.writeAttribute('src', 'characterinfo');
	xmldoc.startElement('queryparams');
	xmldoc.startElement('param');
	xmldoc.writeAttribute('name','characterid');
	xmldoc.writeText(id);
	xmldoc.endElement('param');
	xmldoc.endElement('queryparams');
	xmldoc.startElement('fieldset');
	addfields(xmldoc, ['battlegroup', 'class', 'classid', 'faction', 'factionid', 'gender', 'genderid', 'guildname', 'lastmodified', 'level', 'name', 'race', 'raceid', 'realm', 'title', 'talent_tree1', 'talent_tree2', 'talent_tree3', 'honorablekills', 'health', 'secondbar_casting', 'secondbar_effective', 'secondbar_notcasting', 'secondbar_type', 'strength_attack', 'strength_base', 'strength_block', 'strength_effective', 'agility_armor', 'agility_attack', 'agility_base', 'agility_crithitpercent', 'agility_effective', 'stamina_base', 'stamina_effective', 'stamina_health', 'stamina_petbonus', 'intellect_base', 'intellect_crithitpercent', 'intellect_effective', 'intellect_mana', 'intellect_petbonus', 'spirit_base', 'spirit_effective', 'spirit_healthregen', 'spirit_manaregen', 'armor_base', 'armor_effective', 'armor_percent', 'armor_petbonus', 'res_arcane_petbonus', 'res_arcane', 'res_fire_petbonus', 'res_fire', 'res_frost_petbonus', 'res_frost', 'res_holy_petbonus', 'res_holy', 'res_nature_petbonus', 'res_nature', 'res_shadow_petbonus', 'res_shadow', 'melee_mainhand_skill_rating', 'melee_mainhand_skill', 'melee_offhand_skill_rating', 'melee_offhand_skill', 'melee_mainhand_damage_dps', 'melee_mainhand_damage_max', 'melee_mainhand_damage_min', 'melee_mainhand_damage_percent', 'melee_mainhand_damage_speed', 'melee_offhand_damage_dps', 'melee_offhand_damage_max', 'melee_offhand_damage_min', 'melee_offhand_damage_percent', 'melee_offhand_damage_speed', 'melee_mainhand_speed_hastepercent', 'melee_mainhand_speed_hasterating', 'melee_mainhand_speed', 'melee_offhand_speed_hastepercent', 'melee_offhand_speed_hasterating', 'melee_offhand_speed', 'melee_power_base', 'melee_power_effective', 'melee_power_increaseddps', 'melee_hitrating_increasedhitpercent', 'melee_hitrating', 'melee_critchance_percent', 'melee_critchance_pluspercent', 'melee_critchance_rating', 'ranged_skill_rating', 'ranged_skill', 'ranged_damage_dps', 'ranged_damage_max', 'ranged_damage_min', 'ranged_damage_percent', 'ranged_damage_speed', 'ranged_speed_hastepercent', 'ranged_speed_hasterating', 'ranged_speed', 'ranged_power_base', 'ranged_power_effective', 'ranged_power_increaseddps', 'ranged_power_petattack', 'ranged_power_petspell', 'ranged_hitrating_increasedhitpercent', 'ranged_hitrating', 'ranged_critchance_percent', 'ranged_critchance_pluspercent', 'ranged_critchance_rating', 'spell_bonusdamage_arcane', 'spell_bonusdamage_fire', 'spell_bonusdamage_frost', 'spell_bonusdamage_holy', 'spell_bonusdamage_nature', 'spell_bonusdamage_shadow', 'spell_bonusdamage_pet_attack', 'spell_bonusdamage_pet_damage', 'spell_bonusdamage_pet_fromtype', 'spell_bonushealing', 'spell_hitrating_increasedhitpercent', 'spell_hitrating', 'spell_critchance_rating', 'spell_critchance_arcane', 'spell_critchance_fire', 'spell_critchance_frost', 'spell_critchance_holy', 'spell_critchance_nature', 'spell_critchance_shadow', 'spell_penetration', 'spell_manaregen_casting', 'spell_manaregen_notcasting', 'defense_armor_base', 'defense_armor_effective', 'defense_armor_percent', 'defense_armor_petbonus', 'defense_decreasepercent', 'defense_increasepercent', 'defense_plusdefense', 'defense_rating', 'defense', 'defense_dodge_increasepercent', 'defense_dodge_percent', 'defense_dodge_rating', 'defense_parry_increasepercent', 'defense_parry_percent', 'defense_parry_rating', 'defense_block_increasepercent', 'defense_block_percent', 'defense_block_rating', 'defense_resilience_damagepercent', 'defense_resilience_hitpercent', 'defense_resilience']);
	this.charloader.send(xmldoc.compile());

}

function charpopbyname(e, name) {
return false;
	this.loader = new lewjax();
	this.loader.handler = 'simpledata';
//	this.loader.debug = true;
	this.pos = mousexy(e);
	this.charObj=null;
	this.loader.callback = associateObjWithEvent(this,'loadcharbyname',null);
	var xmldoc = new xmlWriter('query');
	xmldoc.writeAttribute('src', 'charname2id');
	xmldoc.startElement('queryparams');
	xmldoc.startElement('param');
	xmldoc.writeAttribute('name','charactername');
	xmldoc.writeText(name);
	xmldoc.endElement('param');
	xmldoc.endElement('queryparams');
	xmldoc.startElement('fieldset');
	addfields(xmldoc, ['id', 'name']);
	this.loader.send(xmldoc.compile());
}

charpopbyname.prototype.loadcharbyname = function(rxml) {
	if (rxml.childNodes[0].childNodes[1].childNodes.length != 1)
		alert('Character not found.');
	else 
		this.charObj = new charpop(null, rxml.childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].nodeValue, this.pos);
}

charpop.prototype.destroy = function () {
	this.charstats.destroy();
	this.charstats=null;
}

charpop.prototype.loadskills = function(rxml) {
	this.loadcheck[0] = 1;
	this.skills = rxml.childNodes[0].childNodes;
	if (this.loadcheck[0]+this.loadcheck[1]+this.loadcheck[2]+this.loadcheck[3] == 4)
		this.populate(this.charxml);
}
charpop.prototype.loadprofs = function(rxml) {
	this.loadcheck[1] = 1;
	this.profs = rxml.childNodes[0].childNodes;
	if (this.loadcheck[0]+this.loadcheck[1]+this.loadcheck[2]+this.loadcheck[3] == 4)
		this.populate(this.charxml);
}
charpop.prototype.loaditems = function(rxml) {
	this.loadcheck[2] = 1;
	this.items = rxml.childNodes[0].childNodes;
	if (this.loadcheck[0]+this.loadcheck[1]+this.loadcheck[2]+this.loadcheck[3] == 4)
		this.populate(this.charxml);
}

charpop.prototype.loadchar = function(rxml) {
	this.loadcheck[3] = 1;
	this.charxml = rxml;
	if (this.loadcheck[0]+this.loadcheck[1]+this.loadcheck[2]+this.loadcheck[3] == 4)
		this.populate(this.charxml);
}

charpop.prototype.populate = function(rxml) {
	this.loadstop();
	var data = rxml.childNodes[0]; // response/data
	if (data.childNodes[1].childNodes.length != 1) {
		var ecanvas = newElement('div',[],'width: '+this.charstats.width+'px; text-align: center; position: absolute; top: 50px; font: bold 10px verdana', [document.createTextNode('Sorry, I was unable to find those character details :(')]);
		this.charstats.dialog.appendChild(ecanvas);
		return false;
	}
	var row = data.childNodes[1].childNodes[0].childNodes;
	var headings = data.childNodes[0].childNodes;
	this.colheadings = new Array();
	for (var i=0;i<headings.length;i++) {
		this.colheadings[this.colheadings.length] = data.childNodes[0].childNodes[i].childNodes[0].nodeValue;
	}
	
	this.currentrow = row;
	this.charstats.dialog.appendChild(newElement('img', [['src','http://www.wow-supreme.com/armoryicons.php?icon='+this.getfieldbyname('genderid')+'-'+this.getfieldbyname('raceid')+'-'+this.getfieldbyname('classid')+'&type=portrait&resize=33x33&extra='+( ( parseInt(this.getfieldbyname('level')) == 70 )? 'wow-70':((parseInt(this.getfieldbyname('level')) >= 10 )? 'wow' : 'wow-default'))]], 'display: block; position: absolute; top: 30px; left: 48px; width: 33px; height: 33px'));
	this.charstats.dialog.appendChild(newElement('img', [['src','/images/charpopportraitframe.png'], ['className', 'alphapng']], 'display: block; position: absolute; top: 24px; left: 42px; width: 45px; height: 45px'));
	
	// char name/race/level etc
	var charchar = newElement('div', [], 'position: absolute; top: 24px; left: 90px; width: 166px; height: 44px; overflow: hidden;', 
		[
		newElement('div', null, 'font: bold 12px Verdana', 
			[
			document.createTextNode(this.getfieldbyname('name'))
			]),
		newElement('div', null, 'font: normal 10px Verdana',
			[
			document.createTextNode(this.getfieldbyname('level')+' '+this.getfieldbyname('race')+' '+this.getfieldbyname('class'))
			]),
		newElement('div', [['innerHTML','('+this.getfieldbyname('talent_tree1')+'/'+this.getfieldbyname('talent_tree2')+'/'+this.getfieldbyname('talent_tree3')+' - <span style="color: #6ca7b9">'+getbuildname(this.getfieldbyname('classid'),this.getfieldbyname('talent_tree1'),this.getfieldbyname('talent_tree2'),this.getfieldbyname('talent_tree3'))+'</span>)']], 'font: normal 10px Verdana')
		]);
	this.charstats.dialog.appendChild(charchar);
	
	//health/2nd bars
	this.charstats.dialog.appendChild( newElement('div', null, 'position: absolute; border: 1px solid #000; top: 74px; left: 42px; width: 176px; height: 11px; font: normal 9px Verdana; overflow: hidden; color: #fff; background: url(/images/charpopbarhealthbg.gif); text-align: center', [document.createTextNode(this.getfieldbyname('health'))]) );
	this.charstats.dialog.appendChild( newElement('div', null, 'position: absolute; border: 1px solid #000; top: 88px; left: 42px; width: 176px; height: 11px; font: normal 9px Verdana; overflow: hidden; color: #fff; background: url(/images/charpopbar'+((this.getfieldbyname('secondbar_type') == 'e')? 'energy' : ((this.getfieldbyname('secondbar_type') == 'm')? 'mana' : 'rage'))+'bg.gif); text-align: center', [document.createTextNode(this.getfieldbyname('secondbar_effective'))]) );
	
	// itemslots
	for (i=0;i<=18;i++) {
		this.addslot(i);
	}

	// Professions/skills
	if(this.profs[1].childNodes.length>0) {
		this.charstats.dialog.appendChild( newElement('div', null, 'position: absolute; top: 125px; left: 42px; height: 14px; width: 77px; text-align: left; font: normal 9px Verdana; color: #fff', [document.createTextNode(this.profs[1].childNodes[0].childNodes[1].childNodes[0].nodeValue)]) );
		this.charstats.dialog.appendChild( newElement('div', null, 'position: absolute; top: 125px; left: 120px; width: 99px; height: 11px; border: 1px solid #000; background: url(/images/charpopbarprofbg.gif); overflow: hidden') );
		this.charstats.dialog.appendChild( newElement('div', null, 'font: normal 9px Verdana; text-align: center; color: #fff; position: absolute; top: 125px; left: 120px; width: 99px; height: 11px; border: 1px solid #000; background: url(/images/charpopbarprof'+((this.profs[1].childNodes[0].childNodes[2].childNodes[0].nodeValue >= this.profs[1].childNodes[0].childNodes[3].childNodes[0].nodeValue)? '': 'in' )+'complete.gif); background-repeat: no-repeat; overflow: hidden; background-position: -'+Math.floor(99-((this.profs[1].childNodes[0].childNodes[2].childNodes[0].nodeValue/this.profs[1].childNodes[0].childNodes[3].childNodes[0].nodeValue)*99))+'px 0px;', [document.createTextNode(this.profs[1].childNodes[0].childNodes[2].childNodes[0].nodeValue+'/'+this.profs[1].childNodes[0].childNodes[3].childNodes[0].nodeValue)]));
	}
	if(this.profs[1].childNodes.length>1) {
		this.charstats.dialog.appendChild( newElement('div', null, 'position: absolute; top: 141px; left: 42px; height: 14px; width: 77px; text-align: left; font: normal 9px Verdana; color: #fff', [document.createTextNode(this.profs[1].childNodes[1].childNodes[1].childNodes[0].nodeValue)]) );
		this.charstats.dialog.appendChild( newElement('div', null, 'position: absolute; top: 141px; left: 120px; width: 99px; height: 11px; border: 1px solid #000; background: url(/images/charpopbarprofbg.gif); overflow: hidden') );
		this.charstats.dialog.appendChild( newElement('div', null, 'font: normal 9px Verdana; text-align: center; color: #fff; position: absolute; top: 141px; left: 120px; width: 99px; height: 11px; border: 1px solid #000; background: url(/images/charpopbarprof'+((this.profs[1].childNodes[1].childNodes[2].childNodes[0].nodeValue >= this.profs[1].childNodes[1].childNodes[3].childNodes[0].nodeValue)? '': 'in' )+'complete.gif); overflow: hidden; background-position: -'+Math.floor(99-((this.profs[1].childNodes[1].childNodes[2].childNodes[0].nodeValue/this.profs[1].childNodes[1].childNodes[3].childNodes[0].nodeValue)*99))+'px 0px; background-repeat: no-repeat;', [document.createTextNode(this.profs[1].childNodes[1].childNodes[2].childNodes[0].nodeValue+'/'+this.profs[1].childNodes[1].childNodes[3].childNodes[0].nodeValue)]));
	}
	var firstaid = getfirstaid(this.skills);
	this.charstats.dialog.appendChild( newElement('div', null, 'position: absolute; top: 157px; left: 42px; height: 14px; width: 77px; text-align: left; font: normal 9px Verdana; color: #fff', [document.createTextNode('First aid')]) );
	this.charstats.dialog.appendChild( newElement('div', null, 'position: absolute; top: 157px; left: 120px; width: 99px; height: 11px; border: 1px solid #000; background: url(/images/charpopbarprofbg.gif); overflow: hidden') );
	this.charstats.dialog.appendChild( newElement('div', null, 'font: normal 9px Verdana; text-align: center; color: #fff; position: absolute; top: 157px; left: 120px; width: 99px; height: 11px; border: 1px solid #000; background: url(/images/charpopbarprof'+((firstaid[0] >= firstaid[1])? '':'in')+'complete.gif); background-repeat: no-repeat; background-position: -'+(99-((firstaid[0]/firstaid[1])*99))+'px 0px; overflow: hidden', [document.createTextNode(firstaid[0]+'/'+firstaid[1])]) );
	
	//stats
	
	// stats control
	
	var bdmax = 0;
	if (parseInt(this.getfieldbyname('spell_bonusdamage_arcane')) > bdmax)
		bdmax = this.getfieldbyname('spell_bonusdamage_arcane');
	if (parseInt(this.getfieldbyname('spell_bonusdamage_fire')) > bdmax)
		bdmax = this.getfieldbyname('spell_bonusdamage_fire');
	if (parseInt(this.getfieldbyname('spell_bonusdamage_frost')) > bdmax)
		bdmax = this.getfieldbyname('spell_bonusdamage_frost');
	if (parseInt(this.getfieldbyname('spell_bonusdamage_holy')) > bdmax)
		bdmax = this.getfieldbyname('spell_bonusdamage_holy');
	if (parseInt(this.getfieldbyname('spell_bonusdamage_nature')) > bdmax)
		bdmax = this.getfieldbyname('spell_bonusdamage_nature');
	if (parseInt(this.getfieldbyname('spell_bonusdamage_shadow')) > bdmax)
		bdmax = this.getfieldbyname('spell_bonusdamage_shadow');

	var ccmax = 0;
	if (parseInt(this.getfieldbyname('spell_critchance_arcane'))>ccmax)
		ccmax = this.getfieldbyname('spell_critchance_arcane');
	if (parseInt(this.getfieldbyname('spell_critchance_fire'))>ccmax)
		ccmax = this.getfieldbyname('spell_critchance_fire');
	if (parseInt(this.getfieldbyname('spell_critchance_frost'))>ccmax)
		ccmax = this.getfieldbyname('spell_critchance_frost');
	if (parseInt(this.getfieldbyname('spell_critchance_holy'))>ccmax)
		ccmax = this.getfieldbyname('spell_critchance_holy');
	if (parseInt(this.getfieldbyname('spell_critchance_nature'))>ccmax)
		ccmax = this.getfieldbyname('spell_critchance_nature');
	if (parseInt(this.getfieldbyname('spell_critchance_shadow'))>ccmax)
		ccmax = this.getfieldbyname('spell_critchance_shadow');

	var scc = newElement('div', null, 'position: absolute; top: 195px; left: 44px; width: 175px; height: 115px; overflow: hidden;',
		[
		newElement('div', null, 'position: absolute; top: 0px; left: 20px; width: 133px; height: 16px; border: 1px solid #cacaca; font: normal 10px Verdana; text-align: center; overflow: hidden',
			[
			newElement('div', null, 'position: absolute; top: 1px; left: 1px; width: 131px; height: 14px; line-height: 14px; font: normal 10px Verdana; text-align: center; overflow: hidden; background: url(/images/charpopbarstatsbg.gif)', [document.createTextNode('Base stats')], [['click',associateObjWithEvent(this.charstats,'switchstats',+1)]])
			]),
		newElement('div', null, 'position: absolute; width: 12px; height: 16px; overflow: hidden; background: url(/images/charpopshiftleft.gif)', null, [['click', associateObjWithEvent(this.charstats,'switchstats',-1)]]),
		newElement('div', null, 'position: absolute; left: 162px; width: 12px; height: 16px; overflow: hidden; background: url(/images/charpopshiftright.gif)', null, [['click', associateObjWithEvent(this.charstats,'switchstats',1)]]),
		statspanel(document.createTextNode('Strength:'), document.createTextNode(this.getfieldbyname('strength_effective')),
			document.createTextNode('Agility:'), document.createTextNode(this.getfieldbyname('agility_effective')),
			document.createTextNode('Stamina:'), document.createTextNode(this.getfieldbyname('stamina_effective')),
			document.createTextNode('Intellect:'), document.createTextNode(this.getfieldbyname('intellect_effective')),
			document.createTextNode('Spirit:'), document.createTextNode(this.getfieldbyname('spirit_effective')),
			document.createTextNode('Armor:'), document.createTextNode(this.getfieldbyname('armor_effective')), true),
		
		statspanel(document.createTextNode('Weapon Skill:'), document.createTextNode(this.getfieldbyname('melee_mainhand_skill')), 
			document.createTextNode('Damage:'), document.createTextNode(this.getfieldbyname('melee_mainhand_damage_min')+'-'+this.getfieldbyname('melee_mainhand_damage_max')), 
			document.createTextNode('Speed:'), document.createTextNode(this.getfieldbyname('melee_mainhand_speed')+'/'+this.getfieldbyname('melee_offhand_speed')), 
			document.createTextNode('Power:'), document.createTextNode(this.getfieldbyname('melee_power_effective')), 
			document.createTextNode('Hit Rating:'), document.createTextNode(this.getfieldbyname('melee_hitrating')), 
			document.createTextNode('Crit Chance:'), document.createTextNode(this.getfieldbyname('melee_critchance_percent')+'%')),
		
		statspanel(document.createTextNode('Weapon Skill:'), document.createTextNode(this.getfieldbyname('ranged_skill')), 
			document.createTextNode('Damage:'), document.createTextNode(this.getfieldbyname('ranged_damage_min')+'-'+this.getfieldbyname('ranged_damage_max')), 
			document.createTextNode('Speed:'), document.createTextNode(this.getfieldbyname('ranged_speed')), 
			document.createTextNode('Power:'), document.createTextNode(this.getfieldbyname('ranged_power_effective')), 
			document.createTextNode('Hit Rating:'), document.createTextNode(this.getfieldbyname('ranged_hitrating')), 
			document.createTextNode('Crit Chance:'), document.createTextNode(this.getfieldbyname('ranged_critchance_percent')+'%')),
		
		statspanel(document.createTextNode('Bonus Damage:'), document.createTextNode(bdmax), 
			document.createTextNode('Bonus Healing:'), document.createTextNode(this.getfieldbyname('spell_bonushealing')), 
			document.createTextNode('Hit Rating:'), document.createTextNode(this.getfieldbyname('spell_hitrating')), 
			document.createTextNode('Crit Chance:'), document.createTextNode(ccmax+'%'), 
			document.createTextNode('Penetration:'), document.createTextNode(this.getfieldbyname('spell_penetration')), 
			document.createTextNode('Mana Regen:'), document.createTextNode(this.getfieldbyname('spell_manaregen_notcasting'))),
		
		statspanel(document.createTextNode('Armor:'), document.createTextNode(this.getfieldbyname('defense_armor_effective')), 
			document.createTextNode('Defense:'), document.createTextNode(this.getfieldbyname('defense')), 
			document.createTextNode('Dodge:'), document.createTextNode(this.getfieldbyname('defense_dodge_percent')+'%'), 
			document.createTextNode('Parry:'), document.createTextNode(this.getfieldbyname('defense_parry_percent')+'%'), 
			document.createTextNode('Block:'), document.createTextNode(this.getfieldbyname('defense_block_percent')+'%'), 
			document.createTextNode('Resilience:'), document.createTextNode(this.getfieldbyname('defense_resilience')))
		]);
	this.charstats.dialog.appendChild(scc);
	this.charstats.statscanvas = scc;
	this.charstats.statsindex = 0;
	
}

charpop.prototype.getfieldbyname = function(name) {
	var i=0;
	while (i<=this.colheadings.length) {
		if (this.colheadings[i] == name)
			return this.currentrow[i].childNodes[0].nodeValue;
		i++;	
	}
	return 'Field not found';
}

function getfirstaid(skills) {
	for (var i=0;i<skills[1].childNodes.length;i++) {
		if (skills[1].childNodes[i].childNodes[2].childNodes[0].nodeValue == 'firstaid') {
			return [skills[1].childNodes[i].childNodes[4].childNodes[0].nodeValue, skills[1].childNodes[i].childNodes[5].childNodes[0].nodeValue];
		}
	}
	return [0,0];
}

function getitem(items,slot) {
	for (var i=0;i<items[1].childNodes.length;i++) {
		if (items[1].childNodes[i].childNodes[10].childNodes[0].nodeValue == slot) {
			var ret = new Array();
			for (var j=0;j<items[1].childNodes[i].childNodes.length;j++) {
				ret[j] = items[1].childNodes[i].childNodes[j].childNodes[0].nodeValue;
			}
			return ret;
		}
	}
	return ['','','','','','','','','','',''];
}

charpop.prototype.loadstart = function(e,obj,args) {
	while(this.charstats.dialog.childNodes.length>3) {
		this.charstats.dialog.removeChild(this.charstats.dialog.childNodes[this.charstats.dialog.childNodes.length-1]);
	}
	this.charstats.dialog.appendChild(newElement('img',[['src', '/lewlibs/res/ext/image/loading.gif'], ['alt', 'Loading']], 'width: 24px; height: 24px; display: block; position: absolute; top: '+((this.charstats.height / 2) - 12)+'px; left: '+((this.charstats.width / 2) - 12)+'px'));
}

charpop.prototype.loadstop = function(e,obj,args) {
	while(this.charstats.dialog.childNodes.length>3) {
		this.charstats.dialog.removeChild(this.charstats.dialog.childNodes[this.charstats.dialog.childNodes.length-1]);
	}
}


charpop.prototype.addslot = function(slot) {
	var d = [0,0];
	switch (slot) {
		case 0:d=[73,6];break;
		case 1:d=[107,6];break;
		case 2:d=[141,6];break; 
		case 14:d=[175,6];break;
		case 4:d=[209,6];break;
		case 3:d=[243,6];break;
		case 18:d=[277,6];break;
		case 8:d=[311,6];break;
		
		case 9:d=[73,224];break;
		case 5:d=[107,224];break;
		case 6:d=[141,224];break;
		case 7:d=[175,224];break;
		case 10:d=[209,224];break;
		case 11:d=[243,224];break;
		case 12:d=[277,224];break;
		case 13:d=[311,224];break;

		case 15:d=[311,78];break;
		case 16:d=[311,114];break;
		case 17:d=[311,150];break;

	}
	
	var item = getitem(this.items,slot);
	
	this.charstats.dialog.appendChild( newElement('img', [['src', '/armoryicons.php?icon='+item[4]+'&type=item&resize=28x28']], 'display: block; position: absolute; top: '+(d[0]+2)+'px; left: '+(d[1]+2)+'px; width: 28px; height: 28px;') );
	this.charstats.dialog.appendChild( newElement('div', null, 'position: absolute; top: '+(d[0])+'px; overflow: hidden; left: '+(d[1])+'px; width: 32px; height: 32px;', [newElement('img', [['className', 'alphapng'], ['src', '/images/charpopitemframe.png']], '', null, [['mouseover', associateObjWithEvent(this,'itemstats',[1,item])],['mouseout', associateObjWithEvent(this,'itemstats',[0])],['mousemove', associateObjWithEvent(this,'itemstatspos',null)],['click', associateObjWithEvent(this,'itemstats',[1,item])]])]) );
}


charpop.prototype.itemstats = function(e, obj, args) {
	var target = (window.event)? event.srcElement : e.target;
	if (args[0] == 1) {
		target.style.marginLeft='-32px';
		this.itempopup.itempopulate([this.characterid,args[1]]);
	}
	else {
		target.style.marginLeft='0px';
		this.itempopup.hide();
		this.itempopup.loader.abort();
	}
}

charpop.prototype.itemstatspos = function(e, obj, args) {
	var target = (window.event)? event.srcElement : e.target;
	target.style.marginLeft='-32px';
	this.itempopup.setPosition(mousey(e),mousex(e)+10);
}

ljDialog.prototype.itempopulate = function (args) {
	if (args[1][5]=='')return false;
	if (window['ll_itemcache']) {
		for (var i=0;i<window['ll_itemcache'].length;i++) {
			if (window['ll_itemcache'][i][0]==args[0]+'_'+args[1][5]) {
				this.clear();
				var d = getdimensions(window['ll_itemcache'][i][1],[300,-1]);
				this.setDimensions(d);
				this.dialog.appendChild(window['ll_itemcache'][i][1]);
				this.show();
				return true;
			}
		}
	}
	this.loader.onstart = associateObjWithEvent(this,'tt_loadstart',null);
	this.loader.oncomplete = associateObjWithEvent(this,'tt_loadcomplete',null);
	this.loader.handler = 'simpledata';
//	this.loader.debug = true;
	this.loader.callback = associateObjWithEvent(this,'tt_callback',args[2]);
	var xmldoc = new xmlWriter('query');
	xmldoc.writeAttribute('src', 'itemdetail');
	xmldoc.startElement('queryparams');
	xmldoc.startElement('param');
	xmldoc.writeAttribute('name','character');
	xmldoc.writeText(args[0]);
	xmldoc.endElement('param');
	xmldoc.startElement('param');
	xmldoc.writeAttribute('name','item');
	xmldoc.writeText(args[1][5]);
	xmldoc.endElement('param');
	xmldoc.endElement('queryparams');
	xmldoc.startElement('fieldset');
	addfields(xmldoc, ['id', 'character', 'name', 'suffix', 'icon', 'quality', 'maxcount', 'bonding', 'classid', 'equip_invtype', 'equip_subclassname', 'durability', 'maxdurability', 'gem0id', 'socket0color', 'gem0color', 'gem0effect', 'gem0icon', 'gem1id', 'socket1color', 'gem1color', 'gem1effect', 'gem1icon', 'gem2id', 'socket2color', 'gem2color', 'gem2effect', 'gem2icon', 'rp_effect1', 'rp_effect2', 'rp_effect3', 'rp_effect4', 'rp_effect5', 'enchant', 'armor', 'bonusstrength', 'bonusagility', 'bonusstamina', 'bonusintellect', 'bonusspirit', 'bonusdefenseskillrating', 'bonusdodgerating', 'bonusparryrating', 'bonusblockrating', 'bonushitmeleerating', 'bonushitrangedrating', 'bonushitspellrating', 'bonuscritmeleerating', 'bonuscritrangedrating', 'bonuscritspellrating', 'bonushittakenmeleerating', 'bonushittakenrangedrating', 'bonushittakenspellrating', 'bonuscrittakenmeleerating', 'bonuscrittakenrangedrating', 'bonuscrittakenspellrating', 'bonushastemeleerating', 'bonushasterangedrating', 'bonushastespellrating', 'bonushitrating', 'bonuscritrating', 'bonushittakenrating', 'bonuscrittakenrating', 'bonusresiliencerating', 'bonushasterating', 'requiredlevel', 'setname', 'setbonuses', 'setpieces', 'classrestrict', 'racerestrict', 'damage_speed', 'damage_dps', 'damage_data', 'block', 'fireresist', 'natureresist', 'frostresist', 'shadowresist', 'arcaneresist', 'sockets', 'sockets_setbonus', 'gemproperties', 'requiredskill_name', 'requiredskill_rank', 'requiredability', 'spelldata', 'required_faction_name', 'required_faction_rep','desc']);
	this.loader.send(xmldoc.compile());

}

ljDialog.prototype.tt_loadstart = function (e,obj,args) {
	this.clear();
	var el = newElement('div',null,'position: absolute; padding: 10px; font: normal 10px verdana',[newElement('img',[['src', '/lewlibs/res/ext/image/loading.gif'], ['alt', 'Loading']], 'width: 24px; height: 24px;')]);
	this.setDimensions(getdimensions(el));
	this.dialog.appendChild(el);
	this.show();
}

ljDialog.prototype.tt_loadcomplete = function (e,obj,args) {
	this.clear();
}

ljDialog.prototype.tt_callback = function (rxml) {
	var rs = rxml.childNodes[0].childNodes[1].childNodes;
	if (rs.length == 0 || rs[0].childNodes[0].childNodes.length == 0) {
		// no data!
		var ret = newElement('div',null,'position: absolute; padding: 4px; font: normal 10px verdana',[document.createTextNode('Sorry, no data available')]);
	}
	else {
		var ret = itemstats(rxml);
	}
	var d = getdimensions(ret,[300,-1]);
	this.setDimensions(d);
	this.dialog.appendChild(ret);
	if (!window['ll_itemcache'])
		window['ll_itemcache'] = [[itemfield(rxml, 'character')+'_'+itemfield(rxml, 'id'), ret.cloneNode(true)]];
	else {
		if (window['ll_itemcache'].length>50)
			window['ll_itemcache'].shift();
		window['ll_itemcache'].push([itemfield(rxml, 'character')+'_'+itemfield(rxml, 'id'), ret.cloneNode(true)]);
	}
}


function itemstats(rxml) {
	var bonding = itemfield(rxml,'bonding');
	var bondtxt = '';
	switch (bonding) {
		case '1':
			bondtxt = 'Binds when picked up';
			break;
		case '2':
			bondtxt = 'Binds when equipped';
			break;
		case '3':
			bondtxt = 'Binds when used';
			break;
		case '4':
		case '5':
			bondtxt = 'Quest Item';
			break;
	}
	var maxcount = parseInt(itemfield(rxml,'maxcount'));
	if (isNaN(maxcount)) maxcount=0;
	var invtypes = ['Unequippable', 'Head', 'Neck', 'Shoulders', 'Shirt', 'Chest', 'Waist', 'Legs', 'Feet', 'Wrist', 'Hand', 'Finger', 'Trinket', 'One-Hand', 'Off Hand','Ranged', 'Back', 'Two-Hand', 'Bag', 'Tabard', 'Chest', 'Main Hand', 'Off Hand', 'Held In Off Hand', 'Projectile', 'Thrown', 'Ranged', 'Quiver', 'Relic'];
	var invtype = parseInt(itemfield(rxml,'equip_invtype'));
	if (!isNaN(invtype))
		invtype = invtypes[invtype];
	else
		invtype = '';
	if (isNaN(maxcount)) maxcount = 0;
	
	var damage = [];
	var speed = '';
	var s = (itemfield(rxml,'damage_speed'));
	if (s!='') {
		if (s>0)
			speed = 'Speed '+format_number(Math.floor(s *100)/100);
	}
	if (parseInt(itemfield(rxml,'damage_dps'))>0) {
		var dmin = parseInt(itemfield(rxml,'damage_min'))
		if (itemfield(rxml,'class') == '6') { // projectile
			var dd = itemfield(rxml,'damage_data').split(',');
			damage = ['Adds '+( (parseInt(dd[0]) / parseInt(dd[1])) * 0.5)+' DPS'];
		}
		else {
			ddata = itemfield(rxml,'damage_data').split('|');
			dtypes = ['Damage', 'Holy Damage', 'Fire Damage', 'Nature Damage', 'Frost Damage', 'Shadow Damage', 'Arcane Damage'];
			for (var i=0;i<ddata.length;i++) {
				dd = ddata[i].split(',');
				damage.push(dd[1]+ ((dd[2]>dd[1])? '-'+dd[2]+' '+dtypes[parseInt(dd[0])]: '') );
			}
		}
	}
	var dps = itemfield(rxml,'damage_dps');
	if (dps=='0') dps='';
	if (dps != '')
		dps='('+format_number(dps,1)+' damage per second)';
	
	var armor=itemfield(rxml,'armor');
	if (armor=='0')
		armor = '';
	if (armor!='')
		armor += ' Armor';

	var block=itemfield(rxml,'block');
	if (block=='0')
		block = '';
	if (block!='')
		block += ' Block';
	
	bonusstrength = itemfield(rxml,'bonusstrength');
	if (parseInt(bonusstrength)>0) bonusstrength='+'+bonusstrength;
	if (bonusstrength=='0') bonusstrength='';
	if (bonusstrength != '') bonusstrength+= ' Strength';
	
	bonusagility = itemfield(rxml,'bonusagility');
	if (parseInt(bonusagility)>0) bonusagility='+'+bonusagility;
	if (bonusagility=='0') bonusagility='';
	if (bonusagility != '') bonusagility+= ' Agility';
	
	bonusstamina = itemfield(rxml,'bonusstamina');
	if (parseInt(bonusstamina)>0) bonusstamina='+'+bonusstamina;
	if (bonusstamina=='0') bonusstamina='';
	if (bonusstamina != '') bonusstamina+= ' Stamina';

	bonusintellect = itemfield(rxml,'bonusintellect');
	if (parseInt(bonusintellect)>0) bonusintellect='+'+bonusintellect;
	if (bonusintellect=='0') bonusintellect='';
	if (bonusintellect != '') bonusintellect+= ' Intellect';

	bonusspirit = itemfield(rxml,'bonusspirit');
	if (parseInt(bonusspirit)>0) bonusspirit='+'+bonusspirit;
	if (bonusspirit=='0') bonusspirit='';
	if (bonusspirit != '') bonusspirit+= ' Spirit';

	fireresist = itemfield(rxml,'fireresist');
	if (parseInt(fireresist)>0) fireresist='+'+fireresist;
	if (fireresist=='0') fireresist='';
	if (fireresist != '') fireresist+= ' Fire Resistance';
	
	natureresist = itemfield(rxml,'natureresist');
	if (parseInt(natureresist)>0) natureresist='+'+natureresist;
	if (natureresist=='0') natureresist='';
	if (natureresist != '') natureresist+= ' Nature Resistance';
	
	frostresist = itemfield(rxml,'frostresist');
	if (parseInt(frostresist)>0) frostresist='+'+frostresist;
	if (frostresist=='0') frostresist='';
	if (frostresist != '') frostresist+= ' Frost Resistance';
	
	shadowresist = itemfield(rxml,'shadowresist');
	if (parseInt(shadowresist)>0) shadowresist='+'+shadowresist;
	if (shadowresist=='0') shadowresist='';
	if (shadowresist != '') shadowresist+= ' Shadow Resistance';
	
	arcaneresist = itemfield(rxml,'arcaneresist');
	if (parseInt(arcaneresist)>0) arcaneresist='+'+arcaneresist;
	if (arcaneresist=='0') arcaneresist='';
	if (arcaneresist != '') arcaneresist+= ' Arcane Resistance';
	
	var sockets = itemfield(rxml,'sockets');
	if (sockets=='') sockets = [];
	else sockets = sockets.split('|');
	var gems = [[itemfield(rxml,'gem0color'), itemfield(rxml,'gem0effect'), itemfield(rxml,'gem0icon')], [itemfield(rxml,'gem1color'), itemfield(rxml,'gem1effect'), itemfield(rxml,'gem1icon')], [itemfield(rxml,'gem2color'), itemfield(rxml,'gem2effect'), itemfield(rxml,'gem2icon')]];
	var matched = 0;
	var socketbonus = itemfield(rxml,'sockets_setbonus');
	
	var socketdisplay = [];
	
	for (var i=0;i<sockets.length;i++) {
		sockets[i] = sockets[i].split(',');
		if (sockets[i][1] == gems[i][0]) // color match
			matched++;
		if (gems[i][0]!='') // full socket
			socketdisplay.push(newElement('div', [['class', 'socketFull']], '', [ newElement('img', [['src', 'armoryicons.php?resize=10x10&type=gem&icon='+gems[i][2]]], 'width: 10px; height: 10px;'), document.createTextNode(' '+gems[i][1]) ]));
		else // empty socket
			socketdisplay.push(newElement('div', [['class', 'socketEmpty'+sockets[i][1]+' ll_incompleteSet']], '', [ newElement('img', [['src', 'armoryicons.php?resize=10x10&type=gem-base&icon=Socket_'+sockets[i][1]]], 'width: 10px; height: 10px;'), document.createTextNode(' '+sockets[i][1]+' Socket') ]));
	}
	if (socketbonus!='') {
		socketdisplay.push(newElement('div', [['class', ((matched == sockets.length)? 'll_enchant' : 'll_incompleteSet')]],'',[document.createTextNode('Socket Bonus: '+socketbonus)]));
	}
	
	var rpenchants = [];
	var rp_enchants_class = '';
	if (itemfield(rxml,'rp_effect1')!='') rpenchants.push(newElement('div',null, '', [document.createTextNode(itemfield(rxml,'rp_effect1'))]));
	if (itemfield(rxml,'rp_effect2')!='') rpenchants.push(newElement('div',null, '', [document.createTextNode(itemfield(rxml,'rp_effect2'))]));
	if (itemfield(rxml,'rp_effect3')!='') rpenchants.push(newElement('div',null, '', [document.createTextNode(itemfield(rxml,'rp_effect3'))]));
	if (itemfield(rxml,'rp_effect4')!='') rpenchants.push(newElement('div',null, '', [document.createTextNode(itemfield(rxml,'rp_effect4'))]));
	if (itemfield(rxml,'rp_effect5')!='') rpenchants.push(newElement('div',null, '', [document.createTextNode(itemfield(rxml,'rp_effect5'))]));

	var durstr = itemfield(rxml,'maxdurability');
	if (durstr!='' && durstr != '0')
		durstr = 'Durability: '+itemfield(rxml,'durability')+' / '+durstr;
	else
		durstr = '';
	
	var races = itemfield(rxml,'racerestrict');
	if (races=='') races = [];
	else races = races.split(',');
	
	var classes = itemfield(rxml,'classrestrict');
	if (classes=='') classes = [];
	else classes = classes.split(',');
	
	var reqlevel = itemfield(rxml,'requiredlevel');
	if (reqlevel=='' || reqlevel=='0') reqlevel='';
	else reqlevel = 'Requires Level '+reqlevel;
	
	var reqskill = itemfield(rxml,'requiredskill_name');
	if (reqskill!='') reqlevel = 'Requires '+reqskill+' ('+itemfield(rxml,'requiredskill_rank')+')';
	
	var reqability = itemfield(rxml,'requiredability');
	if (reqability!='') reqability = 'Requires '+reqability;
	
	var standing = ['Hated','Hostile','Unfriendly','Neutral','Friendly','Honored','Revered','Exalted'];
	var reqfaction = itemfield(rxml,'required_faction_name');
	if (reqfaction!='') reqfaction = 'Requires '+reqfaction+' - '+standing[parseInt(itemfield(rxml,'required_faction_rep'))];
	
	var spelldata = itemfield(rxml,'spelldata');
	var spelltriggers = ['Use', 'Equip', 'Chance on hit'];
	if (spelldata!='') {
		sd = spelldata.split('+|+');
		spelldata = [];
		for (i=0;i<sd.length;i++) {
			s=sd[i].split('|',2); // spelldata, reagents
			if (s[1]!='')
				sr = s[1].split('|');
			else sr = [];
			for (j=0;j<sr.length;j++) {
				srd=sr[j].split(',',2); // count, name
				sr[j] = srd[1];
				if (srd[0]>1)
					sr[j]+=' ('+srd[0]+')';
			}
			s= s[0].split(',',3); // trigger, charges, desc
			sr = sr.join(', ');
			spelldata.push(newElement('div',[['class', 'll_enchant']],'', [document.createTextNode(spelltriggers[parseInt(s[0])]+': '+s[2]+((s[1]!='0')? 'Charges: '+s[1] : ''))]));
		}
	}
	else spelldata = [];
	
	var set = [];
	var setname = itemfield(rxml,'setname');
	if (setname!='') {
		var setbonuses = itemfield(rxml,'setbonuses').split('|');
		var setpieces = itemfield(rxml,'setpieces').split('|');
		var setcount=0;
		for (i=0;i<setpieces.length;i++) { setpieces[i]=setpieces[i].split(',',2); if (setpieces[i][0] == '1') { setcount++; } }
		set.push(newElement('div',[['class', 'll_itemsettitle']], '', [document.createTextNode(setname+' ('+setcount+'/'+setpieces.length+')')]));
		for (i=0;i<setpieces.length;i++) {
			set.push(newElement('div',[['class', 'll_itemsetpiece'+((setpieces[i][0]=='1')? 'on':'off')]], '', [document.createTextNode(setpieces[i][1])]));
		}
		for (i=0;i<setbonuses.length;i++) {
			sb = setbonuses[i].split(',',2);
			set.push(newElement('div',[['class', 'll_itemsetbonus'+((setcount>=sb[0])? 'on':'off')]], ((i==0)? 'padding-top: 10px;':'')+((i==setbonuses.length)? 'padding-bottom: 10px;':''), [document.createTextNode('('+sb[0]+') Set: '+sb[1])]));
		}
	}
	
	
	return newElement('div',[['class','ll_itemstats']],'position: absolute; padding: 4px',[
	newElement('div',[['class','quality'+itemfield(rxml,'quality')]],'',[document.createTextNode(itemfield(rxml,'name')+' '+itemfield(rxml,'suffix'))]),
	newElement('div',[],'',[document.createTextNode( bondtxt )]),
	newElement('div',[],'',[document.createTextNode( ((maxcount>0)? 'Unique '+((maxcount>1)? '('+maxcount+')' : '') : '') )]),
	newElement('div',[['class','nocalc']],'float: right; text-align: right',[document.createTextNode( itemfield(rxml,'equip_subclassname') )]),
	newElement('div',[],'',[document.createTextNode( invtype )]),
	newElement('div',[['class','nocalc']],'float: right; text-align: right',[document.createTextNode( speed )]),
	newElement('div',[['innerHTML',damage.join('<br />')]],'',[]),
	newElement('div',[],'',[document.createTextNode( dps )]),
	newElement('div',[],'',[document.createTextNode( armor )]),
	newElement('div',[],'',[document.createTextNode( block )]),
	newElement('div',[],'',[document.createTextNode( bonusstrength )]),
	newElement('div',[],'',[document.createTextNode( bonusagility )]),
	newElement('div',[],'',[document.createTextNode( bonusstamina )]),
	newElement('div',[],'',[document.createTextNode( bonusintellect )]),
	newElement('div',[],'',[document.createTextNode( bonusspirit )]),
	newElement('div',[],'',[document.createTextNode( fireresist )]),
	newElement('div',[],'',[document.createTextNode( natureresist )]),
	newElement('div',[],'',[document.createTextNode( frostresist )]),
	newElement('div',[],'',[document.createTextNode( shadowresist )]),
	newElement('div',[],'',[document.createTextNode( arcaneresist )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'enchant') )]),
	newElement('div',[],'', socketdisplay),
	newElement('div',[],'', rpenchants),
	newElement('div',[],'',[document.createTextNode( itemfield(rxml,'gemproperties') )]),
	newElement('div',[],'',[document.createTextNode( durstr )]),
	newElement('div',[],'',[document.createTextNode( ((races.length>0)? 'Races: ': '')+races.join(', ') )]),
	newElement('div',[],'',[document.createTextNode( ((classes.length>0)? 'Classes: ': '')+classes.join(', ') )]),
	newElement('div',[],'',[document.createTextNode( reqlevel )]),
	newElement('div',[],'',[document.createTextNode( reqskill )]),
	newElement('div',[],'',[document.createTextNode( reqability )]),
	newElement('div',[],'',[document.createTextNode( reqfaction )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonusdefenseskillrating','Equip: Increases defense rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonusdodgerating','Equip: Increases your dodge rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonusparryrating','Equip: Increases your parry rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonusblockrating','Equip: Increases your shield block rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushitmeleerating','Equip: Increases melee hit rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushitrangedrating','Equip: Increases ranged hit rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushitspellrating','Equip: Improves spell hit rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonuscritmeleerating','Equip: Increases melee crit rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonuscritrangedrating','Equip: Increases ranged crit rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonuscritspellrating','Equip: Improves spell critical strike rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushittakenmeleerating','Equip: Increases bonusHitTakenMeleeRating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushittakenrangedrating','Equip: Increases bonusHitTakenRangedRating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushittakenspellrating','Equip: Increases bonusHitTakenSpellRating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonuscrittakenmeleerating','Equip: Increases bonusCritTakenMeleeRating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonuscrittakenrangedrating','Equip: Increases bonusCritTakenRangedRating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonuscrittakenspellrating','Equip: Increases bonusCritTakenSpellRating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushastemeleerating','Equip: Increases bonusHasteMeleeRating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushasterangedrating','Equip: Increases bonusHasteRangedRating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushastespellrating','Equip: Increases bonusHasteSpellRating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushitrating','Equip: Improves hit rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonuscritrating','Equip: Improves critical strike rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushittakenrating','Equip: Improves hit avoidance rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonuscrittakenrating','Equip: Improves crit avoidance rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonusresiliencerating','Equip: Improves your resilience rating by ') )]),
	newElement('div',[['class','ll_enchant']],'',[document.createTextNode( itemfield(rxml,'bonushasterating','Equip: Improves haste rating by ') )]),
	newElement('div',[[]],'', spelldata ),
	newElement('div',[['class', 'll_itemset']],'', set ),
	newElement('div',[[]],'', [document.createTextNode( itemfield(rxml,'desc') )] )
	]);
}

function itemfield(rxml,field) {
	var prefix='';
	if (arguments.length==3)
		prefix=arguments[2];
	for (var i=0;i<rxml.childNodes[0].childNodes[0].childNodes.length;i++) {
		if (rxml.childNodes[0].childNodes[0].childNodes[i].childNodes[0].nodeValue == field) {
			if (rxml.childNodes[0].childNodes[1].childNodes[0].childNodes[i].childNodes.length)
				if (rxml.childNodes[0].childNodes[1].childNodes[0].childNodes[i].childNodes[0].nodeValue != '0')
					return prefix+rxml.childNodes[0].childNodes[1].childNodes[0].childNodes[i].childNodes[0].nodeValue;
				else
					if (prefix=='')
						return '0';
			return '';
		}
	}
	return prefix+'n/a';
}

ljDialog.prototype.switchstats = function(e,obj,args) {
	if (!this.switching) {
		var titles = ['Base Stats', 'Melee', 'Ranged', 'Spell', 'Defense'];
		this.switching=true;
		if (args>0) {
			// slide left
			var next=this.statsindex+args;
			if (next > 4) next=0;
			this.slideoutleft(this,[next, -180]);
		}
		else {
			// slide right
			var next=this.statsindex+args;
			if (next < 0) next=4;
			this.slideoutright(this,[next, 180]);
		}
		this.statscanvas.childNodes[0].childNodes[0].innerHTML = titles[next];
		return false;
	}
}

ljDialog.prototype.slideoutleft = function(obj,args) {
	//args = [nextindex, stopat
	// 175px wide
	if (isNaN(parseInt(this.statscanvas.childNodes[this.statsindex+3].style.left))) {
		this.statscanvas.childNodes[this.statsindex+3].style.left = '0px';
	}
	var cur = parseInt(this.statscanvas.childNodes[this.statsindex+3].style.left);
	if (cur > args[1]) {
		this.statscanvas.childNodes[this.statsindex+3].style.left =  (cur-10)+'px';
		setTimeout(associateObjWithTimer(this,'slideoutleft',args),10);
	}
	else if (args[0] != null) {
		this.statscanvas.childNodes[this.statsindex+3].style.display='none';
		this.statsindex=args[0];
		this.statscanvas.childNodes[this.statsindex+3].style.display='block';
		this.statscanvas.childNodes[this.statsindex+3].style.left='180px';
		this.slideoutleft(this,[null,0]);
	}
	else {
		this.switching=false;
	}
}

ljDialog.prototype.slideoutright = function(obj,args) {
	//args = [nextindex, stopat
	// 175px wide
	if (isNaN(parseInt(this.statscanvas.childNodes[this.statsindex+3].style.left))) {
		this.statscanvas.childNodes[this.statsindex+3].style.left = '0px';
	}
	var cur = parseInt(this.statscanvas.childNodes[this.statsindex+3].style.left);
	if (cur < args[1]) {
		this.statscanvas.childNodes[this.statsindex+3].style.left =  (cur+10)+'px';
		setTimeout(associateObjWithTimer(this,'slideoutright',args),10);
	}
	else if (args[0] != null) {
		this.statscanvas.childNodes[this.statsindex+3].style.display='none';
		this.statsindex=args[0];
		this.statscanvas.childNodes[this.statsindex+3].style.display='block';
		this.statscanvas.childNodes[this.statsindex+3].style.left='-180px';
		this.slideoutright(this,[null,0]);
	}
	else {
		this.switching=false;
	}
}


function statspanel(f1,v1,f2,v2,f3,v3,f4,v4,f5,v5,f6,v6,visible) {
	return newElement('div', null, 'position: absolute; top: 25px; width: 175px; display: '+((visible)? 'block' : 'none')+';',
		[
		newElement('div', null, 'position: absolute; top: 2px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana; text-align: left', [(f1)]),
		newElement('div', null, 'position: absolute; top: 2px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v1)]),

		newElement('div', null, 'position: absolute; top: 16px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f2)]),
		newElement('div', null, 'position: absolute; top: 16px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v2)]),

		newElement('div', null, 'position: absolute; top: 30px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f3)]),
		newElement('div', null, 'position: absolute; top: 30px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v3)]),

		newElement('div', null, 'position: absolute; top: 44px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f4)]),
		newElement('div', null, 'position: absolute; top: 44px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v4)]),

		newElement('div', null, 'position: absolute; top: 58px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f5)]),
		newElement('div', null, 'position: absolute; top: 58px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v5)]),

		newElement('div', null, 'position: absolute; top: 72px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f6)]),
		newElement('div', null, 'position: absolute; top: 72px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v6)])
		]);
}
/*
function statspanel2(f1,v1,p1,f2,v2,p2,f3,v3,p3,f4,v4,p4,f5,v5,p5,f6,v6,p6,visible) {
	return newElement('div', null, 'position: absolute; top: 25px; width: 175px; display: '+((visible)? 'block' : 'none')+';',
		[
		newElement('div', null, 'position: absolute; top: 2px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana; text-align: left', [document.createTextNode()]),
		newElement('div', null, 'position: absolute; top: 2px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v1)]),

		newElement('div', null, 'position: absolute; top: 16px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f2)]),
		newElement('div', null, 'position: absolute; top: 16px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v2)]),

		newElement('div', null, 'position: absolute; top: 30px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f3)]),
		newElement('div', null, 'position: absolute; top: 30px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v3)]),

		newElement('div', null, 'position: absolute; top: 44px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f4)]),
		newElement('div', null, 'position: absolute; top: 44px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v4)]),

		newElement('div', null, 'position: absolute; top: 58px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f5)]),
		newElement('div', null, 'position: absolute; top: 58px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v5)]),

		newElement('div', null, 'position: absolute; top: 72px; width: 175px; height: 14px; line-height: 14px; color: #f5c901; font: normal 10px Verdana', [(f6)]),
		newElement('div', null, 'position: absolute; top: 72px; width: 175px; height: 14px; line-height: 14px; color: #fff; font: normal 10px Verdana; text-align: right', [(v6)])
		]);
}
*/
function addfield(xmldoc, name,src,type,width) {
	if (arguments.length == 2) {
		xmldoc.startElement('field');
		xmldoc.writeAttribute('src', name);
		xmldoc.endElement();
	}
	else {
		xmldoc.startElement('field');
		xmldoc.writeAttribute('src', src);
		xmldoc.writeAttribute('type', type);
		xmldoc.writeAttribute('width', width);
		xmldoc.writeText(name);
		xmldoc.endElement();
	}
}

function addfields(xmldoc, fields) {
	for (var i=0; i<fields.length;i++) {
		addfield(xmldoc, fields[i]);
	}
}

function getbuildname(classid,tree1,tree2,tree3) {
	tree1 = parseInt(tree1);
	tree2 = parseInt(tree2);
	tree3 = parseInt(tree3);
	if ((tree1=='0') && (tree2=='0') && (tree3=='0'))
		return 'Untalented';
	if (tree1>tree2 && tree1>tree3) {
		//t1
		switch (classid) {
			
			case '1':
				return 'Arms';
			case '2':
				return 'Holy';
			case '3':
				return 'Beast Mastery';
			case '4':
				return 'Assassination';
			case '5':
				return 'Discipline';
			case '7':
				return 'Elemental';
			case '8':
				return 'Arcane';
			case '9':
				return 'Affliction';
			case '11':
				return 'Balance';
		}
		return 'Unknown';
	}
	if (tree2>tree1 && tree2>tree3) {
		//t2
		switch (classid) {
			case '1':
				return 'Fury';
			case '2':
				return 'Protection';
			case '3':
				return 'Marksmanship';
			case '4':
				return 'Combat';
			case '5':
				return 'Holy';
			case '7':
				return 'Enhancement';
			case '8':
				return 'Fire';
			case '9':
				return 'Demonology';
			case '11':
				return 'Feral Combat';
		}
		return 'Unknown';
	}
	if (tree3>tree1 && tree3>tree2) {
		//t3 
		switch (classid) {
			case '1':
				return 'Protection';
			case '2':
				return 'Retribution';
			case '3':
				return 'Survival';
			case '4':
				return 'Subtlety';
			case '5':
				return 'Shadow';
			case '7':
				return 'Restoration';
			case '8':
				return 'Frost';
			case '9':
				return 'Destruction';
			case '11':
				return 'Restoration';
		}
		return 'Unknown';
	}
	return 'Hybrid';
}
