



dw_Tooltip.writeStyleRule = function() {
    if ( document.createElement && document.getElementsByTagName ) {
        document.write('<style type="text/css" media="screen">.tipContent { display:none; }</style>');
    }
}



addLoadEvent( dw_Tooltip.init );


function initDoconclick() {

}


function dw_initShowTip() { 
    if ( !document.getElementsByTagName ) { return; }
    var list = dw_getElementsByClassName( 'showTip' );
    for (var i=0; list[i]; i++) {
        dw_Event.add( list[i], 'onclick', dw_Tooltip.activate );
        dw_Event.add( list[i], 'mouseout', dw_Tooltip.deactivate );
        dw_Event.add( list[i], 'focus', dw_Tooltip.activate );
        dw_Event.add( list[i], 'blur', dw_Tooltip.deactivate );
    }
    dw_Event.add( document, "keydown", dw_Tooltip.checkKey,  true ); 
    dw_Event.add( window, 'blur', dw_Tooltip.deactivate );
}

function dw_checkForTitle(e) {
    e = dw_Event.DOMit(e); var tgt = e.target; 
    if (tgt.nodeType != 1) tgt = tgt.parentNode; 
    if ( tgt.title ) {
        dw_Tooltip.activate(e);
        dw_Event.add( tgt, 'mouseout', dw_Tooltip.deactivate);
    }
}

function dw_checkForTooltip(e) {
    e = dw_Event.DOMit(e); var tgt = e.target; 
    if (tgt.nodeType != 1) tgt = tgt.parentNode; 
    if ( tgt.tagName == 'A' && tgt.id || tgt.search ) { 
        dw_Tooltip.activate(e);
        dw_Event.add( tgt, 'mouseout', dw_Tooltip.deactivate);
    }
}


function dw_getElementsByClassName(sClass, sTag, oCont) {
    var result = [], list, i;
    var re = new RegExp("\\b" + sClass + "\\b", "i");
    oCont = oCont? oCont: document;
    if ( document.getElementsByTagName ) {
        if ( !sTag || sTag == "*" ) {
            list = oCont.all? oCont.all: oCont.getElementsByTagName("*");
        } else {
            list = oCont.getElementsByTagName(sTag);
        }
        for (i=0; list[i]; i++) 
            if ( re.test( list[i].className ) ) result.push( list[i] );
    }
    return result;
}

if (!Array.prototype.push) {  // ie5.0
	Array.prototype.push =  function() {
		for (var i=0; arguments[i]; i++) this[this.length] = arguments[i];
		return this[this.length-1]; // return last value appended
	}
};




dw_Tooltip.positionWindowCenter = function() {
    var x = Math.round( (dw_Viewport.width - dw_Tooltip.tip.offsetWidth)/2 ) + dw_Viewport.scrollX;
    var y = Math.round( (dw_Viewport.height - dw_Tooltip.tip.offsetHeight)/2 ) + dw_Viewport.scrollY;
    dw_Tooltip.setPosition(x,y);
}


dw_Tooltip.wrapSticky = function(str, title) {
    title = title || '';
    var src = dw_Tooltip.defaultProps['closeBoxImage'];
    var msg = '<table id="stickyTable" border="0" cellpadding="0" cellspacing="0" width="100%"><tr ><td style="height:15px"></td><td></td></tr><tr class="stickyBar">' + 
        '<td><div style="color:black;font-size:12px;font-weight:bold;margin-left:15px;">Member Login' + title + '</div></td>' + 
        '<td style="text-align:left"><a href="javascript: void dw_Tooltip.hide()">' + 
        '<img style="margin-right:15px;" style="float:right" src="' + src + '" border="0" /></a></td></tr>' + 
        '<tr><td colspan="2"><div class="stickyContent">' + str + '</div></td></tr></table>';
    return msg;
}



