﻿// The Roanoke Times global JavaScript
// Updated 1/30/07

// insertAfter function
// This function operates similar to insertBefore except it allows you to insert content AFTER a given element
function insertAfter(newElement,targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}

// addLoadEvent
// Use this function to load multiple functions when the document loads (it will not overwrite the window.onload event): addLoadEvent(FUNCTION);
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
	window.onload = func;
	} else {
		window.onload = function() {
		oldonload();
		func();
		}
	}
}

/* custom pop-up window function (use for custom-size popup windows) */
function makeLarge(url, wPx, hPx) {
	newWin=window.open(url, "popup", "width=" + wPx + ",height=" + hPx + ",top=50,left=50,scrollbars,resizable");
	newWin.focus();
}

/* Ad Control */
function adControl(h) {
//        if (h < 705) document.getElementById("featured-jobs").style.display='none';
//        if (h < 460) document.getElementById("ad-google").style.display='none';
}

/* popUp script
Developer: Patrick Beeson
Created: 08/29/06
*/

// Soundslides popup function
function soundslideOpen (winURL) {
	window.open(winURL,"soundslide_popup","width=740,height=670");
}

// Photogallery popup function
function photogalleryOpen (winURL) {
	window.open(winURL,"photogallery_popup","width=755,height=800");
}

// Smith Mountain Lake Webcam popup function (not functioning)
/* function lakewebcamOpen (winURL) {
	window.open(winURL, "lakewebcam_popup","width=675,height=500");
}*/

// Contact online form popup function
function contactonlineOpen (winURL) {
	window.open(winURL, "contactonline_popup","width=500,height=400");
}

// Poll popup function
function pollOpen (winURL) {
	window.open(winURL, "poll_popup","width=400,height=450");
}

// Off the scale popup function
function obesityOpen (winURL) {
	window.open(winURL, "obesity_popup","width=1152,height=864,scrollbars");
}

// Actual popup function
function popUp() {
	if (!document.getElementsByTagName) return false;
	var lnks = document.getElementsByTagName("a");
	for (var i=0; i<lnks.length; i++) {
		if (lnks[i].className == "soundslide_popup") {
			lnks[i].onclick = function() {
				soundslideOpen(this.getAttribute("href"));
				return false;
			}
		}
		else if (lnks[i].className == "photogallery_popup") {
				lnks[i].onclick = function() {
				photogalleryOpen(this.getAttribute("href"));
				return false;
			}
		}
		/* else if (lnks[i].className == "lakewebcam_popup") {
				lnks[i].onclick = function() {
				lakewebcamOpen(this.getAttribute("href"));
				return false;
			}
		} */
		else if (lnks[i].className == "contactonline_popup") {
				lnks[i].onclick = function() {
				contactonlineOpen(this.getAttribute("href"));
				return false;
			}
		}
		else if (lnks[i].className == "poll_popup") {
				lnks[i].onclick = function() {
				pollOpen(this.getAttribute("href"));
				return false;
			}
		}
		else if (lnks[i].className == "obesity_popup") {
				lnks[i].onclick = function() {
				obesityOpen(this.getAttribute("href"));
				return false;
			}
		}	
	}
}

// Overlay function
//function hideDiv() {
//    document.getElementById('overLay').style.visibility = 'hidden';
//}

// Date function

var months = new Array(12);
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";

var weekDays = new Array(7);
weekDays[0] = "Sunday";
weekDays[1] = "Monday";
weekDays[2] = "Tuesday";
weekDays[3] = "Wednesday";
weekDays[4] = "Thursday";
weekDays[5] = "Friday";
weekDays[6] = "Saturday";

var dteBase = new Date();
var monthName = months[dteBase.getMonth()];
var weekDay = weekDays[dteBase.getDay()];
var date = dteBase.getDate();
var year = dteBase.getYear();

if (year < 2000) year = year + 1900; // Y2K Fix, Isaac Powell http://onyx.idbsu.edu/~ipowell

var formatDate = weekDay + ', ' + monthName + ' ' + date + ', ' + year;

function getFormattedDate() {
    return formatDate;
}

// This function gets the current year, and applies it to the copyright
// Author: Patrick Beeson
// Last modified 1/24/07

function copyrightDate() {
	// Test for the browsers' interpretation of the DOM
	if (!document.getElementById) return false;
	if (!document.getElementById("sitetools")) return false;
	// Create <p> element to display the text and year
	var copyright = document.createElement("p");
	copyright.setAttribute("id","copyright");
	// Write in the HTML and the year from the date function
	copyright.innerHTML = "Copyright &copy;" + " " + year;
	var tools = document.getElementById("sitetools");
	// Test for the gateway via the Real Cities logo (if not found, append to the sitetools <div>)
	if (document.getElementById("real-city")) {
		var realcities = document.getElementById("real-city");
		tools.insertBefore(copyright,realcities);
	} else {
		tools.appendChild(copyright);
	}
}

//this function is to clear the value data on the search box in the mast when a user clicks on it
//author: mary-chris hirsch
//created: 7/17/08

function ClearInput(value, id){ // This calls our function ClearInput, and the two variables we will need for it to function the original value and the id.
    var input = document.getElementById(id); // Gets the input field based on its id.

    if(value == input.value){ // If the default value is equal to the current value.
    input.value = ''; // Empty It.
    }else{ // Else the value is not equal to the current input field value.
    input.value = input.value; // Leave it the same.
    } // End Else.
    } // Close Function.


//Classifed Widget
//create 12/16/08 by Mary-Chris Hirsch
function setClassifiedFocus(b){
    var bxs=['homes','cars','jobs'];
    for (var i=0;i<bxs.length;i++) {
        var bx=document.getElementById('side-tab-'+bxs[i]);
        var lk=document.getElementById(bxs[i]+'-lnk');
        if (b==bxs[i]){
            bx.style.display='block';
            lk.className='current';
         }else{
            bx.style.display='none';
            lk.className='';
        }
    }
}