
var wiz1, wiz2, wiz3, wiz4, wiz5,wiz6 = '';

var firstRun = true;

var wizActive = 1;

var status='';

function wizard() {

	$('.startWizard').click(function() { startWizard(); return false; });
	
}
function startWizard() {
	document.getElementById('iframe').style.display='';
	$('.body').append('<div id="wizWrapper" style="z-index:1;"><a id="shadow" href="#"></a><div id="wizard"><a href="#" class="close">X</a><div id="images"> </div> <h1>What game(s) do you currenty play?</h1><h2>Question <span>#1</span></h2><div id="wizContent"></div><div id="wizAlert" class="p1Line p1pb"></div></div></div>');
	
	$('#shadow').hide().height($('body').height()).css('opacity', 0.0).show().animate({opacity: 0.9}, 'normal', openWizard);
	
}
function openWizard() {
	$('#wizard').hide().css('left', (($('body').width()/2)-250)).css('top', getPageScroll()[1]+20).animate({ width: '506px', height: '500px'}, 1000, wizPage1);
	$('#wizard .close').click(closeWizard);
	$('#shadow').click(closeWizard);
}
function reloadNav() {
	$('.wizNav').remove();
	
	$('#wizard').append('<div class="wizNav"><a href="#" class="wizPrev">&lt;&lt; Previous</a><span>  </span><a href="#" class="wizNext">Next &gt;&gt;</a></div>');
}
function closeWizard() {
	//$(this).blur();
	document.getElementById('iframe').style.display='none';
	$('#wizWrapper').fadeOut('normal', function() { $(this).remove(); });
	firstRun = true;
	wiz1 = wiz2 = wiz3 = wiz4 = wiz5 = null;
	return false;
}
function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}
function wizNext1() {  
		
		$(this).blur();
		if($('#wizard input:checked').get().length==0) {
			wizAlert('Please answer the question.');
			return false;
		} else {
			wiz1 = $($('#wizard input:checked').get(0)).attr('value');
			wizPage2(); 
			return false;
		}
}
function wizPage1() {
	reloadNav();
	var wiz = $('#wizard');
	var content = $('#wizContent');
	$('h2 span', wiz).text('#1');
	$('h1', wiz).text('What game(s) do you currently play?');
	
	$('#wizard .page').remove();
	
	content.append('<div class="p1Line p1fl"><input type="radio" value="FL" name="type" id="p1fl"' + (wiz1=='FL'?' checked="checked"':'') + ' /><label for="p1fl">Florida LOTTO</label></div>');
	content.append('<div class="p1Line p1pb"><input type="radio" value="PB" name="type" id="p1pb"' + (wiz1=='PB'?' checked="checked"':'') + ' /><label for="p1pb">Powerball</label></div>');
	content.append('<div class="p1Line p1both"><input type="radio" value="BOTH" name="type" id="p1both"' + (wiz1=='BOTH'?' checked="checked"':'') + ' /><label for="p1both">BOTH</label></div>');
	content.wrapInner('<div class="page"></div>');
	$('.wizNav span').hide();
	$('.wizNav .wizPrev').hide();
	$('.wizNav .wizNext').click(wizNext1);
		 
	wiz.animate({height: 250+300+'px'});
	
	$('.wizNav').fadeIn();
	firstRun = false;
	
}

function wizPage2() {
	reloadNav();
	var wiz = $('#wizard');
	var content = $('#wizContent');
	$('h2 span', wiz).text('#2');
	$('h1', wiz).text('How many times a month do you currently play?');
	
	$('#wizard .page').remove();
	content.append('<div class="p1Line p1fl"><input type="radio" value="0" name="month" id="p20"' + (wiz2=='0'?' checked="checked"':'') + ' /><label for="p21">0</label></div>'); 
	content.append('<div class="p1Line p1pb"><input type="radio" value="1" name="month" id="p21"' + (wiz2=='1'?' checked="checked"':'') + ' /><label for="p21">1</label></div>');
	content.append('<div class="p1Line p1fl"><input type="radio" value="2-4" name="month" id="p22"' + (wiz2=='2-4'?' checked="checked"':'') + ' /><label for="p22">2-4</label></div>');
	content.append('<div class="p1Line p1pb "><input type="radio" value="5+" name="month" id="p24"' + (wiz2=='5+'?' checked="checked"':'') + ' /><label for="p24">5+</label></div>');
	content.wrapInner('<div class="page"></div>');
	$('.wizNav span').show();
	$('.wizNav .wizPrev').show().click(function() { wizPage1(); return false; });
	$('.wizNav .wizNext').click(function() {}).click(function() { 
		 
		$(this).blur();
		
		if($('#wizard input:checked').get().length==0) {
			wizAlert('Please answer the question.');
			return false;
		} else {
			wiz2 = $($('#wizard input:checked').get(0)).attr('value');
		}
		wizPage3(); return false; 
	});
	wiz.animate({height: 250+300+'px'});
	firstRun = false;
	
}

