//
// (c)2008 The Andra Group, Inc.
//

var swatchwin;
var friendState = 0;
var curTab = 2;
var friendPlus = new Image;
var friendMinus = new Image;
var tab01 = new Image;
var tab02 = new Image;
var tab03 = new Image;
var tab04 = new Image;
var tab05 = new Image;
var tab06 = new Image;
var tab11 = new Image;
var tab12 = new Image;
var tab13 = new Image;
var tab14 = new Image;
var tab15 = new Image;
var tab16 = new Image;
var tab21 = new Image;
var tab22 = new Image;
var tab23 = new Image;
var tab24 = new Image;
var tab25 = new Image;
var tab26 = new Image;

var zStartLeft=300;
var zStartTop=140;
var zStartWidth=1;
var zStartHeight=1;
var zEndLeft=340;
var zEndTop=50;
var zEndWidth=392;
var zEndHeight=262;
var zCount;
var zMaxCount = 20;
var zIntervalID;
var zMode;
var currImage = 'main';

function popcolor(swatchfile, colorname) {
	var regexp = /&/
	if (!swatchwin || swatchwin.closed) {
		swatchwin = window.open("swatch.aspx?Color=" + colorname + "&Swatch=" + swatchfile.replace(regexp,"%26"),"","height=200,width=200")
		if (!swatchwin.opener) {
			swatchwin.opener = window
		}
	} else {
		swatchwin.focus()
		swatchwin.location = "swatch.aspx?Color=" + colorname + "&Swatch=" + swatchfile.replace(regexp,"%26")
	}}

function setcolor(colorcode) {
	for (var i=0; i<document.forms.F1.color.length; i++) {
		if (document.forms.F1.color.options[i].value == colorcode) {
			document.forms.F1.color.selectedIndex = i;
			break
		}}}


function clicked(which) {
	eval('document.MainImage.src = img_' + which + '.src')
	currImage = which;
}

function toggleFriend() {
	if (friendState == 0) {
		document.getElementById("friend").style.visibility = "visible";
		document.getElementById("friend").style.display = "inline";
		document.friendExpand.src = friendMinus.src;
		friendState = 1;
	} else {
		document.getElementById("friend").style.visibility = "hidden";
		document.getElementById("friend").style.display = "none";
		document.friendExpand.src = friendPlus.src;
		friendState = 0;
	}}

function over(tab) {if (tab != curTab) {eval('document.tab' + tab + '.src = tab2' + tab + '.src')} return false}
function off(tab) {if (tab != curTab) {eval('document.tab' + tab + '.src = tab0' + tab + '.src')} return false}
function goto_tab(tab) {eval('document.tab' + curTab + '.src = tab0' + curTab + '.src'); curTab = tab; eval('document.tab' + curTab + '.src = tab1' + curTab + '.src'); document.getElementById("info").focus(); return false}

function LoadImages2() {
	friendPlus.src = 'images/mail-plus.gif';
	friendMinus.src = 'images/mail-minus.gif';
	tab01.src = 'images/tabs/0-01.gif';
	tab02.src = 'images/tabs/0-02.gif';
	tab03.src = 'images/tabs/0-03.gif';
	tab04.src = 'images/tabs/0-04.gif';
	tab05.src = 'images/tabs/0-05.gif';
	tab06.src = 'images/tabs/0-06.gif';
	tab11.src = 'images/tabs/1-01.gif';
	tab12.src = 'images/tabs/1-02.gif';
	tab13.src = 'images/tabs/1-03.gif';
	tab14.src = 'images/tabs/1-04.gif';
	tab15.src = 'images/tabs/1-05.gif';
	tab16.src = 'images/tabs/1-06.gif';
	tab21.src = 'images/tabs/2-01.gif';
	tab22.src = 'images/tabs/2-02.gif';
	tab23.src = 'images/tabs/2-03.gif';
	tab24.src = 'images/tabs/2-04.gif';
	tab25.src = 'images/tabs/2-05.gif';
	tab26.src = 'images/tabs/2-06.gif';
}

