function getObject(objectId) {
	if (document.all && !document.getElementById) {
		return document.all(objectId);
	} else {
		return document.getElementById(objectId);
	}
}

function exp_coll(ind) {
	s = document.getElementById("wbdSide"+ind);		
	if (s.className == 'research-hidden') {
		getObject("wbdSide"+ind).className="research-active";
		classString="research-active";
		getObject("products"+ind).className="wbTitles-minus";
	   	classString="wbTitles-minus";
	}else{
		if (s.className == 'research-active') {
			getObject("wbdSide"+ind).className="research-hidden";
			classString="research-hidden";
			getObject("products"+ind).className="wbTitles";
	   		classString="wbTitles";
		}
	}
}

/*Changed the function to allow the user to collapse the content under a 
 * product in My research Page.
 */
function exp_ind(ind) {
        s = document.getElementById("wbd" + ind);
        if (s.className == 'research-hidden') {
                getObject("wbd"+ind).className="research-active";
                classString="research-active";
                getObject("product"+ind).className="research-header-minus";
                classString="research-header-minus";
        }
       else{
                if (s.className == 'research-active') {
                        getObject("wbd"+ind).className="research-hidden";
                        classString="research-hidden";
                        getObject("product"+ind).className="research-header";
                        classString="research-header";
                }
        }

}

/* Added a new function to resolve index side issue in My Research*/
function exp_research_ind(ind) {
        s = document.getElementById("wbd" + ind);
        if (s.className == 'research-hidden') {
                getObject("wbd"+ind).className="research-active";
                classString="research-active";
                getObject("product"+ind).className="research-header-minus";
                classString="research-header-minus";
        }
}

/* Added a new function to resolve index side issue in My Research*/
function exp_coll_research(ind) {
        s = document.getElementById("wbd" + ind);
        if (s.className == 'research-hidden') {
                getObject("wbd"+ind).className="research-active";
                classString="research-active";
                getObject("product"+ind).className="research-header-minus";
                classString="research-header-minus";
        }
        t = document.getElementById("wbdSide"+ind);
        if (t.className == 'research-hidden') {
                getObject("wbdSide"+ind).className="research-active";
                classString="research-active";
                getObject("products"+ind).className="wbTitles-minus";
                classString="wbTitles-minus";
        }else{
                if (t.className == 'research-active') {
                        getObject("wbdSide"+ind).className="research-hidden";
                        classString="research-hidden";
                        getObject("products"+ind).className="wbTitles";
                        classString="wbTitles";
                }
        }
}



function exp(ind) {
	s = document.getElementById("wbd" + ind);		
	if (s.className == 'research-hidden') {
		getObject("wbd"+ind).className="research-active";
		classString="research-active";
		getObject("product"+ind).className="research-header-minus";
	   	classString="research-header-minus";
	}else{
		if (s.className == 'research-active') {
			getObject("wbd"+ind).className="research-hidden";
			classString="research-hidden";
			getObject("product"+ind).className="research-header";
	   		classString="research-header";
		}
	}	
}

function hide_note(id) 
{
	s = document.getElementById(id);
	s.style.display = "none";
}


function showhidesection(which){
	var selectedDiv = document.getElementById(which);
	if(selectedDiv.style.display != 'block'){
		selectedDiv.style.display = 'block';
	} else {
		selectedDiv.style.display = 'none';
	}
}

function validateName(){
	var title=document.titleRename.strProjectTitle.value;
	title = title.replace(/^\s+|\s+$/g, '') ;
	if(title==""){
		s = document.getElementById("title-error");
		s.style.display = "block";
		return false;
	}else{
		document.titleRename.submit();
		return false;
	}
}

function myResearchAr(strId,strCollId)
{
	var bFlag = false;
	var strUrl = "research?id=";
	var id = strId;
	var collId = strCollId;
	if(id=='null'){
		if(document.NormalSearchForm.ck.length > 0){
			for(i=0; i<document.NormalSearchForm.ck.length; i++ )
			{
				if(document.NormalSearchForm.ck[i].checked==true)
				{
					bFlag = true;
					strUrl = strUrl + document.NormalSearchForm.ck[i].value + "|";
					
				}
			}
		}else{
				if(document.NormalSearchForm.ck.checked==true)
				{
					bFlag = true;
					strUrl = strUrl + document.NormalSearchForm.ck.value ;
				}

		}
		
		if(strUrl.lastIndexOf("|")==(strUrl.length-1))
		{
			strUrl=strUrl.substring(0, strUrl.length-1);
		}
	
		if(bFlag==false)
		{
			var element = document.getElementById("Save-Article-to-Research");
			element.innerHTML = '<font color="red"><b>Please select at least one article to add to your My Research account.</b></font>';
			var errorelememt = document.getElementById("error-classes");
			if(errorelememt != null){
				errorelememt.innerHTML = '';
			}
		}
		else
		{	
			if(collId != null){
				document.NormalSearchForm.action=strUrl+"&cid="+strCollId;	
			}else{
				document.NormalSearchForm.action=strUrl;
			}
			document.NormalSearchForm.submit();
		}
		
	}else{
		document.ResearchFormBean.action=strUrl+id+"&cid="+strCollId;
		document.ResearchFormBean.submit();
	}
}

function forward(strActionName,strCollId){
	if(strCollId==null){
		document.WebBookFormBean.action='webbook';	
		document.WebBookFormBean.submit();
	}else{
		document.WebBookFormBean.action='webbook';	
		document.WebBookFormBean.cid.value=strCollId;	
		document.WebBookFormBean.submit();
	}
	
	return false;
 }

