function formatPhone (textField) {
  textField.value = textField.value.replace(/^(?:1-)?\(?(\d{3})[\)-]?[\s]?(\d{3})[\)\s-]?(\d{4})$/, "$1-$2-$3");
}

function showShadeDiv() {
  // show shade and dialog box
  document.getElementById("shade_div").style.display = 'block';
}

function hideShadeDiv() {
  // show shade and dialog box
  document.getElementById("shade_div").style.display = 'none';
}

function showShadeDivDialog(ajaxUrl, zones) {
	showShadeDiv();
	if (zones == null) zones = "dialog";
	ajaxAnywhere.getAJAX(ajaxUrl, zones);	
}

function showYesNoDialog(actionUrl, objectId) {	
	showShadeDiv();
	document.getElementById("yes_no_div").style.display = 'block';
	length_actionUrl = actionUrl.length;
	last_char_actionUrl = actionUrl.charAt(length_actionUrl-1);
	if (last_char_actionUrl == '&') {
		document.getElementById("dialog_yes").href=actionUrl+"objectId="+objectId;
	} else {
		document.getElementById("dialog_yes").href=actionUrl+"?objectId="+objectId;
	}
	
}

function showYesNoDialogUrl(actionUrl) {	
	showShadeDiv();
	document.getElementById("yes_no_div").style.display = 'block';	
	document.getElementById("dialog_yes").href=actionUrl;
}

function hideYesNoDialog() {
	hideShadeDiv();
	document.getElementById("yes_no_div").style.display = 'none';
	document.getElementById("dialog_yes").href='';
}

function hideShadeDivDialog() {
	hideShadeDiv();
	var dialog = document.getElementById('aazone.dialog');
	if (dialog != null) dialog.innerHTML = "";
}

function hideConfirmation() {
	var dialog = document.getElementById('aazone.confirmation');
	if (dialog != null) dialog.innerHTML = "";
}

function showAlert(message, headerWidth) {	
	showShadeDiv();
	document.getElementById("alert_div").style.display = 'block';	
	document.getElementById("alert_mes").innerHTML = message;	
	if(headerWidth != undefined) {
		document.getElementById("alert_header_div").style.width = headerWidth;
	}	
}
function hideAlert() {	
	hideShadeDiv();
	document.getElementById("alert_div").style.display = 'none';	
}

function _showAlert(message, headerWidth, locationHref) {
	showShadeDiv();
	document.getElementById("_alert_div").style.display = 'block';	
	document.getElementById("_alert_mes").innerHTML = message;
	document.getElementById("_alert_button").onclick =  function() { document.location.href = locationHref };
	if(headerWidth != undefined) {
		_headerWidth = headerWidth - 10;
		document.getElementById("_alert_header_div").style.width = _headerWidth + 'px';
		document.getElementById("_alert_div").style.width = headerWidth + 'px';
	}	
}
function _hideAlert() {	
	hideShadeDiv();
	document.getElementById("_alert_div").style.display = 'none';	
}

function prepareTextFieldValues(){
	var inputElemList = document.getElementsByTagName('input');  
	for (var i = 0; i < inputElemList.length; i++) {
		var inputEl = inputElemList[i]; 
		if (inputEl.getAttribute('type') != 'text' || inputEl.getAttribute('value') == null) {			
			continue;
		}
		inputEl.value = inputEl.getAttribute('value').replace(/&(lt|gt);/g, function (strMatch, p1){
		 	return (p1 == "lt")? "<" : ">";
		});
	} 
}

function  textCounter(field, countfield, maxlimit) {
 if (field.value.length > maxlimit) // if too long...this trims it!
  field.value = field.value.substring(0, maxlimit);
 // otherwise, update 'characters left' counter
 else 
  countfield.value = maxlimit - field.value.length;
}
