/**
* JS source: (C) Web_Sprendimai
* Date: December, 2009
* No rights to copy without authors Permission
* Written for use on "Kauno Ugnelė"
*/

/** Changes thumb in img */
function changephoto(arr_id, change_img, change_style, back_effect) {
	/*alert(change_img);*/
	//var url_obj = document.getElementById("xchgurl");
	var img_obj = document.getElementById("xchgimg");
	var source_img = document.getElementById("xchgimgfrom"+arr_id);
	var old_main_img = img_obj.src;
	//alert("FROM:" + source_img.src + " TO: " + change_img);
	//alert(source_img.src);
	//url_obj.href = change_img;
	img_obj.src = change_img;
	if(change_style !== undefined && change_style !== false) {
		img_obj.style = change_style;
	}
	/*if(back_effect === true) {
		
		source_img.src = old_main_img;
	}*/
}

function isDefined(variable) {
	return (typeof(window[variable]) == "undefined") ? false : true;
}


/** ********* IEŠKOME AR RODYSIME ELEMENTĄ ********* */
function checkShowElement(finalId,currSelectedCategoryId,substBy) {
	var currentSelCatsIdsList = finalId.substr(substBy);
	var currentSelDependentOnCats = currentSelCatsIdsList.split('__');
	var catsArraySize = currentSelDependentOnCats.length;
	var showElement = false;
	/***DEBUG***/ //if(x<14 && x> 11)alert('ARRS:'+currentSelCatsIdsList+' DYDIS:'+catsArraySize);
	for(var catIterator=0; catIterator<catsArraySize; catIterator++) {
		/***DEBUG***/ //if(x<14 && x> 11)alert('CURR:'+currentSelDependentOnCats[catIterator]);
		
		// Ar vienas iš kategorijos ID elementų yra šalies tėvas
		if(currentSelDependentOnCats[catIterator] == currSelectedCategoryId)
			showElement = true;

	}
	return showElement;
}


/** ********* GAUNAME AUKŠTESNĖS KLASĖS ID ********* */
function getSuperId(currentId,iterator_width,prefix) {
	//if(simpleUpdate == 0) iterator_width--;
	// Country ID FROM country ID param
	var superId = currentId.substr(-iterator_width);
	//var superId = currentId.substr(currentId.length-iterator_width,iterator_width);
	/***DEBUG***/ //if(x<14 && x> 11) alert('C->BEFORE<- COUNTRY_ID BY COUNTRY[superId]:' + superId);
	var superLen = superId.length;
	var stackPush = "";
	for(var charIterator=0;charIterator<superLen;charIterator++) {
		if(superId.charAt(charIterator) >= 0 && superId.charAt(charIterator) <= 9) {
			if(superId.charAt(charIterator-1) >= 0 && superId.charAt(charIterator-1) <= 9) {
				stackPush += ""+superId.charAt(charIterator)+"";
			} else {
				stackPush = ""+superId.charAt(charIterator)+"";
			}
		}
	}
	superId = stackPush;
	if(prefix !== null) {
		superId = prefix+superId;
	}
	//alert('C->AFTER<- COUNTRY_ID BY COUNTRY[superId]:' + superId);
	return superId;
}


/** ********* GAUNAME GALUTININĮ ELEMENTO ID ********* */
function getFinalId(currentId,iterator_width) {
	// Category ID FROM COUNTRY id param
	var finalId = currentId;
	//if(gcc<10) { alert('aaa:' + finalId + ' Width:'+finalId.length+' iter width:' + iterator_width);	gcc++; }
	if(iterator_width !== null && iterator_width > 0) {
		//finalId = finalId.substr(-iterator_width,-2);
		finalId = finalId.substr(0,finalId.length-iterator_width);
		//if(x<2)alert('BEFORE FID: ' + finalId);
		//if(x<2)alert('AFTER FID: ' + finalId + ' DROPED:' + -iterator_width);
	}
	//} else {finalId=0;}
	return finalId;
}


