function load_url(url){
    if (url) document.location.href = url;
}

/*bookmarks this page*/
function addbookmark() {

    var tytul = document.title;
    var adres = document.location;
    //FireFox
    if (window.sidebar) { 
        window.sidebar.addPanel(tytul, adres, ""); 
    //IE
    //} else if (window.external) {
      //  window.external.AddFavorite(adres, tytul); 
    //Opera
    } else /*if (window.opera && window.print)*/ {
        alert('Please use CTRL + D to bookmark this website.');
    }
}

/*for include js file*/
function include(script_filename) {
    document.write('<' + 'script');
    document.write(' language="javascript"');
    document.write(' type="text/javascript"');
    document.write(' src="' + script_filename + '">');
    document.write('</' + 'script' + '>');
}
/*include js file after page load*/
function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

function slideSwitch(id) {
    var $active = $('#slideshow'+id+' li.active');
    if ( $active.length == 0 ) $active = $('#slideshow'+id+' li:last');
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow'+id+' li:first');
    $active.addClass('last-active');
    $active.animate({opacity: 0.0}, 1000, function() {
    	$active.css('display','none');
    	$next.css({opacity: 0.0,display: 'block'})
       		.addClass('active')
        	.animate({opacity: 1.0}, 1000, function() {
     	       	$active.removeClass('active last-active');
    	});
    });
}


var Main = {
	Set: function(el){
		    var $tabs = $(el).tabs({
			selected: (($.cookie('tabs'))?$.cookie('tabs'):0),
			show:function(e,ui){
				$.cookie('tabs',ui.index);
				//$('.main-right').css({'opacity':'0','width':'0px'});
				//$('.main-right').animate({
				//	opacity: 1,
				//	width: '250px'
				//});
			},
		 	fx: [{opacity:'toggle', duration:'slow'},{opacity:'toggle', duration:'slow'}]}).tabs("rotate", 15000, true );
	}
}

function Load(){
	this.tinymce = function(){
		$(document).ready(function() {
		$('textarea.tinymce').tinymce({
			file_browser_callback : "tinyBrowser",
			// Location of TinyMCE script
			script_url : GLOBAL__PATH_JAVASCRIPT+'tiny_mce/tiny_mce.js',
			init_instance_callback: function(){
				if($('#'+$(this).attr('id')).css('border') == '1px solid rgb(255, 0, 0)'){
					$('#'+$(this).attr('id')+'_tbl').css('border','1px solid rgb(255, 0, 0)');
				}
			},
			// General options
			theme : "advanced",
			language : "en",
			plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "pastetext,pasteword|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,preview",
			theme_advanced_buttons3 : "forecolor,backcolor,tablecontrols,|,hr,removeformat,visualaid",
			theme_advanced_buttons4 : "sub,sup,|,fullscreen",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,
			theme_advanced_resize_horizontal : false,
			// Example content CSS (should be your site CSS)
			content_css : GLOBAL__PATH_CSS+"style_articles.css",
			//content_css : "css/content.css",

			// Drop lists for link/image/media/template dialogs
			template_external_list_url : "lists/template_list.js",
			external_link_list_url : TINY_MCE_LINK_FILE,
			external_image_list_url : "lists/image_list.js",
			media_external_list_url : "lists/media_list.js",
			font_size_style_values : "8px,11px,12px,13px,14px,16px,18px",
			// Replace values for the template plugin
			template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}
		});
		});
	};
	this.datepicker = function(el,format){
   		include("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js");
		$(document).ready(function(){
			$(el).datepicker({ dateFormat: format});
		});
	}
}


function float(el){
	var float=/^[0-9\.]*$/i;
	var not_float=/[^0-9\.]+/g;
	var value = $(el).val();
	if(value.match(float)){$(el).val(value);
	}else{$(el).val(value.replace(not_float,""));}
}

function integer(el){
	var format=/^[0-9]*$/i;
	var not_format=/[^0-9]+/g;
	var value = $(el).val();
	if(value.match(format)){$(el).val(value);
	}else{$(el).val(value.replace(not_format,""));}
}

function clear_input(arg1,arg2){
	if(arg1){$('#'+arg1).val('');}
	if(arg2){$('#'+arg2).val('');}
}

