<!--

// mce_editor_7_toolbar
function strip_tags(str, allowed_tags) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
 
    var key = '', tag = '', allowed = false;
    var matches = allowed_array = [];
    var allowed_keys = {};
 
    var replacer = function(search, replace, str) {
        return str.split(search).join(replace);
    };
 
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
    }
  
    str += '';
 
    // Match tags
    matches = str.match(/(<\/?[^>]+>)/gi);
 
    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
 
        // Save HTML tag
        html = matches[key].toString();
 
        // Is tag not in allowed list? Remove from str!
        allowed = false;
 
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;
 
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
 
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
 
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
 
    return str;
}



//script by http://www.yvoschaap.com

//XMLHttpRequest class function
function datosServidor() {
};
datosServidor.prototype.iniciar = function() {	
  try {
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
		
	} catch (e) {
		// Explorer
		var _ieModelos = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		for (var i=0;i < _ieModelos.length && !success; i++) {
			try {
				this._xh = new ActiveXObject(_ieModelos[i]);
				success = true;
			} catch (e) {
			}
		}
		if ( !success ) {		  
			return false;
		}		
    return true;
		
	}
}

datosServidor.prototype.ocupado = function() {
	estadoActual = this._xh.readyState;
	return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() {
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

datosServidor.prototype.enviar = function(urlget,datos) {
	if (!this._xh) {		
    this.iniciar();
	}
	if (!this.ocupado()) {		    
    this._xh.open("GET",urlget,false);
    //alert('urlget:'+urlget);
    this._xh.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-2');
    //alert(urlget);    		
		this._xh.send(datos);
		if (this._xh.readyState == 4 && this._xh.status == 200) {
			return this._xh.responseText;
		}
		
	}
	return false;
}


var urlBase = "update.php";
var formVars = "";
var changing = false;
var changing_tiny = false;
var too="";
var con="";


function fieldEnter(campo,evt,idfld) {
	evt = (evt) ? evt : window.event;
	if (evt.keyCode == 13 && campo.value!="") {
		elem = document.getElementById( idfld );
		remotos = new datosServidor;		
		nt = remotos.enviar(urlBase + "?fieldname=" +encodeURI(elem.id)+ "&content="+encodeURI(campo.value)+"&"+formVars,"");
		//nt = remotos.enviar(urlBase + "?fieldname=" +elem.id+ "&content="+campo.value+"&"+formVars,"");
		
		//remove glow
		noLight(elem);
		//alert(nt);
		
		elem.innerHTML = strip_tags(nt);
		changing = false;
		return false;
	} else {
		return true;
	}


}

function fieldBlurInput(campo,idfld) {

	if (campo.value!="") {        
    elem = document.getElementById( idfld );		    
		remotos = new datosServidor;		
		var nt = remotos.enviar(urlBase + "?fieldname=" +encodeURI(elem.id)+ "&content="+encodeURI(campo.value)+"&"+formVars,"");
    								
    //nt = remotos.enviar("?fieldname=" +elemid+ "&content="+str+"&"+formVars,"");
			//alert(nt);
		elem.innerHTML = strip_tags(nt);			
		changing = false;
		window.current=null;
		
		return false;		
	}	 
}

function fieldBlur(campo,idfld) {
  //alert(campo.value);	
  //if (campo!="") { 
	
    //alert('blur');	
    elem = document.getElementById( idfld );
    	
		//tekst=document.getElementById('documentSummary').innerHTML;	
		remotos = new datosServidor;
    		
		//nt = remotos.enviar(urlBase + "?fieldname=" +decodeURI(elem.id)+ "&content="+decodeURI(campo)+"&"+formVars,"");		
		//nt = remotos.enviar(urlBase + "?fieldname=" +elem.id+ "&content="+campo+"&"+formVars,"");
		//alert('campo: '+campo);
		var nt = remotos.enviar(urlBase + "?fieldname=" +escape(elem.id)+ "&content="+escape(campo)+"&"+formVars,"");
    //document.getElementById('tools').innerHTML=urlBase + "?fieldname=" +escape(elem.id)+ "&content="+escape(campo)+"&"+formVars;
		//'alert('nt: '+nt);										
		elem.innerHTML = nt;
				
    //alert('innerHTML: '+elem.innerHTML);				
		//changing = false;
		window.current=null;
		return false;		
	
	//}	 
}

//edit field created
function editBox(actual) {
  //alert(changing);	
	//alert('window - current'+window.current);
		if (window.current)
			{
			//alert('tylko jedno okno do edycji moze byc otwarte. zamknij'+ window.current);
			}
			else 
					{
							
								window.current=actual.id;
								width = widthEl(actual.id) + 20;
								height = heightEl(actual.id) + 2;	  
								
								if (actual.id == 'documentTitle')
								{
									 if(!changing){    
											actual.innerHTML=strip_tags(actual.innerHTML);											
										  actual.innerHTML = "<input id=\""+ actual.id +"\" style=\"width: "+width+"px; height: "+height+"px;\" maxlength=\"254\" type=\"text\" value=\"" + actual.innerHTML + "\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlurInput(this,'" + actual.id + "');\" />";                                        
									 }
									 changing = true;
									 actual.firstChild.focus(); 
								}
								else
										{     
												window.current=actual.id;												 
												width = 560;												 
											
											  //alert('pit actual id:' + actual.id);											  											     
												actual.innerHTML = "<div id='"+ actual.id +"_field' style='width: 560px; height: 34px;' >" + actual.innerHTML + "</div>";
                            												                       												 
												 tinyMCE.execCommand( 'mceAddControl', false, actual.id+'_field');												 
												 var znal=false;
												 var t=document.getElementsByTagName('div');
												 for (var i=0; i<t.length; i++)												
													
													if (t[i].className=='instantDiv')
														{
														 
														 window.exit='no';
														 t[i].onmouseout=function() {window.exit='yes';}
														 t[i].onmouseover=function() {window.exit='no';}
														 break;
														}
												
										}															
						}
  	
}



//find all span tags with class editText and id as fieldname parsed to update script. add onclick function
function editbox_init(){
	if (!document.getElementsByTagName){ return; }
	//var spans = document.getElementsByTagName("span");
	var spans = document.getElementsByTagName("span");

	// loop through all span tags
	for (var i=0; i<spans.length; i++){
		var spn = spans[i];

    if (((' '+spn.className+' ').indexOf("editText") != -1) && (spn.id)) {
			spn.onclick = function () { editBox(this); }
			spn.style.cursor = "pointer";
			spn.title = "Kliknij aby edytować!";	
    }
	}
}

//crossbrowser load function
function addEvent(elm, evType, fn, useCapture)
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Please upgrade your browser to use full functionality on this page");
  }
}

//get width of text element
function widthEl(span){

	if (document.layers){
	  w=document.layers[span].clip.width;
	} else if (document.all && !document.getElementById){
	  w=document.all[span].offsetWidth;
	} else if(document.getElementById){
	  w=document.getElementById(span).offsetWidth;
	}
return w;
}

//get height of text element
function heightEl(span){

	if (document.layers){
	  h=document.layers[span].clip.height;
	} else if (document.all && !document.getElementById){
	  h=document.all[span].offsetHeight;
	} else if(document.getElementById){
	  h=document.getElementById(span).offsetHeight;
	}
return h;
}

function highLight(span){
            //span.parentNode.style.border = "2px solid #D1FDCD";
            //span.parentNode.style.padding = "0";
            span.style.border = "1px solid #54CE43";          
            
}

function noLight(span){
        //span.parentNode.style.border = "0px";
        //span.parentNode.style.padding = "2px";
        span.style.border = "0px";   
}

//sets post/get vars for update
function setVarsForm(vars){
	formVars  = vars;
}

addEvent(window, "load", editbox_init);
-->
