
function openLWnd(link, wWidth,wHeight,sBear) {
	var url = '';
	var width = 668;
	var height = 624;
	
	if (wWidth) {
		width = wWidth;
	}

	if (wHeight) {
		height = wHeight;
	}

	if (typeof(link) == 'string') {
		url = link;
	} else {
		url = link.href;
	}
	
	try {
		$f().unload();
		
	} catch(e) {
	}
	
	MOOdalBox.open( 
		url, // the link URL
		"", // the caption (link's title) - can be blank
		width+' '+height, // width and height of the box - can be left blank,
		sBear
	);

	return false;
}
function logout(){
	document.logout_form.submit();
}
function setUsedTats()
{
	try
	{
		if (!tatUsed) return;
	}
	catch(ex)
	{
		return;
	}
	
	for(var i=0;i<tatUsed.length;i++)
	{
		var tat = tatUsed[i];
		
		if (tat>0 && $('utat'+tat))
		{
			if ($('utat'+tat).tagName == "DIV")
			{
				$('utat'+tat).className = "taten-list-used";
			}
			else
			{
				var dv = $('utat'+tat).getParent('div');
				if (dv)
				{
					dv.className = 'taten-widget-item utat_used';
				}
			}
			//$('utat'+tat).className = 'utat';
		}
	}
}

// load spenden-page as https-page
function HTTPSopenLWnd(link, wWidth, wHeight) {
	// if url is not https, reload https-versio of page with get-parameter spenden=1, which initiates onDomready load of spenden window

	var url = '';
	var width = 668;
	var height = 624;
	
	if (wWidth) width = wWidth;
	if (wHeight) height = wHeight;
	
	if (typeof(link) == 'string') url = link;
	else url = link.href;
	
	url = url.replace('http:','https:');
	url = url.replace('1000000taten','ssl');

	if (location.href.indexOf('https://') != -1) { // https-mode, proceed
		try {
			$f().unload();
		} catch(e) {
		}


		MOOdalBox.open( 
			url, // the link URL
			"", // the caption (link's title) - can be blank
			width+' '+height // width and height of the box - can be left blank
		);
	
		return false;
	} else {
		var a= location.href.replace('http://1000000taten','https://ssl')
		+ ( (location.href.indexOf('?') !== false) ? '&' : '?')  + 'spenden=1';
		location.href = 'https://ssl.greenpeace.at/index.php?id=7197&spenden=1';
		return false;
	}
}

function blurLink()
{
}

function closeLWnd(url)
{

	MOOdalBox.close();
	if (url)
	{
		document.location.href= url.replace('https://ssl', 'http://1000000taten');;
	} else {
		
		location.href = location.href.replace('https://','http://').replace('ssl.greenpeace.at', '1000000taten.greenpeace.at').replace('&spenden=1','');
	}
	return false;
}
function checkAgreement()
{
	if (!$('agreement').checked) 
	{ 
		alert('Bitte akzeptieren Sie unsere Nutzungsbestimmungen');
		return false;
	} 
	if (!$('adult-0').checked && !$('adult-1').checked) 
	{ 
		alert('Bitte bestätigen Sie, dass Sie volljährig sind.');
		return false;
	}
	if ($('adult-1').checked) {
		$('date_of_birth').set('value', '01-01-1995');
	}
	if ($('adult-0').checked) {
		$('date_of_birth').set('value', '01-01-1975');
	}
	
	return true;
}

function updateUserPosition(func)
{

}

function showProfilePictureUpload()
{
	$('profile_img_upload').className = '';
	return false;	
}

function showProfilePasswordPictureUpload()
{
	$('profile_pwd_row1').className = '';
	$('profile_pwd_row2').className = '';
	return false;	
}

var searchCleaned = false;
function searchFocus(el) {
	if (searchCleaned)
		return;
	el.value = '';
	searchCleaned = true;
}

function zipEnter(ev)
{
	if (ev.keyCode == 8 || ev.keyCode == 9 || (ev.keyCode >= 96 && ev.keyCode <= 105) || (ev.keyCode <= 46 && ev.keyCode >= 20))
	{
		return true;
	}
	
	if ((ev.keyCode<48 || ev.keyCode>57))
		return false;
	return true;
}

function limitText(limitField, limitNum) {
	if (limitField.innerHTML.length > limitNum) {
		limitField.innerHTML = limitField.innerHTML.substring(0, limitNum);
	} 
	
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}
function reopenSendToFriend(mode) {
	if(mode) {
	} else {
	mode = 'invite';
	}
	try
	{
		MOOdalBox.close();
		setTimeout("openSendToFriend('index.php?id=7083', "+"'"+mode+"'"+")",1000);
	}
	catch(e) {}
}

function openSendToFriend(ajaxUrl, mode, targetUrl) {
	if (ajaxUrl.indexOf('?') >= 0)
		ajaxUrl += '&mode='+mode;
	else
		ajaxUrl += '?mode='+mode;
	if(targetUrl) {	
		ajaxUrl += '&url='+encodeURIComponent(targetUrl);
	} else {
		ajaxUrl += '&url='+encodeURIComponent(document.location.href);
	}
	openLWnd(ajaxUrl, 668, 620);
}

function initTatenList() {
	var tatenListAcc = new Accordion($('taten-list-id'), 'div.taten-list-category', 'div.taten-list-items', {
		opacity: false,
		onActive: function(toggler, element) {
		},
		onBackground: function(toggler, element) {
		},
		display: -1,
		alwaysHide: true
	});
}


window.addEvent('load', function() {
	setUsedTats();
});
