redux={}; redux.enabled=(window.ie6 || window.ie7 || window.gecko || window.webkit420); redux.layer={};

function getQueryVar(query, variable) { 
var vars = query.split("&"); 
for (var i=0;i<vars.length;i++) { 
var pair = vars[i].split("="); 
if (pair[0] == variable) { return pair[1]; }} 
return false; } 

function mergeVar(variable, value) {
	var mv=variable+'='+value;
	if (page.query=='') return (page.name+'.cfm?'+mv)
	var v=getQueryVar(page.query,variable);
	if (v) {
		return(page.name+'.cfm?'+page.query.replace(variable+'='+v,mv));
	} else {
		return(page.name+'.cfm?'+page.query+'&'+mv);
	}
}

function replaceVar(variable, value, query) {
	var mv=(value=='')?'':variable+'='+value;
	var v=getQueryVar(query,variable);
	if (v) {
		if (mv=='') {
			var temp=query.replace('&'+variable+'='+v,'');
			var temp=temp.replace(variable+'='+v,'')
			return temp;			
		} else {
			return query.replace(variable+'='+v,mv);
		}
	} else {
		if (query == '') {
			return mv;
		} else {
			return (mv=='')?query:query + '&' + mv;
		}
	}
}

function debug(h) {$('pageInfo').innerHTML+=h}
function getElementParent(o,c) {if (o.className==c || o.id==c) {return(o)} else {return getElementParent(o.parentNode,c)}}

function rxurl(v) {	
	//if(v.substring(0,1)=='/') return v.substring(1,v.length);
	
	var tmp=v.split('?')[0].split('.');
	switch (tmp[tmp.length-1]) 
	{
		case "cfm": break;
		default: return false; break;
	}
	
	if(v.substring(0,1)=='/') return v.substring(1,v.length);
	
	switch (v.split(':')[0]) 
	{
		case "javascript": return false; break;
		case "mailto": return false; break;
		case "file": return false; break;
		case "https": if (window.location.protocol == 'http:') {return false} else {break};
		case "http": break;
		default: return v; break;
	}

	var reg = new RegExp(".*" + document.domain + "\/(.*)");
	if (!reg.test(v)) return false;
	return v.replace(reg, "$1");
}

function rxclick(o) {
	var v = rxurl($(o).getProperty('href'));

	if (!v) return true;
	
	redux.get(v,true);
	return false;
}

function rxsubmit(o) {
	
	var out=new Array(); var an={}; var a=new Array();
	x1=$ES('select,input,textarea',$(o));

	$each(x1,function(o){
		if (o.name) {
			if (['submit'].contains(o.type)) {
				if (o.getProperty('clicked') != null) {
					if (!an[o.name]) an[o.name]=[];
					fv=escape(o.value);
					o.removeProperty('clicked');
				}
				return;
			}
			if (['radio'].contains(o.type) && !o.getValue()) return;			
			if (!an[o.name]) an[o.name]=[];
			var fv=escape(o.getValue());
			if (fv) {var co=an[o.name]; co.push(fv);}
		}
	});
	
	for (var x in an) out.push(x+'='+an[x].join(","));
	var str=rxurl(o.action);
	if (!str) return true;
	
	if (o.getProperty('method')=='get') { 
		redux.get(str+"?"+out.join("&"),true);
	} else {
		redux.get(str,true,out.join("&")); 
	}
	
	return false;
}



function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

function rxresource(r) {
	for(res=0; res<r.length; res++) {
		var c=r[res];
		if (c.type=='CSS') {
			var found=false;
			for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
				if (a.getAttribute("cat")==c.title) {
					if (a.id==c.id) {a.disabled=false; found=true} else {a.disabled=true}
				}
			}
			if (!found) {
				xx=new Asset.css(c.url, {id: c.id});
				xx.setAttribute("cat",c.title);
			}
		}
		if (c.type=='JS') {if (!$(c.id)) {new Asset.javascript(c.url, {id: c.id, title: c.title})}}
	}
}

redux.clearObjects = function (o) {
	if (!redux.object) redux.object={};
	for(res=0; res<o.length; res++) {
		var c=o[res]; var co=$(c.o);
		if (!c.hook && c.h && co ) {
			co.empty();
		}
	}
}

