//############################################
//   Generic Scripts
//############################################
//get pagename
var sPath = window.location.pathname;
var pagename = sPath.substring(sPath.lastIndexOf('/') + 1);
//get subdomain
var a = document.URL.split("//"); // split at protocol
var protocol = a[0];
var b = (a[1] ? a[1] : a[0]).split("/");
var domain = b[0];
a = (a[1] ? a[1] : a[0]).split(".");
var subdomain = a[0];

//http://adamv.com/dev/javascript/querystring
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

	// Turn <plus> back to <space>
	// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &

	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}
Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}
Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}
  function breadcrumbs(sClass, sDelimiter)
  {
    if(!sDelimiter) sDelimiter = '|';
    var sURL = (location.pathname.indexOf('?') != -1) ? location.pathname.substring(0, location.pathname.indexOf('?')) : location.pathname;
        sURL = (location.pathname.charAt(0) == '/') ? location.pathname.substring(1) : location.pathname;
    var aURL = sURL.split('/');
    if(aURL)
    {
      var sOutput = '<a href="/">Home</a> ' + sDelimiter + ' ';
      var sPath = '/';
      for(var i = 0; i < aURL.length; i++)
      {
        sPath += aURL[i] + '/';
        sOutput += '<a href="' + sPath + '"';
        if(sClass) sOutput += ' class="' + sClass +'"';
        sOutput += '>' + aURL[i] + '</a>';
        sOutput += ' ' + sDelimiter + ' ';
      }
      sOutput += document.title;
      document.write(sOutput);
    }
  }
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('maincontainer').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position = 'relative';
				footerElement.style.top = windowHeight - (contentHeight + footerHeight - 34) + 'px';
			}
			else {
				footerElement.style.position = 'static';
			}
		}
	}
}
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}
function setInputColor(objElement){
    objElement.style.backgroundColor='#fdeaba';
    objElement.style.border='1px solid #4b63ae';
    
}
function setpwInputColor(objElement){
    objElement.style.backgroundColor='#fdeaba';
    objElement.style.border='1px solid #496f80';
}
function hideColor(objElement){
    objElement.style.backgroundColor='#ffffff';
    objElement.style.border='1px solid #496f80';        
}
function getMessageQueryString()
{
 var querystring = new Array;
 var q = String (document.location).split ('?m=')[1];
 if (!q) return false;
 return q;
}
/*
CSS Browser Selector v0.3.2
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

//############################################
//   JQ Modal
//############################################
/*
 * jqModal - Minimalist Modaling with jQuery
 *   (http://dev.iceburg.net/jquery/jqModal/)
 *
 * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 * 
 * $Version: 03/01/2009 +r14
 */
/**/
(function($) {
$.fn.jqm=function(o){
var p={
overlay: 50,
overlayClass: 'jqmOverlay',
closeClass: 'jqmClose',
trigger: '.jqModal',
ajax: F,
ajaxText: '',
target: F,
modal: F,
toTop: F,
onShow: F,
onHide: F,
onLoad: F
};
return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
if(p.trigger)$(this).jqmAddTrigger(p.trigger);
});};

$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
$.fn.jqmShow=function(t){return this.each(function(){t=t||window.event;$.jqm.open(this._jqm,t);});};
$.fn.jqmHide=function(t){return this.each(function(){t=t||window.event;$.jqm.close(this._jqm,t)});};

$.jqm = {
hash:{},
open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);
 if(c.modal) {if(!A[0])L('bind');A.push(s);}
 else if(c.overlay > 0)h.w.jqmAddClose(o);
 else o=F;

 h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
 if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}

 if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == 'string')?$(r,h.w):$(r),u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u;
  r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
 else if(cc)h.w.jqmAddClose($(cc,h.w));

 if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);	
 (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
},
close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
 if(A[0]){A.pop();if(!A[0])L('unbind');}
 if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
 if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
},
params:{}};
var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
 if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});};
})(jQuery);

