//validates login fields
function validateLoginFields(){
	if (isEmpty(document.getElementById('loginMail').value)){
		document.getElementById('loginMail').focus();
		return false;
	}else if (isEmpty(document.getElementById('loginPassword').value)){
		document.getElementById('loginPassword').focus();
		return false;
	}
	return true;
}
//submits login
function onLoginBeeyootSubmit(){
	if (validateLoginFields()){
		var now = new Date();
		var month = now.getMonth()+1;
		var day = now.getDate();
		var year = now.getFullYear();
		var hours = now.getHours();
		var minutes = now.getMinutes();
		var seconds = now.getSeconds();
		document.getElementById('clientTime').value = month +"/"+day+"/"+year+" "+hours+":"+minutes+":"+seconds;
		document.signInForm.submit();
	}
	return;
}

//validates location fields for post home
function validateLocationField(){
	messageInfoDisplay('errorMsg',"","none");
	if (($('city').value == 0)){
		messageInfoDisplay('errorMsg',"City is required.","block");	
 		$('city').focus();
 		return false;
 	}else if (isEmpty($('neighborhood').value)){
 		messageInfoDisplay('errorMsg',"Neighborhood is required.","block");	
 		$('neighborhood').focus();
 		return false;
 	}else if ($('neighborhood').value==0){
 		messageInfoDisplay('errorMsg',"Neighborhood is required.","block");	
 		$('neighborhood').focus();
 		return false;
 	}else if (isEmpty($('longitude').value)){
 		$('longitude').focus();
 		return false;
 	}else if (isEmpty($('latitude').value)){
 		$('latitude').focus();
 		return false;
 	}
	
	messageInfoDisplay('errorMsg',"","none");
 	return true;
}
//validates listing fields for post home
function propertyContentBehavior(){
			processElementBehavior('txtLotSize');
		 	processElementBehavior('txtBathRooms');
		 	processElementBehavior('txtBedRooms');
		 	processElementBehavior('txtSize');
		 	processElementBehavior('buildYear');
		 	processElementBehavior('txtAddress2');
}

