function checkNumerics(o, msg) {
	var s = new String(o.value);
	s = s.replace(/[^0-9]/g, '');

	if (String(s) == String(o.value)) {
		// All okay
	} else {
		alert(msg);
		o.value = s;
		//o.focus();
		//o.select();
	}
}


function getPageSize() {

var xScroll, yScroll;

if (window.innerHeight && window.scrollMaxY) {	
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}

var windowWidth, windowHeight;

if (self.innerHeight) {	// all except Explorer
if(document.documentElement.clientWidth){
windowWidth = document.documentElement.clientWidth; 
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}	

// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else { 
pageHeight = yScroll;
}

// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){	
pageWidth = xScroll;		
} else {
pageWidth = windowWidth;
}

return [pageWidth,pageHeight];
}

// ---------------------------------------------------------
// Reifenpositionen

// not so nice solution, but works...
/*

if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
*/

var currY = 0;
function getMouseXY(e, obj) {
  var IE = document.all?true:false;
  if (IE) { // grab the x-y pos.s if browser is IE
	if (document.body.scrollTop) {
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
} else {
    tempX = event.clientX + document.documentElement.scrollLeft;
    tempY = event.clientY + document.documentElement.scrollTop;
}
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //document.Show.MouseX.value = tempX
  //document.Show.MouseY.value = tempY
  //return true;
  currY = tempY;
//  return tempY;
}
var showingid = 0;
var timeoutLayer = false;
var showingfabrikat = false;
var showingkennzeichen = false;
var showinghaendler = false;
var showingplzort = false;
var showingidentnummer = false;
function showlist(typ) {
	var theY = 300;
	if (currY) {
		theY = currY;
	}
	if (typ == 'fabrikat' && !showingfabrikat) {
		abbrechen('kennzeichen');
		abbrechen('haendler');
		abbrechen('plzort');
		abbrechen('identnummer');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showingfabrikat = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'fabrikat' && showingfabrikat) {
		abbrechen(typ);
	} else if (typ == 'kennzeichen' && !showingkennzeichen) {
		abbrechen('fabrikat');
		abbrechen('haendler');
		abbrechen('plzort');
		abbrechen('identnummer');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showingkennzeichen = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'kennzeichen' && showingkennzeichen) {
		abbrechen(typ);
	} else if (typ == 'haendler' && !showinghaendler) {
		abbrechen('fabrikat');
		abbrechen('kennzeichen');
		abbrechen('plzort');
		abbrechen('identnummer');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showinghaendler = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'haendler' && showinghaendler) {
		abbrechen(typ);
	} else if (typ == 'plzort' && !showingplzort) {
		abbrechen('fabrikat');
		abbrechen('kennzeichen');
		abbrechen('haendler');
		abbrechen('identnummer');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showingplzort = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'plzort' && showingplzort) {
		abbrechen(typ);
	} else if (typ == 'identnummer' && !showingidentnummer) {
		abbrechen('fabrikat');
		abbrechen('kennzeichen');
		abbrechen('haendler');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showingidentnummer = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'identnummer' && showingidentnummer) {
		abbrechen(typ);
	}
}
// for the new version
function showlist2(typ, id) {
	showingid = id;

	var theY = 300;
	if (currY) {
		theY = currY;
	}
	if (typ == 'fabrikat' && !showingfabrikat) {
		abbrechen('kennzeichen');
		abbrechen('haendler');
		abbrechen('plzort');
		abbrechen('identnummer');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showingfabrikat = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'fabrikat' && showingfabrikat) {
		abbrechen(typ);
	} else if (typ == 'kennzeichen' && !showingkennzeichen) {
		abbrechen('fabrikat');
		abbrechen('haendler');
		abbrechen('plzort');
		abbrechen('identnummer');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showingkennzeichen = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'kennzeichen' && showingkennzeichen) {
		abbrechen(typ);
	} else if (typ == 'haendler' && !showinghaendler) {
		abbrechen('fabrikat');
		abbrechen('kennzeichen');
		abbrechen('plzort');
		abbrechen('identnummer');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showinghaendler = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'haendler' && showinghaendler) {
		abbrechen(typ);
	} else if (typ == 'plzort' && !showingplzort) {
		abbrechen('fabrikat');
		abbrechen('kennzeichen');
		abbrechen('haendler');
		abbrechen('identnummer');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showingplzort = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'plzort' && showingplzort) {
		abbrechen(typ);
	} else if (typ == 'identnummer' && !showingidentnummer) {
		abbrechen('fabrikat');
		abbrechen('kennzeichen');
		abbrechen('haendler');
		MM_findObj(typ).style.visibility = 'visible';
		MM_findObj(typ).style.top = theY+"px";
		MM_findObj(typ).style.left = "420px";
		showingidentnummer = true;
		timeoutLayer = setTimeout("closeLayer("+typ+")", 1500);
	} else if (typ == 'identnummer' && showingidentnummer) {
		abbrechen(typ);
	}
}
function setname(name, typ, parameter1, parameter2, parameter3, parameter4, parameter5) {
	clearTimeout(timeoutLayer);
	if (typ == 'fabrikat') {
		document.main.positionen_fabrikat.value = name;
		abbrechen(typ);
	} else if (typ == 'kennzeichen') {
		document.main.positionen_kennzeichen.value = name;
		if (document.main.positionen_fabrikat) {
			if (parameter3.length) {
				document.main.positionen_identnummer.value = parameter3;
			}
			if (parameter1.length) {
				document.main.positionen_fabrikat.value = parameter1;
			}
		}
		abbrechen(typ);
	} else if (typ == 'haendler') {
		document.main.positionen_haendler.value = name;
		if (document.main.positionen_haendlerinfo) {
			if (parameter5.length) {
				document.main.positionen_haendlerinfo.value = parameter5;
			}
		}
		abbrechen(typ);
	} else if (typ == 'plzort') {
		document.main.positionen_haendlerinfo.value = name;
		abbrechen(typ);
	} else if (typ == 'identnummer') {
		document.main.positionen_identnummer.value = name;
		if (document.main.positionen_fabrikat) {
			if (parameter1.length) {
				document.main.positionen_fabrikat.value = parameter1;
			}
			if (document.main.positionen_kennzeichen) {
				if (parameter2.length) {
					document.main.positionen_kennzeichen.value = parameter2;
				}
			}
			
		}
		abbrechen(typ);
	}
}
function setname2(name, typ, parameter1, parameter2, parameter3, parameter4, parameter5) {
	//alert(showingid)
	clearTimeout(timeoutLayer);
	if (typ == 'fabrikat') {
		document.main.positionen_fabrikat.value = name;
		abbrechen(typ);
	} else if (typ == 'kennzeichen') {
		document.main.positionen_kennzeichen.value = name;
		if (document.main.positionen_fabrikat) {
			if (parameter3.length) {
				document.main.positionen_identnummer.value = parameter3;
			}
			if (parameter1.length) {
				document.main.positionen_fabrikat.value = parameter1;
			}
		}
		abbrechen(typ);
	} else if (typ == 'haendler') {
		document.main.positionen_haendler.value = name;
		if (document.main.positionen_haendlerinfo) {
			if (parameter5.length) {
				document.main.positionen_haendlerinfo.value = parameter5;
			}
		}
		abbrechen(typ);
	} else if (typ == 'plzort') {
		document.main.positionen_haendlerinfo.value = name;
		abbrechen(typ);
	} else if (typ == 'identnummer') {
		document.main['positionen_identnummer_'+showingid].value = name;
		//document.main.positionen_identnummer.value = name;
		if (document.main.positionen_fabrikat) {
			if (parameter1.length) {
				document.main.positionen_fabrikat.value = parameter1;
			}
			if (document.main.positionen_kennzeichen) {
				if (parameter2.length) {
					document.main.positionen_kennzeichen.value = parameter2;
				}
			}
			
		}
		abbrechen(typ);
	}
}
function abbrechen(typ) {
	if (typ == 'fabrikat') {
		showingfabrikat = false;
		/*
		if (document.main.positionen_fabrikat){
			document.main.positionen_fabrikat.focus();
		}
		*/
	} else if (typ == 'kennzeichen') {
		showingkennzeichen = false;
		/*
		if (document.main.positionen_kennzeichen) {
			document.main.positionen_kennzeichen.focus();
		}
		*/
	} else if (typ == 'haendler') {
		showinghaendler = false;
		/*
		if (document.main.positionen_haendler) {
			document.main.positionen_haendler.focus();
		}
		*/
	} else if (typ == 'plzort') {
		showingplzort = false;
		/*
		if (document.main.positionen_haendlerinfo) {
			document.main.positionen_haendlerinfo.focus();
		}
		*/
	} else if (typ == 'identnummer') {
		showingidentnummer = false;
		/*
		if (document.main.positionen_identnummer) {
			document.main.positionen_identnummer.focus();
		}
		*/
	}

	MM_findObj(typ).style.visibility = 'hidden';
}
function startTimeout(typ) {
	timeoutLayer = setTimeout("closeLayer("+typ.id+")", 500);
}
function closeLayer(typ) {
	abbrechen(typ.id);
	MM_findObj(typ.id).style.visibility = 'hidden';
}
// Reifenpositionen
// ---------------------------------------------------------










var selobj = null;
function pselect(obj, id) {
	if (selobj) {
		selobj.className = "pout";
		selobj.tmpClassName = "pout";
	}
	selobj = obj;

	obj.className="psHilightBlack";
	obj.tmpClassName = "psHilightBlack";

	document.register.sp.value = id;
}



function checkMail(email) {
	var allowed = "deutschepost.de, deutsche-post.de, deutschepost.com, deutsche-post.com, dhl.com, dhl.de, partner-store.com, partner-store.de, postbank.de, postbank.com, cmb-communications.com, kohv.com";
	email = email.toLowerCase();
	email = email.split('@');
	if (email.length != 2) {
		return false;
	} else {
		if (allowed.indexOf(email[1]) == -1){
			return false;
		}
	}
	return true;
}




var selobj2 = null;
function pselect2(id, url) {
	
	obj = MM_findObj('nl'+id);

	if (selobj2) {
		selobj2.className = "psSearchP0";
		selobj2.tmpClassName = "psSearchP0";
	}
	selobj2 = obj;

	obj.className="psHilightBlack";
	obj.tmpClassName = "psHilightBlack";

	document.main.nlid.value = id;
}

function hilightMe(obj, onoff) {
	if (onoff == 1) {
		obj.tmpClassName = obj.className;
		obj.className = "psHilight";
	} else {
		obj.className = obj.tmpClassName;
	}
}

function hilightMe2(obj, onoff) {
	if (onoff == 1) {
		obj.tmpClassName = obj.className;
		obj.className = "psHilightBlack";
	} else {
		obj.className = obj.tmpClassName;
	}
}

// Form checks




function partner_nichtgefunden() {
	var f = document.register;
	f.go.value = 'nichtgefunden1';
	f.submit();
}




function partner_zurueck2() {
	var f = document.register;
	f.go.value = 'backtoregister1';
	f.submit();
}

function partner_zurueck3() {
	var f = document.register;
	f.go.value = 'backtoregister2';
	f.submit();
}



// have to insert username and email


// Register screen
function p_register() {
	document.login.go.value = 'register';
	document.login.submit();
}

// Forgot password screen
function p_password() {
	document.login.go.value = 'password';
	document.login.submit();
}


function openAWindow( pageToLoad, winName, width, height, center) {
  xposition=0; yposition=0;
  if ((parseInt(navigator.appVersion) >= 4 ) &&(center)) {
   xposition = (screen.width - width) / 2;
   yposition = (screen.height - height) / 2;
  }
  args = "width=" + width + ","
  + "height=" + height + ","
  + "location=0,"
  + "menubar=1,"
  + "resizable=1,"
  + "scrollbars=1,"
  + "status=0,"
  + "titlebar=1,"
  + "toolbar=1,"
  + "hotkeys=0,"
  + "screenx=" + xposition + "," //NN Only
  + "screeny=" + yposition + "," //NN Only
  + "left=" + xposition + "," //IE Only
  + "top=" + yposition; //IE Only
  window.open( pageToLoad, winName, args );
}
// add and remove thousands separators
function addCommas( sValue ) {

//	var f=sValue;
	sValue = String(sValue);

	//sValue = String(sValue).split(',');
	//sValue = sValue.join('|');

	//alert("d:"+sValue)

	var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'); 
	while(sRegExp.test(sValue)) { 
		sValue = String(sValue).replace(sRegExp, '$1|$2');
	}

	sValue = sValue.split('.');
	sValue = sValue.join(',');

	sValue = sValue.split('|');
	sValue = sValue.join('.');

//	alert('Add: '+f+'=>'+sValue);

	return sValue; 
}
function removeCommas( sValue ) {

//	var f=sValue;

	sValue = String(sValue).split(',');
	sValue = sValue.join('|');



/*
	var sRegExp = new RegExp('/\./');
	while(sRegExp.test(sValue)) { 
		sValue = String(sValue).replace(sRegExp, '');
	}*/

	sValue = sValue.split('.');
	sValue = sValue.join('');

	sValue = sValue.split('|');
	sValue = sValue.join('.');

//	alert('Remove: '+f+'=>'+sValue);

	return sValue;
}

//alert(addCommas('500.10'));

/*
function addCommas( sValue ) { 
	var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'); 
	while(sRegExp.test(sValue)) { 
		sValue = String(sValue).replace(sRegExp, '$1,$2');
	}
	return sValue; 
}
function removeCommas( sValue ) {
	var sRegExp = new RegExp(',');
	while(sRegExp.test(sValue)) { 
		sValue = String(sValue).replace(sRegExp, '');
	}
	return sValue;
}
*/

// netto + ust = brutto
function addFields(one, two, target) {
	//target.value = parseInt(one.value,10) + parseInt(two.value,10);
	var v = Number(one.value) + Number(two.value);
	v = v*100;
	v = Math.round(v);
	v = v/100;

	if (Math.round(v) == v) {
		v = String(v)+'.00';
	}


	target.value = v;
}

function subFields(one, two, target) {
	//target.value = parseInt(one.value,10) + parseInt(two.value,10);
	var v = Number(one.value) - Number(two.value);
	v = v*100;
	v = Math.round(v);
	v = v/100;

	if (Math.round(v) == v) {
		v = String(v)+'.00';
	}

	target.value = v;
}


/*
##################################
# open/close items with arrow
##################################
*/
function pfeil() {

	// passed external arguments
	if (pfeil.arguments.length>0) {
		
		var n1 = 1;
		for (var t=0; t<pfeil.arguments.length/2 ;t++ ) {

			if (eval("document.main.getVar"+n1) != null) {
				while (eval("document.main.getVar"+n1).value.length>0) {
					n1++;
				}
			}

			// transform the arguments into variables and values
			eval("document.main.getVar"+n1).value = pfeil.arguments[(n1-1)*2];
			eval("document.main.getVal"+n1).value = pfeil.arguments[(n1*2)-1];
		}
	}

	// try to submit the form
	if (save(document.main, 'main')) {
		document.main.submit();
	}
}



// DeleteObject
function dObj(loc, id, session) {
	if (confirm("Sind Sie sicher, dass Sie dieses Objekt wirklich löschen wollen?\nEs ist nicht rückgängig machbar!")) {
		//alert("Löschen funktioniert gerade nicht!");
		window.location.href="?l="+loc+"&rid="+id+"&"+session;
	}
}


function dDisabled() {
	window.status = 'Menüfunktion nicht gestattet!';
}



// General Save Function
var savedalready = false;
function save(obj, objname) {
	var returnval = true;
	if (savedalready) {
		returnval = false;
		savedalready = false;
		//alert('Sie haben zwei Mal Speichern gedrückt.\n\nNur das erste Versuch wird akzeptiert!');
	}
	obj.id.disabled = false;

	// Check for custom processing functions
	if (returnval == true) {
		if (submit_handler) {
			returnval = submit_handler(objname);
		}
	}

	// Allow only one click
	if (returnval == true) {
		obj.Submit.disabled = true;
		savedalready = true;
	}
	return returnval;
}

// Search results
function sresults(nr) {
	document.searchform.sstart.value = nr;
	document.searchform.submit();
}

function closewindow() {
	if (confirm("Wollen Sie wirklich das Fenster schließen?\nDie Änderungen werden nicht gespeichert!")) {
		top.close();
	}
}

// converts all commas (,) to points (.) in currencies because SQL handles only points as separators
function sqlValue(obj) {
	var v = String(obj.value);
	if (v.indexOf(",") != -1) {
		var a=v.split(",");
		v=String(a[0]+"."+a[1]);
		obj.value=v;
	}
}
// null function
function nll() {
}
/*
// Browser version check
function Is () {
	var agt=navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);

	this.mac = agt.indexOf('mac') != -1;
	this.ie = agt.indexOf('msie') != -1;
	this.mz = agt.indexOf('gecko') != -1;
	this.win = agt.indexOf('win') != -1;

	// debugging only
	window.status = agt;
}
*/



