// JavaScript Document

var submit = false;

function add_lead() {
	var ents = new Array("wbw_name", "wbw_email", "wbw_country");
	var str = "";
	var i=0;
	for (i=0;i<=ents.length-1;i++) {
		str = str + "&" + ents[i] + "=" + (document.getElementById(ents[i]).value).replace(/&/, "And");
	}
	if(window.XMLHttpRequest){
		var xhr = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4) {
			if (xhr.status == 200) {
				//alert(xhr.responseText);
				// Submit the form when we get a reply back
				document.wbw_form.submit();
			}
		}
	}
	xhr.open("GET", 'save.php?SAVE=true'+str, true);
	xhr.send(null);
	
}


function checkform(al) {
	var error = false;
	
	if ((al) && (!submit)) { // Don't want to fire this until we've hit the submit button once
		return false;
	} else if ((!al)&& (!submit)) {
		submit = true;
	}
	
	// First up loop all the fields listed as required and check for some data (at least 5 char)
	var reqs = new Array("wbw_name", "wbw_email", "wbw_country");
	
	var i=0;
	for (i=0;i<=reqs.length-1;i++) {
		document.getElementById(reqs[i])
		if ((document.getElementById(reqs[i]).value).length < 2) {
			error = true;
			document.getElementById(reqs[i]+'_label').style.color = "#FFFFFF";
			document.getElementById(reqs[i]+'_label').style.backgroundColor = "#CC0000";		
		} else { //We need to set it back to black in case it's the second time around
			document.getElementById(reqs[i]+'_label').style.color = "#000000";
			document.getElementById(reqs[i]+'_label').style.backgroundColor = "#FFFFFF";
		}	
	}
	
	// Next we see if the email address has all the bits it needs to be real
	if (!echeck(document.getElementById('wbw_email').value)) {
		error = true;	
		document.getElementById('wbw_email_label').style.color = "#FFFFFF";		
		document.getElementById('wbw_email_label').style.backgroundColor = "#CC0000";		
	} else {
		document.getElementById('wbw_email_label').style.backgroundColor = "#FFFFFF";		
		document.getElementById('wbw_email_label').style.color = "#000000";		
	}
	
	// has the user selected an event?
	// Check for errors and go from there
	if (error) {
		if (!al) {
			alert('I\m Sorry, but we\'re missing some information from you.\nPlease complete the Required Fields and try again');
		}
		return false;
	} else if (!al) {
		add_lead();
		setTimeout('document.wbw_form.submit()', 1500);
		//document.form1.submit();
		//return true;
	}
}


function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	if (str.indexOf(at)==-1){ return false	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false }
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false }
	if (str.indexOf(at,(lat+1))!=-1){ return false }
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false }
	if (str.indexOf(dot,(lat+2))==-1){ return false }
	if (str.indexOf(" ")!=-1){ return false  }

	return true					
}


function refer_friends() {
	var eee = false;
	
	var name = document.getElementById('fromname').value;
	var email = document.getElementById('fromemail').value;	
	
	if ( (name == "") || (!echeck(email)) ) {
		eee = true;
	}
	
	if (!eee) {
		var form = document.forms['wbw_form'];
		form.submit();
	} else {
		alert('Please enter a valid Name and Email Address');
	}
}
function moreinfo() {
	var form = document.forms['wbw_form'];
	form.action = "?thankyou&page=moreinfo";
	form.submit();

}

function previewemail() {
	document.getElementById('preview').style.display = document.getElementById('preview').style.display ? '' : 'none';
}

