var days = new Array();
var msgs = new Array();
days[0] = "December 20, 1999";
msgs[0] = "Thanks for stopping by on my birthday!";
days[1] = "December 21, 1999";
msgs[1] = "Not Christmas yet, it's only the 21st.";
days[2] = "December 22, 1999";
msgs[2] = "Another day closer, almost there!";
days[3] = "December 23, 1999";
msgs[3] = "Wow, tomorrow is Christmas Eve!";
days[4] = "December 24, 1999";
msgs[4] = "It's Christmas Eve, thanks for visiting!";
days[5] = "December 25, 1999";
msgs[5] = "Welcome to this page on Christmas Day!";
var months = new Array("", 
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
);
var nummonths = new Array("", 
01, 02, 03, 04, 05, 06,
07, 08, 09, 10, 11, 12
);

// Y2K Fix Function
function y2k(year) {
	if (year < 2000){		
		year = year + 1900;
	}
	return year;
}

var today = new Date(); // today
var mon = months[today.getMonth() + 1]; // month
var nummon = nummonths[today.getMonth() + 1]; //return number of month
var day = today.getDate(); // day
var year = y2k(today.getYear()); // year

function fillSelectFromArray(selectCtrl) {
	var i=0, j=1;
	var maxdays = 0;
      tonow = new Date();
	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null; 
	}
      thismonth = document.requestform.frommonth.value;
      thisyear = document.requestform.fromyear.value;
	
      thisday = tonow.getDate();
      montharray=new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      maxdays=montharray[thismonth-1];
	
      if (thismonth==2) {
      	if ((thisyear/4)!=parseInt(thisyear/4)) maxdays=28;
     	 	else maxdays=29;
      }
      for (i = 0; i < maxdays; i++) {
      	selectCtrl.options[i] = new Option(j);
      	selectCtrl.options[i].value = j; 
      	j++;
      }
}
function fillSelectToArray(selectCtrl) {
	var i=0, j=1;
	var tomaxdays = 0;
	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null; 
	}
      tothen = new Date();
	tomonth = document.requestform.tomonth.value;
	toyear = document.requestform.toyear.value;
	
	thisday = tothen.getDate();
      montharray=new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      tomaxdays=montharray[tomonth-1];

      if (tomonth==2) {
      	if ((toyear/4)!=parseInt(toyear/4)) tomaxdays=28;
     	 	else tomaxdays=29;
      }
	
      for (i = 0; i < tomaxdays; i++) {
      	selectCtrl.options[i] = new Option(j);
      	selectCtrl.options[i].value = j; 
      	j++;
      }
}
function fillSelectFromArray2(selectCtrl) {
	var i=0, j=1;
	var maxdays = 0;
      tonow = new Date();
	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null; 
	}
      thismonth = document.requestform.selOrderValidFromMonth.value;
      thisyear = document.requestform.selOrderValidFromYear.value;
	
      thisday = tonow.getDate();
      montharray=new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      maxdays=montharray[thismonth-1];
	
      if (thismonth==2) {
      	if ((thisyear/4)!=parseInt(thisyear/4)) maxdays=28;
     	 	else maxdays=29;
      }
      for (i = 0; i < maxdays; i++) {
      	selectCtrl.options[i] = new Option(j);
      	selectCtrl.options[i].value = j; 
      	j++;
      }
}
function fillSelectToArray2(selectCtrl) {
	var i=0, j=1;
	var tomaxdays = 0;
	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null; 
	}
      tothen = new Date();
	tomonth = document.requestform.selOrderValidToMonth.value;
	toyear = document.requestform.selOrderValidToYear.value;
	
	thisday = tothen.getDate();
      montharray=new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      tomaxdays=montharray[tomonth-1];

      if (tomonth==2) {
      	if ((toyear/4)!=parseInt(toyear/4)) tomaxdays=28;
     	 	else tomaxdays=29;
      }
	
      for (i = 0; i < tomaxdays; i++) {
      	selectCtrl.options[i] = new Option(j);
      	selectCtrl.options[i].value = j; 
      	j++;
      }
}

