/*Tooltip*/
var a=0;          
function move(e)                /*Event-Handler zur Positionsüberwachung Navi*/
{
	b=e.pageX;c=e.pageY;
}

function separate_thousands(zahl) 
{
   var i;
   var j=0;
   var ergebnis="";

   i=zahl.length-1;
   //alert("i="+i);
   while (i >= 0) {
      ergebnis=zahl.substr(i,1)+ergebnis;
      j++;
      if (j==3) {
         ergebnis="."+ergebnis;
         j=0;
      }
      i--;
   }   
   if (ergebnis.substr(0,1) == ".")
   {      
      ergebnis = ergebnis.substr(1,ergebnis.length-1);    
   }   
   return ergebnis;
}


function tips(text,wo)
{
if(navigator.appVersion.substring(0,1) > "3")
 {
 var ctr=null;
 ctr=document.all.tip;
 if (a!=1 && window.name!="no" && ctr!=null)
   {
    if (document.all){document.all.tip.innerHTML=text;
    if( navigator.appVersion.substring(22,23)==5) document.all.tip.style.width="auto";
    linkss=window.event.clientX+document.body.scrollLeft;
    obens=window.event.clientY+document.body.scrollTop;
    //alert(obens)
    //wenn zu weit links
    if (linkss < 150)
    { 
    linkss=150
    }
    //wenn zu weit rechts
    if (linkss > 920)
    {
    linkss=920
    }
    //wenn zu weit oben
    if (obens < 130)
    {
    obens=130
    }
    if (window.screen.width > 1024)
    {
     obens=obens-50
	 linkss=linkss-50
    }
    document.all.tip.style.left=linkss-document.all.tip.offsetWidth/2;
    document.all.tip.style.top=obens-document.all.tip.offsetHeight-15;
   }                  
 else                                             /*Navi*/
 { /*Postionierung der Tips*/
   document.tip.document.open();                   /*Textladen in die Tips*/
   document.tip.bgColor="fffff0";
   document.tip.document.write("<div class=\"tip1\">"+text+"</div>");
   document.tip.document.close();
   document.tip.left=b-document.tip.clip.right/2;
   document.tip.top=c-document.tip.clip.bottom-15;
 }
 a=1;zeigen();}}}                 /*setzen a (im Bereich), Funktion zeigen aufrufen*/
                                  /*setzen a (im Bereich), Funktion zeigen aufrufen*/
 function zeigen()                /*Anzeige Tip*/
 {
	if (document.all) document.all.tip.style.visibility="visible";  /*IE*/
	else document.tip.visibility="visible";                        /*Navi*/
 }
 function ende()					/*Tooltip ausblenden*/
 {
 var ctr=null;
 ctr=document.all.tip;
	a=0;                                                               /*setzen a (nicht im Bereich)*/
 if (ctr!=null)
	{
	if(navigator.appVersion.substring(0,1) > "3")
	{if (document.all) {document.all.tip.style.visibility="hidden";}   /*IE*/
	else {document.tip.visibility="hidden";}                           /*Navi*/
	}
	}
 }
 function leer()       /*Leerfunktion für fehlende Links*/
 { }
/*Ende Tooltipscript*/

//ToolTip


function fctCenter()
{
	var c = document.getElementById("Standardseite");
	if (c!=null)
	{
		c.style.left= (window.screen.width - 1024) / 2;
		c.style.top= (window.screen.height - 842) / 2 + 35;
		c.style.visibility="visible";
	}
}


function SetFocus(feld) 
	{var ctr=null;ctr = feld;
	if (ctr != null){ctr.focus();}
	}


var lastRow = 0;
var BitteWarten = null;
var iScreenPos = 0;
var iMarkedRows = 0;
var iPageNum = 1;

