/*
	the main js source
	Copyright (c) 2006 Bethke et al., Berlin, copyright@b-eta.org
	$Id: main.js,v 1.85 2010/06/11 13:18:55 cvs Exp $
*/

/*
	-------------------------------------------------------
	XMLHttpRequest

	response codes are delivered in X-Status
	codes:
	200: ok
	201: ok and submit form
	202: ok and reset form
	205: ok and do nothing, i.e. do not replace main item
	400: bad request, e.g. cookies disabled
	401: user required
	403: forbidden
	404: item not found, empty basket too
	500: internal error
*/
function reqobj () {
	var req = false;
	try {
		req = new XMLHttpRequest();
	} catch ( ie1 ) {
		try {
			req = new ActiveXObject( "Msxml2.XMLHTTP" );
		} catch ( ie2 ) {
			try {
				req = new ActiveXObject( "Microsoft.XMLHTTP" );
			} catch ( err ) {
				req = false;
			}
		}
	}
	if ( !req )
		alert( "Error initializing XMLHttpRequest!" );
	return req;
}

function getreq ( url, callback )
{
	var req = reqobj();
	if ( !req ) {
		alert( "Error initializing XMLHttpRequest!" );
		return;
	}
	req.open( "GET", url, true );
	req.onreadystatechange = function () { callback( req ) };
	req.send( null );
}

function postreq ( url, data, callback )
{
	var req = reqobj();
	if ( !req ) {
		alert( "Error initializing XMLHttpRequest!" );
		return;
	}
	req.open( "POST", url, callback ? true : false );
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", data.length);
	req.setRequestHeader("Connection", "close");
	if ( callback )
		req.onreadystatechange = function () { callback( req ) };
	req.send( data );
	return req;
}

function getheader( req, header ) {
	try {
		return req.getResponseHeader( header );
	} catch ( e ) { }
}

function xstatus ( req ) {
	var xs = getheader( req, 'X-Status' );
	return xs ? parseInt( xs ) : 200;
}

function img_404(that, def, src) {
	if( src && src != '' ) {
		that.onerror=function() { img_404(this, def); }
		that.src=src;
	}
	else {
		that.onerror= null;
		that.src="/images/"+def;
	}
}

/*
	-------------------------------------------------------
	item changing
*/
function settitle ( subtitle ) {
	if ( subtitle ) {
		var title = document.title;
		var i = title.lastIndexOf( ': ' );
		if ( 0 < i )
			document.title = title.substring( 0, i + 2 ) + subtitle;
		else
			document.title = title + ': ' + subtitle;
	}
}

function setmsg ( txt ) {
	if ( txt ) {
		if( 'absolute' == $('#themsg_wrapper').css('position') ) {
			$('html,body').animate({scrollTop:0}, 1000); 
		}	
		$('#themsg_wrapper').show();
		$('#themsg_overlay').fadeIn();
		$('#themsg_overlay').click(function(){hidemsg();});
		$('#themsg').html(txt);
		$('#themsg').show();
	} else { alert( 'MSG not found' ); }
	
}

var lastvisited;

function createlv () {
	if ( document.cookie ) {
		var lvcookie;
		var cookie = document.cookie.split( '; ' );
		for ( var i = 0; cookie.length > i; ++i ) {
			if ( 0 == cookie[i].indexOf( 'lvtd=' ) ) {
				return cookie[i].substr( 5 ).split( '+' );
			}
		}
	}
	return new Array();
}
function addlvref ( id ) {
	if ( ! lastvisited ) {
		lastvisited = createlv();
		return;
	}
	for ( var i = 0; lastvisited.length > i; ++i ) {
		if ( lastvisited[ i ] == id ) {
			return;
		} 
	}
	if ( 5 < lastvisited.length )
		lastvisited.splice( 0, lastvisited.length - 4 );
	else if ( 5 == lastvisited.length )
		lastvisited.shift();
	lastvisited.push( id )
	var lvcookie = lastvisited.join( '+' );
	document.cookie = 'lvtd=' + lvcookie + ';';
}

function select_node ( node, txt, title ) {
	var el;
	if( node && '' != node ) {
		el = document.getElementById( node )
	}
	else {
		el= document.getElementById('main') || document.getElementById('content');
	}	
	
	if( !el ) {
		alert("node not found:" + node);
		return;
	}	
	
	el.innerHTML = txt;
	settitle( title );

	$('html,body').animate({scrollTop:0}, 1000); 
//	window.scroll( 0, 0 );
}

function updnode( node, val ) {
	if ( val ) {
		var chld = node.childNodes;
		for ( var i = 0; chld.length > i; ++i ) {
			if ( 'A' == chld[i].nodeName ) {
				var txt = chld[i].firstChild.nodeValue;
				var j = txt.indexOf( ': ' );
				if ( j )
					txt = txt.substring( 0, j + 2 ) + val;
				chld[i].firstChild.nodeValue = txt;
				node.style.display = 'block';
				break;
			}
		}
	} else {
		node.style.display = 'none';
	}
}

function setbasket ( cnt ) {
	var bskt0 = document.getElementById( 'thebasket0' );
	var bsktn = document.getElementById( 'thebasketn' );
	var bskcnt  = document.getElementById( 'thebskcnt' );
	if ( '0' == cnt ) {
		bsktn.style.display = 'none';
		bskt0.style.display = 'block';
	} else {
		bskt0.style.display = 'none';
		bsktn.style.display = 'block';
		bskcnt.innerHTML = cnt;
	}
}

function upd_header ( req ) {
	var val = getheader( req, 'X-Set-Basket' );
	setbasket( val ? val : '0' );
	var node = document.getElementById( 'head_cb' );
	if ( node ) {
		val = getheader( req, 'X-Set-CashBack' );
		updnode( node, val );
	}
}


function getitem( id, domid ) {

	var cb = function ( req ) {
		if ( 4 == req.readyState && 200 == req.status ) {
			var xs = xstatus( req );
			if ( 200 == xs ) {
				var txt = req.responseText;
				if ( txt ) {
					var title = getheader( req, 'X-Title' );
					select_node( domid, txt, title ? title : id );
					upd_header ( req );
				}
			} 
			else {
				upd_header ( req );
				setmsg( req.responseText );
			}
		}
		cab_display();
	};

	getreq ( "/getitem?id=" + id, cb );
	
	try {
//		urchinTracker(id);
		pageTracker._initData(id);
		pageTracker._trackPageview(id);
	} catch(e){}
}

function removeDynScripts() {
	var script = document.body.getElementsByTagName('script');
	var len  = script.length;
	for( var n= len-1; n>=0; --n ) {
		if( script[n].className == 'dynScript' ) {
			document.body.removeChild(script[n]);
		}
	}
}


function showSpartippDetails( id, domid, tab) {
	var el = document.getElementById('list_detail')
	if( !el ) return false;
	
	var show_detail = function(txt) {
		if( domid ) {
		var ul = el.parentNode;
		ul.removeChild(el);
		el.innerHTML = txt;
		var li = ul.getElementsByTagName('li');
		for( var n=0; n<li.length; ++n ) {
			if( li[n].id == domid ) {
				li[n].style.display = 'none';
			}
			else {
				li[n].style.display = 'block';
			}
		}
		li = document.getElementById(domid);
		ul.insertBefore(el, li);
		el.style.display = 'block';
		}
		else {
			el.innerHTML = txt;
		}
		removeDynScripts();
		var script = el.getElementsByTagName('script');
		var len = script.length;
		for( var n=0; n<len; ++n ) {
			var node = script[n].cloneNode(true);
			node.className = 'dynScript';
			document.body.appendChild(node);
		}

		if( tab ) {
			onToggleMore('spartipp_details', 'spartipp_details_'+tab);
		}
	}

	var cb = function ( req ) {
		if ( 4 == req.readyState && 200 == req.status ) {
			var xs = xstatus( req );
			if ( 200 == xs ) {
				var txt = req.responseText;
				if ( txt ) {
						show_detail(txt);
				}
			} 
			else {
				upd_header ( req );
				setmsg( req.responseText );
			}
		}
	};

	getreq ( "/spartipp?v=spartipp_detail&id=" + id, cb );

	return true;
}

