function doLogin(form)
{
	document.getElementById("loginLoader").style.display='inline';
	new Ajax.Updater('notice', 'doLogin.php', {
		evalScripts: true,
		parameters: {
          login: form.login.value,
		  password: form.password.value
        } 
	});		
}

function doSearch(value)
{
    document.location='index.php?act=list&catId=search&search='+value;
}

function showImage()
{
	if(navigator.appName=='Microsoft Internet Explorer')
	{
		document.getElementById("loader").style.height=document.body.scrollHeight;
		document.getElementById("loaderImg").style.marginTop=(document.body.scrollTop+200);
	}		
	document.getElementById("loader").style.display='inline';
}

function addCart(id,amount,type)
{
	showImage();
	new Ajax.Updater('cartItems','updateSmallBasket.php', {
		evalScripts: true,
		parameters: {
          id: id,
		  		amount: amount,
					type: type
        } 
	});
}

function updateOrderData(id,amount,type,action)
{
	if(type=='delete')
	{
		if(confirm('Weet u zeker dat u dit item uit uw order wilt verwijderen?')){
	        Effect.Fade('item'+id,{ duration: 0.5 });
	        new Ajax.Updater('cartItems','updateOrderData.php', {
				parameters: {
		          id: id,
				  		amount: amount,
							type: type,
				  		action: action
		        }
			});
	    }
	}
	else
	{
		showImage();
		new Ajax.Updater('cartItems','updateOrderData.php', {
			evalScripts: true,
			parameters: {
	          id: id,
			 			amount: amount,
			 			type: type,
				  	action: action
	        }
		});
	}
}

function updateOrderDatab(id,amount,type)
{
	if(type=='delete')
	{
		if(confirm('Weet u zeker dat u dit item uit uw order wilt verwijderen?')){
	        Effect.Fade('item'+id,{ duration: 0.5 });
	        new Ajax.Updater('cartItems','updateOrderDatab.php', {
				parameters: {
		          id: id,
				  amount: amount,
				  type: type
		        }
			});
	    }
	}
	else
	{
		showImage();
		new Ajax.Updater('cartItems','updateOrderDatab.php', {
			evalScripts: true,
			parameters: {
	          id: id,
			  amount: amount,
			  type: type
	        }
		});
	}
}

function checkAgree(agree)
{
	if(agree)
	{
		document.getElementById('finish').style.display='inline';
	}
	else
	{
		document.getElementById('finish').style.display='none';
	}
}

function finishOrder_old(referentie)
{
	showImage();
	new Ajax.Updater('cartItems','finishOrder.php?ref='+referentie, {evalScripts: true} );
}

function finishOrder(referentie,alt)
{
	showImage();
	document.location='index.php?act=finishorder&ref='+referentie+'&alt='+alt;
}

function showTable(id,state)
{
	if(state)
	{
		document.getElementById(id).style.display='none';
	}
	else
	{
		document.getElementById(id).style.display='block';
	}
}

function checkEmail(id,value)
{
	if(value.indexOf('@')<0||value.indexOf('.')<0||value.length<=7)
	{
		document.getElementById(id).style.color='#d55261';
		return false;
	}
	else
	{
		document.getElementById(id).style.color='#000000';
		return true;
	}	
}

function checkPhone(id,value)
{
	if(value.length<10)
	{
		document.getElementById(id).style.color='#d55261';
		return false;
	}
	else
	{
		document.getElementById(id).style.color='#000000';
		return true;
	}
}

function checkLogin(id,value)
{
	showImage();
	new Ajax.Updater('error', 'checkLogin.php', {
		evalScripts: true,
		parameters: {
			id: id,
			login: value
		}
	});
}

