BASE_URL = 'http://gby.pl/forum/';
var ie  = document.all  ? 1 : 0;
var ns4 = document.layers ? 1 : 0;

function PopUp(url, name, width, height, center, resize, scroll, posleft, postop) {
	if (posleft != 0) x = posleft;
	if (postop  != 0) y = postop;
	if (!scroll) scroll = 1;
	if (!resize) resize = 1;
	
	if ((parseInt(navigator.appVersion) >= 4 ) && center) {
		X = (screen.width  - width ) / 2;
		Y = (screen.height - height) / 2;
	}
	
	if (scroll != 0) scroll = 1;
	
	var Win = window.open(url, name, 'width='+width+',height='+height+',top='+Y+',left='+X+',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
}

function ShowHide(id1, id2) {
	if (id1 != '') expMenu(id1);
	if (id2 != '') expMenu(id2);
}

function expMenu(id) {
	var itm = null;
	
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all) {
		itm = document.all[id];
	} else if (document.layers) {
		itm = document.layers[id];
	}
	
	if (!itm) {
		// do nothing
	} else if (itm.style) {
		if (itm.style.display == "none") {
			itm.style.display = "";
			qrFocus(itm); // quick reply focus
		} else {
			itm.style.display = "none";
		}
	} else {
		itm.visibility = "show";
	}
}

function qrFocus(itm) {
	// focus on QuickReply
	if (itm.id == 'qr_open') {
		try {
			//document.getElementById('qr_input').focus();
			document.getElementById('qr_input').select();
			return false;
		} catch (itm) {
		}
	}
}

function link_to_post(tid, pid) {
	temp = prompt('Oto pełny adres do posta o numerze '+pid+':', BASE_URL+'t/'+tid+'/?p='+pid+'&view=findpost');
	return false;
}

// from skin_msg, pm_popup function
function goto_inbox() {
	Opener.document.location.href = BASE_URL+'act/msg/01';
	window.close();
}
function goto_this_inbox() {
	window.resizeTo('700','500');
	document.location.href = BASE_URL+'act/msg/01';
}
function go_read_msg(mid) {
	window.resizeTo('700','500');
	document.location.href = BASE_URL+'act/msg/03/?VID=in&MSID='+mid;
}

// from skin_post, get_javascript function
var MessageMax  = 100000;

function ValidateForm(isMsg, form) {
	form = form ? form : document.getElementById('REPLIER'); // path to form
	isPost = form.Post ? 1 : 0; // is there a 'Post' field?
	
	errors = '';
	
	if (isMsg == 1 && form.msg_title.value.length < 2) {
		errors = 'Wpisz tytuł wiadomości';
	} else if (isPost && form.Post.value.length < 2) {
		errors = 'Musisz wpisać treść posta!';
	} else if (isPost && MessageMax != 0 && form.Post.value.length > MessageMax) {
		errors = 'Maksymalna długość posta to '+MessageMax+' znaków. Aktualna ilość znaków to: '+form.Post.value.length+'.';
	} else if (form.send_notice && parseInt(form.send_notice.value)) {
		result = ValidateNotice(form);
		if (!result) {
			errors = 'Musisz podać przynajmniej jeden powód moderowania!';
		}
	}
	
	if (errors != '') {
		alert(errors);
		return false;
	} else {
		form.submit.disabled = true;
		return true;
	}
}

function ValidateNotice(form) {
	if (form.reasonReq.value == 1) {
		var givenReason = 0; // number of reasons given in form
		for (i = 0; i < availReasons.length; i++) {
			if(eval('form.reason_'+availReasons[i]+'.checked')) {
				givenReason++;
			}
		}
		if (form.addReason.value.length > 10) {
			givenReason++;
		}
		if (givenReason < 1) {
			return false; // reasonReq is true && no given any reason... return false
		}
	}
	return true;
}

// from skin_forum, PageTop function
function who_posted(tid) {
	window.open(BASE_URL+"act/stats/who/popup.html?t="+tid, "WhoPosted", "toolbar=no,scrollbars=yes,resizable=yes,width=230,height=300");
}

// from skin_global, BoardHeader function
function multi_page_jump(url_bit, total_posts, per_page, st) {
	
	pages = 1;
	cur_st = parseInt(st);
	cur_page  = 1;
	
	if (total_posts % per_page == 0) {
		pages = total_posts / per_page; 
	} else {
		pages = Math.ceil( total_posts / per_page ); 
	}
	
	msg = "Wpisz numer strony, pomiędzy 1 i" + " " + pages;
	if (cur_st > 0) {
		cur_page = cur_st/per_page;
		cur_page = cur_page -1;
	}
	
	show_page = 1;
	if (cur_page < pages) {
		show_page = cur_page + 1; 
	}
	if (cur_page >= pages) {
		show_page = cur_page - 1; 
	} else { 
		show_page = cur_page + 1; 
	}
	
	userPage = prompt(msg, show_page);
	if (userPage > 0) {
		if (userPage < 1) userPage = 1;
		if (userPage > pages) userPage = pages;
		
		if (userPage == 1) {
			start = '';
		} else { 
			start = (userPage - 1) * per_page; 
		}
		
		window.location = url_bit + start;
	}
}

// from skin_poll, poll_javascript function
function go_gadget_show(fid, tid, st) {
	window.location = BASE_URL+'st/'+fid+'/'+tid+'/'+st+'/show';
}
function go_gadget_vote(fid, tid, st) {
	window.location = BASE_URL+'st/'+fid+'/'+tid+'/'+st;
}

