/* Browser Detection Assignment*/
var ua = navigator.userAgent.toLowerCase(); 

// browser engine name
this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

// browser name
this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
this.isSafari      = (ua.indexOf('safari') != - 1);
this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
this.isOpera       = (ua.indexOf('opera') != -1); 
this.isIcab        = (ua.indexOf('icab') != -1); 
this.isAol         = (ua.indexOf('aol') != -1); 
this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
this.isFirebird    = (ua.indexOf('firebird/') != -1);
this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );

//--- Start IE 5.5 and 6.0 PNG Fix --- this fix does not get applied on IE 7.0 ---//
if (navigator.platform == "Win32" && this.isIE && window.attachEvent) {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var IE55
	if (Number(rslt[1]) == 5.5){
		IE55 = true;
	}
	var IEVersionsToFix = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7.0);
	var blnNeedPNGFix = false;	
	if (IEVersionsToFix){
		window.attachEvent("onload", fixPNG);
		blnNeedPNGFix = true;
	}
}






 //--------- End IE 5.5 and 6.0 PNG Fix ------------------
 
 
/* COMMON DHTML FUNCTIONS
 These are handy functions I use all the time.
 By Seth Banks (webmaster at subimage dot com)
 http://www.subimage.com/
 Up to date code can be found at http://www.subimage.com/dhtml/
 This code is free for you to use anywhere, just keep this comment block.

 X-browser event handler attachment and detachment
 @argument obj - the object to attach event to
 @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 @argument fn - function to call
*/
function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}



/*
  Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
  Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
  Gets the full width/height because it's different for most browsers.
*/
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}
/* POPUP WINDOW CODE v1.1
 Used for displaying DHTML only popups instead of using buggy modal windows.
 By Seth Banks (webmaster at subimage dot com)
 http://www.subimage.com/
 Contributions by Eric Angel (tab index code) and Scott (hiding/showing selects for IE users)
 Up to date code can be found at http://www.subimage.com/dhtml/subModal
 This code is free for you to use anywhere, just keep this comment block. */

// Popup code
var gPopupMask = null;
var gPopupContainer = null;
var gPopFrame = null;
var gReturnFunc;
var gPopupIsShown = false;
var gHideSelects = true;

var gTabIndexes = new Array();
// Pre-defined list of tags we want to disable/enable tabbing into
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	

// If using Mozilla or Firefox, use Tab-key trap.
if (!document.all) {
	document.onkeypress = keyDownHandler;
}


var grespectTop = 'false';
function showPopWin(url, width, height, returnFunc, templateID, respectTop) {

    grespectTop = respectTop;
	gPopupMask = document.getElementById("popupMask");
	gPopupContainer = document.getElementById("PopupContainer");
	gPopFrame = document.getElementById("PopupFrame");	
	
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
		gHideSelects = true;
	}
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	if (respectTop == 'true')
	{
	    centerPopWinPositiveTop(width, height);
	}
	else
	{
	    centerPopWin(width, height);
	}
	gPopupContainer.style.width = width + "px";
	
	gPopFrame.style.height = (height) + "px";
	//alert(width);
	// set the url
	gPopFrame.src = url;
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	//window.setTimeout("setPopTitle();", 600);
}

//
var gi = 0;

function centerPopWin(width, height) {
	if (gPopupIsShown == true) {
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		var theBody = document.documentElement;
		
		var scTop
		if (document.documentElement && document.documentElement.scrollTop){
			scTop = parseInt(theBody.scrollTop,10);
		}else if (document.body){
			scTop = parseInt(document.body.scrollTop,10)
		}else{
			scTop = parseInt(theBody.scrollTop,10);
		}
		//var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);				
		gPopupMask.style.height = fullHeight + "px";
		gPopupMask.style.width = fullWidth + "px";
		gPopupMask.style.top = scTop + "px";
		gPopupMask.style.left = scLeft + "px";
		window.status = gPopupMask.style.top + " " + gPopupMask.style.left + " " + gi++;
		var titleBarHeight = 0;
		
		gPopupContainer.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
		gPopupContainer.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
		//alert(fullWidth + " " + width + " " + gPopupContainer.style.left);
	}
}


function centerPopWinPositiveTop(width, height) {
    removeEvent(window, "resize", centerPopWin);
    removeEvent(window, "resize", centerPopWinPositiveTop);
    addEvent(window, "resize", centerPopWinPositiveTop);
    window.onscroll = centerPopWinPositiveTop;

	if (gPopupIsShown == true) {
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		var theBody = document.documentElement;
		
		var scTop
		if (document.documentElement && document.documentElement.scrollTop){
			scTop = parseInt(theBody.scrollTop,10);
		}else if (document.body){
			scTop = parseInt(document.body.scrollTop,10)
		}else{
			scTop = parseInt(theBody.scrollTop,10);
		}
		//var scTop = parseInt(theBody.scrollTop,10);

		var scLeft = parseInt(theBody.scrollLeft,10);				
		gPopupMask.style.height = fullHeight + "px";
		gPopupMask.style.width = fullWidth + "px";
		gPopupMask.style.top = scTop + "px";
		gPopupMask.style.left = scLeft + "px";
		window.status = gPopupMask.style.top + " " + gPopupMask.style.left + " " + gi++;
		var titleBarHeight = 0;
		
		var posGPHeight = (scTop + ((fullHeight - (height+titleBarHeight)) / 2));
		if(posGPHeight < 0)
		{
		    posGPHeight = 0;
		}
		gPopupContainer.style.top = posGPHeight + "px";
		gPopupContainer.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
		//alert(fullWidth + " " + width + " " + gPopupContainer.style.left);
	}
}

addEvent(window, "resize", centerPopWin);
window.onscroll = centerPopWin;

/*
 @argument callReturnFunc - bool - determines if we call the return function specified
 @argument returnVal - anything - return value 
*/


/**
 * Sets the popup title based on the title of the html document it contains.
 * Uses a timeout to keep checking until the title is valid.
 */


/**
 * Hides Floater window
 * Changes parent window location to src
 */


// Tab key trap. iff popup is shown and key was [TAB], suppress it.
// @argument e - event - keyboard event that caused this function to be called.
function keyDownHandler(e) {
    if (gPopupIsShown && e.keyCode == 9)  return false;
}

// For IE.  Go through predefined tags and disable tabbing into them.
function disableTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				gTabIndexes[i] = tagElements[k].tabIndex;
				tagElements[k].tabIndex="-1";
				i++;
			}
		}
	}
}

// For IE. Restore tab-indexes.


/*
* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
* Thanks for the code Scott!
*/


/*Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
  IE has a problem with wanted select form tags to always be the topmost z-index or layer*/








/***********************************************
* Floating Top Bar script- © Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 0 //set x offset of bar in pixels
var startY = 0 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"
//var divContainer='divVitrineVertical';
var largura=1024;

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}


function fnCenterVitrine(divContainer){
	barheight=document.getElementById(divContainer).offsetHeight
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	largura = (ns)?1024 : screen.width;
	
	// fecha vitrine se largura da tela < 1024
	if(largura < 1024)
	  if(ns)
	    barheight.style.visibility='hidden';
	  else
	    barheight.style.display='none';
	  
	  
	var d = document;
	function ml(id){
		var el=d.getElementById(id);
		if (!persistclose || persistclose && get_cookie("remainclosed")=="")
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : iecompattest().scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(0, ftlObj.y); // .sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml(divContainer);
	stayTopLeft();
}

function move(e){
	div = document.getElementById("movedor");
	div.style.left = e.clientX;
	div.style.top = e.clientY;
}