function submitForm(form){
	if(document.getElementById('factuurCheck').checked)
	{
		document.getElementById('factuur').innerHTML='';
	}
	if(document.getElementById('afleverCheck').checked)
	{
		document.getElementById('aflever').innerHTML='';
	}
	
	this.form = document.getElementById(form);
	this.inputs = this.form.getElementsByTagName('input');
	this.error = '';	
	for (i = 0; i < this.inputs.length; i++) 
	{
		if (this.inputs[i].name == 'email') 
		{
			if(!checkEmail(this.inputs[i].id,this.inputs[i].value))
			{
				this.error += this.inputs[i].name + '\r\n';
			}
		}
		else if (this.inputs[i].name == 'telefoon' || this.inputs[i].name == 'fax') 
		{
			if(!checkPhone(this.inputs[i].id,this.inputs[i].value))
			{
				this.error += this.inputs[i].name + '\r\n';
			}						
		}
		else if (this.inputs[i].type == 'text'&&this.inputs[i].name!="extra_email_1"&&this.inputs[i].name!="extra_email_2")
		{
			if(this.inputs[i].value == '')
			{
				this.error += this.inputs[i].name + '\r\n';
			}
		}
	}
	if (this.error == '') 
	{
		this.form.submit();
	}
	else 
	{
		alert('U heeft niet alle benodigde velden juist ingevuld.\r\nVul de volgende velden alsnog goed in.\r\n\r\n' + this.error);
	}
}

function submitRma(){
	
	this.form = document.getElementById('rmaForm');
	this.inputs = this.form.getElementsByTagName('input');
	this.texts = this.form.getElementsByTagName('textarea');
	this.error = '';	
	for (i = 0; i < this.inputs.length; i++) 
	{
		if (this.inputs[i].name == 'email') 
		{
			if(!checkEmail(this.inputs[i].id,this.inputs[i].value))
			{
				this.error += this.inputs[i].name + '\r\n';
			}
		}		
		else if (this.inputs[i].type == 'text'&&this.inputs[i].disabled==false)
		{
			if(this.inputs[i].value == '')
			{
				this.error += this.inputs[i].name + '\r\n';
			}
		}
	}
	for (i = 0; i < this.texts.length; i++) 
	{
	 		if(this.texts[i].value == '')
			{
				this.error += this.texts[i].name + '\r\n';
			}
	}
	if (this.error == '') 
	{
	  document.getElementById('message').style.display='inline';
	}
	else 
	{
		alert('U heeft niet alle benodigde velden juist ingevuld.\r\nVul de volgende velden alsnog goed in.\r\n\r\n' + this.error);
	}
}

function actionWheelShow(products,i)
{
	document.getElementById('actionProdName').innerHTML = products[i]['naam'];
	document.getElementById('actionProdImg').src = 'uploads/product/thumb'+products[i]['id']+'.jpg';
	document.getElementById('actionProdLink').href = 'index.php?act=overview&prodId='+products[i]['id'];
	document.getElementById('actionProdPrice').innerHTML = products[i]['prijs'];
	
	Effect.Appear('actionProdName');
	Effect.Grow('actionProdImg',{ queue: 'front' });
	Effect.Appear('actionProdPrice',{ queue: 'end' });
	
	t=setTimeout('actionWheelClose('+i+');',5000);
}

function actionWheelClose(i)
{
	Effect.Fade('actionProdName');	
	Effect.Fade('actionProdPrice');
	Effect.Puff('actionProdImg',{queue: 'end'});
	
	i++;
	if(i==products.length) { i=0; }
	
	t=setTimeout('actionWheelShow(products,'+i+');',3000);
}

function showAccessoires()
{
  var accCat1 = document.getElementById('accessoireCategories1').value;
	var accCat2 = document.getElementById('accessoireCategories2').value;
	var accBrand = document.getElementById('accessoireBrands').value;
  document.location = 'index.php?act=listAcc&accCat1='+accCat1+'&accCat2='+accCat2+'&accBrand='+accBrand;
}

function setMainImg(src)
{
  document.getElementById('mainImg').src=src;
}
