function showMe(text, ev) {
var theDiv = document.getElementById('showMeDiv');
theDiv.scrollTop = 0;
theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
theDiv.innerHTML = text;
theDiv.style.visibility = 'visible';
theDiv.style.width = "250px";
var wid, hei, dWid, dHei;
if (window.innerWidth) {
wid = window.innerWidth;
hei = window.innerHeight;
}
else {
wid = document.body.clientWidth;
hei = document.body.clientHeight;
}
wid -= 15;

dWid = theDiv.clientWidth;
dHei = theDiv.clientHeight;
if (ev.clientX + dWid > wid)
theDiv.style.left = (parseInt(theDiv.style.left+document.documentElement.scrollTop) - dWid - 30) + "px";
if (ev.clientY + dHei > hei)
theDiv.style.top = (parseInt(theDiv.style.top+document.documentElement.scrollTop) - dHei) + "px";
}

var sDir = 5;
var tId;
var runDelay = 20;
var scrollVar;
var stillScroll;


function hideMe() {
var theDiv = document.getElementById('showMeDiv');
theDiv.style.visibility = 'hidden';
stillScroll = false;
if (tId)
clearTimeout(tId);
}

function moveMe(ev) {
var theDiv = document.getElementById('showMeDiv');
theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
var wid, hei, dWid, dHei;
if (window.innerWidth) {
wid = window.innerWidth;
hei = window.innerHeight;
}
else {
wid = document.body.clientWidth;
hei = document.body.clientHeight;
}
wid -= 15;

dWid = theDiv.clientWidth;
dHei = theDiv.clientHeight;

if (ev.clientX + dWid > wid)
theDiv.style.left = (parseInt(theDiv.style.left) - dWid - 30) + "px";

if (ev.clientY + dHei > hei)
theDiv.style.top = (parseInt(theDiv.style.top) - dHei) + "px";
}

function sizeMe(x) {
var theDiv = document.getElementById('showMeDiv');
if (x != '')
theDiv.style.width = x + 'px';
else
theDiv.style.width = '';
theDiv.style.height = '';
}

function scrollMe() {
scrollVar = 0;
stillScroll = true;
sDir = 5;
nextScrollStep();
var theDiv = document.getElementById('showMeDiv');
}

function nextScrollStep() {
var theDiv = document.getElementById('showMeDiv');

runDelay = 20;

theDiv.scrollTop = scrollVar;
scrollVar += sDir;

if (scrollVar <= 0) {
scrollVar = 0;
sDir = -sDir;
runDelay = 1500;
}

if (scrollVar >= theDiv.scrollHeight - parseInt(theDiv.style.height) +25 ) {
scrollVar = theDiv.scrollHeight - parseInt(theDiv.style.height) + 25;
sDir = -sDir;
runDelay = 1500;
}

if (stillScroll)
tId = setTimeout('nextScrollStep()', runDelay);
}

/*  Show me DIV   -    END*/
function isValidEmail(email, required) {
if (required==undefined) {   // if not specified, assume it's required
required=true;
}
if (email==null) {
if (required) {
return false;
}
return true;
}
if (email.length==0) {
if (required) {
return false;
}
return true;
}
if (! allValidChars(email)) {  // check to make sure all characters are valid
return false;
}
if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
return false;
} else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
return false;
} else if (email.indexOf("@") == email.length) {  // @ must not be the last character
return false;
} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
return false;
} else if (email.indexOf(".")+1 == email.length) {  // . must not be the last character
return false;
}
return true;
}

function allValidChars(email) {
var parsed = true;
var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
for (var i=0; i < email.length; i++) {
var letter = email.charAt(i).toLowerCase();
if (validchars.indexOf(letter) != -1)
continue;
parsed = false;
break;
}
return parsed;
}

function allValidUsernameChars(username){
var parsed = true;
var validchars = "abcdefghijklmnopqrstuvwxyz0123456789_";
for (var i=0; i < username.length; i++) {
var letter = username.charAt(i).toLowerCase();
if (validchars.indexOf(letter) != -1)
continue;
parsed = false;
break;
}
return parsed;
}

function AutoScroll(){
alert(document.body.clientHeight);
document.body.scrollLeft=0;
document.body.scrollTop=0;
if (1600-document.body.clientWidth>0){
document.body.scrollLeft +=Math.round((1600-document.body.clientWidth)/2);
}

if (1000-document.body.clientHeight>0){
document.body.scrollTop +=Math.round((1000-document.body.clientHeight)/2);
}

}


function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}

function displayResult(xml_file,xsl_file,div_id)
{
xml_file=xml_file.unescapeHTML(); // for W3C validator

xml=loadXMLDoc(xml_file);
xsl=loadXMLDoc(xsl_file);
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById(div_id).innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById(div_id).appendChild(resultDocument);
}
}





