//Javascript for skin/customer/main/art_finder_mini.tpl



//*******************//
//  Tooltips Section //
//*******************//
// Simple follow the mouse script
var prevColor = "none";

var divName = 'info_box'; // div that is to follow the mouse
                       // (must be position:absolute)
var offX = -30;          // X offset from mouse position
var offY = 22;          // Y offset from mouse position

var Colors = new Array(11);
var ColorNames = new Array("blackwhite", "black",   "gray",    "white",   "red",     "orange",  "yellow",  "green",    "blue",    "purple",  "brown");
var ColorIds = new Array(  "BlackWhite", "Black",  "Gray",  "White",  "Red",  "Orange",  "Yellow",  "Green",  "Blue",  "Purple",  "Brown");

var Categories = new Array(9);
var CategoryNames = new Array("paintings", "photographs", "glassart", "metalart", "woodart", "ceramics", "fiberart", "jewelry", "prints");
var CategoryIds = new Array("258", "273", "595", "608", "619", "293", "448", "492", "521");

var showTips = false

var price_display = 0;
var ppi = 18;       // pixels per INTERVAL
var ipi = 3;        // inches per INTERVAL
var sizeType;



function getMouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
function getMouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}

function follow(evt) {
	if (document.getElementById) {
		var obj = document.getElementById(divName).style; obj.visibility = 'visible';
		var maxLeftPos = getPageSize()[0] - 20;
		var x = document.getElementById('info_box');
		if (x.offsetWidth)
			var maxLeftPos = maxLeftPos - (x.offsetWidth);

		if((parseInt(getMouseX(evt))+offX) > (maxLeftPos)){
			obj.left = (maxLeftPos) + 'px';
		}else{
			obj.left = (parseInt(getMouseX(evt))+offX) + 'px';
		}
		obj.top = (parseInt(getMouseY(evt))+offY) + 'px';
	}
}

function setCookieSearch(){
	/// If you are not currently using the art finder, use the saved search in a cookie to populate the art finder with the last search.
	if(!searching){

		var temp = getCookie()//.split('_');

		if(temp != null){

			var cookieInfo = temp.split('_');

			var type, value;
			for(var i = 0; i < cookieInfo.length; i++){
				type = cookieInfo[i].split('-')[0];
				value = cookieInfo[i].split('-')[1];

				switch(type){
					case "minheight":
						if (typeof min_height != "undefined") {
							min_height = value;
						}
						break;
					case "maxheight":
						if (typeof max_height != "undefined") {
							max_height = value;
						}
						break;
					case "minwidth":
						min_width = value;
						break;
					case "maxwidth":
						max_width = value;
						break;
					case "slider1":
						var sliderinput1 = getObject('slider-input-1');
						if (sliderinput1 != null && (typeof sl != "undefined")) {
							sliderinput1.value = value;
							sl.setValue(value,1);
						}
						break;
					case "slider2":
						var sliderinput2 = getObject('slider-input-2');
						if (sliderinput2 != null && (typeof sl != "undefined")) {
							sliderinput2.value = value;
							sl.setValue(value,2);
						}
						break;
					case "keywords":

						var searchText = getObject('searchText');
						var searchTextOnly = getObject('searchTextOnly');

						if (searchText != null) {
							temp = value;

							while(temp.indexOf('+') != -1)
								temp = temp.replace('+', ' ');

							searchText.value = unescape(temp);

							if (searchTextOnly != null) {
								document.getElementById("searchTextOnly").value = unescape(temp);
							}
						}
						break;
					case "colorwheel":

						var selected_color = getObject('selected_color');
						if (selected_color != null) {
							selected_color.style.backgroundColor = "#"+value;
						}
						var selected_color_mask = getObject('selected_color_mask');
						if (selected_color_mask != null) {
							selected_color_mask.style.marginTop = "0px";
						}
						var select = getObject('select');
						if (select != null) {
							select.style.backgroundImage = "";
							select.style.backgroundColor = "#"+value;
						}
						var color_select_value = getObject('color_select_value');
						if (color_select_value != null) {
							color_select_value.value = value;
						}
						var color_select_value_temp = getObject('color_select_value_temp');
						if (color_select_value_temp != null) {
							color_select_value_temp.value = value;
						}

						colorWheelOpen = true;

						break;
					case "colorimage":

						var selected_color_image = getObject('selected_color_image');
						if (selected_color_image != null) {
							selected_color_image.style.backgroundColor = "#"+value;
						}
						var selected_color_image_mask = getObject('selected_color_image_mask');
						if (selected_color_image_mask != null) {
							selected_color_image_mask.style.marginTop = "0px";
						}
						var color_image_value = getObject('color_image_value');
						if (color_image_value != null) {
							color_image_value.value = value;
						}
						var color_image_value_temp = getObject('color_image_value_temp');
						if (color_image_value_temp != null) {
							color_image_value_temp.value = value;
						}

						colorImageOpen = true;

						break;
					case "colors":
						temp = value.split('+');

						for(var k = 0; k < temp.length; k++){
							for(var j = 0; j < ColorIds.length; j++){
								if(ColorIds[j] == temp[k]) {
									selectColor(j);
								}
							}
						}

						break;
					case "categories":
						temp = value.split('+');

						var wrap_category_select = getObject("wrap_category_select");

						for(var k = 0; k < temp.length; k++){
							for(var j = 0; j < CategoryIds.length; j++){
								if(CategoryIds[j] == temp[k]){
									if (wrap_category_select != null) {
										wrap_category_select.value = j;
									}
								}
							}
						}

						break;
					case "style":
						var style_select_box = getObject("style_select_box");
						if (style_select_box != null) {
							style_select_box.value = value;
						}

						break;
					case "theme":
						var theme_select_box = getObject("theme_select_box");
						if (theme_select_box != null) {
							theme_select_box.value = value;
						}

						break;

				}
			}
		}

	}
}

