﻿
/*
This file created by Michael Taylor - 2007-07-01

- AttrSet() is used to set an attribute value for any page element that contains an ID attribute.
- It will work on dynamic IDs set by the .NET runat="server" server-side attribute.

Arguments:

	strTag (optional if the full ID is supplied):
		This is the the tag name of the element.
		It is used only if the supplied strIdPart argument doesn't match the ID of a page element.

	strIdPart (required):
		This is the ID or part of the ID of the element.
		If the full ID of a page element is supplied, the strTag argument is not used and can be set to null.
	
	strAttr (required):
		This is the attribute name to search for within the given strTag/strIdPart.
	
	strVal (required):
		This is the value to set for the supplied strAttr of the strTag/strIdPart.
		If the tag/ID is found, the strAttr will be set to this value.
	
	blnDoOnce (required):
		This is a boolean value that tells the function whether to set the attribute value for 
		all elements matching the strTag/strIdPart or to stop setting the value after the first
		occurence.
	
	Examples:
		AttrSet('div', 'Menu_Home', 'style.left', '20px', true); // this will set the left position of this menu item.
		AttrSet('div', 'Menu_', 'style.top', '20px', false); // this will set the top position for all elements whose ID starts with Menu_.

It has been tested on and is compatible with:
	Microsoft Internet Explorer 6 and up
	Mozilla Firefox 2 and up

For inquiries or comments, visit www.genxml.com
*/

function AttrSet(strTag, strIdPart, strAttr, strVal, blnDoOnce) {
	if(blnDoOnce == null) blnDoOnce = true;
	if(document.getElementById(strIdPart) != null) { // then the full ID has been supplied
		eval('document.getElementById(strIdPart).' + strAttr + ' = ""');
		eval('document.getElementById(strIdPart).' + strAttr + ' = strVal');
	}
	else {
		var colTags = document.getElementsByTagName(strTag);
		if(typeof(colTags) != 'undefined') {
			for(var intX = 0; intX < colTags.length; intX++) {
				if(colTags[intX].id.indexOf(strIdPart) != -1) {
					eval('colTags[intX].' + strAttr + ' = ""');
					eval('colTags[intX].' + strAttr + ' = "' + strVal + '";');
					if(blnDoOnce) intX = colTags.length;
				}
			}
		}
	}
}

