﻿//////////////////////////////////////////////////////////
// Common
// Handles common operations
//////////////////////////////////////////////////////////
var Common = {

	refreshMe: function() {
		var url = document.location.href;
		goTo(url);
	} // End refreshMe()
	,
	
	scrollToElement: function(elem) {
	  var selectedPosX = 0;
	  var selectedPosY = 0; 
	  while(elem != null){
		 selectedPosX += elem.offsetLeft;
		 selectedPosY += elem.offsetTop;
		 elem = elem.offsetParent;
	  }
		window.scrollTo(selectedPosX,selectedPosY);
	} // End scrollToElement()
	,
	
	isNumeric: function(sText) {
		var ValidChars = "0123456789.";
		var IsNumber = true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++){ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1){
				IsNumber = false;
			}
		}
		return IsNumber;
	} // End isNumeric()
	,
	
	getExitLink: function(strURL, intType) {
		if (!strURL || !intType) { return; }
		var strSiteExitUrl = '/system_pages/SiteExit.aspx';
		var urlEsc = escape(strURL);
		Common.goTo(strSiteExitUrl + '?url=' + urlEsc + '&type=' + intType);
	} // End getExitLink()
	,
	
	//Navigates to a URL
	goTo: function(strURL) {
		window.location.href = strURL;
	} // End goTo()
	,

	getUrlPath: function() {
		return window.document.location.pathname.toLowerCase();
	}
	,	

	urlPathIs: function(localpath) {
		var pathname = window.document.location.pathname.toLowerCase();
		if (pathname == localpath) { 
			return true;
		}
		else {
			return false;
		}
	}
	,

	preloadImg: function(path, w, h) {
		if (document.images) {
			objImg = new Image(w, h); 
			objImg.src = path;
		}
	}
	,

	enterPress: function(btnid, e) {
	
		var key;
		if (!e) var e = window.event;
		if (e.keyCode) key = e.keyCode;	//IE
		else if (e.which) key = e.which; //FF
		
		if (key == 13) { //Enter key
			document.getElementById(btnid).click(); //Click the button.
		}
		
		//Prevent propagation.
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		
	} // End enterPress()
};
