
/**
	Constants class
**/
function Constants() {}

Constants.NewUserType = "new_user";
Constants.CurrentUserType = "current_user"
Constants.NumberOfColumns = 5;
Constants.NumberOfColumnsProductPage = 2;
Constants.NumberOfRecommendedColumnsCurrentUser = 2;
Constants.ConcatString = "___";
Constants.CheckMarkChar = "x";

Constants.FeatureGroupExpandedImgFirst = "/qb/components/comp_chart/img/expanded.gif";
Constants.FeatureGroupExpandedImgLast = "/qb/components/comp_chart/img/minus.gif";
Constants.FeatureGroupCollapsedImgFirst = "/qb/components/comp_chart/img/expand.gif";
Constants.FeatureGroupCollapsedImgLast = "/qb/components/comp_chart/img/plus.gif";

Constants.ClassFeatureScreenShot = 'screenshot';
Constants.ClassNoFeatureScreenShot = '';
Constants.ClassKeyFeaturesTwoCols = 'two-cols';
Constants.ClassKeyFeaturesThreeCols = 'three-cols';

Constants.ImageFullDot = '<img src="/qb/components/comp_chart/img/btn-blue-dot-full.gif" />';
Constants.ImageNoDot = '&nbsp;';

// Path info
Constants.PathProductImages = "img/products/";
Constants.PathFeatureImages = "";

// Template items (placeholders)
Constants.TPL_ITEM_KEY_FEATURES_CLASS = "KEY_FEATURES_CLASS";

Constants.TPL_ITEM_ProductID = 'PRODUCT_ID';
Constants.TPL_ITEM_ProductName = 'PRODUCT_NAME';

Constants.TPL_ITEM_FeatureGroupID = 'FEATURE_GROUP_ID';
Constants.TPL_ITEM_FeatureGroupName = 'FEATURE_GROUP_NAME';
Constants.TPL_ITEM_FeatureGroupColSpan = 'FEATURE_GROUP_COLSPAN';

Constants.TPL_ITEM_FeatureID = "FEATURE_ID";
Constants.TPL_ITEM_FeatureName = 'FEATURE_NAME';
Constants.TPL_ITEM_FeatureDescription = 'FEATURE_DESCRIPTION';
Constants.TPL_ITEM_ScreenShotImageFileName = 'SCREEN_SHOT_IMAGE_FILE_NAME';
Constants.TPL_ITEM_ScreenShotImage = Constants.PathFeatureImages + Constants.TPL_ITEM_ScreenShotImageFileName;
Constants.TPL_ITEM_FeatureScreenShotClass = 'FEATURE_SCREEN_SHOT';
Constants.TPL_ITEM_FeatureScreenShotLink = 'FEATURE_SCREEN_SHOT_LINK';
Constants.TPL_ITEM_FeatureDotImage = 'FEATURE_DOT_IMAGE';
Constants.TPL_ITEM_FeatureFootNote = 'FEATURE_FOOT_NOTE';


Constants.TPL_ITEM_ProductFeatureID = Constants.TPL_ITEM_ProductID +  Constants.ConcatString + Constants.TPL_ITEM_FeatureID;

// HTML templates
Constants.HTML_ProductHeaderItemFirst =			'<tr>';
Constants.HTML_ProductHeaderItemFirst +=				'<th class="' + Constants.TPL_ITEM_KEY_FEATURES_CLASS + '"><h3>Key Features</h3></th>';	
Constants.HTML_ProductHeaderItemFirst +=			'</tr>';
Constants.HTML_ProductHeaderItemMiddle =			'<th class="product">' + Constants.TPL_ITEM_ProductName + '</th><td>&nbsp;</td>';
Constants.HTML_ProductHeaderItemLast =				'<th class="product last">' + Constants.TPL_ITEM_ProductName + '</th>';

Constants.HTML_FeatureGroupRowOpen =	'<tr class="featureGroup" id="' + Constants.TPL_ITEM_FeatureGroupID + '">';
Constants.HTML_FeatureGroupRowOpen +=		'<th class="description last" colspan="' + Constants.TPL_ITEM_FeatureGroupColSpan + '">';
Constants.HTML_FeatureGroupRowOpen +=			'<img class="btn-expander" src="' + Constants.FeatureGroupCollapsedImgFirst + '" title="collapse this section" />';
Constants.HTML_FeatureGroupRowOpen +=			'<span>' + Constants.TPL_ITEM_FeatureGroupName + '</span>';
Constants.HTML_FeatureGroupRowOpen +=			'<img class="btn-plusminus" src="' + Constants.FeatureGroupCollapsedImgLast + '" title="collapse this section" />';
Constants.HTML_FeatureGroupRowOpen +=		'</th>';
Constants.HTML_FeatureGroupRowOpen +=	'</tr>';

