// JavaScript Document

var usrGlbl;  

function WTlog(thislink) {
	if ( document.cookie.indexOf("qazqsa29") > 0 || document.cookie.indexOf("nonmsa29") > 0 ) {
		wrapDcsMultiTrack(thislink.href) ; 
	}
	else {
		document.cookie="wtdlay=" + thislink.href + ";path=/;domain=asq.org";
	}
}

function WTFileTagging(thislink) {
	WTlog(thislink);
}

function WTlogDlay() {
	if (document.cookie.indexOf("wtdlay") > 0) {
		var startAt		= document.cookie.indexOf("wtdlay")+7; 
		var remainingPart	= document.cookie.substring(startAt);

		wturl = remainingPart.indexOf(";") >-1 	? remainingPart.substring(0,remainingPart.indexOf(";")) 
												: remainingPart ;
		wrapDcsMultiTrack(wturl) ;
		var passedTime  = new Date(new Date().getTime() - 60000);
		document.cookie="wtdlay=asq1;path=/;domain=asq.org;expires=" 	+ passedTime.toGMTString();
	}
}

function wrapDcsMultiTrack (mylink){
	thelink = mylink;
	thelink = thelink.replace(/http:..www.asq.org/,"");
	dcsMultiTrack('DCS.dcssip','www.asq.org','DCS.dcsuri',thelink,'WT.ac') ;
}

//This function is used for highlighting navigation to save on template numbers
function highlight(nav) {
    if (document.getElementById(nav) != null){ 
        document.getElementById(nav).className = 'selected'; //selected
    }
}

function highlightTab(tab,nav) {
	document.getElementById(tab).className = 'overnav'; //selected
	document.getElementById(nav).className = 'selected'; //selected
}

function checkSignInCookie(memberPage) {
	if (document.cookie.indexOf("qazqsa29") > 0) {
		if ( isNonMember(getUsrGlbl())  ) {
			// nothing
		}
		else {
			window.location.href  = memberPage;
		}
	}
}

function getUsrGlbl() {
	var allCookies = document.cookie.toString();
	//if ( allCookies.indexOf("10.1.7.115") > -1) {
		//alert (allCookies);
	//}

	if(allCookies.indexOf("nebsuc") > -1) {
		var startAt			= allCookies.indexOf("nebsuc")+7; 
		var remainingPart 	= allCookies.substring(startAt);

			usrGlbl = remainingPart.indexOf(";") >-1 	? remainingPart.substring(0,remainingPart.indexOf(";")) 
									: remainingPart ;
		if ( allCookies.indexOf("10.1.7.115") > -1 ) {
			//alert("JR TEMPORARY DEBUG.. " + decode(usrGlbl)); 
		}
		return decode(usrGlbl); 
		
	}
}

