startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("me1");
		if(navRoot) for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}

}
window.onload=startList;


sfHover = function() {
	var sfEls = document.getElementById("me1");
	if(sfEls) sfEls = sfEls.getElementsByTagName("LI");
	if(sfEls) for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


function isValidXnr(nr_inp)
{
	var nrpart= "";
	var isValid= (nr_inp != "");

	if(isValid)
	{
		nrpart= nr_inp.match(".*\([0-9]{6,}\).*");
		isValid= nrpart != null;
		if(isValid) isValid= typeof nrpart[1] != 'undefined';
	}

	return isValid;
}

function isValidEmail(email_inp)
{
	var mailpart= "";
	var isValid= (email_inp != "");

	if(isValid)
	{
		mailpart= email_inp.match("\([a-zA-Z0-9_-]+\)\@\([a-zA-Z0-9_-]+\)[\.]{1}\([a-zA-Z0-9]+\)");
		isValid= mailpart != null;
		if(isValid) isValid= typeof mailpart[1] != 'undefined' && typeof mailpart[2] != 'undefined' && typeof mailpart[3] != 'undefined';
	}

	return isValid;
}

function isValidDate(date_inp)
{
	isValid= (date_inp != "");
	if(isValid)
	{
		datepart= date_inp.match("\([0-9]{2}\)\.\([0-9]{2}\)\.\([0-9]{4}\)");
		isValid= datepart != null;
		if(isValid) isValid= !isNaN(datepart[1]) && !isNaN(datepart[2]) && !isNaN(datepart[3]);
		if(isValid) isValid= ((datepart[1] > 0 && datepart[1] <= 31) && (datepart[2] > 0 && datepart[2] <= 12) && (datepart[3] > 1900 && datepart[3] < 2200));
	}
	return isValid;
}

function GetFromCookie()
{
	var SavedValues= "";
	if(document.cookie) SavedValues= document.cookie;

	return SavedValues;
}

function PutToCookie(ToBeSaved)
{
	var tage = "1";
	verfall=new Date();
	verfall.setTime(verfall.getTime()+(86400000*tage));

	// document.cookie = ToBeSaved + "; expires=" + verfall.toGMTString();
	document.cookie = ToBeSaved
}

function CollectValues()
{
	var values= "";
	var is_selectbox= false;
	var allfields= document.forms[0];

	for(index=0; index<allfields.length; index++)
	{
		itype= allfields[index].type;
		is_selectbox= (itype.indexOf("select") > -1);
		if(itype == "text" || itype == "hidden" || is_selectbox)
		{
			iname= allfields[index].name.toLowerCase();

			ivalue= allfields[index].value;
			ivalue= ivalue.replace(/&/g,"*");
			ivalue= ivalue.replace(/=/g,"|");

			if(!(iname.substring(0, 3) == "dns")) values+= iname + "=" + ivalue + "&";
			else if(iname == "dnsfinish") break;
		}
	}

	return values;
}


function GetValue(allvalues, valname)
{
	valname= valname.toLowerCase() + "=";

	valpos= allvalues.indexOf(valname);
	if(valpos >= 0)
	{
		valpos+= valname.length;
		return allvalues.substring(valpos, allvalues.indexOf("&", valpos));
	}
	else return "";
}

function SaveValues()
{
	var collectedvalues= CollectValues();
	if(collectedvalues != "") PutToCookie(collectedvalues);
}

function LoadValues()
{
	var allvalues= GetFromCookie();
	var allfields= document.forms[0];
	var is_selectbox= false;
	var sellength= 0;
	var selselected= false;
	var selpos= 0;
	var temp= "";

	for(index=0; index<allfields.length; index++)
	{
		itype= allfields[index].type;
		is_selectbox= (itype.indexOf("select") > -1);

		if(itype == "text" || itype == "hidden" || is_selectbox)
		{
			iname= allfields[index].name.toLowerCase();
			ivalue= allfields[index].value;

			if(!(iname.substring(0, 3) == "dns") && (ivalue == "" || is_selectbox))
			{
				temp= GetValue(allvalues, iname);
				temp= temp.replace(/\*/g,"&");
				temp= temp.replace(/\|/g,"=");

				if(!is_selectbox)  allfields[index].value= temp;
				else if(is_selectbox)
				{
					sellength= allfields[index].options.length;
					for(selpos= 0; selpos < sellength; selpos++)
					{
						selselected= (allfields[index].options[selpos].value == temp);
						allfields[index].options[selpos].selected= selselected;
						allfields[index].options[selpos].defaultSelected= selselected;
					}
				}
			}
			else if(iname == "dnsfinish") break;
		}
	}
}

function checkVsn()
{
	if(!isValidXnr(document.vsn_form.vertragsnr.value))
	{
		alert("Bitte geben Sie Ihre Vertragsnummer ein.");
		document.vsn_form.vertragsnr.focus();
		return false;
	}
	else
	{ 
		SaveValues();
		return true;
	}

}

