// Site-Wide JS Template
// copyright 2008, RWD 
var oldButValues = '';

function quickEditContent(pageID,showTab){
	var loc = 'zca.cfm?go=zPageEdit&pageID='+pageID;
	if(showTab){
		loc = loc+'&showtab='+showTab;
	}
	window.location.href = loc;	
}

function quickProductEditContent(productID){
	window.location.href = 'zca.cfm?go=zProductEdit&productID='+productID;
}

// Call Ajax Stub Func
function runAjx(tmp,args,img,func,type,async){
	if(!func || func == ''){var func = 'zxResults';}
	if(!type || type == ''){var type = 'p';}
	if(!async || async == ''){var async = 'y';}
	DWRUtil.useLoadingImage(img);
	if(async == 'n'){DWREngine.setAsync(false);}
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null,'runAjx'+type,tmp,args,eval(func));
}

// Main results function
function zxResults(r){
	eval(r);
}

function updateStaticCatTemplates(){
	var args2 ={refreshCategories: 1};
	runAjx('zProdCatMenuCreate.cfm',args2,'#application.AJAXLOADING#');
}
		
function zPageAction(action,pageID,parentID){
	proceed = 1;
	if (action == 'delete'){
		if(parentID == -5){
			var delMsg = 'Remove this page from the footer?';
		}
		else{
			var delMsg = 'Delete This Page?';
		}
		if (confirm(delMsg)){
			proceed = 1;
		}else 
		{ proceed = 0; }
	}
	if (proceed == 1){
	DWRUtil.useLoadingImage(ajaxLoading);
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'PageAction', pageID, parentID, action, zxResults);
	}
}

function zQuickPageEdit(pageID,xo,yo,t,w){
try{
	if(!xo){xo = 0;}
	if(!yo){yo = 'middle';}
	if(!t){t = 600;}
	if(!w){w = 900;}

	this.getviewpoint();
	bw = this.docwidth;
	bh = this.docheight;
	sl = this.scroll_left;
	st = this.scroll_top;
	
	$('quickPageEdit').innerHTML = '<div align="center" style="width:auto;height:300px;padding-top:110px;background:#fefefe;"><div style="border: 1px solid black; padding: 10px; font-family: verdana, arial, helvetica; font-size: 12px; color: black; width: 300px; background-color: #f0f0f0;">Loading...  &nbsp;&nbsp;&nbsp;  <img src="/sysimages/ajax-loader3_f0f0f0.gif" width="25" height="25" alt="" border="0" align="absmiddle"></div></div>';
	
	qew = document.getElementById('quickPageEditWindow');	
	qew.style.display = "block";
	qew.style.position = 'absolute';									
	ow=qew.offsetWidth;
	oh=qew.offsetHeight;
	lp = (sl+(bw-ow)/2);
	tp = (st+(bh-oh)/2);
	if (lp < 0){lp = 0;}
	if (tp < 0){tp = 0;}
	qew.style.left=lp+"px";
	qew.style.top=tp+"px";
	
	DWRUtil.useLoadingImage(ajaxLoading);
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'QuickPageEdit', pageID, bw, bh, sl, st, zxResults);
	}
	catch(e){alert('QuickPageEdit JS Error:\n\n '+e.message); }
}

function zQuickProductEdit(productID,xo,yo,t){
	
	if(!xo){xo = 0;}
	if(!yo){yo = 0;}
	if(!t){t = 500;}
	
	$('quickProductEdit').innerHTML = '<div align="center" style="width:auto;height:300px;padding-top:110px;background:#fefefe;"><div style="border: 1px solid black; padding: 10px; font-family: verdana, arial, helvetica; font-size: 12px; color: black; width: 300px; background-color: #f0f0f0;">Loading...  &nbsp;&nbsp;&nbsp;  <img src="/sysimages/ajax-loader3_f0f0f0.gif" width="25" height="25" alt="" border="0" align="absmiddle"></div></div>';
	qew = document.getElementById('quickProductEditWindow');

	this.getviewpoint();
	bw = this.docwidth;
	bh = this.docheight;
	sl = this.scroll_left;
	st = this.scroll_top;
	qew.style.display = 'block';
	ow=qew.offsetWidth;
	oh=qew.offsetHeight;
	lp = (sl+(bw-ow)/2);
	tp = (st+(bh-oh)/2);
	if (lp < 0){lp = 0;}
	if (tp < 0){tp = 0;}
	qew.style.left=lp+"px";
	qew.style.top=tp+"px"
					
	DWRUtil.useLoadingImage(ajaxLoading);
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'QuickProductEdit', productID, bw, bh, sl, st, zxResults);
}

