// JavaScript Document
// This script deals with navigating functions on the page
// Author: Vu Xuan Linh
// Date: 02 June 2006
//constants
HOTBOX_LIMIT = 4;

// three variables below keep the settings (set in UpdFunnelList)
var hpmaker;
var hpmodel;
var carrier;
var hpmakerId;
var hpmodelId;
var carrierId;
var currentType;
var currentGenre;
var currentLimit;

var currentItem;
var deviceChange;
var alwaysProceed;
var msg;
var nocheck;  // flag whether to check settings in prior getting content, true initially.

var goTypeThen;
var goPageThen;
var goItemThen;
var	genreToGo;
var	typeToGo;
var	limitToGo;
var indexToGo;
var idToGo;
function checkSettings(){
	if (hpmaker == "" || hpmodel == "" || carrier == "") {		
		if (!alwaysProceed)
			msg = "<p>It is recommended that you <a href=\"#\" onclick=\"chooseDevice();\">set your mobile settings</a>" +
								"before going on.<br />" +
								"Alternatively you can just <a href=\"#\" onclick=\"proceed();\">Proceed</a></p>";
		else {
			msg = "<p>It is recommended that you <a href=\"#\" onclick=\"chooseDevice();\">set your mobile settings</a>" +
								"before going on.<br />"
			proceed();
		}
		document.getElementById('notice').innerHTML = msg;
		return false;
	}
	else return true;	
}
// Proceed: go to content without phone setting
// once user has chosen this. The notice box will still pop up but does not prevent user from seeing the content.
function proceed(){
	alwaysProceed = true;
	goType(currentType,currentGenre,0,true,'funnel');
	msg = "<p>It is recommended that you <a href=\"#\" onclick=\"chooseDevice();\">set your mobile settings</a>" +
								" before going on.<br />"
	document.getElementById('notice').innerHTML = msg;
}

function updateSettings(){
	// 02 June 2006 VXL update phone and carrier settings
	hpmakerId = document.getElementById('hpmanufacturer').value;
	hpmodelId = document.getElementById('deviceslist').value;   // 'deviceslist' element is generated by xphonelist.php
	carrierId = document.getElementById('carrierslist').value;	// 'carrierslist' element is generated by xcarrierslist.php								 	
	hpmakerDivId = "m" + hpmakerId;
	hpmodelDivId = "p" + hpmodelId;
	carrierDivId = "c" + carrierId;	
	hpmaker = document.getElementById(hpmakerDivId).text;				// id for this HTMLOptionElement is set same as: 'p' + its value, in xphonelist.php
	hpmodel = document.getElementById(hpmodelDivId).text;				// similar to above,'m' + its value, RET_SEL_MANUFACTURER in ns_functions.php
	carrier = document.getElementById(carrierDivId).text;				// similar to above: 'c' + its value,in xcarrier.php

	assignSettings(hpmakerId,hpmodelId,carrierId,hpmaker,hpmodel,carrier);
	
	return true;
}
// This functions is to assigning device settings when index.php is called with specific parameters
function assignSettings(mkrId,modId,carId,mkr, mod, car){
	hpmakerId = mkrId;
	hpmodelId = modId;
	carrierId = carId;
	hpmaker = mkr;
	hpmodel = mod;
	carrier = car;
	var settingbox = document.getElementById('settingbox');
	if (hpmaker != "" && hpmodel != "" && carrier != "")
	{
		settingbox.innerHTML = "Your phone is:<br /><span class=\"phone\">" + hpmaker + " " + hpmodel + "</span><br />" + 
								"Service provider:<br /><span class=\"carrier\">" + carrier + "</span><br />" +
								"<a href=\"#\" onclick=\"chooseDevice();\">Change</a>";
		var devicesettingbox = document.getElementById('devicesettingbox');						
		devicesettingbox.innerHTML = "<p class=\"generalcontent\">Phone model: <span class=\"phone\">" + hpmaker + " " + hpmodel + "</span><br />" + 
								"Service provider: <span class=\"carrier\">" + carrier + "</span><br /></p>";
								
		var nextY = new Date(2020,31,12);
		setCookie("hpmakerId",hpmakerId,nextY);
		setCookie("hpmodelId",hpmodelId,nextY);
		setCookie("carrierId",carrierId,nextY);
		setCookie("hpmaker",hpmaker,nextY);
		setCookie("hpmodel",hpmodel,nextY);
		setCookie("carrier",carrier,nextY);		
		//alert(hpmaker + " model:" + hpmodel + " carrier:" + carrier);
	}
	return true;
	
}

