var docLoaded = false;
var initFuncs = [];

// runs all functions in initFuncs array
function init()
{
	for (var i = 0; i < initFuncs.length; i++)
	{
		eval(initFuncs[i]);
	}
	docLoaded = true;
}
window.onload = init;

// adds a function to the initFuncs array
function addInitFunc(func)
{
	initFuncs[initFuncs.length] = func;
}

//*** For BabyCare ONLY ***//

function showBottomBar() {
	$("#babycare_bottom_filler").css("display","block");
	resizeHandler();
	// Hide the footer again
	$("#footer").css("display","none");
	$(".first-page-box-container").css("display","none");
}

function resizeHandler() 
{
	var h = 878;
  	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) 
	{
    		//Non-IE
    		h = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
    		//IE 6+ in 'standards compliant mode'
    		h = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
	    //IE 4 compatible
	    h = document.body.clientHeight;
  	}
	if(h < 878)
	{
		h = 878;
	}
	nh = h - 785;

	$("#babycare_bottom_filler").css("height",nh);
	
	centerFooter();
}

function centerFooter() {
	var footerWidth = $("#footer").width() / 2;
	var newWidth = (document.body.clientWidth / 2) - footerWidth;
	$("#footer").css("left",newWidth);	
}
window.onresize = resizeHandler;
window.onload = centerFooter;
//*** END BABYCARE ***//


//opens new window
function openWindow(url, name, feats)
{
	w = window.open(url, name, feats);
	w.focus();
}


/*
Enables user to post form by hitting enter key
*/

addInitFunc("addKeyDownEvents()");

function addKeyDownEvents()
{
	//Collection of all INPUT elements in the document
	var inputElements = document.getElementsByTagName("INPUT");
	//Collection of all A elements in the document
	var aElements = document.getElementsByTagName("A");
	
	//Find INPUT elements with the attribute "TriggerOnEnter"
	for (var i=0; i<inputElements.length; i++)
		
		//Match found
		if(typeof inputElements[i].TriggerOnEnter != "undefined")
		{
			
			var aElementExists = false;
			
			//Find a element specified in TriggerOnEnter and set TriggerOnEnter to
			//the a element's correct id (id may have been changed the .NET engine)
			for (var j=0; j<aElements.length; j++)
			{
				//Match found
				if(aElements[j].id.indexOf(inputElements[i].TriggerOnEnter) > -1)
				{
					inputElements[i].TriggerOnEnter = aElements[j].id;
					aElementExists = true;
					break;
				}
			}
			
			//Found a element, attach onkeydown event to this INPUT element
			if(aElementExists)
			{
				inputElements[i].onkeydown = inputOnKeydown;
			}
			
		}
}

function inputOnKeydown()
{
	if(window.event.keyCode == 13)
	{
		var elm = document.getElementById(window.event.srcElement.TriggerOnEnter);
		elm.click();
	}
	
}

// Replace parts of strings with this method, instead of using RegExps
String.prototype.replaceStr = function(str, rep, ignoreCase)
{
	if (str.length != 0) return this.replace(new RegExp(str, "g" + (ignoreCase) ? "i" : ""), rep);
	return this;
}

function StringBuilder()
{
	this.text = [];
	this.w = function(str)
	{
		this.text[this.text.length] = str;
	}
	this.writeln = function(str)
	{
		this.text[this.text.length] = str + "\n";
	}
	this.toString = function()
	{
		return this.text.join("");
	}
	this.clear = function()
	{
		delete this.text;
		this.text = null;
		this.text = [];
	}
}


function NullObject()
{
	this.isNull = true;
}

String.prototype.getQueryString = function(pName)
{
	if(this.indexOf("?") == -1) return null;
	var qs = this.substr(this.indexOf("?"));
	if(qs.indexOf(pName) == -1) return null;
	var startPos = qs.indexOf(pName) + pName.length + 1;
	var endPos = qs.indexOf("&", qs.indexOf(pName)) > -1? qs.indexOf("&", qs.indexOf(pName)) : qs.length;
	return unescape(qs.substring(startPos, endPos));
};