var new_window;
function windowopen(url,width,height) {
	if (!width) width = window.screen.availWidth * 0.8;

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

	if(arguments.length > 3){
		windowname = arguments[3];
	}else{
		windowname = 'new_window';
	}
	new_window = newWindowOpen(url, width, height, 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 showHideSub(divname){
	Obj = document.getElementById (divname);
	Obj.style.display = Obj.style.display == 'none'
	? 'block'
	: 'none';
}

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 showHideLayer(layer){
	if(layer.style.display == 'none'){
		layer.style.display = ''; 
	}else{
		layer.style.display = 'none';
	}
}

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

function showBox (name, action) {
	if(action == null){
		action = 'block';
	}
	handleCookie (name, action);
}

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' : '');
}

