if(!window.ND){window.ND={};window.NextDigital=window.ND;}
/* 2008/01/10 - ND.addLoadListener v0.82 - Glenn Baker */
ND.addLoadListener=function(fn){if(typeof window.addEventListener!='undefined'){window.addEventListener('load',fn,false);}else if(typeof document.addEventListener!='undefined'){document.addEventListener('load',fn,false);}else if(typeof window.attachEvent!='undefined'){ window.attachEvent('onload',fn);}else{var oldfn=window.onload;if(typeof window.onload!='function'){window.onload=fn;}else{window.onload=function(){oldfn();fn();};}}};
/* 2008/01/14 - ND.anchors v0.99 - Glenn Baker - Support for, external, popup:XXX:XXX, close, and print. Includes PopupWindow(url,n,w,h,sc) */
ND.anchors={storage:{external:function(){var ex=window.open(this.href);return !ex;},popup:function(){var dims=arguments&&arguments.length==2?arguments:window.__popupDims;popupWindow(this.href,'name',dims[0],dims[1],'yes');return false;},close:function(){window.close();return false;},print:function(){window.print();return false;}},init:function(){if(this !=ND.anchors){return ND.anchors.init();}window.popupWindow=this.popupWindow;if(!window.__popupDims)window.__popupDims=[619,380];var atype=window.__aType?window.__aType:"rel";if(document.getElementsByTagName&&document.getElementById){var anchors=document.getElementsByTagName("a");for(i=0;i<anchors.length;i++){var attr=String(atype=="class"?anchors[i].className:anchors[i].getAttribute(atype));if(attr){var matches=attr.match(/([^\s])+/g);for(var j=0;j<matches.length;j++){var match=matches[j].replace(/^([\w]*)[:|][^,\s]+([,]?[^,\s]+)*$/i,"$1");var args=(matches[j].replace(match,"")).match(/[^,|:\s]+/g);if(this.storage[match]){anchors[i].onclick=this.Bind(this.storage[match], args);}}}}}},popupWindow:function(url,n,w,h,sc){var sw=screen.availWidth;var sh=screen.availHeight;lp=(sw)?(sw-w)/2:0;tp=(sh)?(sh-h)/2:0;se='height='+h+',width='+w+',top='+tp+',left='+lp+',scrollbars='+sc+',resizable=yes';win=window.open(url,n,se);win.focus();},add:function(rel, fn){if(!this.storage[rel])this.storage[rel]=fn;else throw("Behaviour already exisits for '"+rel+"'");},setPopupDimensions:function(w,h){window.__popupDims=[w,h];},setAttrType:function(a){window.__aType=a;},Bind:function(fn){var args=[];if(arguments.length>1){args=(new String(arguments[1])).split(",");}return function(){return fn.apply(this, args);};}};
/* 2007/12/05 - ND.classFunctions v0.92 - Glenn Baker - includes addClass, removeClass, hasClass, toggleClass and replaceClass */
ND.classFunctions={addClass:function(t, c){var p=new RegExp("(^|)"+c+"(|$)");if(!p.test(t.className)){if(t.className==""){t.className=c;}else{t.className+=" "+c;}}return true;},removeClass:function(t, c){var removedClass=t.className;var p=new RegExp("(^|)"+c+"(|$)");removedClass=removedClass.replace(p, "$1");removedClass=removedClass.replace(/$/, "");t.className=removedClass;return true;},replaceClass:function(t, prec, c){removeClass(t,prec);addClass(t,c);},toggleClass:function(t, c){if(hasClass(t,c)){removeClass(t,c);}else{addClass(t,c);}},hasClass:function(t, c){var p=new RegExp("(^|)"+c+"(|$)");return p.test(t.className);},init:function(){for(n in this){window[n]=this[n]}}};ND.classFunctions.init();

var	sumLiWidth = 0;
var numLi = 0;

var setIEHovers = function(list) {
	var listItems = list.getElementsByTagName("li");

	for(var k=0; k < listItems.length; k++) {
		if (hasClass(listItems[k],"first-nav")){
			var node = listItems[k];
			node.onmouseover=function() {this.className+=" hover";}
			node.onmouseout=function() {this.className=this.className.replace(" hover", "");}
		}
	}
}

var hoverIE = function() {
	// IE6 only
	//if(window.ActiveXObject && (window.XMLHttpRequest == undefined)) {
		var ul_array = document.getElementsByTagName("ul");
		for (var i=0; i < ul_array.length; i++) {
			if(ul_array[i].parentNode.className == 'navigation') {
				setIEHovers(ul_array[i]);
			}
		}
	//}
}

ND.anchors.setPopupDimensions(619,320);

/* Overlabels */
var hideLabel = function(field_id, hide){
	var field_for;
	var labels = document.getElementsByTagName('label');
	for (var i = 0; i < labels.length; i++) {
		field_for = labels[i].htmlFor || labels[i].getAttribute('for');
		if (field_for == field_id && hasClass(labels[i],"overlabel-apply")) {
			labels[i].style.textIndent = (hide) ? '-9999px' : '0px';
			return true;
		}
	}
};

