// ADDLOADEVENT

// addLoadEvent adds functions once page is loaded addLoadEvent(functionname);
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
// DOM FUNCTIONS

// dom insert after function
function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
   parent.insertBefore(newElement, targetElement.nextSibling);
}
// insert at front
function prependChild(newElement) {
  var parent = targetElement.parentNode;
  parent.insertBefore(newElement, parent.firstChild);
}
// WALK TREE TO HTML

//////////////////////////////////////////////////
//////////////////////////////////////////////////
/*
function to receive xmlresponse node which contains xhtml syntax as xml node
default is to walk all xml node tree
parentNode is alternative node to start walking from
htmlNode is the document DOM node to append to
clearList is an array of document DOM nodes to be replace in document
*/
function walkTreeToHTML(xmlNode, parentNodeId, htmlDomNode, clearList)
{
	// Ensure node is defined
	/*
	if (!window['Node']) {
	    window.Node = new Object();
	    Node.ELEMENT_NODE = 1;
	    Node.ATTRIBUTE_NODE = 2;
	    Node.TEXT_NODE = 3;
	    Node.CDATA_SECTION_NODE = 4;
	    Node.ENTITY_REFERENCE_NODE = 5;
	    Node.ENTITY_NODE = 6;
	    Node.PROCESSING_INSTRUCTION_NODE = 7;
	    Node.COMMENT_NODE = 8;
	    Node.DOCUMENT_NODE = 9;
	    Node.DOCUMENT_TYPE_NODE = 10;
	    Node.DOCUMENT_FRAGMENT_NODE = 11;
	    Node.NOTATION_NODE = 12;
	}
	*/
	//alert("ok walktree");
	if(clearList && clearList.length)
		clearElements(clearList);
	
	// function to clear elements in DOM tree elements nodeNome contained in Array clearList
	function clearElements(clearList)
	{
		if(clearList && clearList.length)
		{
			// if clearList contains elements loop through
			for(var i = 0;i < clearList.length;i++)
			{
				// if each clearList element is not empty and refers to a DOM element replace with empty element
				if(clearList[i] && document.getElementById(clearList[i]))
				{
					var toBlank					= clearList[i];
					var toBlankElement			= document.getElementById(toBlank);
					var toBlankElementName		= toBlankElement.nodeName;
					var toBlankElementId		= toBlankElement.getAttribute("Id");
					var newToBlankElementId		= toBlankElementId+"a";
					toBlankElement.setAttribute("id",newToBlankElementId);
					var newElem					= document.createElement(toBlankElementName);
					newElem.setAttribute("id",toBlankElementId);
					toBlankElement				= toBlankElement.parentNode.replaceChild(newElem,toBlankElement);	
				}
			}
		}
	}
	
	// set node to walk from
	if(parentNodeId)
	{
		var parentXML = xmlNode.getElementById(parentNodeId);
	}else
	{
		var parentXML = xmlNode;
	}
	
	// set DOM node to append to and get that node Id
	var htmlDomFragment 	= document.getElementById(htmlDomNode);
	var htmlDomFragmentId	= htmlDomFragment.getAttribute("Id");
	
	// walk through children of current parent XML node convert to xhtml and append to current html node (received if set)
	function listChildren(parentNode, thisHTMLNode)
	{
		// If current html node is not set then set now
		if(!thisHTMLNode)
			var thisHTMLNode = htmlDomFragment;
		// if there are child nodes
		if(parentNode.childNodes)
		{
			// make array of child nodes
			var childNodeArray = parentNode.childNodes;
			// for each child node
			for(var nodeNo = 0; nodeNo < childNodeArray.length; nodeNo++)
			{
				sortChildren(childNodeArray[nodeNo], thisHTMLNode);
			}
		}
	}
	
	// for each child of current XML node
	function sortChildren(node, thisHTMLNode)
	{
		var thisNode = node;
		// check if text node and if so append if not whitespace (is_ignorable())
		if (thisNode.nodeType == 3 || thisNode.nodeType == 4) {
		    // append text if not whitespace etc
		    if (!is_ignorable(thisNode))
		    {
		    	var textToAdd 		= thisNode.data;
		    	var nodeToAddTextTo	= thisHTMLNode;
		    	addThisText(nodeToAddTextTo, textToAdd);
		    }
	    // if not text node check if element node
		}else if (thisNode.nodeType == 1)
	    {
	    	// create xhtml node the same as current XML node
	    	var nodeToAdd 	= document.createElement(thisNode.nodeName);
	    	var nodeToAddTo	= thisHTMLNode;
	    	// create xhtml attributes in node, the same as current XML node
			var totalattributes=0
			for (i=0;i<thisNode.attributes.length;i++)
			{
			//if attribute is user defined
				if (thisNode.attributes[i].specified)
				{
					nodeToAdd.setAttribute(thisNode.attributes[i].nodeName, thisNode.attributes[i].value);
				}
			}
			// append node to current html node (returns appended xhtml node) then list children 
			thisHTMLNode	= nodeToAddTo.appendChild(nodeToAdd);
			
			var classHere = "";
			if(thisHTMLNode.getAttribute("class"))
				classHere = " class="+thisHTMLNode.getAttribute("class");
			//alert(thisHTMLNode.nodeName+classHere);
			listChildren(thisNode, thisHTMLNode);
	    }
	}
	
	// add text node to thisHTMLChild = 
	function addThisText(nodeToAddTextTo, textToAdd)
	{
		var textNodeToAdd	= document.createTextNode(textToAdd);
		// append node to current html node (returns appended xhtml node)
		thisHTMLNode		= nodeToAddTextTo.appendChild(textNodeToAdd);
		//alert(thisHTMLNode.nodeName);
	}
	
	
	listChildren(parentXML);
	
/*
//=============================================	
	 //Inner text
	function innerText(node) {
	    // is this a text or CDATA node?
	    if (node.nodeType == 3 || node.nodeType == 4) {
	        return node.data;
	    }
	    var i;
	    var returnValue = [];
	    for (i = 0; i < node.childNodes.length; i++) {
	        returnValue.push(innerText(node.childNodes[i]));
	    }
	    return returnValue.join('');
	}
	
	//Function elem() shortcut
	function elem(name, attrs, style, text) {
	    var e = document.createElement(name);
	    if (attrs) {
	        for (key in attrs) {
	            if (key == 'class') {
	                e.className = attrs[key];
	            } else if (key == 'id') {
	                e.id = attrs[key];
	            } else {
	                e.setAttribute(key, attrs[key]);
	            }
	        }
	    }
	    if (style) {
	        for (key in style) {
	            e.style[key] = style[key];
	        }
	    }
	    if (text) {
	        e.appendChild(document.createTextNode(text));
	    }
	    return e;
	}


	// Functional DOM utilities
	
	// return an Array of all nodes, starting at startNode and
	// continuing through the rest of the DOM tree
	function listNodes(startNode) {
	    var list = new Array();
	    var node = startNode;
	    while(node) {
	        list.push(node);
	        node = nextNode(node);
	    }
	    return list;
	}
	// The same as listNodes(), but works backwards from startNode.
	// Note that this is not the same as running listNodes() and
	// reversing the list.
	function listNodesReversed(startNode) {
	    var list = new Array();
	    var node = startNode;
	    while(node) {
	        list.push(node);
	        node = prevNode(node);
	    }
	    return list;
	}
	// apply func to each node in nodeList, return new list of results
	function map(list, func) {
	    var result_list = new Array();
	    for (var i = 0; i < list.length; i++) {
	        result_list.push(func(list[i]));
	    }
	    return result_list;
	}
	// apply test to each node, return a new list of nodes for which
	// test(node) returns true
	function filter(list, test) {
	    var result_list = new Array();
	    for (var i = 0; i < list.length; i++) {
	        if (test(list[i])) result_list.push(list[i]);
	    }
	    return result_list;
	}
	
	// A list of all the element names in document order
	function isElement(node) {
	    return node.nodeType == Node.ELEMENT_NODE;
	}
	function nodeName(node) {
	    return node.nodeName;
	}
	var elementNames = map(filter(listNodes(document),isElement), nodeName);
	// All the text from the document (ignores CDATA)
	function isText(node) {
	    return node.nodeType == Node.TEXT_NODE;
	}
	function nodeValue(node) {
	    return node.nodeValue;
	}
	var allText = map(filter(listNodes(document), isText), nodeValue);
	*/

}


