﻿function validate_articles(nform){
	if(nform.subjid.value==''){
		alert("الرجاء إختيار الموضوع");
		nform.subjid.focus();
		return false;
	}
	if(nform.authid.value==''){
		alert("الرجاء إختيار المؤلف");
		nform.authid.focus();
		return false;
	}
	if(nform.btitle.value==''){
		alert("الرجاء إدخال العنوان");
		nform.btitle.focus();
		return false;
	}
	if(nform.date.value==''){
		alert("الرجاء إدخال التاريخ");
		nform.date.focus();
		return false;
	}
	return true;
}
function validate_book(nform){
	if(nform.subjid.value==''){
		alert("الرجاء إختيار الموضوع");
		nform.subjid.focus();
		return false;
	}
	if(nform.btitle.value==''){
		alert("الرجاء إدخال العنوان");
		nform.btitle.focus();
		return false;
	}
	if(nform.authid.value==''){
		alert("الرجاء إختيار المؤلف");
		nform.authid.focus();
		return false;
	}
	if(nform.coverid.value==''){
		alert("الرجاء إختيار الغلاف");
		nform.coverid.focus();
		return false;
	}
	if(nform.papers.value==''){
		alert("الرجاء إدخال الصفحات");
		nform.papers.focus();
		return false;
	}
	if(nform.sizes.value==''){
		alert("الرجاء إدخال القياس");
		nform.sizes.focus();
		return false;
	}
	if(nform.price.value==''){
		alert("الرجاء إدخال السعر");
		nform.price.focus();
		return false;
	}
	if(nform.picture1.value==''){
		alert("الرجاء إدخال الصورة الكبيرة");
		nform.picture1.focus();
		return false;
	}
	return true;
}
function validate_onefield(nform){
	if(!nform.t_name.value){
		alert("الرجاء إدخال المعلومات");
		nform.t_name.focus();
		return false;
	}
	return true;
}

function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++){
		  if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
			  theForm[z].checked = theElement.checked;
		  }
	}
}


function modify_rank(id,oldorder){
	var newsort=prompt("Enter new rank",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<1){
		alert("The rank should start from 1 and higher");
		return false;
	}
	window.location=spage+"?do=update&id="+id+"&rank="+newsort;
}
function modify_jobrank(id,oldorder){
	var newsort=prompt("ادخل الترتيب الجديد",oldorder)
	var spage=getpage();
	if(newsort==null){
		return false;
	}
	if(newsort<1){
		alert("يجب ان يكون الترتيب أكبر من 1");
		return false;
	}
	window.location=spage+"?do=updaterank&id="+id+"&rank="+newsort;
}
function modify_rank1(id,oldorder,pid){
	var newsort=prompt("Enter new rank",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<1){
		alert("The rank should start from 1 and higher");
		return false;
	}
	window.location=spage+"?do=update&id="+id+"&rank="+newsort+"&pid="+pid;
}
function validate_delete(){
	return confirm("متابعة الإلغاء؟");
}
function pick(x){
  window.opener.form.author.value=x
  window.close()
}
function getpage(){
	var sPath = window.location.pathname;
	//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return sPage;
}



function IsValidEmail(NForm){
        NForm.email.focus();
        var str = NForm.email.value; 
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
        if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid 
                return true; 
        }else{ 
                alert("Enter a valid Email Address");
                return false; 
        } 
}
function modify_jobstatus(ext,oldorder){
	var newsort=prompt("ادخل الرقم 1 لنعم و 0 للا",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<0 && newsort>1){
		alert("ادخل الرقم 1 لنعم و 0 للا");
		return false;
	}
	window.location=spage+"?"+ext+"&status="+newsort;
}

