//this file contains code that is useful but doesn't get used often - don't link directly to this file unless you plan to use all the functionality here. Instead, copy what you need into javascript.js

//swfobject - http://blog.deconcept.com/swfobject/ - mit license
//usage:
//	<div id="flashcontainer"></div>
//	<script type="text/javascript">
//	new function() {
//		var o = new SWFObject("file.swf", "objectid", width, height, version, bgcolor);
//		o.addParam("wmode", "transparent");
//		o.write("flashcontainer");
//	}();
//	</script>
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

//compact version of behaviour, using Ext.DomQuery as css query engine
//requires prototype 1.6 - ~/administration/layouts/javascript/1_6
//usage: see below
var Behaviour = {
	//param: Object sheet = {cssRule : callback}
	//	where cssRule is a string and callback is a function that passes a DOM element as its parameter and returns null, i.e. void callback(DOMElement element)
	register : function(sheet) {Behaviour.list.push(sheet);},
	//call apply after ajaxing stuff if you want behaviour rules to apply to ajaxed elements
	apply : function() {
		for (h = 0; sheet = Behaviour.list[h]; h++) {
			for (selector in sheet) {
				list = $$(selector);
				if (!list) continue;
				for (i = 0; element = list[i]; i++) sheet[selector](element);
			}
		}
	},
	//private
	list : new Array()
}

//behaviours
Event.observe(window, "load", function() {
	Behaviour.register({
		//CSS hover script for elements that don't accept css hover class in IE6
		"li" : function(element) {
			Event.observe(element, "mouseover", function() {Element.addClassName(element, "over");})
			Event.observe(element, /*@cc_on "mouseleave" || @*/"mouseout", function() {Element.removeClassName(element, "over");})
		},
		//usage:
		//	<ul class="tabs">
		//		<li class="selected"><a href="#body1">Tab 1</a></li>
		//		<li><a href="#body2">Tab 1</a></li>
		//	</ul>
		//	<div id="body1">Body for tab 1</div>
		//	<div id="body2" class="hidden">Body for tab 2</div>
		"ul.tabs li a" : function() {
			var tabs = [];
			return function(element) {
				var index = element.href.indexOf("#") + 1;
				if (index) {
					var body = document.getElementById(element.href.substring(index));
					if (body) {
						element.href = "javascript:;";
						tabs.push({tab : element.parentNode, body : body});
						Event.observe(element, "click", function() {
							for (var tab, i = 0; tab = tabs[i]; i++) {
								Element.removeClassName(tab.tab, "selected");
								Element.addClassName(tab.body, "hidden");
							}
							Element.addClassName(element.parentNode, "selected");
							Element.removeClassName(body, "hidden");
						})
					}
				}
			}
		}()
	});
	Behaviour.apply();
})

// xDocSize r1, Copyright 2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xDocSize(){
var b=document.body, e=document.documentElement;var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
if (e) {esw = e.scrollWidth;eow = e.offsetWidth;esh = e.scrollHeight;eoh = e.offsetHeight;}
if (b) {bsw = b.scrollWidth;bow = b.offsetWidth;bsh = b.scrollHeight;boh = b.offsetHeight;}
return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}

//Modal mask
/* modal mask */
var Modal = {
	openMask : function(options) {
		this.close();//close if open	
		var hasMask, maskStyle;
		if (options){
			hasMask = options.hasMask;
		}		
		maskStyle = (hasMask) ? "modalDark" : "modalLight";
		var modalcontainer = $("modalcontainer");
		var modalmask = $("modalmask")
		if (modalcontainer.hasClassName("hidden")) modalcontainer.removeClassName("hidden");		
		modalcontainer.setStyle({top : "0", left: "0"})
		var pageDimensions = xDocSize();
		modalmask.className = "modalmask";
		modalmask.addClassName(maskStyle);
		modalmask.setStyle ({ 	
			height : pageDimensions["h"] + "px",
			width : pageDimensions["w"] + "px"
		})
	},
	close : function() {
		var modalcontainer = $("modalcontainer");
		if($('modalcontent')){
			$('modalcontent').innerHTML = "";
		}
		if (!modalcontainer.hasClassName("hidden")) modalcontainer.addClassName("hidden");
	},
	resizeHandler : function(){

	},
	open :function(options){		
		var width, url, contentEl, hasMask,title;
		var modalbody = $("modalbody");
		if (options){
			width = options.width || 400;
			url = options.url || "";	
			contentEl = options.contentEl || "";			
			hasMask = options.hasMask;
			title = options.title;
		}
		Modal.openMask({hasMask: hasMask});
		modalbody.setStyle({
			width: width + "px",
			top:(document.documentElement.scrollTop + 100) + "px",
			left:(document.body.offsetWidth / 2) - (width / 2) + "px"
		});	

		if(title){
			$('modaltitle').innerHTML = title;
		}
		
		
		if (url != ""){
			new Ajax.Updater("modalcontent",options.url)	
		} 
		else if (contentEl != ""){
			$("modalcontent").innerHTML = $(contentEl).innerHTML;
			//insanely crappy hack, to appease IE6 and it's refusal to re-render <img>s
			setTimeout(function(){
				$("modalcontent").innerHTML = $("modalcontent").innerHTML
			}, 50);
		}
	}
}
Event.observe (window,"resize",Modal.resizeHandler);
Event.observe(window,"load",function(){									 
	if ($("modalcloser"))Event.observe ("modalcloser","click",Modal.close);
})

