﻿/*=================================== Music Script =======================================*/

var currentTrack = "0";
var tDate = new Date();
            
function NavigationClick(caller, index)
{
    overColor       = aryTab[index][0];
    outColor        = aryTab[index][1];
    overSubColor    = aryTab[index][2];
    
    document.getElementById("frmMain").src = aryTab[index][3];
    document.getElementById("tdMain").style.backgroundImage = aryTab[index][4];
    
    DefaultNavigation(index);
    document.body.scrollTop = 0;
}

function MusicClick(caller, index)
{            
    ChangeMusic(index);
    DefaultMusic(index);
}

function MusicClick2(caller, index)
{            
    ChangeMusic2(index);
    DefaultMusic2(index);
}

function ResizeFrame(frameHeight)
{
    document.getElementById("frmMain").style.height = frameHeight + "px";
}
	        
function ChangeMusic(strTrack)
{
    var strMusicSrc = "Music/" + strTrack + ".mp3?time=" + tDate.getMilliseconds();;
    document.getElementById("bgMusic").innerHTML = "<embed src='" + strMusicSrc + "' autostart='true' loop='true' hidden='true'><noembed><bgsound src='" + strMusicSrc + "' loop='infinite'></noembed>";
    currentTrack = strTrack;
    var icon = document.getElementById("imgPlay");
    icon.src = "Images/SoundOn.gif";
}

function ChangeMusic2(strTrack)
{
    var strMusicSrc = "Music/" + strTrack + ".mp3";
    parent.document.getElementById("bgMusic").innerHTML = "<embed src='" + strMusicSrc + "' autostart='true' loop='true' hidden='true'><noembed><bgsound src='" + strMusicSrc + "' loop='infinite'></noembed>";
    currentTrack = strTrack;
    var icon = parent.document.getElementById("imgPlay");
    icon.src = "Images/SoundOn.gif";
}

function StopMusic(caller)
{
    var music = document.getElementById("bgMusic");
    var icon = document.getElementById("imgPlay");
    
    if (icon.src.indexOf('On.gif') != -1)
    {
        music.innerHTML = "";
        icon.src = "Images/SoundOff.gif";
	    document.getElementById('music' + currentTrack).style.color = musicOutTextColor;    
    }
    else
    {
        MusicClick(caller, currentTrack);
        icon.src = "Images/SoundOn.gif";
    }
}

function changeheight(height)
{
    frameheight = height;
    alert(frameheight);
}

function ClearForm()
{
	var frm = document.forms[0];

	for ( i=0; i<frm.length; i++ )
	{
		if ( ( frm.elements[i].type == "text" ) || ( frm.elements[i].type == "textarea" ) || ( frm.elements[i].type == "password" ) )
		{
			frm.elements[i].value = "";
		}
		else if ( frm.elements[i].type == "select-one" )
		{
			frm.elements[i].options[0].selected = true;
		}
		else if ( frm.elements[i].type == "checkbox" )
		{
			frm.elements[i].checked = false;
		}
	}
}
	
function DisplayGuest()
{
    var frm = document.forms[0];
    var intAdult = 0;
    var intChild = 0;
    var intGuest = 0;
    for (i=0; i<frm.length; i++)
    {
	    var e = frm.elements[i];
	    if (e.id.indexOf('drpAdult') != -1)
	    {
	        intAdult = e.value * 1;   
        }
        else if (e.id.indexOf('drpChild') != -1)
        {
            intChild = e.value * 1;
        }
    }
    intGuest = intAdult + intChild;
    var frameHeight = 700 + (intGuest * 30);
    parent.document.getElementById("frmMain").style.height = frameHeight + "px";
    
    
    for (i=1; i<=3; i++)
    {
        if (i <= intAdult)
        {
            document.getElementById("Adult" + i).style.display = "";
            //document.getElementById("spanGuest" + i).innerText= "同行來賓姓名";
        }
        else
        {
            document.getElementById("Adult" + i).style.display = "none";
            document.getElementById("txtAdult" + i).value = "";
        }
        
        if (i <= intChild)
        {
            document.getElementById("Child" + i).style.display = "";
        }
        else
        {
            document.getElementById("Child" + i).style.display = "none";
            document.getElementById("txtChild" + i).value = "";
        }
    }
}

function ShowGuestInfo(blnShow)
{
    if (blnShow)
        document.getElementById("GuestInfo").style.display = "";
    else
    {
        document.getElementById("GuestInfo").style.display = "none";
        
        var frm = document.forms[0];

	    for ( i=0; i<frm.length; i++ )
	    {
		    if ( frm.elements[i].type == "select-one" )
		    {
			    frm.elements[i].options[0].selected = true;
		    }
	    }
	    DisplayGuest();
    }
}








