var isIE  = (document.all) ? true : false;
var isDOM = (document.getElementById) ? true : false;

function subVal(Val,Msg)
{
	if (Val!=="")
	{ 
		if (typeof(Msg)!="undefined") { inlineProcessing(Msg); }
		if (!$('FormStatus')) { addFormStatus(); }
		$('FormStatus').value = Val;
		document.forms[0].submit();
	}
}

function addFormStatus()
{
	var form 		= document.forms[0];
	fStatus 		= document.createElement('input');
	fStatus.type	= 'hidden';
	fStatus.id		= 'FormStatus';
	fStatus.name	= 'FormStatus';
	form.appendChild(fStatus);
}


var klGeneric = {
	  invokeField : ''
	, invokeFunction : ''
	
	, Goto : function (Url) {
		self.location.href = Url;
	}
	
	, SelectState : false
	, SelectAll : function(Prefix, parentObj) 
	{ 
		var pObj = (typeof(parentObj!='undefined')) ? $(parentObj) : document.forms[0];
		var Chks = Form.getInputs(pObj,'checkbox'); 
		klGeneric.SelectState = !klGeneric.SelectState; 
		if (typeof(Prefix)=="undefined") { Prefix="Dl_"; }
		Chks.each( function(idx) { 
			ChkTxt=idx.name.substring(0,Prefix.length);
			if (ChkTxt==Prefix && !idx.disabled) { idx.checked = klGeneric.SelectState; }
		});
		if (klGeneric.SelectState) { klGeneric.allSelected = true; }
	}
	, SelectClass : function(className, parentObj) 
	{ 
		var pObj = (typeof(parentObj!='undefined')) ? $(parentObj) : document.forms[0];
		var Chks = document.getElementsByClassName(className, pObj); 
		klGeneric.SelectState =! klGeneric.SelectState; 
		Chks.each( function(idx) { 
			if (!idx.disabled) { idx.checked = klGeneric.SelectState; }
		});
		if (klGeneric.SelectState) { klGeneric.allSelected = true; }
	}
	
	, allSelected : false
	, markChk : function(Obj) {
		if (!Obj.checked) { klGeneric.allSelected = false; }
	}
	
	, getList : function (Prefix) {
		var itemList=[];
		var Elmnts=[];
		Chks = Form.getInputs(document.forms[0],'checkbox');
		Hidd = Form.getInputs(document.forms[0],'hidden');
		Elmnts = Chks.concat(Hidd);
		if (typeof(Prefix)=="undefined") { Prefix="Dl_"; }
		Elmnts.each( function(idx) { SubName=idx.name.substring(0,Prefix.length); 
		if ((idx.checked||String(idx.getAttribute('rel'))=='checked') && SubName==Prefix) { 
			itemList[itemList.length]=idx.name;
		}});
		return itemList;
	}
	
	, getClassList : function (parent, className) {
		
	}
	
	, getClassType : function (parent, tagName, Prefix) {
		var itemList = [];
		//var Elmnts = $(parent).getElementsByTagName(tagName);
		var Elmnts = $(parent).getElementsBySelector(tagName);
		if (Elmnts) {
			$A(Elmnts).each( function(idx) { SubName=idx.name.substring(0,Prefix.length); 
			if ((idx.checked||String(idx.getAttribute('rel'))=='checked') && SubName==Prefix) { 
				itemList[itemList.length]=idx.name;
			}});
			return itemList;
		}
	}

	, fileBrowse : function (folderType, path, title_str, fillField) {
		if (fillField!='undefined' && fillField!=='') { klGeneric.invokeField = fillField; }
		klGeneric.invokeFunction = 'fillField';
		klGeneric.overlay(true, function() { if (jsAlertMsg) { jsAlertMsg.closeHoverBox(); } klGeneric.overlay(false,null,0); },1);
		inlineFramePop(title_str, 'x_files.php?path='+path+'&local_Title='+title_str, 'FileBrowser', 700, 600, '');
	}
	
	, flvPrev : function (fileName, dispType, title_str, w, h) {
		/*
			dispType - 0 = App Mode
			dispType - 1 = Admin Mode
			dispType - 2 = Hoverbox Only Mode
		*/
		var width 	= (w!='undefined' || w!=='') ? w : 640;
		var height 	= (h!='undefined' || h!=='') ? (parseInt(h,10)+20) : 480;
		if (dispType!=2) {
			klGeneric.overlay(true,function(){ if (jsAlertMsg) { jsAlertMsg.closeHoverBox(); } klGeneric.overlay(false,null,0); },1);
		}
		inlineFramePop(title_str, 'video.php?filename='+fileName, 'VideoPlayer', width, height, '');
	}
	
	, overlay : function (animate, func, state) {
		if (state===0 && $('overlay')) {
			$('overlay').hide();
		}
		else {
			if (!$('overlay')) {
				var objBody = document.getElementsByTagName("body").item(0);
				var objOverlay = document.createElement("div");
				objOverlay.setAttribute('id','overlay');
				objOverlay.style.display = 'none';
				objOverlay.onclick = func;
				objBody.appendChild(objOverlay);
			}
	
			var arrayPageSize = klGeneric.getPageSize();
			$('overlay').setStyle({height:arrayPageSize[1]+'px'});
			if (animate && Effect!=false) { new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.4 }); }
			else { $('overlay').show(); } 
		}
	}
	
	, getPageSize : function () {
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ 
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) { 
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { 
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		var pageHeight = 0;
		if(yScroll<windowHeight) 	{ pageHeight = windowHeight; } else { pageHeight = yScroll; }
		var pageWidth = 0;
		if(xScroll<windowWidth) 	{ pageWidth = windowWidth; } else { pageWidth = xScroll; }
		var arrayPageSize = [pageWidth,pageHeight,windowWidth,windowHeight]; 
		return arrayPageSize;
	}
	
	, getPageScroll : function() {
		var yScroll;
		if (self.pageYOffset) { yScroll = self.pageYOffset; }
		else { 
			if (document.documentElement && document.documentElement.scrollTop) { yScroll = document.documentElement.scrollTop; } 
			else { if (document.body) { yScroll = document.body.scrollTop; } } 
		}
		var arrayPageScroll = ['',yScroll];
		return arrayPageScroll;
	}

	, childInvoke : function (Val) {
		if (this.invokeFunction!=='')
		{
			switch (this.invokeFunction) {
				case "fillField":
					if (this.invokeField!=='') {
						$(this.invokeField).value = Val;
						if (jsAlertMsg) { jsAlertMsg.closeHoverBox(); }
					}
					break;
			}
		}
	}
	
	, reZebra : function (ObjID) {
		var ColorClass = '';
		var ObjList = $(ObjID).getElementsBySelector('li');
		ObjList.each( function(node) {
			ColorClass = (ColorClass!="odd") ? "odd" : "even";
			node.className = ColorClass;
			if (ColorClass=="odd") { $(node).observe("mouseout", function() { this.className = "odd"; }); }
			else { $(node).observe("mouseout", function() { this.className = "even"; }); }
		});
	}
	
	,cancelForm : function(divID, alertMsg) {
		
		function showAlert() { if (alertMsg) { inlineAlertMsg(alertMsg.title, alertMsg.msg, alertMsg.timer); } }
		Effect.SlideUp(divID, {duration:1.5, queue:'end', afterFinish:showAlert });
	}
	
	, inAction : function (txt, state) {
		var inActionTxt = '';
		if ($('inAction'))
		{
			switch (state)
			{
				case 0:
			 		$('inAction').className = 'noactivity';
					break;
				case 1:
					if (txt==='') { inActionTxt = 'Processing, Please Wait...'; }
					else { inActionTxt = txt; }
					$('inAction').innerHTML = inActionTxt;
					$('inAction').className = 'activity';
					break;
			}
		}
	}

	, fixedAction : function (txt, state) {
		var fixedActionTxt = '';
		if (!$('fixedAction'))
		{
			var divElmnt = Builder.node('div', {id:'fixedAction', className:'noactivity'});
			var objBody = document.getElementsByTagName("body").item(0);
			objBody.appendChild(divElmnt);
		}
		if (state==1)
		{
			if (txt==='') { inActionTxt = 'Processing, Please Wait...'; }
			else { inActionTxt = txt; }
			$('fixedAction').innerHTML = inActionTxt;
			$('fixedAction').className = 'fixedactivity';
		}
		else
		{
			$('fixedAction').className = 'noactivity';
		}
	}
	
	, toggleChk : function (Obj) {
		if ($(Obj).hasClassName('chk')) { $(Obj).removeClassName('chk'); }
		else { $(Obj).addClassName('chk'); }
	}
	
	, toggleAll : function (parentObj, togObj) {
		var Elmnts = $(parentObj).getElementsByClassName('member');
		if (togObj.hasClassName('togOn')) { 
			Elmnts.each(function(idx){ if (!$(idx).hasClassName('chk')) { $(idx).addClassName('chk'); } }); 
			$(togObj).className = 'togOff';
			$(togObj).innerHTML = 'Remove assignment from all groups';
		}
		else { 
			Elmnts.each(function(idx){ $(idx).removeClassName('chk'); }); 
			$(togObj).className = 'togOn';
			$(togObj).innerHTML = 'Assign to all groups';
		}
	}
	
	, getMemberIDs : function (parentObj) {
		var members = [];
		var Elmnts = $(parentObj).getElementsByClassName('member');
		Elmnts.each(function(idx) { if ($(idx).hasClassName('chk')) { members.push(idx.id.substring(1)); }});
		if (members.length>0) return members.join(",");
	}
	
	, hideAlerts : function (parentObj) {
		var alertClasses = ['info', 'alert'];
		alertClasses.each( function (className) {
			$(parentObj).getElementsByClassName(className).each(function (idx){ $(idx).hide(); });
		});
	}
}

//(C)webreflection.blogspot.com
function onContent(f){
var a,b=navigator.userAgent,d=document,w=window,
c="__onContent__",e="addEventListener",o="opera",r="readyState",
s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,"()}'></scr","ipt>");
w[c]=(function(o){return function(){w[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(w[c]);
if(d[e])d[e]("DOMContentLoaded",w[c],false);
if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))
(function(){/loaded|complete/.test(d[r])?w[c]():setTimeout(arguments.callee,1)})();
else if(/MSIE/i.test(b))d.write(s);
};

try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}

