// loginCode_ob.js
// Copyright 2008-2009 by Made Headway Limited

function OpenRegisterDlg(){var aa=OpenDialog(280,360,'Register');aa.innerHTML=' <div style="padding:2px 20px 20px 2px;"> <form id="regForm" onsubmit="return false;"> <div style="text-align:left;"> <TABLE class="mi" style="margin-left:auto;margin-right:auto;"> <TR> <TD>Username:</TD> <TD><input type="text" name="username" size="20"/></TD> </TR> <TR> <TD>E-mail:</TD> <TD><input type="text" name="email" size="20"/></TD> </TR> <TR><TD colspan="2"><br/>Please choose a password:</TD></TR> <TR> <TD>Password:</TD> <TD><input type="password" name="pass" id="pass1" size="20"/></TD> </TR> <TR> <TD>Verify:</TD> <TD><input type="password" id="pass2" size="20"/></TD> </TR> <TR> <TD colspan="2"><label><input type="checkbox" name="auto" value="yes" CHECKED=""/>Remember me</label><br/> <label><input type="checkbox" name="newsletter" value="yes" CHECKED=""/>Sign up for free newsletter</label></TD> </TR> <TR><TD colspan="2"><br/><a href="#" onclick="return OpenExtraInfoDialog();">Add optional extra information</a><br/>&nbsp;</TD></TR> </TABLE> </div> <input type="hidden" name="organisationType" value="individual"></input> <input type="hidden" name="fullname" value=""></input> <input type="hidden" name="city" value=""></input> <input type="hidden" name="tel" value=""></input> <div style="text-align:right;"> <input type="button" value="Add User" name="op" onclick="regUser();"/> <input type="button" value="Close" onclick="CancelDialog();"/> </div> </form> </div>';return false;}
function OpenExtraInfoDialog(){var ba=OpenDialog(400,300,'Optional information');ba.innerHTML=' <div style="padding:2px 20px 20px 2px;"> <form id="extraInfoForm"> <div style="text-align:left;"> <TABLE class="mi" style="margin-left:auto;margin-right:auto;"> <TR><TD colspan="2"><br/>Optional information:</TD></TR> <TR> <TD>Full name:</TD> <TD><input type="text" name="fullname" size="20"/></TD> </TR> <TR> <TD>City:</TD> <TD><input type="text" name="city" size="20"/></TD> </TR> <TR> <TD>I am:</TD> <TD><SELECT name="organisationType"> <option value="individual">an individual</option> <option value="business">a business</option> <option value="charity">a charity</option> </SELECT></TD> </TR> <TR> <TD>Telephone No.:</TD> <TD><input type="text" name="tel" size="20"/></TD> </TR> </TABLE> </div> <div style="text-align:right;"> <input type="button" value="Ok" onclick="CopyExtraInfo();"/> <input type="button" value="Cancel" onclick="CancelDialog();"/> </div> </form> </div>';ExtraInfoTransfer(GetElem('regForm'),GetElem('extraInfoForm'));return false;}
function CopyExtraInfo(){ExtraInfoTransfer(GetElem('extraInfoForm'),GetElem('regForm'));CancelDialog();}
function ExtraInfoTransfer(ca,da){da.tel.value=ca.tel.value;da.organisationType.value=ca.organisationType.value;da.fullname.value=ca.fullname.value;da.city.value=ca.city.value;}
var regProgressDlg=null;function regUser(){var ea=GetElem("regForm");if(checkPasses(ea)){var fa=ea.pass1.value;var ga=ea.username.value;var ha=ea.fullname.value;var ia=ea.city.value;var ja=(ea.auto.checked?ea.auto.value:0);var ka=(ea.newsletter.checked?ea.newsletter.value:0);var la=ea.organisationType.value;var ma=ea.email.value;var na=ea.tel.value;regProgressDialog=OpenDialog(300,160,'Processing');regProgressDialog.innerHTML=' <div style="padding:20px 20px 20px 20px;"> <div id="regProgressState"> Please wait... contacting server </div><br/><br/> <form> <input type="button" value="Close" id="regProgressCloseBtn" disabled="true" onclick="CancelDialog();"/> </form> </div>';var oa="newuser.php?op=AddUser&username="+encodeURIComponent(ga)+"&pass="+encodeURIComponent(fa)+"&email="+encodeURIComponent(ma)+"&auto="+encodeURIComponent(ja)+"&newsletter="+encodeURIComponent(ka)+"&organisationType="+encodeURIComponent(la)+"&tel="+encodeURIComponent(na)+"&fullname="+encodeURIComponent(ha)+"&city="+encodeURIComponent(ia);RequestURL(oa,null,"RegReceiveData",ReceiveRegData);}}
function Refresh(){location.href=location.href+'';}
function ReceiveRegData(){var pa=GetElem("regProgressState");var qa=GetElem("regProgressCloseBtn");var ra=GetElem('RegReceiveData').firstChild;if(ra){pa.innerHTML=ra.getAttribute('html');if(ra.getAttribute('result')=="1"){qa.onclick=Refresh;}}
else{pa.innerHTML="Failure contacting server.";}
qa.disabled=false;}
function checkPasses(sa){var p1=sa.pass1.value;var p2=sa.pass2.value;if(p1!=p2){alert("Passwords do not match!");return false;}
if(sa.username.value.length<2){alert("Username not long enough! (min 2 characters)");return false;}
if(sa.email.value.length<2){if(!confirm("No e-mail address entered - you will not be able to receive newsletters or receive responses to messages you send on this site... is this ok?")){return false;}}
return true;}