//############################################
//   JQ Easing
//############################################
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('h.i[\'E\']=h.i[\'y\'];h.F(h.i,{z:\'A\',y:9(x,t,b,c,d){6 h.i[h.i.z](x,t,b,c,d)},G:9(x,t,b,c,d){6 c*(t/=d)*t+b},A:9(x,t,b,c,d){6-c*(t/=d)*(t-2)+b},H:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t+b;6-c/2*((--t)*(t-2)-1)+b},I:9(x,t,b,c,d){6 c*(t/=d)*t*t+b},J:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t+1)+b},K:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t+b;6 c/2*((t-=2)*t*t+2)+b},L:9(x,t,b,c,d){6 c*(t/=d)*t*t*t+b},M:9(x,t,b,c,d){6-c*((t=t/d-1)*t*t*t-1)+b},N:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t*t+b;6-c/2*((t-=2)*t*t*t-2)+b},O:9(x,t,b,c,d){6 c*(t/=d)*t*t*t*t+b},P:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t*t*t+1)+b},Q:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t*t*t+b;6 c/2*((t-=2)*t*t*t*t+2)+b},R:9(x,t,b,c,d){6-c*8.B(t/d*(8.g/2))+c+b},S:9(x,t,b,c,d){6 c*8.n(t/d*(8.g/2))+b},T:9(x,t,b,c,d){6-c/2*(8.B(8.g*t/d)-1)+b},U:9(x,t,b,c,d){6(t==0)?b:c*8.j(2,10*(t/d-1))+b},V:9(x,t,b,c,d){6(t==d)?b+c:c*(-8.j(2,-10*t/d)+1)+b},W:9(x,t,b,c,d){e(t==0)6 b;e(t==d)6 b+c;e((t/=d/2)<1)6 c/2*8.j(2,10*(t-1))+b;6 c/2*(-8.j(2,-10*--t)+2)+b},X:9(x,t,b,c,d){6-c*(8.o(1-(t/=d)*t)-1)+b},Y:9(x,t,b,c,d){6 c*8.o(1-(t=t/d-1)*t)+b},Z:9(x,t,b,c,d){e((t/=d/2)<1)6-c/2*(8.o(1-t*t)-1)+b;6 c/2*(8.o(1-(t-=2)*t)+1)+b},11:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d)==1)6 b+c;e(!p)p=d*.3;e(a<8.r(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.u(c/a);6-(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b},12:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d)==1)6 b+c;e(!p)p=d*.3;e(a<8.r(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.u(c/a);6 a*8.j(2,-10*t)*8.n((t*d-s)*(2*8.g)/p)+c+b},13:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d/2)==2)6 b+c;e(!p)p=d*(.3*1.5);e(a<8.r(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.u(c/a);e(t<1)6-.5*(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b;6 a*8.j(2,-10*(t-=1))*8.n((t*d-s)*(2*8.g)/p)*.5+c+b},14:9(x,t,b,c,d,s){e(s==v)s=1.l;6 c*(t/=d)*t*((s+1)*t-s)+b},15:9(x,t,b,c,d,s){e(s==v)s=1.l;6 c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},16:9(x,t,b,c,d,s){e(s==v)s=1.l;e((t/=d/2)<1)6 c/2*(t*t*(((s*=(1.C))+1)*t-s))+b;6 c/2*((t-=2)*t*(((s*=(1.C))+1)*t+s)+2)+b},D:9(x,t,b,c,d){6 c-h.i.w(x,d-t,0,c,d)+b},w:9(x,t,b,c,d){e((t/=d)<(1/2.k)){6 c*(7.q*t*t)+b}m e(t<(2/2.k)){6 c*(7.q*(t-=(1.5/2.k))*t+.k)+b}m e(t<(2.5/2.k)){6 c*(7.q*(t-=(2.17/2.k))*t+.18)+b}m{6 c*(7.q*(t-=(2.19/2.k))*t+.1a)+b}},1b:9(x,t,b,c,d){e(t<d/2)6 h.i.D(x,t*2,0,c,d)*.5+b;6 h.i.w(x,t*2-d,0,c,d)*.5+c*.5+b}});',62,74,'||||||return||Math|function|||||if|var|PI|jQuery|easing|pow|75|70158|else|sin|sqrt||5625|abs|||asin|undefined|easeOutBounce||swing|def|easeOutQuad|cos|525|easeInBounce|jswing|extend|easeInQuad|easeInOutQuad|easeInCubic|easeOutCubic|easeInOutCubic|easeInQuart|easeOutQuart|easeInOutQuart|easeInQuint|easeOutQuint|easeInOutQuint|easeInSine|easeOutSine|easeInOutSine|easeInExpo|easeOutExpo|easeInOutExpo|easeInCirc|easeOutCirc|easeInOutCirc||easeInElastic|easeOutElastic|easeInOutElastic|easeInBack|easeOutBack|easeInOutBack|25|9375|625|984375|easeInOutBounce'.split('|'),0,{}))

