var whitespace = " \t\n\r";

function isEmail(s)
    {
    var s = s.replace(String.fromCharCode(228), "a");
    var s = s.replace(/ /g, "");
    var s = s.replace(/\(at\)/g, "@"); 
    var s = s.replace(/\[at\]/g, "@"); 
    if (isEmpty(s))
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);

    // is s whitespace?
    if (isWhitespace(s)) return false;

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
        { 
        i++;
        }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
        { 
        i++;
        }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
    }

function isDecimal(sNum)
    {
    return !isNaN(sNum!="" && sNum);
    }
    

function isWhitespace (s)
{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


function getRadioValue(rb)
{
var L=rb.length;var ret="";
for (var i = 0 ; i< L ; i++)
 { if(rb[i].checked) { ret=rb[i].value; break; } }
return(ret);
}


function email(strAddress, strLink, strTitle, strSubject)
{
  var arrAddress     = strAddress.split(",");
  var arrLink        = strLink.split(",");
  var arrTitle       = strTitle.split(",");
  var encodedAddress = "";
  var encodedLink    = "";
  var encodedTitle   = "";
  var result         = "";
  if (isEmpty(strSubject))
        {
        strSubject = "";
        }
  else
        {
        strSubject = "?subject=" + strSubject;
        }
  for (i=0;i<arrAddress.length;i++) encodedAddress = encodedAddress + "&#" + arrAddress[i];
  for (i=0;i<arrLink.length;i++) encodedLink = encodedLink + "&#" + arrLink[i];
  for (i=0;i<arrTitle.length;i++) encodedTitle = encodedTitle + "&#" + arrTitle[i];
  result = "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;" + encodedAddress + strSubject + "\" title=\"" + encodedTitle + "\">" + encodedLink + "<\/a>";
  document.write(result);
  return result; // not necessarily needed, but nice to have just in case
}


function left(str, n)
    {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0,n);
    }

function right(str, n)
    {
    if (n <= 0)
        return "";
    else
        if (n > String(str).length)
        return str;
        else
        {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
        }
    }

function mysqldate(str)
    {
    if (str.length != 10)
        return str;
    else
        return right(str, 4) + "-" + str.substring(3, 5) + "-" + left(str, 2);
    }


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
        var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
        var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
        // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
        for (var i = 1; i <= n; i++) {
                this[i] = 31
                if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
                if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr){
        var daysInMonth = DaysArray(12)
        var pos1=dtStr.indexOf(dtCh)
        var pos2=dtStr.indexOf(dtCh,pos1 + 1)
        var strDay=dtStr.substring(0, pos1)
        var strMonth=dtStr.substring(pos1 + 1, pos2)
        var strYear=dtStr.substring(pos2 + 1)
        strYr=strYear
        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
        for (var i = 1; i <= 3; i++) {
                if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
        }
        month=parseInt(strMonth)
        day=parseInt(strDay)
        year=parseInt(strYr)
        if (pos1==-1 || pos2==-1){
//                alert("The date format should be : mm/dd/yyyy")
                return false
        }
        if (pos1!=2 || pos2!=5){
//                alert("The date format should be : mm/dd/yyyy")
                return false
        }
        if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
//                alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
                return false
        }
        if (strMonth.length<1 || month<1 || month>12){
//                alert("Please enter a valid month")
                return false
        }
        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
//                alert("Please enter a valid day")
                return false
        }
        if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
//                alert("Please enter a valid date")
                return false
        }
return true
}


function trim(argvalue)
    {
    var argvalue = ltrim(argvalue);
    var argvalue = rtrim(argvalue);
    return argvalue;
    }

function rtrim(argvalue)
    {
    if (undefined == argvalue)
        {
        var argvalue = "";
        }
    while (1)
        {
        if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
            break;
        argvalue = argvalue.substring(0, argvalue.length - 1);
        }
    return argvalue;
    }

function ltrim(argvalue)
    {
    if (undefined == argvalue)
        {
        var argvalue = "";
        }
    while (1)
        {
        if (argvalue.substring(0, 1) != " ")
            break;
        argvalue = argvalue.substring(1, argvalue.length);
        }
    return argvalue;
    }


function occurs(arg_str, arg_chr)
    {
    if (undefined == arg_str)
        {
        var arg_str = "";
        }
    var i = 0;
    var anzahl = 0;
    var sLength = arg_str.length;
    while (i < sLength)
        {
        i++;
        if(arg_str.charAt(i) == arg_chr)
            {
            anzahl++;
            }
        }
    return anzahl;
    }


