﻿// JavaScript Document

function Trim(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
} // IsNumeric(sText)


function IsInteger(num)
{
   var Int = parseInt(num);
   var Flt = parseFloat(num);
   
   return (Int == Flt)
}


function Isemail(str) {

	var at = "@"
	var dot = "."
	var lat = str.indexOf(at)
	var lstr = str.length
	var ldot = str.indexOf(dot)
		
		
	if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr || str.indexOf(at) == lstr-1)
		return false ;
		

	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr || str.indexOf(dot) == lstr-1)
		return false ;


	if (str.indexOf(at,(lat+1)) != -1)
		return false ;

	
	if (str.substring(lat-1,lat) == dot || str.substring(lat+1,lat+2) == dot)
		return false ;


	if (str.indexOf(dot,(lat+2)) == -1)
		return false ;
		
	
	if (str.indexOf(" ") != -1)
		return false ;
			
}


function Careers_Validate(frmCareers,lang)
{
	Name = frmCareers.Name ;
	Email = frmCareers.Email ;
	DoB = frmCareers.DoB ;
	Major = frmCareers.Major ;
	Phone = frmCareers.Phone ;
	Country = frmCareers.Country ;
	City = frmCareers.City ;
	CovLeter = frmCareers.CovLet ;
	
	if (lang == "en")
	{
		NameMsg = 'Kindly inseret your name!' ;	
		EmailMsg = 'Kindly inseret your Email!' ;
		DoBMsg = 'Kindly inseret your birth date!' ;
		GenderMsg = 'Kindly select your gender!' ;
		PhoneMsg = 'Kindly inseret your phone number!' ;
		CountryMsg = 'Kindly select your country!' ;
		CityMsg = 'Kindly inseret your city!' ;
		CovLeterMsg = 'Your srtucle should not exceed 1000 characters' ;
	}
	else
	{
		NameMsg = '!الرجاء إدخال الإسم' ;	
		EmailMsg = '!الرجاء إدخال الإيميل' ;
		DoBMsg = '!الرجاء إدخال تاريخ الميلاد' ;
		GenderMsg = '!الرجاء إختيار الجنس' ;
		PhoneMsg = '!الرجاء إدخال رقم الهاتف' ;
		CountryMsg = '!الرجاء إختيار الدولة' ;
		CityMsg = '!الرجاء إدخال المدينة' ;
		CovLeterMsg = 'المقالة يجب أن لا تتجاوز ال 1000 حرف' ;
	}
	
	if (Trim(Name.value) == "" )
	{
		alert(NameMsg) ;
		Name.focus() ;
		return false ;
	}
	
	if (Trim(Email.value) == "" )
	{
		alert(EmailMsg) ;
		Email.focus() ;
		return false ;
	}
	
	if (DoB.value == "" )
	{
		alert(DoBMsg) ;
		DoB.focus() ;
		return false ;
	}
	
	if (Trim(Major.value) == "" )
	{
		alert(MajorMsg) ;
		Major.focus() ;
		return false ;
	}
	
	if (Trim(Phone.value) == "" )
	{
		alert(PhoneMsg) ;
		Phone.focus() ;
		return false ;
	}
	
	if (Country.selectedIndex == 0 )
	{
		alert(CountryMsg) ;
		Country.focus() ;
		return false ;
	}
	
	if (Trim(City.value) == "" )
	{
		alert(CityMsg) ;
		City.focus() ;
		return false ;
	}
	
	if (CovLeter.value.length > 1000)
	{
		alert(CovLeterMsg) ;
		CovLeter.focus() ;
		return false ;
	}
} // function Careers_Validate(frmCareers,lang)


function Editor_Validate(frmEditor,lang)
{
	Title = frmEditor.title ;
	
	if (lang == "en")
		Msg = "Kindly insert the title!" ;
	else
		Msg = "!لطفا أدخل العنوان" ;
		
	if (Trim(Title.value) == "" )
	{
		alert(Msg) ;
		Title.focus() ;
		return false ;
	}
} // function Editor_Validate(frmEditor,lang)


