/*
  $Id: popupmod.js v3.5 2008-1-29 05:52:16 brad $

  SPAN, Open Source E-Commerce Solutions
  http://www.spanzone.com

  Copyright (c) 2002 SPAN

  Released under the GNU General Public License
*/

var dom = (document.getElementById) ? true : false;
var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;
var origWidth, origHeight;
if (ns4) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}
if (nodyn) { event = "nope" }
var tipFollowMouse= true;	
var tipWidth= 300;
var tipHeight= 400;
var offX= 20;	// how far from mouse to show tip
var offY= 12; 
var tipFontFamily= "Verdana, arial, helvetica, sans-serif";
var tipFontSize= "8pt";
var tipFontColor= "#000000";
var tipBgColor= "#FFFFFF"; 
var tipBorderColor= "#a2a9ae";
var tipBorderWidth= 5;
var tipBorderStyle= "solid";
var tipPadding= 4;
var messages = new Array();
var theImgs = new Array();
get_messages(this.location);
//alert(tipWidth);
var startStr = '<table style="text-align: center;" height="100%" border="0"><tr><td style="text-align: center;" align="center" width="100%"><div id="loader_container" align="center" style="position:relative; z-index:50; background-color=#ffffff;"><p>&nbsp;<p>&nbsp;<p><img src="images/loading_32x32.gif"><p>&nbsp;<p>&nbsp;<p></div><div id="loader_img" style="position:relative; z-index:60; display: none;"><img name="preview_img" src="';
var midStr = '" border="0" onload="javascript:remove_loading();"></div></td></tr><tr> <td valign="top">';
var endStr = '</td></tr></table>';
var tooltip, tipcss;
function initTip() {
	if (nodyn) return;
	tooltip = (ns4)? document.tipDiv.document: (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipcss = (ns4)? document.tipDiv: tooltip.style;
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		tipcss.width = tipWidth+"px";
		//tipcss.height = tipHeight+"px";
		tipcss.fontFamily = tipFontFamily;
		tipcss.fontSize = tipFontSize;
		tipcss.color = tipFontColor;
		tipcss.backgroundColor = tipBgColor;
		tipcss.borderColor = tipBorderColor;
		tipcss.borderWidth = tipBorderWidth+"px";
		tipcss.padding = tipPadding+"px";
		tipcss.borderStyle = tipBorderStyle;
	}
	if (tooltip&&tipFollowMouse) {
		if (ns4) document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = trackMouse;
	}
}
var __app_started = false;
if(document.addEventListener) document.addEventListener("DOMContentLoaded", initTip, false);
else {
    document.write("<scr" + "ipt id=__ie_onload defer src=://0><\/scri" + "pt>");
    var script = document.getElementById("__ie" + "_onlo" + "ad");
    script.onreadystatechange = function() {
        if(this.readyState == "complete") initTip();       
    }
}
function getImageWidth(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.width;
	} else {
		return getElementWidth(myImage);
	}
	return -1;
}
function isImageOk(img) {
  // During the onload event, IE correctly identifies any images that
  // werenˇ¦t downloaded as not complete. Others should too. Gecko-based
  // browsers act like NS4 in that they report this incorrectly.
  if (!img.complete) {
    return false;
  }
  // However, they do have two very useful properties: naturalWidth and
  // naturalHeight. These give the true size of the image. If it failed
  // to load, either of these should be zero.
  if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
    return false;
  }
  
  // No other way of checking: assume itˇ¦s ok.
  return true;
}