// End DOM

//===================================================
//===================================================


// LOAD IFRAME

function loadIFrame(thePost, theURL, theFrame) 
{
	var urlToGo = theURL.concat("?",thePost);
	document.getElementById(theFrame).src = urlToGo;
}


// PROTOTYPE - ARRAY 

Array.prototype.indexOf=function(n){for(var i=0;i<this.length;i++){if(this[i]===n){return i;}}return -1;}
Array.prototype.lastIndexOf=function(n){var i=this.length;while(i--){if(this[i]===n){return i;}}return -1;}
Array.prototype.forEach=function(f){var i=this.length,j,l=this.length;for(i=0;i<l;i++){if((j=this[i])){f(j);}}};
Array.prototype.insert=function(i,v){if(i>=0){var a=this.slice(),b=a.splice(i);a[i]=value;return a.concat(b);}}
Array.prototype.shuffle=function(){var i=this.length,j,t;while(i--){j=Math.floor((i+1)*Math.random());t=arr[i];arr[i]=arr[j];arr[j]=t;}}
Array.prototype.unique=function(){var a=[],i;this.sort();for(i=0;i<this.length;i++){if(this[i]!==this[i+1]){a[a.length]=this[i];}}return a;}
if(typeof Array.prototype.concat==='undefined'){Array.prototype.concat=function(a){for(var i=0,b=this.copy();i<a.length;i++){b[b.length]=a[i];}return b;};}
if(typeof Array.prototype.copy==='undefined'){Array.prototype.copy=function(a){var a=[],i=this.length;while(i--){a[i]=(typeof this[i].copy!=='undefined')?this[i].copy():this[i];}return a;};}
if(typeof Array.prototype.pop==='undefined'){Array.prototype.pop=function(){var b=this[this.length-1];this.length--;return b;};}
if(typeof Array.prototype.push==='undefined'){Array.prototype.push=function(){for(var i=0,b=this.length,a=arguments;i<a.length;i++){this[b+i]=a[i];}return this.length;};}
if(typeof Array.prototype.shift==='undefined'){Array.prototype.shift=function(){for(var i=0,b=this[0];i<this.length-1;i++){this[i]=this[i+1];}this.length--;return b;};}
if(typeof Array.prototype.slice==='undefined'){Array.prototype.slice=function(a,c){var i=0,b,d=[];if(!c){c=this.length;}if(c<0){c=this.length+c;}if(a<0){a=this.length-a;}if(c<a){b=a;a=c;c=b;}for(i;i<c-a;i++){d[i]=this[a+i];}return d;};}
if(typeof Array.prototype.splice==='undefined'){Array.prototype.splice=function(a,c){var i=0,e=arguments,d=this.copy(),f=a;if(!c){c=this.length-a;}for(i;i<e.length-2;i++){this[a+i]=e[i+2];}for(a;a<this.length-c;a++){this[a+e.length-2]=d[a-c];}this.length-=c-e.length+2;return d.slice(f,f+c);};}
if(typeof Array.prototype.unshift==='undefined'){Array.prototype.unshift=function(a){this.reverse();var b=this.push(a);this.reverse();return b;};}