redux.setObjects = function (o) {
	if (!redux.object) redux.object={};
	for(res=0; res<o.length; res++) {
		var c=o[res];
		if (c.hook) {
			var hook=window[c.hook]; 
			if(hook) c.vars?hook(c.h,c.vars):hook(c.h);
		} else {
			if (c.h) {
				
			//	alert($('main'));
			//if (window.ie) alert(c.o);
				if ($(c.o)) {
					
					//$(c.o).empty();
					(c.h!='')?$(c.o).setHTML(c.h):$(c.o).empty()
				}; 
				c.h=''
			}
			if (!redux.object[c.o]) redux.object[c.o]=[];
			redux.object[c.o].type=c.t;				
		}
	}
}

redux.load = function (o) {
	if (o.history) {
		window.page=o;
		historySet(o);
	} else {
		window.page.sid=o.sid;	window.page.tid=o.tid
	}
	if (document.title)	document.title=o.title;	
	
	if (o.onstart) o.onstart.call(window);
	if (o.object) redux.clearObjects(o.object);
	if (o.resource) rxresource(o.resource);
	if (o.object) this.setObjects(o.object);
	this.set();
	
	if (o.onload) o.onload.call(window);
	if (window.urchinTracker) {urchinTracker(getPage())}
	if (window.admin_init) admin_init();
	
	if (o.resp) {
		//alert(o.resp);
		if (this.timer) {
			var t=new Date().getTime()-this.timer;
			$('pageInfo').innerHTML='CGI:' + o.resp + 'ms  CTL:' + t + 'ms';}
		else {
			$('pageInfo').innerHTML='CGI:' + o.resp + 'ms';
		}
	}
	
	//alert(t);
}

redux.set = function () {
	if (!redux.enabled) return;
	uRevert=null;
	var rxlinks=document.links;	
	for (var i=0; i<rxlinks.length; i++) {if (!rxlinks[i].onclick && !rxlinks[i].target) rxlinks[i].onclick=function() {return rxclick(this)}}
	var i=0;
	$each($$('form'),function(ol){
		if (ol.getProperty("target")) return;
		$each($ES('input',ol),function(input){
			if(['submit'].contains(input.type) && input.getProperty('name') != null) {
				if (!input.onclick) input.onclick=function() {this.setProperty('clicked',true)}			
			}
		});							  
		if (!ol.onsubmit) ol.onsubmit=function() {return rxsubmit(this)}
	});
}

redux.get = function(n,h,v) {
	var pass2=''; var pass1='';
	for (var x in redux.object)
	{
		var tmp=redux.object[x];
		if (tmp.type==1) {pass1+=x+';'}
		if (tmp.type==2) {pass2+=x+';'}
	}
	
	var rxt=window.page.sid+':'+window.page.tid+':'+((pass1=='')?0:pass1)+':'+((pass2=='')?0:pass2);
	var src = '/' + n + ((n.indexOf("?") > 0)?'&':'?')  + 'rxtype=' + rxt + '&ts=' + new Date().getTime();

	var x=n.indexOf('form=true');
	if (x > 0) n=n.substring(0,x-1);
	redux.timer=new Date().getTime();
	var myXHR = new XHR({method: (v)?'post':'get', onSuccess: function(r){redux.load(Json.evaluate(r))}}).send(src,v);
	window.location.loading=h?n:false;
}

function rxerror(e) {alert(e[0].message)}

function rxrevert(c) {oAlert(c); if (uRevert) uRevert.selectedIndex=0}

function historySet(n) {
	if (window.poll) clearTimeout(poll);
	if (window.location.loading) window.location.hash=getPage();	
	//alert(window.location.loading + '.. ' + getPage());
	if (window.ie) {
		if (window.location.hash=='' || window.location.loading) historyAdd(getPage());
	} else {
		poll=setTimeout('rPoll()',300);
	}
}

function historyResolve(hist) {
	if (getPage()!=hist) {
		redux.get(hist,false);
		window.location.hash=hist;
	}
}

