// JavaScript Document
//initialize and define price
var price = 'images/TL_order_09-TL_order_03_gun.gif';
var matchingLeashLabel = 'images/TL_order_12-TL_order_03_gun.gif';
var matchingCollarLabel = 'images/TL_order_matching_leash.gif';
var colorSelected = false; //globals to track if a color and size are selected, then enable matching leash graphics
var sizeSelected = false;
var currentCollar = '0'; //global for current collar colorVal selected
var matchingLeft = false; //globals for whether a matching leash has been clicked
var matchingRight = false;
//window.alert('file called');
var Leash = new ObjLeash ();
	Leash.black = '025500';
	Leash.red = '025000';
	Leash.olive = '025600';
	Leash.blue	= '025100';
	Leash.green = '025200';
	Leash.pink = '025400';
	Leash.purple = '025300';
	Leash.blaze = '025700';
	
var SmallLeash = new ObjSMLeash ();
	SmallLeash.black = '045500';
	SmallLeash.red = '045000';
	SmallLeash.olive = '045600';
	SmallLeash.blue	= '045100';
	SmallLeash.green = '045200';
	SmallLeash.pink = '045400';
	SmallLeash.purple = '045300';
	SmallLeash.blaze = '045700';
	
//initialize and define colors
var clrGunnison = new ObjCollar();
	clrGunnison.colorVal = '55';
	clrGunnison.index = 0;
	clrGunnison.ImgID = 'TL_collar_select_06';
	clrGunnison.loadImage = 'images/TL_collar_select_06-TL_coll.gif';
	clrGunnison.rolloverImage = 'images/TL_collar_select_06.gif';
	clrGunnison.centerImage = 'images/TL_collar_select_07.gif';
	clrGunnison.headImage = 'images/TL_collar_select_01-TL_coll.gif';
	clrGunnison.orderImage = 'images/TL_order_03-gunnison.gif';
	clrGunnison.leashLeft = 'images/TL_order_13-TL_order_03_gun.gif';
	clrGunnison.leashRight = 'images/TL_order_14-TL_order_03_gun.gif';
	clrGunnison.leashLeftClicked = 'images/TL_order_13-TL_order_03_-43.gif';
	clrGunnison.leashRightClicked = 'images/TL_order_14-TL_order_03_-59.gif';
	clrGunnison.leashLeftCode = Leash.black;
	clrGunnison.leashRightCode = Leash.red;
	clrGunnison.SMleashLeftCode = SmallLeash.black;
	clrGunnison.SMleashRightCode = SmallLeash.red;
	
var clrRedRocks = new ObjCollar(); //50
	clrRedRocks.colorVal = '50';
	clrRedRocks.index = 1;
	clrRedRocks.ImgID = 'TL_collar_select_08';
	clrRedRocks.loadImage = 'images/TL_collar_select_08.gif';
	clrRedRocks.rolloverImage = 'images/TL_collar_select_08-over.gif';
	clrRedRocks.centerImage = 'images/TL_collar_select_07-TL_c-23.gif';
	clrRedRocks.headImage = 'images/TL_collar_select_01-TL_c-03.gif';
	clrRedRocks.orderImage = 'images/TL_order_03-red_rocks.gif';
	clrRedRocks.leashLeft = 'images/TL_order_13-TL_order_03_red.gif';
	clrRedRocks.leashRight = 'images/TL_order_14-TL_order_03_red.gif';
	clrRedRocks.leashLeftClicked = 'images/TL_order_13-TL_order_03_-44.gif';
	clrRedRocks.leashRightClicked = 'images/TL_order_14-TL_order_03_-60.gif';
	clrRedRocks.leashLeftCode = Leash.red;
	clrRedRocks.leashRightCode = Leash.purple;
	clrRedRocks.SMleashLeftCode = SmallLeash.red;
	clrRedRocks.SMleashRightCode = SmallLeash.purple;
		
