// JavaScript Document

function checkFormOpinion(){
	var msg;
	with(window.document.opinionForm){
		msg = txtOpinion
	}
	if(trim(msg.value) == ''){
		alert('Please enter your opinion about our restaurant');
		msg.focus();
		return false;
	} else {
		return true;
	}
}

function cancelCommand(){
	window.close();
}

function refresh_parent(){
	opener.window.location.reload();
	window.close();
}

function checkFormOrder(){
	var name,tel,mobile,email,post,adr,no,plc,date,time,msg,res;
	
	name = window.document.frmMenu.txtName;
	tel = window.document.frmMenu.txtTel;
	mobile = window.document.frmMenu.txtMobile;
	email = window.document.frmMenu.txtEmail;
	post = window.document.frmMenu.txtPost;
	adr = window.document.frmMenu.txtAddress;
	no = window.document.frmMenu.txtNo;
	plc = window.document.frmMenu.txtPlace;
	date = window.document.frmMenu.txtDate;
	time = window.document.frmMenu.txtTime;
	msg = 'Error:\n';
	res = true;

	if (trim(name.value) == ''){
		msg = msg + 'No Name entered\n';
		res = false;
	}
	if (trim(email.value) == ''){
		msg += 'No E-Mail entered\n';
		res = false;
	}
	else if (!isValidEmail(trim(email.value))){
		msg += 'Invalid E-Mail Address\n';
		res = false;
	}
	if (trim(tel.value) == '' && trim(mobile.value) == ''){
		msg += 'No Tel or Mobile entered\n';
		res = false;
	}
	if (trim(tel.value) != '')
		if(!chkNumeric(tel,0,0)){
			msg += 'Invalid Phone Number\n';
			res = false;
		}
	if (trim(mobile.value) != '')
		if(!chkNumeric(mobile,0,0)){
			msg += 'Invalid Mobile Number\n';
			res = false;
		}
	if (trim(adr.value) == ''){
		msg += 'No Address entered\n';
		res = false;
	}
	if (trim(no.value) == ''){
		msg += 'No House Number entered\n';
		res = false;
	}
	if (trim(post.value) == ''){
		msg += 'No Post Code entered\n';
		res = false;
	}
	if (trim(plc.value) == ''){
		msg += 'No Place entered\n';
		res = false;
	}
	if (trim(date.value) == ''){
		msg += 'No Date entered\n';
		res = false;
	}
	if (trim(time.value) == ''){
		msg += 'No Time entered\n';
		res = false;
	}
	if (!res){
		alert(msg);
	}
	return res;
}

function checkFormReservation(){
	var name,tel,mobile,email,no,date,time,msg,res;
	name = window.document.frmReservation.txtName;
	tel = window.document.frmReservation.txtTel;
	mobile = window.document.frmReservation.txtMobile;
	email = window.document.frmReservation.txtEmail;
	no = window.document.frmReservation.txtNumber;
	date = window.document.frmReservation.txtDate;
	time = window.document.frmReservation.txtTime;
	msg = 'Error:\n';
	res = true;
	if (trim(name.value) == ''){
		msg = msg + 'No Name entered\n';
		res = false;
	}
	if (trim(email.value) == ''){
		msg += 'No E-Mail entered\n';
		res = false;
	}
	else if (!isValidEmail(trim(email.value))){
		msg += 'Invalid E-Mail Address\n';
		res = false;
	}
	if (trim(tel.value) == '' && trim(mobile.value) == ''){
		msg += 'No Tel or Mobile entered\n';
		res = false;
	}
	if (trim(tel.value) != '')
		if (!chkNumeric(tel,0,0)){
			msg += 'Invalid Phone Number\n';
			res = false;
		}
	if (trim(mobile.value) != '')
		if (!chkNumeric(mobile,0,0)){
			msg += 'Invalid Mobile Number\n';
			res = false;
		}
	if (trim(no.value) == ''){
		msg += 'No Number of People entered\n';
		res = false;
	}
	else {
		if (!chkNumeric(no,1,99)){
			msg += 'Invalid Number of People\n';
			res = false;
		}
	}
	if (trim(date.value) == ''){
		msg += 'No Date entered\n';
		res = false;
	}
	if (trim(time.value) == ''){
		msg += 'No Time entered\n';
		res = false;
	}
	if (!res){
		alert(msg);
	}
	return res;
}

function checkFormContact(){
	var email;
	email = window.document.frmContact.txtEmail;
	if (!isValidEmail(trim(email.value))){
		alert('Invalid E-Mail Address');
		return false;
	} else
		return true;
}

function trim(str){
	return str.replace(/^\s+|\s+$/g,'');
}

function isValidEmail(str){
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


function chkNumeric(objName,minval,maxval){
	var checkOK = "0123456789";
	var checkStr = objName;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0 ;  i < checkStr.value.length ;  i++){
		ch = checkStr.value.charAt(i);
		for (j = 0 ;  j < checkOK.length ;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length){
			allValid = false;
			break;
		}
		if (ch != ",")
			allNum += ch;
	}
	if (!allValid){	
		alertsay = "Please enter only these values \""
		alertsay = alertsay + checkOK + "\n" 
		alert(alertsay);
		return (false);
	}
	// set the minimum and maximum
	if (!(minval == 0 && maxval == 0)){
		var chkVal = allNum;
		var prsVal = parseInt(allNum);
		if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval)){
			alertsay = "Please enter a value greater than or "
			alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
			alertsay = alertsay + "equal to \"" + maxval + "\n"
			alert(alertsay);
			return (false);
		}
	}
	return allValid;
}