function changeDMY(){
	fromdate = document.requestform.fromdate;
	frommonth = document.requestform.frommonth;
	fromyear = document.requestform.fromyear;
	todate = document.requestform.todate;
	tomonth = document.requestform.tomonth;
	toyear = document.requestform.toyear;

	//now calculate 7 days in advance
	var ctoday = (day + 2);
	var cnummon = nummon;
	var cnumyear = year;
	var differ = 0;
	var differ2 = 0;
	//now calculate next day
	var tomorrow = (ctoday + 1);
	var tonummon = nummon;
	var tonumyear = year;
	
	if (ctoday > 31 && cnummon+1 > 12){
		differ = ctoday - 31;
		frommonth.selectedIndex = 0;
		fromyear.selectedIndex = fromyear.selectedIndex + 1;
		if(differ < 0){ differ = 0 }
		if(differ > 0){ fromdate.selectedIndex = differ-1; }
	}else if (ctoday > 31 && (cnummon == 1 || cnummon == 3 || cnummon == 5 || cnummon == 7 || cnummon == 8 || cnummon == 10)){
		differ2 = ctoday - 31;
		tomonth.selectedIndex = today.getMonth()+1;
		fillSelectToArray(document.requestform.todate);
		todate.selectedIndex = 0;
		if(differ2 < 0){ differ2 = 0 }
		if(differ2 > 0){ todate.selectedIndex = differ2; }
	}else if (ctoday > 30 && (cnummon == 4 || cnummon == 6 || cnummon == 9 || cnummon == 11)){
		differ2 = ctoday - 30;
		tomonth.selectedIndex = today.getMonth()+1;
		fillSelectToArray(document.requestform.todate);
		todate.selectedIndex = 0;
		if(differ2 < 0){ differ2 = 0 }
		if(differ2 > 0){ todate.selectedIndex = differ2; }
	}else if (ctoday > 28 && cnummon == 2){
		differ2 = ctoday - 28;
		tomonth.selectedIndex = today.getMonth()+1;
		fillSelectToArray(document.requestform.todate);
		todate.selectedIndex = 0;
		if(differ2 < 0){ differ2 = 0 }
		if(differ2 > 0){ todate.selectedIndex = differ2; }	
	}else{
		frommonth.selectedIndex = today.getMonth();
		fillSelectFromArray(document.requestform.fromdate);
		fromyear.selectedIndex = 0;
		fromdate.options.value = ctoday;
	}
	
	if (tomorrow > 31 && tonummon+1 > 12){
		differ2 = ctoday - 31;
		tomonth.selectedIndex = 0;
		toyear.selectedIndex = toyear.selectedIndex + 1;
		todate.selectedIndex = 0;
		if(differ2 < 0){ differ2 = 0 }
		if(differ2 > 0){ todate.selectedIndex = differ2; }
	}else if (tomorrow > 31 && (tonummon == 1 || tonummon == 3 || tonummon == 5 || tonummon == 7 || tonummon == 8 || tonummon == 10)){
		differ = ctoday - 31;
		tomonth.selectedIndex = today.getMonth()+1;
		fillSelectFromArray(document.requestform.todate);
		if(differ < 0){ differ = 0 }
		if(differ > 0){ todate.selectedIndex = differ-1; }
	}else if (tomorrow > 30 && (tonummon == 4 || tonummon == 6 || tonummon == 9 || tonummon == 11)){
		differ = ctoday - 30;
		tomonth.selectedIndex = today.getMonth()+1;
		fillSelectFromArray(document.requestform.todate);
		if(differ < 0){ differ = 0 }
		if(differ > 0){ todate.selectedIndex = differ-1; }
	}else if (tomorrow > 28 && tonummon == 2){
		differ = ctoday - 28;
		tomonth.selectedIndex = today.getMonth()+1;
		fillSelectFromArray(document.requestform.todate);
		if(differ < 0){ differ = 0 }
		if(differ > 0){ todate.selectedIndex = differ-1; }	
	}else{
		tomonth.selectedIndex = today.getMonth();
		fillSelectFromArray(document.requestform.todate);
		toyear.selectedIndex = 0;
		todate.options.value = tomorrow;
	}
}

function changeDMYPackage(){
	fromdate = document.requestform.fromdate;
	frommonth = document.requestform.frommonth;
	fromyear = document.requestform.fromyear;
	
	//now calculate 7 days in advance
	var ctoday = (day + 3);
	var cnummon = nummon;
	var cnumyear = year;
	var differ = 0;
	
	if (ctoday > 31 && cnummon+1 > 12){
		differ = ctoday - 31;
		frommonth.selectedIndex = 0;
		fromyear.selectedIndex = fromyear.selectedIndex + 1;
		if(differ < 0){ differ = 0 }
		if(differ > 0){ fromdate.selectedIndex = differ-1; }
	}else if (ctoday > 31 && (cnummon == 1 || cnummon == 3 || cnummon == 5 || cnummon == 7 || cnummon == 8 || cnummon == 10)){
		differ = ctoday - 31;
		frommonth.selectedIndex = today.getMonth()+1;
		fillSelectFromArray(document.requestform.fromdate);
		if(differ < 0){ differ = 0 }
		if(differ > 0){ fromdate.selectedIndex = differ-1; }
	}else if (ctoday > 30 && (cnummon == 4 || cnummon == 6 || cnummon == 9 || cnummon == 11)){
		differ = ctoday - 30;
		frommonth.selectedIndex = today.getMonth()+1;
		fillSelectFromArray(document.requestform.fromdate);
		if(differ < 0){ differ = 0 }
		if(differ > 0){ fromdate.selectedIndex = differ-1; }
	}else if (ctoday > 28 && cnummon == 2){
		differ = ctoday - 28;
		frommonth.selectedIndex = today.getMonth()+1;
		fillSelectFromArray(document.requestform.fromdate);
		if(differ < 0){ differ = 0 }
		if(differ > 0){ fromdate.selectedIndex = differ-1; }	
	}else{
		frommonth.selectedIndex = today.getMonth();
		fillSelectFromArray(document.requestform.fromdate);
		fromyear.selectedIndex = 0;
		fromdate.options.value = ctoday;
	}
}