function locateSelect(evt, imp, li) {
	if( document.all ) {
		evt = window.event;
	}
	switch(evt.keyCode || evt.which) {
		case 38:
		case 63232:
			//alert(li.pos);
			// key up
			if( li.pos > -1 && li.pos < li.length ) {
				li[li.pos].className = '';
			}
			if( li.pos == -1 ) {
				li.pos = li.length-1;
			}
			else {
				li.pos -= 1;
			}	
			if( li.pos > -1 ) {
				imp.value = li[li.pos].innerHTML;
				li[li.pos].className = "selected";
			}
			else {
				li.pos = -1;
				imp.value = li.loc;
			}
			return false;
		case 40:
		case 63233:
			//alert(li.pos);
			// key down
			if( li.pos > -1 && li.pos < li.length ) {
				li[li.pos].className = '';
			}
			li.pos += 1;
			if( li.pos < li.length ) {
				imp.value = li[li.pos].innerHTML;
				li[li.pos].className = "selected";
			}
			else {
				li.pos = -1;
				imp.value = li.loc;
			}
			return false;
			
		default:
			break;
	}
}
function hideLocateHistory(domid) {
	var el = document.getElementById(domid);
	if( el )
		el.style.display = 'none';
}
function locateSpartipp(evt, imp, domid) {

	var el = document.getElementById(domid);
	if(!el) return false;

	if( document.all ) {
		evt = window.event;
	}
	switch(evt.keyCode || evt.which) {
		case 38:
		case 63232:
		case 40:
		case 63233:
		case 13:
			return false;
		default:
			break;
	}		
	

	var cb = function( req ) {
		if ( 4 == req.readyState && 200 == req.status ) {
			var txt = req.responseText;
			el.innerHTML = txt;
			if( '' == txt ){
				el.style.display = 'none';
				imp.onkeydown = '';
				imp.onblur = '';
			}
			else {
				el.style.display = 'block';
				el.style.top = (imp.offsetHeight+imp.offsetTop)+'px';
				el.style.width = (imp.offsetWidth-10) + 'px';
				var li = el.getElementsByTagName('li');
				for( var n=0; n<li.length; n++) {
					li[n].onclick= function(){ imp.value = this.innerHTML; }
				}
				li.pos = -1;
				li.loc = imp.value;
				imp.onkeydown = function(evt) { locateSelect(evt, imp, li); }
				imp.onblur = function() { setTimeout(function(){hideLocateHistory(domid)},100); }
			}	
		}
	}

	getreq ( "/spartipp?loc=" + encodeURIComponent(imp.value), cb );
}

function closeSpartippDetails() {
	var el = document.getElementById('list_detail')
	if( !el ) return false;
	
	var ul = el.parentNode;
	var li = ul.getElementsByTagName('li');
	for( var n=0; n<li.length; ++n ) {
			li[n].style.display = 'block';
	}
	el.style.display = 'none';

	removeDynScripts();
}

function updateSpartipp(frm, tab) {
	var el = document.getElementById('list_detail')
	if( !el ) return false;

	var cb = function ( req ) {
		if ( 4 == req.readyState && 200 == req.status ) {
			var xs = xstatus( req );
			if ( 200 == xs ) {
				var txt = req.responseText;
				if ( txt ) {
						el.innerHTML = txt;
				}
				removeDynScripts();
				var script = el.getElementsByTagName('script');
				var len = script.length;
				for( var n=0; n<len; ++n ) {
					/*
					var node = document.createElement('script');
					node.setAttribute("language", "JavaScript1.5");
					node.setAttribute("type", "text/javascript");
					node.innerHTML = script[n].innerHTML;
					//el.appendChild(node);
					*/
					var node = script[n].cloneNode(true);
					node.className = 'dynScript';
					document.body.appendChild(node);
				}
				if( tab ) {
					onToggleMore('spartipp_details', 'spartipp_details_'+tab);
				}
			} 
			else
			if ( 201 == xs ) {
				setmsg( req.responseText );
				closeSpartippDetails();
			}
			else
			if ( 202 == xs ) {
				setmsg( req.responseText );
				showSpartippDetails(frm.key.value, null, frm.tab.value);
			}
			else {
				upd_header ( req );
				setmsg( req.responseText );
			}
		}
	};

	postreq( '/spartipp', postdata( frm ), cb );

	return false;

}


var superSlideTimer;
var superSlideLastId;

function getmsg ( name, focus_elm ) {
	var cb = function ( req ) {
		if ( 4 == req.readyState ) {
			var val = getheader( req, 'X-Set-Basket' );
			if ( val ) {
				setbasket( val );
			}
			setmsg( req.responseText );
			if( focus_elm ) {
				$('#'+focus_elm).focus()
			}
		}
	};
	getreq ( "/msg/" + name, cb );
}

function buy ( name, focus_elm ) {
	var cb = function ( req ) {
		if ( 4 == req.readyState ) {
			var xs = xstatus( req );
			if( xs == 200 ) {
				document.location.href = '/home/basket';
				return;
			}
			var val = getheader( req, 'X-Set-Basket' );
			if ( val ) {
				setbasket( val );
			}
			setmsg( req.responseText );
			if( focus_elm ) {
				$('#'+focus_elm).focus()
			}
		}
	};
	getreq ( "/msg/" + name, cb );
}

function getRubricPage(domid, form) {
	var elm = document.getElementById(domid);
	if( !elm )
		return;
	var cb = function( req ) {
		elm.innerHTML = req.responseText;
	}
		postreq( "/nsearch", postdata( form ), cb );
}

function postdata( form, button ) {
	var len = form.length;
	var data;
	if ( button ) {
		data = button.name + '=' + encodeURIComponent( button.value );
	}
	for ( var i = 0; len > i; ++i ) {
		var fel = form.elements[ i ];
		switch ( fel.type ) {
		case 'button':
		case 'submit':
			break;
		case 'checkbox':
		case 'radio':
			if ( ! fel.checked )
				break;
		default:
			if ( fel.value && '' != fel.value ) {
				var kv = fel.name + '=' + encodeURIComponent( fel.value );
				if ( data ) {
					 data = data + '&' + kv;
				} else {
					data = kv;
				}
			}
			break;
		}
	}
//alert( "DATA="+data);
	return data;
}

function login ( form ) {
	$('div.msg_login').addClass("loading");
	var cb = function ( req ) {
		if ( 4 == req.readyState && 200 == req.status ) {
			var xs = xstatus( req );
			if ( 200 == xs ) {
				$('#themsg').hide();
				form.cn.value = '';
				form.up.value = '';
				form.submit();
			} else { 
				form.reset();
				if ( 401 == xs ) {
					$('#themsg').addClass("error");
          			$('#themsg').css({position: 'relative'}); 
					for (var x = 1; x <= 3; x++){ 
						$('#themsg').animate({ left: -10 },10) 
		       				.animate({ left: 0 },10) 
									.animate({ left: 10 },10) 
									.animate({ left: 0 },10); 
						setTimeout('$("#themsg").removeClass("error"); 	$("#msg_login_focus").focus();',1000);

					}
				} else {
					setmsg( req.responseText );
				}
			}
		}
		$('div.msg_login').removeClass("loading");
	};
	postreq( "/login", postdata( form ), cb );
	return false;
}

