// global popup function. Pass in file name and width and height of window
function popUp(page,name,w,h,scrolll)
{
    if (navigator.appName == 'Netscape')
	{
        popWindow = window.open(page,name,'width='+w+',height='+h+',resizable=no,menubar=no,status=no,scrollbars='+scrolll+',toolbar=no,directories=no,location=no,screenX=0,screenY=0');
        popWindow.focus();
    }
	else if (navigator.appName == 'Microsoft Internet Explorer')
	{
        popWindow = window.open(page,name,'width='+w+',height='+h+',resizable=no,menubar=no,status=no,scrollbars='+scrolll+',toolbar=no,directories=no,location=no,top=0,left=0');
        popWindow.focus();
    }
    else
	{
        popWindow = window.open(page,name,'width='+w+',height='+h+',resizable=no,menubar=no,status=no,scrollbars='+scrolll+',toolbar=no,directories=no,location=no,top=0,left=0');
        popWindow.focus();
    }
}

function getMacVersionNumber() 
{
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("Safari");
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return 1;
    }
}
function launchCSPopup(type, entryView) {
	//var url = 'http://www.behr.com/colorsmart4/colorsmart/enterCS.jsp?entryView=GlobalWebWaysToFindColor&type=interior&ecommerceUrl=http://store.behr.com/index.asp&scene7Url=http://scene7:79';
	var url = 'http://www.behr.com/Behr/home#';
	//var url = 'http://www.behr.com/colorsmart4/colorsmart/main.jsp';
	popUp(url,'colorSmart','773','580','no');
	//popUp(url,'colorSmart','1024','768','no');
}
function flashColorSmart (type, entryView) {
		hasFlash = true;
		launchCSPopup(type, entryView);
}
function launchColorSmart (type, entryView)
{
	flashColorSmart(type, entryView);
}
var scrollBars = "no";
function OpenWindow(Page, Width, Height)
{
	var left = (window.screen.width/2)  - (Width/2);
  	var top  = (window.screen.height/2) - (Height/2);
  	if (left < 0) left = 20;
  	if (top < 0) top = 50;
	
	popWindow = window.open(Page, "", 'width='+Width+',height='+Height+',resizable=no,menubar=no,status=no,scrollbars='+scrollBars+',toolbar=no,directories=no,location=no,top='+top+',left='+left+'');
    popWindow.focus();
	return;
}

var news_timer;
function scroll_news()
{
	if(document.getElementById('newsContent') && document.getElementById('newsTable'))
	{
		var curr_scroll = document.getElementById('newsContent').scrollTop;
		document.getElementById('newsContent').scrollTop = curr_scroll + 1;
		
		if((document.getElementById('newsContent').scrollTop) >= (document.getElementById('newsTable').offsetHeight+170))
		{
			document.getElementById('newsContent').scrollTop = 0;
		}
		news_timer = setTimeout("scroll_news()", 95);
	}
}

var imgs_timer;
var contObj;
var tblObj;
var scType;

function scroll_imgs()
{
	if(contObj && tblObj)
	{
		var curr_scroll = contObj.scrollLeft;
		contObj.scrollLeft = curr_scroll + scType;
		
		//if((contObj.scrollLeft) >= (tblObj.offsetHeight+170))
		//{
		//	document.getElementById('newsContent').scrollTop = 0;
		//}
		imgs_timer = setTimeout("scroll_imgs()", 55);
	}
}

function stopScrollImgs()
{
	clearTimeout(imgs_timer);
}

function show_reg_v2(openerBlock)
{
	if(regMenuObj.style.display == "block")
	{
		regMenuObj.style.display = "none";
	}
	else
	{
		var pos = findPos(openerBlock);
		regMenuObj.style.display = "block";
		regMenuObj.style.top = (pos[1]-5)+'px';
		regMenuObj.style.left = (pos[0]-8)+'px';
		document.onmousemove = getCurPosition;
	}
	return;
}

function close_reg()
{
	regMenuObj.style.display = 'none';
}

function getCurPosition(e)
{
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }

	if(
		regMenuObj.offsetTop > cursor.y || (parseInt(regMenuObj.offsetTop)+parseInt(regMenuObj.height)) < cursor.y
		||
		regMenuObj.offsetLeft > cursor.x || (parseInt(regMenuObj.offsetLeft)+parseInt(regMenuObj.width)) < cursor.x
	)
	{
		close_reg();
	}
    return cursor;
}

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function getPosition(e)
{
	e = e || window.event;
	var cursor = {x:0, y:0};
	if (e.pageX || e.pageY) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	} else {
		cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
		cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}
	return cursor;
}


function _helpMain(e, sid, type)
{
	var obj1 = document.getElementById('help_table');
	var obj2 = document.getElementById('help_content');
	if(sid == 0)
	{
		help_txt = '';
		obj1.style.display = 'none';
		obj2.innerHTML = '';
	}
	else
	{
		var cur = getPosition(e);
		var screen_w = document.body.offsetWidth;
		var scroll_w = document.body.scrollLeft;
		var x = ((cur.x+270) > screen_w) ? (screen_w-275+scroll_w) : cur.x;
		obj1.style.top = (cur.y+8) + 'px';
		obj1.style.left = x + 'px';
		obj1.style.display = 'block';
		xhelpMain(sid, type);
	}
	return;
}

function xhelpMain(sid, type)
{
	x_getHelpMain(sid, type, xhelp_returnMain);
}
function xhelp_returnMain(output)
{
	document.getElementById('help_content').innerHTML = output;
	return;
}