function historyAdd(hist) {
	window.historyObj.document.write("<html><body><script>parent.historyResolve('"+hist+"');<\/script></body></html>");
	window.historyObj.document.close();	
	return void(0);
}


if (window.ie) document.write('<iframe src="/inc/redux/blank.html" style="width:10px; height:10px; position:absolute; left:0px; visibility:hidden;" id="historyObj" name="historyObj"></iframe>'); 

function getPath() {var rPath=window.location.pathname; var rSearch=window.location.search; rPath=rPath.substring(1,rPath.length); if (rPath=='') rPath='index.cfm'; if (rSearch!='') rPath=rPath+rSearch; return rPath}
function getPage() {var rPage=page.name + '.cfm'; if (page.query) rPage=rPage+'?'+page.query; return rPage}

function rPoll() {	
	if (!redux.enabled) return;
	var rHash=window.location.hash; rHash=unescape(rHash.substring(1,rHash.length));
	var rPage=unescape(getPage()); var rPath=unescape(getPath());
	if (rHash!=rPage && rHash!='') {
		//alert(rHash + ' - ' + rPage);
		redux.get(rHash,false);
	} else {
		if (rHash=='' && rPath!=rPage) {
			//alert(rPath + ' - ' + rPage);
			redux.get(rPath,false)
		} else {
			poll=setTimeout('rPoll()',300)
		}
	}
}

redux.layer.create = function(id,html,opt) {	
	if (opt) {		
		if (opt.skin) {rxresource([{url:'/inc/redux/skin/'+opt.skin+'/skin.css?ts=' + new Date().getTime(),type:'CSS',title:'skin_'+opt.skin,id:'skin_'+opt.skin}])}
		if (opt.close) {html+="<img class='control' onclick=\"redux.layer.remove('" + id + "');\" src='/inc/redux/images/btn_ol_close.jpg'>";}
	}
	var newclass=opt.style?'skin skin_'+opt.skin+' '+opt.style:'skin skin_'+opt.skin;
	if ($(id)) {
		var o=$(id); var b=$(id+'body');
		
		b.setHTML(html); 

		if (opt.style) {
			if (opt.style!=$(id+'table').getProperty('class')) {
				$(id+'table').setProperty('class', opt.style);
				oCenter(o,true);
			}
		}
	} else {	
		var o = new Element('span', {'class':'skin skin_'+opt.skin,'id':id,styles:{overflow:'hidden',visibility:'hidden'}});
		var out='<table id="'+id+'table" class="' + opt.style + '" style="position:relative" cellspacing=0 cellpadding=0 border=0><tr><td class="tl"></td><td class="t"></td><td class="tr"></td></tr>';
		out+='<tr><td class="l"></td><td height="100%" class="body" id="'+id+'body" valign=top>'+html+'</td><td class="r"></td></tr>';
		//out+='<tr><td class="l"></td><td class="body" align=right valign=bottom><div id="resizeHandle" class="resizeHandle" style="border-right:3px solid black; border-bottom:3px solid black; width:25px;height:12px; cursor:pointer; background:white; bottom:2px;"></div></td><td class="r"></td></tr>';
		out+='<tr><td class="bl"></td><td class="b"></td><td class="br"></td></tr></table>';
		o.setHTML(out);
		$('worker').appendChild(o);
		oCenter(o,true);
		o.setStyle('visibility','visible');
		var handle=$E('h1',id+'body');
		if (handle) {
			new Drag.Move(o, {handle:handle, droppables: $$('#droppables div')});
			var t=$(id+'table');
			//var tf=$('Kamiro___Frame');
			var tc=t.getCoordinates();
		    //tf.makeResizable({handle:'resizeHandle',limit: {x: [tc.width, 800], y: [tc.height, 800]}});
			

			
		}			
		
		//alert(newclass);
		//oFade(o,0,1);
	}

	return o;
}

redux.layer.remove = function(id) {
	var o=$(id);
	if (window.ie && o.shim) $(o.shim).remove();
	$('olShader').setStyle('visibility','hidden');
	o.remove();
}

