start=false;
bid='';
eid='';
a = new Array();

function c0(i,j) {
	i += '';
	j += '';
	if ((i < 10) && (i.charAt(0)!='0')) {
		iPrefix = '0';
	} else {
		iPrefix = '';
	}
	if ((j < 10) && (j.charAt(0)!='0')) {
		jPrefix = '0';
	} else {
		jPrefix = '';
	}
	tempId = iPrefix + i + jPrefix + j;
	return tempId;
}

function c1(id) {
	if (start == false) {
		bid = id;
		start = true;
		br=bid.charAt(0) + '' + bid.charAt(1);
		bc=bid.charAt(2) + '' + bid.charAt(3);
	} else {
		eid = id;
		start = false;
		er=eid.charAt(0) + '' + eid.charAt(1);
		ec=eid.charAt(2) + '' + eid.charAt(3);
		c2();
	}
}

function c2() {
	temp='';
	cid='';
	if (((er == br) && (ec >= bc)) || ((er >= br) && (ec == bc))) {
		count = 0;
		for (i=br;i<=er;i++) {
			for (j=bc;j<=ec;j++) {
				cid=c0(i,j);
				temp+=document.getElementById(cid).innerHTML;
				a[count]=cid;
				count++;
			}
		}
	

	} else if (((er == br) && (ec <= bc)) || ((er <= br) && (ec == bc))) {
		count = 0;
		for (i=br;i>=er;i--) {
			for (j=bc;j>=ec;j--) {
				cid=c0(i,j);
				temp+=document.getElementById(cid).innerHTML;
				a[count]=cid;
				count++;
			}
		}

	} else if ((er < br) && (ec >= bc)) {
		count = 0;
		for (i=br,j=bc;(i>=er) && (j<=ec);i--,j++) {
			cid=c0(i,j);
			temp+=document.getElementById(cid).innerHTML;
			a[count]=cid;
			count++;
		}


	} else if ((er >= br) && (ec < bc)) {
		count = 0;
		for (i=br,j=bc;(i<=er)&&(j>=ec);i++,j--) {
			cid=c0(i,j);
			temp+=document.getElementById(cid).innerHTML;
			a[count]=cid;
			count++;
		}

	} else if ((er < br) && (ec < bc)) {
		count = 0;	
		for (i=br,j=bc;(i>=er && j>=ec);i--,j--) {
			cid=c0(i,j);
			temp+=document.getElementById(cid).innerHTML;
			a[count]=cid;
			count++;
		}

	} else if ((er > br) && (ec > bc)) {
		count = 0;	
		for (i=br,j=bc;(i<=er && j<=ec);i++,j++) {
			cid=c0(i,j);
			temp+=document.getElementById(cid).innerHTML;
			a[count]=cid;
			count++;
		}

	}
	if (document.getElementById(temp)!=null) {
		document.getElementById(temp).style.background='#ff00cc';
		for (k=0;k<a.length;k++) {
			if (a[k]!='') {
				document.getElementById(a[k]).style.background='#ff00cc';
				a[k]='';
			}
		}
	}
}

