﻿
function GetCursorPosition( ){
    var obj = document.activeElement;
    var cur = document.selection.createRange();
    var pos = 0;
    var theReturnValue = -1;
    
    
    if( obj&&cur ){
        var tr = obj.createTextRange();
        
        if( tr ){
            while (cur.compareEndPoints("StartToStart", tr) > 0) {
                tr.moveStart("character", 1);
                pos++;
            }
            
            theReturnValue = pos;
        }
    }
    
    return theReturnValue;
}

function GetFocusElement( ){
    var theReturnElement;
    
    
    theReturnElement = document.activeElement;
    
    return theReturnElement;
}

function Trim(str, chars) {
	return LeftTrim(RightTrim(str, chars), chars);
}
 
function LeftTrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function RightTrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function CenterElementVertically( theElement ) { 
    var theWindowHeight = $(window).height(); 
    var theWindowWidth = $(window).width(); 
    
    theElement.css('top', theWindowHeight/2-theElement.height()/2);
    theElement.css('left', theWindowWidth/2-theElement.width()/2); 
}