var countHits_=0;


//**************************
//*** SPAMSCHUTZ ***  
//**************************

function openMailclient(s)
{
	var n=0;
	var r="";
	for(var i=0; i < s.length; i++) {
		n=s.charCodeAt(i);
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(1));
	}

	var subject="Anfrage";
	window.location = "mailto:"+r;
}



// Formularfelder ÃƒÂ¼berprÃƒÂ¼fen

function chkMail(){
	var chkOK = true;
	var chkMail = true;
	var chkEmpty = true;
	var msg = "";

	$$(".chkEmpty").each( function(item){
		if($F(item)=="") {
			chkOK = false;
			chkEmpty = false;
			item.setStyle({backgroundColor: '#FF9999'});
		} else {
			item.setStyle({backgroundColor: '#FFFFFF'});
		}
	} );

	$$(".chkEmail").each( function(item){
                var reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');
                
		if(!reg.test($F(item)))	{
		//if($F(item)=="") {
			chkOK = false;
			chkMail = false;
			item.setStyle({backgroundColor: '#FF9999'});
		} else {
			item.setStyle({backgroundColor: '#FFFFFF'});
		}
	} );

	if(!chkEmpty) msg += ixTransJsempty +"\n";
	if(!chkMail) msg += ixTransJsmail +"\n";
	if(msg!="") alert(msg);
	return chkOK;
}

function fillHiddenField(){
	document.getElementById("spamField").value=document.getElementById("spamStreet").value+document.getElementById("spamPLZ").value
}

//-------- AJAX

function createXMLHttpRequest() 
{
 var req = null;

   try 
   {
     req = new ActiveXObject("MSXML2.XMLHTTP");
   }  

   catch (err_MSXML2) {

     try
     {
       req = new ActiveXObject("Microsoft.XMLHTTP");
     }

     catch (err_Microsoft) {

       if (typeof XMLHttpRequest != "undefined")
         req = new XMLHttpRequest;
     }
   }
   return req;
}



function addHits(ID, product, description)
{	//--- Fügt ein neues Produkt zur "Hitliste" hinzu

	var req=createXMLHttpRequest();
	var body = "product="+escape(product)+"&ID="+escape(ID)+"&description ="+escape(description); 
	req.open("POST", "/php/ajax/addHit.php", false);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(body);
	handleAddHit(req.status, req.responseText);

}

function handleAddHit(status, responseText)
{
	responseText=unescape(responseText); 
	lastHit_=responseText;

	//var  tags = document.getElementById("selektionText").innerHTML;
	//var stripped = tags.replace(/<\/?[^>]+>/gi, '');
	//document.getElementById("selektionText").innerHTML="<a href='detail.php?we_objectID="+ lastHit_+"'>"+stripped +"</a>";
	
}


function deleteHits(ID)
{	//--- Löscht ein Produkt aus der "Hitliste"

	var req=createXMLHttpRequest();
	var body = "ID="+escape(ID); 
	req.open("POST", "/php/ajax/deleteHit.php", false);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(body);
	handleDeleteHit(req.status, req.responseText);
}

function handleDeleteHit(status, responseText)
{
	responseText=unescape(responseText); 
	lastHit_=responseText;
	//document.getElementById("selektionText").innerHTML="<a href='detail.php?we_objectID="+ lastHit_+"'>"+document.getElementById("selektionText").innerHTML+"</a>";
}

function countHits()
{	//--- Zählt die Produkt der "Hitliste"

	var req=createXMLHttpRequest();
	var body = ""; 
	req.open("POST", "/php/ajax/countHits.php", false);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(body);
	handleCountHits(req.status, req.responseText);
}

function handleCountHits(status, responseText)
{
	responseText=unescape(responseText); 
	countHits_= responseText;
}

function firstHit()
{	//--- Zählt die Produkt der "Hitliste"

	var req=createXMLHttpRequest();
	var body = ""; 
	req.open("POST", "/php/ajax/firstHit.php", false);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(body);
	return req.responseText;
}

