
gCurrentBannerIndex = 0

gBannerDivs = $$('div.specials_banner');

if(gBannerDivs.length > 0 ) {
  min = 0;
  max = gBannerDivs.length - 1;
  setTimeout(rotate_banner,'8000');
}

function banner_in(id) {
  Effect.Appear($(gBannerDivs[gCurrentBannerIndex]));
}

function rotate_banner() {
  gCurrentBannerIndex++;
  Effect.Fade($(gBannerDivs[gCurrentBannerIndex - 1]));
  if(gCurrentBannerIndex >= gBannerDivs.length) {
    gCurrentBannerIndex = 0;
  }
  setTimeout(banner_in,'980');
  setTimeout(rotate_banner,'10000');
}

function DisableEnableForm(xForm,xDisabled){
  objElems = xForm.elements;
  for(i=0;i<objElems.length;i++){
    objElems[i].disabled = xDisabled;
  }
}

function changeImgSize(objectId,newWidth,newHeight) {
	imgString = 'theImg = document.getElementById("'+objectId+'")';
	eval(imgString);
	oldWidth = theImg.width;
	oldHeight = theImg.height;
	if(newWidth>0){
		theImg.width = newWidth;
	}
	if(newHeight>0){
		theImg.height = newHeight;
	}
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
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;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
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;
}



function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}


function floatElement(element_id)
{
	var elem = $(element_id);
	
	if(elem == null)
		return false;

	elem.style.position = 'absolute';
	elem.style.zIndex = 100;
		
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var elemTop = arrayPageScroll[1] + ((arrayPageSize[3] - elem.clientHeight) / 2);
	var elemLeft = ((arrayPageSize[0] - elem.clientWidth) / 2);
	
	elem.style.top = (elemTop < 0) ? "0px" : elemTop + "px";
	elem.style.left = (elemLeft < 0) ? "0px" : elemLeft + "px";

	// A small pause between the image loading and displaying is required with IE,
	// this prevents the previous image displaying for a short burst causing flicker.
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	} 

	// Hide select boxes as they will 'peek' through the image in IE
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
    	selects[i].style.visibility = "hidden";
    }


	elem.style.display = 'block';	

	return false;
}


//Start banner rotation


var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();
	// close old layer
	if(ddmenuitem) ddmenuitem.hide();

	// get new layer and show it
	ddmenuitem = $(id);
	ddmenuitem.show();

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.hide();
	window.clearTimeout(closetimer);
}

// go close timer
function mclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
  }
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 


//RGB -- Move all common functions here

var PortalSupport = {

	load_html: function(dom_id,url) {
		new Ajax.Updater(dom_id, url, { method: 'get' });
	},
	
	json_error_to_ul: function(title,error_array,element) {
		var ele = $(element);
		if(ele) {
			var li_html = '<div class="error_message_header">' + title + ', please review the errors listed below and try again. </div>';
			li_html += '<ul class="error_message_list">';
			for(var i = 0;i < error_array.length; i++) {
				li_html += '<li class="error_message_items">' + error_array[i] + '</li>';
			}
			li_html += '</li>';
		}
		ele.update(li_html);
		ele.show();
	},
	
	ajax_post_with_loader: function(uri,params,loader_id) {
		new Ajax.Request(uri,{
          parameters:params,
          asynchronous:true,
          onLoading: function() { $('ajax_loader').toggle(); 	 },
          onSuccess: function(result) { $('ajax_loader').hide(); },
          onFailure: function(result) { $('ajax_loader').hide(); },
          evalScripts:true
        });
	}
	
	
	
}

