﻿// JScript File
function wordWrap() {
    /******
    * wordWrap to firefox for big words
    * Creative Commons license * Version: 1.0 - 26/04/2006
    * Autor: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br - http://elmicoxcodes.blogspot.com
    * Uso: call the function on onload of body element.
    * put the class "word-wrap" on elements to wordwrap
    *******/
    var larg_total, larg_carac, quant_quebra, pos_quebra;
    var elementos, quem, caracs, texto, display_orig;

    elementos = document.getElementsByTagName("p")

    for (var i = 0; i < elementos.length; i++) {
        if (elementos[i].className == "word-wrap") {
            quem = elementos[i];

            quem.innerHTML = String(quem.innerHTML).replace(/ /g, "Ø")
            texto = String(quem.innerHTML)

            quem.innerHTML = " "

            display_orig = quem.style.display;
            quem.style.display = "block";
            larg_oficial = quem.offsetWidth;
            //alert("oficial: " + larg_oficial)
            //alert("display " + quem.style.display)
            if (!document.all) quem.style.display = "table";
            //alert("display " + quem.style.display)
            quem.innerHTML = texto;
            larg_total = quem.offsetWidth;
            //alert("total: " + larg_total)

            pos_quebra = 0;
            caracs = texto.length;
            texto = texto.replace(/Ø/g, " ")
            larg_carac = larg_total / caracs
            if (larg_total > larg_oficial) {
                quant_quebra = parseInt(larg_oficial / larg_carac)
                quant_quebra = quant_quebra - (parseInt(quant_quebra / 6)) //quanto menor o num, maior a garantia;
                quem.innerHTML = ""
                while (pos_quebra <= caracs) {
                    quem.innerHTML = quem.innerHTML + texto.substring(pos_quebra, pos_quebra + quant_quebra) + " "
                    pos_quebra = pos_quebra + quant_quebra;
                }
            } else {
                quem.innerHTML = texto;
            } //end if do larg_total>larg_oficial
            quem.style.display = display_orig;
        } //end if do word wrap
    } //end for loop dos elementos
}
function ConfirmDoYouWantToDelete() {
    if (confirm("?האם אתה בטוח רוצה לבצע מחיקה") == true)
        return true;
    else
        return false;
}

function ConfirmByMessage(message) {
    if (confirm(message) == true)
        return true;
    else
        return false;
}

function OpenPopupWindow(url, features) {
    window.open(url, 'Test', features)
}

function DocumentLocation(url) {
    document.location.href = url;
}



//configure the two variables below to match yoursite's own info

function addbookmark() {
    var bookmarkurl = "http://www.hovalot.org.il"
    var bookmarktitle = "הובלות בישראל"

    if (document.all)
        window.external.AddFavorite(bookmarkurl, bookmarktitle)
}

function EncodeURIFunction(url) {
    return encodeURI(url);
}

///CODropDownList///
// JScript File

function CODropDownList_Load(ddlControlId) {
    var ddlControl = document.getElementById(ddlControlId);
    if (ddlControl == null) //TODO: this might happen when a visible control is found in an invisible gridColumn
        return;
    CODropDownList_VerifyInit(ddlControl);
}


function CODropDownList_VerifyInit(ddlControl) {
    if (ddlControl.IsInited)
        return;
}

function CODropDownList_AllowNull(ddlControl) {
    return ddlControl.AllowNull == "true";
}

function IsDropDownValueWasChosen(source, args) {
    //debugger;
    if (args.Value == "0")
        args.IsValid = false;
    else
        args.IsValid = true;
}

//GUI Script
// Moving JavaScript Document



function ShowPicture(obj, img) {
    //alert('ShowPicture');
    //alert(img);
    obj.firstChild.src = img; //"images/box_on.gif";
}

function boxOpen(obj) {

    obj.firstChild.src = "images/box_on.gif";
}

function boxClose(obj) {
    obj.firstChild.src = "images/box_off.gif";
}

function showHelp(divId, title, txt, aEvent, tableWidth, imgObg) {
    //document.getElementById(divId).style.background = "yellow";
    var helpTable = document.getElementById(divId).firstChild;
    tableWidth = tableWidth ? tableWidth : 150;
    helpTable.style.width = tableWidth + "px";
    helpTable.parentNode.style.width = tableWidth + "px";
    helpTable.firstChild.firstChild.firstChild.innerText = title;
    helpTable.firstChild.firstChild.nextSibling.firstChild.innerText = txt;
    //showHelpContent(divId, aEvent)
    positionByImage(document.getElementById(divId), imgObg, helpTable)
}

function positionByImage(tablContent, imgObg, tblObj) {
    //debugger
    if (!tablContent)
        return;
    tablContent.style.display = "block";
    tablContent.style.position = "absolute";
    tablContent.style.left = (imgObg.offsetLeft - tblObj.offsetWidth) + "px";
    tablContent.style.top = (imgObg.offsetTop + (imgObg.offsetHeight / 2) - (tblObj.offsetHeight / 2)) + "px";



}