function updateHierarchyLists(sourceObject,targetObj,targetsTargetObj,prefix1,prefix2,iterator_width) {
	var myObj = document.getElementById(sourceObject);
	var destObj = document.getElementById(targetObj);
	var destDestObj = document.getElementById(targetsTargetObj);
	//alert('aaaa');

	// Pasirinkto punkto reiksmė [CATEGORY ID]
	var currMySelect = myObj.options[myObj.selectedIndex].value;
	var currSelectedCategoryId = currMySelect;
	if(prefix1 !== null) {
		//alert('CHECK GOT:' + currMySelect);
		currMySelect = prefix1+currMySelect;
		
	}

	if(simpleUpdate == 1) {
		// For FF
		runSimpleUpdater(myObj,destObj,destDestObj,currMySelect,currSelectedCategoryId,prefix1,prefix2,iterator_width);
	} else {
		// For IE & Opera
		runHeavyUpdater(myObj,destObj,destDestObj,currMySelect,currSelectedCategoryId,prefix1,prefix2,iterator_width);
	}
	
	// Nustatome pasirinktomis 1-ąsias reikšmes
	destObj.selectedIndex = 0;
	destDestObj.selectedIndex = 0;
}



// For FF
function runSimpleUpdater(myObj,destObj,destDestObj,currMySelect,currSelectedCategoryId,prefix1,prefix2,iterator_width) {
	// Taikinio elementų skaičius
	var destElements = destObj.length;
	var destDestElements = destDestObj.length;
	//alert('' + '' + ' DEST ELS:' + destElements + ' [DEST DEST ELS]:' + destDestElements + ' CURR MY SEL:' + currMySelect);
	
	var unhideAll = false;
	// Ar parodyti viską
	if(myObj.selectedIndex == 0) {
		unhideAll = true;
	}
	
	// Visų pirma visus taikinio taikinio elementus paslepiame
	for (var x=1; x<destDestElements; x++) {
		// Gauname atributų prieigą x'ąjam elementui(option)
		var currId = destDestObj.options[x];
		//if(x<5) alert(currId.value)
		currId.style.display = "none";
		//currId.style.visibility = "hidden";
		//currId.disabled = "disabled";
	}
	
	// Taikinio punktų atnaujinimai
	for (var x=1; x<destElements; x++) {
		// Gauname atributų prieigą x'ąjam elementui(option)
		var currId = destObj.options[x];
		// Category ID FROM COUNTRY id param
		var finalId = getFinalId(currId.id,iterator_width);
		
		/** ********* IEŠKOME AR RODYSIME ELEMENTĄ ********* */
		var showElement = checkShowElement(finalId, currSelectedCategoryId, prefix1.length);
		if(showElement == true || unhideAll == true) {
			currId.style.display = "block";
		} else {
			currId.style.display = "none";	
		}
		/** ******************* PABAIGA ********************* */
		
		if(unhideAll == false && showElement == true) {
			// Pasirinkto punkto reiksmės reikšmės atnaujinimai
			// Country ID FROM country ID param
			var superId = getSuperId(currId.id,iterator_width,prefix2);
			/** ***************************************** */
			
			/***DEBUG***/ /*if(x<14 && x> 11)
				alert(
					'HEAD CATEOGORY_ID[CURR MY SEL]:' + currMySelect + 
					'\nCAT_ID BY COUNTRY[finalId]:' + finalId +
					'\nCOUNTRY_ID BY COUNTRY[superId]:' + superId
				);*/
				
			// Update all the dest dest elements
			updateHotels(destDestObj,destDestElements,iterator_width,superId,0);
		}
	}
	
	if(unhideAll == true) {
		listAllHotels(destDestObj,destDestElements);
	}
}


