//jquery.patchcord.js
jQuery.fn.patchcord=function(options){return this.each(function(){var settings={left_contact:'',wire:'',right_contact:'',strands:'',lengthInInches:0};if(typeof contactLabelCache=='undefined'){contactLabelCache={};}
if(typeof wireLabelCache=='undefined'){wireLabelCache={};}
if(options){jQuery.extend(settings,options);}
if(isNaN(settings.lengthInInches)){settings.lengthInInches=0;}
if(!settings.left_contact.length){$("td.contact_left_img img",this).attr("src",'contact_holder_active.gif');$("td.left_label",$(this).parents("table").eq(0).prev()).html('');}else{if(settings.strands.length){var imgSrc='images/'+settings.left_contact+'_L_'+settings.strands+'.jpg';}else{var imgSrc='images/'+settings.left_contact+'_L.jpg';}
$("td.contact_left_img img",this).attr("src",imgSrc);var $selectedLeft=$("#contact_codes").find("a[@rel="+settings.left_contact+"]").eq(0);var leftLabel=$selectedLeft.html();if($selectedLeft.attr("freq").length){leftLabel+=' ('+$selectedLeft.attr("imp")+' Ohm, '+$selectedLeft.attr("freq")+' GHz)';}
if($selectedLeft.attr("amp").length){var ampVal=$selectedLeft.attr("amp");var ampLabel='Amps';if(ampVal=='1'){ampLabel='Amp';}
leftLabel+=' ('+ampVal+' '+ampLabel+')';}
$("td.left_label",$(this).parents("table").eq(0).prev()).html(leftLabel);}
$(this).parent().next().html('');if(!settings.right_contact.length){if(settings.left_contact.length&&settings.wire.length){$("tr td.contact_right_img img",this).attr("src",'contact_holder_active.gif');}else{$("tr td.contact_right_img img",this).attr("src",'contact_holder_disabled.gif');}
$("td.right_label",$(this).parents("table").eq(0).prev()).html('');}else{var imgSrc='images/'+settings.right_contact+'_R_'+settings.strands+'.jpg';$("tr td.contact_right_img img",this).attr("src",imgSrc);if(settings.right_contact=='000'){$("td.right_label",$(this).parents("table").eq(0).prev()).html('');$(this).parent().next().html('<span style="display:block;width:218px;"></span>');}else{var $selectedRight=$("#contact_codes").find("a[@rel="+settings.right_contact+"]").eq(0);var rightLabel=$selectedRight.html();if($selectedRight.attr("freq").length){rightLabel+=' ('+$selectedRight.attr("imp")+' Ohm, '+$selectedRight.attr("freq")+' GHz)';}
if($selectedRight.attr("amp").length){var ampVal=$selectedRight.attr("amp");var ampLabel='Amps';if(ampVal=='1'){ampLabel='Amp';}
rightLabel+=' ('+ampVal+' '+ampLabel+')';}
$("td.right_label",$(this).parents("table").eq(0).prev()).html(rightLabel);}}
if(!settings.wire.length){$("tr td.wire_img img",this).attr("src",'wire_holder_active.gif');$("td.wire_label",$(this).parents("table").eq(0).prev()).html('');}else{var imgSrc='images/'+settings.wire+'.jpg';$("tr td.wire_img img",this).attr("src",imgSrc);var $selectedWire=$("#wire_codes").find("a[@rel^="+settings.wire+"]").eq(0);var wireLabel=$selectedWire.html();if($selectedWire.attr("freq").length){wireLabel+=' ('+$selectedWire.attr("imp")+' Ohm, '+$selectedWire.attr("freq")+' GHz)';}
if($selectedWire.attr("amp").length){var ampVal=$selectedWire.attr("amp");var ampLabel='Amps';if(ampVal=='1'){ampLabel='Amp';}
wireLabel+=' ('+ampVal+' '+ampLabel+')';}
$("td.wire_label",$(this).parents("table").eq(0).prev()).html(wireLabel);}
var metersConversion=jQuery.patchcord.convertToMeters(settings.lengthInInches);var meterLabel='';if(settings.lengthInInches<=0){meterLabel='';}else if(settings.lengthInInches<18){meterLabel=String(metersConversion*1000)+'mm';}else{meterLabel=String(metersConversion)+'m';}
if(meterLabel.length){$("td.dimension_label",this).html('['+meterLabel+']<br/>'+settings.lengthInInches+'in.');}else{$("td.dimension_label",this).html('&nbsp;');}});};jQuery.patchcord={convertToMeters:function(lengthInInches){return(lengthInInches*25.4/1000).toFixed(3);},convertToInches:function(lengthInMeters){return lengthInMeters*39.37;}};