function Move(){
	this.menu = function(URL_MOVE){
			$("div.cat_2").sortable({ opacity: 0.6, cursor: 'move',handle: 'span.move',  update: function() {
				var data = $(this).sortable("serialize"); 
				notice_load();
				$.post(URL_MOVE, data, function(theResponse){$('body').prepend(theResponse);remove_notice_load();}); 															 
			}								  
			});
			$("div#sortable").sortable({ opacity: 0.6, cursor: 'move',handle: '.cat_parent span.move',  update: function() {
				var data = $(this).sortable("serialize"); 
				notice_load();
				$.post(URL_MOVE, data, function(theResponse){$('body').prepend(theResponse);remove_notice_load();}); 															 
			}								  
			});
	};
	this.products = function(URL_MOVE){
		$("table tbody").sortable({ opacity: 0.6, cursor: 'move',handle: 'td.move',  update: function() {
				var data = $(this).sortable("serialize"); 
				notice_load();
				$.post(URL_MOVE, data, function(theResponse){$('body').prepend(theResponse);remove_notice_load();}); 															 
			}								  
			});
	};
	this.gallery = function(URL_MOVE){
		$("table tbody").sortable({ opacity: 0.6, cursor: 'move',handle: 'td.move',  update: function() {
				var data = $(this).sortable("serialize"); 
				notice_load();
				$.post(URL_MOVE, data, function(theResponse){$('body').prepend(theResponse);remove_notice_load();}); 															 
			}								  
			});
	};
	this.links = function(URL_MOVE){
		$("table tbody").sortable({ opacity: 0.6, cursor: 'move',handle: 'td.move',  update: function() {
				var data = $(this).sortable("serialize"); 
				notice_load();
				$.post(URL_MOVE, data, function(theResponse){$('body').prepend(theResponse);remove_notice_load();}); 															 
			}								  
			});
	};
	this.hotnews = function(URL_MOVE){
		$("#hotnews #sortable").sortable({ opacity: 0.6, cursor: 'move',handle: 'span.move',  update: function() {
				var data = $(this).sortable("serialize"); 
				notice_load();
				$.post(URL_MOVE, data, function(theResponse){$('body').prepend(theResponse);remove_notice_load();}); 															 
			}								  
			});
	}
	
	

}

var Newsletter = {
	change: function(type){
		if(type == '1'){
			$('#newsletter_subscribe').attr('checked', true);
			$('#newsletter_unsubscribe').attr('checked', false);
		}else{
			$('#newsletter_subscribe').attr('checked', false);
			$('#newsletter_unsubscribe').attr('checked', true);
		}
	}
}

var Categories = {
	SetLang: function(URL_LANG,el,value,lang){
		if(el){
		var data = "id="+el+"&value="+value+'&lang='+lang;
			notice_load();
			$.post(URL_LANG, data, function(theResponse){remove_notice_load()}); 		
		}
	},
	Show: function(id){
		$('.child[id!="child_'+id+'"]').slideUp('fast');
		$('.li_parent > a').removeAttr('class');
		$('#parent_'+id).attr('class','active');
		$('#child_'+id).slideToggle('fast');
	}
	
}


var Articles={
	Type: function(){
		if($('#type').val() == "plik"){
			$('.tresc').hide();
			$('.plik').show();
		}else{
			$('.plik').hide();
			$('.tresc').show();
		}
	},
	AddGallery: function(el,box){
		var id = $('#'+el+' :selected').val();
		var title = $('#'+el+' :selected').text();
		var exist = 0;
		if(id){
			$('.gallery_list').each(function(){
				if($(this).val() == id){
					alert(Lang['_GALERIA_O_PODANEJ_NAZWIE_JEST_JUZ_DODANA']+'.');
					exist = 1;
				}
			});
			if(!exist){
				$('#'+box).append('<input type="hidden" name="gallery_list[]" class="gallery_list" id="gallery_list_'+id+'" value="'+id+'" /> <div id="gallery_'+id+'" ><b>'+title+'</b><a id="delete_'+id+'" class="delete" href="javascript:Articles.DeleteGallery(\''+id+'\')">&nbsp;</a><span class="clear">&nbsp;</span></div>');
				$('#change_gallery').val('1');
			}
		}else{alert(Lang['_GALERIA_NIE_ZOSTALA_WYBRANA']+'.');}
	
	},
	DeleteGallery: function(id){
		$('#gallery_'+id).remove();
		$('#gallery_list_'+id).remove();
		$('#change_gallery').val('1');
	},
	AddArticles: function(el,box){
		var id = $('#'+el+' :selected').val();
		var title = $('#'+el+' :selected').text();
		var exist = 0;
		if(id){
			$('.articles_list').each(function(){
				if($(this).val() == id){
					alert(Lang['_ARTYKUL_O_PODANEJ_NAZWIE_JEST_JUZ_DODANY']+'.');
					exist = 1;
				}
			});
			if(!exist){
				$('#'+box).append('<input type="hidden" name="articles_list[]" class="articles_list" id="articles_list_'+id+'" value="'+id+'" /> <div id="articles_'+id+'" ><b>'+title+'</b><a id="delete_'+id+'" class="delete" href="javascript:Articles.DeleteArticles(\''+id+'\')">&nbsp;</a><span class="clear">&nbsp;</span></div>');
				$('#change_articles').val('1');
			}
		}else{alert(Lang['_ARTYKUL_NIE_ZOSTAL_WYBRANY']+'.');}
	
	},
	DeleteArticles: function(id){
		$('#articles_'+id).remove();
		$('#articles_list_'+id).remove();
		$('#change_articles').val('1');
	},
	ChangeAccess: function(id,URL){
		if(id){
		var data = "id="+id+"&value="+$('#access_'+id).val();
			notice_load();
			$.post(URL, data, function(theResponse){remove_notice_load()}); 		
		}
	}
}

