var ImgNum = 0;
var NewLayoutImg = new Array();


NewLayoutImg[0] = 'images/custom/layouts/range_sml.jpg';
NewLayoutImg[1] = 'images/custom/layouts/citra_ferraraoak_sml.jpg';
NewLayoutImg[2] = 'images/custom/layouts/citra_beech_sml.jpg';
NewLayoutImg[3] = 'images/custom/layouts/forma_white_sml.jpg';
NewLayoutImg[4] = 'images/custom/layouts/forma_cream_sml.jpg';
NewLayoutImg[5] = 'images/custom/layouts/reviva_white_sml.jpg';
NewLayoutImg[6] = 'images/custom/layouts/reviva_cream_sml.jpg';
NewLayoutImg[7] = 'images/custom/layouts/sentia_white_sml.jpg';
NewLayoutImg[8] = 'images/custom/layouts/sentia_cream_sml.jpg';
NewLayoutImg[9] = 'images/custom/layouts/sentia_ferraraoak_sml.jpg';
NewLayoutImg[10] = 'images/custom/layouts/reviva_beech_sml.jpg';
NewLayoutImg[11] = 'images/custom/layouts/forma_beech_sml.jpg';
NewLayoutImg[12] = 'images/custom/layouts/avanti_ferrara_oak_sml.jpg';

function preLoadImages()
{
	var preLoad = new Array()
	var p = NewImg.length

	for (i = 0; i < p; i++)
	{
		preLoad[i] = new Image()
		preLoad[i].src = NewImg[i]
	}
}

function swpImg (id)
{

	if (document.images) 
		document.DoorRange.src = NewImg[id];
}

function setLayoutImg(id)
{
	if (document.images) 
		document.layout.src = NewLayoutImg[id];
}


var elmNum = 1;
function showHideElm(id, action)
{
	if(action == "open")
		document.getElementById(id).style.display = 'block';
	else
		document.getElementById(id).style.display = 'none';
}	




function doNavbgchange(no)
{
	
	document.getElementById("navcell_" + no).style.backgroundColor = '#00A9A7'
}

function doNavbgchangeback(no)
{
	document.getElementById("navcell_" + no).style.backgroundColor = '#ffffff'
}

function takeStep(step)
{
	url = document.location.href;
	
	
		
	var nurl = SetSingleURLParameterValue(url, "step", step);
	
	document.location.href = nurl;
}

function SetSingleURLParameterValue(fullURL, parameterName, parameterValue)
{
	var lowercaseURL = fullURL.toLowerCase();
	var lowercaseParameterName = parameterName.toLowerCase();
	
	
	if (lowercaseURL.indexOf(lowercaseParameterName) != -1)
	{
		var startURL = fullURL.substr(0, lowercaseURL.indexOf(lowercaseParameterName));
		var endURL;
		
		if (fullURL.indexOf("&", lowercaseURL.indexOf(lowercaseParameterName)) != -1)
		{
			// there are more parameters after the one we are looking for
			var endIndex = fullURL.indexOf("&", lowercaseURL.indexOf(lowercaseParameterName));
			endURL = fullURL.substr(endIndex);			
			fullURL = startURL + parameterName + "=" + parameterValue + endURL;
		}
		else
		{
			// this is the last parameter in the list
			fullURL = startURL + parameterName + "=" + parameterValue;
		}
	}
	else
	{	
		// the parameter is not in the list so append it to the end:
		if ((fullURL.charAt(fullURL.length - 1)) != "&")
		{
			fullURL += "&";
		}
		
		fullURL += parameterName + "=" + parameterValue;
	}
	
	return fullURL;
}



