/* 
------------------------------------------
 Flipbox written by CrappoMan
 simonpatterson@dsl.pipex.com
------------------------------------------
*/

//modified by Wooya
function flipBox(who) {
   var tmp;
   if (document.images['b_' + who].src.indexOf('_on') == -1) {
      tmp = document.images['b_' + who].src.replace('_off', '_on');
      document.getElementById('box_' + who).style.display = 'none';
      if (document.getElementById('box_' + who + '_diff')) {
         document.getElementById('box_' + who + '_diff').style.display = 'block';
      }
      document.images['b_' + who].src = tmp;
      disply = 'none';
      now = new Date();
      now.setTime(now.getTime()+1000*60*60*24*365);
      expire = (now.toGMTString());
      document.cookie = "fusion_box_"+who+"=" + escape(disply) + "; expires="+expire;
   } else {
      tmp = document.images['b_' + who].src.replace('_on', '_off');
      document.getElementById('box_' + who).style.display = 'block';
      if (document.getElementById('box_' + who + '_diff')) {
         document.getElementById('box_' + who + '_diff').style.display = 'none';
      }
      document.images['b_' + who].src = tmp;
      disply = 'block';
      now = new Date();
      now.setTime(now.getTime()+1000*60*60*24*365);
      expire = (now.toGMTString());
      document.cookie = "fusion_box_"+who+"=" + escape(disply) + "; expires="+expire;
   }
}

//modified by wooya
function addText(elname, strFore, strAft, formname) {
   if (formname == undefined) formname = 'inputform';
   if (elname == undefined) elname = 'message';
   element = document.forms[formname].elements[elname];
   element.focus();
   // for IE 
   if (document.selection) {
	   var oRange = document.selection.createRange();
	   var numLen = oRange.text.length;
	   oRange.text = strFore + oRange.text + strAft;
	   return false;
   // for FF and Opera
   } else if (element.setSelectionRange) {
      var selStart = element.selectionStart, selEnd = element.selectionEnd;
			var oldScrollTop = element.scrollTop;
      element.value = element.value.substring(0, selStart) + strFore + element.value.substring(selStart, selEnd) + strAft + element.value.substring(selEnd);
      element.setSelectionRange(selStart + strFore.length, selEnd + strFore.length);
			element.scrollTop = oldScrollTop;      
      element.focus();
   } else {
			var oldScrollTop = element.scrollTop;
      element.value += strFore + strAft;
			element.scrollTop = oldScrollTop;      
      element.focus();
	}
}

//modified by Wooya
function insertText(elname, what, formname) {
   if (formname == undefined) formname = 'inputform';
   if (document.forms[formname].elements[elname].createTextRange) {
       document.forms[formname].elements[elname].focus();
       document.selection.createRange().duplicate().text = what;
   } else if ((typeof document.forms[formname].elements[elname].selectionStart) != 'undefined') {
       // for Mozilla
       var tarea = document.forms[formname].elements[elname];
       var selEnd = tarea.selectionEnd;
       var txtLen = tarea.value.length;
       var txtbefore = tarea.value.substring(0,selEnd);
       var txtafter =  tarea.value.substring(selEnd, txtLen);
       var oldScrollTop = tarea.scrollTop;
       tarea.value = txtbefore + what + txtafter;
       tarea.selectionStart = txtbefore.length + what.length;
       tarea.selectionEnd = txtbefore.length + what.length;
       tarea.scrollTop = oldScrollTop;
       tarea.focus();
   } else {
       document.forms[formname].elements[elname].value += what;
       document.forms[formname].elements[elname].focus();
   }
}

//modified by Wooya to W3C standards
function show_hide(msg_id) {
   document.getElementById(msg_id).style.display = document.getElementById(msg_id).style.display == 'none' ? 'block' : 'none';
}

//modified by Wooya to work properly with Opera
function correctPNG() {
   // correctly handle PNG transparency in Win IE 5.5 or higher.
   if (navigator.appName=="Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera")==-1) {
      for(var i=0; i<document.images.length; i++) {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }
}

function getStyle(el,style)
{
	if(typeof el == "string")
		var element = document.getElementById(el);
	else
		var element = el;
	if (element.currentStyle)
		var value = element.currentStyle[style];
	else if (window.getComputedStyle)
		var value = document.defaultView.getComputedStyle(element,null).getPropertyValue(style);
	return value;
}

/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function getposOffset(overlay, offsettype){
   var totaloffset=(offsettype=='left')? overlay.offsetLeft : overlay.offsetTop;
   var parentEl=overlay.offsetParent;
   while (parentEl!=null) {
      if(getStyle(parentEl, "position") != "relative"){
	     totaloffset=(offsettype=='left')? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
      }
	  parentEl=parentEl.offsetParent;
   }
   return totaloffset;
}
   
