var dtCh= "-";
var minYear=1900;
var modDate = new Date();
var maxYear = modDate.getYear();
if(maxYear<1000) 
	maxYear+=1900;
	
//////////////////////////////////////////////////////////////////////////////////////////////////////
//the function Make window as full screen
function FullScreenWindow()
{
    window.moveTo (0, 0);
    if (document.layers) // navigator 4+
    { var deltaX = screen.availWidth - window.outerWidth;
    var deltaY = screen.availHeight - window.outerHeight;
    window.resizeBy (deltaX, deltaY);
    } else if (document.all) // exploder 4+
    { resizeTo(screen.availWidth, screen.availHeight); }
//firefox work by this
    if (document.all) {
        top.window.resizeTo(screen.availWidth, screen.availHeight);
    }

    else if (document.layers || document.getElementById) {
        if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }



}

//this function to handle enter action to the  textBox it take the textboxid and button ID needed
//to set the default button for the text box 
//في حاله لو عندي تكست وعايز أحدد زر عليه عند الضغط علي مفتاح الإنتر
function clickButton(e, buttonid)
{
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);
      if (bt)
      {
          if (evt.keyCode == 13)
          {
                bt.click();
                return false;
          }

      }

}
////////////////////////////////////////////////////////////////////////////////////////////
// the function convert enter button to tag
//مستخدمه في صفحة الlogin عند إدخال اسم المستخدم والضغط علي انتر يتم تحوليها لتاب للإنتقال لكلمة المرور وهكذا 
//ويتم استدعاء الداله علي onkeypress للحقل المراد الإنتقال لتاليه بعد الضغط علي الإنتر
////////////////////////////////////////////////////////////////////////////////////////////
 function enterToTab()
     {
      if(event.keyCode == 13)
      {
        event.keyCode = 9;
       }
     }
     
/////////////////////////////////////////////////////////////////////////////////////////////
//this function check the extensions of file passed to it if it is image or compressed 
//doc file or pdf it returns true else it returns false 
//used for checking file upload image files 
////////////////////////////////////////////////////////////////////////////////////////////
	function checkExtension(ext) {
  ext = ext.substring(ext.length-3,ext.length);
  ext = ext.toLowerCase();
  if(ext == 'jpg' || ext == 'jpeg' || ext == 'bmp' || ext == 'gif' || ext == 'rar' || ext == 'zip' || ext == 'ace' || ext == 'doc' || ext == 'pdf'  )  {
    return true ; }
  else
    return false ; }
