
function showDefault(e, el){
	var targ = null;
	if (!e) e = window.event;
	if (e.target) targ = e.target;
	if (e.srcElement) targ = e.srcElement;
	if (targ.id == el.id)
		showSegment('segDefault');
}
function toggleGG(){
	var countryName = document.getElementById("countryName");
	var worldMap = document.getElementById("worldMap");
	if (countryName.className == "ctryTxtOff")
		countryName.className = "ctryTxtOn";	 
	else
		countryName.className = "ctryTxtOff";	 
	if (worldMap.className == "ctryImgOff")
		worldMap.className = "ctryImgOn";	 
	else
		worldMap.className = "ctryImgOff";	 
}

function showSegment(segName){
	var seg=new Array("segHome","segBusiness","segOnlineStore","segDefault");
	for (var i in seg){
		if(seg[i]!=segName){
			document.getElementById(seg[i]).style.visibility='hidden';
			document.getElementById(seg[i]).style.display='none';
		}
	}
	document.getElementById(segName).style.visibility='visible';
	document.getElementById(segName).style.display='block';
}

function showdivquicklink(thisitem) {
	var boxObj = document.getElementById("mainquicklink"+thisitem);
	var boxStyle = boxObj.style;
	var urlObj = document.getElementById("link"+thisitem);
	boxObj.parentNode.style.position = "relative";
	urlObj.style.background = "#DADAD9";
	urlObj.style.marginLeft = "0px";
	urlObj.style.marginRight = "0";
	urlObj.style.color = "#ccc";
	boxStyle.visibility = 'visible';
}
function hidedivquicklink(thisitem) {
	var boxObj = document.getElementById("mainquicklink"+thisitem);
	var urlObj = document.getElementById("link"+thisitem);
	urlObj.style.background = 'none';
	urlObj.style.borderLeft="none"; 
	urlObj.style.borderRight="none";
	urlObj.style.marginLeft = "0";
	urlObj.style.marginRight = "0";
	boxObj.style.visibility = 'hidden';
}

function setPanels(numberOfPanels)
{
	return numberOfPanels;
}
var totalPanels=setPanels(3);
var ws_height=0;			
var thisNav = navigator.userAgent.toLowerCase();
if(totalPanels==1 )
{
	if( thisNav.indexOf( "msie" ) == -1 )
	{
		ws_height=210;
	}
	else{
		ws_height=200;		
	}
}
if(totalPanels==2 )
{
	if( thisNav.indexOf( "msie" ) == -1 )	
	{
		ws_height=237;
	}
	else
	{
		ws_height=226;		
	}
}
if(totalPanels==3 )
{
	if( thisNav.indexOf( "msie" ) == -1 )
	{
		ws_height=134;
	}
	else
	{
		ws_height=133;
	}
}
function pause()
{
	;
}	

function hideCSDropDown(dropDownLink, dropDownLinkClass, dropDownPane, dropDownOverlay)
{	
	document.getElementById(dropDownLink).className	= dropDownLinkClass;
	document.getElementById(dropDownPane).style.visibility = 'hidden';
	document.getElementById("pipeLeft").style.visibility = 'visible';
	document.getElementById("pipeRight").style.visibility = 'visible';
	document.getElementById('localizationPaneShop2').style.visibility = 'hidden';
	document.getElementById('localizationPaneShop2').style.display= 'none';
}
function showCSDropDown(dropDownLink, dropDownLinkClass, dropDownPane, dropDownOverlay, showPipeLeft, showPipeRight)
{			
	document.getElementById(dropDownLink).className	= dropDownLinkClass+"ON";
	document.getElementById(dropDownPane).style.top =  '33px';
	document.getElementById(dropDownPane).style.visibility = 'visible';
	
	document.getElementById('localizationPaneShop2').style.left  = 		
		document.getElementById("localizationShopLink").offsetWidth
		-1+"px";
	document.getElementById('localizationPaneShop2').style.width = 		
		document.getElementById("localizationPaneShop").offsetWidth
		- document.getElementById("localizationShopLink").offsetWidth
		+"px";
	if (dropDownLink == 'localizationShopLink')
	{
		document.getElementById('localizationPaneShop2').style.visibility = 'visible';
		document.getElementById('localizationPaneShop2').style.display= 'block';
	}
	if (showPipeLeft)
	{
		document.getElementById("pipeLeft").style.visibility = 'visible';
	}
	else
	{
		document.getElementById("pipeLeft").style.visibility = 'hidden';
	}
	if (showPipeRight)
	{
		document.getElementById("pipeRight").style.visibility = 'visible';
	}
	else
	{
		document.getElementById("pipeRight").style.visibility = 'hidden';
	}
}

function hideSNDropDown(dropDownLink, dropDownFly)
{	
	document.getElementById(dropDownLink).className	= 'segNavMainTab';
	if (document.getElementById(dropDownFly)!=null)
	{
		document.getElementById(dropDownFly).style.visibility = 'hidden';
	}

		document.getElementById(dropDownLink).className	= 'segNavMainTab segNavMainTabOn';
	
}

	
function showSNDropDown(dropDownLink, dropDownFly)
{	
	document.getElementById(dropDownLink).className	= 'segNavMainTab segNavMainTabOver';
	if (document.getElementById(dropDownFly)!=null)
	{
		document.getElementById(dropDownFly).style.visibility = 'visible';
	}
}

function dropDownfocus(dropDownLink, dropDownFly)
{
	showSNDropDown(dropDownLink, dropDownFly);
	this.onblur = function () { document.getElementById(dropDownFly).focus(); }
	if((menu = document.getElementById(dropDownFly)))
		if((menu_item = menu.getElementsByTagName('a')))
			menu_item[menu_item.length-1].onblur= function () { hideSNDropDown(dropDownLink, dropDownFly); };
}

function highlightNav(currentUrl, navTabs, onClass, type)
{
	if (PageElements['segment'] != 'global')
	{
	var tabId = "";		
	var tabIdInner = "";		
	var navTab = "";	
	
	for (i = 0; i < navTabs.length; i++) 
	{	
		if (currentUrl.indexOf(navTabs[i].path) > -1) 
		{	
			tabId = navTabs[i].id;
			tabIdInner = navTabs[i].idInner;			
			break;				
		}
	}		
	navTab = document.getElementById(tabId);
	navTab.className = onClass;	  
	if (type == "globalNav")
	{
			navTabInner = document.getElementById(tabIdInner);				
			navTabInner.className = "globalSegNavOn";	  
	}	
	return tabId;
}		
}		

function NPC_divshow( itemlocation, showdiv, xOffset, yOffset )
{
	var xPosition = findPosX( itemlocation );
	var yPosition = findPosY( itemlocation );

	showdiv.style.visibility 	= 'visible';
	showdiv.style.left 			= xPosition + xOffset;
	showdiv.style.top 			= yPosition + yOffset;
}

var submenuoffset=0; 

function showchild(pid, mid, prefix, postfix){
	var cid = mid + postfix;
	var p = document.getElementById(pid);
	var arrdiv = document.getElementsByTagName('div');
	for (i = 0; i < arrdiv.length; i++)	
	{
		var d = arrdiv[i];
		if (d.id.indexOf(prefix) == 0 && d.id != cid && d.id.indexOf(postfix) != -1)
		{
			hidemenu(d.id);
		}
	}
	showmenu(cid);
}

function leftnav_highlight( thisObj )
{
	thisObj.className = "lftNavFlyMenu lftNavOnHover";
}

function leftnav_lowlight( thisObj )
{
	thisObj.className = "lftNavFlyMenu";
}

function leftnav_parent_highlight( thisObj )
{
	thisObj.className = "lftNavMainNav lftNavOnHover";
}

function leftnav_parent_lowlight( thisObj )
{
	thisObj.className = "lftNavMainNav";
}

function hidemenu(mid)
{
	var menu = document.getElementById(mid);

	menu.style.display="none";
	menu.style.visibility="hidden"; 
}

function showmenu(mid) 
{
	cancelfade();
	var menu = document.getElementById(mid);
	
	if (menu == null)
	{
		return;
	}
	
	if(document.all){
		menu.parentNode.style.position="relative"
		menu.style.position = "absolute"
		menu.style.top="0px";
		menu.style.left = menu.parentNode.offsetWidth  - 13 + "px";
	} else {
		menu.parentNode.style.position="relative"
		menu.style.position = "absolute" 
		menu.style.left = menu.parentNode.offsetWidth + "px";
		menu.style.top="0px";
	}

	setOpacity_leftnav(menu, .99);
    menu.style.display = "block";
	menu.style.visibility = "visible";
}

function setOpacity_leftnav(menu, newCount_leftnav) 
{
 	var newOpacityLevel_leftnav = newCount_leftnav;
 	if(document.all)
	{
 		menu.style.filter = "alpha(opacity=" + 100*newCount_leftnav + ")";
 	}
	else if(document.getElementById){
 		menu.style.opacity = newCount_leftnav;
 	}
}

