
//for product info page:
var attributesboxisshowing = false;
var speedforattributesboxshow = 600;	
var productcontent = null;
var attrinfo = null;
var thiscururl8456784 = null;
function show_attributesdiv () {
		if (attributesboxisshowing) {
			//hide box
			//boxdiv.style.display = 'none';
			attrinfo = document.getElementById('productcontentplace').innerHTML;
			document.getElementById('productcontentplace').innerHTML = productcontent;
			productcontent = null;
			attributesboxisshowing = false;
		} else {
			//show box
			if (!attrinfo) {
				attrinfo = document.getElementById('productinfoattributesdiv').innerHTML;
				document.getElementById('productinfoattributesdiv').innerHTML = '';
			}
			boxdiv = document.getElementById('visiblecartquantity');
			if (boxdiv) {
				document.getElementById('hiddencartquantity').value = boxdiv.value;
			}
			//boxdiv.style.display = 'block';
			productcontent = document.getElementById('productcontentplace').innerHTML;
			document.getElementById('productcontentplace').innerHTML = attrinfo;
			attributesboxisshowing = true;
			if (!thiscururl8456784) {
				thiscururl8456784 = window.location;
				location.href = thiscururl8456784 + "#pitop";
			} else {
				location.href = window.location;
			}			
		}
}

//for tabbed area
var curseltab = 1;
var curhovtab = null;
var hoverstatus = new Array();
sethoverstatus();
function sethoverstatus() {
	for (i = 0; i < 6; i++) {
		hoverstatus[i] = false;
	}
}
function showtabarea (a) {
	//tab clicked
	if (curseltab != a) {
		//unhighlight all other tabs
		var tmpimg = document.getElementById('tabimg' + curseltab).src;
		document.getElementById('tabimg' + curseltab).src = document.getElementById('imgchange' + curseltab).src;
		document.getElementById('imgchange' + curseltab).src = tmpimg;
		document.getElementById('tabtxtarea' + curseltab).style.display = 'none';
		curseltab = a;
		hoverstatus[a] = false;
		document.getElementById('tabtxtarea' + curseltab).style.display = 'block';
	}
}
function tabhover (a) {
	//tab hovered
	if (!hoverstatus[a] && a != curseltab) {
		hoverstatus[a] = true;
		var tmpimg = document.getElementById('tabimg' + a).src;
		document.getElementById('tabimg' + a).src = document.getElementById('imgchange' + a).src;
		document.getElementById('imgchange' + a).src = tmpimg;
	}
}
function tabunhover (a) {
	//tab unhovered
	if (hoverstatus[a] && a != curseltab) {
		hoverstatus[a] = false;
		var tmpimg = document.getElementById('tabimg' + a).src;
		document.getElementById('tabimg' + a).src = document.getElementById('imgchange' + a).src;
		document.getElementById('imgchange' + a).src = tmpimg;
	}
}

//for attribute more info
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
	//tempX = event.clientX + document.body.scrollLeft;
	//tempY = event.clientY + document.body.scrollTop;
	tempX = event.clientX;
	tempY = event.clientY;
  } else {  // grab the x-y pos.s if browser is NS
	//tempX = e.pageX;
	//tempY = e.pageY;
	tempX = e.clientX;
	tempY = e.clientY;
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0; }
  if (tempY < 0){tempY = 0; }  
  
  return true;
}
function getWindowDims () {
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}	
	
	return [windowWidth,windowHeight];
}

var isgetting_attributeinfo = false;
function getattributeinfo (id) {
	if (!isgetting_attributeinfo) {
		isgetting_attributeinfo = true;
		document.getElementById('attribute_information_box').innerHTML = '<div align="center"><span style="font-size:14px; font-style:italic;">Loading ...</span></div>';
		//show box
		show_attributeinfobox();
		var request = setRequest();
		if (request) {
			var url = "init_ajax.php";
			var parameters = "ajaxpage=" + escape(encodeURI('GetProductDescription.php')) + "&pid=" + escape(encodeURI(id));
			var theresult = "The server could not be reached at this time. Please try again later.";
			request.open("POST", url, true); 
			request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			request.setRequestHeader("Content-length", parameters.length);
			request.setRequestHeader("Connection", "close");
			request.onreadystatechange = function () {
				//handling request state
				//make sure no errors, if success, clear theresult
				if (request.readyState == 4) {
					if (request.status == 200) {
						finish_getattributeinfo(request.responseXML);
					} else {
						alert (theresult + ' status: ' + request.status);
						hide_show_attributeinfobox();
					}
					isgetting_attributeinfo = false;
				}
			};
			request.send(parameters); 
		}
	}
}

function setRequest() {
	var request = false;
	try {
		request = new XMLHttpRequest();
	} 
	catch (err) {
	   try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	   } 
	   catch (err) {
		   try {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		   } 
			   catch (failed) {
				request = false;
				}
	   }
	}
	return request;
}

