
	function Utilities()
	{	   
  		this.classid = "utilityClass";
  		
  		this.objtype = "fsUtilities";
  		
  		this.mouseWinX = 0;
		this.mouseWinY = 0;
		this.mouseWinX_Old = 0;
		this.mouseWinY_Old = 0;
		this.mouseWinDirection = "";
		
		this.lastMousePos = "";
		this.checkMousePosCountDown = 0;
		
		this.oCurrentFrameToTrack = null;
  		this.mouseCurrentFrameX = 0;
		this.mouseCurrentFrameY = 0;
	}
	
	Utilities.prototype =
	{	
	    getWindowMouseCoords : function(e)
        {
            if (e.pageX || e.pageY)
	        {
		         oUtilities.mouseWinX = e.pageX;
		         oUtilities.mouseWinY = e.pageY;
	        }
	        else
	        {
		         oUtilities.mouseWinX = event.clientX;
		         oUtilities.mouseWinY = event.clientY;
		    }
            	        
		    if(oUtilities.mouseWinX == 11)
		    {
		        
		    }
		    
	        // Determine Mouse Direction
	        var xdiff = oUtilities.mouseWinX - oUtilities.mouseWinX_Old;
            var ydiff = oUtilities.mouseWinY - oUtilities.mouseWinY_Old;
            
            if ((xdiff <  2) && (ydiff < -2)) { oUtilities.mouseWinDirection = "n"; }
            if ((xdiff <  2) && (ydiff >  2)) { oUtilities.mouseWinDirection = "s"; }
            if ((xdiff >  2) && (ydiff <  2)) { oUtilities.mouseWinDirection = "e"; }
            if ((xdiff < -2) && (ydiff <  2)) { oUtilities.mouseWinDirection = "w"; }
            if ((xdiff >  2) && (ydiff >  2)) { oUtilities.mouseWinDirection = "se"; }
            if ((xdiff >  2) && (ydiff < -2)) { oUtilities.mouseWinDirection = "ne"; }
            if ((xdiff < -2) && (ydiff >  2)) { oUtilities.mouseWinDirection = "sw"; }
            if ((xdiff < -2) && (ydiff < -2)) { oUtilities.mouseWinDirection = "nw"; }
            
            oUtilities.mouseWinX_Old = oUtilities.mouseWinX;
            oUtilities.mouseWinY_Old = oUtilities.mouseWinY;
	    },
	    
	    getWindowMouseDirection : function() 
	    {
            return this.mouseWinDirection;
        },
        
	    getFrameMouseCoords : function(e)
        {
	        //alert(oUI.sActiveTabId)
	        if(oInfo.browserType == "MSIE")
	        {
		         oUtilities.mouseCurrentFrameX = document.getElementById("tabCanvas"+oUI.sActiveTabId).contentWindow.event.clientX;
		         oUtilities.mouseCurrentFrameY = document.getElementById("tabCanvas"+oUI.sActiveTabId).contentWindow.event.clientY;
	        }
	        else
	        {
		         oUtilities.mouseCurrentFrameX = e.pageX;
		         oUtilities.mouseCurrentFrameY = e.pageY;
	        }
		    
		    //alert(document.getElementById("tabCanvas"+oUI.sActiveTabId).contentWindow.document);
		    
            document.getElementById("fsWorkspaceToolsBottom").innerHTML = "fx:" + oUtilities.mouseCurrentFrameX + " , fy:" + oUtilities.mouseCurrentFrameY; // Debug
	    },
	    
	    setMouseTracker : function(wfo, status)
	    {
	        // If we're attaching the monitor to the window
	        if(typeof(wfo) == "string" && wfo == "win")
	        {
	            if(status == "on")
	            {
	               oEventTools.addEvent(document.body, "mousemove", this.getWindowMouseCoords);
	            }
    	        
	            if(status == "off")
	            {
	               oEventTools.removeEvent(document.body, "mousemove", this.getWindowMouseCoords);
	            }
	        }
	        
	        // If we're attaching the monitor to a frame
	        if(typeof(wfo) == "object")
	        {	   
	            if(status == "on")
	            {
	               oEventTools.addEvent(wfo, "mousemove", this.getFrameMouseCoords);
	            }
    	        
	            if(status == "off")
	            {
	               oEventTools.removeEvent(wfo, "mousemove", this.getFrameMouseCoords);
	            }
	       }
	        
	    },
    	
	    setWinVsFrameMouseTracker : function(oFrame)
	    {
	        this.oCurrentFrameToTrack = oFrame;
	        
	        //if(((this.mouseCurrentFrameX) - (this.mouseWinX - 200)) == 0)
	        {
	        //   document.getElementById("fsWorkspaceToolsBottom").innerHTML = "wx:" + this.mouseWinX + " , fx:" + this.mouseCurrentFrameX;
	        }        
	    },
	    
	    replace : function (sSearch, sWhat, sWith, sSwitch)
	    {
	        var re = new RegExp(sWhat, sSwitch);
	        return sSearch.replace(re, sWith);
	    },
	    	    
	    formatData : function (sData, sFormat)
	    {
	        var formattedData = tempData = "";
	        
	        switch(sFormat)
	        {
	            case "currency": 
	                
	                tempData = sData.substring(0, sData.length-2) + "." + sData.substring(sData.length-2, sData.length);
	                
	            break;
	        }
	        
	        return formattedData;
	    },
	    
        splitDbRecordData : function (sData)
	    {
	        var arrSplitData = new Array();
	            arrSplitData[0] = (sData) ? "" + sData : "";
	            arrSplitData[1] = "";
	            
	        if(sData && sData.indexOf("[fs--recordset--end][fs--recordset--metadata--start]") > -1)
	        {
	           arrSplitData = sData.split("[fs--recordset--end][fs--recordset--metadata--start]");
	        }
	        
	        var data = arrSplitData[0];
	        var metadata = arrSplitData[1]; 
	        
	        
	        var oRecordSet = new Array();
	        var oRowData = new Array();	        	        
	        var oFieldData = new Array();
	        
	        var tmpRow = null;
	        var metaPos = 1;
	        
	        // If the is data to work with
	        if(data != "")
	        {
               // If there is more than 1 row
               if(data.indexOf("[fs--row--end]") > -1)
               {
                   // "Format" the rows into an neat and tidy array
                   oRowData = data.split("[fs--row--end]");
	               metaPos = oRowData.length;
	               
                   // Iterate through each row
                   for(var r = 0; r < oRowData.length; r++)
                   {
                       // If there is more than 1 field
                       if(oRowData[r].indexOf("[fs--field--end]") > -1)
                       {
                           // "Format" the fields into an neat and tidy array
                           oFieldData = oRowData[r].split("[fs--field--end]");
                       }
                       else // If there is 1 field
                       {
                           // Assume that, because there is not field end token, that this data represent 1 field
                           oFieldData[0] = oRowData[r];
                       }
        	           
                       tmpRow = new Array(); // Start each iteration with an empty temporary row
	                   
                       // Iterate through each field and it's data
                       for(var i = 0; i < oFieldData.length; i++)
                       {
                           // If this field does not have clear key-values then ignore it and don't add it to the row
                           if(oFieldData[i].indexOf("=") > -1)
                           {
                              var tmp = oFieldData[i].split("=");
            	              
                              tmpRow[i] = tmp[1];
                           }
                           else
                           {
                              tmpRow[i] = null;
                           }
                       }
	                   
                       oRecordSet[r] = tmpRow;
                   }
               }
               else
	           {
	                // If there is more than 1 field
                    if(data.indexOf("[fs--field--end]") > -1)
                    {
                        // "Format" the fields into an neat and tidy array
                        oFieldData = data.split("[fs--field--end]");
                    }
                    else // If there is 1 field
                    {
                        // Assume that, because there is not field end token, that this data represent 1 field
                        oFieldData[0] = data;
                    }
    	            
                    tmpRow = new Array(); // Start each iteration with an empty temporary row
                    
                    // Iterate through each field and it's data
                    for(var i = 0; i < oFieldData.length; i++)
                    {
                        // If this field does not have clear key-values then ignore it and don't add it to the row
                        if(oFieldData[i].indexOf("=") > -1)
                        {
                           var tmp = oFieldData[i].split("=");
        	               
                           tmpRow[i] = tmp[1];
                        }
                        else
                        {
                           tmpRow[i] = null;
                        }
                    }
                    
                    oRecordSet[0] = tmpRow;
	           }
	        }
	        else
	        {
	            oRecordSet[0] = null;
	        }
	        
	        // Append the metadata
	        var arrMetaData = new Array();
	            arrMetaData[0] = ""; // Total Pages
	        
	        if(metadata.indexOf("=") > -1)
	        {
	           var arrTmp = metadata.split("=");
	           arrMetaData[0] = arrTmp[1];	        
	        }
	        
	        oRecordSet[metaPos] = arrMetaData;
	        
	        return oRecordSet;
	    },
	    
	    escapeForDatabase : function (sData)
	    {
	        return this.replace(sData, "'", "[--fs--snglqt--placeholder--]", "ig");
	    },
	    
	    checkIsValidEmail : function (sEmail)
	    {
	        var isValid = true;
	        
	        if(sEmail.indexOf("@") == -1 || sEmail.indexOf("@") == 0 || sEmail.indexOf("@") == sEmail.length)
	        {
	           isValid = false;
	        }
	        
	        if(sEmail.indexOf(".") == -1 || sEmail.indexOf(".") == 0 || sEmail.indexOf(".") == sEmail.length)
	        {
	           isValid = false;
	        }
	        
	        if(sEmail.substring(sEmail.indexOf("@"), sEmail.lastIndexOf(".")).length > 0)
	        {
	           isValid = false;
	        }
	        
	        return isValid;
	    },
	    
	    findPos : function(obj) 
	    {
	        var curleft = curtop = 0;
	        
            if (obj.offsetParent) 
            {
                do 
                {
                    curleft += obj.offsetLeft;
                    curtop += obj.offsetTop;
                }
                while (obj = obj.offsetParent);
            }
            
            return [curleft,curtop];
	    }

	}
	
var oUtilities = new Utilities();	
		
