﻿// JScript File
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
//window.attachEvent("onload", correctPNG);

var preloadFlag = false;
function preloadImages() {
	/*if (document.images) {
		image = newImage("images/hebrew_over.gif");
		image = newImage("images/hebrew.gif");
		image = newImage("images/fm2009_over.gif");
		image = newImage("images/fm2009.gif");
		image = newImage("images/fm2008_over.gif");
		image = newImage("images/fm2008.gif");
		image = newImage("images/fmlive_over.gif");
		image = newImage("images/fmlive.gif");
		image = newImage("images/downloads_over.gif");
		image = newImage("images/downloads.gif");
		image = newImage("images/forum_over.gif");
		image = newImage("images/forum.gif");
		image = newImage("images/main_over.gif");
		image = newImage("images/main.gif");
		preloadFlag = true;
	}*/
}

function showDiv(d_id)
{
document.getElementById(d_id).style.display = document.getElementById(d_id).style.display == "none" ? "" : "none"
}
function showoneDiv(d_id)
{
document.getElementById(d_id).style.display = ""
}
function check_delete()
{
if(confirm('האם אתה בטוח?'))
return true;
else return false;
}
function enter_date(form) {
form.date.value=form.day.value + "/" + form.month.value + "/" + form.year.value
}


    
function HoverMenu(sender,hover)
{
    //on mouse over
    if (hover)
    {
        sender.className = sender.className + 'Over';
    }
    //on mouse out
    else
    {
        //if this menulink element is not in "ON" mode
        if (sender.className.indexOf('On') < 0)
        {
            sender.className = sender.className.substring(0,sender.className.length - 4);
        }
    }
}

function ChangeMenu(menu)
{
    var menu_items = new Array();
    
    menu_items[0]='main';
    menu_items[1]='forum';
    menu_items[2]='downloads';
    menu_items[3]='hebrew';
    menu_items[4]='fm2011';
    menu_items[5]='fm2010';
    menu_items[6]='fmlive';

    //show the selected menu div (and hide the others)
    for (i=0;i<=6;i++)
    {
        document.getElementById('menu_' + menu_items[i]).style.display = 'none';
    }
    document.getElementById('menu_' + menu).style.display = '';
    
    //highlight the selected menu header (and not the others)
    var aTags=document.getElementsByTagName("li");
    for (i=0;i<aTags.length;i++)
    {
        if (aTags[i].id != '')
        {
            //found menu link element
            if (aTags[i].id.indexOf('li_') >= 0)
            {
                //if this menulink element is already in "OVER" mode - change it to normal
                if (aTags[i].className.indexOf('Over') >= 0)
                {
                    aTags[i].className = aTags[i].className.substring(0,aTags[i].className.length - 4);
                }
                //if this menulink element is already in "OVER" mode - change it to normal
                if (aTags[i].className.indexOf('On') >= 0)
                {
                    aTags[i].className = aTags[i].className.substring(0,aTags[i].className.length - 2);
                }
                //if this menulink is the selected one - set it for "ON" mode
                if (aTags[i].id.indexOf(menu) >= 0)
                {
                    aTags[i].className = aTags[i].className + 'On';
                }
            }
        }
    }
}

function ResizeImage(img) 
{
    if (img)
    {
        if (img.width > 120)
            img.width = 120;
        if (img.height > 135)
            img.height = 135;
    }
}

function CheckEnter()
{
    if (window.event.keyCode == 13)
    {
        return true;
    }
    return false;
}

function replaceLoadingImage(item)
{
    document.getElementById('image_'+item+'_div').style.display='';
    document.getElementById('loading_'+item+'_div').style.display='none';
}

function replaceDefaultImage(img)
{
    img.src='images/default.jpg';
    img.style.width = '130px';
    img.style.height = '150px';
}

function replaceDefaultUsersImage(img)
{
    img.src='images/defaultUser.jpg';
}

function replaceDefaultTeamsImage(img)
{
    img.src='images/res_teams/default.png';
}

function showPopupDiv(evt,div,show,topOffset,leftOffset)
{
    if (!evt)
    {
        evt = window.event;
    }
    var newTop=(document.body.scrollTop + evt.clientY)-topOffset;
    var newLeft=(document.body.scrollLeft + evt.clientX)-leftOffset;
    
    /*document.getElementById(div).style.top = newTop+'px';
    document.getElementById(div).style.left = newLeft+'px';*/
    
    /*document.getElementById(div).style.marginTop = '15px';
    document.getElementById(div).style.marginRight = '-80px';
    
    document.getElementById(div).style.display = 'inline';
    document.getElementById(div).style.position = 'absolute';*/
    
    document.getElementById(div).style.display = '';
    if (show=='false')
    {
        document.getElementById(div).style.display = 'none';
    }
}
            
//show popup div with image in the center of the screen
function showPopupDivCenterScreen(sender, show)
{
    var divElement = document.getElementById('centerPopup');
    
    //load the image to show
    var imgElement = new Image();
    imgElement.src = sender.src;
    
    //get the "top" value of the current scroller position
    var ScrollTop = document.body.scrollTop;
    if (ScrollTop == 0)
    {
        if (window.pageYOffset)
        {
            ScrollTop = window.pageYOffset;
        }
        else
        {
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }
    }
    
    //put the "left" and "top" values of the PopUpImage div in the center of the screen
    if (imgElement != null)
    {
        //get the "left" value so that the image will be in the center
        var differenceWidth = document.body.clientWidth - imgElement.width;
        if ((differenceWidth / 2) >= 0)
        {
            divElement.style.left = (differenceWidth / 2) + 'px';
        }
        else
        {
            divElement.style.left = '0px';
        }
        
        //get the "top" value so that the image will be in the center
        var differenceHeight = document.documentElement.clientHeight - imgElement.height;
        if ((ScrollTop + (differenceHeight / 2)) >= ScrollTop)
        {
            divElement.style.top = (ScrollTop + (differenceHeight / 2))+'px';
        }
        else
        {
            divElement.style.top = ScrollTop + 'px';
        }
    }

    divElement.innerHTML = "<img style='cursor: pointer;' onclick=showPopupDivCenterScreen(this,'false'); src='" + sender.src + "' /> <div style='width:100%;text-align:center;'>לחץ על התמונה כדי לסגור אותה</div>";
    
    //show or hide the center div
    divElement.style.display = '';
    if (show == 'false')
    {
        divElement.style.display = 'none';
    }
}

function getYoutubeCode(url)
{
    //if the YouTube code is long (with "<object>..." or with "http:\\youtube.com...") - take only the code
    if (url.indexOf('object') >= 0 )
    {
        var start = url.indexOf('/v/') + 3;
        var length = url.indexOf('&') - (url.indexOf('/v/') + 3);
        url = url.substr(start, length);
    }
    else if (url.indexOf('youtube') >= 0 )
    {
        if (url.indexOf('&') >= 0)
        {
            var start = url.indexOf('=')+1;
            var length = url.indexOf('&') - (url.indexOf('=')+1);
            url = url.substr(start, length);
        }
        else
        {
            url = url.substr(url.indexOf('=')+1);
        }
    }
    
    return url;
}