var x,y;

function popUp(url,titel,width,height) {
	window.open(url,titel,'width='+width+',height='+height+',screenX='+getX(width)+',screenY='+getY(height)+',left='+getX(width)+',top='+getY(height)+',scrollbars=auto, resizable=yes, status=yes'); 
}

function getX(width) {
	x = ((window.screen.width-width)/2);
	return x;
}
			
function getY(height) {
	y = ((window.screen.height-height)/2);
	return y;			
}

function finishOrder(finishOrderURL){
	//alert(window.opener);
	//if (! (window.focus && window.opener)){
	//if(window.opener != null){
	if(window.opener && !window.opener.closed){
		//alert('Parent found');
		window.opener.focus();
		window.opener.location=finishOrderURL;
		//alert('close child window');
		window.close();
	}
	else{
		//alert('No parent found');
		window.location=finishOrderURL;
		window.moveTo(0, 0);
		window.resizeTo(window.screen.width, window.screen.height);
	}
}

function checkShowDownloadBox(strLangId,strType){
  //shows or hides a download box in cms mode
  var strRequestedLang="en";
  var strQuerystring=location.search;

  if(strQuerystring.indexOf("lang=")>1){
    strRequestedLang=strQuerystring.replace(/.*lang=(..).*/,"$1");
  }
  if(strRequestedLang==strLangId || strLangId==''){
    //display the box
    //alert('show '+strLangId+' download box')
  }else{
    //hide the box using comments
    //alert('hide '+strLangId+' download box')
    if(strType=='start'){
      document.write('<div style="display:none">');
    }else{
      document.write('</div>');
    }
  }
}

function showDownloadLanguage(){
  //reloads the page with a lang querystring parameter corresponding to the chosen downloads language
  var strSelectedLanguage=document.selectLanguage.downloadsLanguage.options[document.selectLanguage.downloadsLanguage.selectedIndex].value;
  var strNewUrl="";
  strCurrentUrl=location.href;
  
  //replace lanuage if already present in url
  if(strCurrentUrl.indexOf('lang=')>0){
    strNewUrl=strCurrentUrl.replace(/^(.*lang=)..(.*)/,"$1"+strSelectedLanguage+"$2")
  }else{
    if(strCurrentUrl.indexOf('?')>0){
    	strNewUrl=strCurrentUrl+"&lang="+strSelectedLanguage;
	  }else{
	  	strNewUrl=strCurrentUrl+"?lang="+strSelectedLanguage;
		}
  }
  location.replace(strNewUrl);
  
  //alert(strSelectedLanguage+" - "+strCurrentUrl+" - "+strNewUrl);  
}

function correctLangDropDown(){
  if(document.selectLanguage){
    //selects the correct item in the laguage drop down list and removes duplicate values
    var strRequestedLang="en";
    var strQuerystring=location.search;
    var strCurrentLangId="";
    var i=0;
    var strLangFound=",",strLangSearch;
    var arrOptionsIndexToRemove=new Array();
    /**/
    if(strQuerystring.indexOf("lang=")>1){
      strRequestedLang=strQuerystring.replace(/.*lang=(..).*/,"$1");
    }
    //find duplicate vaules from the dropdown list
    for (i=0;i<document.selectLanguage.downloadsLanguage.options.length;i++){
      strCurrentLangId=document.selectLanguage.downloadsLanguage.options[i].value;      
      strLangSearch=","+strCurrentLangId+",";
      //alert("- strLangFound="+strLangFound+"\n- strLangSearch="+strLangSearch+"\n- strLangFound.indexOf(strLangSearch)="+strLangFound.indexOf(strLangSearch));
      if(strLangFound.indexOf(strLangSearch)>=0){
        //duplicate value - store the index in an array
        //alert("remove "+strCurrentLangId);
        arrOptionsIndexToRemove.push(i);
      }else{
        strLangFound+=strCurrentLangId+","; 
      }      
    }
    
    //remove values
    for (i=0;i<arrOptionsIndexToRemove.length;i++){
      var intIndexToRemove=arrOptionsIndexToRemove[i]-i;
      //alert(intIndexToRemove);
      document.selectLanguage.downloadsLanguage.options[intIndexToRemove]=null;
    }  
    
    //select the correct item in the drop down list
    for (i=0;i<document.selectLanguage.downloadsLanguage.options.length;i++){
      strCurrentLangId=document.selectLanguage.downloadsLanguage.options[i].value;
      if(strCurrentLangId==strRequestedLang){
        document.selectLanguage.downloadsLanguage.selectedIndex=i;
      }
    }    
  }
}

function openAssetWindow(theURL,winName,features, myWidth, myHeight) { //v3.0
	isCenter="true";
	if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2-10;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