function basket ( form, button, domid ) {
	var cb = function ( req ) {
		if ( 4 == req.readyState && 200 == req.status ) {
			switch ( xstatus( req ) ) {
			case 200:
				var cnt = getheader( req, 'X-Set-Basket' );
				if ( cnt ) {
					setbasket( cnt );
				}
				var stage = getheader( req, 'X-Stage' );
				if ( ! stage ) stage = 1;
				select_node( domid, req.responseText, getheader( req, 'X-Title' ) );
				break;
			case 404:
				setbasket( '0' );
				var href =location.href.split('\/');
				href.splice(href.length-1,1);
				location.href = href.join('\/');
				break;
			case 403:
			case 401:
				setmsg( req.responseText );
				break;
			}
		}
      cab_display();
	};
	postreq( "/basket", postdata( form, button ), cb );
	if ( form.vcode ) form.vcode.value =  '';
	return false;
}

function cab_display() {
   var cab=false;
   var forms=document.getElementsByTagName('FORM');
   for(i=0;i<forms.length && !cab;i++) {
	 	 for(j=0;j<forms[i].elements.length;j++) {
			 if (forms[i].elements[j].options) {
         for(k=0;k<forms[i].elements[j].options.length;k++) {
						if (forms[i].elements[j].options[k].value=='online') {
							cab=true;
             
						}
					}
				}
     }
   }

  if (cab) {
   var right=document.getElementById('right');
   var divs=right.getElementsByTagName('DIV');
   for(i=0;i<divs.length;i++) {
	   if (divs[i].className=='list_title') {
      divs[i].innerHTML='ClickandBuy';
      break;
		 }
   } 
   var uls=right.getElementsByTagName('UL');
   while(uls[0].firstChild) {
	 		uls[0].removeChild(uls[0].firstChild);
		}
    uls[0].innerHTML='<li style="background-color:#fff"><div align="center"><br><a href="http://clickandbuy.com/DE/de/info.html" target="cab" onclick="popup00(740,500,\'cab\')"><img src="/img/picklets/clickandbuy_alt_120_outline.gif" width="120" height="67" border="0"><br><br>Mehr Infos zu ClickandBuy<br><br></div></li>';
   }
}

/*
	vouchers
*/
function vcheck ( evt, inp, domid )
{
	if ( !evt || 13 == evt.keyCode ) {
		if ( inp.value && 0 < inp.value.length ) {
			basket( inp.form, inp.form.vc, domid );
		}
		return false;
	}
	return true;
}

function register ( form, button, domid ) {
	if ( 'go' == button.name && !eval_reg( form, 14 ) )
		return false;
	var elm = document.getElementById( domid );
	var cb = function ( req ) {
		if ( 4 == req.readyState && 200 == req.status ) {
			if( elm ) {
				elm.style.cursor = 'auto';
			}	
			switch ( xstatus( req ) ) {
			case 200:
				var stage = getheader( req, 'X-Stage' );
				if ( ! stage ) stage = 1;
				select_node( domid, req.responseText, getheader( req, 'X-Title' ) );
				switch(""+stage){
					case "1":
					default:
						// tracking code step 1
						pageTracker._trackPageview("/trichter_G1/registeradresse.html");
						break;
					case "2":
						// tracking code step 2
						pageTracker._trackPageview("/trichter_G1/registerusername.html");
						break;
					case "3":
						// tracking code step 3
						pageTracker._trackPageview("/trichter_G1/registerimmaupload.html");
						break;
				}
				break;
			case 403:
			case 500:
				setmsg( req.responseText );
				break;
			}
		}
	};
	if( elm ) {	
		elm.style.cursor = 'wait';
	}	
	postreq( "/register", postdata( form, button ), cb );
	return false;
}

function account ( form, button, domid ) {
	if ( 'go' == button.name && ! eval_reg( form, 12 ) )
		return false;
	return posthandler( form, '/account', button, domid );
}

function posthandler ( form, dst, button, domid ) {
	var cb = function ( req ) {
		if ( 4 == req.readyState && 200 == req.status ) {
			switch ( xstatus( req ) ) {
			case 200:
				select_node( domid, req.responseText, getheader( req, 'X-Title' ) );
				if ( '/syspost' == dst ) {
					upd_header( req );
				}	
				var msg = getheader( req, 'X-Msg' );
				if( msg ) {
					getmsg(msg);
				}
				break;
			case 201:
				form.submit();
				break;
			case 202:
				form.reset();
			case 205:
			case 400:
			case 401:
			case 403:
			case 500:
			
					$('#themsg').addClass("error");
          			$('#themsg').css({position: 'relative'}); 
					for (var x = 1; x <= 3; x++){ 
						$('#themsg').animate({ left: -10 },10) 
		               				.animate({ left: 0 },10) 
									.animate({ left: 10 },10) 
									.animate({ left: 0 },10); 
						setTimeout('$("#themsg").removeClass("error");',1000);

					}
			
			
				setmsg( req.responseText );
				break;
			}
		}
	};
	postreq( dst, postdata( form, button ), cb );
	return false;
}

function hidemsg ( that ) {
	var msg;
	if ( that ) {
		var el = that.parentNode
		while ( el ) {
			if ( 'msg' == el.className )
				break;
			el = el.parentNode;
		}
		msg = el;
	} else {
		msg = document.getElementById( 'themsg' );
	}
	if ( msg )
		$(msg).hide();

	$('#themsg_overlay').fadeOut();
	$('#themsg_wrapper').hide();
	$('#themsg').removeClass("error");

}

function stopEvent(evt) {
	if( !evt ) {
		evt = window.event;
	}
	if( evt ) {
		evt.cancelBubble = true;
		evt.returnValue = false;
		if( evt.preventDefault )
			evt.preventDefault;
		if( evt.stopPropagation) 
			evt.stopPropagation();
	}
}
function toggleNotepad(evt, that, id) {
	if( !evt ) {
		evt = window.event;
	}
	evt.cancelBubble = true;
	evt.returnValue = false;
	if( evt.preventDefault )
		evt.preventDefault;
	if( evt.stopPropagation) 
		evt.stopPropagation();
	
	if( $(that).hasClass('notepad_added') ) {
		var cb = function(req, status) {
			if(status == "success") {
				$('#notepad').html(req.responseText);
				$(that).toggleClass('notepad_added');
			}	
		}
		$.ajax({url:'/notepad', type:'POST', data:({remove:id}), complete:cb, cache:false})
	}
	else {
		var cb = function(req, status) {
			if(status == "success") {
				$('#notepad').html(req.responseText);
				$(that).toggleClass('notepad_added');
			}	
		}
		$.ajax({url:'/notepad', type:'POST', data:({add:id}), complete:cb, cache:false})
	}
}

function addToNotepad(evt, that, id) {
	if( !evt ) {
		evt = window.event;
	}
	evt.cancelBubble = true;
	evt.returnValue = false;
	if( evt.preventDefault )
		evt.preventDefault;
	if( evt.stopPropagation) 
		evt.stopPropagation();
	
	var cb = function(req, status) {
		if(status == "success") {
			var xs = xstatus(req);
			switch(xs) {
				case 200:
				$(that).addClass("notepad_added");
				var pvo = $(that).parents('li.pvo-item,li.pvo-detail')
					.css('background-color', '#deebfa')
					.animate({backgroundColor:"white"},1000,'linear', function(){
						pvo.css('background-color','');
					});
				if( pvo.hasClass('pvo-detail') ) {	
					pvo.prev().find('.notepad_add').addClass('notepad_added');
				}	
				notepad_navi_sel(0);
				$('#notepad').html(req.responseText);
				$('#notepad .notepad_selected').css('display', 'none')
					.fadeIn('show')
					.animate({backgroundColor:"white"},1000, 'linear', function() {
						$('#notepad .notepad_selected').css('display', '').css('background-color', '').removeClass('notepad_selected');
					});
				break;
				case 401:
					setmsg( req.responseText );
					break;
			}		
		}
	}	
	$.ajax({url:'/notepad', type:'POST', data:({add:id}), complete:cb, cache:false})
}