//----------------------- Produktsuche Volltex


function searchProducts(value, startPath){
	var req=createXMLHttpRequest();
	var body = "value="+escape(value)+"&startPath="+escape(startPath); 
	req.open("POST", "/php/ajax/searchProducts.php", false);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(body);
	handleSearchProducts(req.status, req.responseText);
}

function handleSearchProducts(status, responseText){
	document.getElementById("searchResult").innerHTML=responseText;

	//alert(responseText);
}

//------------------ Ab hier kommen Routinen für die für eine Anfrage zu merkenden Produkte  -----------------------------------------------------
// return hs.htmlExpand(this, {align: \'center\', objectType: \'iframe\', width: \'670\', height: \'500\', preserveContent: false} )
// /xx-en1/newProducts/teaserASP.tmpl
function openMarkedProductsForm(obj) {
	obj.href = obj.href + "&" + encodeURI("markedproducts=fooogooo");
	return hs.htmlExpand(obj, {align: 'center', objectType: 'iframe', width: '670', height: '500', preserveContent: false} );
}

function addProducts(ID, product, url)
{	
	var req=createXMLHttpRequest();
	var body = "product="+escape(product)+"&ID="+escape(ID)+"&url="+escape(url);
	if ($('markedProducts').hasClassName('newProduct')) {body += '&new=1';}
	req.open("POST", "/php/ajax/addProduct.php", false);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(body);
	handleAddProduct(req.status, req.responseText);

}

function handleAddProduct(status, responseText)
{
	responseText=unescape(responseText); 
	document.getElementById("markedProducts"). innerHTML=responseText;

	//var  tags = document.getElementById("selektionText").innerHTML;
	//var stripped = tags.replace(/<\/?[^>]+>/gi, '');
	//document.getElementById("selektionText").innerHTML="<a href='detail.php?we_objectID="+ lastHit_+"'>"+stripped +"</a>";
	
}


function deleteProduct(ID, product, url)
{	
	var req=createXMLHttpRequest();
	var body = "product="+escape(product)+"&ID="+escape(ID)+"&url="+escape(url); 
	req.open("POST", "/php/ajax/deleteProduct.php", false);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(body);
	handleAddProduct(req.status, req.responseText);

}

function handleDeleteProduct(status, responseText)
{
	responseText=unescape(responseText); 

	document.getElementById("markedProducts"). innerHTML=responseText;

	//var  tags = document.getElementById("selektionText").innerHTML;
	//var stripped = tags.replace(/<\/?[^>]+>/gi, '');
	//document.getElementById("selektionText").innerHTML="<a href='detail.php?we_objectID="+ lastHit_+"'>"+stripped +"</a>";
	
}

//-------------------- DIV sichtbar bzw. unsichtbar machen und "Pfeil" ändern


function switchDiv(id, image, rtl)
{
//document.getElementById(id).style.display=="none" || document.getElementById(id).style.display=="" || 

//	alert(image.src.search("symbolClose.jpg"));

	if(rtl){
		if(image.src.search("symbolCloseRtl.jpg")>0){
			document.getElementById(id).style.display="block";
			image.src="/images/symbolOpen.jpg";
		}else{
			document.getElementById(id).style.display="none";
			image.src="/images/rtl/symbolCloseRtl.jpg";
		}
	}else{
		if(image.src.search("symbolClose.jpg")>0){
			document.getElementById(id).style.display="block";
			image.src="/images/symbolOpen.jpg";
		}else{
			document.getElementById(id).style.display="none";
			image.src="/images/symbolClose.jpg";
		}
	}
}

//--------------------- Formularfunktionen - 

function newEntry(popup, name, wert)
{
	var NeuerEintrag = new Option(name, wert, false, false);
	var obj=eval("document.branchen."+popup);	
	var pos=eval("document.branchen."+popup+".options.length");	
	obj.disabled=""; 
	obj.options[pos]=NeuerEintrag;	
}


