﻿/*
* File Name    : common.js
* Description  : Implements the commonly used javascripts in the application.
* Created By   : Susantha Soysa
* Created Date : 15/08/2007
* (C) Copyright id Database Marketing Pty Ltd.
*/

//***************************************browser detect***************************************
var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;
var isIE = ie4 || ie5;
var isNS = ns5;
		    
var standardbody = (document.compatMode=="CSS1Compat")? document.documentElement : document.body;
var _docWidth = function() { return (document.body.clientWidth)? document.body.clientWidth : 0; }
var _docHeight = function() { return (document.body.clientHeight)? document.body.clientHeight: standardbody.offsetHeight; }
var _winWidth = function() { var n =  (document.documentElement)? document.documentElement.clientWidth : 0; return n; }
var _winHeight = function() { var n =  (document.documentElement)? document.documentElement.clientHeight: 0; return n; }
var _scrollX = function() { var n = typeof(window.pageXOffset)=='number' ?  window.pageXOffset : document.documentElement.scrollLeft; return n; }
var _scrollY = function() { var n = typeof(window.pageYOffset)=='number' ?  window.pageYOffset : document.documentElement.scrollTop; return n; }
var _scrollWidth = function() { var n =  (document.body.scrollWidth)? document.body.scrollWidth: 0; return n; }
var _scrollHeight = function() { var n =  (document.body.scrollHeight)? document.body.scrollHeight: 0; return n; }
var _mouseX = function(evt) { return isIE? window.event.clientX + standardbody.scrollLeft : evt.pageX; }
var _mouseY = function(evt) { return isIE? window.event.clientY + standardbody.scrollTop : evt.pageY; }

var activeHtmlEditor;
//***************************************end browser detect***************************************
//***************************************general functions****************************************
String.prototype.replaceAll = function(stringToFind,stringToReplace)
{
    var s = this.toString();
    while (s.indexOf(stringToFind) >= 0)
        s = s.replace(stringToFind, stringToReplace);
    return s;
}

String.prototype.trim = function()
{
    return this.replace(/^\s+|\s+$/g, '');
}

function setEditorValue(command,params)
{
    if (activeHtmlEditor)
        activeHtmlEditor.ExecuteCommand(command,params);
}

function getProperty(obj,prop)
{
    var val = "";
    if (obj != null)
    {
        if (obj.getAttribute)
            val = obj.getAttribute(prop);
        else
            val = eval("obj." + prop);
    }
    
    if (val)
        return val;
    else
        return "";
}

function setProperty(id, property, compareTo, assignTo)
{
    var propValue ;
    eval("propValue = getElement('" + id + "')." + property);
    if (propValue == compareTo)
        eval("getElement('" + id + "')." + property + " = \"" + assignTo + "\";");
    else
        eval("getElement('" + id + "')." + property + " = \"" + compareTo + "\";");
} 
function setFocus(obj)
{
    if (!obj.focus())
        obj.scrollIntoView(); 
}
//***************************************end general functions****************************************
//***************************************cms Footer***************************************
// This code handles the bottom footer div       
function MoveFooter()
{
    footer_div = this.document.getElementById("cmsFooter");
    myY = document.documentElement.clientHeight;
    myScroll = document.documentElement.scrollTop;
    myY = myY - 21 + myScroll;

    footer_div.style.visibility = "hidden";
    footer_div.style.position="absolute";
    footer_div.style.top=myY + "px";
    footer_div.style.visibility = "visible";
}
//***************************************end cms footer***************************************

//***************************************image preloader***************************************
var images = new Hashtable();

function getImage(url)
{
    if (images.get(url))
        return url;
    else
    {
        var img = new Image();
        img.src = url;
        images.put(url,img);
        return url;
    }
}
//***************************************end image preloader***************************************

//***************************************HashTable implementation***************************************
function Hashtable(){
	this.hash = new Array();
	this.keys = new Array();

	this.location = 0;
}

Hashtable.prototype.get = function (key)
{
	return this.hash[key];
}

Hashtable.prototype.put = function (key, value)
{
	if (value == null)
		return null;

	if (this.hash[key] == null)
		this.keys[this.keys.length] = key;

	this.hash[key] = value;
}
//***************************************End HashTable implementation***************************************

function addListener(element, event, listener, bubble) {
  if(element.addEventListener) {
    if(typeof(bubble) == "undefined") bubble = false;
    element.addEventListener(event, listener, bubble);
  } else if(this.attachEvent) {
    element.attachEvent("on" + event, listener);
  }
}

function getElement(elementId)
{
    return (ie4)? document.all[elementId]: (ie5||ns5)? document.getElementById(elementId): null;
}

function getElementWidth(elementId)
{	
    var elm = getElement(elementId);
    return (ie4||ie5)? elm.clientWidth: elm.offsetWidth;
}

function getElementHeight(elementId)
{	
    var elm = getElement(elementId);
    return (ie4||ie5)? elm.clientHeight: elm.offsetHeight;
}

function disableAnchor(id, disable){
  var obj = document.getElementById(id);
  if(disable)
  {
    var href = obj.getAttribute("href");
    if(href && href != "" && href != null)
    {
       obj.setAttribute('href_bak', href);
       obj.setAttribute('disabled', true);
    }
    obj.removeAttribute('href');
    obj.style.color= "#cccccc";
  }
  else if (obj.getAttribute('disabled'))
  {
    obj.setAttribute('href', obj.getAttribute('href_bak'));
    obj.setAttribute('disabled', false);
    obj.style.color = "";
  }
}

function navigate(url, target)
{
    if (url && url != "")
        if (target == "_blank")
            window.open(url,'','');
        else
            window.location.href = url;
}

var formString;
function windowOpen(url,width,height, scroll)
{
    if (scroll == null || scroll != 'yes') 
        scroll = 'no';
        
    window.open(url,'popupWindow','left=50,top=50,toolbars=0,scrollbars=' + scroll + ',location=0,statusbars=1,menubars=0,resizable=1,width=' + width + ',height=' + height);
    return false;
}

function strictToNumbers(eve, con, maxLengthAllowed)
{
    switch (eve.keyCode)
    {
        case 8: // backspace
        case 9: // tab
        case 37: // left 
        case 39: // right
        case 46: // delete
            return true;
            break;
        case 48:
        case 49:
        case 50:
        case 51:
        case 52:
        case 53:
        case 54:
        case 55:
        case 56:
        case 57:
	    case 96:
	    case 97:
	    case 98:
	    case 99:
	    case 100:
	    case 101:
	    case 102:
	    case 103:
	    case 104:
	    case 105:
            return con.value.length < maxLengthAllowed;
            break;
        default:
            return false;
    }
    return false;
}

