/**
 * SOE Platform - Browser utility class.
 * @class browser
 * @requires rpc
 * @author Scott Clarke, Sean White
 * @constructor GNbrowser.init
 */
var GNbrowser={
/**
* browser class properties
*/
currentBrowser: "",  
currentBrowserVersion: "",
currentJSVer: "",


/**
* Constructor for browser class
* @constructor
*/
init: function()
{

	if(navigator.appName=="Microsoft Internet Explorer")
	{
	 	
		GNbrowser.currentBrowser="IE";
		GNbrowser.currentJSVer="1.3";
		
		if(navigator.userAgent.indexOf("MSIE 6.0")>-1)
		{
			GNbrowser.currentBrowserVersion="6";
		}
		if(navigator.userAgent.indexOf("MSIE 7.0")>-1)
		{
			GNbrowser.currentBrowserVersion="7";
		}	
		

	}
	else
	{
	 	GNbrowser.currentBrowser="MOZILLA";
	 	GNbrowser.currentJSVer="1.3";

	}
},

startMouseXYCapture: function()
{
 	if (window.captureEvents) 
	{
		window.captureEvents(Event.MOUSEMOVE);
		window.onmousemove=getMouseXY;
	}
	else
	{
		document.onmousemove=getMouseXY;
	}
},
stopMouseXYCapture: function()
{
 	if (window.captureEvents) 
	{
		window.onmousemove=""; 
	}
	else
	{
		document.onmousemove="";
	}
},
/**
* Get Querystring value
* @param {String} querystring key name
* @returns Value from querystring based on key
*/
queryString : function(skey)
{
	try
	{
		var args = new Object();
		var query = location.search.substring(1); 
		var pairs = query.split("&"); 
		var pl = pairs.length;
		for(var i = 0; i < pl; i++) 
			{
				var pos = pairs[i].indexOf('='); 
				if (pos == -1) continue; 
				var argname = pairs[i].substring(0,pos); 
				var value = pairs[i].substring(pos+1); 
				if(argname==skey)
				{var ph=value;}	
			}
	}
	catch(e)
	{
		GNbrowser.logClientException('queryString',e); 
	}		
	return ph;
},

/**
* Logs client side errors server side
* @param {String} urlString RPC URL used to log client side event serverside
* @param {String} sfunction Function that threw the exception
* @param {Object} errObj Error object return from try catch block
* @returns nothing
*/
logClientException : function(urlString,sfunction,errObj)
{

	var str = "";
	for ( var i in e ) {
		var tmp = '';
		if( i.match(/^(expose|header|footer|ivn|dygolk|ad_)/) )
			tmp = '(excluding as a known custom method or property)'
		else{
			try{ tmp = e[i] } catch(e2){}
		}
		str += i + " = " + tmp;
	}
	if ( str == "" ) {
		str = e;
	}

	rpc.doHttpRequest(urlString+ "?error=" +sfunction+str,"","nothing");
	
},

/**
* Set browser cookie
* @param {String} name Name of the cookie
* @param {String} value Value for the cookie
* @param {String} expires Date the cookie expires
* @returns nothing
*/
 setCookie: function(name, value, expires)
{
	document.cookie = name + "=" + value +  "; expires=" + expires; 
},

/**
* Get browser cookie
* @param {String} name Name of the cookie
* @returns string
*/
 getCookie : function(name) {
    var dcookie = document.cookie; 
	
    var cname = name + "=";
    var clen = dcookie.length;
    var cbegin = 0;
        while (cbegin < clen) {
		
        var vbegin = cbegin + cname.length;
            if (dcookie.substring(cbegin, vbegin) == cname) { 
            var vend = dcookie.indexOf (";", vbegin);
                if (vend == -1) vend = clen;
            return unescape(dcookie.substring(vbegin, vend));
            }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
            if (cbegin == 0) break;
        }

    } ,
	 
/**
* Delete browser cookie
* @param {String} name Name of the cookie
* @returns null
*/
   deleteCookie : function  (name) {
    var expireNow = new Date();
    document.cookie = name + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
	return null;
    },

/**
* Get browser mouse x/y coordinates
* @returns mouse object
*/
 getMouseXY : function(e) {

  if (GNbrowser.currentBrowser=="IE") { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
	var mouse={
	x:tempX,
	y:tempY
	}
  return mouse;
},

/**
* Overrides current values of css class value for a specied element
* @returns mouse object
*/
 overrideCss: function(theClass,element,value) 
{
	 var cssRules;
	 //changes between cssrules(ie) and rules(ff)
	 if (document.all) {cssRules = 'rules';}
	 else if (document.getElementById) {cssRules = 'cssRules';}
	// alert(cssRules);
	  var cssr=document.styleSheets.length;
	 for (var S = 0; S < cssr; S++)
	 {		
	 	  var cssl=document.styleSheets[S][cssRules].length;
		  for (var R = 0; R < cssl; R++) 
		  {
		  		//alert(document.styleSheets[S][cssRules][R].selectorText);
			   if (document.styleSheets[S][cssRules][R].selectorText == theClass) 
			   {
			    document.styleSheets[S][cssRules][R].style[element] = value;
			   }
		  }
	 }	
}

}
GNbrowser.init();
