//----------------------------------------Full View Function------------------------------------------------------
function PicNextPreClick(ListingID_RETS, Action, TotalPicCnt)
{
	PicIndexVal = document.getElementById('PicIndex').value;
	
	if (Action=='Next')
	{
		PicIndexVal = parseInt(PicIndexVal) + 6;
		if (PicIndexVal > TotalPicCnt)
			PicIndexVal = 0;
	}
	else
	{
		PicIndexVal = parseInt(PicIndexVal) - 6;
		if (PicIndexVal<0)
			PicIndexVal = 0;
	}

	xajax_listingPictureLoop(ListingID_RETS, Action, PicIndexVal);
}
function bigImageShowing(pic_no, tot_pic)
{
	for(i=0; i < tot_pic; i++)
	{
		var ctlName = 'mainImg'+i;
		
		if (pic_no==i)
			document.getElementById(ctlName).style.display='block';
		else
			document.getElementById(ctlName).style.display='none';
	}
}
//----------------------------------------xAjax Function------------------------------------------------------
//====================================================================================================
//	Function Name	:	SaveSearch_Click()
//----------------------------------------------------------------------------------------------------
function SaveSearch_Click(Action, SearchNo)
{
	if (Action == 'Show')
	{
		// Show loader
		ToggleLoader(true);

		popupWin('', '', 500, 225);

		// Make the server call
		xajax_saveUserSearch(Action, SearchNo, xajax.getFormValues('frmSearch'));
	}
	else
	{
		with(document.frmSaveSearch)
		{
			if(!IsEmpty(search_title, 'Please, enter search Title'))
			{
				return false;
			}
		}

		// Show loader
		ToggleLoader(true);

		// Make the server call
		xajax_saveUserSearch(Action, SearchNo, xajax.getFormValues('frmSaveSearch'));
	}
}
//====================================================================================================
//	Function Name	:	UpdateFav_Click()
//----------------------------------------------------------------------------------------------------
function UpdateFav_Click(ListingID_RETS)
{
	// Show loader
	//ToggleLoader(true);

	var anchorCtrl = document.getElementById('anchorFav'+ListingID_RETS)

	if (anchorCtrl.innerHTML=='Remove from Favorites')
		var Action = "Remove";
	else
		var Action = "Add";
	
	// Make the server call
	xajax_updateUserFavorites(ListingID_RETS, Action);
}
//====================================================================================================
//	Function Name	:	UpdateRoute_Click()
//----------------------------------------------------------------------------------------------------
function UpdateRoute_Click(ListingID_RETS)
{
	var anchorCtrl = document.getElementById('anchorRoute'+ListingID_RETS)

	if (anchorCtrl.innerHTML=='Remove from Route')
		var Action = "Remove";
	else
		var Action = "Add";

	// Make the server call
	xajax_updateRouteInfo(ListingID_RETS, Action);
}
//====================================================================================================
//	Function Name	:	ScheduleShowing_Click()
//----------------------------------------------------------------------------------------------------
function ScheduleShowing_Click(ListingID_RETS, Action)
{
	// Show loader
	ToggleLoader(true);

	if (Action=='Send')
	{
		frm = document.getElementById('frmSchedule')
		with(frm)
		{
			
 			if(!IsEmpty(lead_preferred_date, 'Please, enter Date.'))
			{
				lead_preferred_date.focus();
				return false;
			}
			
			if(!IsEmpty(lead_name, 'Please, enter First Name.'))
			{
				lead_name.focus();
				return false;
			}
			
			if(!IsEmpty(lead_email, 'Please, enter email address.'))
			{
				lead_email.focus();
				return false;
			}
			else if(!IsEmail(lead_email, 'Please, enter valid email address.'))
			{
				lead_email.focus();
				return false;
			}
		}
		// Make the server call
		xajax_scheduleShowing('', Action, xajax.getFormValues('frmSchedule'));
	}
	else
	{
		popupWin('', '', 550, 300);

		// Make the server call
		xajax_scheduleShowing(ListingID_RETS, Action, '');
	}
}
//====================================================================================================
//	Function Name	:	EmailFriend_Click()
//----------------------------------------------------------------------------------------------------
function EmailFriend_Click(ListingID_RETS, FullUrl, Action)
{
	if (Action=='Send')
	{
		frm = document.getElementById('frmEmailFriend')
		with(frm)
		{
			if(!IsEmpty(subject, 'Please, enter subject.'))
			{
				subject.focus();
				return false;
			}
			
			if(!IsEmpty(your_name, 'Please, enter Your Name.'))
			{
				your_name.focus();
				return false;
			}
			
			if(!IsEmpty(your_email, 'Please, enter Your email address.'))
			{
				your_email.focus();
				return false;
			}
			else if(!IsEmail(your_email, 'Please, enter valid email address.'))
			{
				your_email.focus();
				return false;
			}
			
			if(!IsEmpty(friend_name, 'Please, enter Friend Name.'))
			{
				friend_name.focus();
				return false;
			}
			
			if(!IsEmpty(friend_email, 'Please, enter Friend email address.'))
			{
				friend_email.focus();
				return false;
			}
			else if(!IsEmail(friend_email, 'Please, enter valid email address.'))
			{
				friend_email.focus();
				return false;
			}
		}
		// Show loader
		ToggleLoader(true);

		// Make the server call
		xajax_emailToFriend(ListingID_RETS, '', Action, xajax.getFormValues('frmEmailFriend'));
	}
	else
	{
		// Show loader
		ToggleLoader(true);
		
		popupWin('', '', 500, 170);

		// Make the server call
		xajax_emailToFriend(ListingID_RETS, FullUrl, Action, '');
	}
}
//====================================================================================================
//	Function Name	:	SendInquiry_Click()
//----------------------------------------------------------------------------------------------------
function SendInquiry_Click(ListingID_RETS, Action)
{
	// Show loader
	ToggleLoader(true);

	if (Action=='Send')
	{
		frm = document.getElementById('frmInquiry')
		with(frm)
		{
			if(!IsEmpty(lead_name, 'Please, enter First Name.'))
			{
				lead_name.focus();
				return false;
			}
			
			if(!IsEmpty(lead_email, 'Please, enter email address.'))
			{
				lead_email.focus();
				return false;
			}
			else if(!IsEmail(lead_email, 'Please, enter valid email address.'))
			{
				lead_email.focus();
				return false;
			}
		}
		// Make the server call
		xajax_sendInquiry('', Action, xajax.getFormValues('frmInquiry'));
	}
	else
	{
		popupWin('', '', 350, 250);

		// Make the server call
		xajax_sendInquiry(ListingID_RETS, Action, '');
	}
}
//====================================================================================================
//	Function Name	:	PetsMoreInfo_Click()
//----------------------------------------------------------------------------------------------------
function PetsMoreInfo_Click(Action, ListingID_RETS)
{
	// Show loader
	ToggleLoader(true);

	if (Action=='Send')
	{
		frm = document.getElementById('frmPets')
		with(frm)
		{
			if(!IsEmpty(lead_name, 'Please, enter First Name.'))
			{
				lead_name.focus();
				return false;
			}
			
			if(!IsEmpty(lead_email, 'Please, enter email address.'))
			{
				lead_email.focus();
				return false;
			}
			else if(!IsEmail(lead_email, 'Please, enter valid email address.'))
			{
				lead_email.focus();
				return false;
			}
		}
		// Make the server call
		xajax_sendPetsMoreInfo(Action, xajax.getFormValues('frmPets'));
	}
	else
	{
		popupWin('', '', 350, 250);

		// Make the server call
		xajax_sendPetsMoreInfo(Action, {ListingID_RETS: ListingID_RETS});
	}
}
//====================================================================================================
//	Function Name	:	CourtesyAgent_Click()
//----------------------------------------------------------------------------------------------------
function CourtesyAgent_Click(Action, listingca_id, ListingID_RETS, Agent_ID)
{
	// Show loader
	ToggleLoader(true);

	if (Action=='Edit')
	{
		popupWin('', '', 350, 250);

		// Make the server call
		xajax_CourtesyAgentInfo('Edit', {listingca_id: listingca_id});
	}
	else if (Action=='Add')
	{
		popupWin('', '', 350, 250);

		// Make the server call
		xajax_CourtesyAgentInfo('Add', {ListingID_RETS: ListingID_RETS, Agent_ID: Agent_ID});
	}
	else if ((Action=='Update') || (Action=='Save'))
	{
		frm = document.getElementById('frmCourtesyAgent')
		with(frm)
		{
			if(!IsEmpty(listingca_firstname, 'Please, enter First Name.'))
			{
				listingca_firstname.focus();
				return false;
			}
			
			//if(!IsEmpty(listingca_lastname, 'Please, enter Last Name.'))
			//{
			//	listingca_lastname.focus();
			//	return false;
			//}

			if(!IsEmpty(listingca_email, 'Please, enter email address.'))
			{
				listingca_email.focus();
				return false;
			}
			else if(!IsEmail(listingca_email, 'Please, enter valid email address.'))
			{
				listingca_email.focus();
				return false;
			}
			
			//if(!IsEmpty(listingca_designation, 'Please, enter designation.'))
			//{
			//	listingca_designation.focus();
			//	return false;
			//}
		}
		
		if (Action=='Save')
		{
			if ( document.getElementById("listingca_affirm").checked == false )
			{
				alert("Please Affirm that you are the agent of Listing");	
				return false;
			}
		}
			
		// Make the server call
		xajax_CourtesyAgentInfo(Action, xajax.getFormValues('frmCourtesyAgent'));
	}
}
//----------------------------------------Searches Function------------------------------------------------------
//====================================================================================================
//	Function Name	:	RunSearch_Click()
//----------------------------------------------------------------------------------------------------
function RunSearch_Click(searchId)
{
	document.getElementById('search_id').value = searchId;
	document.getElementById('Action').value = 'RunSearch';
	document.getElementById('frmSavedSearch').submit();
}
//====================================================================================================
//	Function Name	:	EditSearch_Click()
//----------------------------------------------------------------------------------------------------
function EditSearch_Click(searchId)
{
	document.getElementById('search_id').value = searchId;
	document.getElementById('Action').value = 'EditSearch';
	document.getElementById('frmSavedSearch').submit();
}
//====================================================================================================
//	Function Name	:	DeleteSearch_Click()
//----------------------------------------------------------------------------------------------------
function DeleteSearch_Click(searchId)
{
	if (confirm("Are you sure you want to delete search information?"))
	{
		document.getElementById('search_id').value = searchId;
		document.getElementById('Action').value = 'DeleteSearch';
		document.getElementById('frmSavedSearch').submit();
	}
}
//====================================================================================================
//	Function Name	:	updateEmailInfo_Click()
//----------------------------------------------------------------------------------------------------
function updateEmailInfo_Click(searchId)
{
	document.getElementById('search_id').value = searchId;
	document.getElementById('Action').value = 'UpdateEmailInfo';
	document.getElementById('frmSavedSearch').submit();
}
