/* ToolBox Requires Mootools Core & Drag.Move from Mootools More */
var ToolBoxHolder = new Class({
	Implements:Options,
	placeholder:$(document.body),
	options:{
		title:'',
		toolboxdata:null,
		communication:'',
		show:-1,
		shout:{
			canshout:true
		},
		enabledToolbox:{
			'ads':true,
			'shout':true,
			'fpg':true			
		},
		orderToolbox:[]
	},
	loadactive:false,
	
	initialize:function(placeholder,options) {
		
		this.setOptions(options);
		this.placeholder = placeholder;
		
		this.loadingEl = new Element('div',{'class':'loading'}).adopt(new Element('span',{'html':'Loading...'}));
		this.loadingEl.setStyle('opacity',0.9);
		
		this.popupEl = new Element('div').adopt([
			new Element('h4',{'html':''}),
			new Element('p',{'html':''})
		]);
				
		this.tools=new Element('div',{'class':'tools'});
		this.elements = [];
		if(this.options.title!='')this.elements.push(Element('h2',{html:this.options.title}));
		this.elements.push(this.tools);

		this.placeholder.adopt(this.elements);
		this.placeholder.addClass('toolbox');
		//toolbox to show before load
		if( $type(this.options.toolboxdata)=='hash' ) this.build();
		//console.log(this.options.communication);
		this.communicator = new Request({
			'url':this.options.communication,
			'onSuccess':this.receive.bind(this),
			'onRequest':this.loading.start.bind(this)
		});
		this.communicator.send();

	},
	loading:{
		start:function() { this.loadingEl.inject(this.placeholder);},
		stop:function(p) { p.loadingEl.dispose();	}		
	},
	receive:function(response){
		
		data = xml2toolbox(response);
		this.setSettings(data.settings);
		this.options.toolboxdata = new Hash(data);
		this.loading.stop(this);
		this.build();
		
		
	},
	setSettings:function(set){
		
		for(i in set) {
			if(i=='toolbox') continue;
			this.options.enabledToolbox[i] 	= (set[i].available=="True");
			this.options.orderToolbox[set[i].order-1]=i;
			
			if(i==set.toolbox.def && this.options.show == -1) this.options.show=set[i].order-1;
		};
		this.options.shout.canshout = set.shout.canshout == "True";
	},
	send:function(values) {
		//console.log('SEND',values,this.communicator.options.url);
		this.communicator.post(values);
	},
	error:function(msg) {
		this.popupEl.set('class','popup warning_box');
		this.popupEl.getFirst('p').set('html',msg.body);
		this.popupEl.getFirst('h4').set('html',msg.header);
		this.popupEl.inject(this.placeholder);
		var remove = function() { this.popupEl.dispose(); }.delay(3000,this);
	},
	message:function(msg) {
		this.popupEl.set('class','popup message_box');
		this.popupEl.getFirst('p').set('html',msg.body);
		this.popupEl.getFirst('h4').set('html',msg.header);
		this.popupEl.inject(this.placeholder);
		var remove = function() { this.popupEl.dispose(); }.delay(3000,this);
	},
	build:function() {
		if(this.options.toolboxdata.error) {
			this.error(this.options.toolboxdata.error);
			return;
		}
		if(this.options.toolboxdata.msg) {
			this.message(this.options.toolboxdata.msg);
			this.options.toolboxdata.erase(this.options.toolboxdata.msg);
		}
		this.tools.empty();
		
		this.options.orderToolbox.each(function(key,order){
			if(this.options.enabledToolbox[key]) {
				switch(key) {
					case 'ads':		var tb = new AdToolBox(key,this.options.toolboxdata[key]);	break;
					case 'shout':	var tb = new ShoutToolBox(key,this.options.toolboxdata[key],this.options.shout.canshout);	break;
					case 'fpg':		var tb = new FPGToolBox(key,this.options.toolboxdata[key]);	break;
				}
				if(tb) {
					tb.addEvents({
						'save':this.send.bind(this),
						'error':this.error.bind(this)
					});
					this.tools.adopt( tb.getHTML() );
				}
			}
		},this);
		
		total_h 	= $('toolboxholder').getSize().y;
		header_h	= $$('h3.toolhead')[0].getSize().y
		no_of_tools = $$('h3.toolhead').length;
		tool_h = total_h - ( no_of_tools * header_h )-1;
		
		$$('.toolcontainer').each(function(item,x){
			item.getFirst('.content').setStyle('height',tool_h);
			new ScrollBar(item,item.getFirst('.content'));
		});
		
		if($$('div.toolcontainer')[0]){
			this.toolAcc = new Accordion('h3.toolhead','div.toolcontainer',{
				fixedHeight:	tool_h,
				display:			this.options.show,
				onActive:		function(toggler,element,i){
					toggler.addClass('active');
					this.options.show=i;
				}.bind(this),
				onBackground:	function(toggler,element){toggler.removeClass('active');}		
			});
		}
		
	}
	
});

