function openWin(URL,width,height,scroll,resize, status, menubar, toolbar, location, directories, winName) {
	noUrl = false
	if (URL == "" || URL == null) { URL="about:blank"; noUrl=true }
	if (width == "" || width == null ) { width = 640 }
	if (height == "" || height == null ) { height = 480 }
	if (width == "*" ) {
		width = (screen.availWidth * (100/99)) ;
		if (width > 800) width="800"; //since the site isn't wider than 800px, there's no point in opening in fullscreen mode, it just looks silly!
	}
	if (height == "*" ) {
	height =  (screen.availHeight * (100/95));
		if (height > 580) height="580";//since the site isn't taller than 800px, there's no point in opening in fullscreen mode, it just looks silly!
	}
	if (scroll == "" || scroll == null ) { scroll = 1 }
	if (resize == "" || resize == null ) { resize = 1 }
	if (status == "" || status == null ) { status = 1 }
	if (menubar == "" || menubar == null) {menubar=0}
	if (toolbar == "" || toolbar == null) {toolbar=0}
	if (location == "" || location == null) {location=0}
	if (directories == "" || directories == null) {directories=0}
	if (winName == "" || winName == null) {winName="NEW"}

	PARMS = 'toolbar='+toolbar +',location='+location +',directories='+directories +',status='+status +',menubar='+menubar +',scrollbars=' + scroll + ',resizable=' + resize + ',width=' + width + ',height=' + height
  var newWin = window.open(URL,winName,PARMS);
	/* newWin.screenX = 0;
  newWin.screenY = 0; */
	if (noUrl) {
		newWin.document.writeln("<BR><BR><FONT color='red'>It seems like you forgot to put in a value for URL when you called for <I>openWin()</I></FONT>")
		newWin.document.close()
	}
	return;
}

/* Switch map */
function swapMap(mapId) {
	document.getElementById('map').src = '_images/map_' + mapId  + '.gif';
}

/* Clear form fields */
function clearField(id, state) {
	if (state == 'clear')
		document.getElementById(id).value = '';
	else {
		if (document.getElementById(id).value == '')
			document.getElementById(id).value = 1;
	}
}
function moreInfo(infoLayerId, state) {
	grayOut(state);
	if (state == true) {
		document.getElementById('infoLayer_' + infoLayerId).style.zIndex = 100000;
		document.getElementById('infoLayer_' + infoLayerId).style.visibility = 'visible';

	}
	else {
		document.getElementById('infoLayer_' + infoLayerId).style.zIndex = -100000;
		document.getElementById('infoLayer_' + infoLayerId).style.visibility = 'hidden';
	}
}
var item_id;
var gteaser;
var old_value;
function addToCart(item, itemId, teaser) {
	item_id = itemId;
	if (teaser == 'teaser') {
		var quantity = document.getElementById('input_product_teaser_'+itemId).value;
		gteaser = 'teaser_';
	}
	else  {
		var quantity = document.getElementById('input_product_'+itemId).value;
		gteaser = '';
	}
	grayOut(true);
	document.getElementById('cartLayer').style.zIndex = 100000;
	document.getElementById('cartLayer').style.visibility = 'visible';
	var cartOrder = document.getElementById('cart_order');

	cartOrder.innerHTML = cartOrder.innerHTML.replace('$1', item);
	cartOrder.innerHTML = cartOrder.innerHTML.replace('$2', quantity);
	cartOrder.innerHTML = cartOrder.innerHTML.replace('[%1%]', '<strong>');
	cartOrder.innerHTML = cartOrder.innerHTML.replace('[%2%]', '</strong>');

}
function closeCartLayer() {
	grayOut(false);
	document.getElementById('cartLayer').style.zIndex = -100000;
	document.getElementById('cartLayer').style.visibility = 'hidden';
}
function resetCartLayer(resetText) {
	grayOut(false);
	document.getElementById('cartLayer').style.zIndex = -100000;
	document.getElementById('cartLayer').style.visibility = 'hidden';
	document.getElementById('cart_order').innerHTML = resetText;
}

