//------------------------------------------------------------------------
// file:///X:/cd_rom/html/www/FURNITURE/DEUTSCH/PDS/DETAILS/701_tests.HTM

//+++ braucht main.js, dies muss vorher geladen werden! +++

// var CSAg = window.navigator.userAgent;
// var isIE_=1; // bei allen aus
// var isIE_= (document.all && CSAg.indexOf("MSIE") > 0);
var isIE_ = isIE();

function defLang ()
{ var d=document;
  var h; /* <html> */
  var lng;
  if (typeof d.documentElement != 'undefined') h=d.documentElement
  else if (typeof d.html != 'undefined') h=d.html;
  else if (d.getElementByTagName) h=d.getElementsByTagName("html")[0];
  else h=d.documentElement;

  if (typeof h.lang != 'undefined') lng=h.lang
  else if (h.getAttributeNS)
    lng=h.getAttributeNS('xml','lang')
  else
    lng=h.getAttribute('lang');

  return lng
}

function _filterDispatch(filterfun,val)
{ var tf=typeof filterfun;
  var ff=filterfun;
  if (tf == 'undefined')
  { var lng=defLang();
    if (lng == 'fa') val=toFarsiNo(val);
  }
  else
  { /* alert('1.'+tf+ff); - de bug */
    if (tf == 'string' || tf == 'String')
    { if (ff == 'farsi') val=toFarsiNo(val)
      else val='ERR';
    }
    else if (tf == 'function') val=ff(val)
    else val='ERR';
  }
  return val
}

function calculatePriority(number,filterfun)
{

  function color_(what, col)
  { if (what.style)   what.style.color=col; // N6+, IE
	  if (what.color)   what.color=col;
	  if (what.fgColor) what.fgColor=col;
	  if (typeof document.ids != 'undefined' && what.name)
	  { var styl=document.ids[what.name];
	    // for (var i in styl) alert('xx:'+styl+"."+i+": "+styl[i]);
	    if (styl) { styl.color=col; styl.fgColor=col; }
	  }
  }

  function elem_(name, number)
  { name=name+"_"+number;
    var ret=document.forms[0].elements[name];
    // ret.name__ = name;
    return ret;
  }

  //- precond: Keine Spaces davor und innerhalb der Zahl,
  //- und falls nach der Zahl Text kommt, dann muss dieser
  //- durch mindestens ein Leerzeichen von der Zahl getrennt sein.
  function value_(elem)
  { var values=elem.value.split(" ", 1);
    return values[0];
  }

  //- number ist die nummer der jeweiligen radiobutton gruppe
  //- (pro massnahme vergeben)
  var elemG= elem_("G", number);
  var elemB= elem_("B", number);
  var into=  elem_("P", number);

  var result, colorval;

  //- durchlauf des radiobutton arrays einer methode
  //- sind gewichtung und bewertung selektiert
  //- dann wird die prioritaet ausgerechnet und in das form eingetragen
  for (i=0; i< elemG.length; i++)
  	if (elemG[i].checked)
  		for (j=0; j< elemB.length; j++)
  			if (elemB[j].checked)
  			{
  			  result=
  				  value_(elemG[i]) * value_(elemB[j]);
  				colorval= (result>=30) ? 'red' : 'black';

  				color_(into, colorval);
  				result=_filterDispatch(filterfun, result);
  				into.value=result;
  				color_(into, colorval);

  				return true;
  			}
}


/*** toFarsiNo *** js22.8.2006 ***/
function toFarsiDigit(digit)
{ var uc=1776+parseInt(digit,10);
  /* return '&#'+uc+';'; */
  return String.fromCharCode(uc);
}

function toFarsiNo(num)
{ var str=num+'';
  var ret='';
  for (var i=0;i<str.length;++i)
  { var digit=str.charAt(i);
    ret+=toFarsiDigit(digit);
  }
  return ret;
}

function toFarsiNo_NU(num)
{ var str=num+'';
  for (var i=0;i<=9;++i)
  { var uc=1776+i;
    var re=new RegExp(i+'','gi');
    str=str.replace(re,'&#'+uc+';');
  }
  return str;
}


