function popUp(page, name, w, h, is_scroll) { // pop up window
	bar = window.open(page.split(" ").join("%20"), (name == '' ? 'foo' : name), 'height='+h+',width='+w+',top='+ ((screen.height - h) / 2) +',left='+ ((screen.width - w) / 2) +',scrollbars='+ is_scroll +',resizable=yes');
	bar.focus();
}

// fix firefox window close
function closeWindow() {
	window.open('','_parent','');
	window.close();
}

// start tabs
currentshown=1;
function showDiv(thediv){
	
	document.getElementById('div'+currentshown).style.display='none';
	document.getElementById('div'+thediv).style.display='block';
	
	document.getElementById('tab'+currentshown).className = 'null';
	document.getElementById('tab'+thediv).className = 'selected';
	
	currentshown=thediv;
}

function switchTabControl(action){
	if(action == 'stopTabs'){
		document.getElementById('startTabs').style.display='block';
		document.getElementById('stopTabs').style.display='none';
	} else {
		document.getElementById('startTabs').style.display='none';
		document.getElementById('stopTabs').style.display='block';
	}
}

///--------------------------------------

Array.prototype.shuffle = function(times){
	var i,j,t,l = this.length;
	while(times--)	{
		with(Math)	{
			i = floor(random()*l);
			j = floor(random()*l);
		}
		t = this[i];
		this[i] = this[j];
		this[j] = t;
	}
	return this;
}

///--------------------------------------

/****  TIMER *****/
var ticker; //declare the ticker variable as a global
function init () {
/*
	var tabs = document.getElementsByClassName('tabs');
	for (var i = 0; i < tabs.length; i++) {
		$(tabs[i].id).onclick = function () {
			ticker.clicked = true;
			alert(ticker.clicked);
			showDiv(this.id.substring(-1));
	window.status = "" + this.id.substring(-1);
		}
	}
*/
	ticker = new Ticker();
	ticker.tick(1);
}

function resume() {
	if(ticker){
		ticker.clicked = false;
		//currentshown = currentshown + 1;
		ticker.tick(currentshown + 1);
	} else {
		ticker = new Ticker();
		ticker.tick(currentshown + 1);  //go to the second tab because the first is automatically shown on page load.
	}
}

function Ticker(){
    this.count = 0;
    this.timer = new Timer(this);
    this.clicked = false;
}

Ticker.prototype.tick = function(d){
    if(!this.clicked){
	//if we've hit the last tab, select the first tab again
	if (d>4){ d = 1 }
	showDiv(d);
	d++;
	this.timer.setTimeout("tick", 10000, d);
    } else {
	//d=currentshown;
	//get the selected div ID as a starting point for when we start again
	//this.timer.setTimeout("tick", 10000, d);
    }
}

/***** AP Tab Control ******/
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function initTabs(){
	alert(document.getElementById('tab1').onclick);
	document.getElementById('tab1').onclick = tabClick(1);
	alert(document.getElementById('tab1'));
	document.getElementById('tab2').onclick = tabClick(2);
	document.getElementById('tab3').onclick = tabClick(3);
	document.getElementById('tab4').onclick = tabClick(4);
}

function tabClick(tabNum){
	showDiv(tabNum);
	controlTab('stop');
	return false;
}

function controlTab(action){  //actions are: play, stop
	//if(!action){action = document.images.controlButton.src.substr(document.images.controlButton.src.length-8,4);}
	//if the tabs are playing
	if(action == "stop"){
		//pause them
		if(ticker){
			ticker.clicked = true;
		}
		
		//change the image
		//document.images.controlButton.src = document.images.controlButton.src.substring(0,document.images.controlButton.src.length-8) + "stop.gif";
	}
	//otherwise if the tabs are paused
	else if(action == "play"){
		//play them
		ticker.clicked = false;
		ticker.tick(currentshown);
		
		//ticker.timer.setTimeout("tick", 10000, d);
		
		//change the image
		//document.images.controlButton.src = document.images.controlButton.src.substring(0,document.images.controlButton.src.length-8) + "play.gif";
	}
	
}
/***** End Tab Control *****/

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();
}

/***** Code that allows multiple onLoad events *****
function addLoadEvent(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      oldonload(); 
	      func(); 
	    } 
	  } 
	} 
	 
	//usage examples
	//addLoadEvent(nameOfSomeFunctionToRunOnPageLoad); 
	//addLoadEvent(function() { 
	  //more code to run on page load
	}); 
/****** end add multiple onload events ******/

/***** peel ad controls 
function scaleTo(w,h){
	w=w+"px";
	h=h+"px";
	document.getElementById('pageFlip').style.width = w;
	document.getElementById('pageFlip').style.height = h;
	document.getElementById('pageFlipSWF').style.width = w;
	document.getElementById('pageFlipSWF').style.height = h;
	document.getElementById('searchdrop').style.display='none';
}
function showsearch(){
	document.getElementById('searchdrop').style.display='block';
}
*****/

function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function hideDivs(id){ document.getElementById(id).style.display="none"; }
function showDivs(id){ document.getElementById(id).style.display="block"; }

function toggleLogin(state){
	if(state == 'show'){
		changeOpac(0, 'log_box');
		showDivs('log_box');
		opacity('log_box', 0, 98, 300);
	} else {
		opacity('log_box', 98, 0, 300);
		setTimeout("hideDivs('log_box')",300);
	}
}


// character limit
function char_count(textEl,countEl,limit){
	if(textEl.value.length > limit){
		textEl.value = textEl.value.substring(0, limit);
	} else {
		countEl.value = limit - textEl.value.length;
	}
}


// write flash objects
function flash(file,height,width,vars,vars2){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+file+'">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+file+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="FlashVars" value="vars='+file+'&vars='+vars+'&vars2='+vars2+'" />');
	document.write('<embed src="'+file+'" FlashVars="vars='+file+'&vars='+vars+'&vars2='+vars2+'" quality="high" width="'+width+'" height="'+height+'" name="'+file+'" wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function menu(div){
	if(document.getElementById(div).style.display==''){
		document.getElementById(current).style.display='block';
		}
	if(document.getElementById(div).style.display=='block'){
		document.getElementById(div).style.display='none';
		document.getElementById(current+'_tab').className='null';
		document.getElementById(current+'_toggle').className='null';
		document.getElementById('tool_bar').className='tool_click';
		}
	else{
		document.getElementById(current).style.display='none';
		document.getElementById(current+'_tab').className='null';
		document.getElementById(current+'_toggle').className='selected';
		document.getElementById(div+'_tab').className='selected';
		document.getElementById(div+'_toggle').className='toggle_on';
		document.getElementById(div).style.display='block';
		document.getElementById('tool_bar').className='null';
		}
	current=div;
	}
	
function show(div){
	if(document.getElementById(div).style.display=='block'){
		document.getElementById(div).style.display='none';
		}
	else{
		document.getElementById(div).style.display='block';
		if(div=='search'){
			document.searchForm.q.focus();
			}
		}
	}