function removeFromNotepad(evt, that, id) {

	if( !evt ) {
		evt = window.event;
	}
	evt.cancelBubble = true;
	evt.returnValue = false;
	if( evt.preventDefault )
		evt.preventDefault;
	if( evt.stopPropagation) 
		evt.stopPropagation();

	var cb = function(req, status) {
		if(status == "success") {
			notepad_navi_sel(0);
			var text = req.responseText;
			$(that).parents('li.notepad_item').fadeOut('normal', function() {
				$('#notepad').html(text) });
		}
	}
	$.ajax({url:'/notepad', type:'POST', data:({remove:id}), complete:cb, cache:false});
	
}

function getNotepadStatus(evt,o) {

	if( !evt ) {
		evt = window.event;
	}
	evt.cancelBubble = true;
	evt.returnValue = false;
	if( evt.preventDefault )
		evt.preventDefault;
	if( evt.stopPropagation) 
		evt.stopPropagation();

	var cb = function(req, status) {
		if(status == "success") {
			$('#notepad').html(req.responseText);
		}
	}
	$.ajax({url:'/notepad', type:'POST', data:({status:o}), complete:cb, cache:false});

}

function getPVOFilialen(evt, that) {

	stopEvent(evt);
		
	var pvo;
	var lnk;
	if( $(that).hasClass("pvo-item") ) {
		pvo = $(that);
	}	
	else	{
		pvo = $(that).parents('li.pvo-item');
	}	
	if( $(that).hasClass("filial_show") ) {
		lnk = $(that);
	}
	else {
		lnk = pvo.find("a.filial_show");
	}
	
	if( lnk.hasClass('filial_hide') ) {
		pvo.next().slideUp('normal');
		return;
	}
	else {
		pvo.next().slideDown('normal');
		lnk.addClass('filial_hide'); 
	}
}

function getPVODetail(evt, that, query) {

	stopEvent(evt);
	
	var cb = function(req, status) {
		if( status=="success") {
			var pvo = $('#pvo_detail');
			pvo.html(req.responseText);
			pvo.css('display','none').fadeIn('show');
			var top = pvo.offset().top;
			$('html,body').animate({scrollTop: (top-10)+'px'});
			$('#pvo_result li.pvo-item').removeClass("pvo-selected");
			if( $(that).hasClass('pvo-item') ) {
				$(that).addClass('pvo-selected');
			}
			else {
				$(that).parents('li.pvo-item').addClass('pvo-selected');
			}
		}
	}

	$.ajax({ url:'/pvo?'+query, type:'GET', complete:cb, cache:false});

}

function getPVOListFilialen(evt, that, query, opt) {

	stopEvent(evt);
	
	getPVOListDetail(evt, that, query, opt);
	
	var pvo;
	var lnk;
	if( $(that).hasClass("pvo-item") ) {
		pvo = $(that);
	}	
	else	{
		pvo = $(that).parents('li.pvo-item');
	}	
	if( $(that).hasClass("filial_show") ) {
		lnk = $(that);
	}
	else {
		lnk = pvo.find("a.filial_show");
	}
	
	if( lnk.hasClass('filial_hide') ) {
		/*
		pvo.next().slideUp('normal');
		//		pvo.next().remove();
		lnk.removeClass('filial_hide').text("v");
		*/
		return;
	}
	else {
		pvo.next().addClass('pvo-shaded');
		pvo.next().slideDown('normal');
		// pvo.addClass('pvo-shaded');
		lnk.addClass('filial_hide'); 
		
	}
}

function togglePVOListFilialen(evt, that) {

	stopEvent(evt);
	
	var pvo;
	var lnk;
	if( $(that).hasClass("pvo-item") ) {
		pvo = $(that);
	}	
	else	{
		pvo = $(that).parents('li.pvo-item');
	}	
	if( pvo.size() > 0 ) {
	
		if( $(that).hasClass("filial_show") ) {
			lnk = $(that);
		}
		else {
			lnk = pvo.find("a.filial_show");
		}
		if( lnk.hasClass('filial_hide') ) {
			pvo.next().slideUp('normal', function(){
				pvo.next().removeClass('pvo-shaded');
				// pvo.removeClass('pvo-shaded');
			});
			lnk.removeClass('filial_hide');
		}
		else {
			pvo.next().addClass('pvo-shaded');
			pvo.next().slideDown('normal');
			// pvo.addClass('pvo-shaded');
			lnk.addClass('filial_hide'); 
		}
	}
	else {
		pvo = $(that).parents('li.pvo-detail').prev()
		lnk = pvo.find("a.filial_show");
		pvo.css('display', 'block');
		$('#pvo_detail').remove();
		pvo.next().slideUp('normal');
		lnk.removeClass('filial_hide');
	}
	
}

function getPVOListDetail(evt, that, query, opt) {

	stopEvent(evt);
	
	var cb = function(req, status) {
		if( status=="success") {
	
			if( 201 == xstatus(req) ) {
				location.reload();
				return;
			}

			var pvo;
			if( $(that).hasClass('pvo-item') ) {
				pvo = $(that);
			}	
			else {
				pvo = $(that).parents('li.pvo-item');
			}	

			$('#pvo_detail').remove();
			$('#pvo_result li.pvo-item').removeClass('pvo-selected').css('display', 'block');

			if( pvo.size() == 0 && opt && opt.pos) {
				// click from infoWindow
				pvo = $('#pvo_result li.pvo-pos-'+opt.pos);
				var pvm = pvo.parents('li.list_item');
				if( pvm.size() == 1 && pvm.css('display') == 'none' ) {
					pvm.css('display', 'block');
					pvm.prev().find('a.filial_show').addClass('filial_hide');
					pvm.addClass('pvo-shaded');
				}
				var top = pvo.position().top;
				$('html,body').animate({scrollTop: (top-20)+'px'});
			}
			else {
				var pvm = pvo.parents('li.list_item');
				if( pvm.size() == 1 && pvm.css('display') == 'none' ) {
					pvm.css('display', 'block');
					pvm.prev().find('a.filial_show').addClass('filial_hide');
					pvm.addClass('pvo-shaded');
				}
			}
			
			pvo.after(req.responseText);
			pvo.css('display', 'none');
			/*
			if( pvo.hasClass('pvo-selected') ) {
				pvo.next().addClass('pvo-selected');
			}	
			*/
			pvo.addClass("pvo-selected");
			pvo.next().addClass("pvo-selected");
			if( pvo.find('.pvo-pos-box').hasClass('pvo-pos-sel') ) {
				pvo.next().find('.pvo-pos-box').addClass('pvo-pos-sel');
			}
			if( pvo.find('.notepad_add').hasClass('notepad_added') ) {
				pvo.next().find('.notepad_add').addClass('notepad_added');
			}

			if( opt && opt.tab ) {
				onToggleMore('pvo_detail', 'pvo_detail_'+opt.tab);
			}
		
			if( opt && opt.pos ) {
 				if( $('#map_item').hasClass('map_visible' ) ) { 
					markPVOMap(that, opt.pos);
				}
				else {
					_gmap_position = function() { markPVOMap(that,opt.pos); }
				}
			}
		
		}
	}

	$.ajax({ url:'/pvo?'+query, type:'GET', complete:cb, cache:false});

}

function closePVOListDetail() {
		$('#pvo_detail').slideUp('normal', function(){
			$('#pvo_detail').remove();
			$('#pvo_result li.pvo-item').css('display', 'block');
		});
}