//############################################
//   JQ Core
//############################################
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';(3($){$.8={1z:{14:3(a,b,c){6 d=$.8[a].t;15(6 i 1A c){d.A[i]=d.A[i]||[];d.A[i].1B([b,c[i]])}},16:3(a,b,c){6 d=a.A[b];5(!d){4}15(6 i=0;i<d.1C;i++){5(a.k[d[i][0]]){d[i][1].B(a.l,c)}}}},u:{},p:3(a){5($.8.u[a]){4 $.8.u[a]}6 b=$(\'<1D 1E="8-1F">\').17(a).p({1G:\'1H\',H:\'-18\',1I:\'-18\',1J:\'1K\'}).1L(\'19\');$.8.u[a]=!!((!(/1M|1N/).q(b.p(\'1O\'))||(/^[1-9]/).q(b.p(\'1P\'))||(/^[1-9]/).q(b.p(\'1Q\'))||!(/1a/).q(b.p(\'1R\'))||!(/1S|1T\\(0, 0, 0, 0\\)/).q(b.p(\'1U\'))));1V{$(\'19\').1b(0).1W(b.1b(0))}1X(e){}4 $.8.u[a]},1Y:3(e){e.v="1c";e.1d=3(){4 7};5(e.C){e.C.1e="1a"}},1Z:3(e){e.v="20";e.1d=3(){4 n};5(e.C){e.C.1e=""}},21:3(e,a){6 b=/H/.q(a||"H")?\'22\':\'23\',I=7;5(e[b]>0)4 n;e[b]=1;I=e[b]>0?n:7;e[b]=0;4 I}};6 j=$.J.D;$.J.D=3(){$("*",2).14(2).24("D");4 j.B(2,1f)};3 K(a,b,c){6 d=$[a][b].K||[];d=(L d=="M"?d.N(/,?\\s+/):d);4($.25(c,d)!=-1)}$.w=3(g,h){6 i=g.N(".")[0];g=g.N(".")[1];$.J[g]=3(b){6 c=(L b==\'M\'),O=26.t.27.16(1f,1);5(c&&K(i,g,b)){6 d=$.P(2[0],g);4(d?d[b].B(d,O):28)}4 2.29(3(){6 a=$.P(2,g);5(c&&a&&$.2a(a[b])){a[b].B(a,O)}2b 5(!c){$.P(2,g,2c $[i][g](2,b))}})};$[i][g]=3(c,d){6 f=2;2.o=g;2.1g=i+\'-\'+g;2.k=$.1h({},$.w.E,$[i][g].E,d);2.l=$(c).r(\'x.\'+g,3(e,a,b){4 f.x(a,b)}).r(\'Q.\'+g,3(e,a){4 f.Q(a)}).r(\'D\',3(){4 f.1i()});2.1j()};$[i][g].t=$.1h({},$.w.t,h)};$.w.t={1j:3(){},1i:3(){2.l.2d(2.o)},Q:3(a){4 2.k[a]},x:3(a,b){2.k[a]=b;5(a==\'y\'){2.l[b?\'17\':\'2e\'](2.1g+\'-y\')}},2f:3(){2.x(\'y\',7)},2g:3(){2.x(\'y\',n)}};$.w.E={y:7};$.8.1k={2h:3(){6 a=2;2.l.r(\'2i.\'+2.o,3(e){4 a.1l(e)});5($.R.S){2.1m=2.l.T(\'v\');2.l.T(\'v\',\'1c\')}2.2j=7},2k:3(){2.l.U(\'.\'+2.o);($.R.S&&2.l.T(\'v\',2.1m))},1l:3(e){(2.m&&2.z(e));2.F=e;6 a=2,1n=(e.2l==1),1o=(L 2.k.V=="M"?$(e.2m).2n(2.k.V):7);5(!1n||1o||!2.1p(e)){4 n}2.G=!2.k.W;5(!2.G){2.2o=2p(3(){a.G=n},2.k.W)}5(2.X(e)&&2.Y(e)){2.m=(2.Z(e)!==7);5(!2.m){e.2q();4 n}}2.10=3(e){4 a.1q(e)};2.11=3(e){4 a.z(e)};$(1r).r(\'1s.\'+2.o,2.10).r(\'1t.\'+2.o,2.11);4 7},1q:3(e){5($.R.S&&!e.2r){4 2.z(e)}5(2.m){2.12(e);4 7}5(2.X(e)&&2.Y(e)){2.m=(2.Z(2.F,e)!==7);(2.m?2.12(e):2.z(e))}4!2.m},z:3(e){$(1r).U(\'1s.\'+2.o,2.10).U(\'1t.\'+2.o,2.11);5(2.m){2.m=7;2.1u(e)}4 7},X:3(e){4(13.2s(13.1v(2.F.1w-e.1w),13.1v(2.F.1x-e.1x))>=2.k.1y)},Y:3(e){4 2.G},Z:3(e){},12:3(e){},1u:3(e){},1p:3(e){4 n}};$.8.1k.E={V:2t,1y:1,W:0}})(2u);',62,155,'||this|function|return|if|var|false|ui||||||||||||options|element|_mouseStarted|true|widgetName|css|test|bind||prototype|cssCache|unselectable|widget|setData|disabled|mouseUp|plugins|apply|style|remove|defaults|_mouseDownEvent|_mouseDelayMet|top|has|fn|getter|typeof|string|split|args|data|getData|browser|msie|attr|unbind|cancel|delay|mouseDistanceMet|mouseDelayMet|mouseStart|_mouseMoveDelegate|_mouseUpDelegate|mouseDrag|Math|add|for|call|addClass|5000px|body|none|get|on|onselectstart|MozUserSelect|arguments|widgetBaseClass|extend|destroy|init|mouse|mouseDown|_mouseUnselectable|btnIsLeft|elIsCancel|mouseCapture|mouseMove|document|mousemove|mouseup|mouseStop|abs|pageX|pageY|distance|plugin|in|push|length|div|class|gen|position|absolute|left|display|block|appendTo|auto|default|cursor|height|width|backgroundImage|transparent|rgba|backgroundColor|try|removeChild|catch|disableSelection|enableSelection|off|hasScroll|scrollTop|scrollLeft|trigger|inArray|Array|slice|undefined|each|isFunction|else|new|removeData|removeClass|enable|disable|mouseInit|mousedown|started|mouseDestroy|which|target|is|_mouseDelayTimer|setTimeout|preventDefault|button|max|null|jQuery'.split('|'),0,{}))