function resetCookie() {
	document.cookie = "art_finder_search=;expires=;path=/";
}

function getCookie(){

	var cookieName = "art_finder_search=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++){

		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1,c.length);
		if(c.indexOf(cookieName) == 0) return c.substring(cookieName.length,c.length);
	}
	return null;
}

function fixSlider(){
	if (typeof sl !="undefined") {
		sl._select = 1;
		sl.recalculate();
		sl._select = 2;
		sl.recalculate();
	}

	document.getElementById("searchText").style.display="block";
}

function loadArtFinder(){

	setCookieSearch();

	fixSlider();

	setArtFinderMouse();

	deMoronize();

}

function setArtFinderMouse(){
	capExtent=document;
	var fN, mseHandler=follow;
	var re=/function[ ]+(\w+)\(/;
	if (document.onmousemove) {
		if (window.onmousemove)
			capExtent=window;
			fN=capExtent.onmousemove.toString().match(re);
		if (fN[1]=='anonymous') {
			return;
		}
		var str=fN[1]+'(e); '+'follow(e); ';
		mseHandler=new Function('e', str);
	}
	capExtent.onmousemove=mseHandler;
}

function resetArtFinder(){
	//reset keywords
	document.getElementById('searchText').value = "";

	//reset color
	resetColors();

	//reset categories
	document.getElementById('wrap_category_select').value = "none";

	//reset price slider
	resetPrice();

	//reset size
	resetSize();

	//reset more option
	document.getElementById('style_select_box').options[0].selected=true;
	document.getElementById('theme_select_box').options[0].selected=true;

	//reset cookie
	var date = new Date();
	date.setTime(date.getTime() - (3600000 * 24));
	document.cookie = "art_finder_search= ; expires=" + date.toGMTString() + "; path=/";
}

function resetColors () {
	//document.getElementById('selected_color').style.marginTop = "12px";
	document.getElementById('selected_color_mask').style.marginTop = "10px";

	document.getElementById('color_select_value').value = "";

	colorWheelOpen = false;

	//document.getElementById('selected_color_image').style.marginTop = "12px";
	document.getElementById('selected_color_image_mask').style.marginTop = "10px";

	document.getElementById('color_image_value').value = "";

	colorImageOpen = false;


	//reset color cards
	for(i=0;i<11;i++){
		if(Colors[i]==true){
			selectColor(i);
		}
	}
}

function resetSize() {

	min_height = 0;
	max_height = 0;
	min_width = 0;
	max_width = 0;

	document.getElementById('min_area').style.height = 0;
	document.getElementById('min_area').style.width = 0;
	document.getElementById('max_area').style.height = 0;
	document.getElementById('max_area').style.width = 0;

}

function showInfo(msg){
	showTips=true;

	document.getElementById("size_instr").style.display="none";
	document.getElementById('infoSizeContainer').style.display="none";

	document.getElementById("info_content").innerHTML=msg;
	document.getElementById("info_box").style.display="";
}


function hideInfo(){
	showTips=false;
	setTimeout("hideInfoTime()",100)
}

function hideInfoTime(){
	if(!showTips){
		document.getElementById('infoSizeContainer').style.display="none";
		document.getElementById("size_instr").style.display="none";

		document.getElementById("info_box").style.display="none";

		showSelectBoxes();
	}
}

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		if (selects[i].className != "lightBoxImmune") {
			selects[i].style.visibility = "hidden";
		}
	}
}


