function onKeyUp(e,obj){var keyPressed=e.keyCode;switch(keyPressed){case keyDown:if(!suggestionsObj.isVisible()){break}case keyUp:SuggestionsObj.onKeyUp(suggestionsObj,keyPressed);return false;case keyTab:case keyEscape:case keyEnter:return false}var val=0;if(obj.value){val=obj.value}else{return false}var lastComa=val.lastIndexOf(",");if(lastComa!=-1){val=val.substring(lastComa+1,val.length)}if(val==null||val.length==0){return false}val=val.replace(/%/g,"");if(val.length==0){return false}if(val.length==1&&val=="*"){return false}val=val.replace(/\*/g,"%");onReady=function(ajaxReq){if(ajaxReq.responseText!=null){var valArray=eval(ajaxReq.responseText);if(valArray!=null&&valArray.length>0){suggestionsObj.show(obj,valArray)}else{if(suggestionsObj.isVisible()){suggestionsObj.hide()}}}};var queryString="?val="+encodeURIComponent(val);doAjaxReq(queryString,onReady);return true}function onKeyDown(b,a){if(b.keyCode==keyTab){SuggestionsObj.onKeyPress(suggestionsObj,b)}return false}function doAjaxReq(d,a){var b;try{b=new XMLHttpRequest()}catch(c){try{b=new ActiveXObject("Msxml2.XMLHTTP")}catch(c){try{b=new ActiveXObject("Microsoft.XMLHTTP")}catch(c){alert("No Ajax Support in your browser, sorry!");return false}}}b.onreadystatechange=function(){if(b.readyState==4){a(b)}};b.open("GET","php/stlajax.php"+d,true);b.send(null)}function lk2SgV(a){parenIdx=a.indexOf("(");if(parenIdx>=0){return a.substring(0,parenIdx)}return a}SuggestionsObj.prototype.show=function showSuggestions(f,d){var a=this;if(f.keypress==null){f.onkeypress=function(g){return SuggestionsObj.onKeyPress(a,g)}}pos=DOM.getPos(f);this.sgElem=f;this.curSel=-1;this.sgDiv=document.getElementById(sgDivId);this.nrIds=d;if(this.sgDiv==null){this.sgDiv=DOM.createElement("div",{className:"suggestDiv",id:sgDivId});document.body.appendChild(this.sgDiv);if(document.body.onclick==null){document.body.onclick=function(){suggestionsObj.hide()}}}this.sgDiv.style.left=pos.x+"px";this.sgDiv.style.top=(pos.y+f.offsetHeight+2)+"px";this.sgDiv.style.width=f.offsetWidth+"px";this.sgDiv.style.maxHeight=MAX_HEIGHT+"px";this.cleanSgDiv();this.divLinks=new Array(d.length);for(var b in d){var c=DOM.createElement("a",{href:"#",id:b});c.onclick=function(){SuggestionsObj.onmouseclicksglink(a,this)};c.onmouseover=function(){SuggestionsObj.onMouseOverSgLink(a,this)};c.innerHTML=d[b][0];this.sgDiv.appendChild(c);this.divLinks[b]=c}if(this.sgDiv.offsetHeight>MAX_HEIGHT){this.sgDiv.style.height=MAX_HEIGHT+"px"}this.sgDiv.style.visibility="visible"};SuggestionsObj.prototype.setSelected=function(){if(this.divLinks!=null&&this.curSel>=0){if(this.sgElem.value.length==0){this.sgElem.value=lk2SgV(this.divLinks[this.curSel].innerHTML)}else{val=this.sgElem.value;var a=val.lastIndexOf(",");if(a!=-1){val=val.substring(0,a+1);this.sgElem.value=val+lk2SgV(this.divLinks[this.curSel].innerHTML)}else{this.sgElem.value=lk2SgV(this.divLinks[this.curSel].innerHTML)}}GraphCtl.nrIds.push(this.nrIds[this.curSel]);this.nrIds=null}this.hide()};var GraphCtl={defSz:"2",elemDiv:"filterElements",moreBtn:"elems",helpDiv:"helpDiv",cp:"cpanel",nrIds:[],elements:["C","Cr","Co","Cu","Mn","Mo","N","Nb","Ni","P","S","Si","W","V"],defElements:["C","Cr","Co","Mn","Mo","Si","W","V"],ma:false,ha:false,init:function(){if($(GraphCtl.cp)){if($("hrn").checked){GraphCtl.shRefs()}t=$("steelData");if(t){t.style.visibility="visible"}ajaxGetReq("/knives/steels/inc/graphlp.shtml",GraphCtl.createhelp);GraphCtl.adjustCpanel();GraphCtl.initRIds();GraphCtl.setupElements();zkEvent.add(document,"keydown",GraphCtl.submitOnEnter,false);zkEvent.add($("hrn"),"click",GraphCtl.shRefs,false)}},initRIds:function(){nm=decodeURIComponent(getQryParam("nm"));ni=getQryParam("ni");if(ni&&nm){nms=nm.split(",");nis=ni.split(",");for(i=0;i<nms.length;i++){nid=null;if(i<nis.length){nid=nis[i]}GraphCtl.nrIds.push(new Array(nms[i],nid))}}},adjustCpanel:function(){var a=$(GraphCtl.cp);if(a){e=$("nm");h=$("help").parentNode;e.style.width=e.offsetWidth+(a.offsetLeft+a.offsetWidth-h.offsetLeft-h.offsetWidth)-15+"px";a.style.visibility="visible"}},cleanup:function(){zkEvent.remove(document,"keydown",GraphCtl.submitOnEnter,false);zkEvent.remove($("hrn"),"click",GraphCtl.shRefs,false)},createhelp:function(a){if(a.responseText!=null){oDiv=document.createElement("div");oDiv.id="helpDiv";oDiv.className="tipDataSrc";oDiv.innerHTML=a.responseText;main=$("mainDiv");main.appendChild(oDiv)}},shRefs:function(){rule=getCSS(3,".stlGrpNm",false);if(rule){if(rule.style.display=="none"){rule.style.display="";zkTltip.tipProps.qryParam="nn"}else{rule.style.display="none";zkTltip.tipProps.qryParam="in=1&"+zkTltip.tipProps.qryParam}}},submitOnEnter:function(a){a=a?a:window.event;switch(a.keyCode){case 27:if(GraphCtl.ha){GraphCtl.hideHelp()}if(Chm.active){Chm.hideHlp()}if(GraphCtl.ma){GraphCtl.hideMore()}return true;case 67:if(a.altKey){GraphCtl.showMore()}return;case 13:if(document.hasFocus()){if(suggestionsObj!=null&&suggestionsObj.isVisible()){suggestionsObj.setSelected()}GraphCtl.onSubmit()}return true}return true},onSubmit:function(){var f="";var a="";var g="";editCtl=$("nm");if(editCtl.value==null||editCtl.value.length==0){alert("You must specify at least one steel to build the graph!");return}a=editCtl.value;ni=new Array();bHasId=false;if(GraphCtl.nrIds.length>0){snms=a.split(",");for(d=0;d<snms.length;d++){curNi="";for(j=0;j<GraphCtl.nrIds.length;j++){if(GraphCtl.nrIds[j]){sname=lk2SgV(GraphCtl.nrIds[j][0].toLowerCase());if(sname==snms[d].toLowerCase()){curNi=GraphCtl.nrIds[j][1];GraphCtl.nrIds[j]=null;bHasId=true;break}}}ni.push(curNi)}}for(var d=0;d<GraphCtl.elements.length;d++){var b=$(GraphCtl.elements[d]);if(b){if(b.checked){f+=b.value+","}}}szElem=$("sz");szVal=szElem.options[szElem.selectedIndex].value;var c="steelgraph.php?nm="+encodeURIComponent(a);if(bHasId){c+="&ni="+ni.join(",")}if(szVal!=GraphCtl.defSz){c+="&sz="+szVal}if(f.length!=0){if(f.charAt(f.length-1)==","){f=f.substring(0,f.length-1)}c+="&el="+encodeURIComponent(f)}if($("avg").checked==true){c+="&avg=1"}t=($("hrn").checked)?"1":"0";c+="&hrn="+t;c+="&gm="+$("gm").selectedIndex;document.location.href=c},setupElements:function(){var a=decodeURIComponent(getQryParam("el"));var b=null;if(a!=null&&a.length>0){b=a.split(",")}GraphCtl.ckel(b,true)},clearAll:function(){GraphCtl.ckel(GraphCtl.elements,false)},selectAll:function(){GraphCtl.ckel(GraphCtl.elements,true)},selectDefaults:function(){GraphCtl.ckel(GraphCtl.elements,false);GraphCtl.ckel(GraphCtl.defElements,true)},ckel:function(d,c){if(d!=null){for(var b=0;b<d.length;b++){var a=$(d[b]);if(a){a.checked=c}}}},showMore:function(){hDiv=$(GraphCtl.elemDiv);GraphCtl.ma=!GraphCtl.ma;if(GraphCtl.ma){if(GraphCtl.ha){GraphCtl.hideHelp()}if(Chm.active){Chm.hideHlp()}posCtrPrnt(hDiv,$("cpanel"));hDiv.style.visibility="visible";$(GraphCtl.moreBtn).innerHTML="Hide"}else{GraphCtl.hideMore()}hDiv.style.zIndex=100},hideMore:function(){$(GraphCtl.moreBtn).innerHTML="Settings";div=$(GraphCtl.elemDiv);div.style.visibility="hidden";div.style.zIndex=0;GraphCtl.ma=false},showHelp:function(){var a=$(GraphCtl.helpDiv);GraphCtl.ha=!GraphCtl.ha;if(GraphCtl.ha){if(Chm.active){Chm.hideHlp()}posByAnc(a,ge(GraphCtl.cp),5);a.style.visibility="visible"}else{a.style.visibility="hidden"}a.style.zIndex=100},hideHelp:function(){var a=$(GraphCtl.helpDiv);a.style.visibility="hidden";a.style.zIndex=0;GraphCtl.ha=false}};var Chm={chmId:"chemicalprops",chmBtn:"chmBtn",hlpDiv:null,req:null,active:false,cleanup:function(){zkEvent.remove($(Chm.chmBtn),"click",Chm.showHlp,false);Chm.cleanup();CmpC.cleanup()},showHlp:function(){Chm.active=!Chm.active;if(Chm.active){Chm.req=ajaxGetReq("/knives/steels/inc/chemicals.shtml",Chm.hlpReady);if(GraphCtl.ha){GraphCtl.hideHelp()}Chm.hlpDiv=createhelp(Chm.chmId);posByAnc(Chm.hlpDiv,ge(GraphCtl.cp),5);Chm.hlpDiv.style.visibility="visible"}else{Chm.hideHlp()}},hlpReady:function(d){if(Chm.hlpDiv){var a;try{a=d.status}catch(b){return}var c;if(a==200){Chm.hlpDiv.innerHTML=d.responseText}else{Chm.hlpDiv.innerHTML="Unable to access data, please try again."}Chm.req=null}},hideHlp:function(){if(Chm.req){Chm.req.abort()}Chm.req=null;if(Chm.hlpDiv){main=$("mainDiv");main.removeChild(Chm.hlpDiv)}Chm.active=false}};function createhelp(a){oDiv=document.createElement("div");oDiv.id=a;oDiv.className="tipDataSrc";oDiv.innerHTML="Retreiving Data, please wait...";oDiv.style.zIndex=100;main=$("mainDiv");main.appendChild(oDiv);return oDiv}zkTltip.tipProps={srcType:"qryParam",ctSrc:"ajax",qryParam:"nn",sticky:false,bShowCB:true,posFn:zkTltip.posAtSrc,objPreProc:zkTltip.ppStdStk};zkTltip.req=null;zkTltip.qryParam=function(a,c){if(c){var b=zkTltip.getTipCls(c.className);return b.substring(3)}return null};zkAjaxReqFn=function(b,a){zkTltip.req=createAjaxReq();zkTltip.req.onreadystatechange=function(){if(zkTltip.req.readyState==4){zkTltip.responseReady(zkTltip.req,a)}};zkTltip.req.open("GET","php/stlajax.php?"+b,true);zkTltip.req.send(null);return true};zkTltip.responseReady=function(req,stl){var status;try{status=req.status}catch(e){return}var rspObj;if(status==200){rspObj=eval("("+req.responseText+")")}else{rspObj={ttl:"Error!",msg:"No data available!"}}req.onreadystatechange=function(){};req=null;zkTltip.respRecd=true;zkTltip.genTipBody(rspObj.msg,rspObj.ttl,"stl"+stl,true);zkTltip.req=null};zkTltip.zkOnHide=function(){if(zkTltip.req){zkTltip.req.abort();zkTltip.resetReqFlags()}};zkEvent.addLoadEvent(GraphCtl.init);zkEvent.add(window,"unload",GraphCtl.cleanup);