function findPos(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

var leftnavOpacityTimeoutId1_leftnav = null;
var leftnavOpacityTimeoutId2_leftnav = null;
var leftnavOpacityTimeoutId3_leftnav = null;
var leftnavOpacityTimeoutId4_leftnav = null;
var leftnavOpacityTimeoutId5_leftnav = null;
var leftnavOpacityTimeoutId6_leftnav = null;
var leftnavOpacityTimeoutId7_leftnav = null;
var leftnavOpacityTimeoutId8_leftnav = null;
var leftnavOpacityTimeoutId9_leftnav = null;

function fademenu(mid)
{
	
	var menu = document.getElementById(mid);
	hidemenu(mid);
	
}

function cancelfade() 

{
	if(leftnavOpacityTimeoutId1_leftnav)
		clearTimeout(leftnavOpacityTimeoutId1_leftnav);
	
	if(leftnavOpacityTimeoutId2_leftnav)
		clearTimeout(leftnavOpacityTimeoutId2_leftnav);
	
	if(leftnavOpacityTimeoutId3_leftnav)
		clearTimeout(leftnavOpacityTimeoutId3_leftnav);
	
	if(leftnavOpacityTimeoutId4_leftnav)
		clearTimeout(leftnavOpacityTimeoutId4_leftnav);
	
	if(leftnavOpacityTimeoutId5_leftnav)
		clearTimeout(leftnavOpacityTimeoutId5_leftnav);
	
	if(leftnavOpacityTimeoutId6_leftnav)
		clearTimeout(leftnavOpacityTimeoutId6_leftnav);
	
	if(leftnavOpacityTimeoutId7_leftnav)
		clearTimeout(leftnavOpacityTimeoutId7_leftnav);
	
	if(leftnavOpacityTimeoutId8_leftnav)
		clearTimeout(leftnavOpacityTimeoutId8_leftnav);
	
	if(leftnavOpacityTimeoutId9_leftnav)
		clearTimeout(leftnavOpacityTimeoutId9_leftnav);
}

function showdiv(thisitem) {
	var thisitem2= "mainitem"+thisitem;
	var boxObj = document.getElementById(thisitem2);
	var boxStyle = boxObj.style;

	var textitem= "item"+thisitem;
	var urlObj = document.getElementById(textitem);

	var bottomitem = "bottomborder" + thisitem;
	var bottomObj = document.getElementById(bottomitem);
	
	boxObj.parentNode.style.position = "relative";
	boxStyle.bottom = "1em";
	
	document.getElementById("mr1_" + thisitem).style.marginLeft = (urlObj.offsetWidth) + "px";
	
	urlObj.style.background = "#FFF";
	urlObj.style.borderLeft="1px solid #DDD"
	urlObj.style.borderRight="1px solid #DDD";
	urlObj.style.marginLeft = "0px";
	urlObj.style.marginRight = "0px";

	

	bottomObj.style.width=(urlObj.offsetWidth) + "px";
	
	boxStyle.display = 'block';
	boxStyle.visibility = 'visible';
	bottomObj.style.display = 'block';
	bottomObj.style.visibility = 'visible';
}
	
function hidediv(thisitem) {
	var thisitem2= "mainitem"+thisitem;
	var boxObj = document.getElementById(thisitem2);
	boxObj.style.visibility = 'hidden';
	boxObj.style.display = 'none';
	
	var thisitem3= "item"+thisitem;
	var urlObj = document.getElementById(thisitem3);
  	urlObj.style.background = 'none';
	urlObj.style.borderLeft="none"; 
	urlObj.style.borderRight="none";
	urlObj.style.marginLeft = "1px";
	urlObj.style.marginRight = "1px";
	
	var bottomitem = "bottomborder" + thisitem;
	var bottomObj = document.getElementById(bottomitem);
	bottomObj.style.display = 'none';
	bottomObj.style.visibility = 'hidden';
}

document.write("");

function URLredirect( thisURL )
{
	var thisNav = navigator.userAgent.toLowerCase();
	if( thisNav.indexOf( "msie" ) > -1 )
	{
		var LocationFormString = "";

		document.getElementById( 'thisLocationFormDiv' ).innerHTML = LocationFormString;
		document.LocationForm.submit();
	}
	else
	{
		location.href= thisURL;
	}
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function base64( input )
{
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}



function showServicePrice(divId, imgSrc){
	document.getElementById("priceHover"+divId).style.visibility = 'visible';
	document.getElementById("imageHover"+divId).getElementsByTagName("img")[0].src = imgSrc;
}
function hideServicePrice(divId, imgSrc){
	document.getElementById("priceHover"+divId).style.visibility = 'hidden';
	document.getElementById("imageHover"+divId).getElementsByTagName("img")[0].src = imgSrc;
}
function delayHideServicePrice(divId){
	setTimeout("hideServicePrice('" + divId + "')",2000);
}
function showServiceLearn(id) {
document.getElementById(id).style.visibility = 'visible';
}
function hideServiceLearn(id) {
  document.getElementById(id).style.visibility = 'hidden';
}

function showInfoBox(divId){
	document.getElementById("infoBox"+divId).style.visibility = 'visible';
}

function hideInfoBox(divId){
	document.getElementById("infoBox"+divId).style.visibility = 'hidden';
}

function showSrFlyDwn(divId)
{
	document.getElementById("srFlyDwnBdy"+divId).style.visibility = 'visible';
	document.getElementById("srFlyDwnHdr"+divId).className="srFlyDwnWdgtTxt";
}

function hideSrFlyDwn(divId)
{
	document.getElementById("srFlyDwnBdy"+divId).style.visibility = 'hidden';
	document.getElementById("srFlyDwnHdr"+divId).className="srFlyDwnWdgtHdr";
}

function showSBWdgt(divId){
	document.getElementById(divId).style.visibility = 'visible';
}
function hideSBWdgt(divId){
	document.getElementById(divId).style.visibility = 'hidden';
}
function openSBWdgtLinks(socialUrl)
{
	var sbLink = socialUrl.replace("THE_PAGE_URL",window.location.href);			
	sbLink = sbLink.replace("THE_PAGE_TITLE",document.title);			
	window.open(sbLink);
}
function arrayCopy(input)
{
	var output = new Array(input.length);

	for (i in input) {
		if (typeof(input[i]) == 'array') {
			output[i] = arrayCopy(input[i]);
		} else {
			output[i] = input[i];
		}
	}

	return output;
}


	function TreeMenu(iconpath, myname, linkTarget, defaultClass, usePersistence, noTopLevelImages)
	{
		// Properties
		this.iconpath         = iconpath;
		this.myname           = myname;
		this.linkTarget       = linkTarget;
		this.defaultClass     = defaultClass;
		this.usePersistence   = usePersistence;
		this.noTopLevelImages = noTopLevelImages;
		this.n                = new Array();
		this.output           = '';

		this.nodeRefs       = new Array();
		this.branches       = new Array();
		this.branchStatus   = new Array();
		this.layerRelations = new Array();
		this.childParents   = new Array();
		this.cookieStatuses = new Array();

		this.preloadImages();
	}


	TreeMenu.prototype.addItem = function (newNode)
	{
		newIndex = this.n.length;
		this.n[newIndex] = newNode;
		
		return this.n[newIndex];
	}


	TreeMenu.prototype.preloadImages = function ()
	{
		var plustop    = new Image; plustop.src    =  '/plustop.gif';
		var plusbottom = new Image; plusbottom.src = '/plusbottom.gif';
		var plus       = new Image; plus.src       = '/plus.gif';
	
		var minustop    = new Image; minustop.src    = '/minustop.gif';
		var minusbottom = new Image; minusbottom.src = '/minusbottom.gif';
		var minus       = new Image; minus.src       = '/minus.gif';
	
		var branchtop    = new Image; branchtop.src    = '/branchtop.gif';
		var branchbottom = new Image; branchbottom.src = '/branchbottom.gif';
		var branch       = new Image; branch.src       = '/branch.gif';
	
		var linebottom = new Image; linebottom.src = '/linebottom.gif';
		var line       = new Image; line.src       = '/line.gif';
	}


	TreeMenu.prototype.drawMenu = function ()// OPTIONAL ARGS: nodes = [], level = [], prepend = '', expanded = false, visbility = 'inline', parentLayerID = null
	{
		/**
	    * Necessary variables
	    */
		var output        = '';
		var modifier      = '';
		var layerID       = '';
		var parentLayerID = '';
	
		/**
	    * Parse any optional arguments
	    */
		var nodes         = arguments[0] ? arguments[0] : this.n
		var level         = arguments[1] ? arguments[1] : [];
		var prepend       = arguments[2] ? arguments[2] : '';
		var expanded      = arguments[3] ? arguments[3] : false;
		var visibility    = arguments[4] ? arguments[4] : 'inline';
		var parentLayerID = arguments[5] ? arguments[5] : null;

		var currentlevel  = level.length;

		for (var i=0; i<nodes.length; i++) {
		
			level[currentlevel] = i+1;
			layerID = this.myname + '_' + 'node_' + this.implode('_', level);

			/**
            * Store this object in the nodeRefs array
            */
			this.nodeRefs[layerID] = nodes[i];

			/**
	        * Store the child/parent relationship
	        */
			this.childParents[layerID] = parentLayerID;
	
			/**
	        * Gif modifier
	        */
			if (i == 0 && parentLayerID == null) {
				modifier = nodes.length > 1 ? "top" : 'single';
			} else if(i == (nodes.length-1)) {
				modifier = "bottom";
			} else {
				modifier = "";
			}
	
			/**
	        * Single root branch is always expanded
	        */
			if (!this.doesMenu() || (parentLayerID == null && (nodes.length == 1 || this.noTopLevelImages))) {
				expanded = true;
	
			} else if (nodes[i].expanded) {
				expanded = true;
	
			} else {
				expanded = false;
			}
	
			/**
	        * Make sure visibility is correct based on parent status
	        */
			visibility =  this.checkParentVisibility(layerID) ? visibility : 'none';

			/**
	        * Setup branch status and build an indexed array
			* of branch layer ids
	        */
			if (nodes[i].n.length > 0) {
				this.branchStatus[layerID] = expanded;
				this.branches[this.branches.length] = layerID;
			}
	
			/**
	        * Setup toggle relationship
	        */
			if (!this.layerRelations[parentLayerID]) {
				this.layerRelations[parentLayerID] = new Array();
			}
			this.layerRelations[parentLayerID][this.layerRelations[parentLayerID].length] = layerID;
	
			/**
	        * Branch images
	        */
			var gifname  = nodes[i].n.length && this.doesMenu() && nodes[i].isDynamic ? (expanded ? 'minus' : 'plus') : 'branch';
			var iconName = expanded && nodes[i].expandedIcon ? nodes[i].expandedIcon : nodes[i].icon;
			var iconimg  = nodes[i].icon ? this.stringFormat('<img src="{0}/{1}" align="top" id="icon_{2}">', this.iconpath, iconName, layerID) : '';
			
			/**
			* Add event handlers
			*/
			var eventHandlers = "";
			for (j in nodes[i].events) {
				eventHandlers += this.stringFormat('{0}="{1}" ', j, nodes[i].events[j]);
			}

			/**
	        * Build the html to write to the document
			* IMPORTANT:
			* document.write()ing the string: '<div style="display:...' will screw up nn4.x
	        */
			var layerTag  = this.doesMenu() ? this.stringFormat('<div id="{0}" style="display: {1}" class="{2}">', layerID, visibility, (nodes[i].cssClass ? nodes[i].cssClass : this.defaultClass)) : this.stringFormat('<div class="{0}">', nodes[i].cssClass ? nodes[i].cssClass : this.defaultClass);
			var onMDown   = this.doesMenu() && nodes[i].n.length  && nodes[i].isDynamic ? this.stringFormat('onmousedown="{0}.toggleBranch(\'{1}\', true)" style="cursor: pointer; cursor: hand"', this.myname, layerID) : '';
			var imgTag    = this.stringFormat('<img src="{0}/{1}{2}.gif" align="top" border="0" name="img_{3}" {4}>', this.iconpath, gifname, modifier, layerID, onMDown);
			var linkTarget= nodes[i].linkTarget ? nodes[i].linkTarget : this.linkTarget;
			var linkStart = nodes[i].link ? this.stringFormat('<a href="{0}" target="{1}">', nodes[i].link, linkTarget) : '';

			var linkEnd   = nodes[i].link ? '</a>' : '';

			this.output += this.stringFormat('{0}<nobr>{1}{2}{3}{4}<span {5}>{6}</span>{7}</nobr><br></div>',
			                  layerTag,
							  prepend,
			                  parentLayerID == null && (nodes.length == 1 || this.noTopLevelImages) ? '' : imgTag,
							  iconimg,
							  linkStart,
							  eventHandlers,
							  nodes[i].title,
							  linkEnd);

			/**
	        * Traverse sub nodes ?
	        */
			if (nodes[i].n.length) {
				/**
	            * Determine what to prepend. If there is only one root
				* node then the prepend to pass to children is nothing.
				* Otherwise it depends on where we are in the tree.
	            */
				if (parentLayerID == null && (nodes.length == 1 || this.noTopLevelImages)) {
					var newPrepend = '';
	
				} else if (i < (nodes.length - 1)) {
					var newPrepend = prepend + this.stringFormat('<img src="{0}/line.gif" align="top">', this.iconpath);
	
				} else {
					var newPrepend = prepend + this.stringFormat('<img src="{0}/linebottom.gif" align="top">', this.iconpath);
				}

				this.drawMenu(nodes[i].n,
				              arrayCopy(level),
				              newPrepend,
				              nodes[i].expanded,
				              expanded ? 'inline' : 'none',
				              layerID);
			}
		}
	}

/**
* Writes the output generated by drawMenu() to the page
*/
	TreeMenu.prototype.writeOutput = function ()
	{
		document.write(this.output);
	}

/**
* Toggles a branches visible status. Called from resetBranches()
* and also when a +/- graphic is clicked.
*/
	TreeMenu.prototype.toggleBranch = function (layerID, updateStatus) // OPTIONAL ARGS: fireEvents = true
	{
		var currentDisplay = this.getLayer(layerID).style.display;
		var newDisplay     = (this.branchStatus[layerID] && currentDisplay == 'inline') ? 'none' : 'inline';

		var fireEvents     = arguments[2] != null ? arguments[2] : true;

		for (var i=0; i<this.layerRelations[layerID].length; i++) {

			if (this.branchStatus[this.layerRelations[layerID][i]]) {
				this.toggleBranch(this.layerRelations[layerID][i], false);
			}
	
			this.getLayer(this.layerRelations[layerID][i]).style.display = newDisplay;
		}
	
		if (updateStatus) {
			this.branchStatus[layerID] = !this.branchStatus[layerID];
	
			/**
	        * Persistence
	        */
			if (this.doesPersistence() && !arguments[2] && this.usePersistence) {
				this.setExpandedStatusForCookie(layerID, this.branchStatus[layerID]);
			}

			/**
			* Fire custom events
			*/
			if (fireEvents) {
				nodeObject = this.nodeRefs[layerID];
	
				if (nodeObject.ontoggle != null) {
					eval(nodeObject.ontoggle);
				}
				
				if (newDisplay == 'none' && nodeObject.oncollapse != null) {
					eval(nodeObject.oncollapse);
				} else if (newDisplay == 'inline' && nodeObject.onexpand != null){
					eval(nodeObject.onexpand);
				}
			}

			// Swap image
			this.swapImage(layerID);
		}

		// Swap icon
		this.swapIcon(layerID);
	}

/**
* Swaps the plus/minus branch images
*/
	TreeMenu.prototype.swapImage = function (layerID)
	{
		var imgSrc = document.images['img_' + layerID].src;
	
		var re = /^(.*)(plus|minus)(bottom|top|single)?.gif$/
		if (matches = imgSrc.match(re)) {
	
			document.images['img_' + layerID].src = this.stringFormat('{0}{1}{2}{3}',
			                                                matches[1],
															matches[2] == 'plus' ? 'minus' : 'plus',
															matches[3] ? matches[3] : '',
															'.gif');
		}
	}

/**
* Swaps the icon for the expanded icon if one
* has been supplied.
*/
	TreeMenu.prototype.swapIcon = function (layerID)
	{
		if (document.images['icon_' + layerID]) {
			var imgSrc = document.images['icon_' + layerID].src;
	
			if (this.nodeRefs[layerID].icon && this.nodeRefs[layerID].expandedIcon) {
				var newSrc = (imgSrc.indexOf(this.nodeRefs[layerID].expandedIcon) == -1 ? this.nodeRefs[layerID].expandedIcon : this.nodeRefs[layerID].icon);
	
				document.images['icon_' + layerID].src = '/' + newSrc;
			}
		}
	}

/**
* Can the browser handle the dynamic menu?
*/
	TreeMenu.prototype.doesMenu = function ()
	{
		return (is_ie4up || is_nav6up || is_gecko || is_opera7);
	}

/**
* Can the browser handle save the branch status
*/
	TreeMenu.prototype.doesPersistence = function ()
	{
		return (is_ie4up || is_gecko || is_nav6up || is_opera7);
	}

/**
* Returns the appropriate layer accessor
*/
	TreeMenu.prototype.getLayer = function (layerID)
	{
		if (is_ie4) {
			return document.all(layerID);
	
		} else if (document.getElementById(layerID)) {
			return document.getElementById(layerID);
	
		} else if (document.all && document.all(layerID)) {
			return document.all(layerID);
		}
	}

/**
* Save the status of the layer
*/
	TreeMenu.prototype.setExpandedStatusForCookie = function (layerID, expanded)
	{
		this.cookieStatuses[layerID] = expanded;
		this.saveCookie();
	}

/**
* Load the status of the layer
*/
	TreeMenu.prototype.getExpandedStatusFromCookie = function (layerID)
	{
		if (this.cookieStatuses[layerID]) {
			return this.cookieStatuses[layerID];
		}

		return false;
	}

/**
* Saves the cookie that holds which branches are expanded.
* Only saves the details of the branches which are expanded.
*/
	TreeMenu.prototype.saveCookie = function ()
	{
		var cookieString = new Array();

		for (var i in this.cookieStatuses) {
			if (this.cookieStatuses[i] == true) {
				cookieString[cookieString.length] = i;
			}
		}
		
		document.cookie = 'TreeMenuBranchStatus=' + cookieString.join(':');
	}

/**
* Reads cookie parses it for status info and
* stores that info in the class member.
*/
	TreeMenu.prototype.loadCookie = function ()
	{
		var cookie = document.cookie.split('; ');

		for (var i=0; i < cookie.length; i++) {
			var crumb = cookie[i].split('=');
			if ('TreeMenuBranchStatus' == crumb[0] && crumb[1]) {
				var expandedBranches = crumb[1].split(':');
				for (var j=0; jexpandedBranches.length; j++) {
					this.cookieStatuses[expandedBranches[j]] = true;
				}
			}
		}
	}

/**
* Reset branch status
*/
	TreeMenu.prototype.resetBranches = function ()
	{
		if (!this.doesPersistence()) {
			return false;
		}
		
		this.loadCookie();

		for (var i=0; ithis.branches.length; i++) {
			var status = this.getExpandedStatusFromCookie(this.branches[i]);
			// Only update if it's supposed to be expanded and it's not already
			if (status == true && this.branchStatus[this.branches[i]] != true) {
				if (this.checkParentVisibility(this.branches[i])) {
					this.toggleBranch(this.branches[i], true, false);
				} else {
					this.branchStatus[this.branches[i]] = true;
					this.swapImage(this.branches[i]);
				}
			}
		}
	}

/**
* Checks whether a branch should be open
* or not based on its parents' status
*/
	TreeMenu.prototype.checkParentVisibility = function (layerID)
	{
		if (this.in_array(this.childParents[layerID], this.branches)
		    && this.branchStatus[this.childParents[layerID]]
			&& this.checkParentVisibility(this.childParents[layerID]) ) {
			
			return true;
	
		} else if (this.childParents[layerID] == null) {
			return true;
		}
		
		return false;
	}

/**
* New C# style string formatter
*/
	TreeMenu.prototype.stringFormat = function (strInput)
	{
		var idx = 0;
	
		for (var i=1; iarguments.length; i++) {
			while ((idx = strInput.indexOf('{' + (i - 1) + '}', idx)) != -1) {
				strInput = strInput.substring(0, idx) + arguments[i] + strInput.substr(idx + 3);
			}
		}
		
		return strInput;
	}

/**
* Also much adored, the PHP implode() function
*/
	TreeMenu.prototype.implode = function (seperator, input)
	{
		var output = '';
	
		for (var i=0; i<input.length; i++) {
			if (i == 0) {
				output += input[i];
			} else {
				output += seperator + input[i];
			}
		}
		
		return output;
	}

/**
* Aah, all the old favourites are coming out...
*/
	TreeMenu.prototype.in_array = function (item, arr)
	{
		for (var i=0; iarr.length; i++) {
			if (arr[i] == item) {
				return true;
			}
		}
	
		return false;
	}

/**
* TreeNode Class
*/
	function TreeNode(title, icon, link, expanded, isDynamic, cssClass, linkTarget, expandedIcon)
	{
		this.title        = title;
		this.icon         = icon;
		this.expandedIcon = expandedIcon;
		this.link         = link;
		this.expanded     = expanded;
		this.isDynamic    = isDynamic;
		this.cssClass     = cssClass;
		this.linkTarget   = linkTarget;
		this.n            = new Array();
		this.events       = new Array();
		this.handlers     = null;
		this.oncollapse   = null;
		this.onexpand     = null;
		this.ontoggle     = null;
	}

/**
* Adds a node to an already existing node
*/
	TreeNode.prototype.addItem = function (newNode)
	{
		newIndex = this.n.length;
		this.n[newIndex] = newNode;
		
		return this.n[newIndex];
	}

/**
* Sets an event for this particular node
*/
	TreeNode.prototype.setEvent = function (eventName, eventHandler)
	{
		switch (eventName.toLowerCase()) {
			case 'onexpand':
				this.onexpand = eventHandler;
				break;

			case 'oncollapse':
				this.oncollapse = eventHandler;
				break;

			case 'ontoggle':
				this.ontoggle = eventHandler;
				break;

			default:
				this.events[eventName] = eventHandler;
		}
	}

    var agt=navigator.userAgent.toLowerCase();

    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
	
	var is_opera  = (agt.indexOf("opera") != -1);
	var is_opera7 = (is_opera && is_major >= 7) || agt.indexOf("opera 7") != -1;

	// Patch from Harald Fielker
    if (agt.indexOf('konqueror') != -1) {
        var is_nav    = false;
        var is_nav6up = false;
        var is_gecko  = false;
        var is_ie     = true;
        var is_ie4    = true;
        var is_ie4up  = true;
    }

	offClickFigViewer=function(event) {
		var target = Event.element(event);
		if ($('figureViewer-wrap').style.display!="none" && target!=$('figureViewer-wrap') && !target.descendantOf('figureViewer-wrap')) {
			showFigures(event);
			Event.stopObserving(document,"click",offClickFigViewer);
		}
	};


function updateFigImg(doiFigure, index, imgTag) {
	var isMedium = index== 0 && doiFigure.isTocFigure;
	imgTag.src = doiFigure.path + '' + (isMedium ? '' : '') + doiFigure.images[index];
	$(imgTag)[isMedium ? 'addClassName' : 'removeClassName']('tocGraphic');
}

// For toggling the Journal View on the Pubs Home Page
function changeView(id) {
	var show=id+"View";
	var highlight=id+"Link";

	var block1=$('azView');
	var block2=$('catView');
	show=$(show);
	var link1=$('azLink');
	var link2=$('catLink');
	highlight=$(highlight);

	// first, hide both views
	block1.style.display="none";
	block2.style.display="none";

	// second, show the one that was clicked
	show.style.display="block";

	// third, set both links to the default appearance
	link1.style.fontWeight="normal";
	link1.style.background="transparent";
	link1.style.color="#369";
	link1.style.border="0";
	link2.style.fontWeight="normal";
	link2.style.background="transparent";
	link2.style.color="#369";
	link2.style.border="0";

	// fourth, highlight the link that was used
	highlight.style.fontWeight="bold";
	highlight.style.background="#eee";
	highlight.style.color="#000";
	highlight.style.border="solid 1px #ccc";
}


function showPulldown(button) {
	var block;
	var list;

	// for cover art gallery
	if ($('coverVol')) {
		block=$('coverVol');
		button=button.getElementsByTagName('a')[0];
		list=button.parentNode.getElementsByTagName('ul')[0];
		if (list.style.display == "none") {
			Effect.BlindDown(list, {duration:0.3});
			button.style.backgroundPosition="0 -20px";
		}
		else {
			block.style.zIndex="1";
			Effect.BlindUp(list, {duration:0.3});
			button.style.backgroundPosition="0 0";
		}
	}

	// for full text html template
	else {
		block=button.parentNode.parentNode; // ul.anchors
		list=button.parentNode.getElementsByTagName('ul')[0];
		if (list.style.display == "none") {
			block.style.zIndex="9000";
			Effect.BlindDown(list, {duration:0.3});
			button.style.backgroundPosition="0 -20px";
			$(block).writeAttribute("id","openJumpMenu");
			Event.observe(document,"click",offClickAnchors);
		}
		else {
			block.style.zIndex="1";
			Effect.BlindUp(list, {duration:0.3});
			button.style.backgroundPosition="0 0";
			$(block).writeAttribute("id","");
			Event.stopObserving(document,"click",offClickAnchors);
		}
	}
}

function hidePulldown(anchor) {
	var button=anchor.parentNode.parentNode.parentNode.getElementsByTagName('a')[0];
	showPulldown(button);
}



function showRef(ref, ids) {
	initReferencesBaloon(ref, ids);	 // Added by Atypon
	var browserName=navigator.appName;
	if (browserName != "Opera" || /\d+/.exec(navigator.appVersion)[0] >= 9) {
		var balloon=$(ref).next().down();
		if (balloon && balloon.style) { // Atypon: degrade gracefully when baloon is not found
			if (balloon.style.display != "inline") {
				//  hideRef is calling showRef - need to check if is different before is hidden
				var isDifferent = !window.openedReferenceBalloon || window.openedReferenceBalloon.innerHTML != balloon.innerHTML;
				if (window.openedReferenceBalloon) hideRef(window.openedReferenceBalloon);
				if (isDifferent) {
					balloon.style.display = "inline";
					window.openedReferenceBalloon = balloon;
					balloon.writeAttribute("id","openBalloon");
				}
				Event.observe.defer(document,"click",offClickRef);

			}
			else {
				balloon.style.display="none";
				window.openedReferenceBalloon = false;
				balloon.writeAttribute("id","");
				Event.stopObserving(document,"click",offClickRef);
			}
			return;
		}
	}
	parent.location="#references";
}
function hideRef(ref) {
	ref=$(ref).up('.ref').previous();
	showRef(ref);
}



// Article template figure viewer
function showFigures(e) {
	//added by Atypon
	var n=0;
	if (!e)	var e = window.event;
	initViewer(e);  /* Atypon change */
	var viewer=$('figureViewer-wrap');
	if (!viewer) return; // It may take some time till document gets ready
	if (viewer.style.display != '') {
		bg= new Array(); /* Atypon change */
		bg[0]=$('header');
		bg[1]=$('mainBody');
		bg[2]=$('pageFooter-wrap');
		var posY=0;

		if (e.pageY) {
			posY = e.pageY;
		}
		else if (e.clientY) {
			posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}

		while (bg[n]) {
			bg[n].style.MozOpacity="0.70";
			bg[n].style.KHTMLOpacity="0.70";
			bg[n].style.opacity="0.70";
			n++;
		}
		Effect.Appear('figureViewer-wrap', {duration:0.5});
		posY=posY-100; // offset from mouse position
		viewer.style.top=posY+"px";
		new Draggable('figureViewer-wrap',{starteffect: null, endeffect: null});

		// clicking off the viewer hides the viewer
		Event.observe(document,"click",offClickFigViewer);
	}
	else {
		while (bg[n]) {
			bg[n].style.MozOpacity="1";
			bg[n].style.KHTMLOpacity="1";
			bg[n].style.opacity="1";
			n++;
		}
		Effect.Fade('figureViewer-wrap', {duration:0.5});
		Event.stopObserving(document,"click",offClickFigViewer);
	}
}



function initViewer(e) {
	if (!window.figureViewer) return false;
	if ($('figureViewer-wrap') && $('figureViewer-wrap').style.display == '') return false;

	var figures = window.figureViewer.figures;

	/* clear up figures that were not rendered */
	for (var i = figures.length - 1; i >= 0; i--) {
		var figureMeta = figures[i];
		if (!figureMeta || !$(figureMeta.i)) figures.splice(i, 1);
	}
	if (figures.length == 0) {
		window.figureViewer = null;
		return false;
	}

	var fvw = $('figureViewer-wrap');
	if (!fvw) {
		var c = $('container');
		if (c) {
			fvw = document.createElement("div");
			fvw.id='figureViewer-wrap';
			fvw.style.display='none';
			c.appendChild(fvw);
			fvw.innerHTML =
				'<div id="figureViewer">\
					<div id="figureViewerNav">\
						<a title="Close Figure Viewer" href="#" onclick="showFigures(event); return false;" class="close">Close</a>\
						<div class="figureNav">\
							<a class="prev" title="Previous Figure" href="#" class="disabled"></a>\
							<span>Figure <span class="index">1</span> of ' + figures.length + '</span>\
							<a class="next" title="Next Figure" href="#" class="disabled"></a>\
						</div>\
					</div>\
					<div id="figureCanvas">\
						<div id="figTools">\
						</div>\
						<div class="figBox">\
						</div>\
						<div class="caption">&nbsp;\
						</div>\
					</div>\
				</div>\
				<div id="figureViewer-footer">\
					<img alt="" src="../IMG/figureViewer-bg3.gif"/>\
				</div>';
			fvw = $(fvw);
		}
	}

	var index = 0;
	var figureElement = Event.findElement(e, ".figure");
	if (figureElement && figureElement.id) {
		var figureId = figureElement.id;
		while (index < figures.length && figures[index].i != figureId) index++;
	}
	showImage(index);
}

function showImage(index) {
	var figures = window.figureViewer.figures;
	var figureMeta = figures[index];
	if (!figureMeta) figureMeta = figures[index=0];
	var graphics = figureMeta.g;
	var figureElement = $(figureMeta.i);

	var fvw = $('figureViewer-wrap');

	/* image and caption */
	var html = "";
	for (var i = 0; i < graphics.length; i++) {
		html += '<img alt="Figure" src="' + window.figureViewer.path + graphics[i].m + '"/>';
	}
	fvw.down(".figBox").innerHTML = html;
	var captionElement = figureElement.down(".caption");
	fvw.down(".caption").innerHTML = captionElement ? captionElement.innerHTML : "";

	/* navigation */
	var pLink = fvw.down('.prev');
	if (index == 0) {
		pLink.addClassName("disabled");
		pLink.href = "#"
	} else {
		pLink.removeClassName("disabled");
		pLink.href = "JavaScript:showImage(" + (index - 1) + ")";
	}

	index++;
	var nLink = fvw.down('.next');
	if (index == figures.length) {
		nLink.addClassName("disabled");
		nLink.href = "#"
	} else {
		nLink.removeClassName("disabled");
		nLink.href = "JavaScript:showImage(" + index + ")";
	}

	fvw.down('.index').innerHTML = index;

	/* figure tools */
	var ftHtml = '';

	if (figureMeta.weo) {
		for (var i = 0; i < figureMeta.weo.length; i++) {
			var weo = figureMeta.weo[i];
			if (weo && weo.h) {
				ftHtml += ''
				if (weo.t) { ftHtml += ': ' + weo.t; }
				ftHtml += '';
			}
		}
	}


	html = '';
	for (var i = 0; i < graphics.length; i++) {
		if (graphics[i].l) {
			if (html) html += '<br />'; // is not first link
			html += '';
		}
	}
	if (html) {
		ftHtml += '';

		
	}

	fvw.down('#figTools').innerHTML = ftHtml;
}

function showLoading() {
	alert("Loading");
}
function displayFigureBrowser() {
	alert("Loaded");
}
function popRef2(ids) {
}
 function myFocus(element) {
     if (element.value == element.defaultValue) {
       element.value = '';
     }
   }
   function myBlur(element) {
     if (element.value == '') {
       element.value = element.defaultValue;
     }
   }
   
<!-- Set the vars that scapi.js will need -->
var ScapiURL="http://searchapi.scopus.com/";
var ScapiTimeout="40000";
var debug = new scapiDebug();
var scapi = new scapiInterface();
function scapiInterface(){
	this._resultsValid = false;
	this._results = null;
	this._errors = null;
	this._warnings = null;
	this._geturl = "API.php?scopus=get&url=";
	this._search = null;
imeout="40000";

<!-- Include scapi.js -->
	this._callback = null;
	this._errorCallback = null;
	
	this.Backend = new scapiBackend();
	this.Renderer = new scapiListRenderer();
	
	// see here for explination of "me": 
	// http://w3future.com/html/stories/callbacks.xml
	var me = this;
	
	//developerID and it's setter
	this._developerID = null;
	this.setDeveloperID = function(developerID){
		me._developerID = developerID;
	}
	
	//set the renderer (overiding the previous or default renderer)
	this.setRenderer = function(newRenderer){
		if (newRenderer != null){
			this.Renderer = newRenderer;
		}else{
			debug.write("setRenderer:no renderer specified");
		}
	}
	
	this.selectRenderer = function(renderer){
		if(renderer == "list"){
			this.Renderer = new scapiListRenderer();
		}
	}
	
	//set the render location (passthrough to the renderer)
	this.setRenderLocation = function(idName){
		this.Renderer.setRenderLocation(idName);
	}
	
	//set the callback to be called when a search is compleate
	this.setCallback = function(callback){
		if(callback != null){
			this._callback = callback;
		}else{
			debug.write("setCallback:no callback specified");
		}
	}
	
	this.setErrorCallback = function(callback){
		if(callback != null){
			this._errorCallback = callback;
		}else{
			debug.write("setErrorCallback:no callback specified");
		}
	}
	
	//runSearch and it's callback
	this.runSearch = function(searchObj){
		me._resultsValid = false;
		me._search = searchObj;
		me.Backend.submitSearch(searchObj, me._developerID, me.runSearchCallback);
	}
	this.runSearchCallback = function(responseObj){
		me._errors = null;
		me._warnings = null;
		me._results = null;
		me._resultsValid = false;
		if(responseObj == "timeout"){
			debug.write("runSearch: search timed out");
			if(me._errorCallback!=null){
				me._errorCallback();
			}
		}else if(responseObj.ERROR != null){
			debug.write("runSearch: error occured durring search");
			me._errors = responseObj.ERROR.Errors;
			if(me._errorCallback!=null){
				me._errorCallback();
			}
		}else if(responseObj.PartOK != null){
			debug.write("runSearch: warnings occured durring search");
			me._results = responseObj.PartOK;
			me._warnings = responseObj.PartOK.Warnings;
			me._resultsValid = true;
		}else if(responseObj.OK!= null){
			debug.write("runSearch: search results are OK");
			me._results = responseObj.OK;
			me._resultsValid = true;
		}
		if(me._callback!=null){
			me._callback();
		}else{
			debug.write("runSearch:no callback specified");
		}
	}
	
	//search and it's callback
	this.search = function(searchObj){
		me._resultsValid = false;
		me._search = searchObj;
		me.Backend.submitSearch(searchObj, me._developerID, me.searchCallback);
	}
	this.searchCallback = function(responseObj){
		me._errors = null;
		me._warnings = null;
		me._results = null;
		me._resultsValid = false;
		if(responseObj == "timeout"){
			debug.write("runSearch: search timed out");
			if(me._errorCallback!=null){
				me._errorCallback();
			}
		}if(responseObj.ERROR != null){
			debug.write("search: error occured durring search");
			me.Renderer.renderErrors(responseObj.ERROR.Errors);
			if(me._errorCallback!=null){
				me._errorCallback();
			}
			me._errors = responseObj.ERROR.Errors
		}else if(responseObj.PartOK != null){
			debug.write("search: warnings occured durring search");
			me.Renderer.renderWarnings(responseObj);
			
			me._warnings = responseObj.PartOK.Warnings;
			me._results = responseObj.PartOK;
			me._resultsValid = true;
		}else if(responseObj.OK!= null){
			debug.write("search: search results are OK");
			me.Renderer.renderResults(responseObj.OK.Results);
			
			me._results = responseObj.OK;
			me._resultsValid = true;
		}
		if(me._callback!=null){
			me._callback();
		}else{
			debug.write("search:no callback specified");
		}
	}
	
	this.areSearchResultsValid = function(){
		return this._resultsValid;
	}
	
	this.getSearchResults = function(){
		if(this._resultsValid){
			return this._results;
		}else{
			debug.write("getSearchResults:results are not currently valid");
		}
	}
	
	//Renderer passthrough functions
	this.renderDocument = function(position){
		this.Renderer.renderDocument(this._results, position);
	}
	this.renderField = function(position, field){
		this.Renderer.renderField(this._results, position, field);
	}
	this.getField = function(position, field){
		return this._results.Results[position][field];
	}
	this.getTotalHits = function(){
		return this._results.TotalResults;
	}
	this.getNumResults = function(){
		return this._results.ReturnedResults;
	}
	this.getPosition = function(){
		return this._results.Position;
	}
	
	//get the last search request
	this.getLastSearchRequest = function(){
		return this._search;
	}
	
	//Debug option setters
	this.setDebug = function(value){
		debug.setDebug(value);
	}
	this.getDebug = function(){
		return debug.getDebug();
	}
	
}

//The debug class
function scapiDebug(){
	this._debug = false;
	this.setDebug = function(value){
		this._debug = value;
	}
	this.getDebug = function(){
		return this._debug;
	}
	
	//if debuging is enabled writes the message to the end of the specified div tag
	this.write = function(message){
		if(this.getDebug()){
			var newElement=document.createElement("p");
			var newtext=document.createTextNode(message);
			newElement.appendChild(newtext);
			document.getElementById("scapiDebugArea").appendChild(newElement);
		}
	}
}

//This class handles parsing the response from the server and rendering it into 
//html which is then inserted into the html page.
function scapiListRenderer(){
	//the id of the div tag to replace the contents of
	this._renderLocation = "scapi";
	this._scapiURL = ScapiURL;
	
	this._contentProvidedByString = ""
	
	this._resultsTableStart = "";
	this._resultsTableEnd 	= "";
	
	this._errorTableStart 	= "";
	this._errorTableEnd 	= ""
	
	this._errorRowStart1	= "";
	this._errorRowStart2	= "";
	this._errorRowStart3	= "";
	
	this._documentRowStart1	= "";
	this._documentRowStart2	= "";
	this._documentRowStart3 = "";
	this._documentRowEnd	= "";
	
	this._singlefieldtitle	= "";
	this._singlefieldcited	= "";
	
	this._white				="";
	this._grey				="";
	
	this._titleStart		= "";
    this._titleEnd			= "";
	
	this._errorStart		= "";
	this._errorEnd			= "";
	
	this._title				= "title";

	this._firstAuth			="";
	this._firstAuthName		="";
	
	this._abstract			="abstract";
	this._abstractName		="Abstract";
	
	this._affiliations		="affiliations";
	this._affiliationsName	="Affiliation"
	
	this._doctype			="doctype";
	this._doctypeName		="Document Type";
	
	this._sourcetitle		="sourcetitle";
	this._sourcetitleName	="";

	
	this._issn				="issn";
	this._issnName			="ISSN";
	
	this._vol				="vol";
	this._volName			="Volume";
	
	this._issue				="issue";
	this._issueName			="Issue";
	
	this._page				="page";
	this._pageName			="Pages";
	
	this._pubdate			="pubdate";
	this._pubdateName		="Year";
	
	this._eid				="eid";
	this._eidName			="EID";
    
    this._gett				="<iframe scrolling='no' style='padding:0px !important; margin:0px !important;' frameborder='0' id='ifrm' height='55px' width='100%' src='API.php?scopus=gett&data=";
	this._gettend			="'</iframe>";
	
	this._scp				="scp";
	this._scpName			="Scopus ID";
	
	this._citedbycount		="citedbycount";
	this._citedbycountStart	="";
	this._citedbycountEnd	="";
	
	this._inwardurl			="inwardurl";
	this._inwardurlStart	="<div style=\"visibility:hidden;\">";
	this._inwardurlEnd		="</div>";
	
	this._fieldSeperator	=": ";
	this._fieldStart		="";
	this._fieldEnd			="|";
	
	this._noResults			="<strong class=\"txtRedBold\">Please Wait! We're Working On It </strong>";
	
	//sets a new render location overriding the previous one
	this.setRenderLocation = function(idName){
		if(idName != null && idName != ""){
			this._renderLocation = idName;
		}else{
			debug.write("scapiRenderer.setRenderLocation: no render location specified");
		}
	}
	
	//render any errors 
	this.renderErrors = function(errors){
		var output = this._resultsTableStart;
		var hilight = false;
		
		for (i = 0; i < errors.length; i++){
			if(hilight){
				output+= this._errorRowStart1+this._grey+this._errorRowStart2+this._grey+this._errorRowStart3;
			}else{
				output+= this._errorRowStart1+this._white+this._errorRowStart2+this._white+this._errorRowStart3;
			}
			
			error = errors[i].split("\n");
			
			output += this._errorStart+error[0]+this._errorEnd+this._fieldEnd;
			output += error[1];
			
			output += this._documentRowEnd;
			if(hilight){
				hilight = false;
			}else{
				hilight = true;
			}
		}
		output += this._resultsTableEnd;
		this.writeString(output);
	}
	
	
	this.renderWarnings = function(warnings){
		//render warnings
		var output = "";
		output+= this.getAllRenderedWarningsString(warnings.PartOK.Warnings);
		
		//renderresults
		output += this.getAllRenderedResultsString(warnings.PartOK.Results);
		this.writeString(output);
	}
	
	this.getAllRenderedWarningsString = function(warnings){
		return "";
	}
		
	//render the response
	this.renderResults = function(response){
		var output = this._resultsTableStart;
		output += this.getAllRenderedResultsString(response);
		this.writeString(output);
	}
	
	this.getAllRenderedResultsString = function(results){
		var output = this._resultsTableStart;
		var hilight = false;
		if(results.length >0){
			for( var i in results){
                var datatobe=this.getRenderedResultString(results[i]);
                var randomnumber=i+1;
                output +=this._gett+datatobe.replace(/'/i, "thisisaquote")+this._gettend;
				
			}
output +="<img src='IMG/scopus.png'>";
		}else{
			var randomnumber=Math.floor(Math.random()*100) ;
			output += "<div style='text-align:center;text-decoration:none;font-size:12px; font-family:arial,helvetica,sans-serif;color:#0950A0'>"+this._documentRowStart2+this._white+this._documentRowStart3;
			output += this._noResults;
			output += this._documentRowEnd;
			output += "</div>";
		}
		output += this._resultsTableEnd;
		return output;
	}
	
	this.renderDocument = function(response, position){
		var output = this._resultsTableStart;
		output += this.getRenderedResultString(response.Results[position], false);
		output += this._resultsTableEnd;
		this.writeString(output);
	}
	
	this.renderField = function(response, position, field){
		output = this.getRenderedFieldString(field, response.Results[position][field], true);
		this.writeString(output);
	}
	
	this.getRenderedResultString = function(result, hilight){
		output = "";
		if(hilight){
			output+= this._documentRowStart1+this._grey+this._documentRowStart2+this._grey+this._documentRowStart3;
		}else{
			output+= this._documentRowStart1+this._white+this._documentRowStart2+this._white+this._documentRowStart3;
		}
			for(var i in result){
				output += this.getRenderedFieldString(i, result[i], false);
			}
		output += this._documentRowEnd;
		return output;
	}
	
	this.getRenderedFieldString = function(field, string, single){
		output = "";
		if(field == this._title){
			if(single){
			
            	output += this._titleStart+string+this._singlefieldtitle+this._titleEnd;
			}else{
				output += this._titleStart+string+this._titleEnd;
			}
		}else if( field == this._citedbycount){
			if(single){
				output += this._citedbycountStart+string+this._citedbycountEnd;
			}else{
				output += this._citedbycountStart+string+this._citedbycountEnd;
			}
            }else if( field == this._issn){
			output += string;
		}else if( field == this._vol){
			output += string;
		}else if( field == this._issue){
			output += string;
		}else if( field == this._page){
			output += string;		
		}
		return output+this._fieldEnd;
	}
	
	this.writeString = function(output){
		document.getElementById(this._renderLocation).innerHTML = output;
	}
}

//This class handles building and submitting the search request to the server as well as
//the callback response from the server.
function scapiBackend(){
	this._busy = false;
	this._scapiCallback = null;
	
	this._reqCounter = 0;
	this._requests = {};
	
	//Request static vars (should be config vars in a perfect world)
	this._scapiURL = "API.php?scopus=get&url=";
	this._timeoutVal = ScapiTimeout;
	
	//request field names
	this._preventCache = "preventCache";
	this._devID = "devId";
	this._search = "search";
	this._sort = "sort";
	this._sortDirection = "sortDirection";
	this._fields = "fields";
	this._numResults = "numResults";
	this._content = "content";
	this._offset = "offset";
	this._callback = "callback";

	//useful callback strings
	this._callbackStringStart = "scapi.Backend._requests.";
	this._callbackStringEnd = ".callback";
	
	//useful url chars
	this._equals = "=";
	this._connector = "&";
	this._post = "?";
	
	//functions calling this method need to provide a callback method which is
	//in the form function(response).  This is due to the fact that this is an 
	//asyncronus library so when control is returned, processing is not done.
	//When the search is complete submitSearch will call the callback function.
	this.submitSearch = function(searchObj, developerID, callback){
		if(this._busy == true){
			debug.write("Search already in flight...ignoring search request");
			return;
		}else{
			//set busy to true
			this._busy = true;
			
			debug.write("Search submitted: query="+searchObj.getSearch());
			this._scapiCallback = callback;
			
			var searchRequestURL = this._post;
			
			//add in browser cacheing prevention.  This is used to change the generated URL
			//slightly each time to prevent the browser from caching a response to identical searches.
			//That's bad because if it happens the browser won't "run" the response.
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._preventCache,this.randomString());
			
			//add in developerID
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._devID,developerID);
			
			//add in the search
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._search,searchObj.getSearch());
			
			//add in the sort
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._sort,searchObj.getSort());


			//add in the sortDirection
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._sortDirection,searchObj.getSortDirection());

			//add in the fields
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._fields,searchObj.getFields());
			
			//add in the numResults
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._numResults,searchObj.getNumResults());

			//add in the content
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._content,searchObj.getContent());
			
			//add in the offset
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._offset,searchObj.getOffset());
			
			//build the callback string
			var searchID = "search"+this._reqCounter++;
			var searchObjectString = this._callbackStringStart+searchID;
			var callbackString = this._callbackStringStart+searchID+this._callbackStringEnd;
			//add in callback
			searchRequestURL = this.appendVarToURL(searchRequestURL,this._callback,callbackString);
			
			//create a new inflight object
			flight = new inflight(searchID);
			//and add it to the requests array
			this._requests[searchID] = flight;
			
			//make the async call
			this.addRequestToHeader(searchRequestURL);
			//setup a timeout in case bad things happen
			setTimeout('scapi.Backend.timeout('+searchObjectString+')', this._timeoutVal);
		}
	}
	
	//if the value is not null this appends a field and value to an URL 
	//and returns it.  Otherwise it just returns the URL
	this.appendVarToURL = function(url, field, value){
		if(value != null && value != ""){
			url += this._connector+field+this._equals+value;
			return url;
		}else{
			return url;
		}
	}
	
	//Adds an URL to the header of an HTML document in a javascript tag
	//The purpose here is to cause the browser to load the new URL asyncronusly
	this.addRequestToHeader = function(searchURL){
		var head = document.getElementsByTagName("head")[0];
 		script = document.createElement('script');
 		script.id = 'scapiSearch';
 		script.type = 'text/javascript';
 		script.src = 'API.php?scopus=get&url='+searchURL;
 		head.appendChild(script);
	}
	
	//Creates a random string that is 20 chars long.
	this.randomString = function() {
		var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		var string_length = 20;
		var randomstring = '';
		for (var i=0; i<string_length; i++) {
			var rnum = Math.floor(Math.random() * chars.length);
			randomstring += chars.substring(rnum,rnum+1);
		}
		return randomstring;
	}
	
	//This method is called by the inflight object when the response is returned.  At
	//that time it will handle reseting the state of the backend to idle, and the state 
	//of the request to complete, and call the callback function.
	this.callback = function(search, response){
		debug.write("Results recieved by callback...");
		if(search.inflight == false){
			debug.write("...Javascript just recieved a response for a search that had timed out.");
		}else{
			search.inflight = false;
			debug.write("...looking good");
			
			
			this._busy = false;
			this._scapiCallback(response);
		}
		
	}
	
	//This method is called when the timer for a search runs down.  If the search is still active
	//at that time it resets the state of the backend to idle, marks the request as complete(timedout)
	this.timeout = function(search){
		debug.write("Checking for timedout search...");
		if(search.inflight == true){
			debug.write("...Search was timed out");
			search.inflight = false;
			this._busy = false;
			this._scapiCallback("timeout");
		}else{
			debug.write("...search had already compleated");
		}
		//timeout code
	}
}

