 function WallPanelsWizard(){
 	this.iId = null;
	this.oCurrentData = null;
	this.oShoppingCart = globalId('amountInShoppingCart');
	
	//Div
	this.oWizardDiv = document.createElement('div');
	this.oFormDiv = document.createElement('div');
	this.oFormDiv.className = 'formdiv';
	this.oControlDiv = document.createElement('div');
	this.oControlDiv.className = 'controls';
	this.oInfoDiv = document.createElement('div');
	this.oInfoDiv.className = 'wizardInfo';	
	
	//form
	this.oAmountInput = document.createElement('input');
	this.oAmountInput.setAttribute('value',1);
	this.oExtraSelect = null;
	this.aAmountExtra = new Array();
	
	//ajax
	this.oAjax = new Ajax();
	this.oAjax.set('sUrl', document.URL);
	this.oAjax.set('sMethod', 'POST');
	this.oAjax.set('oReturnObject', this);	
	
	//popupje 
	this.oPopupje = new Popup();
	this.oPopupje.sPopupId = 'childArtWizard';
	this.oPopupje.iWidth = 805;
	this.oPopupje.iHeight = 550;
	this.oPopupje.toCenter = false;
	this.oPopupje.iXlocation = 180;
	this.oPopupje.iYlocation = 129;
	
	//values
	this.bUpdate = false;
	this.iProductIndex = 0;
	this.aExtra = new Array();
 }
 
 WallPanelsWizard.prototype.load = function(){
 	this.oPopupje.show();
	this.oPopupje.oPopup.appendChild(this.oWizardDiv);
	this.oWizardDiv.appendChild(this.oInfoDiv);
	this.oWizardDiv.appendChild(this.oFormDiv);
	this.oWizardDiv.appendChild(this.oControlDiv);
	
	//img
	var oImage = new Image();
	oImage.src = '/wallpanels/thumbs/' + this.iId + '.jpg';
	this.oInfoDiv.appendChild(oImage);

	//Control
	var oThis = this;

	//close
	var oClose = document.createElement('a');
	var oCloseText = document.createTextNode('<< Stoppen');
	oClose.appendChild(oCloseText);
	oClose.className = 'cancel';
	this.oControlDiv.appendChild(oClose);
	oClose.onclick = function(){
		oThis.oPopupje.close();
	}
	
	//add
	var oAdd = document.createElement('a');
	var oAddText = document.createTextNode('Toevoegen aan uw mandje >>');
	oAdd.appendChild(oAddText);
	oAdd.className = 'next';
	this.oControlDiv.appendChild(oAdd);
	oAdd.onclick = function(){
		oThis.add();
	}
	
	this.oAjax.set('sQuery', '{"sAction":"getExtra","iId":' + this.iId + '}');
	this.oAjax.set('sSendCode', g_sSendCode);
	this.oAjax.set('sReturnDataTo', 'showForm');
	this.oAjax.doSend();		
 }
 
 WallPanelsWizard.prototype.showForm = function(){
	if (this.oAjax.sRequestedData != '') {
		try {
			
			this.oCurrentData = eval('(' + this.oAjax.sRequestedData + ')');
			g_sSendCode = this.oCurrentData.sJsSendCode;
			var oThis = this;
					
			//amount
			var oLabel = document.createElement('label');
			var oLabelText = document.createTextNode('Geef aan hoeveel wandpanelen u wilt.');
			oLabel.setAttribute('for', 'amount');
			oLabel.appendChild(oLabelText);
			this.oFormDiv.appendChild(oLabel);
			
			this.oAmountInput.setAttribute('name','amount');
			this.oAmountInput.setAttribute('id','amount');
			this.oAmountInput.setAttribute('type','text');
			this.oAmountInput.onkeyup = function(){
				var oRegEx = /^[0-9]+$/
				if (this.value != '') {
					if (!oRegEx.test(this.value)) {
						this.value = 1;
					}
				}
			}
			this.oFormDiv.appendChild(this.oAmountInput);
			
			for(i=0; i < this.oCurrentData.aExtra.length; i++){
				oLabel = document.createElement('label');
				oLabel.innerHTML = 'Hoeveel ' + this.oCurrentData.aExtra[i].sName + ' wilt u bestellen? &euro;' + this.oCurrentData.aExtra[i].fPrice + 'p/s';
				oLabel.setAttribute('for', 'extra_' + this.oCurrentData.aExtra[i].iId);
				this.oFormDiv.appendChild(oLabel);
				
				var oExtraInput = document.createElement('input');
				oExtraInput.setAttribute('name','extra_' + this.oCurrentData.aExtra[i].iId);
				oExtraInput.setAttribute('id','extra_' + this.oCurrentData.aExtra[i].iId);
				oExtraInput.setAttribute('type','text');
				if(this.aExtra[this.oCurrentData.aExtra[i].iId]){
					oExtraInput.setAttribute('value',this.aExtra[this.oCurrentData.aExtra[i].iId]);
				}else{
					oExtraInput.setAttribute('value',0);	
				}
				
				oExtraInput.onkeyup = function(){
					var oRegEx = /^[0-9]+$/
					if (this.value != '') {
						if (!oRegEx.test(this.value)) {
							this.value = 0;
						}
					}
				}				
				
				this.aAmountExtra.push(oExtraInput);
				this.oFormDiv.appendChild(this.aAmountExtra[this.aAmountExtra.length - 1]);
				delete oExtraInput;
			}
			
			
		}catch (e) {
			alert(this.oAjax.sRequestedData);
			alert('Er is een probleem op getreden' +  e);
			//location.reload();
		}
	}
 }
 
 WallPanelsWizard.prototype.add = function(){
 	var sPostData = '';
	var oRegEx = /^[0-9]+$/
	if(oRegEx.test(this.oAmountInput.value) && parseInt(this.oAmountInput.value) > 0){
		sPostData += '"iAmount":'+ this.oAmountInput.value +',';

		sPostData += '"aExtra":[{';
		for(i=0; i < this.aAmountExtra.length; i++){
			if(i > 0){
				sPostData += ',';
			}
			if(oRegEx.test(this.aAmountExtra[i].value)){
				sPostData += '"'+ this.aAmountExtra[i].id +'":'+ this.aAmountExtra[i].value +'';
			}else{
				sPostData += '"'+ this.aAmountExtra[i].id +'":0';
			}
		}
		sPostData += '}],';
		
				
		//action & id
		sPostData += '"iId":' + this.iId + ',';
		if (this.bUpdate) {
			sPostData += '"iProductIndex":' + this.iProductIndex + ',';
			sPostData += '"sAction":"wallPanelsUpdate"';
		}else{
			sPostData += '"sAction":"add"';
		}
		
		//send
		this.oAjax.set('sQuery', '{' + sPostData + '}');
		this.oAjax.set('sSendCode', g_sSendCode);
		this.oAjax.set('sReturnDataTo', 'end');
		this.oAjax.doSend();
	} 
 }

 WallPanelsWizard.prototype.end = function(){
 	//reload
	if(this.bUpdate){
		location.reload();
	}
	
 	this.oPopupje.close();
	var oThis = this;
	try{
		
		this.oCurrentData = eval('(' + this.oAjax.sRequestedData + ')');
		g_sSendCode = this.oCurrentData.sJsSendCode;
		this.oShoppingCart.innerHTML = this.oCurrentData.iAmountInShoppingCart;
			
		//Status popup
	 	this.oPopupje = new Popup();
		this.oPopupje.show();	
		var oClose = document.createElement('a');
		var oCloseText = document.createTextNode('>> Verder winkelen');
		oClose.appendChild(oCloseText);
		oClose.className = 'cancelCart';
		oClose.onclick = function(){
			oThis.oPopupje.close();
		}
		
		var oRemove = document.createElement('a');
		var oRemoveText =  document.createTextNode('>> Bestelling afronden');
		oRemove.appendChild(oRemoveText);
		oRemove.className = 'goCart';
		oRemove.onclick = function(){
			location.href = '/shoppingcart';
		}
		
		var oPopUpDiv = document.createElement('div');
		oPopUpDiv.className = 'PopupDiv';
		var oMessage = document.createElement('p');
		var oMessageText = document.createTextNode('Het schilderij is correct toegevoegd aan uw winkelmandje');
		oMessage.appendChild(oMessageText);
		
		oPopUpDiv.appendChild(oMessage);
		oPopUpDiv.appendChild(oRemove);
		oPopUpDiv.appendChild(oClose);
		
		this.oPopupje.oPopup.appendChild(oPopUpDiv);				
			
			
	}catch(e){
		location.reload();
	}
 }
 
 WallPanelsWizard.prototype.setOldValue = function(){
	try {
		this.oCurrentData = eval('(' + this.oAjax.sRequestedData + ')');
		g_sSendCode = this.oCurrentData.sJsSendCode;
		
		this.iId = this.oCurrentData.aCartData.iProductId; 
		this.oAmountInput.value = this.oCurrentData.aCartData.iAmount;
		this.bUpdate = true;
		
		var sExtraData = '{';
		for(i=0; i < this.oCurrentData.aCartData.aExtra.length; i++){
			if(i > 0){
				sExtraData += ',';
			}
			sExtraData += '"' + this.oCurrentData.aCartData.aExtra[i].iProductId + '":' + this.oCurrentData.aCartData.aExtra[i].iAmount;
		}
		sExtraData += "}";
		this.aExtra = eval('(' + sExtraData + ')');
		
		this.load();
	}catch(e){
		//alert(this.oAjax.sRequestedData);
	}
 }
 
 WallPanelsWizard.prototype.reload = function(p_iId){
 	this.iProductIndex  = p_iId;
	this.oAjax.set('sQuery', '{"sAction":"getProduct","iProductIndex":'+ p_iId +'}');
	this.oAjax.set('sSendCode', g_sSendCode);
	this.oAjax.set('sReturnDataTo', 'setOldValue');
	this.oAjax.doSend(); 	
 }