var ToolBox =  new Class({
	Implements: [Events,Options],
	itemClass:'',
	title:'',
	content:[],
	
	initialize:function() {
		this.toolHead = new Element('h3',{'class':'toolhead','html':this.title});
		this.toolContainer	= new Element('div',{'class':'toolcontainer'});
		this.toolContent	= new Element('div',{'class':'content'});
		this.toolContent.addClass(this.itemClass);						
	},
	getHTML:function() {
		return [this.toolHead, this.toolContainer.adopt(this.toolContent.adopt(this.content))];
		
	},
	save:function(data) {
		this.fireEvent('save',data);
	},
	error:function(msg) {
		this.fireEvent('error',msg);
	}
	
});
var AdToolBox = new Class({
	Extends:ToolBox,
	
	itemClass:'',
	title:'',
	content:[],
	
	initialize:function(itemClass,item) {
		this.itemClass = itemClass;
		this.title = item.title;
		
		this.header = item.header;
		this.body = item.body;
		this.link = item.link;
		this.imgurl = item.imgurl;
		//console.log(this.body)
		this.content=[
			new Element('div',{'class':'header','html':this.header}),
			new Element('div',{'class':'body','html':this.body}),
			new Element('a',{'class':'link','html':'Lees verder','href':this.link,'target':'_blank'}),
			new Element('div',{'class':'img'}).adopt(new Element('img',{'src':this.imgurl}))
		];
		
		return this.parent(itemClass);
	}
});

var ShoutToolBox = new Class({
	Extends:ToolBox,
	
	itemClass:'',
	title:'',
	content:[],
	
	initialize:function(itemClass,item,canshout) {
		this.itemClass = itemClass;
		this.title = item.title;
		
		this.captcha = new Element('img',{'src':'./_scripts/captcha/captcha.asp?'+Math.random(),'class':'captcha'});
		this.formEl = {
			title:new Element('input',{'name':'title'}),
			message:new Element('textarea',{'name':'message'}),
			name:new Element('input',{'name':'name'}),
			email:new Element('input',{'name':'email'}),
			captcha_img:[
				this.captcha,
				new Element('a',{
					'html':'Klik hier als de tekst onleesbaar is',
					'href':'#',
					'events':{
						'click':function() {
							try {
								this.captcha.set('src','./_scripts/captcha/captcha.asp?'+Math.random());
							} catch(e) {}
							return false;
						}.bind(this)
					}
				})
			],
			captcha:new Element('input',{'name':'captcha'})
		};
		
		this.b_Send = new Element('a',{'html':'Verstuur','class':'verstuur','href':'#','events':{'click':this.submit.bind(this)}});
		this.form = new Element('form',{'events':{'submit':function(){return false;}}}).adopt(makeTable([
			['Titel bericht:',this.formEl.title],
			['Reactie:',this.formEl.message],
			['Naam:',this.formEl.name],
			['E-mail adres:',this.formEl.email],
			['',this.formEl.captcha_img],
			['Type de boodschap over:',this.formEl.captcha],
			['&nbsp;',this.b_Send]
		],'input'));
		
		this.response = new Element('div',{'class':'output'});

		item.response.each(function(resp,x){
			
			var msg = new Element('div',{'class':'message'}).adopt([
				new Element('div',{'class':'meta'}).adopt([
					new Element('div',{'class':'name','html':resp.name}),
					new Element('div',{'class':'date','html':resp.date})
				]),
				new Element('div',{'class':'txt'}).adopt(
					new Element('div',{'html':'<b>'+resp.title+'</b>'+resp.txt})
				)
			]);
			//console.log(resp.abn);
			if(resp.abn==="True") msg.addClass('abn-admin');
			
			this.response.adopt(msg)
		},this);
		
		
		
		this.content=[];
		if(canshout){
			this.content.push(	new Element('h4',{'html':'Je reactie'})	);
			this.content.push(	this.form	);
		}
		this.content.push(	new Element('h4',{'html':item.response.length+' reactie(s)'})	);
		this.content.push(	this.response	);
		
		
		return this.parent(itemClass);
	},
	submit:function(e) {
		
		try {	
			error=false;
			var store={
				action: 'saveshout'
			};
			for(i in this.formEl) {
				if(i=='captcha_img') continue;
				//else				
				val=this.formEl[i];
				
				if(val.value=='')	{
					error=true;
					val.addClass('error');
					this.error({header:'Fout in het formulier',body:'Alle velden moeten ingevuld worden'});
					continue;
				}
				if(i=='email' && !check('email',val.value)) {
					error=true;
					val.addClass('error');
					this.error({header:'Fout in het formulier',body:'Dit is geen geldig e-mail adres!'});
					continue;
				}

				val.removeClass('error');
				store[i] = val.value;
				
			}
			if(!error) this.save(store);
		} catch(e) {}
		return false;
	}
});
function check(type,value) {
	switch(type) {
		case 'email':
			return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value));
		break;
	}
	//als fout return false;
	return true;

}

