/* 
 * You, sir, are a douche. :) 
 * Yes, this means i knew you'd look here.
 * If you find any bugs or ideas for improvements, let me know.
 */

/* 
 * File created on Wednessday 02 January 2008
 * Copyrighted (c) Constellation Software 2008
 * Version 0.1a
 */

function validateUser(name) {
	var x = document.getElementById(name).value;
	var url = 'php/ajax.usernametaken.php?username=' + escape(x);
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(setcolor) {
			var user = document.getElementById(name);
			var warning = document.getElementById('warning_user');
			if(setcolor.responseText !== "False" && x != ''){
				user.setStyle({ background: '#a0ff9b' });
				warning.setStyle({ color: '#00FF00' });
				warning.update('Username Available.');
				return true;
			}else{
				user.setStyle({ background: '#ff8787' });
				warning.setStyle({ color: '#FF0000' });
				warning.update('Username Is already In Use.');
				return false;
			}
		}	
	});
}
function compare(pd1, pd2) {
	var pw1 = document.getElementById(pd1).value;
	var pw2 = document.getElementById(pd2).value;
	var a = document.getElementById(pd1);
	var b = document.getElementById(pd2);
	var warning = document.getElementById('warning_compare');
	if((pw1 == '' || pw2 == '') || (pw1 != pw2)){
		a.style.backgroundColor = '#ff8787';
		b.style.backgroundColor = '#ff8787';
		warning.setStyle({ color: '#FF0000' });
		warning.update('Passwords Do Not Match.');
		return false;
	}else{
		a.style.backgroundColor = '#a0ff9b';
		b.style.backgroundColor = '#a0ff9b';
		warning.setStyle({ color: '#00FF00' });
		warning.update('Passwords Match!');
		return true;
	}
}
function validateEmail(email) {
	var mail = document.getElementById(email).value;
	var a = document.getElementById(email);
	var warning = document.getElementById('warning_email');
    var regex = new RegExp("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");
    if(regex.test(mail) && mail != ''){
    	a.style.backgroundColor = '#a0ff9b';
    	warning.setStyle({ color: '#00FF00' });
    	warning.update('Email Correct.');
    	return true;
    }else{
    	a.style.backgroundColor = '#ff8787';
    	warning.setStyle({ color: '#FF0000' });
    	warning.update('Incorrect Email.');
		return false;
	}
}
function validateSite(website) {
	var site = document.getElementById(website).value;
	var a = document.getElementById(website);
	var warning = document.getElementById('warning_site')
    var regex = new RegExp("([a-zA-Z]{3,})://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
    if(regex.test(site) && site != ''){
    	a.style.backgroundColor = '#a0ff9b';
    	warning.setStyle({ color: '#00FF00' });
    	warning.update('Site is Valid');
    	return true;
    }else{
    	a.style.backgroundColor = '#ff8787';
    	warning.setStyle({ color: '#FF0000' });
    	warning.update('Not a Valid Site.');
		return false;
	}
}

function is_enabled(what){
	var a = document.getElementById(what).value;
	if(a == 1) return true;
	else return false;
}
