var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;

function AddToCart(f, iStock)
{	
/*
	if (iStock != "NO")
	{
		//validate input
		return true
	}
	alert("This product is currently out of stock. Please try back later!")
	return false
*/
	return true
}

getViewportWidth = function() {
  var width = 0;
  if( document.documentElement && document.documentElement.clientWidth ) {
	width = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth ) {
	width = document.body.clientWidth;
  }
  else if( window.innerWidth ) {
	width = window.innerWidth - 18;
  }
  return width;
}

getViewportHeight = function() {
  var height = 0;
  if( document.documentElement && document.documentElement.clientHeight ) {
	height = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight ) {
	height = document.body.clientHeight;
  }
  else if( window.innerHeight ) {
	height = window.innerHeight - 18;
  }
  return height;
}

getViewportScrollY = function() {
  var scrollY = 0;
  if( document.documentElement && document.documentElement.scrollTop ) {
	scrollY = document.documentElement.scrollTop;
  }
  else if( document.body && document.body.scrollTop ) {
	scrollY = document.body.scrollTop;
  }
  else if( window.pageYOffset ) {
	scrollY = window.pageYOffset;
  }
  else if( window.scrollY ) {
	scrollY = window.scrollY;
  }
  return scrollY;
}

function reShowVeil() {
	if(document.getElementById('veil').style.display == 'block') loadVeil();
}