// contains
Array.prototype.contains=function(obj){
	return (this.indexOf(obj)>0);
}
// append to array
Array.prototype.append=function(obj, nodup){
	if(!(nodup && this.contains(obj))){
		this[this.length]=obj;
	}
}


//===================================================
//===================================================

// PROTOTYPES - STRING
//trim whitespace
String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
}
// trim l whitespace
String.prototype.ltrim=function(){
    return this.replace(/^\s*/g,'');
}
// trim r whitespace
String.prototype.rtrim=function(){
    return this.replace(/\s*$/g,'');
}

/**
 * Throughout, whitespace is defined as one of the characters
 *  "\t" TAB \u0009
 *  "\n" LF  \u000A
 *  "\r" CR  \u000D
 *  " "  SPC \u0020
 *
 * This does not use Javascript's "\s" because that includes non-breaking
 * spaces (and also some other characters).
 */


/**
 * Determine whether a node's text content is entirely whitespace.
 *
 * @param nod  A node implementing the |CharacterData| interface (i.e.,
 *             a |Text|, |Comment|, or |CDATASection| node
 * @return     True if all of the text content of |nod| is whitespace,
 *             otherwise false.
 */
function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}


/**
 * Determine if a node should be ignored by the iterator functions.
 *
 * @param nod  An object implementing the DOM1 |Node| interface.
 * @return     true if the node is:
 *                1) A |Text| node that is all whitespace
 *                2) A |Comment| node
 *             and otherwise false.
 */

function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}

