/*
// Returns TRUE if the query is non-null
function nonNullQuery(form) {
  isNullCheck = form.query.value.replace(/\s+/, "") == "";
	
  if (isNullCheck)
    alert('Please type in your search in the text box.');
	
  return !isNullCheck;
}
*/

/*
function FindXY(obj) {
  var x=0,y=0;
  while(obj) {
    x += obj.offsetLeft - obj.scrollLeft;
    y += obj.offsetTop - obj.scrollTop;
    obj = (typeof obj.offsetParent == 'object') ? obj.offsetParent : null;
  }

  return {'x' : x, 'y' : y};
}
*/

/*
function getElementsByClassName(oElm, strTagName, strClassName) {
	var arrElements = (strTagName == "*" && oElm.all)
				? oElm.all 
				: oElm.getElementsByTagName(strTagName),
			arrReturnElements = new Array(),
			oElement;
	
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	
	for(var i=0; i<arrElements.length; i++){
			oElement = arrElements[i];      
			if(oRegExp.test(oElement.className)){
					arrReturnElements.push(oElement);
			}   
	}
	
	return arrReturnElements;
}
*/

/*
function elementIsIn(target, parent) {
  try {
    while (target && target != parent) {
	  	var newparent = target.parentNode;
      if (parent) target = newparent;
  		else break;
    }
  } catch(e) {
  }
  return target == parent;
}
*/

/*
function fixEvent(event) {
  event.preventDefault = fixEvent.preventDefault;
  event.stopPropagation = fixEvent.stopPropagation;
  return event;
}
*/

/*
function getTarget(event) {
  return (window.event) ? event.srcElement : event.target;
}
*/

/*
function getRelatedTarget(event) {
  var reltg;

  if (event.relatedTarget) {
    reltg = event.relatedTarget;
  } else {
    if (event.type == "mouseover")
      reltg = event.fromElement;
    else if (event.type == "mouseout")
      reltg = event.toElement;
    else
      reltg = document;
  }

  return reltg;
}
*/

/*
function elementHasClass(element, className) {
  if (element && element.className) {
    var re = new RegExp("(^| )" + className + "( |$)", "g");
    return (element.className.match(re) != null);
  }
  return false;
}
*/

/*
function elementAddClass(element, className) {
  element.className += " " + className;
}
*/

/*
function elementRemoveClass(element, className) {
  var re = new RegExp("(^| )" + className + "( |$)", "g");
  element.className = element.className.replace(re, " ");
}
*/

/*
function getWindowSize() {
  var windowSize = [0, 0];

  windowSize[0] = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  windowSize[1] = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  return windowSize;
}
*/

/*
function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return [curleft,curtop];
}
*/