function Banners_Validate(frmBanners,lang)
{
	ActionStatus = frmBanners.ActionStatus ;
	Bnnaer = frmBanners.image ;
	Name = frmBanners.name ;
	
	if (lang == "en")
	{
		BnnaerMsg = 'Kindly insert the banner image!' ;
		NameMsg = 'Kindly insert the banner name!' ;
	}
	else
	{
		BnnaerMsg = '!لطفا أدخل صورة البانر' ;
		NameMsg = '!لطفا أدخل إسم البانر' ;
	}
	
	if (ActionStatus.value == 'new')
	{
		if (Trim(Bnnaer.value) == "")
		{
			alert (BnnaerMsg) ;
			Bnnaer.focus() ;
			return false ;
		}
	}
	
	if (Trim(Name.value) == "")
		{
			alert (NameMsg) ;
			Name.focus() ;
			return false ;
		}
} // function Banners_Validate(frmBanners,lang)


function Users_Validate(frmUsers,lang)
{
	UserName = frmUsers.uName
	Password = frmUsers.uPass
	
	if (lang == "en")
	{
		uNameMsg = 'Kindly insert the user name!' ;
		uPassMsg = 'Kindly insert the password!' ;
	}
	else
	{
		uNameMsg = '!لطفا أدخل إسم المستخدم' ;
		uPassMsg = '!لطفا أدخل كلمة المرور' ;
	}
	
	if (Trim(UserName.value) == "")
	{
		alert(uNameMsg) ;
		UserName.focus() ;
		return false ;
	}
	
	if (Trim(Password.value) == "")
	{
		alert(uPassMsg) ;
		Password.focus() ;
		return false ;
	}
	
} // function Users_Validate()


function Locate_Area_Validate(frmArea,lang)
{
	AreaName = frmArea.AreaName
	
	if (lang == "en")
		AreaNameMsg = 'Kindly insert the area name!' ;
	else
		AreaNameMsg = '!لطفا أدخل إسم المنطقة' ;
	
	if (Trim(AreaName.value) == "")
	{
		alert(AreaNameMsg) ;
		AreaName.focus() ;
		return false ;
	}
} // function Locate_Area_Validate()


function Locate_Dir_Validate(frmDir,lang)
{
	DirName = frmDir.DirName
	
	if (lang == "en")
		DirNameMsg = 'Kindly insert the directorate name!' ;
	else
		DirNameMsg = '!لطفا أدخل إسم المديرية' ;
	
	if (Trim(DirName.value) == "")
	{
		alert(DirNameMsg) ;
		DirName.focus() ;
		return false ;
	}
} // function Locate_Dir_Validate()


function Locate_Offices_Validate(frmOffic,lang)
{
	OffName = frmOffic.OffName ;
	OffPhone = frmOffic.OffPhone ;
	OffFax = frmOffic.OffFax ;
	OffAddress = frmOffic.OffAddress ;
	
	if (lang == "en")
	{
		OffNameMsg = 'Kindly insert the post office name!' ;
		OffPhoneMsg = 'Kindly insert the phone number!' ;
		OffFaxMsg = 'Kindly insert the fax number!' ;
		OffAddressMsg = 'Kindly insert the post office address!' ;
	}
	else
	{
		OffNameMsg = '!لطفا أدخل إسم مكتب البريد' ;
		OffPhoneMsg = '!لطفا أدخل رقم الهاتف' ;
		OffFaxMsg = '!لطفا أدخل رقم الفاكس' ;
		OffAddressMsg = '!لطفا أدخل عنوان مكتب البريد' ;
	}
	
	if (Trim(OffName.value) == "")
	{
		alert(OffNameMsg) ;
		OffName.focus() ;
		return false ;
	}
	
	if (Trim(OffPhone.value) == "")
	{
		alert(OffPhoneMsg) ;
		OffPhone.focus() ;
		return false ;
	}
	
	if (Trim(OffFax.value) == "")
	{
		alert(OffFaxMsg) ;
		OffFax.focus() ;
		return false ;
	}
	
	if (Trim(OffAddress.value) == "")
	{
		alert(OffAddressMsg) ;
		OffAddress.focus() ;
		return false ;
	}
} // function Locate_Offices_Validate()


