function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}

//disableSelection(document.body)

var message="Welcome to www.sieuthimayvanphong.com !";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
//document.captureEvents(Event.MOUSEDOWN);
//document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
//document.onmousedown=clickIE4;
}

//document.oncontextmenu=new Function("alert(message);return false")

var idgen = 0;

var ElementTextCache = {};
var tblParentCache = {};
var JumpEl;
var jumpcount = 0;

function searchpage(searchBoxEl) {
    var searchText = searchBoxEl.value.toLowerCase();
    var liEls = document.getElementsByTagName('li');
    var matchCount = 0;
    var allParentUls = {};
    var matchedParentUls = {};
    var matchEl;
    for(var i = 0;i < liEls.length;i++) {
	    var innerText;
  
        if (!ElementTextCache[liEls[i].id] || ElementTextCache[liEls[i].id] == "") {
            var AddedsearchText = liEls[i].getAttribute('searchtext');
            innerText = liEls[i].innerHTML.replace(/\<[^\>]+\>/g,'').toLowerCase();
            if (AddedsearchText) { innerText += " " + AddedsearchText; }
            ElementTextCache[liEls[i].id] = innerText;
        } else {
            innerText = ElementTextCache[liEls[i].id];
        }


        var tblParent = getTblParent(liEls[i]);
        if (innerText.match(searchText)) {
            matchEl = liEls[i];
            matchCount++;
            

            liEls[i].className='searchshow';
            matchedParentUls[tblParent.id] = 1;
            allParentUls[tblParent.id] = tblParent;
        } else {
            allParentUls[tblParent.id] = tblParent;
            liEls[i].className='searchhide';
        }
    }
    if (matchCount == 0) {
        document.getElementById('gosearch').style.display='';
    } else {
        document.getElementById('gosearch').style.display='none';
    }

    for(var i in allParentUls) {
        if (matchedParentUls[i]) {
                allParentUls[i].className='searchshow';
        } else {
                allParentUls[i].className='searchhide';
        }
    }
}

function getTblParent(tagEl) {
    if (!tagEl.id) { 
        tagEl.id = 'idgen' + idgen++;
    }
    if (tblParentCache[tagEl.id]) { return tblParentCache[tagEl.id]; } 
    
    var thisEl = tagEl;
    while(thisEl.tagName != "TABLE" && thisEl.parentNode) {
        thisEl = thisEl.parentNode;
    }
    tblParentCache[tagEl.id] = thisEl;
    return thisEl;
}

function clearsearch() {
    var quickJumpEl = document.getElementById('quickjump');
    quickJumpEl.value='';
    searchpage(quickJumpEl);
    
}
function gosearch() {
    var lnkEls = jumpEl.getElementsByTagName('a');
    if (! lnkEls[0].name) {
        lnkEls[0].name = 'jump' + jumpcount++;
    }
    window.location.href='#' + lnkEls[0].name;
}
