/* forms
 
@author Jacob at Goby
 @version 03/10/10
@svn 120
*/

function Checkbox(params)
{if(params)
{this.settings=params;var node=document.createElement(this.tagName);for(var i in this)
if(i!="tagName")
node[i]=this[i];node.init();return node;}}
Checkbox.prototype={type:"checkbox",tagName:"li",checked:false,select:function()
{this.checked=true;this.checkbox.check(true);},close:function()
{if(this.parentNode!=null)
this.parentNode.removeChild(this);},_destruct:function()
{this.close();for(i in this)
this[i]=null;},unselect:function()
{this.checked=false;},getValue:function()
{return this.settings.value;},getName:function()
{return this.getText();},getText:function()
{return this.settings.text;},getElement:function()
{return this;},_select:function()
{this.checkbox.check(true);$(this).addClass("selected");if(this.optionSet!=null)
this.optionSet._select(this);},_unselect:function()
{this.checkbox.check(false);$(this).removeClass("selected");this.optionSet._unselect(this);},customizeInput:function(option)
{$(option).hide();var span=document.createElement("div");span.checkbox=option;option.span=span;option.span.emulate=function(e)
{switch(e)
{case"check":case"uncheck":this.check(false);break;case"focus":$(this).addClass("checkbox_focus");break;default:if($(this).hasClass("checkbox_focus"))
$(this).removeClass("checkbox_focus");}}
option.span.check=function(isInverted)
{if(!this.checkbox.checked)
$(this).removeClass("checkbox_on");else
$(this).addClass("checkbox_on");}
option.span.callback=function()
{if(!this.checkbox.checked)
$(this).removeClass("checkbox_on");else
$(this).addClass("checkbox_on");}
$(span).addClass("checkbox");$(span).insertAfter(option);$(span).click(function()
{checkbox=this.checkbox;$(checkbox).click();this.check('invert');$(checkbox).focus();})
option.check=function(checked)
{this.checked=checked;this.span.emulate('check');}
option.onfocus=function()
{this.span.emulate('focus');}
option.onblur=function()
{this.span.emulate('blur');}
return span;},generateInput:function()
{this.checkbox=document.createElement("input"),this.checkbox.value=this.settings.value;this.checkbox.name=this.settings.field+(Math.random()*200);this.checkbox.className="filterCheckbox";this.checkbox.type=(this.type?this.type:"checkbox");if(this.checked)
this.checkbox.checked=true;this.checkbox.option=this;this.checkbox.onclick=function()
{if(this.checked)
this.option.select();else
this.option.unselect();}
this.checkbox.check=function(checked)
{this.checked=checked;}
this.label.setAttribute("for",this.settings.field);return this.checkbox;},getInput:function()
{return this.checkbox;},init:function()
{this.checked;if(this.content==null)
{this.label=document.createElement((this.settings.labelTag?this.settings.labelTag:"span"));this.label.innerHTML=this.getText();this.appendChild(this.generateInput());this.appendChild(this.label);}},settings:{text:null,value:null,field:null,labelTag:"span",count:0}}
function Radio(params)
{if(params)
{this.settings=params;this.init();}}
Radio.prototype.customizeInput=function()
{$(option).css("width",1);$(option).css("height",1);$(option).css("border",0);$(option).css("position","absolute");$(option).css("left","-400px");var span=document.createElement("div");$(span).data("radio",option);option.span=span;$(span).addClass("radio");$(span).insertAfter(option);option.span.emulate=function(e)
{var radio=$(this).data("radio");switch(e)
{case"focus":if(this!==radio.optionset.currentOption)
$(radio.optionset.currentOption.span).removeClass("radio_focus");$(this).addClass("radio_focus");if(!$(this).hasClass("radio_on"))
{if(this!==radio.optionset.currentOption)
$(radio.optionset.currentOption.span).removeClass("radio_on");$(this).addClass("radio_on");}
break;case"click":if(!$(this).hasClass("radio_on"))
{$(this).addClass("radio_on");}
else
{$(this).removeClass("radio_on");}
break;case"blur":if($(this).hasClass("radio_focus"))
$(this).removeClass("radio_focus");break;default:if($(this).hasClass("radio_focus"))
$(this).removeClass("radio_focus");}}
$(span).click(function()
{radio=$(this).data("radio");if(radio.optionset.currentOption)
$(radio.optionset.currentOption.span).removeClass("radio_on");$(this).addClass("radio_on");$(radio).click();$(radio).focus();});}
Radio.prototype=new Checkbox();Radio.prototype.type="radio";function FilterCheckbox(params)
{if(params!=undefined)
{if(!params.field)
return null;this.settings=params;var node=document.createElement(this.tagName!=null?this.tagName:"li");for(var i in this)
{try{node[i]=this[i];}
catch(e){}}
objects.push(this);objects.push(node);node.init();return node;}}
FilterCheckbox.prototype=new Checkbox;FilterCheckbox.prototype.select=function()
{$(this).addClass("selected");this.checkbox.check(true);this.optionSet.selectOption(this);}
FilterCheckbox.prototype.setCount=function(count)
{this.settings.count=count;$(this.count).text(count);}
FilterCheckbox.prototype.getCount=function()
{return this.settings.count;}
FilterCheckbox.prototype.unselect=function()
{this.checkbox.check(false);$(this).removeClass("selected");this.optionSet.unselectOption(this);}
FilterCheckbox.prototype.init=function()
{this.label=document.createElement((this.settings.labelTag?this.settings.labelTag:"span"));try
{this.label.appendChild(document.createTextNode(this.getText().toLowerCase()));}
catch(e)
{}
this.count=document.createElement("small");this.label.appendChild(document.createTextNode("  "));this.label.appendChild(this.count);var option=this.generateInput();this.appendChild(this.checkbox);if(!navigator.isIE())
this.customizeInput(option);this.appendChild(this.label);}
function FilterRadio(params)
{this.settings=params;this.init();}
FilterRadio.prototype=new Radio;FilterRadio.prototype.select=function()
{this.optionSet.selectOption(this);}
function FilterLink(params)
{if(params)
{this.settings=params;var node=document.createElement("li");for(var i in this)
{try
{node[i]=this[i];}
catch(e){}}
node.init();objects.push(node);return node;}
else
{alert('wierd');}}
FilterLink.prototype=new FilterCheckbox;FilterLink.prototype.getElement=function()
{return this;}
FilterLink.prototype._select=function()
{$(this.content).addClass("selected");}
FilterLink.prototype._unselect=function()
{$(this.content).removeClass("selected");}
FilterLink.prototype.select=function()
{this._select();this.optionSet.selectOption(this);}
FilterLink.prototype.unselect=function()
{this._unselect();this.optionSet.unselectOption(this);}
FilterLink.prototype.setActive=function()
{$(this).removeClass("inert");}
FilterLink.prototype.setInactive=function()
{$(this).addClass("inert");}
FilterLink.prototype.init=function()
{if(this.content==null)
{if(this.settings.active)
{var link=document.createElement("a");link.appendChild(document.createTextNode(this.getText().toLowerCase()));this.appendChild(link);this.setActive();}
else
{var link=document.createElement("span");link.appendChild(document.createTextNode(this.getText().toLowerCase()));this.appendChild(link);this.setInactive();}
if(this.settings.all)
{var span=document.createElement("small");span.innerHTML="&nbsp;all";this.appendChild(span);}
$(this).addClass("filterLink");link.option=this;this.content=link;link.onclick=function()
{var data=window.compileLink(null,this);this.href=data.href;this.hash=data.hash;this.option.select();}}}
function Textarea(object)
{object.init=function()
{this.createContainer();if(!this.value)
this.sleep();this.onfocus=function()
{this.wake();}
this.onblur=function()
{this.sleep();}}
object.sleep=function()
{if(!this.value)
{this.value=this.getAttribute("default_value");$(this.container).addClass("asleep");}}
object.wake=function()
{if(this.value==this.getAttribute("default_value"))
this.value="";$(this.container).removeClass("asleep");}
object.fetchValue=function()
{if(this.value==this.getAttribute("default_value"))
this.value="";return this.value;}
object.createContainer=function()
{var parent=this.parentNode;var container=document.createElement("div");var top=document.createElement("div");var foot=document.createElement("div");container.className="textarea";top.className="ta-top";foot.className="ta-foot";parent.insertBefore(container,this);container.appendChild(top);container.appendChild(this);container.appendChild(foot);this.container=container;}
object.init();return object;}
initInput=function(obj)
{switch(obj.tagName)
{case"TEXTAREA":return Textarea(obj);break;case"INPUT":break;}}
function FilterOption(params)
{if(params)
{this.settings=params;var node=document.createElement("option");node.value=this.settings.value;node.name=this.settings.field;for(var i in this)
try{node[i]=this[i];}catch(e){}
node.init();return node;}}
FilterOption.prototype=new Checkbox();FilterOption.prototype.type="radio";FilterOption.prototype.getElement=function()
{return this;}
FilterOption.prototype.setCount=function(count)
{this.settings.count=count;if(this.getValue()==OPTION_ALL)
this.text=this.settings.label+" ";else
this.text=this.settings.label+" ("+this.settings.count+")";}
FilterOption.prototype.init=function()
{this.value=this.settings.value;this.name=this.settings.field;this.type=this.type;if(this.checked)
this.checkbox.selected=true;this.onselect=function()
{if(this.checked)
this.select();else
this.unselect();}
this.text=this.settings.label;}
FilterOption.prototype.unselect=function()
{if(this.checked)
this.checkbox.selected=false;};FilterOption.prototype.select=function()
{if(this.checked)
this.checkbox.selected=true;this.optionSet._dom.selectedIndex=this.checkbox.index;$(this).addClass("selected");if(this.settings.value!=OPTION_ALL)
this.optionSet.selectOption(this);};var keys={BACKSPACE:8,RETURN:13,DELETE:46,ESCAPE:27,DOWN:40,UP:38,TAB:9,RIGHT:39,LEFT:37,SPACE:32}
function Selector(params,callback)
{this.container=params.container;this.className=(params.className!=null?params.className:"suggestion_box");this.callback=callback;try
{this.dudeID=params.id;}
catch(e)
{}
if(!params.select)
{params.select=document.createElement("select");this.container.appendChild(params.select);}
var node=this.updateSelect(params.select);for(var i in this)
node[i]=this[i];objects.push(node);node.ghost=new GhostFactory({className:params.className,id:params.id});node.ghost.selector=node;node.ghost.onclick=function()
{$(this.selector).focus();}
return node;}
Selector.prototype={setZIndex:function(amt)
{if(this.popup!=null)
$(this.popup.getWrapper()).css("z-index",amt);},addOption:function(option)
{option.innerHTML=option.text;this.appendChild(option);var option2=document.createElement("option");this.ghost.addOption(option);option.selector=this;option.updateGhost=function()
{this.ghost.innerHTML=this.text;}
option.select=function(keep)
{$(this.selector).focus();this.selector.selectedIndex=this.index;this.ghost.highlight();this.selector.select(keep);}},updatePreamble:function()
{this.ghost.updatePreamble();},getContainer:function()
{return this.container;},display:function()
{if(this.popup==null)
{this.container.appendChild(this);this.container.appendChild(this.ghost);this.ghost.displayPreamble();var option=this.getCurrent();option.ghost.highlight();this.popup=new Popup({container:this.container,isShell:true,wrapperClass:"selectbox",content:this.ghost,stem:false,ratio:0,fixed:true,position:"none",isProtected:true,isMask:false,prepend:true});this.popup.display();}},select:function(keep)
{this.ghost.updatePreamble();if(!keep)
{this.ghost.displayPreamble();var callback=this.callback;if((callback!=null)&&(callback.callbackObject))
{callback.callbackObject[callback.callbackMethod](this.getCurrent());}}},getCurrent:function()
{if(this.options.length>0)
return this.options[this.selectedIndex];},updateSelect:function(select)
{var keywordList=select;keywordList.className="suggestion_box";$(keywordList).css("width",20);$(keywordList).css("height",20);keywordList.multiple=false;keywordList.keepOpen=false;$(keywordList).keyup(function(e)
{switch(e.which)
{case keys.RETURN:this.getCurrent().select();break;case keys.UP:case keys.DOWN:case keys.RIGHT:case keys.LEFT:this.ghost.hoverOption(this.getCurrent());break;case keys.ESCAPE:this.closeList();break;}})
keywordList.onchange=function()
{this.ghost.hoverOption(this.getCurrent());}
keywordList.getCurrent=function()
{return this.options[this.selectedIndex];}
keywordList.onblur=function()
{}
keywordList.onfocus=function(e)
{}
keywordList.onclick=function(e)
{this.ghost.hoverOption(this.options[this.selectedIndex]);}
return keywordList;},_destruct:function()
{this.parentNode.removeChild(this);}}
function GhostFactory(params)
{var node=document.createElement("ul");for(var i in this)
{node[i]=this[i];}
objects.push(this);objects.push(node);node.items=[];node.currentOption=null;node.id=params.id;$(node).addClass(params.className);this.node=node;this.node.fullHeight=0;return node;}
GhostFactory.prototype={setCurrent:function(option)
{this.currentOption=option;},setZIndex:function(mt)
{this.selector.setZIndex(mt);},hidePreamble:function()
{$(this).removeClass("inert");$(this.preamble).hide();},updatePreamble:function()
{var option=this.selector.getCurrent();if(!this.preamble)
this.displayPreamble();this.preamble.innerHTML=option.text;},isOpen:function()
{if($(this).hasClass('inert'))
return false;else
return true;},displayPreamble:function()
{if(this.verifyClose)
this.verifyClose.destruct();if(this.preamble==null)
{var option=this.selector.getCurrent();this.preamble=document.createElement("li");$(this.preamble).addClass("preamble");this.preamble.innerHTML=option.text;this.preamble.ghost=this;this.preamble.onclick=function()
{$(this.ghost.keywordList).focus();this.ghost.show();}
$(this).addClass("inert");this.appendChild(this.preamble);this.hideOptions();}
else
{$(this).addClass("inert");this.hideOptions();$(this.preamble).show();}
this.setZIndex(1);},unselectOption:function(option)
{if(option!=null)
option.ghost.unselect();else if(this.currentOption!=null)
this.currentOption.unselect();},hoverOption:function(option)
{this.unselectOption();var scroll=$(this).scrollTop();var h=parseInt($(this).innerHeight());var pos=parseInt($(option.ghost).position().top)-(h/2)+scroll;$(this).scrollTop(pos);option.ghost.select(1);},addOption:function(option)
{var item=document.createElement("li");item.innerHTML=option.text;item.option=option;item.ghost=this;option.ghost=item;this.appendChild(item);$(item).addClass("ghostOption");item.onmouseout=function()
{$(this).removeClass("hover");}
item.onmouseover=function()
{$(this).addClass("hover");}
$(item).dblclick(function(e)
{this.option.select();});item.highlight=function()
{this.ghost.setCurrent(this);$(this).addClass("active");$(this).removeClass("inactive");}
item.remove=function()
{this.parentNode.removeChild(this);}
item.unselect=function()
{$(this).removeClass("active");$(this).addClass("inactive");}
item.select=function(keep)
{this.highlight();this.option.select(keep);}
item.onclick=function(e)
{this.ghost.unselectOption();this.option.select();}
this.items.push(item);if(!this.isOpen())
$(item).hide();},show:function()
{var container=this.selector.getContainer();this.hidePreamble();safeWrappers=[];safeWrappers[container.id]=container;this.setZIndex(500);this.verifyClose=new keywordCloser(safeWrappers,{object:this,method:"displayPreamble"});this.verifyClose.initStgClick(100);this.showOptions();var option=this.selector.getCurrent();var scroll=$(this).scrollTop();var h=parseInt($(this).innerHeight());var pos=parseInt($(option.ghost).position().top)-(h/2)+scroll;$(this).scrollTop(pos);},showOptions:function()
{for(var i in this.items)
{var item=this.items[i];$(item).show();}},hideOptions:function()
{for(var i in this.items)
{var item=this.items[i];$(item).hide();}},hide:function()
{this.displayPreamble();this.hideOptions();},removeOptions:function()
{while(this.items.length>0)
{var item=this.items.pop();item.remove();}
this.currentOption=null;},setSize:function()
{var maxWidth=244;var maxHeight=90;var height=0;var width=0;var count=0;for(index in this.childNodes)
{var item=this.childNodes[index];if(item!=undefined)
{if(item.tagName=="LI")
{var txt=$(item).text();height+=parseInt($(item).css("height"))+parseInt($(item).css("paddingTop"))+parseInt($(item).css("paddingBottom"));var myWidth=8*txt.length;if(myWidth>width)
width=myWidth;}}}
if(!this.childNodes)
$(this).hide();maxWidth=(width>maxWidth?width:maxWidth);maxHeight=(height>maxHeight?height:maxHeight);var maxHeight=height;$(this).css("width",maxWidth);$(this).css("height",maxHeight);},removeOption:function(index)
{$(this).css("height",$(this).css("height")-10);this.currentOption=null;this.removeChild[index];},close:function()
{this.removeOptions();},_destruct:function()
{if(this.popup!=null)
this.popup.close();if(this.parentNode!=null)
this.parentNode.removeChild(this);for(var i in this)
this[i]=null;}}
function List()
{this.length=0,this.pointer=null;this.current=null;this.index={};}
List.prototype={length:0,clear:function()
{this.reset();while(this.valid())
{this.remove(this.getCurrent());this.next();}},remove:function(index)
{if(!this.valid(index))
return false;var current=this.index[index];if(current==this.current)
this.current=(current.prev!=null?current.prev:(current.next!=null?current.next:null));if(current==this.start)
this.start=(current.prev!=null?current.prev:(current.next!=null?current.next:null))
if(current.prev!=null)
current.prev.next=current.next;if(current.next!=null)
current.next.prev=current.prev;this.index[index]=null;this.length--;},add:function(name,value)
{if(this.index[name]!=null)
return false;this.index[name]={};this.index[name].data=value
this.index[name].next=null
if(this.current)
{this.current.next=this.index[name];this.index[name].prev=this.current;}
this.length++;this.current=this.index[name];if(this.start==null)
{this.start=this.current;this.pointer=this.start;}
return this.current;},toStack:function()
{var stack=[];for(var i in this.index)
if(this.index[i]!=null)
stack[i]=this.index[i].data;return stack;},get:function(index)
{if(this.index[index]!=null)
return this.index[index].data;},reset:function()
{this.pointer=this.start;},getCurrent:function()
{return this.pointer.data;},next:function()
{if(this.pointer.next!=null)
{this.pointer=this.pointer.next;return true;}
else
this.pointer=null;},valid:function(index)
{if(index)
return(this.index[index]?true:false);else
return(this.pointer!=null?true:false);}}
function Link(params)
{var node=document.createElement("a");node.href=(params.href?params.href:"#"+BASE_ANCHOR);node.method=params.fnc;node.onclick=function()
{this.method();};if(params.popup!=null)
node.target="_new";node.innerHTML=params.text;return node;}
function initField(field)
{field.searchbox=null;field.deletebox=$(field).parent().contents(".textbox_delete");field.container=$(field).parent(".textbox").parent(".textbox_container");field.default_value=$(field).attr("default_value");field.button=document.getElementById(browseMap[field.id].inputLink);field.storage=document.getElementById(browseMap[field.id].storage);field.button.field=field;if(browseMap[field.id].typeField!=null)
field.typeField=document.getElementById(browseMap[field.id].typeField);field.map=browseMap[field.id];field.active=false;$(field.button).click(function(e)
{e.stopPropagation();this.field.toggleMenu(1);});$(field.button).hover(function()
{$(this).addClass("textbox_link_hover");},function()
{$(this).removeClass("textbox_link_hover");});$(field.button).mouseover(function()
{$(this).addClass("textbox_link_hover");});$(field.button).mouseout(function()
{$(this).removeClass("textbox_link_hover");});$(field).click(function()
{this.closePanel();this.highlight(1);});$(field).focus(function()
{fieldID=jQuery(this).attr("id");this.highlight(1);});$(field).bind('keydown.self',function(e)
{if(e.which==keys.TAB)
{if(this.searchbox!=null)
this.searchbox.closeSuggestions();this.closePanel();this.highlight(2);}
else
{this.closePanel();this.highlight(1);}});$(field).keyup(function(e)
{if((e.which>=41&&e.which<=256)||(e.which==keys.BACKSPACE)||(e.which==keys.DELETE)||(e.which==keys.SPACE))
{this.storage.value='';this.isDeletable();}});field.deletebox.field=field;$(field.deletebox).data('field',field);$(field.deletebox).click(function()
{var field=$(this).data("field");field.closePanel();field.setValue('');field.storage.value='';});$(field).change(function(e)
{this.isDeletable();});field.isDeletable=function()
{if((this.value.length<1)||(this.value==this.default_value))
$(this.deletebox).hide();else
$(this.deletebox).show();}
field.setValue=function(value,type)
{if(this.typeField!=null)
this.typeField.value=(type?type:null);this._setValue(value);}
field._setValue=function(value)
{this.value=value.toLowerCase();$(this).focus();this.value=this.value.replaceAll("&","and");jQuery(this).parent(".textbox").addClass("textbox_active");jQuery(this).removeClass("asleep");jQuery(this).animate({opacity:0.2},200);jQuery(this).animate({opacity:1},200);this.isDeletable();}
field.dehighlight=function()
{this.highlight(2);}
field.highlight=function(toggle)
{if(toggle==2)
{if((!this.value)||(this.value==$(this).attr("default_value")))
{jQuery(this).parent(".textbox").addClass("asleep");jQuery(this).attr("value",$(this).attr("default_value"));}
jQuery(this).parent(".textbox").removeClass("textbox_active");this.active=false;this.closePanel();if(this.kCloser!=null)
{this.kCloser.destruct();this.kCloser=null;}}
else
{var safeWrappers={'keyword':this.container.get(0)};if(this.kCloser==null)
{this.kCloser=new keywordCloser(safeWrappers,{object:this,method:"dehighlight"});this.kCloser.initStgClick(100);}
jQuery(this).parent(".textbox").addClass("textbox_active");jQuery(this).parent(".textbox").removeClass("asleep");this.active=true;if(jQuery(this).attr("value")==$(this).attr("default_value"))
jQuery(this).attr("value","");activeTextbox=this;for(var box in this.searchbox.fields)
{var field=this.searchbox.fields[box];if(field!==this)
field.dehighlight();}}}
field.closePanel=function(track)
{if(this.panel!=null&&this.searchbox.isActivePanel(this.panel))
{this.panel.setTrackable(track?true:false);this.panel.close();}};field.openPanel=function(track)
{if(this.panel==null)
this.panel=new Panel(this);if(!this.searchbox.isActivePanel(this.panel))
this.searchbox.closeActivePanel();this.panel.setTrackable(track?true:false);this.panel.open();};field.toggleMenu=function(track)
{if((this.panel!=null)&&(this.searchbox.isActivePanel(this.panel)))
this.closePanel(track);else
this.openPanel(track);};field.highlight(2);field.isDeletable();return field;}
function initKeywordField(field,params)
{field.deletebox=$(field).parent(".textbox").contents(".textbox_delete");field.default_value=$(field).attr("default_value");if(params)
for(var i in params)
field[i]=params[i];$(field).click(function()
{this.highlight(1);});$(field).focus(function()
{this.highlight(1);});$(field).blur(function()
{this.highlight(2);});$(field).bind('keydown.self',function(e)
{if(e.which==keys.TAB)
{this.highlight(2);}});$(field).keyup(function(e)
{if(e.which==keys.RETURN)
{this.form.submit();}
else if((e.which>=41&&e.which<=256)||(e.which==keys.BACKSPACE)||(e.which==keys.DELETE)||(e.which==keys.SPACE))
{this.isDeletable();}});field.deletebox.field=field;$(field.deletebox).data('field',field);$(field.deletebox).click(function()
{var field=$(this).data("field");field.setValue('');if(field.callback_delete!=null)
{field.callback_delete.object[field.callback_delete.method]();}});$(field).change(function(e)
{this.isDeletable();});field.isDeletable=function()
{if((this.value.length<1)||(this.value==this.default_value))
$(this.deletebox).hide();else
$(this.deletebox).show();}
field.setValue=function(value)
{this.value=value.toLowerCase();$(this).focus();this.value=this.value.replaceAll("&","and");jQuery(this).parent(".textbox").addClass("textbox_active");jQuery(this).removeClass("asleep");this.isDeletable();}
field.highlight=function(toggle)
{if(toggle==2)
{if((!this.value)||(this.value==$(this).attr("default_value")))
{jQuery(this).parent(".textbox").addClass("asleep");jQuery(this).attr("value",$(this).attr("default_value"));}
jQuery(this).parent(".textbox").removeClass("textbox_active");}
else
{if(this.value==$(this).attr("default_value"))
this.value="";jQuery(this).parent(".textbox").addClass("textbox_active");$(this).parent(".textbox").removeClass("asleep");}}
field.resetError=function()
{$(this).removeClass("error");$("#msg-"+this.name).html('');}
field.highlight(2);field.isDeletable();return field;}
var keys={BACKSPACE:8,RETURN:13,DELETE:46,ESCAPE:27,DOWN:40,UP:38,TAB:9,RIGHT:39,LEFT:37,SPACE:32}
function ajaxForm(f)
{f.submitCallback="realSubmit";f.REQUEST_URL=AJAX_PATH+"user_requests.php"
f.request=null;f.errorWrapper=$(f).find(".errorMain");f.setSubmitButton=function(button)
{$(button).click(function(){if(this.form)
this.form.submit();});this.button=button;}
f.hideError=function()
{$(this.errorWrapper).fadeOut(100);$(this.button).removeClass("signalInvalid");}
f.displayError=function(error)
{$(this.errorWrapper).text(error);$(this.errorWrapper).fadeIn(100);$(this.button).removeClass("signalValid");$(this.button).addClass("signalInvalid");}
f.getSubmitButton=function(label)
{try
{if(this[label]!=undefined)
return this[label];else if(this.elements[label]!=undefined)
return this.elements[label];}
catch(e)
{}
if(!this.submitButton)
{for(var i in this.elements)
{var elem=this.elements[i];if(elem!=null)
{if(elem.name==label)
button=elem;else
{switch(elem.type)
{case"button":case"submit":button=elem;break;}}}}
if(!button)
{var button=document.getElementById(label);if(button==null)
return false;}}
return button;}
f.fixSubmission=function()
{for(index in this.elements)
{if((this.elements[index])&&((this.elements[index].type=="text")||(this.elements[index].type=="password")))
{var element=this.elements[index];$(element).keypress(function(e){switch(e.which)
{case keys.RETURN:return false;break;}});$(element).keypress(function(e){switch(e.which)
{case keys.RETURN:return false;break;}});$(element).keypress(function(e){switch(e.which)
{case keys.RETURN:if(this.request==null)
this.form.submit();return false;break;default:break;}});}}}
f.hideMessage=function()
{$(this).find(".msg").text('');$(this.button).removeClass("signalValid");}
f.displayMessage=function(data)
{this.hideError();$(this).find(".msg").show();$(this).find(".msg").text(data);}
f.init=function()
{if(this.submitButton==undefined)
this.submitButton=this.getSubmitButton('submitButton');this.fixSubmission();this.setSubmitButton(this.submitButton);}
f.realSubmit=function(data)
{this.request=null;if(data.valid)
{this.hideError();if(data.location)
window.open(data.location,"_self");else
alert('cool, user is stored AND logged in or something');}
else
{this.displayError(data.error);}}
f.Submit=function()
{this.submit();}
f.powerText=function()
{for(index in this.elements)
{try
{switch(this.elements[index].type)
{case"textarea":initInput(this.elements[index]);break;case"text":case"password":initKeywordField(this.elements[index],{callback_delete:{object:this.elements[index],method:"resetError"}});break;}}
catch(e){;}}}
f.revalidate=function()
{var myValidator=new Validator(this);if(myValidator.validate()>0)
return false;}
f.submit=function()
{if(this.request==null)
{this.hideError();var myValidator=new Validator(this);if(myValidator.validate()>0)
return false;this.request=new AjaxRequest(this.REQUEST_URL,{object:this,method:this.submitCallback},this.requestElements());this.request.makeRequest();}}
f.requestElements=function()
{var data=new Array();for(j=0;j<this.elements.length;j++)
{switch(this.elements[j].type)
{case"textarea":data[this.elements[j].name]=this.elements[j].fetchValue();break;case"select-one":data[this.elements[j].name]=this.elements[j].options[this.elements[j].selectedIndex].value
break;case"checkbox":case"radio":if(!data[this.elements[j].name])
data[this.elements[j].name]=(this.elements[j].checked==true?this.elements[j].value:0);break;default:data[this.elements[j].name]=this.elements[j].value;}}
return data;}
f.validatePassword=function(data)
{this.request=null;if(data.valid)
{this.hideError();this.displayMessage(data.msg);}
else
{this.hideMessage();this.displayError(data.error);}}
return f;}
function initForm(fName,params)
{if(!document.forms[fName])
return false;var form=ajaxForm(document.forms[fName]);for(var i in params)
form[i]=params[i];form.init=function()
{if(!this.submitButton)
this.submitButton=this.getSubmitButton('submitButton');this.fixSubmission();this.setSubmitButton(this.submitButton);if(this.initCallback!=null)
this[this.initCallback]();this.powerText();}
return form;}
function initLoginForm(f)
{var loginForm=ajaxForm(f);loginForm.init=function()
{this.fixSubmission();this.submitButton.onclick=function()
{this.form.submit();};this.powerText();$(this).find(".passwordLink").data("form",this);$(this).find(".passwordLink").click(function()
{form=$(this).data("form");$("#alphaLink").text("Forgot your password?");if(!form.passwordForm)
{data={action:"displayForm",form_name:"password_form",form_type:"password"};var request=new AjaxRequest(form.REQUEST_URL,{object:$(this).data("form"),method:'genPwdForm'},data);request.makeRequest();}
else
{$(this).parents(".content").css("background-image","none");$(form.passwordForm).show();}
$(form).hide()})}
loginForm.realSubmit=function(data)
{$(".msg").fadeOut();this.request=null;if(data.valid)
{this.hideError();if(data.changepwd)
{$("#alphaLink").text("Reset Password");if(this.pwdForm!=undefined)
{$(this.pwdForm).show();}
else
{var ctr=document.createElement("div");$(ctr).html(data.tpl);$(this).hide();$(ctr).insertAfter(this);this.pwdForm=ajaxForm(document.forms[data.name]);this.pwdForm.powerText();this.pwdForm.realSubmit=function(data)
{if(data.valid)
{this.hideError();window.open(data.location,"_self");}
else
this.displayError(data.error);}
this.pwdForm.init();$(this).remove();}}
else if(data.location)
window.open(data.location,"_self");}
else
{this.displayError(data.error);}}
loginForm.genPwdForm=function(data)
{if(!this.passwordForm)
{$(this).parents(".content").css("background-image","none");$(".msg").fadeOut();var frmCtr=document.createElement("div");$(frmCtr).html(data.tpl);$(frmCtr).insertAfter(this);this.passwordForm=initForm(data.form_name,{submitCallback:"validatePassword",initCallback:"setLoginLink",setLoginLink:function()
{$(this).find(".loginLink").data("form",this);$(this).find(".loginLink").click(function()
{$("#alphaLink").text("Alpha Sign In");form=$(this).data("form");$(form.loginForm).show();$(form).hide()});}});this.passwordForm.loginForm=this;this.passwordForm.init();}}
loginForm.init();return loginForm;}
function LoginPopup(params)
{this.params=params;if(params.data)
this.data=params.data;}
LoginPopup.prototype={data:null,request:null,isClosed:function()
{if(this.popup!=null)
{return this.popup.closed;}
else
return true;},close:function()
{this.popup.close();},init:function()
{if(this.data==null)
{if(this.request==null)
{var content=document.createElement("div");data={action:"displayForm",form_name:this.params.form_name,form_type:this.params.form_type};this.request=new AjaxRequest(AJAX_PATH+"user_requests.php",{object:this,method:'displayRemote'},data);this.request.makeRequest();}}
else
this.display();},displayRemote:function(data)
{this.data=data;this.request._destruct();this.display();},getForm:function()
{return this.form;},_destruct:function()
{for(var i in this)
this[i]=null;},display:function()
{var data=this.data;var frmCtr=document.createElement("div");$(frmCtr).html(data.tpl);frmCtr.style.display="none";document.body.appendChild(frmCtr);switch(this.params.form_type)
{case"login":var loginForm=initLoginForm(document.forms[data.form_name]);break;default:this.params.popup=this;var loginForm=initForm(data.form_name,this.params);loginForm.init();}
var _content=document.getElementById(this.params.id);if(_content!=null)
_content.parentNode.removeChild(_content);var content=document.createElement("div");content.id=this.params.id;content.appendChild(loginForm);this.params.container.appendChild(content);this.popup=new Popup({container:this.params.container,content:content,fixed:(this.params.fixed!=null&&this.params.fixed?true:false),isMask:this.params.isMask,useBlind:(this.params.useBlind!=null?this.params.useBlind:false),mask:(this.params.mask?this.params.mask:"#wrapper"),position:"none",isCloser:(this.params.fixed!=null&&this.params.fixed?true:false),slidable:this.params.slidable,maskOpacity:(this.params.opacity?this.params.opacity:0),noClick:(this.params.noClick!=null?this.params.noClick:false)});loginForm.popup=this.popup;loginForm.lp=this;frmCtr.parentNode.removeChild(frmCtr);this.form=loginForm;this.popup.display();}}