var baseURL    = 'http://www.pa-bremen.de/snippet/SIZE/pruefungen/allekommendentermine/';
var baseIFrame = '<iframe src="URL" width="SIZE" height="190" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" style="border:2px solid #F2F2F2;"></iframe>';
var sizes      = new Array('275', '400');

$(function() {
	refreshContent();
	
	$('input[name$="set"]').click(function() {
		refreshContent();
	});
});

function refreshContent() {
	var tmpURL			= '';
	var licenceVal      = $('select[name$="licence_tag"]').val();
	var organisationVal = $('select[name$="organisation_id"]').val();
	var stateVal        = $('select[name$="state_tag"]').val();

	tmpURL = baseURL;
	if(licenceVal.length > 0) {
		tmpURL = tmpURL+licenceVal+'/';
	}

	if(organisationVal.length > 0) {
		//pa XXX -> pa-XXX
		var split 		= organisationVal.split(' ');
		organisationVal = split[0]+'-'+split[1];

		tmpURL = tmpURL+organisationVal+'/';
	}

	if(stateVal.length > 0) {
		tmpURL = tmpURL+stateVal+'/';
	}
	tmpURL = tmpURL.toLowerCase();

	//IFrames und Textfelder aktualisieren.
	for(var i=0; i<sizes.length; i++) {
		var tmpLnk = tmpURL.replace(/size/, sizes[i]);
		$('#pa_exam_snippet_'+sizes[i]).attr('src', tmpLnk);
		var tmpVal = baseIFrame.replace(/SIZE/, sizes[i]);
		$('textarea#snippet'+sizes[i]).val(tmpVal.replace(/URL/, tmpLnk));
	}
}