dw_Tooltip.wrapToWidth = function(obj) {
    var str = obj['str']; 
    var caption = obj['caption'] || '';
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_Tooltip.wrapSticky(str, caption );
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    if ( obj['w'] ) { this.setTipWidth( obj['w'] ) }
    return str;
}

dw_Tooltip.wrapImageToWidth = function(obj) {
    dw_getImage( obj['img'] );
    var caption = obj['caption'] || ''; var w = obj['w'];
    var str = '<img  src="' + obj['img'] + '" width="' +w + '" height="' + obj['h'] + '" alt="">';
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_Tooltip.wrapSticky(str, caption );
        w += 8; 
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    this.setTipWidth(w);
    return str;
}

dw_Tooltip.wrapTextByImage = function(obj) {
    dw_getImage( obj['img'] );
    var caption = obj['caption'] || '';
    
    var str = '<table  cellpadding="0" cellspacing="0" border="0"><tr>' + 
        '<td><div class="txt">' + obj['txt'] + '</div></td>' + 
         '<td><div ><img src="' + obj['img'] + '" /></div>' + 
         '</td></tr></table>';
    
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_Tooltip.wrapSticky(str, caption );
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    if ( obj['w'] ) { this.setTipWidth( obj['w'] ) }
    return str;
}

dw_Tooltip.wrapImageOverText = function(obj) {
    dw_getImage( obj['img'] );
    var caption = obj['caption'] || '';
    var str = '<div class="img"><img src="' + obj['img'] + '" /></div><div class="txt">' + obj['txt'] + '</div>';
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_Tooltip.wrapSticky(str, caption );
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    if ( obj['w'] ) { this.setTipWidth( obj['w'] ) }
    return str;
}

dw_Tooltip.wrapTextOverImage = function(obj) {
    dw_getImage( obj['img'] );
    var caption = obj['caption'] || '';
    var str = '<div class="txt">' + obj['txt'] + '</div><div class="img"><img src="' + obj['img'] + '" /></div>';
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_Tooltip.wrapSticky(str, caption );
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    if ( obj['w'] ) { this.setTipWidth( obj['w'] ) }
    return str;
}

dw_Tooltip.setTipWidth = function(w) {
    w += dw_backCompatWidth( this.tip ); 
    this.tip.style.width = w + "px";
}



function dw_getImage(src) {
    var img = new Image();
    img.src = src;
}


function dw_backCompatWidth(el) {
    var val = 0;
    if ( el.currentStyle && !window.opera && (document.compatMode == null || document.compatMode == "BackCompat") ) {
        var p = parseInt( dw_getCurrentStyle(el, 'paddingLeft') ) + parseInt( dw_getCurrentStyle(el, 'paddingRight') );
        var b = parseInt( dw_getCurrentStyle(el, 'borderLeftWidth') ) + parseInt( dw_getCurrentStyle(el, 'borderRightWidth') )
        val = p + b;
    }
    return val;
}


function dw_getCurrentStyle(el, prop) {
    var val = '';
    if (document.defaultView && document.defaultView.getComputedStyle) {
        val = document.defaultView.getComputedStyle(el, null)[prop];
    } else if (el.currentStyle) {
        val = el.currentStyle[prop];

            if ( !/^\d+(px)?$/i.test(val) && /^\d/.test(val) ) {
				var style = el.style.left;
				var runtimeStyle = el.runtimeStyle.left;
				el.runtimeStyle.left = el.currentStyle.left;
				el.style.left = val || 0;
				val = el.style.pixelLeft + "px";
				el.style.left = style;
				el.runtimeStyle.left = runtimeStyle;
			}
    }
    return val;
}


function dw_getValueFromQueryString(name, obj) {
    obj = obj? obj: window.location; 
    if (obj.search && obj.search.indexOf(name != -1) ) {
        var pairs = obj.search.slice(1).split("&"); 
        var set;
        for (var i=0; pairs[i]; i++) {
            set = pairs[i].split("="); 
            if ( set[0] == name && set[1] ) {
                return set[1];
            }
        }
    }
    return '';
}

