  // JavaScript Document
/****************************************************************************************************************/
function validateSubmitTrulli()
{
 if(document.Trullifrm.Personname.value=='' || !trim(document.Trullifrm.Personname.value) || !checkName(document.Trullifrm.Personname.value))
 {
     alert('Please enter valid name');
	 document.Trullifrm.Personname.focus();
	 return false;
 }
 
 if(document.Trullifrm.email.value=='' || !trim(document.Trullifrm.email.value) || !echeck(document.Trullifrm.email.value))
 {
     alert('Please enter valid email');
	 document.Trullifrm.email.focus();
	 return false;	 
 }
 
 if(document.Trullifrm.photo1.value!='' && trim(document.Trullifrm.photo1.value))
 {
    var img1Val=document.Trullifrm.photo1.value;
    var checkImageExt=img1Val.split(".");
	var length=checkImageExt.length;
	if(checkImageExt[length-1]!='jpg' && checkImageExt[length-1]!='JPG' )
	{
	  alert('Please submit images in Jpeg (.jpg) format');
	  document.Trullifrm.photo1.focus();
	  return false;	  
	}  
 }

if(document.Trullifrm.photo2.value!='' && trim(document.Trullifrm.photo2.value))
 {
    var img1Val=document.Trullifrm.photo2.value;
    var checkImageExt=img1Val.split(".");
	var length=checkImageExt.length;
	if(checkImageExt[length-1]!='jpg' && checkImageExt[length-1]!='JPG' )
	{
	  alert('Please submit images in Jpeg (.jpg) format');
	  document.Trullifrm.photo2.focus();
	  return false;	  
	}  
 } 
 
 if(document.Trullifrm.photo3.value!='' && trim(document.Trullifrm.photo3.value))
 {
    var img1Val=document.Trullifrm.photo3.value;
    var checkImageExt=img1Val.split(".");
	var length=checkImageExt.length;	
	if(checkImageExt[length-1]!='jpg' && checkImageExt[length-1]!='JPG' )
	{
	  alert('Please submit images in Jpeg (.jpg) format');
	  document.Trullifrm.photo3.focus();
	  return false;	  
	}  
 }
 
 if(document.Trullifrm.photo4.value!='' && trim(document.Trullifrm.photo4.value))
 {
    var img1Val=document.Trullifrm.photo4.value;
    var checkImageExt=img1Val.split(".");
	var length=checkImageExt.length;
	if(checkImageExt[length-1]!='jpg' && checkImageExt[length-1]!='JPG' )
	{
	  alert('Please submit images in Jpeg (.jpg) format');
	  document.Trullifrm.photo4.focus();
	  return false;	  
	}  
 }
 
   if(document.Trullifrm.address1.value!='' && (!trim(document.Trullifrm.address1.value) || !isValidPropertyAddress(document.Trullifrm.address1.value)))
   {
     alert('Kindly enter valid property address');
     document.Trullifrm.address1.focus();
     return false;
   } 
  
   if(document.Trullifrm.address2.value!='' && (!trim(document.Trullifrm.address2.value) || !isValidPropertyAddress(document.Trullifrm.address2.value)))
   {
     alert('Kindly enter valid property address');
     document.Trullifrm.address2.focus();
     return false;
   } 

   if( document.Trullifrm.town.value!='' && (!trim(document.Trullifrm.town.value) || !isValidPropertyAddress(document.Trullifrm.town.value)))
   {
     alert('Kindly enter valid town/city value');
     document.Trullifrm.town.focus();
     return false;
   } 

   if( document.Trullifrm.district.value!='' && (!trim(document.Trullifrm.district.value) || !isValidPropertyAddress(document.Trullifrm.district.value)))
   {
     alert('Kindly enter valid district/region value');
     document.Trullifrm.district.focus();
     return false;
   } 

   if( document.Trullifrm.telephone.value!='' && (!trim(document.Trullifrm.telephone.value) || !isValidContactNumber(document.Trullifrm.telephone.value)))
   {
     alert('Kindly enter valid telephone value');
     document.Trullifrm.telephone.focus();
     return false;f
   } 
   
   if( document.Trullifrm.rentalprice.value!='' && (!trim(document.Trullifrm.rentalprice.value) || !checkPrice(document.Trullifrm.rentalprice.value)))
   {
     alert('Kindly enter valid rental price');
     document.Trullifrm.rentalprice.focus();
     return false;
   } 

   if( document.Trullifrm.saleprice.value!='' && (!trim(document.Trullifrm.saleprice.value) || !checkPrice(document.Trullifrm.saleprice.value)))
   {
     alert('Kindly enter valid sale price');
     document.Trullifrm.saleprice.focus();
     return false;
   } 

   if( document.Trullifrm.location.value!='' && (!trim(document.Trullifrm.location.value) || !isValidPropertyLocation(document.Trullifrm.location.value)))
   {
     alert('Kindly enter valid location for the property');
     document.Trullifrm.location.focus();
     return false;
   } 
   if( document.Trullifrm.landarea.value!='' && (!trim(document.Trullifrm.landarea.value) || !isValidPropertyArea(document.Trullifrm.landarea.value)))
   {
     alert('Kindly enter valid landarea for the property');
     document.Trullifrm.landarea.focus();
     return false;
   }
   if( document.Trullifrm.floorarea.value!='' && (!trim(document.Trullifrm.floorarea.value) || !isValidPropertyArea(document.Trullifrm.floorarea.value)))
   {
     alert('Kindly enter valid floorarea for the property');
     document.Trullifrm.floorarea.focus();
     return false;
   }   
 document.Trullifrm.add.value='submitTrulli'; 
 document.Trullifrm.submit();
}

