function extraiScript(texto){
//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
//http://forum.imasters.com.br/index.php?showtopic=165277
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            /**********************
            
            * Alterado por Micox - micoxjcg@yahoo.com.br
            * Alterei pois com o eval não executava funções.
            
            * Alterado por Everton D. Silva - everton.silva@streamingshop.com.br
            * não estava retornando o valor
            ***********************/
            var novo = document.createElement('script');
    novo.type         = 'text/javascript';
    novo.language    = 'javascript';
    novo.text = codigo;
    document.body.appendChild(novo);
    
        }
    }
}


function getHTTPObject() {
	var http = false;
	//Use IE's ActiveX items to load the file.
	if(typeof ActiveXObject != 'undefined') {
		try {http = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {http = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try {http = new XMLHttpRequest();}
		catch (e) {http = false;}
	}
	return http;
}
var http = getHTTPObject();
var id="";

function handler() {
	//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		retorno=unescape(http.responseText.replace(/\+/g,"+"));
		document.getElementById(id).innerHTML = retorno;
		extraiScript(retorno);
	}
	return true;
}

function getMethod() {
	http.open("GET", url+"?"+params, true);
	http.onreadystatechange = handler;
	http.send(null);
}

function ajaxHTML(url,params,locatio) {
	
	http.open("POST", url, true);
	if(locatio===undefined){
		id="innerfloating";
	}else{
	id=locatio;	
	}
	
	document.getElementById(id).innerHTML = "<div style='clear:both'><img src='togi/novo/Loading.gif'></div>";
	//Send the proper header infomation along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = handler;

	http.send(params);
	
	return true;
}
function out(ida){
	ida.style.color='black';
	ida.style.background="#FFF";
}
function over(ida){
	ida.style.color='#FFF';
	ida.style.background="#f0f0f0";
	//FF4F4F
}

function poss(e){
var posx = 0;
var posy = 0;

if (!e)
e = window.event;
if (e.pageX || e.pageY){
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY){
posx = e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}
var retorn=posx+","+posy;

return retorn;
}
function change_up(id,ide){
	
//	document.getElementById(id).src='togi/tab.jpg';
	document.getElementById(ide).className='tab_upper';
		
}
function change_down(id,ide){
	
//	document.getElementById(id).src='togi/undertab.jpg';
	document.getElementById(ide).className='tab_under';
	
		
}

function calledit(id,what,line){
	
	window.open("edit.php?id="+id+"&what="+what+"&line="+line,true,true);
}
function show(){
	
	document.getElementById('floating').style.visibility = "visible";
	document.getElementById('innerfloating').style.visibility = "visible";
}
function hide(){
	
	document.getElementById('floating').style.visibility = "hidden";
	document.getElementById('innerfloating').style.visibility = "hidden";
}

function call(type,id,oi,floating,event){
	
	if(document.getElementById('floating').style.visibility=="visible")
	{

hide();

ajaxHTML("edit.asp","what="+type+"&name="+id+"&line="+oi+"&floating="+floating);

 var e = poss(event);
 var a = e.split(",");

  var x=a[1]-330;
  var y=a[0]-300;

	document.getElementById('floating').style.top=x+"px";
	document.getElementById('floating').style.left=y+"px";
show();		
	}
	else
	{
		
ajaxHTML("edit.asp","what="+type+"&name="+id+"&line="+oi+"&floating="+floating);

 var e = poss(event);
 var a = e.split(",");

  var x=a[1]-330;
  var y=a[0]-300;

	document.getElementById('floating').style.top=x+"px";
	document.getElementById('floating').style.left=y+"px";
 	
show();


	
	}
	
}
function loadi(doc){
	
	ajaxHTML('selects.php','id='+doc+'&where=id','odi');

}
function select(where,what){
if(what == "undefined"){
	what = ""
}

	ajaxHTML('select.php','where='+where+'&last='+document.getElementById(where).innerHTML+"what="+what+"",where);
	
	if(document.getElementById('save').style.visibility=="hidden"){
	
		document.getElementById('save').style.visibility="visible";
	}
}

function active(what){
if(document.getElementById('update').value==""){
	document.getElementById('update').value=what;
}else{
document.getElementById('update').value=document.getElementById('update').value+","+what;
}
	
		if(document.getElementById('save').style.visibility=="hidden"){
	
		document.getElementById('save').style.visibility="visible";
	}
}

function data(where)
{

new vlaDatePicker(where, { style: 'apple_widget',format:'m/d/y', offset: { x: 3, y: 1 } });	

}
