/*
|	Core Manager
|
|	Namespace, utility and global variables creation
|	Requires: None

|	Change Log
	Date		Line (approx)	Description													Author
	-----------	---------------	-----------------------------------------------------------	------------------
	23/07/08	Line 252		Added support for hyphenated email addresses				Eris Ristemena
	24/07/08	Line 232		Added Trim prototype										James Haley
	25/07/08	Line 239		Added replaceNewLine,stripBreaks,stripTags,replaceBreaks	James Haley
	04/08/08	Line 85			Updated copy												Vincent Roby
	04/08/08	Line 89			change vCountry to nCountry									Eris Ristemena
*/

		//Create Namespace
		var hp = {}
		
		//Global vars
		var oXML,vCompany,vDomainList,vEmailMsg,vFormRequired,vFormPassRequired,vRegFields,vCurrentPage='oRegister',bResetPassword=false;
		var bEmailError=bPasswordError=bConfirmPasswordError=bPicError=false;
		var bReadyToSubmit=false,_bLI_Auth;
		//Utilities
		{hp.utils=function(){
			return {
				get:function(){
					var oEA=new Array();
					for (var i=0;i<arguments.length;i++) {
						var oE = arguments[i];
						//alert(oE);
						(typeof oE=='string')?oE=document.getElementById(oE):null;
						if(arguments.length==1) return oE;
						oEA.push(oE);
					}
					return oEA;
				},
				rnd:function(){return Math.floor(Math.random()*1000000000);},
				//geo:function(){return navigator.geolocation||false;},
				addEvent:function(obj,type,fn){
					if (obj.addEventListener){obj.addEventListener(type,fn,false);}else if(obj.attachEvent){obj["e"+type+fn]=fn;obj[type+fn]=function(){obj["e"+type+fn](window.event);};obj.attachEvent("on"+type,obj[type+fn]);};
				},
				removeEvent:function(obj,type,fn){
					if (obj.removeEventListener){obj.removeEventListener(type,fn,false);}else if(obj.detachEvent){obj.detachEvent("on"+type,obj[type+fn]);obj[type+fn]=null;obj["e"+type+fn]=null;}
				},
				simpledate:function(nD){
					var oDate=new Date(nD),oNow=new Date(),nDiff=0,vDate="";
					oDate=(Date.UTC(oDate.getFullYear(),oDate.getMonth(),oDate.getDate(),0,0,0))/86400000;
					oNow=(Date.UTC(oNow.getFullYear(),oNow.getMonth(),oNow.getDate(),0,0,0))/86400000;
					nDiff=(oNow-oDate);
					if(nDiff<1){vDate="Today"}
					else if(nDiff==1){vDate="Yesterday"}
					else if(nDiff<7){vDate=nDiff+" days ago"}
					else if(nDiff<14){vDate="1 week ago"}
					else if(nDiff<31){vDate=Math.floor(nDiff/7)+" weeks ago"}
					else if(nDiff<62){vDate="1 month ago"}
					else if(nDiff<365){vDate=Math.floor(nDiff/31)+" months ago"}
					else if(nDiff<730){vDate="1 year ago"}
					else{vDate=Math.floor(nDiff/365)+" years ago"};
				
					return vDate;
				},
				attach:function(){
					//Document filter
					hp.utils.get('oDocCategories')?hp.utils.addEvent(hp.utils.get('oDocCategories'),'change',function(){hp.content.filterdocs(this)}):null;
					//login buttons
					if (hp.utils.get('oReg_o')) {
						//show registration/login form
						hp.utils.addEvent(hp.utils.get('oMainLoginRegisterLink1'),'click',function(){hp.content.toggle('oReg_o');hp.content.toggle('oReg_u');hp.utils.maximise('oReg_u');});
						hp.utils.addEvent(hp.utils.get('oMainLoginRegisterLink2'),'click',function(){hp.content.toggle('oReg_o');hp.content.toggle('oReg_u');hp.utils.maximise('oReg_u');});
						hp.utils.addEvent(hp.utils.get('oMainLoginRegisterLink3'),'click',function(){hp.content.toggle('oReg_o');hp.content.toggle('oReg_u');hp.utils.maximise('oReg_u');});
						hp.utils.addEvent(hp.utils.get('oMainLoginRegisterLink4'),'click',function(){hp.content.toggle('oReg_o');hp.content.toggle('oReg_u');hp.utils.maximise('oReg_u');});
						
						//hp.utils.addEvent(window,'resize',function(){hp.utils.maximise('oReg_u');});
						//close
						hp.utils.addEvent(hp.utils.get('oRegClose'),'click',function(){hp.content.toggle('oReg_o');hp.content.toggle('oReg_u');if(hp.utils.get('oLoginForm')){hp.content.swap(vCurrentPage,'oRegister');hp.content.clearreg();if(hp.utils.get('oMustBeLoggedIn')){hp.utils.get('oMustBeLoggedIn').style.display='none';};}else{hp.utils.get('oShowChangePassword').style.display='block';hp.utils.get('oChangePassword').style.display='none';};});
						//Attach text hints to required text fields
						hp.utils.addEvent(hp.utils.get('oTitle'),'focus',function(){hp.hint.show('Please select your title.',this);});hp.utils.addEvent(hp.utils.get('oTitle'),'blur',hp.hint.hide);
						hp.utils.addEvent(hp.utils.get('oFirstName'),'focus',function(){hp.hint.show('Please enter your first name only.',this);});hp.utils.addEvent(hp.utils.get('oFirstName'),'blur',hp.hint.hide);
						hp.utils.addEvent(hp.utils.get('oLastName'),'focus',function(){hp.hint.show('Please enter your last name.',this);});hp.utils.addEvent(hp.utils.get('oLastName'),'blur',hp.hint.hide);
						hp.utils.addEvent(hp.utils.get('oEmail'),'focus',function(){hp.hint.show('This has to be a valid email address.Your email address will be used to authorise your registration and be your login to Mobile World Live.It will also be used to receive messages and alerts through Mobile World Live. The GSMA may also communicate with you via your email address if you agree to this.',this);});hp.utils.addEvent(hp.utils.get('oEmail'),'blur',function(){hp.hint.hide();hp.valid.email(this,'oEmailError','oEmailAccept');});
						hp.utils.addEvent(hp.utils.get('oEmailWhy'),'click',function(){hp.utils.get('oEmail').focus();return false;});
						hp.utils.addEvent(hp.utils.get('oPassword'),'focus',function(){hp.hint.show('Please enter a password. Try and make it as random as possible.<br/>2-16 alphanumeric characters please.',this);});hp.utils.addEvent(hp.utils.get('oPassword'),'blur',hp.hint.hide);
						hp.utils.addEvent(hp.utils.get('oConfirmPassword'),'focus',function(){hp.hint.show('Please confirm your password.',this);});hp.utils.addEvent(hp.utils.get('oConfirmPassword'),'blur',hp.hint.hide);
						if(bResetPassword){
							hp.utils.addEvent(hp.utils.get('oResetPassword'),'focus',function(){hp.hint.show('Please enter a password. Try and make it as random as possible.<br/>2-16 alphanumeric characters please.',this);});hp.utils.addEvent(hp.utils.get('oResetPassword'),'blur',hp.hint.hide);
							hp.utils.addEvent(hp.utils.get('oResetConfirmPassword'),'focus',function(){hp.hint.show('Please confirm your password.',this);});hp.utils.addEvent(hp.utils.get('oResetConfirmPassword'),'blur',hp.hint.hide);
						}
						hp.utils.addEvent(hp.utils.get('oCompany'),'focus',function(){hp.hint.show('Please select your company.',this);});hp.utils.addEvent(hp.utils.get('oCompany'),'blur',hp.hint.hide);
						//hp.utils.addEvent(hp.utils.get('oDepartment'),'focus',function(){hp.hint.show('Please enter your department.',this);});hp.utils.addEvent(hp.utils.get('oDepartment'),'blur',hp.hint.hide);
						hp.utils.addEvent(hp.utils.get('oJobTitle'),'focus',function(){hp.hint.show('Please enter your job title.',this);});hp.utils.addEvent(hp.utils.get('oJobTitle'),'blur',hp.hint.hide);
						hp.utils.addEvent(hp.utils.get('oCountry'),'focus',function(){hp.hint.show('Please select your country.',this);});hp.utils.addEvent(hp.utils.get('oCountry'),'blur',hp.hint.hide);
						//hp.utils.addEvent(hp.utils.get('oPhoneNumber'),'focus',function(){hp.hint.show('International code area has to be specified, no spaces.<br/>(i.e. +447878787878)',this);});hp.utils.addEvent(hp.utils.get('oPhoneNumber'),'blur',hp.hint.hide);
						//hp.utils.addEvent(hp.utils.get('oPhoneWhy'),'click',function(){hp.utils.get('oPhoneNumber').focus();return false;});
						hp.utils.addEvent(hp.utils.get('oProfilePicture'),'focus',function(){hp.hint.show('Upload your photo and share it with the Mobile World Community. Please select an image (.jpg or .jpeg) to use as your profile picture. ',this);});hp.utils.addEvent(hp.utils.get('oProfilePicture'),'blur',hp.hint.hide);
						hp.utils.addEvent(hp.utils.get('oProfilePictureWhy'),'click',function(){hp.hint.show('Upload your photo and share it with the Mobile World Community. Please select an image (.jpg or .jpeg) to use as your profile picture. ',this);});hp.utils.addEvent(hp.utils.get('oProfilePicture'),'blur',hp.hint.hide);

						vRegFields="vTitle,vFirstName,vLastName,vEmail,vPassword,nCompany,vJobTitle,nCountry,bContact"; //Record reg fields for post, we'll handle profile pic later
						//hp.utils.addEvent(hp.utils.get('oFirstName'),'keyup',function(){hp.valid.name(this,'oFirstError','oFirstAccept');});
						//hp.utils.addEvent(hp.utils.get('oLastName'),'keyup',function(){hp.valid.name(this,'oLastError','oLastAccept');});
						//hp.valid.name(hp.utils.get('oFirstName'),'oFirstError','oFirstAccept');
						//hp.valid.name(hp.utils.get('oLastName'),'oLastError','oLastAccept');
						
						
						//Live check of email address
						
						hp.utils.addEvent(hp.utils.get('oEmail'),'keyup',function(){hp.valid.email(this,'oEmailError','oEmailAccept');});
						hp.utils.addEvent(hp.utils.get('oPassword'),'keyup',function(){hp.valid.password(this,'oPasswordError','oPasswordAccept');});
						hp.utils.addEvent(hp.utils.get('oConfirmPassword'),'keyup',function(){hp.valid.confirmpass(this,'oConfirmPasswordError','oConfirmPasswordAccept','oPassword');});
						if(bResetPassword){
							hp.utils.addEvent(hp.utils.get('oResetPassword'),'keyup',function(){hp.valid.password(this,'oResetPasswordError','oResetPasswordAccept');});
							hp.utils.addEvent(hp.utils.get('oResetConfirmPassword'),'keyup',function(){hp.valid.confirmpass(this,'oResetConfirmPasswordError','oResetConfirmPasswordAccept','oResetPassword');});
						}
						//file check
						hp.utils.addEvent(hp.utils.get('oProfilePicture'),'change',function(){hp.valid.imagefile(this);});
						//if not logged in
						if(hp.utils.get('oLoginForm')){
							//Main
							hp.utils.addEvent(hp.utils.get('oMainLoginEmail'),'focus',function(){if(this.value.toLowerCase()=='email address'){this.value='';};bReadyToSubmit=true;});
							hp.utils.addEvent(hp.utils.get('oMainLoginEmail'),'blur',function(){if(this.value==''){this.value='Email address';};bReadyToSubmit=false;});
							hp.utils.addEvent(hp.utils.get('oMainLoginPassword'),'focus',function(){if(this.value=='@@@@@@@@'){this.value='';};bReadyToSubmit=true;});
							hp.utils.addEvent(hp.utils.get('oMainLoginPassword'),'blur',function(){if(this.value==''){this.value='@@@@@@@@';};bReadyToSubmit=false;});
							//Popup Login form
							hp.utils.addEvent(hp.utils.get('oLoginEmail'),'focus',function(){if(this.value.toLowerCase()=='email address'){this.value='';};bReadyToSubmit=true;});
							hp.utils.addEvent(hp.utils.get('oLoginEmail'),'blur',function(){if(this.value==''){this.value='Email address';};bReadyToSubmit=false;});
							hp.utils.addEvent(hp.utils.get('oLoginPassword'),'focus',function(){if(this.value=='@@@@@@@@'){this.value='';};bReadyToSubmit=true;});
							hp.utils.addEvent(hp.utils.get('oLoginPassword'),'blur',function(){if(this.value==''){this.value='@@@@@@@@';};bReadyToSubmit=false;});
							hp.utils.addEvent(hp.utils.get('oRemember'),'focus',function(){if(this.value=='checked'){this.value='@@@@@@@@';};bReadyToSubmit=true;});

							//login submit
							hp.utils.addEvent(hp.utils.get('oMainLoginSubmit'),'click',function(){hp.http.send.login(true);}); //in page
							hp.utils.addEvent(hp.utils.get('oLogin'),'click',function(){hp.http.send.login(false);}); //in reg popup
							//listen for enter key
							if(!hp.ua.ie()){
								hp.utils.addEvent(window,'keyup',function(e){
									if(bReadyToSubmit){
										(e.keyCode==13)?hp.http.send.login((hp.utils.get('oReg_o').style.display!='block')):null;
									}
								});
							};
							//forgot password
							hp.utils.addEvent(hp.utils.get('oForgotPassEmail'),'keyup',function(){hp.valid.email(this,'oForgotPassEmailError','oForgotPassEmailAccept');});
							hp.utils.addEvent(hp.utils.get('oForgotPasswordLink'),'click',function(){hp.content.swap(vCurrentPage,'oForgotPassword');});
							hp.utils.addEvent(hp.utils.get('oMainForgotPasswordLink'),'click',function(){hp.content.toggle('oReg_o');hp.content.swap(vCurrentPage,'oForgotPassword');});
							
							hp.utils.addEvent(hp.utils.get('oGetPassword'),'click',hp.http.send.getpassword);
						} else {
							//check data
							hp.valid.email(hp.utils.get('oEmail'),'oEmailError','oEmailAccept');
							hp.valid.password(hp.utils.get('oPassword'),'oPasswordError','oPasswordAccept');
							hp.valid.confirmpass(hp.utils.get('oConfirmPassword'),'oConfirmPasswordError','oConfirmPasswordAccept','oPassword');
							//Password change
							hp.utils.addEvent(hp.utils.get('oShowChangePasswordLink'),'click',function(){hp.utils.get('oShowChangePassword').style.display='none';hp.utils.get('oChangePassword').style.display='block';});
						}
						//Next, back and submit
						hp.utils.addEvent(hp.utils.get('oNext'),'click',hp.valid.check);
						hp.utils.addEvent(hp.utils.get('oBackInterests'),'click',function(){hp.content.swap('oInterests','oRegister');});
						hp.utils.addEvent(hp.utils.get('oSubmitRegistration'),'click',hp.http.send.register);
						if(bResetPassword){
							hp.utils.addEvent(hp.utils.get('oSavePassword'),'click',hp.http.send.resetpassword);
						}
						
						hp.utils.addEvent(hp.utils.get('oRegisterNow'),'click',function(){hp.content.swap('oForgotPassword','oRegister');});
					};
					//setup search
					hp.search.attach();
					hp.email.attach();
				},
				tickall:function(oP,oN){
					var oCollection=document.getElementsByName(oN);
					for(var i=0;i<oCollection.length;i++){
						oCollection[i].checked=oP.checked;
					}
				},
				query:function(){
					var aFields;
					return {
						registration:function(){
							aFields=[];
							var aRegFields=vRegFields.split(","),oE,aValueList;
							for(var i=0;i<aRegFields.length;i++){
								oE=document.getElementsByName(aRegFields[i]);								
								if(oE.length>1){
								aValueList=[];
									for(var j=0;j<oE.length;j++){
										if(oE[j].checked){
											aValueList.push(encodeURIComponent(oE[j].value));
										}
									}
									aFields.push(aRegFields[i]+"="+aValueList);
								}else{
									if(oE[0].type.toLowerCase()!='checkbox'){
										if(aRegFields[i]=='vPassword'){
											
											(oE[0].value!='')?aFields.push(aRegFields[i]+"="+hex_md5(encodeURIComponent(oE[0].value))):aFields.push(aRegFields[i]+"=");
											//(oE[0].value!='')?aFields.push(aRegFields[i]+"="+b64_sha1(encodeURIComponent(oE[0].value))):aFields.push(aRegFields[i]+"=");
										}else{
											aFields.push(aRegFields[i]+"="+encodeURIComponent(oE[0].value));
										}
									}else{
										var bChecked=oE[0].checked?'1':'0';
										aFields.push(aRegFields[i]+"="+bChecked);
									}
								}
							};
							return aFields.join("&");
						}
					}
				}(),
				selectrange: function(oT,nS,nE){
					if(oT.setSelectionRange) {
						oT.setSelectionRange(nS,nE);
					}else if(oT.createTextRange){
				        var oTextRange = oT.createTextRange();
				        oTextRange.moveStart("character", nS);
				        oTextRange.moveEnd("character", nE-oT.value.length);
				        oTextRange.select();
				    } else {
						oT.select();
					}
				},
				isInvalidKey:function(nKey){
					return (/*tab,enter*/(nKey==9)||(nKey==13)||/*shift, ctl*/(nKey==16)||(nKey==17)||/*alt,pause/break,caps lock*/(nKey>=18&&nKey<=20)||/*escape*/(nKey==27)||/*page up,page down,end*/(nKey>=33&&nKey<=35)||/*home,left,up, right, down*/(nKey>=36&&nKey<=40)||/*print screen,insert*/(nKey>=44&&nKey<=45));
				},
				maximise:function(oT){
					var oT=hp.utils.get(oT);
					oT.style.width=document.body.offsetWidth+'px';
					if((document.documentElement.clientHeight>document.body.offsetHeight)){
						oT.style.height=document.documentElement.clientHeight+'px';
					} else {
						oT.style.height=document.body.offsetHeight+'px';
					}
				}
			}
		}()};
		
		//User Agent
		{hp.ua=function(){
			return {
				ie:function(){
					return !!(navigator.appVersion.indexOf("MSIE")!=-1)
				}
			}
		}()}
		
		//DOMParser Patch
		{if (typeof DOMParser=="undefined") {
		   DOMParser=function(){};
		   DOMParser.prototype.parseFromString=function (str, contentType) {
				if (typeof ActiveXObject != "undefined") {
					var d = new ActiveXObject("MSXML.DomDocument");
					d.loadXML(str);
					return d;
				} else if (typeof XMLHttpRequest != "undefined") {
					var req = new XMLHttpRequest;
					req.open(	"GET", "data:" + (contentType || "application/xml") +
								";charset=utf-16," + encodeURIComponent(str), false);
					(req.overrideMimeType)?req.overrideMimeType(contentType):null;
					req.send(null);
					return req.responseXML;
				}
			}
		}};
		
		//Trim prototype
		String.prototype.trim = function() {
			return this.replace(/^\s+|\s+$/g,"");
		}
		
		//remove last full stop prototype
		String.prototype.trimFullStops = function() {
			return this.replace(/^\.+|\.+$/g,"");
		}
		
		//remove spaces prototype
		String.prototype.removeSpace = function() {
			return this.replace(/\s/g,"");
		}
		
		//New line remove protoype
		String.prototype.replaceNewLine = function() {
			return this.replace(/(\r\n|\r|\n)/g, "<br />");
		}
		
		//Replace breaks remove protoype
		String.prototype.replaceBreaks = function() {
			return this.replace(/<br \/>|<br\/>/g, "\n");
		}
		
		//Remove BR protoype
		String.prototype.stripBreaks = function() {
			return this.replace(/<br \/>|<br\/>/g, " ");
		}		
		
		//HTML remove tags protoype
		String.prototype.stripTags = function() {
			return this.replace(/<\S[^>]*>/g, "");
		}
		
		//Hinting
		{hp.hint=function(){
			var oT,oTB;
			return {
				show:function(vT,oP){
					oT=hp.utils.get('oHint'),oTB=hp.utils.get('oText');
					oTB.innerHTML='';oTB.innerHTML=vT;
					var nOT=0;
					while(oP.offsetParent!=null){nOT+=oP.offsetTop;oP=oP.offsetParent;}
					hp.ua.ie()?oT.style.top=(nOT+2)+"px":oT.style.top=(nOT-1)+"px";
					oT.style.display='block';
				},
				hide:function() {
					oT.style.display='none';
					oTB.innerHTML='';
				}
			}
		}()};
		
		//data check
		{hp.valid=function(){
			var aTmp,vEmail,aDomainList,vFileExt;
			return {
							//name:function(oT,oE,oA){
							//	if(oT.value!=''){
							//		var oReName = /^[a-zA-Z\s'-]+$/;
							//		if(oReName.test(oT.value)) {
							//			(oA!=undefined)?hp.utils.get(oA).style.display='block':null;
							//			(oE!=undefined)?hp.utils.get(oE).style.display='none':null;
							//			
							//			(oE==='oFirstError')?bFirstNameError=false:bLastNameError=false;
							//		} else {
							//			(oA!=undefined)?hp.utils.get(oA).style.display='none':null;
							//			(oE!=undefined)?hp.utils.get(oE).style.display='block':null;
							//			(oE==='oFirstError')?bFirstNameError=true:bLastNameError=true;
							//		}
							//	} else {
							//		(oA!=undefined)?hp.utils.get(oA).style.display='none':null;
							//		(oE!=undefined)?hp.utils.get(oE).style.display='none':null;
							//		(oE==='oFirstError')?bFirstNameError=true:bLastNameError=true;
							//	}
							//},

			
			
				email:function(oT,oE,oA){
					var oReEmail=/^%?\w+%?((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
					     if(oReEmail.test(oT.value)) {
					      if(oT.value!=''){
					       (oA!=undefined)?hp.utils.get(oA).style.display='block':null;
					       hp.utils.get(oE).style.display='none';
					      } else {
					       (oA!=undefined)?hp.utils.get(oA).style.display='none':null;
					       hp.utils.get(oE).style.display='none';
					      }
					      bEmailError=false;
					     } else {
					      if(oT.value!=''){
					       (oA!=undefined)?hp.utils.get(oA).style.display='none':null;
					       hp.utils.get(oE).style.display='block';
					       bEmailError=true;
					      } else {
					       (oA!=undefined)?hp.utils.get(oA).style.display='none':null;
					       hp.utils.get(oE).style.display='none';
					       bEmailError=false;
					      }
     }
				},
				password:function(oT,oE,oA){
					var oRePass=/^[A-Za-z\d]{2,25}$/;
					if(oT.value!=''){
						if(oRePass.test(oT.value)){
							(oA!=undefined)?hp.utils.get(oA).style.display='block':null;
							hp.utils.get(oE).style.display='none';
							bPasswordError=false;
						} else {
							(oA!=undefined)?hp.utils.get(oA).style.display='none':null;
							hp.utils.get(oE).style.display='block';
							bPasswordError=true;
						}
					}else{
						(oA!=undefined)?hp.utils.get(oA).style.display='none':null;
						hp.utils.get(oE).style.display='none';
						bPasswordError=false;
					}
				},
				confirmpass:function(oT,oE,oA,oP){
					if(oT.value!=''){
						if(oT.value==hp.utils.get(oP).value){
							hp.utils.get(oA).style.display='block';
							hp.utils.get(oE).style.display='none';
							bConfirmPasswordError=false;
						} else {
							hp.utils.get(oA).style.display='none';
							hp.utils.get(oE).style.display='block';
							bConfirmPasswordError=true;
						}
					} else {
						hp.utils.get(oA).style.display='none';
						hp.utils.get(oE).style.display='none';
						bConfirmPasswordError=false;
					}
				},
				imagefile:function(oT){
					if(oT.value!=''){
						aTmp=oT.value.toLowerCase().split(".");
						vFileExt=aTmp[(aTmp.length-1)];
						if(vFileExt=='jpg'||vFileExt=='jpeg'){
							hp.utils.get('oProfilePictureAccept').style.display='block';
							hp.utils.get('oProfilePictureError').style.display='none';
							bPicError=false;
						} else {
							hp.utils.get('oProfilePictureAccept').style.display='none';
							hp.utils.get('oProfilePictureError').style.display='block';
							bPicError=true;
						}
					} else {
						hp.utils.get('oProfilePictureAccept').style.display='none';
						hp.utils.get('oProfilePictureError').style.display='none';
						bPicError=false;
					}
				},
				phonenumber:function(oT){
					
					var vTel=oT.value.trim().removeSpace();oT.value=vTel;//clean and return to field
					var oTelRE=/^[+]{1}[0-9]*$/;
					if((vTel.length>8)&&(vTel.length<17)&&oTelRE.test(vTel)){
						bPhoneError=false;
					}else{
						bPhoneError=false;
					}
					
				},
				check:function(){
					var nErr=0;
					//quick check of special data
						hp.valid.email(hp.utils.get('oEmail'),'oEmailError','oEmailAccept');
						if(hp.utils.get('oShowChangePassword').style.display=='none'){
							hp.valid.password(hp.utils.get('oPassword'),'oPasswordError','oPasswordAccept');
							hp.valid.confirmpass(hp.utils.get('oConfirmPassword'),'oConfirmPasswordError','oConfirmPasswordAccept','oPassword');
						};
						hp.valid.imagefile(hp.utils.get('oProfilePicture'));
						//hp.valid.phonenumber(hp.utils.get('oPhoneNumber'));
					//end
					if(hp.utils.get('oShowChangePassword').style.display=='none'){
						aTmp=vFormPassRequired.split(",");
					} else {
						aTmp=vFormRequired.split(",");
					}
					for(var i=0;i<aTmp.length;i++){
						
						if(hp.utils.get('o'+aTmp[i]).value=='') {
							nErr++;
							hp.utils.get('o'+aTmp[i]+'Label').className='red';
						}else{
							hp.utils.get('oMandatory').style.display='none';
							hp.utils.get('o'+aTmp[i]+'Label').className='';
						}
					}
					//if(bFirstNameError){
					//	hp.utils.get('oFirstNameLabel').className='red';
					//	nErr++;
					//} else {
					//	hp.utils.get('oFirstNameLabel').className='';
					//}
					//if(bLastNameError){
					//	hp.utils.get('oLastNameLabel').className='red';
					//	nErr++;
					//}else{
					//	hp.utils.get('oLastNameLabel').className='';
					//}
					if(bEmailError){
						hp.utils.get('oEmailLabel').className='red';
						hp.utils.get('oEmailErrorMsg').style.display='block';
						nErr++;
					}else{
						hp.utils.get('oEmail').className='';
						hp.utils.get('oEmailErrorMsg').style.display='none';
					};
					if(bPasswordError){
						hp.utils.get('oPasswordLabel').className='red'
						hp.utils.get('oPasswordErrorMsg').style.display='block';
						nErr++;
					}else{
						hp.utils.get('oPassword').className='';
						hp.utils.get('oPasswordErrorMsg').style.display='none';
					}
					if(bConfirmPasswordError){
						hp.utils.get('oConfirmPasswordLabel').className='red';
						hp.utils.get('oConfirmPasswordErrorMsg').style.display='block';
						nErr++;
					}else{
						hp.utils.get('oConfirmPassword').className='';
						hp.utils.get('oConfirmPasswordErrorMsg').style.display='none';
					};
					if(bPicError){
						hp.utils.get('oProfilePictureLabel').className='red';
						hp.utils.get('oProfilePictureErrorMsg').style.display='block';
						nErr++;
					}else{
						hp.utils.get('oProfilePictureLabel').className='';
						hp.utils.get('oProfilePictureErrorMsg').style.display='none';
					};
										if(nErr>0){
						hp.utils.get('oMandatory').style.display='block';
					}else{
						//Clear Errors
						hp.utils.get('oEmailErrorMsg').style.display='none';
						hp.utils.get('oPasswordErrorMsg').style.display='none';
						hp.utils.get('oConfirmPasswordErrorMsg').style.display='none';
						hp.utils.get('oProfilePictureErrorMsg').style.display='none';
						//jump to next screen
						hp.utils.get('oMandatory').style.display='none';
						//hp.content.swap('oRegister','oInterests');
						hp.http.send.register()
					}
				}
			}
		}()};
		
		//content functions
		{hp.content=function(){
			return {
				//Swap current content (oCC) with new content (oNC)
				swap:function(oCC,oNC,bL){
					if(hp.utils.get(oCC)&&hp.utils.get(oNC)){
						hp.utils.get(oCC).style.display='none';
						hp.utils.get(oNC).style.display='block';
						if(bL==undefined){vCurrentPage=oNC};
					} else {
						alert('An unexpected error occurred. Sorry for any inconvenience.');
						throw new Error("Content not found or does not exist");
					}
				},
				toggle:function(oT){

					if((hp.utils.get(oT).style.display=='block')){
				hp.utils.get(oT).style.display='none';
					}else{
						hp.utils.get(oT).style.display='block';
					};
				},
				filterdocs:function(oT){
					(oT.value!='')?
						(oT.value=='0')?location.href='documents.asp':location.href='documents.asp?filter='+oT.value
					:null;
				},
				clearreg:function(){
					//clear reg form and reset all

					var aRegFields=vRegFields.split(","),oE;
					for(var i=0;i<aRegFields.length;i++){
						oE=document.getElementsByName(aRegFields[i]);
						if(oE.length>1){
							for(var j=0;j<oE.length;j++){
								(oE[j].checked)?oE[j].checked=false:null;
							}
						}else{
							if(oE[0].type.toLowerCase()=='checkbox'){
								bChecked=oE[0].checked=false
							}else if(oE[0].type.toLowerCase()=='select-one'){
								oE[0].selectedIndex=0;
							}else{
								oE[0].value='';
							}
						}
					};
					//specials
					hp.utils.get('oConfirmPassword').value='';
					hp.utils.get('oProfilePicture').value='';
					hp.utils.get('oLoginEmail').value='Email address';
					hp.utils.get('oLoginPassword').value='@@@@@@@@';
					//clear labels
					aTmp=vFormRequired.split(",");
					for(var i=0;i<aTmp.length;i++){
						hp.utils.get('o'+aTmp[i]+'Label').className='';
					}
					hp.utils.get('oMandatory').style.display='none';
					//hide msgs and icons
					hp.content.hideall('oFirstError,oFirstAccept,oLastError,oLastAccept,oEmailError,oEmailAccept,oPasswordError,oPasswordAccept,oConfirmPasswordError,oConfirmPasswordAccept,oProfilePictureError,oProfilePictureAccept');

				},
				hideall:function(vEl){
					if(vEl!=''){
						var aElList = vEl.split(",");
						for(var i=0;i<aElList.length;i++){
							hp.utils.get(aElList[i]).style.display='none';
						}
					}else{
						alert('An unexpected error occurred. Sorry for any inconvenience.');
						throw new Error("Elements required in HideAll");
					}
				},
				selectinterests:function(vI){
					if(vI){
						var aInterests=vI.split(",");
						for(var i=0;i<aInterests.length;i++){						
							hp.utils.get('oInterest'+aInterests[i]).checked=true;
						};
					}
				},
				showcompletedialog:function(){
					//hide reg
					window.scrollTo(0,0)
					hp.content.toggle('oReg_o');
					hp.content.toggle('oReg_Mini');
					hp.utils.maximise('oReg_u');
					hp.utils.addEvent(hp.utils.get('oRegCompleteClose'),'click',hp.content.hidecompletedialog);
				},
				hidecompletedialog:function(){
					hp.content.toggle('oReg_Mini');
					hp.content.toggle('oReg_u');
					//clear reg
					if(hp.utils.get('oLoginForm')){
						hp.content.swap(vCurrentPage,'oRegister');
						hp.content.clearreg();
						if(hp.utils.get('oMustBeLoggedIn')){
							hp.utils.get('oMustBeLoggedIn').style.display='none';
						};
					};
				}
			}
		}()};
		//For the flash programmer in all of us
		trace=alert;
				var Encode=encodeURIComponent;

		
		