/*********************************************************
Set of JavaScript functions used in GlobalWeb
**********************************************************/

/***********************************************************
doquicklink()
Jump to Quicklink
************************************************************/

function do_quicklink(){
	tmp_selection = document.quicklink.sel_quicklink.value;
	tmp_host = 'http://'+window.location.host;
	tmp_path = window.location.pathname;
	tmp_pos = tmp_path.indexOf(".nsf")+4;
	tmp_path = tmp_path.slice(0,tmp_pos);
	tmp_cgi = window.location.search;
	tmp_pos = tmp_cgi.indexOf("&Man")+5;
	tmp_mandant = tmp_cgi.slice(tmp_pos,tmp_pos+3);
	tmp_url = tmp_host+tmp_path+'/TreatAsHTMLSections/'+tmp_selection+'?open&'+tmp_selection;
	location = tmp_url;
}

/***********************************************************
leaveDoc()
Security-chek when user leaves a edited document
************************************************************/

function leaveDoc(){
	msg = "WARNUNG\n\nDieses Dokument wurde noch nicht gespeichert.\nAlle von Ihnen vorgenommenen Änderungen werden verloren gehen!\n";
	//inbuilt get-out: hold control key to bypass message;
	if (isDocBeingSubmitted == false && event.ctrlKey == false) event.returnValue = msg;
}


/***********************************************************
openresult()
open serchresult
************************************************************/
function openresult (tmp_url$)  {
	tmp_host$ = 'http://'+window.location.host;
	tmp_path$ = window.location.pathname;
	tmp_path$ = tmp_path$.replace(/view_SearchPublished/,"TreatAsHTML");

	tmp_cgi$ = window.location.search;
	tmp_pos = tmp_cgi$.indexOf("&Man")+5;
	//tmp_mandant$ = tmp_cgi$.slice(tmp_pos,tmp_pos+3);
	tmp_url$ = tmp_url$.replace(/&CurrentMan&/,"&Man="+tmp_mandant$+"&");

	location = tmp_host$+tmp_path$+tmp_url$;
}


/***********************************************************
dosearch()
start search from searchbox
************************************************************/
function dosearch ()  {
	query$ = document.searchform.tmp_query.value;
	if (query$ == '') 
		return false;
	else {
		while(query$.search(/  /) > 0)
			query$ = query$.replace(/  /," ");	
		while(query$.search(/ /) > 0)
			query$ = query$.replace(/ /,"_");
		while(query$.search(/_/) > 0)
			query$ = query$.replace(/_/," OR ");
		tmp_query=query$;
		tmp_host = 'http://'+window.location.host;
		tmp_path = window.location.pathname;
		tmp_pos = tmp_path.indexOf(".nsf")+4;
		tmp_path = tmp_path.slice(0,tmp_pos);
		tmp_cgi = window.location.search;
		//tmp_pos = tmp_cgi.indexOf("&Man");
		//tmp_cgi = tmp_cgi.slice(tmp_pos);
		//tmp_pos = tmp_cgi.indexOf("&Man")+5;
		//tmp_mandant = tmp_cgi.slice(tmp_pos,tmp_pos+3);
		tmp_pos = tmp_cgi.indexOf("&Lang");
		tmp_cgi = tmp_cgi.slice(tmp_pos);
		tmp_pos = tmp_cgi.indexOf("&Lang")+6;
		tmp_language = tmp_cgi.slice(tmp_pos,tmp_pos+2);
		query$ = '([Title]=('+query$+')+OR+[Content]=('+query$+')+OR+[ContentNoApplet]=('+query$+'))+AND+([ContentLanguage]=('+tmp_language+'))';
		location = tmp_host+tmp_path+'/view_SearchPublished/?SearchView&Query='+query$+'&start=1&count=10'+tmp_cgi;
	}

}