function getPVOMore(evt, that, query) {

	stopEvent(evt);

	var pvo = $(that).parents('li.pvo-more');
	var cb = function(req, status) {
		if( status=="success") {

			if( 201 == xstatus(req) ) {
				location.reload();
				return;
			}
		
			pvo.after(req.responseText);
			pvo.remove();
			getPVOPoempel(query);
		}
	}

	$.ajax({url:'/pvo?list=more&'+query, type:'GET', complete:cb, cache:false});
}

function sortPVOList(evt, that, query) {
	stopEvent(evt);

	var cb = function(req, status) {
		if( status=="success") {

			if( 201 == xstatus(req) ) {
				location.reload();
				return;
			}

			$('#pvo_result').html(req.responseText);
			_gmap_main.clearOverlays();
			_gmap_bounds = new GLatLngBounds();
			_gmap_marker = {};
			_gmap_position = null;	
			getPVOPoempel('o=1&c=25');
		}
	}
	$.ajax({url:'/pvo?sort='+query, type:'GET', complete:cb, cache:false});
}

function getPVOMap(evt, that, rng) {

	stopEvent(evt);

	var pvo;
	if( $(that).hasClass('pvo-item') ) {
		pvo = $(that);
	}	
	else {
		pvo = $(that).parents('li.pvo-item');
	}	

	var pvd;
	if( pvo.size() == 0 ) {
		pvo = $(that).parents('li.pvo-detail').prev();
		if( pvo.size() == 0 ) {
			return;
		}
		pvd = pvo.next();
	}	

	var pos = rng.split('-');
	var b= parseInt(pos[0], 10);
	var e = pos.length==2? parseInt(pos[1], 10) : b;

	if( _mark_selection ) {
		for( var n=0; n<_mark_selection.length; ++n) {
			var marker = _gmap_marker[ _mark_selection[n] ];
				_gmap_main.removeOverlay(marker);
				_gmap_main.addOverlay(marker);
		}
		_mark_selection = [];
	}
	$('#pvo_result .pvo-pos-box').removeClass('pvo-pos-sel');

	if( _gmap_main ) {
	var zoom = 15;
	var center;
	if( b==e ) {
		var marker = _gmap_marker[""+b];
		if( marker ) {
			center = marker.getPoint();
			_mark_selection.push(""+b);
			marker.setImage('/images/content/map_PvO-marker-r.png');
			$('#pvo_result li.pvo-pos-'+b+' .pvo-pos-box').addClass('pvo-pos-sel');
		}
		else {
			return;
		}
	}
	else {
		_mark_selection = []
		var bounds = new GLatLngBounds();
		for(var n=b; n<=e; ++n) {
			var marker = _gmap_marker[""+n];
			if( marker ) {
				bounds.extend(marker.getPoint());
				_mark_selection.push(""+n);
				marker.setImage('/images/content/map_PvO-marker-r.png');
				$('#pvo_result li.pvo-pos-'+n+' .pvo-pos-box').addClass('pvo-pos-sel');
			}	
		}
		center = bounds.getCenter();
		zoom = _gmap_main.getBoundsZoomLevel(bounds);
	}	
	
	$('#map_item').slideDown('normal', function(){
		$('#map_item').addClass("map_visible");
		_gmap_main.setCenter(center, zoom);
		if( b==e ) {
			var marker = _gmap_marker[""+b];
			if( marker ) {
				//marker.openInfoWindow('<div class="pvo-gmap">'+pvo.html()+'</div>');
				marker.openExtInfoWindow(_gmap_main, 'extinfo_window', '<div class="pvo-gmap">'+pvo.html()+'</div>', {beakOffset:3});
			}	
		}
		var top = $('#map_item').position().top;
		$('html,body').animate({scrollTop: (top-10)+'px'});
	});
	}

	$('#pvo_result li.list_item').removeClass('pvo-selected');
	pvo.addClass('pvo-selected');
	if( pvd ) {
		pvd.addClass('pvo-selected');
	}
}

function markPVOMap(that, rng) {

	if( !_gmap_main )
		return;

	var pvo; //  = $(that).parents('li.pvo-item');
	if( $(that).hasClass('pvo-item') ) {
		pvo = $(that);
	}	
	else {
		pvo = $(that).parents('li.pvo-item');
	}	
	if( pvo.size() == 0 ) {
		pvo = $('#pvo_result li.pvo-pos-'+rng);
		if( pvo.size() == 0 ) {
			return;
		}
		pvd = pvo.next();
	}	

	var pos = rng.split('-');
	var b= parseInt(pos[0], 10);
	var e = pos.length==2? parseInt(pos[1], 10) : b;

	if( _mark_selection ) {
		for( var n=0; n<_mark_selection.length; ++n) {
			var marker = _gmap_marker[ _mark_selection[n] ];
				_gmap_main.removeOverlay(marker);
				_gmap_main.addOverlay(marker);
		}
	}
	_mark_selection = [];
	$('#pvo_result .pvo-pos-box').removeClass('pvo-pos-sel');

	var zoom = 15;
	var center;
	if( b==e ) {
		var marker = _gmap_marker[""+b];
		if( marker ) {
			center = marker.getPoint();
			_mark_selection.push(""+b);
			marker.setImage('/images/content/map_PvO-marker-r.png');
			$('#pvo_result li.pvo-pos-'+b+' .pvo-pos-box').addClass('pvo-pos-sel');
		}
		else {
			return;
		}
	}
	else {
		var bounds = new GLatLngBounds();
		for(var n=b; n<=e; ++n) {
			var marker = _gmap_marker[""+n];
			if( marker ) {
				bounds.extend(marker.getPoint());
				_mark_selection.push(""+n);
				marker.setImage('/images/content/map_PvO-marker-r.png');
				$('#pvo_result li.pvo-pos-'+n+' .pvo-pos-box').addClass('pvo-pos-sel');
			}	
		}
		center = bounds.getCenter();
		zoom = _gmap_main.getBoundsZoomLevel(bounds);
	}	

	_gmap_main.setCenter(center, zoom);
	if( b==e ) {
		var marker = _gmap_marker[""+b];
		if( marker ) {
			//marker.openInfoWindow('<div class="pvo-gmap">'+pvo.html()+'</div>');
			marker.openExtInfoWindow(_gmap_main, 'extinfo_window', '<div class="pvo-gmap">'+pvo.html()+'</div>', {beakOffset:3});
		}	
	}

}

function showPVOSlide(pos, inc) {
	clearTimeout(superSlideTimer);
	$('#pvo_detail_img_0').parent().find('li.slide-navi span').removeClass('slide-navi-active');
	$('#pvo_detail_img_0').parent().find('li.slide-navi-stop span').addClass('slide-navi-active');
	var img = $('#pvo_detail_img_0').parent().find('div.pvo-detail-img');
	if( inc != null ) {
		pos = 0;
		for( var n=0; n<img.length;++n) {
			var div = $(img.get(n));
			if( div.css('display') == 'block' ) {
					pos = n;
				div.css('display', 'none');
				break;
			}	
		}
		pos += inc;
	}
	else {
		img.css('display', 'none');
	}

	if( pos >= img.length )
		pos = 0;
	if( pos < 0 )
		pos = img.length-1;

	$(img.get(pos)).css('display', 'block');

	return pos;
}
function playPVOSlide(pos, timeout){
	if( timeout ) {
		pos = 0;
		var img = $('#pvo_detail_img_0').parent().find('div.pvo-detail-img');
		for( var n=0; n<img.length;++n) {
			if( $(img.get(n)).css('display') == 'block' ) {
				pos = n;
				break;
			}
		}
	}
	else {
		pos = showPVOSlide(pos);
		timeout = 5000;
	}	
	$('#pvo_detail_img_0').parent().find('li.slide-navi span').removeClass('slide-navi-active');
	$('#pvo_detail_img_0').parent().find('li.slide-navi-play span').addClass('slide-navi-active');

	superSlideTimer = setTimeout(function(){ playPVOSlide(pos+1) }, timeout);
}

