//****************************************************************************
// Copyright 2007 Starscale Inc.

if(!ibi.YupNope.Templates){ibi.YupNope.Templates={};}
ibi.YupNope.Templates.Account={RegisterCheck:'<span xmlns="http://www.w3.org/1999/xhtml"><img \
src="/static/images/tick.gif" alt="OK"/></span>'}
function doPasswordChange(){var progDiv=$('sp-progress');var errorDiv=$('sp-error');var mainDiv=$('sp-main');if($F('Password').empty()||$F('PasswordConfirm').empty()||($('OldPassword')&&$F('OldPassword').empty())){errorDiv.update(ibi.YupNope.Strings.Account.PasswordChangeMissing);errorDiv.show();return;}
progDiv.show();errorDiv.hide();mainDiv.hide();var consts=ibi.Phix.AccountManagement.Const.ChangePassword;var errFunc=function(status){status=status||consts.Status.GeneralFailure;errorDiv.update(ibi.YupNope.Strings.Account.PasswordChange[status]);Form.reset('sp-form');Form.focusFirstElement('sp-form');errorDiv.show();mainDiv.show();progDiv.hide();}
new ibi.Ajax.Request(consts.uriPath,{asynchronous:true,parameters:Form.serialize('sp-form'),onFailure:function(){errFunc();},onSuccess:function(transport){var json=transport.responseText.evalJSON();if(json.Status==consts.Status.Success){progDiv.hide();$('sp-success').show();}else{errFunc(json.Status);}}});}
function doRegisterCheck(type,value,updateId,progressId){var dest=$(updateId);dest.hide();if(value!=""){$(progressId).show();var consts=ibi.Phix.AccountManagement.Const.RegisterCheck;new ibi.Ajax.Request(consts.uriPath,{asynchronous:true,parameters:type+'='+encodeURIComponent(escape(value)),onFailure:function(){$(progressId).hide();},onSuccess:function(transport){var json=transport.responseText.evalJSON();if(json.Status==consts.Status.Success){dest.updateXHTML(ibi.YupNope.Templates.Account.RegisterCheck);}else{dest.update(ibi.YupNope.Strings.Account.RegisterCheck[json.Status]);}
$(progressId).hide();dest.show();}});}}
function doForgotPassword(){var progDiv=$('fp-progress');var confFormDiv=$('fp-confirmDiv');var errDiv=$('fp-errorResult');var dest=$('fp-mainDiv');progDiv.show();confFormDiv.hide();errDiv.hide();dest.hide()
var consts=ibi.Phix.AccountManagement.Const.StartPasswordReset;new ibi.Ajax.Request(consts.uriPath,{asynchronous:true,parameters:Form.serialize('fp-form'),onFailure:function(){progDiv.hide();errDiv.update(ibi.YupNope.Strings.Account.PasswordReset[consts.Status.GeneralFailure]);errDiv.show();dest.show();confFormDiv.show();},onSuccess:function(transport){var json=transport.responseText.evalJSON();if(json.Status==consts.Status.Success){$('fp-success').show();}else{errDiv.update(ibi.YupNope.Strings.Account.PasswordReset[json.Status]);errDiv.show();dest.show();}
progDiv.hide();confFormDiv.show();}});}
function sendValidationEmail(){var progDiv=$('re-progress');var dest=$('re-result');var button=$('re-emailButton');if($F('Email')!=""){progDiv.show();dest.hide();button.hide();var consts=ibi.Phix.AccountManagement.Const.SendValidationEmail;new ibi.Ajax.Request(consts.uriPath,{asynchronous:true,parameters:Form.serialize('re-form'),onFailure:function(){progDiv.hide();dest.update(ibi.YupNope.Strings.Account.ResendRegisterEmail[consts.Status.GeneralFailure]);dest.addClassName('inline-error');dest.removeClassName('inline-success');dest.show();button.show();},onSuccess:function(transport){var json=transport.responseText.evalJSON();dest.update(ibi.YupNope.Strings.Account.ResendRegisterEmail[json.Status]);if(json.Status==consts.Status.Success){dest.addClassName('inline-success');dest.removeClassName('inline-error');}else{dest.addClassName('inline-error');dest.removeClassName('inline-success');}
dest.show();button.show();progDiv.hide();}});}else{dest.update(ibi.YupNope.Strings.Account.ResendRegisterEmailMissing);dest.show();dest.addClassName('inline-error');dest.removeClassName('inline-success');}}
function expandEula(){new Effect.Scale('reg-eulaBox',400,{scaleX:false,scaleContent:false});new Effect.Fade('eulaExpandLink');new Effect.Appear('eulaShrinkLink',{queue:'end'});}
function shrinkEula(){new Effect.Scale('reg-eulaBox',25,{scaleX:false,scaleContent:false});new Effect.Fade('eulaShrinkLink');new Effect.Appear('eulaExpandLink',{queue:'end'});}
function sendInvite(){var id='invite';var error=$(id+'Error');if($F(id+'Email')==""){error.update(ibi.YupNope.Strings.Account.InviteMissing);error.show();return;}
var prog=$(id+'Progress');var main=$(id+'Div');var success=$(id+'Success');var email=$(id+'EmailSent');main.hide();prog.show();success.hide();error.hide();var phix=ibi.Phix.AccountManagement.Const.SendInvitation;var errFunc=function(status){status=status||phix.Status.GeneralFailure;error.update(ibi.YupNope.Strings.Account.Invite[status]);Form.focusFirstElement(id+'Form');main.show();error.show();prog.hide();}
new ibi.Ajax.Request(phix.uriPath,{asynchronous:true,parameters:Form.serialize(id+'Form'),onFailure:function(){errFunc();},onSuccess:function(transport){var json=transport.responseText.evalJSON();if(json.Status==phix.Status.Success){email.update($F(id+'Email'));ibi.log($F(id+'Email'));prog.hide();success.show();}else{errFunc(json.Status);}}});}
function submitContactForm(){var contactDiv=$('contactDiv');var progressDiv=$('contactProgress');var resultDiv=$('contactResult');var errorDiv=$('contactError');if(contactDiv.visible()){contactDiv.hide();errorDiv.hide();progressDiv.show();}
new ibi.Ajax.Updater(resultDiv,"/contact",{asynchronous:true,evalScripts:true,parameters:Form.serialize('contactForm'),onFailure:function(){errorDiv.update(ibi.YupNope.Strings.Contact.Error);contactDiv.show();errorDiv.show();progressDiv.hide();},onComplete:function(){progressDiv.hide();}});}
