var changedElements = false;
var isIE      = (navigator.appName == "Microsoft Internet Explorer");
// Variablen für die Layer/Buttons
var menuClass = new Array("buttonSelected","buttonOut","buttonOver");
// Variablen für POPUPs
var wFull     = screen.width-20;
var hFull     = screen.height-80;
var winlFull  = 5;
var wintFull  = 5;
winpopFull    = 'height='+hFull+',width='+wFull+',top='+wintFull+',left='+winlFull+',directories=0,resizable=no,menubar=0,toolbar=0,personalbar=0,location=0,locationbar=0,scrollbars=1';
var wL        = 900; //screen.width * 80 / 100;
var hL        = 610; //screen.height * 80 / 100;
var hL        = screen.height - 100;
var winlL     = (screen.width - wL) / 2;
var wintL     = (screen.height - hL) / 4;
winpopL       = 'height='+hL+',width='+wL+',top='+wintL+',left='+winlL+',directories=0,resizable=no,menubar=0,toolbar=0,personalbar=0,location=0,locationbar=0,scrollbars=0';
var wM        = 780;
var hM        = 520;
var winlM     = (screen.width - wM) / 2;
var wintM     = 90;
winpopM       = 'height='+hM+',width='+wM+',top='+wintM+',left='+winlM+',directories=0,resizable=0,menubar=0,toolbar=0,personalbar=0,location=0,locationbar=0,scrollbars=0';
var wM        = 780;
var hM        = 250;
var winlM     = (screen.width - wM) / 2;
var wintM     = (screen.height - hM) / 2;
winpopM2      = 'height='+hM+',width='+wM+',top='+wintM+',left='+winlM+',directories=0,resizable=0,menubar=0,toolbar=0,personalbar=0,location=0,locationbar=0,scrollbars=0';
var wS        = 400; 
var hS        = 150;
var wintS     = (screen.height - hS) / 2;
var winlS     = (screen.width - hS) / 3;
winpopS       = 'height='+hS+',width='+wS+',top='+wintS+',left='+winlS+',directories=0,resizable=0,menubbar=0,toolbar=0,personalbar=0,location=0,locationbar=0,scrollbars=0';
winpopS_Scr   = 'height='+hS+',width='+wS+',top='+wintS+',left='+winlS+',directories=0,resizable=1,menubbar=0,toolbar=0,locationbar=1,scrollbars=1';
var wF        = (screen.width / 1.3);
var hF        = (screen.height / 1.3); 
winpopF       = 'height='+hF+',width='+wF+',top=30,left=30,directories=0,resizable=0,menubbar=0,toolbar=0,personalbar=0,location=0,locationbar=0,scrollbars=1';
var wD        = 870;
var hD        = 586;
var dynH      = false;
var dynW      = true;
if (screen.height > hD && dynH) {
  hD          = screen.height / 1.3;
  var wintD   = 30;
}
else {
  var wintD   = (screen.height - hD) / 3;
}
if (screen.width > wD*1.3 && dynW) {
  wD          = screen.width / 1.3;
  var winlD   = (screen.width - wD) / 2;  
}
else {
  var winlD   = (screen.width - wD) / 2;
}
winpopD       = 'height='+hD+',width='+wD+',top='+wintD+',left='+winlD+',directories=0,resizable=0,menubar=0,toolbar=0,locationbar=0,scrollbars=0';
winpopNULL    = '';

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 euroaxfullsupported(vehtype,supported) {
	var asupported = supported.split(",");
	for (is=0;is<asupported.length;is++)
		if (asupported[is]==vehtype)
			return true;
	return false;
}
function killmysqlquery() {
  $('iframecmdkill').src='mysqlquerykill.php'; 
}
function $(elem,objWin){ 
  retObj = false;
  if (objWin) {
    try {
      if (!retObj && typeof(objWin.document.getElementById)!="undefined") {
        retObj = objWin.document.getElementById(elem);
      }
      if (retObj)
        if (retObj.id==elem) 
          return retObj;
      retObj = false;
    } catch(e) {}
    try {
      if (!retObj && typeof(objWin.document.getElementByName)!="undefined") {
        retObj = objWin.document.getElementByName(elem);
      }
      if (retObj)      
        if (retObj.name==elem) 
          return retObj;
      retObj = false;          
    } catch(e) {}
    try {
      if (!retObj && typeof(objWin.document.all)!="undefined") {
        retObj = objWin.document.all(elem);
      }
      if (retObj)
        if (retObj.name==elem || retObj.id==elem) 
          return retObj;
      retObj = false;          
    } catch(e) {}
    if (retObj!=null) 
      return retObj;
    else 
      return false;
  }
  else {
    try {
      if (!retObj && typeof(document.getElementById)!="undefined") {
        retObj = document.getElementById(elem);
      }
      if (retObj)
        if (retObj.id==elem) 
          return retObj;
      retObj = false;          
    } catch(e) {}
    try {
      if (!retObj && typeof(document.getElementByName)!="undefined") {
        retObj = document.getElementByName(elem);
      }
      if (retObj)
        if (retObj.name==elem)
          return retObj;
      retObj = false;          
    } catch(e) {}
    try {
      if (!retObj && typeof(document.all)!="undefined") {
        retObj = document.all(elem);
      }
      if (retObj)
        if (retObj.name==elem || retObj.id==elem) 
          return retObj;
      retObj = false;          
    } catch(e) {}
    if (retObj!=false) 
      return retObj;
    else
      return false;
  }
}
function $frm(elem,frmname) { 
  if ($(elem)) {
    element = eval('document.'+frmname+'.'+elem);
    return element;
  }
  else {
    return false;
  }
}     
function getStringValue(getFromString,searchString) {
  var foundstring = '';
  var cid_start   = getFromString.indexOf(searchString+'=');
  if (cid_start>-1) {
    cid_start = cid_start + searchString.length+1;
    var cid_end = getFromString.indexOf("&",cid_start);
    if (cid_end>0)
      foundstring = getFromString.substr(cid_start,cid_end-cid_start);
    else
      foundstring = getFromString.substr(cid_start,getFromString.length-cid_start);
  }
  return foundstring;
}
function loadhelp(helpfile) {
  var helpwin = window.open(helpfile,'_blank');
  return false;
}
function delaymillsec(millis) {
  var date = new Date();
  var curDate = null;
  do { curDate = new Date(); } 
  while(curDate-date < millis);
} 

