﻿
function styleBox(element, width, height, color, onlytop, background, onlybottom) {
	
	if (color == 'R') color = '';
	
	var ni = document.getElementById(element);
	
	if (ni) {
	
		if (onlytop) {
			setStyle(ni, 'width:'+width+'px;height:' + (height-4) + 'px; display: table-cell;');
		}
		else if (onlybottom  || parseInt(height) == 0) {
			setStyle(ni, 'width:'+width+'px;height: 100px; display: table-cell;');
		}
		else {
			setStyle(ni, 'width:'+width+'px;height:' + height + 'px; display: table-cell;');
		}
			
		
		width = width-11; //-padding
		//height= height-13 ; //-padding
		height= height-10 ; //-padding
		if (!ni) {alert(element);}
		if (!onlybottom) {
			//Make top left corner
			var newdiv = document.createElement('div');
			var divIdName = 'TL'+element;
			newdiv.setAttribute('id',divIdName);
			newdiv.setAttribute('class','TL'+color);
			newdiv.setAttribute('className','TL'+color);
			newdiv.innerHTML = '';
			ni.appendChild(newdiv);

			//Make topMiddle
			newdiv = document.createElement('div');
			divIdName = 'TM'+element;
			newdiv.setAttribute('id',divIdName);
			newdiv.setAttribute('class','TM'+color);
			newdiv.setAttribute('className','TM'+color);
			setStyle(newdiv, 'width:'+width+'px;');
			ni.appendChild(newdiv);

			//Make TRBorder
			newdiv = document.createElement('div');
			divIdName = 'TR'+element;
			newdiv.setAttribute('id',divIdName);
			newdiv.setAttribute('class','TR'+color);
			newdiv.setAttribute('className','TR'+color);
			newdiv.innerHTML = '';
			ni.appendChild(newdiv);
		}

		//Make center left side
		newdiv = document.createElement('div');
		var divIdName = 'CL'+element;
		newdiv.setAttribute('id',divIdName);
		newdiv.setAttribute('class','CL'+color);
		newdiv.setAttribute('className','CL'+color);
		if (!onlybottom) setStyle(newdiv, 'height:'+height+'px;');
		ni.appendChild(newdiv);

		//Make centerMiddle
		var newdivcontent = document.getElementById(element+'Content');
	        
		if (background == true)	{
			newdivcontent.setAttribute('class','CM'+color);
			newdivcontent.setAttribute('className','CM'+color);
		}
		else {
			newdivcontent.setAttribute('class','CM'+color + ' CMW');
			newdivcontent.setAttribute('className','CM'+color + ' CMW');
		}
		
		if (onlybottom || (height == -10 && color != 'W')) {
			var newheight=height;
			var newwidth=width-10;
			
			setStyle(newdivcontent, 'width:'+newwidth+'px;');
		}
		else {
			var newheight=height-10;
			var newwidth=width-10;
			//if (element == 'divTopMenu') alert(newheight);
			setStyle(newdivcontent, 'width:'+newwidth+'px;height:'+newheight+'px;');
		}
		
		ni.appendChild(newdivcontent);
		
		if ((onlybottom || (height == -10 && color != 'W'))) {
		    
			setStyle(newdiv, 'height: ' + (newdivcontent.offsetHeight) + 'px;');
			//alert(newdivcontent.offsetHeight);
			//if (element == 'ctl00_ContentPlaceHolder1_divMenuCard') {
			//	intBottomTop = newdivcontent.offsetHeight;
			//}
		
	}
		if (height == -10 && color != 'W') {
			var newdivouter = document.getElementById(element+'Outer');		
			setStyle(newdivouter, 'height: ' + (newdivcontent.offsetHeight + 10) + 'px;');
			//alert(newdivcontent.offsetHeight);
		}
		
		//if (height == -13 && color == 'W') setStyle(newdiv, 'height: ' + (newdivcontent.offsetHeight-23) + 'px;');
		
		//Make centerRight
		newdiv = document.createElement('div');
		divIdName = 'CR'+element;
		newdiv.setAttribute('id',divIdName);
		newdiv.setAttribute('class','CR'+color);
		newdiv.setAttribute('className','CR'+color);
		if (!onlybottom) setStyle(newdiv, 'height:'+height+'px;');
		ni.appendChild(newdiv);
		
		if ((onlybottom || (height == -10 && color != 'W'))) setStyle(newdiv, 'height: ' + (newdivcontent.offsetHeight) + 'px;');
		//if (height == -13 && color == 'W') setStyle(newdiv, 'height: ' + (newdivcontent.offsetHeight-23) + 'px;');

		if (!onlytop) {

			//Make bottom left side
			var newdiv = document.createElement('div');
			var divIdName = 'BL'+element;
			newdiv.setAttribute('id',divIdName);
			newdiv.setAttribute('class','BL'+color);
			newdiv.setAttribute('className','BL'+color);
			ni.appendChild(newdiv);

			//Make bottomMiddle
			newdiv = document.createElement('div');
			divIdName = 'BM'+element;
			newdiv.setAttribute('id',divIdName);
			newdiv.setAttribute('class','BM'+color);
			newdiv.setAttribute('className','BM'+color);
			setStyle(newdiv, 'width:'+width+'px;');
			ni.appendChild(newdiv);

			//Make bottomRight
			newdiv = document.createElement('div');
			divIdName = 'BR'+element;
			newdiv.setAttribute('id',divIdName);
			newdiv.setAttribute('class','BR'+color);
			newdiv.setAttribute('className','BR'+color);
			ni.appendChild(newdiv);
		}
	}	
}

