var tmrMenu = new Array();
tmrMenu[0] = null;
tmrMenu[1] = null;

var tmrMenuSlide = new Array();
tmrMenu[0] = null;
tmrMenu[1] = null;

var dir = new Array();
dir[0] = "";
dir[1] = "";

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function ImageClick(imgId)
{
    var i;
    for(i = 0; i < document.images.length; i++)
    {
        try
        {
            var alt = document.images[i].getAttribute("alt").split("|");

            if(document.images[i].id == imgId)
            {
                document.images[i].src = alt[0];
                document.images[i].setAttribute("alt", alt[0] + "|" + alt[1] + "|clicked");
            }
            else
            {
                if(document.images[i].id.indexOf("Image") > -1)
                {
                    document.images[i].src = alt[1];
                    document.images[i].setAttribute("alt", alt[0] + "|" + alt[1] + "|");
                }
            }
        }
        catch(e){}
    }
}

function ImageMouseOver(img)
{
    var alt = img.getAttribute("alt").split("|");
    if(alt[2] != "clicked")
    {
        img.src = alt[0];
    }
}

function ImageMouseOut(img)
{
    var alt = img.getAttribute("alt").split("|");
    if(alt[2] != "clicked")
    {
        img.src = alt[1];
    }
}

function PopupMenu(e, mnuNum)
{
    var menu = document.getElementById("mnu" + mnuNum);
    
    window.clearTimeout(tmrMenu[mnuNum]);
    var e = new Event(e);
    
    menu.style.left = e.eventElementPosition[0] + "px";
    menu.style.top = (-GetElementDimensions(menu)[1] + 63) + "px";
    menu.style.visibility = "visible";
    
    dir[mnuNum] = "in";
    SlideMenuIn(mnuNum);
}

function SlideMenuIn(mnuNum)
{
    if(dir[mnuNum] == "out")
    {
        return;
    }
    
    var menu = document.getElementById("mnu" + mnuNum);
    var top = Math.floor(menu.style.top.replace("px", "")) + 2;
    var mnuHeight = GetElementDimensions(menu)[1];
    
    if(top < 253 - mnuHeight)
    {
        top = 253 - mnuHeight;
    }
    
    if(top > 230)
    {
        dir[mnuNum] = "";
        menu.style.top = "230px";
        window.clearTimeout(tmrMenuSlide[mnuNum]);
        tmrMenu[mnuNum] = window.setTimeout("SlideMenuOut(" + mnuNum + ");", 2000, "JavaScript");
    }
    else
    {
        dir[mnuNum] = "in";
        menu.style.top = top + "px";
        tmrMenuSlide[mnuNum] = window.setTimeout("SlideMenuIn(" + mnuNum + ");", 15, "JavaScript");
    }
}

function SlideMenuOut(mnuNum)
{
    if(dir[mnuNum] == "in")
    {
        return;
    }
    
    window.clearTimeout(tmrMenu[mnuNum]);
    
    var menu = document.getElementById("mnu" + mnuNum);
    var top = Math.floor(menu.style.top.replace("px", "")) - 2;
    var mnuHeight = GetElementDimensions(menu)[1];

    if(top < 253 - mnuHeight)
    {
        dir[mnuNum] = "";
        menu.style.top = (253 - mnuHeight) + "px";
        menu.style.visibility = "hidden";
        window.clearTimeout(tmrMenuSlide[mnuNum]);
    }
    else
    {
        dir[mnuNum] = "out";
        menu.style.top = top + "px";
        tmrMenuSlide[mnuNum] = window.setTimeout("SlideMenuOut(" + mnuNum + ");", 15, "JavaScript");
    }
}

function StartSlideOut(e, mnuNum)
{
    if(!GetMouseOverElement(e, document.getElementById("mnu" + mnuNum)))
    {
        tmrMenu[mnuNum] = window.setTimeout("SlideMenuOut(" + mnuNum + ");", 1000, "JavaScript");
    }
    else
    {
        window.clearTimeout(tmrMenu[mnuNum]);
    }
}

function ScrollIntoView(id)
{
    if(isFF)
    {
        document.anchors[id].scrollIntoView();
    }
    else if(isSafari)
    {
        window.scrollTo(0, GetElementPosition(document.anchors[id])[1]);
    }
    else
    {
        document.getElementById(id).scrollIntoView();
    }
}

//------------------------
//-- START OF FORM CODE --
//------------------------

function SubmitContact(frm, pnl)
{
    var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
    var phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
    
    if(frm.contact_name.value == "")
    {
        alert("Please enter your name!");
        return false;
    }
    
    if(frm.contact_email.value == "")
    {
        alert("Please enter your Email Address!");
        return false;
    }
    else
    {
        if(!emailRe.test(frm.contact_email.value))
        {
            alert("Please enter a valid Email Address!");
            return false;
        }
    }
    
//    if(frm.contact_number.value != "")
//    {
//        if(!phoneRe.test(frm.contact_number.value))
//        {
//            alert("Please enter a valid Telephone Number!");
//            return false;
//        }
//    }
    
    if(frm.comments.value == "")
    {
        alert("Please enter your Questions & Comments!");
        return false;
    }
    
    return PostPage(frm, pnl);
}

//----------------------
//-- END OF FROM CODE --
//----------------------

//--------------------------
//-- START OF IMAGE POPUP --
//--------------------------

var tmrPopup = null;

function ShowPopup(id, evt, pos)
{
    window.clearTimeout(tmrPopup);
    var popup = document.getElementById(id);
    
    var i;
    for(i = 1; i < 6; i++)
    {
        if(id != "popup" + i)
        {
            HidePopup("popup" + i);
        }
    }
    
    if(pos)
    {
        var e = new Event(evt);
        
        var elm = e.eventElement;
        while(elm.tagName != "TD")
        {
            elm = elm.offsetParent;
        }
        
        var elmPos = GetElementPosition(elm);
        var popupDim = GetElementDimensions(popup);
        var windowDim = GetWindowDimensions();
        
        popup.style.top = (elmPos[1] - popupDim[1]) + "px";
        popup.style.left = ((windowDim[0] / 2) - (popupDim[0] / 2) + 5) + "px";
    }
    
    popup.style.visibility = "visible";
}

function StartHidePopup(id)
{
    tmrPopup = window.setTimeout("HidePopup('" + id + "');", 100, "JavaScript");
}

function HidePopup(id)
{
    document.getElementById(id).style.visibility = "hidden";
}

//------------------------
//-- END OF IMAGE POPUP --
//------------------------