
function SymError()
{
	return true;
}

window.onerror = SymError;

function newPnInf(DOM)
{
	open_window(DOM,'pn',500,300,0);
}

function open_window(meineSeite,meinName,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';
	Fenster = window.open(meineSeite,meinName,settings);
}

function elemX (element) 
{
	var x = 0;
	
	while (element) 
	{
		x += element.offsetLeft;
		element = element.offsetParent;
	}
	
	return x;
}

function elemY (element) {
	var y = 0;
	while (element) {
		y += element.offsetTop;
		element = element.offsetParent;
	}
	return y;
}

function getWidth (element) {
	return element.offsetWidth;
}

function getHeight (element) {
	return element.offsetHeight;
}

function elemObj(elementId) {
	if (document.all)
		return document.all[elementId];
	else if (document.getElementById)
		return document.getElementById(elementId);
	else
		return null;
}

function switch_img(DATA,ID){
	document.getElementById('img').innerHTML = '<a href="javascript:ImgBrowser(' + ID + ');"><img src="' + DATA + '" alt="" border="0" /></a>';
}

function switch_img_popup(DATA,ID){
	document.getElementById('img').innerHTML = '<img src="' + DATA + '" alt="" border="0" />';
}

function ImgBrowser(ID,DOM){
	window.open(DOM + 'index.php?p=misc&do=shopimgages&prodid=' + ID, ID, 'width=700,height=600,top=0,left=0');
}

function mergeProduct(ID,RED,CID,DOM){
	window.open(DOM + 'index.php?redir=1&p=misc&do=mergeproduct&prodid=' + ID + '&red=' + RED + '&cid=' + CID, 'merge_win', 'scrollbars=1,width=950,height=750,top=0,left=0');
}


function paymentInf(ID,DOM){
	window.open(DOM + 'index.php?p=misc&do=payment_info&id=' + ID,'paymentinf','width=800,height=550,top=0,left=0,scrollbars=1');
}


function check_search_field(){
	if(document.getElementById('s_x').value != '' && document.getElementById('s_x').value.length < 2){
		document.getElementById('small_search_hidden_div').style.display='';
		return false;
	} else {
		document.getElementById('small_search_hidden_div').style.display='none';
	}	
}

function openAdmin(DOM){
	open_window(DOM + 'admin/index.php','Admin',1200,880,1);
}

function getActiveText(msg){
	selectedText = (document.all) ? document.selection.createRange().text : window.getSelection();if (msg.createTextRange) msg.caretPos = document.selection.createRange().duplicate();return true;
}

function unametofield(theuser) {
	opener.document.f.tofromname.value = '' + theuser + '';
	window.close();
}

function add_code(NewCode){
    document.f.text.value += NewCode;
    document.f.text.focus();
}
function menu_switch() 
{
	anzeige_ist = document.getElementById('inhaltsvz_ul').className;
	switch (anzeige_ist) 
	{
		case 'inhaltsvz_close':
			anzeige_soll = 'inhaltsvz_open';
			break;
		case 'inhaltsvz_open':
			anzeige_soll = 'inhaltsvz_close';
			break;
		default:
			anzeige_soll = 'inhaltsvz_close';
			break;
	}

	document.getElementById('inhaltsvz_ul').className = anzeige_soll;
}

function bn_rebuild(cur)
{
	var cur_name = this;
	var cur_data = 0; 
	var arr_data = new Array();
	var box_name = $(this).parent().parent();
	var box_data = $(box_name).next();
	var name_list = $('.bn_item', box_name);
	
	if (!$(box_data).attr('arr'))
	{
		$('.bn_line', box_data).each(function(i){
			var w = parseFloat($(this).text());
			arr_data[i] = w;
			if (cur_name == name_list[i])
			{
				cur_data = w;
			} 
		});
		$(box_data).attr('arr', arr_data);
	}
	else
	{
		arr_data = $(box_data).attr('arr').split(',');
		cur_data = arr_data[cur.data.num];
	}
		
	$('.bn_line', box_data).each(function(i){
		var w = Math.round(arr_data[i] / cur_data * 100);
		$(this).text((i == cur.data.num ? $('.diffText').eq(0).text()+' ' : '') + w + '%');
	});
}

function bn_recover()
{
	var box_data = $(this).parent().parent().next();
	
	if (!$(box_data).attr('arr'))
	{
		alert('error');
		return false;
	}
	
	var arr_data = $(box_data).attr('arr').split(',');
	
	$('.bn_line', box_data).each(function(i){
		$(this).text(arr_data[i]);
	});
}


function del_attach(elm, id)
{
	$.get(elm.href);
	$('#hidden_count').val($('#hidden_count').val() - 1); 
	swfu_size += parseInt($('#delatt_' + id).attr('filesize'));
	$('#totalSize').html(formatSize(swfu_size));
	$('#delatt_' + id).remove();
	if ($('#attachments div').length < 1)
	{
		$('#attachments_fieldset').css('display', 'none');
	}	
	else
	{
		$('#attachments div').each(function(i){
			if ((i + 1) % 4 == 0)
			{
				if ($(this).next()[0] && $(this).next()[0].tagName != 'BR')
				{
					$(this).after('<br style="clear: both" />');
				}
			}
			else
			{
				if ($(this).next()[0] 
					&& $(this).next()[0].tagName == 'BR')
				{
					$(this).next().remove();
				}
			}
		});
	}
}


