var myTopUrl = top.location.href;
var myThisPage = VI_docName(document.location.href);
var myThisCat = VI_catOf(myThisPage);
var myThisCode = VI_numOf(myThisPage);
var myTopPage = VI_docName(myTopUrl);
var myFrameset = VI_docName(parent.location.href);
var undefined;
var selectedFinish = undefined;
if( myTopPage != "catalog" || myFrameset != "cat_set2" ) {
	top.location.href = "../nav/catalog.htm?cat=" + myThisCat + "&code=" + myThisCode;
} else {
	if( top.myCat != undefined && top.myCat+"_"+top.myCode != myThisPage ) {
		myThisPage = top.myCat+"_"+top.myCode;
		top.myCat = undefined;
		top.myCode = undefined;
		document.location.replace(myThisPage + ".htm");
	} else {
		// make sure the right frame is showing the correct active state
		top.myCat = undefined;
		top.myCode = undefined;
		if( top.rightFrameLoaded && myThisPage != "specials" ) {
			parent.rightFrame.VI_initProduct();
		}
	}
}

function detail_window() {
	var name = document.form1.prodName.value;
	var prodNum = VI_numOf(VI_docName(document.URL));
	var cat = VI_catOf(VI_docName(document.URL));
	VI_Popup("../nav/detail.htm?"+cat+"="+prodNum+"&name="+escape(name), 577, 406);
}

function writeStyleSwitches() {
	myCode = VI_numOf(VI_docName(window.location.href));
	for( var num=0; num<stoneData.length; num++ ) {
		if( stoneData[num].code == myCode ) break;
	}
	myName = stoneData[num].name;
	stoneNum = num;
	
	document.write("<style>");
	if( stoneData[num].quote == "" ) document.write(".quoteButton {display:none}");
	if( stoneData[num].sample == "" ) document.write(".sampleButton {display:none}");
	if( stoneData[num].finish == "" ) document.write("#finishButton {display:none}");
	document.write("</style>");
}
function fullSpecs() {
	VI_Popup('../stonespecs/'+myCode+'.htm?code='+myCode+'&name='+escape(myName), 700, 550);
}

function finish_window() {
	VI_Popup("../nav/finishes.htm", 700, 520, "dependent");
}

function setFinish(num) {
	var finishDiv = getElement("finishButton");
	finishDiv.innerHTML = '<p><a href="javascript:finish_window()"><img src="../images/stone/finishes/thumbs/'+finishData[num].code+'.jpg" width="70" height="56" border="0" align="left">Selected finish:<br><b>'+finishData[num].name+'</b><br>Click to change</a></p>';
	selectedFinish = num;
}

function spec_window() {
	myCat = VI_catOf(VI_docName(document.URL));
	myCode = VI_numOf(VI_docName(document.URL));
	myPage = "../specs/" + myCat + ".htm?code=" + myCode + "&cat=" + myCat + "&name=" + escape(document.form1.prodName.value);
	if( myCat == "stone" && stoneData[stoneNum].finish != "" ) {
		if( selectedFinish == undefined ) {
			alert("Please select a finish for your specification.");
			return;
		} else {
			myPage += "&finish="+escape(finishData[selectedFinish].name);
		}
	}
	VI_Popup(myPage, 705, 550);
}

function quote_window(mode) {
	myCat = VI_catOf(VI_docName(document.URL));
	myCode = VI_numOf(VI_docName(document.URL));
	mode = (mode == undefined) ? "quote" : mode;
	myPage = "../specs/quote.htm?code=" + myCode + "&cat=" + myCat + "&mode=" + mode + "&name=" + escape(document.form1.prodName.value);
	if( myCat == "stone" && stoneData[stoneNum].finish != "" ) {
		if( selectedFinish == undefined ) {
			if( mode == "sample" ) {
				alert("Please select a finish for your sample.");
				return;
			}
		} else {
			myPage += "&finish="+escape(finishData[selectedFinish].name);
		}
	}
	VI_Popup(myPage, 700, 550);
}

function sample_window() {
	quote_window("sample");
}

function call_window() {
	quote_window("call");
}

function specials_link() {
	myProd = VI_docName(document.URL);
	myDesc = document.form1.prodName.value;
	location.href = 'specials.htm?prod=' + myProd + '&name='  + escape(myDesc.replace("/","&slash;"));
}
