uda / OpenLaw - Knesset version

// ==UserScript==
// @name         OpenLaw - Knesset version
// @namespace    http://www.knesset.gov.il/
// @version      0.3.4
// @description  Make the forms on knesset.gov.il work w/o M$ products
// @match        http://www.knesset.gov.il/laws/heb/template.asp*
// @match        http://knesset.gov.il/laws/heb/template.asp*
// @match        http://www.knesset.gov.il/privatelaw/Plaw_display.asp*
// @match        http://knesset.gov.il/privatelaw/Plaw_display.asp*
// @include      http://www.knesset.gov.il/laws/heb/template.asp*
// @include      http://knesset.gov.il/laws/heb/template.asp*
// @include      http://www.knesset.gov.il/privatelaw/Plaw_display.asp*
// @include      http://knesset.gov.il/privatelaw/Plaw_display.asp*
// @author       uda
// @license      MIT; http://opensource.org/licenses/MIT
// @copyright    2014, Yehuda Deutsch (http://0x59.net/)
// @run-at       document-body
// ==/UserScript==

var usw = (typeof this.unsafeWindow !== 'undefined') ? this.unsafeWindow : window;

var getElementByName = function(name) {
    return document.getElementsByName(name).length ? document.getElementsByName(name)[0] : {value:''};
};

var FromNumber = getElementByName('FmNum');
var ToNumber = getElementByName('ToNum');
var FindWord = getElementByName('FndWord');

var oldSndSelf = usw.SndSelf;
usw.SndSelf = function(first, start) {
    var url = 'http://www.knesset.gov.il/laws/heb/template.asp?';
    url += 'Type=' + document.frmSelf.Type.value;
    if (first !== undefined) {
        url += '&First=' + first;
    }
    if (start !== undefined) {
        url += '&Start=' + start;
    }
    if (FromNumber.value) {
        url += '&FmNum=' + FromNumber.value;
    }
    if (ToNumber.value) {
        url += '&ToNum=' + ToNumber.value;
    }
    if (FindWord.value) {
        url += '&FndWord=' + FindWord.value;
    }
    window.location.href = url;
};

var SubmitSelf = function(event) {
    if (event.keyCode == 13) SndSelf();
};

FromNumber.onkeypress = SubmitSelf;
ToNumber.onkeypress = SubmitSelf;
FindWord.onkeypress = SubmitSelf;

var oldSndFileD = usw.SndFileD;
usw.SndFileD = function(nID, nSubID) {
    document.frmFileD.action = 'OneResDoc.asp';
    oldSndFileD(nID, nSubID);
};

var oldValidation = usw.Validation;
usw.Validation = function (nTp, nStart, bNewSrch) {
    if (bNewSrch == true) {
        document.frmSndSelf.ckLawNo.checked = false;
        document.frmSndSelf.LawN.value = "";
        document.frmSndSelf.ckWord.checked = false;
        document.frmSndSelf.FndWord.value = "";
        document.frmSndSelf.ckDate.checked = false;
    }

    if (isNaN(document.frmSndSelf.LawN.value) == true) {
        alert("מספר חוק יכיל מספרים בלבד");
        return;
    }

    document.frmSndSelf.LawTp.value = nTp;
    document.frmSndSelf.RowStart.value = nStart;
    //document.frmSndSelf1.innerHTML = "<Input type=Hidden name=oo value=kjkj>";
    //MirrorForm(document.frmSndSelf, document.frmSndSelf1);
    document.all.frmSndSelf.submit();
};