/*
 * Support for the compare window
 */
ProductCompare = {
	openPopup: function( url,cid ) {
		var inputFieldID = "compareProducts" + cid;
		var strProducts = document.getElementById(inputFieldID).value;
		var productsLast = strProducts.length - 1;
		
		strProducts = strProducts.substring(0,productsLast);
		
		url = url + strProducts;
		window.open(
			url,
			'product_compare',
			'width=800,height=600,scrollbars=yes,resizable=yes',
			true /* replace history in the popped up window */
		).focus();
	},
	compare: function(pid,cid,check) {
		if(check == true){
			ProductCompare.addPID(pid,cid);
		}
		else{
			ProductCompare.removePID(pid,cid);
		}
	},
	addPID: function(pid,cid) {
		var inputFieldID = "compareProducts" + cid;
		var productsToCompare = document.getElementById(inputFieldID).value;
		document.getElementById(inputFieldID).value = productsToCompare + pid + '|';
	},
	removePID: function(pid,cid) {
		var inputFieldID = "compareProducts" + cid;
		var productsToCompare = document.getElementById(inputFieldID).value;
		document.getElementById(inputFieldID).value = productsToCompare.replace(pid + '|', "")
	}
}
