function currentPage() {
	var pageURL = "";
	var pageArray = window.location.toString().split("?");
	var re = new RegExp(/https?:\/\/(([a-zA-z]{2})\.)?delta.com/);
	if(pageArray.length>1)
	{
		if (pageArray[0].match(re)) 
		{
			re = new RegExp(/https?:\/\/((si|pl|qa)\.)?delta.com/);
			if(!pageArray[0].match(re)) { pageArray.shift(); }
		}
	}
	re.compile(/\d+;/);
	pageURL = pageArray[0].toString();
	pageURL = pageURL.replace(re,'');
	re.compile(/https?:\/\/[a-zA-Z]*\.?delta.com/);
	pageURL = pageURL.replace(re,"");
	return pageURL;
}
function addBehaviors() {
	var pageURL = currentPage();
	if(exists(get("menu1Container"))) { setStyleAttr("menu1Container","display","block"); }
	if(exists(get("menu2Container"))) { setStyleAttr("menu2Container","display","block"); }
	if(exists(get("menu3Container"))) { setStyleAttr("menu3Container","display","block"); }
	if(exists(get("menu4Container")))
	{
		if(get("nonjs_Worldwide")!=null&&get("nonjs_Worldwide")!="null") { setStyleAttr("nonjs_Worldwide","display","none"); }
		if(get("lang_loc")!=null&&get("lang_loc")!="null") { setStyleAttr("lang_loc","display","inline"); }
		setStyleAttr("menu4Container","display","block");
	}
//	switch(pageURL)
//	{
//		case ("/home/index.jsp"||"/home/index.jsp#"||"/home/"||"/home/#"):
	//		setStyleAttr('hpApplications','display','block');
//			break;
//		default:
//			break;
//	}
}

// function: left nav rollover
function navRoll(item) {
	// if the nav item is not defaulted to the rollover state then change the nav item class
	if(item.parentNode.className != 'navHot')
	{
		// if the nav item is in the hover state change it to the default state
		if(item.parentNode.className == 'navHover') { item.parentNode.className = ''; }
		// if the navitem is not in the hover state change it to the hover state
		else { item.parentNode.className = 'navHover'; }
	}
}

function gotoAnchorLink(index) {
	if(index != null && index != "")
	{
		var locationString = document.location.href;
		var locationArray = locationString.toString().split('#');
		document.location.href = locationArray[0] + "#" + index;
	}
}

//jump to tab URL when user clicks on tab
function goURL(theUrl) { document.location.href = theUrl; }


function initScreenOverlay() { 
    var msgbox = document.getElementById('popupDiv');
    if (msgbox == null
          || msgbox.style.display == 'none') {
       return;
    }

    var footerdiv = document.getElementById('Footer');
    var bottomOffset = document.body.clientWidth;
    if (footerdiv != null) {
       bottomOffset =  footerdiv.offsetTop;
    }
    bottomOffset = eval(bottomOffset - 80);
    if (msgbox.style.display != 'none') {
        var offsetht = msgbox.offsetHeight;
        var offsetwd = msgbox.offsetWidth;

        var toppos =  Math.round(((document.body.clientHeight - offsetht) / 2.5) + document.body.scrollTop);
        var leftpos =  Math.round((document.body.clientWidth - offsetwd) / 4);

        var totalht = toppos +  offsetht;
        if (totalht > bottomOffset ) {
           toppos = eval(toppos - (totalht - bottomOffset));
        }
        if (toppos < 188) {
           toppos = 188;
        }
        msgbox.style.top = toppos + "px";

        var totalwd = leftpos +  offsetwd;
        if (totalwd > 750) {
           leftpos = eval(leftpos -(totalwd - 750));
        }
        if (leftpos < 0) {
           leftpos = 0;
        }
        msgbox.style.left  = leftpos + "px" ;
    }
} 
 

