SAWDraw = function(){alert("Trying to create instance of static class SAWDraw");}

SAWDraw.getTextSize = function(vDrawEl, sText){
	var vSpan = document.createElement('span');
	vSpan.style.position='absolute';
	vSpan.style.left = '100px';
	vSpan.style.top = '100px';
	vSpan.style.color = '#FFFFFF';
	vSpan.innerHTML = sText;
	vDrawEl.appendChild(vSpan);
	var iRet = new Object();
	iRet.width = vSpan.offsetWidth;
	iRet.height = vSpan.offsetHeight;
	vDrawEl.removeChild(vSpan);
	return iRet;
}

SAWDraw.vline = function(vDrawEl, ix, iyMin, iyMax, sClassName){
	if(!sClassName) sClassName = 'SAWDraw__default';
	var 
		vTable = document.createElement('table'),
		vRow = vTable.insertRow(0),
		vCell = vRow.insertCell(0);
	vCell.style.position = 'absolute';
	vCell.style.left = ix+'px';
	vCell.style.top = iyMin+'px';
	vCell.innerHTML = '<span style="font-size:1px">&nbsp;</span>'; // might be a problem with background - set background color!
	vCell.style.borderWidth = '0px';
	vCell.style.borderLeftWidth = '1px';
	vCell.style.borderLeftStyle = 'solid';
	
	vCell.style.height = (iyMax-iyMin)+'px';
	vCell.className = sClassName;
	vDrawEl.appendChild(vTable);
	
	SAWUtils.setElementHeight(vCell, Math.abs(iyMax-iyMin));
	return vTable;
}

SAWDraw.hline = function(vDrawEl, iy, ixMin, ixMax, sClassName){
	if(!sClassName) sClassName = 'SAWDraw__default';
	var 
		vTable = document.createElement('table'),
		vRow = vTable.insertRow(0),
		vCell = vRow.insertCell(0);
	vCell.style.position = 'absolute';
	vCell.style.left = ixMin+'px';
	vCell.style.top = iy+'px';
	vCell.innerHTML = '<span style="font-size:1px">&nbsp;</span>'; // might be a problem with background - set background color!
	vCell.style.borderWidth = '0px';
	vCell.style.borderTopWidth = '1px';
	vCell.style.borderTopStyle = 'solid';
	
	vCell.style.width = (ixMax-ixMin)+'px';
	vCell.className = sClassName;
	vDrawEl.appendChild(vTable);
	
	SAWUtils.setElementWidth(vCell, ixMax-ixMin);
	return vTable;
}

SAWDraw.text = function(vDrawEl, ix, iy, sText, iCenter1, iCenter2, sClassName){
	if(!sClassName) sClassName = 'SAWDraw__default';
	if(!iCenter1) iCenter1=0;
	if(!iCenter2) iCenter2=0;
	
	var vSize;
	if(iCenter1!=0 || iCenter2!=2) vSize = SAWDraw.getTextSize(vDrawEl, sText);
	if(iCenter1==1) ix -= vSize.width/2;  else if(iCenter1==2) ix -= vSize.width;
	if(iCenter2==1) iy -= vSize.height/2;  else if(iCenter2==0) iy -= vSize.height;
	
	var vSpan = document.createElement('span');
	vSpan.style.position='absolute';
	vSpan.style.left = ix+'px';
	vSpan.style.top = iy+'px';
	vSpan.innerHTML = sText;
	vSpan.className = sClassName;
	vDrawEl.appendChild(vSpan);
}

SAWDraw.rectangle = function(vDrawEl, ixMin, iyMin, ixMax, iyMax, sFillColor, sClassName, sInnerBorderColor){
	if(!sClassName) sClassName = 'SAWDraw__default__rectangle';
	var 
		vTable = document.createElement('table'),
		vRow = vTable.insertRow(0),
		vCell = vRow.insertCell(0);
	
	if(Math.abs(iyMax-iyMin)<4){
		for(var i=Math.min(iyMax,iyMin); i<=Math.max(iyMax, iyMin); i++){
			vEl = SAWDraw.hline(vDrawEl, i, ixMin, ixMax, sClassName);
		}
		return vEl; // just returns the last line
	}
	
	vTable.cellSpacing=0;
	vTable.cellPadding=0;
	vTable.style.position = 'absolute';
	vTable.style.left = ixMin+'px';
	vTable.style.top = iyMax+'px';
	var sInnerHTML = '<span style="font-size:0.1px; color:'+sFillColor+'">x</span>'; // might be a problem with background - set background color!0
	if(sInnerBorderColor && Math.abs(iyMax-iyMin)>=10){
		sInnerHTML = '<table cellspacing=0 cellpadding=0><tr><td style="border: '+sInnerBorderColor+' 1px solid">'+sInnerHTML+'</td></tr></table>';
	}
	else sInnerBorderColor = false;
	vCell.innerHTML = sInnerHTML;
	vCell.style.backgroundColor = sFillColor;
	
	vCell.className = sClassName;
	vDrawEl.appendChild(vTable);
//alert(vTable.innerHTML);
	
	if(sInnerBorderColor){
		vCell1 = vCell.getElementsByTagName('td')[0];
		SAWUtils.setElementWidth(vCell1, ixMax-ixMin-2);
		SAWUtils.setElementHeight(vCell1, Math.abs(iyMax-iyMin)-2);
	}
	else{	
		SAWUtils.setElementWidth(vCell, ixMax-ixMin);
		SAWUtils.setElementHeight(vCell, Math.abs(iyMax-iyMin));
	}
	
	return vTable;
}