function popUp(link, w, h)
{
	left_val=(screen.width-w)/2;
	top_val=(screen.height-h)/2;
	attributes="width="+w+",height="+h+",top="+top_val+",left="+left_val+",menubar=no,resizable=yes,scrollbars=yes";
	window.open(link,"_blank",attributes)
}

function PreLoadImages()
{
	var objects=PreLoadImages.arguments;
	var Img=new Array(objects);

	for(var i=0; i<objects.length; i++)
	{
		Img[i]=new Image();
		Img[i].src=objects[i];
	}
}

function transformValue(text)
 {
  while (text.search(/\*.+/) != -1)
  {
   text = text.replace("*"," ");
  }
  while (text.search(/\+.+/) != -1)
  {
   text = text.replace("+"," ");
  }
  
  while (text.search(/\%.+/) != -1)
  {
   text = text.replace("%"," ");
  }
  while (text.search(/\?.+/) != -1)
  {
   text = text.replace("?"," ");
  }
  text = trim(text);
  text = "*"+text+"*";
 
  return text;
  
 }

 function trim(s) 
 {
   while (s.substring(0,1) == ' ')
   {
     s = s.substring(1,s.length);
   }
   while (s.substring(s.length-1,s.length) == ' ')
   {
     s = s.substring(0,s.length-1);
   }
   return s;
 }

function openLoginPopUp(language)
{
	act_url=location.href;
	act_url=act_url.replace("http://", "https://");
	act_url=act_url.substring(0,act_url.lastIndexOf("/")+1);
	if (act_url.indexOf("hs.xsl")<0) //Seite wird mit http://..../cps/rde/xchg gestartet
	{
		act_url=act_url+"xchg/br-automation_com/hs.xsl/";
	}
	act_url=act_url+"login_"+language+"_HTML.htm";
	popUp(act_url, 560, 420);
}

function openLoginPopUpFromProductcatalogue(language)
{
	act_url=location.href;
	act_url=act_url.replace("http://", "https://");
	act_url=act_url.substring(0,act_url.lastIndexOf("/"));
	act_url=act_url.substring(0,act_url.lastIndexOf("/"));
	act_url=act_url.substring(0,act_url.lastIndexOf("/")+1);
	act_url=act_url+"br-automation_com/hs.xsl/login_"+language+"_HTML.htm";
	popUp(act_url, 560, 420);
}

function WriteMenu()
{
}

function ChangeURL(actURL, paramName, paramValue)
{
	start=actURL.indexOf(paramName);
	temp=actURL.substring(start);
	start=start+temp.indexOf("=")+1;
	temp=actURL.substring(start);
	end=temp.indexOf("&");
	newURL=actURL.substring(0,start)+paramValue+actURL.substring(start+end);
	return newURL;
}

function validateAutomationLetterNew(paramLinkToInvalid)
{
	var email_address;
	var valid;  
	email_address = window.document.getElementById("newsletter_mail").value;        
	valid=true;
	var spl = email_address.split("@");
	if(spl.length!=2)
	{
		valid=false;
	}
	else
	{
	if(spl[0].length<2)
	  {
	       valid=false;
	  }
	  var spl_right = spl[1].split(".");
	  if(spl_right.length<2)
	  {
	       valid=false;
	  }
	  else
	  {
		  if(spl_right[0].length<2)
		  {
		       valid=false;
		  }
		  if(spl_right[1].length<2)
		  {
		       valid=false;
		  }
	 }
	}
	if (valid)
	{
	 window.document.getElementById("automationletter").submit();
	}
	else
	{
	 // location.href="<!IoRangeList><%li_invalid%><!/IoRangeList>";         
	 location.href=paramLinkToInvalid;
	} 
}     

/********        Code, um mit Enter den Login-Button zu betaetigen **********/
function keydownhandler_sernr(e) { 
	var keycode = document.all ? event.keyCode : e.which; 
	if ((""+keycode)=="13") { 
	    if (document.styleSheets && document.all) //ie
		shiftPressed = window.event.shiftKey;
	    if (document.layers) //ns4
		shiftPressed = e.modifiers & Event.SHIFT_MASK;
	    if (document.getElementById && !document.all) //ns6
		shiftPressed = e['shiftKey'];
	    if (!(shiftPressed)) 
	    {

	    }
	} 
} 
function keydownhandler_matnr(e) { 
	var keycode = document.all ? event.keyCode : e.which; 
	if ((""+keycode)=="13") { 
	    if (document.styleSheets && document.all) //ie
		shiftPressed = window.event.shiftKey;
	    if (document.layers) //ns4
		shiftPressed = e.modifiers & Event.SHIFT_MASK;
	    if (document.getElementById && !document.all) //ns6
		shiftPressed = e['shiftKey'];
	    if (!(shiftPressed)) 
	    {
		document.getElementById('modellnummer').value=transformValue(document.getElementById('modellnummer_input').value);       
	    }
	} 
} 
function keydownhandler_search_all(e) { 
	var keycode = document.all ? event.keyCode : e.which; 
	if ((""+keycode)=="13") { 
	    if (document.styleSheets && document.all) //ie
		shiftPressed = window.event.shiftKey;
	    if (document.layers) //ns4
		shiftPressed = e.modifiers & Event.SHIFT_MASK;
	    if (document.getElementById && !document.all) //ns6
		shiftPressed = e['shiftKey'];
	    if (!(shiftPressed))
	    {
		document.getElementById('search').value=transformValue(document.getElementById('search').value); 
	    }
	} 
} 

function changeBGcolor(id,color)
{	//
	if (document.getElementById && document.getElementById(id))
	{
		document.getElementById(id).style.background = color;
		return true;
	}
	else if (document.layers && document.layers[id])
	{
		document.layers[id].bgColor = color;
		return true;
	}
}

function formatFileSize(size_in_bytes, language)
{
    var fs = size_in_bytes;
    var fsString="0 Bytes";

    if (fs < 1024)
    {
        fsString = fs + " Bytes";
    }
    else
    {
        if (fs < 1048576)
        {
          fsString = (fs / 1024)+"";
          var kommaIndex=fsString.indexOf(".");
          if ((kommaIndex>0) && (kommaIndex<fsString.length))
          {
            fsString=fsString.substring(0, kommaIndex+2);
          }
          fsString = fsString + " kB";
        }
        else 
        {
            if (fs < 1073741824)
            {
                fsString = (fs / 1048576) + "";
                var kommaIndex=fsString.indexOf(".");
				if ((kommaIndex>0) && (kommaIndex<fsString.length))
				{
					fsString=fsString.substring(0, kommaIndex+2);
				}
				fsString = fsString + " MB";
            }
            else
            {
                fsString = (fs / 1073741824) + "";
                var kommaIndex=fsString.indexOf(".");
				if ((kommaIndex>0) && (kommaIndex<fsString.length))
				{
					fsString=fsString.substring(0, kommaIndex+2);
				}
				fsString = fsString + " GB";
            }
        }
    }
    return fsString;
}

function formatDate(date, language)
{
	var formatedDate="";
	if (language=="DEU")
	{
		formatedDate=date.substring(6,8)+"."+date.substring(4,6)+"."+date.substring(0,4);
		
	}
	else
	{
		formatedDate=date.substring(6,8)+"/"+date.substring(4,6)+"/"+date.substring(0,4);
	}
	return formatedDate;
}