//==================================================
//Global variables
//To be used for Cookies.
var iNumDays = 100;
var dtExpire = new Date();
dtExpire.setTime (dtExpire.getTime() + (86400 * 1000 * iNumDays));



//==================================================
//SidingColors (Hierarchy in a nutshell)
//			strName
//			strSmallImage
//			strLargeImage
//			ExcludedHouses
//				strHouseID
//				addExcludedHouse()
//			addItem()

//==================================================
//Siding collection
function SidingColors()
{
	this.strNames = new Array();
	this.strSmallImages = new Array();
	this.strLargeImages  = new Array();
	this.ExcludedHouses = new Array();
	this.addItem = SidingColorAdd;
}

function SidingColorAdd(strName, strSmallImage, strLargeImage, ExcludedHouseIDArray)
{
	var iIndex =  this.strNames.length;
	this.strNames[iIndex] = strName;
	this.strSmallImages[iIndex] = strSmallImage;
	this.strLargeImages[iIndex] = strLargeImage;
	this.ExcludedHouses[iIndex] = ExcludedHouseIDArray;
}

//==================================================
//Excluded Houses collection
function ExcludedHouses()
{
	this.strHouseIDs = new Array();
	this.addExcludedHouse = ExcludedHousesAddItem;
}

function ExcludedHousesAddItem(strHouseID)
{
	this.strHouseIDs[this.strHouseIDs.length]=strHouseID;
}


//==================================================
//ShingleTypeList (Hierarchy in a nutshell)
//		types
//			name
//			colors
//				name
//				zipRanges   Z
//					min
//					max
//				addZiprange()  addZ
//			addColor()
//		addTypes()


//======================================
//Shingle color collection
function ShingleTypeList()
{	
	this.types = new Array();
	this.addTypes = ShingleTypeAddItem;
}
function ShingleTypeAddItem(item)
{
	this.types[this.types.length] = item;
}


function ShingleType(name)
{
	//Create a new shingle type.
	this.name = name;
	this.colors = new Array();
	this.addColor = ShingleTypeAddColor;
}

function ShingleTypeAddColor(item)
{
	this.colors[this.colors.length] = item;
}

//======================================
//Shingle color collection
function ShingleColorItem(color,strSmallImage,strLargeImage)
{
	this.name = color;
	this.strSmallImage = strSmallImage;
	this.strLargeImage = strLargeImage;
	this.Z = new Array();
	this.addZ = ZAddItem;
}

//======================================
//Zip Code collection
function ZAddItem(item)
{
	this.Z[this.Z.length]=item;
}

function Z(min,max) //ZipRangeItem
{
	this.min = min;
	this.max = max;
	
}

//======================================
function GetParameter(theStr, param, delim) 
{
	// returns value of param from string
    if (theStr.length == 0) 
	{
		return '';
	}
	
	var iStart = theStr.indexOf(param + "=");
	if (iStart == -1) 
		{return '';}
	iStart = iStart + param.length + 1;
	var iLen = theStr.indexOf(delim, iStart);
	if (iLen == -1) 
		{iLen = theStr.length;}
	return unescape(theStr.substring(iStart, iLen));
}

//=============================================
function CurrentImages()
{
	this.strHouseImage = "contemp.jpg";
	this.strShingleImage = "ShDefault.jpg";
	this.strSidingImage = "SideDefault.jpg";
	this.strTrimImage = "TrimDefault.jpg";
	
	if ( getCookie("HouseSmImage") )
	{
		this.strHouseImage =getCookie("HouseSmImage");
	}
	if ( getCookie("ShingleSmImage") )
	{
		this.strShingleImage = getCookie("ShingleSmImage");
	}
	if ( getCookie("SidingSmImage") )
	{
		this.strSidingImage =getCookie("SidingSmImage");
	}
	if ( getCookie("TrimSmImage") ) 
	{
		this.strTrimImage = getCookie("TrimSmImage");
	}
}

//======================================
//House Collection
function HouseItems()
{	
	this.strSmallImages  = new Array();
	this.strLargeImages  = new Array();
	this.ids = new Array();
	this.addItem = HouseItemAdd;
}
function HouseItemAdd(strSmallImage, strLargeImage, strId)
{
	var iIndex =  this.strSmallImages.length;
	this.strSmallImages[iIndex] = strSmallImage;
	this.strLargeImages[iIndex] = strLargeImage;
	this.ids[iIndex]=strId;
}

//======================================
//Trim Collection
function TrimItems()
{	
	this.strSmallImages = new Array();
	this.strLargeImages  = new Array();
	this.addItem = TrimItemAdd;
}
function TrimItemAdd(strSmallImage, strLargeImage)
{
	var iIndex =  this.strSmallImages.length;
	this.strSmallImages[iIndex] = strSmallImage;
	this.strLargeImages[iIndex] = strLargeImage;
}

//======================================
// Set a cookie given a name, value and 
//expiration date.
//======================================
function setCookie (name, value, expires) 
{
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

//======================================
// Returns the value of the named cookie.
//======================================
function getCookie(name) {

  var search;

  search = name + "="
  offset = document.cookie.indexOf(search) 
  if (offset != -1) {
    offset += search.length ;
    end = document.cookie.indexOf(";", offset) ;
    if (end == -1)
      end = document.cookie.length;
    return unescape(document.cookie.substring(offset, end));
  }
  else
    return "";
}

//======================================
// Delete the named cookie.
//======================================
function deleteCookie(name) {

  var expdate = new Date();
  expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
  setCookie(name, "", expdate);
}