/**
 * Version of |previousSibling| that skips nodes that are entirely
 * whitespace or comments.  (Normally |previousSibling| is a property
 * of all DOM nodes that gives the sibling node, the node that is
 * a child of the same parent, that occurs immediately before the
 * reference node.)
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest previous sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_before( sib )
{
  while ((sib = sib.previousSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

/**
 * Version of |nextSibling| that skips nodes that are entirely
 * whitespace or comments.
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest next sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_after( sib )
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

/**
 * Version of |lastChild| that skips nodes that are entirely
 * whitespace or comments.  (Normally |lastChild| is a property
 * of all DOM nodes that gives the last of the nodes contained
 * directly in the reference node.)
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The last child of |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function last_child( par )
{
  var res=par.lastChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.previousSibling;
  }
  return null;
}

/**
 * Version of |firstChild| that skips nodes that are entirely
 * whitespace and comments.
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The first child of |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function first_child( par )
{
  var res=par.firstChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.nextSibling;
  }
  return null;
}

/**
 * Version of |data| that doesn't include whitespace at the beginning
 * and end and normalizes all whitespace to a single space.  (Normally
 * |data| is a property of text nodes that gives the text of the node.)
 *
 * @param txt  The text node whose data should be returned
 * @return     A string giving the contents of the text node with
 *             whitespace collapsed.
 */
function data_of( txt )
{
  var data = txt.data;
  // Use ECMA-262 Edition 3 String and RegExp features
  data = data.replace(/[\t\n\r ]+/g, " ");
  if (data.charAt(0) == " ")
    data = data.substring(1, data.length);
  if (data.charAt(data.length - 1) == " ")
    data = data.substring(0, data.length - 1);
  return data;
}

//=========================================
	
// show instructions
function show_instruction(instruction, parentnodename)
{
	var parentelem			= document.getElementById(parentnodename);
	var instructiondiv		= document.createElement("div");
	instructiondiv.setAttribute("class","info");
	instructiondiv.setAttribute("id","info");
	instructiondiv.setAttribute("text-align","left");
	
	//var instructionpara		= document.createElement("p");
	//instructionpara.setAttribute("id","infopara");
	if(instruction)
	{
		var instructionArray 	= instruction.split("^");
		var instructionlist		= document.createElement("ul");
		instructionlist.setAttribute("id","instructionList");
		var instructiontext		= document.createTextNode("Instructions");
		instructionlist.appendChild(instructiontext);
		for(var i = 0;i < instructionArray.length; i++)
		{
			var instructionlistitem	= document.createElement("li");
			instructionlistitem.setAttribute("id","list_x"+i);
			var instructiontext		= document.createTextNode(instructionArray[i]);
			instructionlistitem.appendChild(instructiontext);
			instructionlist.appendChild(instructionlistitem);
		}
	
	}
	
	var instructionclose	= document.createElement("a");
	instructionclose.setAttribute("href","javascript:close_instructions('"+parentelem.getAttribute("id")+"','"+instructiondiv.getAttribute("id")+"')");
	instructionclose.setAttribute("title","Click to remove instructions")
	
	var closeimage			= document.createElement("img");
	closeimage.setAttribute("src","./png/fileclose.gif");
	closeimage.setAttribute("align","right");
	closeimage.setAttribute("padding","2em");
	closeimage.setAttribute("vertical-align","middle");
	
	var theBreak 			= document.createElement('br');
	
	instructiondiv.appendChild(theBreak);
	instructionclose.appendChild(closeimage);
	instructiondiv.appendChild(instructionclose);
	instructiondiv.appendChild(instructionlist);
	//instructiondiv.appendChild(instructionpara);
	parentelem.appendChild(instructiondiv);
}

// remove instructions
function close_instructions(parentelem, instructiondiv)
{
	var parentelem = document.getElementById(parentelem);
	var removednode= document.getElementById(instructiondiv);
	parentelem.removeChild(removednode);
}

//=========================================
	
// show loading
function show_loading(parentnodename, advice)
{
	var parentelem			= document.getElementById(parentnodename);
	var advicediv			= document.createElement("div");
	advicediv.setAttribute("class","loading");
	advicediv.setAttribute("id","loading");
	
	//var instructionpara		= document.createElement("p");
	//instructionpara.setAttribute("id","infopara");
	if(advice)
	{
		var loadingElem	= document.createTextNode(advice);
	}else
	{
		var loadingElem	= document.createTextNode("Loading.....");
	}
	
	advicediv.appendChild(loadingElem);
	parentelem.appendChild(advicediv);
}

