var allowClose          = true;

function onLoadFunctions(){
}
function onUnloadFunctions(){
}

function changeToHiEndVersion() {
var currentHighlightNew;
  if (currentMatch){
     currentHighlight = currentMatch;
     pos1 = 0;
     pos2a = currentHighlight.lastIndexOf('.');
     currentHighlightNew = currentHighlight.slice(pos1,pos2a);
     pos2b = currentHighlightNew.lastIndexOf('/');
     htmlName = currentHighlight.slice(currentHighlight.lastIndexOf('/')+1,pos2a);
     currentHighlightNew = currentHighlightNew.slice(pos1,pos2b) + "/_highend/xml/" + htmlName;
     xmlMetaNew =currentHighlightNew;
  } else {
     currentHighlight = self.location.href;
     pos1 = currentHighlight.indexOf("/" + confCountryTopic + "/" + confLanguageTopic);
     pos2a = currentHighlight.lastIndexOf('.');
     currentHighlightNew = currentHighlight.slice(pos1,pos2a);
     pos2b = currentHighlightNew.lastIndexOf('/');
     htmlName = currentHighlight.slice(currentHighlight.lastIndexOf('/')+1,pos2a);
     currentHighlightNew = currentHighlightNew.slice(0,pos2b) + "/_highend/xml/" + htmlName;
     xmlMetaNew =currentHighlightNew;
  }

// all Browsers
  if (document.getElementsByTagName('meta')['target-url-swf']) {
    xmlMeta = document.getElementsByTagName('meta')['target-url-swf'].content;
    if (xmlMeta.indexOf('../') != -1) {
      pos1 = xmlMeta.lastIndexOf('../')+2;
      pos2 = xmlMeta.lastIndexOf('.')
      xmlMetaNew = buildValidServerRelativeUrl(xmlMeta.slice(pos1,pos2));
    }
  }



  if(typeof confCountryTopic != 'undefined' && confCountryTopic != null && typeof confLanguageTopic != 'undefined' && confLanguageTopic != null){
    var basePath            = self.location.href.substring(0, self.location.href.indexOf("/" + confCountryTopic + "/" + confLanguageTopic + "/"));

    var countryLanguagePath = basePath + "/" + confCountryTopic + "/" + confLanguageTopic + "/";
    var highendUrl = countryLanguagePath + framesetPageHighend+'?prm_content='+xmlMeta;
    parent.location.href = highendUrl;
  }
}


function buildLinkList(){
  var links=new Array(document.getElementsByTagName('a').length);
  for (var i = 0; i < document.getElementsByTagName('a').length; i++){
    links[i]=document.getElementsByTagName('a')[i].href;
  }
  return links;
}

function highlightBottomNavigation(){
 if(self.name=="frameContent"){
    if(parent.frames[1] && parent.frameBottom.bottomNavigationLoaded==true){
      parent.frameBottom.highlightBottomNavigation(self.location.href);
    } else {
      setTimeout('highlightBottomNavigation()',300);
    }
  }
}

function resetBottomNavigation(){
  if(self.name=="frameContent"){
    parent.frameBottom.resetBottomNavigation(self.location.href);
  }
}


function stringCompare(comparator1, comparator2){
   var shorter=null;
   var longer=null;
   if(comparator1.length > comparator2.length){
     longer=comparator1.toLowerCase();
     shorter=comparator2.toLowerCase();
   } else {
     longer=comparator2.toLowerCase();
     shorter=comparator1.toLowerCase();
   }
   var matchCount=0;
   for(var x=0;x < shorter.length;x++){
     if(shorter.charAt(x)==longer.charAt(x)){
       matchCount++;
     }  else {
       break;
     }
   }
   return matchCount;
}