/* 
		//For OLD myfinds save animations. 
		
		var tmp = setTimeout(function() { dest.style.backgroundColor = 'transparent'; },2000);
		var mfsAnimate = new tfAnimate(box);
		var mfsCloned = new tfAnimate(cloned);
		
		mfsAnimate.setRate(25,6);
		mfsCloned.setRate(25,6);
		mfsCloned.fade(10,0);
		mfsAnimate.scale(start,end,function() {
			cloned.style.display = 'none';
			mfsAnimate.setRate(10,10);
			mfsCloned.setRate(10,10);
			var	newstart = thefind.func.dimensions(box, true);
			if (type == 'safari' || type == 'opera' || (type == 'msie' && thefind.browser.version == '7')) {
				newstart.y += browserBody.scrollTop;
			}
			mfsAnimate.traverse(newstart,end,function() {
				cloned.style.display = 'block';
				mfsAnimate.setRate(25,6);
				mfsCloned.setRate(25,6);
				mfsCloned.fade(0,10,function() {
					mfsAnimate.fade(10,0,function() {
						var timer = setTimeout(function() { 
							mfsCloned.destroy(mfsAnimate.obj);
							mfsAnimate.destroy();
						},100);
					});
				});
			}); 
		});

function tfAnimate(obj) {
	this.scalingMethod = 1;
	this.obj = obj;
	
	this.setFPS = function(fps) {
		this.delay = 1000 / fps;
	}

	this.setRate = function(delay,frames) {
		this.delay = (delay)?delay:50;
		this.frames = (frames)?frames:10;	
	}

	// destroy
	this.destroy = function(container) {
		this.container = (container)?container:document.body;
		this.container.removeChild(this.obj);
	}

	// Fade
	this.fade = function(start,end,func) {
		this.start = (start)?start:obj.style.opacity; //recalculate start opacity if null
		this.end = end;
		this.step = (this.end - this.start) / this.frames;
		this.funcFade = (func)?func:false;
		this.index = 1;
		var thisObj = this;
		this.calcFade();
		this.timerFade = setInterval(function() { thisObj.calcFade(); },this.delay);
	}
	this.calcFade = function() {
		if (this.index >= this.frames) this.clearFade();
		this.start += this.step;
		setOpacity(this.obj,this.start);
		this.index++;
	}
	this.clearFade = function() {
		clearInterval(this.timerFade);
		if (typeof this.funcFade == 'function') this.funcFade();
	}
	
	// Traverse
	this.traverse = function(start,end,func) {
		this.start = (start)?start:this.getXY(); //recalculate 'start' XY if null
		
		this.end = end;
		this.stepX = (this.end.x - this.start.x) / this.frames;
		this.stepY = (this.end.y - this.start.y) / this.frames;
		this.funcTraverse = (func)?func:false;
		this.index = 1;
		var thisObj = this;
		this.calcTraverse();
		this.timerTraverse = setInterval(function() { thisObj.calcTraverse(); },this.delay);
	}
	this.getXY = function() {
		if (thefind.browser.type == "msie" && thefind.browser.version == "7") return {'x': this.obj.offsetLeft,'y':this.obj.offsetTop}
		else return thefind.func.dimensions(this.obj, true);
	}
	this.calcTraverse = function() {
		if (this.index >= this.frames) this.clearTraverse();
		this.start.x += this.stepX;
		this.start.y += this.stepY;
		this.obj.style.left = this.start.x+'px';
		this.obj.style.top = this.start.y+'px';
		this.index++;
	}
	this.clearTraverse = function() {
		clearInterval(this.timerTraverse);
		if (typeof this.funcTraverse == 'function') this.funcTraverse();
	}
	
	// Scale
	this.scale = function(start,end,func) {
		this.start = (start)?start:thefind.func.dimensions(this.obj); //recalculate 'start' XYWH if null
		this.end = end;
		this.stepW = (this.end.w - this.start.w) / this.frames;
		this.stepH = (this.end.h - this.start.h) / this.frames;
		this.funcScale = (func)?func:false;
		this.index = 1;
		if (this.scalingMethod == 1) this.centerScale();
		var thisObj = this;
		this.calcScale();
		this.timerScale = setInterval(function() { thisObj.calcScale(); },this.delay);
	}
	this.calcScale = function() {
		if (this.index > this.frames) this.clearScale();
		this.start.w += this.stepW;
		this.start.h += this.stepH;
		try { this.obj.style.width = this.start.w+'px'; } catch(e) { }
		try { this.obj.style.height = this.start.h+'px'; } catch(e) { }
		if (this.scalingMethod == 1) {
			this.start.x += this.stepX;
			this.start.y += this.stepY;
			this.obj.style.left = this.start.x+'px';
			this.obj.style.top = this.start.y+'px';
		}
		this.index++;
	}
	this.centerScale = function() {
		var x = this.start.x + (this.start.w - this.end.w) / 2;
		var y = this.start.y + (this.start.h - this.end.h) / 2;
		this.stepX = (x - this.start.x) / this.frames;
		this.stepY = (y - this.start.y) / this.frames;
	}
	this.clearScale = function() {
		clearInterval(this.timerScale);
		if (typeof this.funcScale == 'function') this.funcScale();
	}
}
*/

/*
function getTokenArray(string,delimeter) {
  array = string.split(delimeter);
  return (array)?array:false;
}
*/

/*
function FindXYWH(obj) {
	var ret = FindXY(obj);
	ret.w = obj.offsetWidth;
	ret.h = obj.offsetHeight;
  return ret;
}
*/

/*
function getInnerContent(obj, html){
  if(html) {
    return obj.innerHTML;
  } else {
    if (obj.innerText) {
        return obj.innerText;
    } else if (obj.textContent) {
        return obj.textContent;
    }
  }
}
*/

