//
// editbox code based on HTMLArea 3.0 Beta by interactivetools.com
//
// $Id: andremedeiros.js,v 0.1 2004/02/02 22:49:28 andremedeiros Exp $

// browser detection
ua		 = navigator.userAgent.toLowerCase();
is_ie	 = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1));
is_gecko = (navigator.product == "Gecko");

// some global var's
var textarea;
var editorarea;
var iframe;

// create editbox
function createEditBox(textareaId)
{
  // get the textarea
  textarea = document.getElementById(textareaId);
  // hide it
  textarea.style.display = "none";

  // create the editor area
  editorarea = document.createElement("div");
  // set it's style
  editorarea.className = "editorarea";
  // insert it before the textarea
  textarea.parentNode.insertBefore(editorarea, textarea);
  // associate action to the form submit
  textarea.form.onsubmit = function()
  {
	// put the html on the textarea
	textarea.value = editorGetHTML();
  }

  // create the toolbar
  var toolbar = document.createElement("div");
  // set it's style
  toolbar.className = "toolbar";
  // set it to the same width that the textarea, let's hope it's enough
  toolbar.style.width = textarea.style.width;

  toolbar.innerHTML  = "<img src=\"images/toolbar/bold.gif\" class=\"buttons\" onmouseover=\"setClass(this, 'raise');\" onmouseout=\"setClass(this, 'buttons');\" onmousedown=\"setClass(this, 'press');\" onmouseup=\"setClass(this, 'raise');\" onclick=\"wrapSelection('bold', false);\">";
  toolbar.innerHTML += "<img src=\"images/toolbar/italic.gif\" class=\"buttons\" onmouseover=\"setClass(this, 'raise');\" onmouseout=\"setClass(this, 'buttons');\" onmousedown=\"setClass(this, 'press');\" onmouseup=\"setClass(this, 'raise');\" onclick=\"wrapSelection('italic', false);\">";
  toolbar.innerHTML += "<img src=\"images/toolbar/underline.gif\" class=\"buttons\" onmouseover=\"setClass(this, 'raise');\" onmouseout=\"setClass(this, 'buttons');\" onmousedown=\"setClass(this, 'press');\" onmouseup=\"setClass(this, 'raise');\" onclick=\"wrapSelection('underline', false);\">";
  toolbar.innerHTML += "<img src=\"images/toolbar/toolbarseparator.gif\" class=\"separator\">";
  toolbar.innerHTML += "<img src=\"images/toolbar/blockquote.gif\" class=\"buttons\" onmouseover=\"setClass(this, 'raise');\" onmouseout=\"setClass(this, 'buttons');\" onmousedown=\"setClass(this, 'press');\" onmouseup=\"setClass(this, 'raise');\" onclick=\"wrapSelection('indent', false);\">";
  toolbar.innerHTML += "<img src=\"images/toolbar/orderedlist.gif\" class=\"buttons\" onmouseover=\"setClass(this, 'raise');\" onmouseout=\"setClass(this, 'buttons');\" onmousedown=\"setClass(this, 'press');\" onmouseup=\"setClass(this, 'raise');\" onclick=\"wrapSelection('insertorderedlist', false);\">";
  toolbar.innerHTML += "<img src=\"images/toolbar/unorderedlist.gif\" class=\"buttons\" onmouseover=\"setClass(this, 'raise');\" onmouseout=\"setClass(this, 'buttons');\" onmousedown=\"setClass(this, 'press');\" onmouseup=\"setClass(this, 'raise');\" onclick=\"wrapSelection('insertunorderedlist', false);\">";
  toolbar.innerHTML += "<img src=\"images/toolbar/toolbarseparator.gif\" class=\"separator\">";
  toolbar.innerHTML += "<img src=\"images/toolbar/link.gif\" class=\"buttons\" id=\"buttonslink\" onmouseover=\"setClass(this, 'raise');\" onmouseout=\"setClass(this, 'buttons');\" onmousedown=\"setClass(this, 'press');\" onmouseup=\"setClass(this, 'raise');\" onclick=\"wrapSelection('createlink', prompt('URL:', 'http://'));\">";
  toolbar.innerHTML += "<img src=\"images/toolbar/email.gif\" class=\"buttons\" onmouseover=\"setClass(this, 'raise');\" onmouseout=\"setClass(this, 'buttons');\" onmousedown=\"setClass(this, 'press');\" onmouseup=\"setClass(this, 'raise');\" onclick=\"wrapSelection('createlink', 'mailto:' + prompt('E-Mail:', ''));\">";
  if (is_ie) toolbar.innerHTML += "<img src=\"images/toolbar/link_e.gif\" class=\"buttons\" id=\"buttonslink\" onmouseover=\"setClass(this, 'raise');\" onmouseout=\"setClass(this, 'buttons');\" onmousedown=\"setClass(this, 'press');\" onmouseup=\"setClass(this, 'raise');\" onclick=\"wrapSelection('createlink_e', prompt('URL:', 'http://'));\">";
 
  toolbar.innerHTML += "<img src=\"images/toolbar/toolbarseparator.gif\" class=\"separator\">";
  // insert it on the editorarea element
  editorarea.appendChild(toolbar);

  // create the iframe
  iframe = document.createElement("iframe");
  // insert it on the editorarea element
  editorarea.appendChild(iframe);
  // initialize the frame
  function initFrame()
  {
	var doc = iframe.contentWindow.document;
	// set the iframe editable if mozilla
	if(is_gecko)
	{
	  try
	  {
		doc.designMode = "on";
	  }
	  catch(e)
	  {
		alert(e);
	  }
	}
	// write the starting html there
	var html;
	html  = "<html>\n";
	html += "<head>\n";
	html += "<style>\n";
	html += "body {\n";
	html += "  background: #FFFFFF;\n";
	html += "  margin: 0px;\n";
	html += "  padding: 0px;\n";
	html += "}\n";
	html += "</style>\n";
	html += "</head>\n";
	html += "<body>\n";
	// TODO: Add previous content
	html += textarea.value;
	html += "</body>\n";
	html += "</html>\n";
	// dump it on the iframe
	doc.open();
	doc.write(html);
	doc.close();
	// in ie this has to be done after initializing the document
	if(is_ie)
	{
	  doc.body.contentEditable = true;
	}
  }
  setTimeout(initFrame, is_gecko ? 10 : 0);
}

