/** Version       : 1.2
  * Last modified : (K. Breynck) 02.03.2004
  * Author        : BBDO InterOne Hamburg (W. Rauch)
  * Copyright     : BMW Group 2002-2004
  *
  * Unique scripting solutions that are provided for BMW Group sites are for use exclusively
  * within BMW Group projects. No other use of these solutions is permitted.
  *
  **/
  


var actualFramesetPath;
var contentFrameSource;

var framesetPage     = "index.jsp";   //Name of the Frameset-Page(s)
var initContentURL;
var allowedDomain     = new Array();
    allowedDomain[0]  = "://www.mini.";
    allowedDomain[1]  = "://projects";
    allowedDomain[2]  = "://ecom.bmwgroup.";
    allowedDomain[3]  = "://ecomi.bmwgroup.";
    allowedDomain[4]  = "://localhost";
    allowedDomain[5]  = "://172.23.56.123";
    allowedDomain[6]  = "://webi.muc";
    allowedDomain[7]  = "://wwwint.muc";
    allowedDomain[8]  = "://siapp8.muc";
    allowedDomain[9]  = "://accessories.mini";
    allowedDomain[10] = "://accessoriesi.mini";
    allowedDomain[11] = "://172.26.3.174";
    allowedDomain[12] = "://212.224.18.233";
    allowedDomain[13] = "://212.224.18.163";
    allowedDomain[14] = "://www.mini-partner.de";
	  allowedDomain[15] = "://mail.bmwdialog.de";
	  allowedDomain[16] = "://172.26.3.122";
	  allowedDomain[17] = "://www.miniunited.";
	  allowedDomain[18] = "://wcms20.bmwgroup.com";
	  allowedDomain[19] = "://secure.mini.com";
	  allowedDomain[20] = "://mini-herbststurm2005-pres.rz.interone.de";
	  allowedDomain[21] = "://mini-herbststurm2005-live.rz.interone.de";
	  allowedDomain[22] = "://originwww.mini.";
	  allowedDomain[23] = "://212.224.18.141";
	  allowedDomain[24] = "://mini-calculator-live.dc.interone.de";
	  allowedDomain[25] = "://liintrab.muc";
	  allowedDomain[26] = "://mini-de-pres.ham.interone.de";
	  allowedDomain[27] = "://originwww-neu.mini.";

var domainIsAllowed;

function checkForFrameset(indexDistanceIndicator) {
  var myPath = self.location.href.split("?")[0];
  var myName = myPath;
  var newLocation ="";

  if(!(parent.frames.length > 2)) {
    if(!isNaN(parseInt(indexDistanceIndicator))) { // Use the indexDistanceIndicator to locate the nearest higher-level frameset
      for (i=0; i <= parseInt(indexDistanceIndicator); i++) {
        myPath = myPath.substr(0,myPath.lastIndexOf("/"));
      }
      myPath     += "/";
      myName      = myName.substring(myPath.length, myName.length);
      newLocation = myPath + framesetPage + "?content=" + myName + escape(self.location.search);
    } else { // Extract the filename and append it to the frameset page in that folder
      myName = myName.substr(myName.lastIndexOf("/")+1,myName.length);
      myPath = self.location.href.split("?")[0];
      myPath = myPath.substr(0,myPath.lastIndexOf("/")+1);
      newLocation = myPath + framesetPage + "?content=" + myName + escape(self.location.search);
    }
    self.location.href = newLocation;
  }
}

function checkNscForFrameset(framesetPath) {
	var urlArray = self.location.href.split("/");
  var tempUrl  = urlArray[0] + '/' + urlArray[1] + '/' + urlArray[2]+'/';
      tempUrl += escape(self.location.href.substr(tempUrl.length,self.location.href.length));
  if(!(parent.frames.length > 2)) {
    top.location.href = framesetPath + '?content=' + tempUrl;
  }
}

function getFramesetPath() {
  var tempSubstr;
  if(location.host) {  // server
    tempSubstr = location.href.substr(location.href.split("?")[0].substr(0,(location.href.split("?")[0].lastIndexOf(location.host) + location.host.length)).length, location.href.length);
    tempSubstr = tempSubstr.split("?")[0].substr(0,(tempSubstr.split("?")[0].lastIndexOf("/")+1));
  } else { // local
    tempSubstr = location.href.split("?")[0];
    tempSubstr = tempSubstr.substr(0,(tempSubstr.lastIndexOf("/")+1));
  }
  return tempSubstr;
}

function pageHandler() {
  actualFramesetPath    = ((contentFramePath.indexOf("://") != -1) ? "" : getFramesetPath());
  contentFramePath      = ((contentFramePath.indexOf(location.host) != -1) ? contentFramePath.split(top.location.host)[1] : contentFramePath);
  contentFrameParam     = (((!location.query.content) && (location.search != "")) ? (location.search + "&" + contentFrameParam.substr(1,contentFrameParam.length)) : contentFrameParam);
  contentFramePath      = (((contentFramePath.indexOf("://") != -1)) ? contentFramePath : (((actualFramesetPath != "") && (contentFramePath.lastIndexOf(actualFramesetPath) != -1)) ? contentFramePath.substr((contentFramePath.lastIndexOf(actualFramesetPath) + actualFramesetPath.length), contentFramePath.length) : contentFramePath));
  contentFrameSource    = ((flashCheckIsActive) ? flashCheckSource + "?contentFrameSource=" + actualFramesetPath + contentFramePath + escape(contentFrameParam) : actualFramesetPath + contentFramePath + contentFrameParam);
  
  if(location.query.content) {
    if(location.query.content.indexOf("://") != -1) {
      for (var i=0; i < allowedDomain.length; i++) {
        if(location.query.content.indexOf(allowedDomain[i]) != -1) {
          domainIsAllowed = true;
          break;
        }
      }
      if(domainIsAllowed) {
        initContentURL = ((flashCheckIsActive) ? flashCheckSource + "?contentFrameSource=" + escape(location.query.content) : location.query.content);
      } else {
        initContentURL = contentFrameSource;
      }
    } else {
      actualFramesetPath = getFramesetPath();
      initContentURL = ((flashCheckIsActive) ? flashCheckSource + "?contentFrameSource=" + actualFramesetPath + escape(location.query.content) : actualFramesetPath + location.query.content);
    }
  } else {
    initContentURL = contentFrameSource;
  }
}












