/**************************************************************************/
/*				Variable Declaration									  */
/**************************************************************************/
var strTemp1201 = '';
var strListingType = 'mls';
var strCounty = 'all';
var strNeighborhood = '';
var strZipCode = '';
var intBedrooms = -1;
var intBathrooms = -1;
var intFreshness = -1;
var strHistSearch = new Array();
var booConsolidate = true;
var booShowResult = 0;
var intMapZoom = 9;
var map;
var strSearchingCriteria='';
var arrMarkers = new Array();
var arrMarkerHTML = new Array();
var intMarkerCounter = 0;
var intCurrentProperty = 0;
var booSearchCriteria = false;
var booActionSave = true;
var booZipcode = false;
var booLoginStatus = false;
var objUser;
//var regex = /^[^(@|\W)]+@[^@]+\.[^@]+$/;
var regex = /^[^(@)]+@[^@]+\.[^@]+$/;
var strMessage = '';
//Object variable for history bar
var objHistoryBar;
//Object variable to store search condition
var objSrch = {minPrice: 0, maxPrice:0, streetName: '', MLS: '', zipCode: 0, minYearBuilt: 0, maxYearBuilt: 0, minSquareFeet: 0, maxSquareFeet: 0, minBedrooms: 0, maxBedrooms: 0, minBathrooms: 0, maxBathrooms: 0, garage: 0, conservation: 0, pool: 0, waterFront: 0, bonusRoom: 0, officeDen: 0, oneStory: 0, twoStory: 0, singleFamily: 0, townhome: 0, condo: 0 };

//Array variable that store previos searches
var arrSrchResults = new Array();

//Object variable to store properties informtion
var objProperties;

//Variable to store Neighborhood information
var objNeighborhood = {mls: {all: new Array(), hb: new Array(), po: new Array()}, fl: {all: new Array(), hb: new Array(), po: new Array()}, st: {all: new Array(), hb: new Array(), po: new Array()}};

//Variable to store zipcodes information
var objZipcodes = {mls: {all: new Array(), hb: new Array(), po: new Array()}, fl: {all: new Array(), hb: new Array(), po: new Array()}, st: {all: new Array(), hb: new Array(), po: new Array()}};

/*** Common used functions.
*/
// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
/*var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(16, 16);
baseIcon.shadowSize = new GSize(16, 16);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);*/

/*** Function: dale_control
*/

function showLogin() {
		$.blockUI(strMessage, { backgroundColor: '#f7f7f7',width: '275px', cursor: 'default' }); 
    		$('#semail').val('');
    		$('#spassword').val('');
			$('#eemail').val('');
			$('#epassword').val('');
			$('#ecpassword').val('');
}


/*** Function: goSignUp
*/

function goSignUp() {
	if(!regex.test($('#eemail').val())){
		alert('Please enter proper email.');
		return;
	}
	
	if($('#epassword').val().length<6 && $('#ecpassword').val().length<6) {
		alert('Password length must be at least six characters.');
		return;
	}
	
	if($('#epassword').val() != $('#ecpassword').val()) {
		alert("Please check password.");
		return;
	}
	
	var strUrl = 'signup.php';
	var strData = 'useremail='+$('#eemail').val()+'&password='+$('#epassword').val();
	$.ajax({
		type: "POST",
		url: strUrl,
		data: strData,
		dataType: "json",
		beforeSend: function() {
				$.blockUI('<span style="font-size: 14px; font-weight: bold; color: #0766ba">Processing...</span>&nbsp;&nbsp;&nbsp;<img src="http://leads.teambohannon.com/mls/gimages/processing.gif"/>', { backgroundColor: '#f7f7f7',width: '275px', cursor: 'default' }); 
		},
	    success: function(data) {
	    	booLoginStatus = true;
	    	$.unblockUI();
	    	if(data.loginStatus == 'Success') {
	    		$('#semail').val('');
	    		$('#spassword').val('');
	    		
	    		booLoginStatus = true;
	    		$('#signInInfo').html('<b>Welcome! <a href="javascript:void(0)">'+data.username+'</a></b>, <a href="javascript:void(0)" onclick="goSignOut();">Logout</a>&nbsp;&nbsp;&nbsp;');
    			$('#__searches').html('<li id="s_No"><a href="javascript:void(0);">No Search Found.</a></li>');
    			$('#eemail').val('');
    			$('#epassword').val('');
    			$('#ecpassword').val('');
	    	}
	    },
	    error: function() {
	    	$.unblockUI();
	    	alert('Error in connecting request.');
	    }
	});

	return;
    $.blockUI('<span style="font-size: 14px; font-weight: bold; color: #0766ba">Processing...</span>&nbsp;&nbsp;&nbsp;<img src="http://leads.teambohannon.com/mls/gimages/processing.gif"/>', { backgroundColor: '#f7f7f7',width: '275px', cursor: 'default' }); 
}