function formatSize(n)
{
	if (n < 1024)
	{
		return n + ' Bytes';
	}
	
	n /= 1024;
	if (n < 1024)
	{
		n = Math.round(n * 10);
		return parseFloat(n/10) + ' KB';
	}
	
	n /= 1024;
	n = Math.round(n * 10);
	
	return parseFloat(n/10) + ' MB';
}


//UL in Foren Hack
$(window).load(function(){
	var h;
	$('.forum_post_posting li:has(img), .forum_post_first li:has(img)').each(function(){
		h = $(this).height();
		if (h != 20)
		{
			$(this).css('background-position', 'left '+(h-12)+'px');
		}
	});
});


function koobi_nice_close(testing) {
	var sortTags = new Array(), closeList = new Array();
	var tmp, last = '', maxLen = 0;
	if (!koobi_tags)
	{
		alert('No koobi_tags');
		
		return '';
	}
	
	for (i in koobi_tags)
	{
		tmp = koobi_tags[i].replace(/[\[\]\/]/g, '');
		if (tmp != last)
		{
			last = tmp;
			if (tmp.length > maxLen)
			{
				maxLen = tmp.length;
			}
			
			if (tmp.length == 1)
			{
				sortTags.push(tmp);
			}
			else
			{
				sortTags.unshift(tmp);
			}
		}
	}
	
	p = -1;
	last = '';
	while ( (p = testing.indexOf('[')) != -1 )
	{
		testing = testing.substring(p + 1, testing.length);
		tmp = testing.substring(0, maxLen + 2);
		for (i in sortTags)
		{
			if (tmp.indexOf(sortTags[i] + ']') == 0 || tmp.indexOf(sortTags[i] + '=') == 0)
			{
				closeList.push(sortTags[i]);
				break;
			}
			else if (tmp.indexOf('/' + sortTags[i] + ']') == 0)
			{
				last = closeList.pop();
				if (last != sortTags[i])
				{
					closeList.push(last);
				}
			}
		}
	}
	
	if (closeList.length > 0)
	{
		closeList = closeList.reverse();
		tmp = '[/' + closeList.join('][/') + ']';
	}
	else
	{
		tmp = '';
	}
	
	return tmp;
}


function download_email(id, login)
{
	if (!login)
	{
		if ($('#loginLink').length)
		{
			window.location = $('#loginLink')[0].href;
		}
		else
		{
			alert('No Content');
		}
				
		return;
	}
	
	var res;
	
	$('#notification_button')[0].disabled=true;
	res = $.get(
		$('#homeLink')[0].href + '/index.php?p=useraction&action=downloadEmail&d_id=' + id,
		{},
		function(res)
		{
			if (res == 'ok')
			{
				$('#notification_del_link').css('visibility', 'visible');
				$.blockUI({message: $('#notification_text_set').text()});
				$('#notification_set').css('display', 'none');
				$('#notification_del').css('display', 'block');
				setTimeout($.unblockUI, 2000);
			}
			else
			{
				alert('Problem ' + res);
			}
		}
	);
}


function download_email_del_profile(elm, id)
{
	var res;

	$(elm).css('visibility', 'hidden');
	res = $.get($('#homeLink')[0].href + '/index.php?p=useraction&action=downloadEmailDel&d_id=' + id,
		{}, 
		function (res)
		{
			if (res == 'ok')
			{
				elm = $(elm).parent().parent();
				if ($('.download_list_item', elm.parent()).length == 1)
				{
					elm.parent().parent().remove();
				}
				else
				{
					elm.remove();
				}
			}
			else
			{
				alert('Problem ' + res);
			}
		}
	);	
}


function download_email_del(id)
{
	var res;

	$('#notification_del_link').css('visibility', 'hidden');
	res = $.get($('#homeLink')[0].href + '/index.php?p=useraction&action=downloadEmailDel&d_id=' + id,
		{},
		function(res)
		{
			if (res == 'ok')
			{
				$('#notification_button')[0].disabled=false;
		
				$.blockUI({message: $('#notification_text_unset').text()});
				$('#notification_del').css('display', 'none');
				$('#notification_set').css('display', 'block');
				setTimeout($.unblockUI, 2000);
			}
			else
			{
				alert('Problem ' + res);
			}
		}
	);
}


function showWarningLink(id, verText)
{
	$('#verIdBroken').val(id);
	$('#version_title').html(verText);

	$('#broken_onclick').slideDown('normal', function(){
		smothScroll('broken_onclick');
	});
}


var scrolling = 0;
function smothScroll(id)
{
	var cur, elm;
	
	elm = $('#' + id);
	cur = elm.offset().top - $(document).scrollTop();
	if (cur > 150)
	{
		scrolling = cur - 150;
		
		if (window.innerHeight)
		{
			cur = window.innerHeight;
		}
		else
		{
			cur = document.body.clientHeight;
		}
		
		cur = cur - 150 - 20 - elm.height();
		if (cur > 0 && cur < scrolling)
		{
			scrolling -= cur;
		}
		
		if (scrolling > 0)
		{
			smothScrollCall();
		}	
	}
}


function smothScrollCall()
{
	scrolling -= 5;
	window.scrollBy(0, 5);
	if (scrolling > 0)
	{
		setTimeout(smothScrollCall, 20);
	}
}


function edit_entry(id)
{
	$('.eintrag_edit').hide();
	$('.eintrag').show();
	
	$('#eintrag_' + id).hide();
	$('#eintrag_edit_' + id).show();
}