function isEmpty(inputStr) {
	if (inputStr == null || inputStr == "") {return true} return false}

function verifySubmitTAF() {
	if (isEmpty(document.friend_form.YourName.value)) {
		alert('Your name is required for us to send this to your friend.')
		return false
	}
	if (isEmpty(document.friend_form.YourEmail.value)) {
		alert('Your email address is required for us to send this to your friend.')
		return false
	}
	if (isEmpty(document.friend_form.FriendsEmail.value)) {
		alert('Your friend\'s email address is required for us to send this to them.')
		return false
	}
	if (echeck(document.friend_form.YourEmail.value) == false) return false;
	return echeck(document.friend_form.FriendsEmail.value);
}

function verifySubmitCloseout() {
	if (document.F1.UPC.selectedIndex < 1) {
		alert('Please select a color and size.');
		return false;
	}}

function verifySubmitStandard() {
	if ((document.F1.color.selectedIndex < 1 && document.F1.color.length > 1) || (document.F1.size.selectedIndex < 1 && document.F1.size.length > 1)) {
		alert('Please select a color and size.');
		return false;
	}}


// global variables
// position of the mouse on the screen
var xMousePos = 0; 
var yMousePos = 0;
// position of the main image on the screen
var MainImageX;
var MainImageY;

function showZoom2() {
	//if (zIntervalID) clearInterval(zIntervalID);
	//document.MainImage.src = img_main.src;
	MainImageX = getObjLeft(document.getElementById("MainImage"));
	MainImageY = getObjTop(document.getElementById("MainImage"));
	/*document.getElementById('zoom2').style.left = zStartLeft+'px';
	document.getElementById('zoom2').style.top = zStartTop+'px';
	document.getElementById('zoom2').style.width = zStartWidth+'px';
	document.getElementById('zoom2').style.height = zStartHeight+'px';
	document.getElementById('zoom2').style.visibility = 'visible';
	document.getElementById('zoom2').style.display = 'block';*/

	document.getElementById('zoom4').style.left = (MainImageX-getObjLeft(document.getElementById('body1')))+'px';
	document.getElementById('zoom4').style.top = (MainImageY-getObjTop(document.getElementById('body1')))+'px';
	if (document.all) {	// Internet Explorer
		document.getElementById('zoom4').style.width = '132px';
		document.getElementById('zoom4').style.height = '89px';
	}
	document.getElementById('zoom4').style.zIndex = '2';
	document.getElementById('zoom4').style.visibility = 'visible';
	document.getElementById('zoom4').style.display = 'block';
	
	/*zCount = 0;
	zMode = 1;
	//zIntervalID = setInterval("doZoom()",2);
	hideZoomIcon();*/
	currImage = 'main'
}

function hideZoom2() {
	//if (zIntervalID) clearInterval(zIntervalID);
	/*document.getElementById('zoom2').style.left = zEndLeft+'px';
	document.getElementById('zoom2').style.top = zEndTop+'px';
	document.getElementById('zoom2').style.width = zEndWidth+'px';
	document.getElementById('zoom2').style.height = zEndHeight+'px';
	document.getElementById('zoom2a').style.visibility='hidden';
	document.getElementById('zoom2a').style.display='none';

	zCount = zMaxCount+1;
	zMode = -1;*/
	//zIntervalID = setInterval("doZoom()",2);
}

function hideZoomIcon() {
	//document.getElementById('ZoomIcon').style.visibility='hidden';
	document.getElementById('ZoomIcon').style.display='none';
}

function showZoomIcon() {
	//document.getElementById('ZoomIcon').style.visibility='visible';
	document.getElementById('ZoomIcon').style.display='block';
}

