/*
this file contains the functions necessary for building the connection object 
associated with the web server - KJP

Created May 25,2006
*/


function printSize(productid,category,size,price){
	//set the form size element to the selected size
	document.addCartItem.size.value = productid;
	document.getElementById('baseSize').innerHTML = size;
	document.getElementById('price').innerHTML = "$"+price;
	clearMattingColor();
	//clear image matting color, if any
	clearImageBackground();	
	
}

function noteCard(productid,category,size,price){
	//set the form size element to the selected size
	document.addCartItem.size.value = productid;
	document.getElementById('baseSize').innerHTML = size;
	document.getElementById('finalSize').innerHTML = "";
	document.getElementById('price').innerHTML = "$"+price;
}


function posterSize(productid,category,size,price){
	//set the form size element to the selected size
	document.addCartItem.size.value = productid;
	document.getElementById('baseSize').innerHTML = size;
	document.getElementById('finalSize').innerHTML = "";
	document.getElementById('price').innerHTML = "$"+price;
	//clear the print size radio buttons
	clearPrintSize();
	//clear all matting radio buttons
	clearMattingColor();	
	//clear the matting hidden form field
	document.addCartItem.matting.value = "";
	//clear the color hidden form field
	document.addCartItem.color.value = "";
	//clear image matting color, if any
	clearImageBackground();	
	
}

function cardPackage(productid,category,size,price){
	//set the form size element to the selected size
	document.addCartItem.size.value = productid;
	document.getElementById('baseSize').innerHTML = size;
	document.getElementById('finalSize').innerHTML = "";
	document.getElementById('price').innerHTML = "$"+price;
}

function bookSize(productid,category,size,price){
	//set the form size element to the selected size
	document.addCartItem.size.value = productid;
	document.getElementById('baseSize').innerHTML = size;
	document.getElementById('finalSize').innerHTML = "";
	document.getElementById('price').innerHTML = "$"+price;
}

function clearPrintSize(){
	//loop through the printSize radio button array to 'unselect' each one
	var printArray = document.addCartItem.elements['Print Size'];
	try {
		for (var te=0;te<printArray.length;te++){
			printArray[te].checked=false;	
		}
	} catch (e){}	
}

function clearMatting(){
	document.addCartItem.matting.value = "";
	document.addCartItem.color.value = "";
	//loop through the matting radio button array to 'unselect' each one
	var mattingArray = document.addCartItem.elements['Matting'];
	var mattingItem = "";
	try {
		for (var te=0;te<mattingArray.length;te++){
			mattingItem = mattingArray[te].value;
			mattingArray[te].checked=false;	
			//clear any selected colors
			clearMattingColor(mattingItem);
		}
	} catch (e){}	
}

function clearMattingColor(){
	//loop through the colorMatting radio button array to 'unselect' each one
	var itemName = 'colorMatting';
	var colorMattingArray = document.addCartItem.elements[itemName];
	try {
		for (var te=0;te<colorMattingArray.length;te++){
			colorMattingArray[te].checked=false;	
		}
	} catch (e){}	
}

function clearNoteCard(){
	//'unselect' the note card radio button
	var noteCardArray = document.addCartItem.elements['Note Card'];
	try {
		for (var te=0;te<noteCardArray.length;te++){
			noteCardArray[te].checked=false;	
		}
	} catch (e){}	

}

function clearGreetingCard(){
	//'unselect' the greeting card radio button
	var greetingCardArray = document.addCartItem.elements['Greeting Card'];
	try {
		for (var te=0;te<greetingCardArray.length;te++){
			greetingCardArray[te].checked=false;	
		}
	} catch (e){}	
}

function clearPosterSize(){
	//loop through the printSize radio button array to 'unselect' each one
	try {
		var printArray = document.addCartItem.elements['Poster Size'];
		for (var te=0;te<printArray.length;te++){
			printArray[te].checked=false;	
		}
	} catch (e){}	
}