/*** colorizePriority *** js29.7.2002 ***/
function colorizePriority()
{ var f=document.forms[0];
  var elems=f.elements;

  for (var i=0; i<f.length; ++i)
  { var e=elems[i];
    if (e.name.substring(0, 2) != "P_") continue;

    if (e.value)
      calculatePriority( e.name.substring(2) );
    // ^- gleich Neuberechnen aufrufen ist einfacher ;-)
    //    aber nur wenn schon ein Wert gesezt ist, wegen
    //    Browser die defaultm?ig bei Radio-Buttons
    //    den ersten aktiv machen. (rfc, xforms & iso-html
    //    schreiben diesen Sch... vor. w3c-html l?t dies
    //    unspezifiziert.
  }

  return true;
}


//------------------------------------------------------------------------

function chgWindowName (val) // .
{ var o=self.name;
  if (typeof val != 'undefined')
  { self.name=val;
    // alert('chgWindowName: '+self.name); // DEBUG
  }
  return o;
}

/*** getAnchor *** js29.7.2002
* Return: Object mit .url & .anchor
* Anwendung: a=new JSAnchor(url); with(a) { anchor, url, ..}
***/
function JSAnchor(aurl)
{ this.orig_  = aurl;
  this.last_  = aurl;
  this.pos_   = aurl.lastIndexOf('#');
  this.url_   = aurl;
  this.anchor_= '';

  if (aurl) this.again(aurl);
}

JSAnchor.prototype.anchor = function (v)
{ var o=this.anchor_;
  if (typeof v != 'undefined') this.anchor_=v;
  return o;
}

JSAnchor.prototype.url = function (v)
{ var o=this.url_;
  if (typeof v != 'undefined') this.url_=v;
  // alert('JSAnchor::url:'+this.url_+'\n'+o); // DEBUG
  return o;
}

JSAnchor.prototype.orig = function (v)
{ var o=this.orig_;
  if (typeof v != 'undefined') this.orig_=v;
  // alert('JSAnchor::orig:'+o); // DEBUG
  return o;
}

JSAnchor.prototype.again = function (aurl)
{ this.last_ = aurl;

  if (this.pos_>=0  &&  !this.anchor_)
  { this.anchor_= aurl.substring(this.pos_); // inkl. #
    this.url_   = aurl.substring(0, this.pos_);
  }
}

JSAnchor.prototype.store = function () // js31.7.2002
{
  var value;
  if (this.anchor_) //  && !self.name)
  { var a=this.anchor_.replace('#','_anchor_'); // #,-,. verboten
    value=a;
    //alert("Anker: "+anker.url_+"\n"+anker.anchor_+", "+a+", "+self.name);
  }
  else
  { value='_anchor_'; // = top
  }

  if (!isIE_) // Da im IE, dann auch der Rest nicht mehr funkt!!!
    chgWindowName(value); // self.name=value; // HACK // XXXX
}

JSAnchor.prototype.remove = function () // js31.7.2002
{ // chgWindowName('');
  // ^- // HACK // XXXX st?bei N4x & IE ????!!!
  // aber von hier noch egal, kann vorerst auch bleiben
}

//------------------------------------------------------------------------



