function has_special_char(str) {
	for(var i = 0; i <str.length; i++) {
		var charat = str.charAt(i);
		if(charat == '`' || charat == '~'  || charat == '!'  || charat == '@'  || charat == '#'  || charat == '$'  || charat == '%'  || charat == '^'  || charat == '&'  || charat == '*'  || charat == '('  || charat == ')'  ||
				charat == '`'  || charat == '<'  || charat == '>'  || charat == ';'  || charat == ','  || charat == '|'  || charat == '\\'  || charat == '/'  || charat == '?' || charat == '+' || charat == '=') {
			return true;
		}
	}
	return false;
}
function testuser(obj) {
    for(var i = 0; i < obj.value.length; i++) {
    	var charcode = obj.value.charCodeAt(i);
    	/* A-Z */
 		if(charcode >= 0x41 && charcode <= 0x5A) {
	        continue;
		}

		/* a-z */
		if(charcode >= 0x61 && charcode <= 0x7A) {
			continue;
		}

		/* 0-9 */
		if(charcode >= 0x30 && charcode <= 0x39) {
			continue;
		}

		/* . - _ */
		if(charcode == 0x2D || charcode == 0x5F) {
			continue;
		}
		return false;
	}
	return true;
}

function valid_password(str) {
	for(var i = 0; i < str.length; i++) {
		var charcode = str.charCodeAt(i);
		/* A-Z */
		if(charcode >= 0x41 && charcode <= 0x5A) {
			continue;
		}

        /* a-z */
		if(charcode >= 0x61 && charcode <= 0x7A) {
			continue;
		}

        /* 0-9 */
		if(charcode >= 0x30 && charcode <= 0x39) {
			continue;
		}

		return false;
    }
    return true;

}

function testemail(obj) {
    var atpos = obj.value.indexOf('@');
    if(atpos == -1)
    {
		return false;
	 }
	if(atpos == 0) {
		return false;
	}
	var dotpos = obj.value.indexOf('.', atpos+2);
	if( dotpos == -1) {
		return false;
	}
	if(dotpos == (obj.value.length - 1) ) {
		return false;
	}
	return true;
}

