var arrMonthName = new Array();
arrMonthName[0]="";
arrMonthName[1]="1";
arrMonthName[2]="2";
arrMonthName[3]="3";
arrMonthName[4]="4";
arrMonthName[5]="5";
arrMonthName[6]="6";
arrMonthName[7]="7";
arrMonthName[8]="8";
arrMonthName[9]="9";
arrMonthName[10]="10";
arrMonthName[11]="11";
arrMonthName[12]="12";


arrMonthLength = new Array();
arrMonthLength[0] =0;
arrMonthLength[1] = 31;
arrMonthLength[2] = 31;
arrMonthLength[3] = 31;
arrMonthLength[4] = 31;
arrMonthLength[5] = 31;
arrMonthLength[6] = 31;
arrMonthLength[7] = 30;
arrMonthLength[8] = 30;
arrMonthLength[9] = 30;
arrMonthLength[10] = 30;
arrMonthLength[11] =30;
arrMonthLength[12] = 29;

arrMonthLengthK = new Array();
arrMonthLengthK[0] =0;
arrMonthLengthK[1] = 31;
arrMonthLengthK[2] = 31;
arrMonthLengthK[3] = 31;
arrMonthLengthK[4] = 31;
arrMonthLengthK[5] = 31;
arrMonthLengthK[6] = 31;
arrMonthLengthK[7] = 30;
arrMonthLengthK[8] = 30;
arrMonthLengthK[9] = 30;
arrMonthLengthK[10] = 30;
arrMonthLengthK[11] = 30;
arrMonthLengthK[12] = 30;

var arrYear = new Array();
var i;
arrYear[0] ="";
for( i = 1; i<= 50; i++)
	arrYear[i] = 1339+i;

function cFirstYearNoChanged(){
var YearNoTo = new Number(document.all.frm.test_YearTo.value);
var YearNoFrom = new Number(document.all.frm.test_YearFrom.value);
var MonthNoFrom = new Number(document.all.frm.test_MonthFrom.value);
var MonthNoTo = new Number(document.all.frm.test_MonthTo.value);
var DayNoFrom =  new Number(document.all.frm.test_DayFrom.value);
var DayNoTo =  new Number(document.all.frm.test_DayTo.value);
var DayNoK  = new Number(arrMonthLengthK[new Number(document.all.frm.test_MonthFrom.value)]);
var DayNo  = new Number(arrMonthLength[new Number(document.all.frm.test_MonthFrom.value)]);
if (YearNoFrom == YearNoTo || YearNoFrom >= YearNoTo)
{

CreateList("test_YearTo",YearNoFrom,50,"Year");

	
	if (MonthNoFrom >= MonthNoTo)
	{
		CreateList("test_MonthTo",MonthNoFrom,12,"Month");
		if (DayNoFrom >= DayNoTo)
		{ 	
			var mod = YearNoFrom % 33;
			if (mod == 1 || mod == 5 || mod == 9 || mod == 13 || mod == 17 || mod == 22 || mod == 26 || mod == 30)
			{
				
				CreateList("test_DayFrom",1,DayNoK,"Day");
				Select("test_DayFrom",DayNoFrom);
				CreateList("test_DayTo",DayNoFrom,DayNoK,"Day");
			}
			else
			{
				CreateList("test_DayFrom",1,DayNo,"Day");
				Select("test_DayFrom",DayNoFrom	);
				CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
				Select("test_DayTo",DayNoFrom);
		
				
			}
		}
	}
	 
}
else
{
CreateList("test_MonthFrom",0,12,"Month");
Select("test_MonthFrom",MonthNoFrom);
CreateList("test_MonthTo",0,12,"Month");
Select("test_MonthTo",MonthNoTo);
CreateList("test_YearTo",0,50,"Year");
 Select("test_YearTo",YearNoTo);
var mod = YearNoFrom % 33;
	if (mod == 1 || mod == 5 || mod == 9 || mod == 13 || mod == 17 || mod == 22 || mod == 26 || mod == 30)
	{
		
		CreateList("test_DayFrom",1,DayNoK,"Day");
		Select("test_DayFrom",DayNoFrom);
	}
	else
	{
		CreateList("test_DayFrom",1,DayNo,"Day");
		Select("test_DayFrom",DayNoFrom	);
	}
	
 }		
SetName(document.all.frm.test_DayTo.value,document.all.frm.test_DayFrom.value,document.all.frm.test_MonthTo.value,document.all.frm.test_MonthFrom.value,YearNoTo+1339,YearNoFrom+1339);
}

