

var imageSource = '';
var pagename = '';
var firstWord = '';
var firstWord2 = '';
var secondWord =  '';


function PrePopImage()
{
	//alert('1');
	UpdateImage();
	//alert('2');
	if (imageSource != '')
	{
	
		popImage('http://site.bathroom-glass-vanities.com/images/' + imageSource);
		//alert('http://site.bathroom-glass-vanities.com/images/' + imageSource);
	}
}

function UpdateImage()
		{
var img = document.PreviewImage;

if (img != null)
                       {
			//alert("changed");
			
			var dir = window.location.pathname.substring(0,window.location.pathname.lastIndexOf('/')+1);
			
			var lastnum = window.location.pathname.lastIndexOf('--')+1;
			
			if (lastnum !=0) { var url = window.location.pathname.substring(dir.length,lastnum);} else {var url = window.location.pathname.substring(dir.length,window.location.pathname.length+1);};
			//alert(lastnum);
			//alert (url);
			//alert(url.replace(".html","").replace(".htm",""));
			pagename = url.replace(".html","").replace(".htm","");
			//var selectedItem = document.("Color");
			//alert(pagename);


var dd = document.forms[0].elements["Color"];	
			//alert(dd.options[dd.selectedIndex].text);
			firstWord = '';
//if (dd == null) var dd = document.forms[0].elements["Finish"];
//alert(document.forms[1])

if (dd != null)
                       {
if (dd.options[dd.selectedIndex].text.indexOf(' ') != -1)
			{
				//firstWord = '123';
				firstWord = dd.options[dd.selectedIndex].text.substring(0,dd.options[dd.selectedIndex].text.indexOf(" "));
			
			}
			else
			{
				firstWord = dd.options[dd.selectedIndex].text;
			}}
			

//dsdf
var dd2 = document.forms[0].elements["Finish"];	
			//alert(dd.options[dd.selectedIndex].text);
			firstWord2 = '';
//if (dd == null) var dd = document.forms[0].elements["Finish"];
//alert(document.forms[1])

if (dd2 != null)
                       {
if (dd2.options[dd2.selectedIndex].text.indexOf(' ') != -1)
			{
				//firstWord = '123';
				firstWord2 = dd2.options[dd2.selectedIndex].text.substring(0,dd2.options[dd2.selectedIndex].text.indexOf(" "));
			
			}
			else
			{
				firstWord2 = dd2.options[dd2.selectedIndex].text;
			}
			var secondWord =  firstWord2 + '-';
		    //alert(secondWord);
			}

//sdds
if ((dd != null) && (dd2 != null)) {var firstWord = secondWord + firstWord; //alert(firstWord)
}

if (dd != null)
                       {

			imageSource = pagename + '-' + firstWord + '.jpg';

}
                       else
                               imageSource = pagename + '.jpg';
			//alert('[' + firstWord + ']');
			//alert(imageSource);
			img.src = 'http://site.bathroom-glass-vanities.com/images/medium/'+imageSource;
		}}