// JavaScript Document common.js created on 25th may 2005 to incorporate the character searches available in
//several sub menu pages. It includes double byte single byte character check and also length of the string
//given as input.
//function to check the validity of the DTC entered
function fncCheckDTC(sval, focusitem)
{
	if(sval.length != 5)
	{
		sErrMsg += getMessage("MMSMS_InvalidDTC") + "\n";
		eval('this.document.searchform'+'.'+focusitem+'.focus()');
		return false;
	}

	else
	{
		var origsval = sval;
		var flag = true;
		/*
		var modsval = sval.substring(0,1);
		var valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		if(valid.indexOf(modsval) == -1){
			sErrMsg += getMessage("MMSMS_InvalidDTC") + "\n";
			eval('this.document.searchform'+'.'+focusitem+'.focus()');
			return false;
		}	
		var sval = sval.substring(1,sval.length);
		valid="0123456789";
		var msgcheck = 0;
		for (var i = 0; i < sval.length; i++) {
			if (valid.indexOf(sval.charAt(i)) == -1) {
				if(msgcheck == 0) {
					sErrMsg += getMessage("MMSMS_InvalidDTC") + "\n";
					msgcheck++;
				}							
				eval('this.document.searchform'+'.'+focusitem+'.focus()');
				flag = false; 
			}
			else { 
			 flag = true;
			}
		}
		*/ 
		return flag; 
	}
		
}
//function to trim the spaces 
function trim(str)
{
	return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}