function resetPopupFrame() { 
    var msgbox = document.getElementById('popupFrame');
    if (msgbox != null) {
       document.getElementById('popupFrame').src = '/shared/components/blank.jsp';
    }

}

function openHelp(url,e) {
 w = 474;
 h = 408;
 openWin(url, e, w, h, "yes");
}

function openHelp2(url,e,v) {

   w = 474;
   h = v;
   openWin(url, e, w, h, "yes");
}


var cWin;
function openNewWin(url,name,w,h,scroll,chrome) {
	if(!arguments[5])  {
		chrome = 'no';
	}
	var att = 'width='+ w +',height='+ h +',left=50,top=50,scrollbars='+ scroll +',resizable=yes,toolbar=' + chrome + ',location=' + chrome + ',status=' + chrome + ',menubar=' + chrome;
	cWin = window.open(url,name,att);
	self.name="Main";
}

function openWin(url,name,wd,ht,scroll) {
	openNewWin(url, "deltaPopup", wd, ht, scroll);
	//DeltaOverlayUtil.showPopupOverlay(url, name, wd, ht, scroll);
}


function closeWin() {
   if (window.opener) { 
	   self.close();
   } else if (window.parent != window) {
      DeltaOverlayUtil.hideOverlay();
    } else if(cWin != null) { 
         cWin.close(); 
         cWin = null; 
   }
}

function closeNewWin() {
      self.close();
}

function hidePopupHeader() {
    var divArea = document.getElementById('popHeader');
    if (divArea != null) {
        divArea.style.display = 'none';
    }
}

function hidePopupFrameHeader() {
   try {
      var popupframe = document.getElementById('popupFrame');   
      if (popupframe && popupframe.contentWindow) {
            popupframe.contentWindow.hidePopupHeader();
      }
   } catch (e) {}
}

function closePopupDiv() {
    var divArea = document.getElementById('popupDiv');
    if (divArea != null) {
        divArea.style.display = 'none';
    }
   resetPopupFrame();
}


function closeMe() {
	try { 
	if (window.opener) { 
		self.close();
   }
		
	if(cWin != null){ cWin.close(); cWin = null; } }
	catch(e) {}
	try { if(childwin != null){ childwin.close(); childwin = null; } }
	catch(e) {}
}

// this will open a context-sensitive help window
function openNewHelpWin(url,e)
{
	w = screen.width-470;
	h = screen.height-370;
	x = e.screenX;
	y = e.screenY;
	if(x > w) { x = x-470; }
	if(y > h) { y = y-370; }
	childwin=window.open(url, "childwin", "width=470,height=370,top="+y+",left="+x+",scrollbars=yes,resizable=yes");
}
// this will open a pop-up help window
function openNewHelp2win(url,e,v)
{
	w = screen.width-470;
	h = screen.height-v;
	x = e.screenX;
	y = e.screenY;
	if(x > w) { x = x-470; }
	if(y > h) { y = y-v; }
	childwin=window.open(url, "childwin", "width=470,height="+v+",top="+y+",left="+x+",scrollbars=yes,resizable=yes");
}

function openDesc(title,desc,e)
{
	w = screen.width-470;
	h = screen.height-150;
	x = e.screenX;
	y = e.screenY;
	if(x >  w) { x = x-470; }
	if(y >  h) { y = y-150; }
	var dWin = window.open('','movieDesc', 'width=470,height=150,top='+y+',left='+x+',scrollbars=yes,resizable=yes');
	var head = '<html><head><title>Movies</title><link rel="stylesheet" type="text/css" href="/components/css/global.css" />\n<link rel="stylesheet" type="text/css" href="/components/css/forms.css" />\n<script type="text/javascript" src="/components/js/global.js"></script>'
	+'<script language="JavaScript">\nwindow.onLoad = window.focus();\n</script></head>';
	var banner = '<div id="popHeader">'
	+'<table cellspacing="0" cellpadding="0" border="0">'
	+'<tr>'
	+'<td class="left"><img src="http://delta.m7z.net/delta/delta/backgrounds/headers/popup_header_left.jpg" alt="Delta" title="Delta" /></td>'
	+'<td class="right"><a href="javascript:self.close();"><nobr>Close Window</nobr></a></td>'
	+'</tr>'
	+'</table>'
	+'</div>';
	dWin.document.open();
	dWin.document.write('');
	dWin.document.write(head+'<body>\n'+banner+'<div class="popContainer">\n<p><b>'+title+'</b><br>\n'+desc+'</p></div></body></html>');
	dWin.document.close();
}

