// JavaScript Document
var initWidth;
var halfWay = false;
var flashLoaded = false;
var testcount = 1;
var addHeight= 0;
var oldColor = "";
var totalWidth = 100; //percent
var storeHTML = "";
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function presentationArea_DoFSCommand(command, args) {
	var presentationAreaObj = isInternetExplorer ? document.all.presentationArea : document.presentationArea;
	//
	// Place your code here. 
	if (command == 'isLoaded')
		{
			if (presentationAreaObj.PercentLoaded()==100)
				flashLoaded = true;
		}
	
	if (command == 'playLoaded')
		presentationAreaObj.play();
	//
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub presentationArea_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call presentationArea_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
function changeLayerHeight(chosenLayer,layerHeight)
{
	var wait = 200;
	if (layerHeight==0)
		initHeight = 200;
	if (layerHeight>0)
		initHeight = 0;
	document.all.showTable.style.visibility = 'visible';
	if (parseInt(chosenLayer.style.height)<layerHeight && initHeight==0)
	{
		addHeight = ((layerHeight * .1)-(parseInt(chosenLayer.style.height)*.1))+1;
		chosenLayer.style.height=parseInt(chosenLayer.style.height)+addHeight;
	}
	if (parseInt(chosenLayer.style.height)>=layerHeight && initHeight==200)
	{
		addHeight = (parseInt(chosenLayer.style.height)*.1)+1;
		chosenLayer.style.height=parseInt(chosenLayer.style.height)-addHeight;
	}
	window.status = chosenLayer.style.height + ' ' + addHeight + ' ' + (parseInt(chosenLayer.style.height)<=layerHeight);
	if (parseInt(chosenLayer.style.height)!=layerHeight)
	{
		setTimeout('changeLayerHeight(showcaseMovie,' + layerHeight +')',20);
	} else {
		if (layerHeight != 0) // don't play flash movie on close
		{
			presentationArea_DoFSCommand('playLoaded',0);
		} else {
			document.all.showTable.style.visibility = 'hidden';
		}
	}
}

function initSWF()
{
	if (flashLoaded)
	{
			showcaseMovie.style.height = 0;
			//showcaseMovie.style.visibility = 'visible';
			changeLayerHeight(showcaseMovie,200);
	} else {
		//alert('not loaded');
		//window.status = 'not loaded ' + testcount;
		/* testcount += 1;
		if (testcount==2)
			flashLoaded = true; */
		document.all.showTable.style.visibility = 'hidden';
		presentationArea_DoFSCommand('isLoaded',0);
		setTimeout("initSWF()",2000);
	}
}

function changeMenuformat(currentElement,action)
{
	if (action=="on")
	{
		currentElement.parentElement.style.backgroundColor = getBGcolor(6);
		//moreColor.style.backgroundColor = getBGcolor(6);
	}
	if (action=="off")
	{
		currentElement.parentElement.style.backgroundColor = "";
		//moreColor.style.backgroundColor = "";
	}
	
}
function getBGcolor(numOfColors)
{
	var newColor;
	var pickRandom = parseInt(Math.random()*numOfColors);
	while (oldColor == pickRandom)
	{
		pickRandom = parseInt(Math.random()*numOfColors);
	}
	switch (pickRandom)
	{
		/* Spring Colors
		case 0: {newColor = "#339900"; break;}
		case 1: {newColor = "#F5680A"; break;}
		case 2: {newColor = "#FF0783"; break;}
		case 3: {newColor = "#66CC00"; break;}
		case 4: {newColor = "#00ccff"; break;}
		case 5: {newColor = "#fb4f7a"; break;} */
		/* Fall Colors */
		case 0: {newColor = "#66CC00"; break;}
		case 1: {newColor = "#82552B"; break;}
		case 2: {newColor = "#CC127F"; break;}
		case 3: {newColor = "#F36523"; break;}
		case 4: {newColor = "#672407"; break;}
		case 5: {newColor = "#857F11"; break;}
	}
	oldColor = pickRandom;
	return newColor;
}
function createTable(numOfcol,areaHeight)
{
	
	//alert(selTag.tagName);
	var saveString = '<table width="100%" height="'+areaHeight+'"  border="0" cellpadding="0" cellspacing="0">\n';
	document.write(saveString);
	storeHTML += saveString;
	var tblHeight = 70;
	for (i=0;i<numOfcol;i++)
	{
		var halfWidth = (totalWidth/8);
		var pickRandom = parseInt(Math.random()*halfWidth);
		totalWidth -= pickRandom;
		saveString = '<tr><td id="colorRow'+ i +'" height="'+ pickRandom +'%" bgcolor="'+getBGcolor(6)+'"><img src="" height=1 width=1></td></tr>\n';
		document.write(saveString);
		storeHTML += saveString;
		eval("colorRow"+i).style.filter = "Alpha(Opacity="+(100-tblHeight)+", Style=0)";
		tblHeight -= 10;
	}
	saveString = '</table>';
	document.write(saveString);
	storeHTML += saveString;
}

function alertMsg(whichAlert)
{
	var msg = "";
	if (whichAlert == 'notAvailable')
		msg = "Bella Paris.com\n-----------------\n\nProduct unavailable at this time!\nPlease check back soon!";
	if (whichAlert == 'noCode')
		msg = "Bella Paris.com\n-----------------\n\nDiscount Codes are unavailable at this time!\nPlease check back soon!";		
	if (msg != "")
		alert(msg);
}
function switchImage(whichImg, switchImg)
{
	document.mainimg.src = "/images/products/product"+switchImg+".jpg";
	if (whichImg == 'n')
		document.mainimg.src = preImage.src;
	if (whichImg == 'd')
		document.mainimg.src = preImage2.src;
	
}
function showImage(whichVar,whichImg)
{
	if (whichVar=='vid')
	{
		window.open('video/'+whichImg,"vid","width=350,height=260,scrollbars=false");
	} else {
		window.open('showPic.php?'+whichVar+'='+whichImg,"custPic","width=5,height=5,scrollbars=false");
	}
}
function submitProduct(anyAction)
{
	if (anyAction == "u")
	{
		alertMsg('notAvailable');
	} else {
		document.forms[0].submit();
	}
}
function viewPhotos(whichPic)
{
	window.open("altPics.php?pic="+whichPic+"&type=_full","altViews","width=485,height=500,scrollbars=false");
}

function updateQuant()
{
	document.forms[0].hidUpdateAction.value = "true";
	document.forms[0].submit();
	//alert(document.forms[0].hidUpdateAction.value);
}
function enterCode(codeAction)
{
	if (codeAction == "na")
	{
		alertMsg('noCode');
	} 
	if (codeAction == "s")
	{
		//window.open("showPic.php?cust="+whichImg,"custPic","width=5,height=5,scrollbars=false");
		document.getElementById("discountPage").className = "showLayer";
	}
	if (codeAction == "c")
	{
		//window.open("showPic.php?cust="+whichImg,"custPic","width=5,height=5,scrollbars=false");
		createdURL = "test.php?l=c&rand="+Math.random()*100000;
	//	alert(createdURL);
		if (getCookie('bpDC')!=null)
		{
			document.getElementById("codeStatus").className = "codeFormattingR";
			document.getElementById("codeStatus").innerHTML = "Canceling Discount";
			document.getElementById("imgFrm").src = createdURL;
			setTimeout('showResults("c")',2000);
		} else {
			document.getElementById("discountPage").className = "hideLayer";
			document.getElementById("codeStatus").innerHTML = "&nbsp;";			
		}
		document.getElementById("txtCodeBox").value = "";
		
	}
}
function sendCode(enteredCode)
{
	createdURL = "test.php?l=" + document.getElementById("txtCodeBox").value + "&rand=" + Math.random()*100000;
//	alert(createdURL);
	document.getElementById("imgFrm").src = createdURL;
	document.getElementById("codeStatus").innerHTML = "Processing Code";
	setTimeout('showResults()',2000);
	// document.getElementById("txtCodeBox").value;
}
function showResults(action)
{
	if (action=='c')
	{
		document.getElementById("discountPage").className = "hideLayer";
		document.getElementById("codeStatus").innerHTML = "&nbsp;";
	} else {
		//document.getElementById("codeStatus").innerHTML = getCookie('bpDC');
	}
	window.location.reload();
}
function showCodePage()
{
	enterCode('s');
	document.getElementById("codeStatus").innerHTML = getCookie('bpDC');
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}
function change4Shipping(shipPrice)
{
	var cartTotal = parseFloat(document.forms[0].txtCartTotal.value);
	var cartDiscount = parseFloat(document.forms[0].txtDiscount.value);
	shipPrice = parseFloat(shipPrice);
	var subTotal = (cartTotal - cartDiscount) + shipPrice;
	if (subTotal.toFixed)
	{
		document.forms[0].txtCartSubtotal.value = subTotal.toFixed(2);
	} else {
		subTotalx = formatCurrency(subTotal);
		document.forms[0].txtCartSubtotal.value = subTotalx;
	}
}
	var igMO = "";
	var menuOverImg= new Array(8);
	menuOverImg[0]='btnShopBag';
	var btnShopBagOver = new Image();
	menuOverImg[1]='btnShop';
	var btnShopOver = new Image();
	menuOverImg[2]='btnPress';
	var btnPressOver = new Image();
	menuOverImg[3]='btnRetailers';
	var btnRetailersOver = new Image();
	menuOverImg[4]='btnWholesale';
	var btnWholesaleOver = new Image();
	menuOverImg[5]='btnAbout';
	var btnAboutOver = new Image();
	menuOverImg[6]='btnHelp';
	var btnHelpOver = new Image();
	menuOverImg[7]='btnContact';
	var btnContactOver = new Image();
	

	for (x=0; x<8; x++) 
	{
		eval(menuOverImg[x] + 'Over.src = "/images/over/' +  menuOverImg[x] + '.gif"');
	}

function switchImg(whichImg, switchImg)
{
	if (switchImg!=igMO)
	{
		if (whichImg == 'v')
			eval('document.'+switchImg+'.src =  ' + switchImg + 'Over.src');
		if (whichImg == 'u')
			eval('document.'+switchImg+'.src =  "/images/' + switchImg + '.gif"');
	}
}
