// Adds a class of 'linked' to bullet items that have links inside
// Usage: LinkBullets();
var LinkBullets = function(){
  $ES('li','content-start').each(function(item){
	if (item && $E('a', item))
      $(item).addClassName('linked');
  })
	$$('div.sidebar li').each(function(item){
	if (item && $E('a', item))
      $(item).addClassName('linked');
  })
}


/*



/*
QueryString utility 
----------------------------------------------*/
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
		else this.q = null;
		this.keyValuePairs = new Array();
		if(q) {
			for(var i=0; i < this.q.split("&").length; i++) {
				this.keyValuePairs[i] = this.q.split("&")[i];
			}
		}
		this.getKeyValuePairs = function() { return this.keyValuePairs; }
		this.getValue = function(s) {
			for(var j=0; j < this.keyValuePairs.length; j++) {
				if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
			}
			return false;
		}
		this.getParameters = function() {
			var a = new Array(this.getLength());
			for(var j=0; j < this.keyValuePairs.length; j++) {
				a[j] = this.keyValuePairs[j].split("=")[0];
			}
			return a;
		}
		this.getLength = function() { return this.keyValuePairs.length; } 
};
	
function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key));
};

/*------------------------------------------------------------------------------------
	deviceDocTable
	
	Usage:
	Window.addLoad(docHBX);
------------------------------------------------------------------------------------*/

var docHBX = function(){ 
	if($('deviceDocTable')){
		$$('#deviceDocTable tr').each(function(item){
			var TDel = $E('td.download', item);
			
			//adds the click event to the PDF link
			$E('a', TDel).addEvent('click', function(){
				
				//gets the name of the deliverable/document		
				var docTitle = $E('td.docName', item).innerHTML.trim();
				//gets the value of the userType-key 
				var userType = queryString('userType');	
				
				// TO DO:
				// Add an HBX call ( _HbLink() or something, consult the HBX manual for custom metrics ) and pass the docTitle and userType as custom metric
				
				// alert('UserType: ' + userType + ' , docTitle: ' + docTitle)
				
			});
		});			
	}
}


/*------------------------------------------------------------------------------------
	DOCUMENT MANAGER left nav
	expands the CSS-collapsed left nav based on the selected class of the current page
	
	Usage:
	Window.addLoad(docNav);
	
------------------------------------------------------------------------------------*/

var docNav = function(){
	if($('docmgrd')){
		$$('#sidenav li li').each(function(item){ 
				if(item.className == "selected" || item.parentNode.parentNode.className == "selected" || item.className == "selected first" || item.parentNode.parentNode.className == "selected first" ){
					item.setStyle('display','block');
					$(item.parentNode).setStyle('display','block');
					}
					else{}
		});													 														 
		}
}



/*
Add "first" class to first promo in sidebar to give it the dotted line seperator BG
---------------------------------------------------------*/

function addPromoSeperator(){
	docDiv = document.getElementsByTagName('div');	
	for(i=0; i<docDiv.length; i++){
		if(docDiv[i] && docDiv[i].className == 'sidebar'){
			sidebarDivs = docDiv[i].getElementsByTagName('div');
			for(j=0; j<sidebarDivs.length; j++){
				if(sidebarDivs[j].className && sidebarDivs[j].className == 'promo'){
					sidebarDivs[j].className += ' firstPromo';
					return;
				}
			}
		}
	}
}


/*
POPUP SCRIPT
--------------------*/

function popup(pageurl,winname,wide,vert) { 
	window.open(pageurl,winname,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + wide + ",height=" + vert + ",left=100,top=100");
}

function showcontentstart(){
	if(document.getElementById('content-start')){
		document.getElementById('content-start').style.visibility = 'visible';
	}
}



function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}

/*
JUMP MENU SCRIPT
--------------------*/

//  Go to the page identified by the selected popup entry.  If a sortings attribute
//  exists for the entry, use it to load the page with the preferred sorting.
function gotoSelection(popup,defaultIndex) {
    var selectedOption = popup.options[popup.selectedIndex];
    if( selectedOption ) {
        newLoc = selectedOption.value;
        if (newLoc != "") {
            var sorting_list = selectedOption.getAttribute("sortings");
            if( sorting_list ) {
                loadSortedPage( newLoc, sorting_list );
            } else {
                location.href = newLoc;
            }
        }
    }
    //  Reset the popup to its original value
    if( typeof defaultIndex != "undefined" && defaultIndex >= 0 ) {
        popup.selectedIndex = defaultIndex;
    }
}

