function createNamedElement(doc, type, name) {
   var element = null;
   // Try the IE way; this fails on standards-compliant browsers
   try {
      element = doc.createElement('<'+type+' name="'+name+'">');
   } catch (e) {
   }
   if (!element || element.nodeName != type.toUpperCase()) {
      // Non-IE browser; use canonical method to create named element
      element = doc.createElement(type);
      element.name = name;
   }
   return element;
}

function trim(text) {
    return text.replace(/(^\s*)|(\s*$)/g, '');
}

function countWords(str) {
    var count = 0;
    var treatment = "";
    treatment = str.replace(/\s/g, " ");
    treatment = treatment.split(" ");
    for (var index = 0; index < treatment.length; index = index + 1) {
        if (treatment[index].length > 0) {
            count = count + 1;
        }
    }
    return count;
}

function delimparser(text) {
    var result = new Array ();
    var token = "";
    var j = 0;
    for (i = 0; i < text.length; i++) {
        c = text.charAt(i);
        if (c == ';') {
            result.push(token);
            token = "";
        }
        else if (c == '\\') {
            token += text.charAt(++i);
        } else
            token += c;
    }
    return result;
}

function delimmake(array) {
    var s = "";
    for (var i = 0; i < array.length; i++) {
        var si = array[i];
        si = si.replace("\\", "\\\\")
        si = si.replace(";", "\\;");
        s += si + ';';
    }
    return s;
}

function addPageLoadListener(fn){
	/* Code for Mozilla-Gecko w3c Standards */
	if(typeof window.addEventListener != 'undefined'){
		window.addEventListener('load', fn, false);
	}
	/* Code For compatibility with Opera */
	else if(typeof document.addEventListener != 'undefined'){
		document.addEventListener('load', fn, false);
	}
	/* Code for IE */
	else if(window.attachEvent('onload') != 'function'){
		window.attachEvent('onload', fn);
	}
	/* Code for IE 5 Mac */
	else{
		var oldFn = window.onload;
		if(typeof window.onload != 'function'){
			window.onload=fn;
		}
		else{
			window.onload=function(){
				oldFn();
				fn();
			};
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function imgHover(obj, img) {
    obj.src = obj.src.substring(0, obj.src.lastIndexOf("_")) + "_hover.gif";
}

function imgNormal(obj, img) {
    obj.src = obj.src.substring(0, obj.src.lastIndexOf("_")) + "_normal.gif";
}

function imgPressed(obj, img) {
    obj.src = obj.src.substring(0, obj.src.lastIndexOf("_")) + "_pressed.gif";
}