//This class represents any request that has been submitted to the server
//and contains an id, a status, and a callback function that is called by the 
//response from the server
function inflight(id){
	this.searchID = id;
	this.inflight = true;
	this.callback = function(response){
		scapi.Backend.callback(this,response);
	}
}

//This class is effectivly a bean, and represents all of the fields that a 
//user can specify in a search 
function searchObj(){
	this._search = null;
	this._sort = null;
	this._sortDirection = null;
	this._fields = null;
	this._numResults = null;
	this._content = null;
	this._offset = null;
	
	//search
	this.setSearch = function(search){
		this._search = search;
	}
	this.getSearch = function(){
		return this._search;
	}
	
	//sort
	this.setSort = function(sort){
		this._sort = sort;
	}
	this.getSort = function(){
		return this._sort;
	}
	
	//sortDirection
	this.setSortDirection = function(sortDirection){
		this._sortDirection = sortDirection;
	}
	this.getSortDirection = function(){
		return this._sortDirection;
	}
	
	//fields
	this.setFields = function(fields){
		this._fields = fields;
	}
	this.getFields = function(){
		return this._fields;
	}
	
	//numResults
	this.setNumResults = function(numResults){
		this._numResults = numResults;
	}
	this.getNumResults = function(){
		return this._numResults;
	}
	
	//content
	this.setContent = function(content){
		this._content = content;
	}
	this.getContent = function(){
		return this._content;
	}
	
	//offset
	this.setOffset = function(offset){
		this._offset = offset;
	}
	this.getOffset = function(){
		return this._offset;
	}
}


