﻿function Browser(){d = document;var nav=navigator; this.agt=nav.userAgent.toLowerCase(); this.major = parseInt(nav.appVersion); this.ns=(d.layers); this.dom=(d.getElementById)?1:0; this.ns4up=(this.ns && this.major >=4); this.ns6=(this.agt.indexOf("Netscape6")!=-1); this.op=(window.opera? 1:0); this.ie=(d.all); this.ie5=(d.all&&this.dom); this.fb=(this.agt.indexOf("firebird")!=-1); this.sf=(this.agt.indexOf("safari")!=-1); this.win=((this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1)); this.mac=(this.agt.indexOf("mac")!=-1);}
var oBw = new Browser();
function getW(o) { var w=0; w=(oBw.op)? o.style.pixelWidth:o.offsetWidth; return w; }
function getH(o) { var h=0; h=(oBw.op)? o.style.pixelHeight:o.offsetHeight; return h; }
function getPageX(o) { if (oBw.op) {  var x=0; while(eval(o)) { x+=o.style.pixelLeft; e=o.offsetParent; } return x; } else { var m=(oBw.mac&&oBw.ie)? document.body.leftMargin:0; var x=0; while(eval(o)) { x+=o.offsetLeft; o=o.offsetParent; } return parseInt(x)+parseInt(m) } }
function getPageY(o) { if(oBw.ns) { var y=(o.pageY)? o.pageY:o.y; return y; } else if (oBw.op) {  var y=0; while(eval(o)) { y+=o.style.pixelTop; o=o.offsetParent; } return y; }  else { var m = (oBw.mac&&oBw.ie)? document.body.topMargin:0; var y=0; while(eval(o)) { y+=o.offsetTop; o=o.offsetParent; }  return parseInt(y)+parseInt(m); } }
function addEvt(o,e,f,c){ if(o.addEventListener)o.addEventListener(e,f,c);else if(o.attachEvent)o.attachEvent("on"+e,f);else eval("o.on"+e+"="+f)}
function remEvt(o,e,f) { if(o.removeEventListener)o.removeEventListener(e,f,false);else if(o.detachEvent)o.detachEvent('on'+e,f); }
function _setPageX(o,x) { if(oBw.op) o.style.pixelLeft=x; else o.style.left=x;}
function _setPageY(o,y) { if(oBw.op) o.style.pixelTop=y; else o.style.top=y;}
function setZ(o,z) { if(oBw.ns)o.zIndex=z;else o.style.zIndex=z; }