/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var ddrivetip = {
	offsetxpoint: -60, //Customize x offset of tooltip
	offsetypoint: 20, //Customize y offset of tooltip
	ie: (document.all),
	ns6: (document.getElementById && !document.all),
	enabletip: false,
	tipobj: "dhtmltooltip",
	ietruebody: function() {
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	},
	show: function(thetext, thecolor, thewidth){
		if ($(this.tipobj)){
			if (typeof thewidth!="undefined") $(this.tipobj).style.width=thewidth+"px";
			if (typeof thecolor!="undefined" && thecolor!="") $(this.tipobj).style.backgroundColor=thecolor;
			$(this.tipobj).innerHTML=thetext.replace(/\'/g,"'");
			this.enabletip=true;
			return false;
		}
	},
	hide: function(){
		if ($(this.tipobj)){
			this.enabletip=false;
			$(this.tipobj).style.visibility="hidden";
			$(this.tipobj).style.left="-1000px";
			$(this.tipobj).style.backgroundColor='';
			$(this.tipobj).style.width='';
		}
	},
	position: function(e){
		if (this.enabletip){
			var curX=(this.ns6)? e.pageX : event.clientX+this.ietruebody().scrollLeft;
			var curY=(this.ns6)? e.pageY : event.clientY+this.ietruebody().scrollTop;
			//Find out how close the mouse is to the corner of the window
			var rightedge=this.ie&&!window.opera? this.ietruebody().clientWidth-event.clientX-this.offsetxpoint : window.innerWidth-e.clientX-this.offsetxpoint-20;
			var bottomedge=this.ie&&!window.opera? this.ietruebody().clientHeight-event.clientY-this.offsetypoint : window.innerHeight-e.clientY-this.offsetypoint-20;
			var leftedge=(this.offsetxpoint<0)? this.offsetxpoint*(-1) : -1000;
			//if the horizontal distance isn't enough to accomodate the width of the context menu
			if (rightedge<$(this.tipobj).offsetWidth)
				//move the horizontal position of the menu to the left by it's width
				$(this.tipobj).style.left=this.ie? this.ietruebody().scrollLeft+event.clientX-$(this.tipobj).offsetWidth+"px" : window.pageXOffset+e.clientX-$(this.tipobj).offsetWidth+"px";
			else if (curX<leftedge)
				$(this.tipobj).style.left="5px";
			else
				//position the horizontal position of the menu where the mouse is positioned
				$(this.tipobj).style.left=curX+this.offsetxpoint+"px";
			//same concept with the vertical position
			if (bottomedge<$(this.tipobj).offsetHeight)
				$(this.tipobj).style.top=this.ie? this.ietruebody().scrollTop+event.clientY-$(this.tipobj).offsetHeight-this.offsetypoint+"px" : window.pageYOffset+e.clientY-$(this.tipobj).offsetHeight-this.offsetypoint+"px";
			else
				$(this.tipobj).style.top=curY+this.offsetypoint+"px";
			$(this.tipobj).style.visibility="visible";
		}
	}
}

document.onmousemove = function(e) {
	ddrivetip.position(e)
};

var Cookie={
	set:function(c_name,value, options) {
		var expireDays = options.expires || 1;
		var today = new Date();
		today.setDate(today.getDate() + expireDays);
		document.cookie=c_name + "=" + escape(value) + ";expires=" + today.toUTCString() + ";path=/";
	},
	get:function(c_name) {
		if (document.cookie.length>0) { 
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1) { 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		}
		return null;
	},
	remove:function(c_name) {this.set(c_name,"",-1);}
}

//Change the submit button for uploading into the spinner
var submitContent = function(form){
	$('uploadButton').addClassName('disabled');
	$('uploadButton').disabled=true;
	setTimeout(function() {form.submit();}, 100)
	return false;
}
//Change the submit button for uploading into the spinner
var submitRegister = function(){
	$('registerButton').addClassName('disabled');
	$('registerButton').disabled=true;
}
//Watch Member
var addToWatchList = function(watcherid,watcheeid){
	new Ajax.Request('/'+$('LangaugeVersion').value+'/admin/manage_users/edit_user/addtowatchlist?watcher='+watcherid+'&watchee='+watcheeid+'&isWatching=true',
		{method:'POST',evalScripts:true,
			onSuccess:function(transport) {
				$('addToWatchList'+watcheeid).innerHTML = transport.responseText;
				$('addToWatchListDiv'+watcheeid).innerHTML = 'Saved!';
				$('addToWatchListDiv'+watcheeid).style.display='';
				var timer = 0;
				for(i = 50; i >= 0; i--) {
					setTimeout("changeOpacity(" + i*2 + ",'addToWatchListDiv"+watcheeid+"');",(timer * 30));
					timer++;
				}
				setTimeout("$('addToWatchListDiv"+watcheeid+"').style.display='none';",3000);				
			}
		});
}

var checkAll = function(){
	$$(".checkbox").each(function(el){
		if($("maincheckbox").checked){
			el.checked = true;
		}
		else{
			el.checked = false;
		}
	});
}