function dsplLgn() {
	WTlogDlay() ;
	usrGlbl = getUsrGlbl();
	if (usrGlbl != null){

		var usrNm 	= usrGlbl.substring(0,usrGlbl.indexOf("~"));

		if ( usrNm != null && usrNm != '') { 

		
			if ( 	location.href.indexOf("group-registration") == -1 &&
				( 	usrGlbl.indexOf("ORGANIZATION") > -1 || 
					usrGlbl.indexOf("SUSTAINING") > -1 || 
					usrGlbl.indexOf("SCHOOL") > -1 	|| 
					usrGlbl.indexOf("DISTRICT") > -1
				) 
			) {

				if (location.href.indexOf("/members/") > -1) {
					location.href = '/members/group-registration.html';
				}
			}

			/////  HEADER 
			var header ;
			if (location.href.indexOf(".hq.") > -1) {
				header= '<span class="bluebold">Logged In as ' + usrNm   + '</span> <br /> <a href="http://www.asq.org/log-out.html">Log Out</a> <img src="/img/templates/nonmember/header-member-logout.gif" />&nbsp;&nbsp;<a href="/members/account/manage-account.html">My Account</a> <img src="/img/templates/nonmember/header-my-account.gif" />&nbsp;&nbsp; <a href="http://www.asq.org/store/shopping_cart.html">View Shopping Cart</a> <img src="/img/templates/nonmember/header-shopping-cart.gif" />&nbsp;&nbsp;<a href="http://www.asq.org/pub/qualityprogress/">Quality Progress Magazine</a> <img src="/img/templates/nonmember/header-qp.gif" /> ' ;
			}
			else {
				header= '<span class="bluebold">Logged In as ' + usrNm  + '</span> <br /> <a href="http://www.asq.org/log-out.html">Log Out</a> <img src="/img/templates/nonmember/header-member-logout.gif" />&nbsp;&nbsp;<a href="/members/account/manage-account.html">My Account</a> <img src="/img/templates/nonmember/header-my-account.gif" />&nbsp;&nbsp; <a href="http://www.asq.org/store/shopping_cart.html">View Shopping Cart</a> <img src="/img/templates/nonmember/header-shopping-cart.gif" />&nbsp;&nbsp;<a href="http://www.asq.org/pub/qualityprogress/">Quality Progress Magazine</a> <img src="/img/templates/nonmember/header-qp.gif" /><META NAME="WT.rv" CONTENT="1"> ' ;
			}

			/////  MEMBERSHIP RENEWAL  
			if ( location.href.indexOf("/members/") > -1) {

				var message = getRenewMessage(usrGlbl) ; 
				if (message.length > 0) {
					header += ( message ) ; 
				}
				if ( isGroup(usrGlbl) || isParticipant(usrGlbl) ) {
					if (document.getElementById('headTable') != null) {					
					document.getElementById('manage_URL').href 		= '/members/participant/manage-account.html' ;
					document.getElementById('manage_img').src 		= '/img/templates/manage-my-account.gif' ;
					document.getElementById('manage_img').alt 		= 'Manage My Account' ;
					document.getElementById('callout3_img').alt 	= 'Join ASQ' ;
					document.getElementById('callout3_img').src 	= '/img/templates/join-asq-today.gif' ;
					document.getElementById('callout3_url').href	= '/members/participant/join-asq.html' ;
					document.getElementById('MySectionsBlurb').style.display 	= 'block' ;
					document.getElementById('MyNetworksBlurb').style.display 	= 'block' ;
					document.getElementById('MyForumsBlurb').style.display		= 'block' ;
					document.getElementById('MyBoardsBlurb').style.display 		= 'block' ;
					}
				}

				/////  BENEFITS LINK 
				if (document.getElementById('headTable') != null) {
					//document.getElementById('quality_img').src = '/img/templates/home/we-are-quality.gif' ;
					if 		( usrGlbl.indexOf("ORG")>-1 || isParticipant(usrGlbl) ) {		
						document.getElementById('benefits_URL').href = '/members/participant/benefits-enterprise.html' ;
					}
					else if 	( usrGlbl.indexOf("SUSTAINING")>-1 ) {		
						document.getElementById('benefits_URL').href = '/members/participant/benefits-site.html' ;
					}
					else if 	( usrGlbl.indexOf("SCHOOL")>-1 ||  usrGlbl.indexOf("DISTRICT")>-1 ) {		
						document.getElementById('benefits_URL').href = '/members/participant/benefits-educational.html' ;
					}
					else if 	( usrGlbl.indexOf("NON-MEMBER")>-1 ) {		
						////document.getElementById('benefits_URL').href = '' ;
					}
				}

			}

			if ( location.href.indexOf("/membership/") > -1) {
				if ( isGroup(usrGlbl) || isParticipant(usrGlbl) ) {
					// nothing 
				}
				else {
					if (document.getElementById('membershipTabs') != null) {
						document.getElementById('membershipTabs').innerHTML= '<table border="0" cellspacing="0" cellpadding="0"><tr><td><a href="/membership/members/your-benefits.html" id="ym">Your Membership<br />Benefits and Features</a></td><td><a href="/membership/members/did-you-know.html" id="dyk"><br />Did You Know...?</a></td><td><a href="/membership/members/renew.html" id="renew"><br />Renew</a></td><td><a href="/membership/members/get-involved.html" id="gi"><br />Get Involved</a></td><td><a href="/membership/members/upgrade.html" id="uym">Upgrade Your<br />Membership</a></td></tr></table>';
					}
				}
			}

			
			if ( location.href.indexOf("/global/") > -1) {
				if ( isGroup(usrGlbl) || isParticipant(usrGlbl) ) {
					// nothing 
				}
				else {
					if (document.getElementById('mainText') != null) {
						document.getElementById('mainText').innerHTML= '<p class="blueheadline">Take Advantage of Your ASQ Member Benefits!</p><p><strong><a href="/members/">My ASQ</a></strong> &ndash; Access the online member community. Find information tailored to your needs. Connect with members in your industry or area.</p><p><strong><a href="/members/news/newsletters/gazeta/index.html"><em>Gazeta Global</em></a></strong> &ndash; Read the current issue of this electronic newsletter written specifically for international members like you. There is also an archive of past issues.</p><p><strong><a href="/discuss/">International Quality Discussion Board</a></strong> &ndash; Discuss quality from an international perspective. Topics of discussion might include multinational operations, international standards, or even cultural and economic considerations as they impact the application of quality principles.</p><p><strong>Country Councilors</strong> &ndash; Your membership gives you  access to Country Councilors. Country Councilors are the focal point for  International Chapter members in their respective countries, helping individual  and site members by fostering communications and providing services and  member benefit information. ASQ has Country Councilors in over 45 countries.  You may contact other Councilors if you would like to get in touch with ASQ members  in other countries. Please identify yourself as an ASQ member. Find the  councilor in your region.</p><ul><li><a href="/members/international/africame/index.html">Africa &amp; Middle East</a></li><li><a href="/members/international/americas/index.html">Americas</a></li><li><a href="/members/international/asiapacific/index.html">Asia Pacific</a></li><li><a href="/members/international/europe/index.html">Europe</a></li></ul><p><strong>International Chapter Chair</strong> &ndash; Please contact <a href="mailto:Gregbss@aol.com">Greg Watson</a>, the International  Chapter Chair with general questions and for further assistance.</p>';
						document.getElementById('promoBoxes').innerHTML= 		 '';
						document.getElementById('secondaryNav').innerHTML= '<ul><li id="o"><a href="/global/membership/overview.html">Your Benefits</a></li><li id="m"><a href="/members/index.html">My ASQ</a></li></ul>';
					}
				}
			}
			
			
			if ( location.href.indexOf("/advocacy/") > -1) {
		if ( document.cookie.indexOf("10.1.7.115") > -1 || usrGlbl.indexOf("Dildine") > -1) {
			//alert(usrGlbl); 
			//alert(isGroup(usrGlbl) + " " + isParticipant(usrGlbl) ); 
		}
				if ( isGroup(usrGlbl) || isParticipant(usrGlbl) ) {
					// nothing 
				}
				else {
					if (document.getElementById('mainText') != null) {
						document.getElementById('mainText').innerHTML= '<p class="blueheadline">Network</p><p><strong>Quality Networks:</strong> You can <a href="/advocacy/network/my-networks.html">access the ASQ Networks you&#8217;ve already selected</a>. Or you can <a href="/communities/">peruse all the networks</a> to see if it&#8217;s time to join a new one.</p><p><strong><a href="/advocacy/network/my-sections.html">Your ASQ Sections:</a></strong> Get in touch with your local section and get involved.</p><p><strong><a href="http://www.asq.org/java_members/calendar/submitEvent.jsp">Create an Event:</a></strong> Are you organizing an ASQ-related event? We&#8217;ll help you spread the word.</p><p><strong><a href="http://www.hq.asq.org/discuss/">ASQ&#8217;s Interactive Community:</a></strong> Online options for connecting with others who share your interest in advocating quality.</p><p><strong>Help Us Make a Difference:</strong> Learn more about the power of quality, so you can more effectively carry the message to your peers and community.</p><ul class="bulletOrange"><li><a href="/learn-about-quality/cost-of-quality/overview/overview.html">The Cost of Quality:</a> Actually, it&#8217;s <em>not</em> having quality that costs us. Here&#8217;s a basic primer on the concept.</li><li><a href="/economic-case/">Making the Case for Quality:</a> Get an executive-level look at how quality pays in any organization and how to "make the case" for quality in your organization. Includes resources you can put to work immediately.</li></ul>';
						document.getElementById('promoBoxes').innerHTML= 		 '';
						document.getElementById('secondaryNav').innerHTML= '<ul><li id="o"><a href="/advocacy/network/">Overview</a></li><li id="n"><a href="/advocacy/network/my-networks.html">Quality Networks</a></li><li id="s"><a href="/advocacy/network/my-sections.html">Your ASQ Section</a></li><li id="ce"><a href="http://www.asq.org/java_members/calendar/submitEvent.jsp">Create Event</a></li><li id="ic"><a href="http://www.hq.asq.org/discuss/">Interactive Community</a></li><li id="cq"><a href="/learn-about-quality/cost-of-quality/overview/overview.html">Cost of Quality</a></li><li id="cfq"><a href="/economic-case/">Case for Quality</a></li></ul>';
					}
				}
			}
			
			
			document.getElementById('loginarea').innerHTML = header ; 


		}
		
	}
}

