// *** script for contact entries ***
function validcontact()
  {
    if (trim(document.frmcontact.txtname.value)=="")
	{
	 alert("Please Enter Name...");
	 document.frmcontact.txtname.value="";
	 document.frmcontact.txtname.focus();
	 return false;
	}
    else if (trim(document.frmcontact.txtemail.value)=="")
	{
	 alert("Please Enter Email...");
	 document.frmcontact.txtemail.value="";
	 document.frmcontact.txtemail.focus();
	 return false;
	}
	else if (echeck(trim(document.frmcontact.txtemail.value))==false)
	{
	 document.frmcontact.txtemail.value="";
	 document.frmcontact.txtemail.focus();
	 return false;
	}
	else
	{
	 document.frmcontact.submit();
	 return true;
	}
  }
  
  
// *** script for complex entries ***
function validcomplex()
  {
    if (trim(document.frmcomplex.txtCplxTitle.value)=="")
	{
	 alert("Please Enter Title...");
	 document.frmcomplex.txtCplxTitle.value="";
	 document.frmcomplex.txtCplxTitle.focus();
	 return false;
	}
    else if (trim(document.frmcomplex.txtCplxAddr.value)=="")
	{
	 alert("Please Enter Address...");
	 document.frmcomplex.txtCplxAddr.value="";
	 document.frmcomplex.txtCplxAddr.focus();
	 return false;
	}
	else
	{
	 document.frmcomplex.submit();
	 return true;
	}
  }

// *** script for complex unit image entries ***
function validunitimage()
  {
    if (document.frmcomplex.selCplx.value==0)
	{
	 alert("Please select Apartment...");
	 document.frmcomplex.selCplx.focus();
	 return false;
	}
    else if (document.frmcomplex.selUnit.value==0)
	{
	 alert("Please select Unit...");
	 document.frmcomplex.selUnit.focus();
	 return false;
	}
    else if (trim(document.frmcomplex.file.value)=="")
	{
	 alert("Please select Image to upload...");
	 document.frmcomplex.file.focus();
	 return false;
	}
	else
	{
	 document.frmcomplex.submit();
	 return true;
	}
  }

// *** script for application entries ***
function validapplication()
{
	if (trim(document.frmappl.txtAppType.value)=="")
	{
	 alert("Please Enter Type...");
	 document.frmappl.txtAppType.value="";
	 document.frmappl.txtAppType.focus();
	 return false;
	}
	else if (trim(document.frmappl.txtAppFullName.value)=="")
	{
	 alert("Please Enter Full Name...");
	 document.frmappl.txtAppFullName.value="";
	 document.frmappl.txtAppFullName.focus();
	 return false;
	}
	else if (document.frmappl.chkaccept.checked==false)
	{
	 alert("Please Read and Accept Our Terms...");
	 return false;
	}
	else
	{
	 document.frmappl.submit();
	 return true;
	}
  }

//conformation before delete complex unit image details
function ndeleterequest(id)
{
var chk
chk = confirm("Are you sure to delete?");
if(chk==true)
{
window.location="unitimage.php?dId="+id;
}
else
{
return false;
}
}

//conformation before delete complex details
function deleterequest(id)
{
var chk
chk = confirm("Are you sure to delete?");
if(chk==true)
{
window.location="appartment.php?dId="+id;
}
else
{
return false;
}
}

//conformation before delete application details
function deleterequest1(id)
{
var chk
chk = confirm("Are you sure to delete?");
if(chk==true)
{
window.location="applications.php?dId="+id;
}
else
{
return false;
}
}
  
// *** Numeric validation ***
   function isNumericKey(e)
	{
	var k = document.all ? e.keyCode : e.which;
	return ((k > 47 && k < 58) || k == 8 || k == 0);
	}

// *** Email validation ***
	function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || 
str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || 
str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || 
str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

//check uploaded image is .jpg format
 function checkimagetype(ext) {
  if(!ext) return true;
  ext = ext.substring(ext.length-3,ext.length);
  ext = ext.toLowerCase();
  if((ext != 'jpg') && (ext != 'peg')) {
  alert("Please select a .jpg, or .jpeg file only");
  document.frmcomplex.file.focus();
    return false; }
  else
    return true;
}


//trim blankspace validation
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

