// JavaScript Document
// GET OBJECT //
function $$(id) {
	if(document.getElementById) obj = document.getElementById(id);
	else obj = document.all[id];
	return obj;
}
function swap_img(new_img,obj) {
	obj.src = new_img;
}
/*#####################
#### preload images ###
#####################*/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
MM_preloadImages('images/progresbar.gif','images/loading.gif')

// AJAX //
// get site //
/*advAJAX.setDefaultParameters({
	onLoading : function(obj) { $('preloader_div').style.visibility = 'visible'; $('Loader').style.visibility = 'visible'; },
	onFinalization : function() { $('preloader_div').style.visibility = "hidden"; $('Loader').style.visibility = "hidden"; }
});*/
function get_url(path,objid) {
	advAJAX.get({
		url : path,
		// onLoading : function(obj) { $(objid).innerHTML = 'Ładowanie modułu...<br/><img src="images/progresbar.gif" alt="" />'; },
		onSuccess : function(obj) {
			HTMLcode = obj.responseText;
			$(objid).innerHTML = HTMLcode;
			// alert(HTMLcode);
		},
		onError : function(obj) { $(objid).innerHTML = 'ERROR while loading<br/>' + obj.status;	}
	});
}

// post form //
function submit_form(formid,objid) {
	advAJAX.submit($(formid), {
		onSuccess : function(obj) {
			HTMLcode = obj.responseText;
			$(objid).innerHTML = HTMLcode;
			$(objid).style.textAlign='left'; $(objid).style.verticalAlign='top';
		},
		onError : function(obj) { $(objid).innerHTML = 'ERROR while loading<br/>' + obj.status;	}
	});
}
function assign_form(formid,objid) {
	advAJAX.assign($(formid), {
		onSuccess : function(obj) {
			HTMLcode = obj.responseText;
			$(objid).innerHTML = HTMLcode;
			$(objid).style.textAlign='left'; $(objid).style.verticalAlign='top';
		},
		onError : function(obj) { $(objid).innerHTML = 'ERROR while loading<br/>' + obj.status;	}
	});
}

// MODULES //
function licz(pole,maximum) {
	str = pole.value;
	//alert(str.length);
	if(str.length>maximum) {
		pole.value = pole.value.substr(0,maximum);
	}
}
function disp_div(objid,vis) {
	if(vis) {
		$(objid).style.visibility = vis;
	} else {
		if($(objid).style.visibility == 'visible') $(objid).style.visibility = 'hidden';
		else $(objid).style.visibility = 'visible';
	}
}

// CALENDAR //
function set_date(d,m,y) {
	if(window.date_contener) {
		$(window.date_contener).value = d+'-'+m+'-'+y;
	}
}
function reset_pos(e) {
	mouseX = getMouseXY(e,'x');
	mouseY = getMouseXY(e,'y');
	
	$('calendar_div').style.top = mouseY + 10 + 'px';
	$('calendar_div').style.left = mouseX + 10 + 'px';
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
function getMouseXY(e,os) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	
		if (window.innerHeight) pos = window.pageYOffset;
		else if (document.documentElement && document.documentElement.scrollTop) pos = document.documentElement.scrollTop;
		else if (document.body) pos = document.body.scrollTop;
		
		tempY += pos;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	
	
	if(os=='x') return tempX;
	if(os=='y') return tempY;
}
// MODULE TABS //
function switch_tab(objid,url,id,count) {
	for(var i=1; i<=count; i++) {
		if(i==objid) $('tab_'+i).className = 'tab_over';
		else $('tab_'+i).className = 'tab_out';
	}
	get_url(url,id);	
}
// LOADER //
function follow_loader(e) {
	obj = $('Loader');
	mouseX = getMouseXY(e,'x');
	mouseY = getMouseXY(e,'y');
	
	doc_x = screen.availWidth;
	doc_y = screen.availHeight;
	
	window.status = 'X:'+obj.style.top+"|Y:"+doc_y;

	if(mouseX+60>doc_x) obj.style.left = mouseX-20+'px';
	else obj.style.left = mouseX+15+'px';
	obj.style.top = mouseY+20+'px';
	
}