/****************************************************************************************************************/
function validateLogin()
{
   if(document.Loginfrm.username.value=='' || !trim(document.Loginfrm.username.value))
   {
      alert('Please enter the username.');
      document.Loginfrm.username.focus();
      return false;
   }

   if(document.Loginfrm.passwd.value=='' || !trim(document.Loginfrm.passwd.value))
   {
      alert('Please enter the password.');
      document.Loginfrm.passwd.focus();
      return false;      
   }
	
   document.Loginfrm.flag.value='validateLogin';
   document.Loginfrm.submit();
}

/****************************************************************************************************************/
function validatePoundValue()
{
   if(document.Poundfrm.poundVal.value=='' || !trim(document.Poundfrm.poundVal.value))
   {
      alert('Please enter the value of pound against euro.');
      document.Poundfrm.poundVal.focus();
      return false;      
   }

   if(!checkPrice(document.Poundfrm.poundVal.value))
   {
      alert('Please enter valid value for pound against euro.');
      document.Poundfrm.poundVal.focus();
      return false;      
   }

   document.Poundfrm.flag.value='validatePoundval';
   document.Poundfrm.submit();
}


/****************************************************************************************************************/
function validateProperty(propertyType,propertyID)
{

   if(document.Propertyfrm.title.value=='')
   {
     alert('Kindly enter the property title');
     document.Propertyfrm.title.focus();
     return false;
   }
   if(!trim(document.Propertyfrm.title.value) || !isValidPropertyPageTitle(document.Propertyfrm.title.value))
   {
     alert('Kindly enter valid property title');
     document.Propertyfrm.title.focus();
     return false;
   }

   if(document.Propertyfrm.URL.value=='')
   {
     alert('Kindly enter the web page name');
     document.Propertyfrm.URL.focus();
     return false;
   }
   if(!trim(document.Propertyfrm.URL.value) || !isValidPropertyPageName(document.Propertyfrm.URL.value))
   {
     alert('Kindly enter valid web page name');
     document.Propertyfrm.URL.focus();
     return false;
   }
   
   if(document.Propertyfrm.keywords.value!=''  && !trim(document.Propertyfrm.keywords.value))
   {
     alert('Kindly enter valid property keywords');
     document.Propertyfrm.keywords.focus();
     return false;
   }   

   if(document.Propertyfrm.keywords.value!=''  && !isValidPropertyPageKeywords(document.Propertyfrm.keywords.value))
   {
     alert('Kindly enter valid property keywords');
     document.Propertyfrm.keywords.focus();
     return false;
   }   
   if(document.Propertyfrm.location.value=='')
   {
     alert('Kindly enter the property location');
     document.Propertyfrm.location.focus();
     return false;
   }
   if(!trim(document.Propertyfrm.location.value) || !isValidPropertyLocation(document.Propertyfrm.location.value))
   {
     alert('Kindly enter valid property location');
     document.Propertyfrm.location.focus();
     return false;
   }
  if(document.Propertyfrm.price.value=='')
   {
     alert('Kindly enter the property price');
     document.Propertyfrm.price.focus();
     return false;
   }
   if(!trim(document.Propertyfrm.price.value) || !checkPrice(document.Propertyfrm.price.value))
   {
     alert('Kindly enter valid property price');
     document.Propertyfrm.price.focus();
     return false;
   }   
   if(document.Propertyfrm.landarea.value!=''  && (!trim(document.Propertyfrm.landarea.value) || !isValidPropertyArea(document.Propertyfrm.landarea.value)))
   {
     alert('Kindly enter valid amount of land/garden');
     document.Propertyfrm.landarea.focus();
     return false;
   }      
   if(document.Propertyfrm.floorarea.value!=''  && (!trim(document.Propertyfrm.floorarea.value) || !isValidPropertyArea(document.Propertyfrm.floorarea.value)))
   {
     alert('Kindly enter valid property total floor area');
     document.Propertyfrm.floorarea.focus();
     return false;
   }   
   if(document.Propertyfrm.extensionarea.value!=''  && (!trim(document.Propertyfrm.extensionarea.value) || !isValidPropertyArea(document.Propertyfrm.extensionarea.value)))
   {
     alert('Kindly enter valid property size of extension');
     document.Propertyfrm.extensionarea.focus();
     return false;
   }            
   document.Propertyfrm.flag.value='addNewProperty';
   document.Propertyfrm.propertyToDisplay.value=propertyType;   
   document.Propertyfrm.propertyID.value=propertyID;      
   document.Propertyfrm.submit();
}