function showPVODetailImage(that, d) {
	var pos = 0;
	var img = $(that).parent().find('div.pvo-detail-img');
	for( var n=0; n<img.length;++n) {
		var div = $(img.get(n));
		if( div.css('display') == 'block' ) {
			pos = n;
			div.css('display', 'none');
			break;
		}	
	}	
	
	pos += d;
	if( pos < 0 )
		pos = img.length-1;
	if( pos >=img.length )
		pos = 0

	$(img.get(pos)).css('display', 'block');

}

var _gmap_position = null;
var _gmap_init = false;
function togglePVOMap(evt, that) {
	var gmap = $('#map_item');
	if( gmap.hasClass("map_visible") ) {
		
		gmap.slideUp('normal');	

	}
	else {

		gmap.slideDown('normal', function() {
			if( _gmap_main ) {
			if( 'function' == typeof(_gmap_position) ) {
				_gmap_position();
				_gmap_position = null;
			}
			else
			if( !_gmap_init && !_gmap_bounds.isEmpty() ) {
					var zoom = _gmap_main.getBoundsZoomLevel(_gmap_bounds);
					_gmap_main.setCenter(_gmap_bounds.getCenter(), zoom);
				_gmap_init = 1;
			}
			}
		});

	}
	gmap.toggleClass("map_visible");
}

function clickPVOPoempel(marker,point) {
	if( marker && marker.getTitle ) {
		var pvo = $('#pvo_result li.pvo-pos-'+marker.getTitle());
		pvo.click();
		setTimeout(function(){
			var pvd = $('#pvo_detail');
			try {
			var top = pvd.position().top;
			$('html,body').animate({scrollTop: (top-20)+'px'});
			}
			catch(e) {}
		}, 500);
	}	
}
function showPVOPoempelInfo(marker) {
	var pvo = $('#pvo_result li.pvo-pos-'+marker.getTitle());
	//	marker.openInfoWindow('<div class="pvo-gmap">'+pvo.html()+'</div>');
	marker.openExtInfoWindow(_gmap_main, 'extinfo_window', '<div class="pvo-gmap">'+pvo.html()+'</div>', {beakOffset:3});
}

function getPVOPoempel(query) {
	if( !window._gmap_main )
		return;

	var cb = function(req,status) {
		if( 'success' == status ) {
			var list = req.responseText.split('\n')
			for( var n=0; n < list.length; ++n) {
				var poemple = list[n].split('\t');
				if( poemple.length > 2 ) {
					var latlng = poemple[2].split(',');	
					var pos = poemple[3];
					if( pos != '' && latlng.length == 2 ) {
						var clat = parseFloat(latlng[0].split(":")[1]);
						var clng = parseFloat(latlng[1].split(":")[1]);
						var point = new GLatLng(clat, clng);
						_gmap_bounds.extend(point);
						var marker;
						if( 'here' == pos ) {
							var icon = new GIcon();
							/*
							icon.image = '/css/img/pin_here.png';
							icon.Size = new GSize(40,40);
							icon.iconSize = new GSize(40,40);
							icon.iconAnchor = new GPoint(20,20);
							*/
							icon.image = '/images/content/map_PvO-marker-here.png';
							icon.Size = new GSize(68,69);
							icon.iconSize = new GSize(68,69);
							icon.iconAnchor = new GPoint(34,34);
							/*
							icon.image = '/images/content/map_PvO-marker-here.png';
							icon.Size = new GSize(16,16);
							icon.iconSize = new GSize(16,16);
							icon.iconAnchor = new GPoint(8,8);
							*/
							marker = new GMarker(point, {icon:icon,title:pos})

						}
						else {
							/*
							marker = new GMarker(point, {title:pos})
							*/
							var icon = new GIcon();
							icon.image = '/images/content/map_PvO-marker-g.png';
							icon.Size = new GSize(32,25);
							icon.iconSize = new GSize(32,25);
							icon.iconAnchor = new GPoint(9,24);
							icon.infoWindowAnchor = new GPoint(7,16);
							marker = new GMarker(point, {icon:icon,title:pos})
							GEvent.addListener(marker, 'mouseover', function(){ showPVOPoempelInfo(this);});
//							GEvent.addListener(marker, 'mouseout', function(){this.closeInfoWindow();});
						}	
						_gmap_marker[pos] = marker;
						_gmap_main.addOverlay(marker);
					}	
				}
			}
			var zoom = _gmap_main.getBoundsZoomLevel(_gmap_bounds);
			_gmap_main.setCenter(_gmap_bounds.getCenter(), zoom);
			GEvent.addListener(_gmap_main, "click", clickPVOPoempel);
		}
	}
	$.ajax({url:'/pvo?gmap=load&'+query, type:'GET', complete:cb, cache:false});
}

function updatePVOListDetail(frm, query, tab) {
	var el = document.getElementById('pvo_detail')
	if( !el ) return false;

	var cb = function ( req ) {
		if ( 4 == req.readyState && 200 == req.status ) {
			var xs = xstatus( req );
			if ( 200 == xs ) {
				var txt = req.responseText;
				if ( txt ) {
						el.innerHTML = txt;
				}
				removeDynScripts();
				var script = el.getElementsByTagName('script');
				var len = script.length;
				for( var n=0; n<len; ++n ) {
					var node = script[n].cloneNode(true);
					node.className = 'dynScript';
					document.body.appendChild(node);
				}
				if( tab ) {
					onToggleMore('pvo_detail', 'pvo_detail_'+tab);
				}
			} 
			else
			if ( 201 == xs ) {
				setmsg( req.responseText );
				closePVOListDetail();
			}
			else
			if ( 202 == xs ) {
				setmsg( req.responseText );
				var		pvo = $(frm).parents('li.pvo-detail').prev();
				if( pvo.size() == 0 ) {
						return;
				}	
				getPVOListDetail(null,pvo.get(0),query,tab);
			}
			else {
				upd_header ( req );
				setmsg( req.responseText );
			}
		}
	};

	$(frm).ajaxSubmit({url:'/pvo', complete:cb, cache:false});

	return false;

}



/*
	PPO
*/
function getPPOListDetail(evt, that, query, opt) {

	stopEvent(evt);

	var cb = function(req, status) {
		if( status=="success") {
	
			if( 201 == xstatus(req) ) {
				location.reload();
				return;
			}

			var ppo;
			if( $(that).hasClass('ppo-item') ) {
				ppo = $(that);
			}	
			else {
				ppo = $(that).parents('li.ppo-item');
			}	

			$('#ppo_detail').remove();
			$('#ppo_result li.ppo-item').removeClass('ppo-selected').css('display', 'block');

						
			ppo.after(req.responseText);
			ppo.css('display', 'none');
			
			ppo.addClass("ppo-selected");
			ppo.next().addClass("ppo-selected");

			if( opt && opt.tab ) {
				onToggleMore('ppo_detail', 'ppo_detail_'+opt.tab);
			}
		
		}
	}

	$.ajax({ url:'/ppo?'+query, type:'GET', complete:cb, cache:false});

}

function getPPOMore(evt, that, query) {

	stopEvent(evt);

	var ppo = $(that).parents('li.ppo-more');
	var cb = function(req, status) {
		if( status=="success") {

			if( 201 == xstatus(req) ) {
				location.reload();
				return;
			}
		
			ppo.after(req.responseText);
			ppo.remove();
		}
	}

	$.ajax({url:'/ppo?list=more&'+query, type:'GET', complete:cb, cache:false});
}