function doZoom() {
	zCount = zCount + zMode;
	document.getElementById('zoom2').style.left = (zStartLeft+(zEndLeft-zStartLeft)*zCount/zMaxCount)+'px';
	document.getElementById('zoom2').style.top = (zStartTop+(zEndTop-zStartTop)*zCount/zMaxCount)+'px';
	document.getElementById('zoom2').style.width = (zStartWidth+(zEndWidth-zStartWidth)*zCount/zMaxCount)+'px';
	document.getElementById('zoom2').style.height = (zStartHeight+(zEndHeight-zStartHeight)*zCount/zMaxCount)+'px';
	setOpacity(document.getElementById('MainImage'), 10-5*zCount/zMaxCount)

	if (zMode == 1 && zCount >= zMaxCount) {
		clearInterval(zIntervalID);
		document.getElementById('zoom2').style.left = zEndLeft+'px';
		document.getElementById('zoom2').style.top = zEndTop+'px';
		document.getElementById('zoom2').style.width = zEndWidth+'px';
		document.getElementById('zoom2').style.height = zEndHeight+'px';
		document.getElementById('zoom2a').style.visibility = 'visible';
		document.getElementById('zoom2a').style.display = 'block';

	}
	if (zMode == -1 && zCount < 1) {
		clearInterval(zIntervalID);
		document.getElementById('zoom2').style.visibility='hidden';
		document.getElementById('zoom2').style.display='none';
		if (currImage == 'main') showZoomIcon();
	}}

function moveZoom2(e) {
	try {
		var positX = xMousePos-MainImageX;
		var positY = yMousePos-MainImageY;
		var zoomX = positX - 68;
		var zoomY = positY - 43;
		if (zoomX < 1) zoomX=1;
		if (zoomY < 1) zoomY=1;
		if (zoomX > 89) zoomX=89;
		if (zoomY > document.getElementById('MainImage').height-88) zoomY=document.getElementById('MainImage').height-88;

		document.getElementById('zoom4').style.left = (MainImageX-getObjLeft(document.getElementById('body1'))+zoomX)+'px';
		document.getElementById('zoom4').style.top = (MainImageY-getObjTop(document.getElementById('body1'))+zoomY)+'px';
		document.getElementById('zoom5').style.left = (-zoomX)+'px';
		document.getElementById('zoom5').style.top = (-zoomY)+'px';
		document.getElementById("zoom3").style.left = (-zoomX * 3)+'px';
		document.getElementById("zoom3").style.top = (-zoomY * 3)+'px';
		} catch(e) { // ignore error
	}
}


// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier. We'll also grab the location of the image.
/*var xPos;
var tempEl;
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netscape 6
    document.onmousemove = captureMousePosition;
}*/

function captureMousePosition(e) {
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    } else if (document.all) {
        xMousePos = window.event.clientX+document.body.scrollLeft;
        yMousePos = window.event.clientY+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    }}

function getObjLeft(obj) {
	if (document.layers) { // Netscape 4 -- untested
		return docjslib_getImageXfromLeft(obj);
	} else if (document.all) { // Internet Explorer
		return docjslib_getRealLeft(obj);
	} else if (document.getElementById) { // Netscape 6/Firefox
		return firefox_getRealLeft(obj);
	}}

function getObjTop(obj) {
	if (document.layers) { // Netscape 4 -- untested
		return docjslib_getImageYfromTop(obj);
	} else if (document.all) { // Internet Explorer
		return docjslib_getRealTop(obj);
	} else if (document.getElementById) { // Netscape 6/Firefox
		return firefox_getRealTop(obj);
	}}

function docjslib_getImageXfromLeft(imgID) {
  if (document.layers) return eval(imgID).x
  else return docjslib_getRealLeft(imgID);
}

function docjslib_getImageYfromTop(imgID) {
  if (document.layers) return eval(imgID).y
  else return docjslib_getRealTop(imgID);
}

function docjslib_getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

function firefox_getRealLeft(imgElem) {
	xPos = imgElem.offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function firefox_getRealTop(imgElem) {
	xPos = imgElem.offsetTop;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function setOpacity(obj, value) {	// value: 0-10
	obj.style.opacity = value/10;
	obj.style.filter = 'alpha(opacity=' + value*10 + ')';
}
	