﻿flash = new FlashConfig();



function FlashConfig() {

	this.forcehide = false;

	this.movies = new Array();

	this.embedMode = (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) ? true : false; // netscape plugin architecture (NS3+, Mozilla, Opera3+, IE5+ Mac)

	this.version = 0;

	this.minor = 0;

	this.rev = 0;



	this.setFlashVer = function(verArray) {

		this.version = parseInt(verArray[0]) || 0;

		this.minor = parseInt(verArray[1]) || 0;

		this.rev = parseInt(verArray[2]) || 0;

	};

	

	if(this.embedMode) {

		var sf = navigator.plugins["Shockwave Flash"];

		if(sf && sf.description) {

			this.setFlashVer(sf.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));

		}

	}

	else if(window.ActiveXObject) { // IE4+ Win32

		try {

			var aObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");

			this.setFlashVer(aObj.GetVariable("$version").split(" ")[1].split(","));

		} catch (e) {}

	}

}



function FlashObj(src,width,height) {

	flash.movies[flash.movies.length] = this;

	this.num = flash.movies.length-1;

	this.id = "flashobj_" + this.num;

	this.src = src;

	this.width = width;

	this.height = height;

	this.wmode = "transparent";

	this.params = new Array();

	this.minVersion = 7;



	this.addParam = function(name,value) {

		this.params[this.params.length] = { key:name, val:value };

	};

	

	this.setVersion = function(value) {

		this.minVersion = value;

	};

	

	this.setOpaque = function(wmode) {

		this.wmode = "opaque";

	};

	

	this.setForceHide = function() {

		flash.forcehide = true;

		this.wmode = "window";

	};



	// set unchangable params

	this.addParam("quality","high");

	this.addParam("menu","false");

	this.addParam("allowScriptAccess","sameDomain");

	

	this.getHTML = function() {

		// set wmode

		this.addParam("wmode",this.wmode);

		

		// create html

		var flashHTML = '<div id="flash_'+this.num+'" class="flashobj" style="width:'+this.width + ((this.width.toString().indexOf("%") > -1) ? "" : "px") + ';height:'+this.height+((this.height.toString().indexOf("%") > -1) ? "" : "px")+'; overflow:hidden;z-index: 1;margin: 0 auto;">';

    	if(flash.embedMode) {

	        flashHTML += '<embed style="z-index: 1;" type="application/x-shockwave-flash" pluginspace="'+location.protocol+'//www.macromedia.com/go/getflashplayer" src="'+ this.src +'" width="'+ ((this.width.toString().indexOf("%") > -1) ? "100%" : this.width) +'" height="'+ ((this.height.toString().indexOf("%") > -1) ? "100%" : this.height) +'" id="'+ this.id + '" name="'+ this.id +'"';

	        for(var i = this.params.length-1; i > -1; i--) {

				flashHTML += ' ' + this.params[i].key + '="' + this.params[i].val + '"';

			}

	        flashHTML += '></embed>';

		}

		else {

	        flashHTML += '<object style="z-index: 1;" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+location.protocol+'//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.minVersion+',0,0,0" width="'+ ((this.width.toString().indexOf("%") > -1) ? "100%" : this.width) +'" height="'+ ((this.height.toString().indexOf("%") > -1) ? "100%" : this.height) +'" id="'+ this.id +'">';

	        flashHTML += '<param name="movie" value="' + this.src + '" />';

	        for(var i = this.params.length-1; i > -1; i--) {

				flashHTML += '<param name="' + this.params[i].key + '" value="' + this.params[i].val + '" />';

			}

	        flashHTML += '</object>';

		}

		return (flashHTML += "</div>");

	};

	

	this.write = function(targetID) {

		var target = document.getElementById(targetID);

		if (flash.version >= this.minVersion) {

			target.innerHTML = this.getHTML();

		}

		else {

			var noFlashMsg = '<div id="flasherrormsg" style="border:1px solid #999; padding:10px; margin:0; background-color:#ffffff; text-align:center;"><p>This content requires the Macromedia Flash Player version ' + this.minVersion + ' or higher.<br><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img src="https://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" style="margin-top:5px;" /></a></p></div>';

			var childNodes = target.childNodes;

			var childCount = 0;

			for (var i = 0; i < childNodes.length; i++) {

				if (childNodes[i].nodeType != 3 && childNodes[i].nodeName.toLowerCase() != "script") {

					childCount++;

				}

			}

			if (childCount === 0) {

				target.innerHTML = noFlashMsg; // if no alt content, write out upgrade message

			}

		}

	};

	

}



