

dir_diamond_search_files = '/diamond_search_files/';


function diamondSearchHelpWindow(columnCode, store_name, w, h)
{
	if (w == '' || w == undefined) var w = 320;
	if (h == '' || h == undefined) var h = 200;
	var params = "scrollbars=1,resizable=1,status=0,location=0,width="+ w +",height="+ h ;

	if (document.all) {
		var top = (screen.height - h)/2;
		var left = (screen.width- w)/2;
		params += ",left="+ left +",top="+ top ;
	}

	diamondSearchHelpWin = window.open(
		'diamond_search_files/popups/help_page.php?store_name='+ store_name +'&category='+ columnCode,
		'diamond_search_help',
		params
	);

	diamondSearchHelpWin.focus();
}//diamondSearchHelpWindow()







//This array is used to remember mark status of rows in browse mode
var marked_row = new Array;

function bgOn(obj, color, id) {
	if (!marked_row[id]) {
		if (document.getElementById) {
			obj.style.backgroundColor = color
		}
	}
}

function bgKeeper(obj, id, color) {

	marked_row[id] = (typeof(marked_row[id]) == 'undefined' || !marked_row[id])
				? true
				: null;
				
	if (marked_row[id] == true) {
		obj.style.backgroundColor = color;
	} else {
		obj.style.backgroundColor = '#ffffff';
	}

}




function btnOn(btn, fgc, bgc) {	
	if (fgc==undefined || bgc==undefined) {
		fgc = btn.style.backgroundColor;
		bgc = btn.style.color;
	}

	if (document.getElementById) {
		btn.style.backgroundColor = bgc;
		btn.style.color = fgc;
	}
}


function btnOff(btn, fgc, bgc) {
	if (fgc==undefined || bgc==undefined) {
		fgc = btn.style.backgroundColor;
		bgc = btn.style.color;
	}

	if (document.getElementById) {
		btn.style.backgroundColor = bgc;
		btn.style.color = fgc;
	}
}




var certWin
function openCertWindow(id, path, store_name)
{
	if (certWin && !certWin.closed) {
		certWin.focus();
	}
	else {
		var w = 700;
		var h = 500;
		var params = "scrollbars=1,resizable=1,status=0,location=0,width="+ w +",height="+ h ;

	if (document.all) {
			var top = (screen.height - h)/2;
			var left = (screen.width- w)/2;
			params += ",left="+ left +",top="+ top ;
		}


		$file_info = dir_diamond_search_files+"popups/cert_window.php?id="+ id + "&cert_path="+ path
		if (store_name != '') $file_info += '&store_name='+store_name

		certWin = window.open(
			$file_info,
			"cert_window",
			params
		);
	}
}//openCertWindow()




function formHelpWindow() {
	formHelpWin = window.open(
		dir_diamond_search_files+'includes/help_pages/diamond_search_form_help.php',
		'formHelpWindow'
	);
}




function allBoxes(which) {
	for (i=0; i<document.search_form[which].length; i++) {
		document.search_form[which][i].checked = true
	}
}




function noBoxes(which) {
	for (i=0; i<document.search_form[which].length; i++) {
		document.search_form[which][i].checked = false;
	}
}


if (document.images) {
	arrow_red_up = new Image();
	arrow_red_up.src = dir_diamond_search_files+'images/arrow_red_up.gif';

	arrow_black_up = new Image();
	arrow_black_up.src = dir_diamond_search_files+'images/arrow_black_up.gif';

	arrow_red_down = new Image();
	arrow_red_down.src = dir_diamond_search_files+'images/arrow_red_down.gif';

	arrow_black_down = new Image();
	arrow_black_down.src = dir_diamond_search_files+'images/arrow_black_down.gif';
	
	
	interest_off			=		new Image();
	interest_off.src 		=		dir_diamond_search_files+'images/IAmInterestedInThisGem.gif';		
	interest_on				=		new Image();
	interest_on.src 		=		dir_diamond_search_files+'images/IAmInterestedInThisGem_on.gif';	
	
}

function searchArrowSwitch(imgName, color, dir) {
	if (document.images) {
		document[imgName].src = eval('arrow_'+ color +'_'+ dir +'.src');
	}
}





function checkboxCheckerUnchecker(id_group, group_number) {
	var cb; //checkbox object
	cb = document.search_form[id_group][group_number];
	
	if (cb.checked) { cb.checked = false }
	else cb.checked = true;
	
}




function imgOn(imgName) {
	if (document.getElementById) {
		document.getElementById(imgName).src = eval(imgName + '_on.src');
	}
}

function imgOff(imgName) {
	if (document.getElementById) {
		document.getElementById(imgName).src = eval(imgName + '_off.src');
	}
}





function DiamondDetailLayer(str) {
	if (document.getElementById) {
		document.getElementById(str).style.visibility = 'visible';
	}
}













function resetDiamondSearchForm() {

	document.search_form.carat_low.value	= 0.01;
	document.search_form.carat_high.value	= 15;
	if (document.search_form.measurement_1_1) clearMeasurements();
	if (document.search_form.depth_low) clearPercentages();

	for (i=0; i<document.search_form['cut'].length; i++) {
		document.search_form['cut'][i].checked = false
	}
	for (i=0; i<document.search_form['color'].length; i++) {
		document.search_form['color'][i].checked = false
	}
	for (i=0; i<document.search_form['clarity'].length; i++) {
		document.search_form['clarity'][i].checked = false
	}
	for (i=0; i<document.search_form['certs'].length; i++) {
		document.search_form['certs'][i].checked = false
	}
	
	if (document.search_form.on_hand_only) document.search_form.on_hand_only.checked = false;
}



function clearMeasurements() {
	document.search_form.measurement_1_1.value = '';
	document.search_form.measurement_1_2.value = '';
	document.search_form.measurement_2_1.value = '';
	document.search_form.measurement_2_2.value = '';
	document.search_form.measurement_3_1.value = '';
	document.search_form.measurement_3_2.value = '';
}

function clearPercentages() {
	document.search_form.depth_low.value = '';
	document.search_form.depth_high.value = '';
	document.search_form.tbl_low.value = '';
	document.search_form.tbl_high.value = '';
}







function subsetChecker(frm) {

	for (i=0; i< frm.ds_subset.length; i++) {
		if (frm.ds_subset[i].checked) return true;
	}
	
	alert('Choose at least one stone.');
	return false;

}