function propertyTypeElements(){
			elementMode('txtPrice',false);
		 	elementMode('txtSize',false);
		 	elementMode('buildYear',false);
		 	elementMode('building',false);
		 	elementMode('txtAddress2',false);
			
			setElementBackgroundColor('txtPrice','white');
			setElementBackgroundColor('txtSize','white');
			setElementBackgroundColor('buildYear','white');
			setElementBackgroundColor('building','white');
			setElementBackgroundColor('txtAddress2','white');
} 
//validates listing fields for post home
function validateListingField(){
	if (($('lstType').value == 0)){
		messageInfoDisplay('errorListingMsg',"List type is required.","block");
 		$('lstType').focus();
 		return false;
 	}else if (($('entityType').value == 0)){
 		messageInfoDisplay('errorListingMsg',"Listing entity is required.","block");
 		$('entityType').focus();
 		return false;
 	}else if (($('propType').value == 0)){
 		messageInfoDisplay('errorListingMsg',"Property type is required.","block");
 		$('propType').focus();
 		return false;
 	}else if (($('readType').value == 0)){
 		messageInfoDisplay('errorListingMsg',"Readiness type is required.","block");
 		$('readType').focus();
 		return false;
 	}else if($('propType').value == 4){
		elementMode('txtLotSize',false);
	 	if (isEmpty($('txtPrice').value)){
			messageInfoDisplay('errorListingMsg',"Price is required.","block");
	 		$('txtPrice').focus();
	 		return false;
	 	}else if (!($('txtPrice').value >=1 && $('txtPrice').value <= 999999999.00)){
			messageInfoDisplay('errorListingMsg',"Price is from 1 - 999999999.00 only.","block");
			$('txtPrice').focus();
			return false;
		}else if (isEmpty($('txtLotSize').value)){
			messageInfoDisplay('errorListingMsg',"Lot size is required.","block");
	 		$('txtLotSize').focus();
	 		return false;
	 	}else if (!($('txtLotSize').value >=1 && $('txtLotSize').value <= 99999.00)){
			messageInfoDisplay('errorListingMsg',"Size is from 1 to 99999 only.","block");
			$('txtLotSize').focus();
			return false;
		}
	}else if ($('propType') != 4){
		if (isEmpty($('txtPrice').value)){
	 		messageInfoDisplay('errorListingMsg',"Price is required.","block");
	 		$('txtPrice').focus();
	 		return false;
	 	}else if (!($('txtPrice').value >=1 && $('txtPrice').value <= 999999999.00)){
			messageInfoDisplay('errorListingMsg',"Price is from 1 - 999999999.00 only.","block");	
			$('txtPrice').focus();
			return false;
		}else if (isEmpty($('txtSize').value)){
			messageInfoDisplay('errorListingMsg',"Size is required.","block");
	 		$('txtSize').focus();
	 		return false;
	 	}else if (!($('txtSize').value >=1 && $('txtSize').value <= 99999.00)){
			messageInfoDisplay('errorListingMsg',"Size is from 1 to 99999 only.","block");
			$('txtSize').focus();
			return false;
		}else if (isEmpty($('buildYear').value)){
	 		messageInfoDisplay('errorListingMsg',"Build year is required.","block");
	 		$('buildYear').focus();
	 		return false;
	 	}else if($('buildYear').value.length!=4){
			messageInfoDisplay('errorListingMsg',"Build year must be four digits.","block");
			$('buildYear').focus();
	 		return false;
		}
		
		if($('propType').value == "2"){
		//validation for bathrooms and bedrooms
			if (isEmpty($('txtBathRooms').value)){
				messageInfoDisplay('errorListingMsg',"No. of bathrooms are required.","block");
		 		$('txtBathRooms').focus();
		 		return false;
		 	}else if ($('txtBathRooms').value <= 0){
				messageInfoDisplay('errorListingMsg',"No. of bathrooms must be greater than zero.","block");
		 		$('txtBathRooms').focus();
		 		return false;
		 	}else if (isEmpty($('txtBedRooms').value)){
				messageInfoDisplay('errorListingMsg',"No. of bedrooms are required.","block");
		 		$('txtBedRooms').focus();
		 		return false;
		 	}
		}else if($('propType').value == 1 || $('propType').value == 3 || $('propType').value == 10 || $('propType').value == 11){
			//bathrooms/lotsize/bedrooms	
			if (isEmpty($('txtLotSize').value)){
				messageInfoDisplay('errorListingMsg',"Lot size is required.","block");
		 		$('txtLotSize').focus();
		 		return false;
		 	}else if (!($('txtLotSize').value >=1 && $('txtLotSize').value <= 99999.00)){
				messageInfoDisplay('errorListingMsg',"Size is from 1 to 99999 only.","block");
				$('txtLotSize').focus();
				return false;
			}else if (isEmpty($('txtBathRooms').value)){
				messageInfoDisplay('errorListingMsg',"No. of bathrooms are required.","block");
		 		$('txtBathRooms').focus();
		 		return false;
		 	}else if ($('txtBathRooms').value <= 0){
				messageInfoDisplay('errorListingMsg',"No. of bathrooms must be greater than zero.","block");
		 		$('txtBathRooms').focus();
		 		return false;
		 	}else if (isEmpty($('txtBedRooms').value)){
				messageInfoDisplay('errorListingMsg',"No. of bedrooms are required.","block");
		 		$('txtBedRooms').focus();
		 		return false;
		 	}	
		}
	}
 	//	
	var day =  $('txtdateDay').value;
	var month =  $('txtdateMonth').value;
	var year =  $('txtdateYear').value;
	var hours =  $('txttimeHours').value;
	var minutes =  $('txttimeMinutes').value;
		
	var date = month+" "+day+" "+year+" "+hours+":"+minutes;
	var openHouse_date = $('openHouse_date');
	openHouse_date.value = date;
	
	messageInfoDisplay('errorMsg',"","none");
 	return true; 
}