// insert a tag
function wrapSelection(command, option)
{
  var doc = iframe.contentWindow.document;
  if (is_ie && command=="createlink_e") {
  	t=(iframe.contentWindow.document.selection.createRange().text=="")?option:iframe.contentWindow.document.selection.createRange().text;
  	var link="<a target=_blank href='"+option+"'>"+t+"</a>";
  	iframe.contentWindow.document.selection.createRange().pasteHTML(link);
   }
  else
  	doc.execCommand(command, false, option);
  iframe.contentWindow.focus();
}

// return the html to the textarea
function editorGetHTML()
{
  var doc = iframe.contentWindow.document;
  return doc.body.innerHTML;
}

// change element class
function setClass(element, classId)
{
  element.className = classId;
}






//o código que se segue pertence a PAULO AFONSO - semmais.com
function fotos(caminho,id,categoria,nf){
	largura=450;altura=298;
	LeftPosition=(screen.width)?(screen.width-largura)/2:100;
	TopPosition=(screen.height)?(screen.height-altura)/2:100;
	a=window.open('manipular_imagens.php?nf='+nf+'&caminho='+caminho+'&id='+id+'&categoria='+categoria,'imagens','width='+largura+',height='+altura+',top='+TopPosition+',left='+LeftPosition+',status=1,resize=no,menubar=no,toolbar=no,scrollbars=yes');
	a.focus();
}

//o código que se segue pertence a PAULO AFONSO - semmais.com
function enviaremail(){
	largura=770;altura=550;
	LeftPosition=(screen.width)?(screen.width-largura)/2:100;
	TopPosition=(screen.height)?(screen.height-altura)/2:100;
	b=window.open('http://www.dasn.net/gestao/content.php?op=enviaremail','enviaremail','width='+largura+',height='+altura+',top='+TopPosition+',left='+LeftPosition+',status=1,resize=no,menubar=no,toolbar=no,scrollbars=yes');
	b.focus();
}
var wnd;
function abrir_imagem(url){
	imgVar = new Image();
	imgVar.src = url;
	
	if (wnd!=undefined && !wnd.closed) wnd.window.close();
	wnd=window.open("","Imagens","left=50,width=50,height=50,top=50,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1");
	
	wnd.document.write("<html><script language='JavaScript' type='text/javascript'>");
	wnd.document.write("function tamanho(){");
	wnd.document.write("if(document.images[\"img_principal\"]==undefined) {window.close();}");
	wnd.document.write("else{ window.resizeTo(document.images[\"img_principal\"].width+30, document.images[\"img_principal\"].height+60); window.focus();}");
	wnd.document.write(" }");
	wnd.document.write("</");wnd.document.write("script>");
	wnd.document.write("<body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>");
	wnd.document.write("<table width=\"100%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><center><img src=\"" + url + "\" border=\"0\" name=\"img_principal\" onLoad=\"tamanho();\" onDblClick=\"window.close();\"></center></td></tr></table>");
	wnd.document.write("</body></html>");
	
}








