
var currTab = commonGetCookie("currTab");

/* ------------------------------------------------------------------------------------------------ */
/* showNadlanTab																					*/
/* ------------------------------------------------------------------------------------------------ */
function showNadlanTab (which)
{
	try
	{
		document.getElementById("tab1").className 				= "nadlanTab1";
		document.getElementById("tabData1").style.display 		= "none";
		document.getElementById("totalText1").style.display 	= "none";
	}
	catch (e)
	{
	}

	try
	{
		document.getElementById("tab2").className 				= "nadlanTab2";
		document.getElementById("tabData2").style.display 		= "none";
		document.getElementById("totalText2").style.display 	= "none";
	}
	catch (e)
	{
	}

	try
	{
		document.getElementById("tab3").className 				= "nadlanTab3";
		document.getElementById("tabData3").style.display 		= "none";
		document.getElementById("totalText3").style.display 	= "none";
	}
	catch (e)
	{
	}

	currTab = which;

	commonSetCookie ("currTab", currTab);

	document.getElementById("tab" + currTab).className 				= "nadlanTab" + currTab + "_selected";
	document.getElementById("tabData" + currTab).style.display 	 	= "";
	document.getElementById("totalText" + currTab).style.display 	= "";

/*	if (which == "2")
	{
		alert ("בימים הקרובים יעודכנו נכסים בקטגוריה זו.");
	}
*/
}

/* ------------------------------------------------------------------------------------------------ */
/* sortUp																							*/
/* ------------------------------------------------------------------------------------------------ */
function sortUp (by)
{
	oForm = document.getElementById("nadlanSearchForm");

	oForm.sortBy.value  = by;
	oForm.sortDir.value = "asc";

	oForm.submit ();
}

/* ------------------------------------------------------------------------------------------------ */
/* sortDown																							*/
/* ------------------------------------------------------------------------------------------------ */
function sortDown (by)
{
	oForm = document.getElementById("nadlanSearchForm");

	oForm.sortBy.value  = by;
	oForm.sortDir.value = "desc";

	oForm.submit ();
}

/* ------------------------------------------------------------------------------------------------ */
/* overNadlanRow																					*/
/* ------------------------------------------------------------------------------------------------ */
function overNadlanRow (which, id)
{
	className = document.getElementById(which + "NadlanRow" + id).className;

	if (className.indexOf("_open") == -1)
		document.getElementById(which + "NadlanRow" + id).className += "_open";
}

/* ------------------------------------------------------------------------------------------------ */
/* outNadlanRow																						*/
/* ------------------------------------------------------------------------------------------------ */
function outNadlanRow (which, id)
{
	className = document.getElementById(which + "NadlanRow" + id).className;

	if (document.getElementById(which + "Details"   + id).style.display	== "none" && className.indexOf("_open") != -1)
		document.getElementById(which + "NadlanRow" + id).className		= className.substr(0,className.length-5);
}