var d = document;var pop_timeout = new Array();var pop_delay = new Array();var pop_chGoActive = new Array();var pop_chGoInactive = new Array();var pop_timeoutGoActive = new Array();var pop_timeoutGoInactive = new Array();var pop_isActive = new Array();pop_isActive['active'] = new Array();
function CallbackChain(){this._callbacks = new Array();this.add = cbc_add;this.get = cbc_get;this.count = cbc_count;this.execute = cbc_execute;return this;}
function cbc_add(refCallback){this._callbacks[this._callbacks.length] = refCallback;return true;}
function cbc_get(index){return this._callbacks[index];}
function cbc_count(){return this._callbacks.length;}
function cbc_execute(){for (var i = 0; i < this.count(); i++){var cb = this.get(i);cb();}return true;}
function connectHoverEvents(triggerId, targetId, showChain, hideChain, showDelay, hideTimeout) {var eMouseOver = pop_genActiveEvent(triggerId, showChain, showDelay);var eMouseOut = pop_genInactiveEvent(triggerId, hideChain, hideTimeout);var trigger = d.getElementById(triggerId);addEvt(trigger,  "mouseover",  eMouseOver, false);addEvt(trigger,  "mouseout",   eMouseOut,  false);if (targetId != null) {var target = d.getElementById(targetId);if (!target) return false;addEvt(target, "mouseover",  eMouseOver, false);addEvt(target, "mouseout",   eMouseOut,  false);}}
function pop_genActiveEvent(tabId, showChain, delay) {pop_chGoActive[tabId] = showChain;pop_timeoutGoActive[tabId] = new Function("if (pop_isActive['" +tabId+ "'] != true) {" + "  if (pop_isActive['active'].length != 0) {" + "    pop_makeAllInactive();" + "  } " + "  pop_chGoActive['" +tabId+ "'].execute();" + "} " + "pop_isActive['" +tabId+ "'] = true;" + "pop_isActive['active'][pop_isActive['active'].length] = '" +tabId+ "';");return new Function("clearTimeout(pop_timeout['" +tabId+ "']);" + "clearTimeout(pop_delay['" +tabId+ "']);" + "var defaultDelay = " +delay+ ";" + "var thisDelay = (pop_isActive['active'].length != 0) ? 1 : defaultDelay;" + "pop_delay['" +tabId+ "'] = setTimeout(\"pop_timeoutGoActive['" +tabId+ "']();\", thisDelay);" + "return false;");}
function pop_genInactiveEvent(tabId, hideChain, timeout) {pop_chGoInactive[tabId] = hideChain;pop_timeoutGoInactive[tabId] = new Function("pop_chGoInactive['" +tabId+ "'].execute();" + "pop_isActive['" +tabId+ "'] = false;" + "pop_markInactive('" +tabId+ "');");return new Function("clearTimeout(pop_delay['" +tabId+ "']);" + "clearTimeout(pop_timeout['" +tabId+ "']);" + "pop_timeout['" +tabId+ "'] = setTimeout(\"pop_timeoutGoInactive['" +tabId+ "']();\", " +timeout+ ");" + "return false;");}
function pop_makeAllInactive(skip){var array = pop_isActive['active'];var exceptionData = null;for (var i = (pop_isActive['active'].length - 1); i > -1; i--) {var cur = pop_isActive['active'][i];if (cur == skip) {exceptionData = cur;} else {pop_timeoutGoInactive[cur]();}pop_isActive['active'] = pop_isActive['active'].slice(0, i);}if (exceptionData != null) {pop_isActive['active'][pop_isActive['active'].length] = exceptionData;}}
function pop_markInactive(id) {var others = new Array();for (var i = (pop_isActive['active'].length - 1); i > -1; i--) {var cur = pop_isActive['active'][i];if (cur != id) {others[others.length] = cur;}}pop_isActive['active'] = others;}
function pop_showElement(elId) {var el = d.getElementById(elId);if (el) {el.style.visibility = "visible";}}
function pop_hideElement(elId) {var el = d.getElementById(elId);if (el) {el.style.visibility = "hidden";}}var navNoMenu = new Array("0", "1", "2", "3", "4");var navMenu = new Array("5");var IFRAME_ID = '_js_msie_iframe';var SHOW_DELAY = 250;var HOVER_TIMEOUT = 400;var oBw = new Browser();
function setMenuPos(tabId, menuId, align) {var tab = d.getElementById(tabId);var menu = d.getElementById(menuId);var xOffset = 0;var yOffset = 0;var width = "auto";if (d.all && navigator.userAgent.indexOf("Mac_PowerPC") > -1) {xOffset = -6;yOffset = -15;width = "16.2em";}menu.style.width = width;if (tab.className == "selected") {yOffset = yOffset - 1;}var tabTop = getPageY(tab);var tabLeft = getPageX(tab);var tabHeight = getH(tab);var tabWidth = getW(tab);var tabRight = tabLeft + tabWidth;var menuWidth = getW(menu);var menuHeight = getH(menu);var menuTop = (tabTop + tabHeight + yOffset);var menuLeft = '';if (align == "right") {menuLeft = (tabRight - menuWidth + xOffset);} else {menuLeft = (tabLeft + xOffset);}menu.style.top = menuTop + "px";menu.style.left = menuLeft + "px";if (oBw.ie5 && oBw.win) {var iframe = d.getElementById(IFRAME_ID);if (iframe) {iframe.style.top = menuTop + "px";iframe.style.left = menuLeft + "px";iframe.style.height = menuHeight + "px";iframe.style.width = menuWidth + "px";iframe.style.zIndex = menu.style.zIndex + 1;}}return true;}
function selectTab(tabId) {var tab = d.getElementById(tabId);if (!tab) return false;if (tab.className != "selected") {tab.className = "highlighted";}return true;}
function deselectTab(tabId) {var tab = d.getElementById(tabId);if (!tab) return false;if (tab.className != "selected") {tab.className = "";}return true;}
function tabs_init() {if (!d.getElementById) return false;if (oBw.ie5 && oBw.win) {var tabs = d.getElementById('tabs');var iframe = d.createElement("iframe");iframe.setAttribute('id', IFRAME_ID);iframe.style.height = 0;iframe.style.width = 0;iframe.style.position = "absolute";iframe.style.visibility = "hidden";iframe.style.zIndex = 1;iframe.style.border = 0;tabs.parentNode.insertBefore(iframe, tabs);}for (var i = 0; i < navNoMenu.length; i++) {var num = navNoMenu[i];var tabId = "tab_"+num;var tab = d.getElementById(tabId);if (!tab) continue;var showChain = new CallbackChain();var hideChain = new CallbackChain();connectHoverEvents(tabId, '', showChain, hideChain, SHOW_DELAY, HOVER_TIMEOUT);}for (var i = 0; i < navMenu.length; i++) {var num = navMenu[i];var tabId = "tab_"+num;var tab = d.getElementById(tabId);if (!tab) continue;var menuId = "menu_"+num;var menu = d.getElementById(menuId);if (!menu) continue;var showChain = new CallbackChain();showChain.add(new Function("setMenuPos('" +tabId+ "', '" +menuId+ "', 'right');"));showChain.add(new Function("selectTab('" +tabId+ "');"));showChain.add(new Function("pop_showElement('" +menuId+ "');"));if (oBw.ie5 && oBw.win) showChain.add(new Function("pop_showElement('" +IFRAME_ID+ "');"));var hideChain = new CallbackChain();if (oBw.ie5 && oBw.win) hideChain.add(new Function("pop_hideElement('" +IFRAME_ID+ "');"));hideChain.add(new Function("pop_hideElement('" +menuId+ "');"));hideChain.add(new Function("deselectTab('" +tabId+ "');"));connectHoverEvents(tabId, menuId, showChain, hideChain, SHOW_DELAY, HOVER_TIMEOUT);}}
function CancleEvent(event){if(document.all){event.returnValue=false;event.cancel = true;}else if(event.cancelable)event.preventDefault();}
function disableEnter(event)
{
	var src=document.all?event.srcElement:event.target;
	if(event.keyCode==13)
	{
		if(src.type!='button' && src.type!='text' && src.type!='submit' && src.type!='reset' && src.type!=''&& src.type!='textarea' && src.type!='password')
		{
			CancleEvent(event);
		}
		else if(src.id == 'tbSearchT') 
		{CancleEvent(event);d.getElementById("btnSearchT").click();}
	}
}
function onChangeRating(id)
{
	var r = document.getElementById(id).value;
	var eStar = document.getElementById('ratingStar');
	if(r == "")
		eStar.style.display="none";
	else
	{
		eStar.src= 'images/'+ r +'star.gif';
		eStar.style.display="";
	}
}
function processDiscount()
{
	var v=document.body.all.tags("b");
	alert(v);
	if(v==null)
		return;
	for(i=0;i<v.length;i++)
	{
		alert(v[i].innerText);
		if(v[i].innerText=="Sample Label Text")
		{
			alert(1);
		}
	}
}

