
var TP={CHAR_CODE_ENTER:13,recursivelyCollect:function(element){var elements=[];while(element.nodeType==1){elements.push(element);if(element.parentNode!==null){element=element.parentNode;}else{break;}}
return elements;},ancestors:function(element){return this.recursivelyCollect(element);},getPagePosition:function(object){var x=0;var y=0;if(object.offsetParent){x=object.offsetLeft;y=object.offsetTop;while(object=object.offsetParent){x+=object.offsetLeft;y+=object.offsetTop;}}
return[x,y];},moveBetweenSelects:function(fromSelect,toSelect,callback){var firstSelectedIndex=null;for(var currentIndex=0;currentIndex<fromSelect.options.length;currentIndex++){var currentOption=fromSelect.options[currentIndex];if(currentOption.selected){if(!firstSelectedIndex){firstSelectedIndex=currentIndex;}
fromSelect.remove(currentIndex);try{toSelect.add(currentOption,null);}catch(e){toSelect.add(new Option(currentOption.text,currentOption.value));}
currentIndex--;}}
if((firstSelectedIndex-1)>-1&&fromSelect.options[firstSelectedIndex-1]!==undefined){fromSelect.selectedIndex=firstSelectedIndex-1;}else if(fromSelect.options[0]!==undefined){fromSelect.selectedIndex=0;}
if(typeof callback==='function'){callback();}},getSelectedIndexes:function(select){var selectedIndexes=[];for(var i=0;i<select.options.length;i++){if(select.options[i].selected){selectedIndexes.push(i);}}
return selectedIndexes;},selectSortUp:function(selectBox,callback){if(typeof selectBox.selectedIndex!=='undefined'){var selectedIndexes=TP.getSelectedIndexes(selectBox);for(var i=0;i<selectedIndexes.length;i++){var selectedIndex=selectedIndexes[i];if(selectedIndex>0&&selectedIndex<selectBox.options.length){var selectedOption=selectBox.options[selectedIndex];try{selectBox.add(selectedOption,selectBox.options[selectedIndex-1]);}catch(e){selectBox.add(new Option(selectedOption.text,selectedOption.value),selectBox.options[selectedIndex-1]);selectBox.remove(selectedIndex+1);}
if(typeof callback==='function'){callback();}}}}},selectSortDown:function(selectBox,callback){if(typeof selectBox.selectedIndex!=='undefined'){var selectedIndexes=TP.getSelectedIndexes(selectBox);selectedIndexes.reverse();for(var i=0;i<selectedIndexes.length;i++){var selectedIndex=selectedIndexes[i];if(selectedIndex>=0&&selectedIndex<selectBox.options.length){var selectedOption=selectBox.options[selectedIndex];if(selectedIndex<(selectBox.options.length-1)){try{selectBox.add(selectedOption,selectBox.options[selectedIndex+2]);}catch(e){selectBox.add(new Option(selectedOption.text,selectedOption.value),selectBox.options[selectedIndex+2]);selectBox.remove(selectedIndex);}}
if(typeof callback==='function'){callback();}}}}},characterCode:function(e){var code=null;if(!e){var e=window.event;}
if(e){if(e.keyCode){code=e.keyCode;}else if(e.which){code=e.which;}
return code;}
return null;},setCookie:function(name,value,days,path,domain){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}else{var expires="";}
if(typeof path==='undefined'){path="/";}
var domainString="";if(typeof domain!=='undefined'){domainString="; domain="+domain;}
document.cookie=name+"="+value+expires+"; path="+path+domainString;},getCookie:function(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' '){c=c.substring(1,c.length);}
if(c.indexOf(nameEQ)==0){return c.substring(nameEQ.length,c.length);}}
return null;},deleteCookie:function(name,path,domain){if(TP.getCookie(name))document.cookie=name+'='+
((path)?';path='+path:'')+
((domain)?';domain='+domain:'')+';expires=Thu, 01-Jan-1970 00:00:01 GMT';},saveScroll:function(event,name){if(!name){name=document.location.href.replace(/#.*$/,'').replace(/[=]/g,'');}
var scrollX=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft;var scrollY=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop;TP.setCookie(name+'_x',scrollX,1/48);TP.setCookie(name+'_y',scrollY,1/48);},restoreScroll:function(name){if(!name){name=document.location.href.replace(/#.*$/,'').replace(/[=]/g,'');}
var xCookieName=name+'_x';var yCookieName=name+'_y';var scrollX=TP.getCookie(xCookieName);var scrollY=TP.getCookie(yCookieName);TP.setCookie(xCookieName,null);TP.setCookie(yCookieName,null);if(scrollX||scrollY){window.scrollTo(scrollX,scrollY);}},click:function(element){if(typeof element==='string'){element=document.getElementById(element);}
if(element){var event=document.createEvent("MouseEvents");event.initMouseEvent("click",true,true,window,0,0,0,0,0,false,false,false,false,0,null);element.dispatchEvent(event);}},isObject:function(item){return typeof item=='object'&&item!==null;},extendObject:function(destination,source){var args=Array.prototype.slice.call(arguments);if(args.length>1){for(var i=1;i<args.length;i++){var current=args[i];for(var property in current){destination[property]=current[property];}}}
return destination;},copy:function(object){return this.extendObject({},object);},deepCopy:function(source){var output={};for(var property in source){if(TP.isObject(source[property])){output[property]=this.deepCopy(source[property]);}else{output[property]=source[property];}}
return output;},getObjectString:function(object,recursive,indent){if(typeof recursive=='undefined'){recursive=false;}
if(typeof indent=='undefined'){indent=0;}
var string='';for(var property in object){for(var i=0;i<indent;i++){string+='  ';}
if(recursive&&TP.isObject(object[property])){string+=property+':\n';string+=this.getPrettyObjectString(object[property],recursive,indent+1);}else{string+=property+': '+object[property]+'\n';}}
return string;},ucFirst:function(string){try{return string.substring(0,1).toUpperCase()+string.substring(1);}catch(e){return'';}},ucWords:function(string){try{return string.replace(/(^|\s)([a-z])/g,function(m,p1,p2){return p1+p2.toUpperCase();});}catch(e){return'';}},trim:function(string){try{return string.replace(/^\s+|\s+$/g,"");}catch(e){return'';}},sqlTimeStringToDate:function(sqlTimeString){var date_array=sqlTimeString.split(" ");var yyyymmdd_array=date_array[0].split("-");try{var hhmmss_array=date_array[1].split(":");}catch(e){var hhmmss_array=[0,0,0];}
return new Date(yyyymmdd_array[0],yyyymmdd_array[1]-1,yyyymmdd_array[2],hhmmss_array[0],hhmmss_array[1],hhmmss_array[2],0);},init:function(){this.ie6=(window.external&&typeof window.XMLHttpRequest=='undefined');this.ie7=((navigator.appVersion.indexOf('MSIE 7.')==-1)?false:true);this.ie8=((navigator.appVersion.indexOf('MSIE 8.')==-1)?false:true);this.safari=(/Safari/.test(navigator.userAgent));if(typeof console!=='object'||typeof console.log!=='function'){window.console={log:function(msg){if($('ieConsole')){$('ieConsole').insert(new Element('div').update(msg));}},info:function(){},group:function(){},groupEnd:function(){},debug:function(){},warn:function(){}}}
if(typeof Array.prototype.indexOf==='undefined'){console.log('Needs Array.indexOf');Array.prototype.indexOf=function(obj){for(var i=0;i<this.length;i++){if(this[i]==obj)
return i;}
return-1;}}
TP.Site.EventManager.initEvents();},isIe:function(){return(this.ie6||this.ie7||this.ie8);},arrayIntersection:function(array1,array2){var intersectionArray=[];for(var i=0;i<array1.length;i++){if(array2.indexOf(array1[i])!=-1){intersectionArray.push(array1[i]);}}
return intersectionArray;},arrayMultiIntersection:function(arraySet){var commonArrayHolder={};var multiIntersection=[];var numArrays=0;var arraySetLength=arraySet.length;for(var i=0;i<arraySetLength;i++){var innerArraySetLength=arraySet[i].length;for(var k=0;k<innerArraySetLength;k++){if(!commonArrayHolder[arraySet[i][k]]){commonArrayHolder[arraySet[i][k]]=0;}
commonArrayHolder[arraySet[i][k]]++;}
numArrays++;}
for(index in commonArrayHolder){if(commonArrayHolder[index]==numArrays){multiIntersection.push(index);}}
return multiIntersection;},center:function(element,centerX,centerY){var viewportWidth=document.viewport.getWidth();var viewportHeight=document.viewport.getHeight();if(centerY){if((viewportHeight/2-element.getHeight()/2)<0){element.style.top='0px';}else{element.style.top=viewportHeight/2-element.getHeight()/2+'px';}}
if(centerX){if((viewportWidth/2-element.getWidth()/2)<0){element.style.left='0px';}else{element.style.left=viewportWidth/2-element.getWidth()/2+'px';}}},BrowserDetect:{init:function(){this.browser=this.searchString(this.dataBrowser)||"unknown";this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"unknown";this.OS=this.searchString(this.dataOS)||"unknown";},searchString:function(data){for(var i=0;i<data.length;i++){var dataString=data[i].string;var dataProp=data[i].prop;this.versionSearchString=data[i].versionSearch||data[i].identity;if(dataString){if(dataString.indexOf(data[i].subString)!=-1){return data[i].identity;}}
else if(dataProp){return data[i].identity;}}
return undefined;},searchVersion:function(dataString){var index=dataString.indexOf(this.versionSearchString);if(index==-1){return undefined;}
return parseFloat(dataString.substring(index+this.versionSearchString.length+1));},dataBrowser:[{string:navigator.userAgent,subString:"OmniWeb",versionSearch:"OmniWeb/",identity:"OmniWeb"},{string:navigator.vendor,subString:"Apple",identity:"Safari"},{string:navigator.vendor,subString:"Google",identity:"Chrome"},{string:navigator.vendor,subString:"Apple",identity:"Firefox"},{prop:window.opera,identity:"Opera"},{string:navigator.vendor,subString:"iCab",identity:"iCab"},{string:navigator.vendor,subString:"KDE",identity:"Konqueror"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.vendor,subString:"Camino",identity:"Camino"},{string:navigator.userAgent,subString:"Netscape",identity:"Netscape"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"},{string:navigator.userAgent,subString:"Mozilla",identity:"Firefox",versionSearch:"Minefield"},{string:navigator.userAgent,subString:"Gecko",identity:"Mozilla",versionSearch:"rv"},{string:navigator.userAgent,subString:"Mozilla",identity:"Netscape",versionSearch:"Mozilla"}],dataOS:[{string:navigator.userAgent,subString:"Windows NT 6.0",identity:"Windows/Vista"},{string:navigator.userAgent,subString:"Windows NT 5.1",identity:"Windows/XP"},{string:navigator.userAgent,subString:"Windows NT 6.1",identity:"Windows/7"},{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.userAgent,subString:"Mac OS X",identity:"Mac"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]},BrowserCheck:{supported:false,supportedBrowsers:[{os:'Mac',browser:'Safari',version:'3'},{os:'Mac',browser:'Firefox',version:'3.5'},{os:'Mac',browser:'Firefox',version:'3.6'},{os:'Mac',browser:'Chrome',version:'5'},{os:'Windows/XP',browser:'Firefox',version:'3.5'},{os:'Windows/XP',browser:'Firefox',version:'3.6'},{os:'Windows/XP',browser:'Chrome',version:'5'},{os:'Windows/XP',browser:'Explorer',version:'6'},{os:'Windows/XP',browser:'Explorer',version:'7'},{os:'Windows/XP',browser:'Explorer',version:'8'},{os:'Windows/Vista',browser:'Firefox',version:'3.5'},{os:'Windows/Vista',browser:'Firefox',version:'3.6'},{os:'Windows/Vista',browser:'Chrome',version:'5'},{os:'Windows/Vista',browser:'Explorer',version:'7'},{os:'Windows/Vista',browser:'Explorer',version:'8'},{os:'Linux',browser:'Firefox',version:'3.5'},{os:'Linux',browser:'Firefox',version:'3.6'},{os:'Linux',browser:'Chrome',version:'5'},{os:'Windows/7',browser:'Explorer',version:'7'},{os:'Windows/7',browser:'Explorer',version:'8'},{os:'Windows/7',browser:'Chrome',version:'5'},{os:'Windows/7',browser:'Firefox',version:'3.5'},{os:'Windows/7',browser:'Firefox',version:'3.6'}],init:function(){TP.BrowserDetect.init();for(var i=0;i<this.supportedBrowsers.length;i++){var current=this.supportedBrowsers[i];if(TP.BrowserDetect.browser=='Safari'){this.supported=true;break;}
if(TP.BrowserDetect.browser==current.browser&&TP.BrowserDetect.OS==current.os&&TP.BrowserDetect.version==current.version){this.supported=true;break;}}}}};TP.Associator=function(prefix,options){this.prefix=prefix;this.associatedSelect=document.getElementById(this.prefix+'_associated');this.availableSelect=document.getElementById(this.prefix+'_available');this.sortUpElement=document.getElementById(this.prefix+'_sortUp');this.sortDownElement=document.getElementById(this.prefix+'_sortDown');this.associateElement=document.getElementById(this.prefix+'_associate');this.disassociateElement=document.getElementById(this.prefix+'_disassociate');this.associatedIdsElement=document.getElementById(this.prefix+'_associatedIds');this.preAssociate=function(){};this.postAssociate=function(){};this.preDisassociate=function(){};this.postDisassociate=function(){};this.preSortUp=function(){};this.postSortUp=function(){};this.preSortDown=function(){};this.postSortDown=function(){};if(typeof options=='object'){if(typeof options.preAssociate=='function'){this.preAssociate=options.preAssociate;}
if(typeof options.postAssociate=='function'){this.postAssociate=options.postAssociate;}
if(typeof options.preDisassociate=='function'){this.preDisassociate=options.preDisassociate;}
if(typeof options.postDisassociate=='function'){this.postDisassociate=options.postDisassociate;}
if(typeof options.preSortUp=='function'){this.preSortUp=options.preSortUp;}
if(typeof options.postSortUp=='function'){this.postSortUp=options.postSortUp;}
if(typeof options.preSortDown=='function'){this.preSortDown=options.preSortDown;}
if(typeof options.postSortDown=='function'){this.postSortDown=options.postSortDown;}}
var associator=this;if(this.sortUpElement){this.sortUpElement.onclick=function(){associator.preSortUp();TP.selectSortUp(associator.associatedSelect,function(){associator.updateAssociatedIds();});associator.postSortUp();return false;};}
if(this.sortDownElement){this.sortDownElement.onclick=function(){associator.preSortDown();TP.selectSortDown(associator.associatedSelect,function(){associator.updateAssociatedIds();});associator.postSortDown();return false;};}
if(this.associatedIdsElement){this.updateAssociatedIds();if(this.associateElement){this.associateElement.onclick=function(){associator.preAssociate();TP.moveBetweenSelects(associator.availableSelect,associator.associatedSelect,function(){associator.updateAssociatedIds();});associator.postAssociate();return false;};}
if(this.disassociateElement){this.disassociateElement.onclick=function(){associator.preDisassociate();TP.moveBetweenSelects(associator.associatedSelect,associator.availableSelect,function(){associator.updateAssociatedIds();});associator.postDisassociate();return false;};}}};TP.extendObject(TP.Associator.prototype,{prefix:null,associatedSelect:null,availableSelect:null,sortUpElement:null,sortDownElement:null,associateElement:null,disassociateElement:null,associatedIdsElement:null,updateAssociatedIds:function(){var associated=this.associatedSelect.options;var associatedIdsArray=[];for(var i=0;i<associated.length;i++){associatedIdsArray.push(associated[i].value);}
this.associatedIdsElement.value=associatedIdsArray;},compareAssociatedOptions:function(targetAssociator){var associatedOptions=this.associatedSelect.options;var targetOptions=targetAssociator.associatedSelect.options;if(associatedOptions.length!==targetOptions.length){return false;}
for(var idx=0;idx<associatedOptions.length;idx++){var associatedOption=associatedOptions[idx];var comparisonOption=targetOptions[idx];if(associatedOption.value!==comparisonOption.value){return false;}}
return true;}});if(typeof Function.prototype.bind=='undefined'){Function.prototype.bind=function(){var __method=this;var object=arguments[0];var args=[];for(var i=1;i<arguments.length;i++){args.push(arguments[i]);}
return function(){return __method.apply(object,args);}};}
if(typeof Function.prototype.bindAsEventListener=='undefined'){Function.prototype.bindAsEventListener=function(){var __method=this;var object=arguments[0];var args=[];for(var i=1;i<arguments.length;i++){args.push(arguments[i]);}
return function(event){return __method.apply(object,[event||window.event].concat(args));}}}
