﻿// JavaScript Document
sh1=0;
sh2=0;
indv_type = "";
cor_type = "";
account_type = "";
files_name = Array();
arr_index=0;

function chkform()
{

		if(document.getElementById("account_type").value == "ind")
			{
				if(document.getElementById("name1").value == "" || 
				   document.getElementById("name2").value == "" ||
				   document.getElementById("name3").value == "" || 
				   document.getElementById("name4").value == "" )
					{
							alert("Your name should be in sent in four sections");
							document.getElementById("name1").focus();
							return false;
					}
			  if(document.getElementById("add").value == "")
					{
							alert("Kindly check the address field");
							document.getElementById("add").focus();
							return false;
					}
			  if(document.getElementById("ph").value == "")
					{
							alert("Kindly check the phone field");
							document.getElementById("ph").focus();
							return false;
					}
		
			  if(document.getElementById("mob").value == "")
					{
							alert("Kindly check the mobile field");
							document.getElementById("mob").focus();
							return false;
					}		
			  if(document.getElementById("dob").value == "")
					{
								alert("Kindly check the date of birth field");
								document.getElementById("dob").focus();
								return false;
					}
			  if(document.getElementById("pob").value == "")
					{
								alert("Kindly check the place of birth field");
								document.getElementById("pob").focus();
								return false;
					}
			  if(document.getElementById("nat").value == "")
					{
								alert("Kindly check the Nationality field");
								document.getElementById("nat").focus();
								return false;
					}		
			  if(document.getElementById("prof").value == "")
					{
								alert("Kindly check the Profissional field");
								document.getElementById("prof").focus();
								return false;
					}
		
					xx = document.getElementById("email");
			if(!chkvalidemail(xx))
			{
				return false;
			}
		/// files validation checking for individual //////////////////
		 if(document.getElementById(indv_type))
					{
						if(document.getElementById(indv_type).style.display == "block")
							{
							 return chkFiles();
							}
						else{
							 alert("Kindly choose your Individual account type");
							return false;
							}
					}
			  else if(!document.getElementById(indv_type)){ alert("Kindly choose your Individual account type");return false;}
			}
//******************************************************************
		if(document.getElementById("account_type").value == "corp")
			{
				if(document.getElementById("compname").value == "")
					{
					alert("Kindly check the company name");
					document.getElementById("compname").focus();
					return false;
					}
				if(document.getElementById("tradename").value == "")
					{
					alert("Kindly check the trade name field");
					document.getElementById("tradename").focus();
					return false;
					}
				if(document.getElementById("ph_cor").value == "")
					{
					alert("Kindly check the phone number field");
					document.getElementById("ph_cor").focus();
					return false;
					}
				if(document.getElementById("add_cor").value == "")
					{
					alert("Kindly check the address field");
					document.getElementById("add_cor").focus();
					return false;
					}
				if(document.getElementById("econo").value == "")
					{
					alert("Kindly check the Economic sector field");
					document.getElementById("econo").focus();
					return false;
					}
		
			xx = document.getElementById("email2");
			if(!chkvalidemail(xx))
			{
				return false;
			}
			if(document.getElementById(cor_type))
					{
						if(document.getElementById(cor_type).style.display == "block")
							{
							  return chkFiles();
							}
					}
				else{
							  alert("Kindly choose the corporate account type");
							  return false;
					}


			}// IF CORPORATE 
	}	
	
function chkvalidemail(x)
{

	if(x.value.length==0)
	{	
		alert("Kindly check the email field");		
		x.focus();
		return false;
	}
	if(x.value.indexOf(" ")> -1 )
	{
		alert("Kindly check the email field");		
		x.focus();
		return false;
	}

	if(x.value.indexOf("@")== -1 )
	{			alert("Kindly check the email field");				
		x.focus();
		return false;
	}
	if(x.value.indexOf(".")==-1)
	{
	alert("Kindly check the email field");			
		x.focus();
		return false;
	}
	if(x.value.indexOf("@")==x.value.length-1)
		{
				alert("Kindly check the email field");				
			x.focus();
			return false;
		}
    if(x.value.indexOf(".")==0)
		{
			alert("Kindly check the email field");				
		x.focus();
		return false;
		}
	return true;}
	
