/**
 *  @package yahoo.search.answers
 *	@author  walter punsapy
 **/
/*
 *  @description SpellChecker Library
 				 - SpellController namespace
 				 - Speller object
 *  @requires YAHOO.util.Event
 *  @requires ygConn
 *
 */

/******************************************************************************/

/*  @requires SpellController
 *  @description Speller manages the spell check features, using utilities from 
 *               SpellController for help
 *
 */



/* Util object that we use to do stuff
 ***************************************************** */ 

function KS_Util(pId,pBrowserObj,pIsDebug,pKid,pKNickname,pURL,pIsViewingSelf){
    this.id=pId;
    this.kid=(!this.isNull(pKid)) ? pKid : null;
    this.nick=(!this.isNull(pKNickname)) ? pKNickname : null;
    this.ua=(!this.isNull(pBrowserObj)) ? pBrowserObj : new yg_Browser();
    this.REQUEST_URI = pURL;
    this.DATATYPE_OBJECT="object";
    this.OFFSET_BODY_HEIGHT=100;
    this.EXCEPTION_STRING="EXCEPTION";
    this.isViewingSelf = pIsViewingSelf||false;
    
    this.IS_JAVASCRIPT_DEBUG=pIsDebug||false;
    this.DEBUG_CONSOLE='y-ks-error-log';
    this.DISPLAY_WIDGET_STAR='<img src="http://l.yimg.com/a/i/us/sch/gr/pointsstar.gif" border="0" alt="star"/>';
    this.DISPLAY_WIDGET_ALERT='http://l.yimg.com/a/i/us/sch/gr/alrt12_1.gif';
    this.DISPLAY_WIDGET_1= 'y-ks-header-user-profile-widget-msg-1';
    this.DISPLAY_WIDGET_2= 'y-ks-header-user-profile-widget-msg-2';
    this.current_widget_display=this.DISPLAY_WIDGET_1;
    this.DISPLAY_WIDGET_NOTIFICATION_STATES=new Array(
        '',
'You get 100 points to start',
'Thanks for visiting! (1 point)',
'You asked a question (-5 points)',
'Asking a question anonymously',
'Neglecting my question',
'You chose a best answer (3 points)',
'You answered a question (2 points)',
'Deleted an answer',
'Your answer was picked as best! (10 points)',
'You voted for a best answer (1 point)',
'You rated a best answer (1 point)',
'Evaluated with excellence!',
'Honorable contribution',
'A violation in a question',
'A violation in an answer',
'A violation in a comment',
'A best answer is considered a violation',
'Points removed',
'Thumbs-up for your best answer! (1 point)',
'You chose to call a vote',
'Maximum awards for answer evaluated as positive',
'Number of events to keep in history per user',
'',
'Your question had no best answer (5 points)',
'',
'',
'',
'',
'',
'Answer restored',
'',
'Question restored',
'Appeal rejected'
    );
}
KS_Util.prototype.getKid = function() {
	return this.kid;	
}
KS_Util.prototype.getRequestParameter =function(parameterName) {
	var queryString = window.top.location.search.substring(1)
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		// Find the beginning of the string
		var begin = queryString.indexOf ( parameterName );
		var end;
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			// Return the string
			return unescape(queryString.substring(begin,end));
		}
		// Return "null" if no parameter has been found
		return null;
	}
}

KS_Util.prototype.getIsViewingSelf = function() {
	return this.isViewingSelf;	
}

KS_Util.prototype.setIsViewingSelf = function(pBool) {
	this.isViewingSelf = pBool;	
}

KS_Util.prototype.highlightWords = function(pStr,pResponseText) {
    this.highlight_tag = "strong";
    var tmpStr = String.trim(pStr);
    var tmpArr = tmpStr.split(' ');
    if (tmpArr.length > 0) {
        for (var ii=0; ii< tmpArr.length; ii++) {
            var p = new RegExp (tmpArr[ii],'ig');
            pResponseText = pResponseText.replace(p,"<" + this.highlight_tag + ">"+tmpArr[ii]+"</" + this.highlight_tag + ">");
        }
    }
    return pResponseText;
}


/**
 *  @returns boolean
 *  @description returns whether the string has 'n' words, delimiting by space
 */
KS_Util.prototype.isNthWord = function(pStr) {
    var tmpStr = String.trim(pStr);
    if (tmpStr.length > 0) {
        var tmpArr = tmpStr.split(' ');
        if ((tmpArr.length > (NTH_WORD_INDEX - 1)) && "" != tmpArr[NTH_WORD_INDEX - 1]) return true;
    }
    return false;
}