//function to search for the string value appearance in the allowed elements of sie
function fnStringSearch(stringval,menuSearch,dtccode,sympcode,sisnumber)
{
	var rightframeerrname = "error/Serch.html";
	
	var stringval = trim(stringval);
	if((MANUAL_INFO.lang != "JP" || MANUAL_INFO.lang != "jp") && isDoubleByte(stringval) && (trim(stringval).length !=0)) 
		stringval = StrConvNarrowOtherThanJP(stringval);
	if(trim(stringval).length !=0)
	{
		var flag = hasSpecialCharacters(stringval);		
		if(flag == true) {
			alert(getMessage("MMSMS_InvalidChar"));
			this.document.searchform.string.focus();
			return false;
		}
		else {
			//IMplement special characters check
			if(sisnumber != null && sisnumber != "")
			{
				var dm = application.getAttribute("DATAMANAGER");
				var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SISNO");
				nq.params["menuitemarray"] = menuSearch;
				nq.params["sisno"] = sisnumber;
				var rs = dm.executeNamedQuery(nq);
				if(rs.rowCount==0)
				{
					var menuarray=new Array();
					var dbData = menuarray;
					fncDispResultsInRightFrame(dbData, rightframeerrname);
					return false;
				}			  
			}
			var dm = application.getAttribute("DATAMANAGER");
			var dtcarr = new Array();
			dtcarr = dtccode;
			for(var i = 0;i<dtcarr.length;i++)
			{
				if(dtcarr[i] != null && trim(dtcarr[i]) != "" && dtcarr[i] != ",")
				{
					dtcarr[i] = trim(dtcarr[i]);
					dtcarr[i] = dtcarr[i].toLowerCase();
					//dtcarr[i] = StrConvNarrow(dtcarr[i], MANUAL_INFO.lang);	
					//dtcarr[i] = StrConvWide(dtcarr[i], MANUAL_INFO.lang);
					dtccode[i] = dtcarr[i];
				}
			}
			if(dtccode != null && dtccode != "," && dtccode != "" && sisnumber != "" && sisnumber != null){
				var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_DTC_SISNO_TITLE");
				nq.params["dtcid"] = dtccode;
				nq.params["sisno"] = sisnumber;
				rightframeerrname = "error/DTC-Serch.html";
			}
			else if(dtccode != null && dtccode != "," && dtccode != "")	{
				var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_DTC_TITLE");
				nq.params["dtcid"] = dtccode;
				rightframeerrname = "error/DTC-Serch.html";
			}			
			else if(sympcode != null && trim(sympcode) != "" && trim(sympcode) != "," && sisnumber != "" && sisnumber != null)	{
				var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SYMP_SISNO_TITLE");
				sympcode = trim(sympcode);
				sympcode = sympcode.toLowerCase();
				nq.params["sisno"] = sisnumber;
				nq.params["sympid"] = sympcode;
				rightframeerrname = "error/SYM-Serch.html";
			}
			else if(sympcode != null && trim(sympcode) != "" && trim(sympcode) != ","){
				var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SYMP_TITLE");
				sympcode = trim(sympcode);
				sympcode = sympcode.toLowerCase();
			  //sympcode = StrConvNarrow(sympcode, MANUAL_INFO.lang);	
			  //sympcode = StrConvWide(sympcode, MANUAL_INFO.lang);
				nq.params["sympid"] = sympcode;
				rightframeerrname = "error/SYM-Serch.html";
			}
			
			else if(sisnumber != null && sisnumber != "") {	
				var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SISNO_TITLE");
				sisnumber = sisnumber.toLowerCase();
			  //sisnumber = StrConvNarrow(sisnumber, MANUAL_INFO.lang);	
			  //sisnumber = StrConvWide(sisnumber, MANUAL_INFO.lang);

				nq.params["sisno"] = sisnumber;
				rightframeerrname = "error/SIS-Serch.html";
			}
			else {
				var nq = new NamedQuery("GET_SIE_WITH_TITLE");
			}
						
			  stringval = stringval.toLowerCase();
				//Change
			  stringval = StrConvNarrow(stringval, MANUAL_INFO.lang);	
			  stringval = StrConvWide(stringval, MANUAL_INFO.lang);

			  nq.params["title"] = stringval;
			  nq.params["menuitemarray"] = menuSearch;
			  
			  var rs = dm.executeNamedQuery(nq);
			  var menuarray=new Array();
			  var arrindex = 0;
			  var rsi = rs.iterator();

			  menuarray = getDBData(rsi);
				
			  var dbData = menuarray;
			  
			  fncDispResultsInRightFrame(dbData, rightframeerrname);
			}
	}
	else
	{
		var dm = application.getAttribute("DATAMANAGER");
		var dtcarr = new Array();
		dtcarr = dtccode;
		for(var i = 0;i<dtcarr.length;i++)
		{
			if(dtcarr[i] != null && trim(dtcarr[i]) != "" && dtcarr[i] != ",")
			{
				dtcarr[i] = trim(dtcarr[i]);
				dtcarr[i] = dtcarr[i].toLowerCase();
				dtccode[i] = dtcarr[i];
			}
		}
		if(sisnumber != null && sisnumber != "" && sympcode != null && trim(sympcode) != "" && trim(sympcode) != ",")
		{
			//IMplement special characters check
			if(sisnumber != null && sisnumber != "")
			{
				var dm = application.getAttribute("DATAMANAGER");
				var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SISNO");
				nq.params["menuitemarray"] = menuSearch;
				nq.params["sisno"] = sisnumber;
				var rs = dm.executeNamedQuery(nq);
				if(rs.rowCount==0)
				{
					var menuarray=new Array();
					var dbData = menuarray;
					rightframeerrname = "error/SIS-Serch.html";
					fncDispResultsInRightFrame(dbData, rightframeerrname);
					return false;
				}else
				{
					var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SYMP_SISNO");			
					sympcode = trim(sympcode);
					sympcode = sympcode.toLowerCase();
					nq.params["sympid"] = sympcode;
					nq.params["sisno"] = sisnumber;
					rightframeerrname = "error/SYM-Serch.html";
				}		  
			}			
		}
		else if(sisnumber != null && sisnumber != "" && dtccode != null && dtccode != "," && dtccode != "" )
		{
			if(sisnumber != null && sisnumber != "")
			{
				var dm = application.getAttribute("DATAMANAGER");
				var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SISNO");
				nq.params["menuitemarray"] = menuSearch;
				nq.params["sisno"] = sisnumber;
				var rs = dm.executeNamedQuery(nq);
				if(rs.rowCount==0)
				{
					var menuarray=new Array();
					var dbData = menuarray;
					rightframeerrname = "error/SIS-Serch.html";
					fncDispResultsInRightFrame(dbData, rightframeerrname);
					return false;
				}else
				{
					var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_DTC_SISNO");
					nq.params["sisno"] = sisnumber;
					nq.params["dtcid"] = dtccode;				
					rightframeerrname = "error/DTC-Serch.html";
				}
			}
		}
		else if(sympcode != null && trim(sympcode) != "" && trim(sympcode) != ",")
		{
			var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SYMP");
			sympcode = trim(sympcode);
			sympcode = sympcode.toLowerCase();
			nq.params["sympid"] = sympcode;
			rightframeerrname = "error/SYM-Serch.html";
		}
		/*else if(sisnumber != null && sisnumber != "" && sisflag==true)
		{
			var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SISNO");
			nq.params["sisno"] = sisnumber;			
			rightframeerrname = "error/SIS-Serch.html";
		}*/
		else{
			alert(getMessage("MMSMS_InvalidChar"));
			this.document.searchform.string.focus();
			return false;
		}
		nq.params["menuitemarray"] = menuSearch;		
		var rs = dm.executeNamedQuery(nq);
		var menuarray=new Array();
		var arrindex = 0;
		var rsi = rs.iterator();
		menuarray = getDBData(rsi);				
		var dbData = menuarray;			 
		fncDispResultsInRightFrame(dbData, rightframeerrname);
	}
}

