

function quickfinder_show()
{
	var qfl = document.getElementById("quickfinder_list");
	qfl.style.display = "block";

}

function quickfinder_hide()
{
	var qfl = document.getElementById("quickfinder_list");
	qfl.style.display = "none";
}

function meta_print()
{
	window.print();
}


function person_highlight(id)
{
	var pos = -1;
	for ( var i = 0 ; i<person_id_list.length ; i++ )
	{
		var uid = person_id_list[i];
		if ( uid != id )
			person_unhighlight(uid);
		else
			pos = i;
	}
	var img = document.getElementById("person_image_"+id);
	var container = document.getElementById("person_image_container_"+id);
	var imgS = document.getElementById("person_image_shadow_"+id);
	var srcImg = document.getElementById("NC_IMAGE_"+id).innerHTML;
	var pi = document.getElementById("person_info_"+id);

	//img.src = "/jwa/vfs"+srcImg.replace("_hell","");
	pi.style.display = "block";
	imgS.style.display = "none";
	if ( pos > ( person_id_list.length / 2 ) )
	{
		pi.className = "person_info person_info_right";
	} else { 
		pi.className = "person_info";
	}
	container.className = "person_image_container person_image_container_highlight";
}
function person_unhighlight(id)
{
	var img = document.getElementById("person_image_"+id);
	var imgS = document.getElementById("person_image_shadow_"+id);
	var srcImg = document.getElementById("NC_IMAGE_"+id).innerHTML;
	var pi = document.getElementById("person_info_"+id);
	var container = document.getElementById("person_image_container_"+id);
	//img.src = "/jwa/vfs"+srcImg;
	pi.style.display = "none";
	imgS.style.display = "block";
	container.className = "person_image_container";
}

function init_news_alt(id)
{ 
	
	
	var p = document.getElementById("NC_PDF_"+id);
	

	if ( (p.innerHTML+"").search(".pdf") != -1 )
	{
		p.innerHTML = "<a href=\"/jwa/vfs"+p.innerHTML+"\" target=\"_blank\"><img src=\"/jwa/VFS-DFA-275126-pdf.png\" /></a>";
	} else {
		p.innerHTML = "";
	}
}