function logAction(string)
{
	var trackingPixelSrc = "http://www.delta.com/tracking/htmltag.gif?Log=1";
	if(document.getElementById("trackingPixel")!=null) { document.getElementById("trackingPixel").src = trackingPixelSrc+string.replace("amp;","")+"&rand="+Math.round(Math.random()*100000000); }
}
function setActiveTab(triggerID,type)
{
	var tabsID = type+"Tabs";
	var tabContentClass = type+"TabsContent";
	var activeTab = triggerID.split("_")[0];
	var tabs = get(tabsID);
	var tabCollection = tabs.getElementsByTagName('li');
	var tempCollection = document.getElementsByTagName('div');
	var tabContentCollection = new Array();
	for(var i=0;i<tempCollection.length;i++) { if(tempCollection[i].className.toString().split(" ")[0]==tabContentClass){tabContentCollection.push(tempCollection[i]);}}
	for(var i=0;i<tabCollection.length;i++)
	{
		setClassName(tabCollection[i].id,"");
		if(tabCollection[i].id==triggerID) { setClassName(tabCollection[i].id,"active"); }
		setClassName(tabContentCollection[i].id,tabContentCollection[i].className.toString().split(" ")[0]+" inactive");
		if(tabCollection[i].id==triggerID) { setClassName(tabContentCollection[i].id,tabContentCollection[i].className.toString().split(" ")[0]+" active"); }
	}
	if(document.getElementById(triggerID.split("_")[0]+"_tracking")!=null) { logAction(document.getElementById(triggerID.split("_")[0]+"_tracking").innerHTML); }
	if((document.getElementById(triggerID.split("_")[0]+"_additional")!=null)&&(document.getElementById("additional")!=null)) { document.getElementById("additional").innerHTML = document.getElementById(triggerID.split("_")[0]+"_additional").innerHTML; }
	else if(document.getElementById("additional")!=null) { document.getElementById("additional").innerHTML = ""; }
	else { /*doNothing()*/ }
}
function openPhotoViewer(title,path,imageRoot,numItem,numTotal)
{
	var winPath = "/components/popups/photo_viewer.jsp";
	var query = "?title="+title.replace(" ","_")+"&path="+path+"&imageRoot="+imageRoot+"&numItem="+numItem+"&numTotal="+numTotal;
	openWin(winPath+query,"PhotoViewer",450,450,'no');
}
function openClose(id1,id2)
{
	if (document.getElementById(id1).style.display=="none") { setClassName(id2,"active"); show(id1); }
	else { setClassName(id2,"inactive"); hide(id1); }
}