//  Same as above but link opens in a new window
function gotoSelectionNewWindow(popup,defaultIndex) {
    var selectedOption = popup.options[popup.selectedIndex];
    if( selectedOption ) {
        newLoc = selectedOption.value;
        if (newLoc != "") {
            var sorting_list = selectedOption.getAttribute("sortings");
            if( sorting_list ) {
                loadSortedPage( newLoc, sorting_list );
            } else {
                window.open(newLoc);
            }
        }
    }
    //  Reset the popup to its original value
    if( typeof defaultIndex != "undefined" && defaultIndex >= 0 ) {
        popup.selectedIndex = defaultIndex;
    }
}


/*
OLD SCHOOL MOUSEOVER SCRIPT
---------------------------------*/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}




/*
INFOBOX used on worldwide page
------------------------------------------------------------------------------------------*/

var infoboxBuilt;
var i_mX;
var i_mY;
var i_followMouse;

function initAttachMouse(){
	var IE = document.all ? true:false;
	var tempX = 0;
	var tempY = 0;
	
	if (!IE) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = getMouseXY;
	function getMouseXY(e) {
		if (IE) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft;
			tempY = event.clientY + document.body.scrollTop;
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX;
			tempY = e.pageY;
		}  
		// catch possible negative values in NS4
		if (tempX < 0) tempX = 0;

		if (tempY < 0) tempY = 0;
		i_mX = tempX;
		i_mY = tempY;

		return true;
	}
}



function showInfoBox(lynk, offX, offY) {
	var elem = infoboxen[infolinks.indexOf(lynk)];
	var opacChange = new Fx.Style(elem, 'opacity', {duration: 250});
	elem.setStyle('display', 'block');
	opacChange.set(0);
	elem.injectInside($(document.getElementsByTagName('body')[0]));
	elem.setStyle('top', (i_mY + offY) + 'px');
	elem.setStyle('left', (i_mX + offX) + 'px');
	opacChange.custom(0, 1);
	boxActive = true;
}

function createBoxColumns(infobox) {
	var theUL = infobox.getElement('ul');
	var lis = theUL.getElements('li');
	var newUL;
	for (var i = 10; i < lis.length; i++) {
		if (i % 10 == 0) {
			newUL = new Element('ul');
			newUL.addClass('boxColumn');
			newUL.injectAfter(theUL);
			infobox.setStyle('width', (infobox.getStyle('width').toInt() + 125) + 'px');
			theUL = newUL; 
		}
		lis[i].remove();
		lis[i].injectInside(theUL);
	}
}

function hideInfoBox() {
	$$('.infobox').each(function(el) {
		el.remove();
	});
}

function initInfobox() {
	if (!document.getElementsByTagName) return;
	if (!$("world")) return;
	
	infolinks = $("world").getElements('area');
	infoboxen = $$(".infobox");
	boxActive = false;
	
	for (var i = 0; i < infolinks.length; i++) {
		
		infolinks[i].addEvent('mouseover', function() {
			mapOver(this.className);
		});
		infolinks[i].addEvent('mouseout', function() {
			mapOver("map_overlay_default");
		});
		infolinks[i].addEvent('click', function() {
			hideInfoBox();
			mapOver(this.className, true);
			showInfoBox(this, 20, 0);
			boxActive = true;
		});
		infoboxen[i].getElement('div').getElement('a').addEvent('click', function() {
			hideInfoBox();
		});
		if (infoboxen[i].getElements('li').length > 10) createBoxColumns(infoboxen[i]);
		infoboxen[i].remove();
	}
	
	initAttachMouse();
}


/*
WORLDWIDE
------------------------------------------------------------------------------------------*/

function mapOver(map_className, mouseClicked){
		if(map_className != 'worldmap_overlay_default' && !boxActive){
			document.getElementById('worldmap_overlay').className = map_className;
		}
		if(mouseClicked == true){
			document.getElementById('worldmap_overlay').className = map_className;
		}
	}
	
	
