self.name = 'ua_main';
window.focus();

function popImage(sPicURL, w, h) {
var newWin;
    newWin=window.open("/pages/misc/popup.htm?"+sPicURL, "","resizable=1,HEIGHT=" + h + ",WIDTH=" + w);
	newWin.moveTo(0,0);
	newWin.focus();
}
function popASP(URL, wname, w, h) {
var newWin;
var iWidth;
var iHeight;
	iWidth = (window.screen.width/2) - (w/2 + 10);
	iHeight = (window.screen.height/2) - (h/2 + 50);
	newWin=window.open(URL, wname, 'width=' + w + ', height=' + h + ', left=' + iWidth + ', top=' + iHeight + ', scrollbars=1'); 
	if (window.focus && newWin) {newWin.focus()}
	return false;
}
function moveto(obj1, obj2id) {
var obj2;
	obj2 = document.getElementById(obj2id);
	if (obj1.value.length == obj1.maxLength)
		obj2.focus();
}
function isNumberKey(evt)
{
   var charCode = (evt.which) ? evt.which : evt.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46 && charCode != 37 && charCode != 39)
      return false;
   return true;
}

// OPEN THE LATEST DIGILOG
function catalog() {
var w;
	w = window.open ('/pages/catalog/catalog-ua.asp', 'catalog', 'width=815, height=610, top=0, left=0');
	w.focus();
	return false;
}

// OPEN LIVEPERSON WINDOW
function liveperson() {
	window.open ('http://www.uastores.com/lp.php?referrer=' + document.location, 'chat26259239', 'width=472, height=320, top=0, left=0');
	//window.open('http://server.iad.liveperson.net/hc/26259239/?cmd=file&file=visitorWantsToChat&site=26259239', 'chat26259239', 'width=472, height=320, top=0, left=0');
}

//Submits form when enter pressed, does a 'click' of the button specified
function checkEnter(event,button) {
	if (event.keyCode==13) {
		if (el = document.getElementById(button)) {
			el.click();
			return(false);
		}
	} else return(true);
}

//Adds page as bookmark 
function bookmark() {
 	var urlAddress = "http://www.uniformadvantage.com";
 	var pageName = "Uniform Advantage";

	if (window.sidebar) {// firefox
		window.sidebar.addPanel(pageName, urlAddress, "")
	} else {
		if (window.opera && window.print) { // opera
			var elem = document.createElement('a');
			elem.setAttribute('href',urlAddress);
			elem.setAttribute('title',pagename);
			elem.setAttribute('rel','sidebar');
			elem.click();
		} else {
			if(document.all)// ie
				window.external.AddFavorite(urlAddress, pageName)
			else  
				alert("Sorry! Your browser doesn't support this function.");
		}
	}
}

//Control # of characters entered in a textarea (to be called on onkeyup event)
function chkLen(field, l)
{
	if (field.value.length > l) 
		field.value = field.value.substring(0, l);
}

function samecase(txt)
{
	return !(txt.toUpperCase() == txt || txt.toLowerCase() == txt)
}

function setindex(elem, ind)
{
var k = document.getElementById(elem);
if (k) k.selectedIndex = ind;
}

function titleCase(sValue) {
var sReturn = '';
var sWord = '';
	sValue = sValue.toLowerCase();
var sParts = sValue.split(" ");

	for (i = 0; i < sParts.length; i++){
		if (i > 0) sReturn += ' ';
		if (sParts[i].length > 0) {
			sWord = sParts[i].substr(0);
			sReturn += sParts[i].charAt(0).toUpperCase() + sParts[i].substr(1);
		}
	}
	return sReturn;
}

//Adds trim function to the string class
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
function right(str, num)
{
      return str.substring(str.length-num);  // pull out right num
}