// remove instructions
function close_loading(parentelem, advicediv)
{
	var parentelem = document.getElementById(parentelem);
	var removednode= document.getElementById(advicediv);
	parentelem.removeChild(removednode);
}
// get artist details and create to return
	function getArtistInput(sendVar)
	{
		var sendVar			= sendVar;
		// assign value of artist details to add
			var givenName,familyName,email,origin,keyWords;
			
			if(document.getElementById('addGivenName').value)
	  			givenName 	= document.getElementById('addGivenName').value;
	  		if(document.getElementById('addFamilyName').value)
	  			familyName 	= document.getElementById('addFamilyName').value;
	  		if(document.getElementById('addEmail').value)
	  			email 		= document.getElementById('addEmail').value;
	  			
	  		var selection 	= document.getElementById('artistOrigin');
	  		if(selection.selectedIndex)
	  			origin	 	= selection.options[selection.selectedIndex].value;
	  			
	  		if(document.getElementById('addKeyWords').value)
	  			keyWords 	= document.getElementById('addKeyWords').value;
// check boxes are complete			
	  		if(!familyName)
	  		{
// exit if no value inserted	  			
	  			alert('You must insert the artists family name or firm to add or select another choice from the menu');
	  			exit;
	  		}
	  		if(!keyWords)
	  		{
// exit if no value inserted	  			
	  			alert('You must insert some key words for this artist or select another choice from the menu');
	  			exit;
	  		}
//==================
// start making sendVar to send	 
// replace & buggers up send var	
			if(givenName)  						 						
	  			givenName	= givenName.replace(/&/g,"and"); 		 						
	  		if(familyName)  						 						
	  			familyName	= familyName.replace(/&/g,"and"); 	 						
	  		if(email)  						 						
	  			email		= email.replace(/&/g,"and"); 	 						
	  		if(origin)  						 						
	  			origin		= origin.replace(/&/g,"and"); 	 						
	  		if(keyWords)  						 						
	  			keyWords	= keyWords.replace(/&/g,"and"); 	
	  		
	  		sendVar 	+= "&givenName="+givenName+"&familyName="+familyName+"&email="+email+"&origin="+origin+"&keyWords="+keyWords;
	  		
//==================	  		
// get new artist information - 395 artistInfoText information 
			var artistInfoText;
			// info boxexists and has a value
			if(document.getElementById('artistInfoText') && document.getElementById('artistInfoText').value)	
			{
				artistInfoText 	= document.getElementById('artistInfoText').value;
				artistInfoText	= artistInfoText.replace(/&/g,"and");
				if(artistInfoText.length>2500)
				{
					alert('The information text exceeds 2500 characters. To add bulky text. Save artist and then edit by adding add a text file');
					exit;
				}
				sendVar			+= "&artistInfoText="+artistInfoText;
			}
//==================
// get new artist telecom - 465
	  		// 465 artistPhone div holding telecom 'div' ('id',telecomId) > div' ('class','genreRightDiv');
					//var telecomInputId		= new Array('inputType_'+telecomId, 'inputNumber_'+telecomId, 'inputNotes_'+telecomId);
			// if div holding telecom exists
			if(document.getElementById('artistPhone'))
			{
				// artistPhone has children
				if(document.getElementById('artistPhone').hasChildNodes)
				{
					// get number of telephone nodes first one is the heading
					var telecomArray	= document.getElementById('artistPhone').childNodes;
					var thisTel 		= 0;
					var telCount		= telecomArray.length;
					var telecomHolder	= new Array(telCount-1);
					for(thisTel=1;thisTel<telCount;thisTel++)
					{
						// make array of type number and notes for each telephone entry
						var telecomDetails	= new Array(3);
						var inputArray	= telecomArray[thisTel].getElementsByTagName('input');
						var thisInput	= 0;
						for(thisInput=0;thisInput<3;thisInput++)
						{
							var thisId					= inputArray[thisInput].getAttribute('id');
							telecomDetails[thisInput]	= document.getElementById(thisId).value;
							telecomDetails[thisInput]	= telecomDetails[thisInput].replace(/&/g,"and");	
						}
						// add array of this telephone details to telecom holder array
						telecomHolder[thisTel-1]	= telecomDetails;
					}
//================
// add to sendVar
					sendVar			+= "&telecomHolder="+telecomHolder;
				}
			}
//===================
// 622 div holding address 'id','artistAddress' div' 'genreRightDiv
				// var addressInputId		= new Array('flatSubNo', 'buildingNameNo', 'streetName', 'locality', 'town', 'postZipCode', 'region');
			if(document.getElementById('artistAddress'))
			{
				//alert(document.getElementById('artistAddress').innerHTML);
				var artistAddress	= document.getElementById('artistAddress');
				var artistInputs	= artistAddress.getElementsByTagName('input');
				var thisInput		= 0;
				var inputLength		= artistInputs.length;
				var addressHolder 	= new Array(inputLength);
				var addressInputId	= new Array('flatSubNo', 'buildingNameNo', 'streetName', 'locality', 'town', 'postZipCode', 'region');
				
				for(thisInput=0;thisInput<artistInputs.length;thisInput++)
				{
					addressHolder[thisInput] = document.getElementById(addressInputId[thisInput]).value;
					addressHolder[thisInput]= addressHolder[thisInput].replace(/&/g,"and");	
				}
				// add country
				var countrySelection 	= document.getElementById('country');
		  		if(countrySelection.selectedIndex)
		  		{
		  			origin	 					= countrySelection.options[countrySelection.selectedIndex].value;
		  			addressHolder[7]			= origin;
		  		}
		  		
//===============
// add to sendVar	  		
				sendVar			+= "&addressHolder="+addressHolder;
			}
// make sendVar with value added to create   		
//alert('Family name ='+familyName+' info = '+artistInfoText+' origin ='+origin);
	  			return sendVar;
	}
	
