
smashion.common.global.IMPORT("/js/pwc/window.js");smashion.common.global.IMPORT("/js/pwc/window_effects.js");smashion.common.ModalDialog=Class.create(smashion.common.global.AjaxHandler,{initialize:function(element,formUrl,controlText,options){this.element=$(element);this.formUrl=formUrl;this.controlText=controlText;this.clicked=false;this.options=Object.extend({formName:"sfmodalForm",status:"sfmodalStatus",linkClass:"",theme:"smashionpwc01",onSubmit:function(){},params:{}},options||{});this.form=$(this.options.formName);this.initUI();},initUI:function(){this.control=new Element("a",{href:"javascript:void(0)","class":this.options.linkClass});this.control.update(this.controlText);this.element.update(this.control);Event.observe(this.control,'click',this.btnClick.bindAsEventListener(this));},btnClick:function(event){if(!this.clicked){this.clicked=true;this.showForm(event);}
if(event){Event.stop(event);}
return false;},showForm:function(event){Dialog.confirm({url:this.formUrl,options:{parameters:this.options.params,onSuccess:this.showFormCallback.bind(this)}},{className:this.options.theme,width:500,okLabel:"Submit",cancelLabel:"Cancel",onOk:this.submitForm.bind(this)});},showFormCallback:function(transport,json){if(this.isNotLoggedIn(json)){smashion.common.global.login();}
this.clicked=false;},submitForm:function(win){var form=$(this.options.formName);if(form){$(this.options.formName).request({onSuccess:this.onFormSuccess.bind(this)});}else{Windows.focusedWindow.close();}
return false;},onFormSuccess:function(transport,json){var message=null;if(!json||typeof json.status=="undefined"){message="Server error.  Please try later.";}else if(json.status=='ERROR'){message=json.message;}
if(message!=null){var error=new Element("span",{"class":"sfmodal-error"}).update(message);$(this.options.status).update(error);}else{Windows.focusedWindow.close();this.options.onSubmit.bind(this)();}},handleNotLoggedIn:function(error){smashion.common.global.login();},dispose:function(){}})