function closePPOListDetail() {
		$('#ppo_detail').slideUp('normal', function(){
			$('#ppo_detail').remove();
			$('#ppo_result li.ppo-item').css('display', 'block');
		});
}


/*
	used by fwd2affili
*/
function trypopup ( dst, track ) {
//	try {
		var w = window.open()
		if ( w ) {
			hidemsg();
			w.location.href = dst;
			if( track ) {
				pageTracker._trackPageview('/outgoing/'+track);
			}
		}
//	} catch ( e ) {
//	}
}


function init () {
	if ( window.popup ) {
		trypopup( window.popup, popup_tracking );
	}

	/*
	*/
	if( window.gmap_load )
		gmap_load();

	BoxHeights.equalise('#sitemap_col1','#sitemap_col2','#sitemap_col3','#sitemap_col4','#sitemap_col5');
	BoxHeights.equalise('#list_A','#list_B');	
	BoxHeights.equalise('#top_A','#top_B','#top_C');	

	if($.browser.msie) {
		$('.rounded').before('<div class="mask"><div class="left"></div><div class="right"></div></div>');
		$('#sidebar-wrapper .mask').addClass("sidebar");
		$('.mask').wrap('<div class="roundedIE"></div>');
	}
	
    $('#thumbcarousel').jcarousel({
		auto: 5,
		scroll: 1,
		wrap: 'last',
        initCallback: thumbcarousel_initCallback
        });
    $('#thumbcarousel').css('visibility', 'visible');
    $('#thumbs').mouseover(function(){
   	 	$('.jcarousel-next').css('display', 'block');
	    $('.jcarousel-prev').css('display', 'block');
	});
    $('#thumbs').mouseout(function(){
   	 	$('.jcarousel-next').css('display', 'none');
	    $('.jcarousel-prev').css('display', 'none');
	});
	if($('#super')){
		playSuperSlide(0);
		$('#super').mouseover(function(){clearTimeout(superSlideTimer)});
//		$('#super').mouseout(function(){playSuperSlide(superSlideLastId);});
	}
}


function playSuperSlide(id){
	if((id+1)>$("#super .slide").length) id=0;
	onToggleSuperSlide('slide_'+id);
	superSlideTimer = setTimeout('playSuperSlide('+(id+1)+')', 5000);
	superSlideLastId = id;
}

function onToggleSuperSlide(slide){
		$('.slide').each(function(i){
			$('#slide_'+i+' .box').removeClass('active');
			$('#slide_'+i+' .img').removeClass('active');
		});
		$('#'+slide+' .box').addClass('active');
		$('#'+slide+' .img').addClass('active');
} 

function onToggleMore(item, info) {
		if($('#'+info+'_head').hasClass("active")) {
			onCloseMore(item, info);
		} else {
			onShowMore(item, info);
		}

}

function onCloseMore(item, info) {
	$('#'+info+'_body').slideUp();
	onUpdateMoreNavi(item);
}

function onShowMore(item, info) {
	var elm = document.getElementById(info+'_body');
	if( !elm )
		return;

	if( elm.style.display == 'block' ) {
		onCloseMore(info);
		return;
	}

	var li = document.getElementById(item+'_body').firstChild;
	while( li ) {
		if( li.nodeName == 'LI' ) {
			$(li).hide()
		}	
		li = li.nextSibling;
	}


	if(onCheckMoreNaviActive(item)) {
		$(elm).show();
	} else {
		$(elm).slideDown();
	}
	onUpdateMoreNavi(item, info);
	
	/*
//	urchinTracker(item+info);
	pageTracker._initData(item+info);
	pageTracker._trackPageview(item+info);
  cab_display();
	*/
}

function onCheckMoreNaviActive(item){
	var li = document.getElementById(item+'_head').firstChild;
	while( li ) {
		if( li.nodeName == 'LI' ) {
			if($(li).hasClass("active")) return true;
		}			
		li = li.nextSibling;
	}
	return false;
}

function onClearNavi(item){
	var li = document.getElementById(item+'_head').firstChild;
	while( li ) {
		if( li.nodeName == 'LI' ) {
			$(li).removeClass("active");
		}			
		li = li.nextSibling;
	}

}

function onUpdateMoreNavi(item, info){
	onClearNavi(item)
	if(info) $('#'+info+'_head').addClass("active");

}

function onShowOption(item) {
	var option = document.getElementById(item+"_options");
//	var ob = document.getElementById(item+"_options_back");
	if( option ) {
		if( option.style.display != "block" ) {
			option.style.display = "block";
    }
		else {
			option.style.display="none";
    }
	}
}

function onSelectOption(item, option){
	var item = document.getElementById(item);
	var elem = document.getElementById(option);
	var vari = item.firstChild;
	while( vari ) {
		if( vari.nodeName == 'DIV' )
			vari.style.display = 'none';
		vari = vari.nextSibling;
	}
	var sel = document.getElementById(option+'_select');
	if( sel ) {
		sel.value = option;
	}	
	elem.style.display = 'block';
}



function onRate(that, rate) {
	/*
	var p = that.parentNode;
	if( p.parentNode.nodeName=='FORM' ) {
		p.parentNode.elements['rate'].value = rate;
	}
	var div = p.childNodes;
	for(var n=0; n<div.length; n++ ){
		if(div[n].nodeName != '#text') {
			if(n/2<rate){
				$(div[n]).removeClass("notrated");
				$(div[n]).addClass("rated");
			} else {
				$(div[n]).addClass("notrated");
				$(div[n]).removeClass("rated");
			}
		}
	}
	*/
	$(that).parents('form').find("input[name='rate']").val(rate);
	$(that).parent().find('a.rate_item').each(function(i) {
		if( i < rate ) {
			$(this).removeClass('notrated');
			$(this).addClass('rated');
		}
		else {
			$(this).addClass('notrated');
			$(this).removeClass('rated');
		}
	});
		
}


function getElementByClassName(node,tagName,className,debug) {
	var i=0;
	if (node && node.childNodes) {
		for(i=0;i<node.childNodes.length;i++) {
       if (debug) alert(node.childNodes[i].tagName+","+node.childNodes[i].className);
			if ( node.childNodes[i].tagName==tagName
					&& (node.childNodes[i].className==className
					|| node.childNodes[i].className.indexOf(" "+className) >=0
					|| node.childNodes[i].className.indexOf(className+" ") >= 0 )
			) {
				return node.childNodes[i];
			}
		}
	}
	return null;
}

function onCloseError(that) {
	that.style.display="none";
	that.parentNode.className = that.parentNode.className.replace( / active/, '' );
	var input=getElementByClassName(that.parentNode,"DIV","val");
	input.style.display="inline";
	for ( var sib = input.firstChild; sib; sib = sib.nextSibling ) {
		if ( 3 != sib.nodeType ) {
			sib.focus();
			break;
		}
	}
}

function clearhdob ()
{
	var inp = document.getElementById( 'hdob' );
	inp.value = "";
}

var all_uni = false;
function showuni ( sel )
{
	if ( 0 < sel.selectedIndex ) {
		var copt = eval( sel.options[ sel.selectedIndex ].value );
		var u = document.getElementById( 'unisel' );
		if ( !all_uni ) {
			var txt = document.getElementById( 'alluni' ).innerHTML;
			txt = txt.replace( /[\r\n]/g, '' );
			eval( txt );
		}
		u.selectedIndex = -1;
		u.innerHTML = '';
		for ( var i = 0; copt.length > i; ++i ) {
			var o = document.createElement(  'OPTION' );
			o.value = copt[i];
			o.innerHTML = all_uni[ 'u' + copt[i] ];
			u.appendChild( o );
		}
		u.selectedIndex = 0;
		u.style.visibility = 'visible';
	}
}

