﻿// ---------------------------------------------------------------------------
// PermissionManager
// ---------------------------------------------------------------------------

var PermissionManager = Class.create();

PermissionManager.prototype = {

    initialize: function(crypt)
    {
        this.crypt = crypt;
    },
    
    check: function(url)
    {
        if(typeof(window.getcrypt) == "function") 
        {
           this.crypt = getcrypt();
        }
	    if(this.crypt.length > 0)
	    {
	        window.location.href = url;
	    }
	    else
	    {
		    var w = window.open("/community/login/includes/form_login_popup.asp?startpage="+url,"Login","alwaysRaised=1,toolbar=0,location=0,scrollbars=no,menubar=0,resizable=no,status=0,width=520,height=485,left=200,top=200");
		    w.focus();
	    }
    }

}

// ---------------------------------------------------------------------------
// Navigation
// ---------------------------------------------------------------------------

function ChangeVisibility(id, visibility)
{
    if(document.getElementById(id).innerHTML.indexOf("<") > -1)
        document.getElementById(id).style.visibility=visibility;
}

function ChangeUrlParams(list)
{
    var util = new UrlUtility(document.location.href);
    var url = util.setUrlParamList(list);
    if(url != null)
        document.location.href= url;
}

function ChangeQueryStringParams(list)
{
    var util = new UrlUtility(document.location.href);
    var url = util.setQueryStringParamList(list);
    if(url != null)
        document.location.href= url;
}

function FollowAnchor(elementid)
{
    var anchor = $(elementid);
    if(anchor != null)
    {
        var url = anchor.readAttribute('href');
        if(url != null)
            window.location.href = url;
    }
}

// ---------------------------------------------------------------------------
// UserOnline
// ---------------------------------------------------------------------------

function ShowUserOnline()
{
    window.open("/community/useronline/liste.asp","UserOnline","alwaysRaised=1,toolbar=0,location=0,scrollbars=1,menubar=0,resizable=0,status=0,width=210,height=540");
}

// ---------------------------------------------------------------------------
// Banner
// ---------------------------------------------------------------------------

function moveBanner(codeId, targetId) 
{	
	if ( document.getElementById ) 
	{		
		var myBannerCode = $(codeId);
		var targetId     = $(targetId);
		
		if (myBannerCode && targetId) 
		{	
			while ((myBannerCodeElem = myBannerCode.firstChild)) 
			{	

				if (myBannerCodeElem.tagName && myBannerCodeElem.tagName.toLowerCase() == "script") 
				{	
					myBannerCode.removeChild(myBannerCodeElem);
				} 
				else 
				{	
					targetId.appendChild(myBannerCodeElem);
				}

			}
		}
	}
}

// ---------------------------------------------------------------------------
// Comments
// ---------------------------------------------------------------------------

function ShowCommentForm(textbox)
{
    if(textbox.grown == null)
    {
        textbox.grown = true;
        new Effect.Morph(textbox, { style: 'height:100px', duration:0.5 })
        $('cform_confirmation').show();
    }
}

// ---------------------------------------------------------------------------
// Misc
// ---------------------------------------------------------------------------

function ShowUserOnline()
{
    window.open("/community/useronline/liste.asp","UserOnline","alwaysRaised=1,toolbar=0,location=0,scrollbars=1,menubar=0,resizable=0,status=0,width=210,height=540");
}

function do_bookmark(id, doc)
{
    var bm_url = doc.URL;
    var title = doc.title;

    var service_url = ''
    if(id == 1)
    {
        var service_url = 'http://www.mister-wong.de/index.php?action=addurl&bm_url='+bm_url+'&bm_notice&bm_description='+title+'&bm_tags=Rezept,Kochrezept';
    }
    else if(id == 2)
    {
        var service_url = 'http://www.favoriten.de/url-hinzufuegen.html?bm_url='+bm_url+'&bm_title='+title;
    }
    else if(id == 8)
    {
        var service_url = 'http://social-bookmarking.seekxl.de/?add_url='+bm_url+'&title='+title;
    }
    else if(id == 19)
    {
        var service_url = 'http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk='+bm_url+'&annotation=&labels=&title='+title;
    }
    else if(id == 28)
    {
        var service_url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+title+'&d=&tag=&u='+bm_url;
    }
    else if(id == 29)
    {
        var service_url = 'http://de.facebook.com/sharer.php?u='+bm_url+'&t='+title;
    }
    else if(id == 30)
    {
        var service_url = 'http://twitter.com/home?status='+bm_url;
    }
    else if(id == 31)
    {
        var service_url = 'http://www.studivz.net/Suggest/Selection/?u='+bm_url+'&desc='+title+'prov=Kochrezepte.de';
    }
    window.open(service_url);
}

function bookmarkservices() 
{ 
    var fenster = window.open('/popup/socialBookmarks.htm', "SocialBookmarks", "width=540px,height=500px,resizable=no"); 
    fenster.focus();
}

function raise(element, step)
{
    var tval = parseInt(element.value);
    if(tval != null)
    {
        tval += step;
    }
    
    if(tval < 1000 && tval > 0)
        element.value = tval;
        
    $('span_calculate').show();
}
