
/*
    created 02.11.2005
    author: Christoph Schnieder <mail@intanet.de>
    for more information visit http://intanet.de
*/

// called from body on load
function executeOnLoad()
{
    breakOut();
    
    /* initiate the right status
	if (isset(document.getElementById('day').value) &&
		isset(document.getElementById('month').value) &&
		isset(document.getElementById('year').value)) {
    checkAge(document.getElementById('day').value,
             document.getElementById('month').value,
             document.getElementById('year').value);
	}*/
}

// break out of frames
function breakOut()
{
    if (top != self) {
        top.location = self.location;
    }
}

// change size of an element
function changeSize($id, $width, $height)
{
    if ($width != '') {
        document.getElementById($id).style.width = $width;
    }
    if ($height != '') {
        document.getElementById($id).style.height = $height;
    }
}

// show/hide subnavigation
function subnav($id, $state)
{
    switch ($state) {
        case 'hide':
            window.setTimeout('changeState("' + $id + '", "' + $state + '")', 1000);
            break;
        case 'show':
            changeState($id, $state);
            break;
        default:
            changeState($id);
            break;
    }
}

// display element if age under 18
function checkAge($day, $month, $year)
{
    var $now = new Date();
    var $checkdate = new Date($now.getFullYear() - 18, $now.getMonth(), $now.getDate());
    var $birthdate = new Date($year, $month - 1, $day);
    
    var $check = Date.parse($checkdate);
    var $birth = Date.parse($birthdate);
    
    if ($birthdate >= $checkdate) {
        toggleVisibility('under18', 'show');
    } else {
        toggleVisibility('under18', 'hide');
    }
}

// show/hide html elements
function toggleVisibility($id, $state, $visible)
{
    if (!$visible) {
        var $visible = 'block';
    }
    switch ($state) {
        case 'hide':
            document.getElementById($id).style.display = 'none';
            break;
        case 'show':
            document.getElementById($id).style.display = $visible;
            break;
        default:
            if (document.getElementById($id).style.display == 'none') {
                document.getElementById($id).style.display = $visible;
            } else {
                document.getElementById($id).style.display = 'none';
            }
            break;
    }
}

// set cookie
function setCookie(name, value, domain, expires, path, secure)
{
    var cookie = "name=" + unescape(value);
    cookie += (domain) ? "; domain=" + domain : "";
    cookie += (expires) ? "; expires=" + expires : "";
    cookie += (path) ? "; path=" + path : "";
    cookie += (secure) ? "; secure" : "";
    document.cookie = cookie;
}

// get cookie
function getCookie(name)
{
    var cookie = document.cookie;
    
    // search for start of name-value-string
    var posName = cookie.indexOf("; " + name + "=");
    if (posName == -1) {
        // check if its the first
        if (cookie.indexOf(name + "=") == 0) {
            posName = 0;
        } else {
            return null;
        }
    }
    
    // search beginning and ending of the crumb
    var value_start = cookie.indexOf("=", posName) + 1;
    var value_end   = cookie.indexOf(";", posName + 1);
    if (value_end == -1) {
        value_end = cookie.length;
    }
    
    // read value from the crumb
    var value = cookie.substring(value_start, value_end);
    
    return unescape(value);
}

// get cookie
function getCookie2(name)
{
    // position in the cookie
    var i = 0;
    var search = name + "=";
    
    while (i < document.cookie.length) {
        if (document.cookie.substring(i, i + search.length) == search) {
            var end = document.cookie.indexOf(";", i + search.length);
            end = (end > -1) ? end : document.cookie.length;
            var cookie = document.cookie.substring(i + search.length, end)
            return unescape(cookie);
        }
        i++;
    }
    
    return null;
}

// erase cookie
function eraseCookie(name, domain, path)
{
    var cookie = "name=; expires=Thu, 01-Jan-70 00:00:01 GMT";
    cookie += (domain) ? "domain=" + domain : "";
    cookie += (path) ? "path=" + path : "";
    document.cookie = cookie;
}

// popup images in a new window (click image to close again)
function openWindow(imgPath, imgName, winName, winTitle, myWidth, myHeight, isCenter, features)
{
    if (!imgPath) {
        var imgPath = './images/';
    }
    
    if (window.screen && isCenter && isCenter == "true") {
        var myLeft = (screen.availWidth - myWidth) / 2;
        var myTop = (screen.availHeight - myHeight) / 2;
        var position = ',left=' + myLeft + ',top=' + myTop;
    }
    
    if (window.innerWidth) {
        var size = 'innerWidth=' + myWidth + ',innerHeight=' + myHeight;
    } else {
        var size = 'width=' + (myWidth - 4) + ',height=' + (myHeight - 4);
    }
    
    features += ((features != '') ? ', ' : '') + size + position;
    var imgURL = 'popup.php?path=' + imgPath + '&img=' + imgName + '&title=' + winTitle;
    
    if (window.winName) {
        window.winName.close();
    }
    
    window.winName = open(imgURL, winName, features);
    window.winName.focus();
}

// popup a new window
function openPopup(url, winName, myWidth, myHeight, isCenter, features)
{
    if (window.screen && isCenter && isCenter == "true") {
        var myLeft = (screen.availWidth - myWidth) / 2;
        var myTop = (screen.availHeight - myHeight) / 2;
        var position = ',left=' + myLeft + ',top=' + myTop;
    }
    
    if (window.innerWidth) {
        var size = 'innerWidth=' + myWidth + ',innerHeight=' + myHeight;
    } else {
        var size = 'width=' + (myWidth - 4) + ',height=' + (myHeight - 4);
    }
    
    features += ((features != '') ? ', ' : '') + size + position;
    
    if (window.winName) {
        window.winName.close();
    }
    
    window.winName = open(url, winName, features);
    window.winName.focus();
}