/*****************************************************************************/
function CWsfApp()
{
	this.fBrowserVersion = 0;
	this.IsIE = 0;
	
   this.DetectBrowser()
}

/*****************************************************************************/
CWsfApp.prototype.OnBodyLoad = function()
{
   this.ImplementMouseCapture();
   //this.FixPngImages();
}

/*****************************************************************************/
CWsfApp.prototype.DetectBrowser = function()
{
   this.IsIE = false;
   this.fBrowserVersion = 0;
   var s = navigator.userAgent.toLowerCase();
   
   if (s.indexOf("opera")!=-1)
   {
   	// dummy
   }
   else if (s.indexOf("gecko")!=-1)
   {
   	// dummy
   }
   else if (s.indexOf("msie")!=-1)
   {
      this.IsIE = true;
		var aVersion = navigator.appVersion.split("MSIE")
		this.fBrowserVersion = parseFloat(aVersion[1]);
   }
}

/*****************************************************************************/
CWsfApp.prototype.ImplementMouseCapture = function()
{
	if (this.IsIE) return;
	
 	var capture = ["click", "mousedown", "mouseup", "mousemove", "mouseover", "mouseout" ]; 

   HTMLElement.prototype.setCapture = function()
   { 
   	if (this._capture != null) return;
   	
		var self = this; 
		var flag = false; 
		
		this._capture = function(e)
		{ 
		   if (flag) return;
		   flag = true; 
		   
		   var event = document.createEvent("MouseEvents"); 
		   
		   event.initMouseEvent(e.type, 
		       e.bubbles, e.cancelable, e.view, e.detail, 
		       e.screenX, e.screenY, e.clientX, e.clientY, 
		       e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 
		       e.button, e.relatedTarget); 

		   self.dispatchEvent(event); 
		   flag = false; 
		}; 
		
		for (var i=0; i<capture.length; i++) 
		{ 
		   window.addEventListener(capture[i], this._capture, true); 
		} 
	}

   HTMLElement.prototype.releaseCapture = function()
   { 
   	if (this._capture == null) return;
   	
   	for (var i=0; i<capture.length; i++) 
   	{ 
      	window.removeEventListener(capture[i], this._capture, true); 
      } 
      
      this._capture = null; 
   }
}

/*****************************************************************************/
CWsfApp.prototype.FixPngImages = function()
{
	if (!this.IsIE || this.fBrowserVersion > 6)  return;
	
   for(var i=0; i<document.images.length; i++)
   {
      this.FixPng(document.images[i]);
   }
}

/*****************************************************************************/
CWsfApp.prototype.FixPng = function(img)
{
	if (!this.IsIE || this.fBrowserVersion > 6) return;
	
   var imgName = img.src.toUpperCase()
	      
   if (imgName.substring(imgName.length-4, imgName.length) == ".PNG" && img.style.filter =="")
   {
		//img.style.width = img.width + "px";
	   //img.style.height = img.height + "px";
	   img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "', sizingMethod='scale')";
	   img.src = "/wsf/img/t.gif";
	}
}

/*****************************************************************************/
CWsfApp.prototype.SetCookie = function(sName, sValue, IsGlobal)
{
  //date = new Date();
  
  var s = sName + "=" + escape(sValue);
  if (IsGlobal) s += "; path" + "=/";      // to make HTTRACK dizzy ;-)
  // + "; expires=" + date.toGMTString();
  
  document.cookie = s;
}

/*****************************************************************************/
CWsfApp.prototype.GetCookie = function (sName, DefValue)
{
  // cookies are separated by semicolons
  // IE bug: cookies in total can have up-to 4096KB
  var aCookie = document.cookie.split("; ");
  
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    
    if (sName == aCrumb[0]) return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return DefValue;
}

/*****************************************************************************/
CWsfApp.prototype.GetCookieInt = function (sName, DefValue)
{
	return parseInt(this.GetCookie(sName, DefValue));
}

/*****************************************************************************/
CWsfApp.prototype.CancelEventBubble = function(ev)
{
	if (!ev) ev = window.event;
	ev.cancelBubble = true;
}      

/*****************************************************************************/
CWsfApp.prototype.OpenPopup = function(sUrl, sName, w, h)
{
  w += 32;
  h += 96;
  var wleft = (screen.width - w) / 2;
  var wtop = (screen.height - h) / 2;
  
  var win = window.open(sUrl,
    sName,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=yes, resizable=yes');
  
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}

/*****************************************************************************/
CWsfApp.prototype.CreateXMLHttpRequest = function()
{
   if (window.XMLHttpRequest)
      return new XMLHttpRequest();
   else if (window.ActiveXObject)
      return new ActiveXObject("Microsoft.XMLHTTP");
   else
      return null;
}

/*****************************************************************************/
var g_App = new CWsfApp();