function zQuickUserLogin(xo,yo,t){
	
	if(!xo){xo = 0;}
	if(!yo){yo = 0;}
	if(!t){t = 500;}
	
	$('quickUserLogin').innerHTML = '<div align="center" style="width:auto;background:#fefefe;"><div style="border: 1px solid black; padding: 10px; font-family: verdana, arial, helvetica; font-size: 12px; color: black; width: auto; background-color: #f0f0f0;">Loading...  &nbsp;&nbsp;&nbsp;  <img src="/sysimages/ajax-loader3_f0f0f0.gif" width="25" height="25" alt="" border="0" align="absmiddle"></div></div>';
	qew = document.getElementById('quickUserLoginWindow');

	this.getviewpoint();
	bw = this.docwidth;
	bh = this.docheight;
	sl = this.scroll_left;
	st = this.scroll_top;
	qew.style.display = 'block';
	ow=qew.offsetWidth;
	oh=qew.offsetHeight;
	lp = (sl+(bw-ow)/2);
	tp = (st+(bh-oh)/2);
	if (lp < 0){lp = 0;}
	if (tp < 0){tp = 0;}
	qew.style.left=lp+"px";
	qew.style.top=tp+"px"
					
	DWRUtil.useLoadingImage(ajaxLoading);
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'QuickUserLogin', bw, bh, sl, st, zxResults);
}

function zUserLoginVerify(login,pass,tmp,quick,buttonID,buttonClass){
	login = trim(login);
	pass = trim(pass);
	
	err = ''
	
	if(login == ''){
		err = 'Please enter Login';
	}
	
	if(pass == ''){
		if(err != ''){
			err = err + '\n';
		}
		err = err + 'Please enter Password';
	}
	
	if(err != ''){
		alert(err);
	}
	else{
		//zLoading(buttonID);
		DWRUtil.useLoadingImage(ajaxLoading);
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'verifyLogin', login, pass, tmp, quick, buttonID, buttonClass, zxResults);
	}
}

function zUserLogout(){	
	DWRUtil.useLoadingImage("/sysimages/applications-internet.png");
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'zUserLogout', window.location.href, zResults);
}

function quickProductDetail(productID,template,productPage,xo,yo,t){
	
	if(!xo){xo = 0;}
	if(!yo){yo = 0;}
	if(!t){t = 500;}
	
	$('quickProductDetail').innerHTML = '<div align="center" style="width:auto;height:300px;padding-top:110px;background:#fefefe;"><div style="border: 1px solid black; padding: 10px; font-family: verdana, arial, helvetica; font-size: 12px; color: black; width: 300px; background-color: #f0f0f0;">Loading...  &nbsp;&nbsp;&nbsp;  <img src="/sysimages/ajax-loader3_f0f0f0.gif" width="25" height="25" alt="" border="0" align="absmiddle"></div></div>';
	qew = document.getElementById('quickProductDetailWindow');

	this.getviewpoint();
	bw = this.docwidth;
	bh = this.docheight;
	sl = this.scroll_left;
	st = this.scroll_top;
	
	qew.style.display = "block";
	ow=qew.offsetWidth;
	oh=qew.offsetHeight;
	lp = (sl+(bw-ow)/2);
	tp = (st+(bh-oh)/2);
	if (lp < 0){lp = 0;}
	if (tp < 0){tp = 0;}
	qew.style.left=lp+"px";
	qew.style.top=tp+"px";
	
	var args ={
	productID: productID,
	template: template,
	productPage: productPage,
	bw: bw,
	bh: bh,
	sl: sl,
	st: st
	};
	runAjx('zAjax_quickProductDetail.cfm',args,ajaxLoading);
}

function shipQuoteWin(productID,xo,yo,t,w){
try{
	if(!xo){xo = 0;}
	if(!yo){yo = 'middle';}
	if(!t){t = 600;}
	if(!w){w = 900;}

	this.getviewpoint();
	bw = this.docwidth;
	bh = this.docheight;
	sl = this.scroll_left;
	st = this.scroll_top;
	
	$('prodShipQuote').innerHTML = '<div align="center" style="width:auto;background:#fefefe;"><div style="border: 1px solid black; padding: 10px; font-family: verdana, arial, helvetica; font-size: 12px; color: black; width: 200px; background-color: #f0f0f0;">Loading...  &nbsp;&nbsp;&nbsp;  <img src="/sysimages/ajax-loader3_f0f0f0.gif" width="25" height="25" alt="" border="0" align="absmiddle"></div></div>';
	
	qew = document.getElementById('prodShipQuoteWindow');	
	qew.style.display = "block";
	qew.style.position = 'absolute';									
	ow=qew.offsetWidth;
	oh=qew.offsetHeight;
	lp = (sl+(bw-ow)/2);
	tp = (st+(bh-oh)/2);
	if (lp < 0){lp = 0;}
	if (tp < 0){tp = 0;}
	qew.style.left=lp+"px";
	qew.style.top=tp+"px";
	
	var args ={
	productID: productID, 
	action: 'form',
	bw: bw,
	bh: bh,
	sl: sl,
	st: st};
	
	runAjx('zproducts_ShipQuote.cfm',args,ajaxLoading);
	
	}
	catch(e){alert('Product Ship Quote JS Error:\n\n '+e.message); }
}