function showHelpContent(helpID, aEvent, helpWidth) {
    var posx = 0;
    var posy = 0;
    var helpDiv;
    var winWidth = 1024;
    var e = aEvent ? aEvent : window.event;
    if (document.layers)	   //NN4+
    {
        helpDiv = document.layers[helpID]
    }
    else (document.getElementById)	  //gecko(NN6) + IE 5+
    {
        helpDiv = document.getElementById(helpID)
    }
    if (helpWidth)
        helpDiv.style.width = helpWidth + "px";
    else
        helpDiv.style.width = helpDiv.getAttribute("fixedWidth") + "px";
    if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) { // Firefox
        posx = mouseX(aEvent)
        posy = mouseY(aEvent)
    }
    else {
        if (e.pageX || e.pageY) {
            winWidth = window.innerWidth;
            posx = e.pageX + window.pageXOffset;
            posy = e.pageY + window.pageYOffset;
        }
        else if (e.clientX || e.clientY) {
            winWidth = document.body.offsetWidth;
            posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
            posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
        }
    }
    /*if(posx>(winWidth/2)){
    posx = posx-400
    }*/
    if (helpDiv) {
        helpDiv.style.position = "absolute";
        helpDiv.style.left = posx + "px";
        helpDiv.style.top = posy + "px";
        helpDiv.style.display = "block";
    }
}

function mouseX(evt) {
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
        return evt.clientX + (document.documentElement.scrollLeft ?
	   document.documentElement.scrollLeft :
	   document.body.scrollLeft);
    else return null;
}
function mouseY(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
        return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
    else return null;
}
function hideHelp(helpID, aEvent) {
    var helpObj;
    if (document.layers)	   //NN4+
    {
        helpObj = document.layers[helpID]
    }
    else (document.getElementById)	  //gecko(NN6) + IE 5+
    {
        helpObj = document.getElementById(helpID)
    }
    if (helpObj)
        helpObj.style.display = "none";
}


info = ["",""];
step = 1
nextMessage = 1

function initTSV1(divID) {
    tsvDisplay = document.getElementById(divID);
    info[0] = tsvDisplay.innerHTML;
    for (var i = 0; i < 2; i++) {
        newDiv = document.createElement("DIV")
        newDiv.setAttribute("id", "tsvdiv" + i)
        newDiv.onmouseover = function() { clearTimeout(timer) }
        newDiv.onmouseout = function() { scrollTSV1() }
        newDiv.style.position = "absolute"
        newDiv.style.padding = "0 5 10 5" // top right bottom left
        tsvDisplay.appendChild(newDiv)
    }

    tsvDv0 = document.getElementById("tsvdiv0")
    tsvDv1 = document.getElementById("tsvdiv1")
    tsvDv0.innerHTML = content[0]
    tsvDv1.innerHTML = content[1]

    tsvDv0.style.top = tsvDisplay.offsetHeight
    tsvDv1.style.top = tsvDisplay.offsetHeight + tsvDv0.offsetHeight + "px"

    scrollTSV1(content)
}

function scrollTSV1() {
    tsvDv0Pos = parseInt(tsvDv0.style.top)
    tsvDv1Pos = parseInt(tsvDv1.style.top)

    tsvDv0Pos -= step
    tsvDv1Pos -= step

    tsvDv0.style.top = tsvDv0Pos + "px"
    tsvDv1.style.top = tsvDv1Pos + "px"

    if (tsvDv0Pos < -tsvDv0.offsetHeight) {

        nextMessage++
        if (nextMessage == content.length) { nextMessage = 0 }
        tsvDv0.innerHTML = content[nextMessage]

        if (tsvDv1.offsetHeight < tsvDisplay.offsetHeight) {

            if (tsvDv1.offsetTop < tsvDisplay.offsetHeight - tsvDv1.offsetHeight) {
                tsvDv0.style.top = tsvDisplay.offsetHeight + "px"
            }
            else {
                tsvDv0.style.top = tsvDv1.offsetTop + tsvDv1.offsetHeight + "px"
            }

        }
        else {
            tsvDv0.style.top = tsvDv1.offsetTop + tsvDv1.offsetHeight + "px"
        }

    }

    if (tsvDv1Pos < -tsvDv1.offsetHeight) {

        nextMessage++
        if (nextMessage == content.length) { nextMessage = 0 }
        tsvDv1.innerHTML = content[nextMessage]

        if (tsvDv0.offsetHeight < tsvDisplay.offsetHeight) {

            if (tsvDv0.offsetTop < tsvDisplay.offsetHeight - tsvDv0.offsetHeight) {
                tsvDv1.style.top = tsvDisplay.offsetHeight + "px"
            }
            else {
                tsvDv1.style.top = tsvDv0.offsetTop + tsvDv0.offsetHeight + "px"
            }

        }
        else {
            tsvDv1.style.top = tsvDv0.offsetTop + tsvDv0.offsetHeight + "px"
        }

    }

    timer = setTimeout("scrollTSV1()", 50)

}

// add onload="initTSV1()" to the opening BODY tag









 