function chkArr(x)
{
	count=0;
		for(i=0;i<arr_index;i++)
			{
 				if(x == files_name[i])
				{	count++;}
			}
 	if(count > 0) return false;
	else return true;
	}
	
function submitForms()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
		
		document.Frm_grid.action = "editLGForm.php";
		document.Frm_grid.method = "post";
		document.Frm_grid.submit();
	}
	else
		alert('Please select the row!');	}

function saveLG()
{
	  if(checkLG())
	  {
		document.Frm_LG.action = "editLGForm.php";
		document.Frm_LG.method = "post";
		document.Frm_LG.submit();
	 }}

function checkLG()
{	
	txtName = document.getElementById('txt_name');
	MaliTO = document.getElementById('mail_to');
	MailCC = document.getElementById('mail_cc');
	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(MaliTO.value) == ""){
		alert('Please enter the email!');
		MaliTO.focus();
		return false;	
	}
	else if(!emailpat.test(Trim(MaliTO.value))){
		alert('Please enter a valid email address');
		MaliTO.focus();
		return false;	
	}
	else if(Trim(MailCC.value) != "")
	{
		if(!emailpat.test(Trim(MailCC.value))){
		alert('Please enter a valid email address');
		MailCC.focus();
			return false;
		}
		else
			return true;
	}
	else
		return true;}

function submitFormsUser()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
		
		document.Frm_grid.action = "user_form.php";
		document.Frm_grid.method = "post";
		document.Frm_grid.submit();
	}
	else
		alert('Please select the row!');	}
				
function checkUser()
{
	
		
	txtName = document.Frm_UserForm.txt_name;
	txtUser = document.Frm_UserForm.txt_user;
	txtPass = document.Frm_UserForm.txt_pass;
	txtRepass = document.Frm_UserForm.txt_repass;
	
	if(Trim(txtName.value) == ""){
		alert('Please enter the name!');
		txtName.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(checkUser())
	  {
		document.Frm_UserForm.action = "edituser_form.php";
		document.Frm_UserForm.method = "post";
		document.Frm_UserForm.submit();
	 }}

function deleteUser()
{
	SelectId = document.Frm_grid.selectedId.value ;
	
	if(SelectId != ""){
		if(confirm("Are you sure about delete this row?")){
			location = "user_form.php?id="+SelectId;
			
		}
	}
	else
		alert('Please select the row!');}

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

	date11 = document.Frm_Third.date1;
	txt1 = document.Frm_Third.txt_1;
	txt2 = document.Frm_Third.txt_2;
	txt3 = document.Frm_Third.txt_3;
	txt4 = document.Frm_Third.txt_4;
	txt5 = document.Frm_Third.txt_5;
	txt6 = document.Frm_Third.txt_6;
	txt7 = document.Frm_Third.txt_7;
	txt8 = document.Frm_Third.txt_8;
	txt9 = document.Frm_Third.txt_9;
	
	if(Trim(date11.value) == ""){
		alert('Please fill All field!');
		date11.focus();
		return false;
	}
	else if(Trim(txt1.value) == ""){
		alert('Please fill All field!');
		txt1.focus();
		return false;	
	}	
	else if(Trim(txt2.value) == ""){
		alert('Please fill All field!');
		txt2.focus();
		return false;	
	}	
	else if(Trim(txt3.value) == ""){
		alert('Please fill All field!');
		txt3.focus();
		return false;	
	}	
	else if(Trim(txt4.value) == ""){
		alert('Please fill All field!');
		txt4.focus();
		return false;	
	}	
	else if(Trim(txt5.value) == ""){
		alert('Please fill All field!');
		txt5.focus();
		return false;	
	}	
	else if(Trim(txt6.value) == ""){
		alert('Please fill All field!');
		txt6.focus();
		return false;	
	}	
	else if(Trim(txt7.value) == ""){
		alert('Please fill All field!');
		txt7.focus();
		return false;	
	}		
	else if(Trim(txt8.value) == ""){
		alert('Please fill All field!');
		txt8.focus();
		return false;	
	}	
	else if(Trim(txt9.value) == ""){
		alert('Please fill All field!');
		txt9.focus();
		return false;	
	}		
    else
		return true;
}