//////////////////////////////////////////////////////////////////////////////////////////
//this function check Mail String take control to validate and message to show to user 
/////////////////////////////////////////////////////////////////////////////////////////
function ValidateMail(control,message) 
{
 var ctr = document.getElementById(control);
 var str=ctr.value;
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if(str.length > 0)
{
    if (str.indexOf(at)==-1)
    {
        alert(message);
        ctr.value="";
        ctr.style.backgroundColor="#ff6699";
        ctr.focus();
         return false;
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert(message);
        ctr.value="";
        ctr.style.backgroundColor="#ff6699";
        ctr.focus();
        return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert(message);
        ctr.value="";
        ctr.style.backgroundColor="#ff6699";
        ctr.focus();
        return false
    }

     if (str.indexOf(at,(lat+1))!=-1){
         alert(message);
         ctr.value="";
        ctr.style.backgroundColor="#ff6699";
        ctr.focus();
        return false
     }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
         alert(message);
         ctr.value="";
        ctr.style.backgroundColor="#ff6699";
        ctr.focus();
        return false
     }

     if (str.indexOf(dot,(lat+2))==-1){
         alert(message);
         ctr.value="";
        ctr.style.backgroundColor="#ff6699";
        ctr.focus();
        return false
     }

     if (str.indexOf(" ")!=-1)
     {
         alert(message);
         ctr.value="";
        ctr.style.backgroundColor="#ff6699";
        ctr.focus();
        return false
     }
 }
 ctr.style.backgroundColor="#FFFFFF"
	 return true					
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateNumberLegnth(control,message,Ctrlength)
{
  var MyNumber = document.getElementById(control);
  var PassedControlLength=MyNumber.value.length;
  if (PassedControlLength >0)
  {
      if(parseInt(PassedControlLength) != parseInt(Ctrlength))
      {
        alert(message );
        MyNumber.value="";
        MyNumber.style.backgroundColor="#ff6699";
         MyNumber.focus();
        return false;
     }
      else
      {
        MyNumber.style.backgroundColor="#FFFFFF";
      }
  }
 
    
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this function return message if passed control value is not number
function ValidateNumber(control,message)

{
  var No = document.getElementById(control);
  if (isNaN(No.value))
  {
    alert(message );
    No.value="";
    No.style.backgroundColor="#ff6699";
     No.focus();
     return false;
  }
  else
  {
    No.style.backgroundColor="#FFFFFF";
  }
    
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this function return message if passed control value is not number
function ValidateString(control,message)

{
  var No = document.getElementById(control);
  if (!isNaN(No.value))
  { 
    if (No.value.length >0)
    {
        alert(message );
        No.value="";
        No.style.backgroundColor="#ff6699";
         No.focus();
         return false;
      }
   }
      else
      {
        No.style.backgroundColor="#FFFFFF";
      }
    
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isDate(dtStr)
{
	if (dtStr.length<10)
	{
		return true;
	}
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return true;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isEmpty(control)
{
	if(control!=null)
	{
		if(control.value=="")
		{
			return false;
		}
	}
	return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that validateDaterent character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//the function check the date to be on the style 22021430
function ValidateDateFormat(date)
{
var Cur=document.getElementById(date);
			if( Cur!=null)
			{
				if(!IsNumberOnly(Cur.value))
				{
				Cur.value='';
				Cur.focus();
					return false;
				}
				if(Valid(Cur.value))
			    {
						var n=FormatString(Cur.value);
						Cur.value=n;
						var mm= CheckDateInterval(Cur.value);
						if(! mm )
						{
							Cur.value='';
							Cur.focus();
							return false;
						}
                    return true;
                                          
               }
				
}
			

function CheckDateInterval(Current)
		{
		
			var dt1 = new Array();
			dt1=Current.split("/");
			
			var day1=parseInt(dt1[0]);
			var month1=parseInt(dt1[1]);
			var year1=parseInt(dt1[2]);
if(day1>30)
{
            alert("التاريخ غير مقبول لأن اليوم أكبر من 30");
				return false;
}
    if(month1>12)
    {
     alert("التاريخ غير مقبول لأن الشهر أكبر من 12");
	                return false;
    }
					return true;
							
		  }
		 
		}//end function	
		
		function IsNumberOnly(string)

			{
               if(string.length<8)
                {
        		     alert("عفوا التاريخ يجب أن يكون على هذة الطريقة 03121428");
		        	 return false;
 		        }
			    if(isNaN(string))
			     {
                    alert("عفوا التاريخ يجب أن يكون على هذة الطريقة 03121428");
			         return false;
			     }
			       return true;
          }
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function to check if the date inserted is less than or equal current day 
function ValidateDateLessThanCurrentDate(CurrentDate,CheckedDate)
{
var x=document.getElementById(CurrentDate);//تاريخ اليوم 
var  Cur=document.getElementById(CheckedDate);// التاريخ المراد فحصه

			if(Cur !=null & x!=null)
			{
				if(!IsNumberOnly(Cur.value))
				{
				    Cur.value='';
				    Cur.focus();
					return false;
				}
				if(Valid(Cur.value))
					{
						var n=FormatString(Cur.value);
						Cur.value=n;	
                        var mm=comparedates(Cur.value,x.value);
						if(! mm )
						{
							Cur.value='';
							Cur.focus();
							return false;
						}
                    }
	
			}
}
//-----------------------------------------compare twor date the date2 must be less than current
function comparedates(Current,date2)
		{
			var dt1 = new Array();
			dt1=Current.split("/");
			var dt2 = new Array();
			dt2=date2.split("/");
			var day1=parseInt(dt1[0]);
			var month1=parseInt(dt1[1]);
			var year1=parseInt(dt1[2]);
			
            var day2=parseInt(dt2[0]);
			var month2=parseInt(dt2[1]);
			var year2=parseInt(dt2[2]);
			if(day1>30)
            {
                 alert('التاريخ غير مقبول لأن اليوم أكبر من 30');
			     return false;
            }
            if(month1>12)
            {
             alert('التاريخ غير مقبول لأن الشهر أكبر من 12');
			 return false;
            }

            if(year2 < year1)
			{
                alert('التاريخ غير مقبول لأن السنة أكبر من السنة الحالية');
				return false;
				
			}
			else
			{
				if(year2 == year1 )
				{
				
							if( month2 < month1)
							{
							    alert('التاريخ غير مقبول لأن الشهر أكبر من الشهر الحالية');
                              	return false;
							}
							else
							{
								if (month2 == month1)
								{
									if(day2<day1)
									{
                                    alert('التاريخ غير مقبول لأن اليوم أكبر  من تاريخ اليوم');
									return false;
									alert('أحد التواريخ غير صالح تأكد من البيانات');
									}
								}
							}
				}
					return true;
							
		  }
		 
		}//end function	
				function FormatString(x)
	            {
			            var day=x.substring(0,2);
			            var month=x.substring(2,4);
			            var year=x.substring(4,8);
			            var last=day +"/"+month+"/"+year;
			            return last;
	            }		
        		
        	
		function Valid(string)
		{
			
			if(string=="")
				return false;
			if(string.indexOf('/') >0)
				return false;
			return true;
			
		
		}
//////////////////////////////////////////////////////////////////////////////////////////////////
////this function compare two dates with the format(dd/MM/YYYY) to compare the first date to be less
////than the second date to compare interval 
//function comparedatesInterval(Current,date2)
//		{
//		//alert("now in comparedatesxxxx");
//			var dt1 = new Array();
//			dt1=Current.split("/");
//			var dt2 = new Array();
//			dt2=date2.split("/");
//			var day1=parseInt(dt1[0]);
//			var month1=parseInt(dt1[1]);
//			var year1=parseInt(dt1[2]);
//			                             
//			var day2=parseInt(dt2[0]);
//			var month2=parseInt(dt2[1]);
//			var year2=parseInt(dt2[2]);
//            if(day1>30)
//            {
//                 alert('التاريخ غير مقبول لأن اليوم أكبر من 30');
//			     return false;
//            }
//            if(month1>12)
//            {
//             alert('التاريخ غير مقبول لأن الشهر أكبر من 12');
//			 return false;
//            }

//            if(year2 < year1)
//			{
//                alert('تاريخ الفترة غير صالح يجب أن يكون تاريخ البداية أكبر من تاريخ النهاية ');
//				return false;
//				
//			}
//			else
//			{
//				if(year2 == year1 )
//				{
//				
//							if( month2 < month1)
//							{
//                               alert('تاريخ الفترة غير صالح يجب أن يكون تاريخ البداية أكبر من تاريخ النهاية');
//								return false;
//							
//							}
//							else
//							{
//								if (month2 == month1)
//								{
//									if(day2<day1)
//									{
//                                       alert('تاريخ الفترة غير صالح يجب أن يكون تاريخ البداية أكبر من تاريخ النهاية');
//    									return false;
//									}
//								
//								}
//							}
//				}
//					return true;
//							
//		  }
//		 
//		}
//		//end function	
///////////////////////////////////////////////////////////////////////////////////////////////
//this function used to prevent user to write english chracters
function isArabicOnly(evt)

      {
      var bool=true ;
         var charCode = (evt.which) ? evt.which : event.keyCode
          if ( (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) )
          {
           alert('أكتب باللغه العربية من فضلك');
           bool=false ;
           }
            return bool ;
      }
///////////////////////////////////////////////////////////////////////////////////////////////////
//this function used to write numbers only and prevent user to write any other characters
  function isNumberKey(evt)
      {
      var bool=true;
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
         {
           alert('لا يسمح بغير الأرقام !');
           bool=false ;
           }
            return bool ;
      }
    // the function convert enter button to tag
//مستخدمه في صفحة الlogin عند إدخال اسم المستخدم والضغط علي انتر يتم تحوليها لتاب للإنتقال لكلمة المرور وهكذا 
//ويتم استدعاء الداله علي onkeypress للحقل المراد الإنتقال لتاليه بعد الضغط علي الإنتر
// for ex: textbox to goto next control when press enter: onkeydown="javascript:enterToTab();"
////////////////////////////////////////////////////////////////////////////////////////////
 function enterToTab()
     {
      if(event.keyCode == 13) event.keyCode = 9;
     }
     
/////////////////////////////////////////////////////////////////////////////////////////////  
 function preventBack()
        {
        //alert("now in prevent Back Function");
         if(history.length>0)
         {
            history.go(+1);
            
         }
        }
////////////////////////////////////////////////////////////////////////////////////