function strictToNumbersAndSpaces(eve, con, maxLengthAllowed)
{
    switch (eve.keyCode)
    {
        case 8: // backspace
        case 9: // tab
        case 37: // left 
        case 39: // right
        case 46: // delete
            return true;        
            break;
        case 32:
        case 48:
        case 49:
        case 50:
        case 51:
        case 52:
        case 53:
        case 54:
        case 55:
        case 56:
        case 57:
	    case 96:
	    case 97:
	    case 98:
	    case 99:
	    case 100:
	    case 101:
	    case 102:
	    case 103:
	    case 104:
	    case 105:
            return con.value.length < maxLengthAllowed;
            break;
        default:
            return false;
    }
    return false;
}

function showHint(divId)
{
    var elm = document.getElementById(divId);
    if (elm)
    if (elm.hintVisible)
    {
        //elm.style.position = "absolute";
        //elm.style.visibility = "hidden";
        elm.hintVisible = false;
        elm.style.display = "none";
    }
    else
    {
        //elm.style.position = "relative";
        //elm.style.visibility = "visible";
        elm.hintVisible = true;
        elm.style.display = "";
    }
    return false;
}
    

function ssFishEyeButton(btnId, width,height,maxWidth, maxHeight, buttonAlign)
{
	var div1 = document.getElementById(btnId);
	if (buttonAlign.toLowerCase() == "right")
	    div1.className = "sstoolbtnRight";
	else
	    div1.className = "sstoolbtnLeft";
	this.imgId = btnId + "_img";
	this.img = div1.getElementsByTagName("img")[0];
	this.img.id = this.imgId;
	this.img.width = width;
	this.img.height = height;
	this.img.minwidth = width;
	this.img.minheight = height;
	this.img.maxwidth = maxWidth;
	this.img.maxheight = maxHeight;
	this.img.allowScaleDown = true;
	this.img.lbl = div1.getElementsByTagName('span')[0];
	this.img.lbl.style.display = "none";
	this.anc = div1.getElementsByTagName("a")[0];
	this.anc.onmouseover = function () { this.btn.img.scallingDown = false; this.btn.img.scallingUp = true; scaleUp(this.btn.imgId); };
	this.anc.onmouseleave = function () { this.btn.img.scallingUp = false; this.btn.img.scallingDown = true; scaleDown(this.btn.imgId); };
	this.anc.onmouseout = function () { this.btn.img.scallingUp = false; this.btn.img.scallingDown = true; scaleDown(this.btn.imgId); };
	this.anc.btn = this;

	
}

function scaleUp(objId)
{
		var img = document.getElementById(objId);
		if (img.width < img.maxwidth && img.scallingUp)
		{
			img.width += 1;
			img.height += 1;
			window.setTimeout("scaleUp('" + objId + "');", 10);
		}
		else if (img.scallingUp)
		{
			img.lbl.style.display = "";	
		}
		return true;
}


function scaleDown(objId)
{
		var img = document.getElementById(objId);

		if (img.width > img.minwidth && img.scallingDown)
		{
			img.width -= 1;
			img.height -= 1;
			img.lbl.style.display = "none";
		window.setTimeout("scaleDown('" + objId + "');", 20);
		}
		else if (img.scallingDown)
		{
    img.lbl.style.display = "none";
		}
		return true;
}

// top tool bar functions
  var selected = null;
  try { document.execCommand('BackgroundImageCache', false, true);} catch(e) {}
  
  function btnOver(btn) // li
  {
    var tds = btn.getElementsByTagName("span");
    if (tds.length > 0)
      if (tds[0].className == "topMenuSELeft")
        selected = btn;
    for(i=0, x = tds.length; i<x; i++){
      if (i==0)
        tds[0].className = "topMenuMOLeft";
      if (i==1)
        tds[1].className = "topMenuMOMid";
      if (i==2)
        tds[2].className = "topMenuMORight";
    }
  }
  
  function btnLeave(btn) // li
  {
    var classPrefix = "";
    if (selected)
      classPrefix = "topMenuSE";
    else
      classPrefix = "topMenuMI";

    var tds = btn.getElementsByTagName("span");
    for(i=0, x = tds.length; i<x; i++){
      if (i==0)
        tds[0].className = classPrefix + "Left";
      if (i==1)
        tds[1].className = classPrefix + "Mid";
      if (i==2)
        tds[2].className = classPrefix + "Right";
        
     selected = null;
    }
  }  
  
// end top tool bar functions  

// fade in/Out
var tm=5; var sp=10; var fading = false;
//function fadeInOut(con, f)
//{
//    if (fading)
//        return;
//    fading = true;
//    con = document.getElementById(con);
//    if (f == 1)
//    {
//            con.style.opacity = 0;
//            con.style.filter = 'alpha(opacity=' + con.style.opacity + ')';
// 	        con.style.visibility='visible'; 
// 	}
//    con.timer = setInterval(function(){ doFadeInOut(con,f)},tm)
//}

//function doFadeInOut(c,f){
//    if (isNaN(c.style.opacity))
//        if (f == -1)
//            c.style.opacity = 100;
//        else
//            c.style.opacity = 0;
//            
//    c.style.opacity = c.style.opacity + (f); 
//    c.style.filter = 'alpha(opacity=' + c.style.opacity + ')';

//    if(f==1 && c.style.opacity >= 100)
//    {
//        clearInterval(c.timer);
//        fading = false;

//    }
//    else if(f!=1 && c.style.opacity==0)
//    {
//        c.style.visibility='hidden'; 
//        clearInterval(c.timer);
//        fading = false;
//    }
//}

// fade in/Out
var tm=5; var fading = false; var fadeControl = null;
function fadeInOut(con, fadeStep, timerDelay, startOpactity, endOpacity)
{
    if (fading) return;
    fading = true;
    fadeControl = con;
    if (!fadeControl.tagName)
        fadeControl = document.getElementById(fadeControl);
    fadeControl.oStart = startOpactity;
    fadeControl.oEnd = endOpacity;
    fadeControl.fadeStep = fadeStep;
    fadeControl.timerDelay = timerDelay;
    
    if (fadeStep > 0)
    {
        fadeControl.opacity = startOpactity;
 	}
 	else
 	{
        fadeControl.opacity = endOpacity;
 	}
    fadeControl.style.opacity = fadeControl.opacity / 100;
    fadeControl.style.filter = 'alpha(opacity=' + fadeControl.opacity + ')';
    fadeControl.style.display=''; 
    fadeControl.timer = setInterval(function(){ doFadeInOut()},timerDelay)
}

function doFadeInOut(c){
    if (!fadeControl) return;

    if (fadeControl.fadeStep > 0 && fadeControl.opacity >= fadeControl.oEnd)
    {
        fadeControl.opacity = fadeControl.oEnd;
        fadeControl.fadeStep = 0;

    }
    else if (fadeControl.fadeStep < 0 && fadeControl.opacity <= fadeControl.oStart)
    {
        fadeControl.opacity = fadeControl.oStart;
        fadeControl.fadeStep = 0;
    }
    else
    {
       fadeControl.opacity += fadeControl.fadeStep;
    }

    fadeControl.style.opacity =  fadeControl.opacity / 100; 
    fadeControl.style.filter = 'alpha(opacity=' + fadeControl.opacity + ')';
    if(fadeControl.fadeStep == 0)
    {
        clearInterval(fadeControl.timer);
        fading = false;
        if (fadeControl.opacity == 0)
        {
            fadeControl.style.display = 'none'; 
        }
        fadeControl = null;
    }
    else
    {
        setTimeout('doFadeInOut()', fadeControl.timerDelay);
    }
}