var clrOtter = new ObjCollar();  //56
	clrOtter.colorVal = '56';
	clrOtter.index = 2;
	clrOtter.ImgID = 'TL_collar_select_09';
	clrOtter.loadImage = 'images/TL_collar_select_09.gif';
	clrOtter.rolloverImage = 'images/TL_collar_select_09-over.gif';
	clrOtter.centerImage = 'images/TL_collar_select_07-TL_c-22.gif';
	clrOtter.headImage = 'images/TL_collar_select_01-TL_c-04.gif';
	clrOtter.orderImage = 'images/TL_order_03-otter_cliffs.gif';
	clrOtter.leashLeft = 'images/TL_order_13-TL_order_03_ott.gif';
	clrOtter.leashRight = 'images/TL_order_14-TL_order_03_ott.gif';
	clrOtter.leashLeftClicked = 'images/TL_order_13-TL_order_03_-45.gif';
	clrOtter.leashRightClicked = 'images/TL_order_14-TL_order_03_-61.gif';
	clrOtter.leashLeftCode = Leash.olive;
	clrOtter.leashRightCode = Leash.blaze;
	clrOtter.SMleashLeftCode = SmallLeash.olive;
	clrOtter.SMleashRightCode = SmallLeash.blaze;
	
var clrNewRiver = new ObjCollar();
	clrNewRiver.colorVal = '51';
	clrNewRiver.index = 3;
	clrNewRiver.ImgID = 'TL_collar_select_10';
	clrNewRiver.loadImage = 'images/TL_collar_select_10.gif';
	clrNewRiver.rolloverImage = 'images/TL_collar_select_10-over.gif';
	clrNewRiver.centerImage = 'images/TL_collar_select_07-TL_c-21.gif';
	clrNewRiver.headImage = 'images/TL_collar_select_01-TL_c-05.gif';
	clrNewRiver.orderImage = 'images/TL_order_03-new_river.gif';
	clrNewRiver.leashLeft = 'images/TL_order_13-TL_order_03_new.gif';
	clrNewRiver.leashRight = 'images/TL_order_14-TL_order_03_new.gif';
	clrNewRiver.leashLeftClicked = 'images/TL_order_13-TL_order_03_-46.gif';
	clrNewRiver.leashRightClicked = 'images/TL_order_14-TL_order_03_-62.gif';
	clrNewRiver.leashLeftCode = Leash.blue;
	clrNewRiver.leashRightCode = Leash.pink;
	clrNewRiver.SMleashLeftCode = SmallLeash.blue;
	clrNewRiver.SMleashRightCode = SmallLeash.pink;

var clrGunks = new ObjCollar();
	clrGunks.colorVal = '52';
	clrGunks.index = 4;
	clrGunks.ImgID = 'TL_collar_select_11';
	clrGunks.loadImage = 'images/TL_collar_select_11.gif';
	clrGunks.rolloverImage = 'images/TL_collar_select_11-over.gif';
	clrGunks.centerImage = 'images/TL_collar_select_07-TL_c-20.gif';
	clrGunks.headImage = 'images/TL_collar_select_01-TL_c-06.gif';
	clrGunks.orderImage = 'images/TL_order_03-gunks.gif';
	clrGunks.leashLeft = 'images/TL_order_13-TL_order_03_-39.gif';
	clrGunks.leashRight = 'images/TL_order_14-TL_order_03_-56.gif';
	clrGunks.leashLeftClicked = 'images/TL_order_13-TL_order_03_-47.gif';
	clrGunks.leashRightClicked = 'images/TL_order_14-TL_order_03_-63.gif';
	clrGunks.leashLeftCode = Leash.green;
	clrGunks.leashRightCode = Leash.blue;
	clrGunks.SMleashLeftCode = SmallLeash.green;
	clrGunks.SMleashRightCode = SmallLeash.blue;