//function to search for the string value appearance in the allowed elements of sie
function fnStringSearchWithSCT_SC_CONFIG(stringval,menuSearch,dtccode1,dtccode2,sympcode,sisnumber,sct,sc,config,subsc,si)
{
	var rightframeerrname = "error/Serch.html";
	if(sisnumber != null && sisnumber != "" && sisnumber.length>=18)
	{
		if(trim(stringval).length !=0)
		{
			var flag = hasSpecialCharacters(stringval);
			if(flag == true) {
				alert(getMessage("MMSMS_InvalidChar"));
				return false;
			}	
		}
		if(parent.frameHeader)	{
			parent.frameHeader.fncGetSis(sisnumber);
		}
		var dm = application.getAttribute("DATAMANAGER");
		var nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SISNO");
		nq.params["menuitemarray"] = menuSearch;
		nq.params["sisno"] = sisnumber;
		var rs = dm.executeNamedQuery(nq);
		if(rs.rowCount==0)
		{
			  var menuarray=new Array();
			  var dbData = menuarray;
			fncDispResultsInRightFrame(dbData, rightframeerrname);
			return false;
		}
	}else
	{
		if(sisnumber != null && sisnumber !="" && sisnumber.length <18)
		{
			alert(getMessage("MMSMS_InvalidSIS"));
			document.sisform.sis.focus();
			return false;
		}			  
	}
	if(parent.frameHeader)	{
			parent.frameHeader.fncGetSis(trim(sisnumber));
	}
	var stringval = trim(stringval);
	if((MANUAL_INFO.lang != "JP" || MANUAL_INFO.lang != "jp") && isDoubleByte(stringval) && (trim(stringval).length !=0))
		stringval = StrConvNarrowOtherThanJP(stringval);
	if(trim(stringval).length !=0)
	{
		//IMplement special characters check
		var flag = hasSpecialCharacters(stringval);
		if(flag == true) {
			alert(getMessage("MMSMS_InvalidChar"));
			return false;
		}
		else {
			var dm = application.getAttribute("DATAMANAGER");
			stringval = stringval.toLowerCase();
			//Change
			stringval = StrConvNarrow(stringval, MANUAL_INFO.lang);	
			stringval = StrConvWide(stringval, MANUAL_INFO.lang);
			var nq = "";
			if (((dtccode1 != null && dtccode1 != "") || (dtccode2 != null && dtccode2 != "")) && ( sisnumber != "" && sisnumber != null))
			{
				rightframeerrname = "error/DTC-Serch.html";
				nq = new NamedQuery("GET_SIE_WITH_MENUITEM_DTC_SISNO_TITLE_SCT_SC_CONFIG");

				dtccode1 = dtccode1.toLowerCase();
			  	dtccode2 = dtccode2.toLowerCase();
			  
				nq.params["dtc1"] = dtccode1;
				nq.params["dtc2"] = dtccode2;
				nq.params["sisno"] = sisnumber;
			}
			else if ((dtccode1 != null && dtccode1 != "") || (dtccode2 != null && dtccode2 != "")) {
					rightframeerrname = "error/DTC-Serch.html";
					nq = new NamedQuery("GET_SIE_WITH_MENUITEM_DTC_TITLE_SCT_SC_CONFIG");
					
					dtccode1 = dtccode1.toLowerCase();
				  //dtccode1 = StrConvNarrow(dtccode1, MANUAL_INFO.lang);	
				  //dtccode1 = StrConvWide(dtccode1, MANUAL_INFO.lang);

					dtccode2 = dtccode2.toLowerCase();
				  //dtccode2 = StrConvNarrow(dtccode2, MANUAL_INFO.lang);	
			  	//dtccode2 = StrConvWide(dtccode2, MANUAL_INFO.lang);

					nq.params["dtc1"] = dtccode1;
					nq.params["dtc2"] = dtccode2;
			}
			else if(sympcode != null && sympcode != "")	{
					rightframeerrname = "error/SYM-Serch.html";
					nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SYMP_TITLE_SCT_SC_CONFIG");									 
					sympcode = sympcode.toLowerCase();
				  //sympcode = StrConvNarrow(sympcode, MANUAL_INFO.lang);	
				  //sympcode = StrConvWide(sympcode, MANUAL_INFO.lang);
					nq.params["sympid"] = sympcode;
			}
			else if( sisnumber != "" && sisnumber != null)
			{
				rightframeerrname = "error/SIS-Serch.html";
				nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SISNO_TITLE_SCT_SC_CONFIG");	
				nq.params["sisno"] = sisnumber;
			}
			else {
				nq = new NamedQuery("GET_SIE_WITH_TITLE_SCT_SC_CONFIG");
			}
			nq.params["menuitemarray"] = menuSearch;
			nq.params["sct"]=sct;
			nq.params["sc"]=sc;
			nq.params["config"]=config;
			nq.params["subsc"]=subsc;
			nq.params["si"]=si;
			nq.params["title"] = stringval;			  
			
			var rs = dm.executeNamedQuery(nq);
			var menuarray=new Array();
			var arrindex = 0;
			var rsi = rs.iterator();
			var dbData =getDBData(rsi);
			
			fncDispResultsInRightFrame(dbData, rightframeerrname);
		}
	}
  else
  {
		var dm = application.getAttribute("DATAMANAGER");
		if (((dtccode1 != null && dtccode1 != "") || (dtccode2 != null && dtccode2 != "")) && ( sisnumber != "" && sisnumber != null))
		{
				rightframeerrname = "error/DTC-Serch.html";
				nq = new NamedQuery("GET_SIE_WITH_MENUITEM_DTC_SISNO_SCT_SC_CONFIG");

				dtccode1 = dtccode1.toLowerCase();
			  	dtccode2 = dtccode2.toLowerCase();
			  
				nq.params["dtc1"] = dtccode1;
				nq.params["dtc2"] = dtccode2;
				nq.params["sisno"] = sisnumber;
		}
		else if ((dtccode1 != null && dtccode1 != "") || (dtccode2 != null && dtccode2 != ""))
		{
				rightframeerrname = "error/DTC-Serch.html";
				nq = new NamedQuery("GET_SIE_WITH_MENUITEM_DTC_SCT_SC_CONFIG");

				dtccode1 = dtccode1.toLowerCase();
			  //dtccode1 = StrConvNarrow(dtccode1, MANUAL_INFO.lang);	
			  //dtccode1 = StrConvWide(dtccode1, MANUAL_INFO.lang);

				dtccode2 = dtccode2.toLowerCase();
			  //dtccode2 = StrConvNarrow(dtccode2, MANUAL_INFO.lang);	
			  //dtccode2 = StrConvWide(dtccode2, MANUAL_INFO.lang);
				nq.params["dtc1"] = dtccode1;
				nq.params["dtc2"] = dtccode2;
		}
		else if(sympcode != null && sympcode != "")
		{
				rightframeerrname = "error/SYM-Serch.html";
				nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SYMP_SCT_SC_CONFIG");									 

				sympcode = sympcode.toLowerCase();
				
				//if((MANUAL_INFO.lang != "JP" || MANUAL_INFO.lang != "jp") && isDoubleByte(sympcode) && (trim(sympcode).length !=0)) 
				//	sympcode = StrConvNarrowOtherThanJP(sympcode);
			  //sympcode = StrConvNarrow(sympcode, MANUAL_INFO.lang);	
			  //sympcode = StrConvWide(sympcode, MANUAL_INFO.lang);
				nq.params["sympid"] = sympcode;
		}
		else if(sisnumber != null && sisnumber != "" )
		{
			nq = new NamedQuery("GET_SIE_WITH_MENUITEM_SISNO_SCT_SC_CONFIG");
			nq.params["sisno"] = sisnumber;
			rightframeerrname = "error/SIS-Serch.html";
		}
		else
		{
			nq = new NamedQuery("GET_SIE_WITH_SCT_SC_CONFIG");
			stringval = stringval.toLowerCase();
			//Change
		  stringval = StrConvNarrow(stringval, MANUAL_INFO.lang);	
		  stringval = StrConvWide(stringval, MANUAL_INFO.lang);
			nq.params["title"] = stringval;
		}
	  nq.params["menuitemarray"]=menuSearch;
  	nq.params["sct"]=sct;
	  nq.params["sc"]=sc;
  	nq.params["config"]=config;
	nq.params["subsc"]=subsc;
	nq.params["si"]=si;
	  var rs = dm.executeNamedQuery(nq);
  	var menuarray=new Array();
		var arrindex = 0;
		var rsi = rs.iterator();
		var dbData =getDBData(rsi);
		
		fncDispResultsInRightFrame(dbData, rightframeerrname);
	}          
}

