var minusImg = new Image();
minusImg.src = "../admin/img/minus.gif";
var plusImg = new Image();
plusImg.src = "../admin/img/plus.gif";

var newwin;

function launchwin(winurl,winname,winfeatures,w,h)
{
	//This launches a new window and then
	//focuses it if window.focus() is supported.
	if (screen)
	{
		leftpos = screen.width - w;
		leftpos = leftpos / 2;
		toppos = screen.height -h;
		toppos = toppos / 2;
		leftpos = Math.round(leftpos);
		toppos = Math.round(toppos);
	}

	winfeatures=winfeatures+',left='+leftpos+',top='+toppos;

	newwin = window.open(winurl,winname,winfeatures);
	newwin.focus();
}

function launchwin2(winurl,winname,winfeatures,w,h)
{
	//This launches a new window and then
	//focuses it if window.focus() is supported.
	if (screen)
	{
		leftpos = screen.width - w;
		leftpos = leftpos / 2;
		toppos = screen.height -h;
		toppos = toppos / 2;
		leftpos = Math.round(leftpos);
		toppos = Math.round(toppos);
	}

	winfeatures=winfeatures+'status=no,menubar=no,scrollbars=no,resizable=no,left='+leftpos+',top='+toppos;

	newwin = window.open(winurl,winname,winfeatures);
	newwin.focus();
}

function new_window() 
{ 
	Index = 
window.open('','index','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=600');
} 

function new_window2(url) 
{ 
	Index2 = window.open(url,'index2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=675,height=500');
}

function new_window3() 
{ 
	Index3 = window.open('','index3','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=600,height=600');
}

function CollapsableDiv(imgID, divID)
{
        this.imageID = imgID;
        this.image = null;
        this.divID = divID;
        this.div = null;
	this.visible = false;
        this.init();
}        
CollapsableDiv.prototype.toggle = toggle;
CollapsableDiv.prototype.init = initDiv;
CollapsableDiv.prototype.setup = setupDiv;
        
var isIE = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);

function initDiv()
{
	var thisObj = this;
	if(isIE)
		window.attachEvent("onload", function() { thisObj.setup(); });
	else
		window.addEventListener("load", function() { thisObj.setup(); }, true);
}
        
function setupDiv()
{
        this.div = document.getElementById(this.divID);
	this.visible = (this.div.style.display != "none");
	if(this.imageID)
		this.image = document.getElementById(this.imageID);
}
                
function toggle()
{
	if(!this.div)
	{
		var thisObj = this;
		window.setTimeout(function() { thisObj.toggle(); }, 10);
		return;
	}
	if(this.div.style.display != "")
	{
		if(this.image)
			this.image.src = minusImg.src;
		this.div.style.display = "";
		document.cookie = this.divID + "=true";
		this.visible = true;
	}
        else
        {
		if(this.image)
			this.image.src = plusImg.src;
		this.div.style.display = "none";
		document.cookie = this.divID + "=false";
		this.visible = false;
        }
}


/** AD ROTATOR **/
function adRotator(zoneID, stat, ufl)
{
	this.xmlhttp = null;
	this.zone = zoneID;
	
	this.height = 60;
	this.width = 480;
	this.img = null;
	this.link = null;
	this.flash = ufl;
	this.stat = stat;
	this.adid = null;
	this.url = null;
	this.lnk = null;
	
	var thisObj = this;
	this.cleanup = function () { adRotator_cleanup.call(thisObj); };
	
	this.getAd = function() { adRotator_getAd.call(thisObj); };
	
}
adRotator.prototype.setup = adRotator_setup;
adRotator.prototype.init = adRotator_init;
adRotator.prototype.handleAd = adRotator_handleAd;

function adRotator_cleanup()
{
	this.xmlhttp = null;
	this.img = null;
	this.link = null;
}

var isIE = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);

