 var g_oEnvelopes = null;
 var g_oAddressLabels = null;
 
 function CardWizard(){
	this.iCardId = this.iCardId; 
	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';
	this.oCard = null;
	this.iStep = 1;
	this.oTheCard = null;
	this.iAmount = null;
	this.iEnvelopeId = null;
	this.sFont = 'default';
	this.iAddressLabelId = null;
	this.iUpdateIndex = null;
	this.iSelectedColor = 0;
	this.sSelectColorName = 'Wit';
	this.bColorSelect = false;
	this.oCalculated = new Date();
	this.aDisabled = [{start: new Date(2010,6,28), end: new Date(2010,7,14), message:"Oeps, de datum is tussen 28 juli en 14 augustus, Nieuwe orders en aanvragen kan Gupje verwerken tot 27 juli en dan weer na 14 augustus. Bestaande orders worden natuurlijk gewoon in deze periode gedrukt!"}];
	
	
	//popupje
	this.oPopupje = new Popup();
	this.oPopupje.iWidth = 805;
	this.oPopupje.iHeight = 550;
	this.oPopupje.toCenter = false;
	this.oPopupje.iXlocation = 180;
	this.oPopupje.iYlocation = 129;
	this.oPopupje.sPopupId = 'cardWizard';
	
	//ajax	
	this.oAjax = new Ajax();
	this.oAjax.set('sUrl', document.URL);
	this.oAjax.set('sMethod', 'POST');
	this.oAjax.set('oReturnObject', this);
	
	
	
	//step 1
	this.oPriceSelect = null;
	this.oEnvelopeSelect = null;
	this.oAddressLabel = null;
	this.oAddressLabelsSelect = null;
	this.oFrontTextArea = document.createElement('textarea');
	this.oLeftInsideTextArea = document.createElement('textarea');
	this.oRightInsideTextArea = document.createElement('textarea');
	
	//step 2
	this.oFontRadioButtons = document.createElement('input');
	this.oDayCalculatedSelect = null;
	this.oMonthCalculatedSelect = null;
	this.oYearCalculatedSelect = null;
	
	
	
	//step 3
	this.oShoppingCart = globalId('amountInShoppingCart');
 }

 CardWizard.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);
	
	//thumbs
	var oInSideImg = new Image();
	oInSideImg.src = '/cards/thumbs/' + this.iCardId + '_inside.jpg'; 
	this.oInfoDiv.appendChild(oInSideImg);
	
	var oOutSideImg = new Image();
	oOutSideImg.src = '/cards/thumbs/' + this.iCardId + '_outside.jpg';
	this.oInfoDiv.appendChild(oOutSideImg);
	//load Envelopes
	if (!g_oEnvelopes) {
		this.oAjax.set('sQuery', '{"sAction":"getEnvelopes"}');
		this.oAjax.set('sSendCode', g_sSendCode);
		this.oAjax.set('sReturnDataTo', 'loadEnvelopes');
		this.oAjax.doSend();
	}else {
		this.step();
	}
 }

 CardWizard.prototype.step = function(){ 	
	switch(this.iStep){
		case 1:{
			this.oWizardDiv.removeChild(this.oFormDiv);
			this.oFormDiv = document.createElement('div');
			this.oFormDiv.className = 'formdiv'; 
			this.oWizardDiv.appendChild(this.oFormDiv);
			this.oControlDiv.innerHTML = '';
			this.cardText();
		}
		break;
		
		case 2:{
			this.oWizardDiv.removeChild(this.oFormDiv);
			this.oFormDiv = document.createElement('div');
			this.oFormDiv.className = 'formdiv'; 
			this.oWizardDiv.appendChild(this.oFormDiv);
			this.oControlDiv.innerHTML = '';
			this.cardOptions();
		}
		break;
		
		case 3:{
			this.submitCard();
		}
		break;
	}
 }
 
 CardWizard.prototype.cardText = function(){
 	var oThis = this;
 	var oANext = document.createElement('a');
	var oANextText = document.createTextNode('Volgende stap >>');
	var oOptionTemp = null;
	var oPHeader = null;
	var oPHeaderText = null;
	
	oANext.appendChild(oANextText);
	oANext.className = 'next';
	oANext.onclick = function(){
		oThis.iStep = 2;
		oThis.step();
	}
	
	var oACancel = document.createElement('a');
	var oACancelText = document.createTextNode('<< Stoppen');
	oACancel.appendChild(oACancelText);	
	oACancel.onclick = function(){
		oThis.close();
	}
	oACancel.className = 'cancel';
	
	//Aantallen
	oPHeader = document.createElement('h5');
	oPHeader.className = 'popupHeader';
	oPHeaderText = document.createTextNode('1) Aantallen');
	oPHeader.appendChild(oPHeaderText);
	this.oFormDiv.appendChild(oPHeader);	
	
	//prices
	this.oPriceSelect = document.createElement('select');
	var oLabel = document.createElement('label');
	var oLabelText = document.createTextNode('Geef aan hoeveel kaarten u wilt bestellen');
	oLabel.setAttribute('for', 'price_select');
	oLabel.appendChild(oLabelText);
	this.oFormDiv.appendChild(oLabel);
	
	for(i = 0; i < this.oTheCard.aPriceList.length; i++){
		oOptionTemp = document.createElement('option');
		oOptionTemp.setAttribute('value', this.oTheCard.aPriceList[i]['iAmount']);
		if(this.oTheCard.aPriceList[i]['iAmount'] == this.iAmount){
			oOptionTemp.setAttribute('selected', 'selected');
		}
		oOptionTemp.innerHTML = this.oTheCard.aPriceList[i]['iAmount'] + ' stuks voor &euro; ' + this.oTheCard.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);		
	
	//envelope
	var aColorSelect = null;
	this.oEnvelopeSelect = document.createElement('select');
	oLabel = document.createElement('label');
	oLabelText = document.createTextNode('Welke kleur enveloppen wilt u');
	oLabel.setAttribute('for', 'envelope_select');
	oLabel.appendChild(oLabelText);
	this.oFormDiv.appendChild(oLabel);
	
	oOptionTemp = document.createElement('option');
	oOptionTemp.setAttribute('value', '0');
	oOptionTemp.innerHTML = 'Geen';
	this.oEnvelopeSelect.appendChild(oOptionTemp);
	for(i = 0; i < g_oEnvelopes.length; i++){
		oOptionTemp = document.createElement('option');
		oOptionTemp.setAttribute('value', g_oEnvelopes[i].iId);
		if(this.iEnvelopeId == g_oEnvelopes[i].iId){
			oOptionTemp.setAttribute('selected', 'selected');
		}
		oOptionTemp.innerHTML = g_oEnvelopes[i].sName + ' &euro; ' + g_oEnvelopes[i].fPrice + 'pst';
		this.oEnvelopeSelect.appendChild(oOptionTemp);
		
	}
	this.oEnvelopeSelect.setAttribute('id', 'envelope_select');
	this.oEnvelopeSelect.setAttribute('name', 'envelope_select');
	this.oFormDiv.appendChild(this.oEnvelopeSelect);
	this.oEnvelopeSelect.onchange = function(){
		oThis.iEnvelopeId = this.options[this.selectedIndex].value;
		var oRegColor = /kleur/i;
		if(oRegColor.test(this.options[this.selectedIndex].text)){
			oThis.bColorSelect = true;
			//Show Color
			aColorSelect = oThis.showColorSelect();
			for(i=0; i < aColorSelect.length; i++){
				oThis.oFormDiv.insertBefore(aColorSelect[i], this.nextSibling);
			}
		}else{
			if(aColorSelect != null){
				for(i=0; i < aColorSelect.length; i++){
					oThis.oFormDiv.removeChild(aColorSelect[i]);
				}
				aColorSelect = null					
			}
			oThis.bColorSelect = false;
			oThis.iSelectedColor = 0;
			oThis.sSelectColorName = 'Wit';
		}
	}	
	
	//reload color
	if(this.bColorSelect){
		aColorSelect = this.showColorSelect();
		for(i=0; i < aColorSelect.length; i++){
			this.oFormDiv.insertBefore(aColorSelect[i], this.oEnvelopeSelect.nextSibling);
		}		
	}
	
	
	
	//Addresslabels
	this.oAddressLabelsSelect = document.createElement('select');	
	this.oAddressLabel = document.createElement('label');
	this.oAddressLabel.innerHTML = 'Adressticker ( 8 per vel )<br />';
	this.oAddressLabel.setAttribute('for', 'addresslabels_select');
	this.oFormDiv.appendChild(this.oAddressLabel);
	
	this.oAddressLabelsSelect.setAttribute('id', 'addresslabels_select');
	this.oAddressLabelsSelect.setAttribute('name', 'addresslabels_select');
	
	oOptionTemp = document.createElement('option');
	oOptionTemp.setAttribute('value', '0');
	oOptionTemp.innerHTML = 'Geen';
	this.oAddressLabelsSelect.appendChild(oOptionTemp);
	
	for(i = 0; i < g_oAddressLabels.length; i++){
		oOptionTemp = document.createElement('option');
		oOptionTemp.setAttribute('value', g_oAddressLabels[i].iId);
		oOptionTemp.innerHTML = g_oAddressLabels[i].sName + ' &euro; ' + g_oAddressLabels[i].fPrice + ' per vel';
		if(g_oAddressLabels[i].fExtraCost){
			oOptionTemp.innerHTML += ' (+ 1 malig &euro; ' + g_oAddressLabels[i].fExtraCost + ')';
		}
		if(g_oAddressLabels[i].iId == this.iAddressLabelId){
			oOptionTemp.setAttribute('selected', 'selected');
		}
		this.oAddressLabelsSelect.appendChild(oOptionTemp);
	}
	var oALink = document.createElement('a');
	oALink.onclick = function(){
		oThis.showDefaultLabel();
	}
	var oALinkText = document.createTextNode('Klik hier voor een voorbeeld');
	this.oAddressLabelsSelect.onchange = function(){
		var oRegDefault = /^Standaard/;
		if(oRegDefault.test(this.options[this.selectedIndex].text)){
			oALink.appendChild(oALinkText);
			try{
				oThis.oALink.replaceChild(oALinkText);
			}catch(e){
				oThis.oAddressLabel.appendChild(oALink);
			}
		}else{
			try{
				oThis.oAddressLabel.removeChild(oALink);
			}catch(e){}
		}
		oThis.iAddressLabelId = this.options[this.selectedIndex].value;
	}	
	this.oFormDiv.appendChild(this.oAddressLabelsSelect);
	this.oAddressLabelsSelect.onchange();
	
	//Text
	oPHeader = document.createElement('h5');
	oPHeader.className = 'popupHeader';
	oPHeaderText = document.createTextNode('2) Teksten');
	oPHeader.appendChild(oPHeaderText);
	this.oFormDiv.appendChild(oPHeader);	
	
	//Front
	var oLabel = document.createElement('label');
	var oLabelText = document.createTextNode('Geef hier de tekst op voor de voorkant van de kaart');
	oLabel.setAttribute('for', 'front_text');
	oLabel.appendChild(oLabelText);
	this.oFormDiv.appendChild(oLabel);
	this.oFormDiv.appendChild(this.oFrontTextArea);
	this.oFrontTextArea.setAttribute('id', 'front_text');
	this.oFrontTextArea.setAttribute('name', 'front_text');

	//Left inside
	oLabel = document.createElement('label');
	oLabelText = document.createTextNode('Geef hier de tekst op voor de linker binnenkant van de kaart');
	oLabel.setAttribute('for', 'left_text');
	oLabel.appendChild(oLabelText);
	this.oFormDiv.appendChild(oLabel);	
	this.oFormDiv.appendChild(this.oLeftInsideTextArea);
	this.oLeftInsideTextArea.setAttribute('id', 'left_text');
	this.oLeftInsideTextArea.setAttribute('name', 'left_text');
	
	//right inside
	oLabel = document.createElement('label');
	oLabelText = document.createTextNode('Geef hier de tekst op voor de rechter binnenkant van de kaart');
	oLabel.setAttribute('for', 'right_text');
	oLabel.appendChild(oLabelText);	
	this.oFormDiv.appendChild(oLabel);
	this.oFormDiv.appendChild(this.oRightInsideTextArea);
	this.oRightInsideTextArea.setAttribute('id', 'right_text');
	this.oRightInsideTextArea.setAttribute('name', 'right_text');
	
	this.oControlDiv.appendChild(oACancel);
	this.oControlDiv.appendChild(oANext);
 }
 
 CardWizard.prototype.cardOptions = function(){
 	var oThis = this;
 	var oANext = document.createElement('a');
	var oANextText = document.createTextNode('Toevoegen aan uw mandje >>');
	var oOptionTemp = null;
	var oPHeader = null;
	var oPHeaderText = null;
	
	
	oANext.appendChild(oANextText);
	oANext.className = 'next';
	oANext.onclick = function(){
		oThis.iStep = 3;
		oThis.step();
	}
	
	var oACancel = document.createElement('a');
	var oACancelText = document.createTextNode('<< Vorige stap');
	oACancel.appendChild(oACancelText);	
	oACancel.onclick = function(){
		oThis.iStep = 1;
		oThis.step();
	}
	oACancel.className = 'cancel'; 
	
	
	//Select font
	//Lettertype
	oPHeader = document.createElement('h5');
	oPHeader.className = 'popupHeader';
	oPHeaderText = document.createTextNode('3) Lettertype');
	oPHeader.appendChild(oPHeaderText);
	this.oFormDiv.appendChild(oPHeader);	
	
	var oFontP = document.createElement('p');
	oFontP.className = 'fontSelect';
	var oFontPText = document.createTextNode('Selecteer hieronder het lettertype voor de naam van uw kindje in het geboortekaartje.');
	oFontP.appendChild(oFontPText);
	this.oFormDiv.appendChild(oFontP);
	
	var aFontLabels = new Array();
	aFontLabels[0] = 'default';
	aFontLabels[1] = 'zapfino';
	aFontLabels[2] = 'edwardian script';
	aFontLabels[3] = 'helvetica neue light';
	aFontLabels[4] = 'helvetica neue condensed black';
	aFontLabels[5] = 'ma sexy';
	aFontLabels[6] = 'microgramma';
	aFontLabels[7] = 'microgramma bold';
	aFontLabels[8] = 'engravers';
	
	var oLabel = null;
	var oFontImg = null;
	var iFontIndex = 0;
	
	for(i=0; i < aFontLabels.length; i++){
		//label
		oLabel = document.createElement('label');
		oLabel.setAttribute('for', 'font_input_' + i);
		oLabel.className = 'fontInput';
		oFontImg = new Image();
		oFontImg.src = '/images/fonts/' + i + '.png';
		oLabel.appendChild(oFontImg);
		oLabel.onclick = function(){
			var oFontCheck = globalId(this.getAttribute('for'));
			oFontCheck.checked = true;
			oThis.sFont = oFontCheck.value
		}
		
		this.oFormDiv.appendChild(oLabel);
		
		//Radio button
		
		//if (document.all) {
			//this.oFontRadioButtons = document.createElement('<input name="font_input" />');
		//}else{
			this.oFontRadioButtons = document.createElement('input');
			this.oFontRadioButtons.setAttribute('name', 'font_input');
		//}
			
		this.oFontRadioButtons.setAttribute('type', 'radio');
		this.oFontRadioButtons.setAttribute('value', aFontLabels[i]);
		this.oFontRadioButtons.setAttribute('title', aFontLabels[i]);
		this.oFontRadioButtons.setAttribute('id', 'font_input_' + i);
		this.oFontRadioButtons.onclick = function(){
			oThis.sFont = this.value;
			this.checked = true;
		}
		
		if(this.sFont == aFontLabels[i]){
			iFontIndex = i;
		}

		this.oFormDiv.appendChild(this.oFontRadioButtons);
	}
	var oFontCheck = globalId('font_input_' + iFontIndex);
	oFontCheck.checked = true;
	
	//add date
	oPHeader = document.createElement('h5');
	oPHeader.className = 'popupHeader';
	oPHeaderText = document.createTextNode('4) Datum');
	oPHeader.appendChild(oPHeaderText);
	this.oFormDiv.appendChild(oPHeader);
	
	//Label
	oLabel = document.createElement('label');
	oLabelText = document.createTextNode('Datum uitgerekend');
	oLabel.appendChild(oLabelText);
	this.oFormDiv.appendChild(oLabel);
	
	//Holder
	var oDivDateHolder = document.createElement('div');
	oDivDateHolder.className = 'dateHolder';
	this.oFormDiv.appendChild(oDivDateHolder);
	
	//date day	
	this.oDayCalculatedSelect = document.createElement('select');
	var oTempOption = null;
	var oTempOptionNode = null;
	for(i=1; i < 32; i++){
		oTempOption = document.createElement('option');
		oTempOption.setAttribute('value', i);
		oTempOptionNode = document.createTextNode(i);
		oTempOption.appendChild(oTempOptionNode);

		//select current
		if(i == this.oCalculated.getDate()){
			oTempOption.setAttribute('selected', 'selected');
		}		
	
		this.oDayCalculatedSelect.appendChild(oTempOption);
	}
	oDivDateHolder.appendChild(this.oDayCalculatedSelect);
	this.oDayCalculatedSelect.onchange = function(){
		oThis.oCalculated.setDate(this.options[this.selectedIndex].value);
	}
	
	//date month
	this.oMonthCalculatedSelect = document.createElement('select');

	var aMonths = new Array();
	aMonths[0] = 'januari';
	aMonths[1] = 'februari';
	aMonths[2] = 'maart';
	aMonths[3] = 'april';
	aMonths[4] = 'mei';
	aMonths[5] = 'juni';
	aMonths[6] = 'juli';
	aMonths[7] = 'augustus';
	aMonths[8] = 'september';
	aMonths[9] = 'oktober';
	aMonths[10] = 'november';
	aMonths[11] = 'december';

	for(i = 0; i < aMonths.length; i++){
		oTempOption = document.createElement('option');
		oTempOption.setAttribute('value', i);
		oTempOption.innerHTML = aMonths[i];

		//select current
		if(i == this.oCalculated.getMonth()){
			oTempOption.setAttribute('selected', 'selected');
		}		
		
		this.oMonthCalculatedSelect.appendChild(oTempOption);
	}
	oDivDateHolder.appendChild(this.oMonthCalculatedSelect);
	this.oMonthCalculatedSelect.onchange = function(){
		oThis.oCalculated.setMonth(this.options[this.selectedIndex].value);
	}	
	
	//date year
	this.oYearCalculatedSelect = document.createElement('select');
	var oDateNu = new Date();
	for(i=oDateNu.getFullYear(); i < oDateNu.getFullYear() + 3; i++){
		oTempOption = document.createElement('option');
		oTempOption.setAttribute('value', i);
		oTempOptionNode = document.createTextNode(i);
		oTempOption.appendChild(oTempOptionNode);
		
		//select current
		if(i == this.oCalculated.getFullYear()){
			oTempOption.setAttribute('selected', 'selected');
		}
		
		this.oYearCalculatedSelect.appendChild(oTempOption);		
	}
	oDivDateHolder.appendChild(this.oYearCalculatedSelect);
	this.oYearCalculatedSelect.onchange = function(){
		oThis.oCalculated.setFullYear(this.options[this.selectedIndex].value);
	}
	
	//controls
	this.oControlDiv.appendChild(oANext);
	this.oControlDiv.appendChild(oACancel);
 }
 
 CardWizard.prototype.submitCard = function(){
 	var sSubmitData = '';
	var sError = '';
	
	//Text
	sSubmitData += '"iCardId":'+ this.iCardId +',';
	if(this.iUpdateIndex  != null){
		sSubmitData += '"sAction":"cardUpdate",';
		sSubmitData += '"iProductIndex":'+ this.iUpdateIndex +',';
	}else{
		sSubmitData += '"sAction":"submit",';
	}
	sSubmitData += '"sFrontText":"'+ encodeURIComponent(this.oFrontTextArea.value) +'",';
	sSubmitData += '"sLeftInsideText":"'+ encodeURIComponent(this.oLeftInsideTextArea.value) +'",';
	sSubmitData += '"sRightInsideText":"'+ encodeURIComponent(this.oRightInsideTextArea.value) +'",';
	
	//sSubmitData += '"sBackInsideText":"'+ this.oBackTextArea.value +'",';
	//amount
	sSubmitData += '"iAmount":"'+ this.oPriceSelect.options[this.oPriceSelect.selectedIndex].value +'",';
	
	//envelopes
	sSubmitData += '"iEnvelope":"'+ this.oEnvelopeSelect.options[this.oEnvelopeSelect.selectedIndex].value +'",';
	if (this.bColorSelect) {
		sSubmitData += '"sEnvelopeColor":"' + this.sSelectColorName + '",';
		sSubmitData += '"iEnvelopeColorIndex":"' + this.iSelectedColor + '",';
	}
	
	//date
	var oCheckDate = new Date();

	if(this.oCalculated < oCheckDate){
		sError += 'Datum uitgerekend mag niet in het verleden liggen!';
	}else{
		for(var x=0; x < this.aDisabled.length; x++){
			if(this.oCalculated > this.aDisabled[x].start && this.oCalculated < this.aDisabled[x].end){
				sError += this.aDisabled[x].message;
			}
		}
		if (sError == '') {
			sSubmitData += '"sDateCalculated":"'+ this.oCalculated.getTime() / 1000 +'",';
		}
	}
	
	//Font
	sSubmitData += '"sFont":"'+ this.sFont +'",';
	//labels
	sSubmitData += '"iAddressLabels":"'+ this.oAddressLabelsSelect.options[this.oAddressLabelsSelect.selectedIndex].value +'"';

	if (sError == '') {
		this.oAjax.set('sQuery', '{' + sSubmitData + '}');
		this.oAjax.set('sSendCode', g_sSendCode);
		this.oAjax.set('sReturnDataTo', 'statusPopup');
		this.oAjax.doSend();
	}else{
		alert(sError);
	}
 }

 CardWizard.prototype.statusPopup = function(){
 	var oNewCartData = null;
	this.close();

	//update data
	if (this.iUpdateIndex != null) {
		location.href = document.URL;
	}else{
		
		//Status popup
	 	var oPopupje = new Popup();
		oPopupje.show();	
		var oClose = document.createElement('a');
		var oCloseText = document.createTextNode('>> Verder winkelen');
		oClose.appendChild(oCloseText);
		oClose.className = 'cancelCart';
		oClose.onclick = function(){
			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 geboortekaartje is correct toegevoegd aan uw winkelmandje');
		oMessage.appendChild(oMessageText);
		
		oPopUpDiv.appendChild(oMessage);
		oPopUpDiv.appendChild(oRemove);
		oPopUpDiv.appendChild(oClose);
		
		oPopupje.oPopup.appendChild(oPopUpDiv);		
		
		//Data check 
		if (this.oAjax.sRequestedData != '') {
			try {
				oNewCartData = eval('(' + this.oAjax.sRequestedData + ')');
				g_sSendCode = oNewCartData.sJsSendCode;
				this.oShoppingCart.innerHTML = oNewCartData.iAmountInShoppingCart;
			} 
			catch (sError) {
				location.href = '/shoppingcart';
			}
		}
	}
 }

 CardWizard.prototype.loadEnvelopes = function(){
 	var oData = null;
 	if(this.oAjax.sRequestedData != ''){
		try{
			oData = eval('(' + this.oAjax.sRequestedData + ')');
			g_oEnvelopes = oData.aEnvelopes;
			g_oAddressLabels = oData.aAddressLabels;
			g_sSendCode = oData.sJsSendCode;
		}catch(sError){
			location.href = document.URL;
		}
	}
	this.step();
 }
 
 CardWizard.prototype.close = function(){
 	this.oPopupje.close();
 }
 
 CardWizard.prototype.reLoad = function(){
 	var oData = null;
 	if(this.oAjax.sRequestedData != ''){
		try{
			oData = eval('(' + this.oAjax.sRequestedData + ')');
			g_sSendCode = oData.sJsSendCode;
			this.oTheCard = oData.aProduct;
			this.iAmount = oData.aCartData.iAmount;
			this.iCardId = oData.aCartData.iCardId;
			
			//step 1 
			this.oFrontTextArea.value = oData.aCartData.sFrontText;
			this.oLeftInsideTextArea.value = oData.aCartData.sLeftInsideText;
			this.oRightInsideTextArea.value = oData.aCartData.sRightInsideText;
			this.iEnvelopeId = oData.aCartData.aEnvelope.iEnvelopeId;
			this.iAddressLabelId = oData.aCartData.aAddressLabels.iAddressLabelId
			
			//step 2
			this.sFont = oData.aCartData.sFont;
			this.oCalculated = new Date(oData.aCartData.sDateCalculated * 1000);
			if (oData.aCartData.aEnvelope.sEnvelopeColor) {
				this.sSelectColorName = oData.aCartData.aEnvelope.sEnvelopeColor;
				this.iSelectedColor = oData.aCartData.aEnvelope.iEnvelopeColorIndex;
				this.bColorSelect = true;
			}
			
			//start load
			this.load();	
		}catch(sError){
			location.href = document.URL;
		}
	}
 }
 
 CardWizard.prototype.showColorSelect = function(){
	//Lettertype
	var aColorSelect = new Array();
	var oThis = this;		
	oFontP = document.createElement('p');
	oFontP.className = 'wizardColorInfo';
	oFontPText = document.createTextNode('Geef aan in welke kleur u de enveloppen wilt (Let op! kleuren op uw scherm kunnen afwijken van de daadwerkelijke kleuren.)');
	oFontP.appendChild(oFontPText);
	aColorSelect.push(oFontP)
	
	var aColors = ['rgb(255,255,255)', 'rgb(255,212,0)', 'rgb(250,166,26)', 'rgb(245,126,32)', 'rgb(206,24,31)', 'rgb(151,36,39)', 'rgb(252,222,220)', 'rgb(246,162,181)', 'rgb(226,59,121)', 'rgb(188,228,231)', 'rgb(71,183,210)', 'rgb(0,129,185)', 'rgb(199,208,33)', 'rgb(166,200,52)', 'rgb(91,179,68)', 'rgb(195,200,196)', 'rgb(205,171,126)', 'rgb(103,76,62)'];
	var aColorNames = ['Wit', 'Boterbloemgeel', 'Goudgeel', 'Feloranje', 'Koraalrood', 'Baccararood', 'Rose', 'Cerise', 'Cerise donker', 'Laguneblauw', 'Oceaanblauw', 'Koningsblauw', 'Limoen', 'Lindegroen', 'Weidegroen', 'Metaalgrijs', 'Zandbruin', 'Donkerbruin'];
	var oDivTemp = null;
	var oDivSelectColor = document.createElement('fieldset');
	var oLegend = document.createElement('legend');
	var oLegendText = document.createTextNode('Geselecteerde kleur');
	var oColorName = document.createElement('span');
	oLegend.appendChild(oLegendText);
	oDivSelectColor.appendChild(oLegend);
	oDivSelectColor.appendChild(oColorName);
	oDivSelectColor.className = 'SelectedColor';
	
	var oFirstRowDiv = document.createElement('div');
	oFirstRowDiv.className = 'firstColorRow';
	aColorSelect.push(oFirstRowDiv);
	var oSecantRowDiv = document.createElement('div');
	oSecantRowDiv.className = 'secantColorRow';
	aColorSelect.push(oSecantRowDiv);

	for (i = 0; i < aColors.length; i++) {
		oDivTemp = document.createElement('div');
		oDivTemp.style.background = aColors[i];
		oDivTemp.setAttribute('title', aColorNames[i]);
		oDivTemp.className = 'wizardColorSelect';
		
		//row
		if (aColors.length / 2 > i) {
			oSecantRowDiv.appendChild(oDivTemp);
		}else{
			oFirstRowDiv.appendChild(oDivTemp);
		}
		
		oDivTemp.onclick = function(){
			oThis.iSelectedColor = aColorNames.indexOf(this.title);
			oThis.sSelectColorName = this.title;
			oColorName.innerHTML = this.title;
			oDivSelectColor.style.background = this.style.background;
		}
	}
	aColorSelect.push(oDivSelectColor);
		
	//Color Select
	oDivSelectColor.style.background = aColors[this.iSelectedColor];
	oColorName.innerHTML = aColorNames[this.iSelectedColor];
	
	//return list
	return aColorSelect.reverse();
 }
 
 CardWizard.prototype.showDefaultLabel = function(){
	var oPreviewPopup = new Popup(350, 170);
	var oImg = new Image();
	oImg.src = '/images/default_labels.jpg';
	oImg.onclick = function(){
		oPreviewPopup.close();
	}
	oPreviewPopup.sPopupId = 'previewPopup';
	oPreviewPopup.sBlockId = 'previewBlock';
	oPreviewPopup.show();
	oPreviewPopup.oBlock.style.zIndex = '9999';
	oPreviewPopup.oBlock.onclick = function(){
		oPreviewPopup.close();
	}
	oPreviewPopup.oPopup.appendChild(oImg);
 }
 
 CardWizard.prototype.reLoadStart =  function(p_iProductIndex){
 		this.iUpdateIndex = p_iProductIndex;
 		this.oAjax.set('sQuery','{"sAction":"getProduct","iProductIndex":'+ p_iProductIndex +'}');
		this.oAjax.set('sSendCode', g_sSendCode);
		this.oAjax.set('sReturnDataTo', 'reLoad');
		this.oAjax.doSend();
 }
