// JavaScript Document

popUpLinks = new Array();

function testIE6() {
	browserUserAgent = navigator.userAgent;
	if (browserUserAgent.indexOf('MSIE') != -1) {
		browserVersion = browserUserAgent.substring(browserUserAgent.indexOf('MSIE')+5, browserUserAgent.indexOf('MSIE')+6);
		if (browserVersion < 7) {return true;} else {return false;}
	}
}

function highlightNavLink(navLink) {
	navLink = 'mainNavLink'+navLink;
	document.getElementById(navLink).style.color = '#FFFF66';
}

function showHide(elementID, visibility) {
	document.getElementById(elementID).style.visibility = visibility;
}

function linkPopUp(linkID, state) {
	slug = 'linkSlug'+linkID;
	popUp = 'linkPopUp'+linkID;
	if (state == 'popUp') {
		showHide(popUp, 'visible');
		showHide(slug, 'hidden');
	} else {
		showHide(popUp, 'hidden');
		showHide(slug, 'visible');
	}
}

function trimAll(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}

function replicateStr(s, n) {
    var r = '';
    while (n) {
        if (n & 1) { r += s; }
        s += s;
        n >>= 1;
    }
    return r;
}

function clickButton(e, buttonid) {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

function activatePopUp(concernedLink) {
	for (n in popUpLinks) {
		iteratedLink = popUpLinks[n].replace(/ /g, '');
		linkPopUp(iteratedLink, 'popDown');
	}
	if (concernedLink != 'none') {linkPopUp(concernedLink, 'popUp');}
}

function getViewPortHeight() {
	if (typeof window.innerWidth != 'undefined') {
		// for more standards compliant browsers (mozilla/netscape/opera/IE7)
		viewPortHeight = window.innerHeight
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0) {
		// for IE6 in standards compliant mode
		viewPortHeight = document.documentElement.clientHeight
	} else {
		// for older versions of IE
		viewPortHeight = document.getElementsByTagName('body')[0].clientHeight
	}
	return viewPortHeight;
}

function scrollImagePanel() {
	var wndo = new dw_scrollObj('thumbsContainer', 'thumbsContent', 'thumbsTable');
	wndo.setUpScrollControls('scroller');
}

function preloadBackground(imageCallName) {
	imageSrc = '/Templates/ALI-corporate/graphics/bkground-image-'+imageCallName+'.jpg';
	preloadBkgroundImage = new Image();
	preloadBkgroundImage.src = imageSrc;
	document['backgroundImage'].src = imageSrc;
}

function preloadPopUpLinks(pageLinks) {
	popUpPNG = new Array();
	popUpGIF = new Array();
	preloadPopUpPNG = new Array();
	preloadPopUpGIF = new Array();
	for (n in pageLinks) {
		imageSrc = pageLinks[n].replace(/ /g, '-');
		imageSrcPath = '/Templates/ALI-corporate/graphics/link-pop-up-'+(imageSrc.toLowerCase());
		imageSrcPNG = imageSrcPath+'.png';
		imageSrcGIF = imageSrcPath+'.gif';
		preloadPopUpPNG[n] = new Image();
		preloadPopUpPNG[n].src = imageSrcPNG;
		preloadPopUpGIF[n] = new Image();
		preloadPopUpGIF[n].src = imageSrcGIF;
	}
}

function swapPopUpLinksToGIF(pageLinks) {
	for (n in pageLinks) {
		imageName = 'popUp'+(pageLinks[n].replace(/ /g, ''));
		imageSrc = pageLinks[n].replace(/ /g, '-');
		imagePath = '/Templates/ALI-corporate/graphics/link-pop-up-'+(imageSrc.toLowerCase())+'.gif';
		document[imageName].src = imagePath;
	}
}

function swapToGIF() {
	// standard page elements
	document.getElementById('searchPanel').style.backgroundImage = 'url(/Templates/ALI-corporate/graphics/search-panel.gif)';
	document.getElementById('pageFooter').style.backgroundImage = 'url(/Templates/ALI-corporate/graphics/footer-bkground.gif)';
	document.getElementById('ALIlogo').style.backgroundImage = 'url(/Templates/ALI-corporate/graphics/ALI-logo.gif)';
	// Flash area on landing pages
	if (document.getElementById('flashArea'))	{
		document.getElementById('flashArea').style.backgroundImage = 'url(/Templates/ALI-corporate/graphics/flash-panel-area.gif)';
	}
	// main navigation links
	if (document.getElementById('mainNavLinks'))	{
		for (n=1; n<=4; n++) {
			mainNavLink = 'mainNavLink'+n;
			document.getElementById(mainNavLink).style.backgroundImage = 'url(/Templates/ALI-corporate/graphics/bullet-ALI-logo.gif)';
		}
	}
	// pop-up links
	if (popUpLinks != 'undefined') {
		swapPopUpLinksToGIF(popUpLinks);
	}
}

function initializePage() {
    //preloadBackground(background);
	preloadPopUpLinks(popUpLinks);
	if (document.getElementById('linkPopUpStyles') && testIE6()) {document.getElementById('linkPopUpStyles').href = '/Templates/ALI-corporate/styles/link-pop-up-styles-IE6.css';}
}

function IE6adjustments() {
	if (testIE6()) {
		swapToGIF();
		// set <div> container of background image to a fixed height to allow 'overflow' attribute to work
		document.getElementById('pageBackground').style.height = document.documentElement.clientHeight;
		// adjust position of page footer
		document.getElementById('pageFooter').style.marginTop = '-39px';
		if (document.getElementById('flashArea')) {document.getElementById('flashArea').style.marginTop = '-164px';}
	}
}

function pageLengthAdjustments() {
//	if (document.getElementById('Dashboard')) {
//		document.getElementById('pageBackground').style.height = 700+'px';
//		document.getElementById('pageFooter').style.top = (document.getElementById('Dashboard').offsetHeight)+700+'px';
//		if (document.getElementById('flashArea')) {
//			document.getElementById('flashArea').style.top = (document.getElementById('Dashboard').offsetHeight)+700+'px';
//		}
//		if (document.getElementById('pageElementsMasterContainer')) {
//			document.getElementById('pageElementsMasterContainer').style.height = '700px';
//		}
//	}
	if (document.getElementById('pageHeightMarker')) {
		docHeight = document.getElementById("pageHeightMarker").offsetTop;
		if (docHeight >= getViewPortHeight()) {
			document.getElementById('pageFooter').style.position = 'relative';
			document.getElementById('pageFooter').style.top = '0px';
			document.getElementById('pageFooter').style.marginTop = '0px';
		}
}
	
	
	
}
