/* (CC) 2008 Han Lin Yap. Some Rights Reserved.             	  */
/*   http://creativecommons.org/licenses/by/3.0                   */
/* This style sheet is licensed under a Creative Commons License. */
	/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	* Filename: check.js
	* Version: 1.0 (2008-08-07)
	* Website: http://www.zencodez.net/
	* Author: Han Lin Yap
	* Description: Handles the site style.
	* Last Modified: 2008-08-07
	*/
function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}


function userCheck(user) {
	$.ajax({
		type: "POST",
		url: "ajax/usercheck.php",
		data: "user=" + user.value,
		success: function(msg){
			if (msg) {
				user.style.backgroundColor = "#CFF9A6";
			} else {
				user.style.backgroundColor = "#FFD5D5";
			}
		}
	});
}
function checkAllField(e) {
	valid = true;
	for (i=0;i<e.length;i++) {
		if (e.getElementsByTagName("input")[i].value.length > 0) {
			e.getElementsByTagName("input")[i].style.backgroundColor = "#FFFFFF";
			//e.getElementsByTagName("input")[i].style.backgroundColor = "#CFF9A6";
		} else {
			e.getElementsByTagName("input")[i].style.backgroundColor = "#FFD5D5";
			valid = false;
		}
	}
	return valid;
}
function regcheck(e) {
	valid = true;
	valid = checkAllField(e);
	if (!valid) { return false; }
	
	if (/^[a-zA-Z0-9]{4,}$/.test(e.username.value)) {
	//if (e.username.value.length > 3) {
		e.username.style.backgroundColor = "#CFF9A6";
	} else {
		e.username.style.backgroundColor = "#FFD5D5";
		return false;
	}
				
	if (e.password.value == e.password2.value&&e.password.value.length > 5) {
		e.password.style.backgroundColor = "#CFF9A6";
		e.password2.style.backgroundColor = "#CFF9A6";
	} else {
		e.password.style.backgroundColor = "#FFD5D5";
		e.password2.style.backgroundColor = "#FFD5D5";
		return false;
	}
	//        /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/
	/*valid = /^[a-z0-9\._+\+]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.[a-z]{2,6}$/i.test(e.email.value);
	if (valid) {
		e.email.style.backgroundColor = "#CFF9A6";
	} else {
		e.email.style.backgroundColor = "#FFD5D5";
		return false;
	}
	*/
	
	return true;
}
function logcheck(e) {
	valid = true;
	valid = checkAllField(e);
	if (!valid) { return false; }
	
	if (e.username.value.length >= 3) {
		e.username.style.backgroundColor = "#CFF9A6";
	} else {
		e.username.style.backgroundColor = "#FFD5D5";
		return false;
	}
	
	if (e.password.value.length >= 5) {
		e.password.style.backgroundColor = "#CFF9A6";
	} else {
		e.password.style.backgroundColor = "#FFD5D5";
		return false;
	}
		
	return true;
}
function concheck(e) {
	valid = true;
	valid = checkAllField(e);
	if (!valid) { return false; }
	
	if (e.username.value.length > 3) {
		e.username.style.backgroundColor = "#CFF9A6";
	} else {
		e.username.style.backgroundColor = "#FFD5D5";
		return false;
	}
	/*
	valid = /^[a-z0-9\._+\+]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.[a-z]{2,6}$/i.test(e.email.value);
	if (valid) {
		e.email.style.backgroundColor = "#CFF9A6";
	} else {
		e.email.style.backgroundColor = "#FFD5D5";
		return false;
	}
	*/	
	return true;
}
function procheck(e) {
	/*	
	valid = /^[a-z0-9\._+\+]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.[a-z]{2,6}$/i.test(e.email.value);
	if (valid) {
		e.email.style.backgroundColor = "#CFF9A6";
	} else {
		e.email.style.backgroundColor = "#FFD5D5";
		return false;
	}
	*/	
	return true;
}
function passcheck(e) {
		
	if (e.password3.value.length > 5) {
		if (e.password.value == e.password2.value&&e.password.value.length > 5) {
			e.password.style.backgroundColor = "#CFF9A6";
			e.password2.style.backgroundColor = "#CFF9A6";
		} else {
			e.password.style.backgroundColor = "#FFD5D5";
			e.password2.style.backgroundColor = "#FFD5D5";
			return false;
		}
	}
		
	return true;
}
function passcheck2(e) {
		
		if (e.password.value == e.password2.value&&e.password.value.length > 5) {
			e.password.style.backgroundColor = "#CFF9A6";
			e.password2.style.backgroundColor = "#CFF9A6";
		} else {
			e.password.style.backgroundColor = "#FFD5D5";
			e.password2.style.backgroundColor = "#FFD5D5";
			return false;
		}
		
	return true;
}
function feecheck(e) {
	
	if (e.feedbackmessage.innerHTML.length > 0) {
		e.feedbackmessage.style.backgroundColor = "#CFF9A6";
	} else {
		e.feedbackmessage.style.backgroundColor = "#FFD5D5";
		return false;
	}
		
	return true;
}