function modify_status(ext,oldorder){
	var newsort=prompt("Enter new number",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<0){
		alert("يجب ان يكون الرقم أكبر أو مساوى ل 0");
		return false;
	}
	window.location=spage+"?"+ext+"&status="+newsort;
}
function validate_contactus(nform){
	if(!nform.name.value){
		alert("Please enter your name");
		nform.name.focus();
		return false; 
	}
	if(!nform.company.value){
		alert("Please enter your company name");
		nform.company.focus();
		return false; 
	}
	if(!nform.address.value){
		alert("Please enter your address");
		nform.address.focus();
		return false; 
	}
	if(!nform.phone.value){
		alert("Please enter your phone number");
		nform.phone.focus();
		return false; 
	}
	if(!nform.country.value){
		alert("Please enter your country");
		nform.country.focus();
		return false; 
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	if(!nform.message.value){
		alert("Please enter your message");
		nform.message.focus();
		return false; 
	}
	return true; 
}
function Open_url(spage,swidth,sheight,scrolls,leftpx,toppx,resize){
	var OpenWindow=window.open(spage,"logwindow",'left='+leftpx+',top='+toppx+',height='+sheight+',width='+swidth+',scrollbars='+scrolls+',toolbar=0,resizable='+resize+',addressbar=0');
	OpenWindow.focus();
	return false;
}

function validate_brand(nform){
	if(!nform.bname.value){
		alert("Brand name required!");
		return false;
	}
	return true;
}
function changeSty(classpassed,id){
	document.getElementById(id).className=classpassed;
}
function onclicktd(urlset){
	window.location=urlset;
}

function validate_mobile(nform){
	if(nform.brandid.value==0){
		alert("Brand name required!");
		nform.bid.focus();
		return false;
	}
	if(!nform.model.value){
		alert("Mode Required!");
		nform.model.focus();
		return false;
	}
	if(!nform.bphoto.value && !nform.sphoto.value){
		alert("you must enter at least 1 photo!");
		nform.bphoto.focus();
		return false;
	}
	
	return true;
}
function validate_group(nform){
	if(!nform.fieldname.value){
		alert("Group name required!");
		nform.fieldname.focus();
		return false;
	}
	return true;
}
function validate_booksearch(nform){
	if(nform.subjid.value=='' && nform.btitle.value=='' && nform.authid.value=='' && nform.isbn.value=='' ){
		x=1;
	}else{
			x=0;
	}
	if(x==1){
		alert("الرجاء إختيار البحث");
		return false;
}
	return true;
}

function openbook(id){
	return Open_url('book.php?id='+id,'600',450,1,150,150,0);
}
function handler(e){
	var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if (key == 110)
		return false;
	if ((key > 36 && key < 41) || key == 9 || key == 8 || key == 13 || key == 46 || (key > 47 && key < 58) || (key > 95 && key < 106) || (key==109) || (key==189))
		return true; 
	else
		return false;
}
function checkqty(nform){
	if(isNaN(nform.qty.value)){
		alert("الرجاء التأكد من إدخال الكمية");
		return false;
	}
	if(nform.qty.value<1 || nform.qty.value=='الكمية'){
			alert('أقل كمية مسموحة : 1');
			return false;
	}
	return true;
}
function showhide2ids(id1,id2){
	
	var target1 = document.getElementById(id1);
	var target2 = document.getElementById(id2);
	target1.style.display = 'none'; 
	target2.style.display = ''; 
	return false;
}
function validate_login_form(nform){
	if(!nform.username.value){
		alert("الرجاء ادخال إسم المستخدم");
		nform.username.focus();
		return false;
	}
	if(!nform.pass.value){
		alert("الرجاء ادخال كلمة المرور");
		nform.pass.focus();
		return false;
	}
	return true;
}
function validate_register(nform){
	if(!nform.username.value){
		alert("الرجاء ادخال إسم المستخدم");
		nform.username.focus();
		return false;
	}
	if(!nform.pass1.value){
		alert("الرجاء ادخال كلمة المرور");
		nform.pass1.focus();
		return false;
	}
	if(!nform.pass2.value){
		alert("الرجاء ادخال تأكيد كلمة المرور");
		nform.pass2.focus();
		return false;
	}
	if(nform.pass1.value!=nform.pass2.value){
		alert("كلمة المرور لم تتطابق مع التأكيد");
		nform.pass2.focus();
		return false;
	}
	if(!nform.fname.value){
		alert("الرجاء ادخال الإسم");
		nform.fname.focus();
		return false;
	}

	if(!nform.country.value){
		alert("الرجاء ادخال البلد");
		nform.country.focus();
		return false;
	}
	if(!nform.tel.value){
		alert("الرجاء ادخال الهاتف");
		nform.tel.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	return true;
}
function IsValidEmail(NForm){
        NForm.email.focus();
        var str = NForm.email.value; 
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/; // valid 
        if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid 
                return true; 
        }else{ 
              	alert("الرجاء ادخال بريد الكتروني صالح");
                return false; 
        } 
}
function validate_shiipingform(nform){
	if(!nform.fname.value){
		alert("الرجاء ادخال الإسم");
		nform.fname.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	if(!nform.add.value){
		alert("الرجاء ادخال العنوان");
		nform.add.focus();
		return false;
	}
	if(!nform.city.value){
		alert("الرجاء ادخال المدينة");
		nform.city.focus();
		return false;
	}
	if(!nform.country.value){
		alert("الرجاء ادخال البلد");
		nform.country.focus();
		return false;
	}
	if(!nform.tel.value){
		alert("الرجاء ادخال الهاتف");
		nform.tel.focus();
		return false;
	}
	return true;
}
function validate_update(nform){
	if(!nform.fname.value){
		alert("الرجاء ادخال الإسم");
		nform.fname.focus();
		return false;
	}

	if(!nform.country.value){
		alert("الرجاء ادخال البلد");
		nform.country.focus();
		return false;
	}
	if(!nform.tel.value){
		alert("الرجاء ادخال الهاتف");
		nform.tel.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	return true;
}
function openforgotpass(){
	var OpenWindow=window.open("forgotpassword.php","logwindow",'left=350,top=250,height=190,width=450,toolbar=0,resizable=0,addressbar=0');
	return false;
}
function openchangepass(){
	var OpenWindow=window.open("changepass.php","logwindow",'left=350,top=250,height=190,width=450,toolbar=0,resizable=0,addressbar=0');
	return false;
}
function validatechangepass(nform){
	if(!nform.pass.value){
		alert("الرجاء ادخال كلمة المرور القديمة");
		nform.pass.focus();
		return false;
	}
	if(!nform.pass1.value){
		alert("الرجاء ادخال كلمة المرور");
		nform.pass1.focus();
		return false;
	}
	if(!nform.pass2.value){
		alert("الرجاء ادخال تأكيد كلمة المرور");
		nform.pass2.focus();
		return false;
	}
	if(nform.pass1.value!=nform.pass2.value){
		alert("كلمة المرور لم تتطابق مع التأكيد");
		nform.pass2.focus();
		return false;
	}
	return true;

}
function doPreview_book(file,folder) {
    var src = file;
	if(file=='../images/spacer.gif')
	 document.all.viewimage.style.display='none';
	 else
	 document.all.viewimage.style.display='';
    document.all.viewimage.src=folder+src;
}
function OpenOrder(id){
	var OpenWindow=window.open("openorders.php?id="+id,"logwindow",'left=150,top=100,height=500,width=700,toolbar=0,resizable=0,addressbar=0');
	OpenWindow.focus();
	return false;
}
function validatecontct(nform){
	if(!nform.fullname.value){
		alert("الرجاء ادخال الإسم");
		nform.fullname.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	if(!nform.country.value){
		alert("الرجاء ادخال البلد");
		nform.country.focus();
		return false;
	}

	if(!nform.subject.value){
		alert("الرجاء ادخال الموضوع!");
		nform.subject.focus();
		return false;
	}
	if(!nform.message.value){
		alert("الرجاء ادخال التعليق!");
		nform.message.focus();
		return false;
	}
	return true;
}
function modify_userstatus(id,oldorder){
	var newsort=prompt("الرجاء ادخال الحالة",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<0){
		alert("يجب ان تكون الحالة 0 او 1");
		return false;
	}
	window.location=spage+"?do=ustatus&id="+id+"&status="+newsort;
}
function validate_applyform(nform){
	if(!nform.fullname.value){
		alert("Enter your Full Name");
		nform.fullname.focus();
		return false;
	}
	if(!nform.phone.value){
		alert("Enter your Phone Number");
		nform.phone.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	if(!nform.country.value){
		alert("Choose your Country");
		nform.country.focus();
		return false;
	}
	if(!nform.file.value){
		alert("Choose your CV file");
		nform.file.focus();
		return false;
	}
	return true;
}