var win = null;

// ===============================================================================================================================

function NewWindow(mypage, myname, w, h, scroll)
{	
	
	if (win && !win.closed) win.close();
	
	

	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	win = window.open(mypage, myname, settings);
	if (win.window.focus) { win.window.focus(); }
}

// ===============================================================================================================================







function getViewport(returnmode)
{
	// Gibt Höhe oder Breite des Viewports zurück
	// returnmode == 1 gibt viewportheight zurück
	// returnmode == 2 gibt viewportwidth zurück
	var viewportwidth;
	var viewportheight;
	 
	// standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof(window.innerWidth) != 'undefined')
	{
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
	 
	// IE6 in standards compliant mode
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	 
	// older versions of IE 
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	
	if (returnmode == 1) return viewportheight;
	else return viewportwidth;
	
}

// ===============================================================================================================================

function setHeightSpacer(myValue, showSky)
{
	// Setzt Höhe für pt.gif
	var spacerHeight;
	var minSkySpacerHeight = 550; // min height if skyscraper is visible
	var myHeight = getViewport(1); // get current viewport height
	myValue = myValue || 238;
	showSky = showSky || 0;
	if (document.all) myValue = myValue - 0; // Wenn IE
	
	if (myHeight > 0)
	{
		spacerHeight = myHeight - myValue;
		if (showSky == 1 && spacerHeight < minSkySpacerHeight) spacerHeight = minSkySpacerHeight;
				
		document.getElementById("hoehenspacer").style.height = spacerHeight + "px";
	}
}

// ===============================================================================================================================

function hideDiv(idDiv) 
{
	document.getElementById(idDiv).style.display = 'none';
}

// ===============================================================================================================================

function showDiv(idDiv) 
{
	document.getElementById(idDiv).style.display = '';
}

	
function showTab(tabname, tabno, maxtabs)
{
	if (document.getElementById)
	{		
		for (var i = 1; i <= maxtabs; i++)
		{
			if (document.getElementById(tabname + i)) document.getElementById(tabname + i).style.display = (tabno == i) ? "block" : "none";
			if (document.getElementById(tabname + i + '_link')) document.getElementById(tabname + i + '_link').className = (tabno == i) ? "atablink" : "tablink";
		}
	}
}

// ===============================================================================================================================

function showHideLanguageDiv(show)
{
	if (document.getElementById)
	{
		c = document.getElementById("current-language");
		h = document.getElementById("current-language-helper");
		l = document.getElementById("current-language-link");
		s = document.getElementById("select-language");
		
		if (show)
		{
			c.style.color = "#003466";
			c.getElementsByTagName("div")[1].style.color = "#01314A";
			c.style.background = "#FE6601 url(/images/layout/bg-nav-main-li-current.gif) no-repeat top left";
			h.style.background = "transparent url(/images/layout/bg-nav-main-li-current-span.gif) no-repeat top right";
			l.style.color = "#003466";
			s.style.display = "block";
		}
		else
		{
			c.style.color = "#E1E1E1";
			c.getElementsByTagName("div")[1].style.color = "#E1E1E1";
			c.style.background = "transparent url(/images/layout/arrow-down-orange.gif) no-repeat right 6px";
			h.style.background = "none";
			l.style.color = "#E1E1E1";
			s.style.display = "none";
		}
	}
}

// ===============================================================================================================================

function showHideDealerLanguageDiv(show)
{
	if (document.getElementById)
	{
		s = document.getElementById("select-language-dealer");
		s.style.display = (show) ? "block" : "none";
	}
}

// ===============================================================================================================================

function check_email(email) 
{

 	var usr    = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
  	var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,6}";
  	var regex  = "^" + usr + "\@" + domain + "$";
  	var rgx    = new RegExp(regex);
  	return rgx.exec(email) ? true : false;
}

// ===============================================================================================================================

function format_fieldcolor(idDiv, showError)
{
	showError = showError | false;
	var errorClass = "fc-error";
	var normalClass = "fc-normal";
	var labelColor = (showError) ? "#CC0000" : "";
	var d = document.getElementById(idDiv);
	var currentClass = d.className;
	var myLabel = "labelfor_" + idDiv;
	
	if (showError)
	{
		var showClass = errorClass;
		var oppClass = normalClass;
	}
	else
	{
		var showClass = normalClass;
		var oppClass = errorClass;
	}
	
	if (currentClass == "" || currentClass == oppClass)
	{
		d.className = showClass;
	}
	else
	{
		var indexOfSpace = currentClass.indexOf(" ");
		if(indexOfSpace == -1)
		{
			d.className = currentClass + " " + showClass;
		}
		else
		{
			var mainClass = currentClass.substring(0, indexOfSpace + 1);
			d.className = mainClass + " " + showClass;
		}
	}
	
	if (document.getElementById(myLabel)) document.getElementById(myLabel).style.color = labelColor;
}

