/**************************************************
 # ESP: General Javascripts
// Swap Image
// Toggle Layer
// Show Popup Layer
// Dom Drag Scroll bar
*/

// IMPORTANT SET BASE URL !!!
var baseURL ="";
//var baseURL ="../";


/**************************************************
 # ESP: Refine Search, Favourites button with toggle layer content
/* Image Swap Toggle 
// Netscape 3.0 compatibility test (for javascript image swapping)
*/
compat = false;
if( parseInt( navigator.appVersion ) >= 3 ) { compat = true; }

// cache images for quick swapping
if( compat )
{
	btnTriDwn = new Image;
	btnTriDwn.src = baseURL+"/images/btn_triDwn.gif";
	btnTriUp = new Image;
	btnTriUp.src = baseURL+"/images/btn_triUp.gif";

	btnFavDwn = new Image;
	btnFavDwn.src = baseURL+"/images/btn_favDwn.gif";
	btnFavUp = new Image;
	btnFavUp.src = baseURL+"/images/btn_favUp.gif";
}

var toggleFav = "";
var toggleTri = "";

function swap(x, y)
{
	if (y == "btnFav") { // Favourites Toggle
		if (toggleFav == "") { // get default
			 if (document.images[x].src.search("Dwn") == -1) { toggleFav = "Dwn";  }
			else {toggleFav = "Up";}
		}
		
		document.images[x].src=eval(y+toggleFav+'.src'); 
	
		if (toggleFav == "Up") { toggleFav = "Dwn";}
		else if (toggleFav == "Dwn") { toggleFav = "Up"; }	
	}
	else if (y == "btnTri") { // Refine Search Toggle
		if (toggleTri == "") { // get default
			 if (document.images[x].src.search("Dwn") == -1) { toggleTri = "Dwn";  }
			else {toggleTri = "Up";}
		}
		
		document.images[x].src=eval(y+toggleTri+'.src'); 
	
		if (toggleTri == "Up") { toggleTri = "Dwn";}
		else if (toggleTri == "Dwn") { toggleTri = "Up"; }	
	}	
}
/*
Clear default form value script- by JavaScriptKit.com
Featured on JavaScript Kit (http://javascriptkit.com)
Visit javascriptkit.com for 400+ free scripts!
*/

function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = "";
} 

/**************************************************
 # ESP: Toggle Layer for Refine Search, Favourites Panel and Prog Info Language
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Justin Barlow | http://www.netlobo.com 
*/

function toggleLayer(whichLayer) {

  var elem, vis;
  if(document.getElementById) // this is the way the standards work
    elem = document.getElementById(whichLayer);
  else if(document.all) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if(document.layers) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
	vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

/**************************************************
 # ESP Send to Friend Popup Layer
//
Copyright (C) September 2005  DTHMLGoodies.com, Alf Magne Kalleland
Adapted from bubble-tooltip.js
*/
function showPopup(e,text){
	if(document.all)e = event;
	
	var obj = document.getElementById('popup_layer');
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);

	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = 310; //horizontal distance e.clientX - 140
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top =  st + 180 + 'px' // vertical distance initially on top -1  e.clientY + 3 + st + 'px';  e.clientY + 3 + st + 'px'
	// obj.style.top = e.clientY - obj.offsetHeight + 170 + st + 'px'; (offset height if on top
}	

function hidePopup()
{
	document.getElementById('popup_layer').style.display = 'none';
	
}

/**************************************************
 # ESP Retrieve Password Popup Layer
//
Copyright (C) September 2005  DTHMLGoodies.com, Alf Magne Kalleland
Adapted from bubble-tooltip.js
*/
function showPopuppw(e,text){
	if(document.all)e = event;
	
	var obj = document.getElementById('password_layer');
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);

	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = 130; //horizontal distance e.clientX - 140
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top =  st +  'px'; //st + 180 + 'px' vertical distance initially on top -1  e.clientY + 3 + st + 'px';  e.clientY + 3 + st + 'px'
	// obj.style.top = e.clientY - obj.offsetHeight + 170 + st + 'px'; (offset height if on top
}	

function hidePopuppw()
{
	document.getElementById('password_layer').style.display = 'none';
	
}

/**************************************************
 # ESP Sponsor Layer
//
Copyright (C) September 2005  DTHMLGoodies.com, Alf Magne Kalleland
Adapted from bubble-tooltip.js
*/
function showLayer(e,text){
	//new Effect.Fade('footer', { from: 1, to: 0 }); 


	
	if(document.all)e = event;

	//document.getElementById('pnlLayer').visibility = 'hidden'; // hide the background panel 
	//document.getElementById('pnlLayer').style.opacity=0.4;
	//document.getElementById('pnlLayer').filters.alpha.opacity=40; // hide the background panel 
	
	
    if (document.getElementById('pnlLayer')){
        var oe = document.getElementById('pnlLayer');
        // Set transparency to 50%
        oe.setAttribute("style", "opacity:0.3;")
        if (oe.style.setAttribute) //For IE
			oe.style.setAttribute("filter", "alpha(opacity=30);") // IE. Need to set height, width, position: relative
	}
	
	
	var obj = document.getElementById(text);
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);

	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = 210; //10horizontal distance e.clientX - 140
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top =  st + 100 + 'px'; /* - 200 */

	//vertical distance initially on top -1  e.clientY + 3 + st + 'px';  e.clientY + 3 + st + 'px'
	// obj.style.top = e.clientY - obj.offsetHeight + 170 + st + 'px'; (offset height if on top
																	
}	

function hideLayer(text)
{
	//$('footer').appear();

	document.getElementById(text).style.display = 'none';
	//document.getElementById('pnlLayer').style.visibility = 'visible';
	if (document.getElementById('pnlLayer')){
		
		var oe = document.getElementById('pnlLayer');
        // Set transparency to 50%
        oe.setAttribute("style", "opacity: 1;")
		if (oe.style.setAttribute) { //For IE
			oe.style.setAttribute("filter", "alpha(opacity=100);")
		}
	}

}

/**************************************************
 # ESP : Used for Favorites Panel SCROLL BAR
 *
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};



// PRINT

var message = "Print this Page";

function printpage(type) {

	window.print();  
	
/*	if (type="switch") {

		var t=setTimeout("closePage()",1000);
		
	}
*/
}

// POPUP

function launch(strLink, w, h)
{
	window.open(strLink,'new_win','resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,width='+ w + ',height=' + h + ',top=100,left=150')
}
