var ie4 = document.all;
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all; 

function Obj(txt){
	try{
		if(arguments.length == 2){
			if(arguments[1] == 'name')
				return document.getElementsByName(txt);
			else
				return document.getElementById(txt);
		}else{
			return document.getElementById(txt);
		}
	}catch(e){
		status = 'Não foi encontrado o objeto ' + txt;
	}
}

function htcWinDisplay(tipo,w,h,titulo,disableall,conteudo,t,l){
	try{
		var b = new htcBrowserInfo();
		if(t && l){
			Obj('htcWin').style.left = l + 'px';
			Obj('htcWin').style.top = t + 'px';
		}else{
			if(Request.QueryString('subWin') == 'true'){
				Obj('htcWin').style.left = '10px';
				Obj('htcWin').style.top = '10px';
			}else{	
				Obj('htcWin').style.left = parseInt((b.screenWidth / 2) - (w / 2)) + 'px';
				Obj('htcWin').style.top = ((b.posTop + (b.screenHeight / 2)) - parseInt(h / 2)) - 100 + 'px';
			}
			//Obj('htcWin').style.left = parseInt((b.screenWidth / 2) - (w / 2)) + 'px';
			//Obj('htcWin').style.top = (b.screenHeight / 2) - parseInt(h / 2) - 100 + 'px';
		}
		Obj('htcWin').style.height = (h+40) + 'px';
		Obj('htcWin').style.width = (w+20) + 'px';
		Obj('htcWin_titulo').innerHTML = titulo;
		if(tipo == 'frame'){
			(conteudo.indexOf('?') == -1)?conteudo+='?subWin=true':conteudo+='&subWin=true';
			Obj('htcWin_conteudo').innerHTML = '<iframe id="htcWinFrame" width="'+ w +'" height="'+ h +'" src="'+ conteudo +'" scrolling="yes" frameborder="0" marginheight="0" marginwidth="0"></iframe>';
		}else{
			Obj('htcWin_conteudo').innerHTML = conteudo;
		}
		if(disableall){
			Obj('htcAllDisabled').style.height = b.fullHeight + 'px';
			Obj('htcAllDisabled').style.display = 'block';
		}
		Obj('htcWin').style.display = 'block';
	}catch(e){
		status = 'ERRO HWD- ' + e.description;
	}
}

var htcPopUpW=0;
function closehtcPopUp(){
	if(htcPopUpW){
		if(!htcPopUpW.closed){
			htcPopUpW.close();
			htcPopUpW=0;
		}
	}
}

function htcPopUWin(URLStr, left, top, width, height, sc){
	if(htcPopUpW)
		if(!htcPopUpW.closed) htcPopUpW.close();
	
	if(sc){
    var b = new htcBrowserInfo();
    left = (b.screenWidth / 2) - (width / 2);
    top = (b.screenHeight / 2) - (height / 2); 
  }	
	htcPopUpW = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

//open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbar=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function htcPopUp(name, URLStr, left, top, width, height){
	var b = new htcBrowserInfo();
	left = (b.screenWidth / 2) - (width / 2)
	top = (b.screenHeight / 2) - (height / 2)
	htcPopUpW = open(URLStr, name, 'scrollbars=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function htcBrowserInfo(){
	this.name 		= navigator.appName;
	this.codename 	= navigator.appCodeName;
	this.version 	= navigator.appVersion.substring(0,4);
	this.platform 	= navigator.platform;
	this.javaEnabled 	= navigator.javaEnabled();
	this.screenWidth 	= screen.width;
	this.screenHeight 	= screen.height;

	var Xz = 0, Py = 0, Yz = 0;
	if(navigator.appName.indexOf('Internet Explorer') != -1){
		try{
			Yz = document.body.scrollHeight;
			Xz = document.body.scrollWidth;
			Py = document.body.scrollTop;
		}catch(e){
			//alert('algo falhou');
		}
	}else{
		Yz = self.pageYOffset;
		Xz = self.pageXOffset;
	}
	this.fullHeight = (Yz == 0)?this.screenHeight:Yz;
	this.fullWidth = (Xz == 0)?this.screenWidth:Xz;
	this.posTop = Py;
}
var bi = new htcBrowserInfo();


function htcOpenPic(url,title){
	htcPopUpW = window.open(url,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	htcPopUpW.document.write('<html><head><title>'+ title +'</title>')
	htcPopUpW.document.write('<body oncontextmenu="return false;" onLoad="self.resizeTo(document.images[0].width,document.images[0].height+30);" topmargin="0" leftmargin="0"><img onmoveend="return false;" src="'+url+'"></body></html>')
	htcPopUpW.location.reload();
	htcPopUpW.focus();
}

function moveXbySlicePos(x, img){ 
	if(!document.layers){
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	}else if(img.x) x += img.x;
	return x;
}

function moveYbySlicePos (y, img) {
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}		
	} else if (img.y >= 0) y += img.y;
	return y;
}

