function is_empty(menuId) {
	var myObj;
	var ret_val;
	myObj = document.getElementById(menuId);
	if (myObj.value=='') {
		ret_val = true;
	} else {
		ret_val = false;
	}
	return ret_val;
}
function hide() {
	alert('test');
}
var myForm = -1;
function ptype_select(name,price) {
	myPrice = document.getElementById('price');
	myPrice.value = price;
	myName = document.getElementById('ptype');
	myName.value = name;
}


function ptype_select_new(form_id) {
	myForm = form_id;
}
function submit_order_new(alert_text,popup_text) {
	if (myForm==-1) {
		alert(alert_text);
		return false;
	} else  {
		submitForm = document.getElementById(myForm);
		if (submitForm.as_popup.value==1) {
			if (submitForm.is_netbank!=null && submitForm.is_netbank.value==1) {
				if (doPopupNetbank(submitForm)) {
					submitForm.submit();
				} else {
					alert(popup_text);
					return false;
				}
			} else {
				if (doPopup(submitForm)) {
					submitForm.submit();

				} else {
					alert(popup_text);
					return false;
				}
			}
		} else {
			submitForm.submit();
		}
	}
}

function submit_order(alert_text,popup_text) {
	myPrice = document.getElementById('price');
	myName = document.getElementById('ptype');
	if ((myPrice.value==-1) || (myName.value==-1)) {
		alert(alert_text);
	} else  {
		if (myName.value=='dibs_card') {
			my_dibs_card = document.getElementById('payment');
			if (doPopup(my_dibs_card)) {
				my_dibs_card.submit();
			} else {
				alert(popup_text);
			}
		} else if (myName.value=='dibs_net') {
			my_dibs_net = document.getElementById('payment');
			if (doPopup(my_dibs_net)) {
				my_dibs_net.submit();
			} else {
				alert(popup_text);
			}
		} else {
			return true;
		}
	}
	return false;
}

function showMenu(menuId) {
	var myObj;
	myObj = document.getElementById(menuId);
	myObj.style.visibility = 'visible';
	myObj.style.display = 'block';
	myObj.style.position = 'absolute';
	myObj.style.top = '1px';
	myObj.style.left = '1px';
	//myObj.style.width = '150px';
}

function hideMenu(menuId) {
	var myObj;
	myObj = document.getElementById(menuId);
	myObj.style.display = 'none';
	myObj.style.visibility = 'hidden';
	myObj.visibility = 'hidden';
}

function toggleMenu(menuId) {
	var myObj;
	myObj = document.getElementById(menuId);
	if (myObj.style.visibility == 'hidden') {
		showMenu(menuId);
	} else {
		hideMenu(menuId);
	}
}

var total_added_price = 0.00;

function toggleVariant(i,value) {
	var myObj;
	price_id = 'variant_price_'+i+value;
	current_price_id = 'current_variant_price_'+i;
	row_id = 'variant_'+i+'row';
	cell_id = 'variant_'+i+''+value;
	main_price_obj = document.getElementById('main_price');
	main_price = parseFloat(main_price_obj.value);
	myObj = document.getElementById(row_id);
	price = document.getElementById(price_id);
	
	total_variant_price_obj = document.getElementById('total_variant_price');
	total_added_price+= parseFloat(total_variant_price_obj.value);
	total_variant_price_obj.value = 0;
	
	current_price = document.getElementById(current_price_id);
	total_added_price = total_added_price -  parseFloat(current_price.value);
	
	
	current_price.value = price.value;
	total_added_price = total_added_price + parseFloat(current_price.value);
	if(myObj.firstChild) { // check for children
		var oChild = myObj.firstChild;
		while(oChild) { // run over them
			if(oChild.nodeType==1) {
				oChild.style.border = "1px solid #fff";
				// element
				// oChild is a first level child of oDiv
				// Do what you want with it here
			}
			oChild = oChild.nextSibling;
		}
	}
	myCell = document.getElementById(cell_id);
	if (myCell) {
		myCell.style.border = "1px solid #000";
	}
	
	tmp_total = 0+main_price+total_added_price;
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) return;
	mySum = document.getElementById('total_price_display');

	mySum.firstChild.nodeValue = formatAsMoney(tmp_total);
	if (total_added_price>0) {
		item_show_image('total_price');
	} else {
		item_hide_image('total_price');
	}
}