function toNumber(n)
{
    return (typeof(n) == 'number') ? new Number(n) : 0;
}
    
    
// ----------------- cookie handling -------------
function _setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toUTCString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function _getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function setParentUrl(url)
{
    window.opener.document.location.href = url;
    window.opener.focus();
    return false;
}

function clearCookie(name) {
	_setCookie(name,"",-1);
}
    
// ----------------- end cookie handling -------------     
// tooltip
function setShowHint(id, show)
{
	var elm = document.getElementById(id);
	if (elm)	
	if (show)
	{
		elm.style.display = 'inline';
		elm.style.position = 'absolute'
	}
	else
	{
		elm.style.display = 'none';
	}
}
// end tooltip

// processing panel

function showProcessing()
{
    var img = new Image();
    img.src = "../default/images/processing.gif";
    var proc = document.createElement("div");
    proc.className = 'processing';
    //proc.style.backgroundColor = 'yellow';
    //proc.style.background = "url('../../default/images/processing.gif') center center no-repeat";
    proc.style.position = 'absolute';
    proc.style.left = Math.ceil((_winWidth() - 150) / 2) + 'px';
    proc.innerHTML = 'Processing...';
    document.body.appendChild(proc);
}
// end processing panel
// ----------------- dragger script    
var dragger = function()
{
    var _dragObj = new Object();
    function drag()
    {
        
    }
    
    drag.prototype.dragStart = function(event, dragHandleId, dragPaneId, stopDragCallback)
    {
        if (dragPaneId) {}
        else dragPaneId = dragHandleId;

        _dragObj.dragHandle = document.getElementById(dragHandleId);
        _dragObj.dragPane = document.getElementById(dragPaneId);
        _dragObj.stopDragCallback = stopDragCallback;

        var el;
        var x, y;

        // Get cursor position with respect to the page.

        if (isIE) {
            x = window.event.clientX + document.documentElement.scrollLeft
              + document.body.scrollLeft;
            y = window.event.clientY + document.documentElement.scrollTop
              + document.body.scrollTop;
        }
        else if (isNS) {
            x = event.clientX + window.scrollX;
            y = event.clientY + window.scrollY;
        }

      // Save starting positions of cursor and element.

      _dragObj.cursorStartX = x;
      _dragObj.cursorStartY = y;
      _dragObj.elStartLeft  = parseInt(_dragObj.dragPane.style.left, 0);
      _dragObj.elStartTop   = parseInt(_dragObj.dragPane.style.top,  0);

      if (isNaN(_dragObj.elStartLeft)) _dragObj.elStartLeft = 0;
      if (isNaN(_dragObj.elStartTop))  _dragObj.elStartTop  = 0;

      // Update element's z-index.
      _dragObj.zIndex = _dragObj.dragPane.style.zIndex;  
      _dragObj.dragPane.style.zIndex = 99;//++dragObj.zIndex;

      // Capture mousemove and mouseup events on the page.

      if (isIE) {
        document.attachEvent("onmousemove", dragGo);
        document.attachEvent("onmouseup",   dragStop);
        window.event.cancelBubble = true;
        window.event.returnValue = false;
      }
      if (isNS) {
        document.addEventListener("mousemove", dragGo,   true);
        document.addEventListener("mouseup",   dragStop, true);
        event.preventDefault();
      }
    }

    function dragGo(event) {

      var x, y;

      // Get cursor position with respect to the page.

      if (isIE) {
        x = window.event.clientX + document.documentElement.scrollLeft
          + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop
          + document.body.scrollTop;
      }
      else if (isNS) {
        x = event.clientX + _scrollX();
        y = event.clientY + _scrollY();
      }

      // Move drag element by the same amount the cursor has moved.
      var posX = (_dragObj.elStartLeft + x - _dragObj.cursorStartX);
      var posY = (_dragObj.elStartTop  + y - _dragObj.cursorStartY);
      
      if (posX < 0 ) posX = 0;
      if (posY < 0 ) posY = 0;
      
      _dragObj.dragPane.style.left = posX + "px";
      _dragObj.dragPane.style.top  = posY + "px";

      if (isIE) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
      }
      if (isNS)
        event.preventDefault();
    }

    function dragStop(event) {
      // Stop capturing mousemove and mouseup events.
      if (isIE) {
        document.detachEvent("onmousemove", dragGo);
        document.detachEvent("onmouseup",   dragStop);
      }
      if (isNS) {
        document.removeEventListener("mousemove", dragGo,   true);
        document.removeEventListener("mouseup",   dragStop, true);
      }
      _dragObj.dragPane.style.zIndex = _dragObj.zIndex;//++dragObj.zIndex;

      if (_dragObj.stopDragCallback)
        eval(_dragObj.stopDragCallback + "('" + _dragObj.dragPane.id + "')" );
      
    }    
    return {drag:drag}
}();

var _dragger = new dragger.drag();

function initTracking(rootUrl)
{
    var _objs = document.getElementsByTagName('A');
    var l = _objs.length;
    var i; 
    var _img = null;
    var _obj = null;
    var _imgPreview = false;
    
     for( i=0; i < l; i++)
     {
        _obj = _objs[i];
        _imgPreview = false;
        if (_obj.href)
        {
            if (( img = _obj.getElementsByTagName("IMG")) != null) // set inplace viewing details
            if (img && getProperty(_obj, "displayInplace") == "1")
            {
                _obj.url = _obj.href;
                _obj.owner = getProperty(_obj, "owner")
                _imgPreview = true;
            }
            if (_obj.href.toLowerCase().indexOf('http') == 0)
            if (_obj.href.toLowerCase().indexOf(rootUrl.toLowerCase()) != 0)
            {
                if (_obj.onclick)
                {
                     var fnc = _obj.onclick;
                     _obj.fnc = fnc;
                     if (_imgPreview)
                        _obj.onclick = function (){ if (trackView) trackView('outbound:' + this.href) ; this.fnc(); showInplaceImage(this); handleTrackingUrl(this); return false; };
                     else
                        _obj.onclick = function (){ if (trackView) trackView('outbound:' + this.href) ; this.fnc(); handleTrackingUrl(this); return false;};
                }
                else 
                {
                     if (_imgPreview)
                         _obj.onclick = function (){  if (trackView) trackView('outbound:' + this.href); showInplaceImage(this); handleTrackingUrl(this); return false; };
                     else
                        _obj.onclick = function (){ if (trackView) trackView('outbound:' + this.href); handleTrackingUrl(this); return false;};
                }
            }
            else if (_imgPreview)
            {
                _obj.onclick = function (){ showInplaceImage(this); return false; };
            }
        }
     }
     
}

