function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame 
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens 
    if (opacStart > opacEnd) {
        for (i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    } else if (opacStart < opacEnd) {
        for (i = opacStart; i <= opacEnd; i++) {
            setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers 
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 



function disable(str)
{
document.getElementById(''+str).disabled=true;
}

function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //set the current image as background 
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

    //make image transparent 
    changeOpac(0, imageid);

    //make new image 
    document.getElementById(imageid).src = imagefile;

    //fade in image 
    for (i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')", (timer * speed));
        timer++;
    }
}



//**************************************************************************************************

var topmenu = function() {
    var t = 15, z = 50, s = 6, a;
    function dd(n) { this.n = n; this.h = []; this.c = [] }
    dd.prototype.init = function(p, c) {
        a = c; var w = document.getElementById(p), s = w.getElementsByTagName('ul'), l = s.length, i = 0;
        for (i; i < l; i++) {
            var h = s[i].parentNode; this.h[i] = h; this.c[i] = s[i];
            h.onmouseover = new Function(this.n + '.st(' + i + ',true)');
            h.onmouseout = new Function(this.n + '.st(' + i + ')');
        }
    }
    dd.prototype.st = function(x, f) {
        var c = this.c[x], h = this.h[x], p = h.getElementsByTagName('a')[0];
        clearInterval(c.t); c.style.overflow = 'hidden';
        if (f) {
            p.className += ' ' + a;
            if (!c.mh) { c.style.display = 'block'; c.style.height = ''; c.mh = c.offsetHeight; c.style.height = 0 }
            if (c.mh == c.offsetHeight) { c.style.overflow = 'visible'}
            else { c.style.zIndex = z; z++; c.t = setInterval(function() { sl(c, 1) }, t) }
        } else { p.className = p.className.replace(a, ''); c.t = setInterval(function() { sl(c, -1) }, t) }
    }
    function sl(c, f) {
        var h = c.offsetHeight;
        if ((h <= 0 && f != 1) || (h >= c.mh && f == 1)) {
            if (f == 1) { c.style.filter = ''; c.style.opacity = 1; c.style.overflow = 'visible' }
            clearInterval(c.t); return
        }
        var d = (f == 1) ? Math.ceil((c.mh - h) / s) : Math.ceil(h / s), o = h / c.mh;
        c.style.opacity = o; c.style.filter = 'alpha(opacity=' + (o * 100) + ')';
        c.style.height = h + (d * f) + 'px'

    }
    return { dd: dd }
} ();

/**********************************************************************************************************/

var sidemenu = function() {
    var t = 15, z = 50, s = 6, a;
    function dd(n) { this.n = n; this.h = []; this.c = [] }
    dd.prototype.init = function(p, c) {
        a = c; var w = document.getElementById(p), s = w.getElementsByTagName('ul'), l = s.length, i = 0;
        for (i; i < l; i++) {
            var h = s[i].parentNode; this.h[i] = h; this.c[i] = s[i];
            h.onmouseover = new Function(this.n + '.st(' + i + ',true)');
            h.onmouseout = new Function(this.n + '.st(' + i + ')');
        }
    }
    dd.prototype.st = function(x, f) {
        var c = this.c[x], h = this.h[x], p = h.getElementsByTagName('a')[0];
        clearInterval(c.t); c.style.overflow = 'hidden';
        if (f) {
            p.className += ' ' + a;
            if (!c.mh) { c.style.display = 'block'; c.style.height = ''; c.mh = c.offsetHeight; c.style.height = 0 }
            if (c.mh == c.offsetHeight) { c.style.overflow = 'visible' }
            else { c.style.zIndex = z; z++; c.t = setInterval(function() { sl(c, 1) }, t) }
        } else { p.className = p.className.replace(a, ''); c.t = setInterval(function() { sl(c, -1) }, t) }
    }
    function sl(c, f) {
        var h = c.offsetHeight;
        if ((h <= 0 && f != 1) || (h >= c.mh && f == 1)) {
            if (f == 1) { c.style.filter = ''; c.style.opacity = 1; c.style.overflow = 'visible' }
            clearInterval(c.t); return
        }
        var d = (f == 1) ? Math.ceil((c.mh - h) / s) : Math.ceil(h / s), o = h / c.mh;
        c.style.opacity = o; c.style.filter = 'alpha(opacity=' + (o * 100) + ')';
        c.style.height = h + (d * f) + 'px'

    }
    return { dd: dd }
} ();

/***************************************************************************************************************************/

function validate_required(field, alerttxt) {
    with (field) {
        if (value == null || value == "") {
            alert(alerttxt); return false;
        }
        else {
            return true;
        }
    }
}

function validate_email(field, alerttxt) {
    with (field) {
        apos = value.indexOf("@");
        dotpos = value.lastIndexOf(".");
        if (apos < 1 || dotpos - apos < 2)
        { alert(alerttxt); return false; }
        else { return true; }
    }
}

function validatePwd(thisform) {
    var invalid = " "; // Invalid character is a space
    var minLength = 6; // Minimum length
    var pw1 = thisform.password.value;
    var pw2 = thisform.passwordconf.value;
    // check for a value in both fields.
    if (pw1 == '' || pw2 == '') {
        alert('אנא הזן/י את הסיסמא פעמיים');
        return false;
    }
    // check for minimum length
    if (thisform.password.value.length < minLength) {
        alert('הסיסמא חייבת להכיל לפחות ' + minLength + ' תווים');
        return false;
    }
    // check for spaces
    if (thisform.password.value.indexOf(invalid) > -1) {
        alert("הזנת רווח בסיסמא. הפעולה אינה חוקית");
        return false;
    }
    else {
        if (pw1 != pw2) {
            alert("הסיסמא שהזנת בשדה וידוא הסיסמא שונה מהסיסמא שהזנת בשדה הסיסמא");
            return false;
        }
        else
        { return true; }
    }
}

function validatePwdChng(thisform) {
    var invalid = " "; // Invalid character is a space
    var minLength = 6; // Minimum length
    var pw1 = thisform.newpassword.value;
    var pw2 = thisform.newpasswordconf.value;
    // check for a value in both fields.
    if (pw1 == '' || pw2 == '') {
        alert('אנא הזן/י את הסיסמא פעמיים');
        return false;
    }
    // check for minimum length
    if (thisform.newpassword.value.length < minLength) {
        alert('הסיסמא חייבת להכיל לפחות ' + minLength + ' תווים');
        return false;
    }
    // check for spaces
    if (thisform.newpassword.value.indexOf(invalid) > -1) {
        alert("הזנת רווח בסיסמא. הפעולה אינה חוקית");
        return false;
    }
    else {
        if (pw1 != pw2) {
            alert("הסיסמא שהזנת בשדה וידוא הסיסמא שונה מהסיסמא שהזנת בשדה הסיסמא");
            return false;
        }
        else
        { return true; }
    }
}

function validate_form_signup(thisform) {
    with (thisform) {
        if (validate_required(name, "שדה השם הינו שדה חובה!") == false)
        { name.focus(); return false; }
    }
    with (thisform) {
        if (validate_required(email, "שדה האי-מייל הינו שדה חובה!") == false)
        { email.focus(); return false; }
    }
    with (thisform) {
        if (validate_email(email, "כתובת המייל שהזנת אינה כתובת מייל תקנית!") == false)
        { email.focus(); return false; }
    }
    with (thisform) {
        if (validatePwd(thisform) == false)
        { return false; }
    }
}

function validate_form_PwdChng(thisform) {
    with (thisform) {
        if (validatePwdChng(thisform) == false)
        { return false; }
    }
}

function validate_form(thisform) {
    with (thisform) {
        if (validate_required(name, "שדה השם הינו שדה חובה!") == false)
        { name.focus(); return false; }
    }
    with (thisform) {
        if (validate_required(email, "שדה האי-מייל הינו שדה חובה!") == false)
        { email.focus(); return false; }
    }
    with (thisform) {
        if (validate_email(email, "כתובת המייל שהזנת אינה כתובת מייל תקנית!") == false)
        { email.focus(); return false; }
    }
}