function updaddr2(sel) {
  var form=sel.parentNode;
	while(form.nodeName!="FORM") form=form.parentNode; 
	val=sel.value;
	if (val) {
	var a = val.split(  '\t' );
	form.f401_15.value = a[0];
	form.f401_17.value = a[1];
	form.f401_12.value = a[2];
	form.av.value = val;
	sel.parentNode.style.display = 'none';
	form.achooser.value = val;
	}
}

function updaddr ( list, fname, val )
{
  if (fname) {
	var form = document.forms[ fname ];
	if (val) {
	var a = val.split(  '\t' );
	form.f401_15.value = a[0];
	form.f401_17.value = a[1];
	form.f401_12.value = a[2];
	form.av.value = val;
	list.parentNode.parentNode.style.display = 'none';
	form.achooser.value = val;
	}}
}

function enable_err ( node, erroff )
{
	var prnt = node.parentNode.parentNode;
	if ( 0 > prnt.className.indexOf( ' active' ) )
		prnt.className += ' active';
	var d = prnt.getElementsByTagName( 'DIV' );
	d[erroff].style.display = 'inline';
//	node.parentNode.style.display = 'none';
}

function disable_err(node) {
	var prnt = node.parentNode.parentNode;
	var d = prnt.getElementsByTagName( 'DIV' );
	var i;
	for(i=0;i<d.length;i++) {
	  if (d[i].className!="val" && d[i].className!="lbl") {
	d[i].style.display='none';
		}
	}
}


function eval_reg ( form, numval, dspl )
{
	var el = form.elements;
	var empty = 0;
	var err = 0;
	if ( form.achooser && !form.achooser.value ) return false;
	var uni = false;
	for ( var i = 0; el.length > i; ++i ) {
		switch ( el[i].name ) {
		case 'f401_3': // first name
		case 'f401_2': // last name
		case 'f401_12': // street
		case 'f401_13': // house number
		case 'f401_15': // postal code
		case 'f401_17': // locality
		case 'f401_6':  // e-mail
		case 'f401_8':  // phone
	  disable_err(el[i]);
			if ( ! el[i].value ) {
				++empty;
				if ( 'f401_8' != el[i].name && dspl ) {
					err++;
					enable_err( el[i], 1 );

				}
			} else if ( dspl ) {
				var re = false;
				var off = 1;
				if ( 'f401_6' == el[i].name ) {
					re = /^[^@;'"´`]+@[^@'";´`]+\.[^\.]{2,4}$/;
					off = 2;
				} else if ( 'f401_8' == el[i].name ) {
					re = /^\+?\d+$/;
				} else if ( 'f401_15' == el[i].name ) {
					re = /^\d{5}$/;
					off = 2;
				}
				if ( re && ! re.test( el[i].value ) ) {
					err++;
					enable_err( el[i], off );
				}
			}
			break;
		case 'f401_4': // gender
		case 'f411_c': // course
		case 'f411_u': // university
		case 'f411_t': // term
		case 'f411_e': // estimated end of studies
	  disable_err(el[i]);
			var idx = 'f411_u' == el[i].name ? 0 : 1;
			if ( idx > el[i].selectedIndex && !el[i].value ) {
				++empty;
				if ( dspl ) {
					err++;
					enable_err( el[i], 1 );
				}
			}
			break;
		case 'f401_5': // date of birth 
	  disable_err(el[i]);
			if ( ! el[i].value ) {
				if ( dspl ) {
					var sbox = form.elements[ 'dob_year' ];
					var y = 0 < sbox.selectedIndex &&
						sbox.options[ sbox.selectedIndex ].value;
					sbox = form.elements[ 'dob_mon' ];
					var m = 0 < sbox.selectedIndex &&
						sbox.options[ sbox.selectedIndex ].value;
					sbox = form.elements[ 'dob_day' ];
					var d = 0 < sbox.selectedIndex &&
						sbox.options[ sbox.selectedIndex ].value;
					if ( y && d && m ) {
						var yi = parseInt( y, 10 );
						var mi = parseInt( m, 10 ) - 1;
						var di = parseInt( d, 10 );
						var date = new Date( yi, mi, di );
						if ( yi == date.getFullYear()
							&& mi == date.getMonth()
							&& di == date.getDate()
						) {
							el[i].value = y + m + d + '000000';
							break;
						}
					}
					if ( y || d || m ) {
						err++;
						enable_err( el[i], 2 );
						break;
					}
				}
				++empty;
				if ( dspl ) {
					err++;
					enable_err( el[i], 1 );
				}
			}
		}
	}
	if ( dspl ) {
		if ( !err ) {
			var addr = form.f401_15.value + '\t' + form.f401_17.value + '\t'
				+ form.f401_12.value;
			if ( addr != form.av.value ) form.av.value = '';
		}
		return !err;
	}
	if ( numval != empty ) return eval_reg( form, numval, true );
	return false;
}

function tabOnTop ( elmnt, child, navi ) {
	var main=document.getElementById("middle_main") ||
			document.getElementById('main');
	var divs=main.childNodes;
	var i;
	var item=null;
	for( i = 0; i < divs.length; i++ ) {
		if ( 0 == divs[i].className.indexOf( child ) ) {
			item = divs[i];
			break;
		}
	}
  	if ( item ) {
		var ele = document.getElementById( elmnt );
		var profs = item.getElementsByTagName("div");
		var p_navi;
		for( i = 0; i < profs.length; i++) {
			if ( 0 < profs[i].className.indexOf( ' selected_item' ) ) {
				profs[i].className =
						profs[i].className.replace( / selected_item/, '' );
			}
		}
		ele.className = ele.className + " selected_item";
		divs = navi.childNodes;
		for( i = 0; i < divs.length; i++ ) {
			if ( 'DIV' == divs[i].nodeName ) {
				if ( 0 <= divs[i].className.indexOf( "p_nitem" ) ) {
					var fs = "" + divs[i].onclick;
					divs[i].className = "p_nitem selectable" +
							( 0 < fs.indexOf( elmnt ) ? " selected_item" : "" );
				}
			}
		}
  	}
}

function nextImg(that) {
  if (that && that.className.indexOf("pf110")>=0) {
     var prof=that.parentNode.parentNode;
		 var thys=that.parentNode;
     var divs=prof.childNodes;
     var imgs=new Array();
     var img;
     var i,si=-1;
		 var f=-1;
		 var my=null;
     for(i=0;i<divs.length;i++) {
        if (divs[i].nodeName=="DIV" && divs[i].className.indexOf("pimage")==0) {
				   if (f==-1) {
					 	f=i;
					 }
					 if (si==0) {
					 	si=i;
					 }
				   if (si==-1 && divs[i]==thys) {
					   si=0;
					 }
					 
					 divs[i].className="pimage";
		    }
     }
		 if (si>0) {
		    divs[si].className="pimage selected_img";
		 } else {
		 	if (f>=0) {
		    divs[f].className="pimage selected_img";
			}
		 }
	}
}


function popup00(breite,hoehe,name, url) // popup-Funktion mit komplettem Browsermenu
  {
	var wurl = url ? url : '';
   var fenster=window.open( wurl,name,'width=' + breite + ',height=' + hoehe +',resizable=yes,scrollbars=yes,toolbar=yes,status=yes,menubar=yes,location=yes');
   fenster.focus();
  }


function thumbcarousel_initCallback(carousel)
{

    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
    
    carousel.buttonNext.css('display', 'none');
    carousel.buttonPrev.css('display', 'none');

}


function delCookie(name) {
	document.cookie = name + 
	'=; expires=Thu, 01-Jan-1970 00:00:01 GMT;';
}