//-------------------- Stringfunktionen

function str_replace(strsearch, strreplace, haystack)
{
	// Autor : Thomas B?chler
	// Erstellt : 13.04.2004
	// Kommentar : Ersetzt alle strsearch innerhalb haystack durch strreplace

	if ((haystack == null) || (strsearch == null))
	{
		return null;
	}
   	
   	if ((haystack.length == 0) || (strsearch.length == 0))
   	{
   		return haystack;
   	}

    if ((strreplace == null) || (strreplace.length == 0))
    { 
    	strreplace = "";
    }

    var len_strsearch = strsearch.length;
    var len_strreplace = strreplace.length;
    var Pos = haystack.indexOf(strsearch, 0);

    while (Pos >= 0)
    {
    	haystack = haystack.substring(0, Pos) + strreplace + haystack.substring(Pos + len_strsearch);
    	Pos = haystack.indexOf(strsearch, Pos + len_strreplace);
    }
    
  	//  alert(haystack);
    
    return haystack;
}


function randomNumber(Min, Max){
	return Math.floor(Min+(Max-Min+1)*(Math.random()));
}

//----------------------------------------------------------------------------------------------- Fensterfunktionen

function downloadExcelFile(file, info) //--------------- Zeigt einen Downloadlink und evtl. Informationen dazu in einem neuen Fensetr 
{
	var neues_fenster = window.open('', "Window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=350,height=200,screenX=10,screenY=10,top=10,left=10");
	neues_fenster.document.open();

	var content;

	content="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
	content+="<html xmlns='http://www.w3.org/1999/xhtml'>";

	content+="<head>";
		content+="<meta http-equiv='content-type' content='text/html;charset=utf-8' />";
		content+="<title>Download file</title>";
		content+="<style type='text/css' media='all'><!--";
		content+="body { color: #424145; font-size: 12px; font-family: Arial, Helvetica; }";
		content+="h2 { font-size: 14px; }";
		content+="--></style>";
	content+="</head>";

	content+="<body>";
		content+="<h2>Downlod file</h2>";
		content+="<p>"+info+"</p>";
		content+="<a href='"+file+"'>Download</a>";
	content+="</body>";
content+="</html>";


	with(neues_fenster.document)
	{
		writeln(content);
	}

	neues_fenster.document.close();
	neues_fenster.focus();

}	



function openSampleSitePath(sampleSitePath) //--------------- Zeigt einen Downloadlink und evtl. Informationen dazu in einem neuen Fenster
{
	var neues_fenster = window.open('', "Window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=400,screenX=10,screenY=10,top=10,left=10");
	neues_fenster.document.open();
	var content;

	content="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
	content+="<html xmlns='http://www.w3.org/1999/xhtml'>";

	content+="<head>";
		content+="<meta http-equiv='content-type' content='text/html;charset=utf-8' />";
		content+="<title>Show sample</title>";
		content+="<style type='text/css' media='all'><!--";
		content+="body { color: #424145; font-size: 12px; font-family: Arial, Helvetica; }";
		content+="h2 { font-size: 14px; }";
		content+="--></style>";
	content+="</head>";

	content+="<body>";
		content+=sampleSitePath;
		content+="<h2>Loading sample</h2>";
		content+="<script type='text/javascript'>window.location.href='"+sampleSitePath+"'</script>";
	content+="</body>";
content+="</html>";


	with(neues_fenster.document)
	{
		writeln(content);
	}

	neues_fenster.document.close();
	neues_fenster.focus();

}	