var initOverLabels = function(){
	if (!document.getElementById) return;  	
	var labels, id, field;
	labels = document.getElementsByTagName('label');
	for (var i=0; i < labels.length; i++) {
	    if (labels[i].className == 'overlabel') {
			id = labels[i].htmlFor || labels[i].getAttribute('for');
			if (!id || !(field = document.getElementById(id))){continue;}
			labels[i].className = 'overlabel-apply';		
			if (field.value !== ''){hideLabel(field.getAttribute('id'), true);}
			field.onfocus = function(){
			    hideBothField(this.getAttribute('id'));
			    hideLabel(this.getAttribute('id'), true);
			};
			
			field.onblur = function(){
			    checkPassword(this.getAttribute('id'));
				if(this.value === ''){
					hideLabel(this.getAttribute('id'), false);
				}
			};
			labels[i].onclick = function(){
				var id, field;
				id = this.getAttribute('for');
				if(id && (field = document.getElementById(id))) {
					field.focus();
				}
			};
		}
	}
};

var checkPassword = function(currentFieldID)
{
    if(currentFieldID == emailID || currentFieldID == passwordID)
    {
        emailField = document.getElementById(emailID);
        passwordField = document.getElementById(passwordID);
        
        if(emailField.value != '')
        {
            hideLabel(emailField, true);
        }
        
        if(passwordField.value != '')
        {
            hideLabel(passwordField, true);
        }
        
        if(emailField.value == '' && passwordField.value == ''){
            hideLabel(passwordID, false);
            hideLabel(emailID, false);
        }
    }
};

var hideBothField = function(currentFieldID)
{
    if(currentFieldID == emailID || currentFieldID == passwordID)
    {
        hideLabel(emailID, true);
        hideLabel(passwordID, true);
    }
};

/*Boxes floated on home page*/
var floatedBox = function(){
if (!document.getElementById('boxes-variable')) return;

var div_array = document.getElementById('boxes-variable').getElementsByTagName('DIV');

// get the max height of boxes
var max_height = 0;
var height = 0;
for (i=0; i< div_array.length; i++) {
		height = div_array[i].offsetHeight;
		if (height > max_height)
			max_height = height;
}

for (i=0; i< div_array.length; i++) {
	div_array[i].style.height = max_height + 'px';
}

}


/* Change background color of webparts */

var webpartsHoverIE = function() {
	// IE6 only
	if(window.ActiveXObject && (window.XMLHttpRequest == undefined)) {
	    if (document.getElementById('web-parts') != null){
			var table_array = document.getElementById('web-parts').getElementsByTagName("table");
			for (var i=0; i < table_array.length; i++) {
				var node = table_array[i];
				node.onmouseover=function() {this.className+=" webpart-hover";}			
				node.onmouseout=function() {this.className=this.className.replace(" webpart-hover", "");}
			}
		}
	}
}



var windowResize = function(){
	
	var nav = document.getElementById('navholder');
	if(nav != null)
	{
		var items = jQuery('#navholder li.first-nav');
		var pd = null;
		var item = items[0];
		var newWidth = document.body.clientWidth;
		var liWidth = new Array();
		var liPd = new Array();
		
		// get the width of ul
		var navWidth = nav.offsetWidth;
			for (var i = 0; i < items.length; i++){
				items[i].style.paddingLeft = ((navWidth - sumLiWidth)/numLi/2) + 'px';
				items[i].style.paddingRight = ((navWidth - sumLiWidth)/numLi/2) + 'px';
			}
	}
}


var windowOpen= function(){
	liWidth = new Array();
	var pd = 0;
	var nav = document.getElementById('navholder');
	if(nav != null)
	{
		var items = nav.getElementsByTagName('li');
		for (var i = 0; i < items.length; i++){
			if (hasClass(items[i],"first-nav")){
				pd = parseInt(items[i].style.paddingLeft)/1.025;
				pd += parseInt(items[i].style.paddingRight)/1.025;
				liWidth[i] = items[i].offsetWidth;
				sumLiWidth = sumLiWidth + liWidth[i] - pd;
				numLi++;
			}
		}
	}
	windowResize();
	window.onresize = windowResize;
}


var myInit = function(){hoverIE();ND.anchors.init();initOverLabels();floatedBox();windowOpen();webpartsHoverIE();contentImg();tooltipImg();};
ND.addLoadListener(myInit);

function openLink(id)
{
    var ddlQuickLink = document.getElementById(id);
    var selectedIndex = ddlQuickLink.selectedIndex;
    var selectedValue = ddlQuickLink.options[selectedIndex].value;
    
    var tokens = selectedValue.split(";");
    
    if(tokens[0] == "i")
    {
        window.location = tokens[1];
    }
    else
    {
        window.open(tokens[1]);
    }
}

function onEnterpress(e, id)
{
    //define any varible
    var KeyPress 

    //if which property of event object is supported 
    if(e && e.which)
    {
        e = e
        //character code is contained in NN4's which property
        KeyPress = e.which
    }
    else
    {
        e = event
        KeyPress = e.keyCode
    }
    //13 is the key code of enter key
    if(KeyPress == 13)
    {
        $j(id)[0].click();
        return false    
    }
    else
    {
        return true
    }
}

var contentImg = function(){
                var div_array = document.getElementsByTagName("div");
                for (i=0; i<div_array.length; i++){
                                if(hasClass(div_array[i],"content-img")){
                                                if(div_array[i].getElementsByTagName("img")[0])
                                                    var width = div_array[i].getElementsByTagName("img")[0].offsetWidth;
                                                if(div_array[i].getElementsByTagName("p")[0])
                                                    div_array[i].getElementsByTagName("p")[0].style.width = width-20 +'px';
                                }
                }
}

var tooltipImg = function() {
var img = $j('img');
if(img != null)
	img.attr('title', function()
	{
		return $j(this).attr('alt');
	});
}
