ASInclude("/core/ui/vendor/jquery/jquery.cookie.compressed.js");ASInclude("/core/ui/vendor/json2.compressed.js");ASInclude("/core/ui/classes/ASSanitizer.js");var AS_FORM;var ALCHITECT_VERSION="1.0.0.0";function ASApplication(){AS_FORM=new ASForm();AS_FORM.registerHook(AS_FORM.checkRequiredHook);}function page(){var path_parts=window.location.pathname.split("/");return path_parts[2];}function URLPath(with_app){var app_dir="ui";var new_parts=[];var x=0;var path_parts=window.location.pathname.split("/");var path_stop="app";if(null==with_app){with_app=false;}for(;x<path_parts.length;x++){if(false==with_app&&path_stop==path_parts[x]){break;}new_parts.push(path_parts[x]);if(app_dir==path_parts[x]){break;}}return new_parts.join("/").replace(/\/$/,"");}function ASInclude(file){document.write('<script type="text/javascript" src="'+URLPath()+file+'"><\/script>');}function ASAuthentication(username,password){if(null!=username&&null!=password){this.setAuthHash(username,password);}}ASAuthentication.prototype=new ASObject();ASAuthentication.prototype.authHash=function(){return $.cookie("auth_hash")||null;};ASAuthentication.prototype.authID=function(){return $.cookie("auth_id")||null;};ASAuthentication.prototype.logout=function(){$.cookie("auth_id",null);$.cookie("auth_hash",null);};ASAuthentication.prototype.setAuthHash=function(username,password){var data=JSON.stringify({"form_action":{"value":"set_authentication"},"username":{"value":username},"password":{"value":password}});$.post(URLPath()+"/server.php","form_name=authentication&json="+data,function(xhr_data,status){$.cookie("auth_hash",xhr_data.auth_hash);$.cookie("auth_id",username);},"json");return(null==this.authID()||null==this.authHash());};ASAuthentication.prototype.verifyAuthHash=function(username,auth_hash){var data=JSON.stringify({"form_action":{"value":"verify_authentication"},"username":{"value":(null==username?this.authID():username)},"auth_hash":{"value":(null==auth_hash?this.authHash():auth_hash)}});var _verified;$.ajax({type:"POST",async:false,url:URLPath()+"/server.php",data:"form_name=authentication&json="+data,dataType:"json",success:function(xhr_data,status){_verified=xhr_data.verified;},error:function(xhr,textStatus,errorThrown){console.log("VAH ERROR: %o, %s, %o",xhr,textStatus,errorThrown);}});return _verified;};function ASException(code,message){this.setCode(code);if(null==message){this.setMessage(this.exceptions[code]);}else{this.setMessage(message);}}ASException.prototype=new Error();ASException.AS_EXCEPTION_UNKNOWN=9999;ASException.AS_EXCEPTION_MISSING_ID=1000;ASException.messages=[ASException.AS_EXCEPTION_UNKNOWN="Unknown Exception",ASException.AS_EXCEPTION_MISSING_ID="Missing ID"];ASException.prototype.messageForExceptionCode=function(code){return this.messages[code];};ASException.prototype.setCode=function(code){this.code=code;};ASException.prototype.setMessage=function(message){this.message=message;};ASException.prototype.toString=function(){return"ASException ("+this.code+") "+this.message;};function ASForm(){this.form_submitted_callback=null;this.hooks=[];this.ignore_forms={};this.ready_to_submit=true;this.observeForms();}ASForm.prototype=new ASObject();ASForm.prototype._formSubmitted=function(data,status){if(null!=AS_FORM.form_submitted_callback){AS_FORM.form_submitted_callback(data,status);}};ASForm.prototype.ignoreForm=function(form_id){this.ignore_forms[form_id]=true;var foo=this.ignore_forms;};ASForm.prototype.observeForms=function(){var forms=document.getElementsByTagName("form");var x;for(x=0;x<forms.length;x++){$("#"+$(forms[x]).attr("id")).submit(this._prepare);}};ASForm.prototype._prepare=function(event){if(true==AS_FORM.ignore_forms[event.target.id]){return true;}var frm=$(event.target);var _data={};var x=0;var frm_action=frm.attr("action");if(null==frm_action.match(/^javascript/)){$(frm[0]).attr("action","javascript: void(0)");}frm.find(":input").each(function(idx,el){var element=$(el);if("submit"==element.attr("type")||"reset"==element.attr("type")){return;}if("radio"==element.attr("type")){if(true!==element[0].checked){return;}}if("checkbox"==element.attr("type")){if(true!==element[0].checked){return;}}_data[element.attr("name")]=element.attr("value");});for(x in AS_FORM.hooks){if(false==AS_FORM.hooks[x](frm)){return false;}}if(AS_FORM.ready_to_submit){if(undefined==_data["page"]){_data["page"]=page();}AS_FORM._submit(frm.attr("name")||frm.attr("id"),encodeURIComponent(JSON.stringify(_data,null,4)));}return false;};ASForm.prototype.registerFormSubmittedCallback=function(form_submitted_callback){this.form_submitted_callback=form_submitted_callback;};ASForm.prototype.registerHook=function(hook){AS_FORM.hooks.push(hook);};ASForm.prototype._submit=function(form_name,data){$.post(URLPath()+"/core/server.php","&form_name="+form_name+"&json="+data,this._formSubmitted,"json");};ASForm.prototype.checkRequiredHook=function(frm){var ready_to_submit=true;var required=frm.find('input[required="true"]');required.each(function(idx,el){var element=$(el);if(""==element.val()){element.parent().addClass("error_input");ready_to_submit=false;if(0==idx){element.focus();}}else{element.parent().removeClass("error_input");ready_to_submit=true;}});return ready_to_submit;};function ASObject(){this.id=0;}ASObject.prototype=new Object();ASObject.prototype.id=function(){return this.id;};ASObject.prototype.setID=function(id){this.id=id;};ASObject.prototype.setValueForKey=function(key,value){var method="set"+key;if(this.method){this.method(value);}else{this.key=value;}return this;};ASObject.prototype.valueForKey=function(key){var value=null;var method="get"+key;if(this.method){value=this.method();}else{value=this.key;}return value;};function ASUnitTest(log_to_console){this.log_to_console=log_to_console||false;this.failed_list=[];this.failed=0;this.passed=0;}ASUnitTest.prototype.run=function(){if(this.setup){this.setup();}for(method in this){if(method.match(/^test/)){if(this.log_to_console){console.log("TESTING: %s()",method);}if(true===this[method]()){this.passed++;}else{this.failed++;this.failed_list.push(method);}}}if(this.log_to_console){console.log("PASSED: %d, FAILED: %d",this.passed,this.failed);}};ASUnitTest.prototype.assertTrue=function(x){return true==x;};ASUnitTest.prototype.assertFalse=function(x){return false==x;};ASUnitTest.prototype.assertNull=function(x){return null==x;};ASUnitTest.prototype.assertNotNull=function(x){return null!=x;};ASUnitTest.prototype.assertIsA=function(x,t){return x.prototype.isPrototypeOf(t);};ASUnitTest.prototype.assertEqual=function(x,y){return x==y;};ASUnitTest.prototype.assertNotEqual=function(x,y){return x!=y;};ASUnitTest.prototype.assertIdentical=function(x,y){return x===y;};ASUnitTest.prototype.assertNotIdentical=function(x,y){return x!==y;};ASUnitTest.prototype.assertWantedPattern=function(p,x){return null!=x.match(p);};ASUnitTest.prototype.assertNoUnwantedPattern=function(p,x){return null==x.match(p);};function ASUnitTests(log_to_console){this.unit_tests={"UnitTestTest":ASUnitTestTest,"ObjectTest":ASObjectTest};this.log_to_console=log_to_console||false;this.tests=[];this.passed=0;this.failed=0;this.total=0;}ASUnitTests.prototype.unitTests=function(){return this.unit_tests;};ASUnitTests.prototype.run=function(){var x=null;for(x in this.unit_tests){if(this.log_to_console){console.log("RUNNING: %s",this.unit_tests[x]);}var _test=new this.unit_tests[x](this.log_to_console);this.passed+=_test.passed;this.failed+=_test.failed;this.total++;this.tests.push(_test);}};function ASValidater(){}ASValidater.prototype=new ASObject();ASValidater.prototype.validateEmail=function(str_val,id){var match=null!=str_val.match(/^[\w0-9._%+-]+@[\w0-9.-]+\.[\w]{2,4}$/g);if(false==match){throw {code:1000,message:"Invalid Email Address",id:id};}};ASValidater.prototype.validateURL=function(str_val,id){var re_str="^((https?|ftp|mailto)://)"+"?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"+"(([0-9]{1,3}.){3}[0-9]{1,3}"+"|"+"([0-9a-z_!~*'()-]+.)*"+"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]."+"[a-z]{2,6})"+"(:[0-9]{1,4})?"+"((/?)|"+"(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";var match=new RegExp(re_str).test(str_val);if(false==match){throw {code:1100,message:"Invalid URL",id:id};}};ASValidater.prototype.validateInt=function(str_val,id){var return_val_one=false==isNaN(str_val);var return_val_two=false==isNaN(parseInt(str_val));var match=return_val_one&&return_val_two;if(false==match){throw {code:1200,message:"Invalid Integer",id:id};}};ASValidater.prototype.validateFloat=function(str_val,id){var return_val_one=false==isNaN(str_val);var return_val_two=false==isNaN(parseFloat(str_val));var match=return_val_one&&return_val_two;if(false==match){throw {code:1300,message:"Invalid Float",id:id};}};ASValidater.prototype.validateIP=function(str_val,id){var re_str="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)."+"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)."+"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)."+"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";var match=new RegExp(re_str).test(str_val);if(false==match){throw {code:1400,message:"Invalid IP Address",id:id};}};ASValidater.prototype.validateInputFields=function(frm){var self=this;frm.find(":input").each(function(idx,element){var element=$(element);if("submit"==element.attr("type")||"reset"==element.attr("type")||undefined==element.attr("validate")||""==element.attr("validate")){return;}switch(element.attr("validate").toLowerCase()){case"email":case"email_address":self.validateEmail(element.val(),element.attr("id"));break;case"url":self.validateURL(element.val(),element.attr("id"));break;case"int":case"integer":self.validateInt(element.val(),element.attr("id"));break;case"float":self.validateFloat(element.val(),element.attr("id"));break;case"ip":case"ip_address":self.validateIP(element.val(),element.attr("id"));break;default:break;}});};ASInclude("/core/ui/vendor/jquery/jquery.cookie.compressed.js");ASInclude("/core/ui/vendor/json2.compressed.js");ASInclude("/core/ui/classes/ASSanitizer.js");var AS_FORM;var ALCHITECT_VERSION="1.0.0.0";function ASApplication(){AS_FORM=new ASForm();AS_FORM.registerHook(AS_FORM.checkRequiredHook);}function page(){var path_parts=window.location.pathname.split("/");return path_parts[2];}function URLPath(with_app){var app_dir="ui";var new_parts=[];var x=0;var path_parts=window.location.pathname.split("/");var path_stop="app";if(null==with_app){with_app=false;}for(;x<path_parts.length;x++){if(false==with_app&&path_stop==path_parts[x]){break;}new_parts.push(path_parts[x]);if(app_dir==path_parts[x]){break;}}return new_parts.join("/").replace(/\/$/,"");}function ASInclude(file){document.write('<script type="text/javascript" src="'+URLPath()+file+'"><\/script>');}function ASAuthentication(username,password){if(null!=username&&null!=password){this.setAuthHash(username,password);}}ASAuthentication.prototype=new ASObject();ASAuthentication.prototype.authHash=function(){return $.cookie("auth_hash")||null;};ASAuthentication.prototype.authID=function(){return $.cookie("auth_id")||null;};ASAuthentication.prototype.logout=function(){$.cookie("auth_id",null);$.cookie("auth_hash",null);};ASAuthentication.prototype.setAuthHash=function(username,password){var data=JSON.stringify({"form_action":{"value":"set_authentication"},"username":{"value":username},"password":{"value":password}});$.post(URLPath()+"/server.php","form_name=authentication&json="+data,function(xhr_data,status){$.cookie("auth_hash",xhr_data.auth_hash);$.cookie("auth_id",username);},"json");return(null==this.authID()||null==this.authHash());};ASAuthentication.prototype.verifyAuthHash=function(username,auth_hash){var data=JSON.stringify({"form_action":{"value":"verify_authentication"},"username":{"value":(null==username?this.authID():username)},"auth_hash":{"value":(null==auth_hash?this.authHash():auth_hash)}});var _verified;$.ajax({type:"POST",async:false,url:URLPath()+"/server.php",data:"form_name=authentication&json="+data,dataType:"json",success:function(xhr_data,status){_verified=xhr_data.verified;},error:function(xhr,textStatus,errorThrown){console.log("VAH ERROR: %o, %s, %o",xhr,textStatus,errorThrown);}});return _verified;};function ASException(code,message){this.setCode(code);if(null==message){this.setMessage(this.exceptions[code]);}else{this.setMessage(message);}}ASException.prototype=new Error();ASException.AS_EXCEPTION_UNKNOWN=9999;ASException.AS_EXCEPTION_MISSING_ID=1000;ASException.messages=[ASException.AS_EXCEPTION_UNKNOWN="Unknown Exception",ASException.AS_EXCEPTION_MISSING_ID="Missing ID"];ASException.prototype.messageForExceptionCode=function(code){return this.messages[code];};ASException.prototype.setCode=function(code){this.code=code;};ASException.prototype.setMessage=function(message){this.message=message;};ASException.prototype.toString=function(){return"ASException ("+this.code+") "+this.message;};function ASForm(){this.form_submitted_callback=null;this.hooks=[];this.ignore_forms={};this.ready_to_submit=true;this.observeForms();}ASForm.prototype=new ASObject();ASForm.prototype._formSubmitted=function(data,status){if(null!=AS_FORM.form_submitted_callback){AS_FORM.form_submitted_callback(data,status);}};ASForm.prototype.ignoreForm=function(form_id){this.ignore_forms[form_id]=true;var foo=this.ignore_forms;};ASForm.prototype.observeForms=function(){var forms=document.getElementsByTagName("form");var x;for(x=0;x<forms.length;x++){$("#"+$(forms[x]).attr("id")).submit(this._prepare);}};ASForm.prototype._prepare=function(event){if(true==AS_FORM.ignore_forms[event.target.id]){return true;}var frm=$(event.target);var _data={};var x=0;var frm_action=frm.attr("action");if(null==frm_action.match(/^javascript/)){$(frm[0]).attr("action","javascript: void(0)");}frm.find(":input").each(function(idx,el){var element=$(el);if("submit"==element.attr("type")||"reset"==element.attr("type")){return;}if("radio"==element.attr("type")){if(true!==element[0].checked){return;}}if("checkbox"==element.attr("type")){if(true!==element[0].checked){return;}}_data[element.attr("name")]=element.attr("value");});for(x in AS_FORM.hooks){if(false==AS_FORM.hooks[x](frm)){return false;}}if(AS_FORM.ready_to_submit){if(undefined==_data["page"]){_data["page"]=page();}AS_FORM._submit(frm.attr("name")||frm.attr("id"),encodeURIComponent(JSON.stringify(_data,null,4)));}return false;};ASForm.prototype.registerFormSubmittedCallback=function(form_submitted_callback){this.form_submitted_callback=form_submitted_callback;};ASForm.prototype.registerHook=function(hook){AS_FORM.hooks.push(hook);};ASForm.prototype._submit=function(form_name,data){$.post(URLPath()+"/core/server.php","&form_name="+form_name+"&json="+data,this._formSubmitted,"json");};ASForm.prototype.checkRequiredHook=function(frm){var ready_to_submit=true;var required=frm.find('input[required="true"]');required.each(function(idx,el){var element=$(el);if(""==element.val()){element.parent().addClass("error_input");ready_to_submit=false;if(0==idx){element.focus();}}else{element.parent().removeClass("error_input");ready_to_submit=true;}});return ready_to_submit;};function ASObject(){this.id=0;}ASObject.prototype=new Object();ASObject.prototype.id=function(){return this.id;};ASObject.prototype.setID=function(id){this.id=id;};ASObject.prototype.setValueForKey=function(key,value){var method="set"+key;if(this.method){this.method(value);}else{this.key=value;}return this;};ASObject.prototype.valueForKey=function(key){var value=null;var method="get"+key;if(this.method){value=this.method();}else{value=this.key;}return value;};function ASUnitTest(log_to_console){this.log_to_console=log_to_console||false;this.failed_list=[];this.failed=0;this.passed=0;}ASUnitTest.prototype.run=function(){if(this.setup){this.setup();}for(method in this){if(method.match(/^test/)){if(this.log_to_console){console.log("TESTING: %s()",method);}if(true===this[method]()){this.passed++;}else{this.failed++;this.failed_list.push(method);}}}if(this.log_to_console){console.log("PASSED: %d, FAILED: %d",this.passed,this.failed);}};ASUnitTest.prototype.assertTrue=function(x){return true==x;};ASUnitTest.prototype.assertFalse=function(x){return false==x;};ASUnitTest.prototype.assertNull=function(x){return null==x;};ASUnitTest.prototype.assertNotNull=function(x){return null!=x;};ASUnitTest.prototype.assertIsA=function(x,t){return x.prototype.isPrototypeOf(t);};ASUnitTest.prototype.assertEqual=function(x,y){return x==y;};ASUnitTest.prototype.assertNotEqual=function(x,y){return x!=y;};ASUnitTest.prototype.assertIdentical=function(x,y){return x===y;};ASUnitTest.prototype.assertNotIdentical=function(x,y){return x!==y;};ASUnitTest.prototype.assertWantedPattern=function(p,x){return null!=x.match(p);};ASUnitTest.prototype.assertNoUnwantedPattern=function(p,x){return null==x.match(p);};function ASUnitTests(log_to_console){this.unit_tests={"UnitTestTest":ASUnitTestTest,"ObjectTest":ASObjectTest};this.log_to_console=log_to_console||false;this.tests=[];this.passed=0;this.failed=0;this.total=0;}ASUnitTests.prototype.unitTests=function(){return this.unit_tests;};ASUnitTests.prototype.run=function(){var x=null;for(x in this.unit_tests){if(this.log_to_console){console.log("RUNNING: %s",this.unit_tests[x]);}var _test=new this.unit_tests[x](this.log_to_console);this.passed+=_test.passed;this.failed+=_test.failed;this.total++;this.tests.push(_test);}};function ASValidater(){}ASValidater.prototype=new ASObject();ASValidater.prototype.validateEmail=function(str_val,id){var match=null!=str_val.match(/^[\w0-9._%+-]+@[\w0-9.-]+\.[\w]{2,4}$/g);if(false==match){throw {code:1000,message:"Invalid Email Address",id:id};}};ASValidater.prototype.validateURL=function(str_val,id){var re_str="^((https?|ftp|mailto)://)"+"?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"+"(([0-9]{1,3}.){3}[0-9]{1,3}"+"|"+"([0-9a-z_!~*'()-]+.)*"+"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]."+"[a-z]{2,6})"+"(:[0-9]{1,4})?"+"((/?)|"+"(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";var match=new RegExp(re_str).test(str_val);if(false==match){throw {code:1100,message:"Invalid URL",id:id};}};ASValidater.prototype.validateInt=function(str_val,id){var return_val_one=false==isNaN(str_val);var return_val_two=false==isNaN(parseInt(str_val));var match=return_val_one&&return_val_two;if(false==match){throw {code:1200,message:"Invalid Integer",id:id};}};ASValidater.prototype.validateFloat=function(str_val,id){var return_val_one=false==isNaN(str_val);var return_val_two=false==isNaN(parseFloat(str_val));var match=return_val_one&&return_val_two;if(false==match){throw {code:1300,message:"Invalid Float",id:id};}};ASValidater.prototype.validateIP=function(str_val,id){var re_str="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)."+"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)."+"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)."+"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";var match=new RegExp(re_str).test(str_val);if(false==match){throw {code:1400,message:"Invalid IP Address",id:id};}};ASValidater.prototype.validateInputFields=function(frm){var self=this;frm.find(":input").each(function(idx,element){var element=$(element);if("submit"==element.attr("type")||"reset"==element.attr("type")||undefined==element.attr("validate")||""==element.attr("validate")){return;}switch(element.attr("validate").toLowerCase()){case"email":case"email_address":self.validateEmail(element.val(),element.attr("id"));break;case"url":self.validateURL(element.val(),element.attr("id"));break;case"int":case"integer":self.validateInt(element.val(),element.attr("id"));break;case"float":self.validateFloat(element.val(),element.attr("id"));break;case"ip":case"ip_address":self.validateIP(element.val(),element.attr("id"));break;default:break;}});};