function aColumnEmpty(event) {
	var serviceFound = false;
	var destinationFound = false;
	var allInputs = document.getElementsByTagName("input");
	for (var i = 0; i < allInputs.length; i++) {
		if(allInputs[i].name.substring(0, 9) == "ftermlist" && allInputs[i].checked) {destinationFound = true};
		if(allInputs[i].name.substring(0, 11) == "fnumberlist" && allInputs[i].checked) {serviceFound = true};
	}
	if(!serviceFound || !destinationFound) {
		alert("You must make selections in both Service Number and Destination Number columns, otherwise your report will be blank.");
		cancelEvent(event, true);
		return false;
	} else {
		return true;
	}
}

function accountsSelected(event) {
	var found = false;
	if (!document.getElementById("accountgrid")) {
		
		found = true;
	}
	var allInputs = document.getElementsByTagName("input");
	for (var i = 0; i < allInputs.length; i++) {
		if(allInputs[i].name.substring(0, 12) == "custid_array" && allInputs[i].checked) {
			found = true; 
		}
	}
	if(!found) {
		alert("Please select one or more accounts.");
		return false;
	} else {
		return true;
	}
}
	

function confirmdelete(url) {
	result = confirm("Do you really want to delete this record?");
	if (result) {
		document.location.replace(url);
		return true;
	} else {
		return false;
	}
}

function makeUser() {
	var u = document.getElementById('fcustID');
	document.getElementById('fusername').value = u.options[u.selectedIndex].attributes.id.value +
	document.getElementById('fsurname').value.toLowerCase().substring(0,4);
}

function getDateString(y_obj,m_obj,d_obj) {
	var y = y_obj.options[y_obj.selectedIndex].value;
	var m = m_obj.options[m_obj.selectedIndex].value;
	var d = d_obj.options[d_obj.selectedIndex].value;
	if (y=="" || m=="") { return null; }
	if (d=="") { d=1; }
	return str= y+'-'+m+'-'+d;
	}

function sniffDivUsable() {
	if (navigator.userAgent.indexOf("Netscape") != -1) {
		if (parseFloat(navigator.appVersion.split("Netscape")[1]) < 6) {
			return false;
		}
	}
	if (navigator.userAgent.indexOf("MSIE") != -1) {
		if (parseFloat(navigator.appVersion.split("MSIE")[1]) < 7) {
			return false;
		}
	}
	return true;
}

function datesCrossed(d1, m1, y1, d2, m2, y2) {
	var date1 = getDateString(document.getElementById(y1), document.getElementById(m1), document.getElementById(d1));
	var date2 = getDateString(document.getElementById(y2), document.getElementById(m2), document.getElementById(d2));
	if (date1 > date2) {
		alert("Start date must be before end date.");
		return true;
	} else {
		return false;
	}
}

function toggleGraph() {
	var g = document.getElementById("graphimg");
	if (g.style.visibility == "hidden") {
		//show graph
		g.style.visibility = "visible";
		g.style.height = "550px";
	} else {
		//hide graph
		g.style.visibility = "hidden";
		g.style.height = "0";
	}
}
/*
function toggleGraph(event) {
	var g = document.getElementById("graphimg");
	if (g == null) {
		//No graph image, so we will have to go back to the server
		return true;
	}
	var links = document.getElementsByTagName("a");
	var h = document.getElementById("hidelink");
	if (g.style.visibility == "hidden") {
		//show graph
		g.style.visibility = "visible";
		g.style.height = "550px";
		for (var i = 0; i < links.length; i++) {
			if (links[i].href.indexOf(location.pathname) != -1) {
				links[i].href = links[i].href.replace(/&?hidegraph=yes/g, "");
			}
		}
		h.innerHTML = h.innerHTML.replace(/Show/, "Hide");
	} else {
		//hide graph
		g.style.visibility = "hidden";
		g.style.height = "0";
		for (var i = 0; i < links.length; i++) {
			if (links[i].href.indexOf(location.pathname) != -1) {
				links[i].href = links[i].href.replace(/&?hidegraph=no/g, "");
				links[i].href += "&hidegraph=yes";
			}
		}
		h.innerHTML = h.innerHTML.replace(/Hide/, "Show");
	}
	cancelEvent(event, true);
	return false;
}
*/