function wizPage3() {
	reloadNav();
	var wiz = $('#wizard');
	var content = $('#wizContent');
	$('h2 span', wiz).text('#3');
	$('h1', wiz).text('What amount in the course of 1 month do you spend on the lottery?');
	
	$('#wizard .page').remove();
	
	content.append('<div class="p1Line p1fl"><input type="radio" value="20" name="amount" id="p21"' + (wiz3=='20'?' checked="checked"':'') + ' /><label for="p21">$0-$20</label></div>');
	content.append('<div class="p1Line p1pb"><input type="radio" value="40" name="amount" id="p22"' + (wiz3=='40'?' checked="checked"':'') + ' /><label for="p22">$21-$40</label></div>');
	content.append('<div class="p1Line p1both"><input type="radio" value="60" name="amount" id="p23"' + (wiz3=='60'?' checked="checked"':'') + ' /><label for="p24">$41-$60</label></div>');
	content.append('<div class="p1Line p1fl"><input type="radio" value="80" name="amount" id="p24"' + (wiz3=='80'?' checked="checked"':'') + ' /><label for="p24">$61-$80</label></div>');
    content.append('<div class="p1Line p1pb"><input type="radio" value="120" name="amount" id="p25"' + (wiz3=='120'?' checked="checked"':'') + ' /><label for="p24">$81-$120</label></div>');
    
    content.wrapInner('<div class="page"></div>');
	$('.wizNav .wizPrev').click(function() { wizPage2(); return false; });
	$('.wizNav .wizNext').click(function() {
	
		 
		$(this).blur();
		if($('#wizard input:checked').get().length==0) {
			wizAlert('Please answer the question.');
			return false;
		} else {
			wiz3 = $($('#wizard input:checked').get(0)).attr('value');
		}
		 wizPage4();
         //registerPage();loginPage();
         return false; 
		
	});
	wiz.animate({height: 250+300+'px'});
	firstRun = false;
	
}
function wizPage4() {
	reloadNav();
	var wiz = $('#wizard');
	var content = $('#wizContent');
	$('h2 span', wiz).text('#4');
	$('h1', wiz).text('Does your spending go up when the Jackpot is high?');
	
	$('#wizard .page').remove();
	content.append('<div class="p1Line p1fl"><input type="radio" value="yes" name="high" id="p21"' + (wiz4=='yes'?' checked="checked"':'') + ' /><label for="p22">Yes</label></div>');
    content.append('<div class="p1Line p1pb"><input type="radio" value="no" name="high" id="p22"' + (wiz4=='no'?' checked="checked"':'') + ' /><label for="p21">No</label></div>');
	content.wrapInner('<div class="page"></div>');
	$('.wizNav span').show();
	$('.wizNav .wizPrev').show().click(function() { wizPage3(); return false; });
	$('.wizNav .wizNext').show().click(function() { 
		 
		$(this).blur();
		if($('#wizard input:checked').get().length==0) {
			wizAlert('Please answer the question.');
			return false;
		} else {
			wiz4 = $($('#wizard input:checked').get(0)).attr('value');
		}
	wizPage5(); return false; });
	wiz.animate({height: 250+300+'px'});
	firstRun = false;
	
}
function wizPage5() {
	reloadNav();
	var wiz = $('#wizard');
	var content = $('#wizContent');
	$('h2 span', wiz).text('#5');
	$('h1', wiz).text('How long have you been playing the Lottery or Powerball?');
	
	$('#wizard .page').remove();
	
	content.append('<div class="p1Line p1fl"><input type="radio" value="more" name="less" id="p21" /><label for="p21">1-5 years</label></div>');
	content.append('<div class="p1Line p1pb"><input type="radio" value="less" name="less" id="p22" /><label for="p22">6-10 years</label></div>');
	content.append('<div class="p1Line p1fl"><input type="radio" value="more" name="less" id="p23" /><label for="p23">11-20 years</label></div>');
    content.append('<div class="p1Line p1pb"><input type="radio" value="less" name="less" id="p24" /><label for="p24">21 +</label></div>');
    content.wrapInner('<div class="page"></div>');
	$('.wizNav span').show();
	$('.wizNav .wizPrev').show().click(function() { wizPage4(); return false; });
        $('.wizNav .wizNext').show().click(function() { 
         
        $(this).blur();
        if($('#wizard input:checked').get().length==0) {
            wizAlert('Please answer the question.');
            return false;
        } else {
            wiz5 = $($('#wizard input:checked').get(0)).attr('value');
        }
     (isLogin)? isloginSubmit() : wizPage6(); return false; });
	//$('.wizNav .wizNext').html('<strong>Finish!</strong>').click(finishWizard);
	wiz.animate({height: 250+300+'px'});
	firstRun = false;
	
}
function wizPage6() {
    reloadNav();
    var wiz = $('#wizard');
    var content = $('#wizContent');
    $('h2 span', wiz).text('#6');
    $('h1', wiz).text('Are you currently registered at Lottofam.com?');
    $('#wizard .page').remove();
    content.append('<div class="p1Line p1fl"><input type="radio" value="yes" name="status" id="p21" /><label for="p21">Yes</label></div>');
    content.append('<div class="p1Line p1pb"><input type="radio" value="no" name="status" id="p22" /><label for="p22">No</label></div>');
    content.wrapInner('<div class="page"></div>');
    $('.wizNav span').show();
    $('.wizNav .wizPrev').show().click(function() { wizPage5(); return false; });
    $('.wizNav .wizNext').show().click(function() { 
         
        $(this).blur();
        if($('#wizard input:checked').get().length==0) {
            wizAlert('Please answer the question.');
            return false;
        } else {
            wiz6 = $($('#wizard input:checked').get(0)).attr('value');
        }
     (wiz6=='yes')?loginPage():registerPage();return false; });
    wiz.animate({height: 250+300+'px'});
    firstRun = false;
    
}