function transformToUpperCase(eingabeFeld) {
  var strUpperCase;
  strUpperCase = eingabeFeld.value.toUpperCase();
  eingabeFeld.value=strUpperCase;
}
function set_mandatory_form(form,objname,defaultvalue,setfrominit) {
  element           = eval('document.'+form+'.'+objname);
  cx_element        = eval('document.'+form+'.cx_'+objname);
  oldClass          = element.className;
  if (oldClass.indexOf('Key')>0) {
    oldClassName_S    = oldClass.substring(0,oldClass.indexOf('Key'));
    oldClassName_E    = oldClass.substring(oldClass.indexOf('Key')+3);  
  }
  else
    if (oldClass.indexOf('ReadOnly')>0) {
      oldClassName_S    = oldClass.substring(0,oldClass.indexOf('ReadOnly'));
      oldClassName_E    = oldClass.substring(oldClass.indexOf('ReadOnly')+8);    
    }
    else {
      oldClassName_S    = "inputbox";
      oldClassName_E    = oldClass.substring(oldClass.indexOf('inputbox')+8);     
    }
  if (cx_element.checked) {
    if (!setfrominit)
    changedElements     = true;
    element.value       = defaultvalue;
    element.className   = oldClassName_S+'ReadOnly'+oldClassName_E;
    if (element.mandatory!="")
      element.mandatory = "false";
    element.readOnly    = true;
    cx_element.checked  = true;
  }
  else {
    if (element.value==defaultvalue)
    element.value       = '';
    if (!setfrominit)
    changedElements     = true;
    if (element.mandatory && element.mandatory!="false") {
      element.mandatory   = "true";
      element.className   = oldClassName_S+'Key'+oldClassName_E;  
    }
    else
      element.className   = oldClassName_S+oldClassName_E;  
    element.readOnly    = false;
    cx_element.checked  = false;
  }
}
function set_novalue(objname,defaultvalue,setfrominit) {
  element           = $(objname);
  cx_element        = $('cx_'+objname);  
  if (element && cx_element) {
    oldClass          = element.className;
    if (oldClass.indexOf('Key')>0) {
      oldClassName_S    = oldClass.substring(0,oldClass.indexOf('Key'));
      oldClassName_E    = oldClass.substring(oldClass.indexOf('Key')+3);  
    }
    else {
      if (oldClass.indexOf('ReadOnly')>0) {
        oldClassName_S    = oldClass.substring(0,oldClass.indexOf('ReadOnly'));
        oldClassName_E    = oldClass.substring(oldClass.indexOf('ReadOnly')+8);    
      }
      else {
        oldClassName_S    = oldClass;
        oldClassName_E    = "";
      }
    }
    if (cx_element.checked) {
      if (!setfrominit)
      changedElements     = true;
      element.value       = defaultvalue;
      element.className   = oldClassName_S+'ReadOnly'+oldClassName_E;
      element.readOnly    = true;
      cx_element.checked  = true;
    }
    else {
      if (element.value==defaultvalue)
      element.value       = '';
      if (!setfrominit)
      changedElements     = true;
      element.className   = oldClassName_S+'Key'+oldClassName_E;
      element.readOnly    = false;
      cx_element.checked  = false;
    }
  }
}
function fc_form2popup(objfrm,popupvalues,popupname,iframename,hideProgressBar) {
  if (hideProgressBar)
    var showProgressBar = false;
  else
    var showProgressBar = true;
  WebCarAnalyserPopUp = false;
  if (objfrm=="[object]" || objfrm=="[object HTMLFormElement]") {
    if (iframename) {
      if ($(iframename)) {
        objfrm.target=iframename;
        startProgressBar(showProgressBar,objfrm.name);
        convertalldate(objfrm);
        objfrm.submit();
        return false;
      }
    }
    WebCarAnalyserPopUp = window.open('',popupname,popupvalues);
    convertalldate(objfrm);
    objfrm.submit();
    WebCarAnalyserPopUp.focus();
    return false;
  }
  else {  
    if (iframename) {
      if ($(iframename)) {
        startProgressBar(showProgressBar);
        $(iframename).src=objfrm;       
        return false;
      }
    }    
    if (objfrm.indexOf("print=pdf")>0)
			if (popupvalues)
	      WebCarAnalyserPopUp = window.open('blank.html',popupname,popupvalues);
			else
	      WebCarAnalyserPopUp = window.open('blank.html',popupname);        
    //idee: http bzw. https mitzuliefern, pdfs öffnen sich dann aber nicht
    //if (this.location.protocol)
    //  locationhead = this.location.protocol + "//";
    //else
    locationhead = "http://";
    if (objfrm.substr(0,1)=="/")
      objfrm = objfrm.substr(1);
    if (objfrm.indexOf("http")==-1)
      if (this.location.host=="localhost")
        if (objfrm.indexOf("crm.autopro24.at")==-1)
          objfrm = locationhead+this.location.host+"/crm.autopro24.at/"+objfrm;
        else
          objfrm = locationhead+this.location.host+"/"+objfrm;
      else
        objfrm = locationhead+this.location.host+"/"+objfrm;
    //objfrm = objfrm.replace("//","/");
		if (popupvalues)
	    WebCarAnalyserPopUp2nd = window.open(objfrm,popupname,popupvalues);
		else
	    WebCarAnalyserPopUp2nd = window.open(objfrm,popupname,popupvalues);	
    if (!WebCarAnalyserPopUp2nd)
      alert('Um diese Funktionsweise zu Nutzen, müssen Sie Ihren PopUp-Blocker für diese Seite deaktivieren!');
    else {
      try { WebCarAnalyserPopUp2nd.focus(); } catch(err) {; };
    }
    return false;
  }
}
function checkboxasoption(element,mandatory) {
  var listElement  = (typeof(document.getElementsByName)) ? document.getElementsByName(element.name) : document.getElementById(element.id);
  var valueElement = element.value;
  if (!element.checked) {
    setone = false;
    for (il=0;il<listElement.length;il++) 
      if (listElement[il].checked) setone=true;
    if (setone || !mandatory)
      return true;
    else {
      element.checked = true;
      return false;
    }
  }
  for (il=0;il<listElement.length;il++) {
    if (listElement[il].value==valueElement && element.checked)
      listElement[il].checked = true;
    else
      listElement[il].checked = false;
  }
}
function format(val,currency) {
  val=(val+"").replace(/\,/g,"");
  return ((currency? currency:"") + (Math.round(val*100) + (val<0?-0.1:+0.1))/ 100).replace(/(.*\.\d\d)\d*/,'$1');
}
function format_number2db(obj) {
  value = obj.value.replace(",",".");
  obj.value = format(value,"");
}
function number_format(number, decimals, dec_point, thousands_sep) {
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1) {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if (decimals != null) {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0) {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "") {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  
  return sign + integer + fractional + exponent;
}
Date.prototype.equals = function(y, m, d){
  var bOK = false;
  var _year;
  if(!this.getFullYear){
    _year = this.getYear() + 1900;
  } else {
    _year = this.getFullYear();
  }
  var _month = this.getMonth();
  var _day = this.getDate();
  return (_year == y && _month == m && _day == d);
}
// Umschlüsseln aller Felder mit convert_check_date
function convertalldate(objfrm) {
  // für alle input - objekte des formulars
  var arElements  = document.getElementsByTagName("input");
  for(var i=0; i < arElements.length; i++) {
    var singleElement = arElements[i];
    var singleAction  = singleElement.onclick+singleElement.onblur+singleElement.onchange;
    if (singleAction) {
      if (singleAction.indexOf('convert_check_date')>0 && singleElement.value!='') {
        if (singleAction.indexOf('YYYY-MM-DD HH:MM:SS')>0 || singleAction.indexOf('DD.MM.YYYY HH:MM:SS')>0)
          singleElement.value  = convert_check_date(singleElement,'YYYY-MM-DD HH:MM:SS');   
        else if (singleAction.indexOf('YYYY-MM-DD HH:MM+SS')>0 || singleAction.indexOf('DD.MM.YYYY HH:MM+SS')>0)
          singleElement.value  = convert_check_date(singleElement,'YYYY-MM-DD HH:MM+SS');   
        else if (singleAction.indexOf('YYYY-MM-DD HH:MM')>0 || singleAction.indexOf('DD.MM.YYYY HH:MM')>0)
          singleElement.value  = convert_check_date(singleElement,'YYYY-MM-DD HH:MM+SS'); 
        else if (singleAction.indexOf('YYYY-MM-DD')>0 || singleAction.indexOf('DD.MM.YYYY')>0)
          singleElement.value  = convert_check_date(singleElement,'YYYY-MM-DD');             
        else
          singleElement.value  = convert_check_date(singleElement,'YYYY-MM-DD');   
      }
    }
  }
}
function convert_check_date(checkobj,format,nopreyear) {
  var result;
  var rresult       = "";
  var date_out      = "";
  var d             = 0;
  var m             = 0;
  var y             = 0;
  var errmsg        = "";
  if (!format)
    format          = 'DD.MM.YYYY';
  var DatumAktuell  = new Date();  
  var strDate       = checkobj.value;
  if (!strDate || strDate.replace(' ','')=="")
    return '';
  result = true;    
  if (strDate) {
    arrDate = strDate.split(' ');
    strDate = arrDate[0];
    tz = '-';
    if (strDate.indexOf('-')>0) tz='-';
    if (strDate.indexOf('.')>0) tz='.';
    if (strDate.indexOf('/')>0) tz='/';
    var spl       = strDate.split(tz);
    // falls zeit im format
    if (format.indexOf('HH:MM')>0) {
      if (arrDate.length>1) {
        strTime     = arrDate[1];
        var splTime = strTime.split(':');    
        if (splTime[0]>23) {
          errmsg = 'Zeitstempel nicht möglich';       
          result = false;
        }
        if (splTime[1]>59) {
          errmsg = 'Zeitstempel nicht möglich';          
          result = false;      
        }
      }
      if (strTime=='') {
        var Std = DatumAktuell.getHours();
        var Min = DatumAktuell.getMinutes();
        var StdAusgabe = ((Std < 10) ? "0" + Std : Std);
        var MinAusgabe = ((Min < 10) ? "0" + Min : Min);      
        arrDate[1] = StdAusgabe+':'+MinAusgabe;
        if (format.indexOf('HH:MM+SS')>0)
          arrDate[1] = arrDate[1] +':00';
      }
      else {
        if (splTime.length<3 && format.indexOf('HH:MM+SS')>0)
          arrDate[1] = arrDate[1] +':00';      
      }
    }
    var setformat = '';
    if (spl.length==2) {
      curYear = DatumAktuell.getYear();
      if (curYear < 999)
        curYear += 1900;       
      if (spl[1]>(DatumAktuell.getMonth()+1)) {   
        if (!nopreyear)
          spl[2] = (curYear-1)+'';
        else
          spl[2] = curYear+'';
      }
      else
        spl[2] = curYear+'';
    }       
    if (spl.length==3) {    
      // JJJJ-MM-DD
      if (spl[0].length==4) {
        y = spl[0];
        m = spl[1];
        if (m<10 && m.length<2) {
          m = '0'+''+m;
          setformat = 'YYYY-MM-DD';
        }
        d = spl[2];
        if (d<10 && d.length<2) {
          d = '0'+''+d;
          setformat = 'YYYY-MM-DD';
        }
      }      
      // DD-MM-JJJJ
      // DD-MM-JJ
      else if (spl[2].length==4 || spl[2].length==2) {
        y = spl[2];        
        if (y.length==2 && y.length<3) {
          y='20'+''+y;
          setformat = 'DD.MM.YYYY';
        }
        m = spl[1];
        if (m<10 && m.length<2) {
          m = '0'+''+m;
          setformat = 'DD.MM.YYYY';
        }
        d = spl[0];
        if (d<10 && d.length<2) {
          d = '0'+''+d;
          setformat = 'DD.MM.YYYY';
        }
        if (m.length==2 && d.length==2 && y.length==4)
          setformat = 'DD.MM.YYYY';        
      }
      if (d>0 && m>0 && y>0) {
        date_out = d+'.'+m+'.'+y;
        mC = parseInt(m, 10) - 1;
        var datum = new Date(y, mC, d);
        if (datum.equals(y,mC,d)) {
          if (format=='YYYY-MM-DD') {
            rresult = y+'-'+m+'-'+d;
          }
          if (format=='DD.MM.YYYY') {
            rresult = d+'.'+m+'.'+y; 
          }
          if (format=='YYYY-MM-DD HH:MM' && arrDate.length>1) {
            rresult = y+'-'+m+'-'+d+' '+arrDate[1]; 
            date_out = rresult;
          }           
          if (format=='DD.MM.YYYY HH:MM' && arrDate.length>1) {
            rresult = d+'.'+m+'.'+y+' '+arrDate[1]; 
            date_out = rresult;
          }                
          if (format=='YYYY-MM-DD HH:MM:SS' && arrDate.length>1) {
            rresult = y+'-'+m+'-'+d+' '+arrDate[1]; 
            date_out = rresult;
          }
          if (format=='DD.MM.YYYY HH:MM:SS' && arrDate.length>1) {
            rresult = d+'.'+m+'.'+y+' '+arrDate[1]; 
            date_out = rresult;
          }          
          if (format=='YYYY-MM-DD HH:MM+SS' && arrDate.length>1) {
            rresult = y+'-'+m+'-'+d+' '+arrDate[1];            
            date_out = rresult;
          }
          if (format=='DD.MM.YYYY HH:MM+SS' && arrDate.length>1) {
            rresult = d+'.'+m+'.'+y+' '+arrDate[1];            
            date_out = rresult;
          }   
        }
        else {
          result = false;    
        } 
      }      
      else {
        result = false;    
      } 
    }
    else {
      result = false;    
    } 
  }
  else
    result = false;
   
  if (result==false) {
    if (errmsg!='')
      errmsg = errmsg + '\n';
    if (date_out)  
      errmsg = errmsg + date_out+' als Datum/Zeit ist nicht möglich';
    else
      errmsg = errmsg + 'ungültige Datums-/zeiteingabe';
    alert(errmsg);
    checkobj.value = '';
    checkobj.focus();
    return false;
  }  
  if (rresult) {
    checkobj.value = rresult;   
    return rresult;
  }
  else {
    if (setformat) 
      checkobj.value = date_out;
    return rresult;
  }
}
function valuecheck(checkobj,arrNotValid,strLengthMin,strLengthMax) {
  var result;
  if (checkobj.value=="") return true;
  checkThisString = checkobj.value;
  
  if (arrNotValid=="")  
    var arrNotValid = new Array("ö","ä","ü","Ö","Ä","Ü","_"," ","!","§","$","%","&","/","(",")","=","ß","?","*","~","+","²","³","'","#");
  
  for (var s=0; s < checkThisString.length+1; s++) {  
    for (i=0; i <= arrNotValid.length; i++) {
      if (checkThisString.substr(s,1)==arrNotValid[i]) {
        alert('ungültiges Zeichen an Position '+(s+1));
        checkobj.focus();
        return false;      
      }
    }
  }
  if (strLengthMin!="") {
    if (checkThisString.length < strLengthMin) {
      alert('Die Eingabe muss mindestens '+strLengthMin+' Zeichen lang sein');
      checkobj.focus();
      return false; 
    }
  }
  if (strLengthMax!="") {
    if (checkThisString.length > strLengthMax) {
      alert('Die Eingabe muss maximal '+strLengthMax+' Zeichen lang sein');
      checkobj.focus();
      return false; 
    }
  }  
  return true;   
}
function numeric(checkobj,formatit,digits,min,max) {
  checkobj.value = checkobj.value.replace(",",".");
  if (!checkobj.value) return false;
  if (formatit)
    checkobj.value = format(checkobj.value,'');
  if (isNaN(checkobj.value)) {
    alert('nur nummerische Eingabe erlaubt [z.B 3.20]');
    checkobj.focus();
    return 0;
  }  
  if (digits && digits > 0) {
    if (checkobj.value > (math_pot(10,digits))) {
      alert('die eingegebene Zahl ist zu gross [0 - '+(math_pot(10,digits)-1)+']');
      checkobj.focus();
      return 0;    
    }
  }
  if (min && checkobj.value < min) {
    alert('die eingegebene Zahl ist zu klein [min. '+min+']');
    checkobj.focus();
    return 0;    
  }
  if (max && checkobj.value > max) {
    alert('die eingegebene Zahl ist zu gross [max. '+max+']');
    checkobj.focus();
    return 0;    
  }    
  return 1;
}
function math_pot(x,y) {
  var i,z=1;
  for (i=1;i<=y;i++)
    z*=x;
  return z;
}
function costumer4contractor(item,formname,costumerid,displayname) {
  var objWindow = getWindowByName('xCarAnalyserPaymentDetail;xCarAnalyserInvestDetail;xCarAnalyserPaymentRowDetail;xCarAnalyserMain');
  if (objWindow) {
    objWindow.setUpContractor(costumerid,displayname);
    objWindow.loadContractor(costumerid,item);
    objDiv = getFormObject('icon_contractor_add',objWindow);
    if (objDiv) objDiv.style.display = 'none';
    objDiv = getFormObject('icon_contractor_search',objWindow);
    if (objDiv) objDiv.style.display = 'none';
    
    var objWindow = getWindowByName('xCarAnalyserCostumerShow');
    if (objWindow) {
      objWindow.close();    
    }
  }
}
function costumer4car(item,formname,costumerid,displayname) {
  var sWindow = getWindowByName('xCarAnalyserTblConfigDetail;xCarAnalyserTblDetail;xCarAnalyserCarDetailSell;xCarAnalyserCarDetailBuy;xCarAnalyserCarDetail;xCarAnalyserCostumerConcat;xCarAnalyserPaymentDetail;xCarAnalyserPaymentShow;xCarAnalyserMain;xCarAnalyserCarShow');
  // übertragen des Namens und der Costumerid
  if (sWindow) {
    var attribut     = eval("sWindow.document."+formname+"."+item);
    attribut.value   = costumerid;
    var attribut     = eval("sWindow.document."+formname+"."+item+"_name");    
    attribut.value   = displayname;
    
    // überprüfen, ob nicht auch costumer_show_data offen ist
    var objWindow = getWindowByName('xCarAnalyserCostumerShow');
    if (objWindow) {
      objWindow.close();    
    }    
  }
}
function item2cash(item,formname,formvalues) {
  var sWindow = getWindowByName('xCarAnalyserCashDetail;xCarAnalyserCarSell');
  if (sWindow) {
    if (item=="car") {
      var values = formvalues.split("#");
      var attribut     = eval("sWindow.document."+formname+".carid");
      attribut.value   = values[0];
      var attribut     = eval("sWindow.document."+formname+".carversion");    
      attribut.value   = values[1];
      var attribut     = eval("sWindow.document."+formname+".buy_price");    
      attribut.value   = values[2];
      var attribut     = eval("sWindow.document."+formname+".holder");    
      attribut.value   = values[3];       
      sWindow.setUpValues(item);
    }
    if (item=="carsell") {
      var values = formvalues.split("#");
      var attribut     = eval("sWindow.document."+formname+".vk_car_autonr");
      attribut.value   = values[0];
      var attribut     = eval("sWindow.document."+formname+".vk_car_version");    
      attribut.value   = values[1];
      var attribut     = eval("sWindow.document."+formname+".vk_car_einkaufspreis");    
      attribut.value   = values[2];     
      sWindow.calculate();    
    }
  }
}
function my_print() {
  if (parent.frames.length==0) {
    window.print();
    window.close();
  }  
}
function LoadLayer(action,time) {
  if (typeof(document.getElementById)!="undefined")
    var oLoadLayer = document.getElementById("mLoadLayer");
  else if (typeof(document.all)!="undefined") 
    var oLoadLayer = document.all("mLoadLayer");          
  if (action==true) {
    oLoadLayer.style.left     = ((document.body.clientWidth/2+document.body.scrollLeft/2)-200)+" px";
    oLoadLayer.style.top      = ((document.body.clientHeight/2+document.body.scrollTop/2)-50)+" px";
    oLoadLayer.style.display  = "block";
  }
  if (action==false) {    
    oLoadLayer.style.display = "none";
    if (time)
      window.status='Verarbeitungszeit: '+time+' Sek.';return true;
  }
}
function insertTabOnKey(objname) {
  var tabspace="  ";
  if (window.event.keyCode==9) {
     insertAreaText(document.getElementById(objname),tabspace);
     window.event.returnValue = false;
     return false;
  }
}
function insertAreaText( theForm, theText ) {
   if( document.selection) {
     theSelection      = window.document.selection.createRange();
     theSelection.text = theText;
   }
   else
   if( window.getSelection ) {
     oldValue = new String( theForm.value );
     textStart = theForm.selectionStart;
     textEnd = theForm.selectionEnd;
     newValue = oldValue.substring( 0, textStart ) + theText + oldValue.substring( textEnd, oldValue.length );
     theForm.value = newValue;
   }
   else {
     theForm.value += theText;
   }
}
function textarea_adjust(textarea,minrows,maxrows) {
  // zeilenumbrueche harmonisieren
  var text = textarea.value.replace(/(\015\012)|(\015)|(\012)/g, '\n');
  // text in array verwandeln
  var text_arr = text.split('\n');
  textarea.rows = text_arr.length+1;
  if (isNaN(minrows)) {
  }
  else {
    if (minrows > textarea.rows)
      textarea.rows = minrows;
  }
  if (isNaN(maxrows)) {
  }
  else {
    if (maxrows < textarea.rows && maxrows > 0)
      textarea.rows = maxrows;
  }  
}
function layerresize(resize) {
  if (resize) {
    if (window.opener && !window.opener.closed) 
      resize=resize-20;
    layersize = (screen.height-resize)+"px";
  }
  else
    layersize = "100%";
    
  if (document.getElementById)   
    var oLoadLayer = document.getElementById("content");
  else if (document.all) 
    var oLoadLayer = document.all("content");    
  if (oLoadLayer) {
    oLoadLayer.style.height = layersize;
  }
}
function checkKeyPressEnter(event) {  
  if (getPressedKey(event)=='13') {
    return true;
  }
  else {
    return false;
  }
}
function getPressedKey(e) {
 if (!e) {
  //if the browser did not pass the event 
  //information to the function, 
  //we will have to obtain it from the 
  //event register
  if (window.event) {
     //Internet Explorer
      e = window.event;
   } else {
     //total failure, we have no 
    //way of referencing the event
     return;
   }
 }
 if (typeof (e.keyCode) == 'number') {
    //DOM
    e = e.keyCode;
  } else if (typeof (e.which) == 'number') {
    //NS 4 compatible
    e = e.which;
  } else if (typeof (e.charCode) == 'number') {
   //also NS 6+, Mozilla 0.9+
    e = e.charCode;
  } else {
    //total failure, we have no way of obtaining the key code
    return;
  }
}
function searchCostumer(InputField,OldValue,NewValue) {
  InputFieldName = InputField;
  InputField     = InputField.substring(0,InputField.indexOf("_"));
  if (document.getElementById) {
    var objInputField       = document.getElementById(InputField);
    var objInputFieldName   = document.getElementById(InputFieldName);
    var objInputFieldLupe   = document.getElementById(InputField+"_lupe");  
    var objInputFieldDetail = document.getElementById(InputField+"_detail");      
  }
  else if (document.all) {
    var objInputField       = document.all(InputField);  
    var objInputFieldName   = document.all(InputFieldName);  
    var objInputFieldLupe   = document.all(InputField+"_lupe");  
    var objInputFieldDetail = document.all(InputField+"_detail");  
  }
      
  if (OldValue!=NewValue) {
    if (objInputFieldLupe) {
      objInputField.value = '';
      objInputFieldLupe.onclick();
    }
    else
      objInputFieldName.value = OldValue;
    return false;      
  }
  else {
    if (objInputFieldDetail)
      objInputFieldDetail.onclick();
    return false;
  }
}
// ------------------------------------------------------------------------------------------
// function: setFormValue
// Setzen einer FormVaribale abhängig vom Browsertyp
// ------------------------------------------------------------------------------------------
function setFormValue(fieldname,fieldvalue) {
  if ($(fieldname)) {
    $(fieldname).value=fieldvalue;
  }
}
// ------------------------------------------------------------------------------------------
// function: setFormValue
// Setzen einer FormVaribale abhängig vom Browsertyp
// ------------------------------------------------------------------------------------------
function getFormValue(fieldname) {
  var ele = $(fieldname);
  if (ele) {
    return ele.value;
  }
}
// ------------------------------------------------------------------------------------------
// function: getFormObject
// liefern des Object zu einer FormVaribale abhängig vom Browsertyp
// ------------------------------------------------------------------------------------------
function getFormObject(fieldname,LoadpWindow) {
  if (LoadpWindow) {
    if ((LoadpWindow=="[object]" || LoadpWindow=="[object HTMLFormElement]") && !LoadpWindow.closed) {
      var pWindow = LoadpWindow;
    }
    else {
      if (window.opener && !window.opener.closed)
        var pWindow = window.opener;  
      if (window.parent && !window.parent.closed)
        var pWindow = window.parent;
    }    
    var element = $(fieldname,pWindow);
    if (element) {
      return element;
    }
  }
  else {
    var element = $(fieldname);
    if (element) {
      return element;
    }   
  }
}
// ------------------------------------------------------------------------------------------
// function: getWindowByName
// liefern des Object zu einem Window nach Name window.name
// ------------------------------------------------------------------------------------------
function getWindowByName(winName) {
  var pWindow = window;
  arrWinName = winName.split(";");
  // if current page is search page
  if (!pWindow.closed) {
    for (iName=0;iName < arrWinName.length;iName++) {
      if ((pWindow.name.indexOf(arrWinName[iName])>-1)) {
        if (!sWindow) {
          return pWindow;
        }
      }
    }
  }  
  // suchen des zu übertragenden formulars
  do {
    if (typeof(pWindow)=="object" && pWindow.name) {
      var pWindow = pWindow.opener;
      if (typeof(pWindow)=="object") {
        if (!pWindow.closed) {
          for (iName=0;iName < arrWinName.length;iName++) {
            if ((pWindow.name.indexOf(arrWinName[iName])>-1)) {
              if (!sWindow)
                var sWindow = pWindow;
            }
          }
        }
      }
    }
  } while (typeof(pWindow)=="object" && pWindow.name && !sWindow);
  return sWindow;
}
// ------------------------------------------------------------------------------------------
// function: getRadioValue
// liefern den Wert des aktuell ausgewählten Radio-Types
// ------------------------------------------------------------------------------------------
function getRadioValue(objRadio) {
  for (var i=0; i<objRadio.length; i++) if (objRadio[i].checked) return objRadio[i].value;
  return false;
}
// ------------------------------------------------------------------------------------------
// function: getCheckBoxById
// ------------------------------------------------------------------------------------------
function getCheckBoxById(object, frm_name) {
  obj_id = object + "[]";
  if ($(obj_id)) {
    if (typeof(frm_name)!='undefined')
      var obj_form = frm_name;
    else
      var obj_form = $(obj_id).form.name;
    try {
      obj_all = document.forms[obj_form].elements[object];
      return obj_all;      
    } catch(e) { 
      return false;
    }
  }
  else {
    return false;
  }
}
// ------------------------------------------------------------------------------------------
// function: getCheckBoxValue
// liefern den Wert des aktuell ausgewählten Checkbox-Types
// ------------------------------------------------------------------------------------------
function GetSetCheckBoxValue(object,setCheckedValue) {
  obj_id = object + "[]";
  if ($(obj_id)) {
    var obj_form = $(obj_id).form.name;
    try {
      obj_all = document.forms[obj_form].elements[object];
      for (iO=0; iO < obj_all.length; iO++) {
        if (setCheckedValue) {
          if (obj_all[iO].value==setCheckedValue) 
            obj_all[iO].checked = true;
          else
            obj_all[iO].checked = false;
        }
        else {
          if (obj_all[iO].checked) { 
            return obj_all[iO].value;
          }
        }      
      }
      if (setCheckedValue) 
        return setCheckedValue;
      else
        return false;       
    } catch (e) { 
      return false;
    }
  }
  else {
    return false;
  }
}
function IEOnly_GetSetCheckBoxValue(objCheckBox,setCheckedValue) {
  var checkobj = document.all(objCheckBox);
  var checkobj = $(objCheckBox);
  for (var i=0; i<checkobj.length; i++) { 
    if (setCheckedValue) {
      if (checkobj[i].value==setCheckedValue) 
        checkobj[i].checked = true;
      else
        checkobj[i].checked = false;
    }
    else {
      if (checkobj[i].checked) 
        return checkobj[i].value;
    }
  }
  if (setCheckedValue) 
    return setCheckedValue;
  else
    return false; 
}
// ------------------------------------------------------------------------------------------
// function: stripQueryString
// liefern "location" ohne Parameter zurück
// ------------------------------------------------------------------------------------------
function stripQueryString(path) {
  if (path.indexOf('?')>-1) 
    emptystring = path.substr(0,path.indexOf('?'));
  else
    emptystring = path;
  return emptystring;
}
// ------------------------------------------------------------------------------------------
// functions: setUpContent Height to make it scrollable
// ------------------------------------------------------------------------------------------
function f_setContentHeight(object,forBrowser) {
  var setHeight=0;
  if (forBrowser) {
    if (forBrowser.indexOf(navigator.appName)>-1) {
      setHeight = 1;
    }
    else {
      setHeight = 0;
    }
  }
  else {
    setHeight = 1;  
  }
  if (setHeight==1) {
    if ($(object)) {
      clientHeight = f_clientHeight();
      contentPosY  = f_findPosY($(object));
      setHeight    = clientHeight-contentPosY;
      if (setHeight>0) {
        $(object).style.height = setHeight;
      }
    }
  }
}
function f_clientHeight() {
  return f_filterResults (
    window.innerHeight ? window.innerHeight : 0,
    document.documentElement ? document.documentElement.clientHeight : 0,
    document.body ? document.body.clientHeight : 0
  );
}  
function f_filterResults(n_win, n_docel, n_body) {
  var n_result = n_win ? n_win : 0;
  if (n_docel && (!n_result || (n_result > n_docel)))
    n_result = n_docel;
  return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}  
function f_findPosY(obj) {
   var curtop = 0;
   if(obj.offsetParent) {
      while(obj.offsetParent) {
         curtop += obj.offsetTop
         obj = obj.offsetParent;
      }
   }
   else if(obj.y)
      curtop = obj.y;
   return curtop;
} 
