<!-- 

// General Javascript Utilities



// *** IMPORTANT ***
// ***
// *** The following array holds IDs of valid Moodle Video pages
// *** For the AJAX to work it needs to find a valid ID in this array
// ***


// *** Run ONCE on include ***
// TWO-Dimesional array

// Overide getElementById() so that it runs okay in Internet Explorer
///*
if (/msie/i.test (navigator.userAgent)) //only override IE
{
  document.nativeGetElementById = document.getElementById; 
  document.getElementById = function(id)
  {
	var elem = document.nativeGetElementById(id);
	if(elem)
	{
	  //make sure that it is a valid match on id
	  if(elem.attributes['id'].value == id)
	  {
		return elem;
	  }
	  else
	  {
		//otherwise find the correct element
		for(var i=1;i<document.all[id].length;i++)
		{
		  if(document.all[id][i].attributes['id'].value == id)
		  {
			return document.all[id][i];
		  }
		}
	  }
	}
	return null;
  }
}	
//*/

/*
function addEvent(obj, evType, fn){ 
	if (obj.addEventListener)
	{ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	}
	else if (obj.attachEvent) 
	{ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}
	else
	{ 
		return false; 
	} 
}
*/


//* John Regis Add Event


function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}

function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}



// *** Initialise EVENTS for Website ***

addEvent(window, 'load', initKaniezAbdiWebsite);
//addEvent(window, 'load', initMoodleVideo);




// Initialisation


function initKaniezAbdiWebsite()
{
	// ** OnLoad update all of the Moodle video AJAX page content **

	galleryScrollMenu('gallery_home');
	galleryScrollMenu('gallery_fashion');
	galleryScrollMenu('gallery_interiors');
	galleryScrollMenu('gallery_textile_art');
	//galleryScrollMenu('gallery');
}



// Show/Hide an element based on its id
function showhide(id){
	if (document.getElementById)
	{
		obj = document.getElementById(id);
		if (obj.style.display == "none")
		{
			obj.style.display = "";
		}
		else 
		{
			obj.style.display = "none";
		}
	}
} 

function showhideInfo(sInfoID)
{
	//var myinfo = infoID;
	myfunc = function() { showhide(sInfoID); }
	return myfunc;
}



// Select contents of Text Area or Input Field
function selectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

// Return function ptr that selects contents of Text Area or Input Field
function getSelectAllFunc(sID)
{
	//var myinfo = infoID;
	myfunc = function() { selectAll(sID); }
	return myfunc;
}


// Add onClick Event to... Select contents of Text Area or Input Field
function addSelectAllEvent(sId)
{
    var objElement = document.getElementById(sId);
	var fnCall = null;
	
	if (objElement != null)
	{
		fnCall = getSelectAllFunc( sId );
		addEvent(objElement, 'click', fnCall);
	}
}


// ******

function addEventsFormInputs(myForm, fnCall) {

	var htmlForm = document.getElementById(myForm);
	var objElement = null;

	// ** Get Form Input data values
	// showFormData(configForm);
	aInputs = getFormInputElements(htmlForm);
	
	if (aInputs != null)
	{
		for (i = 0; i < aInputs.length; i++)
		{
			objElement = aInputs[i];
			if (objElement != null)
			{
				addEvent(objElement, 'keyup', fnCall);
				addEvent(objElement, 'change', fnCall);
			}
		}
	}		
}



// Makes sure XML/HTML tags are safely converted to text
function convertXMLToText(sString) {
    var d = document.createElement('div');
    d.appendChild(document.createTextNode(sString));
	
    return d.innerHTML;
}


function collectionToArray(col) {
	a = new Array();
	for (i = 0; i < col.length; i++)
		a[a.length] = col[i];

	return a;
}
 
// * FUNC: getFormInputElements (form)
// * PARAM: Obj: Form element object
// * DESC: Get Input data from a Form
// * RETN: Array of Form Input tag elements
function getFormInputElements(form) {
	var aInputs = null;
	
	if (form != null)
	{
		aInputs = collectionToArray(form.getElementsByTagName("input"));
		aInputs = aInputs.concat(collectionToArray(form.getElementsByTagName("select")));
	}
	
	return aInputs; 
}

function showFormData(form) {
	//inputs = collectionToArray(form.getElementsByTagName("input"));
	//inputs = inputs.concat(collectionToArray(form.getElementsByTagName("select")));
	aInputs = getFormInputElements(form);
	buffer = "";
	
	if (aInputs != null)
	{
		for (i = 0; i < aInputs.length; i++)
		{
			buffer += aInputs[i].name + "=" + aInputs[i].value + "\n";
		}
	}
	
	alert(buffer);
}

// * FUNC: getFormElementValue (formElement)
// * PARAMS: Sring:Form element 'name'
// * DESC: The getElementValue function allows you to get the value of a form element.
// * RETN: It will return a string normally, although for certain elements it will return a boolean.
// * A multiple select is special, in that it will return an array of booleans.

function getFormElementValue(formElement)
{
	if(formElement.length != null) var type = formElement[0].type;
	if((typeof(type) == 'undefined') || (type == 0)) var type = formElement.type;

	switch(type)
	{
		case 'undefined': return;

		case 'radio':
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].checked == true)
			return formElement[x].value;

		case 'select-multiple':
			var myArray = new Array();
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].selected == true)
					myArray[myArray.length] = formElement[x].value;
			return myArray;

		case 'checkbox': return formElement.checked;
	
		default: return formElement.value;
	}
}


// This function can be used to set the value of any type of form element.
// It uses switch to decide how to set the value of each different type of element.
// To use it, simply pass the form element as an object, and the value.
// Note that some types of element require special types of value! These are:

//    * A radio and checkbox, which require a boolean value (true or false).
//    * A select, which requires the number of the item to be selected (these start at 0, so to select the first item on the list, the value would be 0, to select the second, the value would be 1 and so on)
//    * A select that allows multiple selections. This requires that you pass an array of boolean values. The array should be the same size (have the same number of items) as the select. Where the array is true, the list item will be selected, and where false, deselected.

function setFormElementValue(formElement, value)
{
	switch(formElement.type)
	{
		case 'undefined': return;
		case 'radio': formElement.checked = value; break;
		case 'checkbox': formElement.checked = value; break;
		case 'select-one': formElement.selectedIndex = value; break;

		case 'select-multiple':
			for(var x=0; x < formElement.length; x++) 
				formElement[x].selected = value[x];
			break;

		default: formElement.value = value; break;
	}
}





// -->