//function to check special characters
function hasSpecialCharacters(stringval)
{
  var iChars = "!@#$%^&*+=-[]\\\';,.{}|\":<>?`~_";
  for (var i = 0; i < stringval.length; i++) {
            if (iChars.indexOf(stringval.charAt(i)) != -1) {                      
                        return true;
            }
  }
    return false;
}

//array holding all the possible attribute values of sie to construct the menu data in every sub menu page
function fncArray(sct,sc,config,serviceitem, serviceitemname, dtcid, sympid, cuid, cansystem, compdesc,comptype,servcatsub, sitqno, sieid, sortno, infoid, title,sctid,scid,configname,compid,comptypeid, multipath, sub_sc_id,tree_sort_no)
{
	this.sct=sct;
	this.sc=sc;
	this.config=config;
	this.serviceitem=serviceitem;
	this.serviceitemname=serviceitemname;
	this.dtcid=dtcid;
	this.sympid=sympid;
	this.cansystem=cansystem;
	this.compdesc=compdesc;
	this.comptype=comptype;
	this.servcatsub=servcatsub;
	this.sieid=sieid;
	this.cuid=cuid;
	this.sitqno=sitqno;
	this.infoid = infoid;
	this.sortno = sortno;
	this.title = title;
	this.sctid = sctid;
	this.scid = scid;
	this.configname = configname;
	this.compid = compid;
	this.comptypeid = comptypeid;
	this.multipath = multipath;
	this.sub_sc_id = sub_sc_id;
	this.tree_sort_no=tree_sort_no;
}

