﻿function CarInfo(){
this.urlEncumbrance = "http://w2.brreg.no/motorvogn/heftelser_motorvogn.jsp?regnr=";
this.urlPeriodicControl = "https://svvgw.vegvesen.no/http://timeplan.vegvesen.no/exttime/tidspunkt.aspx?__EVENTTARGET=ImageButton1&txtRegNr=";
this.addStyleSheet = function(){
    var dcss  = document.createElement('link');
    dcss.rel = 'stylesheet';
    dcss.type = 'text/css';
    dcss.href = 'js/carinfo/carinfo.css';
    document.getElementsByTagName('head')[0].appendChild(dcss);
};
this._gotoEncumbranceUrl = function(){
    window.open(this.urlEncumbrance + document.getElementById('carinfo_input_encumbrance').value);
};
this._gotoPeriodicUrl = function(){
    window.open(this.urlPeriodicControl + document.getElementById('carinfo_input_control').value);
};
this.createControl = function(){
    var box = document.createElement('div');
    var txt = document.createElement('input');
    var btn = document.createElement('input');
    var form = document.createElement('form');
    var title = document.createElement('p');
    var titletext = document.createTextNode('Heftelser:');
    var me = this;
    document.write("<div id='carinfo_container'></div>");
    box.className = 'carinfo_module';
    txt.id = 'carinfo_input_encumbrance';
    txt.tabindex = 5000;
    btn.className = 'carinfo_submit';
    btn.tabindex = 5001;
    btn.type = 'submit';
    btn.value = 'Søk';
    btn.onclick = function() {me._gotoEncumbranceUrl();return false;};
    form.onsubmit = function() {me._gotoEncumbranceUrl();return false;};
    title.appendChild(titletext);                         
    box.appendChild(title);
    box.appendChild(txt);
    box.appendChild(btn);
    form.appendChild(box);
    document.getElementById('carinfo_container').appendChild(form);
    box = document.createElement('div');
    txt = document.createElement('input');
    btn = document.createElement('input');
    form = document.createElement('form');
    box.className = 'carinfo_module';
    title = document.createElement('p');
    titletext = document.createTextNode('Periodisk EU kontroll:');
    txt.id = 'carinfo_input_control';
    txt.tabindex = 5003;
    btn.className = 'carinfo_submit';
    btn.tabindex = 5004;
    btn.type = 'submit';
    btn.value = 'Søk';
    btn.onclick = function() {me._gotoPeriodicUrl();return false;};                        
    form.onsubmit = function() {me._gotoPeriodicUrl();return false;};
    title.appendChild(titletext);                         
    box.appendChild(title);   
    box.appendChild(txt);
    box.appendChild(btn);
    form.appendChild(box);
    document.getElementById('carinfo_container').appendChild(form);
};
}
var carInfo = new CarInfo();
carInfo.addStyleSheet();
carInfo.createControl();