

function getCookie(name){
   var i=0;
   var suche = name+"=";
   while (i<document.cookie.length){
      if (document.cookie.substring(i, i+suche.length)==suche){
         var ende = document.cookie.indexOf(";", i+suche.length);
         ende = (ende>-1) ? ende : document.cookie.length;
         var cook = document.cookie.substring(i+suche.length, ende);
         return unescape(cook);
      }
      i++;
   }
   return null;
};


function getViewPort()
{
    var dim = {x: 0, y: 0};
    if (self.innerHeight) // all except Explorer
    {
    	dim.x = self.innerWidth;
    	dim.y = self.innerHeight + window.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    	// Explorer 6 Strict Mode
    {
    	dim.x = document.documentElement.clientWidth;
    	dim.y = document.documentElement.clientHeight + document.documentElement.scrollTop;
    }
    else if (document.body) // other Explorers
    {
    	dim.x = document.body.clientWidth;
    	dim.y = document.body.clientHeight + document.documentElement.scrollTop;
    }
    return dim;    
};

function getClientDimension()
{
    var dim = {x: 0, y: 0};
    if (self.innerHeight) // all except Explorer
    {
    	dim.x = self.innerWidth;
    	dim.y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    	// Explorer 6 Strict Mode
    {
    	dim.x = document.documentElement.clientWidth;
    	dim.y = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
    	dim.x = document.body.clientWidth;
    	dim.y = document.body.clientHeight;
    }
    return dim;
}

function getPos(e)
{
    var pos = {x: 0, y: 0};
     
    if (e.pageX || e.pageY)
    {
		pos.x = e.pageX;
		pos.y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		pos.x = e.clientX + document.body.scrollLeft;
		pos.y = e.clientY + document.body.scrollTop;
	}
	
	return pos;
}

function getEvent(e)
{
	if (!e)
       return window.event;    

    return e;
}

function getTarget(e)
{
    var t;
	var e = (window.event)
	   ? window.event
	   : e;

	if (e.target)
	   t = e.target;
	else if (e.srcElement)
	   t = e.srcElement;

	if (t.nodeType == 3) // defeat Safari bug
       return targ.parentNode;
       
    return t;
}

function str_pad(Input, PadTo)
{
    var Cut = 10;
    var Count = 0;
    while (Input.length < PadTo)
    {
        Count ++;
        if (Count > Cut)
            return Input;

        Input = '0' + Input;
//        alert(Input.length);
    }

    return Input;
}

var radioHas = '';


function setSessVar(Var, Val)
{
    new ajax ('/plugin/de.masstisch.ajax/SetSessionVar.php', {
    	postBody: 'Var=' + Var + '&Val=' + Val + '&' + 'PHPSESSID=' + Cart.sessionId(),
    	onComplete: function(r)
    	{
//    	    alert(r.responseText);
    	}
    });
}

function toggleElement(ID, Force, Trigger, ClassDisplay, ClassNone)
{
    if (typeof ID != 'object')
        ID = $(ID);
    
    if (arguments[1])
    {
        ID.style.display = Force;   
    }
    else
    {        
        if (ID.style.display == 'block')
            ID.style.display = 'none';
        else
            ID.style.display = 'block';
    }
    
    if (arguments[2])
    {      
        if (ID.style.display == 'block')
            Trigger.className = ClassDisplay;
        else
            Trigger.className = ClassNone;
    }
    
    setSessVar(ID.id + '_display', ID.style.display);
}


function showElement(id, state, showState) {
	if ($(id)) {
		if (state) {
			$(id).style.display = showState;
		} else {
			$(id).style.display = 'none';
		}
	}
}



function radioSwap(ID, ImgSrc)
{
    $(ID).src = ImgSrc;
}

function radioSet(ID, ImgSrc)
{
    radioHas = ImgSrc;
    radioReset(ID);
}

function radioReset(ID)
{
    $(ID).src = radioHas;
}


function goToURIFromSelect(URI, Select)
{
	//alert(URI);
	//Select.options[Select.selectedIndex].value
	window.location.href = URI + Select.options[Select.selectedIndex].value;
}

function doneEdit(Area)
{
    Parent    = Area.parentNode;
    Parent.innerHTML = Area.value;
    
}

function makeEdit(EdImg)
{
    InSide    = EdImg.parentNode.parentNode.firstChild;
    Content   = InSide.innerHTML;
    InSide.innerHTML = '<textarea style="width: 100%; height: 300px;" onblur="doneEdit(this);">' + Content + '</textarea>';
}


function updateLength(FromElement)
{
    updateCart(FromElement);
}