// For IE & Opera
function runHeavyUpdater(myObj,destObj,destDestObj,currMySelect,currSelectedCategoryId,prefix1,prefix2,iterator_width) {
	// Taikinio elementų skaičius
	var destElements = countriesIdCache.length;
	var destDestElements = hotelsIdCache.length;
	
	// Taikinio elementų skaičius
	var SOURCE__destElements = destObj.length;
	var SOURCE__destDestElements = destDestObj.length;
	
	var destObjPool = 1;
	var destDestObjPool = 1;
	
	var loadAll = false;
	// Ar parodyti viską
	if(myObj.selectedIndex == 0) {
		loadAll = true;
	}

	// Visų pirma visus taikinio taikinio elementus paslepiame
	for (var x=SOURCE__destElements-1; x>=1; x--) {
		destObj.remove(x);
	}
	// Visų antra visus taikinio taikinio elementus paslepiame
	for (var x=SOURCE__destDestElements-1; x>=1; x--) {
		destDestObj.remove(x);
	}
	//destElements = 0;
	// Taikinio punktų sukūrimas
	for (var x=1; x<destElements; x++) {
		// Gauname atributų prieigą x'ąjam elementui(option)
		var currId = countriesIdCache[x-1];
		// Category ID FROM COUNTRY id param
		//if(isDefined(currId) == false || currId == 'undefined' || currId == null) {
		/*if(currId == 'undefined' || currId == null) {
			alert('problema gauta ties x='+x); break;
		}*/
		
		var finalId = getFinalId(currId,iterator_width);
		
		/** ********* IEŠKOME AR RODYSIME ELEMENTĄ ********** */
		var showElement = checkShowElement(finalId, currSelectedCategoryId,prefix1.length);
		if(showElement == true || loadAll == true) {
			var option = new Option (countriesNameCache[x-1], destObjPool); 
			destObj.options.add(option);
			destObj.options[destObjPool].id = countriesIdCache[x-1];
			destObj.options[destObjPool].value = countriesNameCache[x-1];
			destObjPool++;
		}
		/** ******************* PABAIGA ********************* */
	}
	var newDestObjPoolSize = destObjPool;
	//newDestObjPoolSize = 0;
	if(loadAll == false) {
		/***DEBUG***/ //alert('Countries got after:'+newDestObjPoolSize);
		// Taikinio taikinio punktų sukūrimas
		for (var x=1; x<newDestObjPoolSize; x++) {
			// Gauname atributų prieigą x'ąjam elementui(option)
			var currId = destObj.options[x].id;
		
			// Country ID FROM country ID param
			var superId = getSuperId(currId,iterator_width,prefix2);

			// Update all the dest dest elements
			destDestObjPool = updateHotels(destDestObj,destDestElements,iterator_width,superId,destDestObjPool);
		}
	} else {
		listAllHotels(destDestObj,destDestElements);
	}
}

/** Atnaujinam viešbučius */
function updateHotels(destDestObj,destDestElements,iterator_width,superId,destDestObjPool) {
	/***DEBUG***/ //var cache111 = "";
	if(simpleUpdate == 1) {
		for (var y=1; y<destDestElements; y++) {
			// Gauname atributų prieigą y'ąjam elementui(option)
			var currCurrId = destDestObj.options[y];
			var finalFinalId = getFinalId(currCurrId.id,iterator_width);
			/***DEBUG***/ //cache111 += superId +' VS ' +finalFinalId + '\n';
			if(finalFinalId == superId) {
				currCurrId.style.display = "block";
			}
		}
	} else {
		for (var y=1; y<destDestElements; y++) {
			// Gauname atributų prieigą y'ąjam elementui(option)
			var currCurrId = hotelsIdCache[y-1];
			var finalFinalId = getFinalId(currCurrId,iterator_width);
			/***DEBUG***/ //cache1 += superId +' VS ' +finalFinalId + '\n';
			if(finalFinalId == superId) {
				var option = new Option (hotelsNameCache[y-1], destDestObjPool); 
				destDestObj.options.add(option);
				destDestObj.options[destDestObjPool].id = hotelsIdCache[y-1];
				destDestObjPool++;
			}
		}
	}
	/***DEBUG***/ //if(x<14 && x> 11) alert(cache1);
	return destDestObjPool;
}


/** Atnaujinam visus viešbučius */
function listAllHotels(destDestObj,destDestElements) {
	if(simpleUpdate == 1) {
		for (var y=1; y<destDestElements; y++) {
			// Gauname atributų prieigą y'ąjam elementui(option)
			var currCurrId = destDestObj.options[y]; 
			currCurrId.style.display = "block";
		}	
	} else {
		for (var y=1; y<destDestElements; y++) {
			var option = new Option (hotelsNameCache[y-1], y); 
			destDestObj.options.add(option);
			destDestObj.options[y].id = hotelsIdCache[y-1];
		}
	}
}


/** 1 lygio atnaujinimas */
function updateElementLists(sourceObject,targetObj,prefix,iterator_width) {
	var myObj = document.getElementById(sourceObject);
	var destObj = document.getElementById(targetObj);

	var unhideAll = false;
	
	// Ar parodyti viską
	if(myObj.selectedIndex == 0) {
		unhideAll = true;
	}
	
	// Pasirinkto punkto reikšmė [category_id]
	var currMySelect = myObj.options[myObj.selectedIndex].id;

	// Country ID FROM country ID param
	var superId = getSuperId(currMySelect,iterator_width,prefix);
	//alert(currMySelect+',  '+iterator_width+',  '+prefix+'\nsuperId:'+superId);
	if(simpleUpdate == 1) {
		// For FF
		hotelSimpleUpdater(destObj,superId,iterator_width,unhideAll);
	} else {
		// For IE & Opera
		hotelHeavyUpdater(destObj,superId,iterator_width,unhideAll);
	}
	
	// Nustatome kaip pasirinktąją 1-ąją reikšmę
	destObj.selectedIndex = 0;
}


