// ActionScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// JavaScript Document

function show_hide_imgs(v)
{
	if(v == '_')
		document.getElementById('tr_container').style.display = 'none';
	else
	{
		for(var i = 1 ; i < 6 ; i++)
			document.getElementById('tr_images_'+i).style.display = 'none';
		
		document.getElementById('tr_container').style.display = '';
		
		for(var i = 1 ; i <= v ; i++)
			document.getElementById('tr_images_'+i).style.display = '';		
	}
}

function validate_location(frm)
{
	if($F('location_category') == '_')
	{
		alert('Please select Location Category.');
		$('location_category').focus();
		return false;
	}
	if($F('town_id') == '_')
	{
		alert('Please select Town for this Location.');
		$('town_id').focus();
		return false;
	}
	if($F('type_id') == '_')
	{
		alert('Please select Location / Building Type.');
		$('type_id').focus();
		return false;
	}
	if($F('location_title') == '')
	{
		alert('"Location Title" is a required field.');
		$('location_title').focus();
		return false;
	}
	if($F('total_sqft') == '')
	{
		alert('"Square Footage" is a required field.');
		$('total_sqft').focus();
		return false;
	}
	if(isNaN($F('total_sqft')))
	{
		alert('Square Footage should be Numeric Value.');
		$('total_sqft').focus();
		return false;
	}
	if($F('width_sqft') != '')
	{
		if(isNaN($F('width_sqft')))
		{
			alert('Width Square Footage should be Numeric Value.');
			$('width_sqft').focus();
			return false;
		}	
	}
	if($F('depth_sqft') != '')
	{
		if(isNaN($F('depth_sqft')))
		{
			alert('Depth Square Footage should be Numeric Value.');
			$('depth_sqft').focus();
			return false;
		}	
	}
	if($F('bedrooms') == '_')
	{
		alert('Please select Number of Bed Rooms for this Location.');
		$('bedrooms').focus();
		return false;
	}
	if($F('master_bedroom') == '_')
	{
		alert('Please select Master Bed Room Type for this Location.');
		$('master_bedroom').focus();
		return false;
	}
	if($F('bathrooms') == '_')
	{
		alert('Please select Number of Bathrooms for this Location.');
		$('bathrooms').focus();
		return false;
	}
	if($F('floors') == '_')
	{
		alert('Please select Number of Floors for this Location.');
		$('floors').focus();
		return false;
	}
	if($F('porch') == '_')
	{
		alert('Please select Porch Type for this Location.');
		$('porch').focus();
		return false;
	}
	if($F('garage_size') == '_')
	{
		alert('Please select Garage Size for this Location.');
		$('garage_size').focus();
		return false;
	}
	if($F('garage_door_loc') == '_')
	{
		alert('Please select Garage Door Location for this Location.');
		$('garage_door_loc').focus();
		return false;
	}
	if($F('current_status') == '_')
	{
		alert('Please select Current Status for this Location.');
		$('current_status').focus();
		return false;
	}
	if($F('price') == '')
	{
		alert('"Price / Rent" is a required field.');
		$('price').focus();
		return false;
	}
	if(isNaN($F('price')))
	{
		alert('Price / Rent should be Numeric Value.');
		$('price').focus();
		return false;
	}
	if($F('short_intro') == '')
	{
		alert('"Short Introduction" is a required field.');
		$('short_intro').focus();
		return false;
	}
	if($F('full_details') == '')
	{
		alert('"location_details" is a required field.');
		$('full_details').focus();
		return false;
	}
}

function fetch_areas(city_id, w)
{
	var url = '/ajax.php';
	
	if(w == 'f') var div_id = 'td_town';
	else var div_id = 'td_town2';
	
	$(div_id).innerHTML = 'Loading areas, please wait...';
	
	var params = 'pid=2&city_id='+city_id+'&w='+w+'&rnd='+Math.random();
	
	
	var myAjax = new Ajax.Updater(div_id,url, {method: 'get', parameters: params});	
}

function subscribe_me(frm)
{
	if(frm.email.value == '')
	{
		alert('Please enter your e-mail address.');
		frm.email.focus();
		return;
	}
	if(frm.email.value.indexOf('@') == -1 || frm.email.value.indexOf('.') == -1)
	{
		alert('Please enter a valid e-mail address.');
		frm.email.focus();
		return;
	}
	
	Element.show('tr_subscribe');
	
	var url = '/ajax.php';
	
	if(frm.act[0].checked) var subs = 1;
	else var subs = 0;
	
	var params = 'pid=1&email='+frm.email.value+'&action='+subs+'&rnd='+Math.random();
	
	var myAjax = new Ajax.Updater('td_subscribe',url, {method: 'get', parameters: params});	
}