/*
TABS
------------------------------------------------------------------------------------------*/	
	
var docDivs;
var tabLinks;
var subTabLinks;
var subTabContainers;
var docA;
var currentContainer;
var hideCont_i;
var tabInnerHTML;

function toTop() {
	self.scrollTo(0, 0)
}

String.prototype.getAnchor = function() {
	return /#([a-z][\w.:-]*)$/i.exec(this)[1];
}

function changeTabHref(){

	docA.each(function(item){
					
	if(item.href){
			if(item.href.match('#tab_') == '#tab_'){
				hrefString = item.href;
				hrefString = hrefString.replace('#tab_','#tab_tab_');
				item.href = hrefString;
				item.onclick = function() {showlayer(this);}
			}
			if(item.href.match('#ddetail_subtab') == '#ddetail_subtab'){
				hrefString = item.href;
				hrefString = hrefString.replace('#ddetail_subtab','#tab_ddetail_subtab');
				item.href = hrefString;
				item.onclick = function() {showlayer(this);}
			}
		}			   
					   
	})
}

function upDOM(startHere, finishHere){
	parentPath = startHere;
	j = 0;
	while(parentTag != finishHere || j >= 100){
		parentPath = parentPath.parentNode;
		var parentTag = parentPath.tagName.toLowerCase();
		j++;
	}
	return parentPath;
}

function upDomById(startHere, finishHere){
	parentPath = startHere;
	j = 0;
	while(parentId != finishHere || j >= 100){
		parentPath = parentPath.parentNode;
		if(parentPath.id){
			var parentId = parentPath.id;
			parentId = parentId.match(finishHere);
		}
		j++;
	}
	return parentPath;
}

function hideThis(thisObj){
	if(thisObj.style){
		thisObj.style.display = 'none';
	}
}

function showThis(thisObj){
	if(thisObj.style){
		thisObj.style.display = 'block';
	}
	if($('container_wrapper')){
		if($('container_wrapper').style.visibility == 'hidden'){
			$('container_wrapper').style.visibility = 'visible';
		}
	}
}

function clearStyles(theseObj){
	for (var i = 0; i < theseObj.length; i++) {
		if(theseObj[i].parentNode.tagName.toLowerCase() == 'td'){
			theseObj[i].parentNode.className = '';
		}else{
			theseObj[i].className = '';
		}
	}
}

function setSelected(thisObj){
	if(thisObj.parentNode.tagName.toLowerCase() == 'td'){
		thisObj.parentNode.className = 'selected';
	}else{
		thisObj.className = 'selected';
	}
}

function getTab(v){
	return v.split('#tab_')[1];
}

function hideSubTabs(){
	if(subTabContainers.length>=1){
		for(var i = 0; i < subTabContainers.length; i++){
			hideThis(subTabContainers[i]);
		}
	}
}

function hideContentLayers(){
	for(var i = 0; i < docDivs.length; i++){
		if(docDivs[i].id && docDivs[i].id.match('tab_') == 'tab_'){
			hideThis(docDivs[i]);
		}
	}
}

