function loginpro(success) {
	if(success) {
		Element.update('loginform','You are now logged in. Please wait.');
		window.location.href = 'index.php';
	} else {
	  Element.update('warning','Invalid login or password!');
	  Effect.Appear('warning');
		 Effect.BlindUp('warning', { delay:6 } );
		 new Effect.Shake('loginform');
		 Element.update('submitb','<input type=\"submit\" class=\"tba\" value=\"login\" />');
	}

}
 

function loginf(thisf) {

	logn = thisf.login.value;
	logp = thisf.pwd.value;

	//alert(logn+" "+logp);
	
	Element.update('submitb','One moment please...');
	
	var opt = {
		// Use POST
		method: 'post',
		postBody: 'login='+logn+'&pwd='+logp,

		onSuccess: function(t) {
			//alert(t.responseText);
			if(t.responseText==1) {
					loginpro(true);
   } else {
	   	loginpro(false);
			}
		},
		// Handle 404
		on404: function(t) {
			alert('Error 404: location "' + t.statusText + '" was not found.\n\nLogin not possible. Please contact the website administrator.');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText+'\n\nLogin not possible. Please contact the website administrator.');
		}
	}
	
	new Ajax.Request('login.php', opt);
	return false;
  
}


// DELETING


	function delEntry(id,table) {
		
		switch(table) {
		
			case "communities": var wh = "Community"; var el = 'com';	 	break;
			case "designs":  		var wh = "Design";    var el = 'des';	 	break;
			case "files": 			var wh = "File";	  	var el = 'fil';	 	break;
			case "homes":				var wh = "Home";			var el = 'hom'; 	break;
		
		}
	
		if(confirm("Are you sure you want to delete this "+wh+"?")) {

			Element.update("warning","Please wait...");
			Effect.Appear("warning");
			Effect.BlindUp('warning', { delay:6 });			
			
			var handlerFunc = function(t) {
				  Element.update("warning",""+wh+" deleted successfully.");
				  Element.remove(el+"_"+id);      
			}
			var errFunc = function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
			
			new Ajax.Request('index.php', {parameters:'do=delete&table='+table+'&id='+id, onSuccess:handlerFunc, onFailure:errFunc});
		
		} else {
		
			return false;
		
		}
		
		return false;
	
	}	

function contactMail(thisf) {

	fname = thisf.name.value;
	femail = thisf.email.value;
	fphone = thisf.phone.value;
	fmessage = thisf.message.value;
	
	Element.update('warning','One moment please...');
	Effect.Appear('warning');
	
	var opt = {
	
		method: 'post',
		postBody: 'do=sendmail&name='+fname+'&email='+femail+'&phone='+fphone+'&messagef='+fmessage,
		
		onSuccess: function(t) {
			if(t.responseText==1) {
				Element.update('formdiv','<strong>Dear '+fname+',<br /><br />Thank you for your interest in Rice Homes.<br /><br />We will be in contact with you regarding your request.</strong>');		
				Effect.Fade('warning',{duration:.1});
			} else if(t.responseText==2) {
				Element.update('warning','There was an error sending your e-mail. You have specified an incorrect e-mail address.');
				Effect.Highlight('warning');
			} else {
			  //alert(t.responseText);
				Element.update('warning','There was an error sending your e-mail. We apologize for the inconvenience.');
				Effect.Highlight('warning');
			}
		},
		
		// Handle 404
		on404: function(t) {
			alert('Error 404: location "' + t.statusText + '" was not found.\n\nMail sending not possible. Please contact the website administrator.');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText+'\n\nMail sending not possible. Please contact the website administrator.');
		}
	
	}
	
	new Ajax.Request('index.php',opt);
	return false;

}
