
//Top Story content cycling
/*
// globalize variables
var contentCycleInterval;

// Content Cycling Variables
var cycleDelay = 4000;			// timeInMilliseconds
var currentContentPiece = 1;	// defaults to first one
var maxNumContentPieces;	// max number of content/stories

// Preload Images
// auto-cycle controls
previousImage = new Image(18,18);	previousImage.src = "http://a.abclocal.go.com/graphics/v3/global/controlsPrev.gif";
nextImage = new Image(18,18);		nextImage.src = "http://a.abclocal.go.com/graphics/v3/global/controlsNext.gif";
playImage = new Image(18,18);		playImage.src = "http://a.abclocal.go.com/graphics/v3/global/controlsPlay.gif";
pauseImage = new Image(18,18);		pauseImage.src = "http://a.abclocal.go.com/graphics/v3/global/controlsPause.gif";

var moduleName = "topStories";
var contentCycleInterval;
var pauseValue = 0;
*/
// Content Cycling Functions
function adjacentContent(nearContentLoc)
{ /* return values for content ID for prev/next */
	if ( nearContentLoc == "prev" )
	{ // previous content
		decrementContentPieces();
	} else if ( nearContentLoc == "next" )
	{ // next content
		incrementContentPieces();
	} // end if
	return currentContentPiece;
} // end function
/*
function autoCycleContent(currentContentPiece)
{ 
	// call auto-cycle function with delay
	contentCycleInterval = window.setInterval('cycleContent(moduleName, currentContentPiece)', cycleDelay);
} // end function
*/
function autoCycleContent(currentContentPiece)
{ /* calls the auto cycle function with the delay */
	// call auto-cycle function with delay
	if (initialPauseValue == 0)
	{ // default to auto cycle
		contentCycleInterval = window.setInterval('cycleContent(moduleName, currentContentPiece)', cycleDelay);
	} else
	{ // defalut to pause
		pauseCycleContent('topStories', 'perm');
		initialPauseValue = 0;
	} // end if
} // end function

function cycleContent(moduleName, currentContentPiece)
{ /* auto-cycles the content */
	// increment content piece
	currentContentPiece = incrementContentPieces();
	// hide all content
	for( i = 1; i <= maxNumContentPieces; i++ ) {
		document.getElementById("story" + i).style.display = 'none';
	} // end for
	// display current content
	document.getElementById("story" + currentContentPiece).style.display = 'block';
	decorateControls();
} // end function

function pauseCycleContent(moduleName, pauseType)
{ /* toggles pausing the auto-cyle */
	if ( pauseType == "temp" )
	{ // specific content selected
		window.clearInterval(contentCycleInterval);
		pauseValue = 1;
		document.getElementById("pauseImage").src = pauseImage.src;
	} else
	{ // pause button selected
		if ( pauseValue == 0 )
		{ // not currently paused
			// pause auto-cycle
			window.clearInterval(contentCycleInterval);
			pauseValue = 1;
			document.getElementById("pauseImage").src = playImage.src;
		} else
		{ // currently paused
			// resume auto-cycle
			autoCycleContent(moduleName, currentContentPiece);
			document.getElementById("pauseImage").src = pauseImage.src;
			pauseValue = 0;
		} // end if
	} // end if
} // end function

function selectContent(moduleName, storyID)
{ /* displays the content selected and hides the rest */
	if (( storyID == "prev" ) || ( storyID == "next" ))
	{ // previous or next is selected
		storyID =  adjacentContent(storyID);
	} // end if
	for( i = 1; i <= maxNumContentPieces; i++ )
	{ // hide all content
		document.getElementById("story" + i).style.display = 'none';
	} // end for
	// display selected content
	document.getElementById("story" + storyID).style.display = 'block';
	// pause auto cycle
	pauseCycleContent(moduleName, "temp");
	document.getElementById("pauseImage").src = playImage.src;
	currentContentPiece = storyID;
	decorateControls();
} // end function

function selectWeatherContent(moduleName, storyID)
{ /* displays the content selected and hides the rest */
	for( i = 1; i <= maxNumContentPieces; i++ )
	{ // hide all content
		document.getElementById("weatherStory" + i).style.display = 'none';
	} // end for
	// display selected content
	document.getElementById("weatherStory" + storyID).style.display = 'block';
} // end function

function decorateControls()
{ /* displays the control numbers active/passive */
	for( i = 1; i <= maxNumContentPieces; i++ )
	{ // make all control numbers passive display
		document.getElementById("controls" + i).className = 'passiveControls';
	} // end for
	// make current control number active
	document.getElementById("controls" + currentContentPiece).className = 'activeControls';
} // end function

function incrementContentPieces()
{ /* increments the content pieces */
	currentContentPiece++;
	if ( currentContentPiece > maxNumContentPieces )
	{ // check to see if increments past max and reset
		currentContentPiece = 1;
	} // end if
	return currentContentPiece;
} // end function