function load_neuwagen()
{
Effect.Fade('top_content', {duration: 0.2,afterFinish:function(){new Ajax.Updater('top_content', 'jax/load_neuwagen.jax.php', {evalScripts:true, method:'post'});} });
//new Ajax.Updater('top_content', 'jax/load_neuwagen.jax.php', {evalScripts:true, method:'post'});
}

function add_to_slideshow(image_nr,src,width,height,description)
{
image_nr--;
photoArray[image_nr]=new Array(src, 200, 200, description);
}

function start_slideshow(image_nr)
{
image_nr--;

var myPhoto = new Slideshow(image_nr);
myPhoto.initSwap();
}

function standort(use_Gmap,Gmap_key)
{
var arrayPageSize = getPageSize();
$('overlay_div').style.width = arrayPageSize[0]+'px';
$('overlay_div').style.height = arrayPageSize[1]+'px';
$('overlay_div').style.top = '0px';
$('overlay_div').style.left= '0px';
hideSelectBoxes();
hideFlash();
Element.show('overlay_div');
new Ajax.Updater('standort_div', 'jax/load_map.jax.php', {evalScripts:true, method:'post', postBody:'sid=&use_Gmap='+use_Gmap});
}

function closeStandort(use_Gmap,zoom_out_map)
{
if (use_Gmap==0)
{
Element.hide('map_img');
$('map_img').src=zoom_out_map;
}
Element.hide('standort_div');
Element.hide('overlay_div');
showSelectBoxes();
showFlash();
}

function change_map_display(use_Gmap)
{
if (use_Gmap=='0') standort(1);
else standort(0);
}

function load_random_models()
{
if ($('random_fiat'))
{
new Ajax.Updater('random_model_content', 'jax/load_random_models.jax.php', {evalScripts:true, method:'post'});
}
}

function show_random_image(image_obj,container_id)
{
Effect.Appear(image_obj.id,{duration:0.3, afterFinish:function(){$(container_id).style.backgroundImage='';}  });
}

function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}

function team_member(src,obj,content)
{

//alert(content);
var arrayPageSize = getPageSize();
positions=findPos(obj);
$('overlay_div').style.width = arrayPageSize[0]+'px';
$('overlay_div').style.height = arrayPageSize[1]+'px';
$('overlay_div').style.top = '0px';
$('overlay_div').style.left= '0px';
if(/MSIE/.test(navigator.userAgent)) $('team_member_box_arrow').className='team_member_box_arrow_divIE';
else $('team_member_box_arrow').className='team_member_box_arrow_divFF';
hideSelectBoxes();
hideFlash();
$('team_member_img').src=src;
$('team_member_div').style.left=(positions[0]-15)+'px';
$('team_member_div').style.top=(positions[1]-120)+'px';
$('team_member_text_div').innerHTML=content;
Element.show('overlay_div');
Effect.Appear('team_member_div',{duration:0.5});
//Element.show('team_member_div');
}

function close_team_member()
{
$('team_member_img').src='';
Element.hide('team_member_div');
Element.hide('overlay_div');
showSelectBoxes();
showFlash();
//Effect.Fade('standort_div',{afterFinish:function(){Effect.Fade('overlay_div',{duration:0.1})}});
}


