/*

Components of help, re-flow, and color gadgets
author: Thomas Ballard (thomas2003*esqsoft^om antibot: *=@, ^=.c)
© 2001 E.S.Q Software  More scripts and usage requirements: http://esqsoft.com

*/


//pardon my mess... I plan to return and clean this up and bring its DOM support up to date.


var mform_submit_ok=false;

var notify_me = 1;
function will_it_work(){
  //validate browser DOM (very simple, since we aren't implementing a version beyond IE, just check for the all collection)
  if(!document.all){
    if(notify_me) if(!confirm('Your browser doesn\'t support some of the features on this page.\nThis page is best view using Internet Explorer 5 or higher.\nClick Cancel to turn these errors off.')) notify_me=0;
    return 0;    
  }
  return 1;
}

function mvalidate(fobj,mval){
  var str='';
  if(mval){
    str='FORM SUBMISSION: (NEXT PAGE)\
    \n\nThis example isn\'t connected to a CGI.\
    \nNormally at this point the finished form\
    \ndata would be submitted to a CGI for storage\
    \nand the next page of some process.\
    \nLet me know if you want me to set up \
    \na CGI for you using the techniques and \
    \ncore gadgets I\'ve developed in this example.';
  }
  else{
    str='FORM SUBMISSION: (PREVIOUS PAGE)\
    \n\nThis example isn\'t connected to a CGI.\
    \nNormally at this point we would travel to\
    \nthe previous page via a javascript back,\
    \nor if it required form processing to restore\
    \na prior state then via a form submission.\
    \nLet me know if you want me to set up \
    \na CGI for you using the techniques and \
    \ncore gadgets I\'ve developed in this example.';
  }
  alert(str);
  return;
}




//
//
//  HELP GADGET STUFF
//
//

// Setup Help Array
var pha=new Array(); //associative array (similar to a hash in Perl)
pha["default"]="\
HELP >> INTRODUCTION TO HELP GADGET\
\n=================================================================================\
\nThis is an example of the help gadget. You can include detailed explanations \
\nof any page relevant topic which remains hidden unless your visitor requests \
\nit by clicking the help gadget buttons.";
pha["font"]="\
HELP >> FONTS\
\n=================================================================================\
\nYou have the ability to change the appearance of your text by selecting\
\ndifferent font families. Because your visitors may not have the same\
\nselection of fonts, you have the ability to pick a fall back scheme.\
\n\nSelect your first preference for a font face in the leftmost drop down,\
\nyour second in the next drop down, and so on.\
\n\nThe last option is a general font type, this allows your visitors computer \
\nto pick \"whatever\" font is registered as the default \"Serif\" font for example.";
function popuphelp(mval){
  if(pha[mval]) alert(pha[mval]);
  else alert(pha["default"]);
}

// Create Help Buttons 
var hbn=new Image(); hbn.src="help_circle.gif";
var hbo=new Image(); hbo.src="help_circle_over.gif";
var btnnum=0;
function makehelp(mval){
var str="<A HREF=\"javascript:popuphelp('"+mval+"');\" \
ONFOCUS='blur();' \
ONMOUSEOVER='document.mhelp"+(++btnnum)+".src=hbo.src;' \
ONMOUSEOUT='document.mhelp"+(btnnum)+".src=hbn.src;'>\
<IMG NAME='mhelp"+btnnum+"' SRC='"+hbn.src+"' BORDER=0></A>";
document.write(str);
}








//
//
//  COLOR GADGET STUFF
//
//

var DIm  = new Image(); DIm.src   = "mselect.gif";
var TIm  = new Image(); TIm.src   = "mselect_trans.gif";

function apply_mcolor(mobj,hobj,iobj,xobj){
  //mobj: the name of the input field in this instance of the color object
  //hobj: html object for color updates
  //iobj: image object (for image swapping transparent or non-trans)
  //xobj: external call for use with the reflow gadget when it's implemented in tandem
  if(!will_it_work()) return;
  else{
    mstr=""+create_mcolor(mobj,hobj,iobj,xobj)+"";
    eval('document.all.'+hobj+'.innerHTML=mstr;');
  }
}