/*** jumpToWoReset *** js22.7.2002-
* Aufruf: <a href="..." onClick="return jumpToWoReset(this, '...');">
* sehr experimentell, da das Verhalten sehr stark von Debug-Meldungen
* beeinflusst wird.
* Weiteres Problem: IE springt nicht auf das letzte History-Element
*    sondern auf das erste, und h? mehrere Varianten der selben Seite.
*    Geht diese dann permutativ durch, bei jeden history.go(url). :(
*    L?g: Damit nur ein History-Eintrag zu dieser Url besteht,
*    bekommt die Checkliste das selbe verpasst, zum Wechseln auf
*    die Anwendenseite.
*    Allerdings, wenn er sp?r ein anderes Produkt mit der selben
*    Checkliste, oder kurz auf einen anderen Link klickt bleibt das
*    Problem.
* ....
***/
function jumpToWoReset(obj, url)
{ var h=history, l=self.location, d=self.document;
  var oldLoc=l.href,
      oldURL=d.URL,
      oldName=name;

  //~ URL bestimmen
  if (obj && typeof obj.href == "string") url=obj.href;
  if (!url) return true; // Parameter-Fehler!!
  // alert("xxx: "+url+"\n");

  //~ URL vervollst?igen, falls n?!
  // v- vorne selben Pfad wie diese Datei einh?en
  var path=url, li=l.href.lastIndexOf('/');
  if (li >= 0 && url.indexOf('/') == -1)
    path=l.href.substring(0, li+1 )+url;

  //~ Anker rausschneiden
  var anker=new JSAnchor(path);
  path=anker.url(); // exkl. Anker

  anker.store();

  //~ Aktuelle Seite stoppen, f? Fall das noch geladen wird
  if (window.stop) stop();

  //~ Versuch ?ie History dorthin zu wechseln
  // l.replace('#'); geht zumindest unter IE nicht
  h.go(path); // bei IE erst ab v5, allerdings komplett fehlerbehaftet!!

  if (!isIE_)
    path=anker.orig();
  // url inkl. Anker (wieder anh?en bzw. herstellen)
  // IE-History spinnt auch, wenn URL in History mit Anker, und
  // Suche danach ohne.

  //~ Helper Closures
  jumpTo_debug_global=function (title)
  {
    alert(title+":"+
          "\nPath:"+path+" ("+url+")"+
          "\noL:"+oldLoc+"\nnL:"+self.location.href+
          "\nrf:"+d.referrer+ // referrer nur bei http:
          "\noU:"+oldURL+"\nnU:"+self.document.URL+
          "\noN:"+oldName+"\nnN:"+name+
          "\nhC:"+h.length+
          "\ndC:"+d.closed+
          "\nFu:");
    // h[0], h.current erzeugen Rechte-Fehler!!
  }

  function jumpTo_jump()
  { var l=self.location, d=self.document;
    // oldLoc & oldURL aus dem ?egenden G?eitsbereich
    // self vor location, wegen Mehrdeutigkeit mit document.location
    // n?!

    if (true &&
        oldLoc == l.href &&
        oldURL == d.URL) // always true
    {
      //anker.remove(); // HACK // XXXX st?bei N4x & IE ????!!!
      l.href=path;
      // jumpTo_debug_global('Jump:'); // hier erlaubt
      return true; // true => wechseln
    }
    return false;
  }
  jumpTo_jump_global=jumpTo_jump;


  //~ Falls History.go() gescheitert ist ...

  //setTimeout("jumpTo_debug_global('Timer');jumpTo_jump_global();",200);
  // ^- reset unter IE, zumindest falls Seitenwechsel zulange aufgehalten?

  /*window.jumpTo_wait=true;
    setTimeout(
    "jumpTo_debug_global('Timer');window.jumpTo_wait=false;",
    500);
    while (window.jumpTo_wait) {}
  // ^- Crasht zumindest N6!!!! andere nicht getestet
  */

  // jumpTo_debug_global('Direkt'); // St? da alert() !!!

  //jumpTo_jump_global();
  // ^- wird zum Gl?terdr?falls history.go() vorher
  //    die Seite wechselte. (tested: N4.7, N6.1, IE5.5)
  // !! Leider nicht immer!, sondern nur wenn vorher ein alert()
  //    aufgerufen wurde.

  // Falls wir schon jetzt feststellen k?n, das die Seite
  // gewechselt wurde, dann um so besser.
    if (oldLoc != self.location.href ||
        oldURL != self.document.URL)
       return false;

  // ... ansonsten sp?r probieren, da:
  // a) setTimeout gecancel't wird wenn die Seite inzwischen gewechselt
  //    wurde, und
  // b) der Vergleich andernfalls bereits anders ausf?t.
  setTimeout(jumpTo_jump, 400); // mindestens 300ms f?n?!
  // ^- ?ergabe als Referenz, statt als String, bei einem
  //    zu evalierenden String m?es die .._global-Varante
  //    sein.

  return false; // false => kein Sprung von <a href="...">!
}