var clrPink = new ObjCollar();
	clrPink.colorVal = '54';
	clrPink.index = 5;
	clrPink.ImgID = 'TL_collar_select_12';
	clrPink.loadImage = 'images/TL_collar_select_12.gif';
	clrPink.rolloverImage = 'images/TL_collar_select_12-over.gif';
	clrPink.centerImage = 'images/TL_collar_select_07-TL_c-19.gif';
	clrPink.headImage = 'images/TL_collar_select_01-TL_c-07.gif';
	clrPink.orderImage = 'images/TL_order_03-pink.gif';
	clrPink.leashLeft = 'images/TL_order_13-TL_order_03_pin.gif';
	clrPink.leashRight = 'images/TL_order_14-TL_order_03_pin.gif';
	clrPink.leashLeftClicked = 'images/TL_order_13-TL_order_03_-48.gif';
	clrPink.leashRightClicked = 'images/TL_order_14-TL_order_03_-64.gif';
	clrPink.leashLeftCode = Leash.pink;
	clrPink.leashRightCode = Leash.green;
	clrPink.SMleashLeftCode = SmallLeash.pink;
	clrPink.SMleashRightCode = SmallLeash.green;

var clrWildIris = new ObjCollar();
	clrWildIris.colorVal = '53';
	clrWildIris.index = 6;
	clrWildIris.ImgID = 'TL_collar_select_13';
	clrWildIris.loadImage = 'images/TL_collar_select_13.gif';
	clrWildIris.rolloverImage = 'images/TL_collar_select_13-over.gif';
	clrWildIris.centerImage = 'images/TL_collar_select_07-TL_c-18.gif';
	clrWildIris.headImage = 'images/TL_collar_select_01-TL_c-08.gif';
	clrWildIris.orderImage = 'images/TL_order_03-wild_iris.gif';
	clrWildIris.leashLeft = 'images/TL_order_13-TL_order_03_wil.gif';
	clrWildIris.leashRight = 'images/TL_order_14-TL_order_03_pin.gif';
	clrWildIris.leashLeftClicked = 'images/TL_order_13-TL_order_03_-49.gif';
	clrWildIris.leashRightClicked = 'images/TL_order_14-TL_order_03_-64.gif';
	clrWildIris.leashLeftCode = Leash.purple;
	clrWildIris.leashRightCode = Leash.green;
	clrWildIris.SMleashLeftCode = SmallLeash.purple;
	clrWildIris.SMleashRightCode = SmallLeash.green;

var clrBlaze = new ObjCollar();
	clrBlaze.colorVal = '57';
	clrBlaze.index = 7;
	clrBlaze.ImgID = 'TL_collar_select_14';
	clrBlaze.loadImage = 'images/TL_collar_select_14.gif';
	clrBlaze.rolloverImage = 'images/TL_collar_select_14-over.gif';
	clrBlaze.centerImage = 'images/TL_collar_select_07-TL_coll.gif';
	clrBlaze.headImage = 'images/TL_collar_select_01-TL_c-09.gif';
	clrBlaze.orderImage = 'images/TL_order_03-blaze.gif';
	clrBlaze.leashLeft = 'images/TL_order_13-TL_order_03_bla.gif';
	clrBlaze.leashRight = 'images/TL_order_14-TL_order_03_bla.gif';
	clrBlaze.leashLeftClicked = 'images/TL_order_13-TL_order_03_-50.gif';
	clrBlaze.leashRightClicked = 'images/TL_order_14-TL_order_03_-65.gif';
	clrBlaze.leashLeftCode = Leash.blaze;
	clrBlaze.leashRightCode = Leash.olive;
	clrBlaze.SMleashLeftCode = SmallLeash.blaze;
	clrBlaze.SMleashRightCode = SmallLeash.olive;

//initialize and define global array for all functions related to collars
//function createArray () {
var collarArray = new Array(8);
	collarArray[0] = clrGunnison;
	collarArray[1] = clrRedRocks;
	collarArray[2] = clrOtter;
	collarArray[3] = clrNewRiver;
	collarArray[4] = clrGunks;
	collarArray[5] = clrPink;
	collarArray[6] = clrWildIris;
	collarArray[7] = clrBlaze;
//	return collarArray;
//}

