
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// JS-Include File for own functions / extensions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

var selected;
var submitter = null;



function submitFunction() {
    submitter = 1;
}
function popupWindow(url) {
 var Info = window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
	//alert(Info.name);
	if (Info.name) {
		document.getElementById('POPUPERRORBOX').style.display = "none";
	}
	else {
		document.getElementById('POPUPERRORBOX').style.display = "block";
	}
}

function popupSantanderWindow(url) {
 var ccWin = window.open(url,'ccWin','width=800,height=600,dependent=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no')
	//alert(Info.name);
	if (ccWin.name) {
		document.getElementById('POPUPERRORBOX').style.display = "none";
	}
	else {
		document.getElementById('POPUPERRORBOX').style.display = "block";
	}
}

function popupRechnerWindow(url) {
 var Info = window.open(url,'ccWin','toolbar=0,menubar=1,width=470,height=475,location=0,scrollbars=1')
	//alert(Info.name);
	if (Info.name) {
		document.getElementById('POPUPERRORBOX').style.display = "none";
	}
	else {
		document.getElementById('POPUPERRORBOX').style.display = "block";
	}
}

function popupTellWindow(url) {
 var Info = window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=537,height=677,screenX=150,screenY=150,top=150,left=150')
	//alert(Info.name);
	if (Info.name) {
		document.getElementById('POPUPERRORBOX').style.display = "none";
	}
	else {
		document.getElementById('POPUPERRORBOX').style.display = "block";
	}
}

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.getElementById('payment'[0])) {
    document.getElementById('payment'[buttonSelect]).checked=true;
  } else {
    //document.getElementById('payment'[selected]).checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function popupImageWindow(url) {
  window.open(url,'popupImageWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}


//----[ Hauptnavigation ]----------------------------------------------------------------

aktsub=-1;
showtimer=false;

function timeshowsub(nr, subwidth) {
	showtimer=window.setTimeout("showsub("+nr+","+subwidth+")", 500); // Open layer delayed
}
function showsub(nr, subwidth) {

    // position & resize active submenu --[SD]--
    sm=document.getElementById('SUBNAV'+nr);
    mn=document.getElementById('NAV'+nr);
	hn=document.getElementById('NAVI');
	if (!subwidth) subwidth=(mn.offsetWidth-2);

    if (sm) {
		sm.style.width=subwidth+"px";
		leftend=getX(hn)+hn.offsetWidth-14; // right end of navigation
		
		if (getX(mn)+subwidth < leftend) {
			sm.style.left=getX(mn)-13+"px";
		} else {
			//sm.style.left=leftend-subwidth+"px"; // stop at the right end
			sm.style.left=getX(mn)-subwidth+mn.offsetWidth-14+"px"; // flip to the left side!
		}
		sm.style.top=mn.offsetHeight+getY(mn)+"px";
	}
//document.forms.loginbox.email_address.value=getX(mn); // debug...
	// hide all layers and show the selected
	for (i=0;i<19;i++) {
		if (document.getElementById('SUBNAV'+i)) {
			document.getElementById('SUBNAV'+i).style.display=(i==nr)?'block':'none'; 
		}
		if (document.getElementById('NAV'+i) && i!=selnav) {
			document.getElementById('NAV'+i).className=(i==nr)?'hover':''; 
		}
	}
	aktsub=nr;
	
}
function keepsub(nr) {
	aktsub=nr;
}
function timesub() {
	// set 0.5 sec timeout for layer
	
	if (showtimer!=false) {
		clearTimeout(showtimer); // kill main delay for
		timer=window.setTimeout("hidesub()", 500);
		aktsub=-1;
	}
}
function hidesub() {
	// hide all layers
	if (aktsub<0) {
		for (i=0;i<19;i++) {
			if (document.getElementById('SUBNAV'+i)) {
				document.getElementById('SUBNAV'+i).style.display='none'; 
			}
			if (document.getElementById('NAV'+i) && i!=selnav) {
					document.getElementById('NAV'+i).className=''; 
			}
		}
	}
}

function getX(el) {
var x = parseInt(el.offsetLeft);
if (!el.offsetParent) return x;
else return (x+getX(el.offsetParent));
}

function getY (el) {
  var y = parseInt( el.offsetTop );
  if (!el.offsetParent) return y;
  else return y + getY(el.offsetParent);
}


//----[ Produktvergleich ]----------------------------------------------------------------

function checkAll(switcher) {
	var cb = document.getElementsByTagName("input");
  for (var i=0; i<cb.length; i++)
  	if (cb[i].type.indexOf(cb) != 1) cb[i].checked = switcher;
}

 function getParamStr () {
    var paramStr = 'checkbox';
    for ( i=0; i < document.forms[0].elements.length; i++ ) {
       var element = document.forms[0].elements[i];
       paramStr = paramStr + element.name + '=' + element.value + '&';
    }
    return paramStr;
 }

 function mySubmitOpener () {
    var progi = 'vergleich.php';
    var paramStr = getParamStr();
    var buildURL = progi + '?' + paramStr;
  //  alert( buildURL ); // for test purposes only ;)
    window.open( buildURL, '_blank', '' );
 }

function popupVWindow(url) {
 var Info = window.open(url,'window','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=600,screenX=150,screenY=150,top=150,left=150')
  	if (Info.name) {
		document.getElementById('POPUPERRORBOX').style.display = "none";
	}
	else {
		document.getElementById('POPUPERRORBOX').style.display = "block";
	}
} 

function popupVVWindow(url, window) {
 var Info = window.open(url,window,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=600,screenX=150,screenY=150,top=150,left=150')
 	if (Info.name) {
		document.getElementById('POPUPERRORBOX').style.display = "none";
	}
	else {
		document.getElementById('POPUPERRORBOX').style.display = "block";
	} 
} 

function NumOnly(a_oEvent)
{
var iKeyCode;
if (!document.all) {
iKeyCode = a_oEvent.which; //Firefox
} else {
iKeyCode = a_oEvent.keyCode; //IE
}

if (iKeyCode == 0 //alle möglichen Tasten zur Navigation (Tab, Pfeiltasten,...) 
|| iKeyCode == 8 // BackSpace
|| iKeyCode == 9 // TAB
|| iKeyCode == 13 // ENTER
//|| iKeyCode == 37 // Left
//|| iKeyCode == 39 // Right
//|| iKeyCode == 46 // Entf
|| ( iKeyCode > 47 && iKeyCode < 58 ) // 0..9 Tastatur
//|| ( iKeyCode > 95 && iKeyCode < 106 ) // 0..9 NumBlock
)
{
// auch die nicht zulassen, wenn mit shift, alt, ctrl
if ( !iKeyCode.shiftKey && !iKeyCode.altKey && !iKeyCode.ctrlKey ) {
return true;
}
}

return false; // Eingabe ignorieren
}

function NumOnly2(a_oEvent)
{
var iKeyCode;
if (!document.all) {
iKeyCode = a_oEvent.which; //Firefox
} else {
iKeyCode = a_oEvent.keyCode; //IE
}

if (iKeyCode == 0 //alle möglichen Tasten zur Navigation (Tab, Pfeiltasten,...) 
|| iKeyCode == 8 // BackSpace
|| iKeyCode == 9 // TAB
|| iKeyCode == 13 // ENTER
|| iKeyCode == 46 // Punkt
|| iKeyCode == 44 // Komma
//|| iKeyCode == 37 // Left
//|| iKeyCode == 39 // Right
//|| iKeyCode == 46 // Entf
|| ( iKeyCode > 47 && iKeyCode < 58 ) // 0..9 Tastatur
//|| ( iKeyCode > 95 && iKeyCode < 106 ) // 0..9 NumBlock
)
{
// auch die nicht zulassen, wenn mit shift, alt, ctrl
if ( !iKeyCode.shiftKey && !iKeyCode.altKey && !iKeyCode.ctrlKey ) {
return true;
}
}

return false; // Eingabe ignorieren
}


// Funktion um Tausenderpunkt einzufügen --> CE
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;
}