/*
function ResourceEditor() {
  this.resources = [];

  this.Init = function() {
    this.form = document.getElementById("tf_resource_controls");
    this.EnableForm(false);    
  }

  this.Edit = function(resourcename, event) {
    if (event) {
      event.preventDefault();
      event.stopPropagation();
    }

    var resourceid = "tf_resource_" + resourcename.replace(/\./g, "_");
    var resourcediv = document.getElementById(resourceid);
    if (resourcediv) {
			ajaxlib.Get("/resource/edit?" + encodeURIComponent("resource[name]") + "=" + encodeURIComponent(resourcename) + "&" + encodeURIComponent("resource[content]") + "=" + encodeURIComponent(resourcediv.innerHTML));
    }
    return false;
  }
  this.EditResource = function(res) {
    if (res.id) {
      this.Edit(res.id)
    }
  }
  this.Create = function(resid, divid) {
    this.resources[resid] = new Resource(resid, divid, this);
  }
  this.Get = function(resid) {
    if (!this.resources[resid]) {
      try{
        console.log("Create new - %s", resid);
      }catch(err){}
      var divid = "tf_resource_" + resid.replace(/\./g, "_");
      this.Create(resid, divid);
    }
    return this.resources[resid];
  }

  this.Save = function() {
    var url = "/resource/save?cobrandname=" + encodeURIComponent(this.form.elements.cobrand.value);
  
    for (var k in this.resources) { 
      if (!this.resources.hasOwnProperty(k)) continue;

      if (this.resources[k].modified)
        url += "&resource[" + k + "]=" + encodeURIComponent(this.resources[k].content);
    }
    ajaxlib.Get(url);
    return false;
  }

  this.EnableForm = function(state) {
    for (var k in this.form.elements) {
      if (!this.form.elements.hasOwnProperty(k)) continue;

      this.form.elements[k].disabled = (!state);
    }
    
  }
  this.CheckModified = function() {
    if (this.IsModified()) {
      this.EnableForm(true);      
    } else {
      this.EnableForm(false);
    }
  }
  this.IsModified = function() {
    for (var k in this.resources) {
      if (!this.resources.hasOwnProperty(k)) continue;

      if (this.resources[k].modified)
        return true;
    }
    return false;
  }


  this.Init();
}
*/

/*
var resourceeditor;
function Resource(resid, divid, resmgr) {
  this.id = resid;
  this.divid = divid;
  this.resmgr = resmgr;
  this.div = null;
  this.input = null;
  this.editing = false;
  this.modified = false;
  this.content = null;
  this.originalcontent = null;

  this.Init = function() {
    this.div = document.getElementById(this.divid);
    this.input = document.getElementById(this.divid + "_input");
    if (!this.originalcontent)
      this.originalcontent = this.input.value;
  }

  this.Edit = function(reload) {
    if (!this.div || reload) this.Init();

    this.editing = true;
    thefind.utils.elementAddClass(this.div, "active");
    if (this.div.onclick) 
      this.div.onclick = function(event) { event.stopPropagation(); };

    removeEvent(this.div, "click", this);
    addEvent(this.div, "keypress", this);
    addEvent(this.div, "keyup", this);

    if (this.input) {
      this.input.focus();
      addEvent(this.input, "blur", this);
    }
  }

  this.Unedit = function() {
    if (!this.div) this.Init();

    this.CheckModified();

    this.editing = false;
    thefind.utils.elementRemoveClass(this.div, "active");
    addEvent(this.div, "click", this);
    removeEvent(this.div, "keypress", this);

    this.content = this.input.value;
    this.div.innerHTML = this.input.value;
  }

  this.CheckModified = function() {
    if (this.content != this.originalcontent) {
      this.modified = true;

      if (!thefind.utils.elementHasClass(this.div, "modified"))
        thefind.utils.elementAddClass(this.div, "modified");
    } else {
      this.modified = false;
      if (thefind.utils.elementHasClass(this.div, "modified"))
        thefind.utils.elementRemoveClass(this.div, "modified");
    }

    this.resmgr.CheckModified();
  }

  this.handleEvent = function(event) {
    if (!event) event = window.event;
    var target = (event.srcElement || event.target);
    if (event.type == "blur") {
      try{
        console.log(event);
        console.log(target);
        console.log(this.div);
      }catch(err){}
      if (!thefind.utils.elementIsIn(event.explicitOriginalTarget, this.div))
        this.Unedit();
    } else if (event.type == "click") {
      if (!this.editing)
        this.resmgr.EditResource(this);
    } else if (event.type == "keyup" || event.type == "keypress") {
      if (event.type == "keyup" && event.keyCode == 27) { // escape
          this.input.value = this.originalcontent;
          this.content =  this.originalcontent;
      }
      this.CheckModified();
    }
  }
}
*/

/*
function listCookies() {
    var theCookies = document.cookie.split(';');
    var aString = '';
    for (var i = 1 ; i <= theCookies.length; i++) {
        aString += i + ' ' + theCookies[i-1] + "\n";
    }
    return aString;
}
*/

/*
function deleteCookie(name) {
    var aCookie = getCookie(name);
    if (aCookie) {
        document.cookie = aCookie + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
        return name;
    }
}
*/