function openServicePage(servicePagePath, sessionName, sessionID) //--------------- Zeigt Service-Informationen
{
	var neues_fenster = window.open('', "Window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=600,screenX=10,screenY=10,top=10,left=10");
	neues_fenster.document.open();
	var content;

	content="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
	content+="<html xmlns='http://www.w3.org/1999/xhtml'>";

	content+="<head>";
		content+="<meta http-equiv='content-type' content='text/html;charset=utf-8' />";
		content+="<title>Show sample</title>";
		content+="<style type='text/css' media='all'><!--";
		content+="body { color: #424145; font-size: 12px; font-family: Arial, Helvetica; }";
		content+="h2 { font-size: 14px; }";
		content+="--></style>";
	content+="</head>";

	content+="<body>";
		content+=servicePagePath;
		content+="<h2>Loading Page</h2>";
		content+="<script type='text/javascript'>window.location.href='"+servicePagePath+"?"+sessionName+"="+sessionID+"'</script>";
	content+="</body>";
content+="</html>";


	with(neues_fenster.document)
	{
		writeln(content);
	}

	neues_fenster.document.close();
	neues_fenster.focus();

}	


function openToolNavigation(Site, close) //--------------- Zeigt die Links für den REDAKTEUR ZU DEN VERSCHIEDENEN TOOLS 
{
	var newWindow=window.open("", "popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=400,screenX=10,screenY=10,top=10,left=10");
	newWindow.document.open();
	var content;

	content="<h2>Translations</h2>";
	content+="<a href='http://"+mainDomain_+"/"+Site+"/_tools/live/translationMenue.php'>Menue translation</a><br/>";
	content+="<a href='http://"+mainDomain_+"/"+Site+"/_tools/live/generalTranslations.php'>General translations</a><br/>";
	content+="<a href='http://"+mainDomain_+"/"+Site+"/_tools/live/createAllPdfs.php'>Generate PDFs for all products of the current language</a><br/>";

//path="/"+Site+"/_tools/translationFinder.php";
//content+="<a href='javascript:opener.document.location.href=\""+path+"\"'>Test</a>";

	if(close)
		self.close()

	newWindow.document.write(content);
	newWindow.document.close();
	newWindow.focus();
}

function openToolNavigationOld(Site, close) //--------------- Zeigt die Links für den REDAKTEUR ZU DEN VERSCHIEDENEN TOOLS 
{
	var newWindow=window.open("", "popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=400,screenX=10,screenY=10,top=10,left=10");
	newWindow.document.open();
	var content;

	content="<h2>Translations</h2>";
	content+="<a href='http://"+mainDomain_+"/"+Site+"/_tools/live/translationMenue.php'>Menue translation</a><br/>";
	content+="<a href='http://"+mainDomain_+"/"+Site+"/_tools/live/generalTranslations.php'>General translations</a><br/>";
	content+="<a href='http://"+mainDomain_+"/"+Site+"/_tools/live/translation.php'>Application/Group translations</a><br/>";
	content+="<a href='http://"+mainDomain_+"/"+Site+"/_tools/live/translationRotors.php'>Rotor translations</a><br/>";

	content+="<a href='http://"+mainDomain_+"/"+Site+"/_tools/live/createAllPdfs.php'>Generate PDFs for all products of the current language</a><br/>";

	if(close)
		self.close()

	newWindow.document.write(content);
	newWindow.document.close();
	newWindow.focus();
}


function zoom_seite(pfad, x, y) //--------------- ?ffnet eine bereits vorhandene HTML-Datei in definierter gr??e
{
	var fenster=window.open(pfad, "Window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+x+" ,height="+y+" ,screenX=10,screenY=10,top=10,left=10");
}


function showMaxVideo(thisobj, width, height, id) {
  hs.htmlExpand(thisobj, { objectType: 'iframe', width: width,height: height+10, wrapperClassName: 'video-lightbox', align: 'center', preserveContent: false } );
  stopMinVideo(id);    
  return false;            
}

function stopMinVideo(id) { if(document.getElementById(id)) document.getElementById(id).SetVariable("player:jsStop", ""); }
