﻿
function InitPage(pageID)
{
    SetFrameHeight();
    SetActivePage();
    
    if (!pageID)
        pageID = 1;
    ChangePagePicture(pageID, 1000);
}
function SetFrameHeight()
{   
    var contentTable = GetElement('contentTable', true);
    contentTable.style.height = '100%';
    //if (document.body.scrollHeight > 380)
    //{
    document.body.scrollTop = '0';
    contentTable.style.height = document.body.scrollHeight + 40; 
        
        //GetElement('icontent', true).style.height = '100%';
        //contentTable.style.height = '100%'; 
        //alert(document.body.scrollHeight);
    //}
}
function SetActivePage()
{
    //var imenu = window.parent.frames['imenu'];
    var imenu = window.parent;
    if (imenu==null) return;
    //alert(imenu.document.links.length);
    for (var i = 0; i < imenu.document.links.length; i++)
    {
        if (imenu.document.links[i].id.indexOf('normal') == -1){
            if (imenu.document.links[i].href.toString().toLowerCase().indexOf(document.location.toString().toLowerCase()) > -1)
            {
                imenu.document.links[i].id = 'active';
            }
            else
            {
                imenu.document.links[i].id = 'notactive';
            }
        }
    }
}

function checkFrames()
{
	if (document.location.href.indexOf('.htm') > -1 && document.location.href.indexOf('frames.htm') < 0 && self.parent.frames.length == 0){
		if (document.location.href.indexOf('quick') < 0)
		{
			document.location.replace('frames.htm?'+document.location);
		}
		else
		{
			document.location.replace('frames.htm');
		}
	}
}
window.document.onload = checkFrames();

function GetQuerystringParameter(name)
{
  var regexS = '[\\?&]' + name + '=([^&#]*)';
  var regex = new RegExp(regexS);
  var tmpURL = window.location.href;
  var results = regex.exec(tmpURL);
  if(results == null)
    return '';
  else
    return results[1];
}

function ChangePagePicture(id, duration)
{
    var image = GetElement('pageImage', true);
    if (image.src.indexOf('images/layout/image' + id) == -1)
    {
        opacity('pageImage', true, 100, 0, duration/2);
        setTimeout('GetElement("pageImage", true).src = "/images/layout/image' + id + '.jpg";opacity("pageImage", true, 0, 100, ' + duration/2 + ');',duration/2);
    }
    //GetElement(id, parent).src = 'images/layout/image1.jpg';
    //opacity(id, parent, 0, 100, 500);
    
}
function opacity(id, parent, 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 + "', " + parent + ")",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "', " + parent + ")",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id, parent) {

    var object = GetElement(id, parent);

    object.style.opacity = (opacity / 100);
    object.style.MozOpacity = (opacity / 100);
    object.style.KhtmlOpacity = (opacity / 100);
    object.style.filter = "alpha(opacity=" + opacity + ")";
} 