function finish_getattributeinfo (respXML) {
	//display html to user
	var boxdiv = document.getElementById('attribute_information_box');
	if (respXML) {
		var theresult = '';
		if (respXML.getElementsByTagName("warningmsg")[0].hasChildNodes() == true) {
			theresult = respXML.getElementsByTagName("warningmsg")[0].firstChild.data;
		}
		if (theresult != '') {
			boxdiv.innerHTML = theresult;
		} else {
			//everything looks good, display html
			theresult = 'The description could not be retrieved at this time. There was an error in the data.<br>We apologize for any inconvenience this may have caused.<br><br>Please try back again later.<br><br>Thank you, The Telco Depot Team';
			var newhtml = '';
			if (respXML.getElementsByTagName("productdescription")[0].hasChildNodes() == true) {
				try {
					newhtml = respXML.getElementsByTagName("productdescription")[0].firstChild.data;
				} catch (err) {
					newhtml = theresult;
				}
			} else {
				newhtml = theresult;
			}
			boxdiv.innerHTML = newhtml;
		}
	} else {
		boxdiv.innerHTML = 'Unknown Error! Please try your request again later.';
	}
}

function show_attributeinfobox () {
	var boxdiv = document.getElementById('attribute_information_outter_box');
	boxdiv.style.display = 'block';
	var thewidth = boxdiv.offsetWidth;
	var theheight = boxdiv.offsetHeight;
	var arWinSize = getWindowDims();
	var newX = tempX;
	var newY = tempY;
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	newY = newY + ScrollTop;
	var ScrollLeft = document.body.scrollLeft;
	if (ScrollLeft == 0)
	{
		if (window.pageXOffset)
			ScrollLeft = window.pageXOffset;
		else
			ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
	}
	newX = newX + ScrollLeft;
	if (newX + thewidth > arWinSize[0]) {
		//off page!
		newX = newX - thewidth;
		if (newX < 0) {
			newX = 0;
		}
	}
	if (newY + theheight > arWinSize[1]) {
		//off page!
		newY = newY - theheight;
		if (newY < 0) {
			newY = 0;
		}
	}
	boxdiv.style.left = newX + 'px';
	boxdiv.style.top = newY + 'px';
}

function hide_show_attributeinfobox () {
	var boxdiv = document.getElementById('attribute_information_outter_box');
	boxdiv.style.display = 'none';
}

//bread crumb hover code
var bc_lastdiv = 0;
var cur_hover = new Array();
for (i=0; i<20; i++) {
	cur_hover[i] = false;
}
function highlight_breadcrumb (d) {
	if (!cur_hover[d]) {
		var e;
		for (i=1; i<bc_lastdiv; i=i+2) {
			if (cur_hover[i]) {
				//highlighted area, so un-highlight
				if (i > 1) {
					e = i - 1;
					document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/arrow-blue-blue.jpg)';
				}
				//main cell
				e = i;
				document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/bg-blue.jpg)';
				if ((i + 1) == bc_lastdiv) {
					//blue on white
					e = i + 1;
					document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/arrow-blue-trans.png)';
				} else {
					//blue on blue
					e = i + 1;
					document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/arrow-blue-blue.jpg)';
				}
				cur_hover[i] = false;
			}
		}
		cur_hover[d] = true;
		//back one td
		if (d > 1) {
			e = d - 1;
			document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/arrow-blue-orange.jpg)';
		}
		//main cell
		e = d;
		document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/bg-orange.jpg)';
		if ((d + 1) == bc_lastdiv) {
			//orange on white
			e = d + 1;
			document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/arrow-orange-white.jpg)';
		} else {
			//orange on blue
			e = d + 1;
			document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/arrow-orange-blue.jpg)';
		}
	}
}
function unhighlight_breadcrumb (d) {
	var i = d;
	if (cur_hover[i]) {
		//highlighted area, so un-highlight
		if (i > 1) {
			e = i - 1;
			document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/arrow-blue-blue.jpg)';
		}
		//main cell
		e = i;
		document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/bg-blue.jpg)';
		if ((i + 1) == bc_lastdiv) {
			//blue on white
			e = i + 1;
			document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/arrow-blue-trans.png)';
		} else {
			//blue on blue
			e = i + 1;
			document.getElementById('bctd' + e).style.backgroundImage = 'url(includes/templates/tdcustom/images/breadcrumb/arrow-blue-blue.jpg)';
		}
		cur_hover[i] = false;
	}
}

var jumptodivs = new Array();
for (var i=0; i<3; i++) {
	jumptodivs[i] = false;
}
function show_jumptodiv (d) {
	if (!jumptodivs[d]) {
		//show div
		document.getElementById('jumptodiv' + d).style.display = 'block';
		jumptodivs[d] = true;
	} else {
		//hide div
		document.getElementById('jumptodiv' + d).style.display = 'none';
		jumptodivs[d] = false;
	}
}