function openTabContent(thisTabContent){
	thisTabContent_id = thisTabContent;
	thisTabContent = $(thisTabContent);
	if(!thisTabContent) return;
	clearStyles(subTabLinks);
	hideContentLayers();
	//check href target of level 1 anchors, same as thisTabContent? clear level 1 styles, setSelected & hide subTabs
	
	tabLinks.each(function(item){
		linkTarget = $(getTab(item.href));
		if(item.href.match('#tab_') == '#tab_' && linkTarget == thisTabContent){
			clearStyles(tabLinks);
			setSelected(item);
			hideSubTabs();
		}
	})
	
	if($('ddetail_tabs').hasClassName('homePageTabs') && currentContainer != thisTabContent_id){
		
		heightChange = new fx.Style(thisTabContent_id, 'margin-left', {duration:500});

		heightChange.set(-881);
		heightChange.custom(-881, 0);
		showThis($(thisTabContent_id));
		if($(currentContainer)){
			showThis($(currentContainer));
			$(currentContainer).parentNode.style.zIndex = 20;
			$(thisTabContent_id).parentNode.style.zIndex = 21;
		}
		
		if (!navigator.appVersion.match("MSIE")){
			opacChange = new Fx.Style(thisTabContent_id, 'opacity', {duration: 500});
			opacChange.set(0);
			opacChange.custom(0.0, 1.0);
		
		}
		else if (navigator.appVersion.match("MSIE 6.0")){
			var url = window.location.href;
			var strQueryString
  			//alert(url);
  			if(url.indexOf("#") > -1){
				
				strQueryString = url.substr(url.indexOf("#")+1).toLowerCase();			
				
			}
			else{ strQueryString = "";}
		
			
			if(strQueryString.search(/business/) > -1){
				$('smartphonesMenu').style.visibility = 'hidden';
				$('solutionsMenu').style.visibility = 'visible';
			}
			else{
				$('solutionsMenu').style.visibility = 'hidden';
				$('smartphonesMenu').style.visibility = 'visible';
			}
		}
		
		currentContainer = thisTabContent_id;
	}else{
		
		//check href target of level 2 anchors, same as thisTabContent? set selected and show its container. also, set selected to associated level 1 anchor 
		showThis(thisTabContent);
		subTabLinks.each(function(item){							  
			if(item.href.match('#tab_') == '#tab_' && $(getTab(item.href)) == thisTabContent){
				//reference to the container object - which WILL CONTAIN 'ddetail_subtab'+i
				subTabContainer = upDomById(item, 'ddetail_subtab');
				showThis(subTabContainer);
				setSelected(item);			
				tabLinks.each(function(item){								   
					jLinkTarget = $(getTab(item.href));
					if(jLinkTarget == subTabContainer){
						setSelected(item);
					}
				})
			}
		
		})
		
		//check if thisTabContent is a subTab, if so, set selected to the first anchor and open its target href
		if(thisTabContent.parentNode.id == 'ddetail_subtabs_wrapper'){
			subLinks = thisTabContent.getElementsByTagName('a');		
			showThis($(getTab(subLinks[0].href)));
			setSelected(subLinks[0]);
		}
	}
	if(!$('ddetail_tabs').hasClassName('noTabScroll')){
		toTop();
	}
}

function deeplink(){
	if(!document.location.hash){
		if($$('.defaultTabContent')[0]){
			tabContent = $$('.defaultTabContent')[0].parentNode.id;
		}else{
			tabContent = $(getTab(tabLinks[0].href));
		}	
	}else{
		if(document.location.hash.match('subtab') == 'subtab'){	
			newHash = document.location.hash;
			
			if(newHash.match('#tab_tab_') == '#tab_tab_'){
				newHash = newHash.replace('#tab_tab_','');
			}else if(newHash.match('#tab_') == '#tab_'){
				newHash = newHash.replace('#tab_','');
			}
			
			tabContent = $(newHash);
		}else{
			if(document.location.hash.match('#tab_tab_') != '#tab_tab_'){
				tabContent = $(getTab("#tab_"+document.location.hash.getAnchor()));
				window.location.replace("#tab_"+document.location.hash.getAnchor());
			}else{
				tabContent = $(getTab(document.location.hash));	
			}
		}	
	}
	openTabContent(tabContent);
}

function showlayer(link){
	if(link){
			//for hbx tracking
			tabInnerHTML = link.innerHTML.stripTags();
			tabInnerHTMLclean = _hbxStrip(tabInnerHTML);
			var _content = _mlc;
			var _rpnClean = _hbxStrip(_rpn);
			_hbPageView(_rpnClean + "+" + "tab_" + tabInnerHTMLclean,_content);
		window.location.replace(link.href);
		openTabContent(getTab(link.href));
		
	}
}

function initTabs(){
	//if theres tabs, run it
	
	if($('container_wrapper')){
		$('container_wrapper').style.visibility = 'hidden';
	}
	
	if($('ddetail_tabs')){
		//ARRAYS
		
		subTabLinks = $A($('ddetail_subtabs_wrapper').getElementsByTagName('a'));
		if(!subTabLinks[0]){
			hideThis($('ddetail_subtabs_wrapper'));
		}
		
		docA = $A(document.getElementsByTagName('a'));
		changeTabHref();
	
		docDivs = $A(document.getElementsByTagName('div'));		
		tabLinks = $A($('ddetail_tabs').getElementsByTagName('a'));	
		
		subTabContainers = $A($('ddetail_subtabs_wrapper').childNodes);
		
		subTabContainers.each(function(el) {
			hideThis(el);
		});
		
		//PERFORM FUNCTIONS
		
		deeplink();
	}
}
	