function adRotator_setup()
{
	var thisObj = this;
	var init = function() { thisObj.init(); };
	
	if(isIE)
	{
		window.attachEvent("onload", init);
		window.attachEvent("onunload", this.cleanup);
	}
	else
	{
		window.addEventListener("load", init, false);
		window.addEventListener("unload", this.cleanup, false);
	}

	if(this.flash)
	{
		document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
		document.write("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" ");
		document.write("WIDTH=\"480\" HEIGHT=\"60\" id=\"lasbanner\">");
		document.write("<PARAM NAME=\"movie\" VALUE=\"" + this.url + "\">");
		document.write("<PARAM NAME=\"quality\" VALUE=\"high\">");
		document.write("<PARAM NAME=\"bgcolor\" VALUE=\"#FFFFFF\">");
		document.write("<PARAM NAME=\"AllowScriptAccess\" VALUE=\"never\">");
		document.write("<EMBED src=\"" + this.url + "\" quality=\"high\" "); 
		document.write("bgcolor=\"#FFFFFF\" WIDTH=\"480\" HEIGHT=\"60\" NAME=\"lasbanner\" "); 
		document.write("ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" ");
		document.write("PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\">");
		document.write("</EMBED></OBJECT>\n");
	}
	else
	{
		document.write("<a href=\"");
		if(this.lnk)
			document.write("adredir.php?url="+ this.lnk + "&id=" + this.adid);
		else
			document.write("javascript:void(0);")
		document.write("\" id=\"adrotlnk" + this.zone +"\" ");
		if(!(this.url || this.alt))
			document.write(" style=\"visibility:hidden;\" ");
		document.write(" >");
		document.write("<img src=\"");
		if(this.url)
			document.write(this.url);
		else if(this.alt)
			document.write(this.alt);
		document.write("\" height=\"" + this.height + "\" width=\"" + this.width + "\" ");
		document.write("id=\"adrotimg" + this.zone + "\" border=\"0\" />");
		document.write("</a>\n");
	}
}

function adRotator_init()
{
	this.img = document.getElementById("adrotimg"+this.zone);
	this.link = document.getElementById("adrotlnk"+this.zone);
	
	if(!(this.flash || this.stat || !this.url))
	{
		window.setTimeout(this.getAd, 60000);
	}
}

function adRotator_getAd()
{
	try
	{
		var thisObj = this;
		try
		{
			if(isIE)
			{
				this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				this.xmlhttp.onreadystatechange= function () { thisObj.handleAd(); };
			}
			else
			{
				this.xmlhttp = new XMLHttpRequest();
				this.xmlhttp.onload = function () { thisObj.handleAd(); };
			}
		}
		catch (e)
		{
			alert(e.message);
		}
		this.xmlhttp.open("GET", "banner.php?z=" + this.zone, true);
		this.xmlhttp.send(null);
	}
	catch (e)
	{
		alert(e.message);
	}
}

function GetXMLString(xml)
{
        if(!xml) return "null";
        if(xml.xml)
                return xml.xml;
        else if(window.XMLSerializer)
        {
                var xser = new XMLSerializer();
                var s = xser.serializeToString(xml);
                return s;
        }
}

function adRotator_handleAd()
{
	if(this.xmlhttp.readyState == 4)
	{
		try
		{
			var xml = this.xmlhttp.responseXML;
			var ad = xml.getElementsByTagName("bannerAd")[0];
		
			var adName = ad.getElementsByTagName("name")[0].firstChild.data;
			var imgUrl = ad.getElementsByTagName("img")[0].firstChild.data;
			var linkUrl = ad.getElementsByTagName("url")[0].firstChild.data;

			if(imgUrl)
			{
				if(linkUrl)
					linkUrl = escape(linkUrl);
				var adId = ad.getElementsByTagName("id")[0].firstChild.data;

				//alert("adName: " + adName + "\n\nimgUrl: " + imgUrl + "\n\nlinkUrl: " + linkUrl + "\n\nadId: " + adId);
		
				this.img.src = imgUrl;
				this.img.alt = adName;
				this.img.style.display = "";
				this.link.title = adName;
				this.link.href = "adredir.php?url=" + linkUrl + "&id=" + adId
				var thisObj = this;
		
			}
		}
		catch (ex)
		{
			//alert(ex.message + "\n" + GetXMLString(this.xmlhttp.responseXml));
		}

		window.setTimeout(this.getAd, 60000);

	}
}

function doVote(frm)
{
	var form = document.getElementById(frm);
	form.submit();
}


//FIXUP EMAIL LINKS
/*
if(isIE)
	window.attachEvent("onload", fixEmailLinks);
else
	window.addEventListener("load", fixEmailLinks, false);
*/

function fixEmailLinks()
{
	var emls = document.getElementsByTagName("eml");
	for(var i=emls.length-1; i>=0; i--)
	{
		var eml = emls[i];
		var link = (eml.getAttribute("link") == "1");
		var user = eml.getAttribute("user");
		var domain = eml.getAttribute("domain");
		var txt = eml.innerHTML || (user + " a t " + domain);
	alert(txt);

		var txtNode = document.createTextNode(txt);
		var el;
		if(link)
		{
			el = document.createElement("a");
			el.href = "javascript:void(0);";
			el.onmouseover = "window.status='click to send email'";
			el.onmouseout = "window.status=''";
			el.appendChild(txtNode);

		}
		else
		{
			el = document.createElement("span");
			el.appendChild(txtNode);
		}

		var prt = eml.parentNode;
		//prt.replaceChild(el, eml);
		//prt.insertBefore(el, eml);

	} 

}

function setActiveStylesheet(title)
{
	document.body.scrollTop = 0;
	var i, a, main;
	var styles = document.getElementsByTagName("link");
	for(i=0; (a = styles[i]); i++)
	{
		var ttl = a.getAttribute("title");
		if(a.getAttribute("rel").indexOf("style") != -1 && ttl) 
		{
			a.disabled = true;
			if(ttl == title) a.disabled = false;
		}
	}
}



/*
function webrequest()
{
        this.async = true;
        this.request = null;
        this.method = "POST";
        this.requestUrl = "";
        
        this.useWait = false;
        this.waitInContainer = null;
                 
        this.readyStateChange = ctxFunction(this, webrequest_readyStateChange);
        this.init();
}
*/

function loadnews(start)
{
	var request = new webrequest();
	request.method = "GET";
	request.useWait = true;
	var container = document.getElementById("news");
	request.waitInContainer = container;
	request.requestUrl = "news.php?nstart="+start;
	request.color = "transparent";
	request.addEventListener("complete", loadnews_callback);

	request.send();
}

var newssizer = null;
function loadnews_callback(evt, request)
{
	var userAgent = navigator.userAgent.toLowerCase();
	var macff = ((userAgent.indexOf("firefox") != -1) && (userAgent.indexOf("macintosh") != -1));


	var container = document.getElementById("news");
	var oldnews;
	for(var i=0; i<container.childNodes.length; i++)
	{
		if(container.childNodes[i].nodeName == "DIV")
		{
			oldnews = container.childNodes[i];
			break;
		}
	}

	//alert(request.request.responseText);
	var newnews = document.createElement("DIV");
	if(!macff)
	{
		newnews.style.position = "absolute";
		newnews.style.top = "0px";
		newnews.style.left = "0px";
	}
	newnews.innerHTML = request.request.responseText;
	container.appendChild(newnews);

	if(macff)
	{
		container.removeChild(oldnews);
		return;
	}

	newnews.style.opacity = 0;
	var newfade = new PB_fader(newnews);
	newfade.dir = PB_FADE_UP;
	var oldfade = new PB_fader(oldnews);
	oldfade.dir = PB_FADE_DOWN;
	oldfade.OnFadeComplete = ctxFunction(this, newsFadeComplete, [oldnews, container]);
	
	if(newssizer) newssizer.stop();
	newssizer = new PB_sizer(container);
	newssizer.sizeToContainer = newnews;
	newssizer.startSize = oldnews.offsetHeight;
	newssizer.stopSize = newnews.offsetHeight;
	newssizer.OnResizeComplete = function() { newnews.style.position="static"; container.style.height="auto"; };

	oldfade.start();
	newfade.start();
	newssizer.start();
}

function newsFadeComplete(oldnews, container)
{
	//var s = new PB_sizer(container);
	//s.startSize = oldnews.offsetHeight;
	//s.stopSize = newnews.offsetHeight;
	container.removeChild(oldnews);
	//s.start();

}