function buildValidServerRelativeUrl(simpleServerRelativeUrl){
   if(simpleServerRelativeUrl==''){
     return '';
   }
   var validServerRelativeUrl='';
   var simpleSeverrelativeUrlNoParams='';

   if(simpleServerRelativeUrl.indexOf('?')!=-1){
     simpleSeverrelativeUrlNoParams=simpleServerRelativeUrl.substring(0,simpleServerRelativeUrl.indexOf('?'));
  } else {
     simpleSeverrelativeUrlNoParams=simpleServerRelativeUrl;
  }
  if(self.location.href.indexOf('/bmw_edit/') != -1 && simpleSeverrelativeUrlNoParams.indexOf('/bmw_edit/')==-1){
    validServerRelativeUrl ='/bmw_edit'+simpleServerRelativeUrl;
  } else if(self.location.href.indexOf('/bmw_qa/') != -1 && simpleSeverrelativeUrlNoParams.indexOf('/bmw_qa/')==-1){
    validServerRelativeUrl ='/bmw_qa'+simpleServerRelativeUrl;
  } else if(self.location.href.indexOf('/bmw_prod/') != -1 && simpleSeverrelativeUrlNoParams.indexOf('/bmw_prod/')==-1){
    validServerRelativeUrl ='/bmw_prod'+simpleServerRelativeUrl;
  } else {
     validServerRelativeUrl=simpleServerRelativeUrl;
  }
  return validServerRelativeUrl;
}

function getFullPath(basePath,relativePath) {
  var fullPath = basePath.substring(0,(basePath.lastIndexOf("/")+1));
  var regXHostPath = /((^(https{0,1}\:\/\/[^\/]*\/))|(^(file\:\/\/[^\:]*\:\/))|(^([a-z]+\:\\))|(^([a-z]+\:\/))|(^(\\\\))|(^(\/\/)))/i;
  if (regXHostPath.test(relativePath)) {
    fullPath = relativePath;
  } else {
    var regXGoingUp = /(\.\.\/)/g, goingUpArr = [], i;
    if (regXGoingUp.test(relativePath)) {
      goingUpArr = relativePath.match(regXGoingUp);
    }
    for (i=0; i<goingUpArr.length; ++i) {
      fullPath = fullPath.substring(0,(fullPath.lastIndexOf("/",(fullPath.length-2))+1));
    }
    fullPath += relativePath.replace(regXGoingUp,"");
  }
  return fullPath;
}

function setModuleHeader(hasLink) {
 var headerHTML="";
   if(hasLink){
     headerHTML='<a href="javascript:moveMenu();" style="position:relative;display:block;margin-top:1px;">'+moduleHeader+'</a>';
   } else {
    headerHTML='<span style="position:relative;display:block;margin-top:1px;">'+moduleHeader+'</span>';
  }
  if (typeof document.getElementsByTagName('div')['moduleHeaderContainer'] == 'object') {
    writeIntoLayer('moduleHeaderContainer',headerHTML);
    setVisibility('moduleHeaderContainer',1);
  } else {
    moveObject(document.getElementsByTagName('div')['naviClipArea'],null,0);
  }
}

function closeMainNavigation() {
    }




function download(fileUrl) {
  var downloadUrl=buildValidServerRelativeUrl(downloadJSP+'?file='+fileUrl);
  self.location.href=downloadUrl;
}


function writeFramesetTitle(titleText) {
}

function preloader(ticketId) {
  preLoadCounter[ticketId] = 0;
  preload[ticketId] = new Array();
  for(j=0;j<preLoadArray[ticketId].length;j++) {
    preload[ticketId][j]          = new Image();
    preload[ticketId][j].onabort  = function(){loadUpdate(ticketId,j);}
    preload[ticketId][j].onerror  = function(){loadUpdate(ticketId,j);}
    preload[ticketId][j].onload   = function(){loadUpdate(ticketId,j);}
    preload[ticketId][j].src      = preLoadArray[ticketId][j];
  }
}

function loadUpdate(ticketId,imageId) {
  preLoadCounter[ticketId]++;
  if(preLoadCounter[ticketId] == preLoadArray[ticketId].length) {
    preLoadReady(ticketId);
  }
}

function preLoadReady(ticketId) {
}

function showCo2() {
  setVisibility('co2HeaderOn',1);
  setVisibility('co2HeaderOff',0);
  setVisibility('co2body',1);
}

function hideCo2() {
  setVisibility('co2HeaderOn',0);
  setVisibility('co2HeaderOff',1);
  setVisibility('co2body',0);
}

function stopPlayingMp3(){}