/*** toAnchorMatic *** js29.7.2002 ***/
function toAnchor(a)
{ a +=''; // as String
  if (a.charAt(0) != '#') a='#' + a;
  // if (a == '#') a=''; // N6 macht ohne # Probleme

  // alert('AnkerJump: '+a);

  if (a == '#' && self.location.hash == '') return;

  // self.location.href=a;
  self.location.replace(a);
}

function toAnchorMatic()
{
  if (isIE_) return;
  // alert('NonIE');

  var n=chgWindowName(); // self.name;

  if (!n) return;
  n=n.replace('_anchor_', '#');
  li=n.lastIndexOf('#');
  if (li != -1)
  { toAnchor( n.substring(li) );
    chgWindowName( n.substring(0, li ) );   // self.name=...
  }

  // more
  //var d=document;
  //if (d.forms[0]) alert('Formular?!');
}

//------------------------------------------------------------------------


function scrollTop()
{ var w=window; d=document;

  if (typeof(w.pageYOffset) == 'number')
    return w.pageYOffset;
  if (d.body && typeof d.body.scrollTop != 'undefined')
    return d.body.scrollTop;
  return undefined;
}


function showInfo(args, obj)
{ var d=document;

  if (typeof isReallyNN == 'function' && isReallyNN()
      && hasForms()
     ) return false;
  // ^- Falls aktive Checkliste, und es ist Netscape <= v4.x
  //    dann keine Einblendungen, da diese sich nicht mit Formular-
  //    feldern vertragen.

  var x,y;
  var args_=showInfo.arguments;
  var event=args[0];
  if (!event && window.event) event=window.event;

  var layer='info'+
            obj.href.substring(obj.href.lastIndexOf('#')+1 );

  // alert('showInfo: Layer='+layer); // DEBUG

  if (event.pageX) // N4x, N6
  { x=event.pageX;
    y=event.pageY;
  }
  if (event.clientX)
  { x=event.clientX;
    y=event.clientY+scrollTop();
  }

  //if (!x && event.x) { x=event.x; y=event.y+scrollTop();}

  // alert('showInfo: x,y='+x+','+y+','+scrollTop()+'\n'); // DEBUG


  // alert(layer);
  var e=layer2elem(layer);
  var top_=y+10;

  // alert('showInfo1: Elem='+e+', '+top_); // DEBUG

  /* andere Versuche:
     if (d.defaultView &&
         typeof d.defaultView.getOverrideStyle == 'function')
     { var overstyle=d.defaultView.getOverrideStyle(e, null);
       overstyle.setProperty('top', top_+' px;', '');
       alert("over");
     };

     // e.style.offsetTop=top_;
     // e.setAttribute('style', 'top: '+top_+'px;'); // hack
  */

  if (e.style)
  { if (typeof e.style.top == 'number')
      e.style.top=top_
    else
    { e.style.top=top_+'px'; }
    // ^- korrekte Form

    /*var s;
    for (var i in e.style) s += 'style.'+i+'='+'\t';
    alert(s)*/
  }
  else if (e.top)
  { e.top=top_; }

  show(layer);

  return false;
}


function hideInfo(args, obj)
{ var x,y;
  var args_=hideInfo.arguments;
  var event=args[0];
  if (!event && window.event) event=window.event;

  var layer='info'+
            obj.href.substring(obj.href.lastIndexOf('#')+1 );

  hide(layer);

  return false;
}


/*** generateInfoButton *** js14.8.2002 ***/
function generateInfoButton(obj, link, text)
{
  if (typeof isReallyNN == 'function' && isReallyNN()
      && hasForms()
     ) return;
  // ^- Falls aktive Checkliste, und es ist Netscape <= v4.x
  //    dann keine Einblendungen, da diese sich nicht mit Formular-
  //    feldern vertragen.


  var mup=
  '<a class="cHint" href="' +link+ '"\n'+
  '   onClick="return jumpToWoReset(this,\'' +link+ '\');"\n'+
  '   onMouseOver="return showInfo(arguments, this)"\n'+
  '   onMouseOut="return hideInfo(arguments, this)"\n'+
  '   >' +text+ '</a>\n';
  document.write(mup);
}