function checkThird2()
{

	date12 = document.Frm_Third.date2;
	date13 = document.Frm_Third.date3;
	date14 = document.Frm_Third.date4;
	
    txt6 = document.Frm_Third.txt_6;
	txt7 = document.Frm_Third.txt_7;
	txt8 = document.Frm_Third.txt_8;
	txt9 = document.Frm_Third.txt_9;
	txt10 = document.Frm_Third.txt_10;
    txt11 = document.Frm_Third.txt_11;
    txt12 = document.Frm_Third.txt_12;
    txt13 = document.Frm_Third.txt_13;
    txt14 = document.Frm_Third.txt_14;
    txt15 = document.Frm_Third.txt_15;	
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
	
	if(Trim(date12.value) == ""){
		alert('Please fill All field!');
		date12.focus();
		return false;
	}
	else if(Trim(txt6.value) == ""){
		alert('Please fill All field!');
		txt6.focus();
		return false;	
	}	
	else if(Trim(txt7.value) == ""){
		alert('Please fill All field!');
		txt7.focus();
		return false;	
	}	
	else if(Trim(txt8.value) == ""){
		alert('Please fill All field!');
		txt8.focus();
		return false;	
	}	
	else if(Trim(txt9.value) == ""){
		alert('Please fill All field!');
		txt9.focus();
		return false;	
	}	
	else if(Trim(date13.value) == ""){
		alert('Please fill All field!');
		date13.focus();
		return false;	
	}	
	else if(Trim(date14.value) == ""){
		alert('Please fill All field!');
		date14.focus();
		return false;	
	}
	else if(Trim(txt10.value) == ""){
		alert('Please fill All field!');
		txt10.focus();
		return false;	
	}
	else if(Trim(txt11.value) == ""){
		alert('Please fill All field!');
		txt11.focus();
		return false;	
	}
	else if(Trim(txt12.value) == ""){
		alert('Please fill All field!');
		txt12.focus();
		return false;	
	}
	else if(Trim(txt13.value) == ""){
		alert('Please fill All field!');
		txt13.focus();
		return false;	
	}
	else if(Trim(txt14.value) == ""){
		alert('Please fill All field!');
		txt14.focus();
		return false;	
	}
	else if(Trim(txt15.value) == ""){
		alert('Please enter the email!');
		txt15.focus();
		return false;	
	}
	else if(!emailpat.test(Trim(txt15.value))){
		alert('Please enter a valid email address');
		txt15.focus();
		return false;	
	}
	else
		return true;
		

}

function checkLoginForm()
{
	//Frm_Forms
	userName = document.getElementById('txt_username');
	txtPassword = document.getElementById('txt_password');
	
	if(Trim(userName.value) == ""){
		alert('Please enter the username!');
		userName.focus();
		return false;
	}
	else if(Trim(txtPassword.value) == ""){
		alert('Please enter the password!');
		txtPassword.focus();
		return false;
	}
	else
		return true;
}

function submitFormLogin()
{
	if(checkLoginForm())
		document.Frm_Forms.submit();
			
}

function checkLoginFormAr()
{
	//Frm_Forms
	userName = document.getElementById('txt_username');
	txtPassword = document.getElementById('txt_password');
	
	if(Trim(userName.value) == ""){
		alert('!الرجاء إدخال اسم المستخدم');
		userName.focus();
		return false;
	}
	else if(Trim(txtPassword.value) == ""){
		alert('!الرجاء إدخال كلمة المرور');
		txtPassword.focus();
		return false;
	}
	else
		return true;
}
