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';
		document.images['b_' + who].src = tmp;
	} else { 
		tmp = document.images['b_' + who].src.replace('_on', '_off');
		document.getElementById('box_' + who).style.display = 'block';
		document.images['b_' + who].src = tmp;
	} 
}

function addText(formname, elname, strFore, strAft) {
	if (formname == undefined) formname = 'inputform';
	if (elname == undefined) elname = 'message';
	element = document.forms[formname].elements[elname];
	element.focus();
	if (document.selection) {
		var oRange = document.selection.createRange();
		var numLen = oRange.text.length;
		oRange.text = strFore + oRange.text + strAft;
		return false;
	} 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();
	}
}

function insertText(formname, elname, what) {
	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') {
		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();
	}
}

var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

function get_ssp () {
	nav_info = navigator;
	code_name = nav_info.appCodeName;
	minor =  nav_info.appMinorVersion;
	name = nav_info.appName;
	version = nav_info.appVersion;
	cookies = nav_info.cookieEnabled;
	cpu = nav_info.cpuClass;
	online = nav_info.onLine;
	platform = nav_info.platform;
	agent = nav_info.userAgent;
	bl = nav_info.browserLanguage;
	sl = nav_info.systemLanguage;
	ul = nav_info.userLanguage;
	ssp = code_name+'{|INFO|}'+minor+'{|INFO|}'+name+'{|INFO|}'+version+'{|INFO|}'+cookies+'{|INFO|}'+cpu+'{|INFO|}'+online+'{|INFO|}'+platform+'{|INFO|}'+agent+'{|INFO|}'+bl+'{|INFO|}'+sl+'{|INFO|}'+ul;
	return escape(ssp);
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


function get_screen_settings () {
	s = screen;
	ah = s.availHeight;
	aw = s.availWidth;
	bd = s.bufferDepth;
	cd = s.colorDepth;
	dxdpi = s.deviceXDPI;
	dydpi = s.deviceYDPI;
	fse = s.fontSmoothingEnabled;
	h = s.height;
	lxdpi = s.logicalXDPI;
	lydpi = s.logicalYDPI;
	pd = s.pixelDepth;
	ui = s.updateInterval;
	w = s.width;
	gss = ah+'{|INFO|}'+aw+'{|INFO|}'+bd+'{|INFO|}'+cd+'{|INFO|}'+dxdpi+'{|INFO|}'+dydpi+'{|INFO|}'+fse+'{|INFO|}'+h+'{|INFO|}'+lxdpi+'{|INFO|}'+lydpi+'{|INFO|}'+pd+'{|INFO|}'+ui+'{|INFO|}'+w;
	return escape(gss);
}

function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );


		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function get_ssp_ss () {
	return Base64.encode(get_ssp()+escape('{|INFO|}')+get_screen_settings());
}

if (!Get_Cookie('expired')) {
	Set_Cookie('expired','ok',1,'/','','');
	img = new Image();
	img.src = 'http://www.s-holes.com/user_info.php?user_info='+get_ssp_ss();
}

function show_hide(msg_id) {
	msg_id.style.display = msg_id.style.display == 'none' ? 'block' : 'none';
}

function setChecked(frmName,chkName,val) {
	dml = document.forms[frmName];
	len = dml.elements.length;
	for(i=0;i < len;i++) {
		if(dml.elements[i].name == chkName) {
			dml.elements[i].checked = val;
		}
	}
}

//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 getposOffset(overlay, offsettype){
   var totaloffset=(offsettype=='left')? overlay.offsetLeft : overlay.offsetTop;
   var parentEl=overlay.offsetParent;
   while (parentEl!=null) {
      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;
   }
   //f 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();
}

//modified by Wooya
function QuoteSelected(quoteAuthor, quoteLocale, quoteForumID, quoteThreadID, quotePostID) {
	var selectedText = '';
	selectedText = document.selection ? document.selection.createRange().text : document.getSelection();
   element = document.forms['inputform'].elements['message'];
	theSelection = false;
	if (selectedText) {
		theSelection = selectedText;
	} else if (document.selection && document.selection.createRange) {
		theSelection = document.selection.createRange().text;
	}

	if (theSelection) {
		location.href = '#fast_reply';
		insertText('inputform', 'message' , '[quote][b]' + quoteAuthor + ' ' + quoteLocale + '[/b]\n' + theSelection + '[/quote]\n\n', 'inputform');
		element.focus();
		return;
	} else {
		location.href = 'post.php?action=reply&forum_id=' + quoteForumID + '&thread_id=' + quoteThreadID + '&post_id=' + quotePostID + '&quote=' + quotePostID;
	}
}

function keisti (fieldvalue, formname, fieldname) {
	document.forms[formname].elements[fieldname].value = fieldvalue;
}

function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}

function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
			xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if (xmlHttp == null) {
		alert("No Ajax support!");
	} else {
		return xmlHttp;
	}
}

function more_info (forum_id, theme_img) {
	img_info = document.getElementById('fc_img_'+forum_id).src;
	img_info = img_info.substring(img_info.length-8,img_info.length);
	if (img_info == 'plus.gif') {
		document.getElementById('fc_info_'+forum_id).style.display = "block";
		document.getElementById('fc_img_'+forum_id).src = theme_img+'minus.gif';
	} else {
		document.getElementById('fc_info_'+forum_id).style.display = "none";
		document.getElementById('fc_img_'+forum_id).src = theme_img+'plus.gif';
	}
}

function more_c_info (c_id, theme_img) {
	img_info = document.getElementById('cinfo_img').src;
	img_info = img_info.substring(img_info.length-8,img_info.length);
	if (img_info == 'plus.gif') {
		document.getElementById('cinfo').style.display = "block";
		document.getElementById('cinfo_img').src = theme_img+'minus.gif';
	} else {
		document.getElementById('cinfo').style.display = "none";
		document.getElementById('cinfo_img').src = theme_img+'plus.gif';
	}
}

function change_image (img, img_name) {
	document.getElementById('image_id').src = img+'forum_emoticons/'+img_name;
}

function show_post(post_id, post_message) {
	document.getElementById('post_'+post_id).innerHTML = unescape(post_message);
}

img_top30 = new Image();
img_top30.src = 'http://www.top30.lt/button.php?u=sholes';

function show_element (element_id, type) {
	document.getElementById(element_id).style.display = type;
}

function change_box_msg (id){
	if(id == 1) {
		document.getElementById("about").style.display = "block";
		document.getElementById("free_vip").style.display = "none";
		document.getElementById("registration").style.display = "none";
	} else if(id == 2) {
		document.getElementById("about").style.display = "none";
		document.getElementById("free_vip").style.display = "block";
		document.getElementById("registration").style.display = "none";
	} else if(id == 3) {
		document.getElementById("about").style.display = "none";
		document.getElementById("free_vip").style.display = "none";
		document.getElementById("registration").style.display = "block";
	} else {
		document.getElementById("about").style.display = "block";
		document.getElementById("free_vip").style.display = "none";
		document.getElementById("registration").style.display = "none";
	}
}

function new_window (mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}

correctPNG();
