﻿// JavaScript Document


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

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

function saveContact()
{
			document.Frm_Info.action = "contact.php";
			document.Frm_Info.method = "post";
			document.Frm_Info.submit();
	
}

function checkContact()
{
	txtName = document.Frm_Contact.txt_name;
	txtPhone = document.Frm_Contact.txt_phone;
	txtMail = document.Frm_Contact.txt_mail;
	txtMesg = document.Frm_Contact.txt_mesg;
	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(txtPhone.value) == ""){
		alert('Please enter the phone!');
		txtPhone.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(txtMesg.value) == ""){
		alert('Please enter the message!');
		txtMesg.focus();
		return false;	
	}	
	else
		return true;
}

function checkContactAr()
{
	txtName = document.Frm_Contact.txt_name;
	txtPhone = document.Frm_Contact.txt_phone;
	txtMail = document.Frm_Contact.txt_mail;
	txtMesg = document.Frm_Contact.txt_mesg;
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
	
	if(Trim(txtName.value) == ""){
		alert('!الرجاء إدخال الاسم');
		txtName.focus();
		return false;
	}
	else if(Trim(txtPhone.value) == ""){
		alert('!الرجاء إدخال رقم الهاتف');
		txtPhone.focus();
		return false;	
	}		
	else if(Trim(txtMail.value) == ""){
		alert('!الرجاء إدخال البريد الالكتروني');
		txtMail.focus();
		return false;	
	}
	else if(!emailpat.test( Trim(txtMail.value))){
		alert('!الرجاء إدخال البريد الالكبروني بشكل صحيح');
		txtMail.focus();
		return false;	
	}
	else if(Trim(txtMesg.value) == ""){
		alert('!الرجاء إدخال التعليق');
		txtMesg.focus();
		return false;	
	}	
	else
		return true;
}

function goToForm(mailTo)
{
	location = "contact_form.php?mailTO="+mailTo;
}