function handleTrackingUrl(anc)
{
    var target = $(anc).attr("target");
    var url = $(anc).attr("href")
    if (target && target.toLowerCase() == "_blank")
        window.open(url,'',''); 
    else
        setTimeout(' document.location = "' + url + '"',100);
}

var transObject = null;
var galleryArray = null;
var galleryCache = null;
var galleryImage = null;
var galleryImageNext = new Image(); galleryImageNext.src = '../default/images/next.png';
var galleryImagePrev = new Image(); galleryImagePrev.src = '../default/images/prev.png';
var popupImageClose = new Image(); popupImageClose.src = '../default/images/closem.png';
var popupImageCloseMO = new Image(); popupImageCloseMO.src = '../default/images/closem_mo.png';
var popupImageWorking = new Image(); popupImageWorking.src = '../default/images/working.gif';
function showInplaceImage(anc)
{
   
    if (anc.url)
    {
        galleryArray = [];
        galleryCache = [];
        var groupParent = document.getElementById(anc.owner);
        var _elements = groupParent.getElementsByTagName('a');
        var l = _elements.length;
        var i;
        var j = 0; 
        var displayIndex = 1;
        var element;
        for( i=0; i < l; i++)
        {
            element = _elements[i];
            if (anc.owner == getProperty(element, 'owner'))
            {
                galleryArray[j] = element.url;
                galleryCache[j] = new Image();
                galleryCache[j].src = element.url;
                if (anc.url == element.url)
                {
                    displayIndex = j + 1;
                }
                j++;
            }
        }
        
        var aanc = document.createElement('A');
        aanc.onblur = function (){ closePopupOverlay();}
        aanc.onclick = function (){ closePopupOverlay();}
        aanc.href = 'javascript:void(0);';
        var aimg = document.createElement('img');
        aimg.id = 'aimg';
        aimg.style.border = "0px";
        aimg.style.position = "relative";
        aimg.index = displayIndex;
        galleryImage = aimg;
        
        aanc.appendChild(aimg);
        aimg.aanc = aanc;
        
        createPopupOverlay(closeGallery, 12, 0, 0, false);

        popupImageWorking.style.position = 'absolute';
        popupContainer.appendChild(popupImageWorking);
        popupContainer.appendChild(aanc);
        var divFooter = document.createElement('div');
        popupContainer.appendChild(divFooter);
        
        aimg.onload = function (){
            try { popupContainer.removeChild(popupImageWorking);}catch(e){}
            resizePopup(12, this.width,this.height + 26);
            divFooter.innerHTML = "<span style='float:left;font-family:Trebuchet MS;font-size:12px;line-height:24px;verticle-align:middle;padding-left:4px;'>Image " + this.index + " of " + galleryArray.length + "</span><span style='float:right'><input type='image' src='../default/images/prev.png' title='Previous Image' onclick='showInplaceImageNextPrevious(this, false);' />&nbsp;<input type='image' src='../default/images/next.png' title='Next Image' onclick='showInplaceImageNextPrevious(this,true);' /></span>";
            divFooter.style.backgroundColor = '#ffffff';
            divFooter.style.width = '100%';
            divFooter.style.height = '26px';
            
          
        }
        aimg.src = anc.url;
        //adiv.appendChild(aanc);
        //document.body.appendChild(adiv);
        


        
//        var effectDiv = document.createElement('div');
//        effectDiv.style.backgroundColor = "transparent";
//        effectDiv.style.position = "absolute";
//        effectDiv.style.left = _scrollX() + "px";
//        effectDiv.style.top = _scrollY() + "px";
//        effectDiv.style.width = "0px";
//        effectDiv.style.height = "0px";
//        
//        effectDiv.style.border = "1px solid #666666";
//        effectDiv.zIndex = 999;
//        
//        adiv.style.display = 'none';
//        
//        document.body.appendChild(effectDiv);
//        
//        transObject = new Object();
//        transObject.imageDiv = adiv;
//        transObject.imageAnc = aanc;
//        transObject.transDiv = effectDiv;
//        transObject.currentX = _scrollX();
//        transObject.currentY = _scrollY();
//        transObject.currentWidth = 0;
//        transObject.currentHeight = 0;
//        transObject.targetX = ((_winWidth() - w)) / 2 + _scrollX() ;
//        transObject.targetY = ((_winHeight() - h)) / 2 + _scrollY() ;

//        transObject.targetWidth = w;
//        transObject.targetHeight = h;
//        transObject.steps = 40;
//        transObject.speed = 4;
//        transObject.anc = anc;
//        
//        showMoveTransition();
    }
}

function closeGallery()
{
    var galleryArray = null;
    var galleryCache = null;
    var galleryImage = null;
    closePopupOverlay(); 
}

function showInplaceImageNextPrevious(sender, showNext)
{
    sender.src = popupImageWorking.src;
    var i = 0;
    var l = galleryArray.length;
    var newIndex = 0;
    for( i=0; i < l; i++)
    {
        if (galleryArray[i] == galleryImage.src)
        {
            if (showNext)
            {
                newIndex = i + 1; 
                newIndex = newIndex < l? newIndex : 0;
                break;
             }
             else
             {
                newIndex = i - 1; 
                newIndex = newIndex >= 0? newIndex : l-1;
                break;
             }
         }
    }
    galleryImage.index = newIndex + 1;
    galleryImage.src = galleryArray[newIndex]
}

function showMoveTransition()
{
    transObject.xMovement = (transObject.targetX - transObject.currentX) / transObject.steps;
    transObject.yMovement = (transObject.targetY - transObject.currentY) / transObject.steps;
    transObject.widthChange = (transObject.targetWidth - transObject.currentHeight) / transObject.steps;
    transObject.heightChange = (transObject.targetHeight - transObject.currentHeight) / transObject.steps;
    transObject.completed = false;
    
    doShowMoveTransition()
}

function doShowMoveTransition()
{
    if (transObject.steps > 0)
    {
        transObject.transDiv.style.left = (parseInt(transObject.transDiv.style.left,0) + transObject.xMovement) + "px";
        transObject.transDiv.style.top = (parseInt(transObject.transDiv.style.top,0) + transObject.yMovement) + "px";
        transObject.transDiv.style.width = (parseInt(transObject.transDiv.style.width,0) + transObject.widthChange) + "px";
        transObject.transDiv.style.height = (parseInt(transObject.transDiv.style.height,0) + transObject.heightChange) + "px";
        transObject.steps --; 
        window.setTimeout("doShowMoveTransition();", transObject.speed);
    }
    else
    {
        transObject.imageDiv.style.left = transObject.transDiv.style.left;        
        transObject.imageDiv.style.top = transObject.transDiv.style.top;        
        document.body.removeChild(transObject.transDiv);
        transObject.imageDiv.style.display = '';        
        transObject.imageAnc.focus();    

    }
}

function setInputFocus(element, focus)
{
    if (focus)
    {
        element.bkColor = element.style.backgroundColor;
        element.style.backgroundColor = 'yellow';
    }
    else
    {
        element.style.backgroundColor = element.bkColor;
    }
}
 
