function hidediv(divName) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divName).style.visibility = 'hidden';
	}
	else {
		if (document.layers) { // Netscape 4
			document.pleaseWait.visibility = 'hidden';
		}
		else { // IE 4
			document.all.pleaseWait.style.visibility = 'hidden';
		}
	}
}

function showdiv(divName) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divName).style.visibility = 'visible';
	}
	else {
		if (document.layers) { // Netscape 4
			document.pleaseWait.visibility = 'visible';
		}
		else { // IE 4
			document.all.pleaseWait.style.visibility = 'visible';
		}
	}
}
    
function syncWidth(firstel, secondel) {
	document.getElementById(firstel).style.width = null;
	document.getElementById(secondel).style.width = null;
	// Get elements natural width
	var firstwidth = document.getElementById(firstel).offsetWidth;
	var secondwidth = document.getElementById(secondel).offsetWidth;
	// Size both elements after the widest of the two
	var width = (firstwidth > secondwidth) ? firstwidth : secondwidth;
	document.getElementById(firstel).style.width = width + "px";
	document.getElementById(secondel).style.width = width + "px";
}

function compareObjNames(el1, el2) {
	if (el1.name < el2.name) return -1
	if (el2.name < el1.name) return 1
	return 0;
}

function compareObjNameIDs(el1, el2) {
	if (el1.name < el2.name) {
		if (parseInt(el1.id) < parseInt(el2.id)) return -1
		if (parseInt(el2.id) < parseInt(el1.id)) return 1
	}
	if (el2.name < el1.name) {
		if (parseInt(el1.id) < parseInt(el2.id)) return 1
		if (parseInt(el2.id) < parseInt(el1.id)) return -1
	}
	return 0;
}

function sortAndCompleteNameIDList(list) {
	list.sort(compareObjNames);
	//list.sort(compareObjNameIDs);
	return completeNameIDList(list);
}

function completeNameIDList(list) {
	var flag = false;
	for (var i = 1; i <= list.length; i++) {
		if (i < list.length && list[i - 1].name == list[i].name) {
			list[i - 1].name += " (" + list[i - 1].id + ")";
			flag = true;
		} else if (flag) {
			list[i - 1].name += " (" + list[i - 1].id + ")";
			flag = false;
		}
	}
	return list;
}

function clearCombo(id) {
	var element = document.getElementById(id);
	if (element && element.options) {
		for (var i = 1; i < element.options.length; i++) {
			element.options[i] = null;
		}
		element.options.length = 1;
	}
}

function deleteit() {
	return confirm("Do you want to proceed with deleting?");
}

function commitit() {
	return confirm("Do you want to commit your changes now?");
}

function getCookie(name) {
   var result = null;
   var myCookie = " " + document.cookie + ";";
   var searchName = " " + name + "=";
   var startOfCookie = myCookie.indexOf(searchName)
   var endOfCookie;
   if (startOfCookie != -1) {
      startOfCookie += searchName.length; //skip past cookie name
      endOfCookie = myCookie.indexOf(";", startOfCookie);
      result = unescape(myCookie.substring(startOfCookie,endOfCookie));
	 }
   return result;
}

function setCookie(name,value,path) {
	var pathString = ((path == null) ? "" : ("; path=" + path))
	document.cookie = name + "=" + escape(value) + pathString;
}

/*
	Code to add trim functionality to String componenet
*/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