/*controle da janela*/
var _gDrag = true;
var htcWinCorX = 0;
var htcWinCorY = 0;
var htcWinCurrent = '';
function htcWindowAn(w,h,t){
	if(t == 1 || t == 3)
		(w <= 400)?htcWin.style.width = w:htcWin.style.width = '400px';
	if(t == 2 || t == 3)
		(h <= 445)?htcWin.style.height = h:htcWin.style.height='445px';
	if(w <= 400 || h <= 445)
		setTimeout('htcWindowAn('+(w+10)+','+(h+10)+','+t+')',1);
}
function htcStartWinDrag(lay){
	if(_gDrag){
		htcWinCorX = 0;
		htcWinCorY = 0;
		htcWinCurrent = lay;
		document.onmousemove = htcWinDrag;
		document.onmouseup = htcStopWinDrag;
		document.onselectstart = cancelSelect;
		document.body.style.cursor = 'move';
	}
}
function htcStopWinDrag(){
	document.onmousemove = null;
	document.onmouseup = null;
	//document.onselectstart = startSelect;
	htcWinCurrent = '';
	document.body.style.cursor = 'auto';
}

function htcWinDrag(e){
	var mm = document.getElementById(htcWinCurrent);
	if(ns4||ns6){
		x = e.pageX;
		y = e.pageY;
	}else{
		x = event.x + document.body.scrollLeft;
		y = event.y + document.body.scrollTop;
	}
	(isNaN(x))?x = 0:x=x;
	(isNaN(y))?y = 0:y=y;
	var left = parseInt(mm.style.left.replace('px',''));
	var top = parseInt(mm.style.top.replace('px',''));
	(isNaN(left))?left = 0:left=left;
	(isNaN(top))?top = 0:top=top;
	if(htcWinCorX == 0 || htcWinCorY == 0){
		(left > x)?htcWinCorX = parseInt(left - x):htcWinCorX = parseInt(x - left);
		(top > y)?htcWinCorY = parseInt(top - y):htcWinCorY = parseInt(y - top);
		status = 'X:'+ htcWinCorX + ' | Y:'+ htcWinCorY;
	}
	//status = (parseInt(htcWinCorX) + parseInt(x)) + ' | ' + (parseInt(htcWinCorY) + parseInt(y));
	mm.style.left = x - htcWinCorX;
	mm.style.top = y - htcWinCorY;
	return true;
}
function cancelSelect(e){return false;}
function startSelect(e){return true;}

function findObj(theObj, theDoc){
	var p, i, foundObj;
	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for(i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
	return foundObj;
}

function showHideLayers(){ 
	var i, visStr, obj, args = showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3){
		if((obj = findObj(args[i])) != null){
			visStr = args[i+2];
			if(obj.style){
				obj = obj.style;
				if(visStr == 'show') visStr = 'visible';
				else if(visStr == 'hide') visStr = 'hidden';
			}
			obj.visibility = visStr;
		}
	}
}

function moveLayerToMouseLoc(theLayer, offsetH, offsetV){
	var obj;
	if ((findObj(theLayer)) != null){
		if (document.layers){//NS
			document.onMouseMove = getMouseLoc;
			obj = document.layers[theLayer];
			obj.left = mLoc.x +offsetH;
			obj.top  = mLoc.y +offsetV;
		}else if (document.all){//IE
			getMouseLoc();
			obj = document.all[theLayer].style;
			obj.pixelLeft = mLoc.x +offsetH;
			obj.pixelTop  = mLoc.y +offsetV;
		}
		showHideLayers(theLayer,'','show');
	}
}
// get mouse location
function Point(x,y) {  this.x = x; this.y = y; }
mLoc = new Point(-500,-500);

function getMouseLoc(e){
	if(!document.all){//NS
		mLoc.x = e.pageX;
		mLoc.y = e.pageY;
	}else{//IE
		mLoc.x = event.x + document.body.scrollLeft;
		mLoc.y = event.y + document.body.scrollTop;
	}
	return true;
}
//NS init:
if(document.layers){ document.captureEvents(Event.MOUSEMOVE); document.onMouseMove = getMouseLoc;}