var News = {
	ChangeStatus: function(URL_NEWS,id,value){
		if(id){
			var data = "id="+id+"&value="+value;
			notice_load();
			if(value == '1'){ $('#item_'+id).attr('class','row0');$('#status_'+id).val('2');
			}else{$('#item_'+id).attr('class','tr_red');$('#status_'+id).val('1');}
			$.post(URL_NEWS, data, function(theResponse){$('body').prepend(theResponse);remove_notice_load();}); 		
		}
	},
	AddHotNews: function (URL_NEWS,id,value){
		if(id && URL_NEWS){
			notice_load();
			if(value == '1'){ $('#hot_news_'+id).val('0');$('#hot_news_'+id).attr('checked',true);
			}else{$('#hot_news_'+id).val('1');$('#hot_news_'+id).attr('checked',false);}
			data = "id="+id+"&value="+value;
			$.post(URL_NEWS, data, function(theResponse){$('#hotnews').html(theResponse);remove_notice_load();}); 	
		
		}
	},
	Slider: function(class_name){
		var height = $(class_name).height();
		setTimeout("News.Slide('"+class_name+"','"+height+"')", 5000);
	},
	Slide: function(class_name, height){
		var height_inside = $(class_name+' #hotnews').height();
		var count = Math.ceil(height_inside/height);
		var marginTop = parseInt($(class_name+' #hotnews').css('margin-top'));
		if(Math.ceil((marginTop*-1)/height) == (count-1)){
			$(class_name+' #hotnews').animate({'marginTop': '+='+(marginTop*-1)+'px'}, 800 );
		}else{
			$(class_name+' #hotnews').animate({'marginTop': '-='+height+'px'}, 800 );
		}
		setTimeout("News.Slide('"+class_name+"','"+height+"')", 10000);
	}
}

var Gallery = {
	change_status: function(element,URL_CHANGE_STATUS){
		if(element){
		var id = $(element).attr('id').replace('status_','');
		var val = $(element).val();
		var data = "id="+id+"&val="+val;
			notice_load();
			$.post(URL_CHANGE_STATUS, data, function(theResponse){
				if(val == 2){
					$('tr[id^="recordsArray_'+id+':"]').attr('class','tr_red');
				}else{
					$('tr[id^="recordsArray_'+id+':"]').removeAttr('class');
				}
				$('body').prepend(theResponse);
				remove_notice_load();
			});
		}
	}
}

var Page = {
	SetContentHeight: function(){
		if($('#center .article').height() < 420){
			$('#center .article').css('height','445px');
		}
	}
}


var loader_count = 0;
function notice_load(){
	if($('#body_black_white').css('display') != 'block' && $('#body_black').css('display') != 'block'){
		$('body').prepend('<div id="body_black_white" class="body_black"></div><div id="loader"></div>');
		$('#body_black_white').css('height',''+$(document).height()+'px');
		$('#body_black_white').css('display','block');
		$width = $(window).width()/2;
		$height = $(window).height()/2;
		$('#loader').css({'left':$width+'px', 'top':$height+'px'});
	}
	loader_count++;
}

function remove_notice_load(){
	if(loader_count == 1){
	$('#body_black_white').remove();
	$('#loader').remove();
	}
	loader_count--;
}

/*for error and notice*/
function notice(message){
	$('.notice').remove();
	$('.error').remove();
	$('<div class="notice">'+message+'</div>').insertAfter('#topmenu');
	$.post('clearnotice.html', '', function(theResponse){});
}

function error(message){
	$('.notice').remove();
	$('.error').remove();
	$('<div class="error">'+message+'</div>').insertAfter('#topmenu');
	$.post('clearnotice.html', '', function(theResponse){});
}

function remove_notice_and_error(){
	$('.notice').fadeOut("slow");
	$('.notice').remove();
	$('.error').fadeOut("slow");
	$('.error').remove();
}


/* for browser version */
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	checkBrowser: function (element){
		if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version <= 6){
			$(element).append(
			'<div class="ie">'+
				'<h2>'+Lang['_TWOJA_PRZEGLADARKA_NIE_JEST_JUZ_OBSLUGIWANA']+'.</h2>'+
				'<a target="_blank" href="http://www.google.com/chrome/index.html?brand=CHNY&utm_campaign=en&utm_source=en-et-youtube&utm_medium=et"><img src="./public/graf/ie6/chrome.gif" alt="Chrome" /></a>'+
				'<a target="_blank" href="http://www.mozilla.com/?from=sfx&uid=267821&t=449"><img src="./public/graf/ie6/firefox.gif" alt="Firefox" /></a>'+
				'<a target="_blank" href="http://www.apple.com/safari/"><img src="./public/graf/ie6/safari.gif" alt="Safari" /></a>'+
				'<a target="_blank" href="http://www.opera.com/browser/"><img src="./public/graf/ie6/opera.gif" alt="Opera" /></a>'+
				'<a target="_blank" href="http://www.microsoft.com/windows/internet-explorer/default.aspx"><img src="./public/graf/ie6/ie8.gif" alt="Internet Explorer 8" /></a>'+
			'</div>'
			);
		}
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};







