function windowopen(url,popWidth,popHeight) {  

	if (!popWidth) popWidth = window.screen.availWidth * 0.8;

	if (!popHeight) popHeight =  window.screen.availHeight * 0.6;

	if(arguments.length > 3){
		windowname = arguments[3];
	}else{
		windowname = 'new_window';
	}
	new_window = newWindowOpen(url, popWidth, popHeight, windowname);
	if (window.focus) {
		new_window.focus();
	}
}

function autoTab(e, field, length, nextfield){
	var whichCode = (window.Event) ? e.which : e.keyCode;
	strCheck = ',47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105,';
	if (strCheck.indexOf(',' + whichCode + ',') != -1) {
		if(field.value.length == length){
			nextfield.focus();
			nextfield.select();
		}
		return true;
	}else{
		return false;
	}
}

function newWindowOpen(url, width, height, name) {
	return window.open(url, name, 'width='+width+', height='+height+', left='+(((window.screen.availWidth - width)/2)-15)+', top='+((window.screen.availHeight - height)/2)+', toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no');
}


function showLayer(layer){
	if(typeof layer == 'string'){
		layer = document.getElementById(layer);
	}
	layer.style.display = '';
}

function hideLayer(layer){
	if(typeof layer == 'string'){
		layer = document.getElementById(layer);
	}
	layer.style.display = 'none';
}

function showHideLayer(layer){
	if(typeof layer == 'string'){
		layer = document.getElementById(layer);
	}
	if(layer.style.display == 'none'){
		showLayer(layer);
	}else{
		hideLayer(layer);
	}
}

function hideBox (name) {
	handleCookie (name, 'none');
}

function showBox (name) {
	handleCookie (name, 'block');
}

function handleCookie (name, action) {
	var cookiename = 'hide_cookie';

	//get the current value of the cookie, so we can insert this box into the cookie
	var current_cookie = unescape (document.cookie);

	var cookies = current_cookie.split(';');
	var cookie_found = 0;
	var new_cookie = ''; 

	for (var t=0; t< cookies.length; t++) {
		var cname = cookies[t].split ('=');

		//If cname has no properties, it means that we got no cookie
		//So let us break out of the loop

		//If the cookie matches hide_cookie, we got the cookie we want
		if (eval ((cname[0]==' '+cookiename) || cname[0]==cookiename)) {
			//Now we got the value of our cookie in cname[1], so let us split that one up also
			hiddenboxes = cname[1].split('&');
			for (var y=0; y<hiddenboxes.length; y++) {
				var cval = hiddenboxes[y].split (':');
				if (cval[0] == name) {
					hiddenboxes[y] = name+':'+action;
					new_cookie += cval[0]+':'+action+'&';
					cookie_found = 1;
				} else if (cval[0].length > 0) {
					new_cookie += cval[0]+':'+cval[1]+'&';
				}
			}
		}
	}

	if (cookie_found == 0){
		new_cookie += name+':'+action;
	}

	var today = new Date();
	var expire = new Date ();
	expire.setTime (today.getTime() + 3600000*24*365);
	document.cookie = cookiename + '=' + escape (new_cookie) + ';expires='+expire.toGMTString();
}

function setCookie(name, value, expires, path, domain, secure){
	document.cookie= name + '=' + escape(value) +
	((expires) ? '; expires=' + expires.toGMTString() : '') +
	((path) ? '; path=' + path : '') +
	((domain) ? '; domain=' + domain : '') +
	((secure) ? '; secure' : '');
}

//radioButtonValue - return the value of the checked item in a given radiobutton list - argument: radiobutton element (eg. document.forms[0].myradio)
function radioButtonValue(rElement){
	if(rElement.length != null){
		for (var i=0; i < rElement.length; i++){
			if (rElement[i].checked){
				return rElement[i].value;
			}
		}
	}
	//if nothing found
	return null;
}

// consultant web has some checkbox functions here...but we dont use those in cust/tempweb


//make sure opened windows knows which window the axpmainwin is, even if they're opened by other windows.
if(window.opener != null){
	if(window.opener.axpmainwin != null){
		axpmainwin = window.opener.axpmainwin;
	}else{
		axpmainwin = window.opener;
	}
}

//add a trim method to strings for js
if(!String.prototype.trim) { 
	String.prototype.trim = function() {
		return this.replace(/^\s+/g, "").replace(/\s+$/g, "");
	};
}

//this function is an eventhandler for onkeyup on input fields - will check if the pressed key is enter, and if it is, return false, so forms do not submit.
function enter_nosubmit(e){
	var key;
	if(window.event){
		key = window.event.keyCode;     //IE
	}else{
		key = e.which;     //firefox
	}
	if(key == 13){
		return false;
	}else{
		return true;
	}
}
