//AddThis variables need to be set globally
var addthis_pub="jbartonastm";
var addthis_brand = "ASTM";
var addthis_disable_flash = true;

window.addEventListener?window.addEventListener("load",init,false):window.attachEvent("onload",init);

function init(){
    var wherearewe = document.location.href;
    if(!document.gs){ return; }
    else { 
	if(wherearewe.indexOf('SNEWS') > -1 || wherearewe.indexOf('MAGS_NEWSLETTERS') > -1){ return(false); }
	else { SearchFocus(); }
    }
}

function SearchFocus(){
    document.gs.query.focus();
}


//Draw the left navigation bar
//Takes one argument, which can be used to customize navigation for different pages
function DrawNavBar(special) 
{
    document.write("<div id=\"main_navigation\">" +
		   "<div id=\"home\"><h1 id=\"astm_logo\"><a title=\"ASTM International - Standards Worldwide\" href=\"/index.shtml\">ASTM International - Standards Worldwide</a></h1></div>" +
		   "<ul><li><a href=\"/Standard/index.shtml\" title=\"Standards\">Standards</a>");
    
    if(special == 'standards')
    {
	document.write("<ul><li><a href=\"/Standard/index.shtml\" title=\"Search Standards\">Search Standards</a></li>" +
		       "<li><a href=\"/BOOKSTORE/BOS/index.html\" title=\"Annual Book of Standards\">Annual Book of Standards</a></li>" +
		       "<li><a href=\"/DEMO/index.shtml\" title=\"Online Subscriptions\">Online Subscriptions</a></li>" +
		       "<li><a href=\"/DEMO/collections.htm\" title=\"Collections on DVD\">Collections on DVD</a></li>" +
		       "<li><a href=\"/BOOKSTORE/COMPS/compsbycategory.htm\" title=\"Compilations\">Compilations</a></li>" +
		       "<li><a href=\"/Standards/category_index.html\" title=\"By Category\">By Category</a></li>" +
		       "<li><a href=\"/STORE/alert.html\" title=\"Track Standards\">Track Standards</a></li>" +
		       "<li><a href=\"/COPYRIGHT/\" title=\"Copyright/Permissions\">Copyright/Permissions</a></li>" +
		       "<li><a href=\"http://www.astmproducts.com/custom_collection.html\" title=\"Corporate Portals\">Corporate Portals</a></li>" +
		       "<li><a href=\"/IMAGES03/corr_list.doc\" title=\"Corrections\">Corrections</a></li></ul>");
    }
    
    document.write("</li><li><a href=\"/DIGITAL_LIBRARY/index.shtml\" title=\"Standards and Engineering Digital Library\">Standards and Engineering Digital Library</a></li>" +
		   "<li><a href=\"/Standard/books_journals.shtml\" title=\"Books & Journals\">Books &amp; Journals</a></li>" +   
		   "<li><a href=\"/COMMIT/newcommit.html\" title=\"Technical Committees\">Technical Committees</a></li>" +
		   "<li><a href=\"/MEMBERSHIP/index.html\" title=\"Membership\">Membership</a></li>" +
		   "<li><a href=\"/MEETINGS/index.html\" title=\"Meetings\">Meetings</a>");

    if(special == 'meeting')
    {
	document.write("<ul><li><a href=\"/MEETINGS/directions.htm\" title=\"Directions to ASTM\">Directions to ASTM</a></li>" +
		       "<li><a href=\"/MEETINGS/hotels.htm\" title=\"Hotels near ASTM\">Hotels near ASTM</a></li></ul>");	
    }

    document.write("</li><li><a href=\"/SYMPOSIA/index.html\" title=\"Symposia and Workshops\">Symposia &amp; Workshops</a></li>" +
		   "<li><a href=\"/TRAIN/index.html\" title=\"Training Courses\">Training Courses</a>");

    if(special == 'train') 
    {
	document.write("<ul><li><a href=\"/TRAIN/courses.html\" title=\"Course Listing\">Course Listing</a></li>" +
		       "<li><a href=\"/TRAIN/onsite.html\" title=\"On Site Training\">On Site Training</a></li>" +
		       "<li><a href=\"/TRAIN/international.html\" title=\"International Training\">International Training</a></li>" +
		       "<li><a href=\"/TRAIN/pecontinuing.html\" title=\"PE Continuing Education\">PE Continuing Education</a></li></ul>");
    }

    document.write("</li><li><a href=\"/STATQA/index.html\" title=\"Proficiency Testing\">Proficiency Testing</a></li>" +
		   "<li><a href=\"/CERTIFICATION/\" title=\"Certification Program\">Certification Program</a></li>" +
		   "<li><a href=\"/LABS/index.html\" title=\"Lab Directory\">Lab Directory</a></li>" +
		   "<li><a href=\"/CONSULTANTS/index.html\" title=\"Consultants Directory\">Consultants Directory</a></li>" +
		   "<li><a href=\"/ABOUT/aboutASTM.html\" title=\"About ASTM\">About ASTM</a>");

    if(special == 'about')
    {
	document.write("<ul><li><a href=\"/ABOUT/index.html\" title=\"Overview\">Overview</a></li>" +
		       "<li><a href=\"/NEWS/Mission2.html\" title=\"Mission Statement\">Mission Statement</a></li>" +
		       "<li><a href=\"/ABOUT/faqs.html\" title=\"FAQs\">FAQ's</a></li>" +
		       "<li><a href=\"http://www.nxtbook.com/nxtbooks/astm/annualreport2010/index.php\" title=\"Annual Report\">Annual Report</a></li>" +
		       "<li><a href=\"/PRESIDENT/lead_index.html\" title=\"Presidents Column\">President's Column</a></li>" +
		       "<li><a href=\"/ABOUT/history_book.html\" title=\"History\">History</a></li>" +
		       "<li><a href=\"/ABOUT/milestones.html\" title=\"Milestones\">Milestones</a></li></ul>");
    }

    document.write("</li><li><a href=\"/MAGS_NEWSLETTERS/index.html\" title=\"Magazine & Newsletters\">Magazine &amp; Newsletters</a></li>" +
		   "<li><a href=\"http://astmnewsroom.org/newsrelease.aspx\" rel=\"nofollow\" title=\"News Releases\">News Releases</a></li>" +
		   "<li><a href=\"/studentmember/index.html\" title=\"Students & Professors\">Students &amp; Professors</a></li>" +
		   "<li><a href=\"/GLOBAL/index.html\" title=\"Global Cooperation\">Global Cooperation</a></li></ul>");
    
    document.write("<h4>Product Information</h4>" +
		   "<ul><li><a href=\"/marketing_mail/index.html\" title=\"Get Product Updates\">Get Product Updates</a></li>" +
		   "<li><a href=\"/CATALOG_REQUEST/index.html\" title=\"Request a Free Catalog\">Request a Free Catalog</a></li>" +
		   "<li><a href=\"/catalog.html\" title=\"View Catalog\">View Catalog</a></li></ul>");
    
    if(special == 'publish')
    {
	document.write("<h4><a href=\"/PUBLISH/index.html\" title=\"Publish With ASTM\">Publish With ASTM</a></h4>");
    }

    if(special == 'digiLib')
    {
	document.write("<h4>Publish With ASTM</h4>" +
		       "<ul><li><a class=\"bluelinkline_smaller\" href=\"/DIGITAL_LIBRARY/JOURNALS/jrnls.htm\" title=\"Journals\">Journals</a></ul>");
    }

    if(special == 'snews')
    {
	document.write("<img src=\"/IMAGES03/SN_3lang.gif\" height=\"110\" width=\"140\" border=0 USEMAP=#TRILANG><MAP NAME=TRILANG>" +
		       "<AREA SHAPE=rect HREF=/SNEWS/index.html COORDS=\"9,39 123,57\"><AREA SHAPE=rect HREF=/SNEWS/SPANISH/index.html COORDS=\"3,59 140,91\"><AREA SHAPE=rect HREF=/SNEWS/CHINESE/index.html COORDS=\"0,92 147,116\"></MAP>" +
		       "<form name=\"snews-search-1\" method=\"GET\" action=\"/search/site-search.html\" >" +
			"<input type=\"hidden\" name=\"maincat\" value=\"snews\">" +
			"<table width=\"150\">" +
			"<tr><td><span style=\"font-size: 0.8em;\">Standardization News Search</span></td></tr>" +
			"<tr>" +
			"<td width=\"140\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" +
			"<td width=\"140\"> <input type=\"text\" name=\"query\" maxlength=\"100\" size=\"12\" > " +
			"</td>" +
			"<td> <div align=\"right\"><input type=\"image\" value=\"Submit\" src=\"/IMAGES03/go.gif\" border=\"0\" width=\"26\" height=\"16\" alt=\"GO\" title=\"GO\"></div></td></tr>" +
			"</form>" +
			"</table><br />" +
			"</table>");
	
    }
    
    document.write("<a href=\"/RSS/index.html\" title=\"RSS\"><img src=\"/IMAGES03/rss.jpg\" alt=\"RSS\"border=\"0\"></a>" +
		   "<br /><img src=\"/IMAGES03/verisign.jpg\" alt=\"Verisign\"></div>");
}



