

function requestajax(url,div){
	$(div).style.display = 'block';
	new Ajax.Request(url,
  {
    method:'post', 
	 requestHeaders: [ 'Cache-Control', 'no-cache', 'Pragma', 'no-cache'],
	 encoding: 'utf-8',
	 evalJS: 'true',
	 asynchronous: 'true',
	 onCreate: function(){ $(div).innerHTML = '<div class="preloader"></div>';},
	 onSuccess: function(transport) { 
	 	var response = transport.responseText;
	 	$(div).innerHTML = response;
	 },
    onFailure: function(){ $(div).innerHTML = 'błąd'; }
  });

}

function submitajax(url,div,divout){
	new Ajax.Request(url,
  {
    method:'post',
	 requestHeaders: [ 'Cache-Control', 'no-cache', 'Pragma', 'no-cache'],
	 encoding: 'utf-8',
	 evalJS: 'true',
	 asynchronous: 'true',
	 parameters: $(div).serialize(true),
	 onCreate: function(){ $(divout).innerHTML = 'Trwa realizacja żądania...' },
	 onSuccess: function(transport) { 
	 	var response = transport.responseText;
		$(divout).innerHTML = response;
	 },
    onFailure: function(){ $(divout).innerHTML = 'błąd'; }
  });
}

function checkEmail(){
	new Ajax.Request('http://www.meritohurt.pl/profil/sprawdzemail',
	{
		method:'post',
		requestHeaders: [ 'Cache-Control', 'no-cache', 'Pragma', 'no-cache'],
		encoding: 'utf-8',
		parameters: {emailadres: $('fr_email').value},
		onSuccess: function(transport) { 
			var json = transport.responseText.evalJSON(true);

			if( json.status == 'noexists' ){
				$('fr_email_out').innerHTML = json.msg;
			}
			else{
				$('fr_email_out').innerHTML = json.msg;
				new Effect.Highlight('fr_email_out');
			}
		}
	});
}

function tabshow_border(tabmenu){
	new Effect.Morph(tabmenu, {
	  style: 'activetabitems ', // CSS Properties
	  duration: 0.2 // Core Effect properties
	});
	$(tabmenu).style.background = '#FFFFFF';
}

function tabshow(tabgroup, tabmenu, tabid, prefix){
	//alert(root_path);
	var divs = $$('#'+tabgroup+' div.tabentry').length;
	var string_id = '';
	var tabitem_id = '';
	$(tabmenu).style.background = 'url('+root_path_tpl+'images/'+prefix+'tab-active.jpg) no-repeat left';
	$(tabmenu).style.color = '#3F4F0D';
	
	for( i=1; i<=divs; i++ ){
		string_id = prefix + 'tabbar_' + i;
		if( string_id != '' ){
			//alert(string_id);
			$(string_id).style.display = 'none';
		}
		
		tabitem_id = prefix + 'tabitem_' + i;
		if( tabmenu != tabitem_id){
			/*alert('tabitem_id: '+tabitem_id+'  tabmenu:'+tabmenu);*/
			$(tabitem_id).style.background = 'url('+root_path_tpl+'images/'+prefix+'tab-inactive.jpg) no-repeat left';
			$(tabitem_id).style.color = '#999999';
		}
	}
	$(tabid).style.display = 'block';
}

/**related=0&rel=0&fs=1*/
function getVideoThumb(videoid, divid, width, height){
	if( videoid && divid ){
   	var atts = { id: "myytplayer" };
		var params = { allowScriptAccess: "always", allownetworking: "internal", allowfullscreen: "true", wmode: "transparent" };
		swfobject.embedSWF("http://www.youtube.com/v/"+videoid+"&enablejsapi=0&playerapiid=ytplayer", divid, width, height, "8", null, null, params, atts);
	}
	else{
		$(divid).innerHTML = 'Błąd playera . brak id źródła';
	}
}	

function loadBox(divId, which){
	
	if( $(divId).style.display == 'none' ){
		Effect.BlindDown(divId, { duration: 0.7 });
		which.style.color = '#4F4F4F';
	}
	else{
		Effect.SwitchOff(divId, { duration: 0.7 });
		which.style.color = '#C0C0C0';
	}
}


function submitCommentForm(idForm, divOut){
	var params 	= $(idForm).serialize(true);
	var errorStatus 	= true;
	
	if( params.text == '' ){
		errorStatus = false;
		alert('Twój komentarz wygląda na ... nierozpoczęty? :)');
	}
	else if( params.user_name == '' ){
		errorStatus = false;
		alert('Odwagi! Podpisz się pod swoim komentarzem :)');
	}
	else if(params.post_token == ''){
		errorStatus = false;
		alert('Przepisz token! Udowodnij że nie jesteś bootem :)');
	}
	
	if( errorStatus === false ) return false;
	
	submitajax(root_path+'page/addcoment', idForm, divOut);
	
}


function changefontsize($size){
	$('article-text').style.fontSize = $size+'px';
}

function flashnewsBoot(){
	if( $('infoflash').style.display == 'none' ){
		$('infoflash').appear();
	}
	//new Effect.SlideUp('infoflash', { queue: 'end' });
	requestajax(root_path+'p/flash/1', 'infoflash');
	//setInterval("Effect.Fade('infoflash', { duration: 0.5 });", 2000);
}

function flashnews(){
	setInterval("flashnewsBoot();", 10000);
}