var COLLAPSABLE_PARENT_NAME = "collapsable";
var COLLAPSABLE_PARENT_TYPE = "div";
var COLLAPSABLE_CHILD_TYPE = "p";

var COLLAPSABLE_EXPAND = "<b>Description</b> <img src='IMG/down.gif'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
var COLLAPSABLE_SHRINK = "<b>Description</b> <img src='IMG/up.gif'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

init = function() {
    if(document.getElementById && document.createTextNode) {
        var entries = document.getElementsByTagName(COLLAPSABLE_PARENT_TYPE);
        for(i=0;i<entries.length;i++)
            if (entries[i].className==COLLAPSABLE_PARENT_NAME)
                assignCollapse(entries[i]);
    }
}

assignCollapse = function (div) {
    var button = document.createElement('a');
    button.setAttribute('class', 'tabelborder');
    button.setAttribute('width', '100%');
    button.style.cursor='pointer';
    button.setAttribute('expand', COLLAPSABLE_EXPAND);
    button.setAttribute('shrink', COLLAPSABLE_SHRINK);
    button.setAttribute('state', -1);
    button.innerHTML='dsds';
    div.insertBefore(button, div.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0]);

    button.onclick=function(){
        var state = -(1*this.getAttribute('state'));
        this.setAttribute('state', state);
        this.parentNode.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0].style.display=state==1?'none':'block';
        this.innerHTML = this.getAttribute(state==1?'expand':'shrink');
    };                   
    button.onclick();
}


