

/**
* This function looks for an array called messages and if it exists then
* will show some animated alerts
**/
function showMessages(){
	if(!messages || messages.length <= 0) return;
	
	var timeLength = 15000;
	for(var i = 0; i < messages.length; i++){
		var message = messages[i];
		var title = message[0];
		var content = message[1];
		var linkText = message[2];
		var link = message[3];
		var id = "anim_"+i;
		setTimeout("cm.showAnimatedAlert(\""+title+"\", \""+content+"\", \""+linkText+"\", \""+link+"\", \""+id+"\", \""+timeLength+"\")", timeLength*i);
	}
}


function applyRoundedCorners(contentDiv, borderWidth, borderColor){
	var classPrefix = "box"+borderWidth+"px"+borderColor;
	
	var container = document.createElement("div");
	container.className = classPrefix+"_container";
	
	var top = document.createElement("div");
	top.className = classPrefix+"_top";
	
	var topLeft = document.createElement("div");
	topLeft.className = "tl";
	
	var topRight = document.createElement("div");
	topRight.className = "tr";
	
	var body = document.createElement("div");
	body.className = classPrefix+"_body";
	
	var padding = document.createElement("div");
	padding.className = "padding";
	
	var clear = document.createElement("div");
	clear.className = "clear";
	
	var bottom = document.createElement("div");
	bottom.className = classPrefix+"_bottom";
	
	var bottomLeft = document.createElement("div");
	bottomLeft.className = "bl";
	
	var bottomRight = document.createElement("div");
	bottomRight.className = "br";
	
	var clear = document.createElement("div");
	clear.className = "clear";
	
	container.appendChild(top);
	top.appendChild(topLeft);
	top.appendChild(topRight);
	
	container.appendChild(body);
	body.appendChild(padding);
	padding.appendChild(contentDiv);
	padding.appendChild(clear);
	
	container.appendChild(bottom);
	bottom.appendChild(bottomLeft);
	bottom.appendChild(bottomRight);
	bottom.appendChild(clear);
	
	return container;
	
}

function applyHeaderFooterBox(titleDiv, contentDiv, footerDiv, style){
	var container = document.createElement('div');
	container.className = "hf_box";
	
	var styler = document.createElement('div');
	styler.className = style;
	if(!titleDiv) styler.className = "no_head";
	
	var top = document.createElement("div");
	top.className = "top";
	
	var tl = document.createElement("div");
	tl.className = "tl";
	
	var tr = document.createElement("div");
	tr.className = "tr";
	
	var tPadding = document.createElement("div");
	tPadding.className = "padding";
	
	var body = document.createElement("div");
	body.className = "body";
	
	var padding = document.createElement("div");
	padding.className = "padding";
	
	var bottom = document.createElement("div");
	bottom.className = "bottom";
	
	var bl = document.createElement("div");
	bl.className = "bl";
	
	var br = document.createElement("div");
	br.className = "br";
	
	var bPadding = document.createElement("div");
	bPadding.className = "padding";
	
	container.appendChild(styler);
	styler.appendChild(top);
	top.appendChild(tl);
	tl.appendChild(tr);
	tr.appendChild(tPadding);
	if(titleDiv)
		tPadding.appendChild(titleDiv);
	
	styler.appendChild(body);
	body.appendChild(padding);
	padding.appendChild(contentDiv);
	
	if(footerDiv){
		styler.appendChild(bottom);
		bottom.appendChild(bl);
		bl.appendChild(br);
		br.appendChild(bPadding);
		bPadding.appendChild(footerDiv);
	}
	
	return container;
}

/*
 * Takes three divs already in the document and wraps an HF Box around them inline.
 */
function wrapHFBoxInline(titleId,contentId,footId, style){
	var title = document.getElementById(titleId);
	var content = document.getElementById(contentId);
	var foot = document.getElementById(footId);
	// Find the parent from the content since it is the only required item
	var parent = content.parentNode;
	var hfbox = applyHeaderFooterBox(title, content, foot, style);
	parent.appendChild(hfbox);
	return hfbox;
}

function getButton(style, text, width, callback){
	var styleDiv = document.createElement("div");
	styleDiv.className = style;
	styleDiv.style.width = width+"px";
	if(callback){
		styleDiv.onclick = callback;
		styleDiv.style.cursor = "pointer";	
	}
	
	var holder = document.createElement('div');
	styleDiv.appendChild(holder);
	holder.className = "button";
	holder.style.width = width+"px";
	
	
	var left = document.createElement('div');
	left.className = "left";
	
	var center = document.createElement('div');
	center.className = "center";
	
	var right = document.createElement('div');
	right.className = "right";
	
	var padding = document.createElement('div');
	padding.className = "padding";
	
	var clear = document.createElement('div');
	clear.className = "clear";
	
	
	
	holder.appendChild(left);
	holder.appendChild(center);
	holder.appendChild(right);
	center.appendChild(padding);
	padding.appendChild(document.createTextNode(text));
	
	var cornerWidth = 6;
	if(style == 'white') cornerWidth = 9;
	else if(style == 'big_orange') cornerWidth = 4;
	else if(style == 'gray') cornerWidth = 7;
	
	var centerWidth = width-(cornerWidth*2);
	center.style.width = centerWidth+"px";
	
	return styleDiv;
}

/**
 * THis function should be used with elements with only text inside them. 
 */
function toButton(eleId, style, width, callback){
	var ele = document.getElementById(eleId);
	if(!ele) return;
	
	var buttonText = ele.innerHTML;
	ele.innerHTML = "";
	
	var button = getButton(style, buttonText, width, callback);
	ele.appendChild(button);
	
	return button;
}

function getButtonGlow(width){
	var cornerWidth = 24;
	
	var holder = document.createElement('div');
	holder.style.width = width+"px";
	holder.style.height = "45px";
		
	var left = document.createElement('div');
	left.style.cssFloat = "left";
	left.style.styleFloat = "left";
	left.style.height = "45px";
	left.style.width = cornerWidth+"px";
	left.style.background = "transparent url(/includes/templates/master/images/animation/glow_01.png)";
	left.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/includes/templates/master/images/animation/glow_01.png')";
	
	var center = document.createElement('div');
	center.style.cssFloat = "left";
	center.style.styleFloat = "left";	
	center.style.height = "45px";
	center.style.width = (width-(2*cornerWidth))+"px"
	center.style.background = "transparent url(/includes/templates/master/images/animation/glow_02.png) repeat-x";
	center.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/includes/templates/master/images/animation/glow_02.png', sizingMethod='crop')";
	center.style.overflow = "hidden";
	
	
	
	var right = document.createElement('div');
	right.style.cssFloat = "right";
	right.style.styleFloat = "right";
	right.style.height = "45px";
	right.style.width = cornerWidth+"px";	
	right.style.background = "transparent url(/includes/templates/master/images/animation/glow_04.png)";
	right.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/includes/templates/master/images/animation/glow_04.png')";
	
		
	
	var clear = document.createElement('div');
	clear.className = "clear";
	
	holder.appendChild(left);
	holder.appendChild(center);
	holder.appendChild(right);
	holder.appendChild(clear);
	
	var centerWidth = width-(cornerWidth*2);
	center.style.width = centerWidth+"px";
	
	return holder;
}

function getClearDiv(){
	var clear = document.createElement("div");
	clear.className = "clear";
	return clear;
}