function loginPage(){
    status='login';
    var wiz = $('#wizard');
    $('#images').hide();
    var content = $('#wizContent');
    $('h2').hide();
    $('h1').css( 'padding-top', '140px' );
    $('h1').css( 'background-image', 'none' );
    $('h1', wiz).text('Please login to your LottoFam Account to access your recommended pools');
    $('#wizard .page').remove();
    content.append('<form method="post" name="aform" id="aform" action="'+loginUrl+'" onSubmit="return finishWizard(this)" ><input type="hidden" name="amount" value="'+wiz3+'"/><input type="hidden" name="play" value="'+wiz1+'"/> <div class="p1Line p1fl" style="padding-left:110px;height:23px;"><div class="txtName">Email </div><div><input type="text" name="mail" id="mail" style="width:200px;" /></div></div><div class="p1Line p1pb" style="padding-left:110px;height:23px;" ><div class="txtName">Password  </div><div> <input type="password" name="pass" id="pass" style="width:200px;" /></div></div><input value="login" name="next" type="hidden"/><input type="hidden" name="mod" value="user" /><input type="hidden" name="action" value="login" />  <input type="hidden" name="next" value="log in" /><div class="p1Line p1pb" style="padding-left:110px;height:23px;" ><div class="txtName">&nbsp;</div><div><input type="submit" name="submit" class="mysubmit"  value="Login" /></div></div></form>');
	content.wrapInner('<div class="page"></div>');
    $('.wizNav').hide();
    $('.wizNav').css( 'bottom', '326px' );    
    $('.wizNav span').show();
    $('.wizNav .wizPrev').hide();
    //$('.mysubmit').click(finishWizard); 
    wiz.animate({height: 250+300+'px'});
    firstRun = false;
}