//====================
// layout to add telecom
	function telecomToAdd(id, thisId, callFunction)
	{
		var thisNode	= document.getElementById(thisId);
		var id			= id;
		var callFunction= callFunction; 		
// arrays to set up input data
		var nodeArray		= new Array(7);
		var nodeLabel		= new Array(3);
		var nodeIput		= new Array(3);
// array of labels		
		var labelDescr		= new Array('Telecom type','Telecom No.','Telecom notes');
// array ids
		var thisDate		= new Date();
		var uniqueId		= thisDate.getTime();	
		var nodeId			= new Array('telecom_telecomType_'+uniqueId, 'telecom_telecomNo_'+uniqueId, 'telecom_telecomNotes_'+uniqueId);
// make line		
		nodeArray[0]	= document.createElement('hr');
		nodeArray[0].setAttribute('id','telHr');
		var lastId			= 'telHr';
		insertAfter(nodeArray[0],thisNode);
// loop setup inputs		
		var thisNodeArray 	= 0;
		var thisLoop		= 0;
		for(thisLoop=0;thisLoop<3;thisLoop++)
		{
			thisNodeArray++;
			// set up label
			nodeArray[thisNodeArray] 	= document.createElement('div');
			nodeArray[thisNodeArray].setAttribute('class','genreLeftDiv');
			nodeArray[thisNodeArray].setAttribute('id','labelDiv'+thisLoop);
			nodeLabel[thisLoop]			= document.createElement('label');
			nodeLabel[thisLoop].setAttribute('for',nodeId[thisLoop]);
			var labelText				= document.createTextNode(labelDescr[thisLoop]);
			nodeLabel[thisLoop].appendChild(labelText);
			nodeArray[thisNodeArray].appendChild(nodeLabel[thisLoop]);
			insertAfter(nodeArray[thisNodeArray],document.getElementById(lastId));
			// update lastId
			lastId						= 'labelDiv'+thisLoop;
			thisNodeArray++;
			// set up input
			nodeArray[thisNodeArray] 	= document.createElement('div');
			nodeArray[thisNodeArray].setAttribute('class','genreRightDiv');
			nodeArray[thisNodeArray].setAttribute('id','labelInput'+thisLoop);
			nodeIput[thisLoop]			= document.createElement('input');
			nodeIput[thisLoop].setAttribute('type','text');
			nodeIput[thisLoop].setAttribute('id',nodeId[thisLoop]);
			nodeIput[thisLoop].setAttribute('name',nodeId[thisLoop]);
			nodeIput[thisLoop].setAttribute('size','50');
			nodeArray[thisNodeArray].appendChild(nodeIput[thisLoop]);
			insertAfter(nodeArray[thisNodeArray],document.getElementById(lastId));
			// update lastId
			lastId						= 'labelInput'+thisLoop;
		}
		// <div class="genreRightButton">
		var buttonDiv	= document.createElement('div');
		buttonDiv.setAttribute('class','genreRightButton');
		
		var saveButton	= document.createElement('button');
		saveButton.setAttribute('id','saveButton_'+uniqueId);
		
		var buttonText	= document.createTextNode('Save new telecom details');
		// saveButton.setAttribute('onclick','adminStoreAjaxFuncArtist(\'xmlRequestStore.php\',\'adminStoreWelcomeMenu\',\'addArtistTelecom\','+id+','+uniqueId+');');

// check function to call - given as variable in call to this function		
		switch(callFunction)
		{
			case 'adminStoreAjaxFuncArtist': saveButton.setAttribute('onclick','adminStoreAjaxFuncArtist(\'xmlRequestStore.php\',\'adminStoreWelcomeMenu\',\'addArtistTelecom\','+id+','+uniqueId+');');
			break;
			
			case 'adminStoreAjaxFuncSupplier' : saveButton.setAttribute('onclick','adminStoreAjaxFuncSeller(\'xmlRequestStore.php\',\'adminStoreWelcomeMenu\',\'addSellerTelecom\','+id+','+uniqueId+');');
			break;
		}
		saveButton.appendChild(buttonText);
		buttonDiv.appendChild(saveButton);
		insertAfter(buttonDiv,document.getElementById(lastId));
	}
	