function lstTypeChange(_id){
	if($('lstType').value == "2" || $('lstType').value == "0"){
		fetchEntityType(_id);
		$('entityType').options.length = 1;
		$('entityType').options[$('entityType').selectedIndex].text = "Please Select";		
		fetchReadinessType(_id);
		$('readType').options.length = 1;
		$('readType').options[$('readType').selectedIndex].text = "Please Select";
		
	}else{
		fetchEntityType(_id);
		$('entityType').options.length = 1;
		$('entityType').options[$('entityType').selectedIndex].text = "Please Select";		
		fetchReadinessType(_id);
		$('readType').options.length = 1;
		$('readType').options[$('readType').selectedIndex].text = "Please Select";
	}
}

function fetchReadinessType(_lstTypeId){
	new Ajax.Request(readinessTypeUrl, {
		asynchronous:true, method: 'post', parameters: 'lstTypeId='+_lstTypeId,
			onComplete: function(transport){
				var json = transport.responseText.evalJSON();
				for (var i=0; i<json.readinessCollection.length;i++){
					    $('readType').options.add(new Option(json.readinessCollection[i].name,json.readinessCollection[i].id));
				}				
				loadReadinessType($('readType').value);
			}
	});

}

function fetchEntityType(_lstTypeId){
	new Ajax.Request(entityTypeUrl, {
		asynchronous:true, method: 'post', parameters: 'lstTypeId='+_lstTypeId,
			onComplete: function(transport){
				var json = transport.responseText.evalJSON();
				for (var i=0; i<json.entityCollection.length;i++){
					    $('entityType').options.add(new Option(json.entityCollection[i].name,json.entityCollection[i].id));
				}
				loadEntityType($('entityType').value);
			}
	});

}

function loadReadinessType(_id){
	$('readType').value = _id;
}