function initInputElements()
{
    var _elements = document.getElementsByTagName('input');
    var l = _elements.length;
    var i; 
    var element;
    for( i=0; i < l; i++)
    {
        element = _elements[i];
        if (element.type == "text" || element.type == "select")
        {
            if (element.onfocus)
            {
                element.fncFocus = element.onfocus;
                element.onfocus = function() { setInputFocus(this, true); this.fncFocus(); };
            }
            else
            {
                element.onfocus = function() { setInputFocus(this, true); };
            }
            
            if (element.onblur)
            {        
                element.fncBlur = element.onblur;
                element.onblur = function() { setInputFocus(this, false); this.fncBlur(); };
            }
            else
            {
                element.onblur = function() { setInputFocus(this, false); };
            }
        }
    }

    _elements = document.getElementsByTagName('textarea');
    l = _elements.length;
    for( i=0; i < l; i++)
    {
        element = _elements[i];
        if (element.onfocus)
        {
            element.fncFocus = element.onfocus;
            element.onfocus = function() { setInputFocus(this, true); this.fncFocus(); };
        }
        else
        {
            element.onfocus = function() { setInputFocus(this, true); };
        }
        
        if (element.onblur)
        {        
            element.fncBlur = element.onblur;
            element.onblur = function() { setInputFocus(this, false); this.fncBlur(); };
        }
        else
        {
            element.onblur = function() { setInputFocus(this, false); };
        }    
    }
}

function initHints()
{
    var _objs = document.getElementsByTagName('A');
    var l = _objs.length;
    var i; 
    var _img = null;
    var _obj = null;
    var _imgPreview = false;
    
     for( i=0; i < l; i++)
     {
        _obj = _objs[i];
        _imgPreview = false;
        if (_obj.title)
        {
            _obj.moFnc = _obj.onmousemove;
            _obj.mlFnc = _obj.onmouseout;
            _obj.moTitle = _obj.title;
            _obj.title = "";
            _obj.onmousemove = function (e) { if (showHint) showHint(e,this,true); if (this.moFnc) this.moFnc() };
            _obj.onmouseout = function (e) { if (showHint) showHint(e,this,false); if (this.mlFnc) this.mlFnc() };
        }
     }

    _objs = document.getElementsByTagName('IMG');
    l = _objs.length;
    for( i=0; i < l; i++)
    {
        _obj = _objs[i];    
        if (_obj.title)
        {
              _obj.moFnc = _obj.onmousemove;
            _obj.mlFnc = _obj.onmouseout;
            _obj.moTitle = _obj.title;
            _obj.title = "";
            _obj.onmousemove = function (e) { if (showHint) showHint(e,this,true); if (this.moFnc) this.moFnc() };
            _obj.onmouseout = function (e) { if (showHint) showHint(e,this,false); if (this.mlFnc) this.mlFnc();};
        }
     
    }

}

var _hintDiv = null;
function showHint(e,obj, show)
{
    if (!show && _hintDiv)
    {
        _hintDiv.style.display = 'none';
        document.body.removeChild(_hintDiv);
        _hintDiv = null;
    }
    else if (obj)
    {
        if (obj.parentNode)
        {
             if (!_hintDiv)
            {
                _hintDiv = document.createElement("div");
            }
            if (_hintDiv.owner != obj)
            {
                _hintDiv.style.position = 'absolute';
                _hintDiv.style.display = '';
                _hintDiv.style.fontFamily = 'Verdana';
                _hintDiv.style.fontSize = '8pt';
                _hintDiv.style.border = "1px #333333 solid";
                _hintDiv.style.backgroundColor = "#FEEB01";
                _hintDiv.style.width = "auto";
                _hintDiv.style.maxWidth = "250px";
                _hintDiv.style.height = "auto";
                _hintDiv.style.padding = "8px";
                _hintDiv.style.zIndex =  99999;
            }
//            _hintDiv.className = 'tooltip';
            _hintDiv.style.left = _mouseX(e)+ 10 + "px";
            _hintDiv.style.top = (_mouseY(e) + 20) + "px";

            _hintDiv.innerHTML = obj.moTitle;
            _hintDiv.owner = obj;
            document.body.appendChild(_hintDiv);
        }
        
    }
    else if (_hintDiv)
    {
        _hintDiv.style.display = 'none';
        document.body.removeChild(_hintDiv);
        _hintDiv = null;
    }
}


/// RESIZER Script

var resizer = function()
{
    var obj = new Object();
    var myPopup;
    obj.zIndex = 0;
    var _disabled;
    function resize()
    {
    }
    
    resize.prototype.resizeStart = function(event, id) {

      var el;
      var x, y;

      // If an element id was given, find it. Otherwise use the element being
      // clicked on.

      if (id)
        obj.elNode = getElement(id);
      else {
        if (isIE)
          obj.elNode = window.event.srcElement;
        if (isNS)
          obj.elNode = event.target;

        // If this is a text node, use its parent element.

        if (obj.elNode.nodeType == 3)
          obj.elNode = obj.elNode.parentNode;
      }

      // Get cursor position with respect to the page.

      if (isIE) {
        x = window.event.clientX + document.documentElement.scrollLeft
          + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop
          + document.body.scrollTop;
      }
      if (isNS) {
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
      }

      // Save starting positions of cursor and element.

      obj.cursorStartX = x;
      obj.cursorStartY = y;
      obj.elStartWidth  = parseInt(obj.elNode.style.width, 10);
      obj.elStartHeight   = parseInt(obj.elNode.style.height,  10);

      if (isNaN(obj.elStartWidth)) obj.elStartWidth = getElementWidth(id);
      if (isNaN(obj.elStartHeight))  obj.elStartHeight  = getElementHeight(id);

      // Update element's z-index.

      //obj.elNode.style.zIndex = myPopup.style.zIndex + 1;//++obj.zIndex;

      // Capture mousemove and mouseup events on the page.

      if (isIE) {
        document.attachEvent("onmousemove", resizeGo);
        document.attachEvent("onmouseup",   resizeStop);
        window.event.cancelBubble = true;
        window.event.returnValue = false;
      }
      if (isNS) {
        document.addEventListener("mousemove", resizeGo,   true);
        document.addEventListener("mouseup",   resizeStop, true);
        event.preventDefault();
      }
    }
    
    function resizeGo(event) {

      var x, y;

      // Get cursor position with respect to the page.

      if (isIE) {
        x = window.event.clientX + document.documentElement.scrollLeft
          + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop
          + document.body.scrollTop;
      }
      if (isNS) {
        x = event.clientX + _scrollX();
        y = event.clientY + _scrollY();
      }

      // Move drag element by the same amount the cursor has moved.

      obj.elNode.style.width = (obj.elStartWidth + x - obj.cursorStartX) + "px";
      obj.elNode.style.height  = (obj.elStartHeight  + y - obj.cursorStartY) + "px";

      if (isIE) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
      }
      if (isNS)
        event.preventDefault();
    }

    resizeStop = function(event) {
      // Stop capturing mousemove and mouseup events.
      alert('stop');
      if (isIE) {
        document.detachEvent("onmousemove", resizeGo);
        document.detachEvent("onmouseup",   resizeStop);
      }
      if (isNS) {
        document.removeEventListener("mousemove", resizeGo,   true);
        document.removeEventListener("mouseup",   resizeStop, true);
      }
    }    
    return {resize:resize}
}();