Constants.HTML_FeatureScreenShotLink = '<a href="' + Constants.TPL_ITEM_ScreenShotImage + '" id="' + Constants.TPL_ITEM_ProductFeatureID +'" class="thickbox" title="">view screenshot</a>';
Constants.HTML_FeatureRowOpenTr =			'<tr style="display:none;" id="' + Constants.TPL_ITEM_FeatureGroupID +  Constants.ConcatString + Constants.TPL_ITEM_FeatureID + '">';
Constants.HTML_FeatureRowOpenLastTr =	'<tr style="display:none;" class="last" id="' + Constants.TPL_ITEM_FeatureGroupID +  Constants.ConcatString + Constants.TPL_ITEM_FeatureID + '">';
Constants.HTML_FeatureRowFirst =				'<td class="description">';
Constants.HTML_FeatureRowFirst +=					'<a href="javascript:void(0);">' + Constants.TPL_ITEM_FeatureName + '</a>';
Constants.HTML_FeatureRowFirst +=					'<div style="display:none;">' + Constants.TPL_ITEM_FeatureDescription + '</div>';
Constants.HTML_FeatureRowFirst +=				'</td>';
Constants.HTML_FeatureItemMiddle =				'<td class="circle">' + Constants.TPL_ITEM_FeatureDotImage;
Constants.HTML_FeatureItemMiddle +=				'<div style="display:none;" class="' + Constants.TPL_ITEM_FeatureScreenShotClass +  '">' + Constants.TPL_ITEM_FeatureScreenShotLink + '</div>';
Constants.HTML_FeatureItemMiddle +=			'</td>';
Constants.HTML_FeatureItemMiddle +=			'<td>&nbsp;</td>';
Constants.HTML_FeatureItemLast =					'<td class="circle">' + Constants.TPL_ITEM_FeatureDotImage;
Constants.HTML_FeatureItemLast +=					'<div style="display:none;" class="' + Constants.TPL_ITEM_FeatureScreenShotClass +  '">' + Constants.TPL_ITEM_FeatureScreenShotLink + '</div>';
Constants.HTML_FeatureItemLast +=				'</td>';
Constants.HTML_FeatureRowClose =			'</tr>';

// IDs of anchor points
Constants.ID_ProductFeatureDiv = "features"
Constants.ID_ProductFeatureTable = "pcc_productFeatureTable";

// IDs of drop down lists
Constants.PlatformDDL = "#platforms";
Constants.NumberOfBusinessLocationsDDL = "#numberOfBusinessLocations";
Constants.ProductNameDDL = "#productNames";
Constants.YearDDL = "#years";
Constants.NumberOfUsersDDL = "#numberOfUsers";
Constants.IndustryDDL = "#industries";
Constants.TellUsMoreAboutYourBusinessDDL = "#tellUsMoreAboutYourBusiness";
Constants.ProductsUserAddID = "productsUserAdded";
Constants.ProductsUserAddDDL = "#" + Constants.ProductsUserAddID;


// ID of the row that shows the products
Constants.HeaderRow = "#headerRow";

// IDs of user tabs
Constants.CurrentUserTab = "#current";
Constants.NewUserTab = "#new";

// IDs of title rows
Constants.CurrentUserTitleRow = "#titleRowCurrentUser"
Constants.NewUserTitleRow = "#titleRowNewUser"



/**
	Template class
**/
function Template () {}

// Column header
Template.replaceKeyFeaturesClass = function(template, products) {
	var cssClass = "two-cols";

	if (products.length == 3){
		cssClass = "three-cols";
	}


	return template.replace(Constants.TPL_ITEM_KEY_FEATURES_CLASS, cssClass);
}


// Product
Template.replaceProductID = function(template, product) {
	return template.replace(Constants.TPL_ITEM_ProductID, product.productID);
}


Template.replaceProductName = function(template, product) {
	return template.replace(Constants.TPL_ITEM_ProductName, product.productNameShort);
}


// Feature Group
Template.replaceFeatureGroupID = function(template, featureGroup) {
	return template.replace(Constants.TPL_ITEM_FeatureGroupID, featureGroup.featureGroupID);
}


Template.replaceFeatureGroupName = function(template, featureGroup) {
	return template.replace(Constants.TPL_ITEM_FeatureGroupName, featureGroup.featureGroupName);
}


// Feature
Template.replaceFeatureID = function(template, feature) {
	return template.replace(Constants.TPL_ITEM_FeatureID, feature.featureID);
}


Template.replaceFeatureName = function(template, feature) {
	return template.replace(Constants.TPL_ITEM_FeatureName, feature.featureDescriptionShort);
}


Template.replaceFeatureDescription = function(template, feature) {
	return template.replace(Constants.TPL_ITEM_FeatureDescription, feature.featureDescriptionLong);
}


