var isW3C = (document.getElementById) ? true : false
var isAll = (document.all) ? true : false

/** 
 * Responsible for confirming the existence of an object
 * which is passed in by name.
 *
 * For example, a span area is defined in the HTML with 
 * an id of optionsEquipCost.  To confirm its existence, do:
 *
 *     if (objectExists('optionsEquipCost')) { // do work }
 *
 * This must be called AFTER the declaration of the object
 * in the HTML (or after the HTML has loaded).  Otherwise,
 * the return value may be false.
 */
function objectExists(elemID) {
    var elem = (isW3C) ? document.getElementById(elemID) : ((isAll) ? document.all[elemID] : null);
    if (elem) {
        return true;
    } else {
        return false;
    }
}

/** 
 * Responsible for confirming the existence of a function
 * which is passed in by name.
 *
 * For example, a function is defined in the HTML with 
 * the name of doPersonalInfoOnLoad().
 * To confirm its existence, do:
 *
 *     if (functionExists('doPersonalInfoOnLoad')) { // do work }
 */
function functionExists(elemID) {
    return (typeof(window[elemID])!='undefined');
}

/*	
	Release 5.2.6
	Sachin K Mantur

	This is a function to trim the email id:

	If the length  of email id is more than 23 characters,
	it will trim it to the 2nd line

	If the length of the email id is more than 46 characters,
	it will trim it into 3 lines
*/
function trimEmail() {	

	var emailField = new String();
	var var1 = new String();
	var var2 = new String();
	var var3 = new String();        
    
	/*
		get all div tags with class name "email"
	 */
	var elementTags = getElementsByClassName("email","div");
	
	if (null != elementTags) {
		
		for(var i = 0;i < elementTags.length; i++){

            emailField = elementTags[i].innerHTML;

		
			if (emailField.length > 46) {
				
				var1 = emailField.substring(0,23);
				var2 = emailField.substring(23,46);
				var3 = emailField.substring(46);

				elementTags[i].innerHTML = var1+"<br/>"+var2+"<br/>"+var3;
			}
			else if (emailField.length > 23) {
					
				var1 = emailField.substring(0,23);
				var2 = emailField.substring(23);

				elementTags[i].innerHTML = var1+"<br/>"+var2;
			}
		}
	}
}

/*
	Release 5.2.6
	This javascript is dowloaded from net to extract elements by class name.

	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/	
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
		elm = elm || document;
		var elements = elm.getElementsByClassName(className),
		nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
		returnElements = [],
		current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
		return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
			classesToCheck = "",
			xhtmlNamespace = "http://www.w3.org/1999/xhtml",
			namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
			returnElements = [],
			elements,
			node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
			classesToCheck = [],
			elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
			current,
			returnElements = [],
			match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};