
function runit(){

var iRows = parseInt(rows,10);
var paddedRow = '';
var paddedRowPlusOne = '';
var iplusone;

for (i = 1; i <= iRows; i++) {

	paddedRow = '0000' + i;	
	iplusone = i + 1;
	paddedRowPlusOne = '0000' + iplusone;
	
        debugMessage("Leaving " + paddedRow, -1) ;
	debugMessage("Leaving " + paddedRowPlusOne, -1) ;
	
	if(i<iRows){

		var STARTDAY  = $('STARTDAY' + paddedRow);
		var STARTMONTH  = $('STARTMONTH' + paddedRow);
		var STARTYEAR  = $('STARTYEAR' + paddedRow);

		var ENDDAY  = $('ENDDAY' + paddedRow);
		var ENDMONTH  = $('ENDMONTH' + paddedRow);
		var ENDYEAR  = $('ENDYEAR' + paddedRow);

		var STARTDAYnext  = $('STARTDAY' + paddedRowPlusOne);
		var STARTMONTHnext  = $('STARTMONTH' + paddedRowPlusOne);
		var STARTYEARnext  = $('STARTYEAR' + paddedRowPlusOne);

		var ENDDAYnext  = $('ENDDAY' + paddedRowPlusOne);
		var ENDMONTHnext  = $('ENDMONTH' + paddedRowPlusOne);
		var ENDYEARnext  = $('ENDYEAR' + paddedRowPlusOne);
		var bValidComp = true;
		
		if((STARTDAYnext.value == '') || (STARTMONTHnext.value == '') || (STARTYEARnext.value == '')){
			bValidComp = false;
		}
		
		
		ENDDAY.className = 'field';
		ENDMONTH.className = 'field';
		ENDYEAR.className = 'field';
		STARTDAYnext.className   = 'field';
		STARTMONTHnext.className = 'field';   
		STARTYEARnext.className  = 'field';  

		
		
		var sStartDateToCompare = STARTYEARnext.value + STARTMONTHnext.value + STARTDAYnext.value;
		var sEndDateToCompare = ENDYEAR.value + ENDMONTH.value + ENDDAY.value;
	
		var uoDate = new DateAddCustom(ENDYEAR.value,ENDMONTH.value,ENDDAY.value);
		uoDate.AddDay(1);
		
		//Check that dates are contiguous if the next start date is not entered, don't do the comparison
		if((uoDate.sNewDateIso != sStartDateToCompare) && (bValidComp)){
			alert("Next date must be 1 day after for row " + paddedRow + "-" + paddedRowPlusOne + " :, should be " + uoDate.sNewDateIso + ",actually " + sStartDateToCompare);
			ENDDAY.className = 'fieldError';
			ENDMONTH.className = 'fieldError';
			ENDYEAR.className = 'fieldError';
			STARTDAYnext.className   = 'fieldError';
			STARTMONTHnext.className = 'fieldError';   
			STARTYEARnext.className  = 'fieldError';  
		}
	
	}

}




}


// Constructor
function DateAddCustom(sYear,sMonth,sDay) {


this.sYear = sYear;
this.sMonth = sMonth;
this.sDay = sDay
this.sNewDateIso = '';
this.sNewYear = '';
this.sNewMonth = '';
this.sNewDay = '';

}


DateAddCustom.prototype.AddDay = function(iDaysToAdd) {


var dNewDate=new Date();

//Convert to numerics - note take 1 of month as its zero based for some stupid reason
this.iYear = parseInt(this.sYear,10);
this.iMonth = parseInt(this.sMonth,10) - 1;
this.iDay = parseInt(this.sDay,10);

//Set the Date Passed then add 1 to it
dNewDate.setFullYear(this.iYear,this.iMonth,this.iDay) 
dNewDate.setDate(dNewDate.getDate()+iDaysToAdd) 

//Get the new date with X added
this.iNewDay = dNewDate.getDate();
this.iNewMonth = dNewDate.getMonth() + 1;
this.iNewYear = dNewDate.getFullYear();

//Build up the new date in iso format
var sNewDate = '';

sNewDate+= this.iNewYear;
this.sNewYear = this.iNewYear;

if(this.iNewMonth > 9){
	sNewDate+= this.iNewMonth;
	this.sNewMonth = '' + this.iNewMonth;
}
else{
	sNewDate+= '0' + this.iNewMonth;
	this.sNewMonth = '0' + this.iNewMonth;	

}

if(this.iNewDay > 9){
	sNewDate+= this.iNewDay;
	this.sNewDay = '' + this.iNewDay;
}
else{
	sNewDate+= '0' + this.iNewDay;
	this.sNewDay = '0' + this.iNewDay;	

}

this.sNewDateIso = sNewDate;

}