function getRenewMessage(usrGlbl) {
	var mths = new Array('','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	var message = '';
	if (usrGlbl.indexOf("~RN") > -1 ) {
		var ren = usrGlbl.substring(usrGlbl.indexOf("~RN")+1,usrGlbl.indexOf("~RN")+14);

		if ( ren != null && ren.length > 0) {
					
			var arrayRnDt = (ren.substring(3)).split("/");
			if (arrayRnDt[0].substring(0,1) == '0') arrayRnDt[0] = arrayRnDt[0].substring(1);
			var formattedDate = mths[parseInt(arrayRnDt[0])] + ' ' + arrayRnDt[1] + ', ' + arrayRnDt[2] ;

			if ( ren.indexOf("RNL") > -1) {
				  message = 'Your membership expires ' + formattedDate + '. <a href="/membership/renew.html"><b>Renew Now!</b></a>' ;
			}
			else if ( ren.indexOf("RND") > -1 ) {
				  message = 'Membership Renewed ' + formattedDate + '. Thank you.';
			}
		}
	}
	if ( message.indexOf("undefined") > -1) { 
		message = '' ;
	}
	return message;
}


function getPublMessage(usrGlbl) {
	var publDirName = location.href.substring(location.href.indexOf("/pub/")+5,location.href.lastIndexOf("/") ) ; 
	var usrBnefName;
	if (publDirName == 'qualityprogress'){
		publDirname = 'QP';
	}
	else if (publDirName == 'sixsigma'){
		publDirname = 'SSF';
	}
	return '<br>' + publDirName;
}

var base64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function decode(encStr) {
  var bits, decOut = '', i = 0;
  for(; i<encStr.length; i += 4){
    bits =
     (base64s.indexOf(encStr.charAt(i))    & 0xff) <<18 |
     (base64s.indexOf(encStr.charAt(i +1)) & 0xff) <<12 | 
     (base64s.indexOf(encStr.charAt(i +2)) & 0xff) << 6 |
      base64s.indexOf(encStr.charAt(i +3)) & 0xff;
    decOut += String.fromCharCode(
     (bits & 0xff0000) >>16, (bits & 0xff00) >>8, bits & 0xff);
    }
  if(encStr.charCodeAt(i -2) == 61)
    undecOut=decOut.substring(0, decOut.length -2);
  else if(encStr.charCodeAt(i -1) == 61)
    undecOut=decOut.substring(0, decOut.length -1);
  else undecOut=decOut;
  
  return unescape(undecOut);		//line add for chinese char
}

var gAutoPrint = true; // Flag for whether or not to automatically call the print function
function printFriendly()
{
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD><link rel=\"stylesheet\" href=\"/includes/global.css\" type=\"text/css\"><link rel=\"stylesheet\" href=\"/includes/audience.css\" type=\"text/css\">\n';

		html += '\n</HEAD>\n<BODY style=\"font: 11px/13px verdana, arial, sans-serif\"><table border=0 cellspacing=0 cellpadding=0 align=right><tr><td width=69 valign=top><img src=\"/img/templates/shared/asq_logo_s.gif\" border=0></td></tr></table>\n';
		
		var printPageElem = document.getElementById("printFriendly");
		
		if (printPageElem != null)
		{
				html += printPageElem.innerHTML;
		}
		else
		{
			alert("Could not find the printFriendly section in the HTML");
			return;
		}
			
		html += '\n<table width=95% border=0 cellspacing=0 cellpadding=5 align=center><tr><td><hr>Copyright ©2005 American Society for Quality. All rights reserved.<br>Republication or redistribution of ASQ content is expressly prohibited without the prior written consent.<br>ASQ shall not be liable for any errors in the content, or for any actions taken in reliance thereon.</td></tr></table></BODY>\n</HTML>';
		
		var printWin = window.open("","printFriendly");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Sorry, the printer friendly feature works\nonly in javascript enabled browsers.");
	}
}

function openNewWindow(theURL,winName,features) {
    			window.open(theURL,winName,features);
}

function isGroup(usr){
	if 	( 	usr.indexOf("ORG") 			> -1	|| 
			usr.indexOf("SCHOOL") 		> -1 	|| 
			usr.indexOf("SUSTAINING") 	> -1	||
			usr.indexOf("DISTRICT") 	> -1 ) {
		return true;
	}
}

function isParticipant(usr) {
	if 	( usr.indexOf("PARTICIPANT") >-1 ) {
		return true;
	}
}

function isNonMember(usr) {





	if 	( usr.indexOf("NON-MEMBER") >-1 ) {
		return true;
	}
}