KS_Util.prototype.isNull=function(pEle){
    return (null==pEle || "undefined"==pEle || ""==pEle);
}

 /**
  * @function gObj - returns a reference to an element
  * @param pObj - string or object
  * @returns - reference to the document node or NULL
  */  
KS_Util.prototype.gObj=function(pObj){
    var tmp=null;
    if (document.getElementById) {
        tmp = (typeof pObj==this.DATATYPE_OBJECT) ? pObj : document.getElementById(pObj);
    }
    else if (document.all) {
        tmp = (typeof pObj==this.DATATYPE_OBJECT) ? pObj : document.all[pObj];
    }
    if (!this.isNull(tmp)) {
        return tmp;
    }
    return null;
}

KS_Util.prototype.setDocumentTitle=function(pStr) {
    var tmpTitle=document.title;
    document.title = tmpTitle + " - " + pStr;
}

KS_Util.prototype.debug=function(pStr,pLevel) {
    //if (this.IS_JAVASCRIPT_DEBUG && "string" == typeof pStr) {
    	/*
        var d = this.gObj(this.DEBUG_CONSOLE);
        var parent_function = arguments.caller;
        var current_function = arguments.callee;
        if (pStr.indexOf(this.EXCEPTION_STRING) != -1) pStr = "<span style=\"background-color:red;color:#fff;\">" + pStr + "</span>";
        if (null!=d) {
            var tmpStr = d.innerHTML;
            d.innerHTML = tmpStr + ((tmpStr.length > 5) ? "<br/>" : "") + "&gt; " + pStr;
        }
        */
        if (null==pLevel || ""==pLevel || !typeof pLevel=="string") pLevel = "info";
        try {
	        YAHOO.log(pStr,pLevel);
    	}
    	catch(e) {
    		//alert("error: " + e.message);
    	}
    //}
}

KS_Util.prototype.writeWidgetMessage=function(pPt) {
	var s="";
	if (pPt < 0) s +='<span style="">Alert</span>';
	else if (pPt == 0) s +='<span style="">Alert</span>';
	else if (pPt > 0) s +='<span style="color:#52be0a">Thanks!</span>';
	else s +='<span style="">Alert</span>';
	return s;
}