// ===============================================================================================================================

function fieldcolor_normal(idDiv)
{
	format_fieldcolor(idDiv);
}

// ===============================================================================================================================

function fieldcolor_error(idDiv)
{
	format_fieldcolor(idDiv, true);
}

// ===============================================================================================================================
	
function getStyle(el, stylePropJs, stylePropCss)
{
	var obj = document.getElementById(el);
	if (obj.currentStyle) // IE
		var styleValue = obj.currentStyle[stylePropJs];
	else if (window.getComputedStyle) // Mozilla
		var styleValue = document.defaultView.getComputedStyle(obj,null).getPropertyValue(stylePropCss);
	return styleValue;
}

// ===============================================================================================================================

function c24_showToolboxText(textToShow, showOffState)
{
	showOffState = showOffState | 0;
	var el = document.getElementById("toolbox-text");
	el.style.color = (showOffState == 1) ? "#B9B9B9" : "#666666";
	el.innerHTML = textToShow;
}

// ===============================================================================================================================

function c24_showLanguage(showString)
{
	if (showString.indexOf(".gif") != -1)
		{
		showString='<img src="/'+ showString +'" width="100" height="12" border="0" style="margin:1px 0 1px 0;" alt="" />';
		}

	document.getElementById("showlang").innerHTML = (showString != "") ? showString : "Choose your language:";
}

// ===============================================================================================================================

function maildecode (input)
	{
	var output=input;
	output=output.replace(/\|/, '@');
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	return (output);
	}

// ===============================================================================================================================	
	
function writemaillink ($input,$hid)
	{
	$showmail=maildecode($input);
	$showmail=$showmail.replace('@','&#64;');
	$showmail=$showmail.replace(/\./,'&#46;');
	$showmail=$showmail.replace(/\?.*/,'');
	document.write('E-Mail: ');
	document.write ("<a href=\"javascript:makemail('"+$input+"','"+$hid+"')\">");
	document.write($showmail);
	document.write ('</a><br>');
	}

// ===============================================================================================================================
	
function makemail($link,$hid)
	{
	if ($hid>0) mailtocount($hid);
	$link=maildecode($link);
	this.location.href="mailto:"+$link;
	}

// ===============================================================================================================================



function c24_ctbg(el, show)
{
	// CHANGE BACKGROUND TOOLBOX, LANG SELECT DEALER HP
	show = show | false;
	el.style.backgroundColor = (show) ? "#FFF9F5" : "#FFF";
}

// ===============================================================================================================================

ajaxRequest = function(u,f,m,b,h,s)
{
    this.url      = u;
    this.wState   = f || function() { };
    this.method   = m || "GET";
    this.body     = b || null;
    this.headers  = h || false;
    this.sync     = s || true;
    this.abortReq = false;
    
    this.req = (window.XMLHttpRequest) 
           ?
           new XMLHttpRequest()
           :
           ((window.ActiveXObject)
           ?
           new ActiveXObject("Microsoft.XMLHTTP")
           :
           false
           );
    
    this.doRequest = function()
    {
        this.req.open(this.method,this.url,this.sync);
        if (this.headers)
        {
            for (var i=0; i<this.headers.length; i+=2)
            {
                this.req.setRequestHeader(
                    this.headers[i],this.headers[i+1]
                );
            }
        }
        this.req.onreadystatechange = this.wState;
        (!this.abortReq) ? this.req.send(this.body) : this.req.abort();
    }
}

// ===============================================================================================================================

function writeSkyStats(bannerId)
{
	var xmlhttp = new ajaxRequest(
        "../others/ajax_write_sky_stats.htm?extwin=1",
        function()
        {
            var r = xmlhttp.req;
            if (r.readyState == 4)
            {
                var resultString = (r.status == 200) ? r.responseText : "ERROR";
            }
        },
        "POST",
        "bannerid="+bannerId,
        ["Content-Type","application/x-www-form-urlencoded"]
    );
    xmlhttp.doRequest();
}

// ===============================================================================================================================
	

// ADD TO A HREF
function c24addtolink(link,s1)
	{
	link.href=link.href+s1;
	}	
	
	
	