window.onload=init;
//** Animated Collapsible DIV v2.0- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//** May 24th, 08'- Script rewritten and updated to 2.0.
//** June 4th, 08'- Version 2.01: Bug fix to work with jquery 1.2.6 (which changed the way attr() behaves).
//** March 5th, 09'- Version 2.2, which adds the following:
			//1) ontoggle($, divobj, state) event that fires each time a DIV is expanded/collapsed, including when the page 1st loads
			//2) Ability to expand a DIV via a URL parameter string, ie: index.htm?expanddiv=jason or index.htm?expanddiv=jason,kelly

//** March 9th, 09'- Version 2.2.1: Optimized ontoggle event handler slightly.
//** July 3rd, 09'- Version 2.4, which adds the following:
			//1) You can now insert rel="expand[divid] | collapse[divid] | toggle[divid]" inside arbitrary links to act as DIV togglers
			//2) For image toggler links, you can insert the attributes "data-openimage" and "data-closedimage" to update its image based on the DIV state

var animatedcollapse={
divholders: {}, //structure: {div.id, div.attrs, div.$divref, div.$togglerimage}
divgroups: {}, //structure: {groupname.count, groupname.lastactivedivid}
lastactiveingroup: {}, //structure: {lastactivediv.id}
preloadimages: [],

show:function(divids){ //public method
	if (typeof divids=="object"){
		for (var i=0; i<divids.length; i++)
			this.showhide(divids[i], "show")
	}
	else
		this.showhide(divids, "show")
},

hide:function(divids){ //public method
	if (typeof divids=="object"){
		for (var i=0; i<divids.length; i++)
			this.showhide(divids[i], "hide")
	}
	else
		this.showhide(divids, "hide")
},

toggle:function(divid){ //public method
	if (typeof divid=="object")
		divid=divid[0]
	this.showhide(divid, "toggle")
},

addDiv:function(divid, attrstring){ //public function
	this.divholders[divid]=({id: divid, $divref: null, attrs: attrstring})
	this.divholders[divid].getAttr=function(name){ //assign getAttr() function to each divholder object
		var attr=new RegExp(name+"=([^,]+)", "i") //get name/value config pair (ie: width=400px,)
		return (attr.test(this.attrs) && parseInt(RegExp.$1)!=0)? RegExp.$1 : null //return value portion (string), or 0 (false) if none found
	}
	this.currentid=divid //keep track of current div object being manipulated (in the event of chaining)
	return this
},

showhide:function(divid, action){
	var $divref=this.divholders[divid].$divref //reference collapsible DIV
	if (this.divholders[divid] && $divref.length==1){ //if DIV exists
		var targetgroup=this.divgroups[$divref.attr('groupname')] //find out which group DIV belongs to (if any)
		if ($divref.attr('groupname') && targetgroup.count>1 && (action=="show" || action=="toggle" && $divref.css('display')=='none')){ //If current DIV belongs to a group
			if (targetgroup.lastactivedivid && targetgroup.lastactivedivid!=divid) //if last active DIV is set
				this.slideengine(targetgroup.lastactivedivid, 'hide') //hide last active DIV within group first
				this.slideengine(divid, 'show')
			targetgroup.lastactivedivid=divid //remember last active DIV
		}
		else{
			this.slideengine(divid, action)
		}
	}
},

slideengine:function(divid, action){
	var $divref=this.divholders[divid].$divref
	var $togglerimage=this.divholders[divid].$togglerimage
	if (this.divholders[divid] && $divref.length==1){ //if this DIV exists
		var animateSetting={height: action}
		if ($divref.attr('fade'))
			animateSetting.opacity=action
		$divref.animate(animateSetting, $divref.attr('speed')? parseInt($divref.attr('speed')) : 500, function(){
			if ($togglerimage){
				$togglerimage.attr('src', ($divref.css('display')=="none")? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open)
			}
			if (animatedcollapse.ontoggle){
				try{
					animatedcollapse.ontoggle(jQuery, $divref.get(0), $divref.css('display'))
				}
				catch(e){
					alert("An error exists inside your \"ontoggle\" function:\n\n"+e+"\n\nAborting execution of function.")
				}
			}
		})
		return false
	}
},

generatemap:function(){
	var map={}
	for (var i=0; i<arguments.length; i++){
		if (arguments[i][1]!=null){ //do not generate name/value pair if value is null
			map[arguments[i][0]]=arguments[i][1]
		}
	}
	return map
},

init:function(){
	var ac=this
	jQuery(document).ready(function($){
		animatedcollapse.ontoggle=animatedcollapse.ontoggle || null
		var urlparamopenids=animatedcollapse.urlparamselect() //Get div ids that should be expanded based on the url (['div1','div2',etc])
		var persistopenids=ac.getCookie('acopendivids') //Get list of div ids that should be expanded due to persistence ('div1,div2,etc')
		var groupswithpersist=ac.getCookie('acgroupswithpersist') //Get list of group names that have 1 or more divs with "persist" attribute defined
		if (persistopenids!=null) //if cookie isn't null (is null if first time page loads, and cookie hasnt been set yet)
			persistopenids=(persistopenids=='nada')? [] : persistopenids.split(',') //if no divs are persisted, set to empty array, else, array of div ids
		groupswithpersist=(groupswithpersist==null || groupswithpersist=='nada')? [] : groupswithpersist.split(',') //Get list of groups with divs that are persisted
		jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object
			this.$divref=$('#'+this.id)
			if ((this.getAttr('persist') || jQuery.inArray(this.getAttr('group'), groupswithpersist)!=-1) && persistopenids!=null){ //if this div carries a user "persist" setting, or belong to a group with at least one div that does
				var cssdisplay=(jQuery.inArray(this.id, persistopenids)!=-1)? 'block' : 'none'
			}
			else{
				var cssdisplay=this.getAttr('hide')? 'none' : null
			}
			if (urlparamopenids[0]=="all" || jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains the single array element "all", or this div's ID
				cssdisplay='block' //set div to "block", overriding any other setting
			}
			else if (urlparamopenids[0]=="none"){
				cssdisplay='none' //set div to "none", overriding any other setting
			}
			this.$divref.css(ac.generatemap(['height', this.getAttr('height')], ['display', cssdisplay]))
			this.$divref.attr(ac.generatemap(['groupname', this.getAttr('group')], ['fade', this.getAttr('fade')], ['speed', this.getAttr('speed')]))
			if (this.getAttr('group')){ //if this DIV has the "group" attr defined
				var targetgroup=ac.divgroups[this.getAttr('group')] || (ac.divgroups[this.getAttr('group')]={}) //Get settings for this group, or if it no settings exist yet, create blank object to store them in
				targetgroup.count=(targetgroup.count||0)+1 //count # of DIVs within this group
				if (jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains this div's ID
					targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded). Overrides other settings
					targetgroup.overridepersist=1 //Indicate to override persisted div that would have been expanded
				}
				if (!targetgroup.lastactivedivid && this.$divref.css('display')!='none' || cssdisplay=="block" && typeof targetgroup.overridepersist=="undefined") //if this DIV was open by default or should be open due to persistence								
					targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded)
				this.$divref.css({display:'none'}) //hide any DIV that's part of said group for now
			}
		}) //end divholders.each
		jQuery.each(ac.divgroups, function(){ //loop through each group
			if (this.lastactivedivid && urlparamopenids[0]!="none") //show last "active" DIV within each group (one that should be expanded), unless url param="none"
				ac.divholders[this.lastactivedivid].$divref.show()
		})
		if (animatedcollapse.ontoggle){
			jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object and fire ontoggle event
				animatedcollapse.ontoggle(jQuery, this.$divref.get(0), this.$divref.css('display'))
			})
		}
 		//Parse page for links containing rel attribute
		var $allcontrols=$('a[rel]').filter('[rel^="collapse["], [rel^="expand["], [rel^="toggle["]') //get all elements on page with rel="collapse[]", "expand[]" and "toggle[]"
		$allcontrols.each(function(){ //loop though each control link
			this._divids=this.getAttribute('rel').replace(/(^\w+)|(\s+)/g, "").replace(/[\[\]']/g, "") //cache value 'div1,div2,etc' within identifier[div1,div2,etc]
			if (this.getElementsByTagName('img').length==1 && ac.divholders[this._divids]){ //if control is an image link that toggles a single DIV (must be one to one to update status image)
				animatedcollapse.preloadimage(this.getAttribute('data-openimage'), this.getAttribute('data-closedimage')) //preload control images (if defined)
				$togglerimage=$(this).find('img').eq(0).data('srcs', {open:this.getAttribute('data-openimage'), closed:this.getAttribute('data-closedimage')}) //remember open and closed images' paths
				ac.divholders[this._divids].$togglerimage=$(this).find('img').eq(0) //save reference to toggler image (to be updated inside slideengine()
				ac.divholders[this._divids].$togglerimage.attr('src', (ac.divholders[this._divids].$divref.css('display')=="none")? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open)
			}
			$(this).click(function(){ //assign click behavior to each control link
				var relattr=this.getAttribute('rel')
				var divids=(this._divids=="")? [] : this._divids.split(',') //convert 'div1,div2,etc' to array 
				if (divids.length>0){
					animatedcollapse[/expand/i.test(relattr)? 'show' : /collapse/i.test(relattr)? 'hide' : 'toggle'](divids) //call corresponding public function
					return false
				}
			}) //end control.click
		})// end control.each

		$(window).bind('unload', function(){
			ac.uninit()
		})
	}) //end doc.ready()
},