function validate_requests(frm)
{
	if(frm.type_id.value == '_')
	{
		alert('Please select Type of Property.');
		frm.type_id.focus();
		return false;
	}
	if(frm.town_id.value == '_' && frm.other_area.value == '')
	{
		alert('Please select Area Location.');
		frm.town_id.focus();
		return false;
	}
	if(frm.your_name.value == '')
	{
		alert('Please enter your name.');
		frm.your_name.focus();
		return false;
	}
	if(frm.phone.value == '')
	{
		alert('Please enter your phone number.');
		frm.phone.focus();
		return false;
	}
}

function fetch_property(loc_cat)
{
	if(loc_cat == 3 || loc_cat == 1)
	{
		if(loc_cat == 3)	
		{
			$('td_residential').innerHTML = '<table width="129" border="0" cellspacing="0" cellpadding="0"><tr><td width="120" nowrap background="images/btn_enable_bg.jpg">&nbsp;<a href="javascript:;" style="color:#FFFFFF; font-size:10px; text-decoration:none;" onClick="fetch_property(\'1\');">Buying Residential</a></td><td width="14"><img src="images/btn_enable.jpg" width="9" height="22"></td></tr></table>';
			$('td_commercial').innerHTML = '<table width="129" border="0" cellspacing="0" cellpadding="0"><tr><td width="120" nowrap background="images/btn_disable_bg.jpg">&nbsp;<font color="#666666">Buying Commercial</font></td><td width="14"><img src="images/btn_disable.jpg" width="9" height="22"></td></tr></table>';
		}
		else
		{
			$('td_commercial').innerHTML = '<table width="129" border="0" cellspacing="0" cellpadding="0"><tr><td width="120" nowrap background="images/btn_enable_bg.jpg">&nbsp;<a href="javascript:;" style="color:#FFFFFF; font-size:10px; text-decoration:none;" onClick="fetch_property(\'3\');">Buying Commercial</a></td><td width="14"><img src="images/btn_enable.jpg" width="9" height="22"></td></tr></table>';
			$('td_residential').innerHTML = '<table width="129" border="0" cellspacing="0" cellpadding="0"><tr><td width="120" nowrap background="images/btn_disable_bg.jpg">&nbsp;<font color="#666666">Buying Residential</font></td><td width="14"><img src="images/btn_disable.jpg" width="9" height="22"></td></tr></table>';
		}
	}
	else // Renting Property Buttons
	{
		if(loc_cat == 4)	
		{
			$('td_residential').innerHTML = '<table width="129" border="0" cellspacing="0" cellpadding="0"><tr><td width="120" nowrap background="images/btn_enable_bg.jpg">&nbsp;<a href="javascript:;" style="color:#FFFFFF; font-size:10px; text-decoration:none;" onClick="fetch_property(\'2\');">Renting Residential</a></td><td width="14"><img src="images/btn_enable.jpg" width="9" height="22"></td></tr></table>';
			$('td_commercial').innerHTML = '<table width="129" border="0" cellspacing="0" cellpadding="0"><tr><td width="120" nowrap background="images/btn_disable_bg.jpg">&nbsp;<font color="#666666">Renting Commercial</font></td><td width="14"><img src="images/btn_disable.jpg" width="9" height="22"></td></tr></table>';
		}
		else
		{
			$('td_commercial').innerHTML = '<table width="129" border="0" cellspacing="0" cellpadding="0"><tr><td width="120" nowrap background="images/btn_enable_bg.jpg">&nbsp;<a href="javascript:;" style="color:#FFFFFF; font-size:10px; text-decoration:none;" onClick="fetch_property(\'4\');">Renting Commercial</a></td><td width="14"><img src="images/btn_enable.jpg" width="9" height="22"></td></tr></table>';
			$('td_residential').innerHTML = '<table width="129" border="0" cellspacing="0" cellpadding="0"><tr><td width="120" nowrap background="images/btn_disable_bg.jpg">&nbsp;<font color="#666666">Renting Residential</font></td><td width="14"><img src="images/btn_disable.jpg" width="9" height="22"></td></tr></table>';
		}
	}
	
	$('property_container').innerHTML = '<div align="left">&nbsp;<img src="images/loading_small.gif" align="absmiddle"> Loading, Please Wait ... </div>';
	
	var url = 'ajax.php';
	
	var params = 'pid=2&loc_cat='+loc_cat+'&rnd='+Math.random();

	var myAjax = new Ajax.Updater('property_container',url, {method: 'get', parameters: params});
	
}