function init_pdf_download_row(id)
{ 
	if(window.download_rows == null)
		window.download_rows = new Array();
	if(window.download_map == null)
		window.download_map = new Array();
	//window.download_rows.push(id);

	var ct = document.getElementById("pdf-download-row-"+id);
	var p = document.getElementById("NC_PDF_"+id);
	window.download_rows.push(p.innerHTML);
	if(window.download_map[p.innerHTML]==null)
		window.download_map[p.innerHTML] = new Array();
	window.download_map[p.innerHTML].push(id);
	if ( ++rowcount%2==0 )
  		ct.className = "pdf-download-row pdf-download-row2";

	/*t.innerHTML = "<a href=\"/jwa/vfs"+p.innerHTML+"\" target=\"_blank\"><img src=\"/jwa/VFS-DFA-275126-pdf.png\" /> "+t.innerHTML+"</a>";

	if ( o.innerHTML == "keines" )
   		o.innerHTML = "";
	else {
	   o.innerHTML = "<a href=\""+o.innerHTML+"\" target=\"_blank\">Homepage</a>";
	}

	var delay = Math.random()*1200;
	setTimeout("setDummySize("+id+")",delay);*/

}
function parseRows(data) {
	for(var i=0; i < data.length; i++) {
		for(var index in window.download_map[data[i].path]) {
			var id = window.download_map[data[i].path][index];
			var t = document.getElementById("NC_TITLE_"+id);
			var p = document.getElementById("NC_PDF_"+id);
			var obj = document.getElementById("NC_OBJECT_"+id);
			var size = document.getElementById("NC_SIZE_"+id);
	
			if(data[i].csize < 1024) {
				size.innerHTML = data[i].csize + " B";
			} else if(data[i].csize < 1024*1024) {
				size.innerHTML = (data[i].csize/1024.).toFixed(0) + " KB";
			} else if(data[i].csize < 1024*1024*1024) {
				size.innerHTML = (data[i].csize/(1024.*1024.)).toFixed(0) + " MB";
			} else {
				size.innerHTML = (data[i].csize/(1024.*1024.*1024.)).toFixed(0) + " GB";
			}
			size.style.textAlign="right";
	
		//if ( rowcount%2==0 )
  		//	ct.className = "pdf-download-row pdf-download-row2";

			t.innerHTML = "<a href=\"/jwa/vfs"+p.innerHTML+"\" target=\"_blank\" title=\""+t.innerHTML+"\"><img src=\"/jwa/VFS-DFA-275126-pdf.png\" /> <span id=\"nc_processed_title_"+id+"\">"+t.innerHTML+"</span></a>";

			var pt = document.getElementById("nc_processed_title_"+id);

			var pt_content = (pt.innerHTML+"");
			var pt_clenght = pt_content.length;

			while ( pt.offsetWidth > 280 )
			{
				pt_clenght--;
				pt.innerHTML = pt_content.substring(0,pt_clenght)+" ...";
			}

			if ( obj.innerHTML == "keines" )
   				obj.innerHTML = "";
			else {
			   obj.innerHTML = "<a href=\""+obj.innerHTML+"\" target=\"_blank\">Homepage</a>";
			}
		
		}
		window.download_map[data[i].path] = null;

	}
	for (var path in window.download_map){
		for(var index in window.download_map[path]) {
		var id = window.download_map[path][index];
		if(id != null) {
			
			var t = document.getElementById("NC_TITLE_"+id);
			var p = document.getElementById("NC_PDF_"+id);
			var obj = document.getElementById("NC_OBJECT_"+id);
			var size = document.getElementById("NC_SIZE_"+id);
			size.innerHTML = 0;
			size.style.textAlign="right";
			if ( obj.innerHTML == "keines" )
   				obj.innerHTML = "";
			else {
			   obj.innerHTML = "<a href=\""+obj.innerHTML+"\" target=\"_blank\">Homepage</a>";
			}
			
						

		}
		}
	}
}
function getRows() {
	jQuery.ajax({
	  type: 'POST',
	  url: "/jwa/filelist.jsp",
	  dataType: 'json',
	  data: {"path": window.download_rows},
	  success: parseRows
	});

	//jQuery.getJSON( "/jwa/filelist.jsp", "", parseRowsgo);
}



function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function changeSize(size) {  
  size = +size;
  if(!size in {100:'',120:'',150:''})
	size = 120;

  var documentSize = document.getElementById("document_size");
  if(documentSize==null)
	return;
  var url = documentSize.href.replace(/\d+\.css/,size + ".css");
  documentSize.href = url;
Set_Cookie("scrollSize",size,"","/","","");
}

function initSize() {
	var val = Get_Cookie("scrollSize");
	if(val != null) {
		changeSize(val);
	}
}

function mobimo_init(lang)
{
	

	/** links news schreiben **/
	if ( (window.location+"").search("/"+lang+"/home") != -1 )
	{
		var mc = document.getElementById("mainnavigation");
		mc.innerHTML = "<ul class=\"news_left\"><li><a href=\"/"+lang+"/home\">News</a></li></ul>";
	}

	try {
		if ( runImageSwap )
			randomImageSwap(lang);
	} catch ( e )
	{ }

	if ( msieversion() == 6 )
	{
		var msg = "Ihr Webbrowser ist veraltet";
		var val = Get_Cookie("ie6warning");
		if(val == null) {
			jQuery("div.container").each(function() {
				jQuery(this).append("<div id=\"ie6widget\" class=\"ie6widget\">IE 6 Warning</div>");
				jQuery("#ie6widget").html('<h1>Browsersupport</h1><p>Sie benutzen zur Zeit einen nicht unterst&uuml;tzten Browser.<br>Um Ihnen ein bestm&ouml;gliches Erlebnis der Mobimo zu garantieren bitten wir Sie, auf einen der untenstehenden Browser gratis zu aktualisieren:</p><ul><li><a href="http://www.firefox.com/">Firefox ab Version 3.5 (Mac &amp; PC)</a></li><li><a href="http://www.microsoft.com/switzerland/windows/de/internetexplorer/default.aspx">Internet Explorer ab Version 8 (PC)</a></li><li><a href="http://www.apple.com/chde/safari/">Safari ab Version 5 (Mac &amp; PC)</a></li><li><a href="http://www.google.com/chrome/">Google Chrome ab Version 5 (Mac &amp; PC)</a></li></ul><p>Bitte beachten Sie die <a href="de/impressum/technik">technischen Hinweise</a> zur Nutzung von www.mobimo.ch.</p><p>&nbsp;</p><p><a href="#" onclick="ie6closewarning();">&raquo; Diese Meldung schliessen und beim aktuellen Seitenbesuch nicht mehr anzeigen</a></p>');
							
			});

		}
	}

}