function wopen(url, name, w, h)
{
w += 32;
h += 96;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=no, resizable=no');
 win.resizeTo(w, h);
 win.focus();
}

function removeSpaces(str) {
	var result = "";
	str = "" + str;
	splitstring = str.split(/[^0-9]/);
	for(i = 0; i < splitstring.length; i++)
	result += splitstring[i];
	return result;
}

function invalidPhone(str) {
	return 	(str.length < 10 || str.length > 11 || str.charAt(0) != "0");
}

function alertBadNumber(maxnumbers, event) {
	if ((invalidPhone(document.getElementById("fnumberfrom").value) ||
			invalidPhone(document.getElementById("fnumberto").value )) && !document.createnumbersform.fallavail.selectedIndex) {
		alert("Invalid number format: must start with 0 and be 10-11 numbers long.");
		cancelEvent(event, true);
		return false;
	}
	diff = document.createnumbersform.fnumberto.value - document.createnumbersform.fnumberfrom.value;
	if ((diff >= maxnumbers || diff < 0 || document.createnumbersform.fnumberto.value == '') && !document.createnumbersform.fallavail.selectedIndex) {
		alert("Please check number range - " + maxnumbers + " max numbers in batch");
		cancelEvent(event, true);
	}
}

function disableRow(cb) {
	var row = cb.parentNode.parentNode;
	for (var i = 0; i < row.cells.length; i++) {
		var child = row.cells[i].firstChild;
		if (child != cb) {
			try {
				var s = row.cells[i].style;
				if (cb.checked) {
					s.color = 'black';
				} else {
					s.color = 'gray';
				}
				child.disabled = !cb.checked;
			} catch(e) {}
		}
	}
}

function checkAll(colName, masterObj) {
	var cb = document.getElementsByTagName("input");
	for (var i = 0; i < cb.length; i++) {
		if (cb[i].type == "checkbox" && cb[i].name.indexOf(colName) == 0) {
			cb[i].checked = masterObj.checked;
			disableRow(cb[i]);
		}
	}
}

function ignoreReturn(event) {
	if ((window.event && event.keyCode == 13) || (event.which && event.which == 13)) {
		cancelEvent(event, true);
	}
}

function addInputs(obj, gridContents, sortbyContents, dirContents, action) {
	newGrid = document.createElement("input");
	newGrid.setAttribute("type", "hidden");
	newGrid.setAttribute("name", "grid");
	newGrid.setAttribute("value", gridContents);
	newGrid.setAttribute('className', 'genericelement-form-field');
	document.form.appendChild(newGrid);
	newSortby = document.createElement("input");
	newSortby.setAttribute("type", "hidden");
	newSortby.setAttribute("name", "sortby");
	newSortby.setAttribute("value", sortbyContents);
	document.form.appendChild(newSortby);
	newDir = document.createElement("input");
	newDir.setAttribute("type", "hidden");
	newDir.setAttribute("name", "dir");
	newDir.setAttribute("value", dirContents);
	document.form.appendChild(newDir);
	obj.removeAttribute("href");
	document.form.action = action;
}

function gridCheckAll(gridId, switchBox) {
	var cb = document.getElementById(gridId).getElementsByTagName('input');
	for(var i=0; i < cb.length; i++) {
		cb[i].checked = switchBox.checked;
	}
}

function cancelEvent(e, c)
{
	e.returnValue = false;
	if (e.preventDefault) e.preventDefault();
	if (c)
	{
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	}
}

var newwin;

var javascript_version = 1.0;
javascript_version = 1.1;

function myHref(page, ID, linkID, winname, winfeatures){
	var anchorlink = "myAnchor["+linkID+"]"; //Creates the string for the link ID
	var url=page + ID;
	//This launches a new window and then
	//focuses it if window.focus() is supported.
	newwin = window.open(url,winname,winfeatures); //Opens a new window
	if(javascript_version > 1.0)
	{
		//delay a bit here because IE4 encounters errors
		//when trying to focus a recently opened window
 		setTimeout('newwin.focus();',250);
	}
}