//These functions are used in the product_detail.cfm page 

var getDefaultImage = 0;

function openzoom(popurl) 
{			
	var gohref='/popup.cfm?id='+document.getElementById("frame_id").value+'&frame_color_id='+document.getElementById("frame_color_id").value;			
	window.open(gohref,'imager','scrollbars=yes,resizable=1,width=565,height=600'); 		
	return false;
}

function getVariationData(frameID){			
	// This function must wait for the frame size to be reloaded in order to get the correct size.		  
	 setTimeout(function() {setFrameCFC(frameID);}, 50);		   
}

function setFrameCFC(frameID){   
	var color_id = parseInt(document.getElementById("frame_color_id").value);
	var size_id = parseInt(document.getElementById("frame_size_id").value);
	$.getJSON(   		
		window.location.protocol+'//'+window.location.hostname+'/extensions/components/frame.cfc?wsdl&frame_id='+frameID+'&frame_color_id='+color_id+'&frame_size_id='+size_id,   
		{ method : 'getFrameVariationsByOptions', returnformat : 'json', queryformat : 'column' },   
		/*  
			When the JSON data has returned, fire this callback function and pass in the JSON data  as it's argument.  
		*/  
		populateVariationData 
	);   
}   

function populateVariationData(result){   
	document.getElementById("frame_color_caption").innerHTML= result.DATA.color_name[0];
	document.getElementById("regularPrice").innerHTML= "$" + result.DATA.price[0].toFixed(2);
	document.getElementById("sku").innerHTML = result.DATA.fpc[0];
	
	if (result.DATA.file_name[0] == '') {
		document.getElementById("mainImage").src='/images/static/not_available_med.gif';
		} else {
		document.getElementById("mainImage").src='/images/catalog/live/imageLibrary/medium/' + result.DATA.file_name[0];
	}
	
	// update variation id hidden field
	document.getElementById("variation_id").value=result.DATA.id[0];					
	// update add lens to frame link
	document.getElementById("add_lens_frame").href='/lens_wizard.html?id='+document.getElementById("frame_id").value+'&variation_id='+result.DATA.id[0];
}  