function show_divedeeper_box () {
	document.getElementById('divedeeper_box_mid_div').style.display = 'block';
}
function hide_divedeeper_box () {
	document.getElementById('divedeeper_box_mid_div').style.display = 'none';
}
function check_fail_editcart(resp) {
	isshowing_editcart = false;
	alert ('Network connection error! Please try your request again.');
	document.getElementById('shpcart_displayarea91283').innerHTML = cart_replacement298_tmphtml;
}

var isshowing_editcart = false;
var cart_replacement298_tmphtml = null;
function cart_edititem (curUID, itemQTY, hasAttributes) {
	if (!isshowing_editcart) {
		isshowing_editcart = true;
		//save current cart display in case cancel
		//document.getElementById('cart_replacement298').innerHTML = document.getElementById('shpcart_displayarea91283').innerHTML;
		cart_replacement298_tmphtml = document.getElementById('shpcart_displayarea91283').innerHTML;
		//load wait icon
		document.getElementById('shpcart_displayarea91283').innerHTML = document.getElementById('cart_waiting298').innerHTML;
		
		var url = "init_ajax.php";
		var payload = "ajaxpage=" + AjaxTCR.data.encodeValue('EditCartItem.php') + "&curUID=" + AjaxTCR.data.encodeValue(curUID) + "&itemQTY=" + AjaxTCR.data.encodeValue(itemQTY) + "&hasAttributes=" + AjaxTCR.data.encodeValue(hasAttributes);
		var copts = { expires: 0 };
		AjaxTCR.comm.cache.setOptions(copts);
		var options = { method: "POST",
						payload: payload,
						preventCache: true,
						timeout: 5000,
						retries: 3,
						onTimeOut: check_fail_editcart,
						//responseContentType: "text/xml",
						onFail: check_fail_editcart,
						onSuccess: finish_cart_edititem
		};
		AjaxTCR.comm.sendRequest(url,options);
	}
}

function finish_cart_edititem (respXML) {
	//display html to user
	respXML = AjaxTCR.data.serializeXMLString(respXML['responseText']);
	var boxdiv = document.getElementById('shpcart_displayarea91283');
	if (respXML) {
		var theresult = '';
		if (respXML.getElementsByTagName("warningmsg")[0].hasChildNodes() == true) {
			theresult = respXML.getElementsByTagName("warningmsg")[0].firstChild.data;
		}
		if (theresult != '') {
			boxdiv.innerHTML = theresult;
		} else {
			//everything looks good, display html
			theresult = 'The data for the selected cart item could not be retrived at this time. There was an error in the data.<br>We apologize for any inconvenience this may have caused.<br><br>Please try back again later.<br><br>Thank you, The Telco Depot Team';
			var newhtml = '';
			if (respXML.getElementsByTagName("cartedithtml")[0].hasChildNodes() == true) {
				try {
					newhtml = respXML.getElementsByTagName("cartedithtml")[0].firstChild.data;
				} catch (err) {
					newhtml = theresult;
				}
			} else {
				newhtml = theresult;
			}
			boxdiv.innerHTML = newhtml;
			Custom.init();
		}
	} else {
		boxdiv.innerHTML = 'Unknown Error! Please try your request again later.';
	}
}

function cancel_editcartitem () {
	if (isshowing_editcart) {
		isshowing_editcart = false;
		//switch back to cart view
		document.getElementById('shpcart_displayarea91283').innerHTML = cart_replacement298_tmphtml;
		cart_replacement298_tmphtml = null;
	}
}

var startedtotypehere = null;
function movetonextfield (f1, f2, x) {
	if (startedtotypehere == f1) {
		curdiv = document.getElementById(f1);
		nextdiv = document.getElementById(f2);
		if (curdiv && nextdiv) {
			tmpstr = curdiv.value;
			if (tmpstr.length == x) {
				nextdiv.focus();
				nextdiv.select();
				startedtotypehere = null;
			} else if (tmpstr.length > x) {
				alert ("You put too many characters into this field!");
				return;
			}
		}
	} else {
		startedtotypehere = f1;
	}
}

//var alertonetime = false;
function get_XY_fromDIV (ad) {
	pNode = document.getElementById(ad);
	var startX = 0;
	var startY = 0;
	var newstr = '';
	var xc = 0;
	var lastLeft = '';
	var lastTop = '';
	if (pNode) {
		while (pNode) {
			if (pNode.nodeType == 1) {
				//newstr += ' | x: ' + xc + ' left: ' + pNode.offsetLeft + ', top: ' + pNode.offsetTop;
				//if (lastLeft != pNode.offsetLeft && lastTop != pNode.offsetTop) {
				if (xc != 1 && xc != 8) {
					startX = startX + pNode.offsetLeft;
					startY = startY + pNode.offsetTop;
				}
				xc++;
				//}
			}
			pNode = pNode.parentNode;
		}
	}
	//if (!alertonetime) {
		//alert (newstr);
		//alertonetime = true;
	//}
	return [startX, startY];
}

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


