/*
****************************************************************************
* Filename:   ajax-like.js
* Function:   TECHMATRIX - Functions to update help from "search by" pages
*              
* Created by:  Vincent Perlerin for WebFirst, Inc.
* Date:        2007
*
* Modification log:
* Author		Date		Modification
* ------		----		------------
*
****************************************************************************
*/





/*****************************************************************************
* Update text Element
* Attributes: element ID / title / content  / add link of not
*****************************************************************************/
function updateText(id, title,content, addLink) {
	titleTag 	= "div" + id  + "> h4";
	contentTag  = "div" + id  + "> p#contentHelp";


	$(titleTag).html(title);	
	$(contentTag).html(content);
	
	if(addLink!=null)
		$(contentTag).append("  &nbsp;<a href='"+addLink+"' title='More Information' target='_blank' class='moreInfo'>More Information</a>");
}

/*****************************************************************************
* Update list of SubFeatures
* Attributes: element ID / feature 
*****************************************************************************/
function updateSubFeatures(id,feat) {
	subFArray 	= feat.subfeatures;
	divToChange = "div" + id;
	toAdd 		= "";
	
	$(divToChange +">p.listOfLinks").html("");
	
	for(i=0;i<subFArray.length;i++) {
		toAdd += "<a href='aboutProductFeatures.aspx#"+subFArray[i].id+"' title='<strong>" +  subFArray[i].name +":</strong> " + subFArray[i].description  +"' target='_blank' class='addToolTip' >"+subFArray[i].name+  "<a/> ";
		//if( (i % 3 == 0) && i!=0 ) toAdd += "<br/>";
	}

	
	if(toAdd!="") {
		$(divToChange).append("<p class='listOfLinks'><strong class='titleLike'>Associated Sub-features:<br/></strong> "+toAdd+"</p>");
	} 
	
	addwarning();
}


/*****************************************************************************
* Update text Element for Learning Support
* Attributes: LSuuport ID, html element Id
*****************************************************************************/
function updateTextForSupport(id, idTtext) {
	supp = GetSupport(id);	
	supp = supp ? supp : {name:'',description:''};
	updateText(idTtext,supp.name,supp.description); //,"aboutLSupports.aspx#"+id);
}


/*****************************************************************************
* Update text Element for Learning Support
* Attributes: LSuuport ID, html element Id
*****************************************************************************/
function updateTextForFeature(id, idTtext, linkBool) {
	feat = GetFeature(id);
	feat = feat ? feat : {name:'',description:'',subfeatures:[]};
	if(linkBool)	updateText(idTtext,feat.name,feat.description,"aboutProductFeatures.aspx#"+id);
	else 			updateText(idTtext,feat.name,feat.description,null);
	updateSubFeatures(idTtext,feat);
}


/*****************************************************************************
* Update text Element for Products
* Attributes: Product ID, html element Id
*****************************************************************************/
function updateTextForProduct(id, idText) {

    subjectTag  = "div" + idText  + "> p#subjectsHelp";
    supportTag  = "div" + idText  + "> p#learningSupportsHelp";
    descLinkTag  = "div" + idText  + "> p#contentPHelp";
    $(subjectTag).html("");
    $(supportTag).html("");
    $(descLinkTag).html("");
    updateText(idText, "","", null);


	subj = GetProduct(id);
	if (subj)
	{
	    updateText(idText, subj.name ,"", null);
    	
	    // LIST OF SUBJECTS *****************************************************/
	    listOfSubjects = subj.subjects;

	    hasSeveralSub = false;
	    listOfSubjects.length>1?hasSeveralSub=true:hasSeveralSub=false;

	    textForSub = "<strong class='titleLike'>Subject";
	    if(hasSeveralSub) textForSub+="s";
    	
	    textForSub += ":</strong> " + GetSubject(listOfSubjects[0]).name;

	    for(i=1; i<listOfSubjects.length; i++) {
		    textForSub += ", " + GetSubject(listOfSubjects[i]).name + " ";
	    }
    	
	    $(subjectTag).html(textForSub);
    	
	    // LIST OF LEARNING SUPPORTS ********************************************/
	    listOfSupports = subj.supports;
    	
	    hasSeveralSup = false;
	    listOfSupports.length>1?hasSeveralSup=true:hasSeveralSup=false;
    	
	    textForSup = "<strong class='titleLike'>Learning Support";
	    if(hasSeveralSup) textForSup+="s";
    	

	    if(GetSupport(listOfSupports[0])!=null) {
		    textForSup  += ":</strong> <a class='addToolTip' title='"+ GetSupport(listOfSupports[0]).description +"' href='aboutLSupports.aspx#" + GetSupport(listOfSupports[0]).id + "'>" + GetSupport(listOfSupports[0]).name +"</a>";
    	
		    for(i=1; i<listOfSupports.length; i++) {
			    textForSup += ", <a class='addToolTip' title='"+ GetSupport(listOfSupports[i]).description +"' href='aboutLSupports.aspx#" + GetSupport(listOfSupports[i]).id + "'>" + GetSupport(listOfSupports[i]).name + "</a> ";
		    }
    		
		    $(supportTag).html(textForSup+"");
	    }
    	
	    // DESCRIPTION + LINK (more Information)
	    $(descLinkTag).html(subj.description + " <a href=\'ProductProfile.aspx?pid=" + id + "'\ target='_blank' title='More Information' class='moreInfo'>More Information</a>" );
	    addwarning();
	}
}