// get url parameters
var urlquery;
var urlquery2;
urlquery=location.href.split("?");
if (urlquery[1])
	urlquery2=urlquery[1].split("&");
var theurl = new Array();
if (urlquery2)
	{
	for (var i = 0; i < urlquery2.length; i++)
		{
		theurl[i] = new Object();
		theurl[i]['key'] = urlquery2[i].split("=")[0];
		theurl[i]['val'] = urlquery2[i].split("=")[1];
		}
	}

// get current language, domain
if (theurl.length)
	{
	var theL = "";
	var theDomain = "";
	for (var i = 0; i < theurl.length; i++)
		{
		if (theurl[i]['key']=='L')
			theL = theurl[i]['val'];
		if (theurl[i]['key']=='domain')
			theDomain = theurl[i]['val'];
		}
	if (theL == "")
			theL = 0;
	}
else
	{
	theL = 0;
	theDomain = "";
	}

// set current language
function setcurrentlangbar()
	{
	if (document.getElementById('currentlang'))
		{
		switch (theL) 
			{
			case "1":
				document.getElementById('currentlang').src='fileadmin/tpl/sa/img/lang_nl_off.gif';
				break;
			case "2":
				document.getElementById('currentlang').src='fileadmin/tpl/sa/img/lang_de_off.gif';
				break;
			default:
				document.getElementById('currentlang').src='fileadmin/tpl/sa/img/lang_en_off.gif';
				break;
			}
		}
	else
		setTimeout("setcurrentlangbar()",100);
	}

setcurrentlangbar();

function buildurl(key, val, root)
	{
	var keycount = 0;
	var mykeycount = 0;
	if (root == '1')
	var myurl = window.location.protocol + '//' + window.location.hostname;
		else
	var myurl = urlquery[0];
	for (var i = 0; i < theurl.length; i++) 
		{
		if (theurl[i]['key'] != "")
			{
			if (keycount == 0)
				myurl = myurl + '?';
			else
				myurl = myurl + '&';
			if (theurl[i]['key'] == key)
				{
				myurl = myurl + key + '=' + val;
				mykeycount = 1;
				}
			else
				{
				if (keycount == 0 && !theurl[i]['val'])
					{
					if (root != '1')
						myurl = myurl + theurl[i]['key'];
					}
				else
					myurl = myurl + theurl[i]['key'] + '=' + theurl[i]['val'];
				}
			keycount = keycount + 1;
			}
		}
	if (mykeycount == 0 && key != "" && val != "")
		{
		if (keycount == 0)
			myurl = myurl + '?';
		else
			myurl = myurl + '&';
		myurl = myurl + key + '=' + val;
		}
	if (root != '1')
		langbar();
	//if (window.location.protocol != 'https:')
	//	myurl = '#';
	//alert(myurl);
	return myurl;
	}

// switch language bar
function langbar()
	{
	if ( document.getElementById('langbar2').style.visibility=='visible' )
		{
		document.getElementById('langbar2').style.visibility='hidden';
		document.getElementById('langbar2').style.display='none';
		document.getElementById('langenbar').style.background='#84a7d0';
		document.getElementById('langnlbar').style.background='#84a7d0';
		document.getElementById('langdebar').style.background='#84a7d0';
		}
	else
		{
		document.getElementById('langbar2').style.visibility='visible';
		document.getElementById('langbar2').style.display='inline';
		}
	}


// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


// switches tab table elements
function tab_table(theTable, theID)
	{
	obj = findObj(theTable);
	for(var i = 0; i < obj.rows.length; i++) 
		{
		obj.getElementsByTagName("tr")[i].className = "tab_table_lo";
		}
	document.getElementById(theID).className = "tab_table_hi";
	}


  // this function is need to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }  


function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

	    // avoid rows that have a class attribute
        // or backgroundColor style
	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 
         // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
        
		      mytd.style.backgroundColor = even ? evenColor : oddColor;
              
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }

function clickit(cn,clink) {
  if(document.images) {
     (new Image()).src="fileadmin/tpl/sa/external.html?pos="+cn+"&url="+clink;
     (new Image()).src="http://twatch.serverarea.com/jslogger.php?ref="+( document['referrer']==null?"":escape(document.referrer))+"&pg="+escape(window.location+"&pos="+cn+"&url="+clink)+"&cparams=true";
  }
  return true;
}


function CreateBookmarkLink(title,url) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

function buildBookmarkLink(title, url, text) {
 if (window.external || window.sidebar || (window.opera && window.print)) {
  document.write('<a href = "javascript:CreateBookmarkLink(\''+title+'\', \''+url+'\');">'+text+'</a>'); 
  }
}