function hideVeil() {
	var veil = document.getElementById('veil');
	if(veil.style.display == 'block') veil.style.display = 'none';
	var a;
	if(!document.getElementById('dvLargeImage')) {
		a = document.createElement('DIV');
		a.id = 'dvLargeImage';
		document.body.appendChild(a);
	}
	a = document.getElementById('dvLargeImage');
	a.style.display = 'none';
}
function loadVeil() {
	var veil = document.getElementById('veil');
	veil.style.height = (document.body.offsetHeight > document.body.scrollHeight ? document.body.offsetHeight : document.body.scrollHeight)+'px';
	veil.style.width = 	(isIE ? document.body.clientWidth : document.width)+'px';
	veil.style.filter = 'alpha(opacity=50)';
	veil.style.top = 0;
	veil.style.left = 0;
	veil.style.display = 'block';
}
function viewWindow(itemedp,itemdesc,ntype) {
	var a;
	var imgHTML;
	var divWidth;
	var divHeight;
	if(!document.getElementById('dvLargeImage')) {
		a = document.createElement('DIV');
		a.id = 'dvLargeImage';
		document.body.appendChild(a);
	}
	a = document.getElementById('dvLargeImage');
	loadVeil();
	if (ntype == '1')
	{
		divWidth = 520;
		divHeight = 580;
	}
	if (ntype == '2')
	{
		divWidth = 320;
		divHeight = 340;
	}
	var setX = ( getViewportWidth() - divWidth ) / 2;
	var setY = ( getViewportHeight() - divHeight ) / 2;
	if( setX < 0 ) setX = 0;
	if( setY < 0 ) setY = 0;
	if (ntype == '1')
	{
		imgHTML = ""
		imgHTML = imgHTML + "<div id='headerV'><span class='titleV'>Product View</span> <span class='closeV'>Close <a href='javascript:hideVeil()'><img src='/images/TG/btn_close.jpg'></a></span></div>";
		imgHTML = imgHTML + "<div><img src='/images/products/P" + itemedp + "_500.jpg' width=500 height=500 class='imgV'></div>";
		imgHTML = imgHTML + "<div class='titleV'>" + itemdesc + "</div>";
	}
	if (ntype == '2')
	{
		imgHTML = ""
		imgHTML = imgHTML + "<div id='headerV'><span class='titleV'>Watch Video</span> <span class='closeV'>Close <a href='javascript:hideVeil()'><img src='/images/TG/btn_close.jpg'></a></span></div>";
		imgHTML = imgHTML + "<div id=\"flashbox\" style=\"width:320px; height:265px;\"></div>";
	}
	a.innerHTML = imgHTML
	a.style.left = setX + "px";
	a.style.top = getViewportScrollY() + setY + "px";
	a.style.display = 'block';
	if (ntype == '2'){
		util.add_flash_video("flashbox", "/flash/" + itemedp + ".flv", true);
	}
}
function switchtoVideo(division) {
	document.getElementById("defaultimg").innerHTML = "<a href=" + "javascript:switchtoImage('" + division + "')" + " title=" + "View Image" + ">View Image</a>";
	document.getElementById("defaultimg").style.background = 'transparent url("../../images/' + division + '/bg_prodtab.gif") no-repeat scroll -1px top';
	document.getElementById("video").innerHTML = 'Watch Video';
	document.getElementById("video").style.background = 'transparent url("../../images/' + division + '/bg_prodtab-active.gif") no-repeat scroll left top';
	document.getElementById("showcase_view_01").style.display = 'none';
	util.show_flash_video("flashbox");	//use this to avoid firefox/flash glitches
	//document.getElementById("flashbox").style.display = 'block';
}
function switchtoImage(division) {
	document.getElementById("defaultimg").innerHTML = 'View Image';
	document.getElementById("defaultimg").style.background = 'transparent url("../../images/' + division + '/bg_prodtab-active.gif") no-repeat scroll left top';
	document.getElementById("video").innerHTML = "<a href=" + "javascript:switchtoVideo('" + division + "')" + " title=" + "Watch Video" + ">Watch Video</a>";
	document.getElementById("video").style.background = 'transparent url("../../images/' + division + '/bg_prodtab.gif") no-repeat scroll -1px top';
	document.getElementById("showcase_view_01").style.display = 'block';
	util.hide_flash_video("flashbox");	//use this to avoid firefox/flash glitches
	//document.getElementById("flashbox").style.display = 'none';
}
function watchVideo(itemedp)
{
	loadVeil();
}
function showAvail(num) {
	for (i=0; i<=20; i++)
	{
		if (document.getElementById('checkavail_' + i)) {
			document.getElementById('checkavail_' + i).style.visibility = 'hidden';
		}
	}
	if (document.getElementById('checkavail_' + num))
	{
		document.getElementById('checkavail_' + num).style.visibility = "visible";
	}
}
function closeAvail(num) {
	if (document.getElementById('checkavail_' + num))
	{
		document.getElementById('checkavail_' + num).style.visibility = "hidden";
	}
	if (document.getElementById('availemail_' + num))
	{
		document.getElementById('availemail_' + num).style.display = 'block';
	}
	if (document.getElementById('availimage_' + num))
	{
		document.getElementById('availimage_' + num).style.display = 'block';
	}
	document.getElementById('notifymessage_' + num).innerHTML = 'Enter your email address below to be notified when this item becomes available';
}
function showTellFriend() {
	if (document.getElementById('tellfriend'))
	{
		document.getElementById('tellfriend').style.visibility = "visible";
	}
}
function closeTellFriend() {
	if (document.getElementById('tellfriend'))
	{
		document.getElementById('tellfriend').style.visibility = "hidden";
	}
	if (document.getElementById("tellfriendmessage"))
	{
		document.getElementById("tellfriendmessage").style.display = 'none';
	}
	if (document.getElementById("tellemail"))
	{
		document.getElementById("tellemail").style.display = 'block';
	}
	if (document.getElementById("tellimage"))
	{
		document.getElementById("tellimage").style.display = 'block';
	}
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
	    {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
		catch (e)
	    {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	}
	return xmlHttp;
}
function ajxFrmProdNotify(num)
{
	var sku = alltrim(document.getElementById("sku").value);
	var email = alltrim(document.getElementById('availemail_' + num).value);
	var url = "/ajaxed/product-emailnotify.asp?sku="+sku+"&email="+email;
	xmlhttp = new GetXmlHttpObject();
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById('notifymessage_' + num).innerHTML = 'Thanks! You will be emailed when this product is available.';
			if (document.getElementById('availemail_' + num))
			{
				document.getElementById('availemail_' + num).style.display = 'none';
				document.getElementById('availemail_' + num).value = 'Email Address';
			}
			if (document.getElementById('availimage_' + num))
			{
				document.getElementById('availimage_' + num).style.display = 'none';
			}
		}
	}
	xmlhttp.send(null);
}
function ajxFrmProdTellFriend()
{
	var email = alltrim(document.getElementById("tellemail").value);
	var url = "/ajaxed/product-emailfriend.asp?email="+email;
	xmlhttp = new GetXmlHttpObject();
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById('tellfriendmessage').innerHTML = 'Thanks! You friend will be emailed about this great product shortly.';
			if (document.getElementById("tellfriendmessage"))
			{
				document.getElementById("tellfriendmessage").style.display = 'block';
			}
			if (document.getElementById("tellemail"))
			{
				document.getElementById("tellemail").style.display = 'none';
				document.getElementById("tellemail").value = 'Email Address';
			}
			if (document.getElementById("tellimage"))
			{
				document.getElementById("tellimage").style.display = 'none';
			}
		}
	}
	xmlhttp.send(null);
}
function addwishlist(num)
{
	var frm = document.getElementById('frmProduct_' + num)
	if (frm)
	{
	}else{
		frm = document.getElementById('frmProduct');
	}
	var fvalid = "Y"
	if ((frm.quantity.value == "") && (fvalid == "Y"))
	{
		alert("Please enter a Quantity");
		frm.quantity.value = "";
		frm.quantity.focus();
		fvalid = "N"
	}
	if ((!IsNumeric(frm.quantity.value)) && (fvalid == "Y"))
	{
		alert("Please enter a Quantity");
		frm.quantity.value = "";
		frm.quantity.focus();
		fvalid = "N"
	}
	if (fvalid == "Y")
	{
		cururl = '/addwishlist.asp?sku=' + frm.sku.value + '&qty=' + frm.quantity.value; 
		window.location.assign( cururl ); 
	}
}