/********************************************************************

	Allgemeine Javascript-Funktionen

********************************************************************/

function go(i, get_var)
{
	file = document.URL;
	// evtl. Seitennummer in URL entfernen
	file = file.replace(/seite_(\d+)\.php/, "");
	file = file.replace(/(&|\?)seite_nr=(\d+)/, "");
	if (file.indexOf("?") > 0)
	{
		if (file.indexOf(get_var) == -1)
		{
			loc = file + "&" + get_var +"=" + i;
		}
		// wenn Variable bereits enthalten ist...
		else
		{
			// ... Wert austauschen
			// Teil vor dem Wert herausfinden
			start_val = file.indexOf(get_var + "=") + get_var.length + 1;
			loc1 = file.substring(0, start_val);
			loc2 = file.substring(start_val, file.length);
			if (loc2.indexOf("&") > 0)
			{
				loc2 = loc2.substring(loc2.indexOf("&"), loc2.length);
			}
			else
			{
				loc2 = "";
			}
			loc = loc1 + i + loc2;
		}

	}
	else
	{
		loc = file + "?" + get_var + "=" + i;
	}
	window.location.href=loc;
}

function goDirect(url)
{
	window.location.href=url;
}


function confirmLink(link, msg)
{
    var is_confirmed = confirm(msg);
    if (is_confirmed)
	{
        return true;
    }
	else
	{
		return false;
	}
}

function customPrompt(msg, dflt_val, form)
{
    form.value = prompt(msg, dflt_val)
    return true;
}

// überprüft nur, ob alle Pflichtfelder Werte haben
function validateForm(form, msg, val)
{
	num_elem = document.forms[form.name].length;
	for (i = 0; i < num_elem; i++)
	{
		elem = document.forms[form.name].elements[i];
		// nur Felder, deren Name mit 'r_' beginnt sind Pflichtfelder
		// wenn es eine check oder radio box ist
		if (elem.type == "checkbox" || elem.type == "radiobox")
		{
		    comp_val = elem.checked
		}
		else
		{
			comp_val = elem.value
		}
		//alert(elem.name + ":" + elem.type + ":" + comp_val + "==" + val);
		if(elem.name.substring(0,2) == "r_" && comp_val == val)
		{
			alert(msg);
			return false;
		}
	}
	return true;
}

// überprüft, ob nur LATIN-1-ASCII-Code enthalten ist
function isRegCharsOnly(field_name, field_title)
{
	str = document.forms["article"].elements[field_name].value;
	found = 0;
	for (i = 0; i < str.length ; i++)
	{
		if (str.charCodeAt(i) > 255)
		{
			alert("ACHTUNG! Das Feld '" + field_title + "' enthält ein Zeichen an Position " + i + " (vor '" + str.substr(i+1, 10)+ "'), das nicht HTML-konform ist.");
			found = 1;
		}
	}
	if (found == 1)
	{
		return false;
	}
	return true;
}

// Ein Pop-Up-Fenster in einer bestimmten Größe öffnen
function openWin(file, winname, wwidth, wheight)
{
	max_vertical=screen.availHeight-wheight;
	max_horizon=screen.availWidth-wwidth;

    wtop=max_vertical/2;
    wleft=max_horizon/2;
    /*wtop=0;
    wleft=0;*/
    startWin = window.open(file+"?max_vertical="+max_vertical+"&max_horizon="+max_horizon+"&wwidth="+wwidth+"&wheight="+wheight, winname, "width="+wwidth+", height="+wheight+", directories=no, screenX="+wleft+", screenY="+wtop+", top="+wtop+", left="+wleft+", status=yes "+",resizable=1");
    startWin.focus();
}

// Einen Div-Container anzeigen oder verstecken
function toggleVis(id)
{
   var ele = document.getElementById(id);
   //alert(id + ":" + ele.style.display)
   if (ele.style.display == "none")
      ele.style.display = "";
   else
      ele.style.display = "none";
}

// Einen Div-Container anzeigen
function showEle(id)
{
	var ele = document.getElementById(id);
	// nichts tun wenn das Element nicht existiert
	try
	{
		ele.style.display = "block";
	}
	catch (e)
	{
		return
	}
}

// Einen Div-Container verstecken
function hideEle(id)
{
        var ele = document.getElementById(id);
	// nichts tun wenn das Element nicht existiert
	try
	{
		ele.style.display = "none";
	}
	catch (e)
	{
		return
	}
}

function isIE() {

	var version = 0;
	if (navigator.appName.indexOf('Microsoft') > -1)
	{
		version = parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf('MSIE')+5, 3));
	}
	return version
}

// Einen Div-Container anzeigen
function showIEonly(id)
{
	ie_version = isIE()
	if (ie_version > 6 || ie_version == 0)
	{
		return;
	}
	var ele = document.getElementById(id);
	// nichts tun wenn das Element nicht existiert
	try
	{
		ele.style.display = "block";
	}
	catch (e)
	{
		return
	}

}

// Einen Div-Container anzeigen
function hideIEonly(id)
{
	ie_version = isIE()
	if (ie_version > 6 || ie_version == 0)
	{
		return;
	}
	var ele = document.getElementById(id);
	// nichts tun wenn das Element nicht existiert
	try
	{
		ele.style.display = "none";
	}
	catch (e)
	{
		return
	}

}

function setTab(id)
{
	var ele = document.getElementById(id);
	//alert(ele.style.color)
	if(ele.style.color != "#ffffff" && ele.style.color != "rgb(255, 255, 255)")
	{
		return;
	}
	toggleVis('bestlist');
	toggleVis('newlist');
	toggleContentTab('besttab');
	toggleContentTab('newtab');
}

function toggleContentTab(id)
{
	var ele = document.getElementById(id);
	col = "#ffffff";
	act_col = "#425d73";
	bgi = "url('/pics/contenttab.gif') no-repeat";
	act_bgi = "url('/pics/contenttab_act.gif') no-repeat";

	//alert(id + ":" + ele.style.color)

	if (ele.style.color == col || ele.style.color == "rgb(255, 255, 255)")
	{
		ele.style.color = act_col;
		ele.style.background = act_bgi;
	}
	else
	{
		ele.style.color = col;
		ele.style.background = bgi;
	}
}

function getDayTime()
{
	var now = new Date();
	var h = now.getHours();
	if (h >= 5 && h < 9)
	{
	  return "Morgen";
	}
	else if (h >= 18 && h <= 23)
	{
	  return "Abend";
	}
	else
	{
	  return "Tag";
	}
}


// Zahlungsweise setzen, wenn Daten eingegeben werden
function checkPayment(val)
{
	for (var i = 0; i < document.payment.pay_meth.length; i++)
	{
		if(document.payment.pay_meth[i].value == val)
		{
			document.payment.pay_meth[i].checked = true;
		}
	}
}

function radioValue(radioButton)
{
    for (x = 0; x <= radioButton.length; x++)
    {
        if (radioButton[x].checked == true) return radioButton[x].value;
    }
    return radioButton.value;
}

function getCheckedValue(radioObj)
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
        if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++)
        {
		if(radioObj[i].checked || radioObj[i].selected)
                {
			return radioObj[i].value;
		}
	}
	return "";
}

function flipLogo(id) {
	document.getElementById(id).style.display = (document.getElementById(id).style.display == "block") ? "none" : "block";
}

function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }

}