/* Javascript functions for Hoffmann Mobile 2008 made by style XP communications */

var activeMenuDesc = "";
var selectedImageName = "";

function showMenuDescription(descriptionMenu, imageName){

clearMenuDescription();
hideAllSubmenus();

if(document.getElementById(descriptionMenu) != null){
 document.getElementById(descriptionMenu).style.display = "block";
 activeMenuDesc = descriptionMenu;
}

if(document.getElementById('image_'+imageName) != null){
 selectedImageName = imageName;
 document.getElementById('image_'+imageName).src = "/static/website/bt_h_"+imageName+".gif";
}
}

function clearMenuDescription(){

if(activeMenuDesc != "" && document.getElementById(activeMenuDesc) != null){
 document.getElementById(activeMenuDesc).style.display = "none";
 activeMenuDesc = "";
}

if(selectedImageName != "" && document.getElementById('image_'+selectedImageName) != null){
 document.getElementById('image_'+selectedImageName).src = "/static/website/bt_"+selectedImageName+".gif";
 selectedImageName = "";
}

showAllActiveSubmenus();
}

// DIVs fuer die Submenus definieren - Sackgang!

var submenuItems = new Array("submenu_sparerangebote", "submenu_gebrauchtwagen", "submenu_service", "submenu_kontakt", "submenu_nutzfahrzeuge", "submenu_bikershome");
var submenuItemStatus = new Array(10);

function hideAllSubmenus(){
// alle Submenu-Punkte suchen und ggf. neuem Array zuordnen
for (var i = 0; i < submenuItems.length; ++i){
	if(document.getElementById(submenuItems[i]) != null) {
		var submenuItemProperties = new Array(submenuItems[i], document.getElementById(submenuItems[i]).style.display);
	  submenuItemStatus[i] = submenuItemProperties;
	  document.getElementById(submenuItems[i]).style.display = "none";
	}
}
}

function showAllActiveSubmenus(){

if(submenuItemStatus != null && submenuItemStatus.length > 0){
 // erste Ebene zerlegen und einzelne Arrays extrahieren
 for (var j = 0; j < submenuItemStatus.length; ++j){
   // einzelne innere Arrays auslesen
   var submenuItemProperties = submenuItemStatus[j];
   if(submenuItemProperties != null && submenuItemProperties.length > 0){
     // Wert des Eintrages wieder setzen
     if(document.getElementById(submenuItemProperties[0]) != null) document.getElementById(submenuItemProperties[0]).style.display = submenuItemProperties[1];
   }
 }
}
submenuItemStatus = new Array(10); // Array leeren
}

/* Funktionen Popupfenster Startseite */

function loadPopuplink(pageLink){
 setCookie();
 fadePopupOut();
 self.location.href=pageLink;
}

function closePopup(link){
 setCookie();
 fadePopupOut();
}


function setCookie(){
 if(document.getElementById('checkPopup') != null){
  
  // Cookie mit den Popup-Infos schreiben
  if(document.cookie && !document.getElementById('checkPopup').checked){
  	var a = new Date();
		a = new Date(a.getTime() +1000*60*60*24*30);
  	document.cookie = 'cookieHoffmannPopup=false; expires='+a.toGMTString()+';';
  }
  
 }
}


function fadePopupOut(){
 new Effect.Fade('popupInfo');
}

function checkCookie()
{
  a = document.cookie;
 res = '';
 if(a != '')
 {
   cookie = a.indexOf("cookieHoffmannPopup=false");
   if(cookie != null && cookie > -1)
   {
    res="false";
   }
  
 }
 
 return(res)
 /*a = document.cookie;
 res = '';
 while(a != '')
 {
  cookiename = a.substring(0,a.search('='));
  cookiewert = a.substring(a.search('=')+1,a.search(';'));
  if(cookiewert == '')
  {cookiewert = a.substring(a.search('=')+1,a.length);}

  if('cookieHoffmannPopup' == cookiename){res = cookiewert;}

  i = a.search(';')+1;
  if(i == 0){i = a.length}
  a = a.substring(i,a.length);
 }
 return(res)*/
}

function sendCallInfo(kontaktForm){
if(kontaktForm.Kundenname.value !="Ihr Name" && kontaktForm.Rufnummer.value !="Ihre Nummer"
&& checkFieldEntry(kontaktForm.Kundenname.value) && checkFieldEntry(kontaktForm.Rufnummer.value)){
$(kontaktForm.id).request({
  method: 'post',
  	onLoading: function(transport) {
  		document.getElementById("imgPreloader").style.display = "inline";
  	},
	  onSuccess: function(transport) {
	    document.getElementById("sendCallInfo").style.display = "none";
	    document.getElementById("imgPreloader").style.display = "none";
	    document.getElementById("getCallInfoResponse").style.display = "block";
	  },
	  onFailure:function(transport) {
	  	alert("Fehler:\nStatusmeldung: "+transport.status);
  }
})
} else if(!checkFieldEntry(kontaktForm.Kundenname.value) || !checkFieldEntry(kontaktForm.Kundenname.value)){
 alert("Bitte geben Sie Ihren Namen und Ihre Telefonnummer an.");
}

return true;
}

String.prototype.trim = function() {

 // skip leading and trailing whitespace
 // and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

function checkFieldEntry(fieldValue){
  value = fieldValue.trim();
  isTrue = false;
  if(value.length > 2 && value != "" && value !=" ") {isTrue = true;}
  return isTrue;
}

function changeDetailImage(imageURL){
if(document.getElementById('imageDetailLarge') != null){
 document.getElementById('imageDetailLarge').src = imageURL;
}
}

/* interner Bereich */
function switchTab(activeTab, inactiveTab){
 // TAB-Darstellung wechseln
 if(document.getElementById(activeTab) != null && document.getElementById(inactiveTab) != null){
  document.getElementById(activeTab).style.fontWeight = "400";
  document.getElementById(inactiveTab).style.fontWeight = "700";
 }
 // Content wechseln
 if(document.getElementById(activeTab+"Content") != null && document.getElementById(inactiveTab+"Content") != null){
  document.getElementById(activeTab+"Content").style.display = "block";
  document.getElementById(inactiveTab+"Content").style.display = "none";
 }
}