// JavaScript Document

function posicionar() {
    var winW = 170; 
	if (navigator.appname=="Netscape") {
	  winW = window.innerWidth;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1){
	  winW = document.body.offsetWidth;
	}
	document.getElementById('Layer1').style.left= (winW-1003)/2 +"px";
	
}

function createFotos() {
	var TFotos = function() {
		this.itens = new Array();
		this.name = 'TFotos';
		this.atual = -1;
	}
	
	TFotos.prototype.instancia=document.getElementById(arguments[0]);
	TFotos.prototype.timer=(arguments[1] > 0) ? arguments[1]*1000 : 5000;
	TFotos.prototype.randomico=(arguments[2] != '') ? arguments[2] : false;
	TFotos.prototype.idtemp=this.instancia+'timer';
	
	TFotos.prototype.add = function() {
		this.itens[this.itens.length] = new Object();
		this.itens[this.itens.length-1].normal = new Image();
		this.itens[this.itens.length-1].ampliar=arguments[1];
		this.itens[this.itens.length-1].normal.src = arguments[0];
	}
	
	TFotos.prototype.setRandomize= function() {
		this.timer=arguments[0];
	}	
	
	TFotos.prototype.setTime= function() {
		this.timer=arguments[0];
	}
	
	TFotos.prototype.getTime= function() {
		return(this.timer);
	}
	
	TFotos.prototype.count = function() {
		return(this.itens.length);
	}
	
	TFotos.prototype.setInstancia = function() {
		this.instancia=arguments[0];
	}
	
	TFotos.prototype.getInstancia = function() {
		return(this.instancia);
	}
	
	TFotos.prototype.stop = function() {
		window.clearTimeout(this.idtemp);
	}
	
	TFotos.prototype.next = function() {
		this.atual=arguments[0];
		if (this.instancia.src != this.itens[arguments[0]].normal.src)
			this.instancia.src=this.itens[arguments[0]].normal.src;
		this.instancia.ampliar=this.itens[arguments[0]].ampliar;
	}
	
	TFotos.prototype.nexted = function() {
//		alert(this.itens[1].normal.src);
		if (this.count() > 1) {
		if (this.atual+1>this.count()-1) 
			return(0);
		else
			return(this.atual+1);
		} else
			return(0);
	}
	
	TFotos.prototype.start = function(obj) {
		if (this.randomico)
			this.next(Math.floor(Math.random()*(this.count())));
		else
			this.next(this.nexted());
		this.idtemp=window.setTimeout(function(){obj.start(obj)}, this.timer);
	}
	
	return(new TFotos());
}



function MM_FSNum() {
	if ((window.event.keyCode < 48) || ((window.event.keyCode > 57)) && (window.event.keyCode != 13)) window.event.returnValue=false;
}

function MM_FSFloat() {if ((window.event.keyCode >= 48) && (window.event.keyCode <= 57) || (window.event.keyCode == 44) || (window.event.keyCode == 46)) {if (window.event.keyCode == 46)window.event.keyCode=44;window.event.returnValue=true;} else window.event.returnValue=false;}



///////////////////////////////////////////////////////////////////
//   Objeto para criar campos ocultos ao abrir uma nova janela   //
//     Exemplo de uso                                            //
//          var Objetos = createOculto();                        //
//          Objetos.setMethod('get'||'post');                    //
//          Objetos.add('Id_Pedido', 2);                         //
//          Objetos.add('Id_Pedido_Fechado', 5);                 //
//			Objetos.onchange = function() {                      //
//				alert(Objetos.value);                            //
//			}                                                    //
//			Objetos.send('arquivo');                             //
///////////////////////////////////////////////////////////////////
function createOculto() {
	var TOculto = function() {
		this.itens = new Array();
		this.name = 'TOculto';
		this.value = '';
		this.method = 'post';
	}
	
	TOculto.prototype.add = function(Campo, Valor) {
		this.itens[this.itens.length] = new Object();
		this.itens[this.itens.length-1].Campo = Campo;
		this.itens[this.itens.length-1].Valor = Valor;
	}
	
	TOculto.prototype.count = function() {
		return(this.itens.length);
	}
	
	TOculto.prototype.setMethod = function(metodo) {
		this.method=metodo;
	}
	
	TOculto.prototype.onchange = '';
	
	TOculto.prototype.send = function(path, obj) {
		if (typeof(Ajax)=='function')
			Ajax(path, this, this.method);
		else
			alert('erro, faltando a implementação Ajax.');
	}

	return(new TOculto());
}


function createEditors() {	
	var TEditors = function() {
		this.itens = new Array();
	}
	TEditors.prototype.add=function(obj) {
		this.itens.push(obj);
	}
	TEditors.prototype.count=function() {
		return(this.itens.length);
	}
	TEditors.prototype.saveAll=function() {
		for(var i=0;i<this.itens.length;i++) {
			this.itens[i].nicInstances[0].saveContent();
		}
	}
	return(new TEditors);
}


// A função abaixo pega a versão mais nova do xmlhttp do IE e verifica se é Firefox. Funciona nos dois.
function createXMLHTTP() {
	if(navigator.appName == "Microsoft Internet Explorer")
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	else
		xmlHttp = new XMLHttpRequest();
	return xmlHttp;
}

function Ajax(Path, Objeto, tipo) {
	var oHTTPRequest = createXMLHTTP();
	var oStringSend = "";
	if (tipo.length == 0)
		tipo = 'get';
	if (tipo.toLowerCase() == 'post') {
		oHTTPRequest.open("post", Path, false);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	} else {
		oHTTPRequest.open("get", Path, false);
	}
  	oHTTPRequest.onreadystatechange=function() {
    	if (oHTTPRequest.readyState==4) {
			var resultado = oHTTPRequest.responseText;
            resultado = resultado.replace(/\+/g,' ');
			resultado = unescape(resultado);
			Objeto.value = resultado;
			Objeto.xml = oHTTPRequest.responseXML;
			if (typeof(Objeto.onchange) == 'function') {
				Objeto.onchange();
			}
      	}
  	}
	if (typeof(Objeto) == 'object') {
		if (typeof(Objeto.name) == 'string') {
			if (Objeto.name == 'TOculto') {
				for(i=0;i<=Objeto.count()-1;i++) {
					//alert(Objeto.itens[i].Campo + ' = '+Objeto.itens[i].Valor);
					if (oStringSend.length == 0) {
						if ( (Objeto.itens[i].Campo != '') && (Objeto.itens[i].Valor != '') )
							if (Objeto.itens[i].Valor.toString().search('&'))
								oStringSend = Objeto.itens[i].Campo + '=' + escape(Objeto.itens[i].Valor);
							else
								oStringSend = Objeto.itens[i].Campo + '=' + Objeto.itens[i].Valor;
					} else {
						if ( (Objeto.itens[i].Campo != '') && (Objeto.itens[i].Valor != '') )
							if (Objeto.itens[i].Valor.toString().search('&'))
								oStringSend += '&' + Objeto.itens[i].Campo + '=' + escape(Objeto.itens[i].Valor);
							else
								oStringSend += '&' + Objeto.itens[i].Campo + '=' + Objeto.itens[i].Valor;
					}
				}
			}
		}
	}
	if (oStringSend.length >= 0)
		oHTTPRequest.send(oStringSend);
	else
		oHTTPRequest.send(null);
}
