﻿// JScript File
Array.prototype.clear=function(){this.length = 0;};
function ShowLoginPopup(loginInputElement) {
	if (window["objSignupModalPopup"] != undefined) {
		objSignupModalPopup.showPopup();
		var obj = document.getElementById(loginInputElement);
		if (obj) obj.select();
	}
}
function Logout(){
	dnaml.HTMLObjects.Logout(LogoutSuccessful, OnAjaxFunctionCallFailed);
}
function LogoutSuccessful(result, contextstring, methodName) {
	LoginLinkSwitch(false);
	UpdateWebElement("divWelcomeMessage");
	UpdateWebElement("divSignin");
	if (document.URL.indexOf("localhost") >= 0)
		window.location = "/ebook.com/";
	else
		window.location = "/";
}
function GetWebObjectID(id) {
	var obj = document.getElementById(id);
	if (obj && obj.attributes["webobjectid"] && obj.attributes["webobjectid"].value)
		return obj.attributes["webobjectid"].value;
	return null;
}
function UpdateDownloadStat(id) {
	dnaml.HTMLObjects.UpdateDownloadStat(id);
}
function UpdateWebElement(id) {
	var webobj = new dnaml.HTMLObject();
	var webobjid = GetWebObjectID(id);
	if (webobjid != null) {
		webobj.IDString = webobjid;
		webobj.ClientID = id;
		LoadObjectInnerHtml(webobj);
	}
}
function CheckLoggedIn() {
	dnaml.HTMLObjects.IsLoggedIn(CheckLoggedInSuccessful, OnAjaxFunctionCallFailed);
}
function CheckLoggedInSuccessful(result) {
	LoginLinkSwitch(result);
}
function LoginLinkSwitch(LoggedIn) {
	var loginDisplay = "none";
	var logoutDisplay = "none";
	if (LoggedIn)
		logoutDisplay = "";
	else
		loginDisplay = "";
	var objLogout = document.getElementById("lnkLogout");
	if (objLogout)
		objLogout.style.display = logoutDisplay;
	var objLogin = document.getElementById("lnkLogin");
	if (objLogin)
		objLogin.style.display = loginDisplay;
	if (LoggedIn) {
		var objsignup = document.getElementById("spanSignupLink");
		if (objsignup) objsignup.style.display = "none";
	}
		
//	var objmenu1 = document.getElementById("menu1");
//	var objmenu2 = document.getElementById("menu2");
//	var objloggedmenu1 = document.getElementById("loggedmenu1");
//	var objloggedmenu2 = document.getElementById("loggedmenu2");
//	if (objmenu1)
//		objmenu1.style.display = loginDisplay;
//	if (objmenu2)
//		objmenu2.style.display = loginDisplay;
//	if (objloggedmenu1)
//		objloggedmenu1.style.display = logoutDisplay;
//	if (objloggedmenu2)
//		objloggedmenu2.style.display = logoutDisplay;
}
function Login(email, password, OnSuccess){
	var stremail = email;
	var strpassword = password;
	if (email == null) {
		var objusername = document.getElementById("tbLoginEmail");
		if (objusername != null)
			stremail = objusername.value;
	}
	if (password == null) {
		var objpassword = document.getElementById("tbLoginPassword");
		if (objpassword != null)
			strpassword = objpassword.value;
	}
	if (stremail && strpassword) {
		if (OnSuccess != null)
			dnaml.HTMLObjects.Login(stremail, strpassword, OnSuccess, OnAjaxFunctionCallFailed, stremail);
		else
			dnaml.HTMLObjects.Login(stremail, strpassword, LoginCallSuccessful, OnAjaxFunctionCallFailed, stremail);
	}
}
function LoginCallSuccessful(result, contextstring, methodName) {
	if (result.indexOf("http:") == 0) {
		window.location = result;
		return;
	}
	if (result) {
		var obj = document.getElementById("lblMessage");
		if (obj)
			obj.innerHTML = result;
	}
	else {
		if (window["objSignupModalPopup"] != undefined)
			objSignupModalPopup.hidePopup();
		LoginLinkSwitch(true);
		UpdateWebElement("divWelcomeMessage");
		UpdateWebElement("divSigninTop");
		//if (__browserEnvironment.IE)
			__draggingMagneticPanels.reloadAllPanels();
		//else
		//	window.location = window.location;
	}
}
function LoadObjectInnerHtml(webobj) {
	dnaml.HTMLObjects.LoadObjectInnerHtml(webobj, FillObject, OnAjaxFunctionCallFailed, webobj.ClientID);
}
function LoadObjectBody(clientID, pageidx, pagesize) {
	var webobjid = GetWebObjectID(clientID);
	if (webobjid != null) {
		var obj = document.getElementById(clientID + "LoadingImg");
		if (obj) obj.style.display = "block";
		var param = "<PAGEIDX>" + pageidx + "</PAGEIDX>" + "<PAGESIZE>" + pagesize + "</PAGESIZE>";
		var webobj = new dnaml.HTMLObject();
		webobj.IDString = webobjid;
		webobj.Params = param;
		webobj.clientID = clientID;
		dnaml.HTMLObjects.LoadObjectInnerHtml(webobj, FillObject, OnAjaxFunctionCallFailed, clientID);
	}
}
function ResetObjectPositions() {
}
function LoadObjectBodySuccessful(result, id, methodName) {
	//var obj = document.getElementById(id+LoadingImg
	FillObject(result, id, methodName);
}
function LoadCategoryObjectBody(parentID, clientID, loadElementID, pageidx, pagesize, searchparam) {
	var webobjid = GetWebObjectID(clientID);
	if (webobjid != null) {
		var obj = document.getElementById(loadElementID);
		if (obj) obj.style.display = "block";
		var param = "<PAGEIDX>" + pageidx + "</PAGEIDX>" + "<PAGESIZE>" + pagesize + "</PAGESIZE>";
		if (searchparam != null) {
			var ary = searchparam.split(":");
			var criteria = ary[0];
			var exp = "";
			if (ary.length > 1) exp = ary[1];
			param += "<CategoryUrlEncoded>" + criteria + "</CategoryUrlEncoded>";
			param += "<SearchExpression>" + exp + "</SearchExpression>";
		}
		var webobj = new dnaml.HTMLObject();
		webobj.IDString = webobjid;
		webobj.ClientID = clientID;
		webobj.Params = param;
		webobj.LoadingProgressElementID = loadElementID;
		webobj.ParentObjectIDString = parentID;
		dnaml.HTMLObjects.LoadObjectInnerHtml(webobj, FillObject, OnAjaxFunctionCallFailed, clientID);
	}
}
function LoadSearchObjectBody(parentID, clientID, loadElementID, pageidx, pagesize, searchparam) {
	var webobjid = GetWebObjectID(clientID);
	if (webobjid != null) {
		var obj = document.getElementById(loadElementID);
		if (obj) obj.style.display = "block";
		var param = "<PAGEIDX>" + pageidx + "</PAGEIDX>" + "<PAGESIZE>" + pagesize + "</PAGESIZE>";
		if (searchparam != null) {
			var ary = searchparam.split(":");
			var criteria = ary[0];
			var exp = "";
			if (ary.length > 1) exp = ary[1];
			param += "<SearchCriteria>" + criteria + "</SearchCriteria>";
			param += "<SearchExpression>" + exp + "</SearchExpression>";
		}
		var webobj = new dnaml.HTMLObject();
		webobj.IDString = webobjid;
		webobj.ClientID = clientID;
		webobj.Params = param;
		webobj.LoadingProgressElementID = loadElementID;
		webobj.ParentObjectIDString = parentID;
		dnaml.HTMLObjects.LoadObjectInnerHtml(webobj, FillObject, OnAjaxFunctionCallFailed, clientID);
	}
}
function LoadManageEBookList(parentID, clientID, loadElementID, pageidx, pagesize, searchparam) {
	var webobjid = GetWebObjectID(clientID);
	if (webobjid != null) {
		var obj = document.getElementById(loadElementID);
		if (obj) obj.style.display = "block";
		var param = "<PAGEIDX>" + pageidx + "</PAGEIDX>" + "<PAGESIZE>" + pagesize + "</PAGESIZE>";
		if (searchparam != null) {
			var ary = searchparam.split(":");
			var criteria = ary[0];
			var exp = "";
			if (ary.length > 1) exp = ary[1];
			param += "<SearchCriteria>" + criteria + "</SearchCriteria>";
			param += "<SearchExpression>" + exp + "</SearchExpression>";
		}
		var webobj = new dnaml.HTMLObject();
		webobj.IDString = webobjid;
		webobj.ClientID = clientID;
		webobj.Params = param;
		webobj.LoadingProgressElementID = loadElementID;
		webobj.ParentObjectIDString = parentID;
		dnaml.HTMLObjects.LoadObjectInnerHtml(webobj, FillObject, OnAjaxFunctionCallFailed, clientID);
	}
}
function FillObject(result, id, methodName) {
	if (result == null) return;
	var obj = document.getElementById(id);
	if (obj) {
		obj.innerHTML = result.innerHTML;
		if (result.OnLoadJavaScript.length > 0)
			eval(result.OnLoadJavaScript);
		for (var i = 0; i < result.RequiredJavaScriptFiles.length; i++)
			__externalJavaScriptFileLoader.appendjavascriptreference(result.RequiredJavaScriptFiles[i]);
	}
	if (result.LoadingProgressElementID != "") {
		obj = document.getElementById(result.LoadingProgressElementID);
		if (obj) obj.style.display = "none";
	}
}
function GetPageObjectList() {
	dnaml.HTMLObjects.GetPageObjectList(OnGetPageObjectListSuccessful)
}
function OnGetPageObjectListSuccessful(result) {
	var objlist = new NameValueCollection();
	for (var item in result) { objlist.add(item, result[item]); }
	__dataStoreBehavior.storeClientData("serverpageobjectlist", objlist);
}
function LoadUserContentObject(clientID, contentgrpid, contenttype, pageidx, pagesize) {
	var parentID = "";
	var loadElementID = "";
	var webobjid = GetWebObjectID(clientID);
	if (webobjid != null) {
		var obj = document.getElementById(clientID + "LoadingImg");
		if (obj) {obj.style.display = "block"; loadElementID = clientID + "LoadingImg";}
		var param = "<PAGEIDX>" + pageidx + "</PAGEIDX>" + "<PAGESIZE>" + pagesize + "</PAGESIZE>";
		param += "<ContentGroupID>" + contentgrpid + "</ContentGroupID><ContentTypeID>" + contenttype + "</ContentTypeID>";
		var webobj = new dnaml.HTMLObject();
		webobj.IDString = webobjid;
		webobj.ClientID = clientID;
		webobj.Params = param;
		webobj.LoadingProgressElementID = loadElementID;
		webobj.ParentObjectIDString = parentID;
		dnaml.HTMLObjects.LoadObjectInnerHtml(webobj, FillObject, OnAjaxFunctionCallFailed, clientID);
	}
}
function LoadContentsObject(id, clientID) {
//	var params = __dataStoreBehavior.readClientRawData(id);
//	var statusParams = __dataStoreBehavior.readClientRawData(id + "_displaymode");
//	if (params.length == 0 || ("<" + id.toLowerCase() + "></" + id.toLowerCase() + ">") == params)
//		params = "<_DEFAULT_/>";
//	else {
//	if (statusParams.length != 0)
//		params += statusParams;
//	}
	var webobj = new dnaml.HTMLObject();
	webobj.IDString = id;
	webobj.ClientID = clientID;
	webobj.Params = "";
	dnaml.HTMLObjects.LoadObjectInnerHtml(webobj, FillContentsObject, OnAjaxFunctionCallFailed, clientID);
}
function FillContentsObject(result, clientID, methodName) {
	FillObject(result, clientID, methodName);
	var obj = document.getElementById(clientID);
	if (window["__draggingMagneticPanels"] != null) __draggingMagneticPanels.storeContainerObjectPositions(obj);
}
function OnLoadJavaScript(id) {
	dnaml.HTMLObjects.GetObjectOnLoadJavaScript(id, RunOnLoadJavaScript, OnAjaxFunctionCallFailed, id);
}
function RunOnLoadJavaScript(result, id, methodName) {
	setTimeout(result, 1000);
}
function OnAjaxFunctionCallFailed(execption, contextstring, methodName){
	return 0;
}

