function goToUrl(url) {
	disableButtons();
	this.window.name="currentWindow";
	var childWindow = window.open(url,this.window.name,"",false); //add entry to browser history
}

function openUrl(url, width, height) {
    if(arguments.length == 1) {
        width=660;
        height=500;
    }
    var params = "width="+width+",height="+height+",resizable=yes,scrollbars=yes,menubar=yes,status=yes,toolbar=yes,location=yes";
    //,location=yes";
	var childWindow = window.open(url,null,params,false);
}

function openUrlwDisclaimer(url, width, height) {
    if(arguments.length == 1) {
        width=200;
        height=300;
    }
    var params = "width="+width+",height="+height+",resizable=yes,scrollbars=yes,menubar=yes,status=yes,toolbar=yes,location=yes";
    //,location=yes";
    var fullurl = "redirect.do?url=";
    if(url.indexOf('outsideofus')>=0) {
    	fullurl += "worlddisclaimer&redirect="+url;
    } else if(url.indexOf('outsideofstate')>=0) {
    	fullurl += "traveldisclaimer&redirect="+url;
    } else if(url.indexOf('mesa')>=0) {
    	fullurl += "mesadisclaimer&redirect="+url;
    } else {
    	fullurl += "leavingdisclaimer&redirect="+url;
    }
	var childWindow = window.open(fullurl, null, "", false);
}

function popupUrl(url, width, height) {
    if(arguments.length == 1) {
        width=800;
        height=600;
    }
    var params = "width="+width+",height="+height+",resizable=yes,scrollbars=yes";
	var childWindow = window.open(url,'popup',params,false);
}

/* 
 * This module checks all input fields on the home page to determine that at least one item is selected.
 * The form is submitted only if some criteria is provided; otherwise an error message is displayed.
 */
var isModified = false;
function checkModified(errorMessage) {
	isModified = false;
	var frm = document.forms[0];
	for (var i=0; i<document.forms[0].length; i++) {
		var elem = document.forms[0].elements[i];
		if(elem.type == 'text') {
			var val = elem.value;
			var result = val.match(/\w+/g);
			if(result != null) {
				isModified = true;
			}
		} else if(elem.type == 'select-one') {
			if(elem.value != 0 && elem.value != '') {
				isModified = true;
			}
		} else if(elem.type == 'checkbox') {
			if(elem.checked) {
				isModified = true;
			}
		}
	}
	if(isModified) {
		submitForm(this,'Search');
	} else {
		alert(errorMessage);
	}
	return false;
}

/** The p_object parameter is the object that called
 *  this function (i.e., send 'this' (without the quotes)
 *  as a parameter).  If the object calling this function
 *  is determined to be a submit button, the form is not
 *  submitted via this function, thus preventing the form
 *  from being submitted twice.
 */
function submitForm(p_object, p_actionType)
{
	for (n=0; n<document.forms.length;n++){
		document.forms[n].actionType.value = p_actionType;
		if (p_object.type != 'submit')
		{
			//only submit if the calling object is not a submit button
			disableButtons();
			document.forms[n].submit();
		}	
	}
}

function displayDetail(p_object, p_value)
{
	for (n=0; n<document.forms.length;n++){
		//if(document.forms[n].name = 'search-form') {
		if(document.forms[n].providerID != null) {
			document.forms[n].providerID.value = p_value;
		}
	}
	submitForm(p_object, 'ProviderDetail');
}

function deleteCrumbs(p_object, p_value)
{
//alert("crumbIndex: " + p_value);
	for (n=0; n<document.forms.length;n++){
		//if(document.forms[n].name = 'search-form') {
		if(document.forms[n].providerID != null) {
		//alert("crumbIndex: " + p_value);
			document.forms[n].crumbIndex.value = p_value;
		}
	}
	submitForm(p_object, 'RemoveBreadcrumbs');
}

function displayPage(p_object, p_value)
{
//alert('set page to ' + p_value);
//alert('current page = ' + document.forms[0].currentPageNumber.value);
//alert('numberOfPages = ' + document.forms[0].numberOfPages.value);

	for (n=0; n<document.forms.length;n++){
		//if(document.forms[n].name = 'search-form') {
		if(document.forms[n].newPageNumber != null) {
			document.forms[n].newPageNumber.value = p_value;
		}
	}
	submitForm(p_object, 'Page');
}

function isBlank(strValue)
{
	if (strValue == null ||  strValue == "")
	{
		return true;
	} //end if

	return false;
}

// Runs through the all elements on the form,
// disabling all buttons.
// Note that we assume one form per page.  Throughout
// all of the functions in this JavaScript file, it is
// assumed that the submitted form is the only form, thus
// the references to forms[0].  Should we ever move away
// from this assumption, add an extra loop in this function
// to go through all forms in the document.

// 5/16/06 Added second loop becuase we can no longer assume one form per page!
function disableButtons()
{
	for (j=0; j<document.forms.length;j++){		
		if (document.forms.length == 0
		||  document.forms[j].elements.length == 0)
		{
			return;
		}
		for (i=0; i<document.forms[j].elements.length;i++)
		{
			var form_element = document.forms[j].elements[i];
			if (form_element.type == 'submit'
			||  form_element.type == 'button')
			{
				form_element.disabled = 'true';
			}
		}	
	}
}

// This function should be called in the onSubmit attribute
// of the form tag for all JSPs.  It is an opportunity to handle
// any client-side JS necessary as the form is being submitted
// to the server.
function formOnSubmit()
{
	disableButtons();

	return true;
} //end formOnSubmit

// Used in the error page to show more details when needed
function toggleDisplayById(id){
	if(document.getElementById(id).style.display=="") {
		document.getElementById(id).style.display = "none";
	} else {
		document.getElementById(id).style.display = "";
	}
}

	function setType(object, value, action)
	{
		document.forms[0].providerType.value = value;
		submitForm(object, action);
	}
	function setZip(object, value, action)
	{
		document.forms[0].zipcode.value = value;
		submitForm(object, action);
	}
	function setNetwork(object, value, action)
	{
		document.forms[0].network.value = value;
		submitForm(object, action);
	}
	function setSpecialty(object, value, action)
	{
		document.forms[0].specialty.value = value;
		submitForm(object, action);
	}
	function setLanguage(object, value, action)
	{
		document.forms[0].language.value = value;
		submitForm(object, action);
	}
	function setGender(object, value, action)
	{
		document.forms[0].gender.value = value;
		submitForm(object, action);
	}
	function setRadius(object, value, action)
	{
		document.forms[0].radius.value = value;
		submitForm(object, action);
	}
	//<!-- START hide/show div -->
function ShowHide(elementId)
{
	var element = document.getElementById(elementId);
	if(element.style.display != "block")
	{
		element.style.display = "block";
	}
	else
	{
		element.style.display = "none";
	}
}
function UpdateText(element, name)
{
	if(element.innerHTML.indexOf("Show") != -1)
	{
		element.innerHTML = "See less " + name;
	}
	else
	{
		element.innerHTML = "See more " + name;
	}
}