function shipQuote(productID,qty,state,zip,country){
	
	var err = '';
	
	if(typeof(country) == 'undefined'){
		country = 'US';
	}
	
	qty = trim(qty);
	
	if(qty == ''){
		err = 'Please enter quantity';
	}
	else{
		qty = parseInt(qty);
		if(isNaN(qty) || qty < 1){
			err = 'Please enter a valid quantity';
		}
	}
	
	if(trim(zip) == ''){
		if (err != ''){
			err = err + '\n';
		}
		err = err + 'Please enter zip code';
	}
	
	if(state == ''){
		if (err != ''){
			err = err + '\n';
		}
		err = err + 'Please select state';
	}
	
	if (err != ''){
		alert(err);
	}
	else{
		var args ={
		productID: productID, 
		qty: qty,
		state: state,
		zip: zip,
		country: country,
		action: 'quote'};
		
		$('shipQOutput').innerHTML = '<div align="center" class="zFormText" style="padding-top:40px;"><img src="/sysimages/ajax-flower_f0f0f0.gif" width="16" height="16" alt="" border="0" align="absmiddle">&nbsp;Getting Quote...</div>';
		
		runAjx('zproducts_ShipQuote.cfm',args,ajaxLoading);
	}
}

function getviewpoint(){ //get window viewpoint numbers
	var ie=document.all && !window.opera
	var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000 //Preliminary doc width in non IE browsers
	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	this.scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
	this.scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
	this.docwidth=(ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16)
	this.docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
}

function zPageActionLive(action,pageID,parentID){
	proceed = 1;
	if (action == 'delete'){
		if(parentID == -5){
			var delMsg = 'Remove this page from the footer?';
		}
		else{
			var delMsg = 'Delete This Page?';
		}
		if (confirm(delMsg)){
			proceed = 1;
		}else 
		{ proceed = 0; }
	}
	if (proceed == 1){
	DWRUtil.useLoadingImage(ajaxLoading);
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'PageAction', pageID, parentID, action, zQuickResults);
	}
}
function zShowImage(ni,ao){
		if(ao == undefined){ao = 0;}
		if(ni !== undefined)
		{		
			this.getviewpoint();
			bw = this.docwidth;
			bh = this.docheight;
			sl = this.scroll_left;
			st = this.scroll_top;		
			DWRUtil.useLoadingImage(ajaxLoading);
			DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'zSwapImage', ni, bw, bh, sl, st, ao, zImageProcess);
			
		}else{
			// do nothing in admin display
		}
}

function zShowPImage(pID, nextSortID, productID, type){
			DWRUtil.useLoadingImage(ajaxLoading);
			DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'zSwapPImage', pID, nextSortID, productID, type, zImageProcess);		
}

function zLightBox(action){
	if(action == undefined){action = 'show';}
	
	zImgPopUpOverlay = document.getElementById('zImgageOverlay');
	
	if (action == 'show'){
		this.getviewpoint();
		bw = this.docwidth;
		bh = this.docheight;
		sl = this.scroll_left;
		st = this.scroll_top;

		zImgPopUpOverlay.style.width = bw+'px';
		zImgPopUpOverlay.style.height = '100%';
		zImgPopUpOverlay.style.display = 'block';
		zImgPopUpOverlay.style.top=st+'px';

	}
	else{
		zImgPopUpOverlay.style.display = 'none';
	}
	
}

function getImages()
{
//alert('running getImages');
try{
	var images = document.getElementsByTagName("IMG");
	var numOfImages = images.length;
	for (i=0;i<numOfImages;i++)
	{
		//alert('image ' + images[i].src + ' auto: ' + images[i].getAttribute('auto'));
		//alert('image ' + images[i].src + ' from: ' + images[i].getAttribute('from'));
		
		autoSwap = images[i].getAttribute('auto');
		fromImage = images[i].getAttribute('from');
		if ( fromImage !== null && autoSwap !== null )
		{	//alert('setting: '+fromImage);
			setTimeout('zShowImage('+fromImage+');',6000);
		}
	}
}catch(e){
	alert(e.message);
}
}
function zImageProcess(r){
	eval(r);
}
	
function gotoURL(dest){
		window.location = dest; return false;
}
//create function, it expects 2 values.

function insertAfter(newElement,targetElement) {	
	//target is what you want it to go after. Look for this elements parent.	
	var parent = targetElement.parentNode; 	
	
	//if the parents lastchild is the targetElement...	
	if(parent.lastchild == targetElement) {		
	//add the newElement after the target element.		
	parent.appendChild(newElement);		
	} else {		
	// else the target has siblings, insert the new element between the target and it's next sibling.		
	parent.insertBefore(newElement, targetElement.nextSibling);		
	}
}
function hide(did,sc){
	if (!sc){ var sc = 'false';}else{this.SetCookie(group,0);}
	txt = document.getElementById(did);	
	txt.style.display = "none";	 
}

