 function childArtWizard(){
 	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.oPriceSelect = null;
	this.oArtText = document.createElement('textarea');
	this.oArtText.setAttribute('id','extra_text');
	this.oArtText.setAttribute('name','extra_text');
	
	//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.fPrice = null;
	this.bUpdate = false;
	this.iProductIndex = 0;
 }
 
 childArtWizard.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 = '/childart/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();
	}
	
	if (!this.bUpdate) {
		this.oAjax.set('sQuery', '{"sAction":"get","iId":' + this.iId + '}');
		this.oAjax.set('sSendCode', g_sSendCode);
		this.oAjax.set('sReturnDataTo', 'showForm');
		this.oAjax.doSend();
	} else{
		this.showForm();
	}		
 }
 
 childArtWizard.prototype.showForm = function(){
	if (this.oAjax.sRequestedData != '') {
		try {
			if (!this.bUpdate) {
				this.oCurrentData = eval('(' + this.oAjax.sRequestedData + ')');
				g_sSendCode = this.oCurrentData.sJsSendCode;
			}else{
				this.oCurrentData = this.oCurrentData.aProduct;
			}
			
					
			//prices
			this.oPriceSelect = document.createElement('select');
			var oLabel = document.createElement('label');
			var oLabelText = document.createTextNode('Geef aan welk formaat u wilt bestellen');
			oLabel.setAttribute('for', 'price_select');
			oLabel.appendChild(oLabelText);
			this.oFormDiv.appendChild(oLabel);
			
			for(i = 0; i < this.oCurrentData.aPriceList.length; i++){
				oOptionTemp = document.createElement('option');
				oOptionTemp.setAttribute('value', this.oCurrentData.aPriceList[i]['sDescription']);
				if(this.oCurrentData.aPriceList[i]['fPrice'] == this.fPrice){
					oOptionTemp.setAttribute('selected', 'selected');
				}
				oOptionTemp.innerHTML = this.oCurrentData.aPriceList[i]['sDescription'] + ' voor &euro; ' + this.oCurrentData.aPriceList[i]['fPrice'];
				this.oPriceSelect.appendChild(oOptionTemp);
			}
			this.oPriceSelect.onchange = function(){
				oThis.iAmount = this.options[this.selectedIndex].value;
			}
			this.oPriceSelect.setAttribute('id', 'price_select');
			this.oPriceSelect.setAttribute('name', 'price_select');
			this.oFormDiv.appendChild(this.oPriceSelect);				
			
			//extra tekst
			oLabel = document.createElement('label');
			oLabelText = document.createTextNode('Als u een tekst op het schilderij wilt, kunt u die hier opgeven. ( niet verplicht )');
			oLabel.setAttribute('for', 'extra_text');
			oLabel.appendChild(oLabelText);
			this.oFormDiv.appendChild(oLabel);
			
			this.oFormDiv.appendChild(this.oArtText);
						
			
		}catch (e) {
			alert('Er is een probleem op getreden' +  e);
			//location.reload();
		}
	}
 }
 
 childArtWizard.prototype.add = function(){
 	var sPostData = '';
	
	//price
	sPostData += '"sSize":"'+ this.oPriceSelect.options[this.oPriceSelect.selectedIndex].value +'",';
	//text
	sPostData += '"sExtraText":"'+ this.oArtText.value +'",';
	
	
	//action & id
	sPostData += '"iId":' + this.iId + ',';
	if (this.bUpdate) {
		sPostData += '"iProductIndex":' + this.iProductIndex + ',';
		sPostData += '"sAction":"cartArtUpdate"';
	}else{
		sPostData += '"sAction":"add"';
	}
	
	//send
	this.oAjax.set('sQuery', '{' + sPostData + '}');
	this.oAjax.set('sSendCode', g_sSendCode);
	this.oAjax.set('sReturnDataTo', 'end');
	this.oAjax.doSend(); 
 }

 childArtWizard.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();
	}
 }
 
 childArtWizard.prototype.setOldValue = function(){
	try {
		this.oCurrentData = eval('(' + this.oAjax.sRequestedData + ')');
		g_sSendCode = this.oCurrentData.sJsSendCode;
		
		this.iId = this.oCurrentData.aCartData.iProductId; 
		this.fPrice = this.oCurrentData.aCartData.fTotalPrice;
		this.oArtText.value = this.oCurrentData.aCartData.sText;
		this.bUpdate = true;
		
		this.load();
	}catch(e){
		
	}
 }
 
 childArtWizard.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(); 	
 }