function Tenders_Validate(frmTenders,lang)
{
	TenderName = frmTenders.TenName 
	TenderDesc = frmTenders.TenDesc 
	
	if (lang == "en")
	{
		NameMsg = 'Kindly insert the tender name!' ;
		DescMsg = 'Kindly insert the tender description!' ;
	}
	else
	{
		NameMsg = '!لطفا أدخل إسم العطاء' ;
		DescMsg = '!لطفا أدخل وصف العطاء' ;
	}
	

	if (Trim(TenderName.value) == "")
	{
		alert(NameMsg) ;
		TenderName.focus();
		return false;
	}
	
	
	if (Trim(TenderDesc.value) == "")
	{
		alert(DescMsg) ;
		TenderDesc.focus();
		return false;
	}

} // Tenders_Validate()


function Feed_Validate(frmFeedback,lang)
{
	FName = frmFeedback.Name ;
	FTitle = frmFeedback.Title ;
	FDetails = frmFeedback.Details ;
	
	
	if (lang == "en")
	{
		NameMsg = 'Kindly insert your name!' ;
		TitleMsg = 'Kindly insert your note title!' ;
		DetaMsg = 'Kindly insert your note!' ;
		EmailMsg = 'Kindly insert your e-mail!';
	}
	else
	{
		NameMsg = '!لطفا أدخل إسمك' ;
		TitleMsg = '!لطفا عنوان الملاحظة' ;
		DetaMsg = '!لطفا إدخل ملاحظتك' ;
		EmailMsg = '!لطفا أدخل بريدك الإلكتروني';
	}
	
	if (Trim(FName.value) == "")
	{	
		alert(NameMsg) ;
		FName.focus();
		return false;
	}
	
	if (Trim(FTitle.value) == "")
	{
		alert(TitleMsg) ;
		FTitle.focus();
		return false;
	}
	
	if (Trim(FDetails.value) == "")
	{
		alert(DetaMsg) ;
		FDetails.focus();
		return false;
	}

	if(frmFeedback.user_email.value.length == '0' || frmFeedback.user_email.value.length != '0')
	{
			
	var x = frmFeedback.user_email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!(filter.test(x))) 
	{
		alert(EmailMsg);
		frmFeedback.user_email.focus();
		return false;
	}
	
	else 
	{
		return true;}
	}
} // function Feed_Validate()


function Support_Validate(frmSupport,lang)
{
	pDate = frmSupport.pDate ;
	pDetails = frmSupport.pDetails ;
	
	if (lang == "en")
	{
		msgDate = "Kindly insert the date!" ;
		msgDetails = "Kindly insert the details!" ;
	}
	else
	{
		msgDate = "! لطفا أدخل التاريخ" ;
		msgDetails = "!لطفا أدخل تفاصيل المشكلة" ;
	}

	if (pDate.value == "")
	{
		alert(msgDate) ;
		pDate.focus();
		return false;
	}
	
	
	if(Trim(pDetails.value) == "")
	{
		alert(msgDetails) ;
		pDetails.focus();
		return false;
	}
} // Support_Validate()


function Systems_Validate(frmSystems,lang)
{
	Action = frmSystems.Action ;
	SysName = frmSystems.SystemName ;
		
	if (lang == "en")
	{
		MsgSysName = 'Kindly insert the system name!' ;
		MsgDelConfirm = 'Are you sure about delete?' ;
	}
	else
	{
		MsgSysName = 'الرجاء إدخال إسم النظام!' ;
		MsgDelConfirm = 'هل أنت متأكد من عملية الحذف؟' ;
	}
	

	if (Action.value != 'Delete')
	{
		if (Trim(SysName.value) == "")
		{
			alert(MsgSysName) ;
			SysName.focus();
			return false;
		}
	}
	else
	{
		if (confirm(MsgDelConfirm))
			return true;
		else
			return false ;
	}
} // Systems_Validate()