var t1,t2;	// for setTimeouts
var tipOn = false;	// check if over tooltip link
function doTooltip(evt,num) {
	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	if (messages[num][2])	var curBgColor = messages[num][2];
	else curBgColor = tipBgColor;
	if (messages[num][3])	var curFontColor = messages[num][3];
	else curFontColor = tipFontColor;
	if (ns4) {
		var tip = '<table bgcolor="' + tipBorderColor + '" width="' + tipWidth + '" cellspacing="0" cellpadding="' + tipBorderWidth + '" border="0"><tr><td><table bgcolor="' + curBgColor + '" width="100%" cellspacing="0" cellpadding="' + tipPadding + '" border="0"><tr><td>'+ startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr + '</td></tr></table></td></tr></table>';
		tooltip.write(tip);
		tooltip.close();
	} else if (ie4||ie5||ns5) {
	  //alert(document.getElementById('loader_container').style.left);
	  var newImg = new Image();
	  newImg.src = messages[num][0];
	  var height = newImg.height;
	  var width = newImg.width;
    //alert (newImg.src + "\n" + 'The image size is '+width+'*'+height);
	  
		var tip = startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr;
		//alert(tip); // DEBUG
		//alert(theImgs[num].);
		tipcss.backgroundColor = curBgColor;
		tipcss.width = theImgs[num].style.width; // fixed for Firefox & Safari by Jons 2009-07-12
		tooltip.innerHTML = tip;
	 	
	 	//var img = document.getElementById('preview_img');
	 	//alert(img.complete);
	 	// get Image true size
	 	/*
    var img_true_size = function(theImage) {
      var	w = theImage.width ,
          h = theImage.height ;
      if ( "naturalWidth" in theImage ) {	// for Firefox, Safari, Chrome
        w = theImage.naturalWidth;
        h = theImage.naturalHeight;
      } else if ( typeof theImage.runtimeStyle !== 'undefined' ) {	 // for IE
        var run = theImage.runtimeStyle;
        var mem = { w: run.width, h: run.height };	// keep runtimeStyle
        run.width  = "auto";
        run.height = "auto";
        w = theImage.width;
        h = theImage.height;
        run.width  = mem.w;
        run.height = mem.h;
      } else {		 // for Opera
        var mem = { w: theImage.width, h: theImage.height };	// keep original style
        theImage.removeAttribute("width");
        theImage.removeAttribute("height");
        w = theImage.width;
        h = theImage.height;
        theImage.width  = mem.w;
        theImage.height = mem.h;
      }
      return {width:w, height:h};
    }
    */
    //isImageOk(img);
	 	//alert (img.src + "\n" + 'The Image size is '+img_true_size(img).height);
	 	//alert ("\n" + img.src + "\n" + 'The Image size is '+img.width);
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",400);
}
var mouseX, mouseY;
function trackMouse(evt) {
	mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
	mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	if (tipOn) positionTip(evt);
}
function positionTip(evt) {
	if (!tipFollowMouse) {
		mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
		mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	}
	var tpWd = (ns4)? tooltip.width: (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ns4)? tooltip.height: (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
	var winHt = (ns4||ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
	if ((mouseX+offX+tpWd)>winWd) 
		tipcss.left = (ns4)? mouseX-(tpWd+offX): mouseX-(tpWd+offX)+"px";
	else tipcss.left = (ns4)? mouseX+offX: mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		tipcss.top = (ns4)? winHt-(tpHt+offY): winHt-(tpHt+offY)+"px";
	else tipcss.top = (ns4)? mouseY+offY: mouseY+offY+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",400);
}
function hideTip() {
	if (!tooltip) return;
	t2=setTimeout("tipcss.visibility='hidden'",0);
	
	if (t1) clearTimeout(t1);
	tipOn = false;
}

function GetXmlHttpObject(){ var objXMLHttp=null; if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP"); } return objXMLHttp; }

function get_messages(loc) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { return; }
	//alert(loc);
	var url="popupmod.php?loc="+loc;
	//alert(url);
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			eval(xmlHttp.responseText);
		}
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function keyPressHandler(e) {
    var kC  = (window.event) ?    // MSIE or Firefox?
               event.keyCode : e.keyCode;
    var Esc = (window.event) ?   
              27 : e.DOM_VK_ESCAPE // MSIE : Firefox
    if(kC==Esc)
       hideTip();
       //alert("Esc pressed")
}

function remove_loading() {
  var targelem = document.getElementById('loader_container');
  targelem.style.display='none';
  targelem.style.visibility='hidden';
  
  var targelem2 = document.getElementById('loader_img');
  targelem2.style.display='inline';
  //targelem2.style.visibility='visible';
}