// upload a document
// docToUpload('.$artistId.', \'getDocButtonDiv\',\'adminStoreAjaxFuncArtist\')
// <button onclick="docToUpload('.$product->productId.', \'getPicButtonDiv_'.$marker.'\',\'adminStoreAjaxFuncProductPhoto\', '.$photo['productPhotoId'].','.$main.');">
	function docToUpload(id, thisId, callFunction, otherId, main)
	{
		var thisNode	= document.getElementById(thisId);
		var id			= id;
		var callFunction= callFunction; 
		/*
		<form enctype="multipart/form-data" action="uploader.php" method="POST">
 <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
 Choose a file to upload: <input name="uploadedfile" type="file" /><br />
 <input type="submit" value="Upload File" />
 </form>
 */
		var formNode		= document.createElement('form');
		formNode.setAttribute('enctype','multipart/form-data');
//		formNode.setAttribute('action','uploadDoc.php');
		formNode.setAttribute('method','POST');
		formNode.setAttribute('id','uploadForm');
		formNode.setAttribute('name','uploadForm');
		
		var inputSize		= document.createElement('input');
		inputSize.setAttribute('type','hidden');
		inputSize.setAttribute('name','MAX_FILE_SIZE');
		inputSize.setAttribute('id','MAX_FILE_SIZE');
		inputSize.setAttribute('value','500000');
		
		var inputParent		= document.createElement('input');
		inputParent.setAttribute('type','hidden');
		inputParent.setAttribute('name','parentId');
		inputParent.setAttribute('id','parentId');
		inputParent.setAttribute('value',thisId);
		
		var inputOwner		= document.createElement('input');
		inputOwner.setAttribute('type','hidden');
		inputOwner.setAttribute('name','ownerId');
		inputOwner.setAttribute('id','ownerId');
		inputOwner.setAttribute('value',id);
		
		var inputText	= document.createTextNode('Choose a file to upload: ');
		
		var inputNode		= document.createElement('input');
		inputNode.setAttribute('type','file');
		inputNode.setAttribute('name','uploadedfile');
		inputNode.setAttribute('id','uploadedfile');
		
		var lineBreak		= document.createElement('br');
		// <div class="genreRightButton">
		var buttonDiv	= document.createElement('div');
		buttonDiv.setAttribute('class','genreRightButton');
		
		var saveButton	= document.createElement('button');
		saveButton.setAttribute('id','saveDocButton');
		
		var buttonText	= document.createTextNode('Upload this file now ');
		// saveButton.setAttribute('onclick','adminStoreAjaxFuncArtist(\'xmlRequestStore.php\',\'adminStoreWelcomeMenu\',\'addArtistTelecom\','+id+','+uniqueId+');');
		
		switch(callFunction)
		{
// upload artist link related functions found in a  case statement in mainPages/uploadDoc.php		
			case 'adminStoreAjaxFuncArtist': saveButton.setAttribute('onclick','submitForm(\'uploadForm\',\'saveDocButton\')');
											formNode.setAttribute('action','adminstore.html?adminType=editArtist&artistId='+id+'&toProcess=artistLink');
											break;
// upload artist photo											
			case 'adminStoreAjaxFuncArtistPhoto': saveButton.setAttribute('onclick','submitForm(\'uploadForm\',\'saveDocButton\')');
											formNode.setAttribute('action','adminstore.html?adminType=editArtist&artistId='+id+'&toProcess=artistPhoto');
											break;		
// upload product Info											
			case 'adminStoreAjaxFuncProductInfo' : saveButton.setAttribute('onclick','submitForm(\'uploadForm\',\'saveDocButton\')');
											formNode.setAttribute('action','adminstore.html?adminType=editProduct&productId='+id+'&toProcess=productLink');
											break;			
// upload product photo											
			case 'adminStoreAjaxFuncProductPhoto' : saveButton.setAttribute('onclick','submitForm(\'uploadForm\',\'saveDocButton\')');
											formNode.setAttribute('action','adminstore.html?adminType=editProduct&productId='+id+'&toProcess=productPhoto&photoId='+otherId+'&main='+main);
											break;		
			case 'adminStoreAjaxFuncKnowledgeInfo' : saveButton.setAttribute('onclick','submitForm(\'uploadForm\',\'saveDocButton\')');
											formNode.setAttribute('action','adminstore.html?adminType=editKnowledge&knowledgeId='+id+'&toProcess=knowledgeLink');
											break;				
		}
		
		saveButton.appendChild(buttonText);
		buttonDiv.appendChild(saveButton);
		
		formNode.appendChild(inputSize);
		formNode.appendChild(inputParent);
		formNode.appendChild(inputOwner);
		formNode.appendChild(inputText);
		formNode.appendChild(inputNode);
		//formNode.appendChild(lineBreak);
		thisNode.innerHTML	= '';
		insertAfter(formNode,thisNode);
		insertAfter(buttonDiv,document.getElementById('uploadForm'));
	}
	