function HtmlColorString(r,g,b)
{
	var r = r.toString(16); if (r.length == 1) r = '0'+r;
	var g = g.toString(16); if (g.length == 1) g = '0'+g;
	var b = b.toString(16); if (b.length == 1) b = '0'+b;
	return "#" + r + g + b;
}









/*================================= Navigation Script =====================================*/

var navigations = 7;
var navigationCells = new Array();
var navigationSteps = 30;
var navigationStepDuration = 10;
var initPadding = 5;
var defaultNavigation = -1;

function NavigationTransaction(index)
{
	var cell = navigationCells[index];
	if (cell.step)
	{
		cell.step--;
		
		if (cell.padding-initPadding < cell.step/2)
			cell.padding++;
		else
			cell.padding--;
		
		var step = cell.step;
		
		var from = outColor.substr(1);
		var   to = overColor.substr(1);
		var r0 = parseInt (from.substr(0,2),16);
		var g0 = parseInt (from.substr(2,2),16);
		var b0 = parseInt (from.substr(4,2),16);
		var r1 = parseInt (  to.substr(0,2),16);
		var g1 = parseInt (  to.substr(2,2),16);
		var b1 = parseInt (  to.substr(4,2),16);
		var r = Math.floor (r1 * ((navigationSteps-step)/navigationSteps) + r0 * (step/navigationSteps));
		var g = Math.floor (g1 * ((navigationSteps-step)/navigationSteps) + g0 * (step/navigationSteps));
		var b = Math.floor (b1 * ((navigationSteps-step)/navigationSteps) + b0 * (step/navigationSteps));
		var topColor = HtmlColorString (r,g,b);
		
		
		
		var from = outColor.substr(1);
		var   to = overSubColor.substr(1);

		var r0 = parseInt (from.substr(0,2),16);
		var g0 = parseInt (from.substr(2,2),16);
		var b0 = parseInt (from.substr(4,2),16);
		var r1 = parseInt (  to.substr(0,2),16);
		var g1 = parseInt (  to.substr(2,2),16);
		var b1 = parseInt (  to.substr(4,2),16);
		var r = Math.floor (r1 * ((navigationSteps-step)/navigationSteps) + r0 * (step/navigationSteps));
		var g = Math.floor (g1 * ((navigationSteps-step)/navigationSteps) + g0 * (step/navigationSteps));
		var b = Math.floor (b1 * ((navigationSteps-step)/navigationSteps) + b0 * (step/navigationSteps));
		var bottomColor = HtmlColorString (r,g,b);
		
		document.getElementById('tab' + index).style.backgroundColor = topColor;
		document.getElementById('subtab' + index).style.backgroundColor = bottomColor;
		
		if (cell.padding > initPadding)
			document.getElementById('tab' + index).style.paddingTop = cell.padding;
		    
		if (cell.step > 0)
		{
			cell.timerID = setTimeout("NavigationTransaction("+index+")", navigationStepDuration);
		}
		else if (cell.step < 0)
		{
			document.getElementById('tab' + index).style.backgroundColor = "";
			document.getElementById('subtab' + index).style.backgroundColor = "";
		}
	}
}

function NavigationOver(caller, index)
{
    if (index >= 0 && index != defaultNavigation)
    {
	    clearTimeout(document.getElementById('tab' + index).timerID);
	    clearTimeout(document.getElementById('subtab' + index).timerID);
	    document.getElementById('tab' + index).step = navigationSteps;
	    document.getElementById('subtab' + index).step = navigationSteps;
	    navigationCells[index].step = navigationSteps;
	    navigationCells[index].padding = initPadding;
	    document.getElementById('tab' + index).timerID = setTimeout("NavigationTransaction("+index+")", 0);	
	    document.getElementById('subtab' + index).timerID = setTimeout("NavigationTransaction("+index+")", 0);
    }
}

function NavigationOut(caller, index)
{
    if (index >= 0 && index != defaultNavigation)
    {
	    clearTimeout(document.getElementById('tab' + index).timerID);
	    clearTimeout(document.getElementById('subtab' + index).timerID);
	    document.getElementById('tab' + index).step = -1;
	    document.getElementById('subtab' + index).step = -1;
	    document.getElementById('tab' + index).style.backgroundColor = "";
	    document.getElementById('subtab' + index).style.backgroundColor = "";
	    document.getElementById('tab' + index).style.paddingTop = initPadding;
	    navigationCells[index].step = -1;
	    navigationCells[index].padding = -1;
	}
}

function CreateNavigation()
{
	table = document.getElementById('tbNavigation');

	for (var i=0; i<table.rows.length;)
	{
		table.deleteRow(0);
	}
  
	navigationCells = new Array();
	newRow = table.insertRow(0);
  
	for (var i=0; i<navigations; i++)
	{
		newCell = newRow.insertCell(i);
		newCell.index = 0;
		newCell.step = navigationSteps;
		newCell.timerID = 0;
		newCell.padding = initPadding;
		navigationCells[i] = newCell;
		newCell = null;
	}
		
	for (var i=0; i < table.rows.length;)
	{
		table.deleteRow(0);
	}
}

