function setVisibility_explicit(id, visibility) {
	document.getElementById(id).style.display =visibility;
}

function setVisibility(id, visibility) {
	if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display ="inline";
	} else {
		document.getElementById(id).style.display = "none";
	}
}

function MM_preloadImages() { //v3.0
	var d=document; 
	if(d.images){ 
		if(!d.MM_p) d.MM_p = new Array();
		var i;
		var j=d.MM_p.length;
		var a=MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++){
			if (a[i].indexOf("#")!=0){ 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
			}
		}
	}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ccvPopup() {
	window.open('ccv-popup.html', 'ccvWin', 'width=440,height=400,scrollbars=1');
	return true;
}

function defaultMessage(id, msg) {
	var i = document.getElementById(id);
	if(i) {
		i.onclick = function() { if(i.value == msg) { i.value = ""; } };
		i.onblur = function() { if(i.value == "") { i.value = msg } };
	}    
}

// **********************************************************************
// Functions For Lists
// **********************************************************************

function checkAll() {
	f = document.forms['list'];
	for (i = 0; i < f.elements.length; i++)
		if (f.elements[i].type == 'checkbox')
			f.elements[i].checked = true;
}

function uncheckAll() {
	f = document.forms['list'];
	for (i = 0; i < f.elements.length; i++)
		if (f.elements[i].type == 'checkbox')
			f.elements[i].checked = false;
}

function deleteGroup() {
	if (confirm("Are you sure you want to delete the checked items?")) {
		field = document.getElementById('list');
		if(field != null)
		  field.value = 1;
		f = document.forms['list'];						
		f.submit();
	}
}


function list_switch(url) {
	var A;
	
	document.body.style.cursor = 'wait';
	try {
		A = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			A=new ActiveXObject("Microsoft.XMLHTTP");
		} catch (oc) {
			A=null;
		}
	}
	if(!A && typeof(XMLHttpRequest) != "undefined")
		A = new XMLHttpRequest();
	if (!A) {
		document.body.style.cursor = 'auto';
		return true;
	}
	
	A.open("GET", url, true);
	A.setRequestHeader("X-Lister-customer_support_categories", "Ajax");
	A.onreadystatechange = function() {
		if (A.readyState != 4)
			return;
		
		// redraw the table
		document.getElementById("list").innerHTML = A.responseText;
		document.body.style.cursor = 'auto';
	}
	A.send(null);
	delete A;
	return false;
}

// usage: 
//  onclick="return list_switch('categories.php?category_key=9&t=1227246947&move=down');"


// **********************************************************************
// PopUp Window
// **********************************************************************


function PopUpWindow(url,name,width,height) {
	window.open(url,name,"menubar=1,scrollbars=1,resizable=1,width="+width+",height="+height);
}

// **********************************************************************
// Functions For Validating Fields
// **********************************************************************

//  check for valid numeric strings	
function IsNumeric(strString,allowdot) {
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	if(allowdot) strValidChars = strValidChars + ".";
	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1){
			blnResult = false;
		}
	}
	return blnResult;
}

function TypeJustCurrency(e,allowdot){
	var keynum;
	var keychar;
	var numcheck;

	if(window.event){
		// IE
		keynum = e.keyCode;
	} else if(e.which) {
		// Netscape/Firefox/Opera
		keynum = e.which;
	}
	keychar = String.fromCharCode(keynum);
	return IsNumeric(keychar,allowdot);
}

function OnEnterSubmit(e,form){
	var keynum;
	var keychar;
	var numcheck;

	if(window.event){
		// IE
		keynum = e.keyCode;
	} else if(e.which) {
		// Netscape/Firefox/Opera
		keynum = e.which;
	}
	
	if (keynum == 13) {
		form.submit();
		return false;
    }
}

// **********************************************************************
// End Session If Window closed
// **********************************************************************
/*
function logout_user(){
	if(window.screenLeft >screen.width){
		alert("method 1x");
		//browser is closed
	}else{
		//refresh
		alert("method 2x");
	}
	
	if(window.event){
		var e = window.event;
		if((e.clientX<0) && (e.clientY<0)) {
			// window.open("logout.php");     
			alert("method 1");
		}
		if (e.clientX+screen.width < 0 && e.clientY+screen.height < 0) {
			alert("method 2");
		}
	}	
}
*/
// window.onunload = logout_user;




// **********************************************************************
// Change Focus
// **********************************************************************

function change_focus(limit, currentId, nextId){
	var element = document.getElementById(currentId);
	if(element.value.length >= limit){
		document.getElementById(nextId).focus();
	}
}

function assembly_phone_from_parts(id) {
	var i = document.getElementById(id);
	var i1 = document.getElementById(id+'-part1');
	var i2 = document.getElementById(id+'-part2');
	var i3 = document.getElementById(id+'-part3');
		
	if(i1 && i2 && i3) {
		i.value = "(" + i1.value + ") " + i2.value + "-" + i3.value;
	}
}
