// Create first and last list classes

function popUp(URL) {
day = new Date();
id = day.getTime();
//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=570,height=634');");
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=590,height=470');");
}

function changeRowStats(tableRow, highLight, orig) {
	if (highLight) {
		tableRow.className='highlight';
	} else {
		tableRow.className=orig;
	}
}

function changeRow(tableRow, highLight) {
	if (highLight) {
		tableRow.className='highlight';
	} else {
		tableRow.className='';
	}
}

function printArticle() {
	if (window.print) {
		setTimeout('window.print();', 333);
	}
	else if (agt.indexOf("mac") != -1) {
		alert("Press 'Cmd+p' on your keyboard to print article.");
	}
	else {
		alert("Press 'Ctrl+p' on your keyboard to print article.")
	}
}
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");
}

function launchFLASHcheck(url,name,x,y) {
	window.name = "_newshome";
    var ItsTheWindow;
    ItsTheWindow = window.open(url, name,
    "status=no,height="+y+",width="+x+",scrollbars=yes,resizable=no,toolbar=no");
}

function  firstLastList() {
	if(!document.getElementsByTagName) return false;

	var ul = document.getElementsByTagName("ul");

	for (var i = 0; i < ul.length; i++ )
	{
		var li = ul[i].getElementsByTagName("li");
		if (!li.length) continue;
		li[0].className += " first";
		li[li.length-1].className += " last";
	}

	var ol = document.getElementsByTagName("ol");

	for (var i = 0; i < ol.length; i++ )
	{
		var li = ol[i].getElementsByTagName("li");
		if (!li.length) continue;
		li[0].className += " first";
		li[li.length-1].className += " last";
	}
}

// Open links in a new window

function openWindow() {
	if (!document.getElementsByTagName) return false;
	
	var links = document.getElementsByTagName("a");
	
	for ( var i = 0; i < links.length; i++ )
	{
		if (links[i].className.search(/open-window/) != -1)
		{
			links[i].onclick = function() {
				if(!document.getElementById) return true;
				//open a new window with the anchors url
				window.open(this.getAttribute("href"));
				return false;
			}
		}
	}
}

// Stripe tables

// This function is need to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
	
	var result = false;
	
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
	}
	
	return result;
} 
	
	
//onload = function() {
//	if (document.getAttributeNode("class").value != "stats") {
//		stripeTable ()
//	}
//}

function stripeTable() {
	var even = true;
	var tables = document.getElementsByTagName("table");
	
	for(x=0;x!=tables.length;x++){
		table = tables[x];
		if (! table) { return; }
		
		var tbodies = table.getElementsByTagName("tbody");
		
		for (var h = 0; h < tbodies.length; h++) {
			var trs = tbodies[h].getElementsByTagName("tr");
			
			for (var i = 0; i < trs.length; i++) {
				
				for (var i = 0; i < trs.length; i += 2) {
					trs[i].className += "odd";
				}
			}
		}
	}
}

// Choose search criteria

function assignURL()  {
   for( i = 0; i < document.vtsearchform.url.length;i++)    {
   if( document.vtsearchform.url[ i ].checked ) document.vtsearchform.action =  document.vtsearchform.url[ i ].value;
	  document.vtsearchform.submit();
	  }
   }

// Clear search query

function clearquery(id) {
	if(!document.getElementById(id)) return false;
	if (document.getElementById(id).value == "Enter your search here")
	{
		document.getElementById(id).value = "";
	}
}

// Submit search form

function submitForm(formId) {
	document.getElementById(formId).submit();
}

// Event handlers

function addLoadEvent(func) {
	var oldOnLoad = window.onload
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldOnLoad();
			func();
		}
	}
}

addLoadEvent(firstLastList);
addLoadEvent(openWindow);