function changeBackground(mattingid, colorid, hexColor,printSize, dimension, price){
	
	clearPrintSize();

  	var siz = document.getElementById(printSize).size;
  	document.addCartItem.size.value = siz;
  	//adjust the 'printSize'
  	document.getElementById('baseSize').innerHTML = printSize;
  	//adjust the 'finalSize'
  	document.getElementById('finalSize').innerHTML = "("+dimension+" final size)";
	
	//change the border color around the image
	var colorBorder = '#'+hexColor;
	var imageWindow = document.getElementById('mattingWindow');
	imageWindow.setAttribute("bgColor",colorBorder);
	imageWindow.bgColor = colorBorder;

	//set the matting property for the hidden form field
	document.addCartItem.matting.value = mattingid;
	//set the color property for the hidden form field
	document.addCartItem.color.value = colorid;
	//show the color warning
	document.getElementById('colorWarning').innerHTML = "Matting color is approximate.";


	//if the matting color is black or dark green then add white border with note
	if (hexColor=="000000"||hexColor=="003300"){
		var trimColor="#ffffff";
		var borderWindow = document.getElementById('borderWindow');
		borderWindow.setAttribute("bgColor",trimColor);
		borderWindow.bgColor = trimColor;

		//show the color warning
		document.getElementById('colorWarning').innerHTML = "Matting color is approximate.<br>The white line around the print is<br>to illustrate the white core of<br>the mats";
	
	} else {
		var trimColor="";
		var borderWindow = document.getElementById('borderWindow');
		borderWindow.setAttribute("bgColor",trimColor);
		borderWindow.bgColor = trimColor;
	
		//remove the color warning
		document.getElementById('colorWarning').innerHTML = "Matting color is approximate.";
	}

	//check to make sure the correct print size radio button is selected
	var printPrice = document.getElementById(printSize).value;
	document.getElementById(printSize).checked=true;
  	//adjust the 'price'; get the size from the print radio button
  	newPrice = parseFloat(printPrice) + parseFloat(price);

  	//show new price
  	document.getElementById('price').innerHTML = "$"+zeros(convert(newPrice));
	
	
  
}

function addMatt(mattID,printSize,matSize,price){
  	//update the matting hidden form field
  	document.addCartItem.matting.value = mattID;
  	//update the size hidden form field
  	var siz = document.getElementById(printSize).size;
  	document.addCartItem.size.value = siz;
  	//adjust the 'printSize'
  	document.getElementById('baseSize').innerHTML = printSize;
  	//adjust the 'finalSize'
  	document.getElementById('finalSize').innerHTML = "("+matSize+" final size)";

	//check to make sure the correct print size radio button is selected
	var printPrice = document.getElementById(printSize).value;
	document.getElementById(printSize).checked=true;

	//make sure the cards aren't selected
	clearNoteCard();
	clearGreetingCard();
	clearPosterSize();
	
  	//adjust the 'price'; get the size from the print radio button
  	newPrice = parseFloat(printPrice) + parseFloat(price);

  	//show new price
  	document.getElementById('price').innerHTML = "$"+zeros(convert(newPrice));

}

function clearImageBackground(){
	var imageWindow = document.getElementById('mattingWindow');
	imageWindow.setAttribute("bgColor","");
	imageWindow.bgColor = "";
	//clear the color warning
	document.getElementById('colorWarning').innerHTML = "";

	var borderWindow = document.getElementById('borderWindow');
	borderWindow.setAttribute("bgColor","");
	borderWindow.bgColor = "";
	
	//clear the color warning
	document.getElementById('colorWarning').innerHTML = "";



	//clear the color property for the hidden form field
	document.addCartItem.color.value = "";
}

function clearRadioButtons(){
	//clear the hidden form tags
	document.addCartItem.size.value = "";
	document.addCartItem.matting.value = "";
	document.addCartItem.color.value = "";
	//clear the size tags
	document.getElementById('baseSize').innerHTML = "";
	document.getElementById('finalSize').innerHTML = "";
	//clear the price tags
	document.getElementById('price').innerHTML = "$0.00";
	//clear the different form elements
	clearPrintSize();
	clearNoteCard();
	clearMattingColor();
	clearImageBackground();
}


function goBack(){
	history.back();
}