function addItem() {
	doc = document.forms['product_list'];
	document.getElementById('productid').value = item_id;
	document.getElementById('quantity').value = document.getElementById('input_product_'+gteaser+item_id).value;
	document.getElementById('product_list').submit();
	resetCartLayer('Produkt [%1%]$1[%2%] ($2x) zum Warenkorb hinzufügen?');
}
function changeQuantity(itemId, newValue) {
		doc = document.forms['product_list'];
		doc.productid.value = itemId;
		if (newValue == '+')
			doc.quantity.value = 1;
		else
			doc.quantity.value = -1;
		doc.submit();
		//alert(doc.quantity.value);
}
function calculateQuantity(new_value, itemId) {
	if (old_value != new_value) {
		var a = parseInt(old_value);
		var b = parseInt(new_value);

		doc = document.forms['product_list'];
		if (a > b)
			result = '-' + parseInt(a - b);
		else
			result = '+' + parseInt(b - a);;

		doc.productid.value = itemId;
		doc.quantity.value = result;
		doc.submit();
	}
}

function transferUserData(form) {
	doc = document.getElementById(form);
	elements = doc.getElementsByTagName('input');
	var element_parts = '';
	for (var i = 0; i < elements.length; i++) {
		element_parts = elements[i].name.split('_');
		if (element_parts[1] == 'checkbox' || elements[i].name == 'payment_method')
			continue;
		elements[i].value =  document.getElementById('user_' + element_parts[1]).innerHTML;
	}
}

function checkSearchField(field, form) {
	if ($(field).value == '' || (($(field).id == 'email_nl' || $(field).id == 'femail') && ($(field).value.length < 6 || ($(field).value.indexOf("@") < 1)  || ($(field).value.indexOf(".") < 1))))
		Effect.Pulsate($(field),{duration:1, pulses: 2});
	else
		$(form).submit();
}

function setPaymentMethod(paymentMethod) {
	document.getElementById('payment_method').value = paymentMethod;
}

function mergeMail(name, prov, top, subject){
	document.location.href="mailto:" + name +"@"+ prov +"."+ top +"?subject=" + subject;
}

function checkOut(form, paymentMethod) {

	if (paymentMethod == 'creditCard') {
		if ($('extra_delivery_address').checked == true) {
			returnvalue = checkInputs('cart_checkout', '', '', '',  '', '', 'return');
			if (returnvalue ==  true) {
				$(form).action = "index.php?action=cart.checkout&lang=de&tpl=default&id=6.8";
				$('user_update').value = 'true';
				$(form).submit();
			}
		}
		else {
			if ($('terms_checkbox').checked == false)
				Effect.Pulsate($('cart_checkout_accept_terms'),{duration:1, pulses: 2});
			else
				sumbitSaferPay();
		}
	}
	else {
		$('payment_method').value = 'prepay';
		if ($('extra_delivery_address').checked == true)
			checkInputs('cart_checkout');
		else {
			if ($('terms_checkbox').checked == false)
				Effect.Pulsate($('cart_checkout_accept_terms'),{duration:1, pulses: 2});
			else
				$(form).submit();
		}
	}

	/*
	var returnvalue = false;
	if ($('extra_delivery_address').checked == true && paymentMethod == 'creditCard')
		returnvalue = checkInputs('cart_checkout', '', '', '',  '', '', 'return');
	else
		checkInputs('cart_checkout');

	if (returnvalue == true) {
		if ($('terms_checkbox').checked == true) {
			$('payment_method').value = 'prepay';
			if (paymentMethod == 'prepay'){
				$(form).submit();
			}
			else {

				if ($('extra_delivery_address').checked == true)
					document.$(form).action ="index.php?action=cart.checkout";
				else
					sumbitSaferPay();
			}
		}
		else {
			Effect.Pulsate($('cart_checkout_accept_terms'),{duration:1, pulses: 2});
			Effect.Pulsate($('terms_checkbox'),{duration:1, pulses: 2});
		}
	}
	*/
}


function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {};
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }
	//alert(pageHeight);
	var pageHeight='100%';
	var pageWidth='100%'
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;
    dark.style.MozOpacity=opaque;
    dark.style.filter='alpha(opacity='+opacity+')';
    dark.style.zIndex=zindex;
    dark.style.backgroundColor=bgcolor;
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';
  } else {
     dark.style.display='none';
  }
}


function check_zip(zipcode){

	var url = '_modules/mo_check_zip.php?zipcode=' + zipcode;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			if (transport.responseText.match('true')) {
				$('pay').style.display = ('block');
				$('pay_info').style.display = ('none');
			}
			else {
				$('pay').style.display = ('none');
				$('pay_info').style.display = ('block');
			}

		}
	});
}