function cLastYearNoChanged(){
var YearNoTo = new Number(document.all.frm.test_YearTo.value);
var YearNoFrom = new Number(document.all.frm.test_YearFrom.value);
var MonthNoFrom = new Number(document.all.frm.test_MonthFrom.value);
var MonthNoTo = new Number(document.all.frm.test_MonthTo.value);
var DayNoK  = new Number(arrMonthLengthK[new Number(document.all.frm.test_MonthTo.value)]);
var DayNo  = new Number(arrMonthLength[new Number(document.all.frm.test_MonthTo.value)]);
var DayNoTo =  new Number(document.all.frm.test_DayTo.value);
var DayNoFrom =  new Number(document.all.frm.test_DayFrom.value);

if( document.all.frm.test_YearFrom.value == document.all.frm.test_YearTo.value)
{
CreateList("test_MonthTo",MonthNoFrom,12,"Month");
Select("test_MonthTo",MonthNoTo);

var mod = YearNoTo % 33;
		if (mod == 1 || mod == 5 || mod == 9 || mod == 13 || mod == 17 || mod == 22 || mod == 26 || mod == 30)
		{	
			if (document.all.frm.test_MonthFrom.value == document.all.frm.test_MonthTo.value)
			{
				if (DayNoTo < DayNoFrom)
				{
					CreateList("test_DayTo",DayNoFrom,DayNoK,"Day");
					Select("test_DayTo",DayNoFrom);
				}
				else
				{
					CreateList("test_DayTo",DayNoFrom,DayNoK,"Day");
					Select("test_DayTo",DayNoTo);
				}
				
			}
			else 
			{
				CreateList("test_DayTo",1,DayNoK,"Day");
				Select("test_DayTo",DayNoTo);
			}
		}
		else
		{
			
		if (document.all.frm.test_MonthTo.value == document.all.frm.test_MonthFrom.value)
			{
				if (DayNoTo < DayNoFrom)
				{
					CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
				}
				else
				{
					CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
					Select("test_DayTo",DayNoTo);
				}
			}
			else 
			{
				CreateList("test_DayTo",1,DayNo,"Day");
				Select("test_DayTo",DayNoTo);
			}
		
		}

}
else if(YearNoFrom < YearNoTo)
{
	CreateList("test_MonthTo",1,12,"Month");
	
	Select("test_MonthTo",MonthNoTo);
		
	var mod = YearNoTo % 33;
		if (mod == 1 || mod == 5 || mod == 9 || mod == 13 || mod == 17 || mod == 22 || mod == 26 || mod == 30)
		{
			
			CreateList("test_DayTo",1,DayNoK,"Day");
			Select("test_DayTo",DayNoTo);
			
		}
		else
		{
		CreateList("test_DayTo",1,DayNo,"Day");
		Select("test_DayTo",DayNoTo);
		
		}
}
SetName(document.all.frm.test_DayTo.value,document.all.frm.test_DayFrom.value,document.all.frm.test_MonthTo.value,document.all.frm.test_MonthFrom.value,YearNoTo+1339,YearNoFrom+1339);
		

}
function cFirstMonthNoChanged(){ 
var YearNoFrom = new Number(document.all.frm.test_YearFrom.value); 
var YearNoTo = new Number(document.all.frm.test_YearTo.value);
var DayNoFrom = new Number(document.all.frm.test_DayFrom.value);
var DayNoTo = new Number(document.all.frm.test_DayTo.value);
var DayNoK  = new Number(arrMonthLengthK[new Number(document.all.frm.test_MonthFrom.value)]);
var DayNo = new Number(arrMonthLength[new Number(document.all.frm.test_MonthFrom.value)]);
var MonthNoFrom = new Number(document.all.frm.test_MonthFrom.value);
var MonthNoTo = new Number(document.all.frm.test_MonthTo.value);
	if( MonthNoFrom == 12)
	{	
		
		var mod = YearNoFrom % 33;
		if (mod == 1 || mod == 5 || mod == 9 || mod == 13 || mod == 17 || mod == 22 || mod == 26 || mod == 30)
		{
			CreateList("test_DayFrom",1,DayNoK,"Day");
			Select("test_DayFrom",DayNoFrom);
			if (document.all.frm.test_YearFrom.value == document.all.frm.test_YearTo.value)
			{
				if(document.all.frm.test_MonthFrom.value == document.all.frm.test_MonthTo.value)
				{
					CreateList("test_DayTo",DayNoFrom,DayNoK,"Day");
					CreateList("test_MonthTo",MonthNoFrom,12,"Month");
				}
				else
				{
					CreateList("test_DayTo",DayNoFrom,DayNoK,"Day");
					CreateList("test_MonthTo",MonthNoFrom,12,"Month");
					Select("test_MonthTo",MonthNoTo);
				}
				
			}
			else 
			{
				Select("test_DayTo",DayNoTo);
				Select("test_MonthTo",MonthNoTo);
			}
	
		}
		else
		{
			CreateList("test_DayFrom",1,DayNo,"Day");
			Select("test_DayFrom",DayNoFrom	);
			if (document.all.frm.test_YearFrom.value == document.all.frm.test_YearTo.value)
			{
				if (document.all.frm.test_MonthFrom.value == document.all.frm.test_MonthTo.value)
				{
					CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
					CreateList("test_MonthTo",MonthNoFrom,12,"Month");
				}
				else
				{
					CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
					CreateList("test_MonthTo",MonthNoFrom,12,"Month");
					Select("test_MonthTo",MonthNoTo);
				}
			}
			else 
			{
				Select("test_DayTo",DayNoTo);
				Select("test_MonthTo",MonthNoTo);
			}
		}
	}
	else
	{
	
	CreateList("test_DayFrom",1,DayNo,"Day");
	Select("test_DayFrom",DayNoFrom);
	if (document.all.frm.test_YearFrom.value == document.all.frm.test_YearTo.value)
	{
	
		if (document.all.frm.test_MonthFrom.value == document.all.frm.test_MonthTo.value)
		{
		
			CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
			CreateList("test_MonthTo",MonthNoFrom,12,"Month");
		}
		else
		{
			CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
			Select("test_DayTo",DayNoTo);
			CreateList("test_MonthTo",MonthNoFrom,12,"Month");
		}
	}
	else 
	{
		Select("test_DayTo",DayNoTo);
		Select("test_MonthTo",MonthNoTo);
	}
	}
SetName(document.all.frm.test_DayTo.value,document.all.frm.test_DayFrom.value,document.all.frm.test_MonthTo.value,document.all.frm.test_MonthFrom.value,YearNoTo+1339,YearNoFrom+1339);
}
function cLastMonthNoChanged(){
var YearNoTo = new Number(document.all.frm.test_YearTo.value);
var YearNoFrom = new Number(document.all.frm.test_YearFrom.value);
var DayNoFrom = new Number(document.all.frm.test_DayFrom.value);
var DayNoTo = new Number(document.all.frm.test_DayTo.value);
var MonthNoTo = new Number(document.all.frm.test_MonthTo.value);
var MonthNoFrom = new Number(document.all.frm.test_MonthFrom.value);
var DayNoK = new Number(arrMonthLengthK[new Number(document.all.frm.test_MonthTo.value)]);
var DayNo = new Number(arrMonthLength[new Number(document.all.frm.test_MonthTo.value)]);
	
	if(MonthNoTo == 12)
	{
	
		var mod = YearNoTo % 33;
		if (mod == 1 || mod == 5 || mod == 9 || mod == 13 || mod == 17 || mod == 22 || mod == 26 || mod == 30)
		{
			if (document.all.frm.test_YearFrom.value == document.all.frm.test_YearTo.value)
			{
				if(document.all.frm.test_MonthFrom.value == document.all.frm.test_MonthTo.value)
				{
					CreateList("test_DayTo",DayNoFrom,DayNoK,"Day");
					CreateList("test_MonthTo",MonthNoFrom,12,"Month");
				}
				else
				{
					CreateList("test_DayTo",DayNoFrom,DayNoK,"Day");
					CreateList("test_MonthTo",MonthNoFrom,12,"Month");
					Select("test_MonthTo",MonthNoTo);
				}
				
			}
			else 
			{	CreateList("test_DayTo",0,DayNoK,"Day");
				Select("test_DayTo",DayNoTo);
				Select("test_MonthTo",MonthNoTo);
			}
			
			
		
		}
		else
		
		{
		
			if (document.all.frm.test_YearFrom.value == document.all.frm.test_YearTo.value)
			{
				
				if (document.all.frm.test_MonthFrom.value == document.all.frm.test_MonthTo.value)
				{
				
					CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
					CreateList("test_MonthTo",MonthNoFrom,12,"Month");
				}
				else
				{
					CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
					Select("test_DayTo",DayNoTo);
					CreateList("test_MonthTo",MonthNoFrom,12,"Month");
				}
			}
			else 
			{	CreateList("test_DayTo",0,DayNo,"Day");
				Select("test_DayTo",DayNoTo);
				Select("test_MonthTo",MonthNoTo);
			}
		}
	}
	else
	{
	if (document.all.frm.test_YearFrom.value == document.all.frm.test_YearTo.value)
	{
	
		if (document.all.frm.test_MonthFrom.value == document.all.frm.test_MonthTo.value)
		{
		
			CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
			CreateList("test_MonthTo",MonthNoFrom,12,"Month");
		}
		else
		{
			CreateList("test_DayTo",DayNoFrom,DayNo,"Day");
			Select("test_DayTo",DayNoTo);
			CreateList("test_MonthTo",MonthNoFrom,12,"Month");
		}
	}
	else 
	{	CreateList("test_DayTo",0,DayNo,"Day");
		Select("test_DayTo",DayNoTo);
		Select("test_MonthTo",MonthNoTo);
	}
		
	}
SetName(document.all.frm.test_DayTo.value,document.all.frm.test_DayFrom.value,document.all.frm.test_MonthTo.value,document.all.frm.test_MonthFrom.value,YearNoTo+1339,YearNoFrom+1339);
}
function cFirstDayChanged(){
var YearNoFrom = new Number(document.all.frm.test_YearFrom.value); 
var YearNoTo = new Number(document.all.frm.test_YearTo.value);
var MonthNoFrom = new Number(document.all.frm.test_MonthFrom.value);
var MonthNoTo = new Number(document.all.frm.test_MonthTo.value);
var DayNoFrom = new Number(document.all.frm.test_DayFrom.value);
var DayNo2 = new Number(arrMonthLength[new Number(document.all.frm.test_MonthTo.value)]);
var DayNo1 = new Number(arrMonthLength[new Number(document.all.frm.test_MonthFrom.value)]);
var DayNoK = new Number(arrMonthLengthK[new Number(document.all.frm.test_MonthFrom.value)]);
var DayNoTo = new Number(document.all.frm.test_DayTo.value);
if(document.all.frm.test_YearTo.value == document.all.frm.test_YearFrom.value)
{
	if(MonthNoTo>6)	
	{			 
		if(MonthNoFrom == 12)
		{
		
			var mod = YearNoFrom % 33;
			if (mod == 1 || mod == 5 || mod == 9 || mod == 13 || mod == 17 || mod == 22 || mod == 26 || mod == 30)
			{
				if(DayNoFrom > 30)
					alert("كام 30 رنز است.");
				else
				{
					CreateList("test_DayTo",DayNoFrom,DayNoK,"Day");
				}
			}
			else
			{
				if(DayNoFrom > 29)
					alert("كام 29 رنز است.");
				else
				{
					CreateList("test_DayTo",DayNoFrom,DayNo1,"Day");
				}
			}
				
		}
		else	
		{
			if(DayNoFrom >30)
				alert("كام 30 رنز است.");
			else
				//Select("test_DayTo",DayNoFrom);
				CreateList("test_DayTo",DayNoFrom,DayNo1,"Day");
		}
	}
	else
	{
		
		CreateList("test_DayTo",DayNoFrom,DayNo1,"Day");	
	}		 
}
else 
{
	if(YearNoFrom < YearNoTo)
	{
		if(MonthNoTo>6)	
		{			 
			if(MonthNoFrom == 12)
			{
			
				var mod = YearNoFrom % 33;
				if (mod == 1 || mod == 5 || mod == 9 || mod == 13 || mod == 17 || mod == 22 || mod == 26 || mod == 30)
				{
					if(DayNoFrom > 30)
						alert("كام 30 رنز است.");
					else
					Select("test_DayTo",DayNoTo);
					//CreateList("test_DayTo",1,DayNo,"Day");
				}
				else
				{
					if(DayNoFrom > 29)
						alert("كام 29 رنز است.");
					else
					Select("test_DayTo",DayNoTo);
					//Select("test_DayTo",DayNoFrom);
				}
					
			}
			else	
			{
				if(DayNoFrom >30)
					alert("كام 30 رنز است.");
				else
				Select("test_DayTo",DayNoTo);
				//Select("test_DayTo",DayNoFrom);
				
			}
		}	
	}
}
SetName(document.all.frm.test_DayTo.value,document.all.frm.test_DayFrom.value,document.all.frm.test_MonthTo.value,document.all.frm.test_MonthFrom.value,YearNoTo+1339,YearNoFrom+1339);
}
function CreateList(objName,From,To,Tag){
	var	obj=document.getElementById(objName);

	obj.innerHTML =" ";
	for (i=From;i<=To;i++)
	
	{
		var Option = document.createElement("OPTION");
		if (Tag=="Month"){
			if(i==0)
			{
				Option.text="";
			}
			else{
			Option.text=arrMonthName[i];}
		}
		else if (Tag=="Day")
		{	if(i==0)
			{
				Option.text="";
			}
					else{
			Option.text=i;}
		}
		else if(Tag == "Year")
		{
			Option.text = arrYear[i];
		}
			
		Option.value=i;
		obj.add(Option);
		
	}
}
function Select(objName,SelectValue)
{ 
	var	obj=document.getElementById(objName);
	obj.value = SelectValue;
}
		

function SetName (dta,dfa,mta,mfa,yta,yfa)
{
if(dta == "")
 dta = "0";
 if(dfa == "")
 dfa = "0";
 if(mta == "")
 mta = "0";
 if(mfa == "")
 mfa = "0";
 if(yta == "1339")
 yta = "0";
 if(yfa == "1339")
 yfa = "0";
 
var name = 'ndta:'+dta+';ndfa:'+dfa+';nmta:'+mta+';nmfa:'+mfa+';nyta:'+yta+';nyfa:'+yfa;
document.getElementById('HideF').value = name;
}

