function change() {

	var job = document.OneTrueForm.sec_phrase1.value;
	var first_td = document.getElementById('first_td');
	var sec_td = document.getElementById('sec_td');
	var thr_td = document.getElementById('thr_td');
	
	if(job == 'other')
	{
		first_td.innerHTML = "&nbsp; ";
    	sec_td.innerHTML = "<INPUT class='formboxReg' type='text' name='job_text' value=''>";
        thr_td.innerHTML = "<span lang='ar-sa'><b>\n\t\t\t&nbsp; يمكنك كتابة مهنتك في الحقل المجاور\n\t\t</b></span>";
        thr_td.className = 'regNotes';
	}
	else
	{
		first_td.innerHTML = "&nbsp; ";
    	sec_td.innerHTML = "&nbsp; ";
        thr_td.innerHTML =  "&nbsp; ";
        thr_td.className = '';
	}
}



function addtext(what1,what2)
{
	k = "Card (1)" + " " + what1;
	document.getElementById("mydiv1").innerText = k;
	k = "البطاقة(1)" + " " + what2;
	document.getElementById("mydiv2").innerText = k;	
}

var reWhitespace = /^\s+$/;
var reDigit = /^\d/;
// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)

{   // Is s empty?
    return (isEmpty(s) || reWhitespace.test(s));
}
// Returns true if character c is a digit 
// (0 .. 9).
function isDigit (c)
{   
	for ( i=0; i < c.length; i++){
		if ( ! reDigit.test(c.charAt(i)) )
			return false;
	}
	return true;
}



function check_username(username)
{
		if(!spaces(username) || ((username.length=1)&&(username==' '))){
											  				return false;
														 }
		if(username.length==0){
			  					return false;
							  }		
		if(!wrong_test(username)) {
		  						return false;
		  					}

	return true;

}





//تابع يقوم بالتأكد أن جميع محارف السلسلة المحرفية المدخلة كبارامتر أول لا تنتمي لسلسلة أخرى مثل سلسلة الأرقام 
//أو المحارف العربية أو الأجنبية وذلك وفق البارامتر الثاني الذي يقوم بتحديد السلسلة التي سيتم المقارنة على أساسها 
function wrong_test(str)
{
	//سلسلة المحارف الأجنبية الكبيرة و الصغيرة
	string="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-_ ";
	for(i=0;i<str.length;i++){
								c=str.charAt(i);
								x=string.indexOf(c);
								if(x==-1) return false;
							}
	return true;
}

function wrong_test_names(str)
{
	//سلسلة المحارف الأجنبية الكبيرة و الصغيرة
	string="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	for(i=0;i<str.length;i++){
								c=str.charAt(i);
								x=string.indexOf(c);
								if(x==-1) return false;
							}
	return true;
}

function cardat(str)
{
	if(str.length == 0) return true;
	else if(  (str.length != 14)  && (str.length != 20) && (str.length != 12) && (str.length != 13)) return false;
	else 
	{
		string="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
		for(i=0;i<str.length;i++){
								c=str.charAt(i);
								x=string.indexOf(c);
								if(x==-1) return false;
							}
		return true;
	}
}



function spaces(str)
{
	for(i=1;i<str.length;i++){
								c1=str.charAt(i-1);
								c2=str.charAt(i);								
								if((c1 == c2) && (c1 == ' ')) return false;
							}
	return true;
}


function is_number(str)
{
	//سلسلة الأرقام
	string="1234567890";
	for(i=0;i<str.length;i++){
								c=str.charAt(i);
								x=string.indexOf(c);
								if(x==-1) return false;
							}
	return true;
}

function correct_card(str)
{
	//سلسلة الأرقام
	string="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	for(i=0;i<str.length;i++){
								c=str.charAt(i);
								x=string.indexOf(c);
								if(x==-1){
									alert("عذراً...ولكن حقل البطاقة يجب أن لا يحوي سوى محارف أجنبية أو أرقام");
									return false;
								}
							}
	if(  (str.length != 14)  && (str.length != 20) && (str.length != 12) && (str.length != 13)){
					alert("عذراً...ولكن طول حقل البطاقة غير صالح");					
					return false;
			}
	return true;
}


