function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function writeCookie(name, data, noDays){
  var cookieStr = name + "="+ data
  if (writeCookie.arguments.length > 2){
    cookieStr += "; expires=" + getCookieExpireDate(noDays)
    }
  document.cookie = cookieStr
}

function Window(add) {
var url = "http://" + add;
imageWindow=window.open(url , 'NewWindow','width=700,height=600,menubar=no,toolbar=yes,location=yes,scrollbars=yes,resizable=yes,dependent=yes');
imageWindow.focus();
}

function readCookie(cookieName){
   var searchName = cookieName + "="
   var cookies = document.cookie
   var start = cookies.indexOf(cookieName)
   if (start == -1){ // cookie not found
     return ""
     }
   start += searchName.length //start of the cookie data
   var end = cookies.indexOf(";", start)
   if (end == -1){
     end = cookies.length
     }
   return cookies.substring(start, end)
}

function blocking(nr, cookie, vis_state)
{
        if (document.getElementById) // web standard (inkl. firefox)
        {                        			
             display = (document.getElementById(nr).style.display == 'none') ? vis_state : 'none';             
             if (cookie != '')
                        writeCookie(nr, display);
             document.getElementById(nr).style.display = display;
             if (nr == 'albinfo'){             	
             	display == 'none' ? document.getElementById('upshrink').src = 'themes/planetfotos/images/upshrink2.gif' : document.getElementById('upshrink').src = 'themes/planetfotos/images/upshrink.gif';
            }
        }
        else if (document.all) // old IE browser
        {
                current = (document.all[nr].style.display == 'none') ? vis_state : 'none';
                if (cookie != '')
                        writeCookie(nr, current);
                document.all[nr].style.display = current;
        }
        else if (document.layers) // old netscape browser
        {
                current = (document.layers[nr].display == 'none') ? vis_state : 'none';
                if (cookie != '')
         				       writeCookie(nr, current);
                document.layers[nr].display = current;                                
        }        
        	
}


function adjust_popup()
{
        var w, h, fixedW, fixedH, diffW, diffH;

        if (document.all) {
                fixedW = document.body.clientWidth;
                fixedH = document.body.clientHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - document.body.clientWidth;
                diffH = fixedH - document.body.clientHeight;
        } else {
                fixedW = window.innerWidth;
                fixedH = window.innerHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - window.innerWidth;
                diffH = fixedH - window.innerHeight;
        }
        w = fixedW + diffW;
        h = fixedH + diffH;
        if (h >= screen.availHeight) w += 16;
        if (w >= screen.availWidth)  h += 16;
        w = Math.min(w,screen.availWidth);
        h = Math.min(h,screen.availHeight);
        window.resizeTo(w,h);
        window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}


// the following code is for the java tooltips

var ttip = null;

document.onmousemove = updatetooltip;

function updatetooltip(e) {	
	if (ttip != null) {
		x = (document.all) ? window.event.clientX  : e.pageX; //first condition for IE, second for mozilla
		y = (document.all) ? window.event.clientY  : e.pageY;
		
		// === NOW CHECK THAT THE BOX IS WITHIN THE WINDOW X-DIMENSION === //
		if (x < 200) { // we are close to the left screen edge place tool box to the right
		 xf = (document.all) ? -100 : 0.1 * ttip.offsetWidth;
		} else if (x > 600) { // we are close to the right screen edge (close to 800 px which we assume as the screen edge) place tool box to the left
			xf = (document.all) ?  1.05 * ttip.offsetWidth : 1.05 * ttip.offsetWidth;			
		} else { 
			 xf= 0.55 * ttip.offsetWidth;
		}

		// === NOW CHECK THAT THE BOX IS WITHIN THE WINDOW Y-DIMENSION === //
		if (y<100) { // this is the topsearch one (sideways placement prevents overlap with drop down menus and flash box)
			yf = (document.all) ? 50-document.documentElement.scrollTop : 50;
		}	else if (y>100 && y<450) { // this is for mid page ones (placement below cursor)
			yf = (document.all) ? -20-document.documentElement.scrollTop : -20;					
		} else { // this is for close to the bottom of the page ones (placement above the cursor)
			yf = (document.all) ? 1.06  * ttip.offsetHeight -document.documentElement.scrollTop : 1.06  * ttip.offsetHeight;					
		}		
		//alert(y);
		// === PASS DIMENSIONS TO BOX === //
		ttip.style.left = (x - xf) + "px";
		ttip.style.top 	= (y - yf) + "px";				
	}
}

