var DB="CAR";var YourCarHTML="";var tbVRMval="";var sLastSearch="";var sLastMod=0;var SortType="List";var jqDialogHandle=null;var NewLaunchCache=null;var LoggingEnabled=false;var ajax_load2='<div class="ajLoad"><span>Loading...</span><img src="style/img/ajax-loader.gif" /></div>';var ajax_load=ajax_load2;$.ajaxSetup({cache:false});$(function(){$(window).hashchange(function(){Cookie.GetID();DialogClose();if(SubPageNavigation()){return}var h=window.location.hash;var arr=h.split("?");var s=arr[0].substring(1).split("&")[0];var pfx="_OnLoad";if($(arr[0]+"Form").length){log.write("hashchange - stay: "+h);if(s!=""){if(eval("typeof "+s+pfx+" == 'function'")){eval(s+pfx+"()")}}else{window.location.reload()}}else{var p=s+".aspx?Params="+encodeURIComponent(arr[1]);log.write("hashchange - load "+p+": "+h);LoadSection(p)}})});function SubPageNavigation(){var Params,arr,PageName;var h=window.location.hash;arr=h.split("?");if(arr.length<2){return false}Params=arr[1].split("&");if(Params.length<2){return false}if((Params[0]!="SubPages")||(Params[1]=="")){return false}PageName=arr[0].substring(1);if($("#"+Params[1]).length){if(eval("typeof "+PageName+"_OnLoad"+" == 'function'")){log.write("hashchange - subpage: "+h);eval(PageName+"_OnLoad()");return true}}log.write("hashchange - subpage reload: "+h);LoadSection(PageName+".aspx");return true}function SetHash(s){window.location.hash=s}function AddHash(f,s){window.location.hash=EditHash(f,s,window.location.hash)}function RemHash2(f,h){if(f.indexOf(",")>-1){var ar=f.split(",");for(i=0;i<ar.length;i++){h=RemHash2(ar[i],h)}}var p=getParam(f,h);if(p!=""){h=h.replace("&"+f+"="+p,"");h=h.replace("?"+f+"="+p,"?");h=h.replace("?&","?")}return h}function RemHash(f){window.location.hash=RemHash2(f,window.location.hash)}function EditHash(f,s,h){h=RemHash2(f,h);var sep="?";if(h.indexOf("?")>-1){sep="&"}return h+sep+f+"="+s}function Load(h,u,f){Load.CreateCssLink(u);$(h).load(u,function(response,status,xhr){var State=true;if(status=="error"){State=false;log.text("Error: Load(): "+response)}if(typeof f=="function"){f(State)}})}Load.CreateCssLink=function(pageName){var cssName=pageName.split(".")[0];if(cssName.toUpperCase()=="SEARCHBAR"){cssName="Search"}var Html='<link rel="stylesheet" type="text/css" href="style/'+cssName+'.css" />';if($('head>link:[href*="'+cssName+'.css"]').length){return}$("head").append(Html)};function LoadSection(SecPage,func_Callback){$("#Content").html(ajax_load);if(func_Callback==null){Load("#Content",SecPage)}else{Load("#Content",SecPage,func_Callback)}$("#ddmTitle").html("Menu"+"<span></span>")}function DialogClose(){if(jqDialogHandle){jqDialogHandle.dialog("destroy")}jqDialogHandle=null}function logout(){Cookie.DeleteID();Get_JSON("ws.svc/Logout",callback);function callback(a){LoadSection("Login.aspx");Load("#Menu","Menu_Top.aspx");SetHash("Search")}}Object.fromXML=function(source,includeRoot){if(typeof source=="string"){try{if(window.DOMParser){source=(new DOMParser()).parseFromString(source,"application/xml")}else{if(window.ActiveXObject){var xmlObject=new ActiveXObject("Microsoft.XMLDOM");xmlObject.async=false;xmlObject.loadXML(source);source=xmlObject;xmlObject=undefined}else{throw new Error("Cannot find an XML parser!")}}}catch(error){return false}}var result={};if(source.nodeType==9){source=source.firstChild}if(!includeRoot){source=source.firstChild}while(source){if(source.childNodes.length){if(source.tagName in result){if(result[source.tagName].constructor!=Array){result[source.tagName]=[result[source.tagName]]}result[source.tagName].push(Object.fromXML(source))}else{result[source.tagName]=Object.fromXML(source)}}else{if(source.tagName){result[source.tagName]=source.nodeValue}else{result=source.nodeValue}}source=source.nextSibling}return result};function Get_JSON(wsMethod,func_CallBack){$.ajax({url:wsMethod,type:"GET",dataType:"json",error:function(jqXHR,textStatus,errorThrown){var a={"Success":false,"ErrorMessage":"ajax - Get_JSON - error="+wsMethod+"-"+textStatus+", "+errorThrown};if(func_CallBack){func_CallBack(a)}},success:function(data,textStatus,jqXHR){try{var a=eval(data)}catch(err){a={"Success":false,"ErrorMessage":"Malformed eval(JSON.outer)="+wsMethod+"-"+err.description}}if(a.Success==false){if(func_CallBack){func_CallBack(a)}return}if(!a.DS){if(func_CallBack){func_CallBack(a)}return}try{var DS=eval(a.DS);if(func_CallBack){func_CallBack(a,DS)}return}catch(err){a={"Success":false,"ErrorMessage":"Malformed eval(JSON.inner)="+wsMethod+"-"+err.description};if(func_CallBack){func_CallBack(a)}}}})}function getHash(name){var s=window.location.hash;return getParam(name,s)}function getParam(name,url){name=name.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var regexS="[\\?&]"+name+"=([^&#]*)";var regex=new RegExp(regexS);var results=regex.exec(url);if(results==null){return""}return decodeURIComponent(results[1].replace(/\+/g," "))}var log={line:0,clear:function(){if(LoggingEnabled!=true){return}if(typeof console==="object"){try{console.clear()}catch(err){console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")}this.line=0;return}m=this.GetConsoleWindow();if(m==null){return}m.innerHTML="";this.line=0},write:function(txt){if(LoggingEnabled!=true){return}if(typeof console==="object"){console.log(++this.line+": "+txt);return}m=this.GetConsoleWindow();if(m==null){return}$(m).prepend(++this.line+": "+txt+"<br/>")},text:function(txt){if(LoggingEnabled!=true){return}if(typeof console==="object"){console.log(++this.line+": "+txt);return}m=this.GetConsoleWindow();e=window.dbgwnd.document.getElementById("Escaped");if((m==null)||(e==null)){return}$(e).text(txt);txt=$(e).html();$(m).prepend(++this.line+": "+txt+"<br/>")},GetConsoleWindow:function(){if(window.dbgwnd){if(!window.dbgwnd.closed){return(window.dbgwnd.document.getElementById("main"))}}var Html='            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">            <html xmlns="http://www.w3.org/1999/xhtml">                <head><title></title></head>                <body style="background-color:black">                    <div id="main" style="color:white;font-size:12px;font-family:Courier New;"></div>                    <div id="Escaped" style="display:none;visibility:hidden;"></div>                </body>            </html>';window.dbgwnd=window.open("","debug","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,top=0,left=0,width=600,height=250");if(!window.dbgwnd){return(null)}window.dbgwnd.document.write(Html);this.line=0;return(window.dbgwnd.document.getElementById("main"))}};function NewLaunch(){if((typeof DB==="undefined")||(DB==null)||(DB=="")){DB="CAR"}if((NewLaunchCache!=null)){$("#rightNewLaunch div").html(NewLaunchCache);DnD_MakeDraggables("#rightNewLaunch .dnd_individual");$("#rightNewLaunch img").load(function(){$(this).css("opacity","0.01");$(this).css("visibility","visible");$(this).animate({opacity:1},1000)});return}log.write("NewLaunch "+DB);$("#rightNewLaunch div").html(ajax_load2);$.getJSON("ws.svc/NewLaunch?DB="+DB,function(s){var Href;var a=eval(s);if(a.Success){var m=eval(a.DS);var c='<input type="hidden" id="hdnNLDB" value="'+DB+'"/>';for(var i=0;i<m.Table.length;i++){var dr=m.Table[i];Href="\"javascript:SetHash('VehicleDetails?DB="+DB+"&ID="+dr.my_Id+"')\"";c+='<div class="RecentEntry dnd_individual" >'+'<div style="display:none" class="dndiset">'+"{"+'"DB":"'+DB+'",'+'"VehID":"'+dr.my_Id+'",'+'"PicID":"'+dr.my_Id+'",'+'"Txt":"'+dr.Mod+'",'+'"TxtEx":"'+dr.Der+'"'+"}"+"</div>"+'<a class="RctSpA0" href='+Href+">"+'<img src="GetImage.aspx?DB='+DB+"&ID="+dr.my_Id+'&Width=60&Height=45" style="visibility:hidden"/>'+"</a>"+'<a class="RctSpA1" href='+Href+">"+dr.Mod+"<br/>"+dr.Der+"</a>"+"</div>"}$("#rightNewLaunch div").html(c);NewLaunchCache=c;DnD_MakeDraggables("#rightNewLaunch .dnd_individual");$("#rightNewLaunch img").load(function(){$(this).css("opacity","0.01");$(this).css("visibility","visible");$(this).animate({opacity:1},1000)})}})}function YourCar(f){if(($("#yourCar").html()=="")&&(YourCarHTML!="")&&(YourCarHTML.indexOf("Loading")==-1)){$("#yourCar").html(YourCarHTML);$("#tbVRM").val(tbVRMval);YourCar_MakeItDnDable();YourCar_LabelsToAnchors();return}$("#yourCar").html(ajax_load2);$.getJSON("ws.svc/YourCar_Get",function(s){var a=eval(s);if(a.Success){var c="Drag your vehicle here or enter its Registration number";if(a.DS!=""){var m=eval(a.DS);if(m.Table.length>0){var dr=m.Table[0];var Href="\"javascript:SetHash('VehicleDetails?DB="+dr["DB"]+"&ID="+dr["CAPID"]+"')\"";c="<a href="+Href+">"+'<img src="GetImage.aspx?DB='+dr["DB"]+"&ID="+dr["CAPID"]+'&Width=120&Height=90">'+"</a>"+'<label class="ycMan">'+dr["CVehicle_ManText"]+"</label>"+'<label class="ycMan">'+dr["CVehicle_ModText"]+"</label>"+"<label>"+dr["CVehicle_DerText"]+"</label>";$("#tbVRM").val(dr["VRM"])}}$("#yourCar").html(c);YourCarHTML=c;tbVRMval=$("#tbVRM").val();YourCar_MakeItDnDable();YourCar_LabelsToAnchors()}else{HandleErr(a.ErrorMessage,"yourCar")}if(f!=null){f()}})}function VRMin(){if($("#tbVRM").val()=="Enter Reg"){$("#tbVRM").val("")}}function VRMout(){if($("#tbVRM").val()==""){$("#tbVRM").val("Enter Reg")}}function disableEnterKey(e){var key;if(window.event){key=window.event.keyCode}else{key=e.which}return(key!=13)}function VRMkey(e){var key=e.keyCode||e.which;if(key==13){$("#yourCar").html("Looking up Registration number...");$.getJSON("ws.svc/YourCarVRM?VRM="+$("#tbVRM").val(),function(s){var a=eval(s);if(a.Success){$("#yourCar").html(a.String);var DB,ID;var Url=$("#yourCar:visible img").prop("src");if(Url!="undefined"){DB=getParam("DB",Url);ID=getParam("ID",Url);$("#yourCar img").wrap("<a href=\"javascript:SetHash('VehicleDetails?DB="+DB+"&ID="+ID+"')\" />")}YourCarHTML=$("#yourCar").html();tbVRMval=$("#tbVRM").val();YourCar_MakeItDnDable();YourCar_LabelsToAnchors()}else{alert(a.ErrorMessage)}});return false}}function YourCarDnD(DB,CAPID){$("#yourCar").html("Looking up...");$.getJSON("ws.svc/YourCarFromCAPID?DB="+DB+"&CAPID="+CAPID,function(s){var a=eval(s);if(a.Success){$("#yourCar").html(a.String);$("#yourCar img").wrap("<a href=\"javascript:SetHash('VehicleDetails?DB="+DB+"&ID="+CAPID+"')\" />");YourCarHTML=$("#yourCar").html();tbVRMval=$("#tbVRM").val();YourCar_MakeItDnDable();YourCar_LabelsToAnchors()}else{alert("YourCarDnD: "+a.ErrorMessage)}});return false}function YourCar_LabelsToAnchors(){if(!$("#yourCar:visible label").length){return}var ManText=$("#yourCar:visible label").eq(0).html();var ModText=$("#yourCar:visible label").eq(1).html();var DerText=$("#yourCar:visible label").eq(2).html();var Url=$("#yourCar:visible img").prop("src");if(Url=="undefined"){return}var DB=getParam("DB",Url);var ID=getParam("ID",Url);if(DB==""||ID==""){return}var Href="\"javascript:SetHash('VehicleDetails?DB="+DB+"&ID="+ID+"')\"";$("#yourCar label").eq(0).replaceWith('<a class="ycaMan" href='+Href+" >"+ManText+"</a>");$("#yourCar label").eq(0).replaceWith('<a class="ycaMod" href='+Href+" >"+ModText+"</a>");$("#yourCar label").eq(0).replaceWith('<a class="ycaDer" href='+Href+" >"+DerText+"</a>")}function YourCar_MakeItDnDable(){var Html,DB,ID,ManText,ModText,DerText,Description;DnD_YourCarMakeDroppables(".dnd_yourcardropbox:visible");var Url=$("#yourCar img").prop("src");if(Url=="undefined"){return}DB=getParam("DB",Url);ID=getParam("ID",Url);if(DB==""||ID==""){return}Html="My Car";if(DB=="HGV"||DB=="LCV"){Html="My Van"}$("#rightYour h2").html(Html);if(!$("#yourCar .dnd_individual").length){ManText=$("#yourCar label").eq(0).html();ModText=$("#yourCar label").eq(1).html();DerText=$("#yourCar label").eq(2).html();Description=ManText+" "+ModText+" "+DerText;Html=$("#yourCar").html();Html='<div class="dnd_individual" >'+'<div style="display:none" class="dndiset">'+"{"+'"DB":"'+DB+'",'+'"VehID":"'+ID+'",'+'"PicID":"'+ID+'",'+'"Txt":"'+Description+'"'+"}"+"</div>"+Html+"</div>";$("#yourCar").html(Html)}DnD_MakeDraggables("#yourCar .dnd_individual")}var Token={StrNames:["BIKES","CAR","HGV","LCV","GREYS"],Encode:function(Str){var i;Str=Str.toUpperCase();for(i=0;i<this.StrNames.length;i++){if(this.StrNames[i]==Str){break}}if(i>=this.StrNames.length){i=35}return(i.toString(36).toUpperCase())},Decode:function(Token){var i;if(typeof Token==="number"){i=""+Token}i=parseInt(Token,36);if(isNaN(i)||(i<0)||(i>=this.StrNames.length)){i=1}return(this.StrNames[i])}};function HandleErr(s,t){if(s!=("NOTLOGGEDIN")){if(s.startsWith("ERR:")){var err=s.split("ERR:")[1];if(t!=""){SetHTML(t,err)}else{alert(err)}return false}else{return true}}else{window.location="Default.aspx"}}var Cookie={ID:null,Save:function(c_name,value,exdays){var expires="";var exdate=new Date();if(exdays!=null){exdate.setDate(exdate.getDate()+exdays);expires="; expires="+exdate.toUTCString()}value=this.ChecksumString(value);c_name+=this.GetID();document.cookie=c_name+"="+value+expires+"; path=/"},Load:function(c_name){var i,pname,pvalue="";var ARRcookies=document.cookie.split(";");c_name+=this.GetID();for(i=0;i<ARRcookies.length;i++){pname=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));pname=pname.replace(/[()'#?&;<> ]/gi,"");if(c_name!=pname){continue}pvalue=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);pvalue=this.ChecksumValidate(pvalue);return pvalue}return""},Delete:function(c_name){c_name+=this.GetID();createCookie(c_name,"",-1)},ChecksumString:function(Str){var i,Checksum=58718;if((Str==null)||(Str=="")){return""}Str=""+Str;for(i=0;i<Str.length;i++){Checksum+=Str.charCodeAt(i)}Checksum="00000"+Checksum;Checksum=Checksum.substr(Checksum.length-5);return Checksum+Str},ChecksumValidate:function(Str){var i,Checksum=58718,HeaderChecksum;if((Str==null)||(Str=="")){return""}HeaderChecksum=Str.substr(0,5);Str=Str.substr(5);for(i=0;i<Str.length;i++){Checksum+=Str.charCodeAt(i)}Checksum="00000"+Checksum;Checksum=Checksum.substr(Checksum.length-5);if(Checksum!=HeaderChecksum){return""}return Str},GetID:function(callback){var ID=Cookie.ID;if(ID==null){Get_JSON("ws.svc/GetCookieID",function(a,DS){if(a.Success==false){log.text("**** GetCookieID Failed****"+a.ErrorMessage)}else{Cookie.ID=a.String}if(typeof callback=="function"){callback()}});ID="00000000"}else{if(typeof callback=="function"){callback()}}return ID},DeleteID:function(){Cookie.ID=null}};function FormatMoney(n){var c=2;var d=".";var t=",";c=isNaN(c=Math.abs(c))?2:c,d=d==undefined?",":d,t=t==undefined?".":t,s=n<0?"-":"",i=parseInt(n=Math.abs(+n||0).toFixed(c))+"",j=(j=i.length)>3?j%3:0;return"£"+s+(j?i.substr(0,j)+t:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+t)+(c?d+Math.abs(n-i).toFixed(c).slice(2):"")}function GetSearchBar(Selector,Callback){if($(Selector+" #SearchBar").length){UpdateSearchBar();if(typeof Callback=="function"){Callback()}return}if(typeof SearchBarCache!="undefined"){$(Selector).html(SearchBarCache);UpdateSearchBar();if(typeof Callback=="function"){Callback()}return}Load(Selector,"SearchBar.aspx",function(){SearchBarCache=$(Selector+" #SearchBar").eq(0).clone().wrap("<div>").parent().html();UpdateSearchBar();if(typeof Callback=="function"){Callback()}})}function UpdateSearchBar(){Gm.Remove();Gm.Append("#SearchBar #SearchImg",-12,57);MT_DisplayDB();if($("#SearchText").val()==""){$("#SearchText").val(sLastSearch)}};