function doStepTextChange(step)
{
	if(step != null)
	{
		if(step == "1")
		{
			document.getElementById('helpStps').innerHTML = '<span style=\'width:200\' id=\'stepText\'><font color=\'#D94D36\'><b>STEP 1</b></font><br>BASE UNITS<br>DRAWERLINE SINK BASE UNITS<br>CORNER &amp; ANGLED UNITS<br>MIDI &amp; LARDER UNITS<br>APPLIANCE HOUSING</span>';
			document.getElementById('thecart').style.left = 60;
			
			document.getElementById('helpstep').innerHTML = '<a class=\'clickstep\' href="Javascript: takeStep(\'2\')">Click here to go to step 2 -></a>';
		}
		else if(step == "2")
		{
			document.getElementById('helpStps').innerHTML = '<span style=\'width:200\' id=\'stepText\'><font color=\'#D94D36\'><b>STEP 2</b></font><br>WALL UNITS<br>DRAWERLINE SINK BASE UNITS<br>CORNER WALL & BRIDGING UNITS<br>GLASS & OPEN WALL UNITS<br>INTEGRATED APPLIANCE DRS</span>';
			document.getElementById('thecart').style.left =170;
			
			document.getElementById('helpstep').innerHTML = '<a class=\'clickstep\' href="Javascript: takeStep(\'3\')">Click here to go to step 3 -></a>';
		}
		else if(step == "3")
		{
			document.getElementById('helpStps').innerHTML = '<span style=\'width:200\' id=\'stepText\'><font color=\'#D94D36\'><b>STEP 3</b></font><br>ACCESSORIES<br>&nbsp;<br>&nbsp;</span>';
			document.getElementById('thecart').style.left = 285;
			
			document.getElementById('helpstep').innerHTML = '<a class=\'clickstep\' href="Javascript: goCart()">Go to cart  -></a>';
		}
		
		document.cart.src = "images/custom/cart_step"+step+".gif"
	}
	
	
}


function OpenRange( num )
{
	var url;
	var Target;
	try
	{
		if (num != null )
			Target = document.getElementById('layout'+num).src;
		else
			Target = document.layout.src;	
		
		
		if (Target.lastIndexOf('/') != -1)
		{
			firstpos=Target.lastIndexOf('/')+1;
			lastpos=Target.length;
			
			param = Target.substring(firstpos,lastpos);
			
			
		}
		if( param.lastIndexOf('_') != -1)
		{
			lastpos= param.lastIndexOf('_');
			
			param = param.substring(0,lastpos);
		}
		
		range = GetSingleURLParameterValue(location.href, 'Category');
		url = "range.aspx?lid="+param+"&title="+range;
		window.open (url, "win", "height=440,width=580,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
		
	}
	catch(e)
	{
		alert(e.message);
	}
}




function GetSingleURLParameterValue(fullURL, parameterName)
{
	var value, nameStart, valueStart, valueEnd;
	
	fullURL = fullURL.toLowerCase();
	parameterName = parameterName.toLowerCase();
	
	nameStart = fullURL.indexOf(parameterName);
	
	if (nameStart == -1)
	{
		value = '';
	}
	else
	{
		valueStart = fullURL.indexOf('=', nameStart) + 1;
		
		if (fullURL.indexOf('&', valueStart) != -1)
		{
			valueEnd = fullURL.indexOf('&', valueStart);
			value = fullURL.substr(valueStart, valueEnd - valueStart);			
		}
		else
		{
			value = fullURL.substr(valueStart);
			
		}		
	}
	
	return value;
}


function getCalendarDate()
{
	var months = new Array(13);
	months[0]  = "Jan";
	months[1]  = "Feb";
	months[2]  = "Mar";
	months[3]  = "Apr";
	months[4]  = "May";
	months[5]  = "Jun";
	months[6]  = "Jul";
	months[7]  = "Aug";
	months[8]  = "Sep";
	months[9]  = "Oct";
	months[10] = "Nov";
	months[11] = "Dec";

	var now         = new Date();
	var monthnumber = now.getMonth();
	var monthname   = months[monthnumber];
	var monthday    = now.getDate();
	var year        = now.getYear();
	if(year < 2000) { year = year + 1900; }
	var dateString = monthname +
						' ' +
						monthday +
						', ' +
						year;
	return dateString;
}


