// Javascript, Author Frank Scholz Computer Support


var req = false;

var waitSQL   = false;

// define vars for style handler
var tab  = 0;
var det  = 1;

// define array for style handler - define styles depentent from the style
var styleconf = new Array();

styleconf[tab]                       = new Object();
styleconf[tab]["nodeElement"]        = "span";
styleconf[tab]["dummytext"]          = "€";
styleconf[tab]["ElementInBetween"]   = "br";
styleconf[tab]["display"]            = new Object();
styleconf[tab]["display"].bgcolor    = "#000030";
styleconf[tab]["display"].fontfamily = "monospace,fixedsys,terminal,system";
styleconf[tab]["display"].ftsize     = "10pt";
styleconf[tab]["display"].ftcolor    = "#D5D5FF";
styleconf[tab]["hide"]               = new Object();
styleconf[tab]["hide"].bgcolor       = "#D5D5FF";
styleconf[tab]["hide"].fontfamily    = "Arial,Helvetica,sans-serif";
styleconf[tab]["hide"].ftsize        = "12pt";
styleconf[tab]["hide"].ftcolor       = "#000030";
styleconf[det]                       = new Object();
styleconf[det]["nodeElement"]        = "span";
styleconf[det]["dummytext"]          = "€";
styleconf[det]["ElementInBetween"]   = " ";
styleconf[det]["display"]            = new Object();
styleconf[det]["display"].bgcolor    = "#d5d5ff";
styleconf[det]["display"].fontfamily = "Arial,Helvetica,sans-serif";
styleconf[det]["display"].ftsize     = "10pt";
styleconf[det]["display"].ftcolor    = "red";
styleconf[det]["hide"]               = new Object();
styleconf[det]["hide"].bgcolor       = "#d5d5ff";
styleconf[det]["hide"].fontfamily    = "Arial,Helvetica,sans-serif";
styleconf[det]["hide"].ftsize        = "10pt";
styleconf[det]["hide"].ftcolor       = "#000030";

function xmlRequest(scriptQuery,todo,group,id,style)
{
//  alert (scriptQuery);
  req  = false;
  if(window.XMLHttpRequest)
  {
   try
    {
     req = new XMLHttpRequest();
    }
   catch(e)
    {
     req = false;
    }
   }
  else if(window.ActiveXObject)
   {
    try
     {
      req = new ActiveXObject("Msxml2.XMLHTTP");
     }
    catch(e)
     {
      try
       {
        req = new ActiveXObject("Microsoft.XMLHTTP");
       }
      catch(e)
       {
        req = false;
       }
     }
   }
  if (!req)
  {
	  alert("Kann keine XMLHTTP-Instanz erzeugen");
		return false;
  }
  else
  {
   req.onreadystatechange = new Function('f',"readServerMessage(\'" + todo + "\',\'" + group + "\'," + id + "," + style + ")");
   req.open("GET", scriptQuery, true);
   try
   { req.send(true);} // required for mozilla styled browsers, this should be the right way - but
   catch(e)
   { req.send();}     // microsoft seeks to make us wonder. It's to boring to do all thing compliant with the others.
  }
}
function readServerMessage(todo,group,id,style)
{
  switch (req.readyState)
  {
	  case 4:
		  if (req.status != 200)
      {
//			  alert("Fehler:"+req.status);
      }
			else if (waitSQL == true) // mouse should be still over
      {
        switch(todo)
        {
          case 'priceOpt':
 		    	  var xmlDoc	= req.responseXML;                               //save stream sent by the server
            var data = xmlDoc.getElementsByTagName('row');
            var cell    = document.getElementById(group+id);

            var text    = cell.firstChild;
            var newtext = document.createElement(styleconf[style]['nodeElement']);

            for(i=0;data[i];i++)
            {
              if ((i == 1) && (styleconf[style]["ElementInBetween"] == "br"))
              {
                var element = document.createElement(styleconf[style]["ElementInBetween"]);
                newtext.appendChild(element);
              }
              else if (i == 1)
              {
                var element = document.createTextNode(styleconf[style]["ElementInBetween"]);
                newtext.appendChild(element);
              }
              newrow = document.createTextNode(data[i].firstChild.nodeValue);
              newtext.appendChild(newrow);
            }
//            var xclass = document.createAttribute("class");
//            xclass.nodeValue = "pricerange";
//            newtext.setAttributeNode(xclass);
            cell.appendChild(newtext);
            cell.removeChild(text);
            waitSQL   = false;
            break;
          default:
        }
  	  }
	    break;
	 default:
  }
}