function showDiscoverInfo(section,which,notes){	
	
	/*      if(notes.indexOf("'")!=-1){
                notes=notes.replace("'","\\\'");
        }*/
        /* Added for BUG-121 and commented the above two lines*/
        notes=notes.replace(/\'+/g,"\\'");
        notes=notes.replace(/\"+/g,"&quot;");

	/* Added for ENH-6 to display the count of remaining charcaters*/
	if(notes != 'null'){
		var len=notes.length;
		var x ="remaining"+section+which;
		document.getElementById(x).innerHTML = 500 - len;
	}
	 /* Changes for ENH-6 ends here*/
	//<img src=\""+ strRightImage+ "\" height=\"25\" width=\"5\">
	var viewicon="images/icons-view.gif";
	var addicon="images/icons-pencil.gif";
	var rowicon="rowIcon";
	var thenotelinkdiv = document.getElementById(section +"_" +which);
	
	var thenotedetailsdiv = document.getElementById(section + "_details_" + which);
	var thenotetextdiv = document.getElementById(section + "_text_" + which);
	if(thenotedetailsdiv.style.display != 'block'){		
		thenotedetailsdiv.style.display = 'block';
		thenotelinkdiv.innerHTML = '<img class="'+'rowIcon'+'" alt="View Note" src="'+viewicon+'"/>'+" <a href=\"javascript:;\" onclick=\"showDiscoverInfo('"+section+"',"+which+",'"+notes+"');\">[hide note]</a>";

	} else {
		thenotedetailsdiv.style.display = 'none';
		if(notes != 'null'){
			thenotelinkdiv.innerHTML = "<img src=\""+viewicon+"\" alt=\"View Note\" class=\"rowIcon\" /> <a href=\"javascript:;\" onclick=\"showDiscoverInfo('"+section+"',"+which+",'"+notes+"');\">[view note]</a>";
		} else {
			thenotelinkdiv.innerHTML = "<img src=\""+addicon+"\" alt=\"Add Note\" class=\"rowIcon\" /> <a href=\"javascript:;\" onclick=\"showDiscoverInfo('"+section+"',"+which+",'"+notes+"');\">[add note]</a>";
		}		
	}
}

function CheckFieldLength(fn,wn,rn,mc) {
  var textval = document.getElementById(fn).value;
  var len = textval.length;
  var temp;
  if (len > mc) {
    document.getElementById(fn).value = textval.substring(0,mc);
	len = mc;
  }
  if(mc-len == 0){
  	document.getElementById(rn).innerHTML = '<font color="red"> Characters remaining: [0] </font>';
  }else{
  	temp = mc - len;
  	document.getElementById(rn).innerHTML = ' Characters remaining: [' + temp +']';
  }
 }

 function addNotes(id,action,cid,pid){
	s = document.getElementById(id);
	var notes=s.value;
	performAction(notes,action,cid,id,pid);
}
function performAction(notes,action,cid,id,pid){
	/* Changed the notes length from 50 to 500 : ENH-259*/
	if(notes.length<=500){
		var url="research?action="+action+"&note=true&cid="+cid+"&notes="+notes+"&pid="+pid;
		location.href=url;
	}else{			
		s = document.getElementById("notes-error-"+id);
		s.style.display = "block";
		return false;
	}
}


function validateBook(formName,strProdId,strId){
	var form = document.getElementById(formName);
	var bookTitle=form.title.value;
	if(bookTitle==""){
		s = document.getElementById(strId);
		s.style.display = "block";
		return false;
	}else{
		//ENH-43 Added to avoid submission of form twice resulting of single input being treated as double entries
		form.action='webbook';	
		//form.strProductId.value=strProdId;	
		//form.submit();
		return true;		
	}
}

function validateWeb(formName,strProdId,strUrlErr,strUrlInv,strWebName){
	var form = document.getElementById(formName);
	var webname=form.webName.value;
	var weburl=form.webUrl.value;
	if((webname!="") && (weburl!="")){
		if(weburl.indexOf("http://")==-1 && weburl.indexOf("https://")==-1){
			s = document.getElementById(strUrlErr);
			s.style.display = "none";
			t = document.getElementById(strUrlInv);
			t.style.display = "block";
			return false;
		}else{
			//ENH-43 Added to avoid submission of form twice resulting of single input being treated as double entries
			form.action='webbook';	
			//form.strProductId.value=strProdId;	
			//form.submit();	
			return true; 
		}
	}else{
		if(webname=="" ){
			s = document.getElementById(strWebName);
			s.style.display = "block";
			
		}
		if(weburl==""){
			if(webname!="" ){
				s = document.getElementById(strWebName);
				s.style.display = "none";
			}
			t = document.getElementById(strUrlErr);
			t.style.display = "block";
		}
		return false;
	}
}



//Added for ENH-50 for My Research Delete option
function showhideresearch(which){
	var selectedDiv = document.getElementById(which);
	var unselectDiv;
	if(which=='research-rename')
	{
	unselectedDiv = document.getElementById('research-delete');
	}
else	
	{
	unselectedDiv = document.getElementById('research-rename');	
		
	}	
	if(selectedDiv.style.display != 'block'){
		selectedDiv.style.display = 'block';
		unselectedDiv.style.display = 'none';
	} else {
		selectedDiv.style.display = 'none';
	}
}
//Changes for ENH-50 end here