function loadEntityType(_id){
	$('entityType').value = _id;
}
//changes on ui when property type is change 
function propertyTypeChange(){
	propertyContentBehavior();
	if($('propType').value =="4"){
		elementMode('txtLotSize',false);
	 	elementMode('txtPrice',false);
	 	elementMode('txtBathRooms',true);
	 	elementMode('txtBedRooms',true);
	 	elementMode('txtSize',true);
	 	elementMode('buildYear',true);
	 	elementMode('building',true);
	 	elementMode('txtAddress2',true);
	 	
		setElementBackgroundColor('txtLotSize','white');
		setElementBackgroundColor('txtPrice','white');
		setElementBackgroundColor('txtBathRooms','#D4D0C8');
		setElementBackgroundColor('txtBedRooms','#D4D0C8');
		setElementBackgroundColor('txtSize','#D4D0C8');
		setElementBackgroundColor('buildYear','#D4D0C8');
		setElementBackgroundColor('building','#D4D0C8');
		setElementBackgroundColor('txtAddress2','#D4D0C8');
	}else {
		 propertyTypeElements();	
		if($('propType').value =="2"){
			elementMode('txtLotSize',true);
		 	elementMode('txtBathRooms',false);
		 	elementMode('txtBedRooms',false);
		 	setElementBackgroundColor('txtLotSize','#D4D0C8');
			setElementBackgroundColor('txtBathRooms','white');
			setElementBackgroundColor('txtBedRooms','white');
		}else if($('propType').value >= 5 && $('propType').value <= 9  ){
			elementMode('txtLotSize',true);
		 	elementMode('txtBathRooms',true);
		 	elementMode('txtBedRooms',true);
		 	setElementBackgroundColor('txtLotSize','#D4D0C8');
			setElementBackgroundColor('txtBathRooms','#D4D0C8');
			setElementBackgroundColor('txtBedRooms','#D4D0C8');
		}else{
			elementMode('txtLotSize',false);
		 	elementMode('txtBathRooms',false);
		 	elementMode('txtBedRooms',false);
		 	setElementBackgroundColor('txtLotSize','white');
			setElementBackgroundColor('txtBathRooms','white');
			setElementBackgroundColor('txtBedRooms','white');
		}
	}		
	
}
//changes text ui and behaviours
function processElementBehavior(_id){
	if (_id == 'txtAddress2'){
		if(!isElementValueNull(_id) && $(_id).value == ""){
			clearField(_id);
			setElementStyleColor(_id,'black');
		}
		return;
	}
	
	if(!isElementValueNull(_id) && $(_id).value == "-1"){
		clearField(_id);
		setElementStyleColor(_id,'black');
	}
	
}
//validate description fields
function validateDescriptionField(){
	
	var defaultTitle = "Enter Title";
	var defaultDesc = "For example: Spacious Garden Home with Private Pool";
	
	if(isEqualTo($('txtTitle').value,defaultTitle)){
		messageInfoDisplay('errorDescMsg',"Title is required.","block");
		removeDefaultTitleText();
		$('txtTitle').focus();
		return false;
	}else if(isEqualTo($('txtDescription').value,defaultDesc)){
		messageInfoDisplay('errorDescMsg',"Description is required.","block");
		removeDefaultDescText();
		$('txtDescription').focus();
		return false;
	} if (isEmpty($('txtTitle').value)){
		messageInfoDisplay('errorDescMsg',"Title is required.","block");
		$('txtTitle').focus();
		return false;
	} else if (isEmpty($('txtDescription').value)){
		messageInfoDisplay('errorDescMsg',"Description is required.","block");
		$('txtDescription').focus();
		return false;
	}
	messageInfoDisplay('errorMsg',"","none");
	return true;
}
//clear fields
function clear(){
	$('city').selectedIndex = 0;
	$('neighborhood').selectedIndex =0;
	clearField('longitude');
	clearField('latitude');
	clearField('txtAddress');
	
	$('txtTitle').value = "Enter Title";
	$('txtDescription').value = "For example: Spacious Garden Home with Private Pool";
	
}
//show location tab
function showLocation(){
	messageInfoDisplay('errorMsg',"","none");
	$('location').show();
	$('listingData').hide();
	$('_description').hide();
	$('publish').hide();
	
	$('tabLocation').setClassName('tabActive2');
	$('tabData').setClassName('tab');
	$('tabDesc').setClassName('tab');
	$('tabPublish').setClassName('tab');
}

// set site broker as property owner upon brokered service selection
function setBrokered(){
	info.isBrokered = "true";
}