function Stmp_Catg_Validate(frmStamps, lang)
{
	CatName = frmStamps.CatName ;
	IssueYear = frmStamps.IssueYear ;
	
	if (lang == 0)
	{
		msgName = "Kindly insert the category name!" ;
		msgYear = "Kindly insert the category Issue year!" ;		
	}
	else
	{
		msgName = "!الرجاء إدخال إسم المجموعة" ;
		msgYear = "!الرجاء إدخال سنة إصدار المجموعة" ;
	}
	
	if (Trim(CatName.value) == "")
	{
		alert(msgName) ;
		CatName.focus();
		return false;
	}
	
	if (Trim(IssueYear.value) == "")
	{
		alert(msgYear) ;
		IssueYear.focus();
		return false;
	}
} //function Stmp_Catg_Validate()


function Stamps_Validate(frmStamps, lang)
{ 
	Status = frmStamps.Status.value ;
	Stamp = frmStamps.Stamp ;
	isChange = frmStamps.isChange ;
	StampName = frmStamps.StampName ;
	IssueDate = frmStamps.IssueDate ;
	StampPrice = frmStamps.StampPrice ;

	if (lang == 0)
	{
		msgName = "Kindly insert the stamp name!" ;
		msgDate = "Kindly insert the stamp Issue Date!" ;
		msgPrice = "Kindly insert the stamp Price!" ;
		msgStamp = "Kindly upload an image!" ;
	}
	else
	{
		msgName = "!الرجاء إدخال إسم الطابع" ;
		msgDate = "!الرجاء إدخال تاريخ الإصدار" ;
		msgPrice = "!الرجاء إدخال سعر الطابع" ;
		msgStamp = "!الرجاء تحميل صورة" ;
	}

	
	if (Status == "new")
	{
		if (Trim(Stamp.value) == "")
		{
			alert(msgStamp) ;
			Stamp.focus();
			return false;
		}		
	}
	
	
	if (Status == "edit")
	{
		if (isChange.value == "1" && Trim(Stamp.value) == "")
		{
			alert(msgStamp) ;
			Stamp.focus();
			return false;
		}		
	}
	
	
	if (Trim(StampName.value) == "")
	{
		alert(msgName) ;
		StampName.focus();
		return false;
	}
	
	
	if (Trim(IssueDate.value) == "")
	{
		alert(msgDate) ;
		IssueDate.focus();
		return false;
	}
	
	
	if (Trim(StampPrice.value) == "")
	{
		alert(msgPrice) ;
		StampPrice.focus();
		return false;
	} 
} //function Stamps_Validate()