var _resizer = new resizer.resize();

/// END RESIZER Script

/// STEP RESIZER Script

var stepResizer = function()
{
    var obj = new Object();
    var myPopup;
    obj.zIndex = 0;
    var _disabled;
    function resize()
    {
    }
    
    resize.prototype.resize = function(id, columnWidth, columnHeight, borderWidth, maxColumns) {

      var el;

      // If an element id was given, find it. Otherwise use the element being
      // clicked on.

      if (id)
        obj.elNode = getElement(id);
      else {
        if (isIE)
          obj.elNode = window.event.srcElement;
        if (isNS)
          obj.elNode = event.target;

        // If this is a text node, use its parent element.

        if (obj.elNode.nodeType == 3)
          obj.elNode = obj.elNode.parentNode;
      }

      // Get cursor position with respect to the page.
      var w = parseInt(obj.elNode.style.width);
        
      if (w < borderWidth + maxColumns * columnWidth - columnWidth)
      {
         var cols = (w - borderWidth) / columnWidth;
         if (cols + 1 <= maxColumns)
            obj.elNode.style.width = ((cols + 1) * columnWidth + borderWidth) + "px";
         else
            obj.elNode.style.width = (columnWidth + borderWidth) + "px";
      }
      else
      {
         obj.elNode.style.width = (borderWidth + columnWidth) + "px";
      }
       obj.elNode.style.height = columnHeight;

    }
    return {resize:resize}
}();

var _stepResizer = new stepResizer.resize();

function insertAtCursor(textbox, isObject, textToInsert) {
    var elm = textbox;
    if (!isObject)
        elm = document.getElementById(textbox);
   
    //IE support
    if (document.selection) {
        elm.focus();
        var sel = document.selection.createRange();
        sel.text = textToInsert;
    }
    //MOZILLA/NETSCAPE support
    else if (elm.selectionStart || elm.selectionStart == '0') {
        var startPos = elm.selectionStart;
        var endPos = elm.selectionEnd;
        elm.value = elm.value.substring(0, startPos) + textToInsert + elm.value.substring(endPos, elm.value.length);
    } else {
        elm.value += textToInsert;
    }
}

var popupOverlay = null; 
var popupContainer = null;
var popupTitle = null;
var popupCloseButton = null;
function createPopupOverlay(closeEvent, border, width, height, contentHidden)
{
    if (!popupOverlay)
    {
        width += border * 2; // padding
        height += border * 2; // padding

        popupOverlay = document.createElement('div');
        popupOverlay.style.position = 'fixed';
        popupOverlay.style.left = '0px';
        popupOverlay.style.top = '0px';
        popupOverlay.style.bottom = '0px';
        popupOverlay.style.right = '0px';
        popupOverlay.style.zIndex = '9998';
        popupOverlay.style.backgroundColor = '#000000';
        popupOverlay.style.display = 'none';
        
        var popupCloseEvent = function()
        {
            if (popupOverlay.closeEvent)
                popupOverlay.closeEvent();
                
            //closePopupOverlay();
        }
        
        popupOverlay.closeEvent = closeEvent;
        popupOverlay.onclick = popupCloseEvent;
        
        document.body.appendChild(popupOverlay);
        fadeInOut(popupOverlay, 1, 5, 0, 80); 
        
        popupContainer = document.createElement('div');
        popupContainer.style.position = 'absolute';
        popupContainer.style.textAlign = 'right';
        popupContainer.style.overflow = 'visible';
        if (contentHidden)
            popupContainer.style.display = 'none';
        else
            popupContainer.style.display = '';
        popupContainer.style.zIndex = '9999';
        popupContainer.style.border = border + "px #dddddd solid";
        //popupContainer.style.padding = '4px';
        popupContainer.style.backgroundColor = "#444444";
        popupContainer.style.top = '50%';
        popupContainer.style.left = '50%';
        popupContainer.style.width = width + 'px';
        popupContainer.style.height = height + "px";
        popupContainer.style.marginTop = _scrollY() - (height / 2) + "px";
        popupContainer.style.marginLeft = _scrollX() - (width / 2) + "px";
        
        document.body.appendChild(popupContainer);
        
        popupTitle = document.createElement('div');
        popupTitle.id = 'popupTitle';
        popupTitle.style.position = 'absolute';
        popupTitle.style.width = width + 'px';
        popupTitle.style.height = '0px';
        popupContainer.appendChild(popupTitle);
        
        popupCloseButton = document.createElement('img');
        popupCloseButton.style.float = 'right';
        popupCloseButton.zIndex = '9999';
        popupCloseButton.right = '0px';
        popupCloseButton.style.marginRight =  '-22px';
        popupCloseButton.style.marginTop = '-44px';
        popupCloseButton.style.cursor = 'pointer';
        popupCloseButton.src = '../default/images/closem.png';
        popupCloseButton.title = 'Close Window';
        popupCloseButton.onmouseover = function () { this.src = '../default/images/closem_mo.png'; popupContainer.style.borderColor = 'red';}
        popupCloseButton.onmouseleave = function () { this.src = '../default/images/closem.png'; popupContainer.style.borderColor = '#dddddd';}
        popupCloseButton.onmouseout = popupCloseButton.onmouseleave;
        popupCloseButton.onclick = closeEvent;

        popupTitle.appendChild(popupCloseButton);        
    }
}