// submit upload document to server	
	var submitted = 0;
	
	function submitForm(formId,submitId)
	{
        if(!submitted)
        { 
        	document.getElementById(submitId).setAttribute('disabled','true');
            submitted = 1;
            document.getElementById(formId).submit();
        }else
        {
        	alert("Form already submitted, please be patient"); 
        }
	}
	

/*
// dynamically load js
	function dhtmlLoadScript(url)
	{
	   var e = document.createElement("script");
	   e.src = url;
	   e.type="text/javascript";
	   document.getElementsByTagName("head")[0].appendChild(e);
	}

onload = function()
{
   dhtmlLoadScript("dhtml_way.js");
}	

<script type="text/javascript">//<![CDATA[
         function makeRequest() {
           var oScript = document.createElement("script");
           oScript.src = "example1.js";
           document.body.appendChild(oScript);
         }
 
         function callback(sText) {
           alert("Loaded from file: " + sText);
         }
     //]]>
     </script>
   </head>
   <body>
     <input type="button" value="Click Me" onclick="makeRequest()" />
   </body>
 </html> 
The JavaScript file example1.js contains a single line:
callback("Hello world!");

*/
	
	function callBack()
	{
// initialise function to call		
		var toCall	= "";
		toCall		= document.getElementById('toCall').getAttribute('value');
// call function		
		switch(toCall)
		{
			case 'addArtist':	adminStoreAjaxFuncArtist('xmlRequestStore.php','adminStoreWelcomeMenu','addArtist');
			case 'addGenre':	adminStoreAjaxFunc('xmlRequestStore.php','adminStoreWelcomeMenu','addGenre');
			case 'addSeller':	adminStoreAjaxFuncSeller('xmlRequestStore.php','adminStoreWelcomeMenu','addSeller');
		}
	}
	
	function loadAjaxFuncCaller(jsToLoad, toCallBack)
	{
		var ajaxNo		= ajaxArray.length;
		var thisAjax	= 0;
		if(ajaxNo)
		{
			for(thisAjax=0;thisAjax<ajaxNo;thisAjax++)
			{
				jsToLoad			= ajaxArray[thisAjax];
// initialise function to call	
				if(toCallBack)
				{
					var toCall		= toCallBack;
// initialise hidden field with function to call back
					document.getElementById('toCall').setAttribute('value',toCall);			
				}
				
// initialise files loaded		
				var file	= "";
				file	= document.getElementById('loadedScripts').getAttribute('value');
				
				if (file.indexOf(jsToLoad)==-1) //Check to see if this object has not already been added to page before proceeding
				{
// load file			
					var fileref = document.createElement('script');
					fileref.setAttribute('src',jsToLoad);
					fileref.setAttribute('language','javascript');
					fileref.setAttribute('type','text/javascript');
					document.getElementsByTagName("head")[0].appendChild(fileref);
// add file loaded to hidden field			
					document.getElementById('loadedScripts').setAttribute('value',file+" "+jsToLoad);
					
				alert(toCall+" "+document.getElementById('loadedScripts').getAttribute('value')+" "+jsToLoad);
				alert(document.getElementsByTagName("head")[0].innerHTML);
// loaded file must call back to callBack() - this ensures it is loaded before proceeding
				}
			}
		}
	}
	