/*
FROM comparisonChart.js
------------------------------------------------------------------------------------------*/	

function initCompareRow(){
	if (!document.getElementsByTagName){return;}
	
	var CRContainers = $A(document.getElementsByClassName('ComparisonRow_Container'));
	var CRLabels = $A(document.getElementsByClassName('ComparisonRow_Label'));
	var CRContents = $A(document.getElementsByClassName('ComparisonRow_Content'));
	
	for(i = 0; i < CRContents.length; i++){
		if(i >= 2){
			hideThis(CRContents[i]);
			CRContents[i].parentNode.getElementsByTagName('div')[0].getElementsByTagName('p')[0].className = 'closed';
		}
	}
	
	for(i = 0; i < CRLabels.length; i++){
		var thisDiv = CRLabels[i];
		
		function toggleContentDisplay(thisLabel){
			var compRowContentId = thisLabel.parentNode.getElementsByTagName('div')[1].getAttribute('id');	
			var label_p = thisLabel.getElementsByTagName('p')[0];
			
			if($(compRowContentId).style.display == 'none'){
				showThis($(compRowContentId));
				label_p.className = '';
			}else{
				hideThis($(compRowContentId));
				label_p.className = 'closed';
			}	
		}
		
		thisDiv.onclick = function (){	
			toggleContentDisplay(this);
			return false;
		}	
		
		thisDiv.onmouseover = function (){
			this.style.color = '#000';
			return false;
		}
		
		thisDiv.onmouseout = function (){
			this.style.color = '#666';
			return false;
		}		
	}	
}


	
/*
	FROM legacy bb_com.js
------------------------------------------------------------------------------------------*/	

function bb_popup(theURL) {
	if (self.screen) { 
      	sw = screen.width
       	sh = screen.height
		w = 880
		h = 672
		cx = (.5*sw) - (w*.5)
		cy = (.5*sh) - (h*.5)
        var size = 'width='+w+','+'height='+h+',' + 'screenX=' +cx+','+'screenY='+cy+','+'left='+cx+','+'top='+cy
    }
    Pop=window.open(theURL,'',size);   
}

/* PARTNER_ZONE_FUNCTIONS */
  function pz_focusControl() {
	  document.forms[0].username.focus();
  }

  function pz_trim(strInput) {
      var reSpaceStart, reSpaceEnd;

      reSpaceStart = new RegExp("^\\s+", "gi");
      reSpaceEnd   = new RegExp("\\s+$", "gi");

      return (strInput.toString().replace(reSpaceStart, "")).replace(reSpaceEnd, "");
  }

  function pz_isBlank(testStr) {
      return (pz_trim(testStr) == "");
  }

  function pz_validateForm() {
      var theForm = document.frmLogin;
      var blnSubmit = true;

	  if (pz_isBlank(theForm.username.value)) {
          alert("Please enter your user name.");
          theForm.username.focus();
          blnSubmit = false;
      } else if (pz_isBlank(theForm.password.value)) {
          alert("Please enter your password.");
          theForm.password.focus();
          blnSubmit = false;
      }

      return blnSubmit;
  }

  function pz_fncSubmit() {
      if (pz_validateForm()) {
          document.frmLogin.loginLocaleID.value = "";
          document.frmLogin.submit();
      }
  }
  
  function pz_fncSubmit1() {

       document.frmLogin.action = "https://www.blackberry.com/partnerzone/Login.action";
       document.frmLogin.actionName.value = "emailPassword";
       document.frmLogin.loginLocaleID.value  = "1";
       document.frmLogin.submit();
   }

   function pz_fncSubmitonEnter(evt) {
       if (document.layers) {
           if (evt.which == 13) {
               fncSubmit();
           }
       } else {
           if (evt.keyCode == 13) {
               fncSubmit();
           }
       }
   }

   function pz_fncSubmitonEnter1(evt) {
       if (document.layers) {
           if (evt.which == 13) {
               fncSubmit1();
           }
       } else {
           if (evt.keyCode == 13) {
               fncSubmit1();
           }
       }
   }

   function pz_changeLoginLocale(cwLocaleID) {
       document.frmLogin.action = "https://www.blackberry.com/partnerzone/Login.action";
       document.frmLogin.actionName.value = "showLogin";
       document.frmLogin.loginLocaleID.value = cwLocaleID;
       document.frmLogin.submit();
   }

   function pz_forgotPassword() {
       document.frmLogin.action = "https://www.blackberry.com/partnerzone/Forward.action";
       document.frmLogin.path.value           = "/login/login.jsp";
       document.frmLogin.loginLocaleID.value  = "1";
       document.frmLogin.forgotPassword.value = "yes";
       document.frmLogin.submit();
   }

   function pz_backToLoginPage() {
       document.frmLogin.action = "https://www.blackberry.com/partnerzone/Forward.action";
       document.frmLogin.path.value = "/login/login.jsp";
       document.frmLogin.loginLocaleID.value  = "1";
       document.frmLogin.submit();
   }

   function pz_emailPassword() {
       document.frmLogin.action = "https://www.blackberry.com/partnerzone/Login.action";
       document.frmLogin.actionName.value = "emailPassword";
       document.frmLogin.loginLocaleID.value  = "1";
       document.frmLogin.submit();
   }
   
   
