var CANDLE_BOX = 0;
var GIFT_TAGS = 1;
var BLOCK_PUZZLE = 2;
var BUTTON = 3;

var project_states = [];
var project_sizes = [];

project_states[CANDLE_BOX] = "PHOTO_CANDLE";
project_states[GIFT_TAGS] = "PHOTO_TAGS";
project_states[BLOCK_PUZZLE] = "PHOTO_CUTTER";
project_states[BUTTON] = "BUTTON";

project_sizes[CANDLE_BOX] = 0;
project_sizes[BUTTON] = 0;

var BlockWizard = function(){
    var printhelp, expdlg, accessprint, welcome, fileupload, printer, photocutter, fonts, photos, processing, newpasswd, passwd, help;
	var step1, step2, step3;
    var dm;
	var firstrun = true;
	var next;
	var httpObj = new http_class();
	var state = 'START_WIZARD';
	var currentDialog = null;
	var email = '';
	var customer_id = null;
	var temp;
	var deletebtn;
	var refreshbtn;
	var upload_nextbtn;
	var num_photos;
	var photo_callback = null;
	var new_photo = null;
	var photo_first_run = true;
	var settings_to_use = null;
	var old_color = 0;
	var project_type  = -1;
	var projectObject = null;
	
    return {
        init : function(){
    		
        },
        
        showWelcome : function(dom)
        {
        	printhelp = null;
        	expdlg = null;
	   		welcome = null;
	   		fileupload = null;
	   		printer = null;
	   		photocutter = null;
	   		fonts = null;
	   		photos = null;
	   		processing = null;
	   		step1 = null;
	   		step2 = null;
	   		step3 = null;
	   		newpasswd = null;
	   		passwd = null;
			dm = null;
			firstrun = true;
			next = null;
			help = null;
			
			httpObj = new http_class();
			httpObj.setFailure(createObjectCallback(this, this.ajaxFailure))
			
			state = 'START_WIZARD';
			currentDialog = null;
			email = '';
			customer_id = null;
			temp = null;
			deletebtn = null;
			refreshbtn = null;
			upload_nextbtn = null;
			num_photos = 0;
			photo_callback = null;
			new_photo = null;
			photo_first_run = true;
			settings_to_use = null;
		    has_print_job = false;
		    
  			if(!welcome)
  			{
                welcome = new YAHOO.ext.BasicDialog("wizard-dlg", { 
                		modal: true,
                        width:500,
                        height:350,
                        shadow:true,
                        minWidth:500,
                        minHeight:350,
                        proxyDrag: true,
                        resizable: false
                });
                welcome.addKeyListener(27, this.closeWizard, BlockWizard);
                welcome.addKeyListener(13, this.validateEmail, BlockWizard);
                next = welcome.addButton('Next&raquo;', this.validateEmail, BlockWizard);
                welcome.addButton('Cancel', this.closeWizard, BlockWizard);
            }
            welcome.setTitle("Welcome to the Stories by Me Wizard! (v1.2 &copy 2009 Stories By Me)")
            if (dom != null)
            	welcome.show(dom);
            else
            	welcome.show();
            	
            welcome.dialog_id = 'START_WIZARD';
            currentDialog = welcome;
            document.getElementById("wizard_email").focus();
        },

        showNewPassword : function()
        {
  			if(!newpasswd)
  			{
                newpasswd = new YAHOO.ext.BasicDialog("wizard_new_password-dlg", { 
                		modal: true,
                        width:550,
                        height:460,
                        shadow:true,
                        minWidth:550,
                        minHeight:460,
                        proxyDrag: true,
                        resizable: false
                });
                newpasswd.addKeyListener(27, this.closeWizard, BlockWizard);
                newpasswd.addKeyListener(13, this.validateNewPassword, BlockWizard);
                newpasswd.addButton('Agree', this.validateNewPassword, BlockWizard);
                newpasswd.addButton('&laquo;Back', this.restartWizard, BlockWizard);
                newpasswd.addButton('Cancel', this.closeWizard, BlockWizard);
            }
            newpasswd.setTitle("Welcome to the Stories by Me Wizard! (v1.2 &copy 2009 Stories By Me)")
            newpasswd.show();
            newpasswd.dialog_id = 'NEW_PASSWORD';
            currentDialog = newpasswd;
            document.getElementById("wizard_password").focus();
        },        

        showPassword : function()
        {
  			if(!passwd)
  			{
                passwd = new YAHOO.ext.BasicDialog("wizard_password-dlg", { 
                		modal: true,
                        width:500,
                        height:250,
                        shadow:true,
                        minWidth:500,
                        minHeight:250,
                        proxyDrag: true,
                        resizable: false
                });
                passwd.addKeyListener(27, this.closeWizard, BlockWizard);
                passwd.addKeyListener(13, this.validatePassword, BlockWizard);
                passwd.addButton('Next&raquo;', this.validatePassword, BlockWizard);
                passwd.addButton('&laquo;Back', this.restartWizard, BlockWizard);
                passwd.addButton('Cancel', this.closeWizard, BlockWizard);
            }
            passwd.setTitle("Welcome to the Stories by Me Wizard! (v1.2 &copy 2009 Stories By Me)")
            passwd.show();
            passwd.dialog_id = 'CHECK_PASSWORD';
            currentDialog = passwd;
            document.getElementById("wizard_check_password").focus();
        },        

        startPrint : function()
        {
        	if (expired == 1)
        	{
        		this.showExpired();
        		return;
        	}
        	
  			if(!accessprint)
  			{
                accessprint = new YAHOO.ext.BasicDialog("wizard_access_print-dlg", { 
                		modal: true,
                        width:500,
                        height:375,
                        shadow:true,
                        minWidth:500,
                        minHeight:375,
                        proxyDrag: true,
                        resizable: false
                });
                accessprint.addKeyListener(27, this.closeWizard, BlockWizard);
                accessprint.addKeyListener(13, this.validateEmailPassword, BlockWizard);
                accessprint.addButton('Next&raquo;', this.validateEmailPassword, BlockWizard);
                accessprint.addButton('Cancel', this.closeWizard, BlockWizard);
            }
            accessprint.setTitle("Welcome to the Stories by Me Wizard! (v1.2 &copy 2009 Stories By Me)")
            accessprint.show();
            accessprint.dialog_id = 'CHECK_EMAIL_PASSWORD';
            currentDialog = accessprint;
            document.getElementById("wizard_email").focus();
        },           
        
        showFileUpload : function()
        {
        	photo_callback = this.setNumPhotos;
        	var photos = document.getElementById("photo_frame");
        	photos.src = "/wizard/sbm_get_photos.php?id=" + customer_id;
        	document.getElementById("id").value = customer_id;
        	
  			if(!fileupload)
  			{
                fileupload = new YAHOO.ext.BasicDialog("wizard_file_upload-dlg", { 
                		modal: true,
                        width:700,
                        height:450,
                        shadow:true,
                        minWidth:700,
                        minHeight:450,
                        proxyDrag: true,
                        resizable: false
                });
                fileupload.addKeyListener(27, this.closeWizard, BlockWizard);
                fileupload.addKeyListener(13, this.doProject, BlockWizard);
                upload_nextbtn = fileupload.addButton('Next&raquo;',this.doProject, BlockWizard);
                upload_nextbtn.disable();
                fileupload.addButton('Cancel', this.closeWizard, BlockWizard);
                deletebtn = fileupload.addButton('Delete', this.deletePhoto, BlockWizard);
                refreshbtn = fileupload.addButton('Refresh', this.refreshPhotos, BlockWizard);
                deletebtn.disable();
                fileupload.addButton('Contact Support', this.contactUs, BlockWizard);
            }
            fileupload.setTitle("Add Photos (v1.2 &copy 2009 Stories By Me)")
            fileupload.show();
            fileupload.dialog_id = 'FILE_UPLOAD';
            currentDialog = fileupload;
        },
             
        contactUs : function()
        {
			window.location.href = "mailto:wizard@storiesbyme.com";
        },
        
        showPhotoCutter : function()
        {
        	// get the list of images. Have get_photos tell us which image to use
        	photo_callback = this.selectThePhoto;
        	var photos = document.getElementById("cutter_photo_frame");
        	photos.src = "/wizard/sbm_get_photos.php?id=" + customer_id + "&cutter=1";
  			//if(!photocutter)
  		//	{
               photocutter = new YAHOO.ext.BasicDialog("photo_cutter-dlg", { 
               			modal: true,
                        width:770,
                        height:570,
                        shadow:true,
                        minWidth:770,
                        minHeight:570,
                        proxyDrag: true,
                        resizable: true
                });
                photocutter.addKeyListener(27, this.closeWizard, BlockWizard);
                photocutter.addKeyListener(13, this.checkReturn, BlockWizard);
                photocutter.addButton('Print',this.checkBeforeSavePDF, BlockWizard);
                photocutter.addButton('&laquo;Back', this.resetModule, BlockWizard); 
                photocutter.addButton('Cancel',this.checkPhotoCancel, BlockWizard);
                photocutter.addButton('Contact Support', this.contactUs, BlockWizard);
          //  }
            photocutter.setTitle("Photo Cutter (v1.2 &copy 2009 Stories By Me)")
            photocutter.show();
            photocutter.dialog_id = 'PHOTO_CUTTER';
            currentDialog = photocutter;
   			this.projectObject.setHandlePos();
        },
        resetModule : function(func)
        {
        	settings_to_use = null;
        	this.doFileUpload();
        	
        },
        
        showCandleBox : function()
        {
        	// get the list of images. Have get_photos tell us which image to use
        	photo_callback = this.selectThePhoto;
        	var photos = document.getElementById("cutter_photo_frame");
        	photos.src = "/wizard/sbm_get_photos.php?id=" + customer_id + "&cutter=1";
  			//if(!photocutter)
  		//	{
               photocutter = new YAHOO.ext.BasicDialog("photo_candle-dlg", { 
               			modal: true,
                        width:770,
                        height:570,
                        shadow:true,
                        minWidth:770,
                        minHeight:570,
                        proxyDrag: true,
                        resizable: true
                });
                photocutter.addKeyListener(27, this.closeWizard, BlockWizard);
                photocutter.addKeyListener(13, this.checkReturn, BlockWizard);
                photocutter.addButton('Print',this.checkBeforeSavePDF, BlockWizard);
                photocutter.addButton('&laquo;Back', this.doFileUpload, BlockWizard); 
                photocutter.addButton('Cancel',this.checkPhotoCancel, BlockWizard);
                photocutter.addButton('Contact Support', this.contactUs, BlockWizard);
          //  }
            photocutter.setTitle("Block/Box (v1.2 &copy 2009 Stories By Me)")
            photocutter.show();
            photocutter.dialog_id = 'PHOTO_CANDLE';
            currentDialog = photocutter;
   			this.projectObject.setHandlePos();
        },
        showGiftTags : function()
        {
        	// get the list of images. Have get_photos tell us which image to use
        	photo_callback = this.selectThePhoto;
        	var photos = document.getElementById("cutter_photo_frame");
        	photos.src = "/wizard/sbm_get_photos.php?id=" + customer_id + "&cutter=1";
  			//if(!photocutter)
  		//	{
               photocutter = new YAHOO.ext.BasicDialog("photo_gifttag-dlg", { 
               			modal: true,
                        width:770,
                        height:570,
                        shadow:true,
                        minWidth:770,
                        minHeight:570,
                        proxyDrag: true,
                        resizable: true
                });
                photocutter.addKeyListener(27, this.closeWizard, BlockWizard);
                photocutter.addKeyListener(13, this.checkReturn, BlockWizard);
                photocutter.addButton('Print',this.checkBeforeSavePDF, BlockWizard);
                photocutter.addButton('&laquo;Back', this.doFileUpload, BlockWizard); 
                photocutter.addButton('Cancel',this.checkPhotoCancel, BlockWizard);
                photocutter.addButton('Contact Support', this.contactUs, BlockWizard);
          //  }
            photocutter.setTitle("Gift Tags (v1.2 &copy 2009 Stories By Me)")
            photocutter.show();
            photocutter.dialog_id = 'PHOTO_TAGS';
            currentDialog = photocutter;
   			this.projectObject.setHandlePos();
        },
        showButtons : function()
        {
        	// get the list of images. Have get_photos tell us which image to use
        	photo_callback = this.selectThePhoto;
        	var photos = document.getElementById("cutter_photo_frame");
        	photos.src = "/wizard/sbm_get_photos.php?id=" + customer_id + "&cutter=1";
  			//if(!photocutter)
  		//	{
               photocutter = new YAHOO.ext.BasicDialog("photo_button-dlg", { 
               			modal: true,
                        width:770,
                        height:570,
                        shadow:true,
                        minWidth:770,
                        minHeight:570,
                        proxyDrag: true,
                        resizable: true
                });
                photocutter.addKeyListener(27, this.closeWizard, BlockWizard);
                photocutter.addKeyListener(13, this.checkReturn, BlockWizard);
                photocutter.addButton('Print',this.checkBeforeSavePDF, BlockWizard);
                photocutter.addButton('&laquo;Back', this.doFileUpload, BlockWizard); 
                photocutter.addButton('Cancel',this.checkPhotoCancel, BlockWizard);
                photocutter.addButton('Contact Support', this.contactUs, BlockWizard);
          //  }
            photocutter.setTitle("Face Buttons (v1.2 &copy 2009 Stories By Me)")
            photocutter.show();
            photocutter.dialog_id = 'BUTTON';
            currentDialog = photocutter;
   			this.projectObject.setHandlePos();
        },
        setProjectType : function(type)
        {
        	project_type = type;
        },
        showFonts : function()
        {
  			if(!fonts)
  			{
                fonts = new YAHOO.ext.BasicDialog("fonts-dlg", { 
                		modal: true,
                        width:425,
                        height:510,
                        shadow:true,
                        minWidth:425,
                        minHeight:510,
                        proxyDrag: true,
                        resizable: false
                });
                fonts.addButton('Apply', this.applyFont, BlockWizard);
                fonts.addButton('Cancel', fonts.hide, fonts);
            }
            fonts.setTitle("Font Options")
            fonts.show();
            this.projectObject.populateFontDialog();
        },        


        showPhotos : function()
        {
        	if (this.projectObject.checkForChanges())
        	{
        		var retVal = confirm("You have unsaved changes. Are you sure you want to load another photo?");
        		if (!retVal)
        			return;
        	}
  			if(!photos)
  			{
                photos = new YAHOO.ext.BasicDialog("choose_photo-dlg", { 
                		modal: true,
                        width:360,
                        height:320,
                        shadow:true,
                        minWidth:350,
                        minHeight:320,
                        proxyDrag: true,
                        resizable: false
                });
                photos.addButton('Ok', this.selectPhoto, BlockWizard);
                photos.addButton('Cancel', photos.hide, photos);
            }
            photos.setTitle("Choose Photo")
            photos.show();
            var p = document.getElementById("cutter_photo_frame");
        	p.src = p.src;
        },         

        restartWizard : function()
        {
        	this.closeWizard();
        	this.showWelcome();
        },
        
        checkPhotoCancel : function()
        {
			if (!this.checkCancel())
				return;
				
        	this.closeWizard();
        },
        
        checkBeforeSavePDF : function()
        {
			if (!this.checkCancel())
				return;
			
			if (!this.projectObject.hasPrintList())
			{
				alert("You must add at least one photo to the page for printing.");
				return;
			}
				
			
			if (has_print_job)
			{
				var retVal = confirm("Are you sure that you want to print this project? You will lose any previous print jobs that are currently associated with this email address. Press Yes to continue, press Cancel to stop this print request. Remember that you can print multiple photographs by adding each picture to the Photos to Print list.")
        		if (!retVal)
        			return;
			}
			
			
			if (this.projectObject.hasBeenSaved())
			{
				this.savePDF();
			}
			else
			{
				alert("You must save this photo before you can print it.");
			}
        },
        
        savePDF : function()
        {
        	this.showProcessing();
        	var photo_ids = this.projectObject.getPhotoIdsForPDF();
    		state = "SAVE_PDF";
			httpObj.setURL("/wizard/sbm_save_pdf.php");
			httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler));
			var size = this.getSize();
			httpObj.httpMessage({"id":customer_id, "photo_ids":photo_ids, "project_type":project_type, "size":size});	
        },

        passwordReminder : function()
        {
    		state = "PASSWORD_REMINDER";
			httpObj.setURL("/wizard/check_email.php");
			var emailStr = document.getElementById("wizard_email").value;
			if (!this.checkEmail(emailStr))
			{
				alert("Please enter a valid email address.");
				return;
			}
        	this.showProcessing();
			httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler));
			httpObj.httpMessage({"wizard_email":emailStr, "reminder":1});	
        },
        
        checkCancel : function()
        {
        	if (this.projectObject.checkForChanges())
        	{
        		var retVal = confirm("You have unsaved changes. Click Ok to discard changes.");
        		if (!retVal)
        			return false;
        	}
        	return true;
        },
        
        showProcessing : function()
        {
  			if(!processing)
  			{
                processing = new YAHOO.ext.BasicDialog("processing-dlg", { 
                		modal: true,
                        width:400,
                        height:150,
                        shadow:true,
                        minWidth:300,
                        minHeight:300,
                        proxyDrag: true,
                        resizable: false
                });
                processing.addButton('Cancel', processing.hide, processing);
            }
            processing.setTitle("Processing...")
            processing.show();
        },         
        showStep1 : function()
        {
  			if(!step1)
  			{
                step1 = new YAHOO.ext.BasicDialog("step1-dlg", { 
                		modal: true,
                        width:400,
                        height:300,
                        shadow:true,
                        minWidth:300,
                        minHeight:300,
                        proxyDrag: true,
                        resizable: false
                });
                step1.addButton('Ok', step1.hide, step1);
            }
            step1.setTitle("Step 1 Helpful Hints")
            step1.show();
        },         
        showStep2 : function()
        {
  			if(!step2)
  			{
                step2 = new YAHOO.ext.BasicDialog("step2-dlg", { 
                		modal: true,
                        width:550,
                        height:300,
                        shadow:true,
                        minWidth:300,
                        minHeight:300,
                        proxyDrag: true,
                        resizable: false
                });
                step2.addButton('Ok', step2.hide, step2);
            }
            step2.setTitle("Step 2 Helpful Hints")
            step2.show();
        }, 
        showStep3 : function()
        {
  			if(!step3)
  			{
                step3 = new YAHOO.ext.BasicDialog("step3-dlg", { 
                		modal: true,
                        width:400,
                        height:300,
                        shadow:true,
                        minWidth:300,
                        minHeight:300,
                        proxyDrag: true,
                        resizable: false
                });
                step3.addButton('Ok', step3.hide, step3);
            }
            step3.setTitle("Step 3 Helpful Hints")
            step3.show();
        },         
        showExpired : function()
        {
  			if(!expdlg)
  			{
                expdlg = new YAHOO.ext.BasicDialog("expired-dlg", { 
                		modal: true,
                        width:400,
                        height:150,
                        shadow:true,
                        minWidth:300,
                        minHeight:300,
                        proxyDrag: true,
                        resizable: false
                });
                expdlg.addButton('Ok', expdlg.hide, expdlg);
            }
            expdlg.setTitle("Print Out Expired")
            expdlg.show();
        },  
               
        showPrintHelp : function()
        {
  			if(!printhelp)
  			{
                printhelp = new YAHOO.ext.BasicDialog("print_help-dlg", { 
                		modal: true,
                        width:400,
                        height:400,
                        shadow:true,
                        minWidth:400,
                        minHeight:400,
                        proxyDrag: true,
                        resizable: false
                });
                printhelp.addButton('Ok', this.doPrintPDF, BlockWizard);
            }
            printhelp.setTitle("When Printing or Saving")
            printhelp.show();
        },         

        doPrintPDF : function()
        {
        	printhelp.hide();
        	this.showPrintPDF();
        },
        
        showPrintPDF : function()
        {
  			if(!printer)
  			{
  				printer = new YAHOO.ext.LayoutDialog("wizard_print-dlg", { 
                        modal:true,
                        width:750,
                        height:550,
                        shadow:true,
                        minWidth:750,
                        minHeight:550,
                        fixedcenter: true,                        
	                    center: {
		                    initialSize: 700,
		                    minSize: 700,
		                    maxSize: 700,
		                    titlebar: false,
		                    collapsible: false,
		                    animate: false,
		                    autoScroll:true,
		                    cmargins: {top:2,bottom:2,right:2,left:2}  
	                    }
                });
                
                printer.addKeyListener(27, printer.hide, printer);
                printer.addButton('Cancel', printer.hide, printer);
                
				var layout = printer.getLayout();
                layout.beginUpdate();
                
	            var printFrame = YAHOO.ext.DomHelper.append(document.body, {tag: 'iframe', frameBorder: 0, id: 'print-frame', src: "http://www.storiesbyme.com/wizard/get_pdf.php?id="+customer_id});
	            var cp = new YAHOO.ext.ContentPanel(printFrame, {fitToFrame:true, closable:false});
	            layout.add('center', cp); 
                
                
               // var cp =  new YAHOO.ext.ContentPanel('print-page', {fitToFrame:true});
               // alert("http://www.storiesbyme.com/home/bw/get_pdf.php?id="+customer_id);
               // cp.setUrl("get_pdf.php?id="+customer_id);
	            //var lv = layout.add('center', cp);
	            
  				layout.restoreState();               	
                layout.endUpdate();                
  				
            }
            printer.setTitle("Stories by Me Wizard (v1.2 &copy 2009 Stories By Me)")
            printer.show();
        },          
        
        showHelp : function()
        {
  			if(!help)
  			{
                help = new YAHOO.ext.BasicDialog("help-dlg", { 
                		modal: true,
                        width:600,
                        height:400,
                        shadow:true,
                        minWidth:300,
                        minHeight:300,
                        proxyDrag: true,
                        resizable: false
                });
                help.addButton('Close', help.hide, help);
            }
            help.setTitle("Block Wizard Help")
            help.show();
        },         
        
        savePhoto : function(data)
        {
        	if (data.bg_color.indexOf("#") > -1)
        	{
				data.bg_color = data.bg_color.substr(1,7);
        	}
       		if (data.grid_color.indexOf("#") > -1)
        	{
				data.grid_color = data.grid_color.substr(1,7);
        	}
       		if (data.text_color.indexOf("#") > -1)
        	{
				data.text_color = data.text_color.substr(1,7);
        	}        	
			var temp1 = data.text_line_1;
			var temp2 = data.text_line_2;
        	data.text_line_1 = encodeURIComponent(data.text_line_1);
			data.text_line_2 = encodeURIComponent(data.text_line_2);

			var size = this.getSize();
			data.project_type = project_type;
			data.size = size;
			this.showProcessing();
    		state = "SAVE_PHOTO";
			httpObj.setURL("/wizard/sbm_save_photo.php");
			httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler))
			httpObj.httpMessage(data);	
			data.text_line_1 = temp1;
			data.text_line_2 = temp2;
        },
        
        changeShape : function(shape)
        {
        	this.projectObject.changeShape(shape);
        },
        
        changeSize : function()
        {
        	this.projectObject.changeSize();
        },        
        
        getSize : function()
        {
        	var obj = document.getElementById('size_'+project_type);
        	if (obj)
        	   	return obj.options[obj.selectedIndex].value;
        },         
        
        toggleSepia : function()
        {
        	old_color = this.projectObject.getColor();
        	this.showProcessing();
        	// 1. show processing dialog box
        	// 2. make or load sepia image
        	// 3. set blockcutter sepia flag
        	if (this.projectObject.toggleSepia() == 1)
        	{
        		// we need to see if there's already a sepia version
        		// if so, load that image
        		// if not, make it and load that image
        		var photo = this.projectObject.getCurrentPhoto();
        		state = "CONVERT_SEPIA";
				httpObj.setURL("/wizard/convert_photo.php");
				httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler))
				httpObj.httpMessage({"id":customer_id, "photo":photo,"color":"sepia"});				
        	}
        	else
        	{
        		//load the original image
        		processing.hide();
        		this.projectObject.loadImage("/photos/" + customer_id + "/");
        	}
        	
        },

        toggleOriginal : function()
        {
        	old_color = this.projectObject.getColor();
        	this.showProcessing();
        	// 1. show processing dialog box
        	// 2. make or load sepia image
        	// 3. set blockcutter sepia flag
        	if (this.projectObject.toggleOriginal() == 0)
        	{
        		processing.hide();
        		this.projectObject.loadImage("/photos/" + customer_id + "/");			
        	}
        },      
        
        toggleGrey : function()
        {
        	old_color = this.projectObject.getColor();
        	this.showProcessing();
        	// 1. show processing dialog box
        	// 2. make or load sepia image
        	// 3. set blockcutter sepia flag
        	if (this.projectObject.toggleGrey() == 2)
        	{
        		// we need to see if there's already a sepia version
        		// if so, load that image
        		// if not, make it and load that image
        		var photo = this.projectObject.getCurrentPhoto();
        		state = "CONVERT_GREY";
				httpObj.setURL("/wizard/convert_photo.php");
				httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler))
				httpObj.httpMessage({"id":customer_id, "photo":photo,"color":"grey"});				
        	}
        	else
        	{
        		//load the original image
        		processing.hide();
        		this.projectObject.loadImage("/photos/" + customer_id + "/");
        	}
        	
        },
                
        selectPhoto : function()
        {
        	photo_callback(new_photo);
        	photos.hide();
        },
        
        applyFont : function()
        {
        	this.projectObject.applyJustify();
        	this.projectObject.applyBold();
        	this.projectObject.applyFont();
        	fonts.hide();
        },
        
        checkReturn : function(e)
        {
        	if (this.projectObject.isEditingText())
        	{
        		this.projectObject.toggleText();
        		return;
        	}
        },
         
        doProject : function()
        {
        	if (project_type == -1)
        	{
        		var obj = document.getElementById("candle_radio")
        		if (obj.checked)
        		{
        			project_type = CANDLE_BOX;
        		}
        		var obj = document.getElementById("gift_radio")
        		if (obj.checked)
        		{
        			project_type = GIFT_TAGS;
        		}
        		var obj = document.getElementById("button_radio")
        		if (obj.checked)
        		{
        			project_type = BUTTON;
        		}
        		var obj = document.getElementById("puzzle_radio")
        		if (obj.checked)
        		{
        			project_type = BLOCK_PUZZLE;
        		}
        		
        	  	if (project_type == -1)
        		{
	        		alert("Please choose a project type")
	        		return;
        		}
        	}
        	
        	if (project_type == BLOCK_PUZZLE)
        		this.doCutter();
        		
        	if (project_type == CANDLE_BOX)
        		this.doCandle();
        		
        	if (project_type == GIFT_TAGS)
        		this.doGiftTags();        		
        		
        	if (project_type == BUTTON)
        		this.doButtons();           		
        },
    	
        
        doCutter : function()
        {
        	this.projectObject = BlockCutter;
        	document.getElementById("final_text").style.display = "";
        	if (!upload_nextbtn.disabled)
        	{
        		photo_first_run = true;
        		settings_to_use = window.frames["photo_frame"].getPhoto();
	        	state = project_states[project_type];
	        	this.nextState();
        	}
        },
        
        doCandle : function()
        {
        	this.projectObject = CandleBox;
        	this.projectObject.setMaxPhotos(project_sizes[CANDLE_BOX]);
        	document.getElementById("final_text").style.display = "";
        	if (!upload_nextbtn.disabled)
        	{
        		photo_first_run = true;
        		settings_to_use = window.frames["photo_frame"].getPhoto();
	        	state = "PHOTO_CANDLE";
	        	this.nextState();
        	}
        },        

        doGiftTags : function()
        {
        	this.projectObject = GiftTag;
        	document.getElementById("final_text").style.display = "";
        	if (!upload_nextbtn.disabled)
        	{
        		photo_first_run = true;
        		settings_to_use = window.frames["photo_frame"].getPhoto();
	        	state = "PHOTO_TAGS";
	        	this.nextState();
        	}
        },         
        
        doButtons : function()
        {
        	this.projectObject = Button;
        	//this.projectObject.setMaxPhotos(project_sizes[BUTTON]);
        	document.getElementById("final_text").style.display = "none";
        	if (!upload_nextbtn.disabled)
        	{
        		photo_first_run = true;
        		settings_to_use = window.frames["photo_frame"].getPhoto();
	        	state = "BUTTON";
	        	this.nextState();
        	}
        },      
            
        setProjectSize : function(project_type, size)
        {
        	if (project_sizes[project_type] != size)
        	{
        		if (this.projectObject)
        		{
        			this.projectObject.erasePrintList();
        			this.projectObject.updatePrintList();
        		}
        	}
        	project_sizes[project_type] = size;
        },
        
		doFileUpload : function()
		{
        	state = 'FILE_UPLOAD';
        	this.nextState();
		},
		        
        doWelcome: function(fromButton)
        {
        	if (fromButton == true)
        	{
        		if (currentDialog != 'undefined' && currentDialog != null)
        			return;
        	}
        	state = 'START_WIZARD';
        	this.nextState();
        },
        
        
        enableDelete : function()
        {
        	deletebtn.enable();
        },
        
        disableDelete : function()
        {
        	deletebtn.disable();
        },
        
        doPhotoCallback : function(data, bBoolean)
        {
        	if (currentDialog.dialog_id == 'PHOTO_CUTTER' || currentDialog.dialog_id == 'PHOTO_CANDLE' || currentDialog.dialog_id == 'PHOTO_TAGS' || currentDialog.dialog_id == 'BUTTON')
        	{
        		if (bBoolean)
        		{
        			if (photo_first_run)
        			{
        				photo_callback(data);
        				photo_first_run = false;
        			}        				
        		}
        		else
        			new_photo = data;
        	}
        	else
        	{
        		photo_callback(data);
        	}
        },
        
        selectThePhoto : function(data)
        {
        	if (settings_to_use != null)
        	{
        		this.BlockWizard.projectObject.useSavedSettings(settings_to_use);
        		if (settings_to_use.has_jobs == '1')
        			has_print_job = true;
        	}
        	else
				this.BlockWizard.projectObject.useSavedSettings(data);
			settings_to_use = null;
        },
       
        setNumPhotos : function(num)
        {
        	num_photos = num;
        	if (upload_nextbtn)
        	{
	        	if (num_photos > 0)
	        		upload_nextbtn.enable();
	        	else
	        		upload_nextbtn.disable();
        	}
        },
        
		refreshPhotos : function()
		{
        	var photos = document.getElementById("photo_frame");
        	photos.src = photos.src;
        	this.stopProgress();
        	this.disableDelete();
		},
		
		startProgress : function(str)
		{
			document.getElementById("uploadForm").style.display = "none";
			document.getElementById("progress_text").innerHTML = str;
			document.getElementById("progress").style.display = "inline";
		},
		
		stopProgress : function()
		{
			document.getElementById("uploadForm").style.display = "inline";
			document.getElementById("progress").style.display = "none";
		},
		
		uploadError : function(str, type, url)
		{
			if (type != undefined)
			{
				if (type == 'prompt')
				{
					var ret = confirm(str);
					if (ret)
					{
						window.location.href = url;
					}
				}
			}
			else
			{
				alert(str);
			}
			this.stopProgress();
		},
		
		doUpload : function()
		{
			if (num_photos == 20)
			{
				alert("You are only allowed 20 photos.");
				return false;
			}
			this.startProgress("Sending the Photo, please wait...");
			return true;
		},
		
		validateEmail : function()
		{
			var bError = false;
			var szErrorMsg = "Please enter a valid email address";
			var emailStr = document.getElementById("wizard_email").value;
			if (!document.getElementById("wizard_email"))
				bError = true;
				
			if (!this.checkEmail(emailStr))
				bError = true;
				
			if (bError)
			{
				if (document.getElementById("wizard_welcome_str"))
				{
					document.getElementById("wizard_welcome_str").innerHTML = szErrorMsg;
					document.getElementById("wizard_welcome_str").style.color = "#f00";
				}
			}
			else
			{
				// no errors this far so let's do an ajax call and see if there's an issue with this email
				// in the database
				this.showProcessing();
				state = 'CHECK_EMAIL'
				httpObj.setURL("/wizard/check_email.php");
				httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler))
				httpObj.httpMessage({"wizard_email":emailStr});	
			}
		},

		validateNewPassword : function()
		{
			var pass_str = document.getElementById("wizard_password").value;
			var verify_str = document.getElementById("wizard_verify_password").value;
			if (pass_str != verify_str)
			{
				alert("The password do not match. Please make sure the the password and verify password boxes match.");
				return;
			}

			if (pass_str.length < 4 || pass_str > 10)
			{
				alert("Your password must be between 4 and 10 characters");
				return;
			}
			
			// no errors this far so let's do an ajax call and see if there's an issue with this email
			// in the database
			
			var opt = 0;
			if (document.getElementById("opt_in").checked)
				opt = 1;
				
			this.showProcessing();
			state = 'CHECK_PASSWORD'
			httpObj.setURL("/wizard/check_password.php");
			httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler))
			httpObj.httpMessage({"password":pass_str, "verify":verify_str, "id":customer_id,"opt_in":opt});	
		},		
		
		validatePassword : function()
		{
			var pass_str = document.getElementById("wizard_check_password").value;

			if (pass_str.length < 4 || pass_str > 10)
			{
				alert("Your password must be between 4 and 10 characters");
				return;
			}
			
			// no errors this far so let's do an ajax call and see if there's an issue with this email
			// in the database
			this.showProcessing();
			state = 'CHECK_PASSWORD'
			httpObj.setURL("/wizard/check_password.php");
			httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler))
			httpObj.httpMessage({"password":pass_str, "id":customer_id});	
		},		

		validateEmailPassword : function()
		{
			var emailStr = document.getElementById("wizard_email").value;
				
			if (!this.checkEmail(emailStr))
			{
				alert("Please enter a valid email address.");
				return;
			}
			
			var pass_str = document.getElementById("wizard_check_password").value;

			if (pass_str.length < 4 || pass_str > 10)
			{
				alert("Your password must be between 4 and 10 characters");
				return;
			}
			
			// no errors this far so let's do an ajax call and see if there's an issue with this email
			// in the database
			this.showProcessing();
			state = 'CHECK_EMAIL_PASSWORD'
			httpObj.setURL("/wizard/check_password.php");
			httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler))
			httpObj.httpMessage({"key":key, "email":emailStr, "password":pass_str, "id":0});	
		},			
		
		deletePhoto : function()
		{
			var retVal = confirm("Are you sure you want to delete this photo?");
			if (!retVal)
				return;
			
			var settings = window.frames["photo_frame"].getPhoto();
			
			state = 'DELETE_PHOTO';
			this.startProgress("Deleting photo, please wait...");
			httpObj.setURL("/wizard/delete_photo.php");
			httpObj.setSuccess(createObjectCallback(this, this.ajaxHandler))
			httpObj.httpMessage({"id":customer_id, "photo":settings.photo});				
		},
				
		ajaxHandler : function(resp)
		{
			switch(state)
			{
				case 'CHECK_EMAIL':
				{
					processing.hide();
					if (resp == '0')
					{
						alert("I'm sorry but our server said there was an error while checking your email address. Please contact support with Error Code: 1");
						state = 'CLOSE_DIALOG';
					}
					else if (resp == '-1')
					{
						alert("I'm sorry but you cannot use the Stories by Me Wizard at this time.  Please contact support with Error Code: 2");
						state = 'CLOSE_DIALOG';
					}
					else
					{
						if (resp.indexOf("|NEW") > -1)
						{
							var arr = resp.split("|");
							customer_id = arr[0];
							state = 'DO_NEW_PASSWORD';
						}
						else
						{
							customer_id = resp;
							state = 'DO_PASSWORD';
						}
					}
					break;
				}
				case 'CHECK_PASSWORD':
				{
					processing.hide();
					if (resp == '0')
					{
						alert("I'm sorry but the email and password do not match.");
						state = 'NO_CHANGE';
					}
					else
					{
						state = 'FILE_UPLOAD';
					}
					break;
				}				
				case 'CHECK_EMAIL_PASSWORD':
				{
					processing.hide();
					if (resp == '0')
					{
						alert("I'm sorry but the email and password do not match.");
						state = 'NO_CHANGE';
					}
					else
					{
						customer_id = resp;
						state = 'PRINT_HELP';
					}
					break;
				}	
				case 'DELETE_PHOTO':
				{
					if (resp == 998 || resp == 999)
					{
						alert("There was a problem and the Wizard will now close. Please Refresh the page and start the Wizard again.");
						state = 'CLOSE_DIALOG';
					}
										
					if (resp == '-2')
					{
						alert("I'm sorry but the file could not be deleted.  Please contact support with Error Code: 3");
						this.stopProgress();
						state = 'FILE_UPLOAD';
					}
					else if (resp == '-3')
					{
						this.refreshPhotos();
						state = 'FILE_UPLOAD';
					}
					break
				}
				case 'CONVERT_GREY':
				{
					// go back to our original state
					processing.hide();
					state = project_states[project_type];
					if (resp == 998 || resp == 999)
					{
						alert("There was a problem and the Wizard will now close. Please Refresh the page and start the Wizard again.");
						state = 'CLOSE_DIALOG';
					}
					
					if (resp == "1")
					{
						// good conversion or file found
						this.projectObject.loadImage("/photos/"+customer_id+"/grey/", true);
					}
					else
					{
						// bad conversion
						// pop up an error message
						alert("I'm sorry but your picture could not be converted to grayscale. Please contact support with Error Code: 4");
					}
					break;
				}				
				case 'CONVERT_SEPIA':
				{
					// go back to our original state
					processing.hide();
					state = project_states[project_type];
					
					if (resp == 998 || resp == 999)
					{
						alert("There was a problem and the Wizard will now close. Please Refresh the page and start the Wizard again.");
						state = 'CLOSE_DIALOG';
					}

					if (resp == "1")
					{
						// good conversion or file found
						this.projectObject.loadImage("/photos/"+customer_id+"/sepia/", true);
					}
					else
					{
						// bad conversion
						// pop up an error message
						alert("I'm sorry but your picture could not be converted to sepia tone. Please contact support with Error Code: 5");
					}
					break;
				}
				case 'SAVE_PHOTO':
				{
					processing.hide();
					state = project_states[project_type];

					if (resp == 998 || resp == 999)
					{
						alert("There was a problem and the Wizard will now close. Please Refresh the page and start the Wizard again.");
						state = 'CLOSE_DIALOG';
					}

					if (resp == -1)
					{
						// bad data!
						alert("I'm sorry but your photo could not be saved. Error Code: 6");
					}
					if (resp == -2)
					{
						// bad data!
						alert("I'm sorry but your photo could not be saved. Error Code: 7");
					}
					if (resp > 0)
					{
						this.projectObject.setPhotoId(resp);
					}
					break;
				}
				case 'SAVE_PDF':
				{
					processing.hide();
					state = "NO_CHANGE";
					if (resp == 998 || resp == 999)
					{
						alert("There was a problem and the Wizard will now close. Please Refresh the page and start the Wizard again.");
						state = 'CLOSE_DIALOG';
					}					
					if (resp == -1)
					{
						// bad data!
						alert("I'm sorry but there was an error creating your print. Error Code: 8");
					}
					if (resp == -2)
					{
						// bad data!
						alert("I'm sorry but there was an error creating your print. Error Code: 9");
					}
					if (resp == -3)
					{
						// bad data!
						alert("I'm sorry but there was an error creating your print. Error Code: 10");
					}
					if (resp > 0)
					{
						alert("An email has been sent to you with instructions on how to retrieve your print out. IMPORTANT! If you don't receive an email within the next ten minutes, it is possible that your server is blocking our mail. Please contact Stories by Me so we can get this quickly resolved!");
					}
					break;
				}
				case 'PASSWORD_REMINDER':
				{
					processing.hide();
					state = "NO_CHANGE";
					if (resp == 1)
					{
						alert("An email with your password has just been sent to you.");
					}
					else
					{
						alert("We were not able to find a password for the email you specified");
					}
					break;
				}
				default:
					state = 'CLOSE_DIALOG';
					break;
			}
			this.nextState();
			
		},

		ajaxFailure : function()
		{
			switch(state)
			{
				case 'CHECK_EMAIL':
				{
					alert("The web site timed out while trying to check your email. Please try again.");
					state = "NO_CHANGE";
					break;
				}
				case 'CHECK_PASSWORD':
				{
					alert("The web site timed out while trying to check your password. Please try again.");
					state = "NO_CHANGE";
					break;
				}				
				case 'CHECK_EMAIL_PASSWORD':
				{
					alert("The web site timed out while trying to check your email and password. Please try again.");
					state = "NO_CHANGE";
					break;
				}	
				case 'DELETE_PHOTO':
				{
					this.stopProgress();
					alert("The web site timed out while trying to delete your photo. Please try again.");
					state = "NO_CHANGE";
					break;
				}
				case 'CONVERT_GREY':
				case 'CONVERT_SEPIA':
				{
					// go back to our original state
					processing.hide();
					alert("The web site timed out while trying to change the color of your photo. Please try again.");
					this.projectObject.restoreColorState(old_color);
					state = "NO_CHANGE";
					break;
				}				
				case 'SAVE_PHOTO':
				{
					processing.hide();
					alert("The web site timed out while trying to save your photo. Please try again.");
					state = "NO_CHANGE";					
					break;
				}
				case 'SAVE_PDF':
				{
					processing.hide();
					alert("The web site timed out while trying to create your PDF for printing. Please try again.");
					state = "NO_CHANGE";					
					break;
				}
				case 'PASSWORD_REMINDER':
				{
					processing.hide();
					alert("The web site timed out while trying to retrieve your password. Please try again.");
					state = "NO_CHANGE";					
					break;

				}
				default:
					processing.hide();
					alert("The web site timed out. Please try again.");
					state = "NO_CHANGE";					
					break;
			}
			this.nextState();
			
		},
		
		
		AddText : function(line)
		{
			if (project_type == BLOCK_PUZZLE)
			{
				var curr_text = document.getElementById("text_box_"+line).value;
				var text = prompt("Please enter the text for line " + line, curr_text);
		
				if (text == "" || text == false) 
				{
					this.projectObject.setText(line, text);
					return;
				}
				
				if (!text)
					return;
					
				this.projectObject.setText(line, text);
			}

			if (project_type == CANDLE_BOX)
			{
				var curr_text = document.getElementById("candle_text_box_"+line).value;
				var text = prompt("Please enter the text for line " + line, curr_text);
		
				if (text == "" || text == false) 
				{
					CandleBox.setText(line, text);
					return;
				}
				
				if (!text)
					return;
					
				CandleBox.setText(line, text);
			}

			if (project_type == GIFT_TAGS)
			{
				var curr_text = document.getElementById("gifttag_text_box_"+line).value;
				var text = prompt("Please enter the text for line " + line, curr_text);
		
				if (text == "" || text == false) 
				{
					GiftTag.setText(line, text);
					return;
				}
				
				if (!text)
					return;
					
				GiftTag.setText(line, text);
			}
			
			if (project_type == BUTTON)
			{
				var curr_text = document.getElementById("button_text_box_"+line).value;
				var text = prompt("Please enter the text for line " + line, curr_text);
		
				if (text == "" || text == false) 
				{
					Button.setText(line, text);
					return;
				}
				
				if (!text)
					return;
					
				Button.setText(line, text);
			}			
			
		},
		
		closeWizard : function()
		{
			currentDialog.hide();
			currentDialog = null;
		},

		
		nextState :  function()
		{
			switch(state)
			{
				case 'START_WIZARD':
				{
					if (currentDialog)
						currentDialog.hide();
						
					this.showWelcome();
					break;
				}
				case 'DO_PASSWORD':
				{
					if (currentDialog)
						currentDialog.hide();
						
					this.showPassword();
					break;
				}
				case 'DO_NEW_PASSWORD':
				{
					if (currentDialog)
						currentDialog.hide();
						
					this.showNewPassword();
					break;
				}
				case 'CLOSE_DIALOG':
				{
					this.closeWizard();
					break;
				}
				case 'FILE_UPLOAD':
				{
					if (currentDialog.dialog_id != 'FILE_UPLOAD')
					{
						currentDialog.hide();
						this.showFileUpload();
					}
					break;
				}
				case 'PHOTO_CUTTER':
				{
					if (currentDialog.dialog_id != 'PHOTO_CUTTER')
					{
						currentDialog.hide();
						this.showPhotoCutter();
					}
					break;
				}
				case 'PHOTO_CANDLE':
				{
					if (currentDialog.dialog_id != 'PHOTO_CANDLE')
					{
						currentDialog.hide();
						this.showCandleBox();
					}
					break;
				}
				case 'PHOTO_TAGS':
				{
					if (currentDialog.dialog_id != 'PHOTO_TAGS')
					{
						currentDialog.hide();
						this.showGiftTags();
					}
					break;
				}
				case 'BUTTON':
				{
					if (currentDialog.dialog_id != 'BUTTON')
					{
						currentDialog.hide();
						this.showButtons();
					}
					break;
				}				
				case 'PRINT_PDF':
				{
					if (currentDialog.dialog_id != 'PRINT_PDF')
					{
						currentDialog.hide();
						this.showPrintPDF();
					}
					break;
				}
				case 'PRINT_HELP':
				{
					if (currentDialog.dialog_id != 'PRINT_HELP')
					{
						currentDialog.hide();
						this.showPrintHelp();
					}
					break;
				}
				case 'NO_CHANGE':
				{
					break;
				}
				
			}
		},
		
    	checkEmail : function(emailStr)
    	{
			/* The following pattern is used to check if the entered e-mail address
			   fits the user@domain format.  It also is used to separate the username
			   from the domain. */
			var emailPat=/^(.+)@(.+)$/
			/* The following string represents the pattern for matching all special
			   characters.  We don't want to allow special characters in the address. 
			   These characters include ( ) < > @ , ; : \ " . [ ]    */
			var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			/* The following string represents the range of characters allowed in a 
			   username or domainname.  It really states which chars aren't allowed. */
			var validChars="\[^\\s" + specialChars + "\]"
			/* The following pattern applies if the "user" is a quoted string (in
			   which case, there are no rules about which characters are allowed
			   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
			   is a legal e-mail address. */
			var quotedUser="(\"[^\"]*\")"
			/* The following pattern applies for domains that are IP addresses,
			   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
			   e-mail address. NOTE: The square brackets are required. */
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			/* The following string represents an atom (basically a series of
			   non-special characters.) */
			var atom=validChars + '+'
			/* The following string represents one word in the typical username.
			   For example, in john.doe@somewhere.com, john and doe are words.
			   Basically, a word is either an atom or quoted string. */
			var word="(" + atom + "|" + quotedUser + ")"
			// The following pattern describes the structure of the user
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			/* The following pattern describes the structure of a normal symbolic
			   domain, as opposed to ipDomainPat, shown above. */
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
			
			
			/* Finally, let's start trying to figure out if the supplied address is
			   valid. */
			
			/* Begin with the coarse pattern to simply break up user@domain into
			   different pieces that are easy to analyze. */
			var matchArray=emailStr.match(emailPat)
			if (matchArray==null) {
			  /* Too many/few @'s or something; basically, this address doesn't
			     even fit the general mould of a valid e-mail address. */
				//alert("Email address seems incorrect (check @ and .'s)")
				return false
			}
			var user=matchArray[1]
			var domain=matchArray[2]
			
			// See if "user" is valid 
			if (user.match(userPat)==null) {
			    // user is not valid
			  //  alert("The username doesn't seem to be valid.")
			    return false
			}
			
			/* if the e-mail address is at an IP address (as opposed to a symbolic
			   host name) make sure the IP address is valid. */
			var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null) {
			    // this is an IP address
				  for (var i=1;i<=4;i++) {
				    if (IPArray[i]>255) {
				       // alert("Destination IP address is invalid!")
					return false
				    }
			    }
			    return true
			}
			
			// Domain is symbolic name
			var domainArray=domain.match(domainPat)
			if (domainArray==null) {
				//alert("The domain name doesn't seem to be valid.")
			    return false
			}
			
			/* domain name seems valid, but now make sure that it ends in a
			   three-letter word (like com, edu, gov) or a two-letter word,
			   representing country (uk, nl), and that there's a hostname preceding 
			   the domain or country. */
			
			/* Now we need to break up the domain to get a count of how many atoms
			   it consists of. */
			var atomPat=new RegExp(atom,"g")
			var domArr=domain.match(atomPat)
			var len=domArr.length
			if (domArr[domArr.length-1].length<2 || 
			    domArr[domArr.length-1].length>4) {
			   // the address must end in a two letter or three letter word.
			 //  alert("The address must end in a three-letter domain, or two letter country.")
			   return false
			}
			
			// Make sure there's a host name preceding the domain.
			if (len<2) {
			   var errStr="This address is missing a hostname!"
			 //  alert(errStr)
			   return false
			}
			
			// If we've gotten this far, everything's valid!
			return true;
    	},
    	
        getDialog : function()
        {
        	return dialog;
        }
    };
}();


YAHOO.ext.EventManager.onDocumentReady(BlockWizard.init, BlockWizard, true);

//if (print == 1)
//{
//	YAHOO.ext.EventManager.onDocumentReady(BlockWizard.startPrint, BlockWizard);
//}

