function cms_ajax_frame_reload()
{
	location.reload();
}

function cms_ajax_close_reload(close)
{
	if (close == undefined)
	{
		close = null;
		return true;
	}
	if (close == 'reload')
	{
		location.reload();
		return true;
	}
	if (close == 'ufs_submit')
	{
		speichern = $('#cboxIframe').contents().find('#ufs_submit').css('color');
		if (speichern == '#ff0000' || speichern == 'red' || speichern == 'rgb(255, 0, 0)')
		{
			if (confirm('Es wurden die Änderungen noch nicht gespeichert.') == false)
				return false;
			else
				return true;
		}
		else
			return true;
	}
	if (close == 'ufs_submit_reload')
	{
		speichern = $('#cboxIframe').contents().find('#ufs_submit').css('color');
		if (speichern == '#ff0000' || speichern == 'red' || speichern == 'rgb(255, 0, 0)')
		{
			pseudoReturn = confirm('Es wurden die Änderungen noch nicht gespeichert.');
			if (pseudoReturn == true)
				location.reload();
			else
				return false;
		}
		else
		{
			location.reload();
			return true;
		}
	}
	return eval(close + ';');
}

function cms_ajax_frame(action, width, height, close)
{
	if (width == undefined) width = 600;
	if (height == undefined) height = 500;
	
	$.fn.colorbox({href:action, width:width, height:height, iframe:true, transition:"none", speed:0, opacity:0.80, onCleanup:function () {return cms_ajax_close_reload(close);}});
}

function cms_ajax_popup(content)
{
	$.fn.colorbox({html:content, transition:"none", speed:0, opacity:0.80});
	return true;
}

function cms_ajax_popup2(content)
{
	$.fn.colorbox({href:content, transition:"none", speed:0, opacity:0.80});
	return true;
}

function cms_ajax_close()
{
	$.fn.colorbox.close();
	return false;
}

$().ready(function(){
	
	//DATE_INPUT Configuration and Init
	//Deutsche Namen
	jQuery.extend(DateInput.DEFAULT_OPTS, {
		month_names: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
		short_month_names: ["Jan", "Feb", "Mai", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
		short_day_names: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
		start_of_week: 1
	});
	//Deutsches Datumsformat
	$.extend(DateInput.DEFAULT_OPTS, {
  stringToDate: function(string) {
    var matches;
		if (matches = string.match(/^(\d{2,2}).(\d{2,2}).(\d{4,4}) (\d{2,2}):(\d{2,2})$/)) {
			return new Date(matches[3], matches[2] - 1, matches[1], matches[4], matches[5], 0);
		}
    else if (matches = string.match(/^(\d{2,2}).(\d{2,2}).(\d{4,4})$/)) {
      return new Date(matches[3], matches[2] - 1, matches[1]);
    } else {
      return null;
    };
  },
  dateToString: function(date) {
    var month = (date.getMonth() + 1).toString();
    var dom = date.getDate().toString();
    if (month.length == 1) month = "0" + month;
    if (dom.length == 1) dom = "0" + dom;
    return dom + "." + month + "." + date.getFullYear();
  },
  keydownHandler: function(event){}
	});
	$($.date_input.initialize);
	
	/** Form-Submit **/
	$('form[name!=noblock]').submit(function() { $.blockUI({ message: 'Bitte warten ...' }); });
	
	/*Projekte laden*/
	if ($("#projekt_liste").length > 0){
		$('#projekt_liste').bind('click keyup', function() { projekt_change(); } );
		projekt_get('');
	}
	
	cms_email_protection();
	set_projekt_checkbox();
	
});

function cms_form_submit()
{
	$.blockUI({ message: 'Bitte warten ...' });
}

function playmp3(mp3, mp3name)
{
	$('#player').html('<object type="application/x-shockwave-flash" data="../gfx/emff_intervox.swf" width="480" height="28"><param name="movie" value="../gfx/emff_intervox.swf" /><param name="FlashVars" value="src='+ mp3 +'&amp;autostart=yes&amp;volume_link=nupian&#47;intervox.de&#47;www&#47;home&#47;player.ajax.php&amp;mp3name='+ mp3name +'" /></object>');
}
function playshowreel(file)
{
	$('#video').html('<object type="application/x-shockwave-flash" data="../gfx/player_flv_mini.swf" width="370" height="270"><param name="movie" value="../gfx/player_flv_mini.swf" /><param name="FlashVars" value="flv='+ file +'&amp;width=370&amp;height=270&amp;autoplay=1" /></object>');
}

var toggle_id = -1;
function album_beschreibung_toggle(id)
{
	if (toggle_id == id){
		$('#beschreibung'+id).slideUp('slow');
		toggle_id = -1;
		return true;
	}	else{
		$('#beschreibung'+id).slideDown('slow');
		$('#beschreibung'+toggle_id).slideUp('slow');	
	}
	toggle_id = id;
	return true;
}

function cms_ajax_success(data){
	var obj = jQuery.parseJSON(data);
	$.each(obj, function(i,item){
		if ( item.type == "multiselect" )
			$('#'+item.id).val(item.val.split(','));
		if ( item.type == "input" )
			$('#'+item.id).val(item.val);
		if ( item.type == "select" )
			$('#'+item.id).val(item.val);
		if ( item.type == "html" )
			$('#'+item.id).html(item.val);
	});
	return true;
}

function projekt_neu(name)
{
	$.ajax({url: "../home/projekt.ajax.php?job=new_projekt", data: {name: name}, type: "POST", proccessData: true, async: false, cache: false, 
	success: function(data){return cms_ajax_success(data)}});
	projekt_get();
}
function projekt_get(val)
{
	$.ajax({url: "../home/projekt.ajax.php?job=get_projekt", proccessData: true, async: false, cache: false, 
	success: function(data){return cms_ajax_success(data)}});
}
function projekt_del(id)
{
	$.ajax({url: "../home/projekt.ajax.php?job=del_projekt", data: {id: id}, type: "POST", proccessData: true, async: false, cache: false, 
	success: function(data){return cms_ajax_success(data)}});
	projekt_get();
}
function projekt_anzeigen(l)
{
	if ($('#projekt_liste').val() > 0){
		$('#projekt_anzeigen').click( function() { window.location.href = '../home/projekt.php?l=' + l + '&projekt_id=' + $('#projekt_liste').val();});
	}
}
function projekt_change()
{
	$.ajax({url: "../home/projekt.ajax.php?job=change_projekt&id=" + $('#projekt_liste').val(), proccessData: true, async: true, cache: false, 
	success: function(data){return cms_ajax_success(data)}});
	set_projekt_checkbox();
}

function track2benutzerprojekt(track)
{
	$.ajax({url: "../home/projekt.ajax.php?job=track2benutzerprojekt&track=" + track, proccessData: true, async: true, cache: false, 
	success: function(data){return cms_ajax_success(data);}});
}
function projekt_checkbox(track)
{
		$.ajax({url: "../home/projekt.ajax.php?job=track2benutzerprojekt_checkbox&track=" + track, proccessData: true, async: true, cache: false, 
		success: function(data){return cms_ajax_success(data);}});
}
function set_projekt_checkbox()
{
	$(".track2benutzerprojekt_checkbox").html(function() {
		projekt_checkbox($(this).attr("id"))
	});
}
function cms_email_protection()
{
		$(".cms_ep").html(function() {
    e = ($(this).attr('href'));
		n = ($(this).html());
		e1 = e.replace("/","@").replace(/#/g,".");
		$(this).attr("href", "mailto:"+e1);
		if(e==n){
			$(this).html(e1);
		}
	});
}
