//context.js created on 5/23/05. Used of finding the ancestor of a window where the data frame is loaded.
function getRootWindow(win)
{
  var rootWin = getHighestParent(win)  
  return rootWin;
}

function getHighestParent(win)
{
  var curWin = win;
  var curParent = curWin.parent;
  while(curWin.parent != curWin)
  {
    curWin = curWin.parent;
  }
  return curWin;
}

function _request()
{
  this.paramArray = new Array();

  var tmpStr = location.search;
  if (tmpStr.indexOf("?") != -1) {
    tmpStr = tmpStr.substring(tmpStr.indexOf("?")+1);
    var tmpArray = new Array();
    if (tmpStr.match("%26")) {

      tmpArray = tmpStr.split("%26");
    } else {

      tmpArray = tmpStr.split("&");
    }
    for (i in tmpArray) {
      var param = tmpArray[i].split("=");
      if (param[0] != "") {
        this.paramArray[param[0]] = param[1];
      }
    }
  }

  this.getParameter = function(name) {
    if (!this.paramArray[name]) {
      return null;
    }
    return this.paramArray[name];
  }
}

function AttributeContainer()
{
 this.getAttribute = function(name)
 {
	
	if (name=="PagesOpened"){return this.PagesOpened;}
	if (name=="nqData"){return this.nqData;}
	if (name=="itemNo"){return this.itemNo;}
	if (name=="sisnumber"){return this.sisnumber;}
	if (name=="menuId"){return this.menuId;}
	if (name=="PageOpenMode"){return this.PageOpenMode;}
	if (name=="OpenNewWindow"){return this.OpenNewWindow;}
	if (name=="nqCompData"){return this.nqCompData;}
	if (name=="sie_info_id"){return this.sie_info_id;}
	if (name=="DATAMANAGER"){return this.DATAMANAGER;}
	if (name=="URL"){return this.URL;}
	if (name=="vin"){return this.vin;}

   return null;
 }
 this.setAttribute = function(name, value)
 {
 	
 	if (name=="PagesOpened"){this.PagesOpened=value;}
 	if (name=="nqData"){this.nqData=value;}
 	if (name=="itemNo"){this.itemNo=value;}
 	if (name=="sisnumber"){this.sisnumber=value;}
 	if (name=="menuId"){this.menuId=value;}
 	if (name=="PageOpenMode"){this.PageOpenMode=value;}
 	if (name=="OpenNewWindow"){this.OpenNewWindow=value;}
 	if (name=="nqCompData"){this.nqCompData=value;}
 	if (name=="sie_info_id"){this.sie_info_id=value;}
	if (name=="DATAMANAGER"){this.DATAMANAGER=value;}
	if (name=="URL"){this.URL=value;}
	if (name=="vin"){this.vin=value;}


 }
 this.removeAttribute = function(name)
 {
 	if (name=="PagesOpened"){this.PagesOpened=null;}
 	if (name=="nqData"){this.nqData=null;}
 	if (name=="itemNo"){this.itemNo=null;}
 	if (name=="sisnumber"){this.sisnumber=null;}
 	if (name=="menuId"){this.menuId=null;}
 	if (name=="PageOpenMode"){this.PageOpenMode=null;}
 	if (name=="OpenNewWindow"){this.OpenNewWindow=null;}
 	if (name=="nqCompData"){this.nqCompData=null;}
 	if (name=="sie_info_id"){this.sie_info_id=null;}
	if (name=="DATAMANAGER"){this.DATAMANAGER=null;}
	if (name=="URL"){this.URL=null;}
	if (name=="vin"){this.vin=null;}
 }
}

/**Added on 2006/01/12 for removing Window dependency **/
function copy_object(src,dest)
{
	dest.setAttribute("PagesOpened",src.getAttribute("PagesOpened"));
	dest.setAttribute("nqData",src.getAttribute("nqData"));
	dest.setAttribute("itemNo",src.getAttribute("itemNo"));
	dest.setAttribute("sisnumber",src.getAttribute("sisnumber"));
	dest.setAttribute("menuId",src.getAttribute("menuId"));
	dest.setAttribute("PageOpenMode",src.getAttribute("PageOpenMode"));
	dest.setAttribute("OpenNewWindow",src.getAttribute("OpenNewWindow"));
	dest.setAttribute("nqCompData",src.getAttribute("nqCompData"));
	dest.setAttribute("sie_info_id",src.getAttribute("sie_info_id"));
	dest.setAttribute("URL",src.getAttribute("URL"));
	dest.setAttribute("vin",src.getAttribute("vin"));
}

var application = new AttributeContainer();
var session = new AttributeContainer();

/**Modified on 2006/01/12 for removing Window dependency **/
try
{
	if (window.opener!=null && window.opener.top!=null && window.opener.top.name == "ESMWIN" ) 
	{
//For first SIE opened from SIE list page
//		alert("context_sie.js -> SIE List page ");
		copy_object( window.opener.application, application );
		copy_object( window.opener.session,session );
	}
	else 
	{
//For SIEs opened from other SIEs
//		alert("context_sie.js -> SIE opened from another SIE.");
		copy_object( window.opener.application, application );
		copy_object( window.opener.session,session );
	}


}
catch(e)
{
//For SIE opened in Overwrite mode with root parent closed 
//	alert("SIE opened in Overwrite mode with root parent closed ");
	copy_object( window.parent.application, application );
	copy_object( window.parent.session,session );	
}

//Create new DataManager and re-load data in each SIE page	
	var dm=new DataManager();
	dm.setTable("SIE", "../data/allsie.xml");
	dm.setTable("SISCONFIG","../data/sis-config.xml");
	dm.setTable("SITQ","../data/s_sitq.xml");
	dm.setTable("SI","../data/s_si.xml");
	application.setAttribute("DATAMANAGER",dm);

var request = new _request();

