// JavaScript Document
// JavaScript Document
Event.observe(window,'load',function(){
	if (document.getElementById("product-search") != null) {
		document.getElementById("product-search").onchange = function() {
		 // get the current URL
			var sParam = this.value;
			var url = window.location.toString(); //get the parameters 
			url.match(/\?(.+)$/); 
			var base = url.substring(0,url.indexOf("?")+1);
			var params = RegExp.$1;
			// split up the query string and store in an 
			// associative array 
			var params = params.split("&"); 
			var queryStringList = {}; 
			for(var i=0;i<params.length;i++) { 
				var tmp = params[i].split("=");
				if(i!=0 && tmp[0]!="sort") {
					base = base + "&";
				}
				if(tmp[0]!="sort") {
					base = base + params[i];
				}
			}
			base = base + "&sort=" + sParam;
			window.location.href = base;
		}
	}
},false)

function showGrid()
{
		document.getElementById('compare2').style.display = 'none';
		document.getElementById('grid2').style.display = 'block';
		document.getElementById('sidebar2').style.display = 'block';
		
		document.getElementById('productGrid').style.width = '537px';
		document.getElementById('productView').style.width = '539px';
		document.getElementById('productView').style.margin = '0px 17px 0px 22px';
		
		document.getElementById('productGrid').style.backgroundImage = "url(../images/family/top_grad.gif)";
		document.getElementById('productView').style.backgroundImage = "url(../images/family/btm_rnd.gif)";
				
        document.getElementById('grid').style.backgroundImage = "url(../images/family/grid.gif)";
		document.getElementById('grid').style.backgroundPosition = "0px 0px";
		document.getElementById('grid').style.width = "270px";
		
		document.getElementById('compare').style.backgroundImage = "url(../images/family/grid.gif)";
		document.getElementById('compare').style.backgroundPosition = "-270px 0px";
		document.getElementById('compare').style.width = "270px";

		document.getElementById('viewMenu').style.width = "540px";
		
		/* Ugly hacks... */
		document.getElementById('productViewRoundBtm').style.width = '738px';
		document.getElementById('productViewRoundBtmImg').src = '/images/family/btm_rnd2.gif';
				
		updateViewStatus('grid');
}

function showCompare()
{		
		document.getElementById('grid2').style.display = 'none';
		document.getElementById('compare2').style.display = 'inline';
		document.getElementById('sidebar2').style.display = 'none';
		
		document.getElementById('productGrid').style.width = '736px';
		document.getElementById('productView').style.width = '738px';
		document.getElementById('productView').style.margin = '0px 0px 0px 22px';
		
		document.getElementById('productGrid').style.backgroundImage = "url(../images/family/top_gradExt.gif)";
		document.getElementById('productView').style.backgroundImage = "url(../images/family/btm_rndExt.gif)";
		
        document.getElementById('compare').style.backgroundImage = "url(../images/family/compareWide.gif)";
		document.getElementById('compare').style.backgroundPosition = "-370px 0px";
		document.getElementById('compare').style.width = "370px";
		
		document.getElementById('grid').style.backgroundImage = "url(../images/family/compareWide.gif)";
		document.getElementById('grid').style.backgroundPosition = "0px 0px";
		document.getElementById('grid').style.width = "370px";
		
		document.getElementById('viewMenu').style.width = "740px";
		
		/* Ugly hacks... */
		document.getElementById('productViewRoundBtm').style.width = '738px';
		document.getElementById('productViewRoundBtmImg').src = '/images/family/blueRoundBottom.gif';

		if(Object.isUndefined(Irbt.family_compare_scrollbar)){
			irbt_scrollbar_builder();
		}
		
		updateViewStatus('compare');
		
}


//Start - The AJAX Code added for setting the view Status in the Session
function createXMLHttpRequest()
{
    if (window.ActiveXObject)
    {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest)
    {
        xmlHttp = new XMLHttpRequest();
    }
}

function updateViewStatus(viewStatus) 
{
    try
    {       
        createXMLHttpRequest(); 
    }
    catch(e)
    {
        alert("Your browser does not support AJAX.");
    }   
    
	queryString = "../family/viewStatusProcess.jsp?viewStatus="+viewStatus;


    xmlHttp.onreadystatechange = updateAction;  
    try
    {
        xmlHttp.open("GET", queryString, true);
        // setRequestHeader() is for Safari, so rapid xmlHttp requests don't logjam in the browser.
        xmlHttp.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT');
        xmlHttp.send(null);
    }
    catch(e)
    {
        alert("Your browser does not support AJAX.");
    }
}

function updateAction()
{
    if(xmlHttp.readyState == 4)
    {           
        if(xmlHttp.status == 200)
        {
		//	alert("success");
        }
        else
        {
            alert("Unable to retrieve a response from the server.");
        }
    }   
}
//End - The AJAX Code added for setting the view Status in the Session