//-------------------------------------------------------------------------------------------------------------------------
function Validate(lang,formName,formAction)  //Function works in both IE and Netscape browsers.
{

	if(lang == "Arabic")
	{
		lang = "a";
	}
	else if(lang == "English")
	{
		lang = "e";
	}
	//---------------------------------------------------------------------------------------------------
	//Here put any sentence you want to be appeared.
	//---------------------------------------------------------------------------------------------------
	var MsgA	= "برجاء إدخال الحقل / الحقول التالية:";
	var MsgE	= "Please, enter the following Field(s) :";
	
	//document.getElementById("ErrsTable").style.display = "none";
	
	var MandatoryField = new Array();
	var m=0;
	
	var Errs = new Array();
	var e=0;
	//---------------------------------------------------------------------------------------------------
	//Here put any validation pattern and call it in the code.
	//---------------------------------------------------------------------------------------------------
	var ValidAlphaNumeric	= /^[a-zA-Z0-9]+$/;
	var ValidChars			= /^[a-zA-Z]+$/;
	var ValidNumbers		= /^\d*\.{0,1}\d+$/;
	var ValidNumericInt		= /^[0-9]+$/;
	var ValidPatternNumbers = /^\d{1,}\-\d{1,}$/;
	var ValidFloat			= /^\[d{1,11}\.\d{1,2}]|\d{1,11}$/;
	//var ValidEMail added by ahmed elbaz
	var VaildEMail          = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var VaildEMailString	= /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/;
	//var VaildEMailString	= /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/;
	//var ValidURL			= /^\S+\.(gif|jpg|jpeg|png)$/
	var ValidMobile			= /^\d{10}$/;
	//var ValidInternetURL	= /^[a-zA-z0-9]\.[a-zA-z0-9]\.$/;
	
	//http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
	
	var ValidDate			= /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	var ValidDate1			= /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var ValidDate2			= /^(([0-9]|[0-2][0-9])|([3][0-1]))\/([0-9]|([0][0-9])|([1][0-2]))\/((([1][9])|([2][0-2]))\d{2})$/;
	var ValidDate3			= /^\d{2}\-\d{2}\-\d{4}$/;
	var ValidDate4			= /^\d{1,}\-\d{1,}\-\d{4}$/;
	var ValidDate5			= /^\d{1,2}\-\d{1,2}\-\d{4}$/;
	var ValidDate6			= /^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
	var ValidDate7			= /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
	var ValidDayMonthDate	= /^\d{2}\-\d{2}$/;
	var ValidDateDay		= /^(([0-9])|([0-2][0-9])|([3][0-1]))$/;
	var ValidDateMonth		= /^(([0-9])|([0][0-9])|([1][0-2]))$/;
	var ValidDateYear		= /^([2][0-9])\d{2}$/;
	
	var ValidYear			= /^([1][9])|([2][0-2])\d{2}$/;	
	
	var ValidTime1			= /^(\d{1,2}):(\d{2})$/;
	var ValidTime2			= /^(([1][0-2])|[0-9])\:([0-5][0-9]|[0-9])?(\s?(AM|PM)?)?$/;	//(([1][0-2])|[0-9])\:([0-5][0-9]|[0-9])?(\s?(AM|PM)?)?
	var ValidTime12			= /^(\d{1,2}):(\d{2})?(\s?(AM|am|PM|pm)?)?$/;
	var ValidHour			= /^(([0|1][0-9])|([2][0-3]))\:([0-5])([0-9])\:([0-5])([0-9])$/;	//(([1][0-2])|[0-9])\:([0-5][0-9]|[0-9])?(\s?(AM|PM)?)?
	var ValidTimeHourMin	= /^(([0|1][0-9])|([2][0-3]))\:([0-5])([0-9])$/;
	var ValidTimeHour		= /^(([0-9])|([0][0-9])|([1][0-2]))$/;
	var ValidTimeMin		= /^([0-5])([0-9])$/;
	var ValidTimeHourMin12	= /^(([0-9])|([0][0-9])|([1][0-2]))\:([0-5])([0-9])\ (AM|PM)$/;
	
	var ValidDateTime		= /^\d{2}\-\d{2}\-\d{4} (\d{1,2}):(\d{2})$/;
	
	var ValidPhone1			= /^\d{2,3}\-\d{7}$/;					//For example: 048-2427826 [At least 2 occurrence for code area and at most 3 ; and 7 occurance for phone number]
	var ValidPhone2			= /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
	var ValidPhone3			= /^\(\d\d\d\) \d\d\d-\d\d\d\d$/;
	var ValidPhone4			= /^\(\d{3}\) \d{3}-\d{4}$/;
	var ValidPhone5			= /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;	//For example: 012-45689-012-1234
		
	var ValidBool			= /^[0-1]{1}$/;
	
	var FormLength = (document.getElementsByTagName('Form').length);
	for(f=0 ; f < FormLength ; f++)
	{
		if(document.forms(0).name == formName)
		{
			var oCollection = document.forms(0).all;
		}
	}
	/////////////////////////////////
	var LTime =new Date();

    var LTimeField = LTime.getHours()+":";

    LTimeField+= LTime.getMinutes();

    var todayDate = LTime.getDate()+"/";

    todayDate += (LTime.getMonth()+1) +"/";

    todayDate += LTime.getFullYear();

//////////////////////////////////////
	var FromToDate = new Array();
	var FT = 0;
	var FromToDate2 = new Array();
	var FromToNumber = new Array();
	var FromToNumber2 = new Array();
	var FTN = 0;
	var FTN2 = 0;
	var NameItems = new Array();
	var N = 0;

	var EmailItems = new Array();
	var EM = 0;

	var count = 0;
	var eMailAdsCount = 4;

	//Check InsertOne
	var FieldsCount=0;
	var InsertOneCount=0;
	var InsertOneFirstField="";
	var ValidateDublicated=false;
	//----------------------------
	if(oCollection != null)
	 {
		for(index = 0 ; index < oCollection.length; index ++)
		{
			
			var oInput = oCollection[index] ;
			if(lang=='a')
				var Attr = oInput.getAttribute("mandatoryA");
			else if(lang=='e')
				var Attr = oInput.getAttribute("mandatoryE");
      
      
			if(Attr != null && Attr == "true" || Attr == "false")
			{	
        
				if(document.getElementById(formName)[oInput.id].disabled == false && document.getElementById(formName)[oInput.id].style.display == "")
				{
          
					if(document.getElementById(formName)[oInput.id].value == "")
					{
						//Check InsertOne
						if(document.getElementById(formName)[oInput.id].getAttribute("Validation")=="InsertOne" && document.getElementById(formName)[oInput.id].style.display=="")
						{
							InsertOneCount++;
              if(InsertOneFirstField=="")
              {
               InsertOneFirstField=oInput.id;
              }
						}
						//------------------------------------------------------------------
						
						if(Attr == "false")
						{
              				//
							if(document.getElementById(formName)[oInput.id].getAttribute("email") == "true")
							{
								if(document.getElementById(formName)[oInput.id].value == "" && document.getElementById(formName)[oInput.id].style.display=="")
								{
									EmailItems[EM] = oInput.id;
									EM++;	
								}
							}
							//
							
							if(oInput.type == "textarea")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								var Len = value.length;
								if(document.getElementById(formName)[oInput.id].getAttribute("MLen"))
								{
									if(Len > document.getElementById(formName)[oInput.id].getAttribute("MLen"))
									{
										var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabel + ":" + " لابد ألا يتعدي " + document.getElementById(formName)[oInput.id].getAttribute("MLen") + " حرفاً ";
											Errs[e] = ControlLabel + ":" + " لابد ألا يتعدي " + document.getElementById(formName)[oInput.id].getAttribute("MLen") + " حرفاً ";
											e++;
										}	
										if(lang == 'e')
										{
											MsgE += "\n" + ControlLabel + ":" + " must not exceed " + document.getElementById(formName)[oInput.id].getAttribute("MLen") + " characters ";
											Errs[e] = ControlLabel + ":" + " must not exceed " + document.getElementById(formName)[oInput.id].getAttribute("MLen") + " characters ";
											e++;
										}	
										MandatoryField[m] = oInput.id;
										m++;			
									}
								}
							}
							
							if(document.getElementById(formName)[oInput.id].getAttribute("CName") == "true")
								{
									if(document.getElementById(formName)[oInput.id].value == "" && document.getElementById(formName)[oInput.id].style.display=="")
									{
										NameItems[N] = oInput.id;
										N++;	
									}
								}
								if(NameItems.length > 1)
								{
									if(lang == 'a')
									{
										MsgA += "\n" + "لابد من إدخال احد الأسماء";
										
										Errs[e] = "لابد من إدخال احد الأسماء";
										e++;
										
										MandatoryField[m] = NameItems[0];
										m++;
										
										NameItems = new Array();
										N = 0;
									}
									else
									{
										MsgE += "\n" + "At least one name should be written";
										
										Errs[e] = "At least one name should be written";
										e++;
										
										MandatoryField[m] = NameItems[0];
										m++;
										
										NameItems = new Array();
										N = 0;
									}
								}
								else if(NameItems.length == "1")
								{
									if(lang == 'a')
									{
										var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
										MsgA += "\n" + ControlLabel;
										
										Errs[e] = ControlLabel;
										e++;
										
										MandatoryField[m] = NameItems[0];
										m++;
										
										NameItems = new Array();
										N = 0;
									}
									else
									{
										var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
										MsgE += "\n" + ControlLabel;
										
										Errs[e] = ControlLabel;
										e++;
										
										MandatoryField[m] = NameItems[0];
										m++;
										
										NameItems = new Array();
										N = 0;
									}
								}
								
								
								
								
							}	
						if(Attr == "true")
						{
              
							if(document.getElementById(formName)[oInput.id] != null)
							{
								if(document.getElementById(formName)[oInput.id].style.display == "")
								{
									if(document.getElementById(formName)[oInput.id].parentNode.parentElement.style.display == "none")
									{	
									}
									else
									{
										MandatoryField[m] = oInput.id;
										m++;		
										
										var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" +  ControlLabel;
											Errs[e] = ControlLabel;
											e++;
										}
										else if(lang == 'e')
										{
											MsgE += "\n" +  ControlLabel;
											Errs[e] = ControlLabel;
											e++;
										}
									}		
								}
							}
						}		
					}
					else  //mandatory Fields with value, then check type to validate input and control length.
					{
            
						if(Attr == "true" || Attr == "false")
						{
							
							var ValidationType = document.getElementById(formName)[oInput.id].getAttribute("Validation");
							var Pers = document.getElementById(formName)[oInput.id].getAttribute("Valiii");
							if (Pers == "persent")
							{
								var valueee = document.getElementById(formName)[oInput.id].value;
								if (parseInt(valueee) > 100 )
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لا يجب أن تزيد عن 100%";
										Errs[e] = ControlLabel + ":" + "لا يجب أن تزيد عن 100%";
										e++;
									}	 
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Must be Not More Than 100%";
										Errs[e] = ControlLabel + ":" + "Must be Not More Than 100%";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							var MinChar = document.getElementById(formName)[oInput.id].getAttribute("MinChar");
							if (MinChar)
							{
								var min = document.getElementById(formName)[oInput.id].value.length;
								if (min < MinChar )
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لا يجب أن تقل عدد الحروف عن " + MinChar;
										Errs[e] = ControlLabel + ":" + "لا يجب أن تقل عدد الحروف عن " + MinChar;
										e++;
									}	 
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel+ ":" + "Characters Must be Not Less Than " + MinChar;
										Errs[e] = ControlLabel + ":" + "Characters Must be Not Less Than " + MinChar;
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							var MaxChar = document.getElementById(formName)[oInput.id].getAttribute("MaxChar");
							if (MaxChar)
							{
								var max = document.getElementById(formName)[oInput.id].value.length;
								if (max > MaxChar )
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لا يجب أن تزيد عدد الحروف عن " + MaxChar;
										Errs[e] = ControlLabel + ":" + "لا يجب أن تزيد عدد الحروف عن " + MaxChar;
										e++;
									}	 
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel+ ":" + "Characters Must be Not More Than " + MaxChar;
										Errs[e] = ControlLabel + ":" + "Characters Must be Not More Than " + MaxChar;
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							//---------------------------------------------------------------------------------------------------
							//Here put any validation type you need as the following syntax
							//---------------------------------------------------------------------------------------------------
             
							if(ValidationType == "Numeric")
							{
								if(document.getElementById(formName)[oInput.id].getAttribute("DiffNumeric"))
								{
									if(document.getElementById(formName)[oInput.id].getAttribute("DiffNumeric") == "true")
									{
											FromToNumber[FTN] = oInput.id;
											FTN++;
									}
								}
								if(document.getElementById(formName)[oInput.id].getAttribute("DiffNumeric2"))
								{
									if(document.getElementById(formName)[oInput.id].getAttribute("DiffNumeric2") == "true")
									{
											FromToNumber2[FTN2] = oInput.id;
											FTN2++;
									}
								}
								if(document.getElementById(formName)[oInput.id].getAttribute("GInt"))
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									var GInt = parseInt(document.getElementById(formName)[oInput.id].getAttribute("GInt"));
									if(parseInt(document.getElementById(formName)[oInput.id].value) < GInt)
									{
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabel + ":" + "لابد أن يكون  أكبر من" + GInt;
											Errs[e] = ControlLabel + ":" + "لابد أن يكون  أكبر من" + GInt;
											e++;
										}	
										else if(lang == 'e')
										{
											MsgE += "\n" +  ControlLabel + ":" + "Must be Greater Than" + GInt;
											Errs[e] = ControlLabel + ":" + "Must be Greater Than" + GInt;
											e++;
										}
										
										MandatoryField[m] = oInput.id;
										m++;
									}	
								}
								if(document.getElementById(formName)[oInput.id].getAttribute("GValue"))
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									var GValue = document.getElementById(formName)[oInput.id].getAttribute("GValue");
									var GInt   = parseInt(document.getElementById(GValue).value);
									var AntherControlLabel = document.getElementById(GValue).getAttribute("Label");
									if(parseInt(document.getElementById(formName)[oInput.id].value) < GInt)
									{
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabel + ":" + "لابد أن يكون  أكبر من" + AntherControlLabel;
											Errs[e] = ControlLabel + ":" + "لابد أن يكون  أكبر من" + AntherControlLabel;
											e++;
										}	
										else if(lang == 'e')
										{
											MsgE += "\n" +  ControlLabel+ ":" + "Must be Greater Than" + AntherControlLabel;
											Errs[e] = ControlLabel + ":" + "Must be Greater Than" + AntherControlLabel;
											e++;
										}
										
										MandatoryField[m] = oInput.id;
										m++;
									}	
								}
								if(document.getElementById(formName)[oInput.id].getAttribute("EqValue"))
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									var GValue = document.getElementById(formName)[oInput.id].getAttribute("EqValue");
									var GInt   = parseInt(document.getElementById(GValue).value);
									var AntherControlLabel = document.getElementById(GValue).getAttribute("Label");
									if(parseInt(document.getElementById(formName)[oInput.id].value) != GInt)
									{
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabel + ":" + "لابد أن يكون  مساوي لـ" + AntherControlLabel;
											Errs[e] = ControlLabel + ":" + "لابد أن يكون  مساوي لـ" + AntherControlLabel;
											e++;
										}	
										else if(lang == 'e')
										{
											MsgE += "\n" +  ControlLabel+ ":" + "Must be Equal" + AntherControlLabel;
											Errs[e] = ControlLabel + ":" + "Must be Equal" + AntherControlLabel;
											e++;
										}
										
										MandatoryField[m] = oInput.id;
										m++;
									}	
								}
								if(document.getElementById(formName)[oInput.id].getAttribute("LInt"))
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									var LInt = parseInt(document.getElementById(formName)[oInput.id].getAttribute("LInt"));
									if(parseInt(document.getElementById(formName)[oInput.id].value) > LInt)
									{
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabel + ":" + "لابد أن يكون  أصغر من" + LInt;
											Errs[e] = ControlLabel + ":" + "لابد أن يكون  أصغر من" + LInt;
											e++;
										}	
										else if(lang == 'e')
										{
											MsgE += "\n" +  ControlLabel+ ":" + "Must be Less Than" + LInt;
											Errs[e] = ControlLabel + ":" + "Must be Less Than" + LInt;
											e++;
										}
										
										MandatoryField[m] = oInput.id;
										m++;
									}	
								}
								if(document.getElementById(formName)[oInput.id].getAttribute("LValue"))
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									var LValue = document.getElementById(formName)[oInput.id].getAttribute("LValue");
									var LInt   = parseInt(document.getElementById(LValue).value);
									var AntherControlLabel = document.getElementById(LValue).getAttribute("Label");
									if(parseInt(document.getElementById(formName)[oInput.id].value) > LInt)
									{
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabel + ":" + "لابد أن يكون  أصغر من" + AntherControlLabel;
											Errs[e] = ControlLabel + ":" + "لابد أن يكون  أصغر من" + AntherControlLabel;
											e++;
										}	
										else if(lang == 'e')
										{
											MsgE += "\n" +  ControlLabel + ":" + "Must be Less Than" + AntherControlLabel;
											Errs[e] = ControlLabel + ":" + "Must be Less Than" + AntherControlLabel;
											e++;
										}
										
										MandatoryField[m] = oInput.id;
										m++;
									}	
								}
                
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidNumbers.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد أن يكون أرقام فقط";
										Errs[e] = ControlLabel + ":" + "لابد أن يكون أرقام فقط";
										e++;
									}	
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Must be Digits only";
										Errs[e] = ControlLabel + ":" + "Must be Digits only";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
								else
								{
									if(document.getElementById(formName)[oInput.id].getAttribute("MaxLen")!=null && document.getElementById(formName)[oInput.id].getAttribute("MaxLen")!="")
									{
										var maxlen=document.getElementById(formName)[oInput.id].getAttribute("MaxLen")
										
										if(parseInt(value)>parseInt(maxlen))
										{
											var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
											if(lang == 'a')
											{
												MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
												Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
												e++;
											}
											else if(lang == 'e')
											{
												MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";
												Errs[e] = ControlLabel + ":" + "Invalid Data";
												e++;
											}
											
											MandatoryField[m] = oInput.id;
											m++;
										}
									}
								}
							}
							
							else if(ValidationType == "Checkbox")
							{
								var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
								var aa = document.getElementById(formName)[oInput.name].length;
								var selectedCount = 0;
								
								for(i = 0 ; i < aa ;i++)
								{
									if(document.all(oInput.name)[i].checked == true)
									{
										selectedCount++;
									}	
								}				
								if(aa==undefined)
								{
									if(document.all(oInput.name).checked == true)
									{
										selectedCount++;
									}	
								}
								if(selectedCount<1)
								{
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "يجب اختيار مخالفة واحدة على الاقل";
										Errs[e] = ControlLabel + ":" + "يجب اختيار مخالفة واحدة على الاقل";
										e++;
									}
									else
									{
										MsgE += "\n" + ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							else if(ValidationType == "Radio")
							{
								var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
								var aa = document.getElementById(formName)[oInput.name].length;
								var selectedCount = 0;
								for(i = 0 ; i < aa ;i++)
								{
									if(document.all(oInput.name)[i].checked == true)
									{
										selectedCount++;
									}	
								}				
								if(aa==undefined)
								{
									if(document.all(oInput.name).checked == true)
									{
										selectedCount++;
									}	
								}
								if(selectedCount<1)
								{
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "يجب إختيار قيمة";
										Errs[e] = ControlLabel + ":" + "يجب إختيار قيمة";
										e++;
									}
									else
									{
										MsgE += "\n" + ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							////-------------This Part is added by Ahmed Elbaz--------------
							else if(ValidationType == "HDate") //Accept from Now and greater than
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidDate1.test(value); //dd/mm/yyyy
								if(document.getElementById(formName)[oInput.id].getAttribute("DiffDate"))
								{
									if(document.getElementById(formName)[oInput.id].getAttribute("DiffDate") == "true")
									{
											FromToDate[FT] = oInput.id;
											FT++;
									}
								}			
								if(document.getElementById(formName)[oInput.id].getAttribute("DiffDate2"))
								{
									if(document.getElementById(formName)[oInput.id].getAttribute("DiffDate2") == "true")
									{
											FromToDate2[FT] = oInput.id;
											FT++;
									}
								}
								if(document.getElementById(formName)[oInput.id].getAttribute("LDateValue"))
								{         
									var LDateValue = document.getElementById(formName)[oInput.id].getAttribute("LDateValue");
									var Diff = getdifference2Date(document.getElementById(formName)[oInput.id].value,LDateValue);
									if(Diff > 0)
									{
										var ControlLabelStart = document.getElementById(formName)[oInput.id].getAttribute("Label");
										//var ControlLabelEnd = document.getElementById(formName)[FromToDate[en]].getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أصغر من " + LDateValue;
											Errs[e] = ControlLabelStart + "," + " لابد أن يكون أصغر من " + LDateValue;
											e++;
										}	
										else
										{
											MsgE += "\n" + ControlLabelStart + "," + "Should be less than " + LDateValue;
											Errs[e] = ControlLabelStart + "," + "Should be less than " + LDateValue;
											e++;
										}	
										MandatoryField[m] = oInput.id;
										m++;
									}
								}
								if(document.getElementById(formName)[oInput.id].getAttribute("GDateValue"))
								{
									var GDateValue = document.getElementById(formName)[oInput.id].getAttribute("GDateValue");
									var Diff = getdifference2Date(document.getElementById(formName)[oInput.id].value,GDateValue);
									if(Diff < 0)
									{
										var ControlLabelStart = document.getElementById(formName)[oInput.id].getAttribute("Label");
										//var ControlLabelEnd = document.getElementById(formName)[FromToDate[en]].getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أكبر من " + GDateValue;
											Errs[e] = ControlLabelStart + "," + " لابد أن يكون أكبر من " + GDateValue;
											e++;
										}	
										else
										{
											MsgE += "\n" + ControlLabelStart + "," + "Should be Greater than " + GDateValue;
											Errs[e] = ControlLabelStart + "," + "Should be Greater than " + GDateValue;
											e++;
										}	
										MandatoryField[m] = oInput.id;
										m++;
									}
								}
								if(document.getElementById(formName)[oInput.id].getAttribute("LDateField"))
								{
									var LDate = document.getElementById(formName)[oInput.id].getAttribute("LDateField");
									var LDateField = document.getElementById(LDate).value;
									var Diff = getdifference2Date(document.getElementById(formName)[oInput.id].value,LDateField);
									if(Diff > 0)
									{
										var ControlLabelStart = document.getElementById(formName)[oInput.id].getAttribute("Label");
										var ControlLabelEnd = document.getElementById(LDate).getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أصغر من " + ControlLabelEnd;
											Errs[e] = ControlLabelStart + "," + " لابد أن يكون أصغر من " + ControlLabelEnd;
											e++;
										}	
										else
										{
											MsgE += "\n" + ControlLabelStart + "," + "Should be less than " + ControlLabelEnd;
											Errs[e] = ControlLabelStart + "," + "Should be less than " + ControlLabelEnd;
											e++;
										}	
										MandatoryField[m] = oInput.id;
										m++;
									}
								}
								////
								if(document.getElementById(formName)[oInput.id].getAttribute("GDateField"))
								{
									var GDate = document.getElementById(formName)[oInput.id].getAttribute("GDateField");
									var GDateField = document.getElementById(GDate).value;
									var Diff = getdifference2Date(document.getElementById(formName)[oInput.id].value,GDateField);
									if(Diff < "0")
									{
										var ControlLabelStart = document.getElementById(formName)[oInput.id].getAttribute("Label");
										var ControlLabelEnd = document.getElementById(GDate).getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أكبر من " + ControlLabelEnd;
											Errs[e] = ControlLabelStart + "," + " لابد أن يكون أكبر من " + ControlLabelEnd;
											e++;
										}	
										else
										{
											MsgE += "\n" + ControlLabelStart + "," + "Should be Greater than " + ControlLabelEnd;
											Errs[e] = ControlLabelStart + "," + "Should be Greater than " + ControlLabelEnd;
											e++;
										}	
										MandatoryField[m] = oInput.id;
										m++;
									}
								}
								////
								if(!Valid)
								{
									Valid = false;
								}
								//check valid date
								var len=value.length;
								var pos=value.indexOf("/");

								var day=value.substring(0,pos);
								var month_and_year=value.substring(pos+1,len);
								var month=month_and_year.substring(0,pos);
								var year=month_and_year.substring(pos+1,len);

								var NotValid=0;
														
								if(parseInt(month)>12 || parseInt(year)>1600 || parseInt(year)<1000 || parseInt(day)>30)
								{
									NotValid=1;
								}
								
								var dayCh = "";
								var monthCh ="";
								
								if(day.search("/"))
								{
									for(i=0 ; i < day.length ; i++)
									{
										if(day.charAt(i) != "/")
											dayCh += day.charAt(i);
									}	
									day = dayCh;
								}
								
								if(month.search("/"))
								{
									for(j=0 ; j < month.length ;j++)
									{
										if(month.charAt(j) != "/")
											monthCh += month.charAt(j);
									}	
									
									month = monthCh;
								}
								if((!Valid) || (NotValid==1))
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA =  "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = MsgA;
										e++;
									}
									if(document.getElementById(formName)[oInput.id].disabled == "false" || document.getElementById(formName)[oInput.id].style.display == "")
										{
												MandatoryField[m] = oInput.id;
												m++;		
										}		
								}
						}
							////////
							else if(ValidationType == "InternetURL")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidInternetURL.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							else if(ValidationType == "compareTwoValueA")
							{
                
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidNumbers.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد أن يكون أرقام فقط";
										Errs[e] = ControlLabel + ":" + "لابد أن يكون أرقام فقط";
										e++;
									}	
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel;
										Errs[e] = ControlLabel + ":" + "Must be Digits only";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
								else
								{
									if(document.getElementById(formName)[oInput.id].getAttribute("MaxLen")!=null && document.getElementById(formName)[oInput.id].getAttribute("MaxLen")!="")
									{
										var maxlen=document.getElementById(formName)[oInput.id].getAttribute("MaxLen")
										
										if(parseInt(value)>parseInt(maxlen))
										{
											var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
											if(lang == 'a')
											{
												MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
												Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
												e++;
											}
											else if(lang == 'e')
											{
												MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";
												Errs[e] = ControlLabel + ":" + "Invalid Data";
												e++;
												MandatoryField[m] = oInput.id;
												m++;
											}
											
											
										}
									}
									else 
									{
										var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
										if (parseInt(value) > document.getElementById("RateE100").value)
										{
											MsgE += "\n" +  ControlLabel + ":" + "Must not greater than the Rate of The Question";
											Errs[e] = ControlLabel + ":" + "Must not greater than the Rate of The Question";
											e++;
										}
										MandatoryField[m] = oInput.id;
										m++;
									}
								}
							}
							/////--------------------------------End Of El-Baz----------------------------
							else if(ValidationType == "Select" && Attr == "true")
							{
								
								var value = document.getElementById(formName)[oInput.id].value;
								if(value == "-1" || value == "" || value == null)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel ;
										Errs[e] = ControlLabel ;
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  + ControlLabel + ":" + "Must determine the value";
										Errs[e] = ControlLabel + ":" + "Must determine the value";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							else if(ValidationType == "Select" && Attr == "false")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								if(value == "-1")
								{
									//FinYearCombo[f] = oInput.id;
									//f++;
								}
							}
							else if(ValidationType == "NumericInt")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidNumericInt.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد أن يكون أرقام فقط";
										Errs[e] = ControlLabel + ":" + "لابد أن يكون أرقام فقط";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel;
										Errs[e] = ControlLabel + ":" + "Must be Digits only";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							else if(ValidationType == "Mobile")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidMobile.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
              else if(ValidationType == "FileName")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								if(value=='')
                {
                  Valid=true;
                }
                else
                {
                  if(value.indexOf(".")>1 && value.indexOf(".")<value.length-1)
                  {
                    Valid=true;
                  }
                  else
                  {
                    Valid=false;
                  }
                }
                
                
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							else if(ValidationType == "EMail")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = VaildEMail.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							else if(ValidationType == "EMailString")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = VaildEMailString.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							
							else if(ValidationType == "EMailSeparated")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = VaildEMail.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							else if(ValidationType == "Float")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidFloat.test(value);
                
                if(Valid)
                {
                    if(document.getElementById(formName)[oInput.id].getAttribute("MaxFloatValue")!=null && document.getElementById(formName)[oInput.id].getAttribute("MaxFloatValue")!="")
                    {
                      var max=document.getElementById(formName)[oInput.id].getAttribute("MaxFloatValue");
                        if(parseFloat(value)>parseFloat(max))
                        {
                          Valid=false;
                          
                        }
                        
                    }
                }
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
									
								}
							}
              ////////////////////////////////////////////////////////////////
							else if(ValidationType == "NumValues")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								var Pat="0123456789,";
								var NotValid=false;
								for(i=0;i<value.length;i++)
								{
								  var chValue=value.charAt(i);
								  if(Pat.indexOf(chValue)==-1)
								  {
									NotValid=true;
									break;
								  }
								}
								if(NotValid!=true)
								{
									if(document.getElementById(formName)[oInput.id].getAttribute("MaxNumValue")!=null && document.getElementById(formName)[oInput.id].getAttribute("MaxNumValue")!="")
									{
										var max=document.getElementById(formName)[oInput.id].getAttribute("MaxNumValue");
										var Arr=value.split(",")
										for(i=0;i<Arr.length;i++)
										{
											
										  var chValue=Arr[i];
										  
										  if(parseInt(chValue)>parseInt(max))
										  {
											NotValid=true;
											break;
										  }
										}

									}
                  
								}
								if(NotValid==true)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
									
								}
							}
              //////////////////////////////////////////////////////////////
							else if(ValidationType == "Image")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								var ext=document.getElementById(formName)[oInput.id].getAttribute("Ext");
								Valid = ValidateImageExt(oInput.id,ext);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
              ////////////////////////////////////////////////////////////////////
							else if(ValidationType == "DateDay")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidDateDay.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else
									{
										MsgE += "\n" + ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
									
								}
							}
							/////////////////////////Check For Dublicated values///////////////
							else if(ValidationType == "DublicatedValues")
							{
								if(ValidateDublicated!=true)
								{
									var Num = document.getElementById(formName)[oInput.id].getAttribute("FieldsNum")-1;

									var Arr=new Array();
									var start=0;
									if(document.getElementById(formName)[oInput.id].value!="")
									{
										Arr.push(oInput.id);
										start=1;
									}
								
									for(i=start;i<=Num;i++)
									{
										
										var field=document.getElementById(formName)[oInput.id].getAttribute("Field"+i);
										
										if(document.getElementById(formName)[field].value!="")
										{
											Arr.push(field);
										}
									}
									Valid = ValidateDublicatedValues(Arr);
									if(!Valid)
									{
										var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabel + ":" + "البيانات مكررة";
											Errs[e] = ControlLabel + ":" + "البيانات مكررة";
											e++;
										}
										else
										{
											MsgE += "\n" + ControlLabel + ":" + "Dublicated Data";
											Errs[e] = ControlLabel + ":" + "Dublicated Data";
											e++;
										}
										
										MandatoryField[m] = oInput.id;
										m++;
										
									}
									ValidateDublicated=true;
								}
							}
							///////////////////////////////////////////////////////////
							else if(ValidationType == "DateMonth")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidDateMonth.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else
									{
										MsgE += "\n" + ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
									
								}
							}
							
							///////////////////////////////////////////
							
							else if(ValidationType == "DateYear")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidDateYear.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else
									{
										MsgE += "\n" + ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
									
								}
							}
							else if(ValidationType == "TimeHourMin")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidTimeHourMin.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else
									{
										MsgE += "\n" + ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
									
								}
							}
							else if(ValidationType == "TimeHourMin12")
							{
								var value = document.getElementById(formName)[oInput.id].value;							
								Valid = ValidTimeHourMin12.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else
									{
										MsgE += "\n" + ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							else if(ValidationType == "TimeHour")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidTimeHour.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else
									{
										MsgE += "\n" + ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							else if(ValidationType == "TimeMin")
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidTimeMin.test(value);
								if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else
									{
										MsgE += "\n" + ControlLabel + ":" + "Invalid Data";
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}
									
									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							//Check For InsertOne
							else if(ValidationType == "InsertOne")
							{

								FieldsCount++;
                
							}
							else if(ValidationType == "AlphaNumeric")
							{
								
								var value = document.getElementById(formName)[oInput.id].value;
								if(oInput.tagName != "TEXTAREA")
								{
									for(i=0 ; i < value.length ; i++)
									{
										if(value.charAt(i) == ' ' && document.getElementById(formName)[oInput.id].value == parseInt(0) && (document.getElementById(formName)[oInput.id].mandatoryA == "true" || document.getElementById(formName)[oInput.id].mandatoryA == "true"))
										{
											count ++;
											if(count == value.length)
											{
												var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
												if(lang == 'a')
												{
													MsgA += "\n" + ControlLabel + ":" + "لابد من كتابة حروف أو أرقام";
													Errs[e] = ControlLabel + ":" + "لابد من كتابة حروف أو أرقام";
													e++;
													count = 0;
												}	
												else
												{
													MsgE += "\n" + ControlLabel + ":" + "Should be charcters or numbers";
													Errs[e] = ControlLabel + ":" + "Should be charcters or numbers";
													e++;
													count = 0;
												}	
												MandatoryField[m] = oInput.id;
												m++;	
												//count = 0;		
											}
										}
									}
								}
								else if(oInput.tagName == "TEXTAREA")
								{
									var Len = value.length;
									if(document.getElementById(formName)[oInput.id].getAttribute("MLen"))
									{									
										if(Len > document.getElementById(formName)[oInput.id].getAttribute("MLen"))
										{
											var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
											if(lang == 'a')
											{
												MsgA += "\n" + ControlLabel + ":" + " لابد ألا يتعدي " + document.getElementById(formName)[oInput.id].getAttribute("MLen") + " حرفاً ";
												Errs[e] = ControlLabel + ":" + " لابد ألا يتعدي " + document.getElementById(formName)[oInput.id].getAttribute("MLen") + " حرفاً ";
												e++;
											}	
											else
											{
												MsgE += "\n" + ControlLabel + ":" + " must not exceed " + document.getElementById(formName)[oInput.id].getAttribute("MLen") + " characters ";
												Errs[e] = ControlLabel + ":" + " must not exceed " + document.getElementById(formName)[oInput.id].getAttribute("MLen") + " characters ";
												e++;
											}	
											MandatoryField[m] = oInput.id;
											m++;			
										}
									}
									var co = 0;
									for(z = 0 ; z < Len ; z++)
									{
										//alert(co)
										//alert(value.charAt(z));
										//document.write(value.charAt(z));
										var Chars = value.charAt(z);
										var ValidValInt		= ValidNumbers.test(Chars);
										var ValidValChar	= ValidChars.test(Chars);
										if(ValidValInt)
										{
											co++;
										}
										else if(ValidValChar)
										{
											co++;
										}
										else
										{
											if(Chars == "ش" || Chars == "س" || Chars == "ي" ||Chars == "ب" ||Chars == "ل" ||Chars == "ا" ||Chars == "ت" ||Chars == "ن" ||Chars == "م" ||Chars == "ك" ||Chars == "ط" ||Chars == "ض" ||Chars == "ص" ||Chars == "ث" ||Chars == "ق" ||Chars == "ف" ||Chars == "غ" ||Chars == "ع" ||Chars == "ه" ||Chars == "خ" ||Chars == "ح" ||Chars == "ج" ||Chars == "د" ||Chars == "ذ" ||Chars == "ئ" ||Chars == "ء" ||Chars == "ؤ" ||Chars == "ر" ||Chars == "ى" ||Chars == "ة" ||Chars == "و" ||Chars == "ز" ||Chars == "ظ" ||Chars == "أ" ||Chars == "إ")
											{
												co++;
											}
										}
									}
									if(co == 0)
									{
											//document.getElementById(formName)[oInput.id].value = "";
											var LabelCont = document.getElementById(formName)[oInput.id].getAttribute("Label");
											
											MsgA += "\n" + LabelCont;
											MsgE += "\n" + LabelCont;
											Errs[e] = LabelCont;
											e++;
											
											MandatoryField[m] = oInput.id;
											m++;
									}
									
								}
								
								//-------------------------------------
									//Confirm Password
									if(document.getElementById(formName)[oInput.id].getAttribute("Confirm") != null)
									{
									
										var NewPsw = document.getElementById(formName)[oInput.id].getAttribute("ID1");
										var CnfPsw = document.getElementById(formName)[oInput.id].getAttribute("ID2");

										var NewPswLbl = document.getElementById(formName)[NewPsw].getAttribute("Label");
										var CnfPswLbl = document.getElementById(formName)[CnfPsw].getAttribute("Label");

										if(document.getElementById(formName)[NewPsw].value != document.getElementById(formName)[CnfPsw].value)
										{
											if(lang == 'a')
											{
												MsgA += "\n" + CnfPswLbl + ":" + " يجب أن تكون مطابقة لـ " + NewPswLbl;
												Errs[e] = CnfPswLbl + ":" + " يجب أن تكون مطابقة لـ " + NewPswLbl;
												e++;
											}	
											else
											{
												MsgE += "\n" + CnfPswLbl + ":" + " should be the same like " + NewPswLbl;
												Errs[e] = CnfPswLbl + ":" + " should be the same like " + NewPswLbl;
												e++;
											}
											
											MandatoryField[m] = CnfPsw;
											m++;			
										}
									}
									//Check Password Minimum Lenght
									
									 if(document.getElementById(formName)[oInput.id].getAttribute("MinLength") != null)
									 {

										var PswMinLength = document.getElementById(formName)[oInput.id].getAttribute("MinLength");
										

										var PswLbl = document.getElementById(formName)[oInput.id].getAttribute("Label");
										

										if(document.getElementById(formName)[oInput.id].value.length < PswMinLength)
										{
											if(lang == 'a')
											{
												MsgA += "\n" + PswLbl + ":" + " يجب ان تكون على الأقل " + PswMinLength + " حرفآ" ;
												Errs[e] = PswLbl + ":" + " يجب ان تكون على الأقل " + PswMinLength + " حرفآ";
												e++;
											}	
											else
											{
												MsgE += "\n" + PswLbl + ":" + " should be at least " + PswMinLength + " Charachters" ;
												Errs[e] = PswLbl + ":" + " should be at least " + PswMinLength + " Charachters";
												e++;
											}
											
											MandatoryField[m] = oInput.id;
											m++;			
										}
									}
									
									//////////////////////////////////////////////////////////////////////////
                  //Check User Name Spaces
									
									 if(document.getElementById(formName)[oInput.id].getAttribute("Space") != null && document.getElementById(formName)[oInput.id].getAttribute("Space") == "No")
									 {

										var Lbl = document.getElementById(formName)[oInput.id].getAttribute("Label");

										if(document.getElementById(formName)[oInput.id].value.indexOf(" ") != -1)
										{
											if(lang == 'a')
											{
												MsgA += "\n" + Lbl + ":" + "لا يجب ان تحتوى على مسافة" ;
												Errs[e] = Lbl + ":" + "لا يجب ان تحتوى على مسافة" ;
												e++;
											}	
											else
											{
												MsgA += "\n" + Lbl + ":" + " should not contain space "  ;
												Errs[e] = Lbl + ":" + " should not contain space" ;
												e++;
											}
											
											MandatoryField[m] = oInput.id;
											m++;			
										}
									}
                  
                  
                  //////////////////////////////////////////////////////////////////////////////
									if(document.getElementById(formName)[oInput.id].getAttribute("ValidUser") != null )
									 {

										var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
										var val=document.getElementById(formName)[oInput.id].value;
										var Pat="<>";
										var NotValid=false;
										for(i=0;i<Pat.length;i++)
										 {
											var ch=Pat.charAt(i);
											if(val.indexOf(ch)!=-1)
											 {
												NotValid=true;
												break;
											 }
										 }
										if(NotValid==true)
										{
											
											if(lang == 'a')
											{
												MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
												Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
												e++;
											}
											else if(lang == 'e')
											{
												MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";;
												Errs[e] = ControlLabel + ":" + "Invalid Data";
												e++;
											}

											MandatoryField[m] = oInput.id;
											m++;
										}
									}
                  
                  
                  //////////////////////////////////////////////////////////////////////////////
									//Check Password Contains Digits
									
									 if(document.getElementById(formName)[oInput.id].getAttribute("ContainsDigits") != null)
									 {

										var PswContainsDigits = document.getElementById(formName)[oInput.id].getAttribute("ContainsDigits");
										
										if(PswContainsDigits=="true")
										{
											var PswLbl = document.getElementById(formName)[oInput.id].getAttribute("Label");
											var Pass=document.getElementById(formName)[oInput.id].value;
											var Digits="0123456789";
											var validNum=false;
											for(var i=0;i<Pass.length;i++)
											{
												iCh=Pass.charAt(i);
												if(Digits.indexOf(iCh)!=-1)
												{
													validNum=true;
													break;
												}
												
											}
											if(validNum!=true)
											{
												if(lang == 'a')
												{
													MsgA += "\n" + PswLbl + ":" + " يجب ان تحتوى على رقم واحد على الأقل" ;
													Errs[e] = PswLbl + ":" + " يجب ان تحتوى على رقم واحد على الأقل";
													e++;
												}	
												else
												{
													MsgA += "\n" + PswLbl + ":" + " should be Contains at least one digit" ;
													Errs[e] = PswLbl + ":" + " should be Contains at least one digit " ;
													e++;
												}
												
												MandatoryField[m] = oInput.id;
												m++;			
											}
										}
									}
							
							}

							else if(ValidationType == "Date") //Accept from Now and greater than
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidDate2.test(value); //dd/mm/yyyy
								
								if(Valid)
								{
									var RetValue = CheckDate(value);
								}
								
								if(RetValue == false)
								{
									Valid = false;
								}
								
								//check valid date
								var len=value.length;
								var pos=value.indexOf("/");

								var day=value.substring(0,pos);
								var month_and_year=value.substring(pos+1,len);
								var month=month_and_year.substring(0,pos);
								var year=month_and_year.substring(pos+1,len);

								var year_div4=year % 4;
								var NotValid=0;
								
								var dayCh = "";
								var monthCh ="";
								
								if(day.search("/"))
								{
									for(i=0 ; i < day.length ; i++)
									{
										if(day.charAt(i) != "/")
											dayCh += day.charAt(i);
									}	
									day = dayCh;
								}
								
								if(month.search("/"))
								{
									for(j=0 ; j < month.length ;j++)
									{
										if(month.charAt(j) != "/")
											monthCh += month.charAt(j);
									}	
									
									month = monthCh;
								}
														
								if(month>12)
								{
									NotValid=1;
								}
								
								if((month==2) && (day>28) && (year_div4>0))
								{
									NotValid=1;
								}
								if((month==2) && (day>29) && (year_div4==0))
								{
									NotValid=1;
								}
								
								//day entered is not larger than today's date
								var date=new Date();
								dayNow=date.getDate();
								monthNow=date.getMonth()+1;
								yearNow=date.getFullYear();
								
								if(year<yearNow)
								{
									NotValid=1;
								}
								if(year==yearNow)
								{
									if(month<monthNow)
									{
										NotValid=1;
									}
									if((month==monthNow) && (day<dayNow))
									{
										NotValid=1;
									}
								}
								
								if((!Valid) || (NotValid==1))
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}

									MandatoryField[m] = oInput.id;
									m++;
								}
							}
						///////////////////////////////////////
						
						else if(ValidationType == "YearNow") //Accept greater than
							{
								var date=new Date();
								dayNow=date.getDate();
								monthNow=date.getMonth()+1;
								yearNow=date.getFullYear();
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidYear.test(value); //dd/mm/yyyy
								
								if(Valid)
								{	
									var year = document.getElementById(formName)[oInput.id].value;
									if(year<=yearNow)
									{
										//var RetValue = CheckDate(value);
									}
									else
									{
										var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
											Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
											e++;
										}
										else if(lang == 'e')
										{
											MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";;
											Errs[e] = ControlLabel + ":" + "Invalid Data";
											e++;
										}

										MandatoryField[m] = oInput.id;
										m++
										}
								}
								
								else if(!Valid)
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}

									MandatoryField[m] = oInput.id;
									m++;
								}
								
								 
							}
						
              ////////////////////////////////////////////////////////////////////
              
              else if(ValidationType == "DateGreater") //Accept greater than
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidDate2.test(value); //dd/mm/yyyy
								
								if(Valid)
								{
									var RetValue = CheckDate(value);
								}
								
								if(RetValue == false)
								{
									Valid = false;
								}
								
								//check valid date
								var len=value.length;
								var pos=value.indexOf("/");

								var day=value.substring(0,pos);
								var month_and_year=value.substring(pos+1,len);
                pos=month_and_year.indexOf("/");
								var month=month_and_year.substring(0,pos);
                var year=month_and_year.substring(pos+1,len);
                
                
								var year_div4=year % 4;
								var NotValid=0;
								
								var dayCh = "";
								var monthCh ="";
								
								if(day.search("/"))
								{
									for(i=0 ; i < day.length ; i++)
									{
										if(day.charAt(i) != "/")
											dayCh += day.charAt(i);
									}	
									day = dayCh;
								}
								
								if(month.search("/"))
								{
									for(j=0 ; j < month.length ;j++)
									{
										if(month.charAt(j) != "/")
											monthCh += month.charAt(j);
									}	
									
									month = monthCh;
								}
														
								if(month>12)
								{
									NotValid=1;
								}
								
								if((month==2) && (day>28) && (year_div4>0))
								{
									NotValid=1;
								}
								if((month==2) && (day>29) && (year_div4==0))
								{
									NotValid=1;
								}
								
								//day entered is not larger than today's date
								var date=new Date();
								dayNow=date.getDate();
								monthNow=date.getMonth()+1;
								yearNow=date.getFullYear();
								
                if(year<yearNow)
								{
									NotValid=1;
								}
								if(year==yearNow)
								{
									if(month<monthNow)
									{
										NotValid=1;
									}
									if((month==monthNow) && (day<=dayNow))
									{
										NotValid=1;
									}
								}
								
								if((!Valid) || (NotValid==1))
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}

									MandatoryField[m] = oInput.id;
									m++;
								}
							}
              
              
              //////////////////////////////////////////////////////////////////
							else if(ValidationType == "Date_Current_Later") //Accept Now & before & after
							{
								var value = document.getElementById(formName)[oInput.id].value;
								Valid = ValidDate2.test(value); //dd/mm/yyyy
								////
								if(document.getElementById(formName)[oInput.id].getAttribute("DiffDate"))
								{
									if(document.getElementById(formName)[oInput.id].getAttribute("DiffDate") == "true")
									{
											FromToDate[FT] = oInput.id;
											FT++;
									}
								}			
								if(document.getElementById(formName)[oInput.id].getAttribute("DiffDate2"))
								{
									if(document.getElementById(formName)[oInput.id].getAttribute("DiffDate2") == "true")
									{
											FromToDate2[FT] = oInput.id;
											FT++;
									}
								}
								////
								if(document.getElementById(formName)[oInput.id].getAttribute("LDateValue"))
								{
									var LDateValue = document.getElementById(formName)[oInput.id].getAttribute("LDateValue");
									var Diff = getdifference2Date(document.getElementById(formName)[oInput.id].value,LDateValue);
					
									if(Diff >= 0)
									{
										var ControlLabelStart = document.getElementById(formName)[oInput.id].getAttribute("Label");
										//var ControlLabelEnd = document.getElementById(formName)[FromToDate[en]].getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أصغر من " + LDateValue;
											Errs[e] = ControlLabelStart + "," + " لابد أن يكون أصغر من " + LDateValue;
											e++;
										}	
										else
										{
											MsgE += "\n" + ControlLabelStart + "," + "Should be less than " + LDateValue;
											Errs[e] = ControlLabelStart + "," + "Should be less than " + LDateValue;
											e++;
										}	
										MandatoryField[m] = oInput.id;
										m++;
									}
								}
								/////
								if(document.getElementById(formName)[oInput.id].getAttribute("LessThanToday"))//today and less than today

                                                           {

                                                               var Diff = getdifference2Date(document.getElementById(formName)[oInput.id].value,todayDate);

                                                                  if(Diff >0)

                                                                  {

                                                                         var ControlLabelStart = document.getElementById(formName)[oInput.id].getAttribute("Label");
                                                                         if(lang == 'a')

                                                                         {

                                                                                MsgA =  "\n" + ControlLabelStart + "," + "لابد أن يكون أقل من تاريخ اليوم";
                                                                                Errs[e] = ControlLabelStart + "," + " لابد أن يكون أقل من تاريخ اليوم";
											                                          e++;
                                                                         }  

                                                                         else

                                                                         {
                                                                             MsgE =  "\n" + ControlLabelStart + "," + " Should be Before Today's Date " + todayDate;
											                                  Errs[e] = ControlLabelStart + "," + "Should be Before Today's Date" + LDateValue;
											                                    e++;
										                                 }	
										                                   MandatoryField[m] = oInput.id;
										                                    m++;

                                                                  }

                                                           }
								////
								if(document.getElementById(formName)[oInput.id].getAttribute("GDateValue"))
								{
									var GDateValue = document.getElementById(formName)[oInput.id].getAttribute("GDateValue");
									var Diff = getdifference2Date(document.getElementById(formName)[oInput.id].value,GDateValue);
									if(Diff <= 0)
									{
										var ControlLabelStart = document.getElementById(formName)[oInput.id].getAttribute("Label");
										//var ControlLabelEnd = document.getElementById(formName)[FromToDate[en]].getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أكبر من " + GDateValue;
											Errs[e] = ControlLabelStart + "," + " لابد أن يكون أكبر من " + GDateValue;
											e++;
										}	
										else
										{
											MsgE += "\n" + ControlLabelStart + "," + "Should be Greater than " + GDateValue;
											Errs[e] = ControlLabelStart + "," + "Should be Greater than " + GDateValue;
											e++;
										}	
										MandatoryField[m] = oInput.id;
										m++;
									}
								}
								////
								if(document.getElementById(formName)[oInput.id].getAttribute("LDateField"))
								{	
								
									var LDate = document.getElementById(formName)[oInput.id].getAttribute("LDateField");
									var LDateField = document.getElementById(LDate).value;
									var Diff = getdifference2Date(document.getElementById(formName)[oInput.id].value,LDateField);
									if(Diff > 0)
									{
										var ControlLabelStart = document.getElementById(formName)[oInput.id].getAttribute("Label");
										var ControlLabelEnd = document.getElementById(LDate).getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أصغر من " + ControlLabelEnd;
											Errs[e] = ControlLabelStart + "," + " لابد أن يكون أصغر من " + ControlLabelEnd;
											e++;
										}	
										else
										{
											MsgE += "\n" + ControlLabelStart + "," + "Should be less than " + ControlLabelEnd;
											Errs[e] = ControlLabelStart + "," + "Should be less than " + ControlLabelEnd;
											e++;
										}	
										MandatoryField[m] = oInput.id;
										m++;
									}
								}
								////
								if(document.getElementById(formName)[oInput.id].getAttribute("GDateField"))
								{
									var GDate = document.getElementById(formName)[oInput.id].getAttribute("GDateField");
									var GDateField = document.getElementById(GDate).value;
									var Diff = getdifference2Date(document.getElementById(formName)[oInput.id].value,GDateField);
									if(Diff <= "0")
									{
										var ControlLabelStart = document.getElementById(formName)[oInput.id].getAttribute("Label");
										var ControlLabelEnd = document.getElementById(GDate).getAttribute("Label");
										if(lang == 'a')
										{
											MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أكبر من " + ControlLabelEnd;
											Errs[e] = ControlLabelStart + "," + " لابد أن يكون أكبر من " + ControlLabelEnd;
											e++;
										}	
										else
										{
											MsgE += "\n" + ControlLabelStart + "," + "Should be Greater than " + ControlLabelEnd;
											Errs[e] = ControlLabelStart + "," + "Should be Greater than " + ControlLabelEnd;
											e++;
										}	
										MandatoryField[m] = oInput.id;
										m++;
									}
								}
								////
								if(Valid)
								{
									var RetValue = CheckDate(value);
								}
								
								if(RetValue == false)
								{
									Valid = false;
								}
								
								//check valid date
								var len=value.length;
								var pos=value.indexOf("/");

								var day=value.substring(0,pos);
								var month_and_year=value.substring(pos+1,len);
								var month=month_and_year.substring(0,pos);
								var year=month_and_year.substring(pos+1,len);
								
								var year_div4=year % 4;
								var NotValid=0;
														
								if(month>12)
								{
									NotValid=1;
								}
								
								var dayCh = "";
								var monthCh ="";
								
								if(day.search("/"))
								{
									for(i=0 ; i < day.length ; i++)
									{
										if(day.charAt(i) != "/")
											dayCh += day.charAt(i);
									}	
									day = dayCh;
								}
								
								if(month.search("/"))
								{
									for(j=0 ; j < month.length ;j++)
									{
										if(month.charAt(j) != "/")
											monthCh += month.charAt(j);
									}	
									
									month = monthCh;
								}
								
								if((month==2) && (day>28) && (year_div4>0))
								{
									NotValid=1;
								}
								if((month==2) && (day>29) && (year_div4==0))
								{
									NotValid=1;
								}
															
								if((!Valid) || (NotValid==1))
								{
									var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
									if(lang == 'a')
									{
										MsgA += "\n" + ControlLabel + ":" + "لابد من مراجعة الصيغة";
										Errs[e] = ControlLabel + ":" + "لابد من مراجعة الصيغة";
										e++;
									}
									else if(lang == 'e')
									{
										MsgE += "\n" +  ControlLabel + ":" + "Invalid Data";;
										Errs[e] = ControlLabel + ":" + "Invalid Data";
										e++;
									}

									MandatoryField[m] = oInput.id;
									m++;
								}
							}
							
              if(document.getElementById(formName)[oInput.id].getAttribute("DateFrom")!=null &&	document.getElementById(formName)[oInput.id].getAttribute("DateFrom")!="")
              {
                var DateFromID=document.getElementById(formName)[oInput.id].getAttribute("DateFrom");
                var DateToID=document.getElementById(formName)[oInput.id].getAttribute("DateTo");
                
                if(document.all(DateFromID).value!=null && document.all(DateToID).value!=null)
                {
                      
                      if(document.all(DateFromID).value!="" && document.all(DateToID).value!="")
                      { 
                        FromToDate.push(DateFromID);
                        FromToDate.push(DateToID);
                        
                      }
                  }
              }
              
              
						}//end of if Attr=true or false
				 }//end of else
			}
	
		}//End of Attr ->if		
	}//End of For 
}//End of oCollection


