if(top.location!= document.location) top.location = document.location;

function dropdownSelect(dropdown){
	for (i=0;i<dropdown.options.length;i++){
	
		if (dropdown.options[i].selected){

			if (dropdown.options[i].value != ''){
			
				if (dropdown.options[i].value.substring(0,4) == 'http'){
					location.href = dropdown.options[i].value;
				}else{
					location.href = 'http://www.themorningnews.org' + dropdown.options[i].value;
				}
			}
			
		}
	} 
}


function showEmailArticleForm(articleId,articleUrl){
	document.getElementById("emailArticleForm").innerHTML= '<form method="post" action="http://www.themorningnews.org/cgi-bin/mt-send-entry.cgi" ><div><input type="hidden" name="entry_id" value="' + articleId + '" /><input type="hidden" name="_redirect" value="' + articleUrl + '" /><p><input type="text" name="to" value="Recipient\'s Email Address"  onfocus="this.value=\'\';" /></p><p><input type="text" name="from" value="Your Email Address"  onfocus="this.value=\'\';" /></p><p><textarea onfocus="this.value=\'\';" name="message" rows="10" cols="18" >Message (Optional)</textarea></p><p><input type="submit" name="submit" value="Send" class="sendButton" />&nbsp;&nbsp;<input type="button" name="Cancel" value="Cancel"  onclick="hideEmailArticleForm();" class="sendButton" /></p></div></form>';
}


function hideEmailArticleForm(){
	document.getElementById("emailArticleForm").innerHTML= '&#187; <a href="javascript:showEmailArticleForm(articleId,articleUrl);">Email this article</a>';
}


function showDigestEmailArticleForm(articleId,articleUrl){
	document.getElementById("emailArticleForm").innerHTML= '<form method="post" action="http://www.themorningnews.org/cgi-bin/mt-send-entry.cgi" ><div><input type="hidden" name="entry_id" value="' + articleId + '" /><input type="hidden" name="_redirect" value="' + articleUrl + '" /><input type="text" name="to" value="Recipient\'s Email Address"  onfocus="this.value=\'\';" /></p><input type="text" name="from" value="Your Email Address"  onfocus="this.value=\'\';" /></p><input type="submit" name="submit" value="Send" class="sendButton" />&nbsp;&nbsp;<input type="button" name="Cancel" value="Cancel"  onclick="hideDigestEmailArticleForm();" class="sendButton" /></p></div></form>';
}

function hideDigestEmailArticleForm(articleId,articleUrl){
	document.getElementById("emailArticleForm").innerHTML= '&#187; <a href="javascript:showDigestEmailArticleForm(articleId,articleUrl);">Email this article</a>';
}

function emailArticle(entry_id,url,title){

	window.open('/emailArticle.php?entry_id=' + entry_id + '&url=' + url + '&title=' + title,'emailArticle','width=600,height=600,bookmarksbar=no,addressbar=no,statusbar=yes,scrollbar=no');

}














// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") +
        (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    now = now.toGMTString();
    if (f.author != undefined)
       setCookie('mtcmtauth', f.author.value, now, '/', '', '');
    if (f.email != undefined)
       setCookie('mtcmtmail', f.email.value, now, '/', '', '');
    if (f.url != undefined)
       setCookie('mtcmthome', f.url.value, now, '/', '', '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '/', '');
    deleteCookie('mtcmthome', '/', '');
    deleteCookie('mtcmtauth', '/', '');
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}

function hideDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'none';
}

function showDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'block';
}

var commenter_name;

function individualArchivesOnLoad(commenter_name) {

    hideDocumentElement('trackbacks-info');



    if (document.comments_form) {
        if (document.comments_form.email != undefined &&
            (mtcmtmail = getCookie("mtcmtmail")))
            document.comments_form.email.value = mtcmtmail;
        if (document.comments_form.author != undefined &&
            (mtcmtauth = getCookie("mtcmtauth")))
            document.comments_form.author.value = mtcmtauth;
        if (document.comments_form.url != undefined && 
            (mtcmthome = getCookie("mtcmthome")))
            document.comments_form.url.value = mtcmthome;
        if (mtcmtauth || mtcmthome) {
            document.comments_form.bakecookie.checked = true;
        } else {
            document.comments_form.bakecookie.checked = false;
        }
    }
}

function writeTypeKeyGreeting(commenter_name, entry_id) {

}

 function alphabetizeAuthors() { 
  // Sort ALL select elements 
    var oArr = []; 
    // Get the options for the select element 
    for (var j = 0; j < document.getElementById('tmnAuthors').options.length; j++) { 
      // Store this as an object that has an option object member, and 
      // a toString function (which will be used for sorting) 
      oArr[oArr.length] = { 
        option : document.getElementById('tmnAuthors').options[j], 
        toString : function() { 
          // Return the text of the option, not the value 
          return this.option.text; 
        } 
      } 
    }
    // Sort the array of options for this select 
    oArr.sort(); 
    // Remove all options from the select 
    document.getElementById('tmnAuthors').options.length = 0; 
    // Rebuild the select using our sorted array 
    for (var j = 0; j < oArr.length; j++) { 
      document.getElementById('tmnAuthors').options[j] = oArr[j].option; 
    } 
  
}
	

function showDigest(digest){
	hideAllDigestBlurbs();
	document.getElementById('blurb' + digest).style.display = 'block';
	document.getElementById('digestLink' + digest).className = 'highlighted';
}

function hideAllDigestBlurbs(){
	document.getElementById('blurb1').style.display= 'none';
	document.getElementById('blurb2').style.display = 'none';
	document.getElementById('blurb3').style.display = 'none';
	document.getElementById('digestLink1').className = '';
	document.getElementById('digestLink2').className = '';
	document.getElementById('digestLink3').className = '';

}


function showCurrentDigest(){
if (document.getElementById('digestLink1')){
	for (i=1;i<4;i++){
	
		if (document.getElementById('digestLink' + i).className == 'highlighted'){
			document.getElementById('blurb' + i).style.display= 'block';
		}
	}
}
}

function onloadFunctions(){
	alphabetizeAuthors();
	showCurrentDigest();
}

window.onload = onloadFunctions;