function ObjectContentLoadTrigger(triggerId, contentId) {
	this.triggerId = triggerId;
	this.contentId = contentId;
	this.contentIdx = 0;
}
function ObjectContentLoadTriggerBehavior() {
	this.aryTriggers = new Array();
}
ObjectContentLoadTriggerBehavior.prototype = {
	regTrigger : function(triggerId, contentId) {
		var objTrigger = new ObjectContentLoadTrigger(triggerId, contentId);
		this.aryTriggers.push(objTrigger);
	},
	getTrigger : function(triggerId) {
		for (var i = 0; i < this.aryTriggers.length; i++) {
			if (this.aryTriggers[i].triggerId == triggerId)
				return this.aryTriggers[i];
		}
		return null;
	},
//	loadNextContent : function(triggerId) {
//		var objTrigger = this.getTrigger(triggerId);
//		if (!objTrigger) return;
//	},
//	loadPreviousContent : function(triggerId) {
//		var objTrigger = this.getTrigger(triggerId);
//		if (!objTrigger) return;
//	}
	loadNextContent : function(triggerId) {
		var objTrigger = document.getElementById(triggerId);
		if (!objTrigger) return;
		var contentBody = objTrigger.getAttribute("contentbody");
		if (!contentBody) return;
	},
	loadPreviousContent : function(triggerId) {
		var objTrigger = this.getTrigger(triggerId);
		if (!objTrigger) return;
	}
}
function ExternalJavaScriptFileLoader() {
	this.numOfFilesToDownload = 0;
	this.numOfLoadedFiles = 0;
}
ExternalJavaScriptFileLoader.prototype = {
	initLoading : function(count) {
		window["numOfJavascriptFilesToDownload"] = count;
		window["numOfJavascriptFileLoaded"] = 0;
//		this.numOfFilesToDownload = count;
//		this.numOfLoadedFiles = 0;
	},
	include : function(url) {
		this.appendjavascriptreference(url);
	},
	appendjavascriptreference : function(url) {
		var e = document.createElement("script");
		e.src = url;
		e.type="text/javascript";
		var header = document.getElementsByTagName("head")[0];
		var bex = false;
		for (var i = 0; i < header.childNodes.length; i++) {
			var scr = header.childNodes[i];
			if (scr.src == url) {
				bex = true;
				this.numOfLoadedFiles++;
				break;
			}
		}
		if (!bex)
			header.appendChild(e);
	},
	appendjavascriptblock : function(script) {
		if (!__externalJavaScriptFileLoader) return;
		var interval = setInterval(function() {
		  if ((window["numOfJavascriptFileLoaded"] != null) && (window["numOfJavascriptFilesToDownload"] != null) && (window["numOfJavascriptFileLoaded"] >= window["numOfJavascriptFilesToDownload"])) {
			clearInterval(interval);
			__externalJavaScriptFileLoader.appendjavascriptblockcallback(script);
		  }
		}, 10);
	},
	appendjavascriptblockcallback : function(script) {
		var e = document.getElementById("__scriptOnLoadBlock");
		if (!e){
			e = document.createElement('span');
			e.id = '__scriptOnLoadBlock';
			document.getElementsByTagName('body')[0].appendChild(e);
		}
		while(e.childNodes.length > 0) e.removeChild(e.childNodes[0]);
		var scr = document.createElement("script");
		scr.type="text/javascript";
		scr.text=script;
		e.appendChild(scr);
	},
	addEventListener : function(element, ieeventname, mozeventname, func) {
		if (element.addEventListener) {
			element.addEventListener (mozeventname,func,false);
			element.addEventListener (mozeventname,func,false);
		} else if (element.attachEvent) {
			element.attachEvent (ieeventname,func);
			element.attachEvent (ieeventname,func);
		}
	},
	removeEventListener : function(element, ieeventname, mozeventname, func) {
		if (element.removeEventListener) {
			element.removeEventListener (mozeventname,func,false);
			element.removeEventListener (mozeventname,func,false);
		} else if (element.detachEvent) {
			element.detachEvent (ieeventname,func);
			element.detachEvent (ieeventname,func);
		}
	},
	setClickEvent : function(id, eventHandler) {
		var obj = document.getElementById(id);
		if (obj) obj.onclick = eventHandler;
	},
	runAfterLoading : function(script) {
		var interval2 = setInterval(function() {
		  if ((window["numOfJavascriptFileLoaded"] != null) && (window["numOfJavascriptFilesToDownload"] != null) && (window["numOfJavascriptFileLoaded"] >= window["numOfJavascriptFilesToDownload"])) {
			clearInterval(interval2);
			eval(script);
		  }
		}, 10);
	},
	waitForGlobalInstance : function(objname, script) {
		var interval = setInterval(function() {
			if (window[objname] != null) {
				clearInterval(interval); eval(script);
			}
		}, 10);
	}
}
function NameValuePair(name, value) {
	this.key = name;
	this.value = value;
}
function NameValueCollection() {
	this.typeName = "NameValueCollection";
	this.arrayData = new Array();
}
NameValueCollection.prototype = {
	add : function(key, value) {
		var idx = this.indexOf(key);
		var item = new NameValuePair(key, value);
		if (idx > -1) this.arrayData.splice(idx, 1, item);
		else this.arrayData.push(item);
	},
	remove : function(key, value) {
		var idx = this.indexOf(key);
		if (idx > -1) this.arrayData.splice(idx, 1);
	},
	removeAt : function(idx) {
		if (idx >= 0 && idx < this.arrayData.length)
			this.arrayData.splice(idx, 1);
	},
	item : function(idx) {
		if (idx >= 0 && this.arrayData.length > idx)
			return this.arrayData[idx];
		else
			return null;
	},
	indexOf : function(key) {
		var idx = -1;
		for (var i = 0; i < this.arrayData.length && idx == -1; i++) {
			if (this.arrayData[i].key == key) idx = i;
		}
		return idx;
	},
	valueOf : function(key) {
		var val = null;
		for (var i = 0; i < this.arrayData.length; i++) {
			if (this.arrayData[i].key == key) val = this.arrayData[i];
		}
		return val;
	},
	setValue : function(key, value) {
		for (var i = 0; i < this.arrayData.length; i++) {
			if (this.arrayData[i].key == key) this.arrayData[i].value = value;
		}
	},
	length : function() {
		return this.arrayData.length;
	},
	clear : function() {
		while (this.arrayData.length > 0) this.arrayData.pop();
	},
	toXmlString : function(dataname) {
		if (dataname == null) return "";
		var str = "<" + dataname.toLowerCase() + ">";
		for (var i = 0; i < this.arrayData.length; i++) {
			var item = this.item(i);
			str += "<" + item.key.toLowerCase() + ">" + item.value + "</" + item.key.toLowerCase() + ">";
		}
		str += "</" + dataname.toLowerCase() + ">";
		return str;
	},
	fromXmlString : function(xml, dataname) {
		var pos = 0;
		var pos2 = 0;
		if (dataname == null) {
			dataname = __dataStoreBehavior.getFirstXmlNodeName(xml);
		}
		var strstart = "<" + dataname + ">";
		var strend = "</" + dataname + ">";
		var end = xml.indexOf(strend);
		pos2 = xml.indexOf(strstart) + strstart.length;
		this.clear();
		while (pos < end) {
			pos = xml.indexOf("<", pos2);
			pos2 = xml.indexOf(">", pos);
			var key = xml.substring(pos + 1, pos2);
			pos = pos2;
			pos2 = xml.indexOf("</" + key + ">", pos);
			var value = xml.substring(pos + 1, pos2);
			this.add(key, value);
			pos = pos2 + key.length + 3;
			pos2 = pos;
		}
	},
	append : function(collection) {
		if (!collection.typeName || collection.typeName != "NameValueCollection") return;
		for (var i = 0; i < collection.length(); i++) {
			this.add(collection.item(i).key, collection.item(i).value);
		}
	},
	filterWithKeySubstring : function(substr) {
		var nvc = new NameValueCollection();
		for (var i = 0; i < this.length(); i++) {
			if (this.item(i).key.indexOf(substr) >= 0) 
				nvc.add(this.item(i).key, this.item(i).value);
		}
		return nvc;
	},
	filterWithKeyPrefix : function(prefix) {
		var nvc = new NameValueCollection();
		for (var i = 0; i < this.length(); i++) {
			if (this.item(i).key.indexOf(prefix) == 0) 
				nvc.add(this.item(i).key, this.item(i).value);
		}
		return nvc;
	},
	keyNumberingWithPrefix : function(prefix) {
		for (var i = 0; i < this.length(); i++) {
			this.item(i).key = prefix + i.toString();
		}
	},
	findValueIndex : function(val, startIdx) {
		if (startIdx == null) startIdx = 0;
		var idx = -1;
		for (var i = startIdx; i < this.length(); i++) {
			if (this.item(i).value == val) {
				idx = i; break;
			}
		}
		return idx;
	}
}
function WebObjectVisibilityStatus(webobjectid, parentobjectid, visible) {
	this.webobjectid = webobjectid;
	this.parentobjectid = parentobjectid;
	this.visible = visible;
}
function DataStoreBehavior() {
	this.containersprefix = "";
	this.containers = new Array("OBJ0000000060","OBJ0000000061","OBJ0000000062");
}
DataStoreBehavior.prototype = {
	setContainers : function() {
		var objpid = document.getElementById("hfpid");
		var objpouid = document.getElementById("hfpouid");
		var pid = 1;
		var pouid = 0;
		if (objpid) pid = parseInt(objpid.value);
		if (objpouid) pouid = parseInt(objpouid.value);
		this.containersprefix = "";
		if (pid == 1)
			this.containers = new Array("OBJ0000000060","OBJ0000000061","OBJ0000000062");
		if (pid == 14 || pid == 15) {
			this.containers = new Array("OBJ0000000241","OBJ0000000242","OBJ0000000243");
			this.containersprefix = "POUID" + pouid + "_";
		}
	},
	setCookie : function(cname, value, expiredays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=cname+"="+escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	},
	getCookie : function(cname) {
		if (document.cookie.length>0)
		{
			var c_start=document.cookie.indexOf(cname + "=");
			if (c_start!=-1)
			{
				c_start=c_start + cname.length+1;
				var 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 "";
	},
	deleteCookie : function(cname) {
		var cdate = new Date ( );  // current date & time
		cdate.setTime ( cdate.getTime() - 1 );
		document.cookie = cname += "=; expires=" + cdate.toGMTString();
	},
	storeClientData : function(dataname, datavalue) {
		var str = "";
		if (typeof(datavalue) == 'string')
			str = datavalue;
		else if (datavalue.arrayData != undefined) {
			str = datavalue.toXmlString(dataname);
		}
		if (str.length > 0)
			this.setCookie(dataname, str, 365 * 5);
	},
	readClientData : function(dataname, resetExpires) {
		var val = this.readClientRawData(dataname, resetExpires);
		var retVal = null;
		if (this.isXmlData(dataname, val)) {
			retVal = new NameValueCollection();
			retVal.fromXmlString(val);
		}
		else
			retVal = val;
		return retVal;
	},
	readClientRawData : function(dataname, resetExpires) {
		var val = this.getCookie(dataname);
		if (resetExpires == null || resetExpires == true)
			this.setCookie(dataname, val, 365 * 5);
		return val;
	},
	isXmlData : function(dataname, val) {
		if (val.length > dataname.length + 1 && val.substr(0, dataname.length + 2).toLowerCase() == "<" + dataname.toLowerCase() + ">") return true;
		return false;
	},
	getFirstXmlNodeName : function(xml, idx) {
		if (idx == null) idx = 0;
		pos = xml.indexOf("<", idx);
		pos2 = xml.indexOf(">", idx + 1);
		return xml.substring(pos + 1, pos2);
	},
	storeServerData : function(dataname, datavalue, callback) {
	},
	storeObjectStatus : function(idstr, params) {
		dnaml.HTMLObjects.StoreObjectStatus(idstr, params);
	},
	removeObjectWithClientID : function(clientID) {
		var obj = document.getElementById(clientID);
		if (obj) {
			obj.style.display='none';
			var webobjectid = obj.getAttribute("webobjectid");
			if (webobjectid)
				__dataStoreBehavior.setObjectInvisible(webobjectid);
		}
	},
	setObjectInvisible : function(idstr, setServer) {
		var foundininvisible = false;
		for (var i = 0; i < this.containers.length; i++) {
			var nvColl = this.readClientData(this.containersprefix + this.containers[i], false);
			if (nvColl == "")
				nvColl = new NameValueCollection();
			var nvcVisible = nvColl.filterWithKeyPrefix("item");
			var nvcInvisible = nvColl.filterWithKeyPrefix("invisibleitem");
			nvcVisible.keyNumberingWithPrefix("item");
			nvcInvisible.keyNumberingWithPrefix("invisibleitem");
			var idxfound = nvcVisible.findValueIndex(idstr);
			if (idxfound > -1) {
				nvcVisible.removeAt(idxfound);
				nvcVisible.keyNumberingWithPrefix("item");
				idxfound = nvcInvisible.findValueIndex(idstr);
				if (idxfound == -1)
					nvcInvisible.add('invisibleitem' + nvcInvisible.length(), idstr);
			}
			nvColl.clear();
			nvColl.append(nvcVisible);
			nvColl.append(nvcInvisible);
			this.storeClientData(this.containersprefix + this.containers[i], nvColl);
			if (foundininvisible == false) {
				idxfound = nvcInvisible.findValueIndex(idstr);
				if (idxfound > -1) foundininvisible = true;
			}
		}
		if (!foundininvisible) {
			var nvColl = this.readClientData(this.containersprefix + this.containers[0], false);
			if (nvColl == "")
				nvColl = new NameValueCollection();
			var nvcVisible = nvColl.filterWithKeyPrefix("item");
			var nvcInvisible = nvColl.filterWithKeyPrefix("invisibleitem");
			nvcVisible.keyNumberingWithPrefix("item");
			nvcInvisible.keyNumberingWithPrefix("invisibleitem");
			nvcInvisible.add("invisibleitem" + nvcInvisible.length(), idstr);
			nvColl.clear();
			nvColl.append(nvcVisible);
			nvColl.append(nvcInvisible);
			this.storeClientData(this.containersprefix + this.containers[0], nvColl);
		}
		if (setServer == null || setServer == true)
			dnaml.HTMLObjects.SetObjectInvisible(idstr);
	},
	setObjectVisible : function(idstr, setServer) {
		var foundinvisible = false;
		for (var i = 0; i < this.containers.length; i++) {
			var nvColl = this.readClientData(this.containersprefix + this.containers[i], false);
			if (nvColl == "")
				nvColl = new NameValueCollection();
			var nvcVisible = nvColl.filterWithKeyPrefix("item");
			var nvcInvisible = nvColl.filterWithKeyPrefix("invisibleitem");
			nvcVisible.keyNumberingWithPrefix("item");
			nvcInvisible.keyNumberingWithPrefix("invisibleitem");
			var idxfound = nvcInvisible.findValueIndex(idstr);
			if (idxfound > -1) {
				nvcInvisible.removeAt(idxfound);
				nvcInvisible.keyNumberingWithPrefix("invisibleitem");
				idxfound = nvcVisible.findValueIndex(idstr);
				if (idxfound == -1)
					nvcVisible.add('item' + nvcVisible.length(), idstr);
			}
			nvColl.clear();
			nvColl.append(nvcVisible);
			nvColl.append(nvcInvisible);
			this.storeClientData(this.containersprefix + this.containers[i], nvColl);
			if (foundinvisible == false) {
				idxfound = nvcVisible.findValueIndex(idstr);
				if (idxfound > -1) foundinvisible = true;
			}
		}
		if (!foundinvisible) {
			var nvColl = this.readClientData(this.containersprefix + this.containers[0], false);
			if (nvColl == "")
				nvColl = new NameValueCollection();
			var nvcVisible = nvColl.filterWithKeyPrefix("item");
			var nvcInvisible = nvColl.filterWithKeyPrefix("invisibleitem");
			nvcVisible.keyNumberingWithPrefix("item");
			nvcInvisible.keyNumberingWithPrefix("invisibleitem");
			nvcVisible.add("item" + nvcVisible.length(), idstr);
			nvColl.clear();
			nvColl.append(nvcVisible);
			nvColl.append(nvcInvisible);
			this.storeClientData(this.containersprefix + this.containers[0], nvColl);
		}
		if (setServer == null || setServer == true)
			dnaml.HTMLObjects.SetObjectVisible(idstr);
	},
	getAllObjectVisibility : function() {
		var visibility = new Array();
		for (var i = 0; i < this.containers.length; i++) {
			var nvColl = this.readClientData(this.containersprefix + this.containers[i], false);
			if (nvColl != "" && nvColl.length() > 0) {
				var nvcVisible = nvColl.filterWithKeyPrefix("item");
				var nvcInvisible = nvColl.filterWithKeyPrefix("invisibleitem");
				for (var j = 0; j < nvcVisible.length(); j++) {
					var visibleStatus = new WebObjectVisibilityStatus(nvcVisible.item(j).value,
						this.containers[i],
						true);
					visibility.push(visibleStatus);
				}
				for (var j = 0; j < nvcInvisible.length(); j++) {
					var visibleStatus = new WebObjectVisibilityStatus(nvcInvisible.item(j).value,
						this.containers[i],
						false);
					visibility.push(visibleStatus);
				}
			}
		}
		return visibility;
	}
}
function SearchBooks() {
	this.aryCriteria = new NameValueCollection();
	this.searchElemIDPrefix = "spanCond";
	this.searchEditboxID = "tbSearch";
	this.selectedCssClass = "MainSearchCriteriaSelected";
	this.defaultCssClass = "MainSearchCriteria";
	this.searchExpression = "";
}
SearchBooks.prototype = {
	init : function() {
		this.readSettingFromCookie();
	},
	search : function() {
		var cond = "";
		var obj = document.getElementById(this.searchEditboxID);
		if (obj) {
			this.storeSetting("exp", obj.value);
			for (var i = 0; i < 3; i++) {
				if (this.aryCriteria.item(i).value == "1") {
					if (cond.length > 0)
						cond += "_";
					cond += this.aryCriteria.item(i).key;
				}
			}
			if (document.URL.indexOf("localhost") >= 0)
				window.location = "default.aspx?pg=search&p0=" + cond + "&p1=" + obj.value;
			else
				window.location = "/search/" + cond + "/" + obj.value;
		}
	},
	readSettingFromCookie : function() {
		this.searchExpression = __dataStoreBehavior.getCookie("searchcriteria_exp");
		this.aryCriteria.clear();
		var val1 = __dataStoreBehavior.getCookie("searchcriteria_title");
		if (val1.length == 0) val1 = "0";
		var val2 = __dataStoreBehavior.getCookie("searchcriteria_authors");
		if (val2.length == 0) val2 = "0";
		var val3 = __dataStoreBehavior.getCookie("searchcriteria_keywords");
		if (val3.length == 0) val3 = "0";
		this.aryCriteria.add("title", val1);
		this.aryCriteria.add("authors", val2);
		this.aryCriteria.add("keywords", val3);
		if (val1 == "0" && val2 == "0" && val3 == "0") {
			this.storeSetting("title", "1");
			this.storeSetting("authors", "1");
		}
		else {
			this.storeSetting("title", val1);
			this.storeSetting("authors", val2);
			this.storeSetting("keywords", val3);
		}
	},
	storeSetting : function(criteria, val) {
		__dataStoreBehavior.setCookie("searchcriteria_" + criteria, val, 1);
		if (criteria != "exp")
			this.aryCriteria.setValue(criteria, val);
	},
	setSearchCriteriaSelection : function() {
		for (var i = 1; i <= 3; i++) {
			var obj = document.getElementById(this.searchElemIDPrefix + i.toString());
			if (obj) {
				if (this.aryCriteria.item(i - 1).value == "1")
					obj.className = this.selectedCssClass;
				else
					obj.className = this.defaultCssClass;
				obj.setAttribute("selectedvalue", this.aryCriteria.item(i - 1).value);
			}
		}
		var obj = document.getElementById(this.searchEditboxID);
		if (obj) {
			obj.value = this.searchExpression;
			__textBoxDecoration.switchClass(obj);
		}
	},
	toggleCriteriaSetting : function(elemObj, nocookie) {
		var checked = elemObj.getAttribute("selectedvalue");
		if (checked == "1")
			checked = "0";
		else
			checked = "1";
		this.setCriteria(elemObj, checked, nocookie);
	},
	setCriteria : function(elemObj, val, nocookie) {
		elemObj.setAttribute("selectedvalue", val);
		var criteria = elemObj.getAttribute("searchcriteria");
		if (nocookie == null || nocookie == false)
			this.storeSetting(criteria, val);
		if (val == "1")
			elemObj.className = this.selectedCssClass;
		else
			elemObj.className = this.defaultCssClass;
	}
}
if (window["__dataStoreBehavior"] == null) var __dataStoreBehavior = new DataStoreBehavior();
if (window["__searchBooks"] == null) {
	 window["__searchBooks"] = new SearchBooks();
	 __searchBooks.init();
}
if (window["__externalJavaScriptFileLoader"] == null) var __externalJavaScriptFileLoader = new ExternalJavaScriptFileLoader();