uninit:function(){
	var opendivids='', groupswithpersist=''
	jQuery.each(this.divholders, function(){
		if (this.$divref.css('display')!='none'){
			opendivids+=this.id+',' //store ids of DIVs that are expanded when page unloads: 'div1,div2,etc'
		}
		if (this.getAttr('group') && this.getAttr('persist'))
			groupswithpersist+=this.getAttr('group')+',' //store groups with which at least one DIV has persistance enabled: 'group1,group2,etc'
	})
	opendivids=(opendivids=='')? 'nada' : opendivids.replace(/,$/, '')
	groupswithpersist=(groupswithpersist=='')? 'nada' : groupswithpersist.replace(/,$/, '')
	this.setCookie('acopendivids', opendivids)
	this.setCookie('acgroupswithpersist', groupswithpersist)
},

getCookie:function(Name){ 
	var re=new RegExp(Name+"=[^;]*", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
},

setCookie:function(name, value, days){
	if (typeof days!="undefined"){ //if set persistent cookie
		var expireDate = new Date()
		expireDate.setDate(expireDate.getDate()+days)
		document.cookie = name+"="+value+"; path=/; expires="+expireDate.toGMTString()
	}
	else //else if this is a session only cookie
		document.cookie = name+"="+value+"; path=/"
},

urlparamselect:function(){
	window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=divid or divid1,divid2,etc
	return (RegExp.$1!="")? RegExp.$1.split(",") : []
},

preloadimage:function(){
	var preloadimages=this.preloadimages
	for (var i=0; i<arguments.length; i++){
		if (arguments[i] && arguments[i].length>0){
			preloadimages[preloadimages.length]=new Image()
			preloadimages[preloadimages.length-1].src=arguments[i]
		}
	}
}

}
var intTextBox=1;