var createPopup_popupContainer = null;
var createPopup_popupTitle = null;
var createPopup_popupCloseButton = null;
function createPopup(popupForObjectId, x, y, width, height, border, closeEvent, contentHidden)
{
    if (createPopup_popupContainer) // close the current
    {
        createPopup_popupTitle.removeChild(createPopup_popupCloseButton) ; 
        createPopup_popupContainer.removeChild(createPopup_popupTitle);
        document.body.removeChild(createPopup_popupContainer) ; 
        createPopup_popupContainer.objParent.appendChild(createPopup_popupContainer.obj);
        createPopup_popupCloseButton = null;
        createPopup_popupTitle = null;
        createPopup_popupContainer = null;
        
        if (this.closeEvent)
            this.closeEvent();
    }
    createPopup_popupContainer = document.createElement('div');
    createPopup_popupContainer.obj = getElement(popupForObjectId);
    createPopup_popupContainer.objParent = getElement(popupForObjectId).parentNode;
    createPopup_popupContainer.style.position = 'absolute';
    createPopup_popupContainer.style.textAlign = 'right';
    createPopup_popupContainer.style.overflow = 'visible';
    if (contentHidden)
        createPopup_popupContainer.style.display = 'none';
    else
        createPopup_popupContainer.style.display = '';
    createPopup_popupContainer.style.zIndex = '99';
    createPopup_popupContainer.style.border = border + "px #dddddd solid";
    //popupContainer.style.padding = '4px';
    createPopup_popupContainer.style.backgroundColor = "#444444";
    createPopup_popupContainer.style.top = x;
    createPopup_popupContainer.style.left = y;
    if (width)
        createPopup_popupContainer.style.width = width + 'px';
   if (height)
        createPopup_popupContainer.style.height = height + "px";
    
    document.body.appendChild(createPopup_popupContainer);
    
    createPopup_popupTitle = document.createElement('div');
    createPopup_popupTitle.id = 'popupTitle';
    createPopup_popupTitle.style.position = 'absolute';
    createPopup_popupTitle.style.width = width + 'px';
    createPopup_popupTitle.style.height = '0px';
    createPopup_popupContainer.appendChild(createPopup_popupTitle);
    
    createPopup_popupCloseButton = document.createElement('img');
    createPopup_popupCloseButton.style.float = 'right';
    createPopup_popupCloseButton.zIndex = '99';
    createPopup_popupCloseButton.right = '0px';
    createPopup_popupCloseButton.style.marginRight =  '-22px';
    createPopup_popupCloseButton.style.marginTop = '-51px';
    createPopup_popupCloseButton.style.cursor = 'pointer';
    createPopup_popupCloseButton.src = '../default/images/closem.png';
    createPopup_popupCloseButton.title = 'Close Window';
    createPopup_popupCloseButton.onmouseover = function () { this.src = '../default/images/closem_mo.png'; createPopup_popupContainer.style.borderColor = 'red';}
    createPopup_popupCloseButton.onmouseleave = function () { this.src = '../default/images/closem.png'; createPopup_popupContainer.style.borderColor = '#dddddd';}
    createPopup_popupCloseButton.onmouseout = createPopup_popupCloseButton.onmouseleave;
    createPopup_popupCloseButton.closeEvent = closeEvent;
    createPopup_popupCloseButton.onclick = function () { 
        createPopup_popupTitle.removeChild(createPopup_popupCloseButton) ; 
        createPopup_popupContainer.removeChild(createPopup_popupTitle);
        document.body.removeChild(createPopup_popupContainer) ; 
        createPopup_popupContainer.objParent.appendChild(createPopup_popupContainer.obj);
        createPopup_popupCloseButton = null;
        createPopup_popupTitle = null;
        createPopup_popupContainer = null;
        
        if (this.closeEvent)
            this.closeEvent();
    }

    createPopup_popupTitle.appendChild(createPopup_popupCloseButton);     
    createPopup_popupContainer.appendChild(getElement(popupForObjectId));   
}

function resizePopup(border,width,height)
{
        popupTitle.style.width = width + 'px';

        //width += border * 2; // padding
        //height += border * 2; // padding        popupContainer.style.width = width + 'px';

        popupContainer.style.marginTop = _scrollY() - (height / 2) + "px";
        popupContainer.style.marginLeft = _scrollX() - (width / 2) + "px";
        popupContainer.style.width = width + "px";
        popupContainer.style.height = height + "px";
        popupContainer.style.display = '';
}

function closePopupOverlay()
{
    fadeInOut(popupOverlay, -1, 5, 0, 80);
    popupTitle.removeChild(popupCloseButton) ; 
    popupContainer.removeChild(popupTitle);
    document.body.removeChild(popupOverlay); 
    document.body.removeChild(popupContainer) ; 
    popupOverlay = null; 
    popupContainer = null;
    popupCloseButton = null;
    popupTitle = null;
}

var fwpContainer = null;
function vplayerPopupShow(url, width, height, autoplay, navigateUrl)
{
    createPopupOverlay(playerPopupClose, 2, width, height, false);
    popupContainer.navigateUrl = navigateUrl;
         
    fwpContainer = document.createElement('div');
    fwpContainer.id = 'fwpContainer';
    fwpContainer.style.width = '100%';
    fwpContainer.style.height = '100%';
    popupContainer.appendChild(fwpContainer);
    
    var fwpPlayer = flowplayer("fwpContainer", 'http://releases.flowplayer.org/swf/flowplayer-3.2.7.swf', {
        clip:  {
            url: url,
            autoPlay: (autoplay == true || autoplay == 1? true : false),
            autoBuffering: true
        },
        onLoad: function(){
        }
    });
}

function uplayerPopupShow(url, width, height, navigateUrl)
{
    createPopupOverlay(playerPopupClose, 2, width, height, false);
    popupContainer.navigateUrl = navigateUrl;
    
    fwpContainer = document.createElement('div');
    fwpContainer.id = 'fwpContainer';
    fwpContainer.style.width = '100%';
    fwpContainer.style.height = '100%';
    fwpContainer.innerHTML = "<iframe title='YouTube video player' src='" + url + "' width='100%' name='platinumframed' id='platinumframed' height='100%' style='width: 100%; height: 100%;' scrolling='no'" +
        " frameborder='0' allowfullscreen>Your Browser does not appear to support iFrames. <a href='" + url + "' target='_blank'>Please click here to view this video.</a></iframe>";  

    popupContainer.appendChild(fwpContainer);
}

function pplayerPopupShow(url, width, height)
{
    createPopupOverlay(playerPopupClose, 2, width, height, false);

     
    fwpContainer = document.createElement('div');
    fwpContainer.id = 'fwpContainer';
    fwpContainer.style.width = '100%';
    fwpContainer.style.height = '100%';
    fwpContainer.innerHTML = "<iframe src='" + url + "' width='100%' name='platinumframed' id='platinumframed' height='100%' style='width: 100%; height: 100%;' scrolling='no'" +
        " frameborder='0'>Your Browser does not appear to support iFrames. <a href='" + url + "'>Please click here to view this video.</a></iframe>";  

    popupContainer.appendChild(fwpContainer);
}

function playerPopupClose()
{
    var navigateUrl = popupContainer.navigateUrl;
    popupContainer.removeChild(fwpContainer);
    fwpContainer = null; 
    closePopupOverlay();    

    if (navigateUrl != null && navigateUrl != "")
        window.location.href = navigateUrl;
}

function mapAreaOver(area, index, e, dsId){
    var elementId = area.id.replace('_area',''); 
    document.getElementById(elementId).style.display = '';
    document.getElementById(dsId + '_imapTitle').innerHTML = eval('obj' + dsId + '_imapTitles[index]');
    var clickAction = eval('obj' + dsId + '_imapClickActions[index]'); 
    var clickActionTarget = eval('obj' + dsId + '_imapClickActionTargets[index]'); 
    document.getElementById(dsId +'_imapImage').src = eval('obj' + dsId +'_imapImages[index].src');
    document.getElementById(dsId +'_imapDescription').innerHTML = eval('obj' + dsId + '_imapDescriptions[index]');
    if (clickAction){   
        document.getElementById(dsId +'_imapDetails').clickAction = clickAction;   
        document.getElementById(dsId +'_imapDetails').clickActionTarget = clickActionTarget;   
        document.getElementById(dsId +'_imapDetails').onclick = function() { 
            performUrlAction (this.clickAction, this.clickActionTarget ) ;
        };
    } 
    if (document.getElementById(dsId +'_imapDetails').tagName.toLowerCase() == 'div') mapAreaPopupBoxShowContent(dsId, e);
 }
