//====================================
//Jump out from outer Frame
if (!Page.Parameters.FRAMEALLOWED){
	if (top.location != self.location) {
		top.location = self.location
	}
}

//====================================
//Base functions
//====================================
Object.isNull=function(o){return(null==o||undefined==o);}
Object.fromJSON=function(text){try{return!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g,'')))&&eval('('+text+')');}catch(e){return false;}}
Boolean.parse=function(value){if(typeof(value)=='string'){return(value.trim().toLowerCase()=='true');}return value?true:false;}
Number.parse=function(value){if(!value||(value.length==0)){return 0;}return parseFloat(value);}
__sp=String.prototype;
__sp.encodeURI=function(){return escape(this).replace(/\*/g,'%2A').replace(/\+/g,'%2B').replace(/-/g,'%2D').replace(/\./g,'%2E').replace(/\//g,'%2F').replace(/@/g,'%40').replace(/_/g,'%5F');};
__sp.decodeURI=function(){return unescape(this);};
__sp.encodeHtml=function(){return this.replace(/\&/g,'&amp;').replace(/\>/g,'&gt;').replace(/\</g,'&lt;').replace(/\'/g,'&#039;').replace(/\"/g,'&quot;');};
__sp.decodeHtml=function(){return this.replace(/(&quot;)/g,'"').replace(/(&#039;)/ig,'\'').replace(/(&lt;)/ig,'<').replace(/(&gt;)/ig,'>').replace(/(&amp;)/ig,'&');};
__sp.lTrim=__sp.ltrim=function(){return this.replace(/(^\s*)/g, '');}
__sp.rTrim=__sp.rTrim=function(){return this.replace(/(\s*$)/g, '');}
__sp.trim=function(){return this.lTrim().rTrim();}
__ap=Array.prototype;
if (!__ap.push || ![0].push(true)){__ap.push=function(){for(i=0;i<arguments.length;i++){this[this.length]=arguments[i];}return this.length;}}
__ap.add=__ap.queue=function(item){this.push(item);}
__ap.addRange=function(items){if(items)this.push.apply(this,items);return this;}
__ap.clear=function(){if(this.length>0){this.splice(0,this.length);}}
__ap.clone=function(){return[].addRange(this);}
__ap.contains=__ap.exists=__ap.hasItem=function(item){var index=this.indexOf(item);return(index>=0);}
__ap.dequeue=Array.prototype.shift;
if(!__ap.indexOf){__ap.indexOf=function(item,startIndex){var length=this.length;if(length!=0){startIndex=startIndex||0;if(startIndex<0){startIndex=Math.max(0,length+startIndex);}for(var i=startIndex;i<length;i++){if(this[i]==item){return i;}}}return-1;}}

//Base Parameters
var DEBUG_MODE=false;
var $=function(id, win){var w=window;if(win&&win.document){w=win;};return w.document.getElementById(id) || null;}
var deb=function(v){if (Page.Parameters.DEBUG_MODE){if (v != null){if (v['constructor'] == Array){alert("{"+ v.join("}\r\n{") +"}");}else{alert("{"+ v +"}");}}}}
//Base Functions
window.namespace=function(a){var rootObject =window;var currentObject=rootObject;var namespaceParts=(a + '').split('.');for(var i=0; i<namespaceParts.length; i++){var currentPart=namespaceParts[i];if (!rootObject[currentPart]){rootObject[currentPart]={};}currentObject=rootObject=rootObject[currentPart];}return currentObject;};
window.WebPage=namespace('Web');

namespace('Web.Compatibility')['Browser'] = new function() {
	var _isIE = navigator.userAgent.indexOf("MSIE")>=0;
	var _isOpera = navigator.userAgent.indexOf("Opera")>=0;
	var _isMozilla = navigator.userAgent.indexOf("Mozilla")>=0;	
	var _isFirefox = navigator.userAgent.indexOf("Firefox")>=0;
	var _isNetscape = navigator.userAgent.indexOf("Netscape")>=0;	
	this.isIE = function(){return _isIE;};
	this.isMozilla = function(){return (!_isIE && _isMozilla);};	
	this.isOpera = function(){return _isOpera;};	
	this.isFirefox = function(){return _isFirefox};
	this._isNetscape = function(){return _isNetscape};
}();

namespace('Web.Compatibility')['Event'] = function(e) {
	if (e.srcElement){				
	} else if (e.target) {				
		window.event = {
			srcElement : e.target,
			keyCode : e.which
		}
	}
	return window.event;
};

function AttachEvent(o, e, f, c) {
	if (!o || typeof(f) != 'function'){return;}
	var cb = c || false;
	e = e.toLowerCase();
	if (document.attachEvent) {
		o.attachEvent('on' + e, f);
	} else {
		o.addEventListener(e, f, cb);
	}
}

function DetachEvent(o, e, f, c) {
	if (!o || typeof(f) != 'function'){return;}
	var cb = c || false;
	e = e.toLowerCase();
	if (document.detachEvent) {
		o.detachEvent('on' + e, f);
	} else {
		o.removeEventListener(e, f, cb);
	}
}

Page.GotoPage = function(f,v){
	var o;
	if (o = document.getElementById(f)) {
		if (o.Page) {
			o.Page.value = v;o.submit();
		}
	}
}

Page.ElementDisplay = function(id, style) {
	var o = null;
	if (o = $(id)) {
		o.style.display = style;
	}
}
	
namespace('Request')['Cookies'] = function(name,key){
	try {
		if (name == null || name.length == 0) {return;}
		var c = window.document.cookie;
		if (c.length == 0){return;}
		var cc = c.split('; ');
		var cv = Request.Cookies.Match(cc,name);
		if (key != null && key.length > 0) {
			var kc = cv.split('&');
			cv = Request.Cookies.Match(kc,key);
		}
		return (cv.length > 0) ? Request.Cookies.Corrector(cv) : null;

	} catch(e) {
		return null;
	}
}

Request.Cookies.Match = function(a,n) {
	var rv = '';
	try {
		var l = a.length;
		var b = -1;
		var re = new RegExp('^'+ n+'$','i');
		for (var i=0; i<l;++i) {
			b = a[i].indexOf('=');
			if (b != -1) {
				if (Request.Cookies.Corrector(a[i].substring(0,b)).match (re) != null) {
					rv = a[i].substring(b+1);
					break;
				}
			}
		}

	} catch(e) {}
	return rv;
}

Request.Cookies.Corrector = function(v){
	if (v != null && v.length > 0) {
		v = v.replace(/\+/g," ");
	}
	return unescape(v);
}

function SetJSCookie(Cookie_name,Cookie_value) {
	SaveJSCookie(Cookie_name,Cookie_value,Page.Parameters.DOMAIN_NAME);
}

function SaveJSCookie(Cookie_name,Cookie_value,vDomain) {
	var dt = new Date();
	Cookie_name = Cookie_name + '';
	Cookie_value = Cookie_value + '';
	dt.setTime(dt.getTime() + 24*365*3600000 );
	var dName = (vDomain.length > 0) ? 'domain='+ vDomain +';' : '';
	RemoveCookie(Cookie_name, vDomain);
	window.document.cookie = Cookie_name.encodeURI() + '=' + Cookie_value.encodeURI() + ';expires='+ dt.toGMTString() +';path=/;'+ dName;
}


//===============================
//add by mylo 2006-04-18

function RemoveCookie(name, domain) {	
	if(typeof(name) == 'string' && name.length > 0)	{
		var dName = (typeof(domain) == 'string' && domain.length > 0) ? 'domain='+ domain +';' : '';
		var dt = new Date();
		dt.setYear(dt.getFullYear() - 1);
		window.document.cookie = name + '=; expires='+ dt.toGMTString() +'; path=/; '+ dName;
		window.document.cookie = name.encodeURI() + '=; expires='+ dt.toGMTString() +'; path=/; '+ dName;
	}
}



//====================================
//Common functions
//====================================
function verifyNewsletterSingup(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var error_msg = "";

	f = eval('document.' + f);

	if ((f.LoginName.value == null) || (f.LoginName.value == "") || isblank(f.LoginName.value))
	{
		error_msg = "- Your email field is empty";
        empty_fields += "\n      " + error_msg;
    }


    else if (f.LoginName.value.indexOf("@")==-1)
    {
		error_msg = "- Your email address is invalid";
        empty_fields += "\n      " + error_msg;
    }

    if ((!f.Promotions.checked) && (!f.Newsletter.checked))
    {
		error_msg = "- You didn't specify your desired newsletter option(s).";
        empty_fields += "\n      " + error_msg;
    }

    if (!empty_fields && !errors)
    {
		return true;
	}
    msg  = "______________________________________________________\n\n"
    msg += "Your request cannot continue because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit:\n";
    msg += "______________________________________________________\n"

    if (empty_fields) {
        msg += empty_fields + "\n";
    }
    alert(msg);
    return false;
}

// Commom popup window function
function PopupWin(vName,vLink,vWidth,vHeight,vLeft,vTop,vScrollbar,vResizable)
{
	var para = '';
	if(vWidth!=0)
	{para += ',width=' + vWidth;}

	if(vHeight!=0)
	{para += ',height=' + vHeight;}

	if(vLeft!=0)
	{para += ',left=' + vLeft;}

	if(vTop!=0)
	{para += ',top=' + vTop;}

	if(vScrollbar!=0)
	{para += ',scrollbars=' + vScrollbar;}

	if(vResizable!=0)
	{para += ',resizable=' + vResizable;}

	javascript:window.open(vLink ,vName,'toolbar=0,menubar=0,location=0,directories=0,status=0' + para)
}

function isblank(s)
{
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ')&&(c != '\n')&&(c != '\t')) return false;
	}
	return true;
}

function goSearch(sFormName,iLength)
{
	var objForm;
	objForm = eval('document.' + sFormName);
	if (iLength >= 1)
	{
		objForm.submit();
	}
}

function ExpandItem(item)
{
	obj = document.getElementById(item);
	visible = (obj.style.display != 'none');
	key = document.getElementById('x' + item);

	if (visible)
	{
		obj.style.display = 'none';
 		key.style.fontWeight = 'normal';
	}
	else
	{
		obj.style.display = 'block';
		key.style.fontWeight = 'bold';
	}
}

function SetActivedCSS(action){
	var arr;
	if (arr = document.getElementsByTagName("link")) {
		var a;
		var j = 1;
		for (var i=0; i<arr.length; i++){
			a = arr[i];
			if (a.getAttribute("rel") && a.getAttribute("rel").indexOf("stylesheet") != -1 && a.getAttribute("title") && a.getAttribute("title") == "default"){
				if (j == action){
					a.disabled = false;
					SetJSCookie('NV_LARGETEXT',action);
				}else{
					a.disabled = true;
				}
				j++;
			}
		}
	}
}

//====================================


//====================================
//Top Navigation menu functions
//====================================
namespace('Page')['TopNavigationLogin'] = function(){
	var rtv = [];
	var loginName = Request.Cookies("NV_CUSTOMERLOGIN","CONTACTWITH");
	if (loginName != null){
		rtv.push("<p class=\"smTxt\"><span>" + loginName + "</span></p>");
		rtv.push("<p>[<a href=\""+ Page.Parameters.SECUITYSITE +"MyAccount/AccountLogout.asp\">log out</a>]</p>");
	}else{
		rtv.push("<p>[<a href=\""+ Page.Parameters.SECUITYSITE +"MyAccount/AccountLogin.asp\">login</a>]</p>");
	}
	document.write(rtv.join(''));
}

namespace('Page')['TopNavigationCart'] = function(){
	var rtv = [];
	var cartInfo = Request.Cookies("NV_CARTINFO");
	if (cartInfo != null && cartInfo.indexOf("(s)") != -1){
		rtv.push("<p><a href=\""+ Page.Parameters.SHOPPERSITE +"Shopping/shoppingcart.asp?submit=view\" class=\"noLine\"><img src=\""+ Page.Parameters.CACHE_IMAGESITE +"Nest/topCartFull.gif\" alt=\"Shopping Cart with Items\" title=\"Shopping Cart with Items\" border=\"0\" id=\"shoppingCart\" /></a></p>");
	}else{
		rtv.push("<p><a href=\""+ Page.Parameters.SHOPPERSITE +"Shopping/shoppingcart.asp?submit=view\" class=\"noLine\"><img src=\""+ Page.Parameters.CACHE_IMAGESITE +"Nest/topCartEmptyD.gif\" alt=\"Empty Shopping Cart\" title=\"Empty Shopping Cart\" border=\"0\" id=\"shoppingCart\" /></a></p>");
	}
	if (cartInfo != null){
		rtv.push("<p><a href=\""+ Page.Parameters.SHOPPERSITE +"Shopping/shoppingcart.asp?submit=view\">"+ cartInfo.replace("0 Item ","0 Items ").replace(" | ","</a> (") +")</p>");
	}else{
		rtv.push("<p><a href=\""+ Page.Parameters.SHOPPERSITE +"Shopping/shoppingcart.asp?submit=view\">0 Items</a> ($0.00)</p>");
	}
	document.write(rtv.join(''));
}