// object definition for collar objects
function ObjCollar() {
	this.index = 0;
	this.colorVal = '0';
	this.loadImage = '';
	this.rolloverImage = '';
	this.centerImage = '';
	this.headImage = '';
	this.orderImage = '';
	this.leashLeft = '';
	this.leashRight = '';
	this.leashLeftClicked = '';
	this.leashRightClicked = '';
	this.leashLeftCode = '';
	this.leashRightCode = '';
	this.SMleashLeftCode = '';
	this.SMleashRightCode = '';
	this.size = '0';
	this.ImgID = '';
}

function ObjLeash () {
	this.black = '';
	this.red = '';
	this.olive = '';
	this.blue	= '';
	this.green = '';
	this.pink = '';
	this.purple = '';
	this.blaze = '';
	this.collarLeft = '';
	this.collarRight = '';
}

function ObjSMLeash () {
	this.black = '';
	this.red = '';
	this.olive = '';
	this.blue	= '';
	this.green = '';
	this.pink = '';
	this.purple = '';
	this.blaze = '';
	this.collarLeft = '';
	this.collarRight = '';
}

//Activate matching leashes buttons
//When a color button is clicked, the following occurs:
	//The headerImage is swapped
	//The orderImage is swapped
	//The matchingleashleft is displayed and activated
	//The matchingleashright is displayed and activated
function collarOver (collarValue) {
	//window.alert('collarOver called');
	for (x=0; x<=7; x++) {
		if (collarArray[x].colorVal == collarValue) {
			NEW_JG_swapColorImage('collar1', '', collarArray[x].centerImage); //swap center image
			NEW_JG_swapColorImage(collarArray[x].ImgID, '', collarArray[x].rolloverImage); //swap mouseover image
			} 
	}
}

function collarOut (collarValue) {
	for (x=0; x<=7; x++) {
		if (collarArray[x].colorVal == collarValue) {
			NEW_JG_swapColorImage(collarArray[x].ImgID, '', collarArray[x].loadImage); //swap mouseover image
			} 
	}
}

function collarClicked (collarValue) {
	colorSelected = true; //set colorSelected flag to true
	for (x=0; x<=7; x++) {
		if (collarArray[x].colorVal == collarValue) {
			NEW_JG_swapColorImage('TL_collar_select_01', '', collarArray[x].headImage); //swap head image
			NEW_JG_swapColorImage('TL_order_03', '', collarArray[x].orderImage); //swap order image
			NEW_JG_swapColorImage('TL_order_09', '', price); //swap price image
			EnableMatching(x);
			currentCollar = collarArray[x].colorVal;
			matchingLeft = false; //if a matching leash was selected, that color is lost when a new color is clicked
			matchingRight = false;
			} 
	}
}

function EnableMatching (x) {
	if (colorSelected == true) {
		NEW_JG_swapColorImage('TL_order_12', '', matchingLeashLabel); //swap matching leash label
		NEW_JG_swapColorImage('TL_order_13', '', collarArray[x].leashLeft); //swap left
		NEW_JG_swapColorImage('TL_order_14', '', collarArray[x].leashRight); //swap right
		NEW_JG_swapColorImage('TL_matching_collar', '', matchingCollarLabel);
		}
}

function MatchingOver(left, right) { //swap in the matching color for left and right
// first, determine which collar has been selected using the currentCollar ID value set at onClick
	if (left != '') {
	for (x=0; x<=7; x++) {
		if (collarArray[x].colorVal == currentCollar) 
			{NEW_JG_swapColorImage('TL_order_13', '', collarArray[x].leashLeftClicked); //swap head image
			} 
		}
	};	
	if (right != '') {
		for (x=0; x<=7; x++) {
			if (collarArray[x].colorVal == currentCollar) 
			{NEW_JG_swapColorImage('TL_order_14', '', collarArray[x].leashRightClicked); //swap head image
			}
		}
	}
}

