var DomainKey = "HenryWeinhards.com-"; // must match services configuration key.

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
		return found;
	}

	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
		return index;
	}
	return true;
}

function toggleDefaultValue(objName, defaultValue, focusValue) {
var obj = document.getElementById(objName);
if (obj) {
	if (obj.focus) {
		if (obj.value == defaultValue) {
			obj.value = focusValue;
		} else {
			if (obj.value == "") obj.value = defaultValue;	
		}
	} else {
		if (obj.value == focusValue) {
			obj.value = defaultValue;
		}
	}
}
}

function cmsOpenPopup(href, name, width, height, x, y, menu, status, scroll, loc, resize, title, toolbar){
	var attributes = '';
	if (width.length > 0) attributes = attributes + ',width=' + width;
	if (height.length > 0) attributes = attributes + ',height=' + height;
	if (x.length > 0) attributes = attributes + ',screenx=' + x;
	if (x.length > 0) attributes = attributes + ',left=' + x;
	if (y.length > 0) attributes = attributes + ',screeny=' + y;
	if (y.length > 0) attributes = attributes + ',top=' + y;
	attributes = attributes + ',menubar=' + (menu==1?'yes':'no');
	attributes = attributes + ',status=' + (status==1?'yes':'no');
	attributes = attributes + ',scrollbars=' + (scroll==1?'yes':'no');
	attributes = attributes + ',location=' + (loc==1?'yes':'no');
	attributes = attributes + ',titlebar=' + (title==1?'yes':'no');
	attributes = attributes + ',toolbar=' + (toolbar==1?'yes':'no');
	attributes = attributes + ',resizable=' + (resize==1?'yes':'no');
	attributes = attributes.substring(1,attributes.length);
	var cmsPopup = window.open(href, name, attributes);
}

function openWindow (URL, w, h) {
	var winl = (screen.availWidth - w) / 2;
	var wint = (screen.availHeight - h) / 2;
	var win = window.open(URL,'win','top='+wint+',left='+winl+',scrollbars=yes,toolbar=no,menubar=no,location=no,status=no,resizable=yes,width='+w+',height='+h, true);
	//var win = window.open(URL,'win','top='+wint+',left='+winl+',scrollbars=yes,toolbar=yes,menubar=yes,location=yes,status=yes,resizable=yes,width='+w+',height='+h, true);
	win.focus();
}

function getLUID () {
	/*var key = "luid=";
	var allCookies = document.cookie;
	var pos = allCookies.indexOf(key);
	if (pos == -1) {
		//alert("LUID not found!");
		alert(document.cookie += );
		// create a new LUID
	}
	var start = pos + key.length;
	var end = allCookies.indexOf(";", start);
	if (end == -1)
		end = allCookies.length;
	return unescape(allCookies.substring(start, end));*/
	
	var key = "luid";
	var c = readCookie(key);
	if (c == null || c == "null" || c == "") {
		var id = DomainKey + readCookie("ASP.NET_SessionId");
		createCookie(key, id, 365);
		c = readCookie(key);
	}
	return c;
}