/************************************************************
*           web-sn_newdoc.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                     *
************************************************************/


var newDoc = new Array();
var da = document.all;

// create the array of table info to pass back to the main window
function websn_newDoc(mode) {
  // get form info
 var l = da['left'].value;
 var r = da['right'].value;
 var t = da['top'].value; 
 var b = da['bottom'].value;
 var lnk = da['link'].value;
 var ttle = da['title'].value;
 var vlnk = da['visited'].value;
 var alnk = da['active'].value;
 var scrol = da['scroll'].options(da['scroll'].selectedIndex).value;
 var bgcolr = da['chbgcolor'].value;
 var txt = da['txt'].value;
 if (mode != "edit") { 
  // build string
  newStr = "<html>\n<head>\n";
  newStr += "<title>" + ttle + "</title>\n";
  newStr += "<base href=\"" + baseStr + "\">\n";
  newStr += "<meta name=\"Application\" value=\"EditAce(http://www.web-sn.com)\">\n";
  newStr += "</head>\n";
  newStr += "<body style='margin-top:" + t + ";margin-right:" + r + ";margin-bottom:" + b + ";margin-left:" + l + "; background-color:" + bgcolr + ";'";
  newStr += " text='" + txt + "'";
  newStr += " link='" + lnk + "'";
  newStr += " vlink='" + vlnk + "'";
  newStr += " alink='" + alnk + "'";
  newStr += " scroll='" + scrol + "'><p>&nbsp;</p>";
  newStr += "</body>\n</html>";
  newDoc['String'] = newStr;
 }
 else {
  newDoc['title'] = ttle;
  newDoc['mleft'] = l;
  newDoc['mright'] = r;
  newDoc['mtop'] = t;
  newDoc['mbot'] = b;
  newDoc['lnk'] = lnk;
  newDoc['vlnk'] = vlnk;
  newDoc['alnk'] = alnk;
  newDoc['scrol'] = scrol;
  newDoc['bgcolr'] = bgcolr;
  newDoc['txt'] = txt;
 }
 window.returnValue = newDoc; // return string to main window
 window.close();
}


// update the colour indicators if a textbox is manually changed
function update(el,field) {
  switch (field) {
    case "t":
      da['tcol'].style.background = el.value;
	  break;
	case "nl":
	  da['nlcol'].style.background = el.value;
	  break;
	case "vl":
	  da['vlcol'].style.background = el.value;
	  break;
	case "al":
	  da['alcol'].style.background = el.value;
	  break;
	case "bg":
	  da['bgcol'].style.background = el.value;
	  break;
  }
}

// update the colour indicator and associated textbox with the returned value from the popup
function showCol(el1, el2) {
  col = websn_getNewCol();
  if (col != "" && col != null) {
    da[el1].value = col;
    da[el2].style.background = col;
  }
}

function websn_getNewCol() {
 if (document.createAttribute) {
   var retCol = top.dlgColHelperNew.ChooseColorDlg();
   retCol = retCol.toString(16);
   if (retCol.length < 6) {
     var tmp = "000000".substring(0,6-retCol.length);
     retCol = "#" + tmp.concat(retCol);
   }
 }
 else {
  bascol = showModalDialog("colpick.html", "", "dialogWidth:350px; dialogHeight:370px; status:no; help:no");
  if (bascol != null) {
    retCol = "#" + bascol['col'];
  }
 }
 return retCol;
}

function init() {
 if (mode == "edit") { 
  da['left'].value = curVls['mleft'];
  da['right'].value = curVls['mright'];
  da['top'].value = curVls['mtop'];
  da['bottom'].value = curVls['mbot'];
  da['link'].value = curVls['lnk'].toUpperCase();
  da['nlcol'].style.background = curVls['lnk'];
  da['title'].value = curVls['title'];
  da['visited'].value = curVls['vlnk'].toUpperCase();
  da['vlcol'].style.background = curVls['vlnk'];
  da['active'].value = curVls['alnk'].toUpperCase();
  da['alcol'].style.background = curVls['alnk'];
  var scr = curVls['scrol'] == "no" ? 1 : 0;
  da['scroll'].options[scr].selected = true;
  da['chbgcolor'].value  = curVls['bgcolr'].toUpperCase();
  da['bgcol'].style.background = curVls['bgcolr'];
  da['txt'].value = curVls['txt'].toUpperCase();
  da['tcol'].style.background = curVls['txt'];
  
 }
}