function show(did,sc){
	if (!sc){ var sc = 'false';}else{this.SetCookie(group,1);}
	txt = document.getElementById(did);
	txt.style.display = "block";
}
function showinline(did,sc){
	if (!sc){ var sc = 'false';}else{this.SetCookie(group,1);}
	txt = document.getElementById(did);
	txt.style.display = "";
}
function showInline(did,sc){
	if (!sc){ var sc = 'false';}else{this.SetCookie(group,1);}
	txt = document.getElementById(did);
	txt.style.display = "";
}
function zhide(did,sc){
	if (!sc){ var sc = 'false';}else{this.SetCookie(group,0);}
	txt = document.getElementById(did);	
	txt.style.display = "none";	 
}

function zshow(did,sc){
	if (!sc){ var sc = 'false';}else{this.SetCookie(group,1);}
	txt = document.getElementById(did);
	txt.style.display = "block";
}


function hideshow(group,sc) {
if (!sc){ var scc = 'false';}else{var scc = 'true';}
var txt = document.getElementById(group);
 if (txt.style.display == "none") {	
   txt.style.display="block";
   if (scc == 'true'){this.SetCookie(group,1); }
   }
   else{
   txt.style.display="none";
   if (scc == 'true'){this.SetCookie(group,0); }
   }
}
function recallCookie(group) {
	try{
	var x = document.cookie;
	var txt = document.getElementById(group);
	
		y = this.getCookie(group);
		if (y == 1) {
			txt.style.display="block";
		} else {
			txt.style.display="none";
		}
	}
	catch(e){
		alert('recallCookie error: ' + e.message + '\n\n' + e.description);
	}
}
// [Cookie] Sets value in a cookie
function SetCookie(cookieName, cookieValue, expires, path, domain, secure) {
	if (expires == null) {
		var cookie_date = new Date();  // current date & time		
		var month = cookie_date.getMonth() + 1
		expires = new Date ( cookie_date.getFullYear(), month, cookie_date.getDate() );		
	}	
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');		
}

// [Cookie] get Cookie Values
function getCookie(cookieName){
	var results = document.cookie.match ( cookieName + '=(.*?)(;|$)' );
	// alert('cookie:'+cookieName+' value='+results);
	if (results) {
		return (unescape(results[1])); }
	else
		{ return null; }
}

// JS Trim String
function trim(str){
 return str.replace(/^\s*|\s*$/g,"");
}

// Pop-Up Position

var cX = 0; var cY = 0; var rX = 0; var rY = 0;

function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}

if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }

function AssignPosition(d,xo,yo,height) {
try{
if(!xo){ xo = 1 }
if(!yo){ yo = -1 }
if(!height){height = 0}

if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX+xo) + "px";
if (yo != 'auto'){
	d.style.top = (cY-yo) + "px";
}else{
	bh = document.body.clientHeight;
	scrolled = getScrollXY();
	th = cY + height - scrolled;
	alert(th+' = '+cY+' + '+height+' - '+scrolled+' || bh='+bh);
	if (th > height){ 
		alert('too low gotta move it '+th+' calcd pos:'+cY);
		cY = (bh - height);
		alert(cY);
		}else{alert('it fits '+th);

		}
	d.style.top = (cY) + "px";
}
}
catch(e){
	alert('Error in AssignPosition: \n' + e.message);
}
}

function AssignPositionByID(d,xo,yo) {
try{
if(!xo){ xo = 1 }
if(!yo){ yo = -1 }
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
var id = document.getElementById(d);
id.style.left = (cX+xo) + "px";
id.style.top = (cY-yo) + "px";
}
catch(e){
	alert('Error in AssignPosition: \n' + e.message);
}
}

function ajaxSaveForm(formid,action){
	try{
		ColdFusion.Ajax.submitForm(formid,action,zxResults);
	}
	catch(e){
		alert('ajaxSaveForm error: ' + e.message + '\n\n' + e.description);
	}
}

//<![CDATA[

//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

//]]>
// end move a div code....

function refreshPage(path){
	if (confirm('Are you Sure?\n\nAny un-saved changes will be lost')){
	window.location.href = path;
	}
}

function exitEdit(href){
	if (!href){ var href = "zca.cfm?go=zAdminHome";}
	if (href == '' || href == 0){ var href = "zca.cfm?go=zAdminHome";}
	
	window.location.href = href;
}

function zResults(r){
	eval(r);
}

function setPointer(theRow, thePointerColor){
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') { return false; }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        var theCells = theRow.getElementsByTagName('td');
    }else if (typeof(theRow.cells) != 'undefined') {
        var theCells = theRow.cells;
    }else { return false;}
    var rowCellsCnt  = theCells.length;
    for (var c = 0; c < rowCellsCnt; c++) {
        theCells[c].style.backgroundColor = thePointerColor;    }
    return true;
	}
	
