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=' + '663' + ', height=' + '842'  );
	popup.focus();
}
function print_page(url_address){
//	alert(url_address);
	url_address=url_address.replace(/&amp;/g,"&");
	popup = window.open( url_address, 'printpage', 'toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=no,width=' + '595' + ', height=' + '842'  );
	popup.focus();
}
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 open_configurator(brand,model,submodel)
{
	url_address='http://configurator.e-car.at/dealer_729_stippich';
	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 open_car_configurator()
{
	url_address='http://configurator.e-car.at/auswahl/stippich_729';
	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 toggle_submodel_series(brand_id,model_id,submodel_id)
{		
		$('#submodel_series_'+submodel_id).slideToggle("normal");
		$('#submodel_series_'+submodel_id).load('jax/load_serienausstaltung.jax.php',{'brand':brand_id,'model':model_id,'submodel':submodel_id});
} 

/*--------------------------------------------------------------------------*/
				/* overlay div */
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;
			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;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		/**
		 / THIRD FUNCTION
		 * getPageScroll() by quirksmode.com
		 *
		 * @return Array Return an array with x,y page scroll values.
		 */
		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;
		};
		
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 load_map(map_type)
{
	var arrayPageSize = ___getPageSize();
	
	$('#overlay_div').css({
					width:	arrayPageSize[0],
					height:	arrayPageSize[1]
				});
	// Get page scroll
	var arrPageScroll = ___getPageScroll();
	// Calculate top and left offset for the jquery-lightbox div object and show it
	$('#map_jax_target').css({
		top:	arrPageScroll[1] + (arrayPageSize[3] / 10)		
	});
	
	hideSelectBoxes();
	hideFlash();
	$('#overlay_div').fadeIn('slow');	
	$('#map_jax_target').load('jax/load_map.jax.php', {'map_type':map_type});
	$('#map_jax_target').fadeIn('slow');
}

function hide_map()
{		
	$('#map_jax_target').fadeOut('slow');
	$('#overlay_div').fadeOut('slow');
	showSelectBoxes();
	showFlash();
}

function printPage(print_page){
	popup = window.open( print_page, 'print', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,width=' + '708' + ', height=' + '900'  );
}

function change_lang(lang)
{
	$('#press_debug').load('jax/change_lang.jax.php', { 'lang':lang });	
}

function printPage(print_page){
	popup = window.open( print_page, 'print', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,width=' + '708' + ', height=' + '900'  );
}

var selected_tooltip_height=0;
var tooltip_status=0;
function toggle_tooltip()
{
	if (tooltip_status==0)
	{
		if (selected_tooltip_height==0) selected_tooltip_height = $('#tooltip_container').height();
		$('#tooltip_container').css({top: 280-selected_tooltip_height });
		$('#tooltip_table').css({display:'none', visibility:'visible'});
		$('#tooltip_table').show('slide', {direction:'down'}, 300,function(){tooltip_status=1;$('#tooltip_arrow').show('slide', {direction:'up'},200);});
	}
	else
	{
		$('#tooltip_arrow').hide('slide', {direction:'up'},300,function(){tooltip_status=0;$('#tooltip_table').hide('slide', {direction:'down'},300);});
	}
}