//var lock;	
// This variable allows single access to UpdFunnelList function
// lock is obtained(set to true) whenever UpdFunnelList is called;
// it's released in funupdatepage() when funupdatepage returns 
function UpdFunnelObject(){
	function UpdFunnelList(strURL,type,genre,limit,container,startIndex)
	{
		// lock to allow only one access at one time
		//var counter = 0;
		//while (lock && counter < 10) { setTimeout("return;", 300);counter++ };
		//lock = true;
		// Ken code, Linh editted
		
		document.getElementById(container).innerHTML = "<img src='images/loading.gif'> Loading ";
		//alert(fungetquerystring(type,genre,limit));
		var xmlHttpReq = false; 
		var self = this; 
		if (window.XMLHttpRequest) 
		{ self.xmlHttpReq = new XMLHttpRequest(); }
		else if (window.ActiveXObject) 
		{ self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
		self.xmlHttpReq.open('POST', strURL, true);
		self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		self.xmlHttpReq.onreadystatechange = function() { 
			if (self.xmlHttpReq.readyState == 4) { funupdatepage(self.xmlHttpReq.responseText,container,type,genre); }		
			//lock = false;
			}
		self.xmlHttpReq.send(fungetquerystring(type,genre,limit,startIndex));
	}
	function fungetquerystring(type,genre,limit,startIndex) 
	{ 
		var devlist = document.getElementById("deviceslist").value;
		var carlist = document.getElementById("carrierslist").value;
		if (hpmodelId != 0)	devlist = hpmodelId;
		if (carrierId != 0) carlist = carrierId;		
		//var type = document.getElementById("type").value;
		//var genre = currentGenre; //document.getElementById("genrelist").value;
		var	qstr = 'devId='+devlist+'&carId='+carlist  +'&makerId='+hpmakerId + '&model='+hpmodel +'&maker='+hpmaker +'&carrier='+carrier +'&type='+type;
		if (genre != '') qstr = qstr + '&gen='+genre;
		if (limit != '' || limit > 1) qstr = qstr + '&limit='+limit;
		if (startIndex != '' || startIndex > 1) qstr = qstr + '&startIndex='+startIndex;
		return qstr; 
	}
	function funupdatepage(str,container,type,genre){  
		// add Type and Genre indications to Funnel
		var prefix = "";
		if (container == 'funnel')
		{
			
			prefix = "<h3>" + getTypeName(type);
			genreName = getGenreName(genre);
			if (genreName != "")
				prefix += " >> " + genreName;
			prefix += "</h3>";				
		}
		document.getElementById(container).innerHTML = prefix + str;
		
	}
	
	// assigning functions
	this.UpdFunnelList = UpdFunnelList;
	this.fungetquerystring = fungetquerystring;
	this.funupdatepage = funupdatepage;

}

function goPage(type,genre,limit,startIndex){
	strURL = "xdatatemplate.php";
	var myUpdater = new UpdFunnelObject();
	// when page is called directly from index.php?with parameters, class for funnel may not be set, thus the line below:
	document.getElementById('funnel').className = getTypeName(type) ;
	myUpdater.UpdFunnelList(strURL,type,genre,limit,'funnel',startIndex);
}

function getActiveGenresAndTypes(){
	strURL = "xactivegenretype.php";
	document.getElementById("categories").innerHTML = "<img src='images/loading.gif'> Loading Categories";
    var xmlHttpReq = false; 
    var self = this; 
    if (window.XMLHttpRequest) 
    { self.xmlHttpReq = new XMLHttpRequest(); }
    else if (window.ActiveXObject) 
    { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { updateActiveGenreType(self.xmlHttpReq.responseText);} }	
    self.xmlHttpReq.send(activegentypegetquerystring());
}
function activegentypegetquerystring() { 	
	var devlist = document.getElementById("deviceslist").value;
	var carlist = document.getElementById("carrierslist").value;
	if (hpmodelId != 0)	devlist = hpmodelId;
	if (carrierId != 0) carlist = carrierId;
	var	qstr = 'dev='+devlist+'&car='+carlist;
	return qstr; 	
}

var activeTypeGenres = new Array();
// activeTypeGenres[][0] = typeName
// activeTypeGenres[][1..n] = genreName
var activeTypeGenreIds = new Array();
// activeTypeGenres[][0] = typeId
// activeTypeGenres[][1..n] = genreId
var genreDivs = new Array(); // these are names of the divs that contain genres for each type
function updateActiveGenreType(str){
	//get XML document object	
	var xmlDoc;
	if (window.ActiveXObject)
	  {
	  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async="false"
	  xmlDoc.loadXML(str)
	  }
	// code for Mozilla, etc.
	else if (document.implementation &&	document.implementation.createDocument)
	  {
	  // Mozilla, create a new DOMParser 
   	  var parser = new DOMParser(); 
      xmlDoc = parser.parseFromString(str, "text/xml"); 
	  }
	else
	  {
	  alert('Your browser cannot handle this script');
	  }
	// get Types and Genres and put to 2 corresponding arrays
	// display those type and genres in typesgenres DIV
	// element format:<genre id=$genre name=$genreName type=$type typeName=$typeName>< />
	//alert(str);

	myNodes=xmlDoc.getElementsByTagName("genre");
   	//Extract the different values using a loop.
	var genre,genreId, type,typeId;
	var typeCounter = 0;
	var genreCounter;
	// reset activeTypeGenres and activeTypeGenreIds
	activeTypeGenres = new Array();
	activeTypeGenreIds = new Array();
	genreDivs = new Array();
	
   	for(var counter=0;counter<myNodes.length;counter++)
	{
		genre = myNodes[counter].attributes.getNamedItem("genreName").value;
		genreId = myNodes[counter].attributes.getNamedItem("id").value;
		type = myNodes[counter].attributes.getNamedItem("typeName").value;
		typeId = myNodes[counter].attributes.getNamedItem("type").value;
		// if genre is of new type
		var typeLocation = getTypeLocation(typeId);		
		if (typeLocation < 0)
		{
			activeTypeGenreIds[typeCounter] = new Array();
			activeTypeGenres[typeCounter] = new Array();
			activeTypeGenreIds[typeCounter][0] = typeId;
			activeTypeGenres[typeCounter][0] = type;
			genreCounter = 1;
			typeLocation = typeCounter;
			typeCounter++;
		}		
		activeTypeGenreIds[typeLocation][genreCounter] = genreId;
		activeTypeGenres[typeLocation][genreCounter] = genre;
		genreCounter++;			  
		
		
	}
	var HTMLOutput = "<h4>For your phone</h4>\n<ul>";
	/* This code expands all the content Types and Genres 
	for (x in activeTypeGenreIds){
		HTMLOutput += "<li class='type' value='" + activeTypeGenreIds[x][0] + "'><a href='#' onclick=\"goType('" + activeTypeGenreIds[x][0] +
					"','',0,false,'funnel');\">" + activeTypeGenres[x][0] + "</a></li>";
		for (y in activeTypeGenreIds[x]){
			if (y>0)
				HTMLOutput += "<li class='genre' value='" + activeTypeGenreIds[x][y] + "'><a href='#' onclick=\"goType('" + activeTypeGenreIds[x][0] +
					"','" + activeTypeGenreIds[x][y] + "',0,false,'funnel');\">" + activeTypeGenres[x][y] + "</a></li>";
		}
	}	
	*/
	for (x in activeTypeGenreIds){
		genreDivs[x] = activeTypeGenres[x][0] + "genres";
		HTMLOutput += "<li class='type' value='" + activeTypeGenreIds[x][0] + "'><a onclick=\"expand('" + genreDivs[x] +"');\">" + activeTypeGenres[x][0] + "</a></li>";		
		HTMLOutput += "<div id='" + genreDivs[x] +"'>";
		for (y in activeTypeGenreIds[x]){
			if (y>0)				
				HTMLOutput += "<li class='genre' value='" + activeTypeGenreIds[x][y] + "'>" +
				"<a href='index.php?do=gotype&makerId=" + hpmakerId + "&modelId=" + hpmodelId + "&carrierId=" + carrierId + "&maker=" + hpmaker + "&model=" + hpmodel + "&carrier=" + carrier + "&param1=" + activeTypeGenreIds[x][0]+ "&param2=" + activeTypeGenreIds[x][y] + "&param3=0&param4=1&param5=funnel'" + 
				"onclick=\"setCurrentGenre(this);goType('" + activeTypeGenreIds[x][0] +	"','" + activeTypeGenreIds[x][y] + "',0,false,'funnel');return false;\">" + activeTypeGenres[x][y] + "</a></li>";
		}
		HTMLOutput += "</div>";
	}
	HTMLOutput += "</ul>";
	document.getElementById("categories").innerHTML = HTMLOutput;
	updateHotBoxes(nocheck);
	updatePromoBoxes(nocheck);
	
	// this is called when index.php is loaded with parameter do=gotype
	if (goTypeThen)
	{
		goTypeThen = false;
		goType(typeToGo,genreToGo,limitToGo,nocheck,'funnel');
	}
	if (goPageThen)
	{
		goPageThen = false;
		goPage(typeToGo,genreToGo,limitToGo,indexToGo);		
	}
	if (goItemThen)
	{
		goItemThen = false;
		if (!isNaN(idToGo)){
			goItem(idToGo);
			current = 'buysingleitem';
			showOnly(current);
		}
	}
	// Hide all genre div
	for (y in genreDivs){
		document.getElementById(genreDivs[y]).style.display = "none";
	}
}

// This function is used only by updateActiveGenreType()
// is return the position of the submitted type in activeTypeGenres array.
// -1 if the type is not in the array.
function getTypeLocation(typeId){	
	for (y in activeTypeGenreIds){
		if (activeTypeGenreIds[y][0] == typeId) return y;
	}
	return -1;
}
// this function is used ONLY by goType() to get type name from ID
function getTypeName(typeId){
	for (y in activeTypeGenreIds){
		if (activeTypeGenreIds[y][0] == typeId) return activeTypeGenres[y][0];
	}
	return "notype";	
}
function getGenreName(genreId){
	for (x in activeTypeGenreIds)
		for (y in activeTypeGenreIds[x])
			if (y > 0)
				if (activeTypeGenreIds[x][y] == genreId) return activeTypeGenres[x][y];
	
	return "";	
}
// this function expand the genres when user click on the type
function expand(genreDivName){	
	for (y in genreDivs){
		document.getElementById(genreDivs[y]).style.display = "none";
	}
	document.getElementById(genreDivName).style.display = "block";
	
}
function setCurrentGenre(obj){
	obj.className = "currentGenre";
}
// The two functions below deal with single item
function UpdSingleItem(itemId){
	strURL = "xsingleitem.php";
	document.getElementById("singleitem").innerHTML = "<img src='images/loading.gif'> Loading Content";
    var xmlHttpReq = false; 
    var self = this; 
    if (window.XMLHttpRequest) 
    { self.xmlHttpReq = new XMLHttpRequest(); }
    else if (window.ActiveXObject) 
    { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { updatesingleitem(self.xmlHttpReq.responseText);} }	
    self.xmlHttpReq.send("id=" + itemId + "&car="+carrierId);
}

function updatesingleitem(str){	document.getElementById("singleitem").innerHTML = str;	}


// JavaScript Document
// This script deals with navigating functions on the page
// Author: Vu Xuan Linh (xunlinh@yahoo.com)
// Date: 1 June 2006
var current,last;
var mydivs=new Array();

mydivs[0]='HotBoxDiv';
mydivs[1]='PhoneSelDiv';
mydivs[2]='buysingleitem';
mydivs[3]='funnel';
function initialize(){
	// read cookies	
	
 	hpmakerId=getCookie("hpmakerId");
	if (hpmakerId==null) hpmakerId = 0;
		
	hpmodelId=getCookie("hpmodelId");
	if (hpmodelId==null) hpmodelId = 0;
	
	carrierId=getCookie("carrierId");
	if (carrierId==null) carrierId = 0;	
	
	hpmaker=getCookie("hpmaker");
	if (hpmaker==null) hpmaker = "";
	
	hpmodel=getCookie("hpmodel");
	if (hpmodel==null) hpmodel = "";
	
	carrier=getCookie("carrier");
	if (carrier==null) carrier = "";
	//alert(hpmaker + " model:" + hpmodel + " carrier:" + carrier);
	
	assignSettings(hpmakerId,hpmodelId,carrierId,hpmaker,hpmodel,carrier);
	currentGenre = "";
	deviceChange = false;
	alwaysProceed = false;
	hideAll();
	
	// get content from database and put into content boxes
	nocheck = true;
	getActiveGenresAndTypes();
	// Make sure activeGenreAndTypes are completed before updateHotBoxes (because HotBoxes user activeTypeGenres and activeTypeGenreIds arrays
	// updateHotBoxes(nocheck) therefore was moved to inside activegenretypeupdate();
	current = 'HotBoxDiv';
	showOnly(current);
	
	
}
function initializeGoType(mkrId,modId,carId,maker,mod,car,type,genre,limit,ncheck,updateToContainer)
{
	assignSettings(mkrId,modId,carId,maker,mod,car);
	//alert(type + " genre: " + genre);
	genreToGo = genre;
	typeToGo = type;
	limitToGo = limit;
	deviceChange = false;
	alwaysProceed = false;
	hideAll();
	
	// get content from database and put into content boxes
	nocheck = ncheck;
	goTypeThen = true;
	getActiveGenresAndTypes();
	// Make sure activeGenreAndTypes are completed before updateHotBoxes (because HotBoxes user activeTypeGenres and activeTypeGenreIds arrays
	// updateHotBoxes(nocheck) therefore was moved to inside activegenretypeupdate();
	
	current = 'funnel';
	showOnly(current);
}
function initializeGoPage(mkrId,modId,carId,maker,mod,car,type,genre,limit,startIndex)
{
	assignSettings(mkrId,modId,carId,maker,mod,car);
	genreToGo = genre;
	typeToGo = type;
	limitToGo = limit;
	indexToGo = startIndex;
	deviceChange = false;
	alwaysProceed = false;
	hideAll();
		
	// get content from database and put into content boxes
	nocheck = false;
	goPageThen = true;
	getActiveGenresAndTypes();
	// Make sure activeGenreAndTypes are completed before updateHotBoxes (because HotBoxes user activeTypeGenres and activeTypeGenreIds arrays
	// updateHotBoxes(nocheck) therefore was moved to inside activegenretypeupdate();
	
	current = 'funnel';
	showOnly(current);
}

function initializeGoItem(mkrId,modId,carId,maker,mod,car,itemId)
{
	assignSettings(mkrId,modId,carId,maker,mod,car);
	idToGo = itemId;
	deviceChange = false;
	alwaysProceed = false;
	hideAll();
		
	// get content from database and put into content boxes
	nocheck = true;
	goItemThen = true;
	getActiveGenresAndTypes();
	// Make sure activeGenreAndTypes are completed before updateHotBoxes (because HotBoxes user activeTypeGenres and activeTypeGenreIds arrays
	// updateHotBoxes(nocheck) therefore was moved to inside activegenretypeupdate();
	
}


function hideAll(){
	for (x in mydivs){		
			document.getElementById(mydivs[x]).style.display = 'none';			
	}
	return true;
}
function updateHotBoxes(nocheck){	
	document.getElementById('HotBoxDiv').innerHTML = "";
	var pluraltitle;
	for (id in activeTypeGenreIds){
		//alert(activeTypeGenres[id][0]);
		pluraltitle = 'Top ' + activeTypeGenres[id][0] + 's';
		pluraltitle = pluraltitle.replace('ss','s'); // remove double s at the end if any.
		(new ContentCollection(pluraltitle,activeTypeGenres[id][0],activeTypeGenreIds[id][0],'','box','list','hot')).writeTo('HotBoxDiv');		
	}
	for (id in activeTypeGenreIds){
		// 'Hot' sub boxes have id: typeName + 'list'
		//idStr = activeTypeGenres[id][0] + 'list';
		//idStr = idStr.replace(' ','');
		goType(activeTypeGenreIds[id][0],'',HOTBOX_LIMIT,nocheck, activeTypeGenres[id][0] + 'list');	// go default with out checking for devicesettings
	}
	
}
function updatePromoBoxes(nocheck){
		
	document.getElementById('promotion').innerHTML = "";	
	for (id in activeTypeGenreIds){
		(new ContentCollection(activeTypeGenres[id][0],activeTypeGenres[id][0],activeTypeGenreIds[id][0],'','promobox','promo','promo')).writeTo('promotion');		
	}
	for (id in activeTypeGenreIds){			
		// promotion sub boxes have id: 'promo' + typeName
		// since we remove space in id when creating ContentCollection (see ContentCollection)
		// we need to recreate the id here
		idStr = activeTypeGenres[id][0]+'promo';
		idStr = idStr.replace(' ','');		
		goType(activeTypeGenreIds[id][0],'',1,nocheck,idStr);	// go default with out checking for devicesettings
	}
}

function showOnly(divId){
	var x;
	if (!document.getElementById(divId)) alert("ShowOnly: " + divId);
	document.getElementById(divId).style.display = 'block';
	for (x in mydivs){
		if (mydivs[x] != divId)
			document.getElementById(mydivs[x]).style.display = 'none';			
	}
	return true;
}
function goHome(){
	last = current;
	current = 'HotBoxDiv';
	if (deviceChange) {
		
		
	}
	deviceChange = false;
	showOnly(current);
}
function chooseDevice(){	

	if (current != 'PhoneSelDiv'){
		last = current;
		current = 'PhoneSelDiv';
		showOnly(current);
	}
	
	return true;
	
}


function deviceChosen(){
	// flag device change so that can update HotBoxDiv (if happens)
	// if 'funnel' was the one to return back, it will be update right below
	deviceChange = true;
	
	updateSettings();
	nocheck = false;
	getActiveGenresAndTypes(); //also update HotBoxDiv	
	current = last;
	if (current == 'HotBoxDiv') goHome();
	else if (current == 'funnel')
		goType(currentType,currentGenre,0,true,'funnel');	// funnel if currently visible will need to be updated
	else if (current == "buysingleitem")
		goItem(currentItem);
		
	showOnly(current);
	if (checkSettings()) document.getElementById('notice').style.display = 'none';
	return true;
}

function goItem(itemId){
	checkSettings();
	last = current;
	currentItem = itemId;
	UpdSingleItem(itemId);
	
	current = 'buysingleitem';
	showOnly(current);	
}

function goBack(){
	current = last;
	showOnly(current);	
	return true;
}
function goGenre(){
	last = current;
	current = 'genreview';
	showOnly(current);
}
function goType(type,genre,limit,nocheck,updateToContainer){
	currentType = type;
	currentGenre = genre;	
	if (nocheck || checkSettings()){
		if (updateToContainer == 'funnel') {
		last = current;
		current = 'funnel';
		showOnly(current);
		
		}
		// update class of container element so that display will be changed for each content type		
		if (document.getElementById(updateToContainer) == null) {		alert(updateToContainer);return;}

		document.getElementById(updateToContainer).className = getTypeName(type) ;
		var myUpdater = new UpdFunnelObject();
		myUpdater.UpdFunnelList('xdatatemplate.php',type,genre,limit,updateToContainer,0);	// startIndex (0) is only used when paging
		
	}	
}

function settingsOK(){
	if (phonemaker == "" || model == "" || carrier == "")
		return false;
	else 
		return true;
}

// Objects
/* This object contains a collection of content items in a DIV block and get display to the target HTML file 
   when object.writeTo(containerDiv) is called
   outerDivSuffix: suffix for id of outer div (container) of this content collection.
	innerDivSuffix: suffix for id of inner div (subcontainer, exclude the header) of this content collection.
*/
function ContentCollection(title,typeName,typeId,content,outerDivSuffix,innerDivSuffix,collectionType){
	if (collectionType == 'hot'){	
	this.code = "<div class=\"topitem\" id=\"" + typeName + outerDivSuffix +"\">\n" +
					"\t<div class=\"topitemheader\"><span href=\"#\" onclick=\"goType('" + typeId + "',,0,false,'funnel');\">"+ title + "</span></div>\n" +
					"\t<div id=\"" + typeName + innerDivSuffix +"\">" + content + "</div>\n" +
					"\t<div class=\"lastrow\"><p align=\"right\" onclick=\"goType('" + typeId + "','',0,false,'funnel');\">More</p></div>\n" +
				"</div>\n";
	}
	else { // 'promo'
		var idOuter = typeName + outerDivSuffix;
		idOuter = idOuter.replace(' ','');
		var idInner = typeName + innerDivSuffix;
		idInner = idInner.replace(' ','');
		this.code = "<div class=\"promotionbox\" id=\"" + idOuter +"\">\n" +
					"\t<div class=\"topitemheader\"><span href=\"#\" onclick=\"goType('" + typeId + "',,0,false,'funnel');\">"+ title + "</span></div>\n" +
					"\t<div id=\"" + idInner +"\">" + content + "</div>\n" +
					"\t<div class=\"lastrow\"><p align=\"right\" onclick=\"goType('" + typeId + "','',0,false,'funnel');\">More</p></div>\n" +
				"</div>\n";
	}
	function writeTo(containerId){
		var writeElement = document.getElementById(containerId);
		writeElement.innerHTML = writeElement.innerHTML + this.code;		
	}
	this.writeTo = writeTo;
	
}

// Cookie functions: http://www.netspade.com/articles/2005/11/16/javascript-cookies/
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}