﻿var directory = "";
var monthLength = new Array(31,31,31,31,31,31,30,30,30,30,30,30);
var hiddenArray = new Array(35);

var currentyear = 1390;
var currentmonth = 0;
var dp_dir = "";
var newWin_doc = null;
var newWin = null;
var txtboxObj = null;

function formatdate(dd,mm,yy){
	var dstr = "";
	if (dd<10) {dstr += '0' ;}
	dstr += dd;	
	dstr += "/";
	if (mm<10) {dstr += '0' ;}
	dstr += mm;
	dstr += "/";
	dstr += yy;
	return dstr;
	}
function formatdate2(dd,mm,yy){
	var dstr = "";
	dstr += yy;
	if (mm<10) {dstr += '0' ;}
	dstr += mm;
	if (dd<10) {dstr += '0' ;}
	dstr += dd;	
	
	return dstr;
	}
		function returndate(indx){
	   		if(hiddenArray[indx] > 0) {
				if (txtboxObj) {
					document.getElementById(txtboxObj).value = formatdate(hiddenArray[indx],newWin_doc.getElementById('months').options.selectedIndex+1,parseInt(newWin_doc.getElementById('years').value));
					document.getElementById(txtboxObj2).value = formatdate2(hiddenArray[indx],newWin_doc.getElementById('months').options.selectedIndex+1,parseInt(newWin_doc.getElementById('years').value));
					//document.getElementById(txtboxObj).value = formatdate(parseInt(newWin_doc.getElementById('years').value),newWin_doc.getElementById('months').options.selectedIndex+1,hiddenArray[indx]);
					//document.getElementById(txtboxObj2).value = formatdate2(hiddenArray[indx],newWin_doc.getElementById('months').options.selectedIndex+1,parseInt(newWin_doc.getElementById('years').value));
			}
				newWin.close();
			}	   		
		}
		function updateoutput() {
			var ml = newWin_doc.getElementById('months').options.selectedIndex;
			var sday = new Date(parseInt(newWin_doc.getElementById('years').value),ml,01);
			var startindex = 1;
			var numberOfDays = monthLength[ml];
			if (startindex==0) {startindex = 7;}

			for (var n=0; n<3; n++) {
				var str = "c"+n;
				newWin_doc.getElementById(str).src =dp_dir + "0.gif";
				hiddenArray[n] = 0;
			}
			
			for (var m=0; m<numberOfDays; m++)
			{
				var str = "c"+((startindex+m-1)%35);
				newWin_doc.getElementById(str).src =dp_dir + (m+1) + ".gif";
				hiddenArray[((startindex+m-1)%35)] = (m+1);
			}
		}
		
	
	function show_calendar(textfieldname, textfieldname2, dir) {
	if (dir) {dp_dir = dir;}
		newWin = window.open("", "Calendar", "width=202,height=152,status=no,resizable=no,toolbar=no,menubar=no,scrollbars=no,top=200,left=200");
	newWin.opener = self;
	newWin_doc = newWin.document;
	txtboxObj = textfieldname;
	txtboxObj2 = textfieldname2;
 	
		newWin_doc.writeln('<html dir=rtl><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1256"/><link href="../Common/css/bim.css" rel="stylesheet" type="text/css" /><title>لطفا انتخاب کنيد</title></head>');
	newWin_doc.writeln('<body  style="margin: 0px;" scroll=no  onBlur="self.focus()">');
	newWin_doc.writeln('<div align=\"center\"><table bgcolor="#003399" width="200" cellpadding="0" cellspacing="0" dir="rtl"><tr><td align="center" height="35">');
	newWin_doc.writeln('<select id="months" class="cCalender" onchange="window.opener.updateoutput();">');
	newWin_doc.writeln('<option value="01">فروردين</option>');
	newWin_doc.writeln('<option value="02">ارديبهشت</option>');
	newWin_doc.writeln('<option value="03">خرداد</option>');
	newWin_doc.writeln('<option value="04">تير</option>');
	newWin_doc.writeln('<option value="05">مرداد</option>');
	newWin_doc.writeln('<option value="06">شهريور</option>');
	newWin_doc.writeln('<option value="07">مهر</option>');
	newWin_doc.writeln('<option value="08">آبان</option>');
	newWin_doc.writeln('<option value="09">آذر</option>');
	newWin_doc.writeln('<option value="10">دي</option>');
	newWin_doc.writeln('<option value="11">بهمن</option>');
	newWin_doc.writeln('<option value="12">اسفند</option>');
	newWin_doc.writeln('</select>&nbsp;');
	
	newWin_doc.getElementById('months').options.selectedIndex = parseInt(currentmonth);
	newWin_doc.writeln('<select lang="ar" dir="rtl" id="years" class="cCalender" onchange="window.opener.updateoutput();">');
	var styear = 1301;
	for (var i=0; i <= 89; i++) {
		newWin_doc.write("<option id=\"yopt"+ i +"\" value=\""+ (styear+i) +"\">" + (styear+i) +"</option>\n");
	}
	newWin_doc.writeln('</select>&nbsp;');
	for (var i = 0; i < newWin_doc.getElementById('years').options.length; i++ )
	{
		if (newWin_doc.getElementById('years').options[i].value == ""+currentyear)
		{
	  		newWin_doc.getElementById('years').options.selectedIndex = i;
			break;
		}
	}
	
	newWin_doc.writeln('</td></tr>');
	newWin_doc.writeln('<tr><td>');
	newWin_doc.writeln('<TABLE width="100%" cellpadding="1px" cellspacing="1px">');
	newWin_doc.writeln('<TBODY>');
	newWin_doc.writeln("<tr>");
	for (var j=1;j<=35;j++){
 		newWin_doc.writeln("<td align=\"center\" valign=\"middle\" width=\"25px\" bgcolor='#ffffff' class='cCalender' onmouseover=\"this.bgColor='#ff8000';\" onmouseout=\"this.bgColor='#ffffff'\"><a href=\"#\"><img id=\"c"+(j-1)+"\" src=\""+ dp_dir +"0.gif\" onclick=\"window.opener.returndate("+(j-1)+");\" border=\"0\"></a></td>");
		if ((j % 7) == 0) 
			{newWin_doc.writeln("</tr>");}
			}
	newWin_doc.writeln("</tr>");
	newWin_doc.writeln('</TBODY></TABLE>');	
	newWin_doc.writeln('</td></tr></table></div>');
	updateoutput();
	newWin_doc.writeln('</body></html>');
	if(navigator.appName != "Microsoft Internet Explorer")
  	{
		newWin_doc.close();
  	}
}