//############################################
//   JQ Tabs
//############################################
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(4($){$.2a("8.3",{2b:4(){2.m.L+=\'.3\';2.13(14)},2c:4(a,b){5((/^7/).1O(a))2.15(b);C{2.m[a]=b;2.13()}},w:4(){p 2.$3.w},1w:4(a){p a.1P&&a.1P.V(/\\s/g,\'1Q\').V(/[^A-2d-2e-9\\-1Q:\\.]/g,\'\')||2.m.1R+$.q(a)},8:4(a,b){p{m:2.m,2f:a,1i:b}},13:4(e){2.$v=$(\'G:2g(a[D])\',2.x);2.$3=2.$v.1j(4(){p $(\'a\',2)[0]});2.$l=$([]);6 f=2,o=2.m;2.$3.R(4(i,a){5(a.J&&a.J.V(\'#\',\'\'))f.$l=f.$l.16(a.J);C 5($(a).W(\'D\')!=\'#\'){$.q(a,\'D.3\',a.D);$.q(a,\'E.3\',a.D);6 b=f.1w(a);a.D=\'#\'+b;6 c=$(\'#\'+b);5(!c.w){c=$(o.1x).W(\'17\',b).y(o.18).2h(f.$l[i-1]||f.x);c.q(\'19.3\',14)}f.$l=f.$l.16(c)}C o.u.1S(i+1)});5(e){2.x.y(o.1y);2.$l.R(4(){6 a=$(2);a.y(o.18)});5(o.7===1k){5(1z.J){2.$3.R(4(i,a){5(a.J==1z.J){o.7=i;5($.S.1a||$.S.2i){6 b=$(1z.J),1T=b.W(\'17\');b.W(\'17\',\'\');1A(4(){b.W(\'17\',1T)},2j)}2k(0,0);p F}})}C 5(o.X){6 g=2l($.X(\'8-3\'+$.q(f.x)),10);5(g&&f.$3[g])o.7=g}C 5(f.$v.M(\'.\'+o.z).w)o.7=f.$v.Y(f.$v.M(\'.\'+o.z)[0])}o.7=o.7===B||o.7!==1k?o.7:0;o.u=$.2m(o.u.2n($.1j(2.$v.M(\'.\'+o.T),4(n,i){p f.$v.Y(n)}))).1U();5($.1l(o.7,o.u)!=-1)o.u.2o($.1l(o.7,o.u),1);2.$l.y(o.N);2.$v.H(o.z);5(o.7!==B){2.$l.I(o.7).K().H(o.N);2.$v.I(o.7).y(o.z);6 h=4(){$(f.x).O(\'1V\',[B,f.8(f.$3[o.7],f.$l[o.7])],o.K)};5($.q(2.$3[o.7],\'E.3\'))2.E(o.7,h);C h()}$(2p).1b(\'2q\',4(){f.$3.1c(\'.3\');f.$v=f.$3=f.$l=B})}2r(6 i=0,G;G=2.$v[i];i++)$(G)[$.1l(i,o.u)!=-1&&!$(G).Z(o.z)?\'y\':\'H\'](o.T);5(o.P===F)2.$3.1m(\'P.3\');6 j,U,1d={\'2s-2t\':0,1B:1},1C=\'2u\';5(o.11&&o.11.2v==2w)j=o.11[0]||1d,U=o.11[1]||1d;C j=U=o.11||1d;6 k={1n:\'\',2x:\'\',2y:\'\'};5(!$.S.1a)k.1D=\'\';4 1E(a,b,c){b.1W(j,j.1B||1C,4(){b.y(o.N).1e(k);5($.S.1a&&j.1D)b[0].1X.M=\'\';5(c)1o(a,c,b)})}4 1o(a,b,c){5(U===1d)b.1e(\'1n\',\'1F\');b.1W(U,U.1B||1C,4(){b.H(o.N).1e(k);5($.S.1a&&U.1D)b[0].1X.M=\'\';$(f.x).O(\'1V\',[B,f.8(a,b[0])],o.K)})}4 1Y(a,b,c,d){b.y(o.z).2z().H(o.z);1E(a,c,d)}2.$3.1c(\'.3\').1b(o.L,4(){6 b=$(2).2A(\'G:I(0)\'),$12=f.$l.M(\':2B\'),$K=$(2.J);5((b.Z(o.z)&&!o.1p)||b.Z(o.T)||$(2).Z(o.1f)||$(f.x).O(\'2C\',[B,f.8(2,$K[0])],o.15)===F){2.1q();p F}f.m.7=f.$3.Y(2);5(o.1p){5(b.Z(o.z)){f.m.7=B;b.H(o.z);f.$l.Q();1E(2,$12);2.1q();p F}C 5(!$12.w){f.$l.Q();6 a=2;f.E(f.$3.Y(2),4(){b.y(o.z).y(o.1G);1o(a,$K)});2.1q();p F}}5(o.X)$.X(\'8-3\'+$.q(f.x),f.m.7,o.X);f.$l.Q();5($K.w){6 a=2;f.E(f.$3.Y(2),$12.w?4(){1Y(a,b,$12,$K)}:4(){b.y(o.z);1o(a,$K)})}C 2D\'1Z 2E 2F: 2G 2H 2I.\';5($.S.1a)2.1q();p F});5(!(/^1H/).1O(o.L))2.$3.1b(\'1H.3\',4(){p F})},16:4(a,b,c){5(c==1k)c=2.$3.w;6 o=2.m;6 d=$(o.20.V(/#\\{D\\}/g,a).V(/#\\{1r\\}/g,b));d.q(\'19.3\',14);6 e=a.2J(\'#\')==0?a.V(\'#\',\'\'):2.1w($(\'a:2K-2L\',d)[0]);6 f=$(\'#\'+e);5(!f.w){f=$(o.1x).W(\'17\',e).y(o.N).q(\'19.3\',14)}f.y(o.18);5(c>=2.$v.w){d.21(2.x);f.21(2.x[0].2M)}C{d.22(2.$v[c]);f.22(2.$l[c])}o.u=$.1j(o.u,4(n,i){p n>=c?++n:n});2.13();5(2.$3.w==1){d.y(o.z);f.H(o.N);6 g=$.q(2.$3[0],\'E.3\');5(g)2.E(c,g)}2.x.O(\'2N\',[B,2.8(2.$3[c],2.$l[c])],o.16)},1g:4(a){6 o=2.m,$G=2.$v.I(a).1g(),$1i=2.$l.I(a).1g();5($G.Z(o.z)&&2.$3.w>1)2.15(a+(a+1<2.$3.w?1:-1));o.u=$.1j($.23(o.u,4(n,i){p n!=a}),4(n,i){p n>=a?--n:n});2.13();2.x.O(\'2O\',[B,2.8($G.1I(\'a\')[0],$1i[0])],o.1g)},24:4(a){6 o=2.m;5($.1l(a,o.u)==-1)p;6 b=2.$v.I(a).H(o.T);5($.S.2P){b.1e(\'1n\',\'2Q-1F\');1A(4(){b.1e(\'1n\',\'1F\')},0)}o.u=$.23(o.u,4(n,i){p n!=a});2.x.O(\'2R\',[B,2.8(2.$3[a],2.$l[a])],o.24)},25:4(a){6 b=2,o=2.m;5(a!=o.7){2.$v.I(a).y(o.T);o.u.1S(a);o.u.1U();2.x.O(\'2S\',[B,2.8(2.$3[a],2.$l[a])],o.25)}},15:4(a){5(2T a==\'2U\')a=2.$3.Y(2.$3.M(\'[D$=\'+a+\']\')[0]);2.$3.I(a).2V(2.m.L)},E:4(c,d){6 e=2,o=2.m,$a=2.$3.I(c),a=$a[0],26=d==1k||d===F,1h=$a.q(\'E.3\');d=d||4(){};5(!1h||!26&&$.q(a,\'P.3\')){d();p}6 f=4(a){6 b=$(a),$1J=b.1I(\'*:2W\');p $1J.w&&$1J||b};6 g=4(){e.$3.M(\'.\'+o.1f).H(o.1f).R(4(){5(o.1s)f(2).2X().1t(f(2).q(\'1r.3\'))});e.1u=B};5(o.1s){6 h=f(a).1t();f(a).2Y(\'<1K></1K>\').1I(\'1K\').q(\'1r.3\',h).1t(o.1s)}6 i=$.27({},o.1v,{1h:1h,1L:4(r,s){$(a.J).1t(r);g();5(o.P)$.q(a,\'P.3\',14);$(e.x).O(\'2Z\',[B,e.8(e.$3[c],e.$l[c])],o.E);o.1v.1L&&o.1v.1L(r,s);d()}});5(2.1u){2.1u.30();g()}$a.y(o.1f);1A(4(){e.1u=$.31(i)},0)},1h:4(a,b){2.$3.I(a).1m(\'P.3\').q(\'E.3\',b)},19:4(){6 o=2.m;2.x.1c(\'.3\').H(o.1y).1m(\'3\');2.$3.R(4(){6 b=$.q(2,\'D.3\');5(b)2.D=b;6 c=$(2).1c(\'.3\');$.R([\'D\',\'E\',\'P\'],4(i,a){c.1m(a+\'.3\')})});2.$v.16(2.$l).R(4(){5($.q(2,\'19.3\'))$(2).1g();C $(2).H([o.z,o.1G,o.T,o.18,o.N].32(\' \'))})}});$.8.3.33={1p:F,L:\'1H\',u:[],X:B,1s:\'34&#35;\',P:F,1R:\'8-3-\',1v:{},11:B,20:\'<G><a D="#{D}"><28>#{1r}</28></a></G>\',1x:\'<29></29>\',1y:\'8-3-36\',z:\'8-3-7\',1G:\'8-3-1p\',T:\'8-3-u\',18:\'8-3-1i\',N:\'8-3-12\',1f:\'8-3-37\'};$.8.3.38="w";$.27($.8.3.39,{1M:B,3a:4(a,b){b=b||F;6 c=2,t=2.m.7;4 1N(){c.1M=3b(4(){t=++t<c.$3.w?t:0;c.15(t)},a)}4 Q(e){5(!e||e.3c){3d(c.1M)}}5(a){1N();5(!b)2.$3.1b(2.m.L,Q);C 2.$3.1b(2.m.L,4(){Q();t=c.m.7;1N()})}C{Q();2.$3.1c(2.m.L,Q)}}})})(1Z);',62,200,'||this|tabs|function|if|var|selected|ui|||||||||||||panels|options|||return|data||||disabled|lis|length|element|addClass|selectedClass||null|else|href|load|false|li|removeClass|eq|hash|show|event|filter|hideClass|triggerHandler|cache|stop|each|browser|disabledClass|showFx|replace|attr|cookie|index|hasClass||fx|hide|tabify|true|select|add|id|panelClass|destroy|msie|bind|unbind|baseFx|css|loadingClass|remove|url|panel|map|undefined|inArray|removeData|display|showTab|unselect|blur|label|spinner|html|xhr|ajaxOptions|tabId|panelTemplate|navClass|location|setTimeout|duration|baseDuration|opacity|hideTab|block|unselectClass|click|find|inner|em|success|rotation|start|test|title|_|idPrefix|push|toShowId|sort|tabsshow|animate|style|switchTab|jQuery|tabTemplate|appendTo|insertBefore|grep|enable|disable|bypassCache|extend|span|div|widget|init|setData|Za|z0|tab|has|insertAfter|opera|500|scrollTo|parseInt|unique|concat|splice|window|unload|for|min|width|normal|constructor|Array|overflow|height|siblings|parents|visible|tabsselect|throw|UI|Tabs|Mismatching|fragment|identifier|indexOf|first|child|parentNode|tabsadd|tabsremove|safari|inline|tabsenable|tabsdisable|typeof|string|trigger|last|parent|wrapInner|tabsload|abort|ajax|join|defaults|Loading|8230|nav|loading|getter|prototype|rotate|setInterval|clientX|clearInterval'.split('|'),0,{}))

//TrainingPeaks JQuery
var p;
$(document).ready(function () {
    var userAgent = navigator.userAgent.toLowerCase();
    var is_chrome = userAgent.indexOf('chrome') > -1;
    var isIE6 = userAgent.indexOf('msie 6') != -1;
    var isMacFirefox = userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox') != -1;
    var isIPhone = userAgent.indexOf('iphone') != -1;
    if (domain == 'support.trainingpeaks.com') {
        $('a[href^="http://www"]')
			.each(function () {
			    var linkurl = $(this).attr("href");
			    var linktext = $(this).text();
			    if (linkurl.toLowerCase().indexOf('trainingpeaks') == -1 && linkurl.toLowerCase().indexOf('peaksware') == -1 && linkurl.toLowerCase().indexOf('cyclingpeaks') == -1) {
			        $(this).html('<a onclick="openwindow(&#34;' + linkurl + '&#34;);return false;" href="javascript:void()" class="external">' + linktext + '</a>');
			    }
			})
    }
    $("form#loginform").submit(function () {
        if ($("input:first").val() != "" && $(":password").val() != "") {
            return true;
        }
        else {
            $("#loginnotification").text("Username/Password Required").css({ float: 'right', width: '200px', padding: '3px', background: '#2d3953', border: '1px dotted #fff', color: '#fff' }).show().fadeOut(3500);
            return false;
        }
        if ($("input:second").val() != "") {
            return true;
        }
        else {
            $("#loginnotification").text("Please enter a Password").css({ float: 'left', width: '170px', padding: '3px', background: '#fff', border: '1px solid #444', color: '#7c0000' }).show().fadeOut(2500);
            return false;
        }
    });
    //add modal div if it doesn't exist
    if (!$('#modal').length) {
        $('<div id="modal"></div>').appendTo('body');
    }
    $('#modal').jqm({ ajax: '@href', trigger: 'a.jqModal', ajaxText: '<img style="margin:200px 0 0 370px;" src="https://home.trainingpeaks.com/images/loaderModal.gif" />' });
    $('#articleslist a').click(function () {
        $(this).parent().parent().find('div.articlescategorylist').toggle();
        if ($(this).attr('class') == 'opened')
            var closr = true
        $(this).parents('ul:first').find('a').removeClass('opened').end();
        if (closr != true)
            $(this).addClass('opened');
    });
    $('#videoslist a').click(function () {
        $(this).parent().parent().find('div.videoscategorylist').toggle();
        if ($(this).attr('class') == 'opened')
            var closr = true
        $(this).parents('ul:first').find('a').removeClass('opened').end();
        if (closr != true)
            $(this).addClass('opened');
    });
    if (subdomain == 'support') {
        $('#navmain #mainnav-support a').addClass('active');
    }
    else {
        /*set active class on nav main*/
        var path = location.pathname.substring(1);
        if (path) {
            if (location.pathname.indexOf("/", 1) > 0)
                $('#navmain a[@href*="' + location.pathname.substring(1, location.pathname.indexOf("/", 1)) + '"]').attr('class', 'active')
            else
                $('#navmain a[@href$="' + path + '"]').addClass('active');
        }
        else {
            $('#navmain a[@href$="/"]').addClass('active');
        }
    }
    $('#homedynamic-1 > ul').tabs();

    //toggle for plans
    $('#wrappercontentpage .plansubheader a').click(function () {
        $(this).parent().parent().parent().find('div.plandetail').toggle();
    });
    $('#wrappercontentpage #trainingplansbycoach h3 a').click(function () {
        $(this).parent().parent().find('div.plansub').toggle();
    });
    //toggle for articles
    $('#wrappercontentpage #articleslist a').click(function () {
        $(this).parent().parent().find('div.articlescategorylist').toggle();
    });


    if (getProfileQueryString()) {
        p = getProfileQueryString();
    }
    /*
    else
    {
    var totalNum = 20; //the total number of profiles.		
    var rndNum = Math.floor(Math.random() * totalNum);
    p = $("#profiles .items a:eq(" + rndNum+ ")").attr("class");
    if (p == null ){
    p = $("#profiles .items a:first").attr("class");
    }
    }
    */
    profile = $("#profiles .items a." + p + "").attr("id");
    var alink = $("#profiles .items a." + p);

    //$(alink).addClass("on");	
    //link to the profile
    //$("#homemaininnerleft").click(function(){window.location.href = alink.find("img").attr("id");});
    //profile tool tips:
    $("#profiles ul li a div").css({ display: "block", opacity: 0 });
    $("#profiles ul li").mouseover(function () {
        $(this).find("div").show();
        //$(this).find("a").addClass("on");
    }).mouseout(function () {
        $(this).find("div").hide();
        //$(this).find("a").removeClass("on");
    });
    $("#profiles .items a").click(function () {
        var profile = removeSpaces(jQuery(this).attr("id"));
        var alink = jQuery(this);
        var tooltip = jQuery(this).attr("title");
        $("#profiles .items").find("a").removeClass("on");
        $(this).addClass("on");
        $("#wrapperhomemain").load(alink.find("img").attr("id") + " div#homepagemain").show("fast"); ;
        //Home intro text change on profile click - load the first profile homeintro text if no text is found  
        $("#homeintro").load(alink.find("img").attr("id") + " div#homepagecontent", function () {
            var homeintroLength = $("#homeintro").html().length;
            if (homeintroLength < 50) {
                //load the first profile text - 
                $("#homeintro").load($("#profiles .items a:first").find("img").attr("id") + " div#homepagecontent");
            }
        });
        $("#homemaininnerleft").click(function () {
            window.location.href = alink.find("img").attr("id");
        });
    });

    //Account - Purchase Management
    $('#usernameLoading').hide();
    $('.txtUserName').blur(function () {
        $('#usernameLoading').show();
        $.post("/ajaxutils.aspx?method=CheckUserName", {
            username: $('.txtUserName').val()
        }, function (response) {
            $('#usernameResult').fadeOut();
            var usernamemessage;
            if (response == 1) {
                usernamemessage = 'Sorry, this Username is in use. You must select a different username. Do you <a style=\text-decoration:underline;\" href=\"/utilities/forgotpassword.aspx\">already have an account?</a>';
                $('#usernameResult').removeClass("available");
                $('#usernameResult').addClass("unavailable");
            }
            else {
                usernamemessage = '';
                $('#usernameResult').removeClass("unavailable");
                $('#usernameResult').addClass("available");
            }
            setTimeout("finishAjax('usernameResult', '" + escape(usernamemessage) + "')", 400);
        });
        return false;
    });

    //email check
    $('#emailLoading').hide();
    $('.txtEmailConfirm').blur(function () {
        $('#emailLoading').show();
        $.post("/ajaxutils.aspx?method=CheckEmail", {
            email: $('.txtEmailConfirm').val()            
        }, function (response) {
            $('#emailResult').fadeOut();
            var emailmessage;
            if (response == 1) {
                emailmessage = '<div id="email-duplicate">This email address is in use for an existing Personal Edition account. Do you already have an account? If so, you can retrieve the password for this account here: <a href="/utilities/forgotpassword.aspx">forgot password</a>.</div> ';
                $('#emailResult').removeClass("available");
                $('#emailResult').addClass("unavailable");
            }
            else {
                emailmessage = '';
                $('#emailResult').removeClass("unavailable");
                $('#emailResult').addClass("available");
            }
            setTimeout("finishAjax('emailResult', '" + escape(emailmessage) + "')", 400);
        });
        return false;
    });

    $('div.plansub .plansubheader .planexpander .plantitle').click(function () {
        $(this).parent().parent().parent().find('div.plandetail').toggle();
        if ($(this).find('span.plantitle a').attr('class') == 'opened')
            $(this).find('span.plantitle a').removeClass('opened');
        else
            $(this).find('span.plantitle a').addClass('opened');
    });
    $('a#plandetailcollapse').click(function () {
        $('div.plandetail').css('display', 'none');
        $('div#plansearchwrapper').find('span.plantitle a').removeClass('opened');
        $('a#plandetailexpand').text('Expand all Plan Details');
        $('a#plandetailcollapse').text('');
    });
    $('a#plandetailexpand').click(function () {
        $('div.plandetail').css('display', 'block');
        $('div#plansearchwrapper').find('span.plantitle a').addClass('opened');
        $('a#plandetailexpand').text('');
        $('a#plandetailcollapse').text('Collapse all Plan Details');
    });

    //libraries - todo: combine with above and use parent selector
    $('div.librarysub .librarysubheader .libraryexpander').click(function () {
        $(this).parent().parent().find('div.librarydetail').toggle();
        if ($(this).find('span.librarytitle a').attr('class') == 'opened')
            $(this).find('span.librarytitle a').removeClass('opened');
        else
            $(this).find('span.librarytitle a').addClass('opened');
    });
    $('a#librarydetailcollapse').click(function () {
        $('div.librarydetail').css('display', 'none');
        $('div#librarysearchwrapper').find('span.librarytitle a').removeClass('opened');
        $('a#librarydetailexpand').text('Expand all library Details');
        $('a#librarydetailcollapse').text('');
    });
    $('a#librarydetailexpand').click(function () {
        $('div.librarydetail').css('display', 'block');
        $('div#librarysearchwrapper').find('span.librarytitle a').addClass('opened');
        $('a#librarydetailexpand').text('');
        $('a#librarydetailcollapse').text('Collapse all library Details');
    });

    //plan preview
    $('div.plansub .plansubheader .expand').click(function () {
        $(this).parent().parent().parent().find('.plansubheader').css('background', '');
        $(this).parent().parent().find('.plansubheader').css('background', '#eee8ab');
    });
    $('div.plansub .plandetail .expand').click(function () {
        $(this).parent().parent().parent().find('.plansubheader').css('background', '');
        $(this).parent().parent().find('.plansubheader').css('background', '#eee8ab');
    });

    //temp fix for www.trainingpeaks.com/ui/public/plans.aspx - until the file can be changed on server
    $("a.buyplan[href^='https://www']")
    .each(function () {
        this.href = this.href.replace(/^https:\/\/www\.trainingpeaks\.com/,
         "https://home.trainingpeaks.com");
    });

});

 
function openwindow(linkurl){
		window.open(linkurl,'','location=yes,resizable=yes,status=yes,width=850,height=600,left='+(screen.availWidth/2-425)+',top='+(screen.availHeight/2-300)+'');	
	}
function finishAjax(id, response) {
    $('#usernameLoading').hide();
    $('#emailLoading').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
} //finishAjax
// Focus first element
$.fn.focus_first = function() {
  var elem = $('input:visible', this).get(0);
  var select = $('select:visible', this).get(0);
  if (select && elem) {
    if (select.offsetTop < elem.offsetTop) {
      elem = select;
    }
  }
  var textarea = $('textarea:visible', this).get(0);
  if (textarea && elem) {
    if (textarea.offsetTop < elem.offsetTop) {
      elem = textarea;
    }
  }
  if (elem) {
    elem.focus();
  }
  return this;
}
function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}
function getProfileQueryString()
{
 var querystring = new Array;
 var q = String (document.location).split ('p=')[1];
 if (!q) 
	return false;
 else
 	q = String (q).split ('&')[0];
 return q;
}

//###################################################
//################ Mobile Detect
//###################################################

var deviceS60 = "series60";
var deviceSymbian = "symbian";
var deviceIPhone = "iphone";
var engineWebKit = "webkit";
var deviceAndroid = "android";
var deviceWinMob = "windows ce";
var deviceBB = "blackberry";
var devicePalm = "palm";
var FireFox = "firefox";
var ie = "ie";
var uagent = navigator.userAgent.toLowerCase();

function DetectFireFox() {
    if (uagent.search(FireFox) > -1)
        return true;
    else
        return false;
}
function DetectIE() {
    if (uagent.search(ie) > -1)
        return true;
    else
        return false;
}
function DetectIPhone() {
    if (uagent.search(deviceIPhone) > -1)
        return true;
    else
        return false;
}


function DetectS60OssBrowser() {
    if (uagent.search(engineWebKit) > -1) {
        if ((uagent.search(deviceS60) > -1 ||
          uagent.search(deviceSymbian) > -1))
            return true;
        else
            return false;
    }
    else
        return false;
}
function DetectAndroid() {
    if (uagent.search(deviceAndroid) > -1)
        return true;
    else
        return false;
}
function DetectAndroidWebKit() {
    if (DetectAndroid()) {
        if (DetectWebkit())
            return true;
        else
            return false;
    }
    else
        return false;
}
function DetectWindowsMobile() {
    if (uagent.search(deviceWinMob) > -1)
        return true;
    else
        return false;
}
function DetectBlackBerry() {
    if (uagent.search(deviceBB) > -1)
        return true;
    else
        return false;
}
function DetectPalmOS() {
    if (uagent.search(devicePalm) > -1)
        return true;
    else
        return false;
}
function DetectMobile() {
    if (DetectS60OssBrowser())
        return true;
    else if (DetectAndroidWebKit())
        return true;
    else if (DetectWindowsMobile())
        return true;
    else if (DetectBlackBerry())
        return true;
    else if (DetectPalmOS())
        return true;
    else if (DetectIPhone())
        return true;
    else
        return false;
}