function oModeless(c,w) {var o=redux.layer.create('modeless',c,{'skin':'silver','close':true,'style':w})}
function oModal(c,w) {
	if (c.length>1) {
		var o=redux.layer.create('modal',c,{'skin':'silver','close':true,'style':w});
	} else {
		redux.layer.remove('modal');
	}
	//if (!window.ie6) toggleShade(true,.35,'black'); 
}

function oCenter(o,shim) {
	var o=$(o);
	var bs=$(window).getSize();
	var os=o.getSize();
	var l=(bs.size.x-os.size.x)/2;
	var t=(bs.size.y-os.size.y)/2-20+$(window).getScrollTop();
	t=(t<0)?0:t;l=(l<0)?0:l;
	o.setStyle('left',l); o.setStyle('top',t);
	if (shim) oShim(o,true);
}

function oFade(o,s,e,time,fps) {
	if ($(o).getStyle('visibility')=='visible') return;
	var sChange = new Fx.Style($(o), 'opacity', {duration:(time)?time:500, wait:true, fps:(fps)?fps:50}); 
	sChange.start(s,e);
}

function oShim(o,d) {
	return;
	if (window.ie) {
		o=$(o);
		if (!o.shim) {
			//alert('bind');
			//var newShim=new IFrame({'src':'about:blank', 'styles': {'display': 'none', 'position':'absolute'}});
			
			var newShim=new Element('iframe', {'styles': {'display': 'none', 'position':'absolute'}});
			newShim.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
			document.body.appendChild(newShim);
			o.shim=newShim;
		}
		cc=o.shim;
		if (!d) {cc.setStyle('display','none');
			return
		}
		var c=$(o).getCoordinates(); 
		cc.setStyles({width:c.width, backgroundColor:'red', height:c.height, top:c.top, left:c.left, zIndex:parseInt(o.currentStyle.zIndex)-2, display:'block'});
	}	
}

function oAlert(c) {
	$('olLightbody').setHTML('<b>'+c+'</b>');
	oFade('olLightbox',0,1); oCenter('olLightbox',true); toggleShade(true,0,'white');
	setTimeout("oFade('olLightbox',1,0)",1500);
	setTimeout("toggleShade(false)",2000);
	return false;
}

function oLightbox(c) {
	$('olLightbody').setHTML(c+oClose);
	if ($(o).getStyle('visibility')=='hidden') {
		oFade('olLightbox',0,1); 
		oCenter('olLightbox',false); 
		toggleShade(true,.7,'black');
	}
	return false;
}

function oSlideshow(d,s) {
	$('olLightbody').setHTML("<div id='oSlideshow' class='slideshow'><img height='"+s.height+"' width='"+s.width+"' src='"+s.hu+d+"'></div>"+oClose); 
	oFade('olLightbox',0,1); oCenter('olLightbox',false); toggleShade(true,.7,'black');	
	myShow = new Slideshow('oSlideshow', s); 
	return false;
}

function oPage(c,w) {oModal(c,w);}

function toggleShade(state,opacity,color) {
	var s=$('olShader');
	bodySize=$(document.body).getSize();
	s.setStyle('height',(bodySize.scrollSize.y>bodySize.size.y-22)?bodySize.scrollSize.y:bodySize.size.y-22);
	if (state) {
		s.setStyle('background-color',color);
		if (opacity>0) {
			var sChange = new Fx.Style(s, 'opacity', {duration: 500, wait:true, fps: 50});
			oShim('olShader',true);
			sChange.start(0,opacity)
		} else {
			s.setOpacity(.01);
			s.setStyle('visibility','visible');
		}
	} else {
		if (document.title) document.title=page.title;
		$('olShader').setStyle('visibility','hidden');
		//$('olLightbox').setStyle('visibility','hidden');
		//oShim('olLightbox',false);
		oShim('olShader',false);
		if ($('oSlideshow')) $('oSlideshow').remove();
	}	 
}

if (window.ie) {
var sfEls = document.getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
	sfEls[i].onmouseover=function() {this.className+=" sfhover";}         
	sfEls[i].onmouseout=function() {this.className=this.className.replace(new RegExp(" sfhover\\b"), "");}
}}

uRevert=null;