var lasthoverdiv = [];
function hoverdiv_overdiv (div1, div2) {
	newxy = get_XY_fromDIV(div1);
	above = document.getElementById(div2);
	if (above) {
		above.style.left = newxy[0] + 'px';
		above.style.top = newxy[1] + 'px';
		above.style.display = 'block';
		var found = false;
		for (var i=0; i<lasthoverdiv.length; i++) {
			if (isArray(lasthoverdiv[i])) {
				//0 divname, 1 showing or not
				if (lasthoverdiv[i][1] == true && lasthoverdiv[i][0] != div2) {
					//hide
					hidedive(lasthoverdiv[i][0]);
					lasthoverdiv[i][1] = false;
				} else if (lasthoverdiv[i][0] == div2) {
					lasthoverdiv[i][1] = true;
					found = true;
				}
			} else {
				break;
			}
		}
		if(!found) {
			//have to insert new
			i = lasthoverdiv.length;
			lasthoverdiv[i] = [div2, true];
		}
	}
}

function hidedive (ad) {
	above = document.getElementById(ad);
	if (above) {
		above.style.display = 'none';
	}
}

function show_terminfobox (def) {
	document.getElementById('terminfobox_content').innerHTML = document.getElementById(def).innerHTML;
	var boxdiv = document.getElementById('terminfobox');
	definition_is_showing = def;
	boxdiv.style.display = 'block';
	var thewidth = boxdiv.offsetWidth;
	var theheight = boxdiv.offsetHeight;
	var arWinSize = getWindowDims();
	var newX = tempX;
	var newY = tempY;
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	newY = (newY + ScrollTop) - 15;
	var ScrollLeft = document.body.scrollLeft;
	if (ScrollLeft == 0)
	{
		if (window.pageXOffset)
			ScrollLeft = window.pageXOffset;
		else
			ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
	}
	newX = newX + ScrollLeft;
	newX = newX - (thewidth / 2);
	if (newX + thewidth > (arWinSize[0] + ScrollLeft)) {
		//off page!
		newX = newX - (thewidth / 2);
		if (newX < 0) {
			newX = 0;
		}
	}
	//if (newY + theheight > arWinSize[1]) {
		//off page!
		newY = newY - theheight;
		if (newY < 0) {
			newY = 0;
		}
	//}
	
	//off screen?
	//test: document.getElementById('testplacement').innerHTML = 'y: ' + newY + ' stop: ' + ScrollTop;
	if (newY < (ScrollTop - 15)) {
		var adj = 45;
		if ((newY + theheight + adj) + theheight <= (arWinSize[1] + ScrollTop)) {
			newY = newY + theheight + adj;
		}
	}
	if (newX < (ScrollLeft - 10)) {
		adj = 10;
		if ((newX + (thewidth / 2) + adj) + thewidth <= (arWinSize[0] + ScrollLeft)) {
			newX = newX + (thewidth / 2) + adj;
		}
	}
	
	boxdiv.style.left = newX + 'px';
	boxdiv.style.top = newY + 'px';
	
}
window.onresize = function (){
	if (chat_box_isshowing || chat_is_hidden) {
		chatbox = document.getElementById('chat_box_customer');
		chatbox.style.display = 'block';
		var thewidth = chatbox.offsetWidth;
		var theheight = chatbox.offsetHeight;
		var arWinSize = getWindowDims();
		var newX = 0;
		var newY = 0;
		newY = (parseInt(arWinSize[1]) / 2) - (parseInt(theheight) / 2);
		if (newY + theheight > arWinSize[1]) {
			//off page!
			newY = newY - theheight;
			if (newY < 0) {
				newY = 0;
			}
		}
		chatbox.style.top = newY + 'px';
		if (chat_is_hidden) {
			chat_actual_hide();
		} else {
			chatbox.style.left = newX + 'px';
		}
		if (adminhasimage == '1') {
			imgbox = document.getElementById('chat_box_adminbox');
			imgbox.style.display = 'block';
			imgbox.style.left = chatbox.style.left;
			theheight = imgbox.offsetHeight;
			newY = newY - theheight;
			imgbox.style.top = newY + 'px';
		}
	}
	position_flash_walkon();
}

