/** 
*	gesammelte funktionen aus
*	site/index.php
*	share/header_v2.php
*/

function resize_iframe() {
	var abstandoben = 240;
	var myHeight = 0;
	var iframeheight = 500;
	var BO = new detectBrowser();
	if (BO.ie == false) {
		//window.alert('kein IE');
		myHeight = window.innerHeight;
	} else {
		//window.alert('IE');
		myHeight = document.body.clientHeight;
	}
	iframeheight = myHeight - abstandoben;
	//alert(iframeheight);
	$('link_object_iframe').writeAttribute("height", iframeheight);
	return true;
}

function detectBrowser() { 
    //window.alert('detect browser');
    var BO = new Object(); 
    BO["ie"]        = false /*@cc_on || true @*/; 
    //BO["ie4"]       = BO["ie"] && (document.getElementById == null); 
    //BO["ie5"]       = BO["ie"] && (document.namespaces == null) && (!BO["ie4"]); 
    BO["ie6"]       = BO["ie"] && (document.implementation != null) && (document.implementation.hasFeature != null); 
    //BO["ie55"]      = BO["ie"] && (document.namespaces != null) && (!BO["ie6"]);
    BO["ie7"]       = (BO["ie"] && document.implementation != null && document.compatMode != null && window.XMLHttpRequest != null);
    //BO["ns4"]       = !BO["ie"] &&  (document.layers != null) &&  (window.confirm != null) && (document.createElement == null); 
    //BO["opera"]     = (self.opera != null); 
    //BO["gecko"]     = (document.getBoxObjectFor != null); 
    //BO["khtml"]     = (navigator.vendor == "KDE"); 
    //BO["konq"]      = ((navigator.vendor == 'KDE') || (document.childNodes) && (!document.all) && (!navigator.taintEnabled)); 
    //BO["safari"]    = (document.childNodes) && (!document.all) && (!navigator.taintEnabled) && (!navigator.accentColorName); 
    //BO["safari1.2"] = (parseInt(0).toFixed == null) && (BO["safari"] && (window.XMLHttpRequest != null)); 
    //BO["safari2.0"] = (parseInt(0).toFixed != null) && BO["safari"] && !BO["safari1.2"]; 
    //BO["safari1.1"] = BO["safari"] && !BO["safari1.2"] && !BO["safari2.0"]; 
    return BO; 
}