function validate_ar()
{
   if(document.frm.fname.value == "") {
		window.alert("الرجاء ادخال الاسم الأول");
		document.frm.fname.focus();
		return false;
	}

	if(has_special_char(document.frm.fname.value)) {
		window.alert("الرجاء عدم استخدام الأحرف الخاصة في الاسم الأول");
		document.frm.fname.focus();
        return false;
	}

    /* add_lang_sn */
    if(document.frm.lname.value == "") {
        window.alert("الرجاء ادخال اسم العائلة");
        document.frm.lname.focus();
        return false;
    }

    if(has_special_char(document.frm.lname.value)) {
		window.alert("الرجاء عدم استخدام الأحرف الخاصة في اسم العائلة");
		document.frm.lname.focus();
        return false;
	}
    /* email */
    if(document.frm.email.value == "") {
        window.alert("الرجاء كتابة البريد الالكتروني");
        document.frm.email.focus();
        return false;
    }
    if(!testemail(document.frm.email))
    {
            window.alert('يجب كتابه البريد بشكل صحيح');
            document.frm.email.focus();
            return false;
    }

    /* gender */
    if(document.frm.gender.value == "") {
        window.alert("الرجاء اختيار جنس");
        document.frm.gender.focus();
        return false;
    }

    /* countryRES */
    if(document.frm.countryRES.value == "") {
        window.alert("الرجاء ادخال بلد الاقامة");
        document.frm.countryRES.focus();
        return false;
    }

    /* nationality */
    if(document.frm.nationality.value == "") {
        window.alert('الرجاء اختيار الجنسية');
        document.frm.nationality.focus();
        return false;
    }
/*create_user */
    if(document.frm.username.value == "") {
        window.alert("الرجاء ادخال اسم الدخول");
        document.frm.username.focus();
        return false;
    }
    if(!testuser(document.frm.username)) {
        window.alert("(-) والأرقام 0-9 و(_) و a-z اسم الدخول يمكن ان يحتوي فقط على الاحرف ");
        document.frm.username.focus();
        return false;
    }
    if(document.frm.username.value.length > 32) {
    	window.alert("اسم الدخول يجب أن يكون أقل من 32 حرف");
        document.frm.username.focus();
        return false;
    }
    /* newpassword & newpasswordconfirm */
    if(document.frm.newpassword.value == "") {
        window.alert("الرجاء اختيار كلمة سر");
        document.frm.newpassword.focus();
        return false;
    }

   if(!valid_password(document.frm.newpassword.value)) {
  	window.alert("الرجاء استخدام فقط احرف انجليزية في كلمة السر");
   	document.frm.newpassword.focus();
       	return false;
    }

    if(document.frm.newpassword.value.length < 6) {
        window.alert("كلمة السر يجب أن تكون 6 أحرف أو أكثر");
        document.frm.newpassword.focus();
        return false;
    }
    if(document.frm.newpassword.value.length > 20) {
        window.alert("كلمة السر يجب أن تكون أقل من 20 حرف");
        document.frm.newpassword.focus();
        return false;
    }
    if(document.frm.newpassword.value.toLowerCase() == document.frm.username.value.toLowerCase()) {
	window.alert('كلمة السر واسم الدخول يجب أن لا يتطابقا');
        document.frm.newpassword.focus();
        return false;
    }
    if(document.frm.newpassword.value != document.frm.newpasswordconfirm.value) {
        window.alert("كلمات السر لا تتوافق");
        document.frm.newpasswordconfirm.focus();
        return false;
    }

   /* bmon */
    if(document.frm.bmon.value == "") {
        window.alert("الرجاء اختيار شهر الميلاد");
        document.frm.bmon.focus();
        return false;
    }

    /* bday */
    if(document.frm.bday.value == "" || document.frm.bday.value == "dd") {
        window.alert("الرجاء ادخال يوم الميلاد");
        document.frm.bday.focus();
        return false;
    }
    if(isNaN(document.frm.bday.value)) {
        window.alert("الرجاء استعمال الأرقام فقط في يوم الميلاد");
        document.frm.bday.focus();
        return false;
    }

    if(parseInt(document.frm.bday.value) > 31 || (document.frm.bday.value) < 1) {
        window.alert("الرجاء استخدام يوم ميلاد صحيح");
        document.frm.bday.focus();
        return false;
    }
    if(document.frm.byear.value == "" || document.frm.byear.value == "yyyy") {
        window.alert("الرجاء ادخال سنة الميلاد");
        document.frm.byear.focus();
        return false;
    }
    if(isNaN(document.frm.byear.value)) {
        window.alert("الرجاء استخدام الأرقام فقط في سنة الميلاد");
        document.frm.byear.focus();
        return false;
    }

    /* occupation */
    if(document.frm.occupation.value == "") {
        window.alert("الرجاء اختيار مهنة");
        document.frm.occupation.focus();
        return false;
    }

    /* industry */
    if(document.frm.eindustry.value == "") {
        window.alert('الرجاء اختر لقطاع');
        document.frm.eindustry.focus();
        return false;
    }
    /* Cummnaity */
    if(document.frm.community.value == "") {
        window.alert("الرجاء اختيار الطائفه");
        document.frm.community.focus();
        return false;
    }
    /* charch */
    if(document.frm.charch.value == "") {
        window.alert("الرجاء كتابه اسم الكنيسه");
        document.frm.charch.focus();
        return false;
    }
    /* code */
    if(document.frm.code.value == "") {
        window.alert("الرجاء طباعة الرقم الذي يظهر في المربع");
        document.frm.code.focus();
        return false;
    }

        /* C1 */
    if(document.frm.agree.checked == false) {
        window.alert("الرجاء التأكيد على اتفاقية الخدمة وخصوصية مكتوب");
        document.frm.agree.focus();
        return false;
    }

}

function checkvalue()
{
 if(document.frm.newpassword.value != document.frm.newpasswordconfirm.value) {
        document.getElementById('checknewpassword').innerHTML = "كلمات السر لا تتوافق";
        document.frm.newpasswordconfirm.focus();
        return false;
    }

}