/****************************************************************************************************************/
function changePropertyDisplay(type)
{
   if(type=='')
      document.AdminListingfrm.propertyType.value='R';
   else
   if(type=='R')
      document.AdminListingfrm.propertyType.value='S';
   else   
      document.AdminListingfrm.propertyType.value='R';   

      document.AdminListingfrm.limit.value=0;      
      document.AdminListingfrm.submit();
}

/****************************************************************************************************************/
function pagination(limit)
{
  document.AdminListingfrm.limit.value=parseInt(limit);
  document.AdminListingfrm.submit();
}

/****************************************************************************************************************/
function addNewProperty(flag)
{
  document.AdminListingfrm.propertyToDisplay.value=flag;
  document.AdminListingfrm.action="addProperty.php";
  document.AdminListingfrm.submit();
}


/****************************************************************************************************************/
function editProperty(propertyID,flag)
{
  document.AdminListingfrm.propertyToDisplay.value=flag;
  document.AdminListingfrm.propertyID.value=propertyID;  
  document.AdminListingfrm.flag.value='addNewProperty';  
  document.AdminListingfrm.action="addProperty.php";
  document.AdminListingfrm.submit();
}


function setImageVal(imageVal)
{
  if(imageVal==1)
  document.Propertyfrm.image1.value=document.Propertyfrm.photo1.value;
  
  if(imageVal==2)
  document.Propertyfrm.image2.value=document.Propertyfrm.photo2.value;

  if(imageVal==3)
  document.Propertyfrm.image3.value=document.Propertyfrm.photo3.value;

  if(imageVal==4)
  document.Propertyfrm.image4.value=document.Propertyfrm.photo4.value;
  
}

