var CarboneController = {
	
	over: function(id,images) {
		document.getElementById(id).src = "images/"+images;
	}
	,
	
	out: function(id,images) {
		document.getElementById(id).src = "images/"+images;
	}
	,
	getContent: function(cust_id) {
		$.ajax({
			   type: "POST",
			   url: "getCustomer.php",
			   data: "cust_id="+cust_id,
			   success: function(data) {
						document.getElementById('fuse_content').innerHTML = data;
					}
			});
	}
}

function formValidator(){
	// Make quick references to our fields
	var guestname = document.getElementById('guestname');
	var company = document.getElementById('company');
	var address = document.getElementById('address');
	var phone = document.getElementById('phone');
	var email = document.getElementById('email');
	var title = document.getElementById('title');
	var content = document.getElementById('content');
	
	// Check each input in the order that it appears in the form!
		if(isEmpty(guestname, "Bạn chưa nhập Tên")){
			if(isEmpty(company, "Bạn chưasnhập Tên công ty")){
				if(isEmpty(address, "Bạn chưa nhập địa chỉ")){
					if(isEmpty(phone, "Bạn chưa nhập số phone")){
						if(isEmpty(email, "Bạn chưa nhập email")){
							if(isEmpty(content, "Bạn chưa nhập Nội dung")){
	//if(isAlphabet(guestname, "Please enter only letters for your name")){
		//if(isAlphabet(company, "Numbers and Letters Only for Address")){
		//if(isAlphanumeric(address, "Numbers and Letters Only for Address")){
			if(isNumeric(phone, "Nhập số điện thoại")){
					if(emailValidator(email, "Nhập địa chỉ Email sai định dạng")){
						if(lengthRestriction(content, 10, 255)){
							return true;
						}
						}
						}			
						}	
					}
				}
			}
		}
	}	
	return false;	
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.select();
		return false;
	}
}

/*function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}*/

/*function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}*/

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Nội dung nhập nhỏ nhất phải là " +min+ " và lớn nhất là " +max+ " ký tự");
		elem.select();
		return false;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.select();
		return false;
	}
}