var mchild;
function color_gadget(mobj){
  if(mobj!='[object]') mobj=eval(mobj);

  var pass_color=escape(mobj.value);
  if(!pass_color) pass_color='NONE';

  //mchild=window.open("color_gadget.html","mchild","height=350,width=450,location=no,directories=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,screenx=1,screeny=1,left=1,top=1");
  mchild=window.showModalDialog("color_gadget.html",pass_color,"dialogHeight=335px;dialogWidth=415px;resizable=yes;status=0;help=no;center=yes");
  if(mchild){ 
    if(mchild=='NONE') mchild='';
    mobj.value=mchild; 
    mobj.onchange(); 
  }
}

var tcol="";
function create_mcolor(mobj,hobj,iobj,xobj){
  //mobj: the name of the input field in this instance of the color object
  //hobj: html object for color updates
  //iobj: image object (for image swapping transparent or non-trans)
  //xobj: external call for use with the reflow gadget when it's implemented in tandem
var tobj=new Array(); tobj=mobj.split('.');
var temp_pic; (!tcol.length)?temp_pic=TIm.src:temp_pic=DIm.src;
var mcolor_str = "\
<TABLE CELLSPACING=1 CELLPADDING=0 BORDER=0 BGCOLOR=999999>\
<TR VALIGN=middle><TD>\
<A HREF=# ONCLICK='color_gadget(\""+mobj+"\");return false;' STYLE='background-color:"+tcol+";'>\
<IMG NAME="+iobj+" SRC="+temp_pic+" BORDER=0></A></TD><TD>\
<INPUT NAME="+tobj[2]+" VALUE='"+tcol+"' STYLE=\"width:122px;\" \
ONCHANGE='tcol=this.value;apply_mcolor(\""+mobj+"\",\""+hobj+"\",\""+iobj+"\",\""+xobj+"\");"+xobj+"' \
ONFOCUS='this.select();' \
SIZE=10 STYLE='top:-5px;'></TD><TD>\
<INPUT TYPE=button VALUE='Update' STYLE='width:125px;' ONCLICK='tcol=this.form."+tobj[2]+".value;apply_mcolor(\""+mobj+"\",\""+hobj+"\",\""+iobj+"\",\""+xobj+"\");"+xobj+"'>\
</TD></TR></TABLE>";
return mcolor_str;
}






//
//
//  REFLOW GADGET STUFF
//
//

function mpopulate(fobj,cobj,mobj,evaluate){
  if(!will_it_work()) return;

  //setup the formatting characteristics
  var str='<FONT STYLE="';

  if(evaluate){
    str+='font-family:';
      if(fobj.mfont1.value.length>0) str+=fobj.mfont1.value;
      if(fobj.mfont2.value.length>0) str+=','+fobj.mfont2.value;
      if(fobj.mfont3.value.length>0) str+=','+fobj.mfont3.value;
      str+=';';
  
    str+="color:";
      if(fobj.mcolor.value.length>0) str+=fobj.mcolor.value;
      str+=';';
  
    str+='font-size:';
      if(fobj.msize.value.length>0) str+=fobj.msize.value;
      if(fobj.msize_unit.value.length>0) str+=fobj.msize_unit.value;
      str+=';';
  
    str+='font-weight:';
      if(fobj.mweight.value.length>0) str+=fobj.mweight.value;
      str+=';';
  
    str+='text-decoration:';
      if(fobj.mtextdecoration.value.length>0) str+=fobj.mtextdecoration.value;
      str+=';';
  
    str+='font-style:';
      if(fobj.mstyle.value.length>0) str+=fobj.mstyle.value;
      str+=';';
  }

  str+='">';
  str+=cobj.value.substr(0,200);
  if(cobj.value.length>200) str+='...';
  str+="</FONT>";
 
  if(mobj.innerHTML) mobj.innerHTML = str;
}