function removeImage(imageVal)
{
    if(confirm('Are you sure to delete the image?'))
	{
    if(imageVal==1)
    {
      document.getElementById('img1').style.display='none';
      document.Propertyfrm.image1.value='';
    }  
     
     if(imageVal==2)
     {     
           document.getElementById('img2').style.display='none';
           document.Propertyfrm.image2.value='';           
     }      
   
     if(imageVal==3)
     {
           document.getElementById('img3').style.display='none';
           document.Propertyfrm.image3.value='';           
     }      
   
     if(imageVal==4)
     {
           document.getElementById('img4').style.display='none';
           document.Propertyfrm.image4.value='';           
     }  
	 }    
}

function deleteProperty(propertyID, propertyType)
{
  if(confirm('Are you sure to delete the record?'))
  {
	  document.AdminListingfrm.propertyToDisplay.value=propertyType;
	  document.AdminListingfrm.propertyID.value=propertyID;  
	  document.AdminListingfrm.flag.value='delete';  
	  document.AdminListingfrm.action="saveDataRequest.php";
	  document.AdminListingfrm.submit();  
  }	  
}


function updatePropertyOnlineStatus(limit)
{
	  document.AdminListingfrm.flag.value='changeStatus';  
	  document.AdminListingfrm.action="saveDataRequest.php";
	  document.AdminListingfrm.submit();     
}

function changeSaleViewPerPage(recsPerPage)
{
    document.saleListingfrm.SalePerPage.value=recsPerPage;
    document.saleListingfrm.SalePagewise.value='';    
    document.saleListingfrm.submit();
}

function PropertyPagination($nextCnt)
{
    document.saleListingfrm.SalePagewise.value=$nextCnt;    
    document.saleListingfrm.submit();  
}

function PropertyRentPagination($nextCnt)
{
    document.rentListingfrm.RentPagewise.value=$nextCnt;    
    document.rentListingfrm.submit();  
}

/****************************************************************************************************************/

function validateEnquiry()
{   
   if(document.TrulloEnquiryFrm.FName.value=='')
   {
      alert('Please enter your name');
	  document.TrulloEnquiryFrm.FName.focus();
	  return false;
   }
   if(!trim(document.TrulloEnquiryFrm.FName.value) || !checkName(document.TrulloEnquiryFrm.FName.value))
   {
      alert('Please enter valid name');
	  document.TrulloEnquiryFrm.FName.focus();
	  return false;
   }
if(document.TrulloEnquiryFrm.Email.value=='')
   {
      alert('Please enter your email address');
	  document.TrulloEnquiryFrm.Email.focus();
	  return false;
   }
   if(!trim(document.TrulloEnquiryFrm.Email.value) || !echeck(document.TrulloEnquiryFrm.Email.value))
   {
      alert('Please enter your valid email address');
	  document.TrulloEnquiryFrm.Email.focus();
	  return false;
   }      

if(document.TrulloEnquiryFrm.telstd.value=='select')
   {
      alert('Please enter your international telephone code');
	  document.TrulloEnquiryFrm.telstd.focus();
	  return false;
   }

if(document.TrulloEnquiryFrm.telephone.value=='')
   {
      alert('Please enter your telephone number');
	  document.TrulloEnquiryFrm.telephone.focus();
	  return false;
   }   
   if(!trim(document.TrulloEnquiryFrm.telephone.value) || !isValidContactNumber(document.TrulloEnquiryFrm.telephone.value))
   {
      alert('Please enter your valid telephone number');
	  document.TrulloEnquiryFrm.telephone.focus();
	  return false;
   }      
   
   document.TrulloEnquiryFrm.submit();
}


