/*****************************************************************************/
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.png";
	}
}

/*****************************************************************************/
CWsfApp.prototype.SetCookie = function(sName, sValue)
{
  //date = new Date();
  document.cookie = sName + "=" + escape(sValue);// + "; expires=" + date.toGMTString();
}

/*****************************************************************************/
CWsfApp.prototype.GetCookie = function (sName, DefValue)
{
  // cookies are separated by semicolons
  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));
}

/*****************************************************************************/
var g_App = new CWsfApp();
