var New_Window=new Object();
function gupGoal( name , checkstring )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( checkstring );
  if( results == null )
    return "";
  else
    return results[1];
}
//-----------------------------------------------------------------------
// Change Link ('Link','name','tools','root')
//-----------------------------------------------------------------------
function Hib_Open_Link(realUrl,Name,fenster,woher) {
	try {
		goal = gupGoal('goal', realUrl);		
		if (piwikid != 0) {
			
			if (goal != "") {
					
					
					try {
						var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", piwikid);
						piwikTracker.trackPageView();
						piwikTracker.enableLinkTracking();
						piwikTracker.trackGoal(parseInt(goal)); 

					} catch( err ) {}					
					
				}
				
		}
		if (goal != "") {
				realUrl = realUrl.replace('&goal='+goal,'');
				realUrl = realUrl.replace('?goal='+goal,'');
		}
	}
	catch (E) {
		//do nothing
	}		
    var std_tools = 'location=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=800,height=600';
    if (realUrl.indexOf('.pdf') != -1  && (fenster == '' || fenster == '-')) fenster = std_tools;
    //http://w3.autohaus.at/Haendler/A00xxx/?dlr&id=news&news_url=Haendler/A00xxx/ge/hdlr/eigeneseiten/A00xxx_A_120092652998.html
    if (realUrl.indexOf('/eigeneseiten') != -1 && (fenster == '' || fenster == '-') && woher == 'page') {
    	if (parent.frames.length == 0) { 
    		if (realUrl.indexOf('?dlr&id=news&news_url') == -1) realUrl = realUrl.substr(0,17) + '?dlr&id=news&news_url='+ realUrl
    	}
    	//alert(realUrl);
    }	
    	
    if (realUrl.indexOf('?') != -1) {
    	zwLink = realUrl.substr(realUrl.indexOf('?'))
    	aktloc = this.location.toString();
    	teile_akt = aktloc.split('/');
    	pretty_gruppenurl = 'false';
   		long_pretty_gruppenurl = 'false';  	
    	if (teile_akt[3] != 'Haendler') pretty_gruppenurl = 'true';
    	if ((teile_akt[3] == 'autohaus') || (teile_akt[3] == 'nyitolap') || (teile_akt[3] == 'domov')) pretty_gruppenurl = 'false';
    	if  ((teile_akt[4] == 'autohaus') || (teile_akt[4] == 'nyitolap') || (teile_akt[4] == 'domov')) { 
    		pretty_gruppenurl = 'true';
    		long_pretty_gruppenurl = 'true';
    	}
    	if (((aktloc.indexOf('/autohaus/Haendler/') != -1) || (aktloc.indexOf('/domov/Haendler/') != -1) || (aktloc.indexOf('/nyitolap/Haendler/') != -1))&& (pretty_gruppenurl == 'false')){ 
    		newloc_parts = aktloc.split('autohaus/');
    		if (newloc_parts.length == 1) newloc_parts = aktloc.split('domov/');
    		if (newloc_parts.length == 1) newloc_parts = aktloc.split('nyitolap/');
    		this.location = newloc_parts[0] + newloc_parts[1] + realUrl;
    		return;
    		}
    	if ((long_pretty_gruppenurl == 'true') && (pretty_gruppenurl == 'true') && (zwLink == '?gebrauchtwagen' || zwLink == '?weltauto')) {
    		newloc_parts = aktloc.split('autohaus/');
    		if (newloc_parts.length == 1) newloc_parts = aktloc.split('domov/');
    		if (newloc_parts.length == 1) newloc_parts = aktloc.split('nyitolap/');    		
    		this.location = newloc_parts[0] +  realUrl;
    		return;    		
    	}
	    if (zwLink == '?gebrauchtwagen' || zwLink == '?weltauto') {
	    	this.location = realUrl;
	    	return;
	    }
	    if ((realUrl.indexOf('?dlr&') != -1) || (realUrl.indexOf('?KONTID') != -1)) {
	    	this.location = realUrl;
	    	return;
	    }
	}    
    if (realUrl.indexOf('SVC=MAB') != -1) { 
    	std_tools = 'status=no,toolbar=no,scrollbars=yes,resizable=yes,width=435,height=210';
    	realUrl = realUrl.replace("STYLE=VW","STYLE=VWNEU");
    	realUrl = realUrl.replace("STYLE=LNF","STYLE=VWNEU");
    }
    if (realUrl.indexOf('/Hdlzip/') != -1) { 
    	std_tools = 'status=no,toolbar=no,scrollbars=yes,resizable=yes,width=950,height=650';
    	realUrl = realUrl.replace("STYLE=VW","STYLE=VWNEU");
    	realUrl = realUrl.replace("STYLE=LNF","STYLE=VWNEU");
    }	
    if (realUrl.indexOf('/Haendler') == -1 && (fenster == '' || fenster == '-')) fenster = std_tools;
    if (realUrl.indexOf('Parameter=SENDROADMAP') != -1) fenster = std_tools;
    if (fenster != '' && fenster != '-') {
        if(New_Window.closed == false) New_Window.close();
        New_Window = window.open(realUrl,Name,fenster);
        New_Window.focus();
    }else{
        this.location = realUrl;
    } 
}
