/* $Id: extended_lopts.js,v 1.0 2010/07/15 14:43:00 magic Exp $ */

function switch_standard_ext(flag) {
	objEXT = document.getElementById('extended_opts_box');
	objSTD = document.getElementById('standard_opts_box');

	if (!flag || !objEXT || !objSTD) { return false; }

	if (flag == "S") {
//		objEXT.style.display = 'none';
		jQuery("#standard_opts_box").slideDown("slow");
		jQuery("#extended_opts_box").slideUp("slow");

	} else {
//		objSTD.style.display = 'none';
		jQuery("#extended_opts_box").slideDown("slow");
		jQuery("#standard_opts_box").slideUp("slow");
	}

	return true;
}

function check_class_opts(cid, oid) {

	if (!cid || !oid || !extended_modifiers) { return false; }

	for (var x in extended_modifiers[cid]) {
		if (x != oid) {
			box_obj = document.getElementById('po'+cid+'_'+x);

			if (box_obj) {
				box_obj.checked = false;
			}
		}
	}

	return true;
}

function switch_standard_ext_cart(flag, id) {
	objEXT = document.getElementById('extended_opts_box_'+id);
	objSTD = document.getElementById('standard_opts_box_'+id);
	objSTD_EOB = document.getElementById('edit_standart_opts_box_'+id);

	if (!flag || !id || !objEXT || !objSTD) { return false; }

	if (flag == "S") {
		objEXT.style.display = 'none';
		objSTD.style.display = '';
		if (objSTD_EOB) {
			objSTD_EOB.style.display = '';
		}

	} else {
		objSTD.style.display = 'none';
		if (objSTD_EOB) {
			objSTD_EOB.style.display = 'none';
		}
		objEXT.style.display = '';
	}

	makeRequest(id, 'Y');

	return true;
}

function check_class_opts_cart(cid, oid, id) {

	if (!cid || !oid || !extended_modifiers || !id) { return false;	}

	check_box_obj = document.getElementById('po'+cid+'_'+oid+'_'+id);
	amount_obj = document.getElementById('ext_opts_amount_'+cid+'_'+oid+'_'+id);
	prc_obj = document.getElementById('ext_opts_prc_'+cid+'_'+oid+'_'+id);

	if (check_box_obj.checked == true) {
		if (amount_obj) {
			amount_obj.style.display = '';
		}
		if (prc_obj) {
			prc_obj.style.display = '';
		}

	} else {
		if (amount_obj) {
			amount_obj.style.display = 'none';
		}
		if (prc_obj) {
			prc_obj.style.display = 'none';
		}
	}

	for (var x in extended_modifiers[id][cid]) {
		if (x != oid) {
			check_box_obj = document.getElementById('po'+cid+'_'+x+'_'+id);
			amount_obj = document.getElementById('ext_opts_amount_'+cid+'_'+x+'_'+id);
			prc_obj = document.getElementById('ext_opts_prc_'+cid+'_'+x+'_'+id);

			if (check_box_obj) {
				check_box_obj.checked = false;
			}
			if (amount_obj) {
				amount_obj.style.display = 'none';
			}
			if (prc_obj) {
				prc_obj.style.display = 'none';
			}
		}
	}

	makeRequest(id, 'N');

	return true;
}

function makeRequest(id, clear_ext_opts) {
	output = document.getElementById('totals_section_box');

	if (!output || !id || !clear_ext_opts) { return false; }

	output.innerHTML = '<div align="right"><img src='+loader_src+' /></div>';

	var opts = '';

	if (clear_ext_opts != 'Y') {
		for (var j in extended_modifiers[id]) {
			for (var x in extended_modifiers[id][j]) {
				check_box_obj = document.getElementById('po'+j+'_'+x+'_'+id);

				if (check_box_obj && check_box_obj.checked) {
					opts += j+'_'+x+'|';
				}
			}
		}
	}


	jQuery.post('ajax_update_extemded_opts.php', {'cartid': id, 'options': opts}, function(data) { output.innerHTML = data; });

	return true;
}

function correct_display_style(id) {
	objDST = document.getElementById(id);

	if (!id || !objDST) {
		return false;
	}

	objDST.style.display = '';
	return true;
}