KS_Util.prototype.doAggregateIncentiveEvents=function(pIncentiveArray) { 
	var _ele = this.gObj(this.current_widget_display);
	if (null == _ele || ""==_ele || "undefined"==_ele) return;
    var incentiveArray = pIncentiveArray;
    var c_events = incentiveArray.length;
    var s='';
    var isDisplayed = true;
    var hasNoSystemEvents = false;
    if (c_events <= 0) {
        /*
        if (!this.isNull(this.kid)) {
            hasNoSystemEvents = true;        
            var random = Math.floor(Math.random() * 10);
            Util.debug("random number: " + random);
            if (random == 3 && null != this.nick) {
                s += '<span class="alert">Hi <a href="/my/my">' + this.nick + '</a>! Check your <a href="/my/my?link=question&more=y">questions</a> for a best answer</span>';
            }
            else {
                isDisplayed = false;
            }
        }
        */
    }
    else {
        // begin parsing system events
       	s += '<table style="height:50px;" cellpadding="0" cellspacing="0" border="0"><tr>';
        // for EVENT #23, tell em this message
        if (parseInt(incentiveArray[0].getOid()) == 23) {
			s += '<td style="width:60px; height:50px; vertical-align:middle; text-align:center;"><img src="http://l.yimg.com/a/i/us/sch/gr2/medal.gif" vspace="12" style="border:none;" alt="award medal" /></td>';
        	// alert user of questions that need attn
            var tmpUrl = "/my/my?link=question&more=y";
            s += '<td style="height:50px; vertical-align:middle; text-align:center;"><span class="new"><strong>Some of <a href="' + tmpUrl + '">your questions</a> need attention!</strong></span></td>';
        }
        else {
	       	s += '<td style="width:60px; height:50px; vertical-align:middle; text-align:center;"><img src="http://l.yimg.com/a/i/us/sch/gr2/medal.gif" vspace="12" style="border:none;" alt="award medal" /></td>';
    		
            if (1 == c_events) {
            	var obj = incentiveArray[0];
	            s += '<td style="height:50px; vertical-align:middle;"><strong style="margin-top:12px; font-size:115%;">'+this.writeWidgetMessage(parseInt(obj.getPoints()))+'</strong><br/>';
                //s += 'You\'ve earned '+ obj.getPoints() +' point'+( (parseInt(obj.getPoints()) > 0) ? "s" : "") +' for ';
                var msgStr = this.DISPLAY_WIDGET_NOTIFICATION_STATES[parseInt(obj.getOid())];
				//strip out any point info in the string, lame
				msgStr = msgStr.replace(msgStr.substring(msgStr.lastIndexOf("("), msgStr.length), "");
				s += msgStr;
				//append the correct point data to the string
				pointStr = (parseInt(obj.getPoints()) == 1) ? "point" : "points";
				pointStr = " (" + obj.getPoints() + "&nbsp;" + pointStr + ")";
				s += pointStr;
            }
            else { // multiple points
                var count=0;
                s += '<td style="height:50px; vertical-align:middle;">';
                for (var ce=0; ce < c_events; ce++) {
                    var obj = incentiveArray[ce];
                    if (parseInt(obj.getOid()) == 23) continue;
                    this.debug('Util.doAggregateIncentiveEvents() in loop, print string ' + s);
                    var obj = incentiveArray[ce];
                    count += parseInt(obj.getPoints());
                }
                if (count >= 0) {
					s += '<strong style="margin-top:12px; font-size:115%;">Whoa!</strong><br/>';
                	s += "You\'ve earned <strong>"+ count + "</strong> points!";
                	s +=' </span>';//need the space for aesthetic reasons
                } else {
					s += '<strong style="margin-top:12px; font-size:115%;">Alert</strong><br/>';
					var _num = (count * -1);
                	s += "You\'re down <strong>" + _num + "</strong> points!";
                	s +=' </span>';//need the space for aesthetic reasons
                }
            }
            s += '</td>';
        }
        s+= '</tr></table>';
    }
    // s+= (c_events > 1 && !hasNoSystemEvents && isDisplayed) ? '<br/><span style="padding-left:18px;"><a href="/info/scoring_system">Tell Me More</a></span>' : '';

    var self=this;
    if (isDisplayed && s.length > 0) {
        self.doReplaceWidgetDisplay(s);
        setTimeout(function(){ self.doReplaceWidgetDisplay(null) } , 10000);
    }
}

// toggle btwn 1 + 2
KS_Util.prototype.doReplaceWidgetDisplay=function(pMsg) {
    this.fadeElement(this.gObj(this.current_widget_display),false);
    this.current_widget_display=(this.DISPLAY_WIDGET_1==this.current_widget_display) ? this.DISPLAY_WIDGET_2 : this.DISPLAY_WIDGET_1;
    this.fadeElement(this.gObj(this.current_widget_display),true,pMsg);
    var z = parseInt(this.gObj(this.current_widget_display).style.zIndex);
    this.gObj(this.current_widget_display).style.zIndex=(z+2);
}

KS_Util.prototype.fadeElement=function(pEle,pFadeVisible,pMsg) {
     var ele = Util.gObj(pEle);
     if (null!=pMsg && ""!=pMsg) ele.innerHTML = pMsg;
     var oAnim=null;
     if (pFadeVisible) {
   	 	oAnim = new YAHOO.util.Anim(pEle, { opacity: { to: 1, from : 0 } }, 1.9, YAHOO.util.Easing.easeNone);
	 }
	 else { //hidden
   	 	oAnim = new YAHOO.util.Anim(pEle, { opacity: { to: 0, from : 1 } }, 1.9, YAHOO.util.Easing.easeNone);
	 }
	 // YAHOO.util.Event.on(document, 'click', oAnim.animate, anim, true);
   
     //if (pFadeVisible) oAnim.onStart = function() { 
     ele.style.visibility = 'visible';
     oAnim.animate();
     return false;
}

/**
 * @function gObj - set display style
 * @param pObj - string or object
 */  
KS_Util.prototype.sDisplay=function(pObj,pBool) {
    this.gObj(pObj).style.display = (pBool) ? "block" : "none";
}

/** redirect the user to a fully qualified URL
  * @param pUrl - URL
  */ 
KS_Util.prototype.sendRedirect=function(pUrl) {
    parent.location.href = pUrl;
}

KS_Util.prototype.setWindowStatus=function(pStr) {
    if (pStr) window.status = pStr;
}

