﻿// JavaScript Document

function goToEditEmployee()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
		
		document.Frm_grid.action = "editemployees.php";
		document.Frm_grid.method = "post";
		document.Frm_grid.submit();
	}
	else
		alert('Please select the row!');
}

function checkTitle()
{
	txtName = document.Frm_Employee.txt_name;
	txtPosition = document.Frm_Employee.txt_position;
	txtMail = document.Frm_Employee.txt_mail;
	txtUser = document.Frm_Employee.txt_user;
	txtPass = document.Frm_Employee.txt_pass;
	txtRepass = document.Frm_Employee.txt_repass;
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	
	if(Trim(txtName.value) == ""){
		alert('Please enter the name!');
		txtName.focus();
		return false;
	}
	else if(Trim(txtPosition.value) == ""){
		alert('Please enter the position!');
		txtPosition.focus();
		return false;	
	}
	else if(Trim(txtMail.value) == ""){
		alert('Please enter the E-Mail!');
		txtMail.focus();
		return false;	
	}
	else if(!emailpat.test( Trim(txtMail.value))){
		alert('Please enter a valid email address');
		txtMail.focus();
		return false;	
	}
	else if(Trim(txtUser.value) == ""){
		alert('Please enter the username!');
		txtUser.focus();
		return false;	
	}	
	else if(Trim(txtPass.value) == ""){
		alert('Please enter the password!');
		txtPass.focus();
		return false;	
	}
	else if(Trim(txtRepass.value) == ""){
		alert('Please enter the re-type password!');
		txtRepass.focus();
		return false;	
	}
	else if(Trim(txtRepass.value) != Trim(txtPass.value)){
		alert('Please verify your password again!');
		txtRepass.focus();
		return false;	
	}		
	else
		return true;
}

function saveuser()
{
	  if(checkTitle())
	  {
		document.Frm_Employee.action = "editemployees.php";
		document.Frm_Employee.method = "post";
		document.Frm_Employee.submit();
	 }
}

function deleteuser()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
		if(confirm("Are you sure about delete this employee?")){
			document.Frm_grid.action = "employees.php";
			document.Frm_grid.method = "post";
			document.Frm_grid.submit();
		}
	}
	else
		alert('Please select the employee!');
}

function CheckLoginStaff()
{
	txtUser = document.Frm_ELogin.txt_user;
	txtPass = document.Frm_ELogin.txt_pass;
	
	if(Trim(txtUser.value) == ""){
		alert('Please enter the username!');
		txtUser.focus();
		return false;	
	}	
	else if(Trim(txtPass.value) == ""){
		alert('Please enter the password!');
		txtPass.focus();
		return false;	
	}	
	else
		return true;

}

function loginStaff()
{
	  if(CheckLoginStaff())
	  {
		document.Frm_ELogin.action = "staff_action.php";
		document.Frm_ELogin.method = "post";
		document.Frm_ELogin.submit();
	 }
}

function ResetForm()
{
	document.Frm_ELogin.reset();
}

function CheckLoginStaffAr()
{
	txtUser = document.Frm_ELogin.txt_user;
	txtPass = document.Frm_ELogin.txt_pass;
	
	if(Trim(txtUser.value) == ""){
		alert('!الرجاء إدخال اسم المستجدم');
		txtUser.focus();
		return false;	
	}	
	else if(Trim(txtPass.value) == ""){
		alert('!الرجاء إدخال كلمة السر');
		txtPass.focus();
		return false;	
	}	
	else
		return true;

}

function loginStaffAr()
{
	  if(CheckLoginStaffAr())
	  {
		document.Frm_ELogin.action = "staff_action.php";
		document.Frm_ELogin.method = "post";
		document.Frm_ELogin.submit();
	 }
}
