function getPageSizeWithScroll(direction)
{     
		if (window.innerHeight && window.scrollMaxY) 
		{
			// Firefox         
			yWithScroll = window.innerHeight + window.scrollMaxY;
			xWithScroll = window.innerWidth + window.scrollMaxX;     
		} else if (document.body.scrollHeight > document.body.offsetHeight)
		{ // all but Explorer Mac         
			yWithScroll = document.body.scrollHeight;         
			xWithScroll = document.body.scrollWidth;     
		} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
			yWithScroll = document.body.offsetHeight;         
			xWithScroll = document.body.offsetWidth;
		}     
		arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);     
		//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );     
		if (direction=='w')
			return xWithScroll;
		if (direction=='h')
			return yWithScroll;
}

function getY( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetTop;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetLeft;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

var ie=document.all;
var ns6=document.getElementById && !document.all;
var opera=window.opera;

var winwidth=0;
var winheight=0;

function getclientSize() {
	if (!winwidth)
		winwidth=ie&&!opera ? document.body.clientWidth : window.innerWidth-20;
	if (!winheight)		
		winheight=ie&&!opera ? document.body.clientHeight : window.innerHeight-20;
}

var menu_time;
function show_sub_menu(index,visible)
{			
	var length=document.getElementById('nr_of_sub').value;
	for(i=0;i<length;i++) {
		document.getElementById('submenu'+i).style.visibility='hidden';
		//document.getElementById('menu_left_'+i).className='menu_item';
	}

	var left=getX(document.getElementById('menu_left_'+index));
	var top=getY(document.getElementById('menu_left_'+index));
	
	document.getElementById('submenu'+index).style.left=left+'px';
	document.getElementById('submenu'+index).style.top=top+'px';
	
	if (visible==1) {
		if (document.getElementById('nr_of_subsub'+index).value>0)
			document.getElementById('submenu'+index).style.visibility='visible';
		//document.getElementById('menu_left_'+index).className='menu_item_selected';
	} else {
		document.getElementById('submenu'+index).style.visibility='hidden';
		//document.getElementById('menu_left_'+index).className='menu_item';
	}
}


function show_login_pass() {
	document.getElementById('login_pass').style.display='block';
	document.getElementById('login_pass').focus();
	document.getElementById('login_pass_tmp').style.display='none';
}

function hide_login_pass() {
	document.getElementById('login_pass_tmp').style.display='block';
	document.getElementById('login_pass').style.display='none';
	document.getElementById('login_pass_tmp').value='wachtwoord';
}

function format_to_float(nr) {
	var str=nr.toFixed(2);
	return str.replace(".",',');
}

function format_total() {
	
	var total=0;	
	var price=0;	
	price=parseInt(document.getElementById('qt').value)*parseFloat(document.getElementById('price').value);
		
	var attr_len=parseInt(document.getElementById('attr_lent').value);	
	for (i=0;i<attr_len;i++) {
		var attr_sel=parseInt(document.getElementById('attr_'+i).value);		
		var qt=(parseInt(document.getElementById('attr_qt_'+i).value)==1 ? parseInt(document.getElementById('qt').value) : 1);		
		if (document.getElementById('attr_'+i+'_'+attr_sel+'_value')) {
			var attr_value=parseFloat(document.getElementById('attr_'+i+'_'+attr_sel+'_value').value)*qt;
			document.getElementById('attr_'+i+'_holder').innerHTML=format_to_float(attr_value);
			total+=attr_value;		
			
			if (document.getElementById('attr_'+i+'_'+attr_sel+'_type')) {			
				switch (parseInt(document.getElementById('attr_'+i+'_'+attr_sel+'_type').value)) {
					case 1:
						document.getElementById('attr_'+i+'_'+attr_sel+'_holder').style.display='';
						break;
					case 2:					
						document.getElementById('attr_'+i+'_'+attr_sel+'_holder').style.display='';
						break;		
					case 3:
						for (var j=0;j<document.getElementById('attrs_len_'+i).value;j++) {
							if (document.getElementById('attr_'+i+'_'+j+'_holder'))
								document.getElementById('attr_'+i+'_'+j+'_holder').style.display='none';			
						}
						document.getElementById('attr_'+i+'_'+attr_sel+'_holder').style.display='';						
						break;	
												
				}
			} else {				
				for (var j=0;j<document.getElementById('attrs_len_'+i).value;j++) {
					if (document.getElementById('attr_'+i+'_'+j+'_holder'))
						document.getElementById('attr_'+i+'_'+j+'_holder').style.display='none';			
				}
			}
		}
	}
	
	var attr_len=parseInt(document.getElementById('attr_lent').value);
	for (i=0;i<attr_len;i++) {
		
	}
	
	total+=price;
	
	document.getElementById('qt_price').innerHTML=format_to_float(price);
	document.getElementById('total_holder').innerHTML="<b>"+format_to_float(total)+"</b>";
	
}

var file_sel_wnd=null;

function open_file_selector(i,v) {
	var w=600;
	if (screen.width)
		w=screen.width-200;
	var h=400;
	if (screen.height)
		h=screen.height-200;
	file_sel_wnd=window.open(host+'select_file.php?i='+escape(i)+'&v='+v,'filewnd','status=yes,toolbar=no,location=no,menubar=no,directories=no,resizable=true,scrollbars=yes,height='+h+',width='+w);
}


function delete_picture(file) {
	if (confirm('Verwijderen?')) {
		document.getElementById('delete_form').command.value="delete";
		document.getElementById('delete_form').file.value=file;
		document.getElementById('delete_form').submit();
	}
}

function show_upload() {
	show_black();
	document.getElementById('upload_wnd').style.top='230px';
	document.getElementById('upload_wnd').style.left=getX(document.getElementById('main_doc'))+250;
	document.getElementById('upload_wnd').style.display='inline';
}

function hide_upload() {
	hide_black();
	document.getElementById('upload_wnd').style.display='none';
}

function show_black() {
	page_height=getPageSizeWithScroll('h');
	document.getElementById('black_wall').className='black_wall_1';		
	document.getElementById('black_wall').style.height=page_height;		
}

function hide_black() {
	document.getElementById('black_wall').className='black_wall_0';			
}

function do_upload() {
	document.getElementById('upload_form').command.value="upload";
	document.getElementById('upload_form').submit();
}

function select_image(i,j,img,src) {
	if (opener.document.getElementById('attr_'+i+'_'+j+'_file')) {
		opener.document.getElementById('attr_'+i+'_'+j+'_file').value=img;	
		opener.document.getElementById('attr_'+i+'_'+j+'_thumb').src="";
		opener.document.getElementById('attr_'+i+'_'+j+'_thumb').src=src;
		opener.document.getElementById('attr_'+i+'_'+j+'_thumb').style.display='';
	}
	self.close();
}

function add_to_basket() {
	document.getElementById('product_form').command.value='add';
	document.getElementById('product_form').submit();
}

function delete_bascket_item(index) {
	if (confirm('Weet u zeker dat u dit item uit het winkelwagentje wilt verwijderen?')) {
		document.getElementById('delete_form').id.value=index;
		document.getElementById('delete_form').command.value='remove_item';
		document.getElementById('delete_form').submit();	
	}
}

function edit_bascket_item(index) {
	document.getElementById('edit_form').id.value=index;
	document.getElementById('edit_form').command.value='edit_item';
	document.getElementById('edit_form').submit();	
}

function save_basket_item() {
	document.getElementById('product_form').command.value='update';
	document.getElementById('product_form').submit();	
}	

function go_to_checkout() {
	window.location=host+"index.php?com=webshop&checkout=detail";
}

function checkout_confirmed() {
	document.getElementById('order_form').command.value='send_order';
	document.getElementById('order_form').submit();	
}

function show_order_detail(i) {
	if (document.getElementById('holder_'+i).style.display=='none') {
		document.getElementById('holder_'+i).style.display='';
		document.getElementById('sign_'+i).className='minus';		
	} else {
		document.getElementById('holder_'+i).style.display='none';
		document.getElementById('sign_'+i).className='plus'
	}
}

//

function  check_pp_recovery(obj) {
	if (obj.email.value.length==0)
		return false;
	return true;
}

function verzenden() {
	if (confirm('Are you sure you wanna subscribe for newsletter?')) {
	document.form_newsletter.command3.value="verzenden";
	document.form_newsletter.submit();
	}
}