/****************************************************
This is the function called to open the s7 customizer 
data = arguments Object
{
f: form index most often same as p
p: product index
c: s7Code
w: movie width
h: movie height
}
****************************************************/
function opencustomizer(data){
	var prod = data.p || 1; // product index default to one
	var frm = data.f || prod;
	var theWidth = data.w || 500;   // optional argument
	var theHeight = data.h || 500; // optional argument
/* LG 04/16/10 - make data.c optional, first try dnd, then s7, then just submit form
	var s7code = data.c; */
	var theselect = eval('document.frmBuy_' + frm + '.buy_' + prod);
	var theQTY = eval('document.frmBuy_' + frm + '.QTY_' + prod);
	var thebuy = '';
	var theQTYvalue = 1; // we're gonna use 1 as the default
	var dnd = ''; // 04/08/10 - LG
	
	// 10/30/09 - LG - so we can track PGP
	if(eval('document.frmBuy_' + frm + '.prodref_' + prod))
		var prodRef=eval('document.frmBuy_' + frm + '.prodref_' + prod).value;
	else
		var prodRef='';
	
	// If we found the element then find the value
	if(theselect){
		if(theselect.type == 'select-one'){
			thebuy = theselect.options[theselect.selectedIndex].value;
		}
		else if(theselect.type == 'hidden'){
			thebuy = theselect.value;
		}
		else if(theselect[1].type == 'radio'){
			for (i=0; i<theselect.length; i++){
						if (theselect[i].checked == true){thebuy = theselect[i].value;}
			}
		}
	}
	// If we found the QTY element then lets use its value
	if(theQTY){
		theQTYvalue = parseInt(theQTY.value);
	}
	
	if(thebuy != ''){
// LG 04/08/10 - begin add
		var buyArr = thebuy.split(":");
		var frmObj = eval('document.frmBuy_' + frm);
		var dndField = frmObj['dnd_' + prod + '_' + buyArr[1]]

		if(typeof dndField != "undefined")
			dnd = dndField.value;
	
		if(dnd.length > 0){
			var URL = '/dragndrop.cfm?config=' + dnd+ '&buy=' + thebuy + '&qty=' + theQTYvalue;
			var w = 700;
			var h = 750;
		}
		else if(data.c){
			var s7code = data.c;
			// LG 04/08/10 - end add
			var URL = '/customizer.cfm?s7code=' + s7code + '&buy=' + thebuy + '&qty=' + theQTYvalue + '&w=' + theWidth + '&h=' + theHeight;
			var w = 1000;
			var h = 620;
		}
// LG 04/16/10 - begin add
		else{
			frmObj['btnSubmit' + frm].click();
			return; // exit
		}

		// 10/30/09 - LG - so we can track PGP
		if(prodRef.length > 0)
			URL = URL +'&prodref='+prodRef;
		ST_popUp(URL,'customizer',w,h,'no'); //LG 04/08/10 - changed to 'no'
	}else {
		alert('Please select your item first');
	}
}