var FPGToolBox = new Class({
	Extends:ToolBox,
	
	itemClass:'',
	title:'',
	content:[],
	
	programs:[],
	informme:[],
	
	initialize:function(itemClass,item) {
		this.itemClass = itemClass;
		this.title = item.title;
		
		this.formEl={
			email:new Element('input',{'name':'email'}),
			pgm_ids:{}
		}
		
		
		item.programs.each(function(item,x){
			var chkbox_name = 'program_ids';
			var chkbox_id = chkbox_name + '__' + item.program_id
			this.formEl.pgm_ids[item.program_id] = new NiceCheckBox({'value':item.program_id,'name':chkbox_name,'id':chkbox_id,'label':'Informeer mij'});
			this.programs.push(new Element('div',{'class':'programbox'}).adopt([
				new Element('div',{'class':'img'}).adopt(new Element('img',{'src':item.imgurl})),
				new Element('div',{'class':'text'}).adopt([
					new Element('b',{'html':item.header}),
					new Element('span',{'html':item.body}),
					new Element('div',{'class':'informme'}).adopt(
						this.formEl.pgm_ids[item.program_id]
					)
				])
			]))
		},this);
		
		this.b_Send = new Element('a',{'html':'Verstuur','href':'#','events':{'click':this.submit.bind(this)}});
		this.informme = new Element('form',{'events':{'submit':function(){return false;}}}).adopt(new Element('div',{
			'class':'programalert','html':'<b>Video alerts</b>Stuur mij een mail zodra deze nieuwe video\'s online zijn.<br/>'
		}).adopt(makeTable([
			['e-mail adres:',this.formEl.email],
			['&nbsp;',this.b_Send]
		],'fpg')));
		
		this.content=[
			this.programs,
			this.informme
		];
		
		return this.parent(itemClass);
	},
	submit:function(e) {
		try{
			//console.log(this.formEl);
			var store = {
				'action':'savefpg',
				'fpg_id':[]
			}
			if( !check('email',this.formEl.email.value) ) {
				this.formEl.email.addClass('error');
				this.error({header:'Fout in het formulier',body:'Dit is geen geldig e-mail adres!'});
				return null;
			} else {
				this.formEl.email.removeClass('error');
				store['email']=this.formEl.email.value;
			}
			
			for(i in this.formEl.pgm_ids) {
				pgm_id = this.formEl.pgm_ids[i][0].value;
				if(pgm_id!='') store.fpg_id.push(pgm_id);
			}
			if(store.fpg_id.length>0) {
				store.fpg_id=store.fpg_id.join(',');
				this.save(store);
			} else this.error({header:'Fout in het formulier',body:'Selecteer tenminste 1 video'});
		} catch(e) {}
		return false;		
	}
});