/* DEVELOPER LABS LEGAL FORM */
function dl_getCookie(c_name)
{
	if (document.cookie.length>0)
	{ 
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return null
}


function dl_setCookie(c_name,value,expiredays)
{
	var exdate=new Date()
	exdate.setDate(expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : "; expires="+exdate)
}


function dl_checkCookie()
{
	userlegal=dl_getCookie('userlegal')
	if (userlegal!=null) {
		window.location = "developer_labs.jsp"
	}
}


function dl_valbutton(thisform) 
{
	myOption = -1;
	for (i=thisform.myradiobutton.length-1; i > -1; i--) {
		if (thisform.myradiobutton[i].checked)
			myOption = i;
	}
	
	if (myOption == -1) {
		alert("You must select \"I Agree\" or \"I Disagree\"");
		return false;
	}
	if (myOption == 0) {
		userlegal = "agree";
		dl_setCookie('userlegal',userlegal,365);
		window.location = thisform.action;
	}
	if (myOption == 1) {
		window.location="../index.jsp";
	}
}

function dl_checkCookie_redirect()
{
	userlegal=dl_getCookie('userlegal')
	if (userlegal==null)
	  {
	  //alert('You must agree to the legal T&C first');
	  window.location="index.jsp";
	  }
}

	
/*
	FROM navtop_desc.js
------------------------------------------------------------------------------------------*/

function initNavTopDesc(){	
	//IF - Check for 'navtop_desc' object
	if($('navtop_desc')){
		//VAR for 'mouseoutInt()'
		var mouseOut_i;
		
		var navtop_state = 'closed';
		
		var heightChange3 = new fx.Style('navtop_desc', 'height', {duration:250});
		var heightChange4 = new fx.Style('navtop_desc', 'height', {duration:250});

		heightChange3.set(0);
		//FUNCTION - injects 'rel' text via innerHTML as <p>, calls 'showThis()' which sets display to 'block'
		openNavTopDesc = function(desc){	
			$('navtop_desc').innerHTML = '<p>'+desc+'</p>';
			if(navtop_state == 'closed'){
				heightChange3.custom(0, 25);
				navtop_state = 'open';
			}
		}

		//FUNCTION - call 'hideThis()'
		closeNavTopDesc = function(){
			heightChange4.custom(25, 0);
			navtop_state = 'closed';
		}
		
		//FUNCTION - sets timeout for 1000 milliseconds before calling 'closeNavTopDesc()'
		
		mouseoutInt = function(func){
			switch(func){
				case 'set':
					mouseOut_i = setTimeout('closeNavTopDesc()', 1000);
				break;

				case 'clear':
					clearTimeout(mouseOut_i);
				break;
			}
		
		}
		
		//VAR - array of all the links in 'navtop'
		var navtopLinks = $A($('navtop').getElementsByTagName('a'));		

		//FUNCTION - applies functions to mouse states
		navtopLinks.each(function(el){
			el.onmouseover = function(){		
				openNavTopDesc(el.getAttribute('rel'));
				mouseoutInt('clear');
			}
			
			el.onmouseout = function(){
				mouseoutInt('set');
			}
			
			el.onclick = function(){
				el.onmouseout = function(){};
			}
		})
		
	}
}


	
/*
	FROM swfobject.js
------------------------------------------------------------------------------------------*/
/**
 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){_16.push(key+"="+_18[key]);}
return _16;},getSWFHTML:function(){var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){
this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";
}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();return true;
}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(){
var _23=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}
catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
return _23;};
deconcept.PlayerVersion=function(_27){
this.major=_27[0]!=null?parseInt(_27[0]):0;
this.minor=_27[1]!=null?parseInt(_27[1]):0;
this.rev=_27[2]!=null?parseInt(_27[2]):0;
};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){
return false;
}return true;};
deconcept.util={getRequestParameter:function(_29){
var q=document.location.search||document.location.hash;
if(q){var _2b=q.substring(1).split("&");
for(var i=0;i<_2b.length;i++){
if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){
return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
return "";}};
deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
var _2d=document.getElementsByTagName("OBJECT");
for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){
if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};
deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};
__flash_savedUnloadHandler=function(){};
if(typeof window.onunload=="function"){
var _30=window.onunload;
window.onunload=function(){
deconcept.SWFObjectUtil.cleanupSWFs();_30();};
}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};
if(typeof window.onbeforeunload=="function"){
var oldBeforeUnload=window.onbeforeunload;
window.onbeforeunload=function(){
deconcept.SWFObjectUtil.prepUnload();
oldBeforeUnload();};
}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
if(Array.prototype.push==null){
Array.prototype.push=function(_31){
this[this.length]=_31;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject;
var SWFObject=deconcept.SWFObject;


/*
 HBX Post Load Insertion
--------------------------------------------------------*/
function loadContent(file) {
	var h = document.getElementsByTagName('head')[0];
	var s = document.createElement('script');
	s.src = file;
	s.type = "text/javascript";
	h.appendChild(s);
}

function insertHBX() {
	loadContent("/assets/js/hbx.js");
	loadContent("/assets/js/hbx-custom.js");
	
	
}

/*------------------------------------------------------------------------------------
	Preloader
	A very simple image preloader object
  
 	Usage:
    Preloader.add(path);
    Preloader.onFinish(func);
    Preloader.load();
    
      path: 		A string or array of strings of image paths to preload
      func:     A function or array of functions to be called after images are loaded
      load():   Start the preloader
------------------------------------------------------------------------------------*/

var Preloader = {
  callbacks: [],
  images: [],
  loadedImages: [],
  imagesLoaded: 0,
  
  add: function(image){
    if (typeof image == 'string') this.images.push(image);
    if (typeof image == 'array' || typeof image == 'object'){
      for (var i=0; i< image.length; i++){
        this.images.push(image[i]);
      }
    }
  },
  onFinish: function(func){
    if (typeof func == 'function') this.callbacks.push(func);
    if (typeof func == 'array' || typeof func == 'object'){
      for (var i=0; i< func.length; i++){
        this.callbacks.push(func[i]);
      }
    }
  },
  load: function(){
    for(var i=0; i<this.images.length; i++){
      this.loadedImages[i] = new Image();
      this.loadedImages[i].onload = function(){ Preloader.checkFinished.apply(Preloader) }
      this.loadedImages[i].src = this.images[i];
    }
  },
  checkFinished: function(){
    this.imagesLoaded++;
    if (this.imagesLoaded == this.images.length) this.fireFinish();
  },
  fireFinish: function(){
    for (var i=0; i<this.callbacks.length; i++){
      this.callbacks[i]();
    }
    this.images = [];
    this.loadedImages = [];
    this.imagesLoaded = 0;
    this.callbacks = [];
  }
}


/*
Dropdown link HBX
--------------------------------------------------------*/

function dropDownLink(e) {
	
	if(e.value != "") {
		var carrierName = e[e.selectedIndex].innerHTML.replace(/\s+/g,'+');
		carrierName = carrierName.replace('&nbsp;&nbsp;','');
		carrierName = carrierName.replace('&amp;','');
		var param = e.name + "+" + carrierName;
		_hbLink(param);
		window.location = e.value;
	}
}