//<!--

/*
**********
COPYRIGHT: ACKTEL
  Mantainer: Paolo Patri  Authors: Paolo Patri

CHANGE LOG
  2.0  11/10/2003  Paolo ha aggiunto 2 parametri (TagType e Target) per utilizzare un tag <img al posto del tag <input:
                   TagType = 1 per img, = 0 per input (default)
                   Target = "_self" (default), ecc.
                   N.B. Se si usa come <img nella funzionalità Toggable è obbligatorio settare l'URL a "#" e il target a "_self"
  1.2  24/03/2003  Paolo ha cambiato il nome al metodo create() in create_rollover() per motivi di compatibilità con altri oggetti
       e ha incluso una condizione di sicurezza nella create_rollover() per protezione da W e H vuoti
  1.1  17032003:  Marco ha cambiato la funzione nella create da writeln() a write()
  1.1  13032003:  Marco ha aggiunto il costruttore clickableRollover(String inSrc, String inRoll, String targetUrl, String objName), l'uso di questo costruttore non cecessita di un create, benchè tutti i metodi del AcktelRoll restano applicabili.
       13032003:  Patri ha aggiunto l'evento onblur al fine di rimuovere il riquadro attorno all rollover quanto clickato.
  1.0  02 2003:  first release

TODO
  -

UNRESOLVED ISSUES
  - 

USAGE
  - Dichiarare l'oggetto e inizializzarlo come nei seguenti esempi

    NomeOggetto = var newIMM1 = new AcktelRoll(tagName, SourceImage, RollOverImage, ToggleImage, ClickImage, BorderWidth, Width, Height, ALTText, ROverType, objName, TagType, Target)

    o più semplicemente:
  
    var newIMM1 = new clickableRollover(SourceImage, RollOverImage, ClickImage, targetUrl, objName)

    . Esempi:
    
      var newIMM1 = new AcktelRoll("freccia", "vuoto.gif", "click_here.gif", "vuoto_led.gif", "clickkcato.gif", "5", "139", "31", "Testo ALT", "Norm", "newIMM1", 1, "_blank")
      newIMM1.create_rollover()
      newIMM1.toggType("Togg")
      newIMM1.setMOverUrl("http://www.patrilab.com")  --> Togliere il commento nella function
    
      o più semplicemente 

      var newIMM2 = new clickableRollover("vuoto.gif", "click_here.gif", "clickkcato.gif", "http://www.patrilab.com", "newIMM2", 1, "_blank")

    # Legenda per i RollOver:
      Norm -> RollOver standard
      Togg -> Toggable fra 2 immagini sul Click
      preClck -> fase di RollOver standard in attesa della Clck
      Clck -> sul Click display di una immagine fissa

METHOD

//metodi
  void obj.create_rollover(void) -> crea e inizializza il tag INPUT di tipo image
  void obj.toggle(void) -> switch fra la ToggleImage e la SourceImage
  void obj.toggType(string) -> imposta il tipo di Toggle/RollOver
  void obj.setMOverUrl(string) -> imposta l'URL da associare all tag
  void obj.onMouseOver(string) -> esegue il RollOver di tipo Norm o preClck
  void obj.onMouseOut(string) -> ripristina il RollOver di tipo Norm o preClck
  void obj.onClick(string) -> esegue il RollOver di tipo Togg, Clck o preClck
  boolean obj.getValue(void) -> recupera il valore (0,1) dello stato in modalita' Togg

**********
*/

function clickableRollover(inSrc, inRoll, inClick, targetUrl, objName, inTagType, inTarget) {

this.myName = objName
this.Name = objName
//immagini
this.Source = new Image
this.Source.src = inSrc
this.Roll = new Image
this.Roll.src = inRoll
this.Togg = new Image
inTogg = ""
this.Togg.src = inTogg
this.Click = new Image
this.Click.src =inClick
this.Jolly = new Image
this.Jolly.src = inTogg
this.rollType = "preClck"     
//varie
this.Border = "0"
this.Width = ""
this.Height = ""
this.ALT = ""
this.Url = targetUrl

if (!(inTarget)) {
    this.Target = "_self"
} else {
    this.Target = inTarget
}

if (!(inTagType)) {
    this.TagType = 0
} else {
    this.TagType = inTagType
}

//browser sniffing
var brwsType = navigator.userAgent.toLowerCase();
if (brwsType.indexOf("msie")>-1) {
        this.isIE = 1
} else {
        this.isIE = 0
}

//metodi
this.create_rollover = create_rollover
this.create = create    //solo per compatibilità vecchie versioni
this.toggle = toggle
this.toggType = toggType
this.setMOverUrl = setMOverUrl
this.onMouseOver = onMouseOver
this.onMouseOut = onMouseOut
this.onClick = onClick
this.getValue = getValue
this.create_rollover()
}

//*** full optional ***