Template.replaceFeatureDotImage = function(template, product, feature) {
	var featureDotImage = Constants.ImageNoDot;

	if (product.hasFeature(feature)) {
		featureDotImage = Constants.ImageFullDot + Constants.TPL_ITEM_FeatureFootNote;

		// Show custom feature display value
		if (! product.showFeatureDot(feature)) {
			var productFeature = product.getFeature(feature);
			featureDotImage = '<p>' + productFeature.featureGridDisplayValue + Constants.TPL_ITEM_FeatureFootNote + '</p>';
		}
	}

	return template.replace(Constants.TPL_ITEM_FeatureDotImage, featureDotImage);
}


Template.replaceFootNote = function(template, product, feature) {
	var footNoteText = "";

	if (product.hasFeature(feature)) {

		/*
		var productFeature = product.getFeature(feature);

		if (DataUtil.HasValue(productFeature.footNoteID)) {
			footNoteHTML = '<sup>#' + productFeature.footNoteID + '</sup>';
		}
		*/

		var productFeature = product.getFeature(feature);

		if (DataUtil.HasValue(productFeature.footNoteID)) {
			footNoteText = ' <sup>#' + productFeature.footNoteID + '</sup>';
		}

	}

	return template.replace(Constants.TPL_ITEM_FeatureFootNote, footNoteText);
}


Template.replaceScreenShotImageFileName = function(template, feature) {
	return template.replace(Constants.TPL_ITEM_ScreenShotImageFileName, feature.screenShotURL);
}


Template.replaceFeatureScreenShot = function(template, product, feature) {
	var cssClass = Constants.ClassNoFeatureScreenShot;
	var link = "";
	var processedTemplate = "";

	// Don't show the link to the screen shot if the feature is not supported or the feature has no screen shot url
	if ( product.hasFeature( feature ) && DataUtil.HasValue( product.getFeature( feature ).screenShotURL ) ) {
		cssClass = Constants.ClassFeatureScreenShot;
		
		// Process link templated
		link = Constants.HTML_FeatureScreenShotLink;
		link = Template.replaceProductID(link, product);
		link = Template.replaceFeatureID(link, feature);
		link = Template.replaceScreenShotImageFileName(link, product.getFeature(feature))
	}

	processedTemplate = template.replace(Constants.TPL_ITEM_FeatureScreenShotClass, cssClass);
	processedTemplate = processedTemplate.replace(Constants.TPL_ITEM_FeatureScreenShotLink, link);

	return processedTemplate;
}


// Combined template processors
Template.processFeatureGroupRowTemplate = function(template, featureGroup, products) {
	var processedTemplate = template;

	processedTemplate = Template.replaceFeatureGroupID(processedTemplate, featureGroup);

	processedTemplate = Template.replaceFeatureGroupName(processedTemplate, featureGroup);

	processedTemplate = processedTemplate.replace(Constants.TPL_ITEM_FeatureGroupColSpan, products.length * 2);

	return processedTemplate;
}


Template.processFeatureRowTemplate = function(template, feature) {
	var processedTemplate = template;

	processedTemplate = Template.replaceFeatureID(processedTemplate, feature);

	processedTemplate = Template.replaceFeatureName(processedTemplate, feature);

	processedTemplate = Template.replaceFeatureDescription(processedTemplate, feature);

	processedTemplate = Template.replaceFeatureGroupID(processedTemplate, feature.featureGroup);

	return processedTemplate;
}


Template.processProductFeatureCellTemplate = function(template, product, feature) {
	var processedTemplate = template;

	processedTemplate = Template.replaceFeatureID(processedTemplate, feature);

	processedTemplate = Template.replaceProductID(processedTemplate, product);

	processedTemplate = Template.replaceFeatureScreenShot(processedTemplate, product, feature);

	processedTemplate = Template.replaceFeatureDotImage(processedTemplate, product, feature);

	processedTemplate = Template.replaceFootNote(processedTemplate, product, feature);

	return processedTemplate;
}



/**
	jQueryUtility class
**/
function jQueryUtility() {}


jQueryUtility.GetJQObject = function(jqExpr, context) {
	var self = this;
	var jqObj = $(jqExpr);

	if (context) {
		jqObj = $(jqExpr, context);
	}
	else {
		jqObj = $(jqExpr);
	}


	if (jqObj.length == 0) {
		throw new Error("jQuery object has no content.");
	}

	return jqObj;
}



/**
	DataUtil class
**/
function DataUtil() {}

DataUtil.HasValue = function(value) {
	return value != null && value != "" && value != "undefined";
}

DataUtil.ExistsInArray = function(arr, value) {
	for (var i = 0; i < arr.length; i++) {

		if (arr[i] == value)
			return true
	}

	return false;
}