/***********************************************************
dosearch_full()
start search from searchform
************************************************************/
function dosearch_full ()  {
	option$ = '';
	query$ = '';
	//free$ = document.forms[0].Search_Query.value;
	//for(i=0;i<document.forms[0].Search_Query_Keywords.length;++i)
	//	if(document.forms[0].Search_Query_Keywords.options[i].selected == true)
	//	   keyword$ = document.forms[0].Search_Query_Keywords.options[i].text;
	//for(i=0;i<2;++i)
	//	if(document.forms[0].Search_Operator[i].checked == true)
	//	   operator$ = "+"+document.forms[0].Search_Operator[i].value+"+";

	free$ = document.suchen.Search_Query.value;
	for(i=0;i<document.suchen.Search_Query_Keywords.length;++i)
		if(document.suchen.Search_Query_Keywords.options[i].selected == true)
		   keyword$ = document.suchen.Search_Query_Keywords.options[i].text;
	for(i=0;i<2;++i)
		if(document.suchen.Search_Operator[i].checked == true)
		   operator$ = "+"+document.suchen.Search_Operator[i].value+"+";

	//if(document.forms[0].Search_Options[0].checked == true)
	//   option$ = "+&SearchFuzzy=true";
	//if(document.forms[0].Search_Options[1].checked == true)
	//   option$ = option$+"+&SearchWV=true";

	if(free$ != '' && keyword$ != '')
		query$ = free$+" "+keyword$;
	else {
		if(free$ != '')
			query$ = free$;
		if(keyword$ != '')
			query$ = keyword$;
	}
	if(query$ != '') {
		while(query$.search(/  /) > 0)
			query$ = query$.replace(/  /," ");	
		while(query$.search(/ /) > 0)
			query$ = query$.replace(/ /,"_");
		while(query$.search(/_/) > 0)
			query$ = query$.replace(/_/,operator$);
		if (query$ == '') 
			alert('Bitte geben Sie einen Suchbegriff ein.');
		else {
			tmp_host = 'http://'+window.location.host;
			tmp_path = window.location.pathname;
			tmp_pos = tmp_path.indexOf(".nsf")+4;
			tmp_path = tmp_path.slice(0,tmp_pos);
			tmp_cgi = window.location.search;
			//tmp_pos = tmp_cgi.indexOf("&Man");
			//tmp_cgi = tmp_cgi.slice(tmp_pos);
			//tmp_pos = tmp_cgi.indexOf("&Man")+5;
			//tmp_mandant = tmp_cgi.slice(tmp_pos,tmp_pos+3);
			tmp_pos = tmp_cgi.indexOf("&Lang");
			tmp_cgi = tmp_cgi.slice(tmp_pos);
			tmp_pos = tmp_cgi.indexOf("&Lang")+6;
			tmp_language = tmp_cgi.slice(tmp_pos,tmp_pos+2);
			tmp_cgi = tmp_cgi.slice(tmp_pos);
			query$ = '([Title]=('+query$+')+OR+[Content]=('+query$+')+OR+[ContentNoApplet]=('+query$+')+OR+[Keywords]=('+query$+'+))+AND+([ContentLanguage]=('+tmp_language+'))';

			location = tmp_host+tmp_path+'/view_SearchPublished/?SearchView&Query='+query$+'&start=1&count=10'+option$+'&Lang='+tmp_cgi;
		}
	}

}


/***********************************************************
printout()
open printer-optimized articlelayout in popup
************************************************************/
function printout (tmp_url) {
	var SizeX = '790';
	var SizeY = '420';
	var PosX = screen.width/2-SizeX/2;
	var PosY = screen.height/2-SizeY/2;
	window.open(tmp_url,'','screenx='+PosX+',screeny='+PosY+',toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,copyhistory=0,width='+SizeX+',height='+SizeY+'');
}


/***********************************************************
sendmail()
open send-dialogue in popup
************************************************************/
function sendmail (tmp_url){
	var SizeX = '790';
	var SizeY = '420';
	var PosX = screen.width/2-SizeX/2;
	var PosY = screen.height/2-SizeY/2;
	window.open(tmp_url,'','screenx='+PosX+',screeny='+PosY+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width='+SizeX+',height='+SizeY+'');
}


/***********************************************************
mysitelogin()
open login-dialogue fo mysite in popup
************************************************************/
function mysitelogin (tmp_url){
	var SizeX = '400';
	var SizeY = '520';
	var PosX = screen.width/2-SizeX/2;
	var PosY = screen.height/2-SizeY/2;
	window.open(tmp_url,'','screenx='+PosX+',screeny='+PosY+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width='+SizeX+',height='+SizeY+'');
}


/***********************************************************
apply_styles()
apply styles to tabbed tables

2 tabs: apply_styles(2,3,3,6,0)
3 tabs: apply_styles(2,4,3,8,1)
4 tabs: apply_styles(2,5,3,10,2)
5 tabs: apply_styles(2,6,3,12,3)
6 tabs: apply_styles(2,7,3,14,4)
7 tabs: apply_styles(2,8,3,16,5)
************************************************************/
function apply_styles(table_start, table_end, cell_start, cell_end, text_end) {

	mac = (navigator.appVersion.indexOf("Mac") != -1);
	dom = (document.getElementById) ? true : false;

	if (mac == false && dom == true){
		// Table
		for (i=table_start; i<=table_end; i++) {
			document.getElementsByTagName("TABLE")[i].className = "tab_table";
		}
		// Table-Cells
		for (i=cell_start; i<=cell_end; i+=2) {
			document.getElementsByTagName("TD")[i].className = "tab_cell";
		}
		// Tab-Text
		for (i=0; i<=text_end; i++) {
			if (document.getElementsByName("5.1.")[0] != null) {
				document.getElementsByName("5.1.")[i].className = "tab_text";
			}
			if (document.getElementsByName("6.1.")[0] != null) {
				document.getElementsByName("6.1.")[i].className = "tab_text";
			}
		}
		// active Tab-Text
		document.getElementsByTagName("B")[1].className = "tab_text_active";
	}
}