function addCaptionsToImages() {
   wrapImagesInDiv( 'figure', [], [ 'float' ] );
}


if(typeof window.addEventListener != 'undefined') {
   window.addEventListener('load', addCaptionsToImages, false);
}
else if(typeof document.addEventListener != 'undefined') {
   document.addEventListener('load', addCaptionsToImages, false);
}
else if(typeof window.attachEvent != 'undefined') {
   window.attachEvent('onload', addCaptionsToImages);
}

function wrapImagesInDiv( className, attributes, styles ) {
   var images = document.getElementsByClassName(className);
   for ( var i = 0; i < images.length; ++i ) {
      var img = images[i];
      // Lift the image out of the page and insert a div under it.
      var parent = img.parentNode;
      var frame = document.createElement('div');
      var txt = document.createTextNode(img.getAttribute('title'));
      parent.insertBefore(frame, img);
      parent.removeChild(img);
      frame.appendChild(img);
      frame.appendChild(txt);
      // These are special cases.  We always copy these from the image to the
      // div.
      frame.style.width = img.getAttribute('width') + 'px';
      frame.className = img.className;
      // Copy specified attributes and style properties from the image to the
      // div.
      for ( var j = 0; j < attributes.length; ++j ) {
         frame.setAttribute(attributes[j], img.getAttribute(attributes[j]));
      }
      for ( var j = 0; j < styles.length; ++j ) {
         frame.style[styles[j]] = img.style[styles[j]];
      }
   }
}




	function viThumbRes(zone, id)
	{
		document.getElementById("viMidiThumb").src = 'http://files.aktivist.pl/viThumb/' + zone + '/' + id + '_midithumb.jpg?rand=' + Math.floor(Math.random()*1000);
		document.getElementById("viThumbThumb").src = 'http://files.aktivist.pl/viThumb/' + zone + '/' + id + '_minithumb.jpg?rand=' + Math.floor(Math.random()*1000);
		document.getElementById("viThumb").src = 'http://files.aktivist.pl/viThumb/' + zone + '/' + id + '_thumb.jpg?rand=' + Math.floor(Math.random()*1000);	
		document.getElementById("viThumbId").value = id;
		document.getElementById("viThumbDel").style.display = 'block';
	}	
	
	function viThumb(zone, id)
	{
		var viThumbWindow = window.open('/viThumb/index.php?zone=' + zone + '&id=' + id, '_blank', 'width=400,height=350,resizable=0,scrollbars=no,menubar=no,status=yes' );
	}
	
	function addDate(d, h)
	{
		if (!d) d = '';
		//if (!h) h = '{{$smarty.now|date_format:"%H"}}.00';
		if (!h) h = '';
		var e = document.createElement('div');
		e.innerHTML = 'Data: <input type="text" size="10" name="vnt_date[]" value="'+d+'" /> godzina: <input type="text" size="5" name="vnt_hour[]" value="'+h+'" /> [ <span style="cursor:pointer; color: #cc3300; font-weight: bold;" onclick="delDate(this)">usuń datę</span> ]';
		document.getElementById('dates').appendChild(e);
	}	
	
	function addDates()
	{
		var d = new Array();
		d[1] = document.getElementById('kre_d1').checked;
		d[2] = document.getElementById('kre_d2').checked;
		d[3] = document.getElementById('kre_d3').checked;
		d[4] = document.getElementById('kre_d4').checked;
		d[5] = document.getElementById('kre_d5').checked;
		d[6] = document.getElementById('kre_d6').checked;
		d[0] = document.getElementById('kre_d7').checked;
		
		var ddd1 = document.getElementById('kre_od').value;
		var ddd2 = document.getElementById('kre_do').value;
		var h = document.getElementById('kre_hour').value;
		
		var dd1 = new Date(~~ddd1.substr(0, 4), ~~ddd1.substr(5, 2)-1, ~~ddd1.substr(8, 2), 12, 0, 0);
		var dd2 = new Date(~~ddd2.substr(0, 4), ~~ddd2.substr(5, 2)-1, ~~ddd2.substr(8, 2), 12, 0, 0);
		for(var i = ~~(dd1.getTime()/1000); i<=~~(dd2.getTime()/1000); i+=86400)
		{
			var t = new Date(i*1000);
			if(d[t.getDay()])
				addDate(t.getFullYear() + '-' + (t.getMonth()<10?'0':'') + t.getMonth() + '-' + (t.getDate()<10?'0':'') + t.getDate(), h);
		}
	}	
		
	function delDate(o)
	{
		o.parentNode.parentNode.removeChild(o.parentNode);
	}
	
	