//switch to  data tab
function showData(){
	
	messageInfoDisplay('errorMsg',"","none");
	if (!validateLocationField())
		return;
	
	info.cityText = $('city').options[$('city').selectedIndex].text;
	info.city = $('city').value.substring(0,$('city').value.indexOf('-'));
	info.neighborhoodText = $('neighborhood').options[$('neighborhood').selectedIndex].text;
	info.neighborhood = $('neighborhood').value.substring(0,$('neighborhood').value.indexOf('-'));
	info.longitude = $('longitude').value;
	info.latitude = $('latitude').value;
	info.address = $('txtAddress').value;
	
	if($('isOpenHouse').value == "No"){
		$('txtatAddress').value = "";
	}
	$('location').hide();
	$('listingData').show();
	$('_description').hide();
	$('publish').hide();
	
	$('tabLocation').setClassName('tab');
	$('tabData').setClassName('tabActive2');
	$('tabDesc').setClassName('tab');
	$('tabPublish').setClassName('tab');
	document.title = "Beeyoot - Listing Data";
	linkHrefData();
}
//switch to description tab
function showDesc(){
	
	messageInfoDisplay('errorMsg',"","none");
	if (!validateOpenHouseData())
		return;
	info.listingType=$('lstType').value;
	info.propertyType=$('propType').value;
	info.readinessType=$('readType').value;
	info.listingTypeText = $('lstType').options[$('lstType').selectedIndex].text;
	info.propertyTypeText=$('propType').options[$('propType').selectedIndex].text;
	info.readinessTypeText=$('readType').options[$('readType').selectedIndex].text;
	info.status=$('status').value;
	info.price=$('txtPrice').value;
	info.size=$('txtSize').value;
	info.lotSize=$('txtLotSize').value;
	info.bedrooms=$('txtBedRooms').value;
	info.bathroom=$('txtBathRooms').value;
	info.building=$('building').value;
	info.buildingText=$('building').options[$('building').selectedIndex].text;
	info.builtYear=$('buildYear').value;
	info.address = $('txtAddress').value;
	info.openHouse = $('openHouse_date').value;
	info.isOpenHouse = $('isOpenHouse').value;
	info.customBuilding = $('txtAddress2').value;
	info.entityType = $('entityType').value;
	info.entityTypeText = $('entityType').options[$('entityType').selectedIndex].text;
	
	$('location').hide();
	$('listingData').hide();
	$('_description').show();
	$('publish').hide();
	
	$('tabLocation').setClassName('tab');
	$('tabData').setClassName('tab');
	$('tabDesc').setClassName('tabActive2');
	$('tabPublish').setClassName('tab');
	document.title = "Beeyoot - Property Description";
	
	total = photoCollection.length;
	
	linkHrefDesc();
}
//switch to publich tab
function showPublish(){
	
	messageInfoDisplay('errorMsg',"","none");
	if (!validateDescriptionField())
		return;
		
	/*if (!photoCollection.hasPrimary()){
 		messageInfoDisplay('errorDescMsg',"Each property must have a photo. Please upload one.","block");
 		return;
 	}*/
 	
 	var i=0;
 	var str ="";
 	var strPrimary="";
 	$('totalImage').value=photoCollection.length;
 	if($('totalImage').value <= 4){
		$('proPrevButton').style.display = "none";
		$('propNextButton').style.display = "none";
	}else{
		$('proPrevButton').style.display = "block";
		$('propNextButton').style.display = "block";
	}
 	
 	for (var _photo in photoCollection.photos){
 		if (!photoCollection.hasPrimary()){
 			if (photoCollection.length>0){
 				photoCollection.setAsPrimary(_photo);
 			}else{
 				$('primaryDiv').innerHTML='<img id="largeImg" class="primaryPhoto"  src="css/images/default_property_image.jpg" alt="property Image">';
 				break;
 			}
 		}
		 if( typeof(photoCollection.photos[_photo]) == "object" ) {
		    var _display = '';
		    if (i>3)
		    	_display = 'none';
		    if (photoCollection.photos[_photo].isPrimary)	
		    	strPrimary=photoCollection.photos[_photo].encodedUrl;
		 	
		 	str+='<a style="display:'+_display+'" id="thumb_'+i+'" class="propertyClass" href="javascript:void(0);">';
			str+='<img id="thumbs" alt="property" class="thumbs" border="0" src="'+photoCollection.photos[_photo].encodedUrl+'" height="60" style="margin:30px 13px 13px 0;;max-width:90px"></img>';
		 	str+='</a>';
			i++;
		 }
	}
	
	$('imagePlace').innerHTML = "<center>" + str + "<center>";
	if (photoCollection.length>0){
		$('primaryDiv').innerHTML='<img id="largeImg" class="primaryPhoto"  src="'+strPrimary+'" alt="property Image">';
	}
 	
	info.title = $('txtTitle').value;
	info.description = $('txtDescription').value;
	info.imageCollection = photoCollection;
	
	$('lblCity').innerHTML = info.cityText;
	$('lblArea').innerHTML = info.neighborhoodText;
	$('lblLongitude').innerHTML = info.longitude;
	$('lblLatitude').innerHTML = info.latitude;
	$('lblAddress').innerHTML = info.address;

	$('lblListType').innerHTML = info.listingTypeText;
	$('lblPropType').innerHTML = info.propertyTypeText;
	$('lblReadType').innerHTML = info.readinessTypeText;
	$('lblStatus').innerHTML = info.status;
	$('lblPrice').innerHTML = info.price;
	$('lblSize').innerHTML = info.size;
	
	if(info.propertyType == "4"){
		$('_lotsize').style.display = "block";
		$('lblLotSize').innerHTML = info.lotSize;
		$('lblPrice').innerHTML = info.price;
		info.bathroom = "-1";
		info.bedrooms = "0";
		info.size = "-1";
		$('lblSize').style.display = "none";
		info.builtYear ="-1";
		
		if(info.building == "0"){
			$('lblBuilding').innerHTML = info.customBuilding;
		}else{
			$('lblBuilding').innerHTML = "";
			info.customBuilding = "";
		}
	}else{
		if(info.propertyType == "2"){
			info.lotSize = "1";
			$('_lotsize').style.display = "none";
			$('lblPrice').innerHTML = info.price;
			$('lblBathRooms').innerHTML = info.bathroom;
			$('lblbedRooms').innerHTML = info.bedrooms;
			$('lblSize').innerHTML = info.size;
			$('lblBuiltYear').innerHTML = info.builtYear;
			
			if(info.building == "0"){
				$('lblBuilding').innerHTML = info.customBuilding;
			}else{
				$('lblBuilding').innerHTML = info.buildingText;
				info.customBuilding = "";
			}
		}else if(info.propertyType >= 5 && info.propertyType <= 9){
			info.lotSize = "-1";
			info.bathroom = "-1";
			info.bedrooms = "-1";
			$('_lotsize').style.display = "none";
			$('lblPrice').innerHTML = info.price;
			$('lblSize').innerHTML = info.size;
			$('lblBuiltYear').innerHTML = info.builtYear;
			
			if(info.building == "0"){
				$('lblBuilding').innerHTML = info.customBuilding;
			}else{
				$('lblBuilding').innerHTML = info.buildingText;
				info.customBuilding = "";
			}
		}else{
			$('lblPrice').innerHTML = info.price;
			$('lblBathRooms').innerHTML = info.bathroom;
			$('lblLotSize').innerHTML = info.lotSize;
			$('lblbedRooms').innerHTML = info.bedrooms;
			$('lblSize').innerHTML = info.size;
			$('lblBuiltYear').innerHTML = info.builtYear;
			
			if(info.building == "0"){
				$('lblBuilding').innerHTML = info.customBuilding;
			}else{
				$('lblBuilding').innerHTML = info.buildingText;
				info.customBuilding = "";
			}
		}
	}
	$('lblEntityType').innerHTML = info.entityTypeText;
	$('lblTitle').innerHTML = info.title;
	$('lblDescription').innerHTML = info.description;
	if($('isOpenHouse').value == "No"){
		$('lblOpenHouseDate').innerHTML = "";
	}else{
		$('lblOpenHouseDate').innerHTML = info.openHouse;
	}
	
	$('location').hide();
	$('listingData').hide();
	$('_description').hide();
	$('publish').show();
	
	$('tabLocation').setClassName('tab');
	$('tabData').setClassName('tab');
	$('tabDesc').setClassName('tab');
	$('tabPublish').setClassName('tabActive2');
	document.title = "Beeyoot - Publish Property";
	
	linkHrefPublish();
	
	jQuery(".thumbs").click(function(){
		var largePath = jQuery(this).attr("src");
		jQuery("#largeImg").attr({ src: largePath });
	 });
}
//shows subscribe page
function showSubscribe(){
	elementShow('subscribe');
	elementHide('upgrade');
	elementHide('purchase');
	
	document.getElementById('tabSubscribe').className = 'tabActive2';
	document.getElementById('tabUpgrade').className = 'tab';
	document.getElementById('tabPurchase').className = 'tab';
}
//shows purchase page
function showPurchase(){
	elementHide('subscribe');
	elementHide('upgrade');
	elementShow('purchase');

	document.getElementById('tabSubscribe').className = 'tab';
	document.getElementById('tabUpgrade').className = 'tab';
	document.getElementById('tabPurchase').className = 'tabActive2';
}
//links <a> link tags
function linkHrefLocation(){
	disableHref('lnkLocation');
	disableHref('lnkData');
	disableHref('lnkDesc');
	disableHref('lnkPublish');
}
//links <a> link tags
function linkHrefData(){
	disableHref('lnkLocation');
	disableHref('lnkData');
	disableHref('lnkDesc');
	disableHref('lnkPublish');
}
//links <a> link tags
function linkHrefDesc(){
	disableHref('lnkDesc');
	disableHref('lnkData');
	disableHref('lnkLocation');
	disableHref('lnkPublish');
}
//links <a> link tags
function linkHrefPublish(){
	disableHref('lnkLocation');
	disableHref('lnkDesc');
	disableHref('lnkData');
	disableHref('lnkPublish');
}