KS_Util.prototype.doFocusOnLoginBox=function() {
    var f=document.login_form;
    if (f) {
       if (f.username && f.username.value=="") f.username.focus();
       else if (f.passwd && f.passwd.value=="") f.passwd.focus();
    }
    return;
}

KS_Util.prototype.openTargetWindow = function(form, features, windowName) {
    if (!windowName) windowName = 'formTarget' + (new Date().getTime().toString());
    form.target = windowName;
    window.open ('', windowName, features);
}


KS_Util.prototype.fixFooter=function() {
	var l = this.gObj("left");
	var m = this.gObj("middle");
	var r = this.gObj("right");
	if (null == m) m = this.gObj('middle-center'); //if different layout
	if (null == m) m = this.gObj('just-middle'); //if different layout
    if (null == m) m = this.gObj('just-middle'); //if different layout again
	if (null != l && null != m && null != r) {
		var maxH = l.offsetHeight;
		if(r.offsetHeight > maxH) maxH = r.offsetHeight;
		if(maxH > m.offsetHeight) m.style.height = (maxH + this.OFFSET_BODY_HEIGHT)+"px";
    }
    else if (null != l && null != m && null==r) {
		var maxH = l.offsetHeight;
		if(maxH > m.offsetHeight) m.style.height = (maxH + this.OFFSET_BODY_HEIGHT)+"px";
    }
}

KS_Util.prototype.init=function() {
    //this.fixFooter();
    if (this.IS_JAVASCRIPT_DEBUG) {
        this.gObj(this.DEBUG_CONSOLE).style.visibility="visible";
        this.gObj(this.DEBUG_CONSOLE).style.display="block";
    }
    //if (!this.isNull(gPageTitle)) this.setDocumentTitle(gPageTitle);
    this.doAggregateIncentiveEvents(aIncentiveArray);
    this.doFocusOnLoginBox();
    if(this.getKid() != undefined) {
        this.initMCE();
    }
    hasWindowLoaded = true;
}


/**
 * Initialize mini consumption environment (if applicable, based on the current URI)
 */
KS_Util.prototype.initMCE = function() {
	var in_hp = in_my = false;
	var aux_clean_URI = this.REQUEST_URI.replace(/;.*$/, '').replace(/\?.*$/, '');
	if( ( in_hp = (aux_clean_URI.search(/^(\/|\/index)$/) != -1) ) ||
	    ( in_my = (aux_clean_URI.search(/^(\/my\/my)$/) != -1) ) ) {
		this.MCEPageType = in_hp ? 'h' : 'm';
		if(!this.gObj('mce-js').innerHTML.replace(/^\s*/, '').replace(/\s*$/, '')) {
			YAHOO.util.Connect.asyncRequest('GET', '/common/util/ks-pref-xhr-handler.php?pt='+this.MCEPageType+'&rand='+this.getKid()+'+'+Math.round(Math.random()*1000), {
        success: this.successMCE,
        failure: this.failureMCE,
        scope: this
});
		} else {
			var embedded_json = unescape(this.gObj('mce-js').innerHTML);
			this.gObj('mce-js').innerHTML=''; // so as to avoid showing gibberish
			this.successMCE( {responseText: unescape(embedded_json) } );
		}
	}
}


