/******************************************************
*
* webasto dealer locator
*
******************************************************/

/**
 * @param selectId id of the selectbox
 * @param text text of the option
 * @param val value of the option
 */ 
function addOption(selectId, txt)
{
    var objOption = new Option(txt);
    
    var attr_value = document.createAttribute("value");
    attr_value.nodeValue = txt;
    objOption.setAttributeNode(attr_value);
    
    document.getElementById(selectId).options.add(objOption);
}


/**
 * 
 * 
 *
 *
 */
function nextStep()
{
	document.getElementById("result").style.display = "block";
	
	//Wenn Deutschland ausgewählt
	if((document.getElementById("country").options[document.getElementById("country").selectedIndex].text == 'Germany' || document.getElementById("country").options[document.getElementById("country").selectedIndex].text == 'Deutschland') || (document.getElementById("country").options[document.getElementById("country").selectedIndex].text == 'Italy' || document.getElementById("country").options[document.getElementById("country").selectedIndex].text == 'Italien'))
	{
		document.getElementById("region").selectedIndex = 0;
		//document.getElementById("region").style.display = "inline";
		document.getElementById("region_div").style.display = "block";
		document.getElementById("town").value = '';
		document.getElementById("zip").value = '';
		//document.getElementById("zip").style.display = "inline";
		//document.getElementById("town").style.display = "inline";
		document.getElementById("zip_div").style.display = "block";
		document.getElementById("town_div").style.display = "block";		
	}
	
	//Wenn erster Eintrag "Please choose" ausgewählt
	else if(document.getElementById("country").selectedIndex == 0) {
		document.getElementById("result").style.display = "none";
		document.getElementById("region").selectedIndex = 0;
		//document.getElementById("region").style.display = "none";
		//document.getElementById("zip").style.display = "none";
		//document.getElementById("town").style.display = "none";
		document.getElementById("region_div").style.display = "none";
		document.getElementById("zip_div").style.display = "none";
		document.getElementById("town_div").style.display = "none";
	}
	
	//Alle anderen Länder
	else {
	document.getElementById("region").selectedIndex = 0;
		//document.getElementById("region").style.display = "inline";
		//document.getElementById("zip").style.display = "none";
		//document.getElementById("town").style.display = "none";
		document.getElementById("region_div").style.display = "block";
		document.getElementById("zip_div").style.display = "none";
		document.getElementById("town_div").style.display = "none";
		
	}
}


/**
 * 
 * 
 *
 *
 */
function selectCountry(country) {
	for(var i=0; document.getElementById('country').length; i++) {
		if(document.getElementById('country').options[i].text==country) {
			document.getElementById('country').options[i].selected=true;
			break;
		}
	}
	document.getElementById('result').innerHTML = '<img src="typo3conf/ext/webasto_dealers/pi1/images/ajax-loader.gif" alt="ajax loader" />';
	nextStep(country);
	if(country != -1) {
		tx_webastodealers_pi1fillSelect('region', country);
		tx_webastodealers_pi1getData(1, country, '');
	}
	renderPage();
}


/**
 * 
 * 
 *
 *
 */
function selectRegion(country, region) {
	for(var i=0; document.getElementById('region').length; i++) {
		if(document.getElementById('region').options[i].text==region) {
			document.getElementById('region').options[i].selected=true;
			break;
		}
	}

	document.getElementById('zip').value = '';
	document.getElementById('town').value = '';
	if(country != -1)  {
		if(region == 'all' || region == 'alle') tx_webastodealers_pi1getData(1, country, '');
		//nextStep(country)
		//xajax_fillSelect('region', country)
		else tx_webastodealers_pi1getData(2, country, region);
			
	}
	renderPage();
}


/**
 * 
 * 
 *
 *
 */
function selectZip(country, zip)
{
	document.getElementById('region').selectedIndex = 0;
	document.getElementById('town').value = '';
	if(country != -1) 
	{
		tx_webastodealers_pi1getData(3, country, zip);		
	}
	renderPage();
}


/**
 * 
 * 
 *
 *
 */
function selectTown(country, town)
{
	document.getElementById('region').selectedIndex = 0;
	document.getElementById('zip').value = '';
	if(country != -1) 
	{
		tx_webastodealers_pi1getData(4, country, town);	
	}
	renderPage();
}



/******************************************************
*
* webasto homepage functions
*
******************************************************/
/*
function tx_webHomeShowHide(teaserNum, action) {
  action = (action) ? 'block' : 'none';
  teaser = 'teaserHome'+teaserNum;
  document.getElementById(teaser).style.display = action;
}
*/



/******************************************************
*
* webasto homepage teaser functions
*
**************************************************/

var teaserAct = 0;


function tx_webHomeShowHide(teaserNum, action) {  
  teaser = 'teaserHome'+teaserNum;
  //alert(teaser);
  if(action) {
    var teaserAct = teaserNum;
    document.getElementById(teaser).style.visibility = 'visible';    
    Effect.BlindDown(teaser);
    return false;
    
  } else {
    //Effect.BlindUp(teaser);   
    //return false;
    
    
    new Effect.BlindUp(teaser, { 
      duration: 1, 
      fps: 50, 
      afterFinish: function() { 
        document.getElementById(teaser).style.visibility = 'hidden';
      } 
    });        
    
    return false;
  }
}