//Check For InsertOne


if(FieldsCount<1 && InsertOneCount>0)
{

	if(lang == 'a')
	{
		MsgA += "\n" + "لابد من إدخال احد القيم";
		Errs[e] = "لابد من إدخال احد القيم";
		e++;
	}	
	else
	{
		MsgE += "\n" + "At least one value should be written";
		Errs[e] = "At least one value should be written";
		e++;
	}	
  MandatoryField[m] = InsertOneFirstField;
	m++;
				
}
//-----------------------------------------------------------------------------

var Lenqq2 = FromToDate2.length;

if(Lenqq2 > 0 )
{
	s=0;
	en=1;
  
	for(l=1 ; l < Lenqq2/2+1 ; l++)
	{
		
		if(FromToDate2[en] != null && FromToDate2[s] != null)
		{
      
			var Diff = getdifference2Date(document.all(FromToDate2[s]).value,document.all(FromToDate2[en]).value);
			if(Diff < "0")
			{
				
				var ControlLabelStart = document.getElementById(formName)[FromToDate2[s]].getAttribute("Label");
				var ControlLabelEnd = document.getElementById(formName)[FromToDate2[en]].getAttribute("Label");
				if(lang == 'a')
				{
					MsgA =  "\n" + ControlLabelStart + "," + " لابد أن يكون أكبر من " + ControlLabelEnd;
					Errs[e] = MsgA;
					e++;
				}	
				MandatoryField[m] = FromToDate2[0];
				m++;
			}
		}
		s = s+2;
		en = en+2;
	}
}	
var Len = FromToDate.length;