function MatchingOut(left, right) { //swap back the load color for left and right
//add if matchingLeft or matchingRight global vars are true statement
//check first if matchingLeft or matchingRight is not empty

	if (left != '' && matchingLeft == false) {
	//window.alert(matchingLeft);
		for (x=0; x<=7; x++) {
			if (collarArray[x].colorVal == currentCollar) {
			NEW_JG_swapColorImage(left, '', collarArray[x].leashLeft); //swap head image
			} 
		}
	};
	
	if (right != '' && matchingRight == false) {
		for (x=0; x<=7; x++) {
			if (collarArray[x].colorVal == currentCollar) {
			NEW_JG_swapColorImage(right, '', collarArray[x].leashRight); //swap head image
			}
		}
	}
}

function MatchingOnClick (left, right) {// 1) disable MatchingOut somehow and 2) determine which set is currently loaded, so we know what values they are. 3) set up unclick
//if the value clicked was left, first check to see if matchingLeft is already true. if so, change matchingLeft to false; otherwise switch it to true and swap the image.
var localLeft = matchingLeft;
var localRight = matchingRight;
	if (left != '') {
		switch (localLeft) {
			case false ://if its false, flip the image and turn matchingLeft to true
				matchingLeft = true;
				for (x=0; x<=7; x++) {
					if (collarArray[x].colorVal == currentCollar) {
					NEW_JG_swapColorImage(left, '', collarArray[x].leashLeftClicked); //swap left image to clicked
					} 
				}
				break;
			case true : // if its true, this is a second click, so flip it to false so mouseout will do its thing.
				matchingLeft = false;
				break;
		}
	};
	if (right != '') {
		switch (localRight) {
			case false ://if its false, flip the image and turn matchingLeft to true
				matchingRight = true;
				for (x=0; x<=7; x++) {
					if (collarArray[x].colorVal == currentCollar) {
					NEW_JG_swapColorImage(right, '', collarArray[x].leashRightClicked); //swap left image to clicked
					} 
				}
				break;
			case true : // if its true, this is a second click, so flip it to false so mouseout will do its thing.
				matchingRight = false;
				break;
		}
	};
}

function sizeColorYes () {
//if colorSelected = false 
//	popup a box that says choose a color
// if sizeSelected = false
//  popup a box that says choose a size
//sizeSelected = false;
	if (colorSelected == false) 
	{
		//popup window that says pick a color
		//return false;
	};
	if (sizeSelected == false) 
	{
		//popup window that says pick a size
		return false;
	};
}

function checkIfSmall (size) {
	if (size == '10') {
		return true;
		}
	}
