// Java Document
extArray = new Array(".gif", ".jpg", ".png");
extArrayDocs = new Array(".pdf", ".doc", ".xls");

function LimitAttach(form, file, field) 
{
	allowSubmit = false;
	if (!file) return true;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) 
	{
		if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if (allowSubmit) 
	{
		return true;
	}
	else
		alert("Please only upload files that end in types:  " 
		+ (extArray.join("  ")) + "\nPlease select a new "
		+ "file to upload for " + field + " and submit again.");
		return false;
}

function LimitAttachDocs(form, file, field) 
{
	allowSubmit = false;
	if (!file) return true;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArrayDocs.length; i++) 
	{
		if (extArrayDocs[i] == ext) { allowSubmit = true; break; }
	}
	if (allowSubmit) 
	{
		return true;
	}
	else
		alert("Please only upload files that end in types:  " 
		+ (extArrayDocs.join("  ")) + "\nPlease select a new "
		+ "file to upload for " + field + " and submit again.");
		return false;
}

function PreviewImage(dir,form,x,y)
{
	if(x==0)
		x=500;
	if(y==0)
		y=500;
	window.open(dir+form.value,'_blank','width='+x+',height='+y);
}

function PreviewImage2(image,caption,x,y)
{
	var URL;
	URL = "openimage.php?image="+image+"&caption="+caption+"&width="+x+"&height="+y;
	window.open(URL,'_blank','width='+(x*1.1)+',height='+(y*1.5));
}

function Printable_View(URL)
{
	window.open(URL,'_blank');
}

function ExportWindow(URL)
{
	window.open(URL,'_parent', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width=250,height=150,left=20, top=20,screenX=20,screenY=20');
}

function ConfirmMessage(URL,mess)
{
	var msg;
	
	if(mess==1)
		msg="ATTENTION! If you delete this main product category, all of the sub categories associated with this product category will be deleted as well. Are you sure you would like to delete this main category and all of the associated sub categories? THIS DELETION CANNOT BE UNDONE!";
	else
		msg="Are you sure you want to delete this item?";
		
	if(confirm(msg))
		window.open(URL,'_parent');
	else
		return false;
}

var editor = null;
function initEditor(txtarea) {
  editor = new HTMLArea(txtarea);

  // comment the following two lines to see how customization works
  editor.generate();
  return false;

  var cfg = editor.config; // this is the default configuration
  cfg.registerButton({
    id        : "my-hilite",
    tooltip   : "Highlight text",
    image     : "ed_custom.gif",
    textMode  : false,
    action    : function(editor) {
                  editor.surroundHTML("<span class=\"hilite\">", "</span>");
                },
    context   : 'table'
  });

  cfg.toolbar.push(["linebreak", "my-hilite"]); // add the new button to the toolbar

  // BEGIN: code that adds a custom button
  // uncomment it to test
  var cfg = editor.config; // this is the default configuration
  /*
  cfg.registerButton({
    id        : "my-hilite",
    tooltip   : "Highlight text",
    image     : "ed_custom.gif",
    textMode  : false,
    action    : function(editor) {
                  editor.surroundHTML("<span class=\"hilite\">", "</span>");
                }
  });
  */

function clickHandler(editor, buttonId) {
  switch (buttonId) {
    case "my-toc":
      editor.insertHTML("<h1>Table Of Contents</h1>");
      break;
    case "my-date":
      editor.insertHTML((new Date()).toString());
      break;
    case "my-bold":
      editor.execCommand("bold");
      editor.execCommand("italic");
      break;
    case "my-hilite":
      editor.surroundHTML("<span class=\"hilite\">", "</span>");
      break;
  }
};
cfg.registerButton("my-toc",  "Insert TOC", "ed_custom.gif", false, clickHandler);
cfg.registerButton("my-date", "Insert date/time", "ed_custom.gif", false, clickHandler);
cfg.registerButton("my-bold", "Toggle bold/italic", "ed_custom.gif", false, clickHandler);
cfg.registerButton("my-hilite", "Hilite selection", "ed_custom.gif", false, clickHandler);

cfg.registerButton("my-sample", "Class: sample", "ed_custom.gif", false,
  function(editor) {
    if (HTMLArea.is_ie) {
      editor.insertHTML("<span class=\"sample\">&nbsp;&nbsp;</span>");
      var r = editor._doc.selection.createRange();
      r.move("character", -2);
      r.moveEnd("character", 2);
      r.select();
    } else { // Gecko/W3C compliant
      var n = editor._doc.createElement("span");
      n.className = "sample";
      editor.insertNodeAtSelection(n);
      var sel = editor._iframe.contentWindow.getSelection();
      sel.removeAllRanges();
      var r = editor._doc.createRange();
      r.setStart(n, 0);
      r.setEnd(n, 0);
      sel.addRange(r);
    }
  }
);


  /*
  cfg.registerButton("my-hilite", "Highlight text", "ed_custom.gif", false,
    function(editor) {
      editor.surroundHTML('<span class="hilite">', '</span>');
    }
  );
  */
  cfg.pageStyle = "body { background-color: #efd; } .hilite { background-color: yellow; } "+
                  ".sample { color: green; font-family: monospace; }";
  cfg.toolbar.push(["linebreak", "my-toc", "my-date", "my-bold", "my-hilite", "my-sample"]); // add the new button to the toolbar
  // END: code that adds a custom button

  editor.generate();
}
function insertHTML() {
  var html = prompt("Enter some HTML code here");
  if (html) {
    editor.insertHTML(html);
  }
}
function highlight() {
  editor.surroundHTML('<span style="background-color: yellow">', '</span>');
}


