function CountSigns(Text)
{
	Text = Text.value;
    Text = Text.replace(/\@/g, '00');
    Text = Text.replace(/\£/g, '00');
    Text = Text.replace(/\$/g, '00');
    Text = Text.replace(/ß/g, '00');
    Text = Text.replace(/\{/g, '00');
    Text = Text.replace(/\}/g, '00');
    Text = Text.replace(/\[/g, '00');
    Text = Text.replace(/\]/g, '00');
    Text = Text.replace(/\|/g, '00');
    Text = Text.replace(/§/g, '00');
    Text = Text.replace(/€/g, '00');
    Text = Text.replace(/\^/g, '00');
    return Text.length;
}

/*
 Checks the length of a string. If length is to short an error message will be showed.

 object oVal 		= 	String, which will be checked
 integer iLength    = 	Minimum length
 sMessage 			= 	Alert message which will be showed
*/
function checkStringLength(oVal, iLength, sMessage)
{
	if( typeof(oVal) == "object" && CountSigns(oVal) < iLength )
	{
		if( sMessage != "" )
		{
			alert(sMessage);
		}

		oVal.select();
		oVal.focus();
		return false;
	} else if( typeof(oVal) == "object" && CountSigns(oVal) >= iLength ) {
		return true;
	}

}

/*
 Checks if two strings are equal

 string sValOne 	= 	First string, wich will be checked
 string sValTwo 	= 	Second string, wich will be checked
 sMessage 			= 	Alert message which will be showed
*/
function compareStrings(sValOne, sValTwo, sMessage)
{
	if(sValOne.value != sValTwo.value)
	{
		if(sMessage != "")
		{
			alert(sMessage);
		}

		sValOne.select();
		sValOne.focus();
		return false;
	} else {
		return true;
	}
}

function CountSms(num_signs)
{
    if (num_signs > 160)
    {
        return Math.ceil(num_signs/152);
    }
    
    return 1;
}

function changeAllCheckboxes(checkboxname, boxChecked) {
    allCheckboxes = document.getElementsByName(checkboxname);
    for (i = 0; i < allCheckboxes.length; i++) {
        allCheckboxes[i].checked = boxChecked;
    }
}

function confirmMessage(message)
{
    Check = confirm( message );
    return Check;
}

/*
Open a new popup
URL         =   URL, which will be showed in the popup
winName     =   Name of the popup
winWidth    =   Width of the popup
winHeight   =   Height of the popup
Params   	=   Array with additional parameters, which will be available in the new popup as GET php variables
options 	=	Popup options like scrollbar = yes/no, status = yes/no, ...
*/
function openPopup(URL, winName, winWidth, winHeight, aParams, options)
{
	var link_addition = "";

	if (typeof aParams == 'object')
	{
        for (var Key in aParams)
        {
            if (typeof aParams[Key] != 'function') {
        	    link_addition = link_addition + '&' + Key + '=' + aParams[Key];
            }
        }

        var mkURL = URL + '?' + link_addition;

    } else {

		var mkURL = URL;

    }

    var breite = (screen.width - winWidth)/2;
    var hoehe = (screen.height - winHeight)/2 - 60;
    var features = 'width='+winWidth+',height='+winHeight+',top='+hoehe+',left='+breite;
    if(options != '') { features = features+','+options; }
    var popup = window.open(mkURL, winName, features);
    popup.focus();
    return popup;
}

function setCSS (hiddenname, clicked, aButtons)
{
    var sButton;
    for (var i = 0; i < aButtons.length; i++)
    {
        sButton = aButtons[i];
        if(sButton == clicked)
        {
            document.getElementById(sButton).style.display = "block";

        }
        else
        {
            document.getElementById(sButton).style.display = "none";
        }
    }
    document.getElementById(hiddenname).value = clicked;
}

function trim(value)
{
    while (value.substring(0,1) == ' ')
    {
        value = value.substring(1, value.length);
    }

    while (value.substring(value.length-1, value.length) == ' ')
    {
        value = value.substring(0, value.length-1);
    }

    return value;
}

function in_array (haystack, needle, recursive) {
    for (var key in haystack) {
        if (typeof(haystack[key]) == 'object' && recursive) {
            return in_array(haystack[key], needle);
        } else {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
    return false
}