function mapAreaHide(area,index){ 
    document.getElementById(area.id.replace('_area','')).style.display = 'none';
}
function stopEvent(evt){
    evt = evt || window.event; 
    if (evt.stopPropagation){
        evt.stopPropagation();
        evt.preventDefault();
    }
    else if(typeof evt.cancelBubble != 'undefined')
    {   
        evt.cancelBubble = true;
        evt.returnValue = false;
    } 
    return false; 
}
function performUrlAction(action, target, event){ 
    if (action == null || action == '') 
    { 
        return stopEvent(event) ; 
    } 
    if (target == '4') 
        lightBoxShowImage(action); 
    else if (target == '3') 
        eval(action); 
    else if (target == '2') 
        location.href = action; 
    else  
        window.open(action,'',''); 
    
    return stopEvent(event); 
}
function lightBoxShowImage(action){ 
    var aanc = document.createElement('A');
    aanc.onblur = function (){ closePopupOverlay();}
    aanc.onclick = function (){ closePopupOverlay();}
    aanc.href = 'javascript:void(0);';
    var aimg = document.createElement('img');
    aimg.id = 'aimg';
    aimg.style.border = '0px';
    aimg.style.position = 'relative';
    galleryImage = aimg;
    aanc.appendChild(aimg);
    aimg.aanc = aanc;
    
    createPopupOverlay(lightBoxCloseImage, 12, 0, 0, false);

    popupImageWorking.style.position = 'absolute';
    popupContainer.appendChild(popupImageWorking);
    popupContainer.appendChild(aanc);
    
    aimg.onload = function (){
        try { popupContainer.removeChild(popupImageWorking);}catch(e){}
        resizePopup(12, this.width,this.height);
    }
    aimg.src = action;
}
 
function lightBoxCloseImage()
{
    var galleryArray = null;
    var galleryCache = null;
    var galleryImage = null;
    closePopupOverlay();  
}

function mapAreaPopupBoxShowContent(objId, e)
{
    var imgId = '#' + objId + '_img';
    objId =  objId + '_imapDetails';

    var x = _mouseX(e);

    var w = $(imgId).width();
    var ix = $(imgId).offset().left;
    var iy = $(imgId).offset().top;
    x = x - ix;
    if (x >  w / 2)
        doShowInPopup(objId, (ix + 10) + 'px', (iy + 10) + 'px', 10, null, false, '171px',null, 8000)
    else 
        doShowInPopup(objId, (w - 201 + ix) + 'px', (iy + 10) + 'px', 10, null, false, '171px',null, 8000)
       
}

function showInPopup(objId, x, y, border, onCloseCallback, w, h, autoCloseInterval)
{
    doShowInPopup(objId, x, y, border, onCloseCallback, false, w, h, autoCloseInterval);
}

function showInPopupWithOverlay(objId, x, y, border, onCloseCallback, w, h, autoCloseInterval)
{
   doShowInPopup(objId, x, y, border, onCloseCallback, true, w, h, autoCloseInterval);
}

function doShowInPopup(objId, x, y, border, onCloseCallback, showOverlay, w, h, autoCloseInterval)
{
    var borderColor = '#eee';
    var borderColorMO = "red";
    var btnImageSrc = "../default/images/closem.png";
    var btnImageSrcMO = "../default/images/closem_mo.png"; 
    
    var obj = $('#' + objId);
    var sipId = 'sip_' + objId;

    doShowInPopup_close(objId);
    
    if (!border) border = 6; else border = parseInt(border);
    
    if (!x) x = '50%;margin-left:-' + (parseInt(obj.css("width")) / 2) + "px";
    if (!y) y = '50%;margin-top:-' + (parseInt(obj.css("height")) / 2) + "px";
    if (w) w = 'width:' + w + ';';
    if (h) h = 'height:' + h + ';';
    
    var popupWrapper = "<div class='showInPopup' id='" + sipId + "' style='left:" + x + ";top:" + y + ";border-width:" + border + "px;" + w + h + "'></div>";
    if (showOverlay)
        popupWrapper = "<div class='showInPopupWithOverlay'>" + popupWrapper + "</div>";

    $(obj).wrap(popupWrapper);
    if (border < 15) border = (border / 2); else border = 0;

    $(obj).data("wrapped", showOverlay ? 2 : 1);
    $('#' + sipId).append("<input type='image' id='" + sipId + "_btn' src='" + btnImageSrc + "' title='Close' style='position:absolute;float:right;margin:" + (border -22) + "px 0px 0px " + (-border) + "px;' />");
    $('#' + sipId + '_btn').attr("borderColor", borderColor);
    $('#' + sipId + '_btn').attr("borderColorMO", borderColorMO);
    $('#' + sipId + '_btn').attr("buttonImage", btnImageSrc);
    $('#' + sipId + '_btn').attr("buttonImageMO", btnImageSrcMO);
    $('#' + sipId + '_btn').attr("displaying", $(obj).css("display"));
    $('#' + sipId + '_btn').attr("objId", objId);
    $(obj).css("display","inline-block");
    $('#' + sipId + '_btn').data("closeCallBack", onCloseCallback);
    $('#' + sipId + '_btn').bind("click", function() { var objId = $(this).attr("objId"); doShowInPopup_close(objId); return false;} ) ;
    $('#' + sipId + '_btn').bind("mouseover", function() { $(this.parentNode).css("borderColor", $(this).attr("borderColorMO")); this.src = getImage($(this).attr("buttonImageMO"));});
    $('#' + sipId + '_btn').bind("mouseout", function() { $(this.parentNode).css("borderColor", $(this).attr("borderColor"));this.src = getImage($(this).attr("buttonImage"));});
    
    if (autoCloseInterval)
    {
        var timer = setTimeout("doShowInPopup_close('" + objId + "')", autoCloseInterval);
        $(obj).data("timer", timer);
    }
}

function doShowInPopup_close(objId)
{
    var obj = $('#' + objId);
    var isWrapped = $(obj).data("wrapped");
    if (isWrapped > 0)
    {
        clearTimeout($(obj).data("timer"));

        $(obj).css("display", "none");
        if (isWrapped > 0) $(obj).unwrap();
        if (isWrapped > 1) $(obj).unwrap();
        $(obj).data("wrapped", 0);
        
        var closeCallback = $(btn).data("closeCallBack");
        var btn = $('#sip_' + objId + "_btn");
        $(btn).remove();
        if (closeCallback) closeCallback();
    }
}