function Pickup_Validate(frmPickup, lang)
{
	Title = frmPickup.Title ;
	Name = frmPickup.Name ;
	Cperson = frmPickup.Cperson ;
	Mobile = frmPickup.Mobile ;
	Address = frmPickup.Address ;
	Product = frmPickup.Product ;
	Country = frmPickup.Country ;
	Weight = frmPickup.Weight ;
	Cost = frmPickup.Cost ;
	Email = frmPickup.Email ;
	
	if (lang == 0)
	{
		msgTitle = "Kindly select your title!" ;
		msgName = "Kindly insert your name!" ;
		msgCperson = "Kindly insert the contact person name!" ;
		msgMobile = "Kindly insert your mobile number!" ;
		msgAddress = "Kindly insert your address!" ;
		msgProduct = "Kindly select the product you want to send!" ;
		msgCountry = "Kindly select the country you want to send to!" ;
		msgWeight = "Kindly insert the weight!" ;
		msgItemsNo = "Kindly insert the items number!" ;
		msgEmail = "Kindly insert your Email!" ;
		msgEmailValid = "The email you inserted is Invalid!" ;
	}
	else
	{
		msgTitle = "!الرجاء إختيار اللقب" ;
		msgName = "!الرجاء إدخال الإسم" ;
		msgCperson = "!الرجاء إدخال إسم الشخص المسؤول" ;
		msgMobile = "!الرجاء إدخال رقم الموبايل" ;
		msgAddress = "!الرجاء إدخال العنوان" ;
		msgProduct = "!الرجاء إختيار نوع البعيثة" ;
		msgCountry = "!الرجاء إختيار الدولة المراد الإرسال إليها" ;
		msgWeight = "!الرجاء إدخال وزن البعيثة" ;
		msgItemsNo = "!الرجاء إدخال عدد القطع المرسلة" ;
		msgEmail = "!الرجاء إدخال بريدك الإلكتروني" ;
		msgEmailValid = "!البريد الإلكتروني المدخل غير صحيح" ;
	}
	
	
	if (Country.options.selectedIndex == 0)
	{
		alert(msgCountry) ;
		Country.focus() ;
		return false ;
	}
	

	if (Product.options.selectedIndex == 0)
	{
		alert(msgProduct) ;
		Product.focus() ;
		return false ;
	}
	
	
	if (Trim(Weight.value) == "")
	{
		alert(msgWeight) ;
		Weight.focus() ;
		return false ;
	}
	
	
	if (Title.options.selectedIndex == 0)
	{
		alert(msgTitle) ;
		Title.focus() ;
		return false ;
	}
	
	if (Trim(Name.value) == "")
	{
		alert(msgName) ;
		Name.focus() ;
		return false ;
	}
	
	if (Title.options.selectedIndex == 4 || Title.options.selectedIndex == 5)
	{
		if (Trim(Cperson.value) == "")
		{
			alert(msgCperson) ;
			Cperson.focus() ;
			return false ;
		}
	}
	
	if (Trim(Mobile.value) == "")
	{
		alert(msgMobile) ;
		Mobile.focus() ;
		return false ;
	}
	
	
	if (Trim(Email.value) == "")
	{
		alert(msgEmail) ;
		Email.focus() ;
		return false ;
	} 
	
	if (Isemail(Email.value) == false)
	{
		alert(msgEmailValid) ;
		Email.focus() ;
		return false ;
	}
	
	if (Trim(Address.value) == "")
	{
		alert(msgAddress) ;
		Address.focus() ;
		return false ;
	}
} //function Pickup_Validate(frmStamps, lang)