function decrementContentPieces()
{ /* decrements the content pieces */
	currentContentPiece--;
	if ( currentContentPiece < 1 )
	{ // check to see if increments past min and reset
		currentContentPiece = maxNumContentPieces;
	} // end if
	return currentContentPiece;
} // end function
		
			
		

//Tab switching
function moduleSwitcher(moduleName, numTabs, activateNumber)
{ // change display for module tabs/panels
	// localize variables
	var i; var j; var k; var l; var m;

	// obtain module and child nodes
	var myElementID = document.getElementById(moduleName);
	var moduleChildren = myElementID.childNodes;

	for( i = 0; i < moduleChildren.length; i++ )
	{ // loop through children of module
		if ( moduleChildren[i].className == "tabs")
		{ // for all tabs - apply passive look
			for( j = 0, k = 1; j < numTabs; j++, k++ )
			{ // cycle through tabs
				document.getElementById(moduleName + "_tab" + k).className = moduleName + "PassiveTabs";
			} // end for
		} else if ( moduleChildren[i].className == "panels")
		{ // for all panels - hide
			var panelsChildren = moduleChildren[i].childNodes;
			for( l = 0, m = 1; l < numTabs; l++, m++ )
			{ // cycle through tabs
				document.getElementById(moduleName + "_panel" + m).style.display = 'none';
			} // end for
		} // end if
	} // end for

	// change display for activated tabs/panels
	document.getElementById(moduleName + "_tab" + activateNumber).className = moduleName + "ActiveTabs";
	document.getElementById(moduleName + "_panel" + activateNumber).style.display = 'block';
	
	setCookie(moduleName, activateNumber);
} // end function



//Search logo input box swapper

function swapInputImage(el)
{ /* change the input image */

	var searchImagePath = "http://dseabcweb01:8012/graphics/global/stockgraphics/icons/";
	document.getElementById("searchBox").style.backgroundImage = 'url(' + searchImagePath + el.id + '.gif)';
} // end function



//Allow a drop down to have pop up links
function dropDownPopUp(url, windowName, width, height, directories, status, scrollbars, resize, menubar)
{ /* */
	if ( url != "" )
	{ // url not null
	 	var windowName = window.open(url, windowName, 'width=' + width + ',height=' + height + ',directories=' + directories + ',status=' + status+ ',scrollbars=' + scrollbars + ',resize=' + resize + ',menubar=' + menubar);
	 } // end if
} // end function

// generic cookie functions	
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

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";
	} // end if
} // end function

// create an instance of the Date object
var now = new Date();


// My Stories Functionality
function addToMyStories(formName, elementName, obj)
{ /* */

	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

	var itemEqual = false;

	// cookie name - set equal to form name
	cookieName = formName;

	// import cookie
	var cval = getCookie(cookieName);
	
	if (cval)
	{ // cval is not null
		// split cookie into pairs
		mycookie_array = cval.split(":::");

		// compare list of cookie url to new item
		for ( i = 0; i <= mycookie_array.length - 1; i++ )
		{ // split array into pairs - test for uniqueness
			var mycookieItem_array = mycookie_array[i].split("::");
			if ( mycookieItem_array[0] == obj.href )
			{ // item is common
				itemEqual = true;
			} // end if
		} // end for
		if (itemEqual == false )
		{ // item is unique - add to list
			cval = cval + ":::" + obj.href + "::" + obj.title;
			setCookie(cookieName, cval, now);
			if (document.forms[formName])
			{ // make sure the form is on the page
				refreshMyStoriesSelect(formName, elementName);
			} // end if
		} // end if
	} else
	{ // cval is null
		cval = obj.href + "::" + obj.title;
		setCookie(cookieName, cval, now);
		if (document.forms[formName])
		{ // make sure the form is on the page
			refreshMyStoriesSelect(formName, elementName);
		} // end if
	}// end if
} // end function

function refreshMyStoriesSelect(formName, elementName)
{ /*  */

	// cookie name - set equal to form name
	cookieName = formName;

	// import cookie
	var cval = getCookie(cookieName);

	if (cval)
	{ // cval is not null
		// split cookie into pairs
		var mycookie_array = cval.split(":::");
	
		// set select length
		var formLength = mycookie_array.length + 2;
		document.forms[formName].elements[elementName].options.length = mycookie_array.length + 2;
	
		for ( i = 1, j = 0; j <= mycookie_array.length - 1; i++, j++ )
		{ // slit array into pairs
			var mycookieItem_array = mycookie_array[j].split("::");
			document.forms[formName].elements[elementName].options[i].value = mycookieItem_array[0];
			document.forms[formName].elements[elementName].options[i].text = mycookieItem_array[1];
		} // end for
		document.forms[formName].elements[elementName].options[i].value = "deleteCookie";
		document.forms[formName].elements[elementName].options[i].text = "Remove all stories";
	} else
	{ // cval is null
		document.forms[formName].elements[elementName].options.length = 2;
		document.forms[formName].elements[elementName].options[0].value = "";
		document.forms[formName].elements[elementName].options[0].text = "Select Story";
		document.forms[formName].elements[elementName].options[1].value = "deleteCookie";
		document.forms[formName].elements[elementName].options[1].text = "Remove all stories";
	} // end if
} // end function