function HideDelay(group,id,todo,style)
{
  window.setTimeout("PriceInfo(\""+group+"\","+id+",\"hide\","+style+");", 5000);
}

function PriceInfo(group,id,todo,style)
{
  if ((waitSQL == false) || (todo=='hide'))
  {
    var cell    = document.getElementById(group + id);
    var text    = cell.firstChild;

//    for (var Eigenschaft in cell.style)
//      alert (Eigenschaft);

    cell.style.backgroundColor =styleconf[style][todo]['bgcolor'];
    cell.style.fontFamily      =styleconf[style][todo]['fontfamily'];
    cell.style.fontSize        =styleconf[style][todo]['ftsize'];
    cell.style.color           =styleconf[style][todo]['ftcolor'];
    switch(todo)
    {
      case 'display':
        mouseover = true;
        waitSQL   = true;
        xmlRequest("/bin/support.php?do=priceOpt&id=" + id + "&group=" + group,'priceOpt',group,id,style);
        HideDelay(group,id,todo,style);
        break;
      case 'hide':
        var newtext = document.createElement(styleconf[style]['nodeElement']);
        var newrow  = document.createTextNode(styleconf[style]['dummytext']);
        newtext.appendChild(newrow);
        cell.appendChild(newtext);
        cell.removeChild(text);
        cell.appendChild(newtext);
//        waitSQL = false;
        break;
      default:
    }
  }
}


    function findPos(variable,SearchValue,max)
    {
      if ((variable.search(SearchValue)>-1) && (variable.search(SearchValue)<max))
       return variable.search(SearchValue);
      else
       return max;
    }

    function switch_db()
    {
      switch(document.forms[1].elements['desc_set'].options.value)
      {
        case '0':
          document.forms[1].elements['year'].maxLength=4;
          document.forms[1].elements['power_kw'].maxLength=5;
          document.forms[1].elements['power_hp'].maxLength=5;
          document.getElementsByName("year")[0].value = document.getElementsByName("year")[0].value.slice(0,4);
          document.forms[1].elements['power_kw'].value=document.forms[1].elements['power_kw'].value.slice(0,findPos(document.forms[1].elements['power_kw'].value,",",5));
          document.forms[1].elements['power_hp'].value=document.forms[1].elements['power_hp'].value.slice(0,findPos(document.forms[1].elements['power_hp'].value,",",5));
          document.forms[1].elements['year'].style.borderWidth='0px';
          document.forms[1].elements['power_kw'].style.borderWidth='0px';
          document.forms[1].elements['power_hp'].style.borderWidth='0px';
          document.forms[1].elements['desc_set'].style.borderWidth='0px';
        break;
        case '1':
          document.forms[1].elements['year'].maxLength=14;
          document.forms[1].elements['power_kw'].maxLength=10;
          document.forms[1].elements['power_hp'].maxLength=10;
          document.forms[1].elements['year'].style.borderWidth='thin';
          document.forms[1].elements['power_kw'].style.borderWidth='thin';
          document.forms[1].elements['power_hp'].style.borderWidth='thin';
          document.forms[1].elements['desc_set'].style.borderWidth='thin';
          document.forms[1].elements['year'].style.borderColor='#ff0000';
          document.forms[1].elements['power_kw'].style.borderColor='#ff0000';
          document.forms[1].elements['power_hp'].style.borderColor='#ff0000';
          document.forms[1].elements['desc_set'].style.borderColor='#ff0000';
        break;
        default:
      }

    }
    function read_lang()
    {
      if (navigator.appName == "Netscape")
      {
        if (navigator.language.indexOf('de')<0) // browser language is not equal de, switch default de to en
          lang('EN');
      }
      else
      {
        if (navigator.browserLanguage != 'de') // browser language is not equal de, switch default de to en
          lang('EN');
      }
    }
    
    function lang_reg(todo)
    {
      document.getElementById('reg_de').style.backgroundColor = '#D5D5FF';
      document.getElementById('reg_en').style.backgroundColor = '#D5D5FF';
      document.getElementById('reg_fr').style.backgroundColor = '#D5D5FF';
      document.getElementById('type').style.visibility = 'hidden';
      document.getElementById('type_en').style.visibility = 'hidden';
      document.getElementById('type_fr').style.visibility = 'hidden';
      document.getElementById('colour').style.visibility = 'hidden';
      document.getElementById('colour_en').style.visibility = 'hidden';
      document.getElementById('colour_fr').style.visibility = 'hidden';
      document.getElementById('text').style.visibility = 'hidden';
      document.getElementById('text_en').style.visibility = 'hidden';
      document.getElementById('text_fr').style.visibility = 'hidden';
      switch(todo)
      {
        case 'DE':
          document.getElementById('reg_de').style.backgroundColor = 'white';
          document.getElementById('type').style.visibility = 'visible';
          document.getElementById('colour').style.visibility = 'visible';
          document.getElementById('text').style.visibility = 'visible';
          document.getElementById('type').style.display = 'run-in';
          document.getElementById('colour').style.display = 'run-in';
          document.getElementById('text').style.display = 'run-in';
          break;
        case 'EN':
          document.getElementById('reg_en').style.backgroundColor = 'white';
          document.getElementById('type_en').style.visibility = 'visible';
          document.getElementById('colour_en').style.visibility = 'visible';
          document.getElementById('text_en').style.visibility = 'visible';
          document.getElementById('type_en').style.display = 'run-in';
          document.getElementById('colour_en').style.display = 'run-in';
          document.getElementById('text_en').style.display = 'run-in';
          break;
        case 'FR':
          document.getElementById('reg_fr').style.backgroundColor = 'white';
          document.getElementById('type_fr').style.visibility = 'visible';
          document.getElementById('colour_fr').style.visibility = 'visible';
          document.getElementById('text_fr').style.visibility = 'visible';
          break;

      }

    }

     function adjustLang()
     {
       var availHeight=" ";
       if (self.innerHeight) // all except Explorer
	        availHeight = self.innerHeight;
       else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
    	   availHeight = document.documentElement.clientHeight;
       else if (document.body) // other Explorers
   	    availHeight = document.body.clientHeight;
       elementx=document.getElementById('lang-content');
       if (availHeight <= 552)
       {
        elementx.style.position='absolute';
        elementx.style['top']=313+'px';
       }
       elementx.style.visibility = 'visible';
     }


     function lang(todo)
     {
       var path   = window.location.pathname;
       var active = path.indexOf(".") == path.lastIndexOf(".");
       var act_l  = path.slice(path.indexOf("."),path.lastIndexOf("."))
       if ((path.indexOf(".php")<0) && (path.indexOf(".htm")<0) && (todo != 'DE'))
         location.replace(path + "index." + todo.toLowerCase() + ".php");
       else if ((todo != 'DE') && (todo.ToLowerCase != act_l))
         location.replace(path.slice(0,path.indexOf(".")) + "." + todo.toLowerCase() + path.slice(path.lastIndexOf("."),path.length)) ;
       else if ((todo == 'DE') && (!active))
         location.replace(path.slice(0,path.indexOf(".")) + path.slice(path.lastIndexOf("."),path.length));
     }

     function addUrl(addOn)
     {
          window.location.href = window.location.href + addOn;
     }

     function goTo(url)
     {
          window.location.href = url;
     }
     function bigpicture()
     {
        var src_complete = document.images.prev_big.src;
        var src =src_complete.slice(src_complete.lastIndexOf("/")+1,src_complete.lastIndexOf("&")) + "&full=true";
        full = window.open(src);
        full.focus();
     }

     function pictureprev(src)
     {
        document.images.prev_big.src = src;
     }
     

     function confirmTask(destination,text)
     {
        path = window.location.pathname;
        Check = confirm(text);
        if (Check == true)
          location.replace(destination);

     }

     function hello(test)
     {
       alert(test);
     }

