/*
var myADTL2 = new ADTL();
myADTL2.m_bDebug = false;

if (typeof showAjaxWaitGif != 'function')
{
    inc("typo3conf/ext/reea_adds/util/wait.js");
}*/
/*
function getSubCategs(selId)
{

	var catId=document.getElementById(selId).value;

	catId = parseInt(catId);
	if (catId)
	{
		var l_aData = new Array();
		l_aData["catId"] = catId;
		l_aData["callerId"] = encodeURI(selId);
		l_aData["key"] = "SubCategs";
		l_sAjaxServerPage = "typo3conf/ext/reea_adds/util/class.tx_adds_ajaxlibrary.php";
		myADTL2.fetchData(l_aData, l_sAjaxServerPage);
		myADTL2.addDataListener("SubCategs", handleAjaxCall);
		//showAjaxWaitGif();
		document.body.style.cursor = 'wait';
	}
	else
	{
		//reseteaza continutul boxurilor de mai jos
		var idsArr = new Array("tx_reeaadds_pi1[category]", "tx_reeaadds_pi1[subcategory]", "tx_reeaadds_pi1[add_type]");
		for (var i=0; i < 2; i)//idsArr.length; i)
		{
			//determina cite selecturi trebuiesc resetate
			if (idsArr[i++] == selId)
				break;
		}

		//reset selects
//		for (;i<idsArr.length;i++)
		i = 1;
		{
			//get selRef
			sel = document.getElementById(idsArr[i]);
			for (ii=0; ii<sel.options.length-1; ii++)
			{
			    sel.removeChild(sel.lastChild);
			}
		}
	}
}
*/
function buildLocalitate(locId)
{
	var cityId=document.getElementById(locId).value;

	cityId = parseInt(cityId);
	if (cityId)
	{
		var l_aData = new Array();
		l_aData["cityId"] = cityId;
		l_aData["key"] = "loc_id";
		l_aData["callerId"] = encodeURI(locId.replace('city', 'loc_id'));

		l_sAjaxServerPage = "typo3conf/ext/reea_adds/util/class.tx_adds_ajaxlibrary.php";
		myADTL2.fetchData(l_aData, l_sAjaxServerPage);
		
	}
	myADTL2.addDataListener(l_aData["key"], handleAjaxLocalitate);
	//showAjaxWaitGif();
	document.body.style.cursor = 'wait';
}

function handleAjaxCall(arg) {
	
	var out = "";
	var id="";
	var sbSelect = document.getElementById('tx_ttnews[subcategory]');
//	var sbSelect = xajax.$('tx_ttnews[subcategory]');
	
	if (sbSelect == undefined || !sbSelect)
		void(0);

	sbSelect.length=1;

	var i=1;
	var cnt=0;
	var argLength = arg.length-1;
	for (key in arg)
	{
		if (isNaN(key) || cnt++==argLength)
			continue;
					
		var op = document.createElement("option");
	    op.value=key;
	    op.text=arg[key];

		try {
			sbSelect.add(op,null); // standards compliant
		}
		catch(ex) {
			sbSelect.add(op); // IE only
		}			

	}
}

function handleAjaxCallNewAdd(arg) {
	
	var out = "";
	var id="";
	var sbSelect = document.getElementById('tx_reeaadds_pi1[subcategory]');
//	var sbSelect = xajax.$('tx_ttnews[subcategory]');
	
	if (sbSelect == undefined || !sbSelect)
		void(0);

	sbSelect.length=1;

	var i=1;
	var cnt=0;
	var argLength = arg.length-1;
	for (key in arg)
	{
		if (isNaN(key) || cnt++==argLength)
			continue;
					
		var op = document.createElement("option");
	    op.value=key;
	    op.text=arg[key];

		try {
			sbSelect.add(op,null); // standards compliant
		}
		catch(ex) {
			sbSelect.add(op); // IE only
		}			

	}
}

function handleAjaxLocalitate(returnValue)
{
	var locSel = document.getElementById(decodeURI(returnValue['callerId']));

	if (locSel != undefined && locSel)
	{	
		var i = 0;
		optObj = document.createElement("OPTION");
		optObj.value = 0;
		optObj.text = '--- Selectati ---';
		
		locSel.options[i++]=optObj;
		for(var pkey in returnValue['localitate'])
		{
			if (returnValue['localitate'][pkey]['text'])
			{
				optObj = document.createElement("OPTION");
				optObj.value = returnValue['localitate'][pkey]['value'];
				optObj.text = returnValue['localitate'][pkey]['text'];
				
				locSel.options[i++]=optObj;
			}
		}
	}
	//hideAjaxWaitGif();
	document.body.style.cursor = 'default';	
}
/*
// Define the error handler method
myADTL2.errorHandler = function(p_sCode, p_sMsg) {
	alert("I am sorry to report that the application " + 
	      "has failed to receive a response from the " + 
	      "server. The technical description of the " + 
	      "error is the following:\n" + 
	      p_sCode + ": " +  p_sMsg);
}
*/

function checkPrices()
{
	var p, pm;
	try {
		p = document.getElementsByName('tx_reeaimobiliare_pi6[pret]')[0];
		pm = document.getElementsByName('tx_reeaimobiliare_pi6[pret_max]')[0];
	}
	catch(e)
	{}
	
	if (p != undefined && pm != undefined)
	{
		if (p.value<0 || pm.value<0 || p.value>=pm.value)
		{
			alert('Va rugam sa revizuiti preturile introduse ca si criterii de cautare');
			return false;
		}
		else
			return true;
	}
}