// from skin_profile, show_card_download function
function redirect_to(where, closewin) {
	document.location= BASE_URL + where;
	
	if (closewin == 1) {
		self.close();
	}
}

// from skin_search
function go_gadget_simple(f) {
	window.location = BASE_URL+"act/search//"+f+"/?mode=simple";
}
function go_gadget_advanced(f) {
	window.location = BASE_URL+"act/search//"+f+"/?mode=adv";
}
function win_pop() {
	window.open(BASE_URL+'act/search/explain','WIN','width=400,height=300,resizable=yes,scrollbars=yes');
}
function checkvalues() {
	f = document.dateline;
	if (f.st_day.value < f.end_day.value) {
		alert("Pierwsza data MUSI być starsza niż druga.");
		return false;
   }
   if (f.st_day.value == f.end_day.value) {
   	alert("Pierwsza data MUSI być starsza niż druga.");
   	return false;
   }
}


// from skin_msg
function hl(cb)
{
   if (ie)
   {
	   while (cb.tagName != "TR")
	   {
		   cb = cb.parentElement;
	   }
   }
   else
   {
	   while (cb.tagName != "TR")
	   {
		   cb = cb.parentNode;
	   }
   }
   cb.className = 'hlight';
}

function dl(cb) {
   if (ie)
   {
	   while (cb.tagName != "TR")
	   {
		   cb = cb.parentElement;
	   }
   }
   else
   {
	   while (cb.tagName != "TR")
	   {
		   cb = cb.parentNode;
	   }
   }
   cb.className = 'dlight';
}

function cca(cb) {
   if (cb.checked)
   {
	   hl(cb);
   }
   else
   {
	   dl(cb);
   }
}
	   
function CheckAll(cb) {
	var fmobj = document.getElementById('mutliact');
	for (var i=0;i<fmobj.elements.length;i++) {
		var e = fmobj.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled)) {
			e.checked = fmobj.allbox.checked;
			if (fmobj.allbox.checked)
			{
			   hl(e);
			}
			else
			{
			   dl(e);
			}
		}
	}
}
function CheckCheckAll(cb) {	
	var fmobj = document.getElementById('mutliact');
	var TotalBoxes = 0;
	var TotalOn = 0;
	for (var i=0;i<fmobj.elements.length;i++) {
		var e = fmobj.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox')) {
			TotalBoxes++;
			if (e.checked) {
				TotalOn++;
			}
		}
	}
	if (TotalBoxes==TotalOn) {fmobj.allbox.checked=true;}
	else {fmobj.allbox.checked=false;}
}

function select_read() {	
	var fmobj = document.getElementById('mutliact');
	for (var i=0;i<fmobj.elements.length;i++) {
		var e = fmobj.elements[i];
		if ((e.type=='hidden') && (e.value == 1) && (! isNaN(e.name) ))
		{
			eval("fmobj.msgid_" + e.name + ".checked=true;");
			hl(e);
		}
	}
}

function unselect_all() {	
	var fmobj = document.getElementById('mutliact');
	for (var i=0;i<fmobj.elements.length;i++) {
		var e = fmobj.elements[i];
		if (e.type=='checkbox') {
			e.checked=false;
			dl(e);
		}
	}
}

function find_users() {
  url = BASE_URL+"act/legends/finduser_one/popup.html?entry=textarea&name=carbon_copy&sep=line";
  window.open(url,'FindUsers','width=400,height=250,resizable=yes,scrollbars=yes'); 
}
function add_to_form()
{		
	var separator = '$sep';
	var entry     = '$entry';
	var name = document.getElementById('finduser').username.options[document.getElementById('finduser').username.selectedIndex].value;
	var replier = document.getElementById('REPLIER');
	if (separator == 'line')
	{
		separator = '\\n';
	}
	if (entry == 'textarea')
	{
		// Where shall we put the separator?
		var tbox     = replier.$name.value;
		var tboxSize = replier.$name.value.length;			
		// Remove leading spaces...		
		while ( replier.$name.value.slice(0,1) == " " )
		{
			replier.$name.value = replier.$name.value.substr(1, replier.$name.value.length - 1);
			replier.$name.value.length = replier.$name.value.length;
		}		
		// Remove trailing spaces...		
		while ( replier.$name.value.slice(replier.$name.value.length - 1, replier.$name.value.length) == " " )
		{
			replier.$name.value = replier.$name.value.substr(0, replier.$name.value.length - 1);
			replier.$name.value.length = replier.$name.value.length;
		}			
		// Do we have a leading comma?			
		while ( replier.$name.value.slice(0,1) == "\\n" )
		{
			replier.$name.value = replier.$name.value.substr(1, replier.$name.value.length - 1);
			replier.$name.value.length = replier.$name.value.length;
		}			
		// Do we have a trailing comma?...		
		while ( replier.$name.value.slice(replier.$name.value.length - 1, replier.$name.value.length) == "\\n" )
		{
			replier.$name.value = replier.$name.value.substr(0, replier.$name.value.length - 1);
			replier.$name.value.length = replier.$name.value.length;
		}		
		// First in box?			
		if ( replier.$name.value.length == 0)
		{
			replier.$name.value += name;
		}
		else
		{
			replier.$name.value += separator + name;
		}
	}	
}
function bog_off()
{
	var tid = '$tid';
	var fid = '$fid';

	opener.location= '$ibforums->base_url2' + 't/' + tid;
	self.close();
}
