// JavaScript Document

var objDevelopment = Class.create( {
	initialize: function (request, uri, postvars){
		this.request 	= request;
		this.uri	 	= uri;		
		this.postvars	= '';	
		this.current_element = '';	
			
		if(Object.isString(postvars)){
			postdata	= postvars.evalJSON(true);						
			this.postvars = Object.toQueryString (postdata);
			
		}
	},
	build: function (){		
		var child = $('outer');	
		var developmentBar = new Element  ('div', { 'id': 'vpJSDevelopment'});			
		var developmentBar_html = '';		
		developmentBar_html += "<a href=\"javascript: vpDevelopment.close();\" class=\"close\">X</a><div class=\"toolbox\">";
		developmentBar_html += '<strong>Ontwikkeltools:</strong> ';
		
		developmentBar_html += "<a href=\"/?com=sandbox\">De zandbak</a> | ";
		developmentBar_html += "<a href=\"javascript: vpDevelopment.parseinfo_show();\">Parse info</a> | ";
		
			
		developmentBar_html += "<a href=\"javascript: vpDevelopment.techreport_show();\">Technisch rapport</a> | ";
		
		/*
		developmentBar_html += "<a href=\"javascript: 		;"\">Parse info</a> | ";*/

		developmentBar_html += "<a href=\"http://bugs.itakeit.nl/reportissue.php\" target=\"_blank\">Raporteer (BUG) melding</a> | "; 				
		developmentBar_html += "<a href=\"javascript: vpDevelopment.runBot();\">Kit versneld uitvoeren</a> |  <strong> HTTP: </strong>" + vpDev_server_hostname;
		developmentBar_html += " | <strong> MySQL Master: </strong>" + vpDev_mysql_master_hostname;
		developmentBar_html += " | <strong> MySQL Slave: </strong>" + vpDev_mysql_slave_hostname 	+ "</div> "; 	
		

		developmentBar.update( developmentBar_html);
		
		child.insert ({ before: developmentBar} );
		var devider = new Element  ('div', { 'id': 'vpJSDevelopment_devider'}).update ();		
		//devider.hide();
		$('vpJSDevelopment').insert ({after: devider});
		
		
		var parseinfo = new Element  ('div', { 'id': 'vpJSDevelopment_parseInfo'});		

		parseinfo_html = "<div class=\"content\" id=\"vpJSDevelopment_parseInfo_content\"></div>";
		
		parseinfo.innerHTML = parseinfo_html;
		
		
			
		var techreport = new Element  ('div', { 'id': 'vpJSDevelopment_techreport'}).update ();			
		

		
		
		//alert( scrolloffset.top);
		//alert ( document.viewport.getHeight());
		//alert ( scrolloffset.height);
		
		/*
		if ( document.viewport.getHeight() < $('outer').offsetHeight) {
			//$('outer').style.height = ( document.viewport.getHeight- 45) + 'px';
		}
		else {
			$('outer').style.height = (document.viewport.getHeight()-$('footer').offsetHeight) + 'px';
			$('footer').style.marginTop = '0px';
		}
*/		var ie = /MSIE (\d+\.\d+);/.test(navigator.userAgent);
		var ieversion=new Number(RegExp.$1);
		
		if ( ie && ieversion>=6 &&  ieversion < 7){ //test for MSIE x.x;
			//alert ( 'IE6');
			//$('footer').style.marginTop = '-45px';
		//$('container').style.height = ( document.viewport.getHeight() +100) + 'px';		
			$('outer').style.height = ( document.viewport.getHeight() - 25) + 'px';				
			$('container').style.height = ( document.viewport.getHeight() -45 ) + 'px';
		}else {
			scrolloffset = document.viewport.getDimensions();
			$('outer').style.height = ( document.viewport.getHeight() - 45) + 'px';
			devider.insert ({before: parseinfo});
			$('footer').style.marginTop = '0px';			
		}
		
		Event.observe(document.onresize ? document : window, "resize", function() {
			var ie = /MSIE (\d+\.\d+);/.test(navigator.userAgent);
			var ieversion=new Number(RegExp.$1);
			
			if ( ie && ieversion>=6 &&  ieversion < 7){ 	
				$('outer').style.height = ( document.viewport.getHeight() - 25) + 'px';				
				$('container').style.height = ( document.viewport.getHeight() -45 ) + 'px';
			}else {
				scrolloffset = document.viewport.getDimensions();
				$('outer').style.height = ( document.viewport.getHeight() - 45) + 'px';				
				$('footer').style.marginTop = '0px';			
			}
		} );
		
		parseinfo.hide();
	    ct = new Date();

		
		tech_html = '<div class="info">';
		tech_html += '<textarea style="\width: 880px; height: 450px;\">########### TECHNISCH RAPPORT ###########\n\n';
		
		tech_html += '[ AANVRAAG ]\n\n';
		tech_html += 'Datum/tijd: ' + ct.getDate() + '-' + ct.getMonth() + '-' + ct.getFullYear() + ' / ' + ct.getHours() + ':' + ct.getMinutes() + ' uur \n';
		tech_html += 'Huidige pagina: ' + document.location + '\n';
		tech_html += 'Verwijzende pagina: ' + vpDev_referer + '\n\n';
				
		tech_html += '[ APPLICATIE ]\n\n';			
		tech_html += 'Geladen componenten: ' + vpDev_components  + '\n';
		tech_html += 'Geladen plugins: ' + vpDev_plugins  + '\n';
		tech_html += 'Opgevraagde templates: ' + ( vpDev_fttemplates ? vpDev_fttemplates : "-")  + '\n';
		tech_html += 'Weergegeven templates: ' + vpDev_shwtemplates  + '\n\n';
		
		tech_html += '[ GEBRUIKER ]\n\n';
		tech_html += 'Operation System: ' + BrowserDetect.OS + '\n';
		tech_html += 'Webbrowser: ' + BrowserDetect.browser + ' ' + BrowserDetect.version + '\n';				
		tech_html += 'Schermresolutie: ' + screen.width + 'x' + screen.height + '\n';
		tech_html += 'Kleurkwaliteit: ' + screen.pixelDepth + ' bits\n\n';

		tech_html += '[ OMGEVING ]\n\n';
		tech_html += 'GET: ' + (vpDev_get ? vpDev_get : "-") + '\n';
		tech_html += 'POST: ' + (vpDev_post ? vpDev_post : "-") + '\n\n';
		
		
	tech_html += '########### EIND TECHNISCH RAPPORT ###########\n\n';
	/*	tech_html += 'Cookie-data: ' + document.cookie  + '\n';*/
		tech_html += '</textarea></div>';
		
		developmentBar.insert ({after: techreport});
		techreport.innerHTML = tech_html;
		techreport.hide();
		
 	var myMenuItems = [
		  {
			name: 'Markeren',
			className: 'edit', 
			callback: function (){
				alert ( this.uri);	
			}
		  },{
			name: 'Copy',
			className: 'copy', 
			callback: function() {
			  alert('Copy function called');
			}
		  },{
			name: 'View-source', 
			
			className: 'delete',
			callback: function() {
			 document.location = "view-source:" + document.location;
			}
		  },{
			separator: true
		  },{
			name: 'Save',
			className: 'save',
			callback: function() {
			  alert('Saving...');
			}
		  }
		];
	
	/*
		new Proto.Menu({
		  selector: '#outer', // context menu will be shown when element with id of "contextArea" is clicked
		  className: 'menu desktop', // this is a class which will be attached to menu container (used for css styling)
		  menuItems: myMenuItems // array of menu items
		})
*/		
		/*
		Event.observe($('outer'), 'mousemove', function(event) {
			var elt = Event.element(event);
			if (elt && elt != document)
			//$(elt).style.backgroundColor = '#003366';
			$(elt).addClassName ( 'development_over');
			//$(elt).hide();
		});*/
		Event.observe($('outer'), 'mouseover', function (event){
														 		var elt = Event.element(event);
		if (elt && elt != document)	
		this.current_element = 	$(elt);
														 });

		
	},
	runBot: function (){
		new Ajax.Request('/bot.php', 
			{	  onSuccess: function(transport) {
					alert ( 'Kit bot is versneld uitgevoerd, als u mail verwacht, zult u deze binnen enkele ogenblikken ontvangen.\n\nHieronder vindt u het rapport:\n\n' + transport.responseText);
			}
			} );
	},
	close: function (){
		$('vpJSDevelopment_devider').hide();
		$('vpJSDevelopment').hide();
	
	},
	techreport_show: function(){
		Modalbox.show($('vpJSDevelopment_techreport'), {title: 'Technisch rapport', width: 900, height: 500});
	},
	parseinfo_show: function (){
		
		/*
		$('vpJSDevelopment_parseInfo').show();
		$('vpJSDevelopment_parseInfo').setOpacity(1);
			
		
		
		$html->addOnload(");	
		
		
		
		//alert (parse_url); */
			
		Modalbox.show($('vpJSDevelopment_parseInfo'), {title: 'Parse info', width: 900, height: 400});
		
		$('vpJSDevelopment_parseInfo_content').update ( "<img src=\"/spinner.gif\" alt=\"loading...\" />");		
		
		if (/\?/.test(this.uri))	var parse_url = this.uri + '&parse_info=1';
		else 						var parse_url = this.uri + '?parse_info=1';	
		
		
		if ( this.request == 'GET'){					
			new Ajax.Request(parse_url, {
			  method: 'get',
			  onSuccess: function(transport) {
				var vpJSDevelopment_parseInfo_content = $('vpJSDevelopment_parseInfo_content');
				$('vpJSDevelopment_parseInfo_content').innerHTML = "<div class=\"inner\" style=\"overflow: auto; height: 340px;width: 870px;  \">"+ transport.responseText + "</div>";
			  }
			});	
		}
		else if ( this.request == 'POST'){		
			
			if ( confirm ( 'Deze pagina was geladen met een POST Request! Sommige pagina\'s bevatten een anti-spam functie waardoor het resultaat niet realistisch is! Wilt u deze nogmaals uitvoeren om parseinformatie te kunnen bekijken?')){
				new Ajax.Request(parse_url, {
				  method: 'post',
				  postBody: this.postvars,
				  onSuccess: function(transport) {
					var vpJSDevelopment_parseInfo_content = $('vpJSDevelopment_parseInfo_content');
					$('vpJSDevelopment_parseInfo_content').innerHTML = "<div class=\"inner\">"+ transport.responseText + "</div>";
				  }
				});	
			}
			else {
				Modalbox.hide();
				return;	
			}
		}
		
	
	},
	parseinfo_hide: function (){
		Modalbox.hide();
	},	
	mark_element: function (){
		//elm = this.current_element;
		alert (uri);
		//this.current_element .addClassName ( 'development_over');
	},	
	register_element: function (event){

		//this.current_element.innerHTML = elt;

	}
	
});