function buildURL () {
//1: Verify that both size and color are selected. 
//2. Build URL for color and size
//3. Check to see if leash left or right is true. 
//	a. LEFT TRUE: build a separate URL for Left
//	b. RIGHT TRUE: build a sep. URL for right
//	c. Concatenate leash URL to Collar URL
//4. Write complete URL to document.
	//window.alert('buildURL');
var URL = "";
var builtURL = "";
var leftURL = '';
var rightURL = '';
var leashURL = '?productcode=';

var convertedSize = (""+trackSizeValue);
var smallSize = (""+trackSizeValue);
var sizeColorYesResult = true; 

//small collar?
//checkIfSmall (trackSizeValue);
//window.alert('trackSizeValue is '+trackSizeValue);
if (trackSizeValue == '08'||trackSizeValue == '09'||trackSizeValue == '10'||trackSizeValue == '11'||trackSizeValue == '12'||trackSizeValue == '1301') {
	URL="http://www.tazlab.com/shoppingcart.asp?productcode=03";
	}
	else {	URL="http://www.tazlab.com/shoppingcart.asp?productcode=01";
		}
//sizeColorYesResult = sizeColorYes();
//window.alert(sizeColorYesResult);
//switch (sizeColorYesResult) {
	//case false : 
	//	break;
	//case true : 
	//jg: 10-6-06: Call new function to determine if it is a small collar. function should switch the 01xxxx to 03xxxx and small leash matching skus

	if (currentCollar == '0') {
		errcolor = window.open('err_choose_color.htm', 'errcolor', 'width=400, height=170');
	 	errcolor.moveTo(400, 400);
		};
	
	if (currentCollar !='0') 
	{
		for (x=0; x<=7; x++) 
		{
			if (collarArray[x].colorVal == currentCollar) //identify current collar chosen
			{ 
				if (trackSizeValue == '8'||trackSizeValue == '9'){// if  value is 8 or 9, prepend a zero to the size portion of the sku
					smallSize = ("0"+trackSizeValue);
					builtURL=URL+collarArray[x].colorVal+smallSize;
					//window.alert ('convertedSize equals '+convertedSize+' smallSize equals '+smallSize);
					}
					else {
						if (trackSizeValue == '1301') //if its a 13 small, convert the 1301 to 13 to build the sku
						convertedSize = ("13");
						builtURL=URL+collarArray[x].colorVal+convertedSize;
						};
					
				//builtURL=URL+collarArray[x].colorVal+convertedSize; //build collar URL
				if (matchingLeft == true) //if a left leash has been chosen
				{
					if (trackSizeValue == '08'||trackSizeValue == '09'||trackSizeValue == '10'||trackSizeValue == '11'||trackSizeValue == '12'||trackSizeValue == '1301')
					{
					builtURL=builtURL+'&productcode='+collarArray[x].SMleashLeftCode;
					}
					else {
					builtURL=builtURL+'&productcode='+collarArray[x].leashLeftCode;
					//};
					};
				};
				if (matchingRight == true)
				{
				if (trackSizeValue == '08'||trackSizeValue == '09'||trackSizeValue == '10'||trackSizeValue == '11'||trackSizeValue == '12'||trackSizeValue == '1301') {
					builtURL=builtURL+'&productcode='+collarArray[x].SMleashRightCode;
				}
					else {
					builtURL=builtURL+'&productcode='+collarArray[x].leashRightCode;};
					//};
				};
				//window.alert(collarArray[x].colorVal+sizeChosen);
				if (collarArray[x].colorVal != '0' && sizeChosen != false) 
				{
					document.location.href = builtURL;
				} ;
				if (collarArray[x].colorVal == '0' && sizeChosen == false) 
				{
					errcolor = window.open('err_choose_both.htm', 'errcolor', 'width=400, height=170');
	 				errcolor.moveTo(500, 400);
					//window.alert('choose both a color and a size');
				};
				if (sizeChosen == true && collarArray[x].colorVal == '0') 
				{	
					errcolor = window.open('err_choose_color.htm', 'errcolor', 'width=400, height=170');
	 				errcolor.moveTo(500, 400);

					//window.alert('choose a color');
				};
				if (sizeChosen == false && collarArray[x].colorVal != '0') 
				{
					errcolor = window.open('err_choose_size.htm', 'errcolor', 'width=200, height=170');
	 				errcolor.moveTo(500, 400);
					//window.alert('choose a size');
					
				};
				
			}
		}	
	} //else {window.alert('choose a color');	};
}

function setMailAFriend () {//create a string that can be used in the mailto field that determines color and size
}

function loadCheckURLforProductID () {//write method that will parse URL onload to see if there are choices being passed in from an email link (product IDs). 
// If so, load those images as the defaults for the page.
}

function NEW_JG_swapColorImage() { //v3.0
  var i,j=0,x,a=NEW_JG_swapColorImage.arguments; document.JG_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.JG_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
////////////////
////////////////
var colorChosen = false;
var sizeChosen = false;
var trackColorValue = "";
var trackSizeValue = "";
var errcolor; //popup window for error dialog
var matchingLeashLeft = ""; //globals for tracking matching leashes
var matchingLeashRight = "";
var leftLeashYes = false;
var rightLeashYes = false;

//Entry point for color and size clicks
function onClickWrapper(color, size) {
if (size !=null) {
	sizeChosen = true;
	noRestore(size); // call noRestore in the size script and send the size passed in
	trackSizeValue = size; //trap size chosen to build URL for cart
	};
	
if (color !="") {
	colorChosen = true;
	JG_SwapHeader(color); //call color flip and send the color value
	trackColorValue = color; //trap color chosen to build URL for cart
	//JG_swapImage('TL_order_12','','images/TL_order_06-TL_order_03_13.gif',1); //display add a matching leash
	}
}	