var arrItems = new Array();
var arrGroup = new Array();
var arrIds   = new Array();

function changeCountry(reg,default_text,land,region)
{
  var control= document.getElementsByName(land)[0];
  var target = document.getElementsByName(region)[0];
  var myEle ;
  var x ;
  for (var q=target.options.length;q>=0;q--) target.options[q]=null;
  
  myEle = document.createElement("option") ;
  myEle.value = "" ;
  myEle.text  = default_text;
  if (document.all) target.add(myEle); else target.add(myEle,null);
  
  for ( x=0; x<arrItems.length; x++ )
    {
      if ( arrGroup[x] == control.value )
        {
          myEle = document.createElement("option") ;
          myEle.value = arrIds[x];
          myEle.text  = arrItems[x];
          if (document.all) target.add(myEle); else target.add(myEle,null);
          if (myEle.value == reg) { myEle.selected = true; myEle.defaultSelected = true; }
        }
    }
}



function addRegion(i,id,region,land) {
	arrIds[i]   = id;
	arrItems[i] = region;
	arrGroup[i] = land;
}



function check_submit(ask) {
	var i=0;
	var item;
	var valid=true;
	var first=true;
		
	if (document.getElementById("errormsg")) {
		document.getElementById("errormsg").className="hidden";
	}

	while (document.form1.elements[i]) {
		item=document.form1.elements[i];
		item.className = item.className.replace(/(\serror)+/,"");
		
		//erforderliche Checkbox nicht checked?	
		if (item.className.match(/Checkbox\sreq/) && (!item.checked)) {
			item.className=item.className+" error";
			valid=false;
			if (first) { item.focus(); first=false; }
		}
		
		//erforderliches Feld ist leer?	
		if (item.className.match(/req/) && (item.value=="")) {
			item.className=item.className+" error";
			valid=false;
			if (first) { item.focus(); first=false; }
		}
		
		//EMail-Adresse korrekt?	
		if (item.className.match(/email/) && item.value!="" && !item.value.match(/^([-\w]+)(\.[-\w]+)*(\@)([-\w]+)(\.[-\w]+)*(\.)([a-z]{2,4})$/i)) {
			item.className=item.className+" error";
			valid=false;
			if (first) { item.focus(); first=false; }
		}
		
		//Internet-Adresse korrekt?	
		if (item.className.match(/www/) && item.value!="" && !item.value.match(/^(http:\/\/)?([-\w]+)(\.[-\w]+)*(\.)([a-z]{2,4})$/i)) {
			item.className=item.className+" error";
			valid=false;
			if (first) { item.focus(); first=false; }
		}
		
		//Telefonnummern korrekt?	
		if (item.className.match(/telefon/) && item.value!="" && !item.value.match(/^([-\+\d\s\/\(\)]+)$/)) {
			item.className=item.className+" error";
			valid=false;
			if (first) { item.focus(); first=false; }
		}
		
		i++;
	}
		
	if (!valid) {
		if (document.getElementById("errormsg")) {
			document.getElementById("errormsg").className="error"; 
			document.getElementById("errormsg").scrollIntoView("true");
		}
		return false;
	}
	
	if (ask) {	
		return confirm("Datensatz neu abspeichern? Geänderte Daten werden unwiderruflich überschrieben!");	
	} else {
		return true;
	}
}


//e=event, o=object, t=type
function checkInput(e,o,t)
{
	var key;
	var keychar;
	var reg;
	var komma;
	
	if(window.event) { key = e.keyCode; }	// IE
	else if(e.which) { key = e.which; }		// Netscape
	else { return true; }
		
	if (t=="plz") {
		if (key==8 || key==13) return true;
		keychar = String.fromCharCode(key);
		reg = /[A-Za-z0-9]/;
			
		return reg.test(keychar);
	}
	
	if (t=="int" || t=="float") {
		if (key==8 || key==13) return true;
		keychar = String.fromCharCode(key);
		reg = /[0-9,.]/;
		komma = /[,.]/;
		if (komma.test(o.value) || t=="int") { reg = /[0-9]/; }
	
		return reg.test(keychar);
	} 
	
	if (t=="time") {
		if (key==8 || key==13) return true;
		keychar = String.fromCharCode(key);
		reg = /[0-9:.]/;
		komma = /[:.]/;
		if (komma.test(o.value)) { reg = /[0-9]/; }
	
		return reg.test(keychar);
	} 
	
	//default
	if (key==8) return true;
	return (o.value.length<t);
}


function trim(o,t)
{
	if (o.value.length>t) o.value = o.value.substring(0,t);
}


function popup(winurl,winname,w,h)
{
	var ah= screen.availHeight;
	var aw= screen.availWidth;
	var l = Math.round((aw-w)/2);
	var t = Math.round((ah-h)/2);
	window.open(winurl,winname,"width="+w+",height="+h+",left="+l+",top="+t+",resizable=yes,dependent=yes,scrollbars=yes,status=no");
}



// Sets a Cookie with the given name and value.
// name       Name of the cookie
// value      Value of the cookie
// [time]     Time until expiration of the cookie in seconds (default: end of current session)
// [path]     Path where the cookie is valid (default: path of calling document)
// [domain]   Domain where the cookie is valid (default: domain of calling document)
// [secure]   Boolean value indicating if the cookie transmission requires a secure transmission
function setCookie(name, value, time, path, domain, secure)
{
	var expires = new Date();
	var until = expires.getTime() + (time * 1000);
	expires.setTime(until);
    document.cookie= name + "=" + value +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

// Gets the value of the specified cookie.
// name  Name of the desired cookie.
// Returns a string containing value of specified cookie, or "" if cookie does not exist.
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return "";
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return dc.substring(begin + prefix.length, end);
}

// Deletes the specified cookie.
// name      name of the cookie
// [path]    path of the cookie (must be same as path used to create cookie)
// [domain]  domain of the cookie (must be same as domain used to create cookie)
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}



function show(img) { document.getElementById(img).className=""; }

function hide(img) { document.getElementById(img).className="hidden"; }

function check_info(who) {
	var other,ob1,ob2;
	other = (who=='g' ? 'k' : 'g');
	ob1 = document.getElementById('info_'+who);
	ob2 = document.getElementById('info_'+other);
	
	if (ob1.checked) {ob2.checked=false;}
}