function launchStories(formName, elementName, obj)
{ /*  */

	if ( obj == "deleteCookie" )
	{ // delete cookie
		deleteCookie('myStories');
		if (document.forms[formName])
		{ // make sure the form is on the page
			refreshMyStoriesSelect(formName, elementName);
		} // end if
	} else if ( obj != "" )
	{ // url not null - open in same window
		location.href = obj;
		//location.replace(obj);
	} // end if
} // end function

function setMyNews(newsIndex)
{ /* set my news */
    var now = new Date();
    var rand = Math.round(Math.random()*100000000);

	param = "&";
	pos = document.URL.indexOf("POLL");
	if (pos == -1) {
		url = document.URL;
	} else {
		url = document.URL.substring(0, pos-1);
	} // end if
    var redir = document.URL;
    //var redir = url + param + "POLL=" + rand;
	var domain = ".199.181.134.162"; // need to change to the new domain when we launch

    ord = (now.getTime());
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie("MyNewsIndexName", newsIndex, now);
	//setCookie("MyNewsIndexName", newsIndex, now, "/", domain, false);
    reloadPage(window.location.href);
} // end function

function reloadPage(url) {
	if (document.layers) {
		window.location.href = url;
	} else {
    	self.location.replace(url);
	}
}



//Vehicle Finder

var fastFind;
var typeAry = new Array();
    var yNAry = new Array();
    var yUAry = new Array();

yNAry[0] = '2005';
yNAry[1] = '2004';

yUAry[0] = '2004';
yUAry[1] = '2003';
yUAry[2] = '2002';
yUAry[3] = '2001';
yUAry[4] = '2000';
yUAry[5] = '1999';
yUAry[6] = '1998';
yUAry[7] = '1997';
yUAry[8] = '1996';
yUAry[9] = '1995';
yUAry[10] = '1994';
yUAry[11] = '1993';
yUAry[12] = '1992';
yUAry[13] = '1991';
yUAry[14] = '1990';


function init(ff) {
    fastFind = ff;
    ff.IsNew[0].checked = true;
    var ffYear= ff.year;
    clear(ffYear);
    ffYear.disabled = false;
    for (var i = 0; i < yNAry.length; i++) {
	ffYear.options[i] = new Option(yNAry[i], yNAry[i]);
    }
    ffYear.selectedIndex=0;
}

function changeNewUsed(IsNew) {
    var ffYear =  fastFind.year;
    clear(ffYear);
    ffYear.disabled = false;
    (IsNew == 1) ?  setYear(yNAry): setYear(yUAry);
    ffYear.selectedIndex=0;
}

function clear(list) {
    for (var i = list.options.length -1; i >= 0; --i) list.options[i] = null;
}

function setYear(yearList) {
    for (var i = 0; i < yearList.length; i++) {
	    fastFind.year[i] = new Option(yearList[i], yearList[i]);
    }
}

//generic formmailer

function formCheck( form ){
	var errors = 0;
	if (document.validate.from.value.indexOf("@") == -1 || document.validate.from.value == ""){
		alert("Please include a proper e-mail address.");
		errors = 1;
		return false;
	}
	if (errors == 0){
		alert("Thank you for taking the time to write to us.");
		return true;
	}
}


//Pop-up code
function launchURL(url,name,x,y) {
	window.name = "_newshome";
    var ItsTheWindow;
    ItsTheWindow = window.open(url, name, "status=no,height="+y+",width="+x+",scrollbars=no,resizable=no,toolbar=no");
}

var vamIniState = 0;
function resizeDiv(divID)
	{ // resize the VAM
	var divStyle = document.getElementById(divID).style;
	if (vamIniState == 0)
	{ // initial state is small - increase
		divStyle.width = '340px';
		divStyle.height = '290px';
		dropDownVisibilityVAM('hidden');
		vamIniState = 1;
	} else
	{ // initial state is large - decrease
		divStyle.width = '160px';
		divStyle.height = '100px';
		dropDownVisibilityVAM('visible');
		vamIniState = 0;
	} // end if
} // end function

function dropDownVisibilityVAM(dropVisibile)
{ // resolves issue with navigation appearing behind select fields
	if (document.all)
	{ // if IE
		for (var j = 0; j < dropDownModules.length; j++)
		{ // obtain select elements from modules array - assign to an array
			var selectArray = document.getElementById(dropDownModules[j]).getElementsByTagName('select');

			for (var i = 0; i < selectArray.length; i++)
			{ // hide all drop down elements
				selectArray[i].style.visibility = dropVisibile;
			} // end for
		} // end for
	} // end if
} // end function
