// Additional string methods trim(), left(), right()
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
String.prototype.right = function (n) {
	if (n <= 0)     // Invalid bound, return blank string
		 return "";
	else if (n > this.length)   // Invalid bound, return
		 return this;                     // entire string
	else  // Valid bound, return appropriate substring
		 return this.substring(this.length, this.length - n);
}
String.prototype.left = function (n) {
	if (n <= 0)
		return "";
	else if (n > this.length)
		return this;
	else
		return this.substr(0, n);
}
String.prototype.stripChars = function (charsToStrip) {
	s = this;
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
		var c = s.charAt(i);
		if (charsToStrip.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}
String.prototype.stripInvalidCharsFromCC = function () {
	return this.toLowerCase().stripChars('abcdefghijklmnopqrstuvwxyz `~!@#$%^&*()-_=+[{]}\|;:",<.>/?'+"'");
}
String.prototype.cleanProductDescription = function () {
	var temp = this.split("[");
	var prodDesc = temp[0].trim();
	prodDesc = prodDesc.right(2) == " -" ? prodDesc.substr(0, prodDesc.length - 2) : prodDesc;
	return prodDesc;
}

function getURLVar(urlVarName) {
	//divide the URL in half at the '?'
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]) {
		//load all the name/value pairs into an array
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable
		for(i=0; i<=(urlVars.length); i++) {
			if(urlVars[i]) {
				//load the name/value pair into an array
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
					// Found match, load value into the return variable
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	return urlVarValue;   
}

function setFocus(theForm, theField) {
	if (theForm != '')
		document.forms[theForm].elements[theField].focus();		
}

function forgotPassword() {
	document.forms['frmLogin'].elements['hidForgot'].value = '1';
	document.forms['frmLogin'].submit();
	return true;
}

function divEditContentSetup(thisElement) {
	$("div.divEditContent").hover(function() {
		thisElement.fadeTo("fast", 1);
	}, function () {
		thisElement.fadeTo("fast", .25);
	});
}

function getViewportSize() {

	var viewportSize = [];
 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7)
	// use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined') {
		viewportSize[0] = window.innerWidth,
		viewportSize[1] = window.innerHeight
	}
 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
			&& typeof document.documentElement.clientWidth !=
			'undefined' && document.documentElement.clientWidth != 0) {
		viewportSize[0] = document.documentElement.clientWidth,
		viewportSize[1] = document.documentElement.clientHeight
	}
 
	// older versions of IE 
	else {
		viewportSize[0] = document.getElementsByTagName('body')[0].clientWidth,
		viewportSize[1] = document.getElementsByTagName('body')[0].clientHeight
	}
	
	return viewportSize;
}

function showViewportSize() {
	var viewportSize = getViewportSize();
	alert('Viewport Width = ' + viewportSize[0] + ', Viewport Height = ' + viewportSize[1]);
}