function showtooltip(id) {	
	var men = (document.all && id == 'quicksearch') ? document.getElementById('quick_jump') : null;
	if (men != null){ men.style.visibility = "hidden";}
	var men = (document.all && id == 'secure') ? document.getElementById('pay') : null;
	if (men != null){ men.style.visibility = "hidden";}
	var men = (document.all && id == 'versand') ? document.getElementById('titles') : null;
	if (men != null){ men.style.visibility = "hidden";}
	var men = (document.all && id == 'versand2') ? document.getElementById('sship') : null;
	if (men != null){ men.style.visibility = "hidden";}
	var men = (document.all && id == 'payment') ? document.getElementById('sship') : null;
	if (men != null){ men.style.visibility = "hidden";}
	var men = (document.all && id == 'payment') ? document.getElementById('shiptype') : null;
	if (men != null){ men.style.visibility = "hidden";}
	var men = (document.all && id == 'dpi_tip') ? document.getElementById('use') : null;
	if (men != null){ men.style.visibility = "hidden";}
	var men = (document.all && id == 'dpi_tip') ? document.getElementById('circulation') : null;
	if (men != null){ men.style.visibility = "hidden";}
	var men = (document.all && id == 'dpi_tip') ? document.getElementById('distributio') : null;
	if (men != null){ men.style.visibility = "hidden";}
	var men = (document.all && id == 'dpi_tip') ? document.getElementById('duration') : null;
	if (men != null){ men.style.visibility = "hidden";}
	ttip = document.getElementById(id);	
	ttip.style.display = "block";
}

function hidetooltip(qsearch) {
	var men = (document.all && qsearch) ? document.getElementById('quick_jump') : null;
	if (men != null){ men.style.visibility = "visible";}
	var men = (document.all && qsearch) ? document.getElementById('pay') : null;
	if (men != null){ men.style.visibility = "visible";}
	var men = (document.all && qsearch) ? document.getElementById('titles') : null;
	if (men != null){ men.style.visibility = "visible";}
	var men = (document.all && qsearch) ? document.getElementById('sship') : null;
	if (men != null){ men.style.visibility = "visible";}	
	var men = (document.all && qsearch) ? document.getElementById('shiptype') : null;
	if (men != null){ men.style.visibility = "visible";}	
	var men = (document.all && qsearch) ? document.getElementById('use') : null;
	if (men != null){ men.style.visibility = "visible";}
	var men = (document.all && qsearch) ? document.getElementById('circulation') : null;
	if (men != null){ men.style.visibility = "visible";}
	var men = (document.all && qsearch) ? document.getElementById('distributio') : null;
	if (men != null){ men.style.visibility = "visible";}
	var men = (document.all && qsearch) ? document.getElementById('duration') : null;
	if (men != null){ men.style.visibility = "visible";}
	ttip.style.display = "none";	
	ttip = null;
}

function lauchxe(cur) { // currency converter window
	XECurrencyWindow = window.open ('', 'XECurrencyWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=200,width=620');
	XECurrencyWindow.focus(); 
	XECurrencyWindow.location.href = 'http://www.xe.com/pca/input.php?From=EUR&ToSelect='+ cur;
}

// ================ The code below is to show a Picture tooltip ===================

ISIE = document.all ? true : false;
ISDOM = document.getElementById ? true : false;
ISNS4 = document.layers ? true : false;

// ID of element, which would be displayed as tooltip
var pictipId = "pictip";

// tooltip element
var pictip = null;

// array that contains key-values for text
var pictipTextMap = [];

// element, for each tooltip is locked
var currentlyLockedElement = null;

var currentlyUnderMouse = null;

// element, for each tooltip is showing now
currentElement = null;