KS_Util.prototype.successMCE = function(o) {
	var e_mc_div = this.gObj('mini-consumption');
	eval('var handler_nfo = ' + o.responseText);
	if(
	   handler_nfo['mhs'] != undefined &&
	   handler_nfo['mms'] != undefined &&
	   handler_nfo['mhe'] != undefined) {
		if(this.MCEPageType == 'm') {
			YAHOO.util.Dom.addClass(this.gObj('mini-consumption'), 'no-contacts');
		}
		
		this.MCEShowHP = handler_nfo['mhs'];
		this.MCEShowMy = handler_nfo['mms'];

        if(this.MCEShowHP != 1 && this.MCEShowHP != 0) this.MCEShowHP = 1;
        if(this.MCEShowMy != 1 && this.MCEShowMy != 0) this.MCEShowMy = 1;

		this.MCEEnable = handler_nfo['mhe'];
		this.HTML = handler_nfo['HTML'];
		this.MCENewItems = handler_nfo['ni'];
		this.MCEFriendsCount = handler_nfo['fc'];
		var unsignedUrl = '/common/util/ks-pref-xhr-handler.php';
		this.showUrl = handler_nfo.showUrl != undefined ? handler_nfo.showUrl : unsignedUrl;
		this.hideUrl = handler_nfo.hideUrl != undefined ? handler_nfo.hideUrl : unsignedUrl;
		this.closeUrl = handler_nfo.closeUrl != undefined ? handler_nfo.closeUrl : unsignedUrl;
		this.ceUrl = handler_nfo.ceUrl != undefined ? handler_nfo.ceUrl : '/my/contacts/from/';
		if(this.MCEPageType == 'm' || this.MCEEnable || this.MCEFriendsCount) {
			var init_cmd = undefined;
            if(this.HTML) e_mc_div.innerHTML = this.HTML;
			//YAHOO.util.Event.on('mini-c-no_friends-close', 'click', this.closeMCEListener, this, true);
			YAHOO.util.Event.on('mini-c-ctrl-a', 'click', this.toggleMCEListener, this, true);
			if(this.MCEPageType == 'm') {
				init_cmd = this.MCEShowMy == 0 ? 'init_close' : 'init_open';
			} else {
				init_cmd = this.MCEShowHP == 0 ? 'init_close' : 'init_open';
			}
			this.toggleMCE( {action: init_cmd} );
		}
	}
}

KS_Util.prototype.failureMCE = function(o) {

}

KS_Util.prototype.successSaveMCE = function(o) {
	// o.responseText should be "OK"
	this.debug('success handler got responseText:"'+o.responseText+'"');
}

KS_Util.prototype.failureSaveMCE = function(o) {

}

KS_Util.prototype.toggleMCE = function(o_data) {
	if(o_data.action == "h_close" && this.MCEPageType == 'h') {
		YAHOO.util.Connect.asyncRequest('GET', this.closeUrl+'?pt='+this.MCEPageType+'&p=mhe&v=0'+'&rand='+this.getKid()+'+'+Math.round(Math.random()*1000), {
        success: this.successSaveMCE,
        failure: this.failureSaveMCE,
        scope: this
});
	} else {
		var pref_name;
		var pref_value;
		if(o_data.action == "toggle") {
			pref_name = this.MCEPageType == 'h' ? 'mhs' : 'mms';
			var action = YAHOO.util.Dom.hasClass('mini-c-ctrl', 'hide') ? 'close' : 'open';
		} else if(o_data.action == "init_close") {
			var action = 'close';
		} else {
			var action = 'open';
		}
		var h3 = document.getElementById('mini-c').getElementsByTagName('h3')[0];
		var xhr_url;
		if(action == 'close') {
			YAHOO.util.Dom.replaceClass('mini-c-ctrl', 'hide', 'show');
			xhr_url = this.hideUrl;
			if(this.gObj('mini-c-ctrl-a') != null) {
				this.gObj('mini-c-ctrl-a').innerHTML = 'Show';
			}
			YAHOO.util.Dom.setStyle('mini-c-body', 'display', 'none');
			pref_value = 0;
			if(h3 != null) {
				if(this.MCENewItems == 0) {
					h3.innerHTML = '<span class="yks-beta"><a href="'+this.ceUrl+'">My Network&#039;s Q&amp;A</a></span>' + ' <span class="white-space-pre">(Nothing new)</span>';
				} else {
					h3.innerHTML = '<span class="yks-beta"><a href="'+this.ceUrl+'">My Network&#039;s Q&amp;A</a></span>' + ' <span class="white-space-pre">( <img class="mce_new" src="http://l.yimg.com/a/i/nt/ic/ut/bsc/new12_1.gif" alt="new"> New Items)</span>';
				}
			}
		} else { // action == 'open'
			YAHOO.util.Dom.replaceClass('mini-c-ctrl', 'show', 'hide');
			xhr_url = this.showUrl;
			if(this.gObj('mini-c-ctrl-a') != null) {
				this.gObj('mini-c-ctrl-a').innerHTML = 'Hide';
			}
			YAHOO.util.Dom.setStyle('mini-c-body', 'display', 'block');
			pref_value = 1;
			if(h3 != null) {
				h3.innerHTML = '<span class="yks-beta"><a href="'+this.ceUrl+'">My Network&#039;s Q&amp;A</a></span>';
			}
		}
                var els =  YAHOO.util.Dom.getElementsByClassName( 'tt-invite-listener' , 'img');
                var tts =  new YAHOO.widget.Tooltip("tt-invite", {context:els, autodismissdelay: 99999 } );
                
                // this probably shouldn't be here but, theres not reall any other hooks, when migrating create tooltips as a seperate module
                if (document.getElementById("tt-total-points-listener"))
                {
                  var tts =  new YAHOO.widget.Tooltip("tt-total-points", {context: 'tt-total-points-listener', autodismissdelay: 99999 } );
                }
                
		var tt = new YAHOO.widget.Tooltip("tt-invite", {context: 'mini-c-qm', autodismissdelay: 99999 } );
		var tt2 = new YAHOO.widget.Tooltip("tt-invite-contants", {context: 'mini-c-qm2', autodismissdelay: 99999 } );
//		var tt3 = new YAHOO.widget.Tooltip("tt-invite", {context: 'profile-hide-qa', autodismissdelay: 99999 } );
//		var tt4 = new YAHOO.widget.Tooltip("tt-invite", {context: 'profile-hide-contacts', autodismissdelay: 99999 } );
		
		if( pref_name != undefined  ) {
			YAHOO.util.Connect.asyncRequest('GET', xhr_url+'?pt='+this.MCEPageType+'&p='+pref_name+'&v='+pref_value+'&rand='+this.getKid()+'+'+Math.round(Math.random()*1000), {
        success: this.successSaveMCE,
        failure: this.failureSaveMCE,
        scope: this
});
		}
	}
}

