//#################################################################################################################################
// number_format() FÜR JAVASCRIPT - ANALOG ZUR PHP number_format() ################################################################
//#################################################################################################################################

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;

}

//#################################################################################################################################


// ################################################################################################################################
// RICHTIG KAUFMÄNNISCH RUNDEN MIT ROUNDOFF-FUNKTION  #############################################################################
// ################################################################################################################################

function roundoff(v, d) {

	r = Math.pow(10, d);
	v *= r;

	if (v - Math.floor(v) >= 0.49) {

		return (Math.ceil(v)/r);
	
	} else {

		return (Math.floor(v)/r);

	}

}

// ################################################################################################################################


// ################################################################################################################################
// TRIM FUNCTION LIKE PHP trim() ##################################################################################################
// ################################################################################################################################

function ltrim(str, chars) {
	
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");

}

function rtrim(str, chars) {
	
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");

}

function trim(str, chars) {
	
    return ltrim(rtrim(str, chars), chars);

}

// ################################################################################################################################


// ################################################################################################################################
// WINDOW OPENER ##################################################################################################################
// ################################################################################################################################

function windowOpener(open_url, window_name, window_width, window_height, window_resizable, window_scrollbars, window_menubar, window_toolbar, window_location, window_status) {

  window.open(open_url, window_name, "width=" + window_width + ",height=" + window_height + ",resizable=" + window_resizable + ",scrollbars=" + window_scrollbars + ",menubar=" + window_menubar + ",toolbar=" + window_toolbar + ",location=" + window_location + ",status=" + window_status + "");

}

// ################################################################################################################################


// ################################################################################################################################
// SHOW / HIDE ELEMENTS ###########################################################################################################
// ################################################################################################################################

function toggleElement(ElementID) {

	var current_element = document.getElementById(ElementID);

	if (current_element.style.display == '') {

		current_element.style.display = "none";

	}

	if (current_element.style.display == "none") {

		current_element.style.display = "block";

	} else {

	current_element.style.display = "none";

	}

	return false;

}

// ################################################################################################################################


// ################################################################################################################################
// SHOW / HIDE ALL ELEMENTS #######################################################################################################
// ################################################################################################################################

function toggleElementAll(content_div_name, total_div_elements, display_mode) {

	var sort_image		= '';

	// VERZEICHNIS ZUM BILD
	var image_folder	= '/images/ico/';

	// NAME DES BILDES
	var img_dropup	 	= 'toggle_minus_11x11.gif';
	var img_dropdown 	= 'toggle_plus_11x11.gif';

	// --

	// CHECK WELCHER MODE ÜBERGEBEN WORDEN IST
	if (display_mode == 'block')	{ block_image = 'ico_dropup'; none_image = 'ico_dropdown';	}
	if (display_mode == 'none')		{ block_image = 'ico_dropdown'; none_image = 'ico_dropup';	}

// --

		// BLOCK

		i = total_div_elements;

		for (var z = 1; z <= i; z++) {

		document.getElementById(content_div_name + '_' + z).style.display = display_mode;
		document.getElementById(block_image + '_' + z).style.display = "block";
		document.getElementById(none_image + '_' + z).style.display = "none";

		}

	// --

}

// ################################################################################################################################


// ################################################################################################################################
// REQUEST FORM FUNCTIONS #########################################################################################################
// ################################################################################################################################

function selectContactType(_mode) {

	if (_mode == 'mail') {

		document.getElementById('form_phone').style.display 	= "none";

	}

	// --

	if (_mode == 'phone') {

		document.getElementById('form_phone').style.display 	= "block";

	}

	return false;

}

// CHECKBOXEN HANDLING
function check_status(_mode) {

	var select_request1	= document.getElementById('select_request1_value').checked;
	var select_request2	= document.getElementById('select_request2_value').checked;

	if (_mode == 2) {

		if (select_request2 == true) {

			document.getElementById('select_request1_value').checked	= true;
			document.getElementById('select_request1_value').disabled	= false;

			// --

		}

		if (select_request2 == false) {

			document.getElementById('select_request1_value').checked	= false;
			document.getElementById('select_request1_value').disabled	= false;

			// --

		}

	}

	// --

}

// CLEAR FORM ELEMENT
function clearform(div_id) {

	if (div_id == 'optional_request' && document.getElementById('optional_request').value == 'Hier können Sie Ihre Anfrage oder weitere Wünsche wie z. B. Reparatur Ihres Displays eingeben') {

  	document.getElementById(div_id).value = '';

	}

}

// --

function fillform(div_id) {

	if (div_id == 'optional_request' && document.getElementById('optional_request').value == '') {

		document.getElementById(div_id).value = 'Hier können Sie Ihre Anfrage oder weitere Wünsche wie z. B. Reparatur Ihres Displays eingeben';

	}

}

// ################################################################################################################################