// --- ajax init ---
var onloads = new Array();

function onJetztLoad() {
	var i=0;
	//alert(onloads.length);
	for (i;i<onloads.length;i++) {
		onloads[i]();
	}
	enableTooltips(null,'tooltip');
}

// --- jetztpopup ---
function popupOeffnen(url, width, height) {
    var popup = window.open(url, "jetztpopup", "width="+width+",height="+height);
    popup.focus();
}

// --- jetztbotschaften ---
function markMails(formName) {
  for (var i=0; i<document.forms[formName].elements.length; i++){
    var elem = document.forms[formName].elements[i];
	elem.checked = true;
  }
}

function unmarkMails(formName) {
    for (var i=0; i<document.forms[formName].elements.length; i++){
    var elem = document.forms[formName].elements[i];
	elem.checked = false;
  }
}

// --- jetzttextverfassen ---
function switchStatus(id) {
	if (document.getElementById(id).style.display=='none') {
		show(id);
	} 
	else {
		hide(id);
	}
}
function show(id) {
if(document.getElementById)
    document.getElementById(id).style.display='block';
}

function hide(id) {
if(document.getElementById)
    document.getElementById(id).style.display='none';
}

// automatische Vergrößerung der Textareas
function getMax(anumber, another) { 
				return((anumber > another) ? anumber : another);
			} 
			
function textfeldgroesseaendern(t, minRows, minCols) { 
} 	


//kommentieren
function zitieren(autor, id) { 
	var str = $('kommentartext'+id).innerHTML;
	str = str.replace(/<blockquote>/g,"[zitat]");
	str = str.replace(/<\/blockquote>/g,"[\/zitat]");
	str = str.replace(/<b>/g,"[b]");
	str = str.replace(/<\/b>/g,"[\/b]");
	if ($('kommentarinhalt') == null) {
        if ($('kommentarinhalt_zwei') != null) {
            $('kommentarinhalt_zwei').value += '[zitat][b]'+autor+'[/b] sagte: \n'+str.stripTags()+'[/zitat]\n';
            $('kommentarinhalt_zwei').focus();
        }
    }
    else {
        $('kommentarinhalt').value += '[zitat][b]'+autor+'[/b] sagte: \n'+str.stripTags()+'[/zitat]\n';
        $('kommentarinhalt').focus();
    }
}

//ivw
function countIVW(code) {
    code = typeof(code) != 'undefined' ? 'szmag_'+code : 'szmag';
    
    var IVW_random = new String(Math.random()*100000);
    var IVW_referrer = escape(document.referrer);
    $('countIVW').src = 'http://sueddeut.ivwbox.de/cgi-bin/ivw/CP/'+code+'?r='+IVW_referrer+'&d='+IVW_random;
}

//startseite
var pending = new Array();
function switchLatestRessortNews(id) {
    var visible = ['news_macht','news_sex','news_job','news_kultur','news_technik','news_leben','news_reise'];
    if (pending.indexOf(id) == -1) {
        pending[pending.length] = id;
        
	    visible.each(function(item) {
	      if ($('news_'+id)) {
		      if ($(item) && $(item).style.display != 'none') {
		          if (item != 'news_'+id) {
		              new Effect.SlideUp($(item), { duration: 0.5, fps: 30, queue: 'end', afterFinish: function() { $('ressort_img').src = '/img/jetztrubrik/leiste_'+id+'.gif'; pending = pending.without(id); } });
		              new Effect.SlideDown($('news_'+id), { duration: 0.5, fps: 30, queue: 'end' });
		              countIVW();
		          }
		      }
		  }
	    });
    }
}

//roccatune
function playRoccatune(mode,id) {
    settings="width=720,height=700,top=20,left=40,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=yes,resizable=no,dependent=no";
    if(mode == 'search') {
    win=window.open("http://sz-magazin.roccatune.com/de/sz_magazin_suche.html?query="+$('roccatuneInput').value,"roccatunePlayer",settings);
    } else {
    win=window.open("http://sz-magazin.roccatune.com/de/sz_magazin_player.html?tl="+id,"roccatunePlayer",settings);
    }
    win.focus();
}
function switchRoccatune(switchTo) {
    $('roccatune_show').innerHTML = $('roccatune_'+switchTo).innerHTML;
    $('roccatuneticker').style.fontWeight = 'normal';
    $('roccatunecharts').style.fontWeight = 'normal';
    $('roccatune'+switchTo).style.fontWeight = 'bold';
}

function checkBoxLength(objectid, maxlength, errorspan)
{
	var objectid = document.getElementById(objectid);
	var numofsign = objectid.value.length;
	
	if (numofsign > maxlength) {
		var scrollTop=objectid.scrollTop;
		
		if(document.selection) {
			var range = document.selection.createRange();
		    var stored_range = range.duplicate();
		    stored_range.moveToElementText(objectid);
		    stored_range.setEndPoint( 'EndToEnd', range );
		    objectid.selectionStart = stored_range.text.length;
		    var selectionStart=objectid.selectionStart;
		}
		else {
			var selectionStart=objectid.selectionStart;
		}
		
		if (objectid.selectionStart < maxlength) {
			objectid.value = objectid.value.substring(0,selectionStart-1) + objectid.value.substring(selectionStart,maxlength+1);
		    objectid.selectionEnd=selectionStart-1;
		    objectid.selectionStart=selectionStart-1;
		}
		
		else {
		    objectid.value = objectid.value.substring(0,maxlength);
		    objectid.selectionStart=selectionStart;
		    objectid.selectionStart=selectionStart;
		}
		objectid.scrollTop=scrollTop;
		stillavailable = 0;
		document.getElementById(errorspan).style.color = "#CF0000";
	}
	else {
		stillavailable = maxlength - numofsign;
		document.getElementById(errorspan).style.color = "#8ED33C";
	}
	document.getElementById(errorspan).innerHTML=stillavailable;
}