String.prototype.trim = function() {return this.replace(/(^[\s]*)|([\s]*$)/g, "");}
function onSearch()
{
	if(checkFields())
	{
		window.location="search.aspx?p=1&iN="+(d.getElementById("cbName").checked ? 1:0)+"&iT="+(d.getElementById("cbTitle").checked ? 1:0)+"&iP="+(d.getElementById("cbPublisher").checked?1:0)+"&c="+d.getElementById("ddlCategories").value+"&pS="+d.getElementById("tbPriceStart").value+"&pE="+d.getElementById("tbPriceEnd").value+"&fF="+(d.getElementById("cbFree").checked?1:0)+"&fD="+(d.getElementById("cbDiscount").checked?1:0)+"&q="+ encodeURIComponent(d.getElementById("tbSearch").value);
	}
	CancleEvent(event);
}

function onGoogleSearch()
{
	var cof="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;";
	var sitesearch;
	if(d.getElementById("rWeb").checked) 
		sitesearch="" 
	else
		sitesearch="SharewarePlaza.com";
	var q = d.getElementById("q").value.trim();
	if(q=="")
	{
		d.getElementById("lbError").innerHTML="<ul><li>Please input the words you want to search in Google.</li></ul>";
		return;
	}
	window.location = "http://www.google.com/custom?domains=SharewarePlaza.com&client=pub-8897475352764699&forid=1&ie=UTF-8&flav=0000&sig=cemZ2EbAhzhKcvIq&oe=UTF-8&cof="+encodeURIComponent(cof)+"&hl=en&sitesearch="+sitesearch+"&q="+encodeURIComponent(q);
}