function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		if (selects[i].className != "lightBoxImmune") {
			selects[i].style.visibility = "visible";
		}
	}
}

//***********************************//
//  Color, Category, & Price Section //
//***********************************//

function selectColor(color){

	var colorObj = getObject(ColorNames[color]);
	//var colorBox = getObject(ColorNames[color]+"_box");

	if (colorObj != null) {
		if (Colors[color]){
			colorObj.style.marginTop = "10px"
			colorObj.style.zIndex -= 10;

			//colorBox.style.marginTop = "12px"
			//colorBox.style.zIndex -= 10;

			Colors[color]=false;
		}else{
			colorObj.style.marginTop = "0px"
			colorObj.style.zIndex -= (-10);

			//colorBox.style.marginTop = "2px";
			//colorBox.style.zIndex -= (-10);

			Colors[color]=true;
		}
	}

}

function findColor(name){
	for(i = 0; i < ColorIds.length; i++){
		if(name == ColorIds[i])
			selectColor(i);
	}
}

function selectCategoryDropDown(category){
	for(var i = 0; i < Categories.length; i++){
		if(i == category)
			Categories[i] = true;
		else
			Categories[i] = false;
	}
}

//***************//
//  Size Section //
//***************//

function startSizeDrag(event, type){
	sizeType = type;

	if (sizeType == 'min'){
		otherType = "max";
	}else{
		otherType = "min";
	}

	//-----------------------//
	// display initial sizes //
	//-----------------------//

	minObj = document.getElementById('min_area')
	maxObj = document.getElementById('max_area')

	if(sizeType == 'min'){
		minObj.style.border = "1px solid #666666";
		maxObj.style.border = "1px solid #aaaaaa";

		if(!(max_width <= 0 && max_height <= 0)){
			if(max_height == "No Limit"){
				maxObj.style.height = (12 * ppi - 1) + 'px';
				maxObj.style.borderBottom = "";
			}else{
				maxObj.style.height = (max_height * ppi - 2) + 'px';
			}

			if(max_width == "No Limit"){
				maxObj.style.width = (12 * ppi - 1) + 'px';
				maxObj.style.borderRight = "";
			}else{
				maxObj.style.width = (max_width * ppi - 2) + 'px';
			}

			minObj.style.margin = "0";
		}

	}else{
		minObj.style.border = "";
		maxObj.style.border = "1px solid #666666";

		if(min_width > 0 && min_height > 0){
			minObj.style.height = (min_height * ppi - 2) + 'px';
			minObj.style.width = (min_width * ppi - 2) + 'px';
			if (!dragBrowser.isIE)
				minObj.style.margin = "1px";
		}
	}

	//---------------//
	// locate cursor //
	//---------------//

	curPos = getCursorPos(event);

	dragObj = document.getElementById('dragPointer');
	//dragObj.style.display="";
	dragObj.style.top=(curPos.y-0+6)+"px";
	dragObj.style.left=(curPos.x-0+6)+"px";

	//-------------//
	// display box //
	//-------------//

	hideSelectBoxes();

	ancPos = getAnchorPosition(sizeType+'_anchor');

	sizeObj = document.getElementById('size_box');
	sizeObj.style.display="";
	sizeObj.style.top=(ancPos.y-30)+"px";
	sizeObj.style.left=(ancPos.x-54)+"px";

	//----------------------//
	// setup drag functions //
	//----------------------//

	if (dragBrowser.isIE) {
		document.attachEvent("onmousemove", updateSizeDrag);
		document.attachEvent("onmouseup",   endSizeDrag);
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if (dragBrowser.isNS) {
		document.addEventListener("mousemove", updateSizeDrag,   true);
		document.addEventListener("mouseup",   endSizeDrag, true);
		event.preventDefault();
	}

	//document.getElementById('max_anchor').onmouseover = function(){showSize('Max')};
	//document.getElementById('min_anchor').onmouseover = function(){showSize('Min')};

	updateSizeDrag();
}

function updateSizeDrag(){

	boxObj = document.getElementById(sizeType+'_area');
	otherObj = document.getElementById(otherType+'_area');

	otherWidth = -1;
	otherHeight = -1;

	//get locations of boxes

	dragX = dragObj.style.left.split('px')[0];
	dragY = dragObj.style.top.split('px')[0];

	sizeX = sizeObj.style.left.split('px')[0];
	sizeY = sizeObj.style.top.split('px')[0];

	//---------------//
	// find new size //
	//---------------//

	//find initial new size
	boxWidth = dragX - sizeX - 10;
	boxHeight = dragY - sizeY - 10;

	//adhere to set intervals
	boxWidth = boxWidth - (boxWidth % ppi);
	boxHeight = boxHeight - (boxHeight % ppi);

	//check boundaries
	if ((sizeType == 'min') && (boxWidth < 3 * (ppi / ipi)) && (boxHeight < 3 * (ppi / ipi))){
		boxWidth = 0;
		boxHeight = 0;
	}else{

		//adjust for width boundaries
		if (boxWidth < 6 * (ppi / ipi)){
			boxWidth = 6 * (ppi / ipi);
		}else if (boxWidth > 36 * (ppi / ipi)){
			if (sizeType == 'max'){
				boxWidth = 9999;
			}else{
				boxWidth = 36 * (ppi / ipi);
			}
		}

		//adjust for height boundaries
		if (boxHeight < 6 * (ppi / ipi)){
			boxHeight = 6 * (ppi / ipi);
		}else if (boxHeight > 36 * (ppi / ipi)){
			if (sizeType == 'max'){
				boxHeight = 9999;
			}else{
				boxHeight = 36 * (ppi / ipi);
			}
		}
	}

	//adjust other object's width based on this object's location
	if ((sizeType == 'max') && (boxWidth < (min_width-0 + 2) * ppi)){

		//move min inward
		otherWidth = boxWidth - (2 * ppi);

		if(otherWidth < 2 * ppi){
			otherWidth = 0;
			otherHeight = 0;
		}
	}else if ((sizeType == 'min') && (max_width != 0) && (boxWidth > (max_width - 2) * ppi)){

		//move max outward
		otherWidth = boxWidth + (2 * ppi);

		if(otherWidth > 36 * (ppi / ipi))
			otherWidth = 9999;
	}

	//adjust other object's height based on this object's location
	if ((sizeType == 'max') && (boxHeight < (min_height-0 + 2) * ppi)){

		//move min inward
		otherHeight = boxHeight - (2 * ppi);

		if(otherHeight < 2 * ppi){
			otherHeight = 0;
			otherWidth = 0;
		}
	}else if ((sizeType == 'min') && (max_height != 0) && (boxHeight > (max_height - 2) * ppi)){

		//move max outward
		otherHeight = boxHeight + (2 * ppi);

		if(otherHeight > 36 * (ppi / ipi))
			otherHeight = 9999;
	}

	// adjust for 'No Limit'
	if (boxHeight == 9999){
		boxHeight = 36 * (ppi / ipi) + 1;
		boxObj.style.borderBottom = "";
	}else{
		boxObj.style.borderBottom = "1px solid #666666";
	}

	if (boxWidth == 9999){
		boxWidth = 36 * (ppi / ipi) + 1;
		boxObj.style.borderRight = "";
	}else{
		boxObj.style.borderRight = "1px solid #666666";
	}

	//display box
	if (boxHeight > 1 && boxWidth > 1){
		boxObj.style.height = (boxHeight-2)+'px';
		boxObj.style.width = (boxWidth-2)+'px';
		boxObj.style.display = "";
	}else{
		boxObj.style.display = "none";
	}

	//----------------//
	// draw other box //
	//----------------//

	if(sizeType == "min"){
		if(!(max_width <= 0 && max_height <= 0)){
			if(max_height == "No Limit"){
				otherObj.style.height = (12 * ppi - 1) + 'px';
				otherObj.style.borderBottom = "";
			}else{
				otherObj.style.height = (max_height * ppi - 2) + 'px';
				otherObj.style.borderBottom = "1px solid #666666";
			}

			if(max_width == "No Limit"){
				otherObj.style.width = (12 * ppi - 1) + 'px';
				otherObj.style.borderRight = "";
			}else{
				otherObj.style.width = (max_width * ppi - 2) + 'px';
				otherObj.style.borderRight = "1px solid #666666";
			}
		}
	}else{
		if(min_width > 0 && min_height > 0){
			otherObj.style.height = (min_height * ppi - 2) + 'px';
			otherObj.style.width = (min_width * ppi - 2) + 'px';
			minObj.style.margin = "1px";

			minObj.style.display = "";
		}
	}

	//repeat for changes to other object
	if(otherWidth != -1){
		if (otherWidth == 9999){
			otherWidth = 36 * (ppi / ipi) + 1;
			otherObj.style.borderRight = "";
		}

		if (otherWidth > 1){
			otherObj.style.width = (otherWidth-2)+'px';
			otherObj.style.display = "";
		}
	}

	if(otherHeight != -1){
		if (otherHeight == 9999){
			otherHeight = 36 * (ppi / ipi) + 1;
			otherObj.style.borderBottom = "";
		}

		if (otherHeight > 1){
			otherObj.style.height = (otherHeight-2)+'px';
			otherObj.style.display = "";
		}
	}

	if(otherHeight == 0 || otherWidth == 0)
		otherObj.style.display = "none";

	//-----------------------//
	// display size info box //
	//-----------------------//

	var otherSize = "";

	//first see if we need to display dimensions for the other box
	if (otherHeight != -1 || otherWidth != -1){

		otherSize += "<br>"+otherType+": ";

		//find height string
		if(otherHeight != -1){
			tempHeight = otherHeight;
		}else if(otherType == "min"){
			tempHeight = min_height * ppi;
		}else{
			tempHeight = max_height * ppi;
		}

		if (tempHeight <= 36 * (ppi / ipi)){
			otherHeightFt = parseInt(parseInt(tempHeight * ipi / ppi) / 12);
			otherHeightIn = parseInt(tempHeight * ipi / ppi) % 12;
			otherSize += otherHeightFt + '\' ' + otherHeightIn +'"';
		}else{
			otherSize += "No Limit ";
		}

		otherSize +="H x ";

		//find width string
		if(otherWidth != -1){
			tempWidth = otherWidth;
		}else if(otherType == "min"){
			tempWidth = min_width * ppi;
		}else{
			tempWidth = max_width * ppi;
		}

		if (tempWidth <= 36 * (ppi / ipi)){
			otherWidthFt = parseInt(parseInt(tempWidth * ipi / ppi) / 12);
			otherWidthIn = parseInt(tempWidth * ipi / ppi) % 12;
			otherSize += otherWidthFt + '\' ' + otherWidthIn +'"';
		}else{
			otherSize += "No Limit ";
		}

		otherSize +="W";

	}

	//then calculate dimensions for this box
	if (boxHeight <= 36 * (ppi / ipi)){
		heightFt = parseInt(parseInt(boxHeight * ipi / ppi) / 12);
		heightIn = parseInt(boxHeight * ipi / ppi) % 12;
		var heightInfo = heightFt + '\' ' + heightIn +'"';
	}else{
		var heightInfo = "No Limit ";
	}

	if (boxWidth <= 36 * (ppi / ipi)){
		widthFt = parseInt(parseInt(boxWidth * ipi / ppi) / 12);
		widthIn = parseInt(boxWidth * ipi / ppi) % 12;
		var widthInfo = widthFt + '\' ' + widthIn +'"';
	}else{
		var widthInfo = "No Limit ";
	}

	showInfo(sizeType+": "+heightInfo+'H x '+widthInfo+'W'+otherSize);
}

function endSizeDrag(){

	//---------------//
	// end functions //
	//---------------//

	if (dragBrowser.isIE) {
		document.detachEvent("onmousemove", updateSizeDrag);
		document.detachEvent("onmouseup",   endSizeDrag);
	}
	if (dragBrowser.isNS) {
		document.removeEventListener("mousemove", updateSizeDrag,   true);
		document.removeEventListener("mouseup",   endSizeDrag, true);
	}

	showSelectBoxes();

	sizeObj.style.display="none";

	//----------------//
	// store new size //
	//----------------//

	if(sizeType == 'max'){
		if(boxHeight > 36 * (ppi / ipi))
			max_height = "No Limit";
		else
			max_height = parseInt(boxHeight / ppi);

		if(boxWidth > 36 * (ppi / ipi))
			max_width = "No Limit";
		else
			max_width = parseInt(boxWidth / ppi);

	}else{
		min_height = parseInt(boxHeight / ppi);
		min_width = parseInt(boxWidth / ppi);
	}

	if(otherHeight != -1){
		if(otherType == 'max'){
			if(otherHeight > 36 * (ppi / ipi))
				max_height = "No Limit";
			else
				max_height = parseInt(otherHeight / ppi);
		}else{
			min_height = parseInt(otherHeight / ppi);
		}
	}

	if(otherWidth != -1){
		if(otherType == 'max'){
			if(otherWidth > 36 * (ppi / ipi))
				max_width = "No Limit";
			else
				max_width = parseInt(otherWidth / ppi);
		}else{
			min_width = parseInt(otherWidth / ppi);
		}
	}

	hideInfo();

	//--------------------//
	// setup size display //
	//--------------------//

	//document.getElementById('max_anchor').onmouseover = function(){showSize('Max')};
	//document.getElementById('min_anchor').onmouseover = function(){showSize('Min')};
}

function showSize(msg){
	var sizeInfo = "";

	//use because originals may contain text
	var temp_max_width = max_width;
	var temp_max_height = max_height;

	document.getElementById("size_instr").innerHTML = "Drag to Set "+msg+" Size<br><br>";

	infoCont = document.getElementById('infoSizeContainer');
	maxSizeInfo = document.getElementById('infoSizeMax');
	minSizeInfo = document.getElementById('infoSizeMin');

	if(temp_max_width == "No Limit"){
		temp_max_width = 12;
	}

	if(temp_max_height == "No Limit"){
		temp_max_height = 12;
	}

	//set size of Max box & center box
	if(temp_max_width == 0 || temp_max_height == 0){
		maxSizeInfo.style.width = (min_width * 4 - 2) + "px";
		maxSizeInfo.style.height = (min_height * 4 - 2) + "px";

		infoCont.style.width = (min_width * 4 - 2) + "px";
		infoCont.style.height = (min_height * 4 - 2) + "px";

		minSizeInfo.style.left = 0;
		minSizeInfo.style.top = 0;
	}else{
		maxSizeInfo.style.width = (temp_max_width * 4) + "px";
		maxSizeInfo.style.height = (temp_max_height * 4) + "px";

		infoCont.style.width = (temp_max_width * 4) + "px";
		infoCont.style.height = (temp_max_height * 4) + "px";

		minSizeInfo.style.left = ((temp_max_width - min_width) * 2 + 1) + "px";
		minSizeInfo.style.top = ((temp_max_height - min_height) * 2 + 1) + "px";

		//find max dimensions
		if (max_height != "No Limit"){
			maxHeightFt = parseInt(parseInt(max_height * ipi) / 12);
			maxHeightIn = parseInt(max_height * ipi) % 12;
			var heightInfo = maxHeightFt + '\' ' + maxHeightIn +'"';

			maxSizeInfo.style.borderTop="1px solid #777777";
			maxSizeInfo.style.borderBottom="1px solid #777777";
		}else{
			var heightInfo = "No Limit ";

			maxSizeInfo.style.borderTop="1px solid #FFFFFF";
			maxSizeInfo.style.borderBottom="1px solid #FFFFFF";
		}

		if (max_width != "No Limit"){
			maxWidthFt = parseInt(parseInt(max_width * ipi) / 12);
			maxWidthIn = parseInt(max_width * ipi) % 12;
			var widthInfo = maxWidthFt + '\' ' + maxWidthIn +'"';

			maxSizeInfo.style.borderLeft="1px solid #777777";
			maxSizeInfo.style.borderRight="1px solid #777777";
		}else{
			var widthInfo = "No Limit ";

			maxSizeInfo.style.borderLeft="1px solid #FFFFFF";
			maxSizeInfo.style.borderRight="1px solid #FFFFFF";
		}

		sizeInfo += "<br>Max: "+heightInfo+'H x '+widthInfo+'W';
	}

	//set size of Min box & display min dimensions
	if(min_width != 0 && min_height != 0){
		minSizeInfo.style.width = (min_width * 4 - 2) + "px";
		minSizeInfo.style.height = (min_height * 4 - 2) + "px";

		minHeightFt = parseInt(parseInt(min_height * ipi) / 12);
		minWidthFt = parseInt(parseInt(min_width * ipi) / 12);

		minHeightIn = parseInt(min_height * ipi) % 12;
		minWidthIn = parseInt(min_width * ipi) % 12;

		sizeInfo += "<br>Min: "+minHeightFt+'\' '+minHeightIn+'"H x '+minWidthFt+'\' '+minWidthIn+'"W';
	}

	//display everything
	showInfo(sizeInfo);

	if (min_height != 0 && min_width != 0){
		minSizeInfo.style.display = "";
	}else{
		minSizeInfo.style.display = "none";
	}

	maxSizeInfo.style.display = "";
	infoCont.style.display = "";

	document.getElementById("size_instr").style.display = "";
}

//***************//
// Submit Search //
//***************//

function submitSearch(){

	var parameters = new Array();
	var url = "/customer/art_finder.php"

	var searchText = getObject('searchText');
	var searchTextOnly = getObject('searchTextOnly');
	if (searchText != null && searchTextOnly != null) {
		if (searchTextOnly.value != 'Keywords Search') {
			searchText.value = searchTextOnly.value;
		}
		if(searchText.value != '' && searchText.value != 'Search the Store' && searchText.value != 'Keywords Search'){
			parameters[parameters.length] = "keywords="+escape(searchText.value);
		}
	}


	var wrap_category_select = getObject('wrap_category_select');
	if (wrap_category_select != null) {
		// Update the Categories array with the current value in the hidden field
		selectCategoryDropDown(wrap_category_select.value);
	}

	for(i=0;i<Categories.length;i++){
		if(Categories[i]) {
			parameters[parameters.length] = "categories[]="+CategoryIds[i];
		}
	}

	for(i=0;i<Colors.length;i++){
		if(Colors[i])
			parameters[parameters.length] = "colors[]="+ColorIds[i];
	}

	var color_select_value = getObject('color_select_value');
	if(color_select_value != null && color_select_value.value != "") {
		parameters[parameters.length] = "color-wheel="+color_select_value.value;
	}

	var color_image_value = getObject('color_image_value');
	if(color_image_value != null && color_image_value.value != "") {
		parameters[parameters.length] = "color-image="+color_image_value.value;
	}

	var sliderinput1 = getObject('slider-input-1');
	var sliderinput2 = getObject('slider-input-2');
	if (sliderinput1 != null && sliderinput2 != null) {

		var price1 = sliderinput1.value;
		var price2 = sliderinput2.value;

		if ((price1 > 0  && price1 < 102) || (price2 > 0 && price2 < 102)) {

			if (price1 > price2){
				var maxPrice = price1;
				var minPrice = price2;
			}else{
				var maxPrice = price2;
				var minPrice = price1;
			}

			var newVal;
			var newValPartA;
			var newValPartB;
			var roundedTo;

			if(minPrice==102){
				parameters[parameters.length] = "priceOp1=No Limit";
			}else{
				if(minPrice < 25){
					newVal = 4 * minPrice;
					roundedTo = 20;
				}else if(minPrice < 50){
					newVal = 6 * minPrice - 50;
					roundedTo = 25;
				}else if(minPrice < 75){
					newVal = 10 * minPrice - 250;
					roundedTo = 50;
				}else{
					newVal = 20 * minPrice - 1000;
					roundedTo = 100;
				}

				newValPartA =parseInt(newVal/roundedTo);
				newValPartB =newVal%roundedTo;
				if(newValPartB>=(roundedTo/2)){
					newValPartA++;
				}

				parameters[parameters.length] = "priceOp1="+newValPartA*roundedTo;
			}

			if(maxPrice==102){
				parameters[parameters.length] = "priceOp2=No Limit";
			}else{
				if(maxPrice < 25){
					newVal = 4 * maxPrice;
					roundedTo = 20;
				}else if(maxPrice < 50){
					newVal = 6 * maxPrice - 50;
					roundedTo = 25;
				}else if(maxPrice < 75){
					newVal = 10 * maxPrice - 250;
					roundedTo = 50;
				}else{
					newVal = 20 * maxPrice - 1000;
					roundedTo = 100;
				}

				newValPartA =parseInt(newVal/roundedTo);
				newValPartB =newVal%roundedTo;
				if(newValPartB>=(roundedTo/2)){
					newValPartA++;
				}

				parameters[parameters.length] = "priceOp2="+newValPartA*roundedTo;
			}

			//append the price slider positions
			parameters[parameters.length] = "slider-input-1="+sliderinput1.value;
			parameters[parameters.length] = "slider-input-2="+sliderinput2.value;
		}

	}


	if ((typeof min_height != "undefined") && (typeof max_height != "undefined") && (typeof min_width != "undefined") && (typeof max_width != "undefined")) {

		if (min_height > 0 || max_height > 0 || min_width > 0 || max_width > 0) {
			var temp = "heightOp1=";
			if(min_height * ipi >= 12) {
				temp += (Math.floor((min_height * ipi) / 12) +" ft ");
			}
			parameters[parameters.length] = temp += (((min_height * ipi) % 12)+" in");

			if (max_height == "No Limit" || max_height == 0) {
				parameters[parameters.length] = "heightOp2=No Limit";
			}else{
				var temp = "&heightOp2=";
				if(max_height * ipi >= 12) {
					temp += (Math.floor((max_height * ipi) / 12) +" ft ");
				}
				parameters[parameters.length] = temp += (((max_height * ipi) % 12)+" in");
			}

			//append the Size dimensions
			parameters[parameters.length] = "min-height="+min_height;
			parameters[parameters.length] = "max-height="+max_height;

			var temp = "widthOp1=";
			if(min_width * ipi >= 12) {
				temp += (Math.floor((min_width * ipi) / 12) +" ft ");
			}
			parameters[parameters.length] = temp += (((min_width * ipi) % 12)+" in");

			if (max_width == "No Limit" || max_width == 0){
				parameters[parameters.length] = "widthOp2=No Limit";
			}else{
				var temp = "widthOp2=";
				if (max_width * ipi >= 12) {
					temp += (Math.floor((max_width * ipi) / 12) +" ft ");
				}
				parameters[parameters.length] = temp += (((max_width * ipi) % 12)+" in");
			}

			//append the Size dimensions
			parameters[parameters.length] = "min-width="+min_width;
			parameters[parameters.length] = "max-width="+max_width;
		}

	}

	//parameters[parameters.length] = "&depthOp1=0 in&depthOp2=No Limit"

	//append the style selection
	var style_select_box = getObject('style_select_box');
	if (style_select_box != null && style_select_box.value) {
		parameters[parameters.length] = "style="+style_select_box.value;
	}

	//append the theme selection
	var theme_select_box = getObject('theme_select_box');
	if (theme_select_box != null && theme_select_box.value) {
		parameters[parameters.length] = "theme="+theme_select_box.value;
	}

	if (parameters.length > 0) {
		for(i=0;i<parameters.length;i++) {
			if (i == 0)	{
				url += "?";
			}else{
				url += "&";
			}
			url += parameters[i];
		}
	}
	window.location = url;
}


//returns size of the page

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function resetPrice() {
	document.getElementById("slider-input-1").value = 0;
	document.getElementById("slider-input-2").value = 102;

	sl.setValue(0,1);
	sl.setValue(102,2);

	used = false;

	fixSlider();
}

Event.observe(window, 'load', loadArtFinder, false);