/**
 * Cookie plugin
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('n.5=v(9,d,2){8(f d!=\'F\'){2=2||{};4 3=\'\';8(2.3&&(f 2.3==\'l\'||2.3.k)){4 6;8(f 2.3==\'l\'){6=D C();6.B(6.x()+(2.3*z*m*m*A))}j{6=2.3}3=\'; 3=\'+6.k()}4 a=2.a?\'; a=\'+2.a:\'\';4 7=2.7?\'; 7=\'+2.7:\'\';4 b=2.b?\'; b\':\'\';c.5=[9,\'=\',q(d),3,a,7,b].s(\'\')}j{4 g=t;8(c.5&&c.5!=\'\'){4 h=c.5.w(\';\');y(4 i=0;i<h.e;i++){4 5=n.p(h[i]);8(5.o(0,9.e+1)==(9+\'=\')){g=u(5.o(9.e+1));E}}}r g}};',42,42,'||options|expires|var|cookie|date|domain|if|name|path|secure|document|value|length|typeof|cookieValue|cookies||else|toGMTString|number|60|jQuery|substring|trim|encodeURIComponent|return|join|null|decodeURIComponent|function|split|getTime|for|24|1000|setTime|Date|new|break|undefined'.split('|'),0,{}));


/*
 * jQuery form plugin
 * @requires jQuery v1.0.3
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id$
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('8.h.1n=7(2){5(z 2==\'7\')2={A:2};2=8.1Y({Y:3.1s(\'1v\')||\'\',13:3.1s(\'13\')||\'1f\'},2||{});2.A=2.A||2.1w;2.U=2.U||2.1x;2.m=2.m||2.13;4 a=3.18(2.C);5(2.U&&2.U(a,3,2)===17)b;4 q=8.19(a);5(2.m.1y()==\'1f\'){2.Y+=(2.Y.1z(\'?\')>=0?\'&\':\'?\')+q;2.w=B}p 2.w=q;4 $6=3,D=[];5(2.14)D.g(7(){$6.14()});5(2.1c)D.g(7(){$6.1c()});5(!2.1A&&2.1h){4 1i=2.A||7(){};D.g(7(w,S){8(2.1h).1B(w).1C().G(1i,[w,S])})}p 5(2.A)D.g(2.A);2.A=7(w,S){u(4 i=0,d=D.l;i<d;i++)D[i](w,S)};8.1D(2);b 3};8.h.1P=7(2){b 3.G(7(){8("k:R,k:N,1F:R",3).1G(7(o){4 $6=3.6;$6.s=3;5(3.m==\'N\'){5(o.1j!=X){$6.H=o.1j;$6.F=o.1H}p 5(z 8.h.J==\'7\'){4 J=$(3).J();$6.H=o.1k-J.1I;$6.F=o.1m-J.1J}p{$6.H=o.1k-3.1K;$6.F=o.1m-3.1M}}1N(7(){$6.s=$6.H=$6.F=B},10)})}).R(7(e){8(3).1n(2);b 17})};8.h.18=7(C){4 a=[];5(3.l==0)b a;4 6=3[0];4 Q=C?6.1q(\'*\'):6.1R;5(!Q)b a;u(4 i=0,d=Q.l;i<d;i++){4 9=Q[i];4 n=9.c;5(!n)V;5(C&&6.s&&9.m=="N"){5(!9.15&&6.s==9)a.g({c:n+\'.x\',f:6.H},{c:n+\'.y\',f:6.F});V}4 v=8.O(9,1d);5(v===B)V;5(v.1a==1b){u(4 j=0,1o=v.l;j<1o;j++)a.g({c:n,f:v[j]})}p a.g({c:n,f:v})}5(!C&&6.s){4 16=6.1q("k");u(4 i=0,d=16.l;i<d;i++){4 k=16[i];4 n=k.c;5(n&&!k.15&&k.m=="N"&&6.s==k)a.g({c:n+\'.x\',f:6.H},{c:n+\'.y\',f:6.F})}}b a};8.h.1W=7(C){b 8.19(3.18(C))};8.h.1X=7(r){4 a=[];3.G(7(){4 n=3.c;5(!n)b;4 v=8.O(3,r);5(v&&v.1a==1b){u(4 i=0,d=v.l;i<d;i++)a.g({c:n,f:v[i]})}p 5(v!==B&&z v!=\'X\')a.g({c:3.c,f:v})});b 8.19(a)};8.h.O=7(r){4 E,W;u(4 i=0,d=3.l;i<d;i++){4 9=3[i];4 v=8.O(9,r);5(v===B||z v==\'X\'||(v.1a==1b&&!v.l))V;5(9.m!=\'11\')b v;W=W||9.c;5(W!=9.c)b E;E=E||[];E.g(v)}b E};8.O=7(9,r){4 n=9.c,t=9.m,I=9.1e.1g();5(z r==\'X\')r=1d;5(r&&(!n||9.15||t==\'M\'||(t==\'11\'||t==\'1p\')&&!9.1r||(t==\'R\'||t==\'N\')&&9.6&&9.6.s!=9||I==\'P\'&&9.Z==-1))b B;5(I==\'P\'){4 T=9.Z;5(T<0)b B;4 a=[],12=9.2;4 L=(t==\'P-L\');4 d=(L?T+1:12.l);u(4 i=(L?T:0);i<d;i++){4 K=12[i];5(K.1L){4 v=8.1O.1Q&&!(K.1S[\'f\'].1T)?K.1t:K.f;5(L)b v;a.g(v)}}b a}b 9.f};8.h.1c=7(){b 3.G(7(){8(\'k,P,1l\',3).1u()})};8.h.1u=8.h.1Z=7(){b 3.G(7(){4 t=3.m,I=3.1e.1g();5(t==\'1t\'||t==\'1E\'||I==\'1l\')3.f=\'\';p 5(t==\'11\'||t==\'1p\')3.1r=17;p 5(I==\'P\')3.Z=-1})};8.h.14=7(){b 3.G(7(){5(z 3.M==\'7\'||(z 3.M==\'1U\'&&!3.M.1V))3.M()})}',62,124,'||options|this|var|if|form|function|jQuery|el||return|name|max||value|push|fn|||input|length|type||ev|else||successful|clk||for||data|||typeof|success|null|semantic|callbacks|cbVal|clk_y|each|clk_x|tag|offset|op|one|reset|image|fieldValue|select|els|submit|status|index|beforeSubmit|continue|cbName|undefined|url|selectedIndex||checkbox|ops|method|resetForm|disabled|inputs|false|formToArray|param|constructor|Array|clearForm|true|tagName|GET|toLowerCase|target|oldSuccess|offsetX|pageX|textarea|pageY|ajaxSubmit|jmax|radio|getElementsByTagName|checked|attr|text|clearFields|action|after|before|toUpperCase|indexOf|dataType|html|evalScripts|ajax|password|button|click|offsetY|left|top|offsetLeft|selected|offsetTop|setTimeout|browser|ajaxForm|msie|elements|attributes|specified|object|nodeType|formSerialize|fieldSerialize|extend|clearInputs'.split('|'),0,{}));

/**
 *  jQuery Plugin highlightFade (jquery.offput.ca/highlightFade)
 *  (c) 2006 Blair Mitchelmore (offput.ca) blair@offput.ca
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('6.1T.f=q(E){k o=(E&&E.A==1b)?{v:E}:E||{};k d=6.f.T;k i=o[\'D\']||d[\'D\'];k a=o[\'z\']||d[\'z\'];k I={\'Y\':q(s,e,t,c){5 n(s+(c/t)*(e-s))},\'1B\':q(s,e,t,c){5 n(s+O.1E(((c/t)*1I)*(O.1e/1J))*(e-s))},\'1f\':q(s,e,t,c){5 n(s+(O.1j(c/t,2))*(e-s))}};k t=(o[\'u\']&&o[\'u\'].A==R)?o[\'u\']:I[o[\'u\']]||I[d[\'u\']]||I[\'Y\'];j(d[\'u\']&&d[\'u\'].A==R)t=d[\'u\'];5 l.1i(q(){j(!l.4)l.4={};k e=(l.4[a])?l.4[a].p:6.f.11(l,a)||[7,7,7];k c=6.f.G(o[\'v\']||o[\'1m\']||o[\'1n\']||d[\'v\']||[7,7,m]);k s=6.K(o[\'K\']||d[\'K\']);k r=o[\'P\']||(l.4[a]&&l.4[a].J)?l.4[a].J:6.1S(l,a);j(o[\'p\']||d[\'p\'])r=6.f.M(e=6.f.G(o[\'p\']||d[\'p\']));j(1p o[\'P\']!=\'16\')r=o[\'P\'];j(l.4[a]&&l.4[a].H)Q.12(l.4[a].H);l.4[a]={C:((s.1q)/i),D:i,B:0,v:c,p:e,J:r,z:a};6.f(l,a,o[\'1u\'],t)})};6.f=q(e,a,o,t){e.4[a].H=Q.1K(q(){k 14=t(e.4[a].v[0],e.4[a].p[0],e.4[a].C,e.4[a].B);k 13=t(e.4[a].v[1],e.4[a].p[1],e.4[a].C,e.4[a].B);k 15=t(e.4[a].v[2],e.4[a].p[2],e.4[a].C,e.4[a].B);6(e).X(a,6.f.M([14,13,15]));j(e.4[a].B++>=e.4[a].C){6(e).X(a,e.4[a].J||\'\');Q.12(e.4[a].H);e.4[a]=N;j(o&&o.A==R)o.1F(e)}},e.4[a].D)};6.f.T={v:[7,7,m],D:1G,K:1L,z:\'18\'};6.f.G=q(c,d){k 8;j(c&&c.A==1M&&c.1O==3)5 c;j(8=/W\\(\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*\\)/.L(c))5[n(8[1]),n(8[2]),n(8[3])];F j(8=/W\\(\\s*([0-9]+(?:\\.[0-9]+)?)\\%\\s*,\\s*([0-9]+(?:\\.[0-9]+)?)\\%\\s*,\\s*([0-9]+(?:\\.[0-9]+)?)\\%\\s*\\)/.L(c))5[U(8[1])*2.V,U(8[2])*2.V,U(8[3])*2.V];F j(8=/#([a-w-x-9]{2})([a-w-x-9]{2})([a-w-x-9]{2})/.L(c))5[n("y"+8[1]),n("y"+8[2]),n("y"+8[3])];F j(8=/#([a-w-x-9])([a-w-x-9])([a-w-x-9])/.L(c))5[n("y"+8[1]+8[1]),n("y"+8[2]+8[2]),n("y"+8[3]+8[3])];F 5 6.f.19(c)||d||N};6.f.M=q(a){5"W("+a.1c(",")+")"};6.f.11=q(e,a,b){k s,t;b=b||10;t=a=a||6.f.T[\'z\'];1l{s=6(e).X(t||\'18\');j((s!=\'\'&&s!=\'17\')||(e.1r.Z()=="1s")||(!b&&e.4&&e.4[a]&&e.4[a].p))1v;t=10}1y(e=e.1z);j(!b&&e.4&&e.4[a]&&e.4[a].p)s=e.4[a].p;j(s==16||s==\'\'||s==\'17\')s=[7,7,7];5 6.f.G(s)};6.f.19=q(c){j(!c)5 N;1d(c.1k(/^\\s*|\\s*$/g,\'\').Z()){h\'1w\':5[0,7,7];h\'1A\':5[0,0,0];h\'1C\':5[0,0,7];h\'1H\':5[7,0,7];h\'1N\':5[m,m,m];h\'1P\':5[0,m,0];h\'1R\':5[0,7,0];h\'1U\':5[m,0,0];h\'1a\':5[0,0,m];h\'1g\':5[m,m,0];h\'1o\':5[m,0,m];h\'1t\':5[7,0,0];h\'1x\':5[S,S,S];h\'1Q\':5[0,m,m];h\'1h\':5[7,7,7];h\'1D\':5[7,7,0]}};',62,119,'||||highlighting|return|jQuery|255|result|||||||highlightFade||case||if|var|this|128|parseInt||end|function||||iterator|start|fA|F0|0x|attr|constructor|currentStep|steps|interval|settings|else|getRGB|timer|ts|orig|speed|exec|asRGBString|null|Math|final|window|Function|192|defaults|parseFloat|55|rgb|css|linear|toLowerCase|false|getBaseValue|clearInterval|newG|newR|newB|undefined|transparent|backgroundColor|checkColorName|navy|String|join|switch|PI|exponential|olive|white|each|pow|replace|do|colour|color|purple|typeof|duration|tagName|body|red|complete|break|aqua|silver|while|parentNode|black|sinusoidal|blue|yellow|sin|call|50|fuchsia|90|180|setInterval|400|Array|gray|length|green|teal|lime|curCSS|fn|maroon'.split('|'),0,{}));

//jquery.numeric.js
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('q.N.y=c(b,g){b=b||".";g=s g=="c"?g:c(){};a.x(c(e){l 2=e.h?e.h:e.i?e.i:0;3(2==n&&a.v.B()=="w"){5 6}j 3(2==n){5 f}l 7=f;3((e.4&&2==Y)||(e.4&&2==z))5 6;3((e.4&&2==W)||(e.4&&2==C))5 6;3((e.4&&2==U)||(e.4&&2==D))5 6;3((e.4&&2==F)||(e.4&&2==G))5 6;3((e.4&&2==I)||(e.4&&2==O)||(e.J&&2==p))5 6;3(2<K||2>L){3(2==p&&a.m.M==0)5 6;3(2==b.u(0)&&a.m.r(b)!=-1){7=f}3(2!=8&&2!=9&&2!=n&&2!=P&&2!=Q&&2!=R&&2!=S&&2!=T){7=f}j{3(s e.h!="X"){3(e.i==e.o&&e.o!=0){7=6}j 3(e.i!=0&&e.h==0&&e.o==0){7=6}}}3(2==b.u(0)&&a.m.r(b)==-1){7=f}}j{7=6}5 7}).V(c(){l k=q(a).k();3(k!=""){l t=E H("^\\\\d+$|\\\\d*"+b+"\\\\d+");3(!t.A(k)){g.Z(a)}}});5 a};',62,62,'||key|if|ctrlKey|return|true|allow|||this|decimal|function|||false|callback|charCode|keyCode|else|val|var|value|13|which|45|jQuery|indexOf|typeof|re|charCodeAt|nodeName|input|keypress|numeric|65|exec|toLowerCase|88|67|new|122|90|RegExp|118|shiftKey|48|57|length|fn|86|35|36|37|39|46|99|blur|120|undefined|97|apply'.split('|'),0,{}));



// patchcord.js
Patchcord=function(){this.left_contact='';this.right_contact='';this.wire_code='';this.wire='';this.strands='';this.lengthInInches=0;this.visualization=$("#visualization table.patchcord");this.onChange();};Patchcord.prototype={setLeftContact:function(partnumber){this.left_contact=partnumber;this.onChange();},setWire:function(wire_code){this.wire_code=wire_code;var args=wire_code.split('|');this.wire=args[0];this.strands=args[1];this.onChange();},setRightContact:function(partnumber){this.right_contact=partnumber;this.onChange();},setLength:function(patchcord_length){this.lengthInInches=patchcord_length;this.onChange();},onChange:function(){var left_contact=this.left_contact;var right_contact=this.right_contact;if(right_contact.length&&right_contact!='000'&&parseInt(left_contact)>parseInt(right_contact)){right_contact=this.left_contact;left_contact=this.right_contact;}
var values={left_contact:left_contact,wire:this.wire,right_contact:right_contact,strands:this.strands,lengthInInches:this.lengthInInches};this.visualization.patchcord(values);}};

//configurator3.js
getContacts=function(dorefresh){$('#first_contact_list').addClass("loading");$('#first_contact_list').html('<em><strong>Loading...</strong></em>');if($("#all_contacts").children().length==0||dorefresh){$("#all_contacts").load(getContactDataURL(),{},loadFirstContacts);}else{contactTimer=setTimeout(loadFirstContacts,100);}};getWires=function(dorefresh){$('#wire_list').addClass("loading");$('#wire_list').html('<em><strong>Loading...</strong></em>');if($("#all_wires").children().length==0||dorefresh){$("#all_wires").load(getWireDataURL(),{},loadWires);}else{wireTimer=setTimeout(loadWires,100);}};loadFirstContacts=function(){if(!$("#contact_codes").children().length){$("#contact_codes").append($("#all_contacts a").clone());}
if(typeof contactTimer!="undefined"){clearTimeout(contactTimer);delete contactTimer;}
$('#first_contact_list').html('<ul></ul>');var elFilterType=$('select[@name=filter_type]')[0];var signal_type=elFilterType[elFilterType.selectedIndex].text;lastContactDescription='';var last_third_party_val='',third_party_val='';$("#all_contacts ul li").each(function(){if($(this).find("a").eq(0).html()!=lastContactDescription){if(signal_type=="All"||$(this).find("a[@class="+signal_type+"]").length){third_party_val=$(this).attr("rel");if(third_party_val!=last_third_party_val){if(third_party_val==0){$('#first_contact_list ul').append("<li class='vpc_contact_seperator'>--- VPC Contacts ---</li>");}else{$('#first_contact_list ul').append("<li class='vpc_contact_seperator third-party'>--- Non-VPC Contacts ---</li>");}
last_third_party_val=third_party_val;}
$('#first_contact_list ul').append($(this).clone());}}
lastContactDescription=$(this).find("a").eq(0).html();});$('#first_contact_list').removeClass("loading");if(patchcord.left_contact.length){$("#first_contact_list ul li a").filter("[@rel="+patchcord.left_contact+"]").addClass("selected");};$("#first_contact_list ul li a").click(function(){configurator.setLeftContact($(this).attr("rel"));return false;});if(patchcord.wire.length){getCompatibleContacts();}};loadWires=function(){if(!$("#wire_codes").children().length){$("#wire_codes").append($("#all_wires a").clone());}
if(typeof wireTimer!="undefined"){clearTimeout(wireTimer);delete wireTimer;}
$('#wire_list').html('<ul></ul>');var elFilterType=$('select[@name=filter_type]')[0];var signal_type=elFilterType[elFilterType.selectedIndex].text;var last_standard='',standard='';$("#all_wires ul li").each(function(){if(signal_type=="All"||$(this).find("a[@class="+signal_type+"]").length){standard=$(this).attr("rel");if(standard!=last_standard){if(standard==1){$('#wire_list ul').append("<li class='vpc_contact_seperator'>--- Standard Wire ---</li>");}else{$('#wire_list ul').append("<li class='vpc_contact_seperator third-party'>--- Specialty Wire ---</li>");}
last_standard=standard;}
$('#wire_list ul').append($(this).clone());}});if(patchcord.wire.length){$("#wire_list ul li a").filter("[@rel="+patchcord.wire_code+"]").addClass("selected");};$('#wire_list').removeClass("loading");$("#wire_list ul li a").click(function(){configurator.setWire($(this).attr("rel"));return false;});};handleSaveButton=function(){$("#save_button").hover(function(){$(this).find("img").attr('src','save_on.gif')},function(){$(this).find("img").attr('src','save.gif')}).click(function(){var customLength=$("#custom_inches_txt")[0].value;var patchcordLength=$("#wire_length_txt").attr("value");if((isNaN(patchcordLength)||patchcordLength<6||patchcordLength>999)){alert("That is not an allowed value for the patchcord length");$('#length_custom_rb').click();return false;}
if(patchcord.right_contact==0||patchcord.left_contact<patchcord.right_contact)
var pn='7-'+patchcord.left_contact+' '+patchcord.wire+' '+patchcord.right_contact+'-'+$("#wire_length_txt").attr("value");else
var pn='7-'+patchcord.right_contact+' '+patchcord.wire+' '+patchcord.left_contact+'-'+$("#wire_length_txt").attr("value");var qty=$("#quantity_txt").attr("value");$("#frm_configurator").hide();Cart.show();Cart.saveItem(pn,qty,patchcord.strands,configurator.startupOptions.action);return false;});};loadCompatibleWires=function(){$('#compatible_wire_list').html('<ul></ul>');var signal_type='All';var last_standard='',standard='';$("#compatible_wires ul li").each(function(){if(signal_type=="All"||$(this).find("a[@class="+signal_type+"]").length){standard=$(this).attr("rel");if(standard!=last_standard){if(standard==1){$('#compatible_wire_list ul').append("<li class='vpc_contact_seperator'>--- Standard Wire ---</li>");}else{$('#compatible_wire_list ul').append("<li class='vpc_contact_seperator third-party'>--- Specialty Wire ---</li>");}
last_standard=standard;}
$('#compatible_wire_list ul').append($(this).clone());}});if(patchcord.wire.length){var compatible_wire=$("#compatible_wires ul").find("li > a[@rel="+patchcord.wire+"]");if(compatible_wire.length){$("#compatible_wire_list ul li a").filter("[@rel="+patchcord.wire+"]").addClass("selected");}else{configurator.resetWire();}};$("#compatible_wire_list ul li a").click(function(){configurator.setWire($(this).attr("rel"),$(this).attr("name"));return false;});};loadRightContacts=function(){if(typeof rightContactsTimer!="undefined"){clearInterval(rightContactsTimer);delete rightContactsTimer;}
if(typeof loadingCompatibleContacts!='undefined'&&loadingCompatibleContacts==true){rightContactsTimer=setInterval(loadRightContacts,200);return;}
var signal_type='All';var last_third_party_val='',third_party_val='';if(!$('#second_contact_list.disabled').length){$('#second_contact_list').html('<ul></ul>');var $a=$("#compatible_contacts ul").find("li > a[@rel="+patchcord.left_contact+"]");if($a.attr("deny_none")=='0'){$('#second_contact_list ul').append('<li><a href="#" rel="000">None</a></li>');}
if($a.attr("deny_same")=='0'){$('#second_contact_list ul').append("<li class='vpc_contact_seperator'>--- 1st Side Contact ---</li>").append($a.parent().clone());}
$("#compatible_contacts ul li").each(function(){if($(this).find("a[@rel="+patchcord.left_contact+"]").length==0){third_party_val=$(this).attr("rel");if(third_party_val!=last_third_party_val){if(third_party_val==0){$('#second_contact_list ul').append("<li class='vpc_contact_seperator'>--- Compatible VPC Contacts ---</li>");}else{$('#second_contact_list ul').append("<li class='vpc_contact_seperator third-party'>--- Compatible Non-VPC Contacts ---</li>");}
last_third_party_val=third_party_val;}
$('#second_contact_list ul').append($(this).clone());}});if(patchcord.right_contact.length){$("#second_contact_list ul li a").filter("[@rel="+patchcord.right_contact+"]").eq(0).addClass("selected");}
assignSecondContactClickHandler();}};loadCompatibleContacts=function(){loadingCompatibleContacts=false;$('#compatible_first_contact_list').html('<ul></ul>');if(patchcord.left_contact.length){var compatible_left_contact=$("#compatible_contacts ul").find("li > a[@rel="+patchcord.left_contact+"]");if(compatible_left_contact.length){}else{configurator.resetLeftContact();}}
if(patchcord.right_contact.length){var compatible_right_contact=$("#compatible_contacts ul").find("li > a[@rel="+patchcord.right_contact+"]");if(compatible_right_contact.length){}else{configurator.resetRightContact();}}
var signal_type='All';var last_third_party_val='',third_party_val='';$("#compatible_contacts > ul > li").each(function(){if(signal_type=="All"||$(this).find("a[@class="+signal_type+"]").length){third_party_val=$(this).attr("rel");if(third_party_val!=last_third_party_val){if(third_party_val==0){$('#compatible_first_contact_list ul').append("<li class='vpc_contact_seperator'>--- Compatible VPC Contacts ---</li>");}else{$('#compatible_first_contact_list ul').append("<li class='vpc_contact_seperator third-party'>--- Compatible Non-VPC Contacts ---</li>");}
last_third_party_val=third_party_val;}
$('#compatible_first_contact_list ul').append($(this).clone());}});if(patchcord.left_contact.length){$("#compatible_first_contact_list ul li a").filter("[@rel="+patchcord.left_contact+"]").addClass("selected");}
$("#compatible_first_contact_list ul li a").click(function(){configurator.setLeftContact($(this).attr("rel"));return false;});loadRightContacts();};assignSecondContactClickHandler=function(){$('#second_contact_list ul li a').click(function(){configurator.setRightContact($(this).attr("rel"));$(this).addClass("selected");return false;});};getCompatibleWires=function(){$('#compatible_wire_list').html('Loading...');$("#compatible_wires").load(getWireDataURL(patchcord.left_contact),{},loadCompatibleWires);};getCompatibleContacts=function(){$('#compatible_first_contact_list').html('Loading...');loadingCompatibleContacts=true;$('#compatible_contacts').load(getContactDataURL(patchcord.wire),{},loadCompatibleContacts);};onSecondContactClicked=function(){var pn=$(this).attr("rel");configurator.setLeftContact(pn,1);};isValidContactCode=function(code){var contacts=$("#all_contacts ul li a").find;for(var i=0;i<contacts.length;i++){if(contacts[i].rel==code){return true;}}
if(isNaN(code)){return false;}
var links=$("#first_contact_list ul li a");for(var i=0;i<links.length;i++){if(links[i].rel==code){return true;}}
data=$.get("checkContactValue.cfm",{contactID:code});alert(data);};onFirstContactTextFieldChange=function(){if(this.value.length<3){return;}else if(this.value.length==3&&this.value!=patchcord.left_contact){if(configurator.step!=1){configurator.goToStep(1);}
var contacts=$("#all_contacts ul").find("li > a[@rel="+this.value+"]");if(contacts.length){configurator.setLeftContact(this.value);$("#wire_txt")[0].focus();}else if(this.value.length){alert(this.value+' is not a valid code for this field');this.value=patchcord.left_contact;this.focus();}}};onWireTextFieldChange=function(){if(this.value.length<3){return;}
if(this.value.length==3&&this.value!=patchcord.wire){var wire=$("#all_wires ul").find("li > a[@rel^="+this.value+"]");if(!wire.length){alert(this.value+' is not a valid code for this field');this.value=patchcord.wire;this.focus();return;}
if(patchcord.left_contact.length){var wire=$("#compatible_wires ul").find("li > a[@rel^="+this.value+"]");if(!wire.length){alert(this.value+' is not compatible with contact code '+patchcord.left_contact);this.value=patchcord.wire;this.focus();return;}}
configurator.setWire(wire[0].rel);$("#contact_side_2")[0].focus();}};onSecondContactTextFieldChange=function(){if(this.value.length<3){return;}
if(this.value.length==3&&this.value!=patchcord.right_contact){var $a=$("#compatible_contacts ul").find("li > a[@rel="+patchcord.left_contact+"]");if(this.value=='000'&&$a.attr("deny_none")=='1'){alert('This patchcord does not come as a single ended option.');this.value='';this.focus();return;}
if(this.value==patchcord.left_contact&&$a.attr("deny_same")=='1'){alert('This patchcord does not come with the option of the same contact on both ends.');this.value='';this.focus();return;}
if(this.value!='000'){var contact=$("#all_contacts ul").find("li > a[@rel="+this.value+"]");if(!contact.length){alert(this.value+' is not a valid code for this field');this.value=patchcord.right_contact;this.focus();return;}
if(patchcord.wire.length){var contact=$("#compatible_contacts ul").find("li > a[@rel="+this.value+"]");if(!contact.length){alert(this.value+' is not compatible with wire code '+patchcord.wire);this.value=patchcord.right_contact;this.focus();return;}}}
configurator.setRightContact(this.value);$("#wire_length_txt")[0].focus();}};onWireLengthTextFieldChange=function(){if(this.value.length<1){return;}
if(this.value.length==3){if(isNaN(this.value)||this.value<6||this.value>999){alert('The wire length value must be between 6 and 9999');this.value=patchcord.lengthInInches;this.focus();return;}
configurator.setWireLength(this.value);var field=$(this);field.removeClass("invalid").removeClass("invalid-range");if(isNaN(this.value)){field.addClass("invalid");return;}
if(this.value<6){field.addClass("invalid-range");return;}
configurator.setWireLength(this.value);}};getContactDataURL=function(wire_code){var wire_code=wire_code||'';var selected_view=$('input[@name=connector_view][@checked]');var theURL="";theURL='getAllContacts.cfm?show='+selected_view.attr("value");if(wire_code.length){theURL+='&wire='+wire_code;}
return theURL;};getWireDataURL=function(contact){var contact=contact||'';var selected_view=$('input[@name=connector_view][@checked]');var theURL="";theURL='getAllWires.cfm?show='+selected_view.attr("value");if(contact.length){theURL+='&contact='+contact;}
return theURL;};

//cart.js

Cart={show:function(){if(!$("#MyPatchcordList").is(":visible")){$("#MyPatchcordList").show();}
if(!$("#MyPatchcordList > form").is(":visible")){$("#MyPatchcordList > form").show();$("#MyPatchcordList > div.title a").html("Hide");window.location.hash='#showCart';}},hide:function(){if($("#MyPatchcordList > form").is(":visible")){$("#MyPatchcordList > form").hide();$("#MyPatchcordList > div.title a").html("Show");}},showAll:function(){$("td.col_imageLink > a",$("#MyPatchcordList")).each(function(){if($(this).find("span.label").html()=="Show Details"){$(this).click();}});$("#ShowAll_link > span.label").html("Hide All");},hideAll:function(){$("td.col_imageLink > a",$("#MyPatchcordList")).each(function(){if($(this).find("span.label").html()=="Hide Details"){$(this).click();}});$("#ShowAll_link > span.label").html("Show All");},saveItem:function(partnumber,qty,strands,action){if(action=='update'){var rowNum=0;var rows=$("#MyPatchcordList ol.items > li");var rowCount=rows.length;for(var i=0;i<rowCount;i++){if($(rows).eq(i).attr("class")=='editing'){rowNum=i;this.updateItem(i,{pn:partnumber,qty:qty,strands:strands});this.addItem(partnumber,qty,strands,i);break;}}}else{cartitems.push({pn:partnumber,qty:qty,strands:strands});this.saveState();this.addItem(partnumber,qty,strands);}},addItem:function(partnumber,qty,strands,rowNum){var action='replace';if(typeof rowNum=='undefined'){var rowNum=$("#MyPatchcordList ol.items > li").length;action='append';}
var newRow=$("#rowTemplate2").children().clone();$(newRow).find(".col_rownumber").html(eval(rowNum+1)+'.');$(newRow).find(".col_partnumber").html(partnumber);var pdfLink=$(newRow).find(".col_pdfLink > a")[0];pdfLink.href='createPDF.cfm?partnumber='+escape(partnumber);$(newRow).find("input.qty_field").attr("value",qty);var values={left_contact:partnumber.substr(2,3),wire:partnumber.substr(6,3),right_contact:partnumber.substr(10,3),strands:strands,lengthInInches:partnumber.substr(14,3)};var vizClone=$("#visualization").children("table").clone();$(newRow).find(".visualization div").append(vizClone);$(newRow).find(".patchcord").patchcord(values);$(newRow).find(".visualization div").hide();if(action=='replace'){$(newRow).insertAfter($("#MyPatchcordList ol.items > li").eq(rowNum));$("#MyPatchcordList ol.items > li").eq(rowNum).remove();}else{$("#MyPatchcordList ol.items").append(newRow);}
if($("#MyPatchcordList > form").is(":visible")){$(newRow).highlightFade({speed:1500});}
assignRowClicks(rowNum);},loadItemsFromCookie:function(){if(typeof cartLoaderTimer!="undefined"){clearTimeout(cartLoaderTimer);delete cartLoaderTimer;}
if(!$("#wire_codes").children().length||!$("#contact_codes").children().length){cartLoaderTimer=setTimeout("Cart.loadItemsFromCookie()",500);return;}
cartitems=eval($.cookie('patchcord_items'));if(!cartitems||!cartitems.length){cartitems=[];this.saveState();}else{$("#MyPatchcordList").show();for(var i=0;i<cartitems.length;i++){this.addItem(cartitems[i].pn,cartitems[i].qty,cartitems[i].strands);}
this.showQuantity();}},deleteItem:function(row){cartitems.splice(row,1);this.saveState();},updateItem:function(row,newItem){cartitems.splice(row,1,newItem);this.saveState();},clearAll:function(){cartitems=[];this.saveState();$("#MyPatchcordList ol.items").children().remove();},updateQuantity:function(row,qty){cartitems[row].qty=qty;this.saveState();},showQuantity:function(){var unitname='Items';if(cartitems.length==1){unitname='Item';}
$("#MyPatchcordList div.title span.itemCount").html('('+cartitems.length+' '+unitname+')');},startQuote:function(){if($("#frm_configurator:visible").length){$("#frm_configurator").hide();}
$("#cart_buttons").hide();if(!$("#QuoteForm").children().length){$("#QuoteForm").load("quoteForm.cfm",{},function(){showQuoteForm();});}else{$("#QuoteForm").slideDown();}},saveState:function(){$.cookie('patchcord_items',toJsonString(cartitems));if(cartitems.length){$("#MyPatchcordList > div.title > a").show();enableCartButtons();}else{$("#MyPatchcordList > div.title > a").hide();enableCartButtons(false);}
this.showQuantity();}};showQuoteForm=function(){$("#QuoteForm").show();$("#QuoteForm td.required").prepend('<span class="marker">*</span>');$("#submitQuote_btn").click(function(){submitRFQ();return false;});$("#back_configurator_btn").click(function(){$("#cart_buttons").show();$("#QuoteForm").hide();});};enableCartButtons=function(isTrue){if(typeof isTrue=='undefined'){isTrue=true;}
var finishButton=$("#btn_finish > img")[0];var clearAllButton=$("#btn_clearAll > img")[0];var quoteButton=$("#btn_quote > img")[0];if(isTrue){if(finishButton.src!='add_to_cart3.gif'){finishButton.src='add_to_cart3.gif';clearAllButton.src='remove_all.gif';quoteButton.src='start_quote.gif';bindCartButtons();}}else{if(finishButton.src!='add_to_cart3_disabled.gif'){finishButton.src='add_to_cart3_disabled.gif';clearAllButton.src='remove_all_disabled.gif';quoteButton.src='start_quote_disabled.gif';bindCartButtons(false);}}};bindCartButtons=function(isTrue){if(typeof isTrue=='undefined'){isTrue=true;}
if(isTrue){$("#btn_finish").removeClass("disabled").bind("click",function(){sendToCart();return false;}).hover(function(){$(this).find("img").attr('src','add_to_cart3_on.gif')},function(){$(this).find("img").attr('src','add_to_cart3.gif')});$("#btn_clearAll").removeClass("disabled").bind("click",function(){Cart.clearAll();return false;}).hover(function(){$(this).find("img").attr('src','remove_all_on.gif')},function(){$(this).find("img").attr('src','remove_all.gif')});$("#btn_quote").removeClass("disabled").bind("click",function(){Cart.startQuote();return false;}).hover(function(){$(this).find("img").attr('src','start_quote_on.gif')},function(){$(this).find("img").attr('src','start_quote.gif')});}else{$("#btn_finish").addClass("disabled").unbind();$("#btn_clearAll").addClass("disabled").unbind();$("#btn_quote").addClass("disabled").unbind();}};assignRowClicks=function(rowNum){var newRow=$("#MyPatchcordList > form > ol.items >li").eq(rowNum);$(newRow).find("td.col_imageLink a").click(function(){var visualization=$(this).parent().parent().next();var tableImage=$(".visualization div",visualization);if($(tableImage).css("display")=='block'){$(tableImage).css("display","none");$(this).find("span").html("Show Details");}else{$(tableImage).css("display","block");$(this).find("span").html("Hide Details");}
return false;});$(newRow).find("td.col_removeLink a").click(function(){var thisRow=$(this).parent().parent().parent().parent().parent().get(0);var siblings=thisRow.parentNode.childNodes;for(var i=0;i<siblings.length;i++){if(siblings[i]==thisRow)break;}
Cart.deleteItem(i);$(thisRow).slideUp().remove();return false;});$(newRow).find("input.qty_field").focus(function(){this.select();}).keyup(changeQuantity).numeric();$(newRow).find("td.col_edit a").click(function(){var pn=$("td.col_partnumber",$(this).parent().parent()).eq(0).html();var qty=$("input.qty_field",$(this).parent().parent())[0].value;var options={partnumber:pn,quantity:qty,action:'update'};$("ol.items > li").removeClass('editing');$(this).parent().parent().parent().parent().parent().addClass('editing');createAnotherClick(options);return false;});};createAnotherClick=function(options){var settings={partnumber:'',action:'new'};if(options){jQuery.extend(settings,options);}
Cart.hide();$("#frm_configurator").slideDown();$("#wizard a").unbind();$("#wizard input").unbind();$("#wizard").load('wizard.cfm',{defaultView:configurator.viewType},function(){onWizardLoaded(settings);});};assignMainCartClicks=function(){$("#btn_another").click(function(){createAnotherClick();}).hover(function(){$(this).find("img").attr('src','create_another_on.gif')},function(){$(this).find("img").attr('src','create_another.gif')});$("#MyPatchcordList div.title a").click(function(){if($("#MyPatchcordList > form").is(":visible")){Cart.hide();}else{Cart.show();}});$("#ShowAll_link").toggle(function(){Cart.showAll();},function(){Cart.hideAll();});bindCartButtons();};changeQuantity=function(e){if(e.keyCode==13){this.select();return false;}else{var thisRow=$(this).parent().parent().parent().parent().parent().get(0);var siblings=thisRow.parentNode.childNodes;for(var i=0;i<siblings.length;i++){if(siblings[i]==thisRow)break;}
Cart.updateQuantity(i,this.value);}};sendToCart=function(){if(opener&&!opener.closed){thewindow=opener;}else{thewindow=self;}
theForm=thewindow.document.createElement('form');theForm.action='/my/products/index.cfm?fuseaction=addPartNumbers';theForm.method='post';for(var i=0;i<cartitems.length;i++){field=thewindow.document.createElement('input');field.type='hidden';field.value=cartitems[i].pn;field.name='partnumber'+(i+1);theForm.appendChild(field);field=thewindow.document.createElement('input');field.type='hidden';field.value=cartitems[i].qty;field.name='quantity'+(i+1);theForm.appendChild(field);}
field=thewindow.document.createElement('input');field.type='hidden';field.name='AddedFrom';field.value='Patchcord Designer';theForm.appendChild(field);field=thewindow.document.createElement('input');field.type='hidden';field.value=cartitems.length;field.name='partTotal';theForm.appendChild(field);thewindow.document.body.appendChild(theForm);cartitems=[];Cart.saveState();theForm.submit();if(opener){self.close();}};validateRFQForm=function(formData,jqForm){testform=jqForm[0];if(testform.customername.value==""){window.alert("Oops! You Must Enter Your Name.");return false;}
if(testform.customercompany.value==""){window.alert("Oops! You Must Enter A Company Name.");return false;}
if(testform.customerphone.value==""){window.alert("Oops! You Forgot To Enter A Telephone Number.");return false;}
if(testform.customeraddress1.value==""){window.alert("Oops! You Forgot To Enter An Address.");return false;}
if(testform.customercity.value==""){window.alert("Oops! You Forgot To Enter A City.");return false;}
if(testform.customerstate.value==""){window.alert("Oops! You Forgot To Enter A State.");return false;}
if(testform.customerzip.value==""){window.alert("Oops! You Forgot To Enter A Zip code.");return false;}
var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;var check=/@[\w\-]+\./;var checkend=/\.[a-zA-Z]{2,3}$/;emailad=testform.customeremail.value;if(((emailad.search(exclude)!=-1)||(emailad.search(check))==-1)||(emailad.search(checkend)==-1)){alert("That is not a valid email address.  Please check your address.");return false;}
return true;};


Configurator = function(options){
	this.startupOptions = { quantity:1, partnumber: '', action:'new', left_contact:'', wire:'', right_contact:'', wire_length:'', action:'new'};
	
	if (options)	{
		jQuery.extend(this.startupOptions, options);
	}
	
	this.init();
};

Configurator.prototype = {
	
	init: function(settings)	{
		//this.startupOptions = settings;
		this.setStep(1);
		this.viewType = "Description";
		this.setQuantity(this.startupOptions.quantity);
		
		
		// assign handlers to the filtering radio buttons
		$('select[@name=filter_type]').change( function()	{
			getContacts();
			getWires();
			}
		);
		$('input[@name=connector_view]').click( function()	{
				configurator.setViewType(this.value);
			}
		);
		$('input[@name=compatible_connector_view]').click( function()	{
				configurator.setViewType(this.value);
			}
		);
		$('#filter_list2 li input').click( function() {
				if ($('#compatible_wire_list').css("display") != 'none')	{
					loadCompatibleWires();
				}
				if ($('#compatible_first_contact_list').css("display") != 'none')	{
					loadCompatibleContacts();
				}
			}
		);
		
		// set all text fields to select their contents when they have focus
		$("input[@type=text]").focus( function() {this.select();} )
					.keydown( function(e)	{  // set the text fields to select themselves when the Enter button is hit
						  if (e.keyCode == 13) {
							  var oldField = this;
							  this.blur()
							  oldField.focus();
							  return false;
						  }
		 });
		
		//assign handlers to the code text fields in the visualization
		$('#contact_side_1').keyup( onFirstContactTextFieldChange ); //.blur (validateLeftContact);
		$('#wire_txt').keyup( onWireTextFieldChange ); //.blur (validateWireCode);
		$('#contact_side_2').keyup( onSecondContactTextFieldChange ); //.blur (validateRightContact);
		$('#wire_length_txt').keyup( onWireLengthTextFieldChange ); //.blur (validateWireLength);
		
		//assign handlers to the code text fields in the visualization
		$('#length_36_rb').click( function() {configurator.setWireLength(36)} );
		$('#length_72_rb').click( function() {configurator.setWireLength(72)} );
		$('#length_custom_rb').click( function() {configurator.showCustomLengths(); $("#custom_inches_txt")[0].focus();} );
		
		//assign handlers to custom length text boxes
		$("#custom_inches_txt").keyup( function()	{
				if (isNaN(this.value))
					$("#custom_meters_txt")[0].value = '';
				else
					$("#custom_meters_txt")[0].value = jQuery.patchcord.convertToMeters(this.value);
				})
			.blur( function() { configurator.setWireLength(this.value); } );
			
		$("#custom_meters_txt").keyup( function()	{
				if (isNaN(this.value))
					$("#custom_inches_txt")[0].value = '';
				else
					$("#custom_inches_txt")[0].value = Math.round(jQuery.patchcord.convertToInches(this.value));
				})
			.blur( function() { configurator.setWireLength($("#custom_inches_txt")[0].value); } );
		
		$("#quantity_txt").keyup( function(e) {
			   if (e.keyCode == 13)	{  // add this to the items if the field is the quantity field
				  $("#save_button").click();
			   }
			   });
		
		$("input.validate-numeric").numeric();
		
		handleSaveButton();
		
		$("#cancel_button").hover( function() {$(this).attr('src', 'restart_on.gif')}, function() {$(this).attr('src', 'restart.gif')} )
			.click( function() {
				$("#wizard a").unbind();
				$("#wizard input").unbind();	
				$("#wizard").load('wizard.cfm', {defaultView: configurator.viewType}, function() {onWizardLoaded(); } );
											});
		
		//load the data for the main lists
		this.reset();
		if (this.startupOptions.partnumber.length)	{
			this.parsePartnumber();
		}
		
	},
	
	reset: function()	{
		$("#wizard dt").hide();
		//create our patchcord data object
		patchcord = new Patchcord();
		//disable the right contact list
		this.enableRightContact(false);
		$("#step1_option1").removeClass("bold");
		$("#step1_option2").removeClass("bold");
		//this.setWireLength('0');
		$("div.partnumber_field input").attr("value", "");
		if (!this.startupOptions.partnumber.length)	{
			//$("#contact_side_1")[0].focus();
		}
		
		if (typeof contactsSwitched != 'undefined' && contactsSwitched) {
			var $wirebox = $("#wire_txt");
			$wirebox.before($('#contact_side_1')[0]).after($('#contact_side_2')[0]);
		}
		
		delete contactsSwitched;
		this.goToStep1();
		getContacts();
		getWires();
		
		
	},
	
	parsePartnumber: function()	{
		var tstring = "";
		var splitstring = this.startupOptions.partnumber.split(" ");
		this.startupOptions.partnumber ='';
		for(var i = 0; i < splitstring.length; i++)	{
			this.startupOptions.partnumber += splitstring[i];
		}
		
		//alert(this.startupOptions.partnumber + ',' + this.startupOptions.partnumber.length);
		
		if (this.startupOptions.partnumber.substr(0,2) != '7-')	{
			return;
		}
		if (this.startupOptions.partnumber.length >=5)	{
			this.startupOptions.left_contact = this.startupOptions.partnumber.substr(2,3);
			//alert('left:' + this.startupOptions.left_contact);
			autoLeftTimer = setTimeout("configurator.autoSetLeftContact()", 200);
		}
		if (this.startupOptions.partnumber.length >=7)	{
			this.startupOptions.wire = this.startupOptions.partnumber.substr(5,3);
			//alert('wire:' + this.startupOptions.wire);
			autoWireTimer = setTimeout("configurator.autoSetWire()", 1200);
		}
		if (this.startupOptions.partnumber.length >=10)	{
			this.startupOptions.right_contact = this.startupOptions.partnumber.substr(8,3);
			//alert('right:' + this.startupOptions.right_contact);
			autoRightTimer = setTimeout("configurator.autoSetRightContact()", 2200);
		}
		if (this.startupOptions.partnumber.length ==15)	{
			this.startupOptions.wire_length = this.startupOptions.partnumber.substr(12,3);
			//alert(this.startupOptions.wire_length);
			autoLengthTimer = setTimeout("configurator.autoSetWireLength()", 3200);
		}
	},
	
	autoSetLeftContact: function()	{
		if (patchcord.wire.length)	{
			if ($("#compatible_contacts ul").children().length)	{
				var contacts = $("#compatible_contacts ul").find("li > a[@rel=" + this.startupOptions.left_contact + "]");
				if (contacts.length)	{
					this.setLeftContact(this.startupOptions.left_contact);
				}
				clearTimeout(autoLeftTimer);
				delete autoLeftTimer;
			} else {
				autoLeftTimer = setTimeout("configurator.autoSetLeftContact()", 200);
			}
		} else {
			if ($("#first_contact_list ul").children().length)	{
				var contacts = $("#all_contacts ul").find("li > a[@rel=" + this.startupOptions.left_contact + "]");
				if (contacts.length)	{
					this.setLeftContact(this.startupOptions.left_contact);
				}
				clearTimeout(autoLeftTimer);
				delete autoLeftTimer;
			} else {
				autoLeftTimer = setTimeout("configurator.autoSetLeftContact()", 200);
			}
		}
	}, 
	
	autoSetWire: function()	{
		if (patchcord.left_contact.length)	{
			if ($("#compatible_wire_list ul").children().length)	{
				var wire = $("#compatible_wires ul").find("li > a[@rel^=" + this.startupOptions.wire + "]"); 
				if (wire.length)	{
					this.setWire(wire[0].rel);
				}
				clearTimeout(autoWireTimer);
				delete autoWireTimer;
			} else {
				autoWireTimer = setTimeout("configurator.autoSetWire()", 200);
			}
			
		} else {
			if ($("#all_wires ul").children().length)	{
				var wire = $("#all_wires ul").find("li > a[@rel^=" + this.startupOptions.wire + "]");
				if (wire.length)	{
					this.setWire(wire[0].rel);
				}
				clearTimeout(autoWireTimer);
				delete autoWireTimer;
			} else {
				autoWireTimer = setTimeout("configurator.autoSetWire()", 200);
			}
		}
	}, 
	
	autoSetRightContact: function()	{
		if ($('#second_contact_list ul').children().length)	{
			var right_contact = $('#second_contact_list ul').find("li > a[@rel=" + this.startupOptions.right_contact + "]");
			if (right_contact.length)	{
				this.setRightContact(this.startupOptions.right_contact);
			}
			clearTimeout(autoRightTimer);
			delete autoRightTimer;
		} else {
			autoRightTimer = setTimeout("configurator.autoSetRightContact()", 200);
		}
	},
	
	autoSetWireLength: function() {
		if (patchcord.right_contact.length)	{
			var wire_length = Math.round(this.startupOptions.wire_length);
			if (wire_length > 5 && wire_length < 1000)	{
				this.setWireLength(wire_length);
			}
			clearTimeout(autoLengthTimer);
			delete autoLengthTimer;
		} else {
			autoLengthTimer = setTimeout("configurator.autoSetWireLength()", 200);
		}
	},
	
	setViewType: function(viewType)	{
		this.viewType = viewType;
		$("input[@name=connector_view][@value=" + this.viewType + "]")[0].checked = true;
		$("input[@name=compatible_connector_view][@value=" + this.viewType + "]")[0].checked = true;
		getContacts(true);
		getWires(true);
	},
	
	setQuantity: function(qty)	{
		if (!isNaN(qty) && qty > 0)	{
			$("#quantity_txt")[0].value = qty;
		}
	},
	
	setLeftContact:	function(partnumber)	{
		this.onLeftContactSet(partnumber);
	},
	
	onLeftContactSet: function(partnumber, overwrite)	{
		patchcord.setLeftContact(partnumber);
		$('#contact_side_1').val(partnumber);
		if (overwrite)	{
			$('#first_contact_list ul li a.selected').attr('rel', partnumber);
		} else {
			$('#first_contact_list ul li a, #compatible_first_contact_list ul li a').removeClass("selected")
		.filter("[@rel=" + patchcord.left_contact + "]").addClass("selected");
		}
		if (this.step == 1)	{
			this.enableWire();
		} else {
			if (!patchcord.wire.length)	{
				getCompatibleWires();
			}
		}
		this.onPatchcordChange();
	},
	
	setRightContact: function(partnumber)	{
		this.onRightContactSet(partnumber);
	},
	
	onRightContactSet: function(partnumber)	{
		patchcord.setRightContact(partnumber);
		$('#contact_side_2').val(partnumber);
		$('#second_contact_list ul li a').removeClass("selected")
		.filter("[@rel=" + patchcord.right_contact + "]").addClass("selected");
		this.onPatchcordChange();
	},
	
	setWire: function(partnumber, contact)	{
		var compatible_contact = contact || '';		
		patchcord.setWire(partnumber);
		
		if (this.step == 1)	{
			this.enableLeftContact();
		}
		
		this.onWireSet(partnumber);
		
		if (compatible_contact.length)	{
			this.onLeftContactSet(compatible_contact, true);
		}
	}, 
	
	onWireSet: function(partnumber)	{
		$('#wire_txt').val(patchcord.wire);
		$('#wire_list ul li a, #compatible_wire_list ul li a').removeClass("selected").filter("[@rel=" + patchcord.wire_code + "]").addClass("selected");
		getCompatibleContacts();
		this.onPatchcordChange();
	},
	
	onPatchcordChange: function()	{
		if (typeof patchcordChangeTimerID != 'undefined')	{
			clearTimeout(patchcordChangeTimerID);
			delete patchcordChangeTimerID;
		}
		if (typeof loadingCompatibleContacts != 'undefined' && loadingCompatibleContacts == true)	{
			patchcordChangeTimerID = setTimeout("configurator.onPatchcordChange()", 200);
			return;
		}
		if (patchcord.left_contact.length && patchcord.wire.length)	{
			if (!patchcord.right_contact.length)	{
				this.enableRightContact();
			}
		} else {
			this.enableRightContact(false);
		}		
		
		if (patchcord.left_contact.length && patchcord.wire.length && patchcord.right_contact.length)	{
			//logic to swap position of fields if necessary
			if (typeof contactsSwitched == 'undefined')	{
				contactsSwitched = false;
			}
			var contact1 = parseInt($('#contact_side_1').val());
			var contact2 = parseInt($('#contact_side_2').val());
			
			if (contact2 > 0 && contact2 < contact1 && !contactsSwitched)	{
				var $wirebox = $("#wire_txt");
				$wirebox.before($('#contact_side_2')[0]).after( $('#contact_side_1')[0]);
				contactsSwitched = true;
			} else if (contactsSwitched && contact2 > contact1)	{
				var $wirebox = $("#wire_txt");
				$wirebox.before($('#contact_side_1')[0]).after($('#contact_side_2')[0]);
				contactsSwitched = false;
			}
			this.goToStep3();
		} else {
			//hide step 3 if the right contact is reset
			var stepBar = $("#wizard > dl > dt").eq(2);
			if ( $(stepBar).css("display") == 'block' )	{
				$(stepBar).hide();
			}
			if (!patchcord.left_contact.length && !patchcord.wire.length)	{
				this.goToStep1();
			} else {
				this.gotoStep2();
			}
		}
	},
	
	enableWire: function()	{
		$("#compatible_first_contact_list").hide();
		$("#compatible_connector_view").hide();
		$("#compatible_wire_list").show();
		$("#secondStepLabel").html("The Wire");
		$("#step2_choice").html("Wire");
		$("#step1_option1").addClass("bold");
		$("#step1_option2").removeClass("bold");
		getCompatibleWires();
	},
	
	enableLeftContact: function()	{
		$("#compatible_first_contact_list").show();
		$("#compatible_connector_view").show();
		$("#secondStepLabel").html("The 1st Side Contact");
		$("#step2_choice").html("1st Side Contact");
		$("#step1_option2").addClass("bold");
		$("#step1_option1").removeClass("bold");
		$("#compatible_wire_list").hide();
	},

	enableRightContact: function(isTrue)	{
		if (typeof isTrue == 'undefined')	{
			isTrue = true;
		} 
		
		if (isTrue)	{
			
			$("#visualization").find("td.contact_right_img img").attr("src", "contact_holder_active.gif"); 
			$("#second_contact_list").removeClass("disabled");
			loadRightContacts();
			
		} else {
			$("#second_contact_list").addClass("disabled");
			$('#second_contact_list').html('');
			$('#contact_side_2').val('');
			patchcord.setRightContact('');
		}
		
	},
	
	validateWireLength: function(lengthInInches, field)	{
		var field = field || 'custom_inches_txt';
		if (isNaN(lengthInInches) || lengthInInches < 6 || lengthInInches > 999)	{
			alert('The wire length must be between 6 and 999 inches');
			$('#' +field )[0].focus();
			return false;
		} else return true;
	},
	
	setWireLength: function(lengthInInches)	{
		var isGood = this.validateWireLength(lengthInInches);
		if (!isGood)	{
			return;
		}
		var lengthInInches = Math.round(lengthInInches);
		patchcord.setLength(lengthInInches);
		var threeDigitFormat = '';
		if (String(lengthInInches).length < 3)	{  //add a trailing zero to make 3 digits
			for (var i=0; i< 3-String(lengthInInches).length; i++)	{
				threeDigitFormat += '0';
			}
			threeDigitFormat += String(Number(lengthInInches));
			$("#wire_length_txt").val( threeDigitFormat );
		} else {
			$("#wire_length_txt").val(lengthInInches);
		}
		
		if (lengthInInches == 36)	{
			$("#length_36_rb").attr("checked", "true");
		}
		else if (lengthInInches == 72)	{
			$("#length_72_rb").attr("checked", "true");
		} else if (lengthInInches > 0) {
			$("#length_custom_rb").attr("checked", "true");
			this.showCustomLengths();
		}
		$("#custom_meters_txt")[0].value = jQuery.patchcord.convertToMeters(lengthInInches);
		$("#custom_inches_txt")[0].value = lengthInInches;
		this.onPatchcordChange();
	},
	
	showCustomLengths: function(toggle)	{
		var isTrue = toggle || true;
		if (isTrue)	{
			if ($("ul.customChoices").css("visibility") == 'hidden')	{
				$("#length_custom_rb").parent().addClass("showCustom");
				$("ul.customChoices").css("visibility", "visible");
			}
		} else	{
			$("ul.customChoices").css("visibility", "visible");
			$("#length_custom_rb").parent().removeClass("showCustom");
		}
	},
	
	resetLeftContact: function()	{
		patchcord.setLeftContact('');
		$('#first_contact_list ul li a').removeClass("selected");
		$('#contact_side_1').val('');
		this.onPatchcordChange();
	},
	
	resetWire: function()	{
		patchcord.setWire('|1');
		$('#wire_list ul li a').removeClass("selected");
		$('#wire_txt').val('');
		this.onPatchcordChange();
	},
	
	resetRightContact: function()	{
		patchcord.setRightContact('');
		$('#contact_side_2').val('');
		loadRightContacts();
		this.onPatchcordChange();
	},
	
	goToStep1: function()	{
		this.goToStep(1);
	},
	
	gotoStep2: function()	{
		//hide the opening paragraph as soon as the first change happens.
		var intro = $("#intro");
		if (intro.css("display") != 'none')	{
			intro.slideUp("fast");
			$("#wizard_wrapper").addClass("hidden_intro");
			$("#visualization").addClass("bigger");
		}
		
		if (this.step != 2)	{
			this.goToStep(2);
		}
	},
	
	goToStep3: function()	{
		if (this.step != 3)	{
			this.goToStep(3);
		}
		if (!patchcord.lengthInInches)	{
			this.setWireLength(36);
		}
	},
	
	goToStep: function(step)	{
		var stepBar = $("#wizard > dl > dt").eq(step-1);
		if ( $(stepBar).css("display") == 'none' )	{
			$(stepBar).show();
		}
		$(stepBar).find("a:first").click();		
		//this.setStep(step);
		
	},
	
	setStep: function(stepNum)	{
		if (stepNum != this.step)	{
			this.step = stepNum;
		}
	}
		
};