function registerPage(){
    status='register';
    var wiz = $('#wizard');
    $('#images').hide();
    var content = $('#wizContent');
    $('h2').hide();
    $('h1').css( 'padding-top', '40px' );
    $('h1').css( 'background-image', 'none' ); 
    $('h1', wiz).text('Please register for a LottoFam Account to access your Recommended Pools');
    $('#wizard .page').remove();
    content.append('<div><form method="post" name="aform" id="aform" action="'+registerUrl+'" onSubmit="return finishWizard(this)" ><input type="hidden" name="amount" value="'+wiz3+'"/><input type="hidden" name="play" value="'+wiz1+'"/> <input type="hidden" name="mod" value="user" /><input type="hidden" name="action" value="register" /><div class="p1Line p1fl" style="padding-left:20px;height:23px;"><div class="txtName">Email </div><div class="txtfield"><input type="text" name="mail" id="mail" style="width:200px;" /></div></div><div class="p1Line p1pb" style="padding-left:20px;height:23px;" ><div class="txtName">First name  </div><div class="txtfield"> <input type="text" name="firstname" id="firstname" style="width:200px;" /></div></div><div class="p1Line p1fl" style="padding-left:20px;height:23px;" ><div class="txtName">Last name  </div><div class="txtfield"> <input type="text" name="surname" id="surname" style="width:200px;" /></div></div><div class="p1Line p1pb" style="padding-left:20px;height:23px;" ><div class="txtName">Password  </div><div class="txtfield"> <input type="password" name="password" id="password" style="width:200px;" /></div></div><div class="p1Line p1fl" style="padding-left:20px;height:23px;" ><div class="txtName">Re-Password  </div><div class="txtfield"> <input type="password" name="repassword" id="repassword" style="width:200px;" /></div></div> <div class="p1Line p1pb" style="padding-left:20px;height:23px;" ><div class="txtName">Birth date  </div><div class="txtfield"><input type="text" name="birthm" id="birthm" style="width:20px;" maxlength="2" /><input type="text" name="birthd" id="birthd" style="width:20px;" maxlength="2" /><input type="text" name="birthy" id="birthy" style="width:40px;" maxlength="4" /></div></div><div class="p1Line p1fl" style="padding-left:20px;height:23px;" ><div class="txtName">Phone  </div><div class="txtfield"> <input type="text" name="phone" id="phone" style="width:200px;" /></div></div><div class="p1Line p1pb" style="padding-left:20px;height:23px;" ><div class="txtName">Address  </div><div class="txtfield" ><input type="text" name="address" id="address" style="width:200px;" /></div></div><div class="p1Line p1fl" style="padding-left:20px;height:23px;" ><div class="txtName">City  </div><div class="txtfield" ><input type="text" name="city" id="city" style="width:200px;" /></div></div><div class="p1Line p1pb" style="padding-left:20px;height:23px;" ><div class="txtName">State  </div><div class="txtfield" ><select name="state" class="bhide" style=" width:210px;"><option value="AL">Alabama</option><option value="AK">Alaska</option><option value="AR">Arkansas</option><option value="AZ">Arizona</option><option value="CA">California</option><option value="CO">Colorado</option><option value="CT">Connecticut</option><option value="DE">Delaware</option><option value="FL" selected>Florida</option><option value="GA">Georgia</option><option value="HI">Hawaii</option><option value="ID">Idaho</option><option value="IL">Illinois</option><option value="IN">Indiana</option><option value="IA">Iowa</option><option value="KS">Kansas</option><option value="KY">Kentucky</option><option value="LA">Louisiana</option><option value="ME">Maine</option><option value="MD">Maryland</option><option value="MA">Massachusetts</option><option value="MI">Michigan</option><option value="MN">Minnesota</option><option value="MS">MS</option><option value="MO">Missouri</option><option value="MT">Montana</option><option value="NE">Nebraska</option><option value="NV">Nevada</option><option value="NH">New Hampshire</option>	<option value="NJ">New Jersey</option><option value="NM">New Mexico</option><option value="NY">New York</option><option value="NC">North Carolina</option><option value="ND">North Dakota</option><option value="OH">Ohio</option><option value="OK">Oklahoma</option><option value="OR">Oregon</option><option value="PA">Pennsylvania</option><option value="RI">Rhode Island and Providence Plantations</option><option value="SC">South Carolina</option><option value="SD">SD</option><option value="TN">Tennessee</option><option value="TX">Texas</option><option value="UT">Utah</option><option value="VT">Vermont</option><option value="VA">Virginia</option><option value="WA">Washington</option><option value="WV">West Virginia</option><option value="WI">Wisconsin</option><option value="WY">Wyoming</option></select></div></div><div class="p1Line p1fl" style="padding-left:20px;height:23px;" ><div class="txtName">Zip Code</div><div class="txtfield"> <input type="text" name="zip" id="zip" style="width:200px;" /></div></div><div class="p1Line p1fl" style="padding-left:20px;" ><div class="txtName" style="width:590px;"> <input name="agree" type="radio" value="yes"/> I AGREE to allow LottoFam, LLC to purchase Florida Lottery and/or Powerball tickets on my behalf to share with other members of the LottoFam Player\'s Club. I have read the <a target="_blank" href="http://lottofam.com/mod/art/action/show/id/terms.html">LEGAL</a> section of the LottoFam Player\'s Club website and agree to the terms and conditions stated therein. </div></div><div class="p1Line p1pb" style="padding-left:20px;" ><div class="txtName">&nbsp;</div><div class="txtfield"><input type="submit" name="next" class="mysubmit"  value="Register Now!" /></div></div></form></div>');
    content.wrapInner('<div class="page"></div>');
    $('.wizNav').hide();
    wiz.animate({height: 250+300+'px'});
    firstRun = false;
}
 