var ismoving = null;
  function move_chatbox(direction, speed) {
  	if (ismoving) {
		//kill previous interval obj
		clearInterval(ismoving);
	}
	move_chatbox2(direction, speed);
	ismoving = setInterval("move_chatbox2(" + direction + "," + speed + ")", 300);
  }
	  
  function move_chatbox2(direction, speed) {
  	var boxChild = document.getElementById('chat_box_content');
	//only move box if it is bigger than parent
	var boxParent = document.getElementById('chat_box_contentwrapper');
	if (boxChild.offsetHeight > boxParent.offsetHeight) {
		var childY = boxParent.offsetTop + boxChild.offsetTop;
		var domove = true;
		//figure out if scroll allowed
		if (direction < 0) {
			if ((childY + boxChild.offsetHeight) <= (boxParent.offsetTop + boxParent.offsetHeight)) {
				domove = false;
			}
		} else {
			if (childY >= boxParent.offsetTop) {
				domove = false;
			}
		}
		if (domove) {
			var increment = (30 * speed) * direction;
			var newY = boxChild.offsetTop + increment;
			boxChild.style.top = newY + 'px';
		}
	}
  }
  
  function stop_move_chatbox() {
  	clearInterval(ismoving);
	ismoving = null;
  }
  
  function fix_chat_innerdiv(div1, div2) {
	var H = document.getElementById(div1).offsetHeight;
	d2 = document.getElementById(div2);
	var H2 = d2.offsetHeight;
	//alert (H + ' / ' + H2);
	var v = parseInt(H) - parseInt(H2);
	if (v < 0) {
		var newY = 0 + v;
		d2.style.top = newY + 'px';
	}
  }
	  
  function fix_chat_innerdiv_adjust(origH, div1, div2) {
	var H = document.getElementById(div1).offsetHeight;
	d2 = document.getElementById(div2);
	var H2 = d2.offsetHeight;
	//alert (H + ' / ' + H2);
	var v = parseInt(H) - parseInt(H2);
	if (v < 0) {
		if (parseInt(origH) != parseInt(H2)) {
			v = parseInt(H2) - parseInt(origH);
			var newY = d2.offsetTop - v;
			d2.style.top = newY + 'px';
		}
	}
  }
  
  function add_to_cart_noattrs () {
	  if (document.getElementById('visiblecartquantity')) {
	  	document.getElementById('hiddencartquantity').value = document.getElementById('visiblecartquantity').value;
	  }
	  document.cart_quantity.submit();
  }
  
  function request_livechat () {
	  show_requestlivechatbox();
  }
  
  var is_requestingchat = false;
  function request_livechat_2 () {
	  if (!is_requestingchat) {
		  var txtname = document.getElementById('livechatrequest_name' + whichchatbox).value;
		  if (txtname != '') {
			    is_requestingchat = true;
			    var url = www_url + "init_ajax.php";
				var payload = "ajaxpage=" + AjaxTCR.data.encodeValue('RequestALiveChat.php') + "&cust_name=" + AjaxTCR.data.encodeValue(txtname);
				var copts = { expires: 0 };
				AjaxTCR.comm.cache.setOptions(copts);
				var options = { method: "POST",
								payload: payload,
								preventCache: true,
								timeout: 5000,
								retries: 3,
								onTimeOut: chatrequest_fail,
								//responseContentType: "text/xml",
								onFail: chatrequest_fail,
								onSuccess: finish_request_livechat_2
				};
				AjaxTCR.comm.sendRequest(url,options);
		  } else {
			 alert ("Please type your name before continuing.");
			 is_requestingchat = false;
			 return;
		  }
	  }
	  hide_requestlivechatbox();
	  hide_requestlivechatbox2();
  }
  
  function chatrequest_fail (resp) {
	  if (is_requestingchat) {
		 alert ('An unstable network connection is preventing us from receiving your request. Please try again later.');
		 is_requestingchat = false;
	  }
  }
  
  function finish_request_livechat_2 (resp) {
	  is_requestingchat = false;
	  if (!should_check_chat) {
		  set_chat_check();
	  } else {
		 check_chat(''); 
	  }
  }
  
  function hide_requestlivechatbox () {
	  if (document.getElementById('livechatrequest_form')) {
	  	document.getElementById('livechatrequest_form').style.display = 'none';
	  }
  }
  
  function hide_requestlivechatbox2 () {
	  var bdiv = document.getElementById('livechatrequest_form2');
	  if (bdiv) {
	  	bdiv.style.display = 'none';
	  }
  }
  
  function show_requestlivechatbox () {
	  whichchatbox = '';
	var boxdiv = document.getElementById('livechatrequest_form');
	boxdiv.style.display = 'block';
	var thewidth = boxdiv.offsetWidth;
	var theheight = boxdiv.offsetHeight;
	var arWinSize = getWindowDims();
	var newX = tempX;
	var newY = tempY;
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	newY = newY + ScrollTop;
	var ScrollLeft = document.body.scrollLeft;
	if (ScrollLeft == 0)
	{
		if (window.pageXOffset)
			ScrollLeft = window.pageXOffset;
		else
			ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
	}
	newX = newX + ScrollLeft;
	if (newX + thewidth > arWinSize[0]) {
		//off page!
		newX = newX - thewidth;
		if (newX < 0) {
			newX = 0;
		}
	}
	if (newY + theheight > arWinSize[1]) {
		//off page!
		newY = newY - theheight;
		if (newY < 0) {
			newY = 0;
		}
	}
	boxdiv.style.left = newX + 'px';
	boxdiv.style.top = newY + 'px';
  }
  
  var whichchatbox = '';
  function request_livechat2 () {
	  whichchatbox = '2';
	var boxdiv = document.getElementById('livechatrequest_form2');
	boxdiv.style.display = 'block';
	var thewidth = boxdiv.offsetWidth;
	var theheight = boxdiv.offsetHeight;
	var arWinSize = getWindowDims();
	var newX = tempX;
	var newY = tempY;
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	newY = newY + ScrollTop;
	var ScrollLeft = document.body.scrollLeft;
	if (ScrollLeft == 0)
	{
		if (window.pageXOffset)
			ScrollLeft = window.pageXOffset;
		else
			ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
	}
	newX = newX + ScrollLeft;
	if (newX + thewidth > arWinSize[0]) {
		//off page!
		newX = newX - thewidth;
		if (newX < 0) {
			newX = 0;
		}
	}
	newY = newY - theheight;
	if (newY + theheight > arWinSize[1]) {
		//off page!
		newY = newY - theheight;
		if (newY < 0) {
			newY = 0;
		}
	}
	if (newY < 0) {
		newY = 0;
	}
	boxdiv.style.left = newX + 'px';
	boxdiv.style.top = newY + 'px';
  }
  
    var is_getting_image = false;
	function enlarge_image (num, pid) {
		if (!is_getting_image) {
			is_getting_image = true;
			show_wait();
			var url = "init_ajax.php";
			var payload = "ajaxpage=" + AjaxTCR.data.encodeValue('EnlargeImage.php') + "&image=" + AjaxTCR.data.encodeValue(num) + "&pid=" + AjaxTCR.data.encodeValue(pid);
			var copts = { expires: 0 };
			AjaxTCR.comm.cache.setOptions(copts);
			var options = { method: "POST",
							payload: payload,
							preventCache: true,
							timeout: 5000,
							retries: 3,
							onTimeOut: img_enlarge_fail,
							//responseContentType: "text/xml",
							onFail: img_enlarge_fail,
							onSuccess: finish_enlarge_image
			};
			AjaxTCR.comm.sendRequest(url,options);
		}
	}
	
	var is_showing_enlarged_image = false;
	function finish_enlarge_image (respXML) {
		if (!is_showing_enlarged_image) {
			animateoverlay();
		}
		hide_wait();
		//display html to user
		is_getting_image = false;
		var boxdiv = document.getElementById('big_img_wrapper');
		//respXML = AjaxTCR.data.encodeAsHTML(respXML);
		respXML = AjaxTCR.data.serializeXMLString(respXML['responseText']);
		//document.getElementById('testplacement').innerHTML = respXML[i];
		 //var teststr = '';
		 //for (var i in respXML) {
			//teststr = teststr + i + ' = ' + respXML[i] + ' --- ' + '<br>'; 
		 //}
		 //document.getElementById('testplacement').innerHTML = '"' + teststr + '"';
		//alert (AjaxTCR.data.serializeXML(respXML));
		if (respXML) {
			var theresult = '';
			if (respXML.getElementsByTagName("warningmsg")[0].hasChildNodes() == true) {
				try {
					theresult = respXML.getElementsByTagName("warningmsg")[0].firstChild.data;
				} catch (err) {  }
			}
			if (theresult == '') {
				var newhtml = '';
				if (respXML.getElementsByTagName("content")[0].hasChildNodes() == true) {
					try {
						newhtml = respXML.getElementsByTagName("content")[0].firstChild.data;
					} catch (err) {
						theresult = 'An error occurred. Please try your request again later.';
					}
				}
				if (newhtml != '') {
					boxdiv.innerHTML = newhtml;
					if (!is_showing_enlarged_image) {
						position_img_wrapper();
					}
				}
			}
			if (theresult != '') {
				alert (theresult);
				hide_img_wrapper();
			}
		}
	}
	
	function position_img_wrapper () {
		imgbox = document.getElementById('big_img_wrapper');
		if (imgbox) {
			is_showing_enlarged_image = true;
			imgbox.style.display = 'block';
			var thewidth = imgbox.offsetWidth;
			var theheight = imgbox.offsetHeight;
			var arWinSize = getWindowDims();
			var newY = (parseInt(arWinSize[1]) / 2) - (parseInt(theheight) / 2);
			var newX = (parseInt(arWinSize[0]) / 2) - (parseInt(thewidth) / 2);
			var ScrollTop = document.body.scrollTop;
			if (ScrollTop == 0)
			{
				if (window.pageYOffset)
					ScrollTop = window.pageYOffset;
				else
					ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
			newY = newY + ScrollTop;
			var ScrollLeft = document.body.scrollLeft;
			if (ScrollLeft == 0)
			{
				if (window.pageXOffset)
					ScrollLeft = window.pageXOffset;
				else
					ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
			}
			newX = newX + ScrollLeft;
			if (newX < 0) {
				newX = 0;
			}
			if (newY < 0) {
				newY = 0;
			}
			imgbox.style.left = newX + 'px';
			imgbox.style.top = newY + 'px';
		}
	}
	
	function hide_img_wrapper () {
		document.getElementById('big_img_wrapper').style.display = 'none';
		is_showing_enlarged_image = false;
		hideoverlay();
	}
	
	function img_enlarge_fail (resp) {
		is_getting_image = false;
		hide_wait();
	}
	
	function show_wait () {
		//show and position wait box
		waitbox = document.getElementById('waiting_box');
		if (waitbox) {
			waitbox.style.display = 'block';
			var thewidth = waitbox.offsetWidth;
			var theheight = waitbox.offsetHeight;
			var arWinSize = getWindowDims();
			var newY = 0;
			var newX = (parseInt(arWinSize[0]) / 2) - (parseInt(thewidth) / 2);
			waitbox.style.left = newX + 'px';
			waitbox.style.top = newY + 'px';
		}
	}
	
	function hide_wait() {
		document.getElementById('waiting_box').style.display = 'none';
	}
	
	function animateoverlay () {
		var arWinSize = getWindowDims();
		var boxDiv = document.getElementById('overlay');
		//make sure element responds to opacity change
		forceRerendering(boxDiv);
		//we offset the overly by 10px in case page has margin
		arWinSize[0] = parseInt(arWinSize[0]) + 10;
		arWinSize[1] = parseInt(arWinSize[1]) + 10;
		boxDiv.style.width = arWinSize[0] + 'px';
		boxDiv.style.height = arWinSize[1] + 'px';
		//we want to fade in the overlay
		//styles for IE and firefox: opacity:0.4; filter: Alpha(Opacity=40);
		try {
				boxDiv.style.opacity = 0;
			} catch (err) { }
		//for IE
		try {
			boxDiv.style.filter = 'Alpha(Opacity=0)';
		} catch (err) { }
		boxDiv.style.display = 'block';
		window.setTimeout('changeOpacity(\'overlay\', ' + opchange + ', 40)', opspeed);
	}
	
	function hideoverlay () {
		document.getElementById('overlay').style.display = 'none';
	}
	
	var opspeed = 50;
	var opchange = 10;
	function changeOpacity (ele, curop, finalop) {
		if (curop <= finalop && curop > 0) {
			//for FF
			var curop2 = parseFloat(curop) / 100;
			var boxDiv = document.getElementById(ele);
			try {
				boxDiv.style.opacity = curop2;
			} catch (err) { }
				
			//for IE
			try {
				boxDiv.style.filter = 'Alpha(Opacity=' + curop + ')';
			} catch (err) { }
			
			curop2 = curop + opchange;
			window.setTimeout('changeOpacity(\'' + ele + '\', ' + curop2 + ', ' + finalop + ')', opspeed);
		}
	}
	
	function forceRerendering (element) {
	  try {
		var n = document.createTextNode(' ');
		element.appendChild(n);
		element.removeChild(n);
		if (element.style.zIndex <= 0) {
			element.style.zIndex = 1;
		}
	  } catch(err) { }
	}
	
	//vertical nav on side:
	var cur_vertical_hover = null;
	function highlight_vcat(cid) {
		var boxdiv;
		if (cur_vertical_hover != cid) {
			if (cur_vertical_hover) {
				//unhighligh first
				unhighlight_vcat(cur_vertical_hover);
			}
			boxdiv = document.getElementById('vcsbox' + cid);
			if (boxdiv) {
				boxdiv.style.backgroundImage = 'url(includes/templates/tdcustom/images/newlayout/sidenav/bg-highlight.png)';
				cur_vertical_hover = cid;
			}			
		}
	}
	
	function unhighlight_vcat(cid) {
		var boxdiv;
		if (cur_vertical_hover) {
			//unhighligh first
			boxdiv = document.getElementById('vcsbox' + cid);
			if (boxdiv) {
				boxdiv.style.backgroundImage = '';
			}
			cur_vertical_hover = null;
		}
	}
	
	var viewing_vertical_cat_sub = null;
	function expand_vcat(cid) {
		var boxdiv;
		boxdiv = document.getElementById('vcssubbox' + cid);
		if (boxdiv) {
			if (viewing_vertical_cat_sub == cid) {
				//wants to hide
				boxdiv.style.display = 'none';
				viewing_vertical_cat_sub = null;
			} else if (viewing_vertical_cat_sub != cid && viewing_vertical_cat_sub) {
				//hide other sub cat before showing new cat
				boxdiv.style.display = 'block';
				boxdiv = document.getElementById('vcssubbox' + viewing_vertical_cat_sub);
				boxdiv.style.display = 'none';
				viewing_vertical_cat_sub = cid;
			} else {
				//just show new
				boxdiv.style.display = 'block';
				viewing_vertical_cat_sub = cid;
			}
		}
	}
	
	function show_cartalert() {
		animateoverlay();
		imgbox = document.getElementById('cart_backordereditems');
		imgbox.style.display = 'block';
		var thewidth = imgbox.offsetWidth;
		var theheight = imgbox.offsetHeight;
		var arWinSize = getWindowDims();
		var newY = (parseInt(arWinSize[1]) / 2) - (parseInt(theheight) / 2);
		var newX = (parseInt(arWinSize[0]) / 2) - (parseInt(thewidth) / 2);
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0)
		{
			if (window.pageYOffset)
				ScrollTop = window.pageYOffset;
			else
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
		newY = newY + ScrollTop;
		var ScrollLeft = document.body.scrollLeft;
		if (ScrollLeft == 0)
		{
			if (window.pageXOffset)
				ScrollLeft = window.pageXOffset;
			else
				ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
		}
		newX = newX + ScrollLeft;
		if (newX < 0) {
			newX = 0;
		}
		if (newY < 0) {
			newY = 0;
		}
		imgbox.style.left = newX + 'px';
		imgbox.style.top = newY + 'px';
	}
	
	function hide_cartalert() {
		hideoverlay();
		document.getElementById('cart_backordereditems').style.display = 'none';
	}
	
	function showhide_companyfield() {
		if (document.getElementById('companyquestion').checked) {
			document.getElementById('companynamespot1').style.display = 'block';
			if (document.getElementById('companynamespot2')) {
				document.getElementById('companynamespot2').style.display = 'block';
			}
		} else {
			document.getElementById('companynamespot1').style.display = 'none';
			if (document.getElementById('companynamespot2')) {
				document.getElementById('companynamespot2').style.display = 'none';
			}
		}
	}
	
	function show_checkout_createnewaddress() {
		document.getElementById('pickaddressspot_div').style.display = 'none';
		document.getElementById('createnewaddressspot_div').style.display = 'block';
	}
	
	function redirect_to_link (url) {
		if (this.location) {
			this.location.href = url;
		} else if (document.window.location) {
			document.window.location.href = url;
		} else if (window.location) {
			window.location.href = url;
		} else if (document.location) {
			document.location.href = url;
		}
	}
	
	var twitter_box_location = [];
	twitter_box_location[0] = 0;
	twitter_box_location[1] = -1; //direction
	var twitter_go = null;
	var twitter_speed = 5000;
	var twitter_move_speed = 1;
	function move_twitter_box () {
		var bd1 = document.getElementById('twitter_wrapper');
		var bd2 = document.getElementById('twitter_wrapper_in');
		if (bd1 && bd2) {
			var h1 = parseInt(bd1.offsetHeight);
			var h2 = parseInt(bd2.offsetHeight);
			if (h2 > h1) {
				//move!
				var y = twitter_box_location[0];
				var ymax = h1 - h2;
				if (y >= 0) {
					//reverse direction
					twitter_box_location[1] = -1;
				} else if (y <= ymax) {
					//reverse direction
					twitter_box_location[1] = 1;
				}
				twitter_box_location[0] += (twitter_move_speed * twitter_box_location[1]);
				//update position
				bd2.style.top = twitter_box_location[0] + 'px';
			} else {
				//clear 
				clearInterval(twitter_go);
				twitter_go = null;
			}
		} else {
			clearInterval(twitter_go);
			twitter_go = null;
		}
	}
	
	function pause_twitter_box () {
		if (twitter_go) {
			clearInterval(twitter_go);
			twitter_go = null;
		}
	}
	
	function start_twitter_box () {
		if (!twitter_go) {
			twitter_go = setInterval("move_twitter_box()", twitter_speed);
		}
	}
	var op_grp = [];
	function expand_option_group(i) {
		var bd = document.getElementById('attr_content_wrapper' + i);
		var bd2 = document.getElementById('attr_content_wrapper_msg' + i);
		if (bd && bd2) {
			if (op_grp[i]) {
				//is showing, hide
				bd.style.display = 'none';
				bd2.style.display = 'block';
				op_grp[i] = false;
			} else {
				//is hiding, show
				bd.style.display = 'block';
				bd2.style.display = 'none';
				op_grp[i] = true;
			}
		}
	}
	
	var shouldshowflash_walkon = false;
	function position_flash_walkon() {
		if (shouldshowflash_walkon) {
			var bdiv = document.getElementById('flash_walkon');
			var arWinSize = getWindowDims();
			var newY = 50;
			var newX = parseInt(arWinSize[0]) - 720;
			if (bdiv) {
				bdiv.style.left = newX + 'px';
				bdiv.style.top = newY + 'px';
			}
		}
	}
	
	function hide_flash_walkon() {
		if (shouldshowflash_walkon) {
			var bdiv = document.getElementById('flash_walkon');
			if (bdiv) {
				bdiv.style.display = 'none';
			}
		}
	}
	