/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// GET PAGE SIZES ARRAY

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// GET ELEMENTS BY CLASS

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}


/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// GET PAGE SCROLL

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// FORCE GET ELEMENT BY ID

if(!document.getElementById) {
	if(document.all) {
		document.getElementById = function() {
			if(typeof document.all[arguments[0]] != "undefined") {
				return document.all[arguments[0]];
			} else { return null; }
		}
	} else if(document.layers) {
		document.getElementById = function() {
			if(typeof document[arguments[0]] != "undefined") {
				return document[arguments[0]];
			} else { return null; }
		}
	}
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// LOADING?

function loading(n){
	if(n){
    	$('loadText').innerHTML = "is " + n + "...";
		new Effect.Appear('loadText', {duration: 0.4});
		new Effect.Appear('loading', {duration: 0.4});
	} else {
		new Effect.Fade('loadText', {delay: 1.0, duration: 0.6});
		new Effect.Fade('loading', {delay: 1.0, duration: 0.6});
	}
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SET RECENT PLACEMENT

function setRecentPlacement(id, tot){
    for(i=1; i<=tot; i++){
		$('rp_' + i).style.display = (i == id)? "block" : "none";
	}	
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SWITCH SERIES TAB

function switchTabSeries(id, tot){
	for(i=1; i<=tot; i++){
		$('tab_' + i).className = (i == id)? "onHeader" : "offHeader";
	}	
}

function hiOn(el){
    el.className = "hilite";	
}

function hiOff(el){
    el.className = null;	
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SHOW HIDE

function showBOX(n){
    document.getElementById(n).style.display = 'block';
}

function hideBOX(n){
    document.getElementById(n).style.display = 'none';
}  
  
function swapBOX(n){
	document.getElementById(n).style.display = document.getElementById(n).style.display=='none'?'block':'none';
}  

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SHOW CITY

var onCity = false;
var checkCityInterval = 0;

function showCity(city){
	
	onCity = true;
	
	var x = getElementsByClassName(document, "div", "cityInfo");
	for(c=0; c< x.length; c++){
		x[c].style.display = 'none';
	}
	
	showBOX(city);
	
}

function offCity(){
	onCity = false;
	if(checkCityInterval) clearTimeout ( checkCityInterval );
	checkCityInterval = setTimeout ( "checkCity()", 2000 );
}

function checkCity(){
	if(!onCity){
		hideCity();
	} else {
		if(checkCityInterval) clearTimeout ( checkCityInterval );
		checkCityInterval = setTimeout ( "checkCity()", 2000 );
	}
}

function hideCity(){
	var x = getElementsByClassName(document, "div", "cityInfo");
	for(c=0; c< x.length; c++){
		x[c].style.display = 'none';
	}
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// FADE UNFADE

function fadeSCREEN(){
	numID = 1;
	
	sizes = getPageSize();
	
	$("FADE").style.height = sizes[1]+"px";
	$("FADE").style.display = 'block';
	Element.setOpacity('FADE', 0.7);
	//new Effect.Opacity("FADE", {duration:0.0, from:0.0, to:0.7});
	$("ALERT").style.display = 'block';
}

function unfadeSCREEN(){
	hideBOX("ALERT");
	hideBOX('FADE');
}

function clearSmoke(){
	new Effect.Fade('smoke', { duration: 0.3, queue: 'end'});
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SWAP IMAGE


function swapSrc(src){
	$("registerImg").src = src;
}

function swap_image(id, hover){
	var thisImage  = document.getElementById(id);
	var tempSource = (hover)? "media/panes/" : "media/panes/white/";
	thisImage.src  = tempSource + id + ".jpg";
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SLIDE DIV

var busy_slide = false;
var fps = 40;

function slide(eleId, varX, varY, transTime) {
	if(busy_slide == false){
		busy_slide = true;
		slideDiv(eleId, varX, varY, transTime);
	}
}

function slideDiv(eleId, varX, varY, transTime) {
	if(eleId) {
		j = 0;
		oDiv = document.getElementById(eleId);
		startX = oDiv.style.left.replace(/px/, "") * 1;
		startY = oDiv.style.top.replace(/px/, "") * 1;
		approxSteps = fps * (transTime / 1000);
		delay = transTime / approxSteps;
		sinInc = (Math.PI/2) / approxSteps;
		moveX = varX;
		moveY = varY;
	}
	if (j <= approxSteps) {
		var posX = startX + Math.ceil(Math.sin(j * sinInc) * moveX);
		var posY = startY + Math.ceil(Math.sin(j * sinInc) * moveY);
		oDiv.style.left = posX + "px";
		oDiv.style.top = posY + "px";
		j++;
		setTimeout("slideDiv()", delay);
	} else {
		busy_slide = false;
		return;
	}
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
