/* forms
 
@author Jacob at Goby
 @version 09/02/11
@svn goby_-150
*/

var msgCode={EMAIL:"email",DATE:"date",REQUIRED:"required",MATCH:"match",MIN_LEN:"minlen",ALPHA:"alpha",INT:"int",WORD:"word",FLOAT:"float",ALL:"all",UNIQUE:'unique',ZIPCODE:"zipcode",PHONE:"phone",CREDIT:"credit",URL:'url'}
function Validator(form)
{this.form=form;this.labels=this.form.getElementsByTagName("label");this.errorCnt=0;this.fields=new Array();this.fieldIndex={};for(var i in this.form.elements)
{var node=this.form.elements[i];if(node!=null)
this.fieldIndex[node.name]=node;}
if(this.labels.length)
{for(index in this.labels)
{var label=this.labels[index];if(label==undefined)
continue
try
{var fieldName=label.getAttribute("for");if(fieldName==null||!fieldName)
continue;}
catch(e)
{continue;}
if((fieldName)&&(this.fieldIndex[fieldName]!=undefined))
{var field=this.fieldIndex[fieldName];var inst2=label.className.match(/\[(.*?)\]/);if(!inst2)
continue;inst=inst2[1];var fieldItem={'label':label,'field':field,'ins':inst};this.fields.push(fieldItem);}}}}
Validator.scrolled=false;Validator.prototype.validate=function()
{while(this.fields.length>0)
{if(!this.validateField(this.fields.pop()))
this.errorCnt++;}
return this.errorCnt;}
Validator.prototype.validateField=function(fieldItem)
{var instructions=fieldItem.ins;var field=fieldItem.field;var label=fieldItem.label;var blah=instructions.split(":");var type=blah[0];var isRequired=(blah[1]==1?true:false);var msgParams=false;var valid=true;if(field.getValue!=null)
var value=field.getValue(1);else
var value=field.value;if(value&&value.length>0)
{switch(type)
{case"date":if(string=value.match(/^[0-9]{1,2}[/]{1}[0-9]{1,2}[/]{1}[0-9]{4}$/))
valid=true;else
{msgID=msgCode.DATE;valid=false;}
break;case"email":if(string=value.match(/^[0-9a-zA-Z_\.\+\-]+@([0-9a-zA-Z\.\+\-\_]+)[\.]{1}[a-zA-Z]{2,4}$/))
valid=true;else
{msgID=msgCode.EMAIL;valid=false;}
break;case"word":if(value.match(/^[a-zA-Z\-\'\.\W]+$/))
valid=true;else
{msgID=msgCode.WORD;valid=false;}
break;case"alpha":if(value.match(/^[A-Za-z ]+$/))
valid=true;else
{msgID=msgCode.ALPHA;valid=false;}
break;case"int":if(value.match(/^[0-9]+$/))
valid=true;else
{msgID=msgCode.INT;valid=false;}
break;case"url":if(value.match(/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/))
valid=true;else
{msgID=msgCode.URL;valid=false;}
break;case"float":if(value.match(/^[0-9\.\,]+$/))
valid=true;else
{msgID=msgCode.FLOAT;valid=false;}
break;case"zipcode":if(value.match(/^[0-9]{5}$/)?true:false)
valid=true;else
{msgID=msgCode.ZIPCODE;valid=false;}
break;case"phone":if(value.match(/(^([0-9]{3}|\([0-9]{3}\))[^0-9]{0,2}[0-9]{3}[^0-9]{0,2}[0-9A-Za-z]{4}$)/))
valid=true;else
{msgID=msgCode.PHONE;valid=false;}
break;case"credit":if(value.match(/^(\(??[0-9]{4}(?:\) |-)+?[0-9]{4}[-| ][0-9]{4}[-| ][0-9]{4})$/))
valid=true;else
{msgID=msgCode.CREDIT;valid=false;}
break;case"all":case"pwd":case"unique":valid=true;break;}}
else if(isRequired)
{var valid=false;msgID=msgCode.REQUIRED;}
else
{valid=true;}
if(blah[2]!=undefined)
{var advIns=blah[2].split("&");for(index in advIns)
{scrap=advIns[index].split("=");switch(scrap[0])
{case"matchField":var fieldName=scrap[1];var eField=this.fieldIndex[fieldName];if(valid)
{var valid=(eField.value==field.value?true:false);msgID=msgCode.MATCH;msgParams={field:eField.name}}
break;case"minlen":if(valid==true)
{var valid=(field.value.length>=scrap[1]?true:false);msgID=msgCode.MIN_LEN;msgParams={length:scrap[1]}}
break;}}}
if(!valid)
{$(label).addClass("error");$(field).addClass("error");if(!this.scrolled)
{$(window).scrollTo(field,500,'easeOutSine');this.scrolled=true;}
if(field.setError!=null)
{field.setError(this.getMsg(msgID,msgParams,fieldItem));}
else
{var error=new Link({nodes:[new Small({className:"validmsg"}),new Span({text:this.getMsg(msgID,msgParams,fieldItem)})],fnc:function(){$(this).remove();}});field.parentNode.appendChild(error);}
return false;}
else
{if(field.setError!=null)
{field.unsetError();}
else
{$(label).parent().contents(".validmsg").text('');$("#msg-"+field.name).text('');$("#msg-"+field.name).hide();}
$(label).removeClass("error");$(field).removeClass("error");return true;}}
Validator.prototype.getMsg=function(msgID,params,fieldObject)
{var label=(fieldObject.label.innerHTML?fieldObject.label.innerHTML:"This");switch(msgID)
{case msgCode.EMAIL:return"invalid email address";break;case msgCode.INT:return label+" needs to be a valid number";break;case msgCode.DATE:return"invalid date";break;case msgCode.WORD:return label+" needs letters and punctuation";break;case msgCode.ALPHA:return label+" needs to contain only word characters";break;case msgCode.URL:return label+" needs to be a valid url";break;case msgCode.PHONE:return label+" needs to be a valid phone number";break;case msgCode.CREDIT:return label+" needs to be a valid credit card number";break;case msgCode.REQUIRED:return"required "+label;break;case msgCode.MATCH:var msg=label+" must match";return msg;break;case msgCode.ZIPCODE:var msg=label+" must be a valid zipcode";return msg;break;case msgCode.MIN_LEN:var msg=label+" must be at least "+params.length+" characters long";return msg;break;default:return"there was an error, apparently";}}
var inputCnt=0;function Checkbox(params)
{if(params!=null)
return this._construct(params);}
Checkbox.prototype={type:"checkbox",tagName:"li",checked:false,_construct:function(params)
{this.settings=params;var node=this.generateInput();for(var i in this)
if(i!="tagName")
try{node[i]=this[i];}
catch(e){}
objects.push(this);objects.push(node);node.init();return node;},setWrapper:function(node)
{this.content=node;},getWrapper:function()
{return this.content;},select:function()
{this.checked=true;this.commit(true);},unselect:function()
{this.checked=false;this.commit(false);},close:function()
{var content=this.getElement();if(content.parentNode!=null)
content.parentNode.removeChild(content);},_destruct:function()
{this.close();for(i in this)
this[i]=null;},commit:function(ch)
{if(this.checked)
$(this.getWrapper()).addClass("selected");else
$(this.getWrapper()).removeClass("selected");if(this.ghost!=null)
this.ghost.check();},getValue:function()
{return this.settings.value;},getName:function()
{return this.getText();},getText:function()
{return this.settings.text;},getElement:function()
{return this.content;},_select:function()
{this.checked=true;this.commit(true);(this.optionSet!=null?this.optionSet._select(this):'');},_unselect:function()
{this.checked=false;this.commit(false);(this.optionSet!=null?this.optionSet._unselect(this):'');},customizeInput:function()
{try
{var span=document.createElement("div");span.handler=this;this.ghost=span;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");}}
span.check=function()
{if(this.handler.checked)
$(this).addClass("checkbox_on");else
$(this).removeClass("checkbox_on");}
$(span).addClass("checkbox");$(span).click(function(){(this.handler.checked?this.handler.unselect():this.handler.select())});return span;}
catch(e)
{}
return span;},generateInput:function()
{node=document.createElement("input"),node.value=this.settings.value;node.name=this.settings.field;if(this.settings.id)
node.id=this.settings.id;node.className=(this.settings.className?this.settings.className:"filterCheckbox");node.type=(this.type?this.type:"checkbox");this.checked=(this.settings.checked?this.settings.checked:false);node.onclick=function(e){(this.checked?this.select():this.unselect())};node.onfocus=function(e){this.ghost.emulate('focus')};node.onblur=function(e){this.ghost.emulate('blur')};return node;},getInput:function()
{return this;},displayLabel:function()
{this.label=document.createElement((this.settings.labelTag?this.settings.labelTag:"span"));this.label.innerHTML=this.getText();this.label.setAttribute("for",this.settings.field);return this.label;},init:function()
{if(this.content==null)
{this.content=document.createElement('li');this.content.appendChild(this.customizeInput());this.content.appendChild(this.displayLabel());}
return this.content;},settings:{text:null,value:null,field:null,labelTag:"span",count:0}}
function Radio(params)
{if(params)
return this._construct(params);}
Radio.prototype=new Checkbox();Radio.prototype.select=function()
{this.optionSet._select(this);this.checked=true;this.commit(true);}
Radio.prototype.unselect=function()
{return false;}
Radio.prototype.customizeInput=function()
{this.ghost=document.createElement("div");this.ghost.handler=this;$(this.ghost).addClass("radio");this.ghost.check=function()
{if(this.handler.checked)
$(this).addClass("radio_on");else
$(this).removeClass("radio_on");}
$(this.ghost).click(function(){(this.handler.checked?this.handler.unselect():this.handler.select())});return this.ghost;}
Radio.prototype.type="radio";function FilterCheckbox(params)
{if(params!=undefined)
return this._construct(params);}
FilterCheckbox.prototype=new Checkbox;FilterCheckbox.prototype.select=function()
{this.checked=true;this.commit(true);this.optionSet.selectOption(this);}
FilterCheckbox.prototype.unselect=function()
{this.checked=false;this.commit(false);this.optionSet.unselectOption(this);}
FilterCheckbox.prototype.setCount=function(count)
{this.settings.count=count;$(this.count).text(count);}
FilterCheckbox.prototype.getCount=function()
{return this.settings.count;}
FilterCheckbox.prototype.displayLabel=function()
{this.label=document.createElement((this.settings.labelTag?this.settings.labelTag:"span"));this.label.appendChild(document.createTextNode(this.getText().toLowerCase()));this.label.setAttribute("for",this.settings.field);try
{this.count=document.createElement("small");this.label.appendChild(document.createTextNode("  "));this.label.appendChild(this.count);}
catch(e)
{}
return this.label;}
function FilterRadio(params)
{if(params)
return this._construct(params);}
FilterRadio.prototype=new Radio;FilterRadio.prototype.select=function()
{this.checked=true;this.commit(true);this.optionSet.selectOption(this);}
FilterRadio.prototype.unselect=function()
{this.checked=false;this.commit(false);this.optionSet.unselectOption(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 FilterOption(params)
{if(params)
return this._construct(params);}
FilterOption.prototype=new Checkbox();FilterOption.prototype.generateInput=function()
{var node=document.createElement("option");return node;}
FilterOption.prototype.type="option";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)
{if(params)
return this._construct(params,callback);}
Selector.prototype={_construct:function(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);node.optionIndex={};return node;},remove:function()
{try
{if(this.popup!=null)
this.popup.close();if(this.ghost.parentNode!=null)
this.ghost.parentNode.removeChild(this.ghost.parentNode);if(this.parentNode!=null)
this.parentNode.removeChild(this);this.ghost._destruct();}
catch(e)
{}},setZIndex:function(amt)
{if(this.popup!=null)
$(this.popup.getWrapper()).css("z-index",amt);},addOption:function(option,params)
{if(option!=null)
{option.innerHTML=option.text;}
else
{var option=document.createElement('option');option.value=params.value;option.text=params.label;option.innerHTML=params.label;option.className=(params.className!=undefined)?params.className:'';}
this.appendChild(option);this.ghost.addOption(option);option.selector=this;option.updateGhost=function()
{this.ghost.innerHTML=option.innerHTML?option.innerHTML:option.text;this.ghost.className=option.className;}
option.getGhost=function()
{return this.ghost;}
option.unselect=function()
{this.ghost.unselect();}
option.select=function(keep)
{this.selector.selectedIndex=this.index;this.ghost.highlight();this.selector.select(keep);}
this.optionIndex[option.value]=option;return option;},updatePreamble:function()
{this.ghost.updatePreamble();},getPreamble:function()
{return this.ghost.g_g_getPreamble();},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,noClick:true,position:"none",isProtected:true,isMask:false,prepend:true});this.popup.display();}},selectOption:function(index)
{if(this.optionIndex[index]!=null)
{if(this.getCurrent())
this.getCurrent().unselect();this.optionIndex[index].select();return this.optionIndex[index];}},select:function(keep)
{this.ghost.updatePreamble();if(!keep)
{this.ghost.displayPreamble();var callback=this.callback;if(callback!=null)
{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;},showOptions:function()
{return true;},show:function()
{this.ghost.show();},removeOptions:function(omit)
{},hideOptions:function()
{},_destruct:function()
{}}
function GhostFactory(params,selector)
{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.selector=selector;node.id=params.id;$(node).addClass(params.className);node.onclick=function(){}
this.node=node;this.node.fullHeight=0;return node;}
GhostFactory.prototype={setCurrent:function(option)
{this.currentOption=option;},g_g_getPreamble:function()
{return this.preamble;},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.innerHTML?option.innerHTML:option.text;},isOpen:function()
{if($(this).hasClass('inert'))
return false;else
return true;},selectPreamble:function()
{this.show();},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.innerHTML?option.innerHTML:option.text;this.preamble.ghost=this;this.preamble.onclick=function()
{this.ghost.selectPreamble();}
$(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.innerHTML;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();if(this.showOptions())
{this.hidePreamble();safeWrappers=[];safeWrappers[container.id]=container;this.setZIndex(1000);this.verifyClose=new keywordCloser(safeWrappers,{object:this,method:(this.selector.closeMethod?this.selector.closeMethod:"displayPreamble")});this.verifyClose.initStgClick(100);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()
{var whatever=this.selector.showOptions();if(whatever)
{for(var i in this.items)
{var item=this.items[i];$(item).show();}
return whatever;}
else
return false;},hideOptions:function()
{if(this.items)
this.selector.hideOptions();for(var i in this.items)
{var item=this.items[i];$(item).hide();}},hide:function()
{this.displayPreamble();this.hideOptions();},removeFrom:function()
{if(this.selector.parentNode)
$(this.selector.parentNode).removeClass('open');this.selector.remove();},remove:function()
{this.close();this._destruct();},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()
{for(var i in this)
try{this[i]=null;}catch(e){}}}
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();}},isEmpty:function()
{return this.length<1?true:false;},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)
{this.index[name]={data:value,name: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.data;},toStack:function()
{var stack=[];for(var i in this.index)
if(this.index[i]!=null)
stack.push(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()
{if(this.pointer==null)
this.reset();return this.pointer.data;},getCurrentPosition:function()
{var node=this.pointer;var i=0;this.reset();while(this.valid())
{i++;if(this.pointer===node)
break;this.next();}
this.pointer=node;return i;},setCurrent:function(name)
{this.pointer=this.index[name];},last:function()
{this.reset();while(this.valid())
{var _tmp=this.pointer;this.next();}
this.pointer=_tmp;konsole.log(this.pointer,'tell me please.');},getIndex:function()
{return this.pointer.name;},toArray:function()
{return this.index;},rewind:function()
{if(this.pointer&&this.pointer.prev!=null)
{this.pointer=this.pointer.prev;return true;}
else
this.pointer=null;},next:function()
{if(this.pointer&&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)
{if(params!=null)
return this._construct(params);}
Link.prototype={update:function(str)
{this.innerHTML=str;},_construct:function(params)
{var node=document.createElement("a");for(var i in this)
try{node[i]=this[i];}catch(e){}
for(var i in params)
try{node[i]=params[i];}catch(e){}
node.href=(params.href?params.href:"#"+Goby.conf('path.anchor'));if(params.className!=null)
node.className=params.className;if(params.id!=null)
node.id=params.id;if(params.fnc!=null)
{node.method=params.fnc;$(node).click(function(e)
{this.method(e);});}
if(params.widget)
node.widget=params.widget;if(params.popup!=null)
node.target="_new";if(params.text)
node.innerHTML=params.text;objects.push(node);try
{if((params.href==null||!params.href)&&(Goby.get("resultSet")!=null))
preserveParameters(node);}
catch(e)
{}
return node;},remove:function()
{if(this.parentNode)
this.parentNode.removeChild(this);this.widget=null;},_destruct:function()
{this.widget=null;this.targetNode=null;this.content=null;this.fnc=null;this.callback=null;$(this).empty();this.remove();}}
function ToggleLink(params)
{if(params.fnc)
params.callback=params.fnc;if(params.init)
params.className="sel";params.text=params.init?params.content.off:params.content.on;params.fnc=function(){this.toggle(this.on?false:true);};params.href=false;var node=this._construct(params);preserveParameters(node);node.on=params.init;node.textOff=params.textOff;node.callback=params.callback;return node;}
ToggleLink.prototype=new Link(null);ToggleLink.prototype.toggle=function(select)
{if(this.on==select)
return false;if(select)
{this.on=true;this.callback(this.on);this.innerHTML=this.content.off;if(this.useSlide)$(this.targetNode).slideDown(100);$(this).addClass('sel');}
else
{this.on=false;this.callback(this.on);if(this.useSlide)$(this.targetNode).slideUp(100);this.innerHTML=this.content.on;$(this).removeClass('sel');}}
function initField(field)
{field.searchbox=null;field.deletebox=$(field).parent().contents(".textbox_delete");field.container=(field.wrapper?$(field.wrapper):$(field).parent(".textbox").parent());if(field.storage==null)
field.storage=document.getElementById(browseMap[field.id].storage);field.default_value=field._default_value=$(field).attr("default_value");field.setAttribute('placeholder',field.default_value);field.button=document.getElementById(browseMap[field.id].inputLink);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).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).focus();});$(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.$destruct=function()
{this.deletebox.field=null;this.deletebox=null;for(var i in this)
{try{if(typeof this[i]=="Object")this[i]=null;}
catch(e){}}}
field.highlight(2);field.isDeletable();return field;}
function GrilleForm(params,admin)
{if(params)
{this.button={};this.admin=admin;this.actions={submit:''};this.fields={'name':new Field('portfolio_name','input'),'content':new Field('portfolio_content','textarea')};this.makeButton(0,"save",function(){this.form.submit(1)});this.makeButton(1,"apply",function(){this.form.submit(2)});this.makeButton(2,"close",function(){this.form.close()});return this._construct(params,admin);}}
GrilleForm.prototype={params:null,id:false,formClass:'portfolioForm',title:'',button:null,tableName:"dude",requireLogin:false,url:"portfolio.php",supress:function(e)
{},_construct:function(params,admin)
{if(this.button==null)
this.button={};if(this.fieldsets==null)
this.fieldsets=new List();if(params)
{this.id=(params.id?params.id:this.id);this.values=params.values;this.admin=admin;var form=document.createElement("form");form.className=(params.formClass?params.formClass:this.formClass);for(var i in this)
if(i!="title")
form[i]=this[i];if(!this.fieldsets.valid('primary'))
this.addFieldset('primary',new FieldSet(this.fields,{legend:this.title}));form._title=this.title;form.onsubmit=function(e)
{this.submit('save');return false;}
objects.push(form);return form;}
else
{}
return null;},getFieldset:function(id)
{return this.fiedsets.get(id);},getTitle:function(){return this._title;},getID:function()
{return(this.values[this.index]!=null?this.values[this.index]:'');},setList:function(list)
{this.list=list},makeButton:function(type,text,fnc)
{if(this.button==null)
this.button={};this.button[type]=document.createElement("input");this.button[type].type="button";this.button[type].value=text;this.button[type].className="button-"+type;this.button[type].onclick=fnc;return this.button[type];},addFieldset:function(index,fieldset)
{if(this.fieldsets==null)
this.fieldsets=new List();this.fieldsets.add(index,fieldset);return fieldset;},display:function()
{while(this.fieldsets.valid())
{var node=this.fieldsets.getCurrent();if(node)
{node.append(this);this.appendChild(node);}
this.fieldsets.next();}
if(this.values!=null)
for(var i in this.fields)
this.fields[i].setValue(this.values[i]!=null?this.values[i]:'');this.buttonHolder=new Div({className:"button-set",nodes:this.button});if(this.fieldsets.length>1)
{this.appendChild(getClear());this.appendChild(this.buttonHolder);}
else
{this.fieldsets.get("primary").appendChild(getClear());this.fieldsets.get("primary").appendChild(this.buttonHolder);}},close:function(data)
{this.fieldsets.reset();while(this.fieldsets.valid())
{this.fieldsets.getCurrent().clear();this.fieldsets.next();}
if(this.parentNode!=null)
this.parentNode.removeChild(this);if(this.admin)
this.admin.currentForm=null;if(this.popup!=null)
this.popup.close();this._destruct();},ende:function(data)
{if(data.msg)
this.admin.displayMsg(data.msg);else if(data.error)
this.admin.displayMsg(data.error,true);else
this.admin.displayMsg({message:'whoops, technical glitch'},true);},_destruct:function()
{for(var i in this)
try{this[i]=null;}
catch(e){}
killself(this);},validate:function()
{var error=false;if(this.msg!=null&&this.msg.parentNode!=null)
try{$(this.msg).fadeOut(100);}catch(e){}
if(this.request!=null)
this.request.terminateRequest();var myValidator=new Validator(this);try
{var data={action:this.actions.submit};this.fieldsets.reset();while(this.fieldsets.valid())
{var fieldset=this.fieldsets.getCurrent();fieldset.unsetError();if(!fieldset.validate())
var error=true;var fields=fieldset.getFields();for(var i in fields)
if(fields[i]!=null)
data[fields[i].name]=fields[i].getValue();this.fieldsets.next();}
if(myValidator.validate()>0)
return false;if(error==true)
return false;this.values=data;return this.values;}
catch(e)
{konsole.log(e);return false;}},updatePhoto:function()
{konsole.log('sending update photo signal');if(this.customerImage&&this.customerImage.tagName!="IMG")
{var node=Goby.get('customer').getCustomerImage('48x48');this.customerImage.parentNode.replaceChild(node,this.customerImage);this.customerImage=node;}},getCustomerImage:function()
{if(this.customerImage)
return this.customerImage;if(Goby.get('customer'))
this.customerImage=Goby.get('customer').getCustomerImage('48x48');else
this.customerImage=new Span({text:"",className:"customer-avatar",id:"non-user"});return this.customerImage;},submit:function(method)
{var data=this.validate();if(data)
{if(!this.requireLogin||Goby.promptLogin({object:this,method:'submit'}))
{if(this.requireLogin&&this.customerImage)
this.updatePhoto();this.request=new AjaxRequest(this.url,{object:this,method:"ende"},data,"POST");this.request.makeRequest({useLoader:true,loaderParent:this.buttonHolder,loaderClass:"form_loader",append:true});}}},setCallback:function(callback)
{this.callback=callback;},runCallback:function(data)
{return this.callback.object[this.callback.method](data);}}
function Field(params)
{if(params)
return this._construct(params)}
Field.prototype={tip:'',fieldType:"text",_construct:function(params)
{if(this.PARENT&&this.PARENT.CLASS)
for(var i in this.PARENT.CLASS)
this[i]=this.PARENT.CLASS[i];if(this.CLASS)
for(var i in this.CLASS)
this[i]=this.CLASS[i];this.params=params;this.tag=this.tag?this.tag:"input";var node=document.createElement(this.tag);this.validation=(this.params.v?this.params.v:false);this.default_value=(this.params.default_value?this.params.default_value:'');if(params.id)
this.id=this.params.id;this.tip=this.params.tip;for(var i in this)
node[i]=this[i];node.id='field-'+this.params.name;if(this.params.default_value)
{node.default_value=this.params.default_value;}
if(node.default_value)
node.setAttribute('default_value',node.default_value);try{if(this.tag=="input")
node.setAttribute("type",this.fieldType);}
catch(e){}
node.params=this.params;node.name=this.params.name;node.formNode=params.form;(params.value!=null?node.setValue(params.value):'');objects.push(node);return node;},remove:function()
{this.close();},getValidation:function()
{if(this.validation)
return this.validation;else
return'';},setValue:function(value)
{if(value)
this.value=value;},getValue:function()
{if(this.default_value&&this.value==this.default_value)
return'';else
return this.value;},close:function()
{if(this.getNode())
this.getNode().parentNode.removeChild(this.getNode());},displayLabel:function()
{if(this.params.label)
{var label=document.createElement("label");label.innerHTML=this.params.label;label.className=this.getValidation();label.setAttribute("for",this.getAttribute("name"));this.label=label;return label;}
else
return new Span({text:''});},hasTip:function()
{},displayTip:function(text)
{var text=(text?text:this.tip);if(text)
this.wrapper.appendChild(new Span({className:'tip',text:text}));},displayMsg:function()
{return null;},setError:function(text)
{if(this.msg)
this.msg.remove();this.msg=new Span({className:"validmsg",text:"<div class=\"ico-bad\"></div><span>"+text+'</span>'});$(this.getNode()).prepend(this.msg);},unsetError:function()
{if(this.label)
$(this.label).removeClass('error');if(this.msg)
this.msg.remove();},displayWrapper:function()
{this.wrapper=document.createElement("div");this.wrapper.className="form-item";this.wrapper.id=this.name;this.wrapper.appendChild(this.displayLabel());this.wrapper.appendChild(this);this.displayTip(this.tip);this.wrapper.appendChild(getClear());return this.wrapper;},getNode:function()
{return this.wrapper;},display:function()
{this.wrapper=this.displayWrapper();return this.wrapper;}}
function HiddenField(params)
{if(params)
return this._construct(params);}
HiddenField.prototype=new Field();HiddenField.prototype.fieldType="hidden";HiddenField.prototype.display=function(){return this;}
HiddenField.prototype.getValue=function(){return this.value}
function makeOption(val,label)
{var node=document.createElement('option');node.setAttribute('value',val);node.innerHTML=label;return node;}
function Div(params,proto)
{if(!proto)
return this._construct(params);}
Div.prototype={tag:'div',_construct:function(params)
{if(this.PARENT&&this.PARENT.CLASS)
for(var i in this.PARENT.CLASS)
this[i]=this.PARENT.CLASS[i];if(this.CLASS)
for(var i in this.CLASS)
this[i]=this.CLASS[i];var node=document.createElement(this.tag);for(var i in this)
try{node[i]=this[i]}catch(e){konsole.log(i)}
if(params)
{for(var i in params)
{if(i=="prefix")
node.borderName=params.prefix;else
{try{node[i]=params[i]}
catch(e){konsole.log(e)}}}
if(params.id)
node.id=params.id;if(params.display)
node.style.display=params.display;if(params.nodes)
for(var i in params.nodes)
try
{if(params.nodes[i]!=null)
node.appendChild(params.nodes[i])}
catch(e)
{konsole.log(params.nodes[i]);}
if(params!=null&&params.text)
node.innerHTML=(params.text?params.text:'');}
objects.push(this);node.render(params);return node;},remove:function()
{if(this.parentNode)
this.parentNode.removeChild(this);this._destruct();},update:function(txt)
{this.innerHTML=txt;},getValue:function()
{return this.innerHTML;},truncate:function(len)
{var count=0;var length=this.recurseLengths(this,len,count);},recurseLengths:function(node,len,count)
{for(var i=0;i<node.childNodes.length;i++)
{var child=node.childNodes[i];var string=$(child).text();var count=count+string.length;if($(child).is(":visible"))
count=this.recurseLengths(child,len,count);if(count>len)
node.removeChild(child);}
return count;},render:function()
{},_destruct:function()
{if(this.nodes)
for(var i in this.nodes)
this.nodes[i]=null;$(this).empty();for(var i in this)
try{this[i]=null;}catch(e){}
this.CLASS=null;Goby._kill(this);},CLASS:[]}
function UL(params)
{return this._construct(params);}
UL.prototype=new Div(null,1);UL.prototype.tag="ul";function Border(params)
{if(params.keinWgt)
params.className=(params.type?params.type:'head');else if(!params.className)
params.className="widget-"+(params.type?params.type:'head');else
params.className=params.className+(params.type?params.type:'');return this._construct(params);}
Border.prototype=new Div(null,1);Border.prototype.render=function()
{this.innerHTML="<p class=\"r\"></p><p class=\"l\"></p>";}
function BorderWrapper(params)
{this.tag=(params.tag?params.tag:this.tag);this.params=params;return this._construct(params);}
BorderWrapper.prototype=new Div(null,1);BorderWrapper.prototype.render=function()
{var head=new Border({className:this.borderName,type:"head"});var content=this.node;var foot=new Border({className:this.borderName,type:"foot"});if(content.parentNode!=null)
content.parentNode.insertBefore(this,content);$content=$(content);$(this).css("marginTop",$content.css("marginTop"));$(this).css("marginBottom",$content.css("marginBottom"));$(this).css("marginRight",$content.css("marginRight"));$(this).css("marginLeft",$content.css("marginLeft"));$content.css("margin",0);this.appendChild(head);this.appendChild(content);this.appendChild(foot);}
function Span(params)
{if(params)
return this._construct(params);}
Span.prototype=new Div(null,1);Span.prototype.tag="span";function Small(params)
{return this._construct(params);}
Small.prototype=new Div(null,1);Small.prototype.tag="small";function P(params)
{return this._construct(params);}
P.prototype=new Div(null,1);P.prototype.tag="p";function LI(params,child)
{if(child==null)
return this._construct(params);}
LI.prototype=new Div(null,1);LI.prototype.tag="li";function Head(params)
{this.tag="H"+(params.type?params.type:3);return this._construct(params);}
Head.prototype=new Div(null,1);function IFrame(params)
{return this._construct(params);}
IFrame.prototype=new Div(null,1);IFrame.prototype.tag="iframe";function TableCell(params)
{return this._construct(params);}
TableCell.prototype=new Div(null,1);TableCell.prototype.tag="td";function TableRow(params)
{return this._construct(params);}
TableRow.prototype=new Div(null,1);TableRow.prototype.tag="tr";function Table(params)
{return this._construct(params);}
Table.prototype=new Div(null,1);Table.prototype.tag="table";function EggTimer(date)
{var node=this._construct({className:"egg-timer"});node.date=date;node.renderTime();return node;}
EggTimer.prototype=new Span(null);EggTimer.prototype.renderTime=function()
{this.innerHTML=this.getText();}
EggTimer.prototype.getText=function()
{var now=new Date();var diff=(now.getTime()/1000)-(this.date.getTime()/1000);for(var i in this.sequence)
{if(diff<i)
{var val=Math.floor(diff/this.sequence[i].m);var date=this;this.timeout=setTimeout(function(){date.renderTime();},this.sequence[i].m*1000);if(val<=1)
return"about a "+this.sequence[i].l+" ago";else
return val+"&nbsp;"+this.sequence[i].l+"s ago";}}}
EggTimer.prototype.sequence={3600:{m:60,l:"minute"},86400:{m:3600,l:"hour"},604800:{m:86400,l:"day"},2592000:{m:648000,l:"week"},31536000:{m:2592000,l:"month"},999999999999:{m:31536000,l:"year"}}
function FlashBar(params)
{var node=this._construct({text:params.text,id:'flashbar'});node.params=params;$(node).click(function()
{this.flash()});return node;}
FlashBar.prototype=new Div(null,1);FlashBar.prototype.start=function()
{$(this).fadeIn(this.params.speed);var node=this;this.timeout=setTimeout(function()
{try{node.flash();}
catch(e)
{}},this.params.time);}
FlashBar.prototype.flash=function()
{try{$(this).fadeOut(this.params.speed,function(){this.remove!=null?this.remove():null})}
catch(e){}
if(this.timeout!=null)
clearTimeout(this.timeout);}
function FieldSet(fields,params)
{if(fields==null&&params==null)
return false;this.fields={};if(!params.nodes)
params.nodes=[];var node=this._construct(params);for(var i in fields)
node.add(fields[i]);return node;}
FieldSet.prototype=new Div(null,1);FieldSet.prototype.CLASS={render:function(params)
{this.appendChild(this.generateLegend(params));this.content=new Div({className:"content"});this.appendChild(this.content);},hidden:false,tag:"fieldset",isFieldset:true,getField:function(id)
{return this.fields[id];},getFields:function()
{return this.fields;},setValue:function(field)
{},setError:function(txt)
{if(this.msg)
$(this.msg).remove();this.msg=document.createElement('legend');this.msg.className='error';$(this).addClass("error");this.msg.appendChild(new Span({className:'validmsg',text:"<div class=\"ico-bad\"></div>"+txt}));$(this).prepend(this.msg);$(window).scrollTo(this.msg,100,'easeOutSine');},unsetError:function()
{if(this.msg)
if(this.msg.parentNode!=null)
$(this.msg).fadeOut(500,'easeOutSine',$(this.msg).remove());$(this).removeClass("error");this.msg=null;},validate:function()
{return true;},add:function(field)
{if(field)
{this.remove(field.name);this.fields[field.name]=field;this.fields[field.name].fieldset=this;if(!this.hidden)
{if(field.display)
this.content.appendChild(field.display());}}},append:function(form)
{for(var i in this.fields)
form.fields[i]=this.fields[i];},remove:function(id)
{if(this.fields[id]!=null)
{try{this.fields[id].remove();this.fields[id]=null;}
catch(e){konsole.log(e);}}},clear:function()
{for(var i in this.fields)
{this.remove(i);this.fields[i]=null;}},close:function()
{this.clear();this.parentNode.removeChild(this);},display:function()
{},toggleView:function()
{this.hidden=this.hidden?false:true;this.hidden?$(this.legend).addClass('collapsed'):$(this.legend).removeClass('collapsed');this.hidden?$(this.content).fadeOut(500):$(this.content).fadeIn(500);this.toggleCallback();},toggleCallback:function(){},generateLegend:function(params)
{if(params.legend)
{this.legend=document.createElement(navigator.isBrowser(browser.SAFARI)?"h2":'legend');if(params.collapsable)
{this.legend.className="collapsable";this.legend.appendChild(new Link({widget:this,text:params.legend,fnc:function(){this.widget.toggleView();}}));}
else
this.legend.innerHTML=params.legend;return this.legend;}
else
{return new Div();}}}
function ImageUploader(params)
{this.params=params;var node=document.createElement("iframe");node.setAttribute('frameborder','0');node.setAttribute('border','0');node.setAttribute('cellspacing','0');node.setAttribute('frameborders','0');node.frameborder="0";node.border="0";this.callback=this.params.callback;for(var i in this)
node[i]=this[i];node.setHandle();node.render();objects.push(node);node.frameBorder="0";node.setAttribute('frameBorder',"0");return node;}
ImageUploader.prototype={setHandle:function()
{if(!Goby.has('imageUploaders'))
{var uploader=[];Goby.set('imageUploaders',uploader);this.handle=1;}
else
{var uploader=Goby.get("imageUploaders");this.handle=uploader.length+1;}
uploader[this.handle]=this;this.params.info.objectName=this.handle;},render:function()
{var params=this.params;var addr='';for(var i in this.params.info)
addr+=i+"="+this.params.info[i]+"&";this.frameborder=0;this.src=(params.src?params.src+"?"+addr:Goby.conf('path.ajax')+"user/renderImageForm?"+addr);this.width=(params.width?params.width:225);this.border=(params.border?params.border:0);this.frameborder=0;this.border=0;this.setAttribute('border','0');this.setAttribute('cellspacing','0');this.setAttribute('frameBorder','0');this.height=(params.height?params.height:74);},callback:null,upload:function(data)
{if(this.criteria!=null&&this.criteria.current!=null)
$(this.criteria.current).removeClass("active");if(data.error)
this.displayError(data.error);else
this.callback.object[this.callback.method](data);},loadFile:function(f)
{if(f)
{homeDiv=f;var container=homeDiv.parentNode;var loading=document.createElement("div");loading.innerHTML="<span>uploading photo</span>";loading.className="default_loader";$(homeDiv).hide();container.appendChild(loading);}},displayError:function(error)
{if(this.criteriaNodes!=null&&this.criteriaNodes[error.code]!=null)
{this.criteria.current=this.criteriaNodes[error.code];$(this.criteria.current).addClass('active');jQuery(this.criteria.current).animate({opacity:0.2},200);jQuery(this.criteria.current).animate({opacity:1},200);}
else if(this.criteria)
{var errorNode=document.createElement("div");errorNode.innerHTML="<p>"+error.message+"</p>";errorNode.id="image-error";$(errorNode).fadeIn(500);$(this.criteria).prepend(errorNode);}
else
{alert(error.message);}},displayCriteria:function()
{var list=document.createElement("ol");try
{this.criteriaNodes={'type':new LI({text:"Your image must be a gif, jpeg or png"}),'size':new LI({text:"Your image must be under 976kb (1 MB) in size"})}
for(var i in this.criteriaNodes)
list.appendChild(this.criteriaNodes[i]);var node=document.createElement("div");this.criteria=node;this.criteria.id="image_criteria";this.criteria.appendChild(list);return this.criteria;}
catch(e)
{alert(e.message);}},close:function()
{if(this.criteria)
this.criteria.parentNode.removeChild(this.criteria);this.parentNode.removeChild(this);}}
function ServiceImage(data)
{var ghostbar=$("#imageGhosts").get(0);var thumbnail=new Image();thumbnail.src=data.thumbnail;if(data.type&&data.type=="google")
{var watermark=new Div({className:"watermark-google"});var li=new LI({className:"serviceImage",nodes:[watermark,thumbnail]});}
else
var li=new LI({className:"serviceImage",nodes:[thumbnail]});if(data.ghost)
{li.ghost=data.ghost;li.ghost.data=data;}
else
li.data=data;li.url=data.url;var src=data.thumbnail;li.onclick=function()
{if(this.url)
window.open(this.url,"_blank");}
$(li).hover(function()
{if(this.popup==null)
{this.popup=new ImagePopup(this.ghost?this.ghost:this);this.popup.display();}},function()
{if(this.popup!=null)
{this.popup.close();this.popup=null;}});return li;}
ServiceImage.prototype.getPhoto=function()
{return this.img;}
function ImagePopup(container)
{try
{this.data=container.data;this.container=container;this.content=new Div({});this.generateImage();}
catch(e)
{konsole.log(e);}}
ImagePopup.prototype=new Popup(null);ImagePopup.prototype.isShell=true,ImagePopup.prototype.stem=true,ImagePopup.prototype.wrapperClass="thumbnailPopup";ImagePopup.prototype.noClick=true;ImagePopup.prototype.position="top";ImagePopup.prototype.isMask=false;ImagePopup.prototype.follow=true;ImagePopup.prototype.prepend=true;ImagePopup.prototype.callback=function(img)
{if(img)
{var caption=new Div({});caption.className="popupCaption";caption.innerHTML="<strong>"+this.data.title+"</strong><span>"+this.data.source+"</span>";var content=this.getNode();content.appendChild(caption);img._destruct();this.positionContent();}}
ImagePopup.prototype.generateImage=function()
{this.preloader=new ImagePreloader
(this.data.full,this.getNode(),{loaderStyle:"loader_popup",callback:{object:this,method:"callback"}});}
function SearchImage(data,widget)
{this.data=data;this.widget=widget;return this._construct({className:"searchImage"});}
SearchImage.prototype=new Div(null,1);SearchImage.prototype.tag="li";SearchImage.prototype.render=function()
{var imageData=this.data;var link=new Link({fnc:function(){this.widget.setValue(this.image.src)},widget:this.widget});link.image=new ImagePreloader(imageData.thumbnail,link,{});$(link.image).css('opacity',0.8);link.image.onmouseover=function(){$(this).fadeTo(200,1.00);}
link.image.onmouseout=function(){$(this).fadeTo(200,0.8);}
this.appendChild(link);}