function AcktelRoll(inName, inSrc, inRoll, inTogg, inClick, inBorder, inWidth, inHeight, inALT, inType, objName, inTagType, inTarget) {

this.myName = objName
this.Name = inName
//immagini
this.Source = new Image
this.Source.src = inSrc
this.Roll = new Image
this.Roll.src = inRoll
this.Togg = new Image
this.Togg.src =inTogg
this.Click = new Image
this.Click.src =inClick
this.Jolly = new Image
this.Jolly.src =inTogg
this.rollType = inType        //Norm - Togg - Clck
//varie
this.Border = inBorder
this.Width = inWidth
this.Height = inHeight
this.ALT = inALT
this.Url = "#"

if (!(inTarget)) {
    this.Target = "_self"
} else {
    this.Target = inTarget
}

if (!(inTagType)) {
    this.TagType = 0
} else {
    this.TagType = inTagType
}

//browser sniffing
var brwsType = navigator.userAgent.toLowerCase();
if (brwsType.indexOf("msie")>-1) {
    this.isIE = 1
} else {
    this.isIE = 0
}

//metodi
this.create_rollover = create_rollover
this.create = create    //solo per compatibilità vecchie versioni
this.toggle = toggle
this.toggType = toggType
this.setMOverUrl = setMOverUrl
this.onMouseOver = onMouseOver
this.onMouseOut = onMouseOut
this.onClick = onClick
this.getValue = getValue
//this.setStatusBar = setStatusBar
//this.setValue = setValue
//this.reset = reset

}

function getValue() {
    return this.rollPass
}

/*function reset() {
    immObj = document.getElementById("imm_"+this.myName)
    immObj.src = this.Source.src
}*/

function setMOverUrl(inUrl) {
    //input
    if (this.TagType==0) {
        this.Url = inUrl
    //img
    } else if (this.TagType==1) {
        this.Url = inUrl
        lnkObj = document.getElementById("anchor_"+this.myName)
        lnkObj.href = inUrl
    }
}

function onMouseOver(inImmSrc) {
    //alert(this.rollType)
    immObj = document.getElementById("imm_"+this.myName)
    if (this.rollType == "Norm") {
        immObj.src = inImmSrc
        //input
        if (this.TagType==0) {
            window.location.href = this.Url
        //img
        } else if (this.TagType==1) {
            if (this.Target=="_blank") {
                window.open(this.Url,'','')
            } else {
                window.location.href = this.Url
            }
        }
    } else if (this.rollType == "preClck") {
        immObj.src = inImmSrc
    }
}

function onMouseOut(inImmSrc) {
    immObj = document.getElementById("imm_"+this.myName)
    if (this.rollType == "Norm" || this.rollType == "preClck") {
        immObj.src = inImmSrc    
    }
}

function onClick() {
    immObj = document.getElementById("imm_"+this.myName)
    switch (this.rollType) {
        case "Togg" :
            immObj.src = this.Jolly.src
            this.toggle()
            window.status = this.getValue()
        break
        case "Clck" :
            immObj.src = this.Click.src    
        break
        case "preClck" :
            this.rollType = "Clck"
            immObj.src = this.Click.src
            //input
            if (this.TagType==0) {
                window.location.href = this.Url
            }
        break
    }
}

function toggle() {
    //alert(this.Click.src)
    if (this.rollPass == 1) {
        this.Jolly.src = this.Togg.src
        this.rollPass = 0
    } else {
        this.Jolly.src = this.Source.src
        this.rollPass = 1
    }
}

function toggType(inTType) {
    this.rollType = inTType
}

function create() {
    //fittizia per compatibilità
}

function create_rollover() {
    //tag input
    //alert(this.TagType)
    if (this.TagType==0) {
        //se this.Width e this.Height sono vuoti non li scrivo nel tag
        if (this.Width && this.Height) {
            var tagInput = "<input type='image' id='imm_"+this.myName+"' name='"+this.Name+"' border='"+this.Border+"' src='"+this.Source.src+"' width='"+this.Width+"' height='"+this.Height+"' alt='"+this.ALT+"' title='"+this.ALT+"' onMouseOut="+this.myName+".onMouseOut('"+this.Source.src+"') onMouseOver="+this.myName+".onMouseOver('"+this.Roll.src+"') onClick="+this.myName+".onClick('') onFocus='this.blur();'>"
        } else {
            var tagInput = "<input type='image' id='imm_"+this.myName+"' name='"+this.Name+"' border='"+this.Border+"' src='"+this.Source.src+"' alt='"+this.ALT+"' title='"+this.ALT+"' onMouseOut="+this.myName+".onMouseOut('"+this.Source.src+"') onMouseOver="+this.myName+".onMouseOver('"+this.Roll.src+"') onClick="+this.myName+".onClick('') onFocus='this.blur();'>"
        }
    //o tag image
    } else if (this.TagType==1) {
        if (this.Width && this.Height) {
            var tagInput = "<a id='anchor_"+this.myName+"' href='"+this.Url+"' target='"+this.Target+"' onMouseOut="+this.myName+".onMouseOut('"+this.Source.src+"') onMouseOver="+this.myName+".onMouseOver('"+this.Roll.src+"') onFocus='this.blur()' onClick="+this.myName+".onClick('')><img id='imm_"+this.myName+"' name='img_"+this.Name+"' src='"+this.Source.src+"' alt='"+this.ALT+"' title='"+this.ALT+"' border='"+this.Border+"' width='"+this.Width+"' height='"+this.Height+"'></a>"
        } else {
            var tagInput = "<a id='anchor_"+this.myName+"' href='"+this.Url+"' target='"+this.Target+"' onMouseOut="+this.myName+".onMouseOut('"+this.Source.src+"') onMouseOver="+this.myName+".onMouseOver('"+this.Roll.src+"') onFocus='this.blur()' onClick="+this.myName+".onClick('')><img id='imm_"+this.myName+"' name='img_"+this.Name+"' src='"+this.Source.src+"' alt='"+this.ALT+"' title='"+this.ALT+"' border='"+this.Border+"'></a>"
        }
    }
    document.write(tagInput)
}

//-->