$j(document).ready(function() {
	if ($j('#pressplatform').length) {
		$j('#pressplatform').change(function() {
			window.location.href = '?platform=' + $j('#pressplatform').val();
		});
		if (checkSelectBoxSingle('pressplatform',2) && !$j('#presslang').length) {
			$j('#pressplatform').change();
		}
	}
	if ($j('#presslang').length) {
		$j('#presslang').change(function() {
			lang_elem = $j('#presslang').val().split('-');
			uri = '?platform=' + $j('#pressplatform').val() + '&dmn=' + lang_elem[0] + '&lang=' + lang_elem[1] + '&section=';
			uri += ($j('#presstype').length) ? $j('#presstype').val() : 2;
			window.location.href = uri;
		});
		checkSelectBoxSingle('presslang',2);
	}
	if ($j('#presstype').length) {
		$j('#presstype').change(function() {
			lang_elem = $j('#presslang').val().split('-');
			window.location.href = '?platform=' + $j('#pressplatform').val() + '&dmn=' + lang_elem[0] + '&lang=' + lang_elem[1] + '&section=' + $j('#presstype').val();
		});
	}
	if ($j('#dt_display').length) $j("#dt_display").datepicker({ altField: '#dt', altFormat: 'yy-mm-dd' });
});

function editContactInfo() {
	$j('#cntct_info_link').hide();
	$j('#pbcontacteditor').show()
	$j('#pbcontacteditor').hide();
	$j('#pbcontacteditor').show();
	switchEditors("pbcontact");
}
function toggleDisplay(eID) {
	$j("#pbj"+eID).show();
	$j("#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(id) {
	$j('#'+id).toggle();
	if ($j('#'+id).is(":visible")) {
		$j('#'+id+"_link").hide();
		doCmsScroll('#'+id);
	}
	else $j("#"+id+"_link").show();
}

function checkPressParams() {
	//get values from form
	p = $j('#pressplatform').val();
	l = $j('#presslang').val();
	
	//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() {
	$j('#addpix_box').show();
	$j('#btn_addpix').hide();
}
function showContactEditor() {
	$j('#contacteditor_cnt').show();
	$j('#contactbutton_add').hide();
	$j('#contactbutton_edit').hide();
}
function hideContactEditor() {
	contactdata = FCKeditorAPI.GetInstance('contactinfo').GetData();
	$j('#contacteditor_cnt').hide();
	if (contactdata.length) $j('#contactbutton_edit').show();
	else $j('#contactbutton_add').show();
}
function clearContactEditor() {
	FCKeditorAPI.GetInstance('contactinfo').Commands.GetCommand('NewPage').Execute();
}
function getPressReleases() {
	filter = ($j('#prlisttype').is(":checked")) ? 1 : 0;
	qs = window.location.search.substring(1);
	qs += "&type="+$j('#prlisttype').val()+"&filter="+filter;
	
	$j.ajax({
		type: "POST",
		url: "/content/cms/press/aj_prlist.php", 
		data: qs,
		success: function(data) {
			if ('result' in data) $j('#pressreleaselisting_box').html(data.result);
			else $j('#pressreleaselisting_box').text('Error fetching list (1)');
		},
		error: function() {
			$j('#pressreleaselisting_box').text('Error fetching list (2)');
		},
		dataType: "json"
	});
}
