


function showEmailForm(){
	document.getElementById('contentHolder').innerHTML = document.getElementById('articleTools').innerHTML;

	document.getElementById('articleTools').innerHTML = document.getElementById('emailArticleForm').innerHTML
}

function hideEmailForm(){
	document.getElementById('articleTools').innerHTML = document.getElementById('contentHolder').innerHTML;
}



var timer;
function createTimer(timer){
timer = setTimeout('hideAll()',1000);
}


function showArchivesNav(){

	clearTimeout(timer);
	
	hideAll();
	document.getElementById('archivesNav').style.visibility = 'visible';
}


function showSubNav1(){

	clearTimeout(timer);
	
	hideSubNavs();
	document.getElementById('archivesSubNav1').style.visibility = 'visible';
}

function showSubNav2(){

	clearTimeout(timer);
	
	hideSubNavs();
	document.getElementById('archivesSubNav2').style.visibility = 'visible';
}


function showSubNav3(){

	clearTimeout(timer);
	hideSubNavs();
	document.getElementById('archivesSubNav3').style.visibility = 'visible';
}


function showSubNav4(){

	clearTimeout(timer);
	
	hideSubNavs();
	document.getElementById('archivesSubNav4').style.visibility = 'visible';
}




function showAboutNav(){
	clearTimeout(timer);
	hideAll();
	document.getElementById('aboutNav').style.visibility = 'visible';
}

function showMediaCentreNav(){
	clearTimeout(timer);
	hideAll();
	document.getElementById('mediaCentreNav').style.visibility = 'visible';
}

function showCategoryNav(){

	clearTimeout(timer);
	
	hideSubNavs();
	document.getElementById('categoryNav').style.visibility = 'visible';
}


function showCustomerCareNav(){

	clearTimeout(timer);
	
	hideAll();
	document.getElementById('customerCareNav').style.visibility = 'visible';
}

function hideAll(){

	document.getElementById('archivesNav').style.visibility = 'hidden';
	document.getElementById('archivesSubNav1').style.visibility = 'hidden';
	document.getElementById('archivesSubNav2').style.visibility = 'hidden';
	document.getElementById('archivesSubNav3').style.visibility = 'hidden';
	document.getElementById('archivesSubNav4').style.visibility = 'hidden';
	document.getElementById('aboutNav').style.visibility = 'hidden';
	document.getElementById('mediaCentreNav').style.visibility = 'hidden';
	document.getElementById('categoryNav').style.visibility = 'hidden';
	document.getElementById('customerCareNav').style.visibility = 'hidden';
}

function hideSubNavs(){

	document.getElementById('archivesSubNav1').style.visibility = 'hidden';
	document.getElementById('archivesSubNav2').style.visibility = 'hidden';
	document.getElementById('archivesSubNav3').style.visibility = 'hidden';
	document.getElementById('archivesSubNav4').style.visibility = 'hidden';
	document.getElementById('categoryNav').style.visibility = 'hidden';
}



function setTimer(){

	timer = setTimeout('hideAll()',1000);
	
}

var page;
function sidebarPop(page){
window.open(page,'pop','width=300,height=600,scrollbars=auto,bookmarksbar=no,addressbar=no,statusbar=no');
}


function getAdjustment(){
	var adjusted;
	var browswidth;

	if (document.layers){
		browswidth = windows.innerwidth;
	} else {
		browswidth = document.body.offsetWidth;
	}

	adjusted=(browswidth-800)/2;
	return adjusted;
}


function setMenuPosition(){
	var adjusted = getAdjustment();
	var mac = false;
	if (adjusted > 0){
	if (navigator.userAgent.search('Macintosh') != -1){
		mac = true;
	}
	

		if (document.layers){
			eval(layerRef + '["aboutNav"]' + styleSwitch + '.left=' + adjusted+45);
			eval(layerRef + '["archivesNav"]' + styleSwitch + '.left=' + adjusted+180);
			eval(layerRef + '["archivesSubNav1"]' + styleSwitch + '.left=' + adjusted+379);
			eval(layerRef + '["archivesSubNav2"]' + styleSwitch + '.left=' + adjusted+379);
			eval(layerRef + '["archivesSubNav3"]' + styleSwitch + '.left=' + adjusted+379);
			eval(layerRef + '["archivesSubNav4"]' + styleSwitch + '.left=' + adjusted+379);
			eval(layerRef + '["categoryNav"]' + styleSwitch + '.left=' + adjusted+379);
			eval(layerRef + '["mediaCentreNav"]' + styleSwitch + '.left=' + adjusted+663);
			eval(layerRef + '["customerCareNav"]' + styleSwitch + '.left=' + adjusted+333);
	
		}else{
	
			
			document.getElementById('aboutNav').style.left=adjusted+57+ 'px';
			document.getElementById('archivesNav').style.left=adjusted+180+ 'px';
			document.getElementById('archivesSubNav1').style.left=adjusted+378+ 'px';
			document.getElementById('archivesSubNav2').style.left=adjusted+378+ 'px';
			document.getElementById('archivesSubNav3').style.left=adjusted+378+ 'px';
			document.getElementById('archivesSubNav4').style.left=adjusted+378+ 'px';
			document.getElementById('categoryNav').style.left=adjusted+378+ 'px';
			document.getElementById('mediaCentreNav').style.left=adjusted+640+ 'px';
			document.getElementById('customerCareNav').style.left=adjusted+335+ 'px';
		
		}
	} 
	

	
}





var req;
function loadXMLDoc(url) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {

			req.onreadystatechange = processReqChange;
		
		
		req.open("POST", url, true);
		req.send("");
	}
	

}
function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...

            var xmldoc = req.responseXML;
            document.getElementById('poll').innerHTML = xmldoc.getElementsByTagName('pollForm').item(0).childNodes.item(0).data;
            
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }


    
}



function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}



function submitPoll(articleId){
	for (var i=0; i<document.pollForm.vote.length; i++) {
		if (document.pollForm.vote[i].checked) {
			voteValue = document.pollForm.vote[i].value;
		}
	}

	if (voteValue){
		loadXMLDoc('http://www.walrusmagazine.com/include/poll/showPollResults.php?mode=inline&vote=' + voteValue + '&articleId=' + articleId);
		setCookie(articleId + 'poll' ,'true',1000);
	}
}


function showPollResults(articleId){
	loadXMLDoc('http://www.walrusmagazine.com/include/poll/showPollResults.php?mode=inline&articleId=' + articleId);
}


function replaceLineBreaks (ta) {
  return ta.replace(/\r\n|\r|\n/g, '<br />');
}

	
function previewComment(){
	document.getElementById('commentPreview').style.display = 'block';
	document.getElementById('commentPreview').innerHTML = '<h3>Comment Preview<\/h3>' + replaceLineBreaks(document.getElementById('commentText').value) + '<p><input type="submit" name="commentSubmit" id="commentSubmit" value="Post" /><\/p>';
	document.getElementById('commentSubmit').disabled = false;
}
	
function disablePost(){
	
	document.getElementById('commentSubmit').disabled = true;
	
}

function init(){
	setMenuPosition();
	createTimer(timer);
}

window.onload=init;

window.onresize= setMenuPosition;