/*
function BrowseMap(basediv) {
  //this.eventtype = "mouseover";
  this.eventtype = "click";
  this.initialized = false;

  this.Init = function(basedivid) {
    var basediv = (typeof(basedivid) == "string" ? document.getElementById(basedivid) : basedivid);
    if (basediv) {
console.log('init %s#%s.%s', basediv.tagName, basediv.id, basediv.className);
      if (basediv.tagName == "UL") {
        thefind.utils.elementAddClass(basediv, "tf_product_map_popup");
        var subcatpopuplinks = basediv.getElementsByTagName("a");
        for (var j = 0; j < subcatpopuplinks.length; j++) {
          addEvent(subcatpopuplinks[j], this.eventtype, this);
        }
      }

      var subcats = thefind.utils.getElementsByClassName(basediv, "ul", "tf_product_map_subcategory");
      for (var i = 0; i < subcats.length; i++) {
        if (!thefind.utils.elementHasClass(subcats[i], "tf_product_map_popup")) {
          this.Init(subcats[i]);
        }
      }
    } else {
      console.log('divname mismatch: %s', basedivid);
    }
  }
  this.Expand = function(path, parent) {
    var subcatelement;

    if (parent) {
      for (var i = 0; i < parent.childNodes.length; i++) {
        if (parent.childNodes[i].className && parent.childNodes[i].childNodes.length > 1 && parent.childNodes[i].className.match(/\btf_product_map_popup\b/)) {
          subcatelement = parent.childNodes[i];
          break;
        }
      }
      this.HideAll(parent);
    }

    if (subcatelement) {
      subcatelement.style.display = "block";
    } else {
			ajaxlib.Get(path)
    }

  }
  this.HideAll = function(except) {
    var olddivs = thefind.utils.getElementsByClassName(document, 'ul', 'tf_product_map_popup');
    for (var divnum = 0; divnum < olddivs.length; divnum++) {
      if (!except || !thefind.utils.elementIsIn(except, olddivs[divnum])) { 
				console.log("hide it!");
        olddivs[divnum].style.display = 'none'; 
      } 
    }
  }

  this.handleEvent = function(event) {
    if (!event) event = window.event;
    var target = (event.srcElement || event.target);

    if (target.className.match(/\btf_product_map_subcategorypopup\b/)) {
      if (event.type == this.eventtype) {
        event.preventDefault();
        event.stopPropagation();

        this.Expand(target.href, target.parentNode);
      } else if (event.type == "mouseout") {
        this.HideAll();
      }
    }
  }

  this.Init(basediv);
}
*/

/*
function objFader(obj,start,end,interval,delay,display) {
  this.start = (start)?start:0;
  this.current = this.start;
  this.end = (end)?end:10;
  this.interval = (interval)?interval:1;
  this.delay = (delay)?delay:100;
	this.display = display;
  this.obj = obj;
  this.Create = function() {
    var thisObj = this;
    var objFaderTimer = setInterval(function() {
      setOpacity(thisObj.obj,thisObj.current);
      if (thisObj.start < thisObj.end) {
        if (thisObj.current >= thisObj.end) { clearInterval(objFaderTimer); }
        thisObj.current += thisObj.interval;
      } else {
        if (thisObj.current <= thisObj.end) { 
					if (thisObj.display) thisObj.obj.style.display = "none";
					else thisObj.obj.style.visibility = "hidden"; 
					setOpacity(thisObj.obj,10); 
					clearInterval(objFaderTimer); 
				}
        thisObj.current -= thisObj.interval;
      }
    },this.delay);
  }
  this.Create();
}
*/

/*
function foreach(obj, fn, limit) {
  if (obj && fn) {
    if (typeof obj == 'array') {
      if (typeof limit == 'undefined')
        limit = obj.length;
      for (var i = 0; i < limit; i++) {
        fn(obj[i]);
      }
    } else if (typeof obj == 'object') {
      var keys = objkeys(obj);
      if (typeof limit == 'undefined')
        limit = keys.length;
      for (var i = 0; i < limit; i++) {
        fn(obj[keys[i]]);
      }
    }
  }
}
*/

/*
function drawDot(x,y,size,color) {
	// draws a [color] square [size] px wide at x:y coords
	x = (x)?x:10;
	y = (y)?y:10;
	color = (color)?color:'#fed';
	size = (size)?size:2;
	var dot = document.createElement('div');
	dot.style.position = 'absolute';
	dot.style.backgroundColor = color;
	dot.style.height = size+'px';
	dot.style.width = size+'px';
	dot.style.top = y+'px';
	dot.style.left = x+'px';
	document.body.appendChild(dot);
}
*/

/*
function objkeys(obj) {
  var ret = [];
  if (obj.hasOwnProperty) {
    for (var k in obj) {
      if (obj.hasOwnProperty(k)) 
        ret.push(k);
    }
  }
  return ret;
}
*/

/*
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}
*/