function isloginSubmit(){
	var dis = document.createElement('div')
	dis.style.display='none';
	var fom = document.createElement('form');
	var in1 = document.createElement('input');
	var in2 = document.createElement('input');		
	in1.type = in2.type = 'hidden';
	in1.name = 'amount' ;
	in2.name = 'play';
	in2.value = wiz1;
	in1.value = wiz3 ;
	fom.action = isLogin;
	fom.method = 'GET';
//	fom.enctype = 'application/x-www-form-urlencoded'
	fom.appendChild(in1) ;
	fom.appendChild(in2);
	dis.appendChild(fom)
	document.body.appendChild(dis);
    closeWizard();                        	
	fom.submit();	
}

function finishWizard(frm) {
        var str='';
        var reason = "";
        if(status == 'register'){
            reason += validateEmail(frm.mail); 
            reason += isEmpty(frm.firstname,"First Name too Short.\n"); 
            reason += isEmpty(frm.surname,"Last Name too Short.\n");
            reason += isPass(frm.password,frm.repassword);
            str+= isEmpty(frm.birthm,"yes");
            str+= isEmpty(frm.birthd,"yes");
            str+= isEmpty(frm.birthy,"yes"); 
            if(str){
              reason +="Enter your DOB.\n";  
            }
            reason += validatePhone(frm.phone);
			reason += isEmpty(frm.address,"Address too Short.\n");
			reason += isEmpty(frm.city,"Enter your city.\n"); 
			reason += isEmpty(frm.zip,"Enter your zip code.\n"); 
            reason += radio(frm.agree,"Click AGREE to Complete Registration.\n");  
        }else if(status == 'login'){
           reason += validateEmail(frm.mail); 
           reason += isEmpty(frm.pass,"Enter your password.\n");  
        }
        if (reason != "") {
         alert("Some fields need correction:\n" + reason);
         return false;
        }
	    closeWizard();						
        return true;		
}

function wizAlert(text) {
	$('#wizAlert').text(text).fadeIn('slow', function() { $(this).fadeOut('slow'); });
}
$(wizard);

function trim(s){
  return s.replace(/^\s+|\s+$/, '');
}

function radio(fld,message){
     var error="";  
     if(fld.checked != true){
     error = message;
     }
     return error;
}

function isEmpty(fld,message){
     var error="";
     var name = trim(fld.value);
     if(name==''){
         //fld.style.background = 'Yellow';
          error = message+"";
     }else{
         fld.style.background = 'White';
     }
     return error;
}

function isPass(pass,repass){
     var error="";
     var password = trim(pass.value);
     var repassword = trim(repass.value);
     if(password=='')  {
        // pass.style.background = 'Yellow';
          error = "Please enter password.\n";
     }else if(password.length<=4){
          //  pass.style.background = 'Yellow';
          error = "Password atleast 5 char.\n";
     }
     else if(repassword!=password){
          // pass.style.background = 'Yellow';
           error = "Password mismatch.\n";
     }
     return error;
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    if (fld.value == "") {
       // fld.style.background = 'Yellow';
        error = "Please enter E-email.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
       // fld.style.background = 'Yellow';
        error = "Please enter E-email.\n";
    } else if (fld.value.match(illegalChars)) {
       // fld.style.background = 'Yellow';
        error = "Invalid E-mail.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validatePhone(fld) {
   var error = "";
   var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    
   if (fld.value == "") {
        error = "Phone too Short.\n";
       // fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "Phone too Short.\n";
        //fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "";
       // fld.style.background = 'Yellow';
    }
    return error;
}