//shows thank you message after mortgage form is submit
function showThankYou(){
	elementShow('thankyou');
	elementHide('mortgage_form');
}
//clear all markers in gmap
function emptyMap(){
	if(map){
		map.clearOverlays();
		clearField('latitude');	
		clearField('longitude');	
    }
}
//loads area to map
function loadAreaToMap(_id){
	var _address = _id.substring(_id.indexOf("-")+1).split("|");
	if (!_address[1])
		return;
	_address = _address[0].toDegreeFormat(true) +" "+_address[1].toDegreeFormat(false);
	var pagerUrl_ = window.location.href;
	if ( pagerUrl_.match('post_home')  ){
		isAutoPin = true;
	}
	
	loadMapByAddress(_address);
}
//fetch all neighborhood depends on the city which is selected
function showArea(_cityId,_isSearch){
	$('neighborhood').options.length = 0;
	if (_cityId==0 && _isSearch){
		$('neighborhood').options.add(new Option('All','0'));
		return;
	}
	
	isAutoPin = true;
	new Ajax.Request(areaCity, { 													
		asynchronous:true, method: 'post', parameters: 'cityId='+_cityId+'&search='+_isSearch,
			onComplete: function(transport){
				var json = transport.responseText.evalJSON();
				var str = '';
				if (_isSearch)
					$('neighborhood').options.add(new Option('All','0'));
				
				for (var i=0; i<json.areaCollection.length;i++){
				    $('neighborhood').options.add(new Option(json.areaCollection[i].name,json.areaCollection[i].id+'-'+json.areaCollection[i].coordinates));
				}
					
				if (_isSearch)
					setQuickSearchArea();
				loadAreaToMap($('neighborhood').value);
			}
	});
	
}

