/************************************************************
*           web-sn_frmprops.js - part of EditAce            *
*           copyright Simon Norris 2002                     *
*           email: si@web-sn.com                            *
*           EditAce home page: http://www.web-sn.com        *
*                                                           *
*           Removal or modification of this notice is       *
*		    a violation of copyright and the terms of use   *
*           Last Modified: June 24 2002                     *
************************************************************/



/* write form controls to the editor */


// write form tags
function websn_writeForm() {
  var sname = document.all['form_name'].value;
  var saction = document.all['form_action'].value;
  var smethod = document.all['form_method'].options(document.all['form_method'].selectedIndex).value;
  // assemble string to write
  var scontent = "<form name='" + sname + "' method='" + smethod + "' action='" + saction + "'>&nbsp;</form>";
  var frm = new Array();
  frm['path'] = null;
  frm['content'] = scontent;
  window.returnValue = frm; // return the info to main window
  window.close();
 }
 
// write checkbox
function websn_writeCheckbox() {
  var sname = document.all['checkbox_name'].value;
  var chkbxclass = document.all['checkbox_class'].value;
  var chkbxvalue = document.all['checkbox_value'].value;
  var scontent = "<input type='checkbox' name='" + sname + "' class='" + chkbxclass + "' value='" + chkbxvalue + "'>";
  var frm = new Array();
  frm['path'] = null;
  frm['content'] = scontent;
  window.returnValue = frm;
  window.close();
 }
 
// write radio button
function websn_writeRadio() {
  var sname = document.all['radio_name'].value;
  var radioclass = document.all['radio_class'].value;
  var radiovalue = document.all['radio_value'].value;
  var scontent = "<input type='radio' name='" + sname + "' class='" + radioclass + "' value='" + radiovalue + "'>";
  var frm = new Array();
  frm['path'] = null;
  frm['content'] = scontent;
  window.returnValue = frm;
  window.close();
 }
 
// write textbox
function websn_writeTextbox() {
  var sname = document.all['text_name'].value;
  var txtclass = document.all['text_class'].value;
  var ssize = document.all['text_size'].value;
  var svalue = document.all['text_value'].value;
  var scontent = "<input type='text' name='" + sname + "' class='" + txtclass + "' size='" + ssize + "' value='" + svalue + "'>";
  var frm = new Array();
  frm['path'] = null;
  frm['content'] = scontent;
  window.returnValue = frm;
  window.close();
 }
 
// write password box
function websn_writePasswordbox() {
  var sname = document.all['ptext_name'].value;
  var ptxtclass = document.all['ptext_class'].value;
  var ssize = document.all['ptext_size'].value;
  var scontent = "<input type='password' name='" + sname + "' class='" + ptxtclass + "' size='" + ssize + "'>";
  var frm = new Array();
  frm['path'] = null;
  frm['content'] = scontent;
  window.returnValue = frm;
  window.close();
 }
 
// write button (button, submit, or reset) 
function websn_writeButton() {
  var sname = document.all['button_name'].value;
  var svalue = document.all['button_value'].value;
  var sclass = document.all['button_class'].value;
  var stype = document.all['button_type'].options(document.all['button_type'].selectedIndex).value;
  var scontent = "<input type='" + stype + "' class='" + sclass + "' value='" + svalue + "' name='" + sname + "'>";
  var frm = new Array();
  frm['path'] = null;
  frm['content'] = scontent;
  window.returnValue = frm;
  window.close();
 }
 
// write textarea
function websn_writeTextarea() {
  var sname = document.all['textarea_name'].value;
  var scols = document.all['textarea_cols'].value;
  var sclass = document.all['textarea_class'].value;
  var srows = document.all['textarea_rows'].value;
  var scontent = "<textarea name='" + sname + "' class='" + sclass + "' rows='" + srows + "' cols='" + scols + "'></textarea>";
  var frm = new Array();
  frm['path'] = null;
  frm['content'] = scontent;
  window.returnValue = frm;
  window.close();
 }
 
// write file box
function websn_writeFileinput() {
  var sname = document.all['file_name'].value;
  var sclass = document.all['file_class'].value;
  var scontent = "<input type='file' class='" + sclass + "' name='" + sname + "'>";
  var frm = new Array();
  frm['path'] = null;
  frm['content'] = scontent;
  window.returnValue = frm;
  window.close();
 }
 
// prepare for select box
function websn_prepSelect() {
  var sname = document.all['select_name'].value;
  var sclass = document.all['select_class'].value;
  var opt = document.all['select_options'].value;
  var h = 170; // the starting height
    for (i=2;i<opt;i++) 
	  { // add 25 pixels to the height for each option required, stop if height gets to 600
	    if (h < 600)
	     {h = h + 25;}
	  }	
  var j = h;
  var frm = new Array();
  frm['path'] = "includes/makeselect.asp?name=" + sname + "&class=" + sclass + "&opt=" + opt + "&h=" + j;
  frm['h'] = h;
  frm['content'] = null;
  window.returnValue = frm; // return info for new window
  window.close();
 }

 // validate select options. if ok is clicked then there must be a number
function websn_chkNum(val) {
  var msg = "Please enter a NUMBER in the \"Number of List Items\" box";
  if (val != "") {
       var val2 = val;
       val2 = parseInt(val);
	   
	   if (isNaN(val2)) { // it's not a number
	      alert(msg);
		  document.all['select_options'].focus();
		  return false;
	   }
	   else { // it's a number
	      websn_prepSelect();
	   }
  }
  else { // box is empty
    alert(msg);
    document.all['select_options'].focus();
    return false;
  }
}