function toggleEditOption(n,id,iid){
try{
	count = 1;
	while (document.getElementById(id+count) != null)
	{
		aimg = document.getElementById(iid+count)
		aimg.src = "/sysImages/dot.gif";
		hide(id+count);
		
		count ++;
	}
	aimg = document.getElementById(iid+n)
	aimg.src = "/sysImages/arrow-right.gif";
	show(id+n);
}
catch(e){
	alert(e.message);
}
}
function refreshzPage(){
	alert('refresh');
}


function addContactName(){
	
		stid = document.getElementById('contactSendToNew');
		st = stid.value;
		stnid = document.getElementById('contactSendToNameNew');
		stn = stnid.value;
		if (st == '' || stn == ''){
			alert('You must enter both a email address and a display name');
		}else{
			DWRUtil.useLoadingImage(ajaxLoading);
			DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'contactForm', st, stn, zxResults);
		}		
}

function deleteContactName(id){

	if (confirm('Delete this Contact Option?')){
	
		DWRUtil.useLoadingImage(ajaxLoading);
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'contactFormDelete', id, zxResults);
	
	}

}

// Simple Prod Ops Absolute Price Display
function setOpPrice(selectObj,mode,pID,dspNone){ 
	if(mode == 1){
		var newPrice = selectObj[selectObj.selectedIndex].getAttribute('dsp');
		if(newPrice != ''){
			$('pPriceAmt'+pID).innerHTML = newPrice;
		}
		else{
			$('pPriceAmt'+pID).innerHTML = dspNone;
		}
	}
}

// Custom Bind Functions, Uses custom-event-listeners.js which is included in zJs.cfm
function addBindListener(eName,eObj,bObj,bType,bSource,popIn,syncOnLoad){ 
	var event = eName;
	window[eName] = new Event();
	listenOnObj = document.getElementById(eObj);
	window[eName].addListener(listenOnObj,'bind',function(){getBinds(bObj,bType,bSource,popIn,syncOnLoad);});
}

function getBinds(bObj,bType,bSource,popIn,syncOnLoad){	
	var bField = $(bObj).getAttribute('bField');
	var cObjs = $(bObj).getAttribute('cObjs');
	var cFields = $(bObj).getAttribute('cFields');
	var dftSel = $(bObj).getAttribute('dftSel');
	var nextBind = escape($(bObj).getAttribute('onChange'));
	nextBind = nextBind.replace(/function%20anonymous%28%29%0A%7B%0A/i, "")
	nextBind = nextBind.replace(/%0A%7D/gi, "")
	var cValues = new Array;
	if(trim(cObjs) != ''){
		var cObjsArray = cObjs.split(',');
		for(var i=0; i<cObjsArray.length; i++){
 				cValues[i] = $(cObjsArray[i]).value;
		}
	}
	var args ={
	bObj: bObj,
	bType: bType,
	bSource: bSource,
	bField: bField,
	cValues: cValues,
	cFields: cFields,
	dftSel: dftSel,
	nextBind: nextBind,
	popIn: popIn,
	syncOnLoad: syncOnLoad
	};
	runAjx('zAjax_getBinds.cfm',args,ajaxLoading);
}

function getBoundProd(bObj,bType,bSource,oID,imgSwapMain,zim){
	var bField = $(bObj).getAttribute('bField');
	var cObjs = $(bObj).getAttribute('cObjs');
	if(trim(cObjs) != ''){
		cObjs = cObjs + ',' + bObj;
	}
	else{
		cObjs = bObj;
	}
	var cFields = $(bObj).getAttribute('cFields');
	cFields = cFields + ',' + bField
	var cValues = new Array;
	if(trim(cObjs) != ''){
		var cObjsArray = cObjs.split(',');
		for(var i=0; i<cObjsArray.length; i++){
 				cValues[i] = $(cObjsArray[i]).value;
		}
	}
	var args ={
	bType: bType, 
	bSource: bSource, 
	cValues: cValues, 
	cFields: cFields, 
	oID: oID, 
	imgSwapMain: imgSwapMain,
	zim: zim
	};
	runAjx('zAjax_getBoundProd.cfm',args,ajaxLoading);
}

//Handles multiple window.onload without overide
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// Find current browser scrolled position
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [scrOfY];
}

// Delete a product
function prodDelete(productID,script){
	if(confirm('Are you sure you want to delete this product?')){
		
		var args ={
		productID: productID, 
		script: script
		};
		runAjx('zAjax_prodDelete.cfm',args,ajaxLoading);
	}
}

