/* scripts for debuging */
/* Ctrl+Shift+X shows the XML-tree */
/* Ctrl+Shift+H shows the HTML-tree */
/* Ctrl+Shift+D shows the Newt debug */
/* Ctrl+Shift+M shows the XML-mode */
/* Ctrl+Shift+C shows the Return to page */

var allkeys = new Array ('_xml','_newt_debug','_xml_mode','_html','_newt_debug_step','_inline_editor')

function getKey(e){
	if (!e) var e = window.event;
	var cCode = (e.charCode) ? e.charCode : 0;
	var kCode = (e.keyCode) ? e.keyCode : 0;
	var code = cCode + kCode;
	if (e.ctrlKey && e.shiftKey) {
		switch (code) {
			case(88) :  // Shift+Ctrl+X
		 		location_xml('_xml');
			break;
			case(68) :  // Shift+Ctrl+D
		 		location_xml('_newt_debug');
			break;
			case(72) :  // Shift+Ctrl+H
		 		location_xml('_html');
			break;
			case(77) :  // Shift+Ctrl+M
		 		location_xml('_xml_mode');
			break;
			case(67) :  // Shift+Ctrl+C
		 		location_xml('');
			break;
			case(69) :  // Shift+Ctrl+E
				getFrameworkEditor();
			break;
			case(81) :  // Shift+Ctrl+Q // lenux // 28.10.2008
				location_xml('_inline_editor');
			break;
		}
	
	}

/*
	// test for keycodes not needed in work
	// use it, if you don't know what event code use on keydown
	
	if (e.ctrlKey && e.shiftKey) {
	// if CTRL+SHIFT pressed - red symbols
		document.getElementById('sss').innerHTML = '<span style="color:red">'+code+'</span><br>';
	} else {
	// if without CTRL+SHIFT pressed - black symbols
		document.getElementById('sss').innerHTML = code+'<br>';
	}

*/

	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	
	}


function clear_allkeys (str) {
	str = new String(str)
	var i;
	for (i=0; i< allkeys.length ; i ++) {
		var key = allkeys[i]
		if (str.indexOf('?'+key) != -1) {
			var arr = str.split(key)
		} else {
			var arr = str.split('&'+key)
		}
		str = arr.join('');
	}
	return str;
}

function location_xml (flag) {
	var cl = document.location.href
	cl = clear_allkeys (cl)
	if ( cl.indexOf('#') != -1  )
		cl=cl.substring(0,cl.indexOf('#'));

	if ( flag!='' )
		cl += ( cl.indexOf('?') !=-1 ) ?  '&'+flag : '?&'+flag

	if ( cl.indexOf('?') ==  cl.length - 1)
		cl=cl.substring(0,cl.length-2);

	document.location=cl
}

function getFrameworkEditor() {
	var editorPath = '/admin/editor';
	document.location=editorPath;	
}

// in IE onkeypress not work properly, but with onkeydown all work!
document.onkeydown = getKey; 