//fetch all neighborhoods for a given city, select the provided one
function showAndSelectArea(_cityId,_selectedArea){

	$('neighborhood').options.length = 0;
	new Ajax.Request(areaCity, { 													
		asynchronous:true, method: 'post', parameters: 'cityId='+_cityId+'&search=false',
			onComplete: function(transport){
				var json = transport.responseText.evalJSON();
				var str = '';
				
				for (var i=0; i<json.areaCollection.length;i++){
				    $('neighborhood').options.add(new Option(json.areaCollection[i].name,json.areaCollection[i].id+'-'+json.areaCollection[i].coordinates));
				}
				
				$('neighborhood').value = _selectedArea;
				setQuickSearchArea();
				loadAreaToMap($('neighborhood').value);				
			}
	});
	
}

//publish newly added property
function publishProperty(){
	var formPublish = document.publishForm;
	$('propertyData').value = info.toString();
	formPublish.submit();
}
//validates mortgage
function validateMortage() {

	if(isEmpty($('name').value)) {
		$('errorMortgageMsg').innerHTML = "Name is required";
		$('name').focus();
		return;
	}else if(isEmpty($('mobile').value)) {
		$('errorMortgageMsg').innerHTML = "Mobile number is required";
		$('mobile').focus();
		return;
	}else if(!isNumeric($('mobile').value)){
		$('errorMortgageMsg').innerHTML = "Mobile number is in invalid format";
		$('mobile').focus();
		return
	}else if(isEmpty($('email').value)) {
		$('errorMortgageMsg').innerHTML = "Email is required";
		$('email').focus();
		return;
	}else if (!isValidEmail($('email'))) {
		$('errorMortgageMsg').innerHTML = "Invalid email";
		$('email').focus();
		return;
	}else if(isEmpty($('profit').value)) {
		$('errorMortgageMsg').innerHTML = "Salary/ Net Profit is required";
		$('profit').focus();
		return;
	}else if(!isNumeric($('profit').value)){
		$('errorMortgageMsg').innerHTML = "Salary/ Net Profit is in invalid format";
		$('profit').focus();
		return;
	}else if($('profit').value <= 0) {
		$('errorMortgageMsg').innerHTML = "Salary/ Net Profit must be greater than zero.";
		$('profit').focus();
		return;
	} else if(isEmpty($('price').value)) {
		$('errorMortgageMsg').innerHTML = "Selling Price is required.";
		$('price').focus();
		return;
	}else if(!isNumeric($('price').value)){
		$('errorMortgageMsg').innerHTML = "Selling Price is in invalid format";
		$('price').focus();
		return;
	}else if($('price').value <= 0) {
		$('errorMortgageMsg').innerHTML = "Selling Price must be greater than zero.";
		$('price').focus();
		return;
	}else if(isEmpty($('loanAmount').value)) {
		$('errorMortgageMsg').innerHTML = "Loan amount is required.";
		$('loanAmount').focus();
		return;
	}else if(!isNumeric($('loanAmount').value)){
		$('errorMortgageMsg').innerHTML = "Loan amount is in invalid format";
		$('loanAmount').focus();
		return;
	}else if($('loanAmount').value <= 0) {
		$('errorMortgageMsg').innerHTML = "Loan amount must be greater than zero.";
		$('loanAmount').focus();
		return;
	}
	
	if (document.sendMortgage.agreement.checked == false) {
		$('errorMortgageMsg').innerHTML = "";
		$('agreeMsg').innerHTML = "Do you agree?";
		return;
	}
	
	document.sendMortgage.submit();
}
//validates add propejct fields
function validateAddProject() {

	if(isEmpty($('proj_name').value)) {
		$('errorMortgageMsg').innerHTML = "Project name is required";
		$('proj_name').focus();
		return;
	}else if(isEmpty($('fname').value)) {
		$('errorMortgageMsg').innerHTML = "First name is required";
		$('fname').focus();
		return;
	}else if(isEmpty($('lname').value)) {
		$('errorMortgageMsg').innerHTML = "Last name is required";
		$('lname').focus();
		return;
	}else if(isEmpty($('telno').value)) {
		$('errorMortgageMsg').innerHTML = "Telephone number is required";
		$('telno').focus();
		return;
	}else if(!isNumeric($('telno').value)){
		$('errorMortgageMsg').innerHTML = "Telephone number is in invalid format";
		$('telno').focus();
		return
	}else if(isEmpty($('email').value)) {
		$('errorMortgageMsg').innerHTML = "Email address is required";
		$('email').focus();
		return;
	}else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('email').value))) {
		$('errorMortgageMsg').innerHTML = "Invalid email";
		$('email').focus();
		return;
	}
	
	if (document.addProject.agreement.checked == false) {
		$('errorMortgageMsg').innerHTML = "";
		$('agreeMsg').innerHTML = "Do you agree?";
		return;
	}
	
	document.addProject.submit();
}


