/**
 * Projekt Sunny-Portal 
 * 21.12.2004
 * Dirk Schlote
 */
 
// Opens the given target (url) in a new window
function OpenHelpWindow(test) {
    var ret = window.open(test, "SunnyPortalHelp", "width=635,height=480,scrollbars=yes, resizable=yes");
    ret.focus();
}

// Opens the given target (url) in a new window
function OpenPublicPageWindow(test) {
    var ret = window.open(test, "SunnyportalPublicPage", "width=1024,height=768,scrollbars=yes,resizable=yes,menubar=no,status=no,toolbar=no,location=no");
    ret.focus();
}

// Opens the given target (url) in a new window
function OpenWebBoxWindow(test) {
    var ret = window.open(test, "SunnyWebBox","scrollbars=yes,resizable=yes,menubar=yes,status=yes,toolbar=yes,location=yes");
    ret.focus();
}

// Creates a cookie
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// Reads a cookie
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// Erase a cookie
function eraseCookie(name)
{
	createCookie(name,"",-1);
}

// min and max for diagram configuration

function SetDisable(what, text)
{
 
       //alert("SetDisable");
        var  my_id = what.id;
        var igt="igtxtx";
        var count_id = my_id.length - 8;
        var  my_id_new = my_id.substring(0,count_id);
        var text_id = my_id_new.concat(text); 
        var text_id_show = igt.concat(text_id);    
        var textValueID = document.getElementById(text_id_show); 
        var textValueID_hide = document.getElementById(text_id); 
        var numTBElement = document.getElementById(text + "_numTB"); 
        var numTBElement_hidden = document.getElementById(text + "_numTB_hidden"); 
        if(what.checked)
        {   
           if (textValueID) //alte IGformerly-Komponente
           {
               textValueID.value = "";  
               textValueID_hide.value = "";
               //textValueID.disabled = true;
               //textValueID.visibility == "hide";
           }
           if (numTBElement) //neue eigene Komponente
           {
               numTBElement.value = "";  
               numTBElement_hidden.value = "";
               numTBElement.disabled = true;
               //numTBElement.visibility == "hide";
           }
           what.focus();

        }
        else
        {
           if (textValueID) //alte IGformerly-Komponente
           {
               //textValueID.disabled = false;
               //textValueID.visibility = "show";
               textValueID.focus();
           }
           if (numTBElement) //neue eigene Komponente
           {
               numTBElement.disabled = false;
               //numTBElement.visibility = "show";
               numTBElement.focus();
           }
        }
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function CheckMailFormat(input, separator) {
    var checkOK = true;
    if (input.length <= 0) {
        checkOK = false;
    }
    else if (separator != "") {
        var mailArray = input.split(separator);
        var totalResult = true;
        for (var i = 0; i < mailArray.length; i++) {
            var tmpMail = mailArray[i];
            if (tmpMail.substring(0, 1) == " ")
                tmpMail = tmpMail.substring(1);
            if (!CheckMailFormat(tmpMail, "")) {
                totalResult = false;
                break;
            }
        }
        return totalResult;
    }
    else {
        if (input.indexOf("@") < 1)
            checkOK = false;
        else if (input.indexOf("@.") >= 0)
            checkOK = false;
        else if (input.indexOf(".@") >= 0)
            checkOK = false;
        else if (input.indexOf("@-") >= 0)
            checkOK = false;
        else if (input.indexOf("..") >= 0)
            checkOK = false;
        else if (input.indexOf(".") <= 0)
            checkOK = false;
        else if (input.lastIndexOf(".") > input.length - 3)
            checkOK = false;
        else if (input.lastIndexOf(".") < input.length - 5)
            checkOK = false;
        else if (input.lastIndexOf("-") > input.length - 5)
            checkOK = false;
        else if (input.lastIndexOf("_") > input.length - 5)
            checkOK = false;
        else if (input.indexOf("@") > input.length - 5)
            checkOK = false;
        else if (input.lastIndexOf("@") > input.indexOf("@"))
            checkOK = false;
        else if (input.indexOf("www.") == 0)
            checkOK = false;
        else if (input.indexOf("@t.-online.de") >= 0)
            checkOK = false;
        else if (input.indexOf("@aol.de") >= 0)
            checkOK = false;
    }
    return checkOK;
}

function CheckKeyMail(event, charArray) {
    var allowedChar = new Array(45, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 95, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122);
    //allowedChar: 45="bindestrich", 46="punkt", 48-57="null-neun", 64="klammeraffe", 65-90="A-Z", 95="unterstrich", 97-122="a-z"
    if (typeof charArray != "undefined") {
        allowedChar = allowedChar.concat(charArray);
    }
    return CheckKeyCode(event, allowedChar);
}

function CheckKeyCode(event, allowedChar) {
    var charOK = false;
    if (event.charCode == 0) //d.h. Navigationstaste unter Netscape, dann OK
        return true;
    // gedrücktes Zeichen einlesen (verschiedene Browser benutzen verschiedene Befehle)
    var currentChar = event.keyCode ? event.keyCode : event.charCode ? event.charCode : event.which;
    if (currentChar > 255) //d.h. Navigationstaste unter Opera, dann OK
        return true;
    if (currentChar)
        for (var i in allowedChar) {
        if (allowedChar[i] == currentChar)
            charOK = true;
    }
    return charOK;
}