//====================================
//Jump out from outer Frame
if (!Page.Parameters.FRAMEALLOWED){
	if (top.location != self.location) {
		top.location = self.location
	}
}

//====================================
//Base functions
//====================================
//Base Parameters
var DEBUG_MODE = false;
var $ = function(id) {return document.getElementById(id) || null;}

//String Functions
String.prototype.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');};
String.prototype.decodeURI = function(){return unescape(this);};
String.prototype.encodeHtml = function(){return this.replace(/\&/g,'&amp;').replace(/\>/g,'&gt;').replace(/\</g,'&lt;').replace(/\'/g,'&#039;').replace(/\"/g,'&quot;');};
String.prototype.decodeHtml = function(){return this.replace(/(&amp;)/ig,'&').replace(/(&gt;)/ig,'>').replace(/(&lt;)/ig,'<').replace(/(&#039;)/ig,'\'').replace(/(&quot;)/g,'"');};

String.prototype.ltrim = function(){return this.replace(/(^\s*)/g, '');}
String.prototype.rtrim = function(){return this.replace(/(\s*$)/g, '');}
String.prototype.trim = function(){return this.ltrim().rtrim();}

var deb = function(v){
	if (Page.Parameters.DEBUG_MODE) {
		if (v != null){
			if (v['constructor'] == Array){
				alert("{"+ v.join("}\r\n{") +"}");
			}else{
				alert("{"+ v +"}");
			}
		}
	}
}

if (!Array.prototype.push || ![0].push(true)){
	Array.prototype.push = function() {
		for(i=0;i<arguments.length;i++){
			this[this.length] = arguments[i];
		}
		return this.length;
	}	
}

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;
	}
}
	
var Request = {};
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();
	dt.setTime(dt.getTime() + 24*365*3600000 );
	var dName = (vDomain.length > 0) ? 'domain='+ vDomain +';' : '';
	window.document.cookie = Cookie_name + '=' + Cookie_value + ';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.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
//====================================
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(''));
}

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(''));
}

//====================================
//Base initialize
//====================================
JS_Initialize = function() {}