//function to change image on mouse over
function fnchangeImg(thisImg)
{
	if(thisImg.name=='btnSIS_Search')
		thisImg.src="../images/SIS_Search_f.jpg";
	if(thisImg.name=='btnSIS_Clear')
		thisImg.src="../images/SIS_Clear_f.jpg";
	if(thisImg.name=='btnClear1')
		thisImg.src="../images/Clear_f.jpg";
	if(thisImg.name=='btnSIS_Search1')
		thisImg.src="../images/Search_f.jpg";
}

//function to change image on mouse click
function fnChangeImgOnClick(img){
if(img.name=='btnSIS_Search')
	img.src="../images/SIS_Search_c.jpg";
if(img.name=='btnSIS_Clear')
	img.src="../images/SIS_Clear_c.jpg";
if(img.name=='btnClear1')
	img.src="../images/Clear_c.jpg";
if(img.name=='btnSIS_Search1')
	img.src="../images/Search_c.jpg";
}

//function to change image on mouse out
function fnshowDefault(thisImg)
{
	if(thisImg.name=='btnSIS_Search')
		thisImg.src="../images/SIS_Search.jpg";
	if(thisImg.name=='btnSIS_Clear')
		thisImg.src="../images/SIS_Clear.jpg";
	if(thisImg.name=='btnClear1')
		thisImg.src="../images/Clear.jpg";
	if(thisImg.name=='btnSIS_Search1')
		thisImg.src="../images/Search.jpg";
	if(thisImg.name=='btnSIS_Search_n')
		thisImg.src="../images/SIS_Search_n.jpg";
}
//function to get the common menu search elements
function getMenuData(itemNo)
{
	var dm = application.getAttribute("DATAMANAGER");
	var nq = new NamedQuery("GET_MENUITEMARRAY");
	var menuSearch = new Array();
	var arrindex  = 0;
	//if(parseInt(itemNo)<10 && itemNo.toString().substring(0,1) != "0")
	//	itemNo = "0" + itemNo;
	//itemNo = parseInt(itemNo);

	nq.params["menuitemno"] = itemNo;
	rs = dm.executeNamedQuery(nq);
	rsi = rs.iterator();
	//var s = ""
	while (rsi.hasNext())
	{
		menuSearch[arrindex] = new Array(2);
		var rec = rsi.getNext();
		menuSearch[arrindex][0] = rec["value"];
		menuSearch[arrindex][1] = rec["type"];
		arrindex++;
	}
	return menuSearch;
}
//function to get the records into the menu data for contents tree
function getDBData(rsi)
{
	var arr = new Array();
	var arrindex = 0;
	
	while (rsi.hasNext())
	{
		var rec = rsi.getNext();
		
		sct= rec["sct"];
		sc= rec["sc"];
		config= rec["config"];
		serviceitem= rec["serviceitem"];
		serviceitemname= rec["serviceitemname"];
		component= rec["compdesc"];
		comptype= rec["comptype"];
		servcatsub= rec["servcatsub"];
		dtcid=rec["dtcid"];
		sieid= rec["sieid"];
		sympid= rec["sympid"];
		cuid= rec["cuid"];
		cansystem= rec["cansystem"];
		sitqno=rec["sitqno"];
		sortno=rec["sortno"];
		infoid=rec["infoid"];
		title=rec["title"];
		sctid = rec["sct_id"];
		scid = rec["sc_id"];
		configname = rec["configname"];
		compid = rec["compid"];
		comptypeid = rec["comptype_id"];
		multipath = rec["multipath"];
		sub_sc_id = rec["sub_sc_id"];
		tree_sort_no=rec["TREE_SORT_NO"];
		
		arr[arrindex]=new fncArray(sct,sc,config,serviceitem,serviceitemname, dtcid, sympid, cuid,cansystem, component,comptype,servcatsub, sitqno, sieid, sortno, infoid, title,sctid,scid,configname,compid,comptypeid,multipath,sub_sc_id,tree_sort_no);
		arrindex++;
	}
	return arr;
}
//www.nissan-techinfo.com