﻿// JScript File

var timeout;
var topTimeout;

function showSubMenu()
{
//    if (timeout != undefined)
//        clearTimeout(timeout);
//        
//    var submenu = document.getElementById("submenu");

   var gallery = document.getElementById("gallery");
   var submenuStyle = document.getElementById("submenu").style;
  
    if (timeout != undefined)
        clearTimeout(timeout);
        
    if (topTimeout != undefined)
        clearTimeout(topTimeout);

   if (submenuStyle.opacity != "" && submenuStyle.opacity != undefined)
   {
        var opacityStr = submenuStyle.filter.substring(submenuStyle.filter.indexOf("=") + 1, submenuStyle.filter.indexOf(")"));

        if (submenuStyle.opacity < 1 || opacityStr < 100)
        {
            opacity("submenu", opacityStr, 100, 500);
        }
   } 
   else {
        opacity("submenu", 0, 100, 500);
        }
//    if (submenu.style.opacity < 100)
//    {
//        opacity("submenu", 0, 100, 1000);
//        gallery.style.background = "url(images/menu_line.gif) no-repeat center bottom";
//        
//    }     
}
function hideSubMenu()
{
   topTimeout = setTimeout("actualHideSubMenu()", 200);
}
function actualHideSubMenu()
{
    var submenuStyle = document.getElementById("submenu").style;
    opacity("submenu", submenuStyle.opacity * 100, 0, 500);
}


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--) {
            timeout = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;            
        }
    } else if(opacStart < opacEnd) {
    
        for(i = opacStart; i <= opacEnd; i++)
            {
            timeout = 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 + ")";
    
    if (opacity == 0)
        object.display = "none";
    else
        object.display = "inline";
} 
function closeWindow(id)
{
    var popupStyle = document.getElementById(id).style;
    popupStyle.display = "none";
}
function openWindow(id)
{
    var popupStyle = document.getElementById(id).style;
    
    if (popupStyle.display == "block")
        popupStyle.display = "none";
    else
        popupStyle.display = "block";
}
function SetToScroll(id)
{
    var popupStyle = document.getElementById(id).style;
    popupStyle.position = "absolute";
    popupStyle.top = (document.documentElement.scrollTop + 30) + "px";
    popupStyle.margin = "0px auto";
}
function openAndScroll(id)
{
    openWindow(id);
    SetToScroll(id);
    return false;
}
function openImage(popupId, imageUrl, width, height)
{
    var popup = document.getElementById(popupId);
    popup.style.width = width + "px";

    var closeBtn = document.getElementById('imgCloseBtn');
    closeBtn.style.top = ( -1 * (height - 10)) + "px"
    popup.style.margin = "0px auto";
    var imageObj = document.getElementById('fullImage');
    imageObj.src = imageUrl;
    
    SetToScroll('imgPopup');
    openWindow(popupId);
}
function checkContact(name, email, url, text)
{
    var nameTxt = document.getElementById(name).value;
    if (nameTxt == "")
    {
        alert("Please enter your name.");
        return false;
    }
    
    var emailTxt = document.getElementById(email).value;
    if (emailTxt == "")
    {
        alert("Please enter your email.");
        return false;
    }
    if (!echeck(emailTxt))
        return false;

    var urlTxt = document.getElementById(url).value;
    
    if (urlTxt != "" && urlTxt.indexOf("http://") == -1)
    {
        alert("URL must include 'http://'");
        return false;
    }

    if (document.getElementById(text).value == "")
    {
        alert("Please enter text for your comment.");
        return false;
    }
    
    return true;
}
function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid email address.")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid email address.")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid email address.")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid email address.")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid email address.")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid email address.")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid email address.")
	    return false
	 }

	 return true					
}
function clearImage(imageID)
{
    var imageObj = document.getElementById(imageID);
    imageObj.src = "";
}