function feld(arg_str, arg_chr, arg_no)
    {
    var string_array = arg_str.split(arg_chr);
    return string_array[arg_no - 1];
    }

function padl(arg_str, arg_chr, arg_no)
    {
    i = 0;
    pad_str = "";
    while (i < 100)
        {
        pad_str = pad_str + arg_chr;
        i++;
        }
    arg_str = ltrim("" + arg_str);
    arg_str = right(pad_str + arg_str, arg_no);
    return arg_str;
    }
    
    
function myTrim(feld)
    {
    feld.value = trim(feld.value);
    }


function check_date(arg_field)
    {
    var datum_ok = "";
    arg_field.value = trim(arg_field.value);
    t_anzahl = occurs(arg_field.value, ".");
    if(t_anzahl == 2)
        {
        tag = feld(arg_field.value, ".", 1);
        monat = feld(arg_field.value, ".", 2);
        jahr = feld(arg_field.value, ".", 3);
        if(!isNaN(tag) && !isNaN(monat) && !isNaN(jahr))
            {
            tag = parseInt(tag, 10);
            monat = parseInt(monat, 10);
            jahr = parseInt(jahr, 10);
            if(jahr < 100) {jahr = jahr + 2000;}
            if(tag > 0 && tag < 32 && monat > 0 && monat < 13 && jahr > 2004 && jahr < 3000)
                {
                datum_neu = padl(tag, "0", 2) + "." + padl(monat, "0", 2) + "." + jahr;
                arg_field.value = datum_neu;
                datum_ok = "OK";
                }
            }
        }
    return datum_ok;
    }

	
function validateDateField(event)
    {
    if(window.event)
    key = window.event.keyCode;
    else
    if(event)
    key = event.which;
    else
    return true;
    if((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
        {
        return true;
        }
    else
//    if(key == 118 && event.ctrlKey)
//{
//return true;
//}
//    else
    if(key == 46)
        {
        return true;
        }
    else
    if(key > 47 && key < 58)
        {
        return true;
        }
    else
        {
        return false;
        }
    }

function validateDecField(event)
    {
    if(window.event)
        key = window.event.keyCode;
    else
    if(event)
        key = event.which;
    else
        return true;
    if((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
        {
        return true;
        }
    else
    if(key == 44 || key == 46)
        {
        return true;
        }
    else
    if(key > 47 && key < 58)
        {
        return true;
        }
    else
        {
        return false;
        }
    }


function validateIntField(event)
    {
    if(window.event)
        key = window.event.keyCode;
    else
    if(event)
        key = event.which;
    else
        return true;
    if((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
        {
        return true;
        }
    else
    if(key > 47 && key < 58)
        {
        return true;
        }
    else
        {
        return false;
        }
    }


function validateTimeField(event)
    {
    if(window.event)
        key = window.event.keyCode;
    else
    if(event)
        key = event.which;
    else
        return true;
    if((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
        {
        return true;
        }
    else
    if(key == 58)
        {
        return true;
        }
    else
    if(key > 47 && key < 58)
        {
        return true;
        }
    else
        {
        return false;
        }
    }


function entsub(myform)
    {
    if(window.event && window.event.keyCode == 13)
        myform.submit();
    else
        return true;
    }


function resizeWindow(img)
    {
    if(img.width < 600)
        window.resizeTo(800, img.height + 230);
    else
    if(img.height > 700)
        window.resizeTo(img.width + 100, 700);
    else
        window.resizeTo(img.width + 100, img.height + 250);
    }


function NewWindow(url, width, height, from_left, from_top)
    {
    title = "";
    from_left = from_left || 100;
    from_top = from_top || 100;
    win_parameters = "scrollbars=yes, toolbar=no, width=" + width + ", height=" + height + ", left=" + from_left + ", top=" + from_top;
    void window.open(url, title, win_parameters);
    }
    
	
function radioWert(rObj) 
    {
    for (var i = 0; i < rObj.length; i++)
		if (rObj[i].checked) 
			return rObj[i].value;
    return false;
    }
	
function arrMax(my_arr)
    {
    var max = Number.MIN_VALUE;
    for (i = 0; i < my_arr.length; ++i)
    if(typeof(v = my_arr[i]) == 'number')
    max = Math.max(max, v);
    return max;
    }

function arrMin(my_arr)
    {
    var min = Number.MAX_VALUE;
    for (i = 0; i < my_arr.length; ++i)
    if(typeof(v = my_arr[i]) == 'number')
    min = Math.min(min, v);
    return min;
    }

    