function xml2toolbox(xml) {
	var output = {};

	data = xml2json.parser(xml);
	if(!data || !data.qxl) return;
	data = data.qxl;
	
	output.settings = data.settings;
	if(data.msg) output.msg = data.msg;
	if(data.error) output.error = data.error;
	
	for(toolboxtype in data.content) {
		var item = data.content[toolboxtype];
		switch(toolboxtype) {
			case 'ads':
				output.ads = {
					'title':item.title,
					'header':item.header,
					'body':item.body,
					'link':item.url,
					'imgurl':item.image
				}
			break;
			case 'shouts':
				output.shout={
					'title':'Reageren',
					'response':[]
				}
				
				if($type(item.shout)!==false) {
					if( $type(item.shout) != 'array') item.shout = Array(item.shout);
					item.shout.each(function(sh){
						output.shout.response.push({
							'name':sh.name,
							'date':sh.date,
							'title':sh.title,
							'txt':sh.message,
							'abn':sh.abn
						})
					});
				}
			break;
			case 'fpgs':
				output.fpg={
					'title':'Binnenkort bij ABN AMRO TV',
					'programs':[]
				};
				if( $type(item.fpg) != 'array') item.fpg = Array(item.fpg);
				item.fpg.each(function(sh){
					output.fpg.programs.push({
						'imgurl':sh.thumb,
						'header':sh.title,
						'body':sh.description,
						'program_id':sh.fpg_id
					})
				});
			break;
		}
	};
	
	return output;
}
function makeTable(item,cl) {
	if($type(cl)==false) cl='';
	var output = new Element('tbody');	
	var classes=['key','value'];
	item.each(function(row){
		var tr = new Element('tr');
		row.each(function(val,x){
			if($type(val)=='string')	tr.adopt(new Element('td',{'html':val,'class':classes[x]}));
			else						tr.adopt(new Element('td',{'class':classes[x]}).adopt(val));
		});
		output.adopt(tr);
	},this);
	
	return new Element('table',{'class':cl}).adopt(output);
}

var NiceCheckBox = new Class({
	output:[],
	initialize:function(item) {

		this.stdValue = item.value;
		this.checked = ($type(item.checked)==false?false:item.checked);

		this.inputBox = new Element('input',{'type':'hidden','name':item.name,'value':''});
		this.displBox = new Element('div',{'class':'nicecheckbox'});
		this.output.push(this.inputBox,this.displBox);
		
		if( $type(item.label)!=false ) {
			this.label = new Element('label',{
				'html':item.label,
				'events':{'click':this.toggle.bind(this)}
			});
			this.output.push(this.label);
		}
		
		this.displBox.addEvent('click',this.toggle.bind(this));
		this.check();
		
		return this.output;	
	},
	toggle:function() {
		this.checked = (this.checked?false:true);
		this.check();
	},
	set:function(state) {
		this.checked=state;
		this.check();
	},
	check:function() {
		if(this.checked) {
			this.displBox.addClass('checked');
			this.inputBox.set('value',this.stdValue);
			this.value=this.stdValue;
		} else {
			this.displBox.removeClass('checked');			
			this.inputBox.set('value',null);
			this.value=null;
		}
	}
});

var ScrollBar = new Class({
	Implements:[Options],
	options:{
		scrollspeed:10
	},
	isActive:false,
	initialize:function(item,content,options) {
		this.item = item;
		this.content = content;
		this.setOptions(options);
		this.update();
		
	},
	toBig:function() {
		return( this.content.getStyle('height').toInt() < this.content.getScrollSize().y );  //< Get scroll
	},
	update:function() {
		if(!this.toBig()){
			if(this.isActive) this.removeScrollbar();
			return;
		}
		this.addScrollbar();
		this.scrollByStep(-1);
	},
	addScrollbar:function() {
		this.item.addClass('withScrollbar');
		this.item.adopt(this.getScrollbar());

		//set sizes
		this.content.setStyle('width',this.content.getStyle('width').toInt()-this.scrollContainer.getStyle('width').toInt());
		this.h_bUp = this.bUp.getSize().y;
		this.h_bDown = this.bDown.getSize().y;
		this.h_scrollContainer = this.scrollContainer.getSize().y;
		this.h_scroller = this.h_scrollContainer-this.h_bUp-this.h_bDown-(Browser.Engine.trident?44:0);
		this.h_knob = this.knob.getStyle('height').toInt();
		this.scroller.setStyles({
			'top':this.h_bUp,
			'height':this.h_scroller
		});
		

		this.scrollDrag = new Drag.Move(this.knob,{
			container:this.scroller,
			onDrag:this.dragger.bind(this)
		});
		
		$(document.body).addEvent('mouseleave',function(){this.scrollDrag.stop()}.bind(this));
		
		
	},
	removeScrollbar:function(){
		this.item.removeClass('withScrollbar');
		this.scrollContainer.destroy();
	},
	getScrollbar:function() {
		this.scroller 	= new Element('div',{'class':'rubriekscrollbar'});
		this.knob 		= new Element('div',{'class':'rubriekscrolldot'});
		this.bUp 		= new Element('div',{'class':'scrollUp'});
		this.bDown 		= new Element('div',{'class':'scrollDown'});
		this.scrollContainer = new Element('div',{'class':'scrollContainer'}).adopt(this.scroller.adopt(this.knob),this.bUp,this.bDown);
		
		this.item.addEvent('mousewheel',this.mouseScroller.bind(this));
		
		this.bUp.addEvent('click',function(){this.scrollByStep(-5*this.options.scrollspeed)}.bind(this));
		this.bDown.addEvent('click',function(){this.scrollByStep(5*this.options.scrollspeed)}.bind(this));

		return this.scrollContainer;
	},
	dragger:function(el) {
		var scrollPercentage = el.getStyle('top').toInt()/(this.h_scroller-this.h_knob);
		this.scrollByPercentage(scrollPercentage*100);
	},
	mouseScroller:function(e) {
		this.scrollByStep(-1*this.options.scrollspeed*e.wheel);
	},
	scrollByPercentage:function(p) {
		var y=( (p/100) *  this.contentScrollSize());
		this.content.scrollTo(0,y);
	},
	scrollByStep:function(step) {
		var y=this.content.getScroll().y + step;
		this.content.scrollTo(0,y);
		
		//y=this.content.getScroll().y;
		scrollermove = ( (y/this.contentScrollSize())* (this.h_scroller-this.h_knob ) ).toInt();
		if(scrollermove<0)scrollermove=0;
		if(scrollermove>this.h_scroller) scrollermove = this.h_scroller;
		
		this.knob.setStyle('top',scrollermove+'px');
	},
	contentScrollSize:function(){
		return ( this.content.getScrollSize().y - this.content.getStyle('height').toInt()  );
	}
	
});