function rank(rank, type, id, res)
{
	advAJAX.post({
	    url: "/ajax/rank/",
	    parameters : {
			"rank" : rank,
			"type" : type,
			"id" : id
	    },
	    timeout : 3000,
	    onSuccess : function(obj) { document.getElementById(res).innerHTML = obj.responseText; },
	    onError : function(obj) { document.getElementById(res).innerHTML = 'AjaxError: ' + obj.responseText; }
	});
}

function linkRank(rank, id, res)
{
	advAJAX.post({
	    url: "/ajax/rank/",
	    parameters : {
			"rank" : rank,
			"type" : "link",
			"id" : id
	    },
	    timeout : 3000,
	    onSuccess : function(obj) { var b = trim(obj.responseText); document.getElementById(res).innerHTML = b; if(b.substr(0, 3) == 'Dzi') { document.getElementById('rank_value_' + id).innerHTML = ~~document.getElementById('rank_value_' + id).innerHTML + rank; } },
	    onError : function(obj) { document.getElementById(res).innerHTML = 'AjaxError: ' + obj.responseText; }
	});
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function ajaxcform(form, res, del1, del2)
{
	advAJAX.assign(document.getElementById(form), 
	{
		timeout : 3000,
	    parameters : {
			"ajax" : 1
	    },
	   	onSuccess : function(obj) 
	   	{ 
	   		var r = trim(obj.responseText);
		   	if(r.substr(0, 1) == '#')
		   	{
		   		document.getElementById(del1).innerHTML = '<p class="pkom_text">' + (r.substr(1)).replace("|||", "<br />").replace("|||", "<br />").replace("|||", "<br />").replace("|||", "<br />").replace("|||", "<br />").replace("|||", "<br />").replace("|||", "<br />") + '<br /><br />&nbsp;</p>';
		   		document.getElementById(del2).innerHTML = '';
		   	}
		   	else
			   	document.getElementById(res).innerHTML = r;
	   	},
	    onError : function(obj) { document.getElementById(res).innerHTML = 'AjaxError: ' + obj.responseText; }
	});
}


	function FCKajax()
	{
	        this.UpdateEditorFormValue = function()
	        {
	                for ( i = 0; i < parent.frames.length; ++i )
	                        if ( parent.frames[i].FCK )
	                                parent.frames[i].FCK.UpdateLinkedField();
	        }
	}
	var FFF = new FCKajax();

function ajaxform(form, res)
{
	var savf = document.getElementById('save_elm');
			
	if(savf)
	savf.onclick = function()
	{
		//oFCKeditor.UpdateEditorFormValue();
		FFF.UpdateEditorFormValue();
	}	
	
	advAJAX.assign(document.getElementById(form), 
	{
		timeout : 6000,
	    parameters : {
			"ajax" : 1
	    },
	   	onSuccess : function(obj) 
	   	{ 
	   		var r = trim(obj.responseText);
		   	if(r.substr(0, 1) == '#')
		   	{
		   		document.getElementById(res).innerHTML = r.substr(1);
		   		document.getElementById(form).innerHTML = '';
		   	}
		   	else
			   	document.getElementById(res).innerHTML = r;
			window.scrollTo(0,0);
	   	},
	    onError : function(obj) { document.getElementById(res).innerHTML = 'AjaxError: ' + obj.responseText; }
	});
}


function ajax_get_quarters(cid, res, sel, def)
{
	advAJAX.post({
	    url: "/ajax/getquarters/",
	    parameters : {
			"cid" : cid,
			"sel" : sel,
			"def" : def
	    },
	    timeout : 3000,
	    onSuccess : function(obj) { document.getElementById(res).innerHTML = obj.responseText; },
	    onError : function(obj) { document.getElementById(res).innerHTML = obj.responseText; }
	});
}

function ajax_get_locals(pat, cid, res, sel, def)
{
	advAJAX.post({
	    url: "/ajax/getlocals/",
	    parameters : {
	    	"pat" : pat,
			"cid" : cid,
			"sel" : sel,
			"def" : def
	    },
	    timeout : 3000,
	    //onLoading : function(obj) { document.getElementById(res).innerHTML = 'Trwa wczytywanie...';
	    //},
	    onSuccess : function(obj) { document.getElementById(res).innerHTML = obj.responseText;
	    //myfilter = new filterlist("vnt_local");
	     },
	    onError : function(obj) { document.getElementById(res).innerHTML = obj.responseText; }
	    
	});
	
}