function showLrgDetailImg(filename,filetitle,w,h,imageID,to,from,rs){

	
	// zImgAdd#addImgCount# = thumbimage
	// prodMainImg = main image
	// id="zProductImage#pID#"
	// onclick="showLrgDetailImg(#addImgCount#,'#jsstringFormat("#application.ImageDir#/#zProductDetailImages.fileName#")#','#jsstringformat(zProductDetailImages.iTitle)#','#pID#')"
	
	mainImg = document.getElementById('prodMainImg');
	if (rs == 'lightbox'){
	js = ' id="zImage'+from+'" onclick="javascript:zShowImage( '+from+',1 );" style="cursor:pointer;"  title="'+filetitle+' (Click to View Larger Image) " ';
	}
	else if (rs == 'href'){
	js = ' id="zImage'+from+'" onclick="javascript:gotoURL(\''+to+'\');" style="cursor:pointer;"  title="'+filetitle+' (Click for More Info) " ';
	}
	else{
	js = '  title="'+filetitle+'" ';
	}
	mainImg.innerHTML = '<img src="'+filename+'" alt="'+filetitle+'" width="'+w+'" height="'+h+'" '+js+'  border="0" class="imgTrans">';

}

//function zPartOptions(op,opSetField){
//	DWRUtil.useLoadingImage(ajaxLoading);
//	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'zPartOptions', op, opSetField, zxResults);
//}

function prodOpsEdit(opID){
	if(opID != 0){
		$('zProdOpsEditArea').innerHTML = '<div align="center">Loading...</div>';
		var args ={
			opID: opID
		};
		runAjx('zAjax_prodOpsEdit.cfm',args,'#application.AJAXLOADING#');
	}
	else{
		$('zProdOpsEditArea').innerHTML = '';
	}
}

function getPageSize(){
	
	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){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// Functions for page and checkout form fields
function fieldAdd(sourceID,queryName){
	if($('fieldType_'+sourceID).value == 'label'){
		var args ={
		action: "Add",	
		sourceID: sourceID,
		queryName: queryName,
		fieldTitle: '',
		fieldValues: $('fieldValues_'+sourceID).value,
		fieldType: $('fieldType_'+sourceID).value,
		fieldStyle: '',
		fieldMaxLength: 0,
		fieldReq: 0,
		fieldValidate: '',
		updateList: 1
		};
	}
	else{
		if($('fieldReq_'+sourceID).checked){
			var fReq = 1;
		}
		else{
			var fReq = 0;
		}
		var args ={
		action: "Add",	
		sourceID: sourceID,
		queryName: queryName,
		fieldTitle: $('fieldTitle_'+sourceID).value,
		fieldValues: $('fieldValues_'+sourceID).value,
		fieldType: $('fieldType_'+sourceID).value,
		fieldStyle: $('fieldStyle_'+sourceID).value,
		fieldMaxLength: $('fieldMaxLength_'+sourceID).value,
		fieldReq: fReq,
		fieldValidate: $('fieldValidate_'+sourceID).value,
		updateList: 1
		};
	}
	$('fieldTitle_'+sourceID).value = '';
	$('fieldValues_'+sourceID).value = '';
	runAjx('zAjax_FormFieldsAdmin.cfm',args,ajaxLoading);
}

function fieldEdit(sortID,sourceID,queryName,updateList){
	if($('fieldReq_'+sourceID+'_'+sortID).checked){
		var fReq = 1;
	}
	else{
		var fReq = 0;
	}
	var args ={
	action: "Update",	
	sourceID: sourceID,
	queryName: queryName,
	fieldTitle: $('fieldTitle_'+sourceID+'_'+sortID).value,
	fieldValues: $('fieldValues_'+sourceID+'_'+sortID).value,
	fieldType: $('fieldType_'+sourceID+'_'+sortID).value,
	fieldStyle: $('fieldStyle_'+sourceID+'_'+sortID).value,
	fieldMaxLength: $('fieldMaxLength_'+sourceID+'_'+sortID).value,
	fieldReq: fReq,
	fieldValidate: $('fieldValidate_'+sourceID+'_'+sortID).value,
	sortID: sortID,
	updateList: updateList
	};
	runAjx('zAjax_FormFieldsAdmin.cfm',args,ajaxLoading);
}

function fieldTypeChk(sortID,sourceID){
	var thisFieldTitle = $('fieldTitle_'+sourceID+'_'+sortID);
	var thisfieldValues = $('fieldValues_'+sourceID+'_'+sortID);
	var thisfieldType = $('fieldType_'+sourceID+'_'+sortID);
	var thisfieldStyle = $('fieldStyle_'+sourceID+'_'+sortID);
	var thisfieldMaxLength = $('fieldMaxLength_'+sourceID+'_'+sortID);
	var thisfieldReq = $('fieldReq_'+sourceID+'_'+sortID);
	var thisfieldValidate = $('fieldValidate_'+sourceID+'_'+sortID);
	if(thisfieldType.value == 'label'){
		thisFieldTitle.value = '-- Use Values for text --';
		thisFieldTitle.disabled = true;
		thisfieldStyle.value = '';
		thisfieldStyle.disabled = true;
		thisfieldMaxLength.value=0;
		thisfieldMaxLength.disabled = true;
		thisfieldReq.checked = false;
		thisfieldReq.disabled = true;
		thisfieldValidate.selectedIndex = 0;
		thisfieldValidate.disabled = true;
	}
	else{
		if(thisFieldTitle.value.toUpperCase() == '-- USE VALUES FOR TEXT --'){
			thisFieldTitle.value = 'Title';
		}
		thisFieldTitle.disabled = false;
		thisfieldStyle.disabled = false;
		thisfieldMaxLength.disabled = false;
		thisfieldReq.checked = false;
		thisfieldReq.disabled = false;
		thisfieldValidate.disabled = false;
	}
}

function fieldDelete(sortID,sourceID,queryName){
	if(confirm('Are you sure you want to delete this field?')){
		var args ={
		action: "Delete",	
		sourceID: sourceID,
		queryName: queryName,
		sortID: sortID,
		updateList: 1
		};
		runAjx('zAjax_FormFieldsAdmin.cfm',args,ajaxLoading);
	}
}

function fieldSort(sortID,sortDir,sourceID,queryName){
	var args ={
	action: "Sort",	
	sourceID: sourceID,
	queryName: queryName,
	sortID: sortID,
	sortDir: sortDir,
	updateList: 1
	};
	runAjx('zAjax_FormFieldsAdmin.cfm',args,ajaxLoading);
}

function moduleOptions(op,pageID,modOpsDsp,pageCopySource){
	if (op == ""){
		hide('module_Options');
		}else{
		show('module_Options');
	}
	
	DWRUtil.useLoadingImage(ajaxLoading);
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'pageOptions', op, pageID, modOpsDsp, pageCopySource, zResults);
}

