
	
	
function $(v) { return(document.getElementById(v)); }
function $S(v) { return(document.getElementById(v).style); }

/*
function window_teil( url )
{
	window_teil_ = openwindow_center( url, 'teilwindow', 800, 600, 'yes', 'yes' );
	window_teil_.focus();
}
*/

function openwindow_center( url, name, width, height, scrollbars, resizable, menubar )
{
	var left = parseInt( (screen.width - width) / 2 );
	var top = parseInt( (screen.height - height) / 2 );
	
	if( left == NaN || left < 0 ) left = 0;
	if( top == NaN || top < 0 ) top = 0;
	if( scrollbars == undefined ) scrollbars = 'no';
	if( resizable == undefined ) resizable = 'no';
	if( menubar == undefined ) menubar = 'no';
	
	winopen = window.open( url, name, "width="+width+",height="+height+",left="+left+",top="+top+",scrollbars="+scrollbars+",status=no,menubar="+menubar+",toolbar=no,resizable="+resizable);
	
	return winopen;
}

/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
function setCheckboxes(the_form, the_field, do_check)
{
    var elts      = document.forms[the_form].elements[the_field];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        } // end for
    } else {
        elts.checked        = do_check;
    } // end if... else

} // end of the 'setCheckboxes()' function

function set_location_href( new_url )
{
	window.location.href = new_url;
	//alert( linktarget );
}

function Go(U,T) {
	var Check;
	Check=confirm(T);
	if(Check==true)
		this.location=U;
} 


function change_display( option, value )
{
	if( value == 1 )
	{
		document.getElementById(option + '_button').style.display = 'none';
		document.getElementById(option).style.display = '';
	}
	else
	{
		document.getElementById(option + '_button').style.display = '';
		document.getElementById(option).style.display = 'none';
	}
	set_cookie(option, value);
}

function set_cookie (Bezeichner, Wert) 
{
  var Verfallszeit = 1000 * 60 * 60 * 24 * 365;
  var jetzt = new Date();
  var Auszeit = new Date(jetzt.getTime() + Verfallszeit);
  document.cookie = Bezeichner + "=" + Wert + "; expires=" + Auszeit.toGMTString() + ";";
}

function add_option( select_id, value, name )
{
	var select_element = document.getElementById( select_id );
	
	var opt = document.createElement("option");
	
	opt.text = name;
	opt.value = value;
	var index = null;
  	if (document.all)
    	index = attr.length;
  	select_element.add(opt, index);
}

function add_to_cart(media_id)
{
	material = document.getElementById('material').value;
	format = document.getElementById('formats').value;
	fit = document.getElementById('fit').value;
	
	//alert(material + ',' + format + ',' + fit);
	xajax_add_to_cart_x(media_id, material + ',' + format + ',' + fit);
}


function submit_to_ajax(formname, x_func, x_params)
{
	var tmp_str = '';

	for(i=0;i<document.forms.item_edit_form.elements.length;i++)
	{
		if(document.forms.item_edit_form.elements[i].type == 'checkbox')
		{
			if(document.forms.item_edit_form.elements[i].checked === true)
			{
				tmp_str += document.forms.item_edit_form.elements[i].id + '~xx~' +document.forms.item_edit_form.elements[i].value + '**YY**';
			}
			
		}
		else
		{
			tmp_str += document.forms.item_edit_form.elements[i].id + '~xx~' +document.forms.item_edit_form.elements[i].value + '**YY**';
		}
	}
	eval('xajax_' + x_func + '("' + x_params + '","' + tmp_str + '")');
}
function toggle_status(name_str,default_class,count,id)
{
	
	for(i=0;i<count;i++)
	{
		document.getElementById(name_str + i).className = default_class;
	}
	document.getElementById(name_str + id).className = default_class +'_active';


}
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;
}