function checkFields(direct)
{
	var lbError = d.getElementById("lbError");
	var cbFree = d.getElementById("cbFree");
	var cbDiscount = d.getElementById("cbDiscount");
	if(cbFree.checked && cbDiscount.checked)
	{
		cbFree.checked = cbDiscount.checked = false;
	}
	d.getElementById("tbSearch").value = d.getElementById("tbSearch").value.trim();
	var words = d.getElementById("tbSearch").value;
	d.getElementById("tbPriceStart").value = d.getElementById("tbPriceStart").value.trim();
	var priceStart = d.getElementById("tbPriceStart").value;
	d.getElementById("tbPriceEnd").value = d.getElementById("tbPriceEnd").value.trim();
	var priceEnd = d.getElementById("tbPriceEnd").value;
	
	lbError.innerHTML = "";
	if(isNaN(Number(priceStart)) || isNaN(Number(priceEnd)))
	{
		lbError.innerHTML += "<li>The price must be a number</li>";
	}
	if(direct != true || words != "")
	{
		var reg = new RegExp("^[\\sa-zA-Z0-9\\.\\+@#_\\-\\()/!'\"\\\\]{3,255}$");
		if(reg.test(words) == false)
		{
			lbError.innerHTML+="<li>Search words must be three characters or more. It may consist of space, A-Z, a-z, 0-9,/,!,quotation mark,bracket,\", underscores(_), hyphen(-) and a single dot (.)</li>";
		}
	}
	if(lbError.innerHTML != "")
	{
		lbError.innerHTML="<ul>"+lbError.innerHTML+"</ul>";
		return false;
	}

	if(words != "" && lbError.innerHTML == "" && d.getElementById('pagePanel') && direct==true)
	{
	//	document.getElementById("panelSearch").style.display="none";
	}
	return true;
}

function onSearchBoxClick(event)
{
	var src=document.all?event.srcElement:event.target;
	src = src.id;
	var rowPrice = d.getElementById("rowPrice");
	var cbFree = d.getElementById("cbFree");
	var cbDiscount = d.getElementById("cbDiscount");
	var searchIn = new Array();
	searchIn[0] = d.getElementById("cbName");
	searchIn[1] = d.getElementById("cbTitle");
	searchIn[2] = d.getElementById("cbPublisher");

	if(src == "cbFree")
	{
		if(cbFree.checked)
		{
			cbDiscount.checked = false;
			rowPrice.disabled = true;
		}
		else
		{
			rowPrice.disabled = false;
		}
	}
	else if(src == "cbDiscount" && cbFree.checked)
	{
		cbFree.checked = false;
		rowPrice.disabled = false;
	}
	else
	{
		var count = 0;
		var clickE;
		for(var i=0;i<searchIn.length;i++)
		{
			if(searchIn[i].checked) count++;
			if(src == searchIn[i].id)
			{
				clickE = searchIn[i];
			}
		}
		if(clickE != null && count == 0)
		{
			clickE.checked= true;
		} 
	}
}