// JavaScript Document

var ie4 = false; if(document.all) { ie4 = true; }
function getObject(id) {
    if (ie4) {
        return document.all[id];
    } else {
        return document.getElementById(id);
    }
}

function toggle(Id) {

	var divId;
	var obj1;
	var obj2;
	var obj3;

	divId = 'ah_details' + Id;
	obj1 = getObject(divId);
	divId = 'toggle_' + Id;
	obj2 = getObject(divId);
	divId = 'help_' + Id;
	obj3 = getObject(divId);
	
	if((obj1) && (obj2)) {
		var lText = obj2.innerHTML; 
		if (lText.indexOf('plus.gif',1) >= 1) {
			obj2.innerHTML = '<img border="none" src="html/minus.gif" width="12" height="12">'; obj1.style.display = 'block';
		} else { obj2.innerHTML = '<img border="none" src="html/plus.gif" width="12" height="12">'; obj1.style.display = 'none';}
	}
	if(obj3) {
		if(obj3.style.display=='block')
		   obj3.style.display='none';
		else
		   obj3.style.display='block';
	}
}

function mCloseWin() {
	window.open('','_parent','');
	window.close();
}

function setCookie(c_name,value,expiredays) {
	date_now=new Date();
    date_exp=new Date(date_now.getTime()+expiredays*86400000);
    document.cookie=c_name+"="+value+";expires="+date_exp.toGMTString()+";";
}

function getCookie(c_name) {
	value="";
	if(document.cookie) {
		if (document.cookie.length>0) {
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1) { 
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				value=unescape(document.cookie.substring(c_start,c_end));
			} 
		}
	}
	return value;
}

function mOver(oObj) {
	oObj.style.backgroundColor='lightblue';
}
function mOut(oObj) {
	oObj.style.backgroundColor='#EAFFFF';
}
function mClick(theDuns,theField,theForm) {
	if (document.all) {
    	document.all(theField).value=theDuns;
		document.forms(theForm).submit();
	}
	else {
		document.getElementById(theField).value=theDuns;
		eval('document.forms.' + theForm).submit();
	}
}

function mPrevNext(theValue) {
	if (document.all) {
    	document.all('startat').value=theValue;
		document.forms('pagenav').submit();
	}
	else {
    	document.getElementById('startat').value=theValue;
		document.forms.pagenav.submit();
	}
}

function mFilterActive(val) {
	if (document.all) {
		if (val == 1) {
			document.all('detail_filter').value=1;
		}
		else {
			if (document.all('filter_active').checked) {
				document.all('detail_filter').value=1;
			}
			else {
				document.all('detail_filter').value=0;
			}
		}
		document.forms('reorder').submit();
	}
	else {
		if (val == 1) {
			document.getElementById('detail_filter').value=1;
		}
		else {
			if (document.getElementById('filter_active').checked) {
				document.getElementById('detail_filter').value=1;
			}
			else {
				document.getElementById('detail_filter').value=0;
			}
		}
		document.forms.reorder.submit();
	}
}

function mReOrder(theSort) {
	if (document.all) {
    	document.all('detail_sort').value=theSort;
		document.forms('reorder').submit();
	}
	else {
    	document.getElementById('detail_sort').value=theSort;
		document.forms.reorder.submit();
	}
}

function mShowPubs(theMax,theLfn) {
	if (document.all) {
    	document.all('pub_lfn').value=theLfn;
		document.all('pub_max').value=theMax;
		document.forms('showpubs').submit();
	}
	else {
    	document.getElementById('pub_lfn').value=theLfn;
		document.getElementById('pub_max').value=theMax;
		document.forms.showpubs.submit();
	}
}

function mSubmit(theForm) {
	if (document.all) {
		document.forms(theForm).submit();
	}
	else {
		eval('document.forms.' + theForm).submit();
	}
}

function mMonListAction(key, action) {
	if (document.all) {
		document.all('key').value=key;
		document.all('action').value=action;
		document.forms('change').submit();
	}
	else {
		document.getElementById('key').value=key;
		document.getElementById('action').value=action;
		document.forms.change.submit();
	}
}

function mShowReason() {
	window.open('html/shreasonfound.htm', 'db','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,width=600,height=400');
}

function IsEmail(inputString) {
	
	apos=inputString.indexOf("@"); 
	dotpos=inputString.lastIndexOf(".");
	lastpos=inputString.length-1;
	
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
		return false;
		}
	else {
		for(checkeml=0; checkeml<inputString.length; checkeml++) {
			if(notvalidemchar(inputString.charAt(checkeml))) {
				return false;
			}
		}
		return true;
	}
}

function notvalidemchar(tocheck) {
	// zugelassene sonderzeichen
	if((tocheck == '-') || (tocheck == '_') || (tocheck == '@') || (tocheck == '.')) {
		return false;
	}
	
	// buchstaben und zahlen sind erlaubt
	if(((tocheck >= 'A') && (tocheck <= 'Z')) || ((tocheck >= 'a') && (tocheck <= 'z')) || ((tocheck >= '0') && (tocheck <= '9'))) {
		return false;
	}

	// alles andere ist nicht erlaubt
	return true;
}

function checkminlength(str,minlng) {

	var arr
	var n
	
	// get an array of tokens
	arr = str.split(" ");
	
	// check each token length
	for(n=0 ; n<arr.length ; n++) {
		if(arr[n].length < minlng)
			return false;
	}
	return true;
}

function counttoken(str) {
  return str.split(' ').length;
}

function removedoublespace(str) {
	
	while(str.indexOf("  ")>=0) {
		str = str.replace("  "," ");
	}

	// return the string
	return str;
}

function checkrepeatedtoken(str) {

	var arr
	var n1
	var n2
	var cnt
	
	// get array of tokens
	arr = str.split(" ");
	
	// count each token in the array
	for(n1=0 ; n1<arr.length ; n1++) {
		cnt=0;
		for(n2=0 ; n2<arr.length ; n2++) {
			if(arr[n1].toLowerCase()==arr[n2].toLowerCase()) cnt++;
		}
		
		// if we have more than one ...
		if(cnt>1) return true;
	}
	
	// they are all unique
	return false;
}		

function removebadchars(str) {

	// definition of bad chars
	var badchars=getbadchars()
	var n=0;
	
	// replace all bad characters with a #
	for( n=0 ; n<badchars.length ; n++ ) {
		while(str.indexOf(badchars.charAt(n))>=0) {
			str = str.replace(badchars.charAt(n),"#");
		}
	}
	
	// remove all # and return new string
	while(str.indexOf("#")>=0) {
		str = str.replace("#","");
	}

	// return the string
	return str;
}

function getbadchars(spread) {
	if(spread) 
		return '¦ + @ * % & / ( ) = ? ° § | ~ ; , : { } [ ] _ "';
	else
		return '¦+@*%&/()=?°§|~;,:{}[]_"';
}

function isdatevalid(str) {

	var day=0
	var month=0
	var year=0
	var arr
	
	// get all values into an array
	arr = str.split(".");
	
	// we need 3 values
	if(arr.length != 3) return false;
	
	// read values
	day = arr[0];
	month = arr[1];
	year = arr[2];
	
	// check values
	if( (day<1) || (day>31) ) return false;
	if( (month<1) || (month>12) ) return false;
	if( (year<1990) || (year>2100) ) return false;

	// looks ok ...
	return true;
}

