﻿
/*
**
** Global Functions for ImpleoCMS
** $VER: thesnakepit.js 1.0 (17.02.2009)
**
**
** This file is part of the ImpleoCMS project.
**
** (C) 2008-2009 Daniel J. Allsopp
** All rights reserved
**
**
*/

/*
**
**	Slideshow Functions
**  Created 23.04.2009
**
*/

function StartShow(id, first, last, delay, random, start)
    {
        /* random start */
        if(random != false) start = Math.ceil(Math.random() * last);

        /* ensure correct first image */
        if(start == 1)
            start = last;
        else
            start = start - 1;

        /* start */
        setTimeout(PlayShow(id, start, first, last, delay), 0);
    }
                                                
function PlayShow(name, frame, first, last, delay)
	{
		return (function()
			{
				Effect.Fade(name + '_' + frame);
				if (frame == last) { frame = first; } else { frame = frame + 1; }
				setTimeout("Effect.Appear('" + name + "_" + frame + "');", 250);
				setTimeout(PlayShow(name, frame, first, last, delay), delay + 250);
			})
	}

/*
**
** Global Variables
**
*/

var activecolour = '#e6f5fa';
var activeborder = '#80bfea';
var inactivecolour = '#ffffff';
var inactiveborder = '#afafaf';
var readonlycolour = '#ffe0e0';

/*
**
** Common Functions
**
*/

function ShowHide(id)
    {
        if(document.getElementById)
            {
                obj = document.getElementById(id);

                if(obj.style.display == 'none')
                    obj.style.display = "";
                else
                    obj.style.display = "none";
            }
    }

function ExpandHide(id, more)
    {
        if(document.getElementById)
            {
                obj = document.getElementById(id);

                if(obj.style.display == 'none')
                    {
                        obj.style.display = ''
                        more.innerHTML = 'Less';
                    }
                else
                    {
                        obj.style.display = 'none';                        
                        more.innerHTML = 'More';
                    }
            }
    }

function Highlight(id, colour)
    {
        id.style.cursor = 'Pointer';
        id.style.backgroundColor = colour;
    }
    
function Expand(item)
   {
      if(document.getElementById)
         {
             obj = document.getElementById(item);
             new Effect.BlindDown(item);
         }
   }

function Pointer(id)
    {
        id.style.cursor = 'Pointer';
    }

function MouseOver(id)
	{
		id.style.color = '#44abfd';
    	id.style.cursor = 'Pointer';
    }

function MouseOut(id)
    {
        id.style.color = '#1156a1';
    }
    
function GotoLocation(loc)
   {
      /* internet explorer really is crap! */
      if(navigator.appName == 'Microsoft Internet Explorer')
         {
            var b = document.getElementsByTagName('base');
            
            if(b && b[0] && b[0].href)
               {
                  if(loc != b[0].href)
                     {
                        if (b[0].href.substr(b[0].href.length-1) == '/' && loc.charAt(0) == '/') loc = loc.substr(1);
                        loc = b[0].href + loc;
                     }
               }
         }

      document.location.href = loc;
   }

/*
**
** Form Functions
**
*/

function ActiveField(id)
	{
		id.style.backgroundColor = activecolour;
		id.style.borderColor = activeborder;
	}

function ReadOnlyField(id)
	{
		id.style.backgroundColor = readonlycolour;
		id.style.borderColor = readonlyborder;
	}
	
function InactiveField(id)
	{
		id.style.backgroundColor = inactivecolour;
		id.style.borderColor = inactiveborder;
	}

function SubmitForm(name)
   {
      document.getElementById(name).submit();
   }

function ResetForm(name)
   {
      document.getElementById(name).reset();
   }

/*
**
** Download File
**
*/
   
function DownloadFile(id)
    {
        var url = 'download/?file=' + id;
        location.href = url;
    }