// ------------------------------
// Funktionen Styleswitcher Start
//------------------------------- 
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
  	    if(a.getAttribute("title") == title) {
  	        a.disabled = false;
            createCookie("style", title, 365);
            try
            {
                if (window.frames["iFrame1"] != null)
                {
                    window.frames["iFrame1"].setActiveStyleSheet(title);
                }
            }
            catch(e)
            {}
  	    }
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
//  var title = getActiveStyleSheet();
//  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
// -----------------------------
// Funktionen Styleswitcher Ende
//------------------------------ 

// ---------------------------
// Allgemeine Funktionen Start
//---------------------------- 

function openwindow(url) 
{
	OpenWin = window.open(url, "openwindow", "width=800,height=600,location=no,menubar=no,status=no,scrollbars=yes,toolbar=no");
}

function openwindowWithSize(url, width, height) 
{
	OpenWin = window.open(url, "openwindow", "width=" + width + ",height=" + height + ",location=yes,menubar=yes,status=yes,scrollbars=yes,toolbar=yes,resizable=yes");
}

function openwindowWithSize2(url, width, height)
{
    OpenWin = window.open(url, "openwindow", "width=" + width + ",height=" + height + ",location=no,menubar=no,status=no,scrollbars=yes,toolbar=no");
}

function openOL(url) 
{
	OpenWin = window.open(url, "openwindow", "width=600,height=300,resizable=yes,location=no,menubar=no,status=no,scrollbars=yes,toolbar=no");
}

// --------------------------
// Allgemeine Funktionen Ende
//--------------------------- 

// ----------------------------
// Funktionen Offenlegung Start
//----------------------------- 

function toggle(tableId) 
{
	var table = document.getElementById(tableId);
	if (table.style.display == "none")
	{
		table.style.display = "block";
	}
	else
 	{
 		table.style.display = "none";
	}
}

function redirectOffenlegungDst(chid, brid, dstid, back)
{
	var url;
	
	url =	'chid=' + chid + '&brid=' + brid + '&dstid=' + dstid + '&back=' + back;
			
	location.href = 'offenlegung_dst.wk?' + url;
}

// ---------------------------
// Funktionen Offenlegung Ende
//---------------------------- 

// ----------------------------
// Funktionen Detailseiten Start
//----------------------------- 

function openNewWindowNoParams(url, width, height) 
{
	var OpenWin = window.open(url, "_blank", "width=" + width + ",height=" + height + ",location=no,menubar=no,status=no,scrollbars=no,toolbar=no");
}
function openNewWindowScr(url, width, height) 
{
	var OpenWin = window.open(url, "_blank", "width=" + width + ",height=" + height + ",location=no,menubar=no,status=no,scrollbars=yes,toolbar=no");
}
function openSitemap(url) 
{
	mapWin = window.open(url, "Sitemap", "width=550,height=700,location=no,menubar=no,status=no,scrollbars=yes,toolbar=no");
}

// ----------------------------
// Funktionen Detailseiten Ende
//-----------------------------

// --------------------------------
// Funktionen Abfallstoffsuche Start
//---------------------------------

function checkCallerPostback()
{
    var postbackValue = document.getElementById("PostbackValue").value;
    if (postbackValue != "")
    {
        if (opener != null)
        {
            var theForm = opener.document.Form1;
            var parentValue = opener.document.getElementById("SelectedAbfaelle");
            parentValue.value = postbackValue;
            theForm.submit();
            window.close();
        }
    }
}

// --------------------------------
// Funktionen Abfallstoffsuche Ende
//---------------------------------

function getAbfallsucheUrl()
{
    var value = document.getElementById("tbAbfallschluesselnr_EDB").value;
    return "../Frontend/SucheAbfallschluessel.aspx?mode=1&nr=" + value;
}