/** 1 lygio atnaujinimas */
function hotelSimpleUpdater(destObj,superId,iterator_width,unhideAll) {
	// returns number of options
	var destElements = destObj.length;	
	
	//alert('' + '' + ' DEST ELS:' + destElements + ' CURR MY SEL:' + superId)
	for (var x=1; x<destElements; x++) {
		//accesses value attribute of 1st option
		var currId = destObj.options[x];
		// Category ID OF COUNTRY
		var finalId = getFinalId(currId.id,iterator_width);
		// IF Category ID OF COUNTRY == Current category ID
		if(finalId == superId || unhideAll == true) {
			currId.style.display = "block";
		} else {
			currId.style.display = "none";	
		}
		//alert(x);//if(x==5) break;
	}
}

/** 1 lygio atnaujinimas */
function hotelHeavyUpdater(destObj,superId,iterator_width,unhideAll) {
	// returns number of options
	var destElements = hotelsIdCache.length;
	var SOURCE__destElements = destObj.length;
	var hotelCounter = 1;
	
	// Visus viešbučius panaikiname
	for (var x=SOURCE__destElements-1; x>=1; x--) {
		destObj.remove(x);
	}
	//alert('SOURCE__destElements:' + SOURCE__destElements + ' DEST ELS:' + destElements + ' CURR MY SEL:' + superId);
	/***DEBUG***/ //var cache1 = "";
	for (var x=1; x<destElements; x++) {
		//accesses value attribute of 1st option
		var currId = hotelsIdCache[x-1];
		// Category ID OF COUNTRY
		//alert('currId: ' + currId + ' VS superId: ' + superId);
		var finalId = getFinalId(currId,iterator_width);
		/***DEBUG***/ //cache1 += superId +' VS ' +finalId + '\n';

		// IF Category ID OF COUNTRY == Current category ID
		if(finalId == superId || unhideAll == true) {
			var option = new Option (hotelsNameCache[x-1], hotelCounter); 
			destObj.options.add(option);
			destObj.options[hotelCounter].id = hotelsIdCache[x-1];
			destObj.options[hotelCounter].value = hotelsNameCache[x-1];
			hotelCounter++;
		}
		//alert(x);if(x==8) break;
	}
	/***DEBUG***/ //if(x<14 && x> 11)
	//alert(cache1);
}


/**
* Flipbox written by CrappoMan
* 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 flipBox_text(who) {
	var tmp;
	if(document.getElementById('box_' + who).style.display == 'block') {
		tmp = 'none';
	} else {
		tmp = 'block';
	}
    document.getElementById('box_' + who).style.display = tmp;
    if (document.getElementById('box_' + who + '_diff')) {
        document.getElementById('box_' + who + '_diff').style.display = 'none';
    }

      disply = tmp;
      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 Web_Sprendimai
function replaceText(thisfield, what, formname) {
	document.forms[formname].elements[thisfield].value = ''; // Si eilute padaro tai ka ivedem tusciu
	if (formname == undefined) formname = 'inputform';
	if (document.forms[formname].elements[thisfield].createTextRange) {
		document.forms[formname].elements[thisfield].focus();
		document.selection.createRange().duplicate().text = what;
	} else if ((typeof document.forms[formname].elements[thisfield].selectionStart) != 'undefined') {
		// for Mozilla
		var tarea = document.forms[formname].elements[thisfield];
		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[thisfield].value = '';
		document.forms[formname].elements[thisfield].value += what;
		document.forms[formname].elements[thisfield].focus();
	}
}

// modified by Web_Sprendimai
function replaceText2(thisfield, what, formname) {
	document.forms[formname].elements[thisfield].value = what; // Si eilute padaro tai ka ivedem reiksme 'what'
}

// 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();
}

NewWindowPopUp = null;
function PopUpCentered(src, wdth, hght) {
   //close previous popup window
   if (NewWindowPopUp != null) {
        NewWindowPopUp.close();
        NewWindowPopUp = null;
   }
   //if center parameter given center opoup window 
   wtop = (screen.availHeight-hght)/2;
   wleft = (screen.availWidth-wdth)/2;
   NewWindowPopUp = window.open(src, "","toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,status=no,directories=no,resizable=no,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;