function styleBoxRed(element,width,height) {
	styleBox(element, width, height, 'R', false, true, false);
}


function styleBoxYellow(element,width,height) {
	styleBox(element, width, height, 'Y', false, true, false);
}
function styleBoxWhite(element,width,height) {
	styleBox(element, width, height, 'W', false, false, false);
}
function styleBoxYellowNoBg(element,width,height) {
	styleBox(element, width, height, 'Y', false,false, false);
}
function styleBoxGreen(element,width,height) {
	styleBox(element, width, height, 'G', false, true, false);
}
function styleBoxGreenSmall(element,width,height) {
	styleBox(element, width, height, 'GS', false, true, false);
}
function styleTopBoxRed(element,width,height) {
	styleBox(element, width, height, 'R', true, true, false);
}
function styleBottomBox(element,width,color) {
	styleBox(element, width, 0, color, false, true, true);
}
function styleBottomBoxFixedHeight(element,width,heigth,color) {
	styleBox(element, width, heigth, color, false, true, true);
}

function styleOnlySides(element,width,color) {
	styleBox(element, width, 0, color, true, false, true);
}

function setStyle( object, styleText ) 
{ 
    if (object != null)
    {
        if( object.style.setAttribute ) 
        { 
            object.style.setAttribute("cssText", styleText ); 
        } 
        else 
        { 
            object.setAttribute("style", styleText ); 
        } 
    }
    
}

function editText(textObject) {
	window.open('/pages/tools/Changethecontent.aspx?Contenttitle=' + textObject.replace("#", "SpacingStuff") + '');
}

function setButtom(){

	var BottomY = parseInt(findPositionY(document.getElementById("divBottomOuter"))) + 119;
	var PageY = document.body.parentNode.scrollHeight;

	if (BottomY < PageY) {
		document.getElementById('divBottomOuter').style.top = PageY + 25;
	}
}
function findPositionY( oLink ) {
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;
    }
    return [ posY ];
  } else {
    return [ oLink.y ];
  }
}


function styleBoxNew(element, width, color) {

	if (color == 'R') color = '';
	
	var ni = document.getElementById(element);
	setStyle(ni, 'width:'+width+'px;display: table-cell;');
	width = width-11; //-padding

	//Make center left side
	var newdiv = document.createElement('div');
	var divIdName = 'CL'+element;
	newdiv.setAttribute('id',divIdName);
	newdiv.setAttribute('class','CL'+color);
	newdiv.setAttribute('className','CL'+color);
	ni.appendChild(newdiv);

	//Make centerMiddle
	var newdivcontent = document.getElementById(element+'Content');
	newdivcontent.setAttribute('class','CM'+color);
	newdivcontent.setAttribute('className','CM'+color);

	var newwidth=width-10
	setStyle(newdivcontent, 'width:'+newwidth+'px;');
	ni.appendChild(newdivcontent);
	
	//alert(newdivcontent.offsetHeight);
	setStyle(newdiv, 'height: ' + newdivcontent.offsetHeight + 'px;')
	//Make centerRight
	newdiv = document.createElement('div');
	divIdName = 'CR'+element;
	newdiv.setAttribute('id',divIdName);
	newdiv.setAttribute('class','CR'+color);
	newdiv.setAttribute('className','CR'+color);
	setStyle(newdiv, 'height: ' + newdivcontent.offsetHeight + 'px;')
	ni.appendChild(newdiv);
	
	//Make bottom left side
	/*var newdiv = document.createElement('div');
	var divIdName = 'BL'+element;
	newdiv.setAttribute('id',divIdName);
	newdiv.setAttribute('class','BL'+color);
	newdiv.setAttribute('className','BL'+color);
	ni.appendChild(newdiv);

	//Make bottomMiddle
	newdiv = document.createElement('div');
	divIdName = 'BM'+element;
	newdiv.setAttribute('id',divIdName);
	newdiv.setAttribute('class','BM'+color);
	newdiv.setAttribute('className','BM'+color);
	setStyle(newdiv, 'width:'+width+'px;');
	ni.appendChild(newdiv);

	//Make bottomRight
	newdiv = document.createElement('div');
	divIdName = 'BR'+element;
	newdiv.setAttribute('id',divIdName);
	newdiv.setAttribute('class','BR'+color);
	newdiv.setAttribute('className','BR'+color);
	ni.appendChild(newdiv);*/
	
	
}