function escapeText(text){
    return text.replace(/\n/g, '').replace(/[\"]/g, "\\\"");
}

function getElement(wnd, styleId) {
    var element;

    if (ISDOM) {
        element = wnd.document.getElementById(styleId);
    } else if (ISIE) {
        element = wnd.document.all[styleId];
    } else if (ISNS4) {
        element = wnd[styleId];
    }
    return element;
}

function isDef(){
	for(var i=0; i<arguments.length; ++i){
		if(typeof(arguments[i])=='undefined')
			return false;
	}
	return true;
}

// calculates elements offset from the left
function elOffsetX(e){
	var x = 0;
	
	while (e) {
		if (isDef(e.offsetLeft))
			x += e.offsetLeft;
		e = isDef(e.offsetParent) ? e.offsetParent : null;
	}
	
	return x;
}

// calculates elements offset from the top
function elOffsetY(e){
	var y = 0;
	
	while (e) {
		if (isDef(e.offsetTop))
			y += e.offsetTop;
			
		e = isDef(e.offsetParent) ? e.offsetParent : null;
	}
	
	return y;
}

// shows tooltip near 'el' element
function showPictip(el, text){
    // do nothing if tolltip is locked to this element
	if(el == currentlyLockedElement)
		return;

	pictip = pictip || getElement(window, pictipId);

	// form tooltips text
	text = getPictipText(el, text);

	if (text == null || text == "")
		return;

	unlockPictip();

    currentElement = el;
    currentlyUnderMouse = el;
	// set events
	el.onmouseout = function(){currentlyUnderMouse = null; window.setTimeout('unlockPictip()', 1000);};
	lockPictip(el);

	pictip.innerHTML = text;

	positePictip(el);
}

function getPictipText(el, text){
    // if text was sent to function - return it
	if(text != null && text != "")
		return text;

	if(el.getAttribute("pictipType") == 'inline')
		return el.getAttribute("pictipText");

	if(el.getAttribute("pictipType") == 'array')
		return pictipTextMap[el.getAttribute("pictipKey")];

	// if no text was sent to function - try to fetch it from 'title' attribute
	if(el.title != null && el.title != "")
		return el.title;

	// if no text was sent to function and title attribute is now specified and this is image - try to get alt attribute value
	if(el.tagName == "IMG" && el.alt != null && el.alt != "")
		return el.alt;

	return null;
}

function pageWidth(){
	return window.innerWidth != null ? window.innerWidth : document.body != null ? document.body.clientWidth : 800;
}

function pageHeight(){
	return window.innerHeight != null ? window.innerHeight : document.body != null ? document.body.clientHeight : 500;
}

// position tooltip to the text
function positePictip(el){
	if(pictip.clientHeight > pageHeight())
		pictip.height = pageHeight() / 2;
		
	var w = el.clientWidth;
	var h = el.clientHeight;

	if (w == null || w == '' || w == 0)
		w = el.scrollWidth;
	
	if (h == null || h == '' || h == 0)
		h = el.scrollHeight;

	var left = elOffsetX(el) + w - 5;
	var top = elOffsetY(el) + h - 2;

	if(pageWidth() < left + pictip.clientWidth)
		left = elOffsetX(el) - pictip.clientWidth + 5;

    if(left < 0)
        left = 0;

    if(document.documentElement.scrollTop + pageHeight() < top + pictip.clientHeight){
		top = elOffsetY(el) - pictip.clientHeight;
	}

    if(top < 0){
        top = 0;
        left += 5;
    }

  pictip.style.left = left + "px";
	pictip.style.top = top + "px";
}

// lock tooltip on screen
function lockPictip(el){
	el.onclick = function(){unlockPictip()};
	pictip.className = "pictipLocked";
	currentlyLockedElement = el;
}

// remove lock from tooltip and hide it
function unlockPictip(){
	if(currentlyUnderMouse != null){
		window.setTimeout('unlockPictip()', 1000);
		return;
	}

	hidePictip();
	currentlyLockedElement = null;
	pictip.className = "pictipFloating";
}

// remove tooltip from screen
function hidePictip(){
	pictip.style.left = '-1000px';
	pictip.style.top = '-1000px';
  currentElement = null;
}

// get all elements with specified classname
function getElementsByAttribute() {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = new Array();

	for (var i = 0; i < children.length; i++) {
		var child = children[i];

		if(child.hasAttribute("pictipType"))
			elements.push(child);
	}

	return elements;
}

// attach tooltips to elements
function attachPictips(){
	var els = getElementsByAttribute();
	
	for(var i = 0; i < els.length; i++){
		var el = els[i];

	            var text = getPictipText(el);

        	    if(text != null && text != "")
                	eval("el.onmouseover = function(){showPictip(this, \"" + escapeText(text) + "\")}");
    }
}