
function initPage(){
	initZoomImages();
}


var az_p=location.protocol=='https:'?'https:':'http:';
var az_r=Math.floor(Math.random()*99999999);
if (!document.phpAds_used) document.phpAds_used = ',';
function az_adjs(z,n)
{
  /* mgirr, 10.10.2007
     auskommentiert, da der Adserver noch kein https unterstützt und es deshalb Probleme beim Seitenaufbau gab
  */

  /*
  if (z>-1) {
    var az="<"+"script language='JavaScript' type='text/javascript' src='"+az_p+"//max.i12.de/adjs.php?n="+n+"&amp;what=zone:"+z;
    az+="&amp;source="+az_channel+"&amp;exclude="+document.phpAds_used+"&amp;r="+az_r;
    if (window.location) az+="&amp;loc="+escape(window.location);
    if (document.referrer) az+="&amp;referer="+escape(document.referrer);
    az+="'><"+"/script>";
    document.write(az);

  }
  */
}
var az_channel = '';




function show_form_error(elem, text){

    id_ext = elem.id;

    if(document.getElementById('form_error_' + id_ext)){
        document.getElementById('form_error_' + id_ext).innerHTML = text;
        new Effect.Highlight('form_error_' + id_ext);
    } else {
        var div = document.createElement('div');
        div.className = 'show_form_error';
        div.id = 'form_error_' + id_ext;
        div.innerHTML = text;

        div.style.display = 'none';

        elem.className = 'error';
        elem.parentNode.appendChild(div);

        new Effect.BlindDown('form_error_' + id_ext, {duration: 0.5});
    }
 }

 function hide_form_error(elem){

    id_ext = elem.id;

    elem.className = '';
    if(document.getElementById('form_error_' + id_ext)){
        new Effect.BlindUp('form_error_' + id_ext, {duration: 0.5});
    }
 }

 function blindUpDownDiv(name){
 	if(document.getElementById(name).style.display == 'none'){
 		new Effect.BlindDown(name, {duration: 0.5});
 	} else {
 		new Effect.BlindUp(name, {duration: 0.5});
    }
    return false;

 }



 function blindUpDownDivId(id){

 	if(div = document.getElementById(id)){
 		if(div.style.display == 'none'){
 			new Effect.BlindDown(id, {duration: 0.5});
 		} else {
 			new Effect.BlindUp(id, {duration: 0.5});
 		}
 	}

 }


 function growShrinkDiv(id){

 	if(div = document.getElementById(id)){
 		if(div.style.display == 'none'){
 			new Effect.Grow(id);
 		} else {
 			new Effect.Shrink(id);
 		}
 	}
 }


//Zoom Images
//------------------------------------------

var imgTimeOut;

function initZoomImages(){

	div = document.createElement('div');
	div.id = 'zoomDiv';
	div.style.display = 'none'
	document.body.appendChild(div);

	if(items = document.getElementsByTagName('img')){
		for(i = 0; i < items.length; i++){
			if(items[i].id.indexOf('move_') == 0){
				items[i].onmouseover = showZoomImg;
				items[i].onmouseout  = hideZoomImg;
				items[i].onmousemove = moveZoom;
			}
		}
	}

}

function showZoomImg(){
	uniq_id = this.id.substr(5, this.id.length);
	imgTimeOut = window.setTimeout('zoomImg("' + uniq_id + '")', 600);
}

function zoomImg(uniq_id){
	var imgUrl = '/img/p.' + uniq_id + '.jpg';

	div = document.getElementById('zoomDiv')

	div.style.position = 'absolute';
	div.style.backgroundColor = '#fff';
	div.style.border = '1px solid #ddd'

	if(div.hasChildNodes()){
		div.removeChild(div.childNodes[0]);
	}

	img = document.createElement('img');
	img.style.padding='4px';
	img.src = imgUrl;

	div.appendChild(img);
	div.style.display = 'block'
}

function hideZoomImg(){
	window.clearTimeout(imgTimeOut);
	if(div = document.getElementById('zoomDiv')){
		div.style.display='none';
	}
}

function moveZoom(event){

	if(div = document.getElementById('zoomDiv')){
		if(document.all){


		    div.style.left = window.event.clientX + document.documentElement.scrollLeft + 10 + 'px';
		    div.style.top = window.event.clientY + document.documentElement.scrollTop + 10 + 'px';
		}else{
		    div.style.left = event.pageX + 10 +'px';
		    div.style.top = event.pageY + 10 +'px';
	    }
	}

}

//------------------------------------------ dragging
var drag_div = false;
var dx = 0; var dy = 0;