if(Len > 0 )
{
	s=0;
	en=1;
  
	for(l=1 ; l < Len/2+1 ; l++)
	{
		
		if(FromToDate[en] != null && FromToDate[s] != null)
		{
      
			var Diff = getdifference2Date(document.all(FromToDate[en]).value,document.all(FromToDate[s]).value);
      
			if(Diff < "0")
			{
				var ControlLabelStart = document.getElementById(formName)[FromToDate[s]].getAttribute("Label");
				var ControlLabelEnd = document.getElementById(formName)[FromToDate[en]].getAttribute("Label");
				if(lang == 'a')
				{
					MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أصغر من " + ControlLabelEnd;
					Errs[e] = ControlLabelStart + "," + " لابد أن يكون أصغر من " + ControlLabelEnd;
					e++;
				}	
				else
				{
					MsgE += "\n" + ControlLabelStart + "," + "Should be less than " + ControlLabelEnd;
					Errs[e] = ControlLabelStart + "," + "Should be less than " + ControlLabelEnd;
					e++;
				}	
				MandatoryField[m] = FromToDate[0];
				m++;
			}
		}
		s = s+2;
		en = en+2;
	}
}	

if(FromToNumber.length > 0 )
{
	SN = 0;
	EN = 1;

	for(i=1 ; i < FromToNumber.length/2+1 ; i++)
	{
		var StartValue = parseInt(document.getElementById(formName)[FromToNumber[SN]].value);
		var EndValue = parseInt(document.getElementById(formName)[FromToNumber[EN]].value);

		if(EndValue < StartValue)
		{
			var ControlLabelStart = document.getElementById(formName)[FromToNumber[SN]].getAttribute("Label");
			var ControlLabelEnd = document.getElementById(formName)[FromToNumber[EN]].getAttribute("Label");
			if(lang == 'a')
			{
				MsgA += "\n" + ControlLabelStart + "," + " لابد أن يكون أصغر من " + ControlLabelEnd;
				Errs[e] = ControlLabelStart + "," + " لابد أن يكون أصغر من " + ControlLabelEnd;
				e++;
			}	
			else
			{
				MsgE += "\n" + ControlLabelStart + "," + "Should be less than " + ControlLabelEnd;
				Errs[e] = ControlLabelStart + "," + "Should be less than " + ControlLabelEnd;
				e++;
			}	
			MandatoryField[m] = FromToNumber[0];
			m++;

			SN = SN + 2;
			EN = EN + 2;
		}	
	}
}	
if(FromToNumber2.length > 0 )
{
	SN = 0;
	EN = 1;

	for(i=1 ; i < FromToNumber2.length/2+1 ; i++)
	{
		var StartValue = parseInt(document.getElementById(formName)[FromToNumber2[SN]].value);
		var EndValue = parseInt(document.getElementById(formName)[FromToNumber2[EN]].value);

		if(EndValue > StartValue)
		{
			var ControlLabelStart = document.getElementById(formName)[FromToNumber2[SN]].getAttribute("Label");
			var ControlLabelEnd = document.getElementById(formName)[FromToNumber2[EN]].getAttribute("Label");
			if(lang == 'a')
			{
				MsgA += "\n" + ControlLabelEnd + "," + " لابد أن يكون أصغر من " + ControlLabelStart;
				Errs[e] = ControlLabelEnd + "," + " لابد أن يكون أصغر من " + ControlLabelStart;
				e++;
			}	
			else
			{
				MsgE += "\n" + ControlLabelEnd + "," + "Should be less than " + ControlLabelStart;
				Errs[e] = ControlLabelEnd + "," + "Should be less than " + ControlLabelStart;
				e++;
			}	
			MandatoryField[m] = FromToNumber2[0];
			m++;

			SN = SN + 2;
			EN = EN + 2;
		}	
	}
}
if(EmailItems.length == eMailAdsCount)
{
	if(lang == 'a')
	{
		MsgA += "\n" + "لابد من إدخال احد العناوين البريدية";
		
		Errs[e] = "لابد من إدخال احد العناوين البريدية";
		e++;
		
		MandatoryField[m] = EmailItems[0];
		m++;
		
		//EmailItems = new Array();
		//EM = 0;
	}
	else
	{
		MsgE += "\n" + "At least one email address should be written";
		
		Errs[e] = "At least one email address should be written";
		e++;
		
		MandatoryField[m] = EmailItems[0];
		m++;
	}
}
else if(EmailItems.length == "1")
{
	if(lang == 'a')
	{
		var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
		MsgA += "\n" + ControlLabel;
		
		Errs[e] = ControlLabel;
		e++;
		
		MandatoryField[m] = NameItems[0];
		m++;
		
		EmailItems = new Array();
		EM = 0;
	}
	else
	{
		var ControlLabel = document.getElementById(formName)[oInput.id].getAttribute("Label");
		MsgE += "\n" + ControlLabel;
		
		Errs[e] = ControlLabel;
		e++;
		
		MandatoryField[m] = EmailItems[0];
		m++;
		
		EmailItems = new Array();
		EM = 0;
	}
}
	if(lang == 'a')
	{
		if(MandatoryField.length > 0)
		{
			var Msg	= "برجاء إدخال الحقل التالي :";
			var MsgA = MsgA;
			alert(MsgA);
			
			MsgItem = new Array();
			mg = 0;
			
			if(document.getElementById(MandatoryField[0]))
			{
				document.getElementById(MandatoryField[0]).focus();
				//document.getElementById("vFlag").value = "0";
				document.getElementById(formName).onsubmit = "return false;";
				return false;
			}	
		}
		else
		{
			document.getElementById(formName).action = formAction;
			document.getElementById(formName).submit();
		}
	}
	else if(lang == 'e')
	{
		if(MandatoryField.length > 0)
		{
			//var Msg	= "Please Enter These Fileds";
			//var MsgE = MsgE;
			alert(MsgE);
			
			var Errs = new Array();
			var e=0;
			
			if(document.getElementById(MandatoryField[0]))
			{
				document.getElementById(MandatoryField[0]).focus();
				//document.getElementById("vFlag").value = "0";
				//document.getElementById(formName).onsubmit = "return false;";
				return false;
			}	
		}
		else
		{
			//document.getElementById("vFlag").value = "1";
			document.getElementById(formName).action = formAction;
			document.getElementById(formName).submit();
			//document.getElementById(formName).onsubmit = "return true;";
			//return true;
		}
	}
	////////////////////////////////////////////
}

function getdifference2Date(todate,fromdate)

{

      toar   = new Array();

      fromar = new Array();

      var index  = 0;

      var val    = "";

      

      for(i=0;i<todate.length;i++)

      {

            switch (todate.charAt(i))

            {

                  case "\/":

                        toar[index]=val;

                        index++;

                        val="";

                        break;

                        default:

                        val=val+todate.charAt(i);

                  case "\-":

                        

            }

      }

      

      toar[index] = val; //array of the day-month-year

      var dateto  = new Date(toar[2],(toar[1]-1),toar[0]);

 

 

      index1=0;

      val1="";

      for(i=0;i<fromdate.length;i++){

            switch (fromdate.charAt(i)){

                  case "\/":

                  fromar[index1]=val1;

                        index1++;

                        val1="";

                        break;

                        default:

                        val1=val1+fromdate.charAt(i);

                  case "\-":

            }

      }

      fromar[index1]=val1; //array of the day-month-year

      var datefrom = new Date(fromar[2],(fromar[1]-1),fromar[0]);

      var diff = dateto.getTime()- datefrom.getTime();

      

      var days = Math.floor(diff / (1000 * 60 * 60 * 24));

  return  days;

}