function DefaultNavigation(index)
{
    for (var i=0; i<navigations; i++)
    {
        if (i == index)
        {
            NavigationOver(null, index);
        }
        else
        {
            document.getElementById('tab' + i).style.backgroundColor = "";
            document.getElementById('subtab' + i).style.backgroundColor = "";
        }
    }
    defaultNavigation = index;
}











var musicOutColor = "#171717";
var musicOverColor = "#ffcc00";
var musicOutTextColor = "#696861";
var musics = 9;
var musicCells = new Array();
var musicSteps = 30;
var musicStepDuration = 1;
var defaultMusic = -1;

function MusicTransaction(index)
{
    var musicCell = musicCells[index];
	if (musicCell.step)
	{
	    if (musicCell.step > 0)
	    {
		    musicCell.step--;
    		
		    var musicStep = musicCell.step;
    		
		    var from = musicOutColor.substr(1);
		    var   to = musicOverColor.substr(1);
		    var r0 = parseInt (from.substr(0,2),16);
		    var g0 = parseInt (from.substr(2,2),16);
		    var b0 = parseInt (from.substr(4,2),16);
		    var r1 = parseInt (  to.substr(0,2),16);
		    var g1 = parseInt (  to.substr(2,2),16);
		    var b1 = parseInt (  to.substr(4,2),16);
		    var r = Math.floor (r1 * ((musicSteps-musicStep)/musicSteps) + r0 * (musicStep/musicSteps));
		    var g = Math.floor (g1 * ((musicSteps-musicStep)/musicSteps) + g0 * (musicStep/musicSteps));
		    var b = Math.floor (b1 * ((musicSteps-musicStep)/musicSteps) + b0 * (musicStep/musicSteps));
		    var topColor = HtmlColorString (r,g,b);
    		
		    document.getElementById('music' + index).style.borderColor = topColor;
    		    
		    if (musicCell.step > 0)
		    {
			    musicCell.timerID = setTimeout("MusicTransaction("+index+")", musicStepDuration);
		    }
		}
		else
		{
		    document.getElementById('music' + index).style.borderColor = musicOutColor;
		}
	}
}

function MusicOver(caller, index)
{
    if (index >= 0)
    {
	    clearTimeout(document.getElementById('music' + index).timerID);
	    document.getElementById('music' + index).step = musicSteps;
	    musicCells[index].step = musicSteps;
	    document.getElementById('music' + index).timerID = setTimeout("MusicTransaction("+index+")", 0);	
    }
}

function MusicOut(caller, index)
{
    if (index >= 0)
    {	    
	    clearTimeout(document.getElementById('music' + index).timerID);
	    document.getElementById('music' + index).step = -1;
	    document.getElementById('music' + index).style.borderColor = musicOutColor;
	    musicCells[index].step = -1;
	}
}

function CreateMusic()
{
	table = document.getElementById('tbMusic');

	for (var i=0; i<table.rows.length;)
	{
		table.deleteRow(0);
	}
  
	musicCells = new Array();
	newRow = table.insertRow(0);
  
	for (var i=0; i<musics; i++)
	{
		newCell = newRow.insertCell(i);
		newCell.index = 0;
		newCell.step = musicSteps;
		newCell.timerID = 0;
		musicCells[i] = newCell;
		newCell = null;
	}
		
	for (var i=0; i < table.rows.length;)
	{
		table.deleteRow(0);
	}
}

function DefaultMusic(index)
{
    for (var i=0; i<musics; i++)
    {
        if (i == index)
        {
            document.getElementById('music' + i).style.borderColor = musicOutColor;
            document.getElementById('music' + i).style.color = musicOverColor;
        
            //MusicOver(null, index);
        }
        else
        {
            document.getElementById('music' + i).style.borderColor = musicOutColor;
            document.getElementById('music' + i).style.color = musicOutTextColor;
        }
    }
    defaultMusic = index;
}

function DefaultMusic2(index)
{
    for (var i=0; i<musics; i++)
    {
        if (i == index)
        {
            parent.document.getElementById('music' + i).style.borderColor = musicOutColor;
            parent.document.getElementById('music' + i).style.color = musicOverColor;
        
            //MusicOver(null, index);
        }
        else
        {
            parent.document.getElementById('music' + i).style.borderColor = musicOutColor;
            parent.document.getElementById('music' + i).style.color = musicOutTextColor;
        }
    }
    defaultMusic = index;
}


//function stretchIFrame(frameName,minHeight)
//{
//	contentHeight = 0;
//	try
//	{
//	   contentHeight=document.getElementById(frameName).contentWindow.document.body.scrollHeight+50;
//	}
//	catch(err){}
//	if (contentHeight < minHeight) contentHeight = minHeight;
//	document.getElementById(frameName).style.height=contentHeight;
//}