function zRefreshCaptcha(capDiv,capForm){
	DWRUtil.useLoadingImage(ajaxLoading);
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'zRefreshCaptcha', capDiv,capForm, zResults);
}

// Functions for new category system product edit and quick edit.
var C1Sel = '';
var C2Sel = '';
var C3Sel = '';
var C4Sel = '';
var C5Sel = '';
var C6Sel = '';

function prodAddCategory(pCatName,pCatLvl,isMulti){
	if(!isMulti){isMulti = 0;}
	if(isMulti == 0){mName = ''}else{mName = 'Multi';}
	
	pCatName = trim(pCatName);
	pCatName = pCatName.substring(0,50);
	if (pCatName !== ''){
	
	if (pCatName == 'Add New Category'){
	document.getElementById('CategoryID'+mName+pCatLvl+'Sel').style.display = 'none';
	document.getElementById('CategoryNewID'+mName+pCatLvl+'Sel').style.display = 'block';
	}else
	{
	
	document.getElementById('CategoryNewID'+mName+pCatLvl+'Sel').style.display = 'none';
	document.getElementById('CategoryID'+mName+pCatLvl+'Sel').style.display = 'block';
	
	if (pCatName != ''){
		var dupeName = false;
		var cl = $('prodCat'+mName+pCatLvl+'List').getElementsByTagName('div')
		for (var i=0;i < cl.length;i++) 
		{
  				if(cl[i].getAttribute('catName') == pCatName){
				dupeName = true;
			}
		}
		if(!dupeName){
			var args ={
			pCatName: pCatName,
			pCatLvl: pCatLvl,
			pCatCount: cl.length,
			pmName: mName
			};
			runAjx('zAjax_prodAddCategory.cfm',args,ajaxLoading);
		}
		else{
			alert('The category named \''+pCatName+'\' is already defined');
		}
	}
	else{
		alert('Please enter or select a category name');
	}
	}
	}
}

function prodDelCategory(pid,cid){
	var parentNode = document.getElementById(pid);
	var childNode = document.getElementById(cid);
    parentNode.removeChild(childNode);
	if($(pid).getElementsByTagName('div').length == 0){
		var newSpan = document.createElement("span");
		newSpan.setAttribute('id',pid+'-blankCat');
		newSpan.innerHTML = 'None Defined';
		parentNode.appendChild(newSpan);
	}
}

function trShow(id){
	document.getElementById(id).style.display = '';
}

function setStyle( object, styleText ) {
	object.style.cssText += styleText;
}

function changecss(theClass,element,value) {
	//Last Updated on May 21, 2008
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 var added = false;
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    if(document.styleSheets[S][cssRules][R].style[element]){
	    document.styleSheets[S][cssRules][R].style[element] = value;
	    added=true;
		break;
	    }
	   }
	  }

	  if(!added){
	  if(document.styleSheets[S].insertRule){
			  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
			} else if (document.styleSheets[S].addRule) {
				document.styleSheets[S].addRule(theClass,element+': '+value+';');
			}
	  }
	 }
	}