//Draw header
//Also takes one argument for customization
function DrawHeader(special) 
{
    
    document.write("<div id=\"wordwheel\"></div>" +
		   "<div id=\"mainContent_new\" class=\"group_nav\"><div class=\"group_nav\"><ul class=\"secNav_new\"><li><a href=\"/translations.html\" title=\"Other Languages\">Other Languages</a></li></ul></div>" +
		   "<div id=\"header_new\" class=\"group_nav\">" +
		   "<div class=\"group_nav\"><ul class=\"secNav_new\">");
    
    if(special == 'logout') document.write("<li id=\"loginItem\"><a href=\"http://myastm.astm.org/CUSTOMERS/logout.cgi\" title=\"Login\" class=\"login\">Logout</a></li>");
    else document.write("<li id=\"loginItem\"><a href=\"http://myastm.astm.org/CUSTOMERS/checkpassword_landing_page.cgi\" title=\"Login\" class=\"login\">Login</a></li>");
    
    document.write("<li><a href=\"/index.shtml\" title=\"Home\">Home</a></li>" +
		   "<li><a href=\"/ABOUT/aboutASTM.html\" title=\"About ASTM\">About ASTM</a></li>" +
		   "<li><a href=\"/SITEMAP/index.html\" title=\"Site Map\">Site Map</a></li>" +
		   "<li><a href=\"/SUPPORT/index.html\" title=\"Support\">Support</a></li>" +
		   "<li><a href=\"/CONTACT/index.html\" title=\"Contact\">Contact</a></li>" +
		   "<li><a href=\"/prpolicy.html\" title=\"Web/IP Policies\">Web/IP Policies</a></li>" +
		   "<li><a href=\"/COPYRIGHT/\" title=\"Copyright/Permissions\">Copyright/Permissions</a></li>" +
		   "</ul></div>" +
		   "<div class=\"cart_search group_nav\"><ul>" +
		   "<li class=\"search\"><form name=\"gs\" method=\"GET\" action=\"/search/site-search.html\" >" +
		   "<input type=\"text\" name=\"query\" size=\"40\" id=\"searchField\" autocomplete=\"off\" >" +
		   "<input type=\"hidden\" name=\"cartname\" value=\"mystore\">" +
		   "<input type=\"submit\" value=\"Search\" id=\"searchBtn\">" +
		   "</form></li>" +
		   "<li class=\"cart\"><a id=\"spr_cart\" href=\"/STORE/showcart.html\" title=\"View Shopping Cart\"><img src=\"/IMAGES03/shopping_button.gif\" width=\"144\" height=\"21\" alt=\"View Shopping Cart\" /></a></li>" +
		   "</ul></div></div></div>" +
		   "<br style=\"clear:both;\" />");

    //once the search form exists, setup wordwheel events
    addEvent(document.getElementById('searchField'), "keyup", 
	     function (evt)
	     {
		 evt = (evt) ? evt : ((window.event) ? window.event : "");
		 if (evt)
		 {
		     if(evt.keyCode == 38)
		     {
			 //up arrow
			 if(wwIndex > 0)
			 {
			     wwIndex--;
			     wordwheel_highlight();
			 }
		     }

		     else if(evt.keyCode == 40)
		     {
			 //down arrow
			 if(wwIndex < document.getElementById('wordwheel').childNodes.length - 1)
			 {
			     wwIndex++;
			     wordwheel_highlight();
			 }
		     }

		     else
		     {
			 var val = evt.target ? evt.target.value : evt.srcElement.value;
			 val = val.replace(/\"|\'/g, '');
		     
			 lastKeystroke = new Date();
			 setTimeout('wordwheel_request("' + val + '");', WWTIMEOUT);
		     }
		 }
	     }
	    );
    
    //hide wordwheel if the user clicks outside of it
    addEvent(document.body, "click", 
	     function() 
	     {  
		 document.getElementById('wordwheel').style.display = 'none'; 
	     }
	    );
    
}





function DrawDigiLib(special) 
{
    document.write("<div><img src=\"/IMAGES03/dl_tech_banner.jpg\" /></div>" +
		   "<div id=\"dl_tabs_sm\" class=\"dl_sm_hl_" + special +"\">" +
		   
		   "<div class=\"dl_wrap\" id=\"dl_wrap_home\"><a id=\"dl_tab_home\" href=\"/DIGITAL_LIBRARY/index.shtml\"></a></div>" +
		   "<div class=\"dl_wrap\" id=\"dl_wrap_mystan\"><a id=\"dl_tab_mystan\" href=\"/Standard/index.shtml?complete\"></a></div>" +
		   "<div class=\"dl_wrap\" id=\"dl_wrap_journals\"><a id=\"dl_tab_journals\" href=\"/DIGITAL_LIBRARY/JOURNALS/index.htm\"></a></div>" +
		   "<div class=\"dl_wrap\" id=\"dl_wrap_stps\"><a id=\"dl_tab_stps\" href=\"/DIGITAL_LIBRARY/STP/stp_toclist.htm\"></a></div>" +
		   "<div class=\"dl_wrap\" id=\"dl_wrap_mnls\"><a id=\"dl_tab_mnls\" href=\"/DIGITAL_LIBRARY/MNL/mnl_toclist.htm\"></a></div>" +
		   "<div class=\"dl_wrap\" id=\"dl_wrap_ebooks\"><a id=\"dl_tab_ebooks\" href=\"/DIGITAL_LIBRARY/EBOOK\"></a></div>" +
		   "<div class=\"dl_wrap\" id=\"dl_wrap_subs\"><a id=\"dl_tab_subs\" href=\"/DIGITAL_LIBRARY/SUBSCRIPTIONS/index.html\"></a></div>" +
		   
		   "<div id=\"end_shadow\"></div><div style=\"clear:both;\"></div></div>");
}


//Wordwheel Stuff
var lastKeystroke = new Date();
var WWTIMEOUT = 300;
var WWSEQ = 0;
var wwIndex = -1;

//toss a coin here to determine which server
var DOMAIN = "maxxcat.astm.org";
if(Math.floor(Math.random() * 2) == 1) DOMAIN = "maxxcat2.astm.org";

function wordwheel_request(q, force)
{
    var timeDiff =  WWTIMEOUT - 50;
    var now = new Date();
    
    q = q.replace(/^\s+/g, '').replace(/\s+$/, '');
    q = q.replace(/ /g, '+');

    if(!q.match(/\w\w\w/)) return;

    if((now - lastKeystroke > timeDiff) || force)
    {
	WWSEQ++;
	var head = document.getElementsByTagName('head')[0];
	var script = document.createElement("script");    
	var url = "http://" + DOMAIN + "/TypeAhead.cgi?"  + q + "&collection=COLID7&seqID=" + WWSEQ;
	script.setAttribute("src",url);
	script.setAttribute("type","text/javascript");
	head.appendChild(script);
    }
}

function wordwheel_callback(seq, d)
{
    if(seq == WWSEQ)
    {
	var resHTML = '';
	
	for(var i = 0; i < d.length; i++)
	{
	    resHTML += '<a class="ww_item" onclick="wordwheel_select(\'' + d[i].query + '\');">' + d[i].query + '</a>';
	}
	
	if(d.length > 0)
	{
	    document.getElementById('wordwheel').innerHTML = resHTML;
	    document.getElementById('wordwheel').style.display = 'block';
	    wwIndex = -1;
	    wordwheel_highlight();
	}
    }
}

function wordwheel_select(q)
{
    document.getElementById('searchField').value = q;
    document.getElementById('wordwheel').style.display = 'none';
    document.gs.submit();
}

function wordwheel_highlight()
{
    if(wwIndex >= 0)
    {
	var wwNodes = document.getElementById('wordwheel').childNodes;
	for(var i = 0; i < wwNodes.length; i++)
	{
	    wwNodes[i].className = "";
	    if(i == wwIndex)
	    {
		wwNodes[i].className = "ww_highlighted";
		document.getElementById('searchField').value = wwNodes[i].innerHTML;
	    }
	}
    }
}