function png_fix()
{
/*

Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters))
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
}

function print_page(url_address){
url_address=url_address.replace(/&amp;/g,"&");
popup = window.open( url_address, 'printpage', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=no,width=' + '708' + ', height=' + '900'  );
popup.focus();
}
function pdf_page(url_address){
url_address=url_address.replace(/&amp;/g,"&");
popup = window.open( url_address, 'pdfpage', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,width=' + '708' + ', height=' + '900'  );
popup.focus();
}

function open_configurator(brand,model,submodel)
{
url_address='http://e-car.at/configurator/dealer_703_doerfler';
if (brand!='') url_address+='/'+brand+'v2/';
if (model!='') url_address+='index.php?modell='+model;
if (submodel!='') url_address+='&sub_modell='+submodel;
//alert(url_address);
popup = window.open( url_address, 'configurator', 'toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=no,width=' + '779' + ', height=' + '510'  );
popup.focus();
}

function configurator_brand_choose()
{
new Ajax.Updater('configurator_container', 'jax/configurator.jax.php', {evalScripts:true, method:'post'});
var arrayPageSize = getPageSize();
$('overlay_div').style.width = arrayPageSize[0]+'px';
$('overlay_div').style.height = arrayPageSize[1]+'px';
$('overlay_div').style.top = '0px';
$('overlay_div').style.left= '0px';
hideSelectBoxes();
hideFlash();
Element.show('overlay_div');
Element.show('configurator_container');
//Effect.Appear('team_member_div',{duration:0.5});
}
function configurator_close()
{
Element.hide('configurator_container');
Effect.Fade('overlay_div',{duration:0.1});
showSelectBoxes();
showFlash();
}

function toggle_submodel_series(brand_id,model_id,submodel_id)
{
if ($('submodel_series_'+submodel_id).style.display=='none')
{
$('submodel_series_'+submodel_id).innerHTML='<div align="center" style="padding-top:20px"><img src="images/loader3.gif"/><br>Wird geladen...</div>';
Effect.toggle('submodel_series_'+submodel_id,'blind',{duration:0.5, afterFinish:function(){$('submodel_series_'+submodel_id).innerHTML='';displayResult("curl_ecar.php?type=series&brand="+brand_id+"&model="+model_id+"&submodel="+submodel_id,"xsl_templates/series.xsl","submodel_series_"+submodel_id);} });
}
else
Effect.toggle('submodel_series_'+submodel_id,'blind',{duration:0.3});
}

function submitNewsletter(frm){
if (frm.profile_name.value=='' || frm.profile_name.value==default_profilename)
{
alert(require_name);
frm.profile_name.focus();
return false;
}
if (frm.letter_email.value=='' || frm.letter_email.value==default_email)
{
alert(require_email);
frm.letter_email.focus();
return false;
}else{
if (!isValidEmail(frm.letter_email.value)) {  // check to make sure all characters are valid
alert(require_email_2);frm.letter_email.focus();return false;
}
}
frm.submit();
}

function map_zoom_in(has_Gmap,zoom_in_map)
{
if (has_Gmap==0) {Element.hide('map_img');$('map_img').src=zoom_in_map;}
else map.zoomIn();
}

function map_zoom_out(has_Gmap,zoom_out_map)
{
if (has_Gmap==0) {Element.hide('map_img');$('map_img').src=zoom_out_map;}
else map.zoomOut();
}

function map_close(has_Gmap,zoom_out_map)
{
Element.hide('map_img');
if (has_Gmap==0) $('map_img').src=zoom_out_map;
}

function map_print()
{
var url_address='map_print.php';
popup = window.open( url_address, 'printpage', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=no,width=' + '708' + ', height=' + '900'  );
popup.focus();
}



function add_image(image_nr,car_id,src,description)
{
src=src.replace(/&amp;/g,"&");
if (image_nr=='') image_nr=0;
current_array="photo_array_"+car_id;
eval(current_array+"["+image_nr+"]=new Array('"+src+"', 200, 200, '"+description+"')");
}










/*--------------------------------------------------------------------------*/
/* overlay div */
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

var xScroll, yScroll;

if (self.pageYOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
yScroll = document.documentElement.scrollTop;
xScroll = document.documentElement.scrollLeft;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
xScroll = document.body.scrollLeft;
}

arrayPageScroll = new Array(xScroll,yScroll)
return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){

var xScroll, yScroll;

if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}

var windowWidth, windowHeight;

//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

if (self.innerHeight) {	// all except Explorer
if(document.documentElement.clientWidth){
windowWidth = document.documentElement.clientWidth;
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}

// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
//	console.log("pageWidth " + pageWidth)

arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}


function showSelectBoxes(){
var selects = document.getElementsByTagName("select");
for (i = 0; i != selects.length; i++) {
selects[i].style.visibility = "visible";
}
}

// ---------------------------------------------------

function hideSelectBoxes(){
var selects = document.getElementsByTagName("select");
for (i = 0; i != selects.length; i++) {
selects[i].style.visibility = "hidden";
}
}

// ---------------------------------------------------

function showFlash(){
var flashObjects = document.getElementsByTagName("object");
for (i = 0; i < flashObjects.length; i++) {
flashObjects[i].style.visibility = "visible";
}

var flashEmbeds = document.getElementsByTagName("embed");
for (i = 0; i < flashEmbeds.length; i++) {
flashEmbeds[i].style.visibility = "visible";
}
}

// ---------------------------------------------------

function hideFlash(){
var flashObjects = document.getElementsByTagName("object");
for (i = 0; i < flashObjects.length; i++) {
flashObjects[i].style.visibility = "hidden";
}

var flashEmbeds = document.getElementsByTagName("embed");
for (i = 0; i < flashEmbeds.length; i++) {
flashEmbeds[i].style.visibility = "hidden";
}

}
function setCookie(name, value, expiredays, path, domain, secure) {

if (expiredays) {

var exdate=new Date();

exdate.setDate(exdate.getDate()+expiredays);

var expires = exdate.toGMTString();

}

document.cookie = name + "=" + escape(value) +

((expiredays) ? "; expires=" + expires : "") +

((path) ? "; path=" + path : "") +

((domain) ? "; domain=" + domain : "") +

((secure) ? "; secure" : "");

}

function getCookie(name) {

var cookie = " " + document.cookie;

var search = " " + name + "=";

var setStr = null;

var offset = 0;

var end = 0;

if (cookie.length > 0) {

offset = cookie.indexOf(search);

if (offset != -1) {

offset += search.length;

end = cookie.indexOf(";", offset)

if (end == -1) {

end = cookie.length;

}

setStr = unescape(cookie.substring(offset, end));

}

}

return setStr;

}


