// The next lines are not actually used but may be useful later if isLetter is updated
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

var whitespace = " \t\n\r";
var decimalPointDelimiter = "."

var defaultEmptyOK = false

function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29; 
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
    return returnString;
}

function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}

function stripInitialWhitespace (s)
{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    return s.substring (i, s.length);
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

function isAlphabetic (s)
{   var i;
    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isLetter(c))
        return false;
    }
    return true;
}

function isAlphanumeric (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }
    return true;
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    return ((s.length == 2) || (s.length == 4));
}

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);
    if (!isInteger(s, false)) return false;
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}
function daysInFebruary (year)
{   return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isDate (year, month, day)
{   if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);
    if (intDay > daysInMonth[intMonth]) return false; 
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
    return true;
}

function getRadioButtonValue (radio)
{   for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { break }
    }
    if ( i == radio.length )
		return 0;
    return radio[i].value
}

function isPhoneNum(str) {
otherchars="+-/ " + digits
if (isWhitespace(str)) return false;
if (str.length<5) { return false }
  for (j=0; j<str.length; j++) {
      if (otherchars.indexOf(str.charAt(j)) ==-1){ return false}
    }
  return true;
}


function SubmitDetailForm(cmd, checkFnkt)
{
	var formnr = 0;
	if (checkFnkt == true)
	{
		if (cmd == 'SAVECLOSE') document.forms[formnr].IGNORE_CMD.value = 'SAVECLOSE';
		document.forms[formnr].submit();
		return true;
	}
	else
		return false;
}

function isTextFieldEmpty(fname)
{
	var formnr = 0;
	if (isEmpty(document.forms[formnr].elements[fname].value))
	{
		alert(notEmpty);
		document.forms[formnr].elements[fname].focus();
		return true;
	}
	return false;
}

function isTextFieldValidEmail(fname)
{
	var formnr = 0;
	if (!isEmail(document.forms[formnr].elements[fname].value))
	{
		alert(invalidEMail);
		document.forms[formnr].elements[fname].focus();
		return true;
	}
	return false;
}

function isCheckedValidObject(checkboxname, checkboxnr, objectname)
{
	var formnr = 0;
	if (document.forms[formnr].elements[checkboxname][checkboxnr].checked && document.forms[formnr].elements[objectname].value == 0)
	{
		alert(selErr);
		document.forms[formnr].elements[objectname].focus();
		return false;
	}
	return true;
}

function locateObject(n, d) {
  var p,i,x;  
  if(!d) d = document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=locateObject(n,d.layers[i].document); return x;
}

function hideTooltip(object) {
if (document.all) {
	locateObject(object).style.visibility="hidden"
	locateObject(object).style.left = 1;
	locateObject(object).style.top = 1;
	return false;
}
else if (document.layers) {
	locateObject(object).visibility="hide"
	locateObject(object).left = 1;
	locateObject(object).top = 1;
	return false;
}
else
	return true;
}

function showTooltip(object, e, tipContent) {
	var backcolor = '#ffff99'
	var bordercolor = '#000000'
	var textcolor = '#000000'
	if (document.all) {
			locateObject(object).style.top=document.body.scrollTop+event.clientY+20
			locateObject(object).innerHTML='<table style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; border: '+bordercolor+'; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; background-color: '+backcolor+'" width="10" border="0" cellspacing="1" cellpadding="1"><tr><td nowrap><font style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; color: '+textcolor+'">'+unescape(tipContent)+'</font></td></tr></table> '
			if ((e.x + locateObject(object).clientWidth) > (document.body.clientWidth + document.body.scrollLeft)) {	
					locateObject(object).style.left = (document.body.clientWidth + document.body.scrollLeft) - locateObject(object).clientWidth-10;
			}
			else {
				locateObject(object).style.left=document.body.scrollLeft+event.clientX
			}
		locateObject(object).style.visibility="visible"
	}
	else if (document.layers) {
		locateObject(object).document.write('<table width="10" border="0" cellspacing="1" cellpadding="1"><tr bgcolor="'+bordercolor+'"><td><table width="10" border="0" cellspacing="0" cellpadding="2"><tr bgcolor="'+backcolor+'"><td nowrap><font style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; color: '+textcolor+'">'+unescape(tipContent)+'</font></td></tr></table><td></tr></table>')
		locateObject(object).document.close()
		locateObject(object).top=e.y+20
		if ((e.x + locateObject(object).clip.width) > (window.pageXOffset + window.innerWidth))	{
				locateObject(object).left = window.innerWidth - locateObject(object).clip.width-10;
			}
		else {
			locateObject(object).left=e.x;
			}
		locateObject(object).visibility="show"
	}
	else
	{
		return true;
	}
}

function getSelectedLanguage()
{
	for (var count = 0;count < document.f_edit.IGNORE_LANGDDSPRACHE.length; count++)
		if (document.f_edit.IGNORE_LANGDDSPRACHE[count].selected == true)
			return document.f_edit.IGNORE_LANGDDSPRACHE[count].value;
	return 0;
}
function checkURL(objURL){
		strUpperURL = objURL.value.toUpperCase()
		if (strUpperURL.substring(0,4) == "WWW."){
			objURL.value = "http://" + objURL.value
		}
	}
function stripInitialZero (s)
{   var i = 0;
    while ((i < s.length) && s.charAt(i) == "0")
       i++;
    return s.substring (i, s.length);
}	
	
function isTextDate( sDate ){
	arrDate = sDate.split(".")
	if (arrDate.length != 3) return false;
	return (isDate(stripInitialZero(arrDate[2]), stripInitialZero(arrDate[1]), stripInitialZero(arrDate[0])));		
}