function Subscrib_Validate(frmSubscrib, lang)
{
	Name = frmSubscrib.Name ;
	Pass1 = frmSubscrib.Password1 ;
	Pass2 = frmSubscrib.Password2 ;
	Phone = frmSubscrib.Phone ;
	Email = frmSubscrib.Email ;
	Fees = frmSubscrib.Fees ;
	Purch_Year = frmSubscrib.Purch_Year ;
	
	if (lang == 0)
	{
		msgName = "Kindly insert your name!" ;
		msgPass1 = "Kindly insert your password!" ;
		msgPass2 = "Kindly confirm your password!" ;
		msgPass3 = "Password and passwrd confirmation should be match!" ;
		msgPhone = "Kindly insert your phone!" ;
		msgLegalPhone = "Kindly insert a correct phone number!" ;
		msgEmail = "Kindly insert your email!" ;
		msgLegalEmail = "Kindly insert a legal email!" ;
		msgFees = "Kindly insert your subscription fees!" ;
		msgLegalFees = "Subscription fees should be numeric!" ;
		msgPurch = "Kindly insert your expected purchases!" ;		
	}
	else
	{
		msgName = "!الرجاء إدخال الإسم" ;
		msgPass1 = "!الرجاء إدخال كلمة المرور" ;
		msgPass2 = "!الرجاء تأكيد كلمة المرور" ;
		msgPass3 = "!كلمة المرور و التأكيد يجب أن تتطابق" ;
		msgPhone = "!الرجاء إدخال رقم الهاتف" ;
		msgLegalPhone = "!الرجاء إدخال رقم هاتف صحيح" ;
		msgEmail = "!الرجاء إدخال الإيميل" ;
		msgLegalEmail = "!الرجاء إدخال الإيميل بشكل صحيح" ;
		msgFees = "!الرجاء إدخال قيمة الإشتراك" ;
		msgLegalFees = "!قيمة الإشتراك يجب أن تكون رقمية" ;
		msgPurch = "!الرجاء إدخال قيمة المشتريات المتوقعة سنوياً" ;		
	}
	
	if (Trim(Name.value) == "")
	{
		alert(msgName) ;
		Name.focus() ;
		return false ;
	}
	
	
	if (Trim(Pass1.value) == "")
	{
		alert(msgPass1) ;
		Pass1.focus() ;
		return false ;
	}
	
	
	if (Trim(Pass2.value) == "")
	{
		alert(msgPass2) ;
		Pass2.focus() ;
		return false ;
	}
	
	
	if (Pass2.value != Pass1.value)
	{
		alert(msgPass3) ;
		Pass2.focus() ;
		return false ;
	}
	
	
	if (Trim(Phone.value) == "")
	{
		alert(msgPhone) ;
		Phone.focus() ;
		return false ;
	}
	
	
	if (! IsNumeric(Phone.value))
	{
		alert(msgLegalPhone) ;
		Phone.focus() ;
		return false ;
	}
	
	
	if (Trim(Email.value) == "")
	{
		alert(msgEmail) ;
		Email.focus() ;
		return false ;
	} 
	
	if (Isemail(Email.value) == false)
	{
		alert(msgLegalEmail) ;
		Email.focus() ;
		return false ;
	}
	
	
	if (Trim(Fees.value) == "")
	{
		alert(msgFees) ;
		Fees.focus() ;
		return false ;
	}
	
		if (! IsNumeric(Fees.value))
	{
		alert(msgLegalFees) ;
		Fees.focus() ;
		return false ;
	}
	
	if (Trim(Purch_Year.value) == "")
	{
		alert(msgPurch) ;
		Purch_Year.focus() ;
		return false ;
	}
} // function Subscrib_Validate(frmSubscrib, lang)


function OrderValidate(frmOrder, lang)
{
	Email = frmOrder.Email ;
	Code = frmOrder.Code ;
	RowsNum = frmOrder.RowsNum.value ;
	SelectedIds = frmOrder.SelectedIds.value ;
	var i ;
	
	if (lang == 0)
	{
		msgEmail = "Kindly insert your email!" ;
		msgCode = "Kindly insert your subscription code!" ;
		msgSelect = "Kindly select the stamps you want to order!" ;
		msgQuant = "Kindly Insert the quantity of the selected stamps!" ;
		msgQuantLegal = "Quantity should by integer number!" ;
	}
	else
	{
		msgEmail = "!الرجاء إدخال الإيميل" ;
		msgCode = "!الرجاء إدخال رمز الإشتراك" ;
		msgSelect = "!الرجاء إختيار الطوابع المراد شراؤها" ;
		msgQuant = "!الرجاء إدخال كمية الطوابع المختارة" ;
		msgQuantLegal = "!حقل الكمية يجب أن يكون رقمي" ;
	}
	
	
	if (Trim(Email.value) == "")
	{
		alert(msgEmail) ;
		Email.focus() ;
		return false ;
	}
	
	
	if (Trim(Code.value) == "")
	{
		alert(msgCode) ;
		Code.focus() ;
		return false ;
	}
	
	
	if (SelectedIds == "")
	{
		alert(msgSelect)
		return false ;
	}
	
	
	for (i=1; i<=RowsNum; i++)
	{
		if (eval("frmOrder.cbx" + i + ".checked"))
		{
			Quantity = eval("frmOrder.Quant" + i) ;
			
			if (Trim(Quantity.value) == "")
			{
				alert(msgQuant)
				Quantity.focus() 
				return false 
			}
			
			if (IsInteger(Quantity.value) == false)
			{
				alert(msgQuantLegal)
				Quantity.focus() 
				return false
			}
		} // if (eval("frmOrder.
	} // for (i=1; i<=Row
} // function OrderValidate(frmOrder, lang)