function toggle_added_item(checkbox_obj,added_item_id,added_item_buy_id,item_price) {
	myObj = document.getElementById('main_price');
	main_price = parseFloat(myObj.value);
	item_price = parseFloat(item_price);
	if (checkbox_obj.checked) {
		total_added_price = total_added_price+item_price;
		show_added_item(added_item_id,added_item_buy_id);
	} else {
		total_added_price = total_added_price-item_price;
		hide_added_item(added_item_id,added_item_buy_id);
	}
	tmp_total = 0+main_price+total_added_price;
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) return;
	mySum = document.getElementById('total_price_display');

	mySum.firstChild.nodeValue = formatAsMoney(tmp_total);
	if (total_added_price>0) {
		item_show_image('total_price');
	} else {
		item_hide_image('total_price');
	}
}


function show_added_item(menuId,added_item_buy_id) {
	var myObj;
	//alert('Show: '+menuId);
	myObj_buy = document.getElementById(added_item_buy_id);
	myObj_buy.value = 1;
	myObj = document.getElementById(menuId);
	myObj.style.visibility = 'visible';
	myObj.style.display = 'block';
}

function hide_added_item(menuId,added_item_buy_id) {
	var myObj;
	//alert('Hide: '+menuId);
	myObj_buy = document.getElementById(added_item_buy_id);
	myObj_buy.value = 0;
	myObj = document.getElementById(menuId);
	myObj.style.display = 'none';
	myObj.style.visibility = 'hidden';
	myObj.visibility = 'hidden';
}
function formatAsMoney(mnt) {
	mnt -= 0;
	mnt = (Math.round(mnt*100))/100;
	return (mnt == Math.floor(mnt)) ? mnt + ',00'
	: ( (mnt*10 == Math.floor(mnt*10)) ?
	mnt + '0' : mnt);
}
function update_added(added_variant_input_id,new_value) {
	var myObj;
	//alert('Hide: '+menuId);
	myObj= document.getElementById(added_variant_input_id);
	myObj.value = new_value;
}

var current_selected_item = 'description';

function item_show_property(menuId) {
	var myObj;
	menu_link_id = menuId+'_a';
	myObj = document.getElementById(menuId);
	myLinkObj = document.getElementById(menu_link_id);
	myLinkObj.style.color = '#c5221a';
	myObj.style.visibility = 'visible';
	myObj.style.display = 'inline';
}

function item_hide_property(menuId) {
	var myObj;
	menu_link_id = menuId+'_a';
	myObj = document.getElementById(menuId);
	myLinkObj = document.getElementById(menu_link_id);
	myLinkObj.style.color = '#88b2a9';
	myObj.style.display = 'none';
	myObj.style.visibility = 'hidden';
	myObj.visibility = 'hidden';
}
function item_toggle_property(menuId) {
	item_hide_property(current_selected_item);
	item_show_property(menuId);
	current_selected_item = menuId;
	return false;
}

var current_selected_image = 'image_0';
function item_show_image(menuId) {
	var myObj;
	myObj = document.getElementById(menuId);
	myObj.style.visibility = 'visible';
	myObj.style.display = 'inline';
	//	myObj.style.background = '';
}

function item_hide_image(menuId) {
	var myObj;
	myObj = document.getElementById(menuId);
	myObj.style.display = 'none';
	myObj.style.visibility = 'hidden';
	myObj.visibility = 'hidden';
}
function item_toggle_image(menuId) {
	item_hide_image(current_selected_image);
	item_show_image(menuId);
	current_selected_image = menuId;
	return false;
}

newwin = null;
function doPopup(f) {
	newwin = window.open('', 'Betaling','menubar=no,toolbar=no,scrollbars,status,width=691,height=300');
	newwin.focus();
	if(!self.name) {
		self.name = 'shopwin';
	}
	if (!newwin.opener) {
		newwin.opener = self;
	}
	f.opener.value = self.name;
	return true;
}


function doPopupNetbank(f) {
	newwin = window.open('', 'Betaling','menubar=no,toolbar=no,scrollbars,status,width=800,height=600');
	newwin.focus();
	if(!self.name) {
		self.name = 'shopwin';
	}
	if (!newwin.opener) {
		newwin.opener = self;
	}
	//f.opener.value = self.name;
	return true;
}

defaultWidth  = 820;
defaultHeight = 620;
startX = 100;
startY = 100;
var multipleWindows = true;
if (parseInt(navigator.appVersion.charAt(0))>=4) {
	var isNN = (navigator.appName=="Netscape") ? 1 : 0;
	var isIE = (navigator.appName.indexOf("Microsoft")!=-1) ? 1 : 0;
}

