var emailValid = '';

sfHover = function() {
	//alert('loaded');
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			//alert('over');
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			//alert('out');
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


var newwindow;
function loginwin(url)
{
	newwindow=window.open(url,'name','height=400,width=350,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

var newwindow;
function popup(url)
{
	newwindow=window.open(url,'name','height=580,width=508,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function SaveProperty() {
	$.get("/includes/process_ajax.asp?atn=userstatus", function(data){
	    if (data.length >= 1) 
	    	{
	    	//save the prop

	$("#dlgsaveproperty").dialog({ 
	    modal: true,
	    title: 'Save Property',
	    overlay: { 
	        opacity: 0.5, 
	        background: "black" 
	    },	    
	    buttons: { 
	        "Ok": function() { 
	            //document.formsaveproperty.submit();
	            $.post("/includes/process_ajax.asp?atn=saveproperty", { mls: document.formsaveproperty.mls.value, comments: document.formsaveproperty.comments.value } );
	            $(this).dialog("close");
	           	$("#savedproperties").load("/includes/process_ajax.asp?atn=savedproperties");
	        }, 
	        "Cancel": function() { 
	            $(this).dialog("close"); 
	        } 
	    } 
	});
	    	
	    	}
	    	else
	    	{
	    	alert('Please Login or Signup under My Account to use this feature');
	    	}
	  });





	}


function SaveSearch() {
	$.get("/includes/process_ajax.asp?atn=userstatus", function(data){
	    if (data.length >= 1) 
	    	{
	    	//save the prop

	$("#dlgsavesearch").dialog({ 
	    modal: true,
	    title: 'Save Search',
	    overlay: { 
	        opacity: 0.5, 
	        background: "black" 
	    },	    
	    buttons: { 
	        "Ok": function() { 
	            //document.formsaveproperty.submit();
	            $.post("/includes/process_ajax.asp?atn=savesearch", { searchurl: window.location.search.substring(1), searchtitle: document.formsavesearch.searchtitle.value, comments: document.formsavesearch.comments.value } );
	            $(this).dialog("close");
	           	$("#savedsearches").load("/includes/process_ajax.asp?atn=savedsearches");
	        }, 
	        "Cancel": function() { 
	            $(this).dialog("close"); 
	        } 
	    } 
	});
	    	
	    	}
	    	else
	    	{
	    	alert('Please Login or Signup under My Account to use this feature');
	    	}
	  });





	}


function Signup() {
	$("#dlgsignup").dialog({ 
	    modal: true,
	    title: 'My Account Signup',
	    height: 280,
	    width: 340,
	    overlay: { 
	        opacity: 0.5, 
	        background: "black" 
	    },	    
	    buttons: { 
	        "Signup": function() { 
	            if (validateSignup()) {
	            	$.post("/includes/process_ajax.asp?atn=signup", { email: document.formsignup.email.value, firstname: document.formsignup.firstname.value, lastname: document.formsignup.lastname.value, password1: document.formsignup.password1.value, password2: document.formsignup.password2.value} );
	            	$(this).dialog("close");
	            	}
	        }, 
	        "Cancel": function() { 
	            $(this).dialog("close"); 
	        } 
	    } 
	});
	}

function validateEmail() {
	//alert('fired');
	$.post("/includes/process_ajax.asp?atn=validateemail", { email: document.formsignup.email.value },
	  function(data){
	    //alert("Data Loaded: " + data);
	    if (data.length < 1) 
	    	{
	    	emailValid = 'yes';
	    	}
	    	else
	    	{
	    	emailValid = 'no';
	    	}
	    document.getElementById('emailextra').innerHTML = data;
	  });
	}
	
function validateSignup() {
	//alert('validateSignup fired');
	if (emailValid != 'yes' | document.formsignup.firstname.value.length<1 | document.formsignup.password1.value != document.formsignup.password2.value) 
		{
		alert('wrong');
		return false;
		}
		else
		{
		return true;
		}
	}

function Login() {
	$("#dlglogin").dialog({ 
	    modal: true,
	    title: 'My Account Login',
	    overlay: { 
	        opacity: 0.5, 
	        background: "black" 
	    },	    
	    buttons: { 
	        "Login": function() { 
	            	$.post("/includes/process_ajax.asp?atn=login", { email: document.formlogin.email.value, password: document.formlogin.password.value}, 
	            		function(data) {
	            			if (data.length < 1)
	            				{
	            				//alert('logged in');
	            				$("#dlglogin").dialog("close");
	            				window.location.reload()
	            				}
	            				else
	            				{
	            				//alert('no');
	            				document.getElementById('loginextra').innerHTML = data
	            				}
	            			});
	        }, 
	        "Cancel": function() { 
	            $(this).dialog("close"); 
	        } 
	    } 
	});
	}