function under_dev()
{
	alert('Under Development.');	
	return false;
}

function validate_contact()
{
	if(document.frmEnq.name.value == "")
	{
		alert("Name is a required field");
		document.frmEnq.name.focus();
		return false;
	}
	else if(document.frmEnq.email.value == "")
	{
		alert("E-Mail is a required field.");
		document.frmEnq.email.focus();
		return false;
	}
	else if(document.frmEnq.email.value.indexOf("@") == -1 || document.frmEnq.email.value.indexOf(".") == -1)
	{
		alert("Please enter a valid e-mail address.");
		document.frmEnq.email.focus();
		return false;
	}
}

function validate_enquiry(frm)
{
	if($F('move_date') == '_'){
		alert("When would you like to move by? Please Select.");
		$('move_date').focus();
		return false;
	}
	if($F('property_to_sell') == '_'){
		alert("Do you have a property to Sell? Please Select.");
		$('property_to_sell').focus();
		return false;
	}
	if($F('property_to_let') == '_'){
		alert("Do you have a property to Let? Please Select.");
		$('property_to_let').focus();
		return false;
	}
	if($F('first_name') == ""){
		alert("First Name is a required field");
		$('first_name').focus();
		return false;
	}
	if($F('last_name') == ""){
		alert("Last Name is a required field");
		$('last_name').focus();
		return false;
	}
	if($F('email') == ""){
		alert("E-Mail is a required feild.");
		$('email').focus();
		return false;
	}
	if($F('email').indexOf("@") == -1 || $F('email').indexOf(".") == -1){
		alert("Please enter a valid e-mail address.");
		$('email').focus();
		return false;
		}
	
}

function login_from_enquire(frm)
{
	if($F('email') == '')
	{
		alert("E-mail is a required feild.");
		frm.email.focus();
		return false;
	}
	if($F('email').indexOf("@") == -1 || $F('email').indexOf(".") == -1)
	{
		alert("Please enter a valid E-mail address.");
		frm.email.focus();
		return false;
	}
	if($F('pwd') == '')
	{
		alert('Password is a required feild.');
		$('pwd').focus();
		return false;
	}
	frm.action = '/members/login';
	frm.submit();
}
var srf = 0;
var srfl = 0;
function show_reg_fields(i)
{
	if(i == 1)
	{
		if(srf == 0)
		{
			Element.show('div_register');
			srf = 1;
		}
		else
		{
			Element.hide('div_register');
			srf = 0;
		}
	}
	else
	{
		if(srfl == 0)
		{
			Element.show('div_login');
			srfl = 1;
		}
		else
		{
			Element.hide('div_login');
			srfl = 0;
		}
	}
}

function validate_login(frm){
	
	if(frm.email.value == "")
	{
		alert("E-mail is a required feild.");
		frm.email.focus();
		return false;
	}
	if(frm.email.value.indexOf("@") == -1 || frm.email.value.indexOf(".") == -1)
	{
		alert("Please enter a valid E-mail address.");
		frm.email.focus();
		return false;
	}
	if(frm.pwd.value=="")
	{
		alert("Password is a required feild.");
		frm.pwd.focus();
		return false;
	}
	
}

function forgot_password(frm)
{	
	if(frm.email.value == "")
	{
		alert("E-mail is a required feild.");
		frm.email.focus();
		return false;
	}
	if(frm.email.value.indexOf("@") == -1 || frm.email.value.indexOf(".") == -1)
	{
		alert("Please enter a valid E-mail address.");
		frm.email.focus();
		return false;
	}		
}