function overlay(curobj, subobjstr, opt_position){
   if (document.getElementById){
      var subobj=document.getElementById(subobjstr)
      subobj.style.display=(subobj.style.display!='block')? 'block' : 'none'
      var xpos=getposOffset(curobj, 'left')+((typeof opt_position!='undefined' && opt_position.indexOf('right')!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
      var ypos=getposOffset(curobj, 'top')+((typeof opt_position!='undefined' && opt_position.indexOf('bottom')!=-1)? curobj.offsetHeight : 0)
      subobj.style.left=xpos+'px'
      subobj.style.top=ypos+'px'
      return false
   }
   else
   return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display='none'
}

//written by Wooya
NewWindowPopUp = null;
function OpenWindow(src, wdth, hght, wcenter) {
   //close previous popup window
   if (NewWindowPopUp != null) {
        NewWindowPopUp.close();
        NewWindowPopUp = null;
   }
   //if center parameter given center opoup window 
   if (wcenter == false) { 
      wtop = 0;
      wleft = 0;
   } else {
        wtop = (screen.availHeight-hght)/2;
        wleft = (screen.availWidth-wdth)/2;
   }
   NewWindowPopUp = window.open(src, "","toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=yes,status=no,directories=no,resizable=yes,height="+hght+",width="+wdth+",top="+wtop+",left="+wleft+"");
   NewWindowPopUp.focus();
}

//Image Resizer by Matonor
function resize_forum_imgs(){
	var max;
	var viewport_width;
	//Get the width of the viewport
	if(self.innerWidth)
		viewport_width = self.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth)
		viewport_width = document.documentElement.clientWidth;
	else if(document.body)
		viewport_width = document.body.clientWidth;
	else
		viewport_width = 1000;

	//Set the max width/height according to the viewport-width
	if(viewport_width <= 800)
		max = 200;
	else if(viewport_width < 1152)
		max = 300;
	else if(viewport_width >= 1152)
		max = 400;
	
	//loop through images that have the className forum-img
	for(var i=0; i<document.images.length; i++) {
		var image = document.images[i];
		if(image.className!="forum-img"){
			continue;
		}
		var height = image.height;
		var width = image.width;
		var resized = false;
		//resize the image with correct aspect ratio
		if(width <= height){
			if(height > max){
				image.height = max;
				image.width = width*(max/height);
				resized = true;
			}
		}else{
			if(width > max){
				image.width = max;
				image.height = height*(max/width);
				resized = true;
			}
		}
		
		//Find the div around the image and the next element around the div.
		var span = image.parentNode;
		var parent = span.parentNode;
		if(span.className != "forum-img-wrapper"){
			continue;
		}
		
		if(resized){ //Insert the link and make the span inline
			span.style.display = "inline";
			if(parent.tagName != "A"){
				span.onclick = new Function("OpenWindow('"+image.src+"', "+(width+40)+", "+(height+40)+", true)");
				span.onmouseover = "this.style.cursor='pointer'";
			}
		}else{ //only make the span inline
			span.style.display = "inline";
		}
	}
	return true;
}

function onload_events(){//Add function calls to be executed onload here
	resize_forum_imgs();
	correctPNG();
}

window.onload = onload_events;

function rmw_go()
{
	var rmw_img_array = document.getElementsByTagName("IMG");
	for (var i = 0; i < rmw_img_array.length; i++)
	{
		var rmw_img = rmw_img_array[i];
		if (String(rmw_img.getAttribute('resizemod')) == 'on')
		{
			if (rmw_wait_for_width && rmw_img.width && !isNaN(rmw_img.width))
			{
				if (rmw_img.width > Number(rmw_max_width))
				{
					rmw_img.setAttribute('resizemod','off');
					rmw_img.onload = null;
					rmw_img.removeAttribute('onload');
					var rmw_clone = rmw_img.cloneNode(false);
					var rmw_parent = rmw_img.parentNode;
					rmw_clone.setAttribute('width',String(rmw_max_width));
					rmw_parent.replaceChild(rmw_clone,rmw_img);
					rmw_make_pop(rmw_clone);
				}
			}
			else if (!rmw_wait_for_width)
			{
				rmw_img.setAttribute('resizemod','off');
				var rmw_clone = rmw_img.cloneNode(false);
				rmw_img.onload = null;
				rmw_img.removeAttribute('onload');
				var rmw_parent = rmw_img.parentNode;
				var rmw_ind = rmw_count++;
				rmw_clone.setAttribute('resizemod',String(rmw_ind));
				rmw_preload[rmw_ind] = new Image();
				rmw_preload[rmw_ind].src = rmw_img.src;
				if (window.showModelessDialog)
				{
					rmw_clone.style.margin = '2px';
				}
				rmw_clone.style.border = rmw_border_1;
				rmw_clone.style.width = '28px';
				rmw_parent.replaceChild(rmw_clone,rmw_img);
			}
		}
	}
	if (!rmw_over && document.getElementById('resizemod'))
	{
		rmw_over = true;
		rmw_go();
	}
	else if (!rmw_over)
	{
		window.setTimeout('rmw_go()',2000);
	}
}
function rmw_img_loaded(rmw_obj)
{
	if (!document.getElementsByTagName || !document.createElement) {return;}
	var rmw_att = String(rmw_obj.getAttribute('resizemod'));
	var rmw_real_width = false;
	if ((rmw_att != 'on') && (rmw_att != 'off'))
	{
		var rmw_index = Number(rmw_att);
		if (rmw_preload[rmw_index].width)
		{
			rmw_real_width = rmw_preload[rmw_index].width;
		}
	}
	else
	{
		rmw_obj.setAttribute('resizemod','off');
		if (rmw_obj.width)
		{
			rmw_real_width = rmw_obj.width;
		}
	}
	if (!rmw_real_width || isNaN(rmw_real_width) || (rmw_real_width <= 0))
	{
		var rmw_rand1 = String(rmw_count++);
		eval("rmw_retry" + rmw_rand1 + " = rmw_obj;");
		eval("window.setTimeout('rmw_img_loaded(rmw_retry" + rmw_rand1 + ")',2000);");
		return;
	}
	if (rmw_real_width > Number(rmw_max_width))
	{
		if (window.showModelessDialog)
		{
			rmw_obj.style.margin = '2px';
		}
		rmw_make_pop(rmw_obj);
	}
	else if (!rmw_wait_for_width)
	{
		rmw_obj.style.width = String(rmw_real_width) + 'px';
		rmw_obj.style.border = '0';
		if (window.showModelessDialog)
		{
			rmw_obj.style.margin = '0px';
		}
	}
	if (window.ActiveXObject) // IE on Mac and Windows
	{
		window.clearTimeout(rmw_timer1);
		rmw_timer1 = window.setTimeout('rmw_refresh_tables()',10000);
	}
}
function rmw_refresh_tables()
{
	var rmw_tables = document.getElementsByTagName("TABLE");
	for (var j = 0; j < rmw_tables.length; j++)
	{
		rmw_tables[j].refresh();
	}
}
function rmw_make_pop(rmw_ref)
{
	rmw_ref.style.border = rmw_border_2;
	rmw_ref.style.width = String(rmw_max_width) + 'px';
	if (!window.opera)
	{
		rmw_ref.onclick = function()
		{
			if (!rmw_pop.closed)
			{
				rmw_pop.close();
			}
			rmw_pop = window.open('about:blank','christianfecteaudotcom',rmw_pop_features);
			rmw_pop.resizeTo(window.screen.availWidth,window.screen.availHeight);
			rmw_pop.moveTo(0,0);
			rmw_pop.focus();
			rmw_pop.location.href = this.src;
		}
	}
	else
	{
		var rmw_rand2 = String(rmw_count++);
		eval("rmw_pop" + rmw_rand2 + " = new Function(\"rmw_pop = window.open('" + rmw_ref.src + "','christianfecteaudotcom','" + rmw_pop_features + "'); if (rmw_pop) {rmw_pop.focus();}\")");
		eval("rmw_ref.onclick = rmw_pop" + rmw_rand2 + ";");
	}
	document.all ? rmw_ref.style.cursor = 'hand' : rmw_ref.style.cursor = 'pointer';
	rmw_ref.title = rmw_image_title;
	if (window.showModelessDialog)
	{
		rmw_ref.style.margin = '0px';
	}
}
if (document.getElementsByTagName && document.createElement) // W3C DOM browsers
{
	rmw_preload = new Array();
	if (window.GeckoActiveXObject || window.showModelessDialog) // Firefox, NN7.1+, and IE5+ for Win
	{
		rmw_wait_for_width = false;
	}
	else
	{
		rmw_wait_for_width = true;
	}
	rmw_pop_features = 'top=0,left=0,width=' + String(window.screen.width-80) + ',height=' + String(window.screen.height-190) + ',scrollbars=1,resizable=1';
	rmw_over = false;
	rmw_count = 1;
	rmw_timer1 = null;
	if (!window.opera)
	{
		rmw_pop = new Object();
		rmw_pop.closed = true;
		rmw_old_onunload = window.onunload;
		window.onunload = function()
		{
			if (rmw_old_onunload)
			{
				rmw_old_onunload();
				rmw_old_onunload = null;
			}
			if (!rmw_pop.closed)
			{
				rmw_pop.close();
			}
		}
	}
	window.setTimeout('rmw_go()',2000);
}

var rmw_max_width = 500; // you can change this number, this is the max width in pixels for posted images
var rmw_border_1 = '1px solid solid';
var rmw_border_2 = '2px dotted dotted';
var rmw_image_title = 'Klikni pre zobrazenie v pôvodnej veľkosti';
