/* Version: $Header: /dot/device/dcdevel_01/CVSROOT/dcl/package/dclbasic/dclsite/include/js/include.js,v 1.19 2002/01/30 15:54:52 tim Exp $ */
/* <[docvers:"/dclsite/include/js/include.js"=2002013001]> */

function getroot()
{ var myroot = parent;
  
  while (myroot.parent && myroot.parent.frames && myroot.parent.frames[ 0 ])
  	{ if (myroot == myroot.parent) break;
  	  myroot = myroot.parent;
	}
  
  return myroot;
}

function getrootpath()
{ myroot =  parent;
  mypath = 'parent';
  
  while (myroot.parent && myroot.parent.frames && myroot.parent.frames[ 0 ])
  	{ if (myroot == myroot.parent) break;
  	  myroot = myroot.parent;
  	  mypath = mypath + '.parent';
	}
	
  return mypath;
}

function getdoc(which,myroot)
{ var inx;
  var myfund;
  
  if (myroot == null) myroot = getroot();

  if (myroot.frames[ which ]) return myroot.frames[ which ].document;
  	
  for (inx = 0; myroot.frames[ inx ]; inx++)
  	{ myfund = getdoc(which,myroot.frames[ inx ]);
  	  
  	  if (myfund) return myfund;
  	}
  	
  return null;
}

function getdocpath(which,myroot)
{ var inx;
  var myfund;

  if (myroot == null) myroot = getroot();

  if (myroot.frames[ which ]) return 'frames[ "' + myroot.frames[ which ].name + '" ]';
  
  for (inx = 0; myroot.frames[ inx ]; inx++)
  	{ myfund = getdocpath(which,myroot.frames[ inx ]);
  	  
  	  if (myfund) return 'frames[ "' + myroot.frames[ inx ].name + '" ].' + myfund;
  	}
  	
  return null;
}

function getsubmit(which,myroot)
{ mysubmit = getrootpath() + '.' + getdocpath(which,myroot) + '.document.forms[ 0 ].submit()';
  
  return mysubmit;
}

function getloc(which,myroot)
{ var inx;
  var myfund;
  
  if (myroot == null) myroot = getroot();

  if (myroot.frames[ which ]) return myroot.frames[ which ].location;
  
  for (inx = 0; myroot.frames[ inx ]; inx++)
  	{ myfund = getloc(which,myroot.frames[ inx ]);
  	  
  	  if (myfund) return myfund;
  	}
  	
  return null;
}

function getframe(which,myroot)
{ var inx;
  var myfund;
  
  if (myroot == null) myroot = getroot();

  if (myroot.frames[ which ]) return myroot.frames[ which ];
  
  for (inx = 0; myroot.frames[ inx ]; inx++)
  	{ myfund = getframe(which,myroot.frames[ inx ]);
  	  
  	  if (myfund) return myfund;
  	}
  	
  return null;
}

function settitphp(tit,add)
{ myframe = getframe('title',null);

  if (myframe)
	if (myframe.whoami)
	  { myframe.setTitle(tit,add);
	  }
}

var statusbar_blink = "no";
var _global_statusvisible = 0;

function set_statustext(message)
{ var speed=400;

  if (statusbar_blink == "yes")
	{ if (_global_statusvisible == 0)
		{ window.status = message;
		  _global_statusvisible = 1;
		}
	  else
		{ window.status = "";
		  _global_statusvisible = 0;
		}

	  setTimeout('set_statustext("' + message + '")', speed);
	}
  else
	window.status = message;
}

function To8859(mystr)
{ if (navigator.platform != "MacPPC") 
    return mystr;
    
  newstr = "";
  
  for (jnx = 0; jnx < mystr.length; jnx++)
	{ if (mystr.charCodeAt(jnx) == 128)
		newstr += String.fromCharCode(196);
	  else
	  if (mystr.charCodeAt(jnx) == 133)
		newstr += String.fromCharCode(214);
	  else
	  if (mystr.charCodeAt(jnx) == 134)
		newstr += String.fromCharCode(220);
	  else
	  if (mystr.charCodeAt(jnx) == 138)
		newstr += String.fromCharCode(228);
	  else
	  if (mystr.charCodeAt(jnx) == 154)
		newstr += String.fromCharCode(246);
	  else
	  if (mystr.charCodeAt(jnx) == 159)
		newstr += String.fromCharCode(252);
	  else
	  if (mystr.charCodeAt(jnx) == 167)
		newstr += String.fromCharCode(223);
	  else
		newstr += mystr.substr(jnx, 1);
	}

  return newstr;
}

function delete_prompt_it(msg)
  { var qdel = confirm(msg);
   	  
   	if ((qdel != null) && (qdel != ''))
   	  { document.forms[ 0 ].deleteit.value=1;
   	    document.forms[ 0 ].submit();
   	  }
  }

function sync_prompt_it(msg)
  { var qdel = confirm(msg);

        if ((qdel != null) && (qdel != ''))
          { document.forms[ 0 ].syncit.value=1;
            document.forms[ 0 ].submit();
          }
  }

function Form_CheckRequired(reqfields,errormsg)
{ var theform  = document.forms[ 0 ];
  var is_complete = true;

  for (var i = 0; i < reqfields.length; i++)
	{ if (theform.elements[ reqfields[ i ] ].value == "")
		is_complete = false;
	}

  if (! is_complete)
	alert(errormsg);

  return is_complete;
}

function Form_ElementValue(felement)
{ fetype  = felement.type;
  fevalue = "";
			  
  if (fetype == "checkbox" || fetype == "radio")
	{ if (felement.checked) 
		{ if (felement.value == "Array")
			{ for (i = 0; i < felement.length; i++)
	   			{ if (felement.options[ i ].selected == true)
				    { if (fevalue != "")
				        fevalue += '###' + felement.options[ i ].value;
				      else
				        fevalue += felement.options[ i ].value;
				    }
				}
			}
		  else
			fevalue = felement.value;
		}
	}
  else
  if (fetype == "select-one")
	{ myindex = felement.selectedIndex;
	  fevalue = felement.options[ myindex ].value;
	}
  else
  if (fetype == "select-multiple")
	{ for (i = 0; i < felement.length; i++)
		{ if (felement.options[ i ].selected == true)
		    { if (fevalue != "")
		        fevalue += '###' + felement.options[ i ].value;
		      else
		        fevalue += felement.options[ i ].value;
		    }
		}
	}
  else
	fevalue = felement.value;
			  
  return fevalue;
}

function AssistantForm_submit(href,val)
{ var myform  = document.forms[ 0 ];
  
  myform.link.value = val;
  myform.action = href;  
  myform.submit();
}