function checkReg(){
	
	if(document.frmReg.title.value == '_'){
		alert("Title is a requried feild.");
		document.frmReg.title.focus();
		return false;
	}
	if(document.frmReg.firstName.value == ""){
		alert("First Name is a requried feild.");
		document.frmReg.firstName.focus();
		return false;
	}
	if(document.frmReg.lastName.value == ""){
		alert("Last Name is a requried feild.");
		document.frmReg.lastName.focus();
		return false;
	}
	if(document.frmReg.email.value == ""){
		alert("Email is a required feild.");
		document.frmReg.email.focus();
		return false;
	}
	if(document.frmReg.email.value.indexOf("@") == -1 || document.frmReg.email.value.indexOf(".") == -1){
		alert("Please enter a valid Email address.");
		document.frmReg.email.focus();
		return false;
	}
	
	if(document.frmReg.pwd.value==""){
	alert("Password is a required feild.");
	document.frmReg.pwd.focus();
	return false;
	}
	if(document.frmReg.pwd2.value==""){
		alert("Confirm Password is a required feild.");
		document.frmReg.pwd2.focus();
		return false;
	}
	if(document.frmReg.pwd.value != document.frmReg.pwd2.value){
		alert("Password not matched please check it.");
		document.frmReg.pwd.value = "";
		document.frmReg.pwd2.value = "";
		document.frmReg.pwd.focus();
		return false;
	}
}


function checkReg2(){
	
	if(document.frmReg.title.value == '_'){
		alert("Title is a requried feild.");
		document.frmReg.title.focus();
		return false;
	}
	if(document.frmReg.firstName.value == ""){
		alert("First Name is a requried feild.");
		document.frmReg.firstName.focus();
		return false;
	}
	if(document.frmReg.lastName.value == ""){
		alert("Last Name is a requried feild.");
		document.frmReg.lastName.focus();
		return false;
	}
	if(document.frmReg.email.value == ""){
		alert("Email is a required feild.");
		document.frmReg.email.focus();
		return false;
	}
	if(document.frmReg.email.value.indexOf("@") == -1 || document.frmReg.email.value.indexOf(".") == -1){
		alert("Please enter a valid Email address.");
		document.frmReg.email.focus();
		return false;
	}
}



function check_member_id()
{
	var re = $F('chk_reg');
	if($F('member_id').length > 4 && !$F('member_id').match(re))
	{
		$('div_member_id_result').innerHTML = '<br><img src="http://www.solidtowerhomes.com/images/loading_small.gif" align="absmiddle"> Please Wait, Checking Availability ... ';
		var url = 'http://www.solidtowerhomes.com/ajax.php';
		//var url = 'ajax.php';
		var params = 'pid=5&member_id='+$F('member_id')+'&rnd='+Math.random();
		var myAjax = new Ajax.Updater('div_member_id_result',url, {method: 'get', parameters: params});
	}
	
	
}

function fetch_property_pagination(loc_cat, page)
{
	$('property_container').innerHTML = '<div align="left"><img src="images/loading_small.gif" align="absmiddle"> Loading, Please Wait ... </div>';
	
	var url = 'ajax.php';
	
	var params = 'pid=3&loc_cat='+loc_cat+'&page='+page+'&rnd='+Math.random();
	var myAjax = new Ajax.Updater('property_container',url, {method: 'get', parameters: params});
}

var div_id;

function subscribe_ajax(frm)
{
	if(frm.email.value == '')
	{
		alert('Please enter your E-mail Address.');
		frm.email.focus();
		return false;
	}
	if(frm.email.value.indexOf('@') == -1 || frm.email.value.indexOf('.') == -1)
	{
		alert('Please enter a Valid E-mail Address.');
		frm.email.focus();
		return false;
	}
	if(frm.first_name.value == '')
	{
		alert('Please enter your First Name.');
		frm.first_name.focus();
		return false;
	}
	if(frm.last_name.value == '')
	{
		alert('Please enter your Last Name.');
		frm.last_name.focus();
		return false;
	}
	
	url += '&rnd='+Math.random();

	div_id = 'subscribe_msg';	

	var url = 'ajax.php';
	
	var params = 'pid=1&email='+$F('email')+'&first_name='+frm.first_name.value+'&last_name='+frm.last_name.value+'&action='+$F('action');

	frm.btnSubmit.value = 'Submiting, Please Wait ... ';
	frm.btnSubmit.disabled = true;
		
	frm.email.value = '';
	frm.first_name.value = '';
	frm.last_name.value = '';
	frm.action[0].checked = true;

	$(div_id).innerHTML = ' Please Wait ... ';
	
	var myAjax = new Ajax.Request(url, {methosd: 'get', parameters: params, onComplete: subscription_return});
	
}
function subscription_return(req)
{
	$('subscribe_msg').innerHTML = req.responseText;
	$('btnSubmit').value = 'Submit';
	$('btnSubmit').disabled = false;
}
function MM_jumpMenu(targ,selObj,restore)
{
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if(restore) selObj.selectedIndex=0;
}