function previewMessage()
{
   if(document.FriendFrm.UName.value=='')
   {
      alert('Please enter your name');
	  document.FriendFrm.UName.focus();
	  return false;
   }
   if(!trim(document.FriendFrm.UName.value) || !checkName(document.FriendFrm.UName.value))
   {
      alert('Please enter valid name');
	  document.FriendFrm.UName.focus();
	  return false;
   }  

 if(document.FriendFrm.UEmail.value=='')
   {
      alert('Please enter your email address');
	  document.FriendFrm.UEmail.focus();
	  return false;
   }
   if(!trim(document.FriendFrm.UEmail.value) || !echeck(document.FriendFrm.UEmail.value))
   {
      alert('Please enter your valid email address');
	  document.FriendFrm.UEmail.focus();
	  return false;
   }   
   
  if(document.FriendFrm.FriendName.value=='')
   {
      alert('Please enter your friends name');
	  document.FriendFrm.FriendName.focus();
	  return false;
   }
   if(!trim(document.FriendFrm.FriendName.value) || !checkName(document.FriendFrm.FriendName.value))
   {
      alert('Please enter valid friends name');
	  document.FriendFrm.UName.focus();
	  return false;
   }   

 if(document.FriendFrm.FriendEmail.value=='')
   {
      alert('Please enter your freinds email address');
	  document.FriendFrm.FriendEmail.focus();
	  return false;
   }
   if(!trim(document.FriendFrm.FriendEmail.value) || !echeck(document.FriendFrm.FriendEmail.value))
   {
      alert('Please enter valid friends email address');
	  document.FriendFrm.FriendEmail.focus();
	  return false;
   }   

   document.FriendFrm.action="previewMessage.php";
   document.FriendFrm.submit();  
}

function validateToFriend()
{
   if(document.FriendFrm.UName.value=='')
   {
      alert('Please enter your name');
	  document.FriendFrm.UName.focus();
	  return false;
   }
   if(!trim(document.FriendFrm.UName.value) || !checkName(document.FriendFrm.UName.value))
   {
      alert('Please enter valid name');
	  document.FriendFrm.UName.focus();
	  return false;
   }

 if(document.FriendFrm.UEmail.value=='')
   {
      alert('Please enter your email address');
	  document.FriendFrm.UEmail.focus();
	  return false;
   }
   if(!trim(document.FriendFrm.UEmail.value) || !echeck(document.FriendFrm.UEmail.value))
   {
      alert('Please enter your valid email address');
	  document.FriendFrm.UEmail.focus();
	  return false;
   }   
   
  if(document.FriendFrm.FriendName.value=='')
   {
      alert('Please enter your friends name');
	  document.FriendFrm.FriendName.focus();
	  return false;
   }
   if(!trim(document.FriendFrm.FriendName.value) || !checkName(document.FriendFrm.FriendName.value))
   {
      alert('Please enter valid friends name');
	  document.FriendFrm.UName.focus();
	  return false;
   }   

 if(document.FriendFrm.FriendEmail.value=='')
   {
      alert('Please enter your freinds email address');
	  document.FriendFrm.FriendEmail.focus();
	  return false;
   }
   if(!trim(document.FriendFrm.FriendEmail.value) || !echeck(document.FriendFrm.FriendEmail.value))
   {
      alert('Please enter valid friends email address');
	  document.FriendFrm.FriendEmail.focus();
	  return false;
   }   
   document.FriendFrm.action="sendFriendEmail.php";
   document.FriendFrm.submit();  
}
function backToAdminListing()
{
   document.Poundfrm.action="admin-listing.php";
   document.Poundfrm.submit();   
}

function sendToFriend(propertyType)
{  
  document.TrulloEnquiryFrm.action="../sendToFriend.php";
  document.TrulloEnquiryFrm.submit();
}

function submitToOptions()
{
  document.AdminListingfrm.action="options.php";
  document.AdminListingfrm.submit();  
}

function backToAdminListingfrmAdd()
{
  document.Propertyfrm.action="admin-listing.php";
  document.Propertyfrm.submit();  
}