var optNN = 'scrollbars=no,width=770,height=470,left='+startX+',top='+startY;
var optIE = 'scrollbars=no,width=770,height=470,left='+startX+',top='+startY;
function showImageOld(imageURL,imageTitle) {
	if (isNN) {
		imgWin=window.open('about:blank','',optNN);
	}
	if (isIE) {
		imgWin=window.open('about:blank','',optIE);
	}
	with (imgWin.document) {
		writeln('<html><head><title>BMC</title><style>body{margin:0px;}</style>');
		writeln('<scr'+'ipt>');
		writeln('var isNN,isIE;');
		writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');
		writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');
		writeln('if (isIE){');
		writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');
		writeln('if (isNN){');
		writeln('window.innerWidth=document.images["BMC"].width;');
		writeln('window.innerHeight=document.images["BMC"].height;}}');
		writeln('function make_title(){document.title="'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		if (!multipleWindows) {
			writeln('</head><body bgcolor="#000000" scroll="yes" onload="reSizeToImage();make_title();self.focus()">')
		}
		else {
			writeln('</head><body bgcolor="#000000" scroll="no" onload="reSizeToImage();make_title();self.focus()" onblur="self.close()">');
		}
		writeln('<img name="BMC" src="'+imageURL+'" style="display:block"></body></html>');
		close();
	}
}
function showImage(imageURL,imageTitle) {
	if (isNN) {
		imgWin=window.open('about:blank','',optNN);
	}
	if (isIE) {
		imgWin=window.open('about:blank','',optIE);
	}
	with (imgWin.document) {
		writeln('<html><head><title>BMC</title><style>body{margin:0px;}</style>');
		writeln('<scr'+'ipt>');
		writeln('var isNN,isIE;');
		writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');
		writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');
		writeln('if (isIE){');
		writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');
		writeln('if (isNN){');
		writeln('window.innerWidth=document.images["BMC"].width;');
		writeln('window.innerHeight=document.images["BMC"].height;}}');
		writeln('function make_title(){document.title="'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		if (!multipleWindows) {
			writeln('</head><body bgcolor="#000000" scroll="yes" onload="reSizeToImage();make_title();self.focus()">')
		}
		else {
			writeln('</head><body bgcolor="#ffffff" scroll="no" onload="make_title();self.focus()" onblur="self.close()"><center>');
		}
		writeln('<img name="BMC" src="'+imageURL+'" style="display:block"></center></body></html>');
		close();
	}
}

function mod_newsletter_subscribe(subscribe) {
	myObj = document.getElementById('mod_newsletter_action');
	subscriber_email = document.getElementById('mod_newsletter_email');
	if (subscribe && (subscriber_email.value!='')) {
		myObj.value = 1;
		document.forms.mod_newsletter.submit();
	} else if (!subscribe && (subscriber_email.value!='')) {
		myObj.value = 0;
		document.forms.mod_newsletter.submit();
	}
	return false;
}
function isEmpty(val) {
	if (val.match(/^s+$/) || val == "") {
		return true;
	} else {
		return false;
	}
}


not_empty_fields = new Array(9);
not_empty_fields[0] = 'first_name';
not_empty_fields[1] = 'last_name';
not_empty_fields[2] = 'address';
not_empty_fields[3] = 'city';
not_empty_fields[4] = 'zipcode';
not_empty_fields[5] = 'city';
not_empty_fields[6] = 'country';
not_empty_fields[7] = 'email';
not_empty_fields[8] = 'phoneno';
function check_address () {
	return_val = true;
	error_msg = '';
	user_accept_field = document.getElementById('user_accept');
	freight_select = document.getElementById('freight');

	user_accept_text = document.getElementById('user_accept_text');
	freight_text = document.getElementById('freight_text');
	required_fields_text = document.getElementById('required_fields_text');

	if (!user_accept_field.checked) {
		error_msg+= user_accept_text.value+"\n";
		return_val = false;
	}
	if (freight_select.selectedIndex==0) {
		error_msg+= freight_text.value+"\n";
		tmp_obj_text = document.getElementById('freight_help');
		tmp_obj_text.className = 'address_error';
		return_val = false;
	}
	empty_field_found = false;
	for(i=0;i<not_empty_fields.length;i++) {
		tmp_obj = document.getElementById(not_empty_fields[i]);
		tmp_obj_text = document.getElementById(not_empty_fields[i]+'_text');
		if (isEmpty(tmp_obj.value)) {
			tmp_obj_text.className = 'address_error';
			empty_field_found = true;
		} else {
			tmp_obj_text.className = '';
		}
	}
	if (empty_field_found) {
		error_msg+= required_fields_text.value+"\n";
		return_val = false;
	}
	if (!return_val) {
		alert(error_msg);
	}
	return return_val;
}