function cmdPauseToggle(el) {
	state = objPlayer.fgetPlayState();
	setPauseToggle(el);
	switch(state) {
		case 1:
		case 2:
			return cmdPlay(); 
		break;
		case 3:
			return cmdPause();
		break;
		default:
			return false;
		break;
	}
	
}




xml2json={
	parser:function(xmlcode,ignoretags,debug){
		if(!ignoretags){ignoretags=""};
		xmlcode=xmlcode.replace(/\s*\/>/g,'/>');
		xmlcode=xmlcode.replace(/<\?[^>]*>/g,"").replace(/<\![^>]*>/g,"");
		if (!ignoretags.sort){ignoretags=ignoretags.split(",")};
		var x=this.no_fast_endings(xmlcode);
		x=this.attris_to_tags(x);
		x=escape(x);
		x=x.split("%3C").join("<").split("%3E").join(">").split("%3D").join("=").split("%22").join("\"");
		for (var i=0;i<ignoretags.length;i++){
			x=x.replace(new RegExp("<"+ignoretags[i]+">","g"),"*$**"+ignoretags[i]+"**$*");
			x=x.replace(new RegExp("</"+ignoretags[i]+">","g"),"*$***"+ignoretags[i]+"**$*")
		};
		x='<JSONTAGWRAPPER>'+x+'</JSONTAGWRAPPER>';
		this.xmlobject={};
		var y=this.xml_to_object(x).jsontagwrapper;
		if(debug){y=this.show_json_structure(y,debug)};
		return y;
	},
	xml_to_object:function(xmlcode){
		var x=xmlcode.replace(/<\//g,"¤");
		x=x.split("<");
		var y=[];
		var level=0;
		var opentags=[];
		for (var i=1;i<x.length;i++){
			var tagname=x[i].split(">")[0];
			opentags.push(tagname);
			level++
			y.push(level+"<"+x[i].split("¤")[0]);
			while(x[i].indexOf("¤"+opentags[opentags.length-1]+">")>=0){level--;opentags.pop()}
		};
		var oldniva=-1;
		var objname="this.xmlobject";
		for (var i=0;i<y.length;i++){
			var preeval="";
			var niva=y[i].split("<")[0];
			var tagnamn=y[i].split("<")[1].split(">")[0];
			tagnamn=tagnamn.toLowerCase();
			var rest=y[i].split(">")[1];
			if(niva<=oldniva){
				var tabort=oldniva-niva+1;
				for (var j=0;j<tabort;j++){objname=objname.substring(0,objname.lastIndexOf("."))}
			};
			objname+="."+tagnamn;
			
			
			pobject=objname.substring(0,objname.lastIndexOf("."));
			if (eval("typeof "+pobject) != "object"){preeval+=pobject+"={value:"+pobject+"};\n"};
			var objlast=objname.substring(objname.lastIndexOf(".")+1);
			
			
			var already=false;
			for (k in eval(pobject)){if(k==objlast){already=true}};
			var onlywhites=true;
			for(var s=0;s<rest.length;s+=3){
				if(rest.charAt(s)!="%"){onlywhites=false}
			};
			if (rest!="" && !onlywhites){
				if(rest/1!=rest){
					rest="'"+rest.replace(/\'/g,"\\'")+"'";
					rest=rest.replace(/\*\$\*\*\*/g,"</");
					rest=rest.replace(/\*\$\*\*/g,"<");
					rest=rest.replace(/\*\*\$\*/g,">")
				}
			} 
			else {rest="{}"};
			if(rest.charAt(0)=="'"){rest='unescape('+rest+')'};
			if (already && !eval(objname+".sort")){preeval+=objname+"=["+objname+"];\n"};
			var before="=";after="";
			if (already){before=".push(";after=")"};
			var toeval=preeval+objname+before+rest+after;
			eval(toeval);
			if(eval(objname+".sort")){objname+="["+eval(objname+".length-1")+"]"};
			oldniva=niva
		};
		return this.xmlobject
	},
	show_json_structure:function(obj,debug,l){
		var x='';
		if (obj.sort){x+="[\n"} else {x+="{\n"};
		for (var i in obj){
			if (!obj.sort){x+=i+":"};
			if (typeof obj[i] == "object"){
				x+=this.show_json_structure(obj[i],false,1)
			}
			else {
				if(typeof obj[i]=="function"){
					var v=obj[i]+"";
					//v=v.replace(/\t/g,"");
					x+=v
				}
				else if(typeof obj[i]!="string"){x+=obj[i]+",\n"}
				else {x+="'"+obj[i].replace(/\'/g,"\\'").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")+"',\n"}
			}
		};
		if (obj.sort){x+="],\n"} else {x+="},\n"};
		if (!l){
			x=x.substring(0,x.lastIndexOf(","));
			x=x.replace(new RegExp(",\n}","g"),"\n}");
			x=x.replace(new RegExp(",\n]","g"),"\n]");
			var y=x.split("\n");x="";
			var lvl=0;
			for (var i=0;i<y.length;i++){
				if(y[i].indexOf("}")>=0 || y[i].indexOf("]")>=0){lvl--};
				tabs="";for(var j=0;j<lvl;j++){tabs+="\t"};
				x+=tabs+y[i]+"\n";
				if(y[i].indexOf("{")>=0 || y[i].indexOf("[")>=0){lvl++}
			};
			if(debug=="html"){
				x=x.replace(/</g,"&lt;").replace(/>/g,"&gt;");
				x=x.replace(/\n/g,"<BR>").replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;")
			};
			if (debug=="compact"){x=x.replace(/\n/g,"").replace(/\t/g,"")}
		};
		return x
	},
	no_fast_endings:function(x){
		x=x.split("/>");
		for (var i=1;i<x.length;i++){
			var t=x[i-1].substring(x[i-1].lastIndexOf("<")+1).split(" ")[0];
			x[i]="></"+t+">"+x[i]
		}	;
		x=x.join("");
		return x
	},
	attris_to_tags: function(x){
		var d=' ="\''.split("");
		x=x.split(">");
		for (var i=0;i<x.length;i++){
			var temp=x[i].split("<");
			for (var r=0;r<4;r++){temp[0]=temp[0].replace(new RegExp(d[r],"g"),"_jsonconvtemp"+r+"_")};
			if(temp[1]){
				temp[1]=temp[1].replace(/'/g,'"');
				temp[1]=temp[1].split('"');
				for (var j=1;j<temp[1].length;j+=2){
					for (var r=0;r<4;r++){temp[1][j]=temp[1][j].replace(new RegExp(d[r],"g"),"_jsonconvtemp"+r+"_")}
				};
				temp[1]=temp[1].join('"')
			};
			x[i]=temp.join("<")
		};
		x=x.join(">");
		x=x.replace(/ ([^=]*)=([^ |>]*)/g,"><$1>$2</$1");
		x=x.replace(/>"/g,">").replace(/"</g,"<");
		for (var r=0;r<4;r++){x=x.replace(new RegExp("_jsonconvtemp"+r+"_","g"),d[r])}	;
		return x
	}
};


if(!Array.prototype.push){
	Array.prototype.push=function(x){
		this[this.length]=x;
		return true
	}
};

if (!Array.prototype.pop){
	Array.prototype.pop=function(){
  		var response = this[this.length-1];
  		this.length--;
  		return response
	}
};
