// JavaScript Document
function displaydiv(id)
{
	document.getElementById(id).style.display='block';
	
}

function hidediv(id)
{
	document.getElementById(id).style.display='none';

}
//focusing of the textbox if available 
if(document.getElementById('frm_fin_max'))
{
	document.getElementById('frm_fin_max').txt_fullname.focus();
}
else if(document.getElementById('frm_contact_us'))
{
	document.getElementById('frm_contact_us').txt_name.focus();
}
/*else if(document.getElementById('txt_main_name'))
{
	document.getElementById('txt_main_name').focus();
}*/



var ajax = new sack();
function submitContact(url)
{
	pid = document.getElementById('txt_main_phone').value;
	name =  document.getElementById('txt_main_name').value;
	if(name == 'Your Name')
	{
	document.getElementById('txt_main_name').focus();
	alert('Please enter Contact Name'); 
	return false;
	}
	if(pid == 'Your Number')
	{
	document.getElementById('txt_main_phone').focus();
	alert('Please enter Contact Number'); 
	return false;
	}
	if(isNaN(pid))
	{ 
	document.getElementById('txt_main_phone').focus();
	alert('Please enter digits only'); 
	return false;
	}
	else if (pid!=0)
	{
		ajax.requestFile = url+'controllers/ajax/ajax.php?num='+pid+'&name='+name;
		ajax.onCompletion = dispInfo;
		ajax.runAJAX();	
	}
}
function dispInfo()
{
	eval(ajax.response);
}

	function ValidateContact()
	{
			var frm = document.getElementById('frm_contact_us');
		
			if(namevalidation(frm.txt_name,"your Name.","","") =='')
			{
			return false;
			}
			else if(phoneNo(frm.txt_contact_no,"your Contact Number.","","") =='')
			{
			return false;
			}
			else if(EmailValidation(frm.txt_email) == 0)
			{
			return false;
			}
			
			else if(frm.txt_enquiry.value =='')
			{
				alert('Please enter your Enquiry.');
				frm.txt_enquiry.focus();
				return false;
			}
			document.getElementById('hid_sub').value = 1;
	}
	
	
	function ValidateFM()
	{
		var frm = document.getElementById('frm_fin_max');

	if(namevalidation(frm.txt_fullname,"your Full Name.","","") =='')
	{
	return false;
	}
	else if(postCode(frm.txt_postcode,"your Post Code.","","") =='')
	{
	return false;
	}
	else if(phoneNo(frm.txt_contact_no,"your Telephone Number.","","") =='')
	{
	return false;
	}
	else if(EmailValidation(frm.txt_email) == 0)
 	{
 	return false;
 	}
	
    else if(frm.txt_rel_plan.value =='')
	{
        alert('Please enter your Relevant Planning Information.');
        frm.txt_rel_plan.focus();
        return false;
    }
	  else if(frm.txt_address.value =='')
	{
        alert('Please enter your Address.');
        frm.txt_address.focus();
        return false;
    }
	  else if(frm.txt_appraisal_prop_address.value =='')
	{
        alert('Please enter your Appraisal Property Address.');
        frm.txt_appraisal_prop_address.focus();
        return false;
    }
	  else if(frm.txt_property_potential.value =='')
	{
        alert('Please enter your Overview of Property Potential.');
        frm.txt_property_potential.focus();
        return false;
    }
	document.getElementById('hid_sub').value = 1;
	}


function phoneNo(Val,charr)
	{
		if(Val.value=='')
		{
			alert('Please enter  '+charr);
			Val.focus();
			return false;
		}
		var alp = "0123456789";
		for (var i=0;i<Val.value.length;i++)
		{
			temp=Val.value.substring(i,i+1);
			if (alp.indexOf(temp)==-1)
			{
				alert("No alphabets/ special characters/ spaces in "+charr+" \nValid entries are [0-9]");
				Val.focus();
				return 0;
			}
		}
	}
	
	function postCode(Val,charr)
	{
		if(Val.value=='')
		{
			alert('Please enter  '+charr);
			Val.focus();
			return false;
		}
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		for (var i=0;i<Val.value.length;i++)
		{
			temp=Val.value.substring(i,i+1);
			if (alp.indexOf(temp)==-1)
			{
				alert("No special characters/ spaces in "+charr+" \nValid entries are [0-9][a-z][A-Z]");
				Val.focus();
				return 0;
			}
		}
	}

function namevalidation(Val,charr)
	{
		if(Val.value=='')
		{
			alert('Please enter '+charr);
			Val.focus();
			return false;
		}
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
		for (var i=0;i<Val.value.length;i++)
		{
			temp=Val.value.substring(i,i+1);
			if (alp.indexOf(temp)==-1)
			{
				alert("No special characters/ numbers in "+charr+" \nValid entries are [a-z][A-Z][space]");
				Val.focus();
				return 0;
			}
		}
	}

function EmailValidation(Element)
{

	  if(Element.value=='')
	  {
	     alert("Email field should not be empty");
         Element.focus();
		 return false;
	  }
	  else
	  {
		Flag  = 1;
		count = 0;
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.-";
		if(Element.value.length > 0)
		{
			for (var i=0; i<Element.value.length; i++)
			{
				temp = Element.value.substring(i, i+1);

				if (alp.indexOf(temp) == -1)
				{
					Flag = 0;
				}
			}
		}
		else
		{
			Flag = 0;
		}

		for(var i=0; i <= Element.value.length; i++)
		{
			if(Element.value.charAt(0)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(Element.value.length-1)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(i)=='@')
			{
				count = count + 1;

				if(count>1)
				{
					Flag = 0;
					break;
				}

				if((Element.value.charAt(i-1)=='.') || (Element.value.charAt(i+1)=='.'))
				{
					Flag = 0;
					break;
				}
			}
			if(Element.value.indexOf('@')==-1)
			{
				Flag = 0;
				break;
			}
			if(Element.value.charAt(0)=='.')
			{
				Flag = 0;
				break;
			}
			if(Element.value.indexOf('.')==-1)
			{
				Flag = 0;
				break;
			}
	  }

		if(Element.value.charAt(Element.value.length-1) == '.')
			Flag = 0;

		if(Flag != 1)
		{
			alert("Please enter a valid Email ID.");
			Element.focus();
			return 0;
		}
		else
			return 1;
	  }
}





function displaymenu(val)
{
	document.getElementById('link'+val).style.display='block';
	document.getElementById('menu'+val).className='activate';	
}

function hidemenu(val)
{
	document.getElementById('link'+val).style.display='none';
	document.getElementById('menu'+val).className='link-bar';
}