//FUNCTION TO ADD TEXT BOX ELEMENT
function addElement()
{
intTextBox = intTextBox + 1;
var contentID = document.getElementById("content");
var newTBDiv = "<tr><td class=\"newsheading1\"><label for=\"14\">Author "+intTextBox+"'s Name:</label></td><td height=\"46\" class=\"field\"><input style=\"width:345px\" name=\"13[]\" type=\"text\" class=\"validate[required,length[0,100]] text-input\" id=\"13[]\" value=\"\" maxlength=\"40000\"/></td></tr><tr><td class=\"newsheading1\"><label for=\"14\">Author "+intTextBox+"'s E-Mail:</label></td><td height=\"46\" class=\"field\"><input style=\"width:345px\" name=\"13[]\" type=\"text\" class=\"validate[required,length[0,100]] text-input\" id=\"13[]\" value=\"\" maxlength=\"40000\"/></td></tr><tr><td class=\"newsheading1\"><label for=\"14\">Author "+intTextBox+"'s Affiliation:</label></td><td height=\"46\" class=\"field\"><input style=\"width:345px\" name=\"13[]\" type=\"text\" class=\"validate[required,length[0,100]] text-input\" id=\"13[]\" value=\"\" maxlength=\"40000\"/></td></tr>";
contentID.appendChild(newTBDiv);
}

//FUNCTION TO REMOVE TEXT BOX ELEMENT
function removeElement()
{
if(intTextBox != 0)
{
var contentID = document.getElementById("content");
contentID.removeChild(document.getElementById("strText"+intTextBox));
intTextBox = intTextBox-1;
}
}