function zLoading(bID,action,loadClass){
	// Note this function assumes that the button class names are "myClassName", "myClassName:hover" and "myClassNameOver"
	// by default the button class willbe replaced with 'zButtonWorking', you can overide this with the 'loadClass' var.
	if(!action){action = 'start';}
	if(!loadClass){loadClass = 'zButtonWorking';}
	myButton = document.getElementById(bID);
	
	if (action == 'start'){		
		myButton.onmouseout = function(){};
		myButton.onmouseover = function(){};
		myButton.className = loadClass;	
		myButton.disabled = true;
	}else{
		myButton.onmouseout = function(){changeclass(action)};
		myButton.onmouseover = function(){changeclass(action+'Over')};
		myButton.className = action;
		myButton.disabled = false;
	}
}

function setClassName(oid,newClass){
	obj = document.getElementById(oid);
	obj.className = newClass;	
}

function chkAll(c,n){
	var cb = document.getElementsByName(n);
	for (var i = 0; i < cb.length; i++){
		cb[i].checked = c;
	}		       
}

// Custom Search Table Funcs
function stDrillDown(tID,tDepth,thisDepth,thisValue,vis,bVis){
	//alert('Table ID: '+tID+'\nTable Depth: '+tDepth+'\nThis Depth: '+thisDepth+'\nThis Value: '+thisValue);
	
	// vis / bVis 0 = No Change 1 = Hide / Show
	if(!vis){vis=0};
	if(!bVis){bVis=0};
	
	if(bVis == 1){
	
		if(thisDepth == tDepth && thisValue != ''){
			trShow('stSearchButton'+tID);
		}
		else{
			hide('stSearchButton'+tID);
		}
		
	}
	
	if(vis == 1){
		
		if(thisValue == ''){
			var s = thisDepth;
		}
		else{
			var s = thisDepth + 1;
		}
		
		var l = ["", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"];
		for (var i=1;i<=tDepth;i++){
			
			if(i <= s){
				trShow('stRow'+l[i]+''+tID);
			}
			else{
				hide('stRow'+l[i]+''+tID);
			}
			
		}
		
	}
	
}

//Url encode a string via JS
function js_urlencode(str){
	str = escape(str);
	return str.replace(/[*+\/@]|%20/g,
	function(s){
		switch(s){
			case "*": s = "%2A"; break;
			case "+": s = "%2B"; break;
			case "/": s = "%2F"; break;
			case "@": s = "%40"; break;
			case "%20": s = "+"; break;
		}
		return s;
	}
	);
}

function wordcount(string,formid) {
  var a = string.split(/\s+/g); // split the sentence into an array of words
  fcnt = document.getElementById(formid);
  fcnt.value = a.length;
  return;
}

function dupToMenu(cv){
	pt = document.getElementById('titleID').value;
	mt = document.getElementById('menuID').value;
	bt = document.getElementById('browserTitleID').value;
	mtInput = document.getElementById('mTitleForm').style.display;
	btInput = document.getElementById('bTitleForm').style.display;

	if (mt == null || mt == '' || mtInput == 'none'){ document.getElementById('menuID').value = leftTrim(document.getElementById('titleID').value,50) }
	if (bt == null || bt == '' || btInput == 'none'){ document.getElementById('browserTitleID').value = document.getElementById('titleID').value }

}

function pageTeaserAction(pageID,action){	
	teaserList = document.getElementById('teaserIDList').value;
	//alert(teaserList);
	//alert(pageID);
	$('pageTeaserSample').innerHTML = '<div align="center" style="width:auto;height:300px;padding-top:110px;background:#fefefe;"><div style="border: 1px solid black; padding: 10px; font-family: verdana, arial, helvetica; font-size: 12px; color: black; width: 300px; background-color: #f0f0f0;">Loading...  &nbsp;&nbsp;&nbsp;  <img src="/sysimages/ajax-loader3_f0f0f0.gif" width="25" height="25" alt="" border="0" align="absmiddle"></div></div>';
	DWRUtil.useLoadingImage(ajaxLoading);
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'PageTeaserAction', teaserList, pageID, action, zxResults);
}

function purgeFormData(id,action){
	if(!action){action = 'purge';}
	if(confirm('Are you sure you want to ' + action +' this forms\' data?')){
		var args ={id: id, action: action};
		runAjx('zPageForm_PurgeData.cfm',args,ajaxLoading);
	}
}
function chkDisplayType(v){
	ty = document.getElementById('customTeaserSelect');
	if (v == 3){
		
		ty.style.display = 'block';
		}
		else{
		ty.style.display = 'none';
		}
	
}

function zValidEmail(str){
	str = str.toLowerCase();
	return (str.search(/^[a-zA-Z]+([_\.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9]+)*(\.[a-zA-Z]{2,4})+$/) != -1);
}

function leftTrim(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function rightTrim(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}