// this opens window with customizable dimensions, chrome (controls), scroll bar and spawn location; used when content is whole page, not pop-up content
function openWinfull( url, name, width, height, xpos, ypos, chrome, scroll ) {
	var x, y, w, h, moveX=0, moveY=0, features="";
	chrome = chrome ? "yes" : "no";
	scroll = scroll ? "yes" : "no";
	features += "toolbar="+chrome+",location="+chrome+",status="+chrome+",menubar="+chrome;
	features += ",scrollbars="+scroll+",resizable="+scroll;
	if(width) features += ",width="+width;
	if(height) features += ",height="+height;
	if(xpos && window.screen) {
		w = window.screen.availWidth;
		width = parseInt(width);
		switch(xpos){
			case "left": x = 0; break;
			case "center": x = (w-width)/2; break;
			case "right": x = w-width; break;
			default: x = xpos;
		}
		features += ",screenX="+x+",left="+x;
		var moveX = x;
	}
	if(ypos && window.screen){
		h = window.screen.availHeight;
		height = parseInt(height);
		switch(ypos){
			case "top": y = 0; break;
			case "middle": y = (h-height)/2; break;
			case "bottom": y = h-height; break;
			default: y = ypos;
		}
		features += ",screenY="+y+",top="+y;
		var moveY = y;
	}
	var openWinReference = window.open(url,name,features);
	if(moveX || moveY){
		// position the window for browsers that don't recognize screenX, screenY
		try {
			openWinReference.moveTo(moveX,moveY);
		} catch(AccessDeniedError) {}
	}
}
openFull = function(url,name){ openWinfull(url,name,"640","480","center","middle",false,"scroll"); }
openAll = function(url,name,width,height){ openWinfull(url,name,"640","480","center","middle","chrome","scroll"); }




var cWin = null;
var childwin = null;
var home_containers = new Array("primary_messaging","secondary_messaging","group_one","group_two_top","group_two_bottom");
var left_pos = 378;
var url_lang = window.location.toString().split(".")[0].split("//")[1];


function formatURL(url){
	var formattedURL = unescape(url);
	window.location = formattedURL;
}


function getDomainFromURL(url){
	var domain = null;
	if (url.length > 10 
		&& (url.substring(0,4) == 'http'))  {
		domain = url.substring(0, url.indexOf('/', 7));
}
return domain;
}
// Javascript Code for TeaLeaf Technology, Inc.
// Round Trip calculation function

function tltRoundTrip() {
//	var pos;
//	var GIF = "tlt_rt.gif";
//	var QueryString = "?TeaLeafRoundTrip=Yes&";
//	var PageTime = 0;
//	var d = new Date()
//	if (d.getTimezoneOffset) { QueryString += "TZ=" + -(d.getTimezoneOffset()/60) + "&"; }
//	PageTime = Math.round((new Date())/1000);
//	pos = document.cookie.indexOf("TLTSID=");
//	if (pos != -1) { QueryString += document.cookie.substring(pos,document.cookie.indexOf(";",pos)) + "&"; }
//	pos = document.cookie.indexOf("TLTUID=");
//	if (pos != -1) { QueryString += document.cookie.substring(pos,document.cookie.indexOf(";",pos)); }
//	QueryString += "&PageTime=" + PageTime
//	document.write("<img src=\"\/\/images.delta.com/delta/thirdparty/" + GIF + QueryString + "\" height=\"1\" width=\"1\" border=\"0\">");
//	return;
}
function SelectRadioButton(id){
	var tagRef = get(id);
	var radioList  = document[tagRef.form.name][tagRef.name];
	if(parseInt(radioList.length).toString() === 'NaN') {
		tagRef.checked = true;
	} else {
		for(var i = 0, j = radioList.length; i<j; i++) {
			radioList[i].checked = (radioList[i].value === tagRef.value);
		}
	}
}

function urlEncode(stringToEncode) {
	stringToEncode = stringToEncode.toString();  
	var encodedString = escape(stringToEncode);
	encodedString = encodedString.replace(/\+/g, "%2B").replace(/\//g, "%2F"); 
	return encodedString;
}

function doNWAInterstitial() {
	var qs = [];
	for(var i=0, j=arguments.length; i<j; i++) {
		var qsDefinition = arguments[i];
		if(typeof(qsDefinition) === 'object' && exists(qsDefinition.qsProp) && exists(qsDefinition.value) ) {
			qs[qs.length] = qsDefinition.qsProp + '=' + urlEncode(qsDefinition.value);
		}
	}
	openNewWin('/shared/components/interstitial/nwa/index.jsp' + (qs.length !== 0 ? '?' + qs.join('&') : ''), 'nwaWait', 1000, 750, 'yes', 'yes');
	cWin.focus();
}