function ie6closewarning()
{
	jQuery("#ie6widget").hide();
	Set_Cookie( "ie6warning", true, null , null , null );	
}


function ip_geo_show(n)
{
	var i = document.getElementById('ischweiz');	
	i.src = '/jwa/vfs/web/mobimo.ch/media/immobilien/anlageobjekte/karte/CH_'+n+'.jpg';
}
function ip_geo_hide()
{
	var i = document.getElementById('ischweiz');	
	i.src = '/jwa/vfs/web/mobimo.ch/media/immobilien/anlageobjekte/karte/CH.jpg';
}

var debugStart = null;
var debugLast = null;

function debugMessage(msg)
{
	//disable
	return true;


	if ( debugStart == null )
	{
		debugStart = new Date();
		debugLast = debugStart;
	}
	var now = new Date();

	try {
		console.log((now-debugStart)+" : "+(now-debugLast)+" : "+msg);	
	} catch (e) {};
	debugLast = now;
}




function msieversion()
   {
      var ua = window.navigator.userAgent
      var msie = ua.indexOf ( "MSIE " )

      if ( msie > 0 )      // If Internet Explorer, return version number
         return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
      else                 // If another browser, return 0
         return 0

   }


var person_id_list = Array();

function irhtml_load(url)
{
	window.loadingJs=true;

	if ( msieversion() == 6 )
	{
	   window.location = 'http://ir.mobimo.ch/websites/mobimo2011/'+url;
	}


	
	
	jQuery("#includedContent").load("/irhtml/"+url+" #content_inner",function() {
	 
		jQuery(".person").each(function() {

			var id = (this.id+"").split("_")[1];

			var p = document.getElementById("person_"+id);
			var img = document.getElementById("person_image_"+id);
			var img_container = document.getElementById("person_image_container_"+id);
			var le = document.getElementById("person_list_entry_"+id);
			var url = document.getElementById("NC_IMAGE_"+id).innerHTML;
			var title = document.getElementById("NC_TITLE_"+id).innerHTML;
			var fkt = document.getElementById("NC_FUNCTION_"+id).innerHTML;
			var descr = document.getElementById("NC_DESCRIPTION_"+id).innerHTML;
			var pl = document.getElementById("person_list");
			var il = document.getElementById("image_list");
			img.src = ("http://ir.mobimo.ch/mobimo2011/img/"+url);
			img.alt = ("Bild von "+title);
		
			var print_info = '<table><tr><td class="title">'+title+'</td><td class="title">'+fkt+'</td></tr><tr><td class="img"><img src="'+img.src+'" alt="'+img.alt+'" class="print_info_image" /></td><td class="text">'+descr+'</td></tr></table>';

			le.innerHTML = '<span class="name">'+title+'</span><span class="function">'+fkt+'</span><div class="print_info">'+print_info+'</div>';
			pl.appendChild(le);
			il.appendChild(img_container);
			person_id_list[person_id_list.length] = id;


		});

		var valuableCode = "";
		jQuery("#includedContent").find("#content_inner").each(function() {
		valuableCode = this.innerHTML;
		});

		valuableCode = valuableCode.replace(/\"\/mobimo2011\/img/g,'"http://ir.mobimo.ch/mobimo2011/img');

		document.getElementById("includedContent").innerHTML = valuableCode;
		window.loadingJs=false;

	}); 




}

/************ NEWS ALT ***************************/
function news_alt_toggle(nhead)
{
	var nc = nhead.parentNode;

	jQuery(nc.parentNode).find('.news_alt').each( function(cnt) {
		var doToggle = true;
		var nch = jQuery(this).find('.news_head').each( function(cnt2) {
			if ( this.innerHTML == nhead.innerHTML )
				doToggle = false;
		});
		if ( doToggle )
			jQuery(this).toggle();
	});

	jQuery(nhead.parentNode).find('.news_article').each( function(cnt) {
		jQuery(this).toggle();
	});
	


}


