//NEED POTOTYPE.JS
//*************************************************//
//       ASSIGN VALUE1 IF VALUE0 & VICEVERSA       //
//*************************************************//
toggleStyle = function (element, style0, style1)
{
	// Toggle elementID classname
	element.className = (element.className == style0 || element.className == '') ? style1 : style0;
}
//*************************************************//
//      TOGGLE BETWEEN SHOW AND HIDE STYLE         //
//*************************************************//
function toggleClass(selectedIndex,Total)
{
	var selectedIndex, Total;
	var Attribute = (navigator.appName.indexOf('Microsoft') == -1) ? 'class' : 'className';
	//*************************************************//
	//     LOOP IN ARRAY ITEMS THAT HOLD DIVS NAMES    //
	//*************************************************//
	for(i=0; i < Total; i++)
	{
		var TabObj = document.getElementById('tab-' + i);
		var CtObj = document.getElementById('ct-' + i);

		if(i == selectedIndex)
		{
			TabObj.setAttribute(Attribute, 'current');
			CtObj.setAttribute(Attribute, 'show');
		}
		else
		{
			TabObj.removeAttribute(Attribute);
			CtObj.setAttribute(Attribute, 'hide');
		}
	}
}
//*************************************************//
//            SCRIPTACULOUS TAB STYLE              //
//*************************************************//
/*-----------------------------------------------------------
  Toggles element's display value
Input: any number of element id's
Output: none 
---------------------------------------------------------*/
function toggleDisp()
{
	for (var i=0;i<arguments.length;i++)
	{
		var d = $(arguments[i]);

		d.style.display = (d.style.display == 'none') ? 'block' : 'none';
	}
}
/*-----------------------------------------------------------
  Toggles tabs - Closes any open tabs, and then opens current tab
Input:     1.The number of the current tab
2.The number of tabs
3.(optional)The number of the tab to leave open
4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
Output: none 
---------------------------------------------------------*/
function toggleTab(num, numelems, opennum, animate)
{
	// Toggle classname for tabHeader
	var Attribute = (navigator.appName.indexOf('Microsoft') == -1) ? 'class' : 'className';

	if ($('tabContent'+num).style.display == 'none')
	{
		for (var i=1;i<=numelems;i++)
		{
			if ((opennum == null) || (opennum != i))
			{
				var temph = 'tabHeader'+i;

				var h = $(temph);

				if (!h)
				{
					var h = $('tabHeaderActive');
					h.id = temph;
				}

				var tempc = 'tabContent'+i;
				var c = $(tempc);

				if (c.style.display != 'none')
				{
					if (animate || typeof animate == 'undefined')
					{
						Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 2}});

						// Toggle classname for tabHeader
						h.removeAttribute(Attribute);
					}
					else
					{
						toggleDisp(tempc);

						// Toggle classname for tabHeader
						h.removeAttribute(Attribute);
					}
				}
			}
		}

		var h = $('tabHeader'+num);

		if (h)
		{
			h.id = 'tabHeaderActive';
		}

		h.blur();

		var c = $('tabContent'+num);

		//c.style.marginTop = '2px';

		if (animate || typeof animate == 'undefined')
		{
			Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 2}});

			// Toggle classname for tabHeader
			h.setAttribute(Attribute, 'currenttab');
		}
		else
		{
			toggleDisp('tabContent'+num);

			// Toggle classname for tabHeader
			h.setAttribute(Attribute, 'currenttab');
		}
	}
}
//*************************************************//
//        CHANGE HTML CONTENT OF A ID ELEMENT      //
//*************************************************//
function change_html(elem_id,value)
{
	var elem_id = elem_id;

	document.getElementById(elem_id).innerHTML = value;
}
//*************************************************//
//             CHANGE ANCHOR_ID HREF               //
//*************************************************//
function change_href(anchor_id,anchor_url)
{
	var button = document.getElementById(anchor_id);
	 
	var href = anchor_url;

	button.setAttribute("href", href);
}
//*************************************************//
//      OPEN BROWSER WINDOWS WITH OPTIONS   	   //
//*************************************************//
function openWindow(url,width,height,options,name)
{
	var options = (options == '') ? 'scrollbars=no,resizable=yes,status=no' : options;

	var winleft = (screen.width - width) / 2;
	var winup = (screen.height - height) / 2;

	winprop = 'width='+width+',height='+height+',left='+winleft+',top='+winup+','+options;

	window.open(url, name, winprop);
}
//*************************************************//
//         FUNCTION BASIC TO SWAP IMAGES    	   //
//*************************************************//
function newImage(arg) {
	if(document.images)
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages(imagename, newimage, newWidth, newHeight)
{
	$(imagename).src = newimage;

	// Reset image width
	if(newWidth && newHeight)
	{
		$(imagename).width = newWidth;
		$(imagename).height = newHeight;
	}

	return true;
}
//*************************************************//
//         FUNCTION BASIC TO SWAP IMAGES    	   //
//*************************************************//
function imagePreloader()
{
	this.setupEventHandlers( imagePreloader.prototype.onImageLoad,
				 imagePreloader.prototype.onImageError,
				 imagePreloader.prototype.onImageAbort );
}

imagePreloader.prototype.preloadImageList = function( imageList )
{
	this.nImagesCount           = imageList.length;
	this.nProcessedImagesCount  = 0;
	this.nLoadedImagesCount     = 0;
	this.bPreloadDone           = false;

	for( var i = 0; i < imageList.length; i++ )
		this.preload( imageList[i] );
}

imagePreloader.prototype.preload = function( imageFilePath )
{
	var image = new Image;

	image.onload  = this.onImageLoadEvent;
	image.onerror = this.onImageErrorEvent;
	image.onabort = this.onImageAbortEvent;

	image.preloader = this;

	image.bLoaded = false;
	image.bError  = false;
	image.bAbort  = false;

	image.src = imageFilePath;
}

imagePreloader.prototype.setupEventHandlers = function( onLoad, onError, onAbort )
{
	this.onImageLoadEvent = onLoad;
	this.onImageErrorEvent = onError;
	this.onImageAbortEvent = onAbort;
}

imagePreloader.prototype.onImageLoad = function()
{
	this.bLoaded = true;
	this.preloader.nLoadedImagesCount++;
	this.preloader.onComplete();
}

imagePreloader.prototype.onImageError = function()
{
	this.bError = true;
	this.preloader.onComplete();
}

imagePreloader.prototype.onImageAbort = function()
{
	this.bAbort = true;
	this.preloader.onComplete();
}

imagePreloader.prototype.onComplete = function( imageList )
{
	this.nProcessedImagesCount++;

	if( this.nProcessedImagesCount == this.nImagesCount )
	{
		this.bPreloadDone = true;
	}
}

function ezjslib_preloadImageList( filepathList )
{
	var preloader = new imagePreloader();

	preloader.preloadImageList( filepathList );
}