function do_drag_div(e){
	if(document.all){
        drag_div.style.pixelTop = window.event.clientY - dy;
		drag_div.style.pixelLeft = window.event.clientX - dx;
    }else{
        drag_div.style.top = parseInt(e.clientY) - dy + 'px';
		drag_div.style.left = parseInt(e.clientX) - dx + 'px';
    }
}

function startdrag(e, divName){

	drag_div = document.getElementById(divName);

	if(document.all){
		dx = window.event.clientX - drag_div.style.pixelLeft;
		dy = window.event.clientY - drag_div.style.pixelTop;
	}else{
		dx = e.clientX - parseInt(drag_div.style.left);
		dy = e.clientY - parseInt(drag_div.style.top);

		document.captureEvents(Event.MOUSEMOVE);
	}

	document.onmousemove = do_drag_div;

}

function stopdrag(){
	document.onmousemove = null;
	drag_div = false;
}



var old_height = new Array();

function expandFellowTextDiv(){

	var div = this.parentNode;

	if(div.scrollHeight > div.offsetHeight || !div.style.height){
		if(div.style.height){
		    old_height[div.id] = div.style.height;
			div.style.overflow = 'hidden';
			expandDiv(div.id, div.offsetHeight, div.scrollHeight);
	        var img = div.getElementsByTagName('img')[0];
	        img.src = '/_images/collapse_msg.gif';
	        //img.style.cursor = 'n-resize';
		} else {
			div.style.height = old_height[div.id];
			div.style.overflow = 'hidden';
	        var img = div.getElementsByTagName('img')[0];
	        img.src = '/_images/expand_msg.gif';
			//img.style.cursor = 's-resize';
		}
	}
}

function expandDiv(div_id, start, stop){

	var elem = document.getElementById(div_id);

	if(start < stop){
		start = start * 1.1;
		elem.style.height = Math.round(start) + 'px';
		window.setTimeout('expandDiv(\'' + div_id + '\', ' + start + ', ' + stop + ')', 7);
	} else {
		elem.style.height = '';
	}
}


function saveTags(uniq_id){

	var tags = document.getElementById('fellowship_tags_' + uniq_id).value;

    new Ajax.Request('/_xml/xml.save_user_tags.php?uid=' + uniq_id + '&payload=' + tags, {
    			method: 'get',
    			onSuccess: function(response){showSaveTagStatus(response, uniq_id)}
    		}
      	);

    return false;
}


function organizeParticipants(){
	if($('invites')){
        var lis = $('invites').getElementsByTagName('li');
        var wanted = new Array();
        for(i = 0; i < lis.length; i++){
        	wanted[wanted.length] = lis[i].id;
        }
        $('wanted_participants').value = wanted.join(',');
	}
}

function addFellowToList(elem){
    $('invites').appendChild(elem);
    $('add_' + elem.id).style.display = 'none';
    $('remove_' + elem.id).style.display = 'inline';
    $('invites').style.backgroundColor = '';
}

function removeFellowFromList(elem){
    $('fellows').appendChild(elem);
    $('add_' + elem.id).style.display = 'inline';
    $('remove_' + elem.id).style.display = 'none';
}



//Tags
function highlightTag(tag){
    var arr_images = tags[tag];

    for(i = 0; i < arr_images.length; i++){
        //new Effect.Highlight(arr_images[i], {startcolor:'#EF86A3', endcolor: '#ffffff' });
		$(arr_images[i]).className = 'animated';
        window.setTimeout("resetHighlight('" + tag + "')", 1500);
    }
}

function resetHighlight(tag){
    var arr_images = tags[tag];

    for(i = 0; i < arr_images.length; i++){
        $(arr_images[i]).className = '';
    }
}

function window_center(str_url, num_window_width, num_window_height) {

    var num_screen_width, num_screen_height, obj_window;

    num_screen_width  = screen.width;
    num_screen_height = screen.height;

    num_position_x = (num_screen_width - num_window_width) / 2;
    num_position_y = (num_screen_height - num_window_height) / 2;

    obj_window = window.open(str_url, 'window_center', 'left=' + num_position_x + ',top=' + num_position_y + ',screenX=' + num_position_x + ',screenY=' + num_position_y + ',width=' + num_window_width + ',height=' + num_window_height + ',menubar=no,toolbar=no,resizable=1');
    obj_window.focus();
}





function changeFachthemaBox(page_id){
    var url = '/_xml/xml.fachthema_blaettern.php?page_id=' + page_id;
    var div = document.getElementById('box_fachthema');
    var blaettern = document.getElementById('div_blaettern');

    blaettern.innerHTML = ('<img src="/_images/ajax/loading_bar.gif" />');
    new Ajax.Updater('box_fachthema', url);
}