KS_Util.prototype.toggleMCEListener = function(e) {
	this.toggleMCE( {action: "toggle"} );
	YAHOO.util.Event.stopEvent(e);
}

KS_Util.prototype.closeMCEListener = function(e) {
	this.toggleMCE( {action: "h_close"} );
	YAHOO.util.Event.stopEvent(e);
}

KS_Util.prototype.getRadioValue = function(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(!radioLength || radioLength == undefined) 
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for (var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return null;
}

KS_Util.prototype.highlightElement = function (id, fps, duration, from, to) 
{
	Fat.fade_element(id,fps,duration,from,to);
}

/** Use this to add an event to an object unobtrusively
 *  @param - obj: Object to add event to (i.e. window)
 *  @param - evType: Event type (i.e. 'load')
 *  @param - fn:Function to be called when event occurs
 */
KS_Util.prototype.addEvent = function (obj, evType, fn){ 
    if (obj.addEventListener){ 
        obj.addEventListener(evType, fn, false); 
        return true; 
    } 
    else if (obj.attachEvent){ 
        var r = obj.attachEvent("on"+evType, fn); 
        return r; 
    } 
    else { 
        return false; 
    } 
}

/** Use this for displaying validation info to the user on the client side.
  * This function assumes that the form label and place for more information
  * are called inputIdLabel and inputIdHelp respectively.
  *
  * @param inputId: id of the input being evaluated
  * @param helpString: string to display for the user
  * @param show: boolean, show or hide the error and help string
  */
KS_Util.prototype.displayErrorInfo = function(inputId, helpString, show) {
    try {
        var helpString = helpString;
        var inputLabel = this.gObj(inputId+"Label"); //Main info label, will turn red
        var inputHelp = this.gObj(inputId+"Help"); //Place to put additional information in red
        var inputContainer = this.gObj(inputId+"Container"); //Place to put additional information in red
        if(show) {
                this.debug("error message to be displayed, input ID: " + inputId);
                if(inputLabel != null && inputLabel.className.indexOf("error") < 0) {
                        this.debug("Label to be set as error: "+inputLabel.id);
                        inputLabel.className = inputLabel.className + " error";
                }
                if(inputHelp != null) {
                        this.debug("Help content to be set as error: "+inputHelp.id);
                        inputHelp.className = inputHelp.className + " error";
                        inputHelp.innerHTML = helpString;
                }
		if(inputContainer != null) {
			this.debug("Changing container style: "+inputContainer.id);
			inputContainer.className = inputContainer.className + " error-container";
		}
        } else {
                this.debug("no errors, let's reinstate the element, input ID: " + inputId);
                if(inputLabel != null) {
                        inputLabel.className = inputLabel.className.replace("error", "");
                }
                if(inputHelp != null) {
                        inputHelp.className = inputHelp.className.replace("error", "");
                        inputHelp.innerHTML = "";
                }
                if(inputContainer != null) {
                        inputContainer.className = inputContainer.className.replace("error-container", "");
                }
        }
    } 
    catch(e) {
        this.debug(e.message);
    }
    return;
}