function PopUpvoid() {}
var popup = '';
function showpopup(message) 
	{
	msgWindow=openWinOhneTitel('','Tip', 'left=' + (screen.width/2-125).toString() + ', top=' + (screen.height/2-40).toString() + ',width=250,height=80,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	msgWindow.document.writeln('<BODY>' + message + '</BODY>');
	msgWindow.document.title = "      -- Info --      ";
	msgWindow.document.close();
	}
function closepopup() 
	{
    if (!msgWindow.closed)
    //wartet einen Moment bis zur Schließung
	//setTimeout('msgWindow.close()',5000);
	//schließt sofort
	msgWindow.close(); 
	}


function AchtungSystemDaten(sText)
	{
	alert (sText);
	}
			
function ShowStep()
{
	if (BitteWarten != null) {BitteWarten.writeln('Bitte warten ...');}
}

function ShowBitteWarten2(sText) {
    var sHtml = '<html><HEAD>' +
		'<script language="javascript" type="text/javascript">var iBitteWartenSekunden = 0;<\/script>' +
		'<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"><\/HEAD><body>' +
		'<form method="post">' +
		'<table width="100%"><tr><td align="center">' +
		'<input style="height:24px;width:80px;font-family: Arial, Helvetica, sans-serif;font-size: 9pt;font-weight: bold;border:0;" type=text value="' + sText + '">' +
		'<input style="height:24px;width:40px;font-family: Arial, Helvetica, sans-serif;font-size: 9pt;font-weight: bold;border:0;" id="txtBitteWartenSekunden" type=text value="">' +
		'<\/td><\/tr><\/table>' +
		'<\/form><\/body><\/html>'
	
	BitteWarten = window.open('', 'BitteWarten','<scrollbars=no, toolbar=no, menubar=no, location=no, width=200, height=30, left=' + (screen.width/2-100).toString() + ' , top=' + (screen.height/2-15).toString() + ', resizable=yes');
	BitteWarten.document.writeln(sHtml);
	BitteWarten.document.title = "BASF - " + sText;
	BitteWarten.setInterval('iBitteWartenSekunden++;window.document.getElementById("txtBitteWartenSekunden").value = iBitteWartenSekunden;', 1000);
	BitteWarten.focus();
}

function ShowBitteWarten() {
	// Fenster in einem anderen Ferster oeffnen, damit Referenz bestehen bleibt.
	try {
		win = window.top;
		if (win == null) return;
		win.ShowBitteWarten2(sBitteWarten);
	}
	catch (e) {
		return;
	}
	finally { ; }
}

function HideBitteWarten() {
	// Referenz aus anderen Ferster holen.
	try {
		win = window.top;
		if (win == null) return;
		if (win.BitteWarten != null) {win.BitteWarten.close();}
	}
	catch (e) {
		return;
	}
	finally { ; }
}

function InDbl(sText, gsDecimalSeparator, sDecimalPoint)
{  
      var d
    //d = parseFloat(sText.Replace(sDecimalPoint , gsDecimalSeparator));
    
    d = parseFloat(ReplaceChar(sText,sDecimalPoint , gsDecimalSeparator));
      return d;
}

function OutDbl(sText, gsDecimalSeparator, sDecimalPoint)
{  
      var d
      d = ReplaceChar(sText, gsDecimalSeparator, sDecimalPoint);
      return d;
}

function RememberPage(sName, iPage)
{
	var ctr=document.getElementById(sName + "_Page");;
	if (ctr == null) return;
	ctr.value = iPage;
}

function ShowPage(sName, iPage) 
{
	var tab="";
	var ctr=null;
	var i=1;
	while (true)
	{
		tab = sName + 'P' + i;
		ctr = document.getElementById(tab);
		if (ctr == null) break;
		ctr.style.visibility = 'hidden';
		i++;
	}
	
	tab = sName + 'P' + iPage;
	ctr = document.getElementById(tab);
	if (ctr != null) {
		ctr.style.visibility = 'visible';
		RememberPage(sName, iPage)
	}
	else
	{	
		iPage--;
		if (iPage < 1) iPage=1;
		ShowPage(sName,iPage);
	}
}

function RowColor(sZeile, color)
{
	var col = 1;
	var ctr=null;
	
	while (true)
	{
		ctr = document.getElementById(sZeile + 'C' + col++);
		if (ctr == null) return;
		ctr.style.backgroundColor=color;
	}
}

function MarkRow(sZeile)
{
	var ctr=null;
	var btnDelete = null;
	
	ctr = document.getElementById("chk" + sZeile);
	if (ctr == null) {
		ctr = document.getElementById("rbt" + sZeile);		
		if (ctr == null) return;
		RowColor(lastRow, "")
		RowColor(sZeile, "#CCFF00")
		lastRow = sZeile
	}	
	else {
		btnDelete = document.getElementById("btnDelete");
		if (ctr.checked) {
			iMarkedRows++;
			RowColor(sZeile, "LightSalmon");
			if (btnDelete != null) {btnDelete.disabled = false};
		} else {
			iMarkedRows--;
			RowColor(sZeile, "");
			if ((btnDelete != null) && (iMarkedRows == 0)) {btnDelete.disabled = true};
		}
	}		
}

function ShowTableLastPage(sName) 
{
	var tab="";
	var ctr=null;
	var i=1;
	while (true)
	{
		tab = sName + 'P' + i;
		ctr = document.getElementById(tab);
		if (ctr == null) break;
		ctr.style.visibility = 'hidden';
		i++;
	}
	i--;
	tab = sName + 'P' + i;
	ctr = document.getElementById(tab);
	ctr.style.visibility = 'visible';
	RememberPage(sName, i)
}

function ShowTableFirstPage(sName) 
{
	var tab="";
	var ctr=null;
	var i=2;
	while (true)
	{
		tab = sName + 'P' + i;
		ctr = document.getElementById(tab);
		if (ctr == null) break;
		ctr.style.visibility = 'hidden';
		i++;
	}
	tab = sName + 'P1';
	ctr = document.getElementById(tab);
	ctr.style.visibility = 'visible';
	RememberPage(sName, 1)
}

function ShowTablePreviousPage(sName) 
{
	var tab="";
	var ctr=null;
	var i=2;
	while (true)
	{
		tab = sName + 'P' + i;
		ctr = document.getElementById(tab);
		if (ctr == null) return;
		if (ctr.style.visibility != 'hidden')
		{
			ctr.style.visibility = 'hidden';
			i--;
			tab = sName + 'P' + i;
			ctr = document.getElementById(tab);
			ctr.style.visibility = 'visible';
			RememberPage(sName, i)
			return;
		}
		i++;
	}
}

function ShowTableNextPage(sName) 
{
	var tab="";
	var ctr=null;
	var i=1;
	while (true)
	{
		tab = sName + 'P' + i;
		ctr = document.getElementById(tab);
		if (ctr == null) return;
		if (ctr.style.visibility != 'hidden')
		{
			ctr.style.visibility = 'hidden';
			index = i++;
			tab = sName + 'P' + i;
			ctr = document.getElementById(tab);
			if (ctr == null) return;
			ctr.style.visibility = 'visible';
			RememberPage(sName, i)
			index = i++;
			tab = sName + 'P' + i;
			ctr = document.getElementById(tab);
		}
		i++;
	}
}

function CheckNummer(sValue, nMin, nMax)
{
	if (sValue == '') return true;
	sValue = InputDouble(sValue);
	if (isNaN(sValue)) return false;
	if (sValue < nMin) return false;
	if (sValue >= nMax) return false;
	return true;
}

function ReplaceChar(sText, cFind, cReplace)
{
	var i
	var sRet = ""
	
    for (i = 0; i < sText.length; i++)
    {    
        if (sText.charAt(i) == cFind)
        {  
			sRet += cReplace;
        }
        else
        {
			sRet += sText.charAt(i);
        }
    }
    return sRet;
}

function InputDouble(sText)
{  
	sRet = ReplaceChar(sText, GroupSeparator, '');
	sRet = parseFloat(ReplaceChar(sRet, DecimalSeparator, '.'));
    return sRet;
}

function lg(x)
{
	return Math.log(x) / log10;
}

function exp10(x)
{
	return Math.exp(x * log10);
}

function OutputDouble(dWert, nNKS)
{
	var sVKS
	var sNKS
	var s
	var f
	var i
	
	f = exp10(nNKS);
	s = (Math.round(dWert * f)).toString();
	sVKS = s.substring(0, s.length - nNKS);
	if (sVKS == "") sVKS = "0";
	sNKS = s.substring(s.length - nNKS)
    for (i = sNKS.length; i < nNKS; i++) {
		sNKS += "0";
	}
	s = sVKS + "," + sNKS;
	return s;	
}

function fctSelfCloseAndReadOpenerAgain()
{
	//alert(self.opener.location.href);
	var x = self.opener.location.href;	
	if (x.indexOf("&kopiert=true") > 0) {
		x = x.replace("&kopiert=true","");
		//alert(x);
	}	
	self.opener.location.href = x;
	self.close();
}

function fctOpenerSubmitAndSelfClose()
{
	// Opener wird aktualisiert ohne Werte in Cbo's etc. zu verlieren
	self.opener.document.Form1.submit();
	self.close();
}

function WandleKommaInPunkt (s)	{
	//Im String Komma durch ein Punkt ersetzen
	var i;
	var komma = ",";
	var punkt = ".";
	var s_end = "";

	for (i = 0; i < s.length; i++)
	{    
		if (s.charAt(i) == komma)
		{  
			s_end = s_end + punkt;
		}
		else
		{
			s_end = s_end + s.charAt(i);
		}
	}
	return s_end;
}	

function WandlePunktInKomma (s) {
	//Im String Punkt durch ein Komma ersetzen
	var i;
	var komma = ",";
	var punkt = ".";
	var s_end = "";

	for (i = 0; i < s.length; i++)
	{    
		if (s.charAt(i) == punkt)
		{  
			s_end = s_end + komma;
		}
		else
		{
			s_end = s_end + s.charAt(i);
		}
	}
	return s_end;
}	

function fct_Sind_Kommas_drin(s) {				
	//pruefen, ob Kommas im String sind
	var i;
	var komma = ",";
		
	for (i=0;i<s.length;i++)
	{
		if (s.charAt(i) == komma)
		{
			return true;
		}
	}
	return false;		
}

////////////////////////////////////// F E N S T E R ////////////////////////////////////////////////////////

function gf_ShowWindow(sUrl) {
    window.location.href = sUrl;
}

function ShowFixedWindow(sUrl, sName, iWidth, iHeight)
{	
	var sFeatures = 'scrollbars=no, toolbar=no, menubar=no, location=no, resizable=no' +
		', width=' + iWidth +
		', height=' + iHeight +
		', left=' + ((screen.width-iWidth)/2).toString() + 
		', top=' + ((screen.height-iHeight)/2).toString();
	//alert(sFeatures);
	var win=window.open(sUrl, sName, sFeatures);
	win.focus();
	return win;
}

function ShowFixedWindow2(sUrl, sName, iWidth, iHeight)
{					
	Win=window.open(sUrl, sName, 'scrollbars=yes, resizable=yes, toolbar=no, menubar=no, location=no, width=' + iWidth +
		', height=' + iHeight +
		', left=' + ((screen.width-iWidth)/2).toString() + 
		', top=' + ((screen.height-iHeight)/2).toString() );
	return Win;
}

function ShowStandardWindow(sUrl, sName)
{					
	Win=window.open(sUrl, sName,'scrollbars=yes, toolbar=no, menubar=no, location=no, width=1014, height=766, left=' + (screen.width/2-507).toString() + ', top=' + (screen.height/2-369).toString() + ', resizable=yes');	
	return Win;
}

function gp_MaximizeWindow() {
    try {
        window.moveTo(0,0);
        window.resizeTo(screen.width, screen.height);        
    }
	catch(e){
	;}	
}

function gp_CenterStandardWindow() {
    try {
	    var nTop = (screen.width - 1024)/2;
	    var nLeft = (screen.height - 768)/2;
	    window.resizeTo(1024,768);
	    
	    if ((nTop > 0) && (nLeft > 0)) {
	        window.moveTo(nTop, nLeft);
	    }
	    else {
	        window.moveTo(0, 0);
	    }      
    }
	catch(e){
	;}
}

//Fenster ohne Titel    
function openWinOhneTitel(windowURL, windowName, windowFeatures ) 
{
	return  window.open( windowURL, windowName, windowFeatures ) ;
}

//Stammdatenfenster öffnen
//s_STI_Filename = name of sti-file, but without ".sti". E.g. "T_CONT_UNCLEAR"
//arr_NAVL = 2-dimensional array of name and values: arr_NAVL[i][0] = name / arr_NAVL[i][1] = value. These will be proceeded to the sti-file interpretation
//n_PageLocationLevel = number of the file hierarchie level where the calling aspx-file is positioned. Can be omitted, if it is the first sublevel.
function fwin_ShowRefdataWindow(s_STI_FileName, arr_NAVL, n_PageLocationLevel)
{					
    var sWinFeatures = "";
    //if only 2 arguments are given
    if (fwin_ShowRefdataWindow.arguments.length < 3) {
        n_PageLocationLevel = 1;        
    }  
    
    var sPrefix = "";
    for (i = 0; i < n_PageLocationLevel; i++)
    {
        sPrefix = "../" + sPrefix;
    }    
    
    var sQueryString = "";
    var j;
    
    for (var i = 0; i < arr_NAVL.length; i++) 
    {
        j = i + 1;
        sQueryString += "&Name" + j + "=" + arr_NAVL[i][0] + "&Value" + j + "=" + arr_NAVL[i][1];
    }
    
    sWinFeatures = 'scrollbars=no, toolbar=no, menubar=no, location=no, width=1000, height=600, left=' + (screen.width/2-507).toString() + ', top=' + (screen.height/2-369).toString() + ', resizable=yes';
	Win=window.open(sPrefix + "Refdata/MasterDataCaller.aspx?StiFile=" + s_STI_FileName + "&NoMenu=1" + sQueryString, s_STI_FileName,sWinFeatures);
	//Win.resizeTo(1024,768)
	return Win;
}

//IPR-Fenster öffnen
//s_IPR_Filename = name of ipr-file, but without ".ipr". E.g. "T_SST_IMP_SHIPDECLAR"
//arr_NAVL = 2-dimensional array of name and values: arr_NAVL[i][0] = name / arr_NAVL[i][1] = value. These will be proceeded to the ipr-file interpretation
//n_PageLocationLevel = number of the file hierarchie level where the calling aspx-file is positioned. Can be omitted, if it is the first sublevel.
//b_NewWindow decides, whether the page is opened in a new window or not
function fwin_Show_IPR_Window(s_IPR_FileName, arr_NAVL, n_PageLocationLevel, b_NewWindow)
{	

    var sQueryString = "";
    var j;
    var sPrefix = "";
    var sWinFeatures = "";
    var Win;
    
    //if only 3 arguments are given
    if (fwin_Show_IPR_Window.arguments.length < 4) {
        b_NewWindow = true;        
    } 
    				
    //if only 2 arguments are given
    if (fwin_Show_IPR_Window.arguments.length < 3) {
        n_PageLocationLevel = 1;        
    }  
    
    // jetzt geht's los
    for (i = 0; i < n_PageLocationLevel; i++)
    {
        sPrefix = "../" + sPrefix;
    }    
    
    if (b_NewWindow == true) {
        sQueryString = "&NoMenu=1";}
    else {
        sQueryString = "&NoMenu=0";
    }
    
    for (var i = 0; i < arr_NAVL.length; i++) 
    {
        j = i + 1;
        sQueryString += "&Name" + j + "=" + arr_NAVL[i][0] + "&Value" + j + "=" + arr_NAVL[i][1];
    }
    
    if (b_NewWindow == true) {
        sWinFeatures = 'scrollbars=no, toolbar=no, menubar=no, location=no, width=1000, height=600, left=' + (screen.width/2-507).toString() + ', top=' + (screen.height/2-369).toString() + ', resizable=yes';
	    Win=window.open(sPrefix + "Refdata/MasterDataCaller.aspx?IprFile=" + s_IPR_FileName  + sQueryString, s_IPR_FileName, sWinFeatures);
	    //Win.resizeTo(1024,768)
	    return Win;
	}
    else {
        window.location.href = sPrefix + "Refdata/MasterDataCaller.aspx?IprFile=" + s_IPR_FileName  + sQueryString;
        return window;
    }
}
function gfwin_Show_IPR_ExcelDownload(s_IPR_FileName, arr_NAVL, n_PageLocationLevel, s_OfficeVersion)
{	
    var sQueryString = "";
    var j;
    var sPrefix = "";
    var sWinFeatures = "";
    var Win;
    

    //if only 3 arguments are given
    if (gfwin_Show_IPR_ExcelDownload.arguments.length < 4) {
        s_OfficeVersion = '2003';        
    }
       				
    //if only 2 arguments are given
    if (gfwin_Show_IPR_ExcelDownload.arguments.length < 3) {
        n_PageLocationLevel = 1;        
    }  
    
    // jetzt geht's los
    for (i = 0; i < n_PageLocationLevel; i++)
    {
        sPrefix = "../" + sPrefix;
    }    
    
    
    for (var i = 0; i < arr_NAVL.length; i++) 
    {
        j = i + 1;
        sQueryString += "&Name" + j + "=" + arr_NAVL[i][0] + "&Value" + j + "=" + arr_NAVL[i][1];
    }
    
    sWinFeatures = 'scrollbars=no, toolbar=no, menubar=no, location=no, width=1000, height=600, left=' + (screen.width/2-507).toString() + ', top=' + (screen.height/2-369).toString() + ', resizable=yes';
    Win=window.open(sPrefix + "Refdata/MasterDataCaller.aspx?IprFile=" + s_IPR_FileName + "&Excel=" + s_OfficeVersion + sQueryString, s_IPR_FileName, sWinFeatures);
    return Win;
}

function gfwin_Show_IPR_CSV_Download(s_IPR_FileName, arr_NAVL, n_PageLocationLevel)
{	
    var sQueryString = "";
    var j;
    var sPrefix = "";
    var sWinFeatures = "";
    var Win;
    
       				
    //if only 2 arguments are given
    if (gfwin_Show_IPR_CSV_Download.arguments.length < 3) {
        n_PageLocationLevel = 1;        
    }  
    
    // jetzt geht's los
    for (i = 0; i < n_PageLocationLevel; i++)
    {
        sPrefix = "../" + sPrefix;
    }    
    
    
    for (var i = 0; i < arr_NAVL.length; i++) 
    {
        j = i + 1;
        sQueryString += "&Name" + j + "=" + arr_NAVL[i][0] + "&Value" + j + "=" + arr_NAVL[i][1];
    }
    
    sWinFeatures = 'scrollbars=no, toolbar=no, menubar=no, location=no, width=1000, height=600, left=' + (screen.width/2-507).toString() + ', top=' + (screen.height/2-369).toString() + ', resizable=yes';
    Win=window.open(sPrefix + "Refdata/MasterDataCaller.aspx?IprFile=" + s_IPR_FileName + "&CSV=1" + sQueryString, s_IPR_FileName, sWinFeatures);
    return Win;
}

// open IPR file without special name and value list:
function gp_CallIPRFile(s_IPRFile, b_NewWindow, n_PageLocationLevel)
{
    var newWin;
    var arrNAVL = new Array();
    newWin = fwin_Show_IPR_Window(s_IPRFile, arrNAVL, n_PageLocationLevel, b_NewWindow);
}
    
//Stammdatenzuordnungsfenster öffnen
//s_IBZ_Filename = name of IBZ-file, but without ".sti". E.g. "T_CONT_UNCLEAR"
//arr_NAVL = 2-dimensional array of name and values: arr_NAVL[i][0] = name / arr_NAVL[i][1] = value. These will be proceeded to the ibz-file interpretation
//n_PageLocationLevel = number of the file hierarchie level where the calling aspx-file is positioned. Can be omitted, if it is the first sublevel.
function fwin_ShowIBZWindow(s_IBZ_FileName, arr_NAVL, n_PageLocationLevel)
{					
    var sWinFeatures = "";
    //if only 2 arguments are given
    if (fwin_ShowIBZWindow.arguments.length < 3) {
        n_PageLocationLevel = 1;        
    }  
    
    var sPrefix = "";
    for (i = 0; i < n_PageLocationLevel; i++)
    {
        sPrefix = "../" + sPrefix;
    }    
    
    var sQueryString = "";
    var j;
    
    for (var i = 0; i < arr_NAVL.length; i++) 
    {
        j = i + 1;
        sQueryString += "&Name" + j + "=" + arr_NAVL[i][0] + "&Value" + j + "=" + arr_NAVL[i][1];
    }
    
    sWinFeatures = 'scrollbars=no, toolbar=no, menubar=no, location=no, width=1000, height=600, left=' + (screen.width/2-507).toString() + ', top=' + (screen.height/2-369).toString() + ', resizable=yes';
	Win=window.open(sPrefix + "Refdata/MasterDataCaller.aspx?IbzFile=" + s_IBZ_FileName + "&NoMenu=1" + sQueryString, s_IBZ_FileName,sWinFeatures);
	//Win.resizeTo(1024,768)
	return Win;
}

//get the parameters to open a crystal report popup window
//md: rfc 69979 add
function getReportWindowParams() {
    iWidth = 990;
    iLeft = ((screen.width  - iWidth)  / 2) - 5;
    iHeight = 680;
    iTop =  ((screen.height - iHeight) / 2) ;
    return 'directories=0 scrollbars=no, toolbar=no, menubar=no, location=no, width='+iWidth+', height='+iHeight+',  left='+iLeft+', top='+iTop+', resizable=yes'
}

//open a crystal report window
//md: rfc 69979 add
function gp_OpenCRReport(n_ReportNumber, s_Params, n_PageLocationLevel) {

    var sUrl;
    var sPrefix = "";
    //default value for page location leves is "1"
    if (gp_OpenCRReport.arguments.length < 3) {
        n_PageLocationLevel = 1;        
    } 		
    // get prefix for page url
    for (i = 0; i < n_PageLocationLevel; i++)
    {
        sPrefix = "../" + sPrefix;
    }    
    
    sUrl = sPrefix + "CReport.aspx?REPORT=" + n_ReportNumber;
    sUrl = sUrl + s_Params;   
    sUrl = encodeURI(sUrl);
	WinPrint=window.open(sUrl,'ReportWindow', getReportWindowParams());
}



function fPrint (sTable)
{
    var sHeight;
    var nHheight;
    Win=window.open('','Druckansicht','directories=0 scrollbars=yes, toolbar=no, menubar=no, location=no, width=990, height=680,  left=10, top=10, resizable=yes');			
    
    Win.document.write('<LINK href="../Styles.css" type="text/css" rel="stylesheet">');
    document.Form1.style.top
    document.Form1.style.left
   
    tbl=document.getElementById(sTable + "_Table_Header");
    sHeight=tbl.style.height;
    nHeight=parseInt(sHeight);
    Win.document.write('<div>');
    Win.document.write(tbl.innerHTML);
    Win.document.write('</div>');
        
    tbl=document.getElementById(sTable + "_Table_Body");
    if (tbl) {
        Win.document.write('<div id="ptblBody" style="position:absolute;top:' + sHeight + ';left:0px">');
        Win.document.write(tbl.innerHTML);
        Win.document.write('</div>');
        try {
            nHeight = nHeight + tbl.scrollHeight;
        } catch(e){nHeight=0;}
        
    }
    
    if (nHeight > 0) {
        tbl=document.getElementById(sTable + "_Table_Footer");
        if (tbl) {
            Win.document.write('<div id="ptblBody" style="position:absolute;top:' + nHeight + 'px;left:0px">');
            Win.document.write(tbl.innerHTML);
            Win.document.write('</div>');
        }
    }
    
    try {
        var coll = Win.document.all.tags('A');
        if (coll!=null){
            var iLength = coll.length;
            for (i=0; i<iLength; i++) coll[0].outerHTML='<span>' + coll[0].innerHTML + '</span>';
        }
        Win.document.getElementById(sTable + '_PrintIcon').style.visibility='hidden';

        coll = Win.document.getElementsByName('NoPrintPic')
        if (coll!=null){
            iLength = coll.length;
            for (i=0; i<iLength; i++) coll[i].style.visibility='hidden';
        }
    } catch(e){;}
}
//md: add 
//Aufruf der DokumentenSeite
var winDocument; //wird in 2 Funktionen gehändelt (fShowDocumentWindow() und fCloseDocumentWindow())

//function fShowDocumentWindow(typ, sUrlToInput)
//{
//	var iWidth=985;			
//	var iHeight=600;			
//	var sLeft = ((screen.width - iWidth) / 2) - 10;									
//	//var sTop = window.screenTop + 50;
//	var sTop = (screen.height - iHeight)/2;
//	var sFeatures = "height=" + iHeight + ", width=" + iWidth + ", top=" + sTop + ", left=" + sLeft + ", scrollbars=no, toolbar=no, menubar=no, location=no, resizable=yes";
//	winDocument = window.open(sUrlToInput + '?typ=' + typ, 'Files', sFeatures);							
//	winDocument.focus();
//}
function fShowDocumentWindow(typ, sUrlToInput, id, id_pos, bNoUpload, sIDForCaption, id_partpos)
{
    fShowDocumentWindow3(typ, sUrlToInput, id, id_pos, bNoUpload, sIDForCaption, id_partpos);
}

function fShowDocumentWindow2(typ, sUrlToInput, id, id_pos, id_partpos)
{
// ------------------------------------------------------------
//	var iWidth=990;			
//	var iHeight=600;
//	var sLeft;
//	if (screen.width - iWidth >= 20) { 
//	    sLeft = ((screen.width - iWidth) / 2) - 10;	
//	}			
//	else {
//	    sLeft = 0;
//	}
//	//var sLeft = ((screen.width - iWidth) / 2) - 10;																	
//	var sTop = (screen.height - iHeight)/2;
//	var sFeatures = "height=" + iHeight + ", width=" + iWidth + ", top=" + sTop + ", left=" + sLeft + ", scrollbars=no, toolbar=no, menubar=no, location=no, resizable=yes";
//	var sUrl;
//	sUrl = sUrlToInput + '?typ=' + typ;
//	if (id != '') {
//	    sUrl = sUrl + '&id=' + id;
//	    if (id_pos != '') {
//	        sUrl = sUrl + '&id_pos=' + id_pos;
//	    }
//	    if (id_partpos != '') {
//	        sUrl = sUrl + '&id_partpos=' + id_partpos;
//	    }
//	}
//	winDocument = window.open(sUrl, 'Files', sFeatures);							
//	winDocument.focus();
// ------------------------------------------------------------
  //sw:add 07.11.08
  //Please use this function in future:
  fShowDocumentWindow3(typ, sUrlToInput, id, id_pos, 0, '', id_partpos)
  //sw:end 07.11.08
}
//No Upload mode -- Siehe js.js in Universalhafen
//sw:add 07.11.08
function fShowDocumentWindow3(typ, sUrlToInput, id, id_pos, bNoUpload, sIDForCaption, id_partpos)

{
	var iWidth=985;			
	var iHeight=600;
	var sLeft;
	if (screen.width - iWidth >= 20) { 
	    sLeft = ((screen.width - iWidth) / 2) - 10;	
	}			
	else {
	    sLeft = 0;
	}
	//var sLeft = ((screen.width - iWidth) / 2) - 10;																	
	var sTop = (screen.height - iHeight)/2;
	var sFeatures = "height=" + iHeight + ", width=" + iWidth + ", top=" + sTop + ", left=" + sLeft + ", scrollbars=no, toolbar=no, menubar=no, location=no, resizable=yes";
	var sUrl;
	sUrl = sUrlToInput + '?typ=' + typ;
	if (id != '') {
	    sUrl = sUrl + '&id=' + id;
	    if (id_pos != '') {
	        sUrl = sUrl + '&id_pos=' + id_pos;
	    }
	    if (id_partpos != '') {
	        sUrl = sUrl + '&id_partpos=' + id_partpos;
	    }
	    if (bNoUpload) {
	        sUrl = sUrl + '&no_upload=1' ;
	    }	    
	}
	//md: 2.9.8 start
	if (sIDForCaption != '')
	{
	    sUrl = sUrl + '&sIDForCaption=' + sIDForCaption;
	}
	sUrl = encodeURI(sUrl);
	//md: 2.9.8 end
	winDocument = window.open(sUrl, 'Files', sFeatures);							
	winDocument.focus();
}
//sw:end 07.11.08

//Dokumentenseite schließen
function fCloseDocumentWindow()
{
	try {
		if (winDocument != null) {
			if (winDocument.closed == true) {
			}
			else {
				winDocument.close();
			}
		}
	}
	catch(e){;}
}
function fShowDocumentWindowNoUpload(typ, sUrlToInput, id, id_pos, id_partpos)
{
    //fShowDocumentWindow(typ, sUrlToInput, id, id_pos, true);
    fShowDocumentWindow(typ, sUrlToInput, id, id_pos, true, '', id_partpos);
}
function fShowDocumentWindowWithExtraCaptionID(typ, sUrlToInput, id, id_pos, bNoUpload, sIDForCaption)
{
    //md: 2.9.8 add
    fShowDocumentWindow(typ, sUrlToInput, id, id_pos, bNoUpload, sIDForCaption);
}
//Dokumentenseite schließen
function fCloseDocumentWindow()
{
	try {
		if (winDocument != null) {
			if (winDocument.closed == true) {
			}
			else {
				winDocument.close();
			}
		}
	}
	catch(e){;}
}

//Zugeordnetes Dokument mit ID s_ID anzeigen / Show assigned document with ID s_ID
function gp_ShowFile(s_ID, n_PageLocationLevel) 
{			
//	var iWidth=800;			
//	var iHeight=600;			
//	var sLeft = ((screen.width - iWidth) / 2) 									
//	var sTop = ((screen.height - iHeight) / 2)
	var iWidth=1;			
	var iHeight=1;			
	var sLeft = screen.width;								
	var sTop = screen.height;
	
	var sPrefix = "";
	
    if (gp_ShowFile.arguments.length < 2) {
        n_PageLocationLevel = 1;        
    }  
    	
    for (i = 0; i < n_PageLocationLevel; i++)
    {
        sPrefix = "../" + sPrefix;
    }	
    
	var sUrl = sPrefix + "Dateitransfer/Show.aspx?FileId=" + s_ID;
	var sFeatures = "height=" + iHeight + ", width=" + iWidth + ", top=" + sTop + ", left=" + sLeft + ", scrollbars=yes, toolbar=no, menubar=no, location=no, resizable=yes";
	var newwin = window.open(sUrl, 'Dateianzeige', sFeatures);												
	//newwin.focus();
} //end of function

//Notizseite schließen
//Dokumentenseite schließen
function fCloseNotizWindow()
{
	try {
		if (win != null) {
			if (win.closed == true) {
			}
			else {
				win.close();
			}
		}
	}
	catch(e)
	{
	}
}

//Close a window
function fCloseWindow(winAnyWindow)
{
	try {
		if (winAnyWindow != null) {
			if (winAnyWindow.closed == true) {
			}
			else {
				winAnyWindow.close();
			}
		}
	}
	catch(e)
	{
	}
}


//Fenster der zugeordneten Betriebsmittel anzeigen (md: 8.2.8 add)
function fctShowOrderAssignedPM(n_OrderID, n_PositionID, n_order_type)
{
	var iWidth=525;
	var iHeight=400;				
	var iLeft = ((screen.width - iWidth) / 2) - 10;
	var iTop = (screen.height - iHeight) / 2;									
	var sFeatures = "height="+iHeight+",width="+iWidth+",top="+iTop+",left="+iLeft+", scrollbars=no, toolbar=no, menubar=no, location=no, resizable=yes"
	var newWinOrderBM
	newWinOrderBM = window.open('../Verkehrsportal/BM_Positionen.aspx?OrderID=' + n_OrderID + '&PositionID=' + n_PositionID + '&OrderType=' + n_order_type,  'newWinOrderBM', sFeatures);							
	newWinOrderBM.focus()
}

//Show popup window with contact persons for special BUSINESS_PARTNER_ID
function fShowKundeAnsprechpartner(s_BUSINESS_PARTNER_ID)
{
	if (s_BUSINESS_PARTNER_ID == "")
	{		
		return;
	}	
	
	var adresstyp = 1;
	var iWidth=985;
	var iHeight=562;				
	var iLeft = ((screen.width - iWidth) / 2) - 10;
	var iTop = (screen.height - iHeight) / 2;									
	var sFeatures = "height="+iHeight+",width="+iWidth+",top="+iTop+",left="+iLeft+", scrollbars=no, toolbar=no, menubar=no, location=no, resizable=yes"
	var newWin;
	newWin = window.open('kundeansprechpartner.aspx?kunde_id=' + s_BUSINESS_PARTNER_ID + '&adresstyp=' + adresstyp, 'newWin', sFeatures);								
	newWin.focus();
}
//////////////////////////////////////// Eigenschaften/Zustände wechseln ///////////////////////////////////////////

// Allgemein
function fShow_Element(element){
	document.getElementById(element).style.visibility = "";
}

function fHide_Element(element){
	document.getElementById(element).style.visibility = "hidden";
}

function fEnable_Element(element){
	document.getElementById(element).disabled = false;
}

function fDisable_Element(element){
	document.getElementById(element).disabled = true;
}

// Textbox
function fFill_Textbox(element, text){
	document.getElementById(element).value = text;
}

function fClear_Textbox(element){
	document.getElementById(element).value = "";
}

function fEnable_Textbox(element){
	document.getElementById(element).disabled = false;
}

function fDisable_Textbox(element){
	document.getElementById(element).disabled = true;
}

function fValue_Textbox(element){
	return document.getElementById(element).value;
}

//Checkbox
function fFill_Checkbox(element){
	document.getElementById(element).checked = true;
}
function fClear_Checkbox(element){
	document.getElementById(element).checked = false;
}

function fValue_Checkbox(element){
	if(document.getElementById(element).checked == true){
		return 1;
	}
	else{
		return 0;
	}
}

function fEnable_Checkbox(element){
	document.getElementById(element).disabled = false;
}

function fDisable_Checkbox(element){
	document.getElementById(element).disabled = true;
}

function fSet_Checkbox(element, value){
	Checkbox = document.getElementById(element);
	if (value == '1') {
	    Checkbox.checked = true;
	    return;
	}
	Checkbox.checked=false;
}

function fctSetCheckboxColor(sCheckboxName,sHexColor)
{
    children = document.getElementById(sCheckboxName).parentNode.children;                    
    for(i=0; i<children.length; i++)
    {                        
        children[i].style.color=sHexColor;
    }	
}

function fctSetCheckboxDisplay(sCheckboxName,sVisible){
	parentes = document.getElementById(sCheckboxName).parentNode;
	parentes.style.display=sVisible;
}

//Combobox

function fValue_Combobox(element){
	return document.getElementById(element).value;
}

function fSelectedText_Combobox(element){
    return document.getElementById(element).options[document.getElementById(element).options.selectedIndex].text;
}

function fDefault_Combobox(element){
	document.getElementById(element).options[0].selected=true
}

function fDisable_Combobox(element){
	document.getElementById(element).disabled = true;
}

function fEnable_Combobox(element){
	document.getElementById(element).disabled = false;
}
function fDisableEnable_Combobox(element,bDisabled){
	document.getElementById(element).disabled = bDisabled;
}

function fClear_Combobox(element){
		var thecbo =  document.getElementById(element)
		var cbo_length = thecbo.length;
		var counter = cbo_length-1;
		for (i=1; i <= cbo_length; i++){
			thecbo.options[counter] = null;
			counter--;
		}
}

function fClear_Combobox2(s_DropDownListId, b_AddEmptyItem){
	var cbo = document.getElementById(s_DropDownListId);
	cbo.innerHTML = "";
	if (b_AddEmptyItem == true) fAdd_Option_Combobox(s_DropDownListId, '', '');
}

function fSelect_Combobox(element, value){
	Combobox = document.getElementById(element);
	for(var i = 0; i < Combobox.length; i++){
		if(Combobox.options[i].value==value){
			Combobox.options[i].selected=true;
			break;
		}
	}
}

function fIs_In_Combobox(element, value){
	Combobox = document.getElementById(element);
	for(var i = 0; i < Combobox.length; i++){
		if(Combobox.options[i].value==value){
			return true;
			break;
		}
	}
}

function fAdd_Option_Combobox(element, name, value){
	Combobox = document.getElementById(element);
	Combobox.options[Combobox.options.length] = new Option (name, value);
}

///////////////////////////////////////////////// Label ///////////////////////////////////////////////////


function fSet_InnerText(element, value){
    if (document.getElementById(element).innerText != undefined)
    {
        //works with labels in IE
        document.getElementById(element).innerText = value;
    }
    else
    {
        //works with labels in safari
        document.getElementById(element).textContent = value;
    }
}

///////////////////////////////////////////////// URL ENCODING ///////////////////////////////////////////////////

function fENCODE_UTF8(plaintext){
	plaintext = plaintext.replace(/\r\n/g,"\n");
	if(navigator.appName==("Microsoft Internet Explorer")){
		var utftext = "";
		for(var n=0; n<plaintext.length; n++){
			var c=plaintext.charCodeAt(n);
			if (c<128)
				utftext += String.fromCharCode(c);
			else if((c>127) && (c<2048)){
				utftext += String.fromCharCode((c>>6)|192);
				utftext += String.fromCharCode((c&63)|128);
			}
			else{
				utftext += String.fromCharCode((c>>12)|224);
				utftext += String.fromCharCode(((c>>6)&63)|128);
				utftext += String.fromCharCode((c&63)|128);
			}
		}
		return utftext;
	}
	else{
		return plaintext;
	}
}

function fDECODE_UTF8(utftext){
	var plaintext = ""; var i=0; var c=c1=c2=0;
	while(i<utftext.length){
		c = utftext.charCodeAt(i);
		if (c<128){
			plaintext += String.fromCharCode(c);
			i++;
		}
		else if((c>191) && (c<224)){
			c2 = utftext.charCodeAt(i+1);
			plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
			i+=2;
		}
		else{
			c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
			plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
			i+=3;
		}
	}
	return plaintext;
}



//*********************************************
//new technique for web forms with tabs - start
//*********************************************
function gf_ManageTabs(arr_DIV, arr_Caption, n_No, n_Top, sClassNameChosen, sClassNameNotChosen)
{
    //1. hide all tabs and set default classname tabnotchosen for tabs and captions 
    var nTopMinus = n_Top - 2;
    
    if (sClassNameChosen == null)    sClassNameChosen    = 'tabChosen';
    if (sClassNameNotChosen == null) sClassNameNotChosen = 'tabnotChosen';

    for (var i = 0; i < arr_DIV.length; i++)
    {
        document.getElementById(arr_DIV[i]).style.visibility = 'hidden';
        document.getElementById(arr_Caption[i]).className = sClassNameNotChosen;
        document.getElementById(arr_Caption[i]).style.top = '' + n_Top + 'px';
        //document.getElementById(arr_Caption[i]).style.height = '20px'; 'md: 9.2.9 del
    }
    
    //2. show tab with number n_No
    document.getElementById(arr_DIV[n_No]).style.visibility = 'visible';
    
    //3. set correct style for displayed tab and caption
    document.getElementById(arr_Caption[n_No]).className = sClassNameChosen;
    document.getElementById(arr_Caption[n_No]).style.top = '' + nTopMinus + 'px';
    //document.getElementById(arr_Caption[n_No]).style.height = '22px'; 'md: 9.2.9 del
}

//********************************************
//new technique for web forms with tabs - end
//********************************************
//********************************************
//restrict length of multiline textfields
//********************************************
  function gRestrictLength( stextbox , nLength )
        {
          if (document.getElementById(stextbox).value.length > nLength )
          {
            document.getElementById(stextbox).value = document.getElementById(stextbox).value.substring(0,nLength);
          }
        }
        
  function gfb_IsMaxlength(txtBox_Name, n_MaxLength)
  {
    if (document.getElementById(txtBox_Name))
    {
        return (document.getElementById(txtBox_Name).value.length <= n_MaxLength);
    }
    else
    {
        return true;
    }
  }

//*******************
//Refresh Time functions
//*******************          

function fs_NewDate(sDateTimeFormat)
{
    var dNow = new Date();
    var sNow = gfs_FormatDateTime(dNow, sDateTimeFormat, true);
    return sNow;
}

function p_TextboxRefreshTime(sTextBoxID, sDateTimeFormat)
{
    var sNow = fs_NewDate(sDateTimeFormat);
    document.getElementById(sTextBoxID).value = sNow;
}

// ******************************************* 
// Search functions in the select field
// ******************************************* 
function searchOptions(select, vArray, sText)
{
    lastVal = select.options[select.selectedIndex].value;
    tempArray = new Array();
    i = 0;
    emptyRowIncluded = false;
    if(vArray[0].text == "") 
    {
        tempArray[0] = vArray[0];
        i++;
        emptyRowIncluded = true;
    }
    if(sText != null && sText != "")
    {
        vText = sText.toLowerCase();
        for(x=0; x<vArray.length; x++){
            if(vArray[x].text.toLowerCase().indexOf(vText) == 0) 
            {
                tempArray[i] = vArray[x];
                i++;
            }
        }
    } else {
        tempArray = vArray
    }	 

    restoreOptions(select, tempArray)
    if(lastVal != "") {
        for(x=0; x<select.options.length; x++){
            if(lastVal == select.options[x].value) 
            {
                select.options[x].selected = true;
            }
        }
    }
    
    if(tempArray.length  == 2 && emptyRowIncluded) 
    {
        select.options[0].selected = false;
        select.options[1].selected = true;
    }
}

function storeOptions(select, vArray) 
{
    for(i=0; i<select.options.length; i++)
    {
        vArray[i] = select.options[i];
    }
}

function restoreOptions(select, vArray) 
{
    select.options.length = 0;
    for(i=0; i<vArray.length; i++)
    {
        select.options[i] = vArray[i];
        select.options[i].selected = false;
    }
    select.options[0].selected = true;
}

function scaleTableCells(table, bTableWidth, dTableWidth) {
    rows = table.getElementsByTagName('tr');
    for (i = 0; i < rows.length; i++) {
	    cells = rows[i].getElementsByTagName('td');
	    for (j = 0; j < cells.length; j++) {
		    if (cells[j].style.width != '') {
			    width = cells[j].style.width.replace('px','');
			    width = width / bTableWidth * dTableWidth;
			    cells[j].style.width = width + 'px';
		    }
	    }
    }
    table.style.width = dTableWidth + 'px';
}

function setPrintClass(table , dTableWidth) {
    table.className = table.className.replace("display", "print")
    table.style.width = dTableWidth + 'px';
}

function replaceHTMLSigns(sFieldName){
    //Add Ro 2011-10-04 
    if (document.getElementById(sFieldName)) 
    {
        var sText = document.getElementById(sFieldName).value;
        if(sText != null && sText != "")
        {
            //replace all  <
            sText = sText.replace(/</g, "[*lt*]");
            //replace all  >
            sText = sText.replace(/>/g, "[*gt*]");
            //alert(sText);
            document.getElementById(sFieldName).value = sText;
        }
    }
    //return true;
}
