// 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 parametricNav(theDiv, theButton){
	var paraDiv = document.getElementById(theDiv);
	var paraBtn = document.getElementById(theButton);
	if(paraDiv.style.display == "none"){
		paraDiv.style.display = "block";
		paraBtn.style.backgroundPosition = '0px -14px';
	}else{
		paraDiv.style.display = "none";	
		paraBtn.style.backgroundPosition = '0px 0px';
	}
} 

//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