// SEARCH //
function search_focus() {
	if($('search').value == 'search') {
		$('search').value = '';
		$('search').className = '';
	}
}
function search_blur() {
	if($('search').value == 'search' || $('search').value == '') {
		$('search').value = 'search';
		$('search').className = 'search_temp';
	}
}

/* 	ASNIMATIONS */
window.m_over = new Array();
function func_timer(objid,func) {
	window.timer_out = setTimeout(func+'("'+objid+'")',1000);
}
function blind_out(objid) {
	obj = $(objid);
	
	if(!window.m_over[objid]) {
		if(window.timer_out) clearTimeout(window.timer_out);
		obj.style.display = 'none';
		window.sitemap_div = 0;
	}
}
function show_sitemap(objid) {
	obj = $(objid);
	
	if(!window.sitemap_div) {
		if(window.timer_out) clearTimeout(window.timer_out);
		obj.style.display = 'block';
		window.sitemap_div = 1;
	}
}
window.scroll_flag = 0;
function scroll_div(objid,val) {
	if(window.scroll_flag) {
		$(objid).scrollTop += val;
		if(window.scrollTimer) clearTimeout(window.scrollTimer);
		window.scrollTimer = setTimeout('scroll_div("'+objid+'",'+val+')',10);
	}
}

/* PSEUDO CRON FUNCTION */
function pseudo_cron() {
	// list of cron task's //
	urls = new Array('http://www.ruah.pl/ajax.php?opt=newsletter_email&task=sendmail');
	for(var i=0; i<urls.length ;i++) {
		advAJAX.get({
			url : urls[i],
			onError : function(obj) { }
		});
	}
	
	// other stuff onload //
	if($('mod_shop_vert')) get_url('ajax.php?opt=shop','mod_shop_vert');

}


//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["ForumFrame"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller


function swf_insert(filename,w,h) {
			var oeTags = '<object  style="position:absolute;" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			+ 'width="'+w+'" height="'+h+'"'
			+ 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">'
			+ '<param name="movie" value="'+filename+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="wmode" value="transparent" />'
			+ '<embed src="'+filename+'" quality="high" bgcolor="#000000" '
			+ 'width="'+w+'" height="'+h+'" name="MapViewer9" align="middle"'
			+ 'play="true"'
			+ 'wmode="transparent"'
			+ 'loop="false"'
			+ 'quality="high"'
			+ 'allowScriptAccess="sameDomain"'
			+ 'type="application/x-shockwave-flash"'
			+ '>'
			+ '<\/embed>'
			+ '<\/object>';
		majorVersion=8;
		minorVersion=8;
		installinfo='<br/><br/><br/><a href="https://www.macromedia.com/go/getflashplayer" class="black" target="_blank" ><img src="images/GET_FLA.png" alt="pobierz Flash Playera" border="0" /><br/>pobierz wtyczke <strong>flash player</strong></a>'; // URL zawierajacy informacje o potrzebie instalacji
		if(navigator.product=='Gecko' || navigator.userAgent.indexOf('Opera')!=-1) {
		 if(plugin=navigator.plugins["Shockwave Flash"]) {
		  if(majorVersion > parseInt(plugin.description.substr(plugin.description.indexOf(".")-1, 1))
		  || minorVersion > parseInt(plugin.description.substr(plugin.description.length-2)) )
			document.write(installinfo);  // pobieranie flasha
		  else document.write(oeTags);
		 } else {
			document.write(installinfo);  // pobieranie flasha 
		 }
		}
		else document.write(oeTags);
		//-->
}

// SEND COMENT //
function send_coment() {
	document.ComentForm.pin.value = '123qwe';
	submit_form('ComentForm','mod_coment');
}