function js_object(which) {
	fenster_js_object = open(which,"js_object","width=500,height=550,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_object.focus();
}               

function js_object_form(which) {
	fenster_js_object_form = open(which,"js_object_form","width=650,height=550,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_object_form.focus();
}               

function js_object_wide(which) {
	fenster_js_object_wide = open(which,"js_object_wide","width=800,height=700,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_object_wide.focus();
}               

function js_dokument(which) {
	fenster_js_dokument = open(which,"js_dokument","width=450,height=200,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_dokument.focus();
}               

function js_person(which) {
	fenster_js_person = open(which,"js_person","width=450,height=400,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_person.focus();
}               

function js_tabelle(which) {
	fenster_js_tabelle = open(which,"js_tabelle","width=600,height=400,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_tabelle.focus();
}               

function js_pictures(which) {
	fenster_js_pictures = open(which,"js_pictures","width=300,height=300,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_pictures.focus();
}               

function js_news(which) {
	fenster_js_news = open(which,"js_news","width=570,height=500,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_news.focus();
}               

function js_news_edit(which) {
	fenster_js_news_edit = open(which,"js_news_edit","width=515,height=600,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_news_edit.focus();
}               

function js_chart_zoom(which) {
	fenster_js_chart_zoom = open(which,"js_chart_zoom","width=780,height=500,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_chart_zoom.focus();
}               

function js_preview_pic(which) {
	fenster_js_preview_pic = open(which,"js_preview_pic","scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_preview_pic.focus();
}               

function js_related_item_edit(which) {
	fenster_js_related_item_edit = open(which,"js_related_item_edit","width=450,height=300,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_related_item_edit.focus();
}               

function js_page2ordner(which) {
	fenster_js_page2ordner = open(which,"js_page2ordner","width=570,height=500,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_page2ordner.focus();
}               

function js_highlight(which) {
	fenster_js_highlight = open(which,"js_visual","width=800,height=600,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_highlight.focus();
}               

function js_detail(which) {
	fenster_js_detail = open(which,"js_detail","width=550,height=620,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_detail.focus();
}               

function js_kommentare(which) {
	fenster_js_kommentare = open(which,"js_kommentare","width=450,height=350,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_kommentare.focus();
}               

function js_edit(which) {
	fenster_js_edit = open(which,"js_edit","width=500,height=500,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_edit.focus();
}               

function js_chemidex(which) {
	fenster_js_chemidex = open(which,"js_chemidex","width=1000,height=720,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_chemidex.focus();
}               

function js_calendar(which) {
	fenster_js_calendar = open(which,"js_calendar","width=250,height=250,scrollbars=no,resizable=yes,toolbar=no,status=no");
	fenster_js_calendar.focus();
}               

function js_textarea(which) {
	fenster_js_textarea = open(which,"js_textarea","width=520,height=420,scrollbars=no,resizable=yes,toolbar=no,status=yes");
	fenster_js_textarea.focus();
}

function js_user(which) {
	fenster_js_user = open(which,"js_user","width=520,height=600,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_user.focus();
}
function js_group(which) {
	fenster_js_group = open(which,"js_user","width=520,height=400,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_group.focus();
}
function js_editrechte(which) {
	fenster_js_editrechte = open(which,"js_editrechte","width=450,height=600,scrollbars=yes,resizable=yes,toolbar=no,status=no");
	fenster_js_editrechte.focus();
}

// [#LINK_MAIL_TOOLBAR]
function enable_link_mail_collecting() {
	set_cookie('link_mail_enable', 1, null, '/');
	window.location.reload();
} // function enable_link_mail_collecting()

function disable_link_mail_collecting() {
 	delete_cookie('link_mail_enable');
 	delete_cookie('link_mail_docs');
	window.location.reload();
} // function enable_link_mail_collecting()

function cleanArray(actual){
  var newArray = new Array();
  for(var i = 0; i<actual.length; i++){
      if (actual[i]){
        newArray.push(actual[i]);
    }
  }
  return newArray;
}

function link_mail_store_docs() {
	var cookie = get_cookie('link_mail_docs');
	var docs = [];
	docs = read_link_mail_form();
	var lang = get_lang_cookie();
	if (cookie == null) {
		set_cookie('link_mail_docs', docs, null, '/');
	} else {
		var cookie_array = cookie.split(',');
		var bib_projekt = J('#ref_origin').val()
		
		J.each(cookie_array, function(index, value) {
			var cookie_bib_projekt = cookie_array[index].split('-')[0];
			if (cookie_bib_projekt == bib_projekt) {
				cookie_array[index] = undefined;
			}
		});
		
		cookie_array = cleanArray(cookie_array);
		cookie_array.push(docs);
		set_cookie('link_mail_docs', cookie_array.toString(), null, '/');
	}
	switch (lang) {
		case 'd':
			alert('Die Dokumenten-Auswahl wurde zwischengespeichert');
		break;
		case 'e':
			alert('The choice of the documents was temporary saved');
		break;
		case 'f':
			alert('Les documents s&eacute;lectionn&eacute;s ont &eacute;t&eacute; mis en sauvegarde interm&eacute;diaire');
		break;
		default:
			alert('Die Dokumenten-Auswahl wurde zwischengespeichert');
	}
	
	window.location.reload();
} // function link_mail_store_docs()

function read_link_mail_form() {
	var docs = new Array();
	J("input:checkbox[name=link_mail_document]:checked").each(function() {
		docs.push(J(this).val());
	});
	// console.log(docs);
	return docs;
} // function read_link_mail_form()

function delete_cookie(name) {
	if (get_cookie(name)) {
		document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/;';
	}
} // function delete_cookie()

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 set_cookie()

function get_cookie(name) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
} // function set_cookie()

function open_document_mail() {
	var cookie = get_cookie('link_mail_docs');
	if (cookie) {
		window.open('/link_mail_content.php','Linkmail','width=800,height=600');
	} else {
		var lang = get_lang_cookie();
		switch (lang) {
			case 'd':
				alert('Sie haben keine Dokumente zum Versand gespeichert.');
			break;
			case 'e':
				alert('No documents saved for sending');
			break;
			case 'f':
				alert('Pas de documents enregistr&eacute; pour envoyer');
			break;
			default:
				alert('Sie haben keine Dokumente zum Versand gespeichert.');
		}
	}
} // function open_document_mail()

function get_lang_cookie() {
	var result = 'd';
	var lang = get_cookie('visit_lang');
	if (lang != '') {
		result = lang;
	}
	return result;
} // function get_lang_cookie()

function toggle_help() {
	var display = J('#anleitung').css('display');
	var lang = get_lang_cookie();
	if (display == 'block') {
		J('#anleitung').css('display', 'none');
		switch (lang) {
			case 'd':
				J('#helplink').attr('title', 'Hilfe anzeigen');
				J('#helplink img').attr('alt', 'Hilfe anzeigen');
			break;
			case 'e':
				J('#helplink').attr('title', 'Show Help');
				J('#helplink img').attr('alt', 'Show Help');
			break;
			case 'f':
				J('#helplink').attr('title', 'Hilfe anzeigen');
				J('#helplink img').attr('alt', 'Hilfe anzeigen');
			break;
			default:
				J('#helplink').attr('title', 'Hilfe anzeigen');
				J('#helplink img').attr('alt', 'Hilfe anzeigen');
		}
	} else {
		J('#anleitung').css('display', 'block');
		switch (lang) {
			case 'd':
				J('#helplink').attr('title', 'Hilfe ausblenden');
				J('#helplink img').attr('alt', 'Hilfe ausblenden');
			break;
			case 'e':
				J('#helplink').attr('title', 'Hide Help');
				J('#helplink img').attr('alt', 'Hide Help');
			break;
			case 'f':
				J('#helplink').attr('title', 'Hilfe ausblenden');
				J('#helplink').attr('title', 'Hilfe ausblenden');
			break;
			default:
				J('#helplink').attr('title', 'Hilfe ausblenden');
				J('#helplink').attr('title', 'Hilfe ausblenden');
		}
	}
} // function toggle_help()