function swapform(bob) {
/*	document.getElementById('alreadyregistered').style.display = document.getElementById('alreadyregistered').style.display ? '' : 'none';
	document.getElementById('freetickets').style.display = document.getElementById('freetickets').style.display ? '' : 'none';*/
	document.getElementById('alreadyregistered').style.display = bob ? '' : 'none';
	document.getElementById('freetickets').style.display = bob ? 'none' : '';
	
}
function register(){
	var error = false;
	var username = document.getElementById('user_login');
	var form = document.getElementById('registerform');
	var e2  = document.getElementById('user_email_confirm');
	var e1  = document.getElementById('user_email');
	
	if (username.length < 3) {
		error = true;
		alert('Please enter a Username');
		return false;		
	}

	if(window.XMLHttpRequest){
		var xhr = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	
	
	if (!echeck(e1.value)) {
		error = true;
		alert('Please enter a valid email address');
		return false;
	}
	
	if (e1.value != e2.value) {
		error = true;
		alert('Please confirm your email address');
		return false;		
	}
	
	if(document.getElementById('ym_subscription')) {
		//
	} else if(getCheckedValue(document.forms['registerform'].elements['ym_subscription']).length < 3) {
		error = true;
		alert('Please Select a Valid Membership');	
		return false;		
	}

	xhr.open("GET", 'login.php?username='+username.value+'&email='+e1.value, true);
	xhr.send(null);		
	if (!error) {
		xhr.onreadystatechange = function() {
			if(xhr.readyState == 4) {
				if (xhr.status == 200) {
					if (xhr.responseText == '2') {
						alert('This username is invalid.  Please enter a valid username.');
						error = true;
						return false;
					} else if (xhr.responseText == '3') {
						alert('This username is already registered, please choose another one.');
						error = true;
						return false;
					} else if (xhr.responseText == '4') {
						alert('Please type your e-mail address.');
						error = true;
						return false;
					}else if (xhr.responseText == '5') {
						alert('The email address isn&#8217;t correct.');
						error = true;
						return false;
					} else if (xhr.responseText == '6') {
						alert('This email is already registered, please choose another one.');
						error = true;
						return false;
					} else {
						form.submit();
					}
				}
			}
		}
		
	}
	return true;
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}




/**
 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){_16.push(key+"="+_18[key]);}
return _16;},getSWFHTML:function(){var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){
this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";
}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();return true;
}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(){
var _23=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}
catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
return _23;};
deconcept.PlayerVersion=function(_27){
this.major=_27[0]!=null?parseInt(_27[0]):0;
this.minor=_27[1]!=null?parseInt(_27[1]):0;
this.rev=_27[2]!=null?parseInt(_27[2]):0;
};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){
return false;
}return true;};
deconcept.util={getRequestParameter:function(_29){
var q=document.location.search||document.location.hash;
if(q){var _2b=q.substring(1).split("&");
for(var i=0;i<_2b.length;i++){
if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){
return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
return "";}};
deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
var _2d=document.getElementsByTagName("OBJECT");
for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){
if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};
deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};
__flash_savedUnloadHandler=function(){};
if(typeof window.onunload=="function"){
var _30=window.onunload;
window.onunload=function(){
deconcept.SWFObjectUtil.cleanupSWFs();_30();};
}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};
if(typeof window.onbeforeunload=="function"){
var oldBeforeUnload=window.onbeforeunload;
window.onbeforeunload=function(){
deconcept.SWFObjectUtil.prepUnload();
oldBeforeUnload();};
}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
if(Array.prototype.push==null){
Array.prototype.push=function(_31){
this[this.length]=_31;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject;
var SWFObject=deconcept.SWFObject;

var score2 = new Array();
var score3 = new Array();
var score4 = new Array();
var score5 = new Array();
var qs = new Array('How often do you feel really happy with your current life?','How often are you really pleased with your current diet, exercise and general health?','How often do you feel totally comfortable with your emotions?', 'How often do you feel at peace with the world, your faith or lack of it, and your purpose?', 'How often do you feel you have all the know-how you need for the best life you can imagine for you?', 'About how often do you feel really comfortable about your finances?','How often do you feel you are devoting your life to what you see as your top priorities?', 'How often do you feel all aspects of your life are in total harmony?', 'How often do you feel your key relationships are fantastic?', 'How often do you feel so happy with your life that you just want to leave it as it is?')

function checkradios() {
	var str = "";
	var i=1;
	var t=0;
	for (i=1;i<=10;i++) {
		switch (getCheckedValue(document.forms['quickcheckup'].elements['qc_q'+i])) 
		{
			case '1':
			t = t + 2;
			score2[score2.length] = i;
			break;
			case '2':
			t = t + 4;
			score2[score2.length] = i;
			break;
			case '3':
			t = t + 6;
			score3[score3.length] = i;
			break;
			case '4':
			t = t + 8;
			score4[score4.length] = i;
			break;
			case '5':
			t = t + 10;
			score5[score5.length] = i;
			break;
			default:
		}
	}	
	return t;
}
function showanswers() {
	document.getElementById('more').style.display = '';
	if (score2.length > 0) {
		document.getElementById('score2').style.display = '';
		document.getElementById('score2_results').innerHTML = getresults(score2);
	}
	if (score3.length > 0) {
		document.getElementById('score3').style.display = '';
		document.getElementById('score3_results').innerHTML = getresults(score3);
	}
	if (score4.length > 0) {
		document.getElementById('score4').style.display = '';
		document.getElementById('score4_results').innerHTML = getresults(score4);
	}
	if (score5.length > 0) {
		document.getElementById('score5').style.display = '';
		document.getElementById('score5_results').innerHTML = getresults(score5);
	}	
}

function getresults(array){
	var ret = '<ul class="qc_results">';
	for (i=0;i<=array.length-1;i++) {
		ret = ret + "<li>"+qs[i]+"</li>";
	}
	ret = ret + '</ul>';
	return ret;
}


function finish() {
	var score = checkradios();
	var urgent = document.getElementById('urgent');
	var good = document.getElementById('good');
	var problem = document.getElementById('problem');
	var wrap = document.getElementById('qc_wrap');
	urgent.style.display = 'none';
	good.style.display = 'none';
	problem.style.display = 'none';
	wrap.style.display = 'none';
	
	if (document.getElementById('tytext')) {
		document.getElementById('tytext').style.display = 'none';
	}
	
	if (score <= 40) {
		urgent.style.display = '';
	} else if (score >= 65)	{
		good.style.display = '';
	} else {
		problem.style.display = '';		
	}
	showanswers();
	window.location.href = "#top";
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}