/* ------------------------------------------------------------------------------------------------ */
/* openCloseNadlanRow																				*/
/* ------------------------------------------------------------------------------------------------ */
function openCloseNadlanRow (which, id)
{
	className = document.getElementById(which + "NadlanRow" + id).className;

	if (document.getElementById(which + "Details"   + id).style.display	== "none")
	{
		if (className.indexOf("_open") == -1)
			document.getElementById(which + "NadlanRow" + id).className += "_open";
		document.getElementById(which + "Details"   + id).style.display	= "";
	}
	else
	{
		if (className.indexOf("_open") != -1)
			document.getElementById(which + "NadlanRow" + id).className	= className.substr(0,className.length-5);
		document.getElementById(which + "Details"   + id).style.display	= "none";
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* openNadlanRow																					*/
/* ------------------------------------------------------------------------------------------------ */
function openNadlanRow (which, id)
{
	document.getElementById(which + "Details"   + id).style.display	= "";

	className = document.getElementById(which + "NadlanRow" + id).className;

	if (className.indexOf("_open") == -1)
		document.getElementById(which + "NadlanRow" + id).className += "_open";
}

/* ------------------------------------------------------------------------------------------------ */
/* closeNadlanRow																					*/
/* ------------------------------------------------------------------------------------------------ */
function closeNadlanRow (which, id)
{
	document.getElementById(which + "Details"   + id).style.display	= "none";

	var className = document.getElementById(which + "NadlanRow" + id).className;

	document.getElementById(which + "NadlanRow" + id).className		= className.substr(0,className.length-5);
}

/* ------------------------------------------------------------------------------------------------ */
/* markAll																							*/
/* ------------------------------------------------------------------------------------------------ */
function markAll (which)
{
	oTbl	= document.getElementById (which + "NadlanTable").getElementsByTagName("tbody")[0];

	for (i=1; i<oTbl.rows.length-1; i++)
	{
		oTbl.rows[i].cells[0].childNodes[0].checked = true;
		i = i+2;
	}

	document.getElementById(which + "_markAll").style.display   = "none";
	document.getElementById(which + "_unmarkAll").style.display = "";
}

/* ------------------------------------------------------------------------------------------------ */
/* markAll																							*/
/* ------------------------------------------------------------------------------------------------ */
function unmarkAll (which)
{
	oTbl	= document.getElementById (which + "NadlanTable").getElementsByTagName("tbody")[0];

	for (i=1; i<oTbl.rows.length-1; i++)
	{
		oTbl.rows[i].cells[0].childNodes[0].checked = false;
		i = i+2;
	}

	document.getElementById(which + "_markAll").style.display   = "";
	document.getElementById(which + "_unmarkAll").style.display = "none";
}

/* ------------------------------------------------------------------------------------------------ */
/* printSelected																					*/
/* ------------------------------------------------------------------------------------------------ */
function printSelected (which)
{
	// find selected
	itemIds = "";

	oTbl	= document.getElementById (which + "NadlanTable").getElementsByTagName("tbody")[0];

	for (i=1; i<oTbl.rows.length-1; i++)
	{
		if (oTbl.rows[i].cells[0].childNodes[0].checked)
		{
			if (itemIds != "") itemIds += ",";

			itemIds += oTbl.rows[i].id.substr(9+which.length,oTbl.rows[i].id.length);;
		}
		i = i+2;
	}

	if (itemIds == "")
	{
		alert ("יש לבחור לפחות מודעה אחת להדפסה");
	}
	else
	{
		window.open ("index2.php?id=13&itemIds=" + itemIds);
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* printThisItem																					*/
/* ------------------------------------------------------------------------------------------------ */
function printThisItem (itemId)
{
	window.open ("index2.php?id=13&itemIds=" + itemId);
}

/* ------------------------------------------------------------------------------------------------ */
/* openCloseBar																						*/
/* ------------------------------------------------------------------------------------------------ */
function openCloseBar (which)
{
	oTopBar = document.getElementById("topBar");

	// find curr open
	currOpen = "";
	if (document.getElementById("addNadlan").style.display == "")
	{
		currOpen = "add";
	}

	if (document.getElementById("searchNadlan").style.display == "")
	{
		currOpen = "search";
	}

	if (document.getElementById("agentNadlan").style.display == "")
	{
		currOpen = "agent";
	}

	if (which != currOpen)
	{
		if (currOpen == "add")
			document.getElementById("addNadlan").style.display		= "none";

		if (currOpen == "search")
			document.getElementById("searchNadlan").style.display	= "none";

		if (currOpen == "agent")
			document.getElementById("agentNadlan").style.display	= "none";

		currOpen = which;
	}

	if (which == "add")
	{
		if (document.getElementById("addNadlan").style.display == "")
		{
			document.getElementById("addNadlan").style.display		= "none";
			if (oTopBar.className.indexOf("_open") != -1)
				oTopBar.className = oTopBar.className.substr(0,oTopBar.className.length-5);
		}
		else
		{
			document.getElementById("addNadlan").style.display		= "";
			if (oTopBar.className.indexOf("_open") == -1)
				oTopBar.className += "_open";
		}
	}

	if (which == "search")
	{
		if (document.getElementById("searchNadlan").style.display == "")
		{
			document.getElementById("searchNadlan").style.display	= "none";
			if (oTopBar.className.indexOf("_open") != -1)
				oTopBar.className = oTopBar.className.substr(0,oTopBar.className.length-5);
		}
		else
		{
			document.getElementById("searchNadlan").style.display	= "";

			if (oTopBar.className.indexOf("_open") == -1)
				oTopBar.className += "_open";
		}
	}

	if (which == "handle")
	{
		try
		{
			if (document.getElementById("handleNadlanIn") == undefined)
				document.getElementById("handleNadlan").style.display	= "";		// login
			else
				document.getElementById("myNadlan").style.display		= "";		// my nadlan items
		}
		catch (e) {}
	}
	else
	{
		try
		{
			if (document.getElementById("handleNadlanIn") == undefined)
				document.getElementById("handleNadlan").style.display	= "none";	// login
			else
				document.getElementById("myNadlan").style.display		= "none";	// my nadlan items
		}
		catch (e) {}
	}

	if (which == "agent")
	{
		if (document.getElementById("agentNadlan").style.display == "")
		{
			document.getElementById("agentNadlan").style.display	= "none";
			if (oTopBar.className.indexOf("_open") != -1)
				oTopBar.className = oTopBar.className.substr(0,oTopBar.className.length-5);
		}
		else
		{
			document.getElementById("agentNadlan").style.display	= "";

			if (oTopBar.className.indexOf("_open") == -1)
				oTopBar.className += "_open";
		}
	}

	if (which != "handle" || document.getElementById("handleNadlanIn") == undefined)
	{
//		document.getElementById("topBar").className				= "topBar_open";
		document.getElementById("nadlan").style.display			= "";
	}
	else
		document.getElementById("nadlan").style.display			= "none";
}

/* ------------------------------------------------------------------------------------------------ */
/* closeBar																							*/
/* ------------------------------------------------------------------------------------------------ */
function closeBar (which)
{
	document.getElementById(which + "Nadlan").style.display		= "none";

	var topBarClass = document.getElementById("topBar").className;

	document.getElementById("topBar").className	= topBarClass.substr(0,topBarClass.length-5);
}

/* ------------------------------------------------------------------------------------------------ */
/* promoteNadlan																					*/
/* ------------------------------------------------------------------------------------------------ */
function promoteNadlan (itemId)
{
	xml = "<data>" +
				"<command>private.promoteNadlan</command>"			   	+
				"<itemId>"		        + itemId					  	+ "</itemId>" 				+
		  "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "promoteNadlan_response");
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* promoteAll																						*/
/* ------------------------------------------------------------------------------------------------ */
function promoteAll (memberId)
{
	xml = "<data>" +
				"<command>private.promoteAll</command>"			   	+
				"<memberId>"		        + memberId				+ "</memberId>" 				+
		  "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "promoteNadlan_response");
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* promoteNadlan_response																			*/
/* ------------------------------------------------------------------------------------------------ */
function promoteNadlan_response ()
{
	location.reload ();
}

/* ------------------------------------------------------------------------------------------------ */
/* deleteNadlan																						*/
/* ------------------------------------------------------------------------------------------------ */
function deleteNadlan (itemId)
{
	var oForm = document.getElementById("deleteForm" + itemId);

	var deleteReason  = "";

	if (oForm.deleteReason1.checked)
		deleteReason = oForm.deleteReason1.value;
	else if (oForm.deleteReason2.checked)
		deleteReason = oForm.deleteReason2.value;

	if (deleteReason == "")
	{
		alert ("נא לבחור את אחת הסיבות");;
		return false;
	}
	xml = "<data>" +
				"<command>private.deleteNadlan</command>"			   	+
				"<itemId>"		        + itemId					  	+ "</itemId>" 				+
				"<deleteReason>"	    + deleteReason				  	+ "</deleteReason>" 		+
				"<price>"        		+ oForm.price.value  			+ "</price>" 				+
				"<currency>"			+ oForm.currency.value 			+ "</currency>" 			+
				"<saleByBroker>"		+ oForm.saleByBroker.value 		+ "</saleByBroker>" 		+
		  "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "deleteNadlan_response");
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* deleteNadlan_response																			*/
/* ------------------------------------------------------------------------------------------------ */
function deleteNadlan_response ()
{
	location.href = "index2.php?id=15";
}

/* ------------------------------------------------------------------------------------------------ */
/* openNadlanDelete																					*/
/* ------------------------------------------------------------------------------------------------ */
function openNadlanDelete (itemId)
{
	if (document.getElementById("deleteNadlan" + itemId).style.display == "")
		document.getElementById("deleteNadlan" + itemId).style.display = "none";
	else
		document.getElementById("deleteNadlan" + itemId).style.display = "";
}

/* ------------------------------------------------------------------------------------------------ */
/* changeNadlanType																					*/
/* ------------------------------------------------------------------------------------------------ */
function changeNadlanType ()
{
	oForm = document.getElementById("nadlanEditForm");

	if (document.getElementById("nadlanTypeOut").value == 4 || document.getElementById("nadlanTypeOut").value == 5)
	{
		document.getElementById("rentPeriodText").style.display		= "";
		oForm.rentPeriod.style.display								= "";
	}
	else
	{
		document.getElementById("rentPeriodText").style.display		= "none";
		oForm.rentPeriod.style.display								= "none";
	}

	if (document.getElementById("nadlanTypeOut").value == 2)
	{
		document.getElementById("evictionTitle").innerHTML = "אכלוס";
	}
	else
	{
		document.getElementById("evictionTitle").innerHTML = "תאריך פינוי";
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* changeImmediate																					*/
/* ------------------------------------------------------------------------------------------------ */
function changeImmediate (formName)
{
	oForm = document.getElementById(formName);

	if (oForm.immediateEviction.checked)
	{
		var theDate = new Date();
		var year 	= theDate.getFullYear();
		var month 	= theDate.getMonth() +1;
		var day 	= theDate.getDate();

		year  = (year+"").substr(2,2);
		month = ("" + month).length == 1 ? "0" + month : month;
		day   = ("" + day  ).length == 1 ? "0" + day   : day;

		if (formName == "nadlanEditForm")
			oForm.dateField2.value = day + "." + month + "." + year;
		else
			oForm.dateField1.value = day + "." + month + "." + year;
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* resetSearchForm																					*/
/* ------------------------------------------------------------------------------------------------ */
function resetSearchForm ()
{
	oForm = document.getElementById("nadlanSearchForm");

	oForm.nadlanType.value			= "sale";
	oForm.fromPrice.value			= "";
	oForm.currency.value			= "USD";
	oForm.toPrice.value				= "";
	oForm.inf_dateField1.value		= "";
	oForm.dateField1.value			= "";
	oForm.immediateEviction.checked	= false;
	oForm.rentPeriod.value			= "";
	oForm.plottage.value			= "";
	oForm.balconyPlottage.value		= "";
	oForm.gardenPlottage.value		= "";
	oForm.numRooms.value			= "";
	oForm.elevator.checked			= false;
	oForm.parking.checked			= false;
	oForm.airConditioning.checked	= false;
	oForm.parentsBedroom.checked	= false;
	oForm.store.checked				= false;
	oForm.freeText.value			= "";

	resetMultiSelection (oForm.itemType);
	resetMultiSelection (oForm.cityId);
	resetMultiSelection (oForm.neighborhood);
	resetMultiSelection (oForm.numRooms);
}

/* ------------------------------------------------------------------------------------------------ */
/* resetBrokerConstractorForm																		*/
/* ------------------------------------------------------------------------------------------------ */
function resetBrokerConstractorForm (which)
{
	if (which == "broker")
		document.getElementById(which + "_nadlanType").value = "sale";

	resetMultiSelection (document.getElementById(which + "_itemType"));
	resetMultiSelection (document.getElementById(which + "_cityId"));
	resetMultiSelection (document.getElementById(which + "_neighborhood"));
	resetMultiSelection (document.getElementById(which + "_numRooms"));
}

/* ------------------------------------------------------------------------------------------------ */
/* resetMultiSelection																				*/
/* ------------------------------------------------------------------------------------------------ */
function resetMultiSelection (field)
{
	for (var i=0; i<field.options.length; i++)
	{
		field.options[i].selected = false;
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* validateNadlanSearchForm																			*/
/* ------------------------------------------------------------------------------------------------ */
function validateNadlanSearchForm ()
{
	var foundError = false;

	oForm = document.getElementById("nadlanSearchForm");

	// from price
	var charpos = oForm.fromPrice.value.search("[^0-9]"); 
	if (oForm.fromPrice.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("fromPriceError").innerHTML = "יש להזין מחיר בספרות בלבד";
	}
	else
	{
		document.getElementById("fromPriceError").innerHTML = "";
	}

	// to price
	var charpos = oForm.toPrice.value.search("[^0-9]"); 
	if (oForm.toPrice.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("toPriceError").innerHTML = "יש להזין מחיר בספרות בלבד";
	}
	else
	{
		document.getElementById("toPriceError").innerHTML = "";
	}
	
	// eviction date
	dateError = isDate(oForm.dateField1.value);
	if (oForm.dateField1.value != "" && dateError != "")
	{
		foundError = true;
		document.getElementById("evictionDateError").innerHTML = dateError;
	}
	else
	{
		document.getElementById("evictionDateError").innerHTML = "";
	}

	// plottage
	var charpos = oForm.plottage.value.search("[^0-9]"); 
	if (oForm.plottage.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("plottageError").innerHTML = "יש להזין שטח בספרות בלבד";
	}
	else
	{
		document.getElementById("plottageError").innerHTML = "";
	}
	
	// balconyPlottage
	var charpos = oForm.balconyPlottage.value.search("[^0-9]"); 
	if (oForm.balconyPlottage.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("balconyPlottageError").innerHTML = "יש להזין שטח בספרות בלבד";
	}
	else
	{
		document.getElementById("balconyPlottageError").innerHTML = "";
	}
	
	// gardenPlottage
	var charpos = oForm.gardenPlottage.value.search("[^0-9]"); 
	if (oForm.gardenPlottage.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("gardenPlottageError").innerHTML = "יש להזין שטח בספרות בלבד";
	}
	else
	{
		document.getElementById("gardenPlottageError").innerHTML = "";
	}
	
	oForm.evictionDate.value = document.getElementById("dateField1").value;

	var neighborhoodField = document.getElementById("nadlanSearchForm_neighborhood");

	var neighborhoods = "";
	for (var i=0; i < neighborhoodField.options.length; i++)
	{
		if (neighborhoodField.options[i].selected)
			neighborhoods += " " + neighborhoodField.options[i].value;
	}
	oForm.neighborhood.value = neighborhoods;

	return (!foundError);
}

/* ------------------------------------------------------------------------------------------------ */
/* validateBrokerConstructorSearchForm																*/
/* ------------------------------------------------------------------------------------------------ */
function validateBrokerConstructorSearchForm (type)
{
	var foundError = false;

	var neighborhoodField = document.getElementById(type + "SearchForm_neighborhood");

	var neighborhoods = "";
	for (var i=0; i < neighborhoodField.options.length; i++)
	{
		if (neighborhoodField.options[i].selected)
			neighborhoods += " " + neighborhoodField.options[i].value;
	}

	document.getElementById(type + "_neighborhood").value = neighborhoods;

	return (!foundError);
}


/* ------------------------------------------------------------------------------------------------ */
/* validateNadlanAddForm																			*/
/* ------------------------------------------------------------------------------------------------ */
function validateNadlanAddForm ()
{
	if (multiUploadCountPics != 0)
	{
		alert ("יש להמתין לסיום טעינת קבצי התמונות");
		return false;
	}

	var errorMsg = validateNadlanDetails("add");

	if (errorMsg == "")
	{
		oForm = document.getElementById("nadlanEditForm");
		
			// not private
		if (oForm.nadlanType.value != 1 && oForm.nadlanType.value != 4 && !validCode)
		{
			alert ("קוד הלקוח אינו חוקי - לפרסום נכסים אנא פנה אלינו באמצעות דף \"צור קשר\" באתר. תודה!");
			return false;
		}
		checkMember ();
	}
	else
	{
//		alert ("אנא מלא את הפרטים המסומנים באדום על מנת שנוכל לפרסם את מודעתך באתר. תודה!");
		alert ("על מנת שנוכל לפרסם את מודעתך באתר " + errorMsg + ". תודה!");
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* validateNadlanUpdateForm																			*/
/* ------------------------------------------------------------------------------------------------ */
function validateNadlanUpdateForm ()
{
	if (multiUploadCountPics != 0)
	{
		alert ("יש להמתין לסיום טעינת קבצי התמונות");
		return false;
	}

	var errorMsg = validateNadlanDetails("update");

	if (errorMsg == "")
	{
		setFilesNames ();

		document.getElementById("nadlanEditForm").submit ();

		return true;
	}
	else
	{
//		alert ("אנא מלא את הפרטים המסומנים באדום על מנת שנוכל לפרסם את מודעתך באתר. תודה!");
		alert ("על מנת שנוכל לפרסם את מודעתך באתר " + errorMsg + ". תודה!");
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* validateNadlanDetails																			*/
/* ------------------------------------------------------------------------------------------------ */
function validateNadlanDetails (editType)
{
	oForm = document.getElementById("nadlanEditForm");
	
	oForm.evictionDate.value 	= document.getElementById("dateField2").value;
	oForm.nadlanType.value 		= document.getElementById("nadlanTypeOut").value;
	oForm.balconyPlottage.value = document.getElementById("balconyPlottageOut").value;

	var foundError  = false;
	var errorMsgs   = new Array();
	var errorSelect = new Array();

	// nadlanType
	if (oForm.nadlanType.value == "")
	{
		foundError = true;
		document.getElementById("nadlanTypeError").innerHTML = "יש לבחור סוג עסקה";
		errorSelect.push ("סוג עסקה");
	}
	else
	{
		document.getElementById("nadlanTypeError").innerHTML = "";
	}

	// itemType
	if (oForm.itemType.value == "")
	{
		foundError = true;
		document.getElementById("itemTypeError").innerHTML = "יש לבחור סוג נכס";
		errorSelect.push ("סוג נכס");
	}
	else
	{
		document.getElementById("itemTypeError").innerHTML = "";
	}

	// cityId
	if (oForm.cityId.value == "")
	{
		foundError = true;
		document.getElementById("cityIdError").innerHTML = "יש לבחור ישוב";
		errorSelect.push ("ישוב");
	}
	else
	{
		document.getElementById("cityIdError").innerHTML = "";
	}

	// neighborhood
	if (document.getElementById("nadlanEditForm_neighborhood").value == "")
	{
		foundError = true;
		document.getElementById("neighborhoodError").innerHTML = "יש לבחור שכונה";
		errorSelect.push ("שכונה");
	}
	else
	{
		document.getElementById("neighborhoodError").innerHTML = "";
		oForm.neighborhood.value = document.getElementById("nadlanEditForm_neighborhood").value;
	}

	// streetNo
/*	var charpos = oForm.streetNo.value.search("[^0-9]"); 
	if (oForm.streetNo.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("streetNoError").innerHTML = "יש להזין ספרות בלבד";
	}
	else
	{
		if (oForm.streetNo.value.length > 0 && oForm.streetNo.value > 300)
		{
			document.getElementById("streetNoError").innerHTML = "יש להזין מספר בין 0 ל-300";
		}
		else
		{
			document.getElementById("streetNoError").innerHTML = "";
		}
	}
*/
	// numRooms
	if (oForm.numRooms.value == "")
	{
		foundError = true;
		document.getElementById("numRoomsError").innerHTML = "יש לבחור מס' חדרים";
		errorSelect.push ("מס' חדרים");
	}
	else
	{
		document.getElementById("numRoomsError").innerHTML = "";
	}

	// eviction date
	dateError = isDate(oForm.dateField2.value);
	if (oForm.dateField2.value != "" && dateError != "")
	{
		foundError = true;
		document.getElementById("evictionDateError2").innerHTML = dateError;
		errorMsgs.push ("תאריך פינוי בפורמט יום.חודש.שנה");
	}
	else
	{
		document.getElementById("evictionDateError2").innerHTML = "";
	}


	// plottage
	var charpos = oForm.plottage.value.search("[^0-9]"); 
	if (oForm.plottage.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("plottageError2").innerHTML = "יש להזין שטח בספרות בלבד";
		errorMsgs.push (document.getElementById("plottageError2").innerHTML);
	}
	else
	{
		if (oForm.plottage.value.length > 0 && oForm.plottage.value > 1000)
		{
			foundError = true;
			document.getElementById("plottageError2").innerHTML = "יש להזין מספר בין 0 ל-1000";
			errorMsgs.push (document.getElementById("plottageError2").innerHTML);
		}
		else
		{
			document.getElementById("plottageError2").innerHTML = "";
		}
	}
	
	// floors
	if (oForm.numFloors.value != "" && oForm.numFloors.value < oForm.floorNo.value)
	{
		foundError = true;
		document.getElementById("floorError").innerHTML = "מס' הקומות קטן ממספר הקומה";
		errorMsgs.push ("יש להזין מס' קומות קטן ממספר הקומה");
	}
	else
	{
		document.getElementById("floorError").innerHTML = "";
	}

	// price
	if (oForm.price.value == "")
	{
		foundError = true;
		document.getElementById("priceError").innerHTML = "יש להזין מחיר";
		errorMsgs.push (document.getElementById("priceError").innerHTML);
	}
	else
	{
		var charpos = oForm.price.value.search("[^0-9,]"); 
		if (oForm.price.value.length > 0 && charpos >= 0)
		{
			foundError = true;
			document.getElementById("priceError").innerHTML = "יש להזין מחיר חוקי";
			errorMsgs.push (document.getElementById("priceError").innerHTML);
		}
		else
		{
			var priceSplit = oForm.price.value.split(",");
			if (priceSplit.length > 1)
			{
				for (var i=1; i<priceSplit.length; i++)
				{
					if (priceSplit[i].length != 3)
					{
						foundError = true;
						document.getElementById("priceError").innerHTML = "יש להזין מחיר חוקי";
						errorMsgs.push (document.getElementById("priceError").innerHTML);
						break;
					}
					else
					{
						document.getElementById("priceError").innerHTML = "";
					}
				}
			}
			else
			{
				document.getElementById("priceError").innerHTML = "";
			}

		}
	}

	// balconyPlottage
   	var charpos = oForm.balconyPlottage.value.search("[^0-9]"); 
	if (oForm.balconyPlottage.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("balconyPlottageError2").innerHTML = "יש להזין שטח בספרות בלבד";
		errorMsgs.push (document.getElementById("balconyPlottageError2").innerHTML);
	}
	else
	{
		if (oForm.balconyPlottage.value.length > 0 && oForm.balconyPlottage.value > 400)
		{
			foundError = true;
			document.getElementById("balconyPlottageError2").innerHTML = "יש להזין שטח בין 0 ל-400";
			errorMsgs.push (document.getElementById("balconyPlottageError2").innerHTML);
		}
		else
		{
			document.getElementById("balconyPlottageError2").innerHTML = "";
		}
	}
	
	// gardenPlottage
	var charpos = oForm.gardenPlottage.value.search("[^0-9]"); 
	if (oForm.gardenPlottage.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("gardenPlottageError2").innerHTML = "יש להזין שטח בספרות בלבד";
		errorMsgs.push (document.getElementById("gardenPlottageError2").innerHTML);
	}
	else
	{
		if (oForm.gardenPlottage.value.length > 0 && oForm.gardenPlottage.value > 1000)
		{
			foundError = true;
			document.getElementById("gardenPlottageError2").innerHTML = "יש להזין שטח בין 0 ל-1000";
			errorMsgs.push (document.getElementById("gardenPlottageError2").innerHTML);
		}
		else
		{
			document.getElementById("gardenPlottageError2").innerHTML = "";
		}
	}
	
	// contactName
	if (oForm.contactName.value == "")
	{
		foundError = true;
		document.getElementById("contactNameError").innerHTML = "יש להזין שם איש קשר";
		errorMsgs.push (document.getElementById("contactNameError").innerHTML);
	}
	else
	{
		document.getElementById("contactNameError").innerHTML = "";
	}

	// contact phone 1
	if (oForm.contactPhonePre1.value == "1700" || oForm.contactPhonePre1.value == "1800")
	{
		regexp  = new RegExp("^[1-9][0-9]{5}$");
	}
	else if (oForm.contactPhonePre1.value == "*")
	{
		regexp  = new RegExp("^[1-9][0-9]{2,3}$");
	}
	else
	{
		regexp  = new RegExp("^[1-9][0-9]{6}$");
	}

	if (oForm.contactPhoneNo1.value == "")
	{
		foundError = true;
		document.getElementById("contactPhoneNo1Error").innerHTML = "יש להזין טלפון";
		errorMsgs.push (document.getElementById("contactPhoneNo1Error").innerHTML);
	}
	else
	{
		if (!regexp.test(oForm.contactPhoneNo1.value))
		{
			foundError = true;
			document.getElementById("contactPhoneNo1Error").innerHTML = "מספר טלפון לא חוקי";
			errorMsgs.push ("יש להזין מספר טלפון חוקי");
		}
		else
		{
			if (oForm.contactPhonePre1.value == "")
			{
				foundError = true;
				document.getElementById("contactPhoneNo1Error").innerHTML = "יש לבחור קידומת";
				errorSelect.push ("קידומת למספר הטלפון");
			}
			else
			{
				document.getElementById("contactPhoneNo1Error").innerHTML = "";
			}
		}
	}

	// contact phone 2	
	if (oForm.contactPhonePre2.value == "1700" || oForm.contactPhonePre2.value == "1800")
	{
		regexp  = new RegExp("^[1-9][0-9]{5}$");
	}
	else if (oForm.contactPhonePre2.value == "*")
	{
		regexp  = new RegExp("^[1-9][0-9]{2,3}$");
	}
	else
	{
		regexp  = new RegExp("^[1-9][0-9]{6}$");
	}
		
	if (oForm.contactPhoneNo2.value != "" && !regexp.test(oForm.contactPhoneNo2.value))
	{
		foundError = true;
		document.getElementById("contactPhoneNo2Error").innerHTML = "מספר טלפון לא חוקי";
		errorMsgs.push ("יש להזין מספר טלפון חוקי");
	}
	else
	{
		if (oForm.contactPhoneNo2.value != "" && oForm.contactPhonePre2.value == "")
		{
			foundError = true;
			document.getElementById("contactPhoneNo2Error").innerHTML = "יש לבחור קידומת";
			errorSelect.push ("קידומת למספר הטלפון הנוסף");
		}
		else
		{
			document.getElementById("contactPhoneNo2Error").innerHTML = "";
		}
	}
	
	if (editType == "add")	
	{
		// contactEmail
		if (oForm.contactEmail.value == "")
		{
			foundError = true;
			document.getElementById("contactEmailError").innerHTML = "יש להזין דוא\"ל";
			errorMsgs.push (document.getElementById("contactEmailError").innerHTML);
		}
		else
		{
			if (!validateEmailv2(oForm.contactEmail.value))
			{
				foundError = true;
				document.getElementById("contactEmailError").innerHTML = "יש להזין דוא\"ל חוקי";
				errorMsgs.push (document.getElementById("contactEmailError").innerHTML);
			}
			else
			{
				document.getElementById("contactEmailError").innerHTML = "";
			}
		}	

		// contactPassword
		if (oForm.contactPassword.value == "")
		{
			foundError = true;
			document.getElementById("contactPasswordError").innerHTML = "יש להזין סיסמא";
			errorMsgs.push (document.getElementById("contactPasswordError").innerHTML);
		}	
		else
		{
			if (oForm.contactPassword.value.length < 6 || oForm.contactPassword.value.indexOf(" ") != -1)
			{
				foundError = true;
				document.getElementById("contactPasswordError").innerHTML = "סיסמא בת 6 תווים ללא רווחים";
				errorMsgs.push ("יש להזין סיסמא בת 6 תווים ללא רווחים");
			}
			else
			{
				document.getElementById("contactPasswordError").innerHTML = "";
			}
		}	

		if (!oForm.terms.checked)
		{
			foundError = true;
			document.getElementById("termsError").innerHTML = "חובה לציין הסכמה לתנאי השימוש";
			errorMsgs.push (document.getElementById("termsError").innerHTML);
		}
		else
		{
			document.getElementById("termsError").innerHTML = "";
		}
	}

	if (oForm.contactPhoneNo1.value != "")
		oForm.contactPhone1.value = oForm.contactPhonePre1.value + "-" + oForm.contactPhoneNo1.value;

	if (oForm.contactPhoneNo2.value != "")
		oForm.contactPhone2.value = oForm.contactPhonePre2.value + "-" + oForm.contactPhoneNo2.value;

	if (!foundError)
	{
		// remove , from price field
		oForm.price.value = oForm.price.value.replace(/,/g, "");
		return "";
	}
	else
	{
		var errorMsg = "";
		if (errorSelect.length != 0)
		{
			lastError = errorSelect.pop ();

			errorMsg = "יש לבחור ";
			if (errorSelect.length == 0)
				errorMsg += lastError;
			else
				errorMsg += errorSelect.join(", ") + " ו" + lastError; 

			if (errorMsgs.length == 1)
				errorMsg += " ו";
			else if (errorMsgs.length > 1)
				errorMsg += ", ";
		}
		if (errorMsgs.length == 1)
			errorMsg += errorMsgs.pop ();
		else if (errorMsgs.length > 1)
		{
			lastError = errorMsgs.pop ();
			errorMsg += errorMsgs.join(", ") + " ו" + lastError;
		}

		return errorMsg;
	}
}

var xmlRequest = new xmlObj(false);
/* ------------------------------------------------------------------------------------------------ */
/* checkMember																						*/
/* ------------------------------------------------------------------------------------------------ */
function checkMember (formName)
{
	if (formName == undefined) 
	{
		formName = "nadlanEditForm";
		oForm = document.getElementById(formName);

		theEmail = oForm.contactEmail.value;
		thePass	 = oForm.contactPassword.value;
	}
	else
	{
		oForm = document.getElementById(formName);

		theEmail = oForm.agentEmail.value;
		thePass	 = oForm.agentPassword.value;
	}


	xml = "<data>" +
				"<command>private.checkMember</command>"   	+
				"<contactEmail>"        + theEmail  		+ "</contactEmail>" 		+
				"<contactPassword>"		+ thePass 			+ "</contactPassword>" 		+
		  "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, formName + "_checkMember_response");
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* nadlanEditForm_checkMember_response																*/
/* ------------------------------------------------------------------------------------------------ */
function nadlanEditForm_checkMember_response ()
{
	xmlRequest.init(commonDecode(asyncHttpObj.responseText));
						
	try
	{
		success = xmlRequest.getValue("success");
	}
	catch (e)
	{
		alert ("AJAX Error");
		return false;
	}
	
	if (success == "0")
	{
		verification_check ("nadlanEditForm", "HEB");
		return false;
	}
	else if (success == "1")
	{
		alert ("סיסמת זיהוי שגויה עבור דוא\"ל זה");
		document.getElementById("contactPasswordError").innerHTML = "יש להזין סיסמא שוב";
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* nadlanEditFormSubmit																				*/
/* ------------------------------------------------------------------------------------------------ */
function nadlanEditFormSubmit ()
{
	setFilesNames ();

	// disable button
	document.getElementById("addBtn").style.display 	= "none";
	document.getElementById("disableBtn").style.display = "";
	document.getElementById("nadlanEditForm").submit ();
}

/* ------------------------------------------------------------------------------------------------ */
/* getDetailsByCode																					*/
/* ------------------------------------------------------------------------------------------------ */
function getDetailsByCode ()
{
	oForm = document.getElementById("nadlanEditForm");

	if (oForm.code.value == "")
			return;

	xml = "<data>" +
				"<command>private.getDetailsByCode</command>"			   	+
				"<code>"        + oForm.code.value  	+ "</code>" 		+
		  "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "getDetailsByCode_response");
	return false;
}

var validCode = false;

/* ------------------------------------------------------------------------------------------------ */
/* getDetailsByCode_response																		*/
/* ------------------------------------------------------------------------------------------------ */
function getDetailsByCode_response ()
{
	xmlRequest.init(commonDecode(asyncHttpObj.responseText));
						
	try
	{
		success = xmlRequest.getValue("success");
	}
	catch (e)
	{
		alert ("AJAX Error");
		return false;
	}

	if (success == "1")
	{
		document.getElementById("contactName").value 		= xmlRequest.getValue("contactName");
		document.getElementById("contactPhoneNo1").value 	= xmlRequest.getValue("contactPhoneNo1");
		document.getElementById("contactPhonePre1").value 	= xmlRequest.getValue("contactPhonePre1");
		document.getElementById("contactPhoneNo2").value 	= xmlRequest.getValue("contactPhoneNo2");
		document.getElementById("contactPhonePre2").value 	= xmlRequest.getValue("contactPhonePre2");
		document.getElementById("contactEmail").value 		= xmlRequest.getValue("email");
		validCode = true;
	}
	else if (success == "0")
	{
		validCode = false;
		alert ("הקוד לא נמצא");
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* setFilesNames																					*/
/* ------------------------------------------------------------------------------------------------ */
function setFilesNames ()
{
	oForm = document.getElementById("nadlanEditForm");

	filesNames = "";

	oTbl = document.getElementById("picsTbl").getElementsByTagName("tbody")[0];

	numPics = oTbl.rows.length;

	for (r=1; r<numPics; r++)
	{
		row = oTbl.rows[r];

		picName   = row.cells[1].childNodes[1].id;	// innerText;

		if (filesNames != "") filesNames += " ";

		filesNames += picName.replace(/\s/g, "_");
	}

	oForm.filesNames.value = filesNames;

}

/* ------------------------------------------------------------------------------------------------ */
/* validateLoginForm																				*/
/* ------------------------------------------------------------------------------------------------ */
function validateLoginForm (forSendPassword)
{
	var loginForm = document.getElementById("loginForm");

	var formValidator = new Validator("loginForm");
	formValidator.clearAllValidations ();

	formValidator.addValidation("email",	"required",	"יש להזין דוא\"ל");
	formValidator.addValidation("email",	"email",	"יש להזין דוא\"ל חוקי");

	if (!forSendPassword)
	{
		formValidator.addValidation("password",	"required",	"יש להזין סיסמא");
	}

	if (formValidator.validate ())
	{
		if (forSendPassword)
		{
			var passForm = document.getElementById("passForm");

			passForm.username.value = loginForm.email.value;

			passForm.submit ();
			
		}

		loginForm.username.value = loginForm.email.value;

		return true;
	}
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* sendPasswordFromAddNadlan																		*/
/* ------------------------------------------------------------------------------------------------ */
function sendPasswordFromAddNadlan ()
{
	var oForm = document.getElementById("nadlanEditForm");

	var formValidator = new Validator("nadlanEditForm");
	formValidator.clearAllValidations ();

	formValidator.addValidation("contactEmail",	"required",	"יש להזין דוא\"ל");
	formValidator.addValidation("contactEmail",	"email",	"יש להזין דוא\"ל חוקי");

	if (formValidator.validate ())
	{
		var passForm = document.getElementById("passForm");

		passForm.username.value = oForm.contactEmail.value;

		passForm.submit ();
			
	}
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* switchOpenStatus																					*/
/* ------------------------------------------------------------------------------------------------ */
function switchOpenStatus (divName)
{
	var oDiv = document.getElementById(divName);

	if (oDiv.style.display == "")
		oDiv.style.display = "none";
	else
		oDiv.style.display= "";
}

/* ------------------------------------------------------------------------------------------------ */
/* loadNeighborhoods																				*/
/* ------------------------------------------------------------------------------------------------ */
function loadNeighborhoods (formName)
{
	var theForm		= document.getElementById(formName);
	
	if (formName.indexOf ("broker") != -1)
		var cityField = document.getElementById("broker_cityId");
	else if (formName.indexOf("constractor") != -1)
		var cityField = document.getElementById("constractor_cityId");
	else
		var cityField = theForm.cityId;

	var cities 		= "";

	for (var i=0; i < cityField.options.length; i++)
	{
		if (cityField.options[i].selected)
			cities += " " + cityField.options[i].value;
	}
	
	if (cities == "") 
	{
		setNeighborhoodOptions (formName, "");
		return;
	}

	xml = "<data>" +
				"<command>private.getNeighborhoodOptions</command>"	   	+
				"<cities>"				+ cities						+ "</cities>"				+
				"<formName>"			+ formName						+ "</formName>"				+
		  "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "loadNeighborhoods_response");
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* loadNeighborhoods_response																		*/
/* ------------------------------------------------------------------------------------------------ */
function loadNeighborhoods_response ()
{
	xmlRequest.init(commonDecode(asyncHttpObj.responseText));

	try
	{
		var options 	= xmlRequest.getValue("options");
		var formName	= xmlRequest.getValue("formName");
	}
	catch (e)
	{
		alert ("AJAX Error");
		return false;
	}

 	setNeighborhoodOptions (formName, options);
}

function setNeighborhoodOptions (formName, options)
{
	if (formName == "nadlanEditForm")
		document.getElementById(formName + "_neighborhoods").innerHTML = "<select id='nadlanEditForm_neighborhood' " + 
																		 "		  name='nadlanEditForm_neighborhood' tabIndex='4'>" +
			   																options +
																	     "</select>";	
	else
		document.getElementById(formName + "_neighborhoods").innerHTML = "<select id='" + formName + "_neighborhood' " + 
																		 "		  name='" + formName + "_neighborhood' " + 
																		 "       multiple style='height:60px'>" + 
			   																options +
																		 "</select>";

}
	
var emailForm = new floatWindow();;

/* ------------------------------------------------------------------------------------------------ */
/* nadlan_openEmailForm																				*/
/* ------------------------------------------------------------------------------------------------ */
function nadlan_openEmailForm (bcId, itemId, parentName, x, y, type)
{
	var title = "לקבלת פרטים נוספים מ";

	if (type == "broker")
		title += "משרד התיווך";
	else
		title += "משרד המכירות";
		
	var html = "<div id='sendEmailTop'>" + 
					"<div id='sendEmailTop_in'>" + title + "</div>" +
			   "</div>" + 
			   "<div id='sendEmailBg'>" + 
			   	"<div id='sendEmailBg_in'>" + 
				   	"<form id='sendEmailForm' name='sendEmailForm' method='post' onsubmit='return nadlan_validateEmailForm()'>" + 
					"<input type='hidden' id='bcId'   name='bcId'   value='" + bcId   + "' />" +
					"<input type='hidden' id='itemId' name='itemId' value='" + itemId + "' />" +
					"<input type='hidden' id='title'  name='title'  value='" + title + "' />" +
					"<table cellspacing='2' cellpadding='2' border='0'>" + 
					"<tr>" +
						"<td class='mandatory'>*</td>" +
						"<td class='formFieldText' style='text-align:right'>שם</td>" +
						"<td class='formField'><input type='text' id='myName' name='myName' maxLength='30' style='width:150px' /></td>" +
					"</tr>" +
					"<tr>" +
						"<td class='mandatory'>*</td>" +
						"<td class='formFieldText' style='text-align:right'>טלפון</td>" +
						"<td class='formField'><input type='text' id='myPhone' name='myPhone' maxLength='11' dir='ltr' style='width:150px' /></td>" +
					"</tr>" +
					"<tr>" +
						"<td class='mandatory'></td>" +
						"<td class='formFieldText' style='text-align:right'>דוא\"ל</td>" +
						"<td class='formField'><input type='text' id='myEmail' name='myEmail' maxLength='150' dir='ltr' style='width:150px' /></td>" +
					"</tr>" +
					"<tr>" +
						"<td class='mandatory'></td>" +
						"<td class='formFieldText' valign='top' style='text-align:right'>הערות</td>" +
						"<td class='formField'><textarea id='myRemarks' name='myRemarks' style='width:150px'></textarea></td>" +
					"</tr>" +
					"<tr height='5px'><td></td></tr>" +
					"<tr>" +
						"<td colspan='2'></td>" +
						"<td align='center'>" +
							"<input type='image' src='loadedFiles/email_send.png' border='0''/>&nbsp;&nbsp;" +
							"<img src='loadedFiles/email_close.png' border='0' onclick='emailForm.close()' style='vertical-align:top' />" +
						"</td>" +
					"</tr>" +
					"</table>" + 
					"</form>" + 
			   	"</div>" +
			   "</div>" +
			   "<div id='sendEmailBottom'></div>";

	emailForm.create (parentName, "emailPopup", html, x, y);

	emailForm.show ();
}

/* ------------------------------------------------------------------------------------------------ */
/* nadlan_validateEmailForm																			*/
/* ------------------------------------------------------------------------------------------------ */
function nadlan_validateEmailForm ()
{
	var formValidator = new Validator("sendEmailForm");
	formValidator.clearAllValidations ();

	formValidator.addValidation("myName",	"required",	"יש להזין שם");
	formValidator.addValidation("myPhone",	"required",	"יש להזין טלפון");
	formValidator.addValidation("myPhone",	"phone",	"יש להזין טלפון חוקי");
	formValidator.addValidation("myEmail",	"email",	"יש להזין דוא\"ל חוקי");

	if (formValidator.validate ())
	{
		var oForm = document.getElementById("sendEmailForm");

		xml = "<data>" +
				"<command>private.sendAdvertiserEmail</command>"   	+
				"<bcId>"		       + oForm.bcId.value		  	+ "</bcId>" 				+
				"<itemId>"		       + oForm.itemId.value		  	+ "</itemId>" 				+
				"<myName>"		       + oForm.myName.value		  	+ "</myName>" 				+
				"<myPhone>"		       + oForm.myPhone.value	  	+ "</myPhone>" 				+
				"<myEmail>"		       + oForm.myEmail.value	  	+ "</myEmail>" 				+
				"<myRemarks>"		   + oForm.myRemarks.value		+ "</myRemarks>" 			+
			  "</data>";

		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "sendEmail_response");
	}

	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* sendEmail_response																				*/
/* ------------------------------------------------------------------------------------------------ */
function sendEmail_response ()
{
	var oForm = document.getElementById("sendEmailForm");

	var html = "<div id='sendEmailTop'>" + 
					"<div id='sendEmailTop_in'>" + oForm.title.value + "</div>" +
			   "</div>" + 
			   "<div id='sendEmailBg'>" + 
			   	"<div id='sendEmailBg_in'>" + 
					"<div id='sendEmailBg_msg'>הבקשה נשלחה בהצלחה.</div>" +
					"<div id='sendEmailBg_close'>" + 
						"<img src='loadedFiles/email_close.png' border='0' onclick='emailForm.close()' style='vertical-align:top' />" +
					"</div>" +
			   	"</div>" +
			   "</div>" +
			   "<div id='sendEmailBottom'></div>";

	emailForm.loadHtml (html);


}

/* ------------------------------------------------------------------------------------------------ */
/* validateNadlanAgentForm																			*/
/* ------------------------------------------------------------------------------------------------ */
function validateNadlanAgentForm ()
{
	var oForm = document.getElementById("nadlanAgentForm");

	var foundError = false;

	// from price
	var charpos = oForm.fromPrice.value.search("[^0-9]"); 
	if (oForm.fromPrice.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("agent_fromPriceError").innerHTML = "יש להזין מחיר בספרות בלבד";
	}
	else
	{
		document.getElementById("agent_fromPriceError").innerHTML = "";
	}

	// to price
	var charpos = oForm.toPrice.value.search("[^0-9]"); 
	if (oForm.toPrice.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("agent_toPriceError").innerHTML = "יש להזין מחיר בספרות בלבד";
	}
	else
	{
		document.getElementById("agent_toPriceError").innerHTML = "";
	}
	
	if (oForm.toPrice.value*1 != 0 && oForm.fromPrice.value*1 > oForm.toPrice.value*1)
	{
		foundError = true;
		document.getElementById("agent_toPriceError").innerHTML = "טווח מחירים לא חוקי";
	}
	else
	{
		document.getElementById("agent_toPriceError").innerHTML = "";
	}

	// eviction date
	dateError = isDate(oForm.dateField3.value);
	if (oForm.dateField3.value != "" && dateError != "")
	{
		foundError = true;
		document.getElementById("agent_evictionDateError").innerHTML = dateError;
	}
	else
	{
		document.getElementById("agent_evictionDateError").innerHTML = "";
	}

	// plottage
	var charpos = oForm.plottage.value.search("[^0-9]"); 
	if (oForm.plottage.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("agent_plottageError").innerHTML = "יש להזין שטח בספרות בלבד";
	}
	else
	{
		document.getElementById("agent_plottageError").innerHTML = "";
	}
	
	// balconyPlottage
	var charpos = oForm.balconyPlottage.value.search("[^0-9]"); 
	if (oForm.balconyPlottage.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("agent_balconyPlottageError").innerHTML = "יש להזין שטח בספרות בלבד";
	}
	else
	{
		document.getElementById("agent_balconyPlottageError").innerHTML = "";
	}
	
	// gardenPlottage
	var charpos = oForm.gardenPlottage.value.search("[^0-9]"); 
	if (oForm.gardenPlottage.value.length > 0 && charpos >= 0)
	{
		foundError = true;
		document.getElementById("agent_gardenPlottageError").innerHTML = "יש להזין שטח בספרות בלבד";
	}
	else
	{
		document.getElementById("agent_gardenPlottageError").innerHTML = "";
	}
	
	oForm.evictionDate.value = document.getElementById("dateField3").value;

	var neighborhoodField = document.getElementById("nadlanAgentForm_neighborhood");

	var neighborhoods = "";
	for (var i=0; i < neighborhoodField.options.length; i++)
	{
		if (neighborhoodField.options[i].selected)
			neighborhoods += " " + neighborhoodField.options[i].value;
	}
	oForm.neighborhood.value = neighborhoods;

	if (document.getElementById("agentPassword") != undefined)
	{
		// contactEmail
		if (oForm.agentEmail.value == "")
		{
			foundError = true;
			document.getElementById("agent_emailError").innerHTML = "יש להזין דוא\"ל";
		}
		else
		{
			if (!validateEmailv2(oForm.agentEmail.value))
			{
				foundError = true;
				document.getElementById("agent_emailError").innerHTML = "יש להזין דוא\"ל חוקי";
			}
			else
			{
				document.getElementById("agent_emailError").innerHTML = "";
			}
		}	

		// contactPassword
		if (oForm.agentPassword.value == "")
		{
			foundError = true;
			document.getElementById("agent_passwordError").innerHTML = "יש להזין סיסמא";
		}	
		else
		{
			if (oForm.agentPassword.value.length < 6 || oForm.agentPassword.value.indexOf(" ") != -1)
			{
				foundError = true;
				document.getElementById("agent_passwordError").innerHTML = "סיסמא בת 6 תווים ללא רווחים";
			}
			else
			{
				document.getElementById("agent_passwordError").innerHTML = "";
			}
		}	

		if (!oForm.agent_terms.checked)
		{
			foundError = true;
			document.getElementById("agent_termsError").innerHTML = "חובה לציין הסכמה לתנאי השימוש";
		}
		else
		{
			document.getElementById("agent_termsError").innerHTML = "";
		}

	}

	if (foundError)
	{
		alert ("כדי להפעיל את הסוכן החכם יש למלא את הפרטים המסומנים באדום, תודה!");
		return false;
	}

	if (document.getElementById("agentPassword") == undefined)
		return true;

	checkMember ("nadlanAgentForm");
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* nadlanAgentForm_checkMember_response																*/
/* ------------------------------------------------------------------------------------------------ */
function nadlanAgentForm_checkMember_response ()
{
	xmlRequest.init(commonDecode(asyncHttpObj.responseText));
						
	try
	{
		success = xmlRequest.getValue("success");
	}
	catch (e)
	{
		alert ("AJAX Error");
		return false;
	}
	
	if (success == "0")
	{
		document.getElementById("nadlanAgentForm").submit ();
	}
	else if (success == "1")
	{
		alert ("סיסמת זיהוי שגויה עבור דוא\"ל זה");
		document.getElementById("contactPasswordError").innerHTML = "יש להזין סיסמא שוב";
	}
}

/* ------------------------------------------------------------------------------------------------ */
/* sendPasswordFromAgent																			*/
/* ------------------------------------------------------------------------------------------------ */
function sendPasswordFromAgent ()
{
	var oForm = document.getElementById("nadlanAgentForm");

	var formValidator = new Validator("nadlanAgentForm");
	formValidator.clearAllValidations ();

	formValidator.addValidation("agentEmail",	"required",	"יש להזין דוא\"ל");
	formValidator.addValidation("agentEmail",	"email",	"יש להזין דוא\"ל חוקי");

	if (formValidator.validate ())
	{
		var passForm = document.getElementById("passForm");

		passForm.username.value = oForm.agentEmail.value;
		passForm.redirect.value	= "37&open=agent";

		passForm.submit ();
			
	}
	return false;
}

/* ------------------------------------------------------------------------------------------------ */
/* resetAgentForm																					*/
/* ------------------------------------------------------------------------------------------------ */
function resetAgentForm ()
{
	oForm = document.getElementById("nadlanAgentForm");

	oForm.nadlanType.value			= "all";
	oForm.fromPrice.value			= "";
	oForm.currency.value			= "USD";
	oForm.toPrice.value				= "";
	oForm.inf_dateField3.value		= "";
	oForm.dateField3.value			= "";
	oForm.immediateEviction.checked	= false;
	oForm.rentPeriod.value			= "";
	oForm.plottage.value			= "";
	oForm.balconyPlottage.value		= "";
	oForm.gardenPlottage.value		= "";
	oForm.numRooms.value			= "";
	oForm.elevator.checked			= false;
	oForm.parking.checked			= false;
	oForm.airConditioning.checked	= false;
	oForm.parentsBedroom.checked	= false;
	oForm.store.checked				= false;

	resetMultiSelection (oForm.itemType);
	resetMultiSelection (oForm.cityId);
	resetMultiSelection (oForm.nadlanAgentForm_neighborhood);
	resetMultiSelection (oForm.numRooms);
}

var minYear=00;
var maxYear=99;

function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
	{   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) 
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
	check = checkDate(dtStr, ".");
	if (check != "") return check;

	check = checkDate(dtStr, "-");
	if (check != "") return check;

	check = checkDate(dtStr, "/");
	if (check != "") return check;

	return "";
}

function checkDate (dtStr, dtCh)
{
	var daysInMonth = DaysArray(12)
	var pos1		= dtStr.indexOf(dtCh)
	var pos2		= dtStr.indexOf(dtCh,pos1+1)
	var strDay		= dtStr.substring(0,pos1)
	var strMonth	= dtStr.substring(pos1+1,pos2)
	var strYear		= dtStr.substring(pos2+1)
	strYr = strYear
//	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
//	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
//	for (var i = 1; i <= 3; i++) 
//	{
//		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
//	}
	month	= strMonth*1;
	day		= strDay*1
	year	= strYr*1;

	if (pos1==-1 || pos2==-1)
	{
		return "תאריך בפורמט יום.חודש.שנה";
	}
//	if (strDay.length != 2)
//	{
//		return ("יש להזין יום בשתי ספרות");
//	}
	if (day<1 || day>31)
	{
		return ("יום לא חוקי");
	}
	if ((month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
	{
		return ("יום לא חוקי בחודש");
	}
//	if (strMonth.length != 2)
//	{
//		return ("יש להזין חודש בשתי ספרות");
//	}
	if (month<1 || month>12)
	{
		return ("חודש לא תקין");
	}
	if (strYear.length != 2 || year==0 || year<minYear) // || year>maxYear)
	{
		return ("שנה לא חוקית");
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		return ("תאריך לא חוקי");
	}
	return ""
}