function checkFormData(){
		var status = true;		
			


		//Checking The Answer of the qusetion
		var refnum = document.OneTrueForm.refnum.value;
		if(refnum == 12){
		  					status = false;
		  					document.OneTrueForm.refnum.focus();
		  					alert("عذراً...ولكن يجب الإجابة على السؤال الأول");
		  					return status;
						  }
		//end of Checking The Answer of the qusetion.		



		//Checking First Name
		var first = document.OneTrueForm.first.value;
		if(!spaces(first) || ((first.length=1)&&(first==' '))){
		  													status = false;
		  													document.OneTrueForm.first.focus();
		  													alert("عذراً...ولكن حقل الاسم الأول يحوي الكثير من الفراغات الزائدة");
											  				return status;
														 }		
		if(first.length==0){
		  					status = false;
		  					document.OneTrueForm.first.focus();
		  					alert("عذراً...ولكن حقل الاسم الأول يجب ملأه");
		  					return status;
						  }
		if(!wrong_test_names(first)) {
		  						status = false;
		  						alert("عذراً...يرجى كتابة الاسم الأول باللغة الأجنبية");
		  						document.OneTrueForm.first.focus();
		  						return status;
							  }
		//end of checking first name.		

		//Checking Last Name
		var last = document.OneTrueForm.last.value;
		if(!spaces(last) || ((last.length=1)&&(last==' '))){
		  													status = false;
		  													document.OneTrueForm.last.focus();
		  													alert("عذراً...ولكن حقل الكنية يحوي الكثير من الفراغات الزائدة");
											  				return status;
														 }
		if(last.length==0){
		  					status = false;
		  					document.OneTrueForm.last.focus();
		  					alert("عذراً...ولكن حقل الكنية يجب ملأه");
		  					return status;
						  }
		if(!wrong_test_names(last)) {
		  						status = false;
		  						alert("عذراً...يرجى كتابة حقل الكنية باللغة الأجنبية");
		  						document.OneTrueForm.last.focus();
		  						return status;
							  }
		//end of checking last name.		
		
		
		//Checking Job
		var job_t = document.OneTrueForm.sec_phrase1.value;
		if(job_t == 'other')
		{
			var job = document.OneTrueForm.job_text.value;
			if(!wrong_test_names(job)) {
			  						status = false;
			  						alert("عذراً...يرجى كتابة المهنة باللغة الأجنبية");
			  						document.OneTrueForm.job_text.focus();
			  						return status;
							  }
		}
		//end of checking job.		



		//Checking Address1
		var add = document.OneTrueForm.address1.value;
		if(!spaces(add) || ((add.length=1)&&(add==' '))){
		  													status = false;
		  													document.OneTrueForm.address1.focus();
		  													alert("عذراً...ولكن حقل العنوان الأول يحوي الكثير من الفراغات الزائدة");
											  				return status;
														 }
		if(add.length==0){
		  					status = false;
		  					document.OneTrueForm.address1.focus();
		  					alert("عذراً...ولكن حقل العنوان الأول يجب ملأه");
		  					return status;
						  }	
		if(!wrong_test_names(add)) {
		  						status = false;
		  						alert("عذراً...يرجى كتابة حقل العنوان الأول باللغة الأجنبية");
		  						document.OneTrueForm.address1.focus();
		  						return status;
							  }
		//end of checking address1.		
		

		// Checking the phone...
		var daytime= document.OneTrueForm.daytime.value;
		if (!(daytime.length >= 5 && is_number(daytime))){
			if ( daytime.length > 0 || !is_number(daytime)){
				status = false;
				document.OneTrueForm.daytime.focus();
				alert("عذراً...ولكن يوجد خطأ في رقم الهاتف");
				return status;				
			}
		}//end of checking the phone.



		var pkgpart = document.OneTrueForm.pkgpart.value;	

		// Checking Mobile Number...
		var mob = document.OneTrueForm.mobile3.value;
		if (document.OneTrueForm.mobile3.value.length == 7 && is_number(mob)){
				document.OneTrueForm.night.value = document.OneTrueForm.mobile1.value;
				document.OneTrueForm.night.value += document.OneTrueForm.mobile2.value;
				document.OneTrueForm.night.value += document.OneTrueForm.mobile3.value;
		}
		else{
			if(pkgpart == 301)
			{
				status = false;
				document.OneTrueForm.mobile3.focus();
				alert("عذراً...ولكن حقل الجوال يجب ملأه");
				return status;				
			}
			else
			{
				if ( document.OneTrueForm.mobile3.value.length > 0 || !is_number(mob)){
					status = false;
					document.OneTrueForm.mobile3.focus();
					alert("عذراً...ولكن يوجد خطأ في رقم الموبايل");
					return status;				
				}
				else{
					document.OneTrueForm.night.value = "";																			
				}
			}
		}//end of checking mobile number.
		
		//Checking UserName
		if(pkgpart != 301)
		{
			var username = document.OneTrueForm.username.value;
			if(!spaces(username) || ((username.length=1)&&(username==' '))){
												status = false;
		  										document.OneTrueForm.username.focus();
		  										alert("عذراً...ولكن حقل اسم المستخدم يحوي الكثير من الفراغات الزائدة");
											  	return status;
											 }
			if(username.length==0){
						status = false;
			  			document.OneTrueForm.username.focus();
			  			alert("عذراً...ولكن حقل اسم المستخدم يجب ملأه");
			  			return status;
					  }		
			if(!wrong_test(username)) {
		  					status = false;
		  					alert("عذراً...يرجى كتابة حقل اسم المستخدم باللغة الأجنبية");
		  					document.OneTrueForm.username.focus();
		  					return status;
						  }
			//end of checking username.

			//Checking Password
			var password = document.OneTrueForm._password.value;
			if(!spaces(password) || ((password.length=1)&&(password==' '))){
												status = false;
												document.OneTrueForm._password.focus();
												alert("عذراً...ولكن حقل كلمة السر يحوي الكثير من الفراغات الزائدة");
												return status;
											}
			if(password.length==0){
						status = false;
						document.OneTrueForm._password.focus();
						alert("عذراً...ولكن حقل كلمة السر يجب ملأه");
						return status;
					}		
			if(!wrong_test(password)) {
							status = false;
							alert("عذراً...يرجى كتابة حقل كلمة السر باللغة الأجنبية");
							document.OneTrueForm._password.focus();
							return status;
						}
			//end of checking password.	
			

			//Checking Re-Password
			var password2 = document.OneTrueForm._password2.value;
			if(!spaces(password2) || ((password2.length=1)&&(password2==' '))){
												status = false;
												document.OneTrueForm._password2.focus();
												alert("عذراً...ولكن حقل تأكيد كلمة السر يحوي الكثير من الفراغات الزائدة");
								  				return status;
											 }
			if(password2.length==0){
						status = false;
						document.OneTrueForm._password2.focus();
						alert("عذراً...ولكن حقل تأكيد كلمة السر يجب ملأه");
						return status;
					  }		
			if(!wrong_test(password2)) {
							status = false;
							alert("عذراً...يرجى كتابة حقل تأكيد كلمة السر باللغة الأجنبية");
							document.OneTrueForm._password2.focus();
							return status;
						}
			//end of checking Re-password.	
		
			//Checking the agreement between Password and Re-Password
			if(password != password2){
							status = false;
		  					alert("عذراً...ولكن كلمة السر و تأكيدها غير متطابقتين");	  						
							document.OneTrueForm._password.focus();
		  					return status; 
						}
			//end of checking the agreement between passwords
		}

		// Checking phone Number1...
		var pk = document.OneTrueForm.pkgpart.value;
		if(pk == "195")
		{	
			var phone1 = document.OneTrueForm.phone1.value;
			var temp;
			if (phone1.length >= 5 && is_number(phone1)){
					temp = document.OneTrueForm.phc1.value;
					temp += phone1;
					document.OneTrueForm.phoneOpen1.value = temp;
			}
			else{
					status = false;
					document.OneTrueForm.phone1.focus();
					alert("عذراً...ولكن يوجد خطأ في رقم الهاتف الأول");
					return status;				
				}

		
		
			// Checking phone Number2...
			var phone2 = document.OneTrueForm.phone2.value;
			var temp2;
			if (phone2.length >= 5 && is_number(phone2)){
					temp2 = document.OneTrueForm.phc2.value;
					temp2 += phone2;
					document.OneTrueForm.phoneOpen2.value = temp2;
			}
			else{
				if ( phone2.length > 0 || !is_number(phone2)){
					status = false;
					document.OneTrueForm.phone2.focus();
					alert("عذراً...ولكن يوجد خطأ في رقم الهاتف الثاني");
					return status;				
				}
				else{
					document.OneTrueForm.phoneOpen2.value = "";																			
				}
			}//end of checking phone number2.
		
		}
		
		//end of checking phone number1.

		
		//Checking the Cards
		var code1 = document.OneTrueForm.code1.value;
		var code2 = document.OneTrueForm.code2.value;
		var code3 = document.OneTrueForm.code3.value;
		var code4 = document.OneTrueForm.code4.value;
		var code5 = document.OneTrueForm.code5.value;
		
		// Bronze and Golden Subscriptions
		if( (pkgpart == 192) || (pkgpart == 198) || (pkgpart == 301))
		{
			if(!correct_card(code1)){document.OneTrueForm.code1.focus();status = false;return status;}
		}
		else// Others Subscriptions
		{
			if(!correct_card(code1)){document.OneTrueForm.code1.focus();status = false;return status;}

			if(!cardat(code2)){
						 			document.OneTrueForm.code2.focus();
									alert("عذراً...ولكن يجب عليك أن تملأ حقل البطاقة الثانية بأربعة عشر محرف صحيحة أو اتركه فارغاً");
							 		status = false;	return status;
						 	}


			 	else if(!cardat(code3)){
						 				document.OneTrueForm.code3.focus();
										alert("عذراً...ولكن يجب عليك أن تملأ حقل البطاقة الثالثة بأربعة عشر محرف صحيحة أو اتركه فارغاً");
							 			status = false;	return status;
						 	}
					else if(!cardat(code4)){
											document.OneTrueForm.code4.focus();
						 					alert("عذراً...ولكن يجب عليك أن تملأ حقل البطاقة الرابعة بأربعة عشر محرف صحيحة أو اتركه فارغاً");										
											status = false;return status;
								}
						else if(!cardat(code5)){
												document.OneTrueForm.code5.focus();
												alert("عذراً...ولكن يجب عليك أن تملأ حقل البطاقة الخامسة بأربعة عشر محرف صحيحة أو اتركه فارغاً");
												status = false;return status;
									}

		}

		//Checking the agreement of cec.sy
		if(document.OneTrueForm.terms.checked == false){
		 						status = false;
		  						alert("عذراً...ولكن يجب الموافقة على اتفاقية الموقع كي تتمكن من الإشتراك");	  						
								document.OneTrueForm.terms.focus();
		  						return status; 						
						}
		
		//end of checking the agreement of cec.sy

				
		if(job_t == 'other')
		{
			document.OneTrueForm.sec_phrase.value = document.OneTrueForm.job_text.value;
		}
		else
		{
			document.OneTrueForm.sec_phrase.value = document.OneTrueForm.sec_phrase1.value;
		}
		return status;
}//end of function.




