var gc=YAHOO.namespace("PSConstants");var gv=YAHOO.namespace("PSGlobals");var fn=YAHOO.namespace("PSFunctions");var yue=YAHOO.util.Event;var yl=YAHOO.lang;var yu=YAHOO.util;var yw=YAHOO.widget;var yud=YAHOO.util.Dom;var yuc=YAHOO.util.Connect;gc.BLANK=" ";gc.COMMA=",";gc.NULLSTR="";gc.NL="\n";gc.SLASH="/";gc.PERIOD=".";gc.EQ="=";gv.ERROR=[];gv.ERROR[0]="OK";gv.ERROR[100]="Invalid Number";gv.ERROR[101]="Item Is Not In List";gv.ERROR[102]="No Model Selected";gv.ERROR[103]="Invalid US Zip Code";gv.ERROR[104]="Invalid Canadian Postal Code";gv.ERROR[105]="Invalid Canadian Provence";gv.ERROR[106]="Invalid Phone Number";gv.ERROR[107]="Invalid Email Address";gv.ERROR[108]="Invalid Extension";gv.ERROR[109]="Invalid Model Year";gv.ERROR[110]="Invalid Vehicle Mileage";gv.ERROR[111]="Invalid VIN";gv.ERROR[112]="No Valid Value Chosen";gv.oPhoneFormat={dashes:1,parens:2,dots:3};gv.reAlphaNum=/([^\w\s\.\'])/gi;gv.reAlpha=/([^[a-z\s\.\'])/gi;gv.reInteger=/(\D)/gi;gv.reStripCommas=/(\,)/gi;gv.reEmail=/^(?:[a-zA-Z0-9_'^&amp;/+-])+(?:\.(?:[a-zA-Z0-9_'^&amp;/+-])+)*@(?:(?:\[?(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\.){3}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\]?)|(?:[a-zA-Z0-9-]+\.)+(?:[a-zA-Z]){2,}\.?)$/;fn.IsDefined=function(A){return(typeof A!="undefined"&&A!=null)};fn.IsBlank=function(A){return(fn.RemoveBlanks(A).length==0)};fn.ErrorAlert=function(C,D,B){var A="\n";alert("===> SYSTEM ERRROR <==="+A+A+C+A+D+A+"Status: "+B+A+A+"PLEASE REPORT TO TECHNICAL STAFF")};fn.GetArgs=function(){var E={},F=location.search.substring(1),G=F.split("&"),D,B;for(var C=0,A=G.length;C<A;C++){D=G[C].indexOf("=");B=G[C].substring(0,D);E[B]=decodeURIComponent(G[C].substring(D+1))}return E};fn.AddCommas=function(C){var A,D,B;A=C.length;if(A<=3){return C}D=gc.COMMA+C.slice(A-3);B=C.slice(0,A-3);return fn.AddCommas(B)+D};fn.Hilight=function(C,E){var A="background-color",D=fn.Hilight;D.astrElements=C;function B(){var G,F;if(!fn.IsDefined(D.dim)){return }for(G=0,F=D.astrElements.length;G<F;G++){yud.setStyle(D.astrElements[G],A,D.dim)}}yue.addFocusListener(C,function(F){if(!fn.IsDefined(D.dim)){D.dim=yud.getStyle(yue.getTarget(F).id,A)}B();yud.setStyle(yue.getTarget(F).id,A,E)})};fn.ErrorMsg=function(B,A){if(!fn.IsDefined(gv.ErrDialog)){gv.ErrDialog=new yw.SimpleDialog("errmsg",{effect:{effect:yw.ContainerEffect.FADE,duration:0.1},fixedcenter:true,modal:true,visible:false,draggable:true,icon:yw.SimpleDialog.ICON_WARN,buttons:[{text:"OK",handler:function(){this.hide()}}]})}gv.ErrDialog.setHeader(B);gv.ErrDialog.setBody(A);gv.ErrDialog.render(document.body);gv.ErrDialog.show()};fn.DeleteRow=function(A){yuc.asyncRequest("POST","delete_row.php",{success:function(B){window.status="Data Deleted"},failure:function(B){ErrorAlert("DeleteRow Failed",B.statusText,B.status)}},"table="+A.table+"&pkcol="+A.pkcol+"&pkval="+A.pkval);if(A.OK){A.OK(true,A.pkval)}};fn.DeleteConfirm=function(A,B){if(!fn.IsDefined(gv.DeleteConfirm)){gv.DeleteConfirm=new yw.SimpleDialog("delconfrm",{effect:{effect:yw.ContainerEffect.FADE,duration:0.1},fixedcenter:true,width:"15em",modal:true,visible:false,draggable:true,close:false,buttons:[{text:"<span class='delbut'>Delete</span>",handler:function(){this.hide();if(B.dt){var C=B.dt;fn.DeleteRow(B);C.deleteRow(C.getLastSelectedRecord())}}},{text:"<span class='delcan'>Cancel</span>",handler:function(){this.hide()}}]})}gv.DeleteConfirm.setHeader("<span class='delhdr'>Confirm Deletion</span>");gv.DeleteConfirm.setBody("<span class='delmsg'>"+A+"</span>");gv.DeleteConfirm.render(document.body);gv.DeleteConfirm.show()};fn.ClearForm=function(){var B=yud.getElementsByClassName("input","input");for(var C=0,A=B.length;C<A;C++){B[C].value=gc.NULLSTR}};fn.LoadAC=function(A){var D={},C={},B,E=A.source;fn.LoadAC.IdCounter=fn.LoadAC.IdCounter||0;if(fn.IsDefined(A.data)){D=new yu.LocalDataSource(A.data);A.force=true;A.showLength=A.data.length}else{D=new yu.XHRDataSource("loadac.php",{maxCacheEntries:5,responseType:yu.XHRDataSource.TYPE_TEXT,responseSchema:{recordDelim:gc.NL,fieldDelim:"~"}})}function F(){var J,I,H,G="open";if(fn.IsDefined(A.toggle)){J=yud.get(A.toggle);I=new yw.Button({container:J});H=function(K){if(!yud.hasClass(J,G)){yud.addClass(J,G)}if(C.isContainerOpen()){C.collapseContainer()}else{C.getInputEl().focus();setTimeout(function(){C.sendQuery(gc.NULLSTR)},0)}};I.on("click",H);C.containerCollapseEvent.subscribe(function(){yud.removeClass(J,G)})}}if(A.queryLength<0){alert("queryLength Must Be >= 0, forcing default of 0");A.queryLength=0}if(yl.isUndefined(A.force)){A.force=false}if(yl.isUndefined(A.queryLength)){A.queryLength=0}if(yl.isUndefined(A.showLength)){A.showLength=20}if(yl.isUndefined(A.markup.div)){A.markup.div="ac-container-"+fn.LoadAC.IdCounter++;B=document.createElement("div");B.id=A.markup.div;yud.get(A.markup.input).parentNode.appendChild(B)}C=new yw.AutoComplete(A.markup.input,A.markup.div,D,{prehighlightClassName:"yui-ac-prehighlight",useShadow:true,queryDelay:0.1,minQueryLength:A.queryLength,animVert:true,animSpeed:0.05,maxResultsDisplayed:A.showLength,forceSelection:A.force,typeAhead:true,useIFrame:true});if(A.preload){D.doBeforeCallback=function(J,G,H,I){H.results.splice(0,0,A.preload);return H}}if(A.selhandler){C.itemSelectEvent.subscribe(A.selhandler)}if(A.changehandler){C.unmatchedItemSelectEvent.subscribe(A.changehandler)}if(!fn.IsDefined(A.data)){C.generateRequest=function(G){if(A.clear){yud.get(A.clear).value=gc.NULLSTR}if(A.linked){return"?tbl="+E.table+"&col="+E.displaycol+"&id="+E.idcol+"&linkcol="+A.linked.linkcol+"&linkval="+yud.get(A.linked.linkval).value+"&prefix="+G}else{return"?tbl="+E.table+"&col="+E.displaycol+"&id="+E.idcol+"&prefix="+G}}}F();return{AC:C,DS:D}};fn.FormatNumber=function(D,C){var A,E,F;if(yl.isNull(D)){return D}function B(G){return G.replace(/[\D]/g,gc.NULLSTR)}if(!fn.IsDefined(C.Commas)){C.Commas=false}if(!fn.IsDefined(C.DecWidth)){C.DecWidth=0}if(C.Type===fn.FormatNumber.Integer){D=B(D);if(D.length<=C.IntWidth){if(C.Commas){D=fn.AddCommas(D)}}else{fn.ErrorMsg(gv.ERROR[100],"The Number Must Contain No More Than "+C.IntWidth+" Digits.")}}else{D=D.replace(/[\,]/g,gc.NULLSTR);A=D.split(/\./);if(A.length>2){fn.ErrorMsg(gv.ERROR[100],"There Is More Than One Decimal Point.")}E=B(A[0]);if(E.length<=C.IntWidth){E=fn.AddCommas(E)}else{fn.ErrorMsg(gv.ERROR[100],"Decimal Number Has More Than "+C.IntWidth+" Digits Before the Decimal Point.")}if(C.DecWidth>0){if(A.length===2){F=B(A[1]);if(F.length>C.DecWidth){fn.ErrorMsg(gv.ERROR[100],"There are Too Many Digits After Decimal Point.")}while(F.length<C.DecWidth){F=F.replace(/$/,"0")}}else{F=gc.NULLSTR;while(F.length<C.DecWidth){F=F.replace(/$/,"0")}}D=E+gc.PERIOD+F}else{D=E}}return D};fn.FormatNumber.Integer=1;fn.FormatNumber.Decimal=2;fn.EditSQLDate=function(A){if(fn.IsDefined(A)){var B=new Date(Date.parse(A.replace(/\-/g,gc.BLANK)));var C=B.toDateString().split(gc.BLANK);return fn.EditSQLDate.Months[C[1]]+gc.SLASH+C[2]+gc.SLASH+C[3]}else{return gc.NULLSTR}};gc.DateFormat={US:1,SQL:2};fn.FormatDate=function(B,A){if(fn.IsDefined(B)){switch(A){case (gc.DateFormat.US):return B;break;case (gc.DateFormat.SQL):return yu.Date.format(new Date(B),{format:"%F"});default:alert("Bad Date Format Passed to fn.FormatDate");return gc.NULLSTR}}else{return gc.NULLSTR}};fn.EditSQLDate.Months={Jan:"01",Feb:"02",Mar:"03",Apr:"04",May:"05",Jun:"06",Jul:"07",Aug:"08",Sep:"09",Oct:"10",Nov:"11",Dec:"12"};fn.EditZip=function(){function A(D){var F=D.replace(/\D/g,gc.NULLSTR);var C=F.length;if(C===5){return F}else{if(C===9){var E=F.match(/(\d{5})(\d{4})/);return E[1]+"-"+E[2]}else{fn.ErrorMsg(gv.ERROR[103],"A US Zip Must Be Either 5 or 9 Digits.");return D}}}function B(F,E){var H,E,C;var G={AB:"T",BC:"V",MB:"R",NB:"E",NL:"A",NT:"X",NS:"B",NU:"X",ON:"KLMNP",PE:"C",QC:"GHJ",SK:"S",YT:"Y"};strWork=fn.RemoveBlanks(F.toUpperCase());var D=strWork.match(/([A-Z])(\d)([A-Z])(\d)([A-Z])(\d)/);if(D===null){fn.ErrorMsg(gv.ERROR[104],"A Candian Postal Code Must Be:<br>Letter-Digit-Letter Digit-Letter-Digit.<br><br>For "+E+", the First Letter Must be: "+G[E].match(/./g).join(", ")+gc.PERIOD);return F}if(G[E]===undefined){fn.ErrorMsg(gv.ERROR[105],"The Canadian Provence Is Invalid.");return F}if(G[E].indexOf(D[1])>-1){return D[1]+D[2]+D[3]+gc.BLANK+D[4]+D[5]+D[6]}else{fn.ErrorMsg(gv.ERROR[104],"The First Letter Does Not Correspond to the Provence.<br><br>For "+E+", the First Letter Must be: "+G[E].match(/./g).join(", ")+gc.PERIOD);return F}}if(arguments[0].length===0){return gc.NULLSTR}switch(arguments.length){case 1:case 2:strCode=arguments[0];strProvence=gv.NULLSTR;strCountry="US";break;case 3:strCode=arguments[0];strProvence=arguments[1];strCountry=arguments[2];break}if(strCountry.toUpperCase()=="US"){return A(strCode)}else{if(strCountry.toUpperCase()=="CA"){return B(strCode,strProvence)}else{return A(strCode)}}};fn.CompressBlanks=function(A){return A.replace(/(\S+)(\s{2,})/g,"$1 ").replace(/^\s*/,gc.NULLSTR).replace(/\s*$/,gc.NULLSTR)};fn.RemoveBlanks=function(A){return A.replace(/\s/g,gc.NULLSTR)};fn.ToProperCase=function(A){return fn.CompressBlanks(A).toLowerCase().replace(/^(.)|\s(.)/g,function(B){return B.toUpperCase()})};fn.ValidateText=function(A,B){if(A){return A.replace(B,gc.NULLSTR)}else{return gc.NULLSTR}};fn.EditPhone=function(E){var B,D,A,C={},F=fn.EditPhone;if(!F.aReplace){F.aReplace=[];F.aText=[];F.aText[7]=[];F.aText[10]=[];F.aReplace[7]=/(\d{3})(\d{4})/;F.aReplace[10]=/(\d{3})(\d{3})(\d{4})/;F.aText[7][gv.oPhoneFormat.dashes]="$1-$2";F.aText[7][gv.oPhoneFormat.parens]="$1-$2";F.aText[7][gv.oPhoneFormat.dots]="$1.$2";F.aText[10][gv.oPhoneFormat.dashes]="$1-$2-$3";F.aText[10][gv.oPhoneFormat.parens]="($1) $2-$3";F.aText[10][gv.oPhoneFormat.dots]="$1.$2.$3"}if(arguments.length===2){B=arguments[1]}else{B=gv.oPhoneFormat.dashes}D=E.replace(/\D/g,gc.NULLSTR);A=D.length;if((A===7)||(A===10)){return{error:false,value:D.replace(F.aReplace[A],F.aText[A][B])}}else{fn.ErrorMsg(gv.ERROR[106],"A Phone Number Must Have 7 or 10 Digits.");return{error:true,value:E}}};fn.ReplyOK=function(A){return !yl.JSON.parse(A).Reply.Header.Status};fn.ReplyData=function(A){return yl.JSON.parse(A).Reply.Data};fn.SaveWait=function(B){var A=fn.SaveWait;if(B==="hide"){if(A.Panel){A.Panel.hide()}return }if(A.Panel){A.Panel.show()}else{A.Panel=new yw.Panel("saveWait",{width:"240px",fixedcenter:true,close:false,draggable:false,zindex:4,modal:true,visible:false});if(arguments.length===1){A.Panel.setHeader("Saving Data, Please Wait...")}else{A.Panel.setHeader(arguments[1])}A.Panel.setBody('<img src="http://l.yimg.com/a/i/us/per/gr/gp/rel_interstitial_loading.gif" />');A.Panel.render(document.body);A.Panel.show()}};fn.AddDialog=function(C){var F,J,I,A;var H="green",D="'Times New Roman',Times,serif",E="bold",B="1.2em";var G;G=(C.AddButtonLabel?C.AddButtonLabel:"Add");F=new yw.Button(C.id,{type:"push",label:G,title:C.header,onclick:{fn:function(){I.show()}}});J=document.createElement("div");J.id=C.div;document.body.appendChild(J);I=new yw.Dialog(C.div,{visible:false,context:[C.id,"tl","bl"],underlay:"none",close:false,modal:true,buttons:[{text:"Add",handler:C.addHandler,isDefault:false},{text:"Cancel",handler:function(){this.cancel()},idDefault:true}]});I.setHeader(C.header);I.setBody(C.body);I.render();A=C.div+"_h";yud.setStyle(A,"color",fn.IsDefined(C.color)?C.color:H);yud.setStyle(A,"fontFamily",fn.IsDefined(C.font)?C.font:D);yud.setStyle(A,"fontWeight",fn.IsDefined(C.weight)?C.fontWeight:E);yud.setStyle(A,"fontSize",fn.IsDefined(C.fontSize)?C.fontSize:B)};fn.CreateAddForm=function(D){var C,B,A;C="<form>";for(B=0,A=D.length;B<A;B++){C+="<p>"+D[B].label+'</p><input type="text" id = '+D[B].id+">"}C+="</form>";return C};fn.SimpleAddDialog=function(C){var F,J,I,A,G;var H="green",D="'Times New Roman',Times,serif",E="bold",B="1.2em";G=C.Container?C.Container:fn.NextID();J=document.createElement("div");J.id=G;document.body.appendChild(J);I=new yw.Dialog(G,{visible:false,context:[C.Link,"tl","bl"],underlay:"none",close:false,modal:true,buttons:[{text:"Add",handler:C.AddHandler,isDefault:false},{text:"Cancel",handler:function(){this.cancel()},isDefault:true}]});I.setHeader(C.Header);I.setBody(C.Body);I.render();A=G+"_h";yud.setStyle(A,"color",fn.IsDefined(C.color)?C.color:H);yud.setStyle(A,"fontFamily",fn.IsDefined(C.font)?C.font:D);yud.setStyle(A,"fontWeight",fn.IsDefined(C.weight)?C.fontWeight:E);yud.setStyle(A,"fontSize",fn.IsDefined(C.fontSize)?C.fontSize:B);return I};fn.InsertRow=function(F,C,D){var B=[],E,A;for(E=0,A=D.length;E<A;E+=2){B.push({col:D[E],val:D[E+1]})}yuc.asyncRequest("POST","insert_row.php",{success:function(G){C.call(null,G)},failure:function(G){fn.ErrorAlert("InsertRow Failed",G.statusText,G.status)}},"o="+yl.JSON.stringify({table:F,data:B}))};fn.CreateElement=function(B){var A;if(!B){B={}}if(!B.type){B.type="div"}A=document.createElement(B.type);if(!B.id){B.id=fn.NextID()}A.id=B.id;if(B.target){if(typeof B.target==="string"){B.target=yud.get(B.target)}B.target.appendChild(A)}else{document.body.appendChild(A)}return B.id};fn.NextID=function(){var A=fn.IsDefined(fn.NextID.Counter)?++fn.NextID.Counter:(fn.NextID.Counter=0);if(arguments.length==0){return"dyn-el-"+A}else{return arguments[0]+A}};fn.MakeToolTip=function(D){var B,C;B=fn.IsDefined(D.Delay)?D.Delay:250;C=fn.IsDefined(D.Dismiss)?D.Dismiss*1000:2000;var A=new yw.Tooltip(fn.NextID(),{context:D.ID,text:D.Text,showDelay:B,autodismissdelay:C})};fn.MakePanel=function(F){var D,C,A=F.ClickID;D=fn.IsDefined(F.Width)?F.Width:"65%";C=function(J){var L,H,I,G,K;L=new yw.Panel(fn.NextID(),{close:true,visible:false,fixedcenter:true,width:D,underlay:"none",constraintoviewport:true});L.setHeader(F.Header);L.setBody(J.responseText);L.render(fn.CreateElement());if(fn.IsDefined(F.Styles)){if(fn.IsDefined(F.Styles.Body)){I=F.Styles.Body;for(K in I){yud.setStyle(L.body,K,I[K])}}if(fn.IsDefined(F.Styles.Header)){G=F.Styles.Header;for(K in G){yud.setStyle(L.header,K,G[K])}}}return L};function B(H){var I,G;I=yud.get(H);G=yud.getRegion(I);yud.setXY(I,[(yud.getViewportWidth()-G.width)/2,(yud.getViewportHeight()-G.height)/2])}function E(){if(!fn.IsDefined(E.oPanel)){fn.SaveWait("show","Processing, Please Wait...");var G=yu.Connect.asyncRequest("GET",F.URI+"?panel="+F.Panel,{success:function(H){E.oPanel=C(H);fn.SaveWait("hide");E.oPanel.show();B(E.oPanel.id)}},null)}else{E.oPanel.show();B(E.oPanel.id)}}yue.addListener(A,"click",E);yue.addListener(A,"mouseover",function(){yud.setStyle(A,"cursor","pointer");yud.setStyle(A,"fontWeight","bold")});yue.addListener(A,"mouseout",function(){yud.setStyle(A,"cursor","default");yud.setStyle(A,"fontWeight","normal")})};