Event.observe(window, 'load', function() {
	checkSelectBoxSingle('pressplatform',1);
	checkSelectBoxSingle('presslang',1);
	if ($('dt')) dp_cal = new Epoch('epoch_popup','popup',$('dt'));
});

function editContactInfo() {
	$('cntct_info_link').hide();
	$('pbcontacteditor').show()
	$('pbcontacteditor').hide();
	$('pbcontacteditor').show();
	switchEditors("pbcontact");
}
function toggleDisplay(eID) {
	$("pbj"+eID).show();
	$("pbj"+eID+"_link").hide();
}
function forceDisplay(eID) {
	toggleDisplay(eID);
	uri = window.location.href;
	ancpos = uri.indexOf('#');
	if (ancpos > -1) {
		anc = uri.substr(ancpos);
		uri = uri.replace(anc,"");
	}
	window.location = uri+"#"+eID;
}
function toggleYear(eID) {
	$(eID).toggle();
	if ($(eID).visible()) {
		$(eID+"_link").hide();
		Effect.ScrollTo(eID);
	}
	else $(eID+"_link").show();
}

function checkPressParams() {
	//get values from form
	p = $F('pressplatform');
	l = $F('presslang');
	
	//check platform change and correct language setting accordingly
	qp = getParam('pressplatform');
	ql = getParam('presslang');
	l_elem = l.split('-');
	if (qp != p) {
		switch (p) {
			case 'bvdir': l = l_elem[1]+'-'+l_elem[1]; break;
			case 'atldir': l = 'eu-'+l_elem[1]; break;
		}
	}
	//execute
	window.location.href = '?presstype='+getParam('presstype')+'&pressplatform='+p+'&presslang='+l;
}

function getParam(id) {
  id = id.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexs = "[\\?&]"+id+"=([^&#]*)";
  var regex = new RegExp(regexs);
  var results = regex.exec(window.location.href);
  if (results==null) return "";
  else return results[1];
}

//PRESS RELEASES PAGE
function showPicsUpload() {
	$('addpix_box').show();
	$('btn_addpix').hide();
}
function showContactEditor() {
	$('contacteditor_cnt').show();
	$('contactbutton_add').hide();
	$('contactbutton_edit').hide();
}
function hideContactEditor() {
	contactdata = FCKeditorAPI.GetInstance('contactinfo').GetData();
	$('contacteditor_cnt').hide();
	if (!contactdata.empty()) $('contactbutton_edit').show();
	else $('contactbutton_add').show();
}
function clearContactEditor() {
	FCKeditorAPI.GetInstance('contactinfo').Commands.GetCommand('NewPage').Execute();
}
function getPressReleases() {
	qs = window.location.search.substring(1);
	filter = ($('prlisttype').checked) ? 1 : 0;
	new Ajax.Request("/content/cms/press/aj_prlist.php", { 
		parameters: qs+'&filter='+filter,
		onSuccess: function(data) {
			res = data.responseJSON;
			if (!Object.isUndefined(res.result)) $('pressreleaselisting_box').update(res.result);
			else $('pressreleaselisting_box').update('Error fetching list (1)');
		},
		onFailure: function() { $('pressreleaselisting_box').update('Error fetching list (2)'); }
	});
}