/*** Function: goSignOut()
*/

function goSignOut() {
	$('#semail').val('');
	$('#spassword').val('');
	
	var strUrl = 'logout.php';
	$.ajax({
		type: "POST",
		url: strUrl,
		dataType: "json",
		beforeSend: function() {
				$.blockUI('<span style="font-size: 14px; font-weight: bold; color: #0766ba">Processing...</span>&nbsp;&nbsp;&nbsp;<img src="http://leads.teambohannon.com/mls/gimages/processing.gif"/>', { backgroundColor: '#f7f7f7',width: '275px', cursor: 'default' }); 
		},
	    success: function(data) {
	    	$.unblockUI();	
	    	if(data.logoutStatus == 'Success') {
	    	booLoginStatus = false;
			$('#signInInfo').html('You are not logged-in, Please <a href="javascript:void(0);" onclick="showLogin();">Login</a>&nbsp;&nbsp;&nbsp;');
			$('#__searches').html('<li id="s_No"><a href="javascript:void(0);">No Search Found.</a></li>');
	    	}
	    }
	});
}

/*** Function: goSignIn
*/

function goSignIn() {
	/*if(!regex.test($('#semail').val())){
		alert('Please enter proper email.');
		return;
	}
	*/
	/*if($('#spassword').val().length<6) {
		alert('Password length must be at least six characters.');
		return;
	}*/
	
	var strUrl = 'http://www.true2ourselves.com/forum/temp_login.php';
	var strData = 'vb_login_username='+$('#semail').val()+'&vb_login_password='+$('#spassword').val();
	$.ajax({
		type: "POST",
		url: strUrl,
		data: strData,
		dataType: "json",
		beforeSend: function() {
				$.blockUI('<span style="font-size: 14px; font-weight: bold; color: #0766ba">Processing...</span>&nbsp;&nbsp;&nbsp;<img src="http://leads.teambohannon.com/mls/gimages/processing.gif"/>', { backgroundColor: '#f7f7f7',width: '275px', cursor: 'default' }); 
		},
	    success: function(data) {

			$.unblockUI();	
			
	    	if(data.loginStatus == 'Success') {
	    		
	    		booLoginStatus = true;
	    		$('#signInInfo').html('<b>Welcome! <a href="javascript:void(0)">'+data.username+'</a></b>, <a href="javascript:void(0)" onclick="goSignOut();">Logout</a>&nbsp;&nbsp;&nbsp;');
	    		if(data.search.saved <1) {
	    			var strHTML = '<li id="s_0"><a href="javascript:void(0);">No searche found.</a></li>';
	    		}
	    		else {
	    			if(data.search.saved > 0) {
	    				$('#__searches').html('');
	    			}
	    			else {
	    				$('#__searches').html('<li id="s_No"><a href="javascript:void(0);">No Search Found.</a></li>');
	    			}
	    			
	    			$.each(data.search.items, function(i,item) {
	    				$('#__searches').append('<li id="s_'+item.searchId+'"><a href="javascript:void(0);" onclick="loadSearch(\''+item.searchId+'\')">'+item.searchName+'</a></li>');
	    			});
	    		}
	    		
	    		if(booActionSave==false) {
	    			booActionSave=true;
	    			goSave();
	    		}
	    	}
	    	else {
	    		alert('Login Failed');
	    		showLogin();
	    	}
	    },
	    error: function() {
	    	alert('Error in request');
	    	showLogin();
	    }
	});

	return;
    
}

$(function() {
	$('#save').click(function(){
//		if($('#txtSearchName').val()!='')
//			alert('Validate');
//		else 
//			alert('Non-validate');
			
		alert('Start Working');
	});
});
