var _resizerDown = 0;
_showResizerPixels = true;
_resizeOnlyFirst   = false;



function resizeCell( n, ind){
	var active = document.getElementsByTagName(n)[ind];
	
	_resizerDown = 1;	
	
	if( active ){
		var actParent = active.parentNode;
		var grandPar  = actParent.parentNode;
		var tableBody = grandPar.parentNode;
		var table 	  = tableBody.parentNode;
		
		
		var parIndex = findParentIndex( active );
		
		if(!actParent.childNodes[parIndex-1]){
			otherElement = actParent.childNodes[parIndex+1];
			otherIndex	 = parIndex+1;
		}
		else {
			otherElement = actParent.childNodes[parIndex-1];
			otherIndex	 = parIndex-1;
		}
				

		var orgX = event.clientX;
		var orgW = active.offsetWidth;
		var orOW = otherElement.offsetWidth;
		var tabW = grandPar.parentNode.offsetWidth;

		if( _showResizerPixels ){
			show( $('_conResWid') );
			$('_conResWid').innerHTML = noBr( active.offsetWidth+' px' );
			$('_conResWid').style.left = findPosX($('_conResWid'))-10- document.body.scrollLeft;
			$('_conResWid').style.top  = findPosY($('_conResWid'))-10- document.body.scrollTop;
		}

		document.onselectstart=new Function ('return false');
		if($('kpqf').value==1){
			document.onmousemove = function(){
				
				$('_conRes').style.left=event.clientX;
				$('_conResWid').style.left=event.clientX;
				try{
						
					if( !_resizeOnlyFirst ){
						for(var i=0;i<grandPar.childNodes.length;i++){
							grandPar.childNodes[i].childNodes[parIndex].width = orgW - (event.clientX - orgX);
							grandPar.childNodes[i].childNodes[otherIndex].width = orOW + (event.clientX - orgX);
						}
					}
					else {
						grandPar.parentNode.width = tabW + event.clientX - orgX
						grandPar.childNodes[0].childNodes[otherIndex].width = orOW + (event.clientX - orgX);
					}
				}
				catch(e){""}
				try{
				$('_conResClone').style.left = findPosX( active )+2 - document.body.scrollLeft;
				$('_conResClone').style.top  = findPosY( active )+2 - document.body.scrollTop;
				
				$('_conResClone').style.width = active.offsetWidth;
				$('_conResClone').style.height = active.offsetHeight;
				}
				catch(e){}
				show( $('_conResClone') );

				
//				$('_conResWid').innerHTML = noBr( orOW + (event.clientX - orgX)+' px' );
				$('_conResWid').innerHTML = noBr( active.offsetWidth+' px' );
			}
		}
	}
}

function resizeRow( n, ind){
	var active = document.getElementsByTagName(n)[ind];
	_resizerDown = 1;	
	var activeDiv = document.body;
	if(active  && activeDiv.contentEditable){
		
		var actParent = active.parentNode;
		var grandPar  = actParent.parentNode;
		var tableBody = grandPar.parentNode;
		
		var parIndex = findParentIndex( active );
		var orgY = event.clientY;
		var orgH = active.offsetHeight;
		
		document.onselectstart=new Function ('return false');

		show( $('_conResWid') );
		$('_conResWid').style.top=event.clientY-20+ document.body.scrollTop;
		$('_conResWid').innerHTML = noBr( active.offsetHeight +' px' );
		$('_conResWid').style.left=findPosX($('_conResWid'))+10- document.body.scrollLeft;


		if($('_conRowMod').value==1){
			document.onmousemove = function(){
				try{
				$('_conRow').style.top=event.clientY;
				

				var tempHeight = orgH + (event.clientY - orgY);
				
				for(var i=0;i<actParent.childNodes.length;i++){
					
					actParent.childNodes[i].height     = tempHeight;

					$('_conResClone').style.height	   = active.offsetHeight//orgH + (event.clientY - orgY);
				}
				
				
				//fix for wrong heights
				if(active.offsetHeight != tempHeight )	{
					for(var i=0;i<actParent.childNodes.length;i++)
						actParent.childNodes[i].height     =active.offsetHeight;
				}			
				else 
					$('_conResWid').style.top=event.clientY-20;

				$('_conResWid').style.top=event.clientY+document.body.scrollTop;

				$('_conResClone').style.left = findPosX( active )+2  - document.body.scrollLeft;
				$('_conResClone').style.top  = findPosY( active )+2  + document.body.scrollTop;
				
				$('_conResClone').style.width = active.offsetWidth;
				$('_conResClone').style.height = active.offsetHeight;

				}
				catch(e){""}
				show( $('_conResClone') );
				
				
//				$('_conResWid').innerHTML = noBr( orgH + (event.clientY - orgY)+' px' );
				$('_conResWid').innerHTML = noBr(  active.offsetHeight +' px' );
			}
		}
	}
}

/*function insertTableCellModifier( node ){
	
	if(!event.ctrlKey)
	{
		var nname = node.nodeName;
		var nodId 	  = findNodeIndex( node )
		$('_conResNode').value = nname;
		$('_conResIndex').value = nodId;
	
		$('_conRes').style.display='block';
		$('_conRow').style.display='block';
		
		$('_conRow').style.left = findPosX(document.getElementsByTagName(nname)[nodId])-2 - document.body.scrollLeft;
		$('_conRow').style.top  = findPosY(document.getElementsByTagName(nname)[nodId])+document.getElementsByTagName(nname)[nodId].offsetHeight - document.body.scrollTop;;
		$('_conRow').style.width= document.getElementsByTagName(nname)[nodId].offsetWidth;
		
		$('_conRes').style.left = findPosX(document.getElementsByTagName(nname)[nodId])-2 - document.body.scrollLeft;
		$('_conRes').style.top  = findPosY(document.getElementsByTagName(nname)[nodId]) - document.body.scrollTop;
		$('_conRes').style.height  = document.getElementsByTagName(nname)[nodId].offsetHeight;
	
		$('_conResWid').style.left = findPosX(document.getElementsByTagName(nname)[nodId])-2 - document.body.scrollLeft;
		$('_conResWid').style.top  = findPosY(document.getElementsByTagName(nname)[nodId])-10 - document.body.scrollTop;
	}
	else
	{
		var r = document.body.createControlRange();
		r.add(node.parentElement.parentElement.parentElement);
		r.select()
	}

}*/


function narCell( n, ind){
	var active = document.getElementsByTagName(n)[ind];
	
	if(active){
		
		active.width=active.offsetWidth-5;

	}
}

function widCell( n, ind){
	var active = document.getElementsByTagName(n)[ind];
	if(active){
		active.style.width=parseInt(active.offsetWidth)+5;
		if($('kpq').value==1)
			setTimeout("widCell('"+n+"',"+ind+")",100);
	}
}


