function MyError()
{
  	alert('Ocorreu um erro no acesso ao servidor!');
}


function FillCombo(oElem, oTarget, oFill)
{
  	var strValue = oElem.options[oElem.selectedIndex].value;
  	var strFName = oTarget.form.name;
  	var strEName = oTarget.id;
  	if (!strEName)
  		strEName = oTarget.name;

	var ot = document.getElementById('ot').value;
	if (!oFill)
		oFill = '';
	
  	if (!strValue)
  	{
	   var objDDL = document.forms[strFName].elements[strEName];
	  	objDDL.options.length = 0;
	}
	else
	{
		var url = "index.php?module=FMS&func=fillcomboajax";
	  	var strParams = "q=" + strValue +
		  					 "&f=" + strFName +
							 "&e=" + strEName +
							 "&ot=" + ot +
							 "&fill=" + oFill;

		var loader1 = new net.ContentLoader(url, FillDropDown, MyError, "POST", strParams);
	}
}

function FillDropDown()
{
  	var xmlDoc = this.req.responseXML.documentElement;

  	var xSel = xmlDoc.getElementsByTagName('selectElement')[0];
  	var strFName = xSel.childNodes[0].firstChild.nodeValue;
  	var strEName = xSel.childNodes[1].firstChild.nodeValue;

  	var objDDL = document.forms[strFName].elements[strEName];
  	objDDL.options.length = 0;

  	var xRows = xmlDoc.getElementsByTagName('entry');
  	for(i = 0; i < xRows.length; i++)
  	{
		var theText = xRows[i].childNodes[0].firstChild.nodeValue;
		var theValue = xRows[i].childNodes[1].firstChild.nodeValue;
		var option = new Option(theText, theValue);

		try {
		  	objDDL.add(option, null);
		}
		catch (e)
		{
		  	objDDL.add(option, -1);
		}
	}
}


/**
 *
 * @access public
 * @return void
 **/
function FilterContacts(oElem1, oElem2, oElem3, oTarget, nocontacttype)
{
  	var oElem1 = document.getElementById(oElem1);
  	var oElem2 = document.getElementById(oElem2);
  	var oElem3 = document.getElementById(oElem3);

	var strValue1 = oElem1.options[oElem1.selectedIndex].value;
	var strValue2 = oElem2.options[oElem2.selectedIndex].value;
	var strValue3 = oElem3.value;
  	var strFName = oTarget.form.name;
  	var strEName = oTarget.id
  	if (!strEName)
  		strEName = oTarget.name;

/*  	if (!strValue1 && !strValue2)
  	{
	   var objDDL = document.forms[strFName].elements[strEName];
	  	objDDL.options.length = 0;
	}
	else
	{
*/		var url = "index.php?module=FMS&func=filtercontactsajax";
	  	var strParams = "&q1=" + strValue1 +
	  						 "&q2=" + strValue2 +
	  						 "&q3=" + strValue3 +
		  					 "&f=" + strFName +
							 "&e=" + strEName + 
							 "&nocontacttype=" + nocontacttype;
//alert(url + strParams);
		var loader1 = new net.ContentLoader(url, FillDropDown, MyError, "POST", strParams);
//	}
}
