﻿function navSelect(navname)
{
	document.getElementsByClassName("navSub").each(function(element) {
		element.style.display="none";
	});
	$("navSub"+navname).style.display="block";
}

var onloads = new Array();
function bodyOnLoad() {
    onloads.each(function (load) { load(); });
}

function menuHover() {
var sfEls = document.getElementsByClassName("navTitle");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
		    this.className+=" menuhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" menuhover\\b"), "");
		}
	}
    var homeItem = document.getElementById("navTitleHome");
    if (homeItem!=null)
    {
        homeItem.onmouseover=function() {
            this.className+=" menuhover";
        }
        homeItem.onmouseout=function() {
            this.className=this.className.replace(new RegExp(" menuhover\\b"), "");
	    }
	}
}
if (window.attachEvent) window.attachEvent("onload", menuHover);

function element(fieldname) {
    return document.getElementById(fieldname);
}

function validate(){
if (
    element("Lastname").value=="" ||
    element("Firstname").value=="" ||
    element("Email").value=="" ||
    element("dd").value=="" ||
    element("mm").value=="" ||
    element("yy").value==""
    )
{
    alert("Not all fields completed");
    return false;
} else {
    element("birthday").value = element("yy").value + "/" + element("mm").value + "/" + element("dd").value;
    return true;
    }
}

function changeVideo(file){
    if (!document.getElementById('videoPlayer')) return null;
    var player = document.getElementById('videoPlayer');
    player.style.display="none";
    var so1 = new SWFObject(file, "videomachine", "262", "149", "9", "#f0f0f0");
	so1.addParam("wmode", "transparent");
	so1.write("videoPlayer");
	player.style.display="block";
}

// videoplayer is the container div
// programDetailVideo is the OBJECT or EMBED ID

function getFlashMovieObject(movieName){
  if (window.document[movieName]){
      return window.document[movieName];
  }
  if (document.embeds && document.embeds[movieName]) {
      return document.embeds[movieName]; 
  }
  else {
    return document.getElementById(movieName);
  }
}

function logoFlash() {
    var logo = new SWFObject("/Common/Flash/Logo.swf", "logoFlash", "120", "110", "8", "#f0f0f0");
	logo.addParam("wmode", "transparent");
	if (logo.write("logoHeader"))
	{
	    var div = $("logoHeader");
	    div.style.backgroundImage = "none";
	    if (div.filters)
	        div.style.filter="";
	    div.style.top = "-5px";
	    div.style.left = "-5px";
	    div.style.width = "120px";
	    div.style.height = "110px";
	}
}

function inputLabel(element, labelText)
{
    element.labelText = labelText;
    if (element.value == "") element.value = element.labelText;
    element.onfocus = function () { if (this.value==this.labelText) this.value = ""; }
    element.onblur = function () { if (this.value=="") this.value = this.labelText; }
}
onloads.push(function() {
    rolloverInit()
    var elements = document.getElementsByClassName("SearchKeywords");
    if (elements.length>0)
        inputLabel(elements[0], "Mess with us here...")
});

// Imagescale Helper Class
var ImageScale = Class.create();
ImageScale.prototype = {
    initialize: function (reference) {
        var breakdown = reference.split(".");
        this.ref = reference;
        this.size = breakdown[breakdown.length-2];
        var dimensions = this.size.split("x");
        this.width = dimensions[0];
        this.height = dimensions[1];
        this.src = reference;
    },
    popup: function () {
	    var openWindow = window.open("", "", "resizable=no,menubar=no,scrollbars=no,status=no,titlebar=no,toolbar=no,height="+this.height+",width="+this.width+"", false);
	    openWindow.document.body.style.border = "0px";
	    openWindow.document.body.style.padding = "0px";
	    openWindow.document.body.style.margin = "0px";
	    openWindow.document.body.innerHTML = '<center><img src="' + ((this.src.indexOf("//")==-1)?document.location.protocol + "//" + document.location.host + "/":"") + this.src + '"/></center>';
	    return openWindow;
    },
    apply: function(image, width, height) {
        image.style.display = "none";
        image.src = this.src;
        image.width = this.width;
        image.height = this.height;
        if (width)
        {
            var px = Math.round((width - this.width)/2);
            image.style.marginLeft = px + "px";
            image.style.marginRight = (width - this.width - px) + "px";
        }
        if (height)
        {
            var px = Math.round((height - this.height)/2);
            image.style.marginTop = px + "px";
            image.style.marginBottom = (height - this.height - px) + "px";
        }
        image.style.display = "inline";
    }
}

function SetCookie( name, value, expires, path, domain, secure ) 
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires)
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function GetCookie( name ) {
    	
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) &&
    ( name != document.cookie.substring( 0, name.length ) ) )
    {
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ";", len );
    if ( end == -1 ) end = document.cookie.length;
       return unescape( document.cookie.substring( len, end ) );
}
	
	
	// this deletes the cookie when called
function DeleteCookie( name, path, domain ) {
    if ( GetCookie( name ) ) document.cookie = name + "=" +
        ( ( path ) ? ";path=" + path : "") +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function openWindow(width, height, content) {
    var newWindow = window.open("", "", "resizable=no,menubar=no,scrollbars=no,status=no,titlebar=no,toolbar=no,height="+height+",width="+width+"", false);
    if (newWindow!=null) newWindow.document.write(content);
    return newWindow;
}

// Trap enter button presses and send them to the right submission control.
function trapEnter(btn, event){
    var selbtn = document.getElementById(btn);
    if ((event.keyCode == 13)||(event.which == 13)){
        event.returnValue=false;
        event.cancel = true;
        selbtn.click();
    }
}

function rolloverInit() {
    var imgRoll = document.getElementsByClassName("rollover");
    for (var i=0; i<imgRoll.length; i++) {
	    imgRoll[i].parentNode.onmouseover=function() {
	        var j = this.getElementsByClassName('rollover')[0];
	        j.src = j.src.replace('_off','_on');
	    }
	    imgRoll[i].parentNode.onmouseout=function() {
		    var j = this.getElementsByClassName('rollover')[0];
	        j.src = j.src.replace('_on','_off');
	    }
    }
}
