

/*
   # This Javascript file is used to Call Ajax for the functionality of the Exhaustive attribute
	 selection box.   
   # This File also handle most of the functionality of easy attribute selection box.  
   # This function is used for getting matching attributes list through Ajax for specific attribute
	 id in Exhaustive Attribute Selection Box.
*/

function getattributes(str)
{	
	document.body.style.cursor = "wait";
	var url = '/ajax_handler.php?attributes=' + str;
	new Ajax.Request(url, {
	method: 'get',
	onComplete: function() { 
	document.body.style.cursor = "default";
},  
  onSuccess:function(result) {      
	document.getElementById('exhaustive').innerHTML =result.responseText; 
}
});  
return false ;  
}  
           
//This javascript function is for getting  searched product Name with respect to search text.
function getProductName(attList)
{
 var keyword = document.getElementById("textValue").value;
 window.location.href='index.php?attributes='+attList+'&keywords='+keyword;         
}

function getValue(productName)
{
	productName	= productName;	
	document.getElementById('textValue').value = productName;
}

/*
	Ajax call for Getting Matching attribute list with respect to group_id.
*/

function getAttributefromGroupId(group_id)
{
	document.getElementById('searchAttribute').value='';
	document.getElementById('sort_order').value = '';
	document.body.style.cursor = "wait";
	var url = '/ajax_handler.php?group_id=' + encodeURIComponent(group_id);
	new Ajax.Request(url, {
			method: 'get',
			onComplete: function() 
			{
				document.body.style.cursor = "default";
			},
			onSuccess: function(result) 
			{
				document.getElementById('exhaustive').innerHTML = result.responseText; 
			}
			});
		return false;
}      

/* 
Ajax Call for sorting of an  match attribute_list with respect to  
popularity/attribute display_value.
*/
function sortAttributeList()
{
		var sortorder = document.getElementById('sort_order').value;
		document.body.style.cursor = "wait";
		var url = '/ajax_handler.php?sort_order=' + encodeURIComponent(sortorder);

				new Ajax.Request(url, {
				
				method: 'get',
				onComplete: function() 
							{
								document.body.style.cursor = "default";	
							},
				onSuccess: function(result) 
				{					
					document.getElementById('exhaustive').innerHTML = result.responseText; 
					document.getElementById('sort_order').value = sortorder;				
				}
		});
		return false; 
}

// Ajax Call for finding matching attributes with respect to search text
function filterAttributeList(str)
{
		//document.getElementById('sort_order').value = '';
		var sortorder = document.getElementById('sort_order').value;
		var attrname = str.value  
		var url = '/ajax_handler.php?attr=' + attrname;

		new Ajax.Request(url, {		
		method: 'get',       
		onComplete: function() 
					{
						document.body.style.cursor = "default";
					},
		onSuccess: function(result) 
		{			
			document.getElementById('exhaustive').innerHTML = result.responseText; 
			document.getElementById('searchAttribute').value = str.value;
			document.getElementById('searchAttribute').focus();   
			document.getElementById('sort_order').value = sortorder;		     
		} 
});     
return false;
}   

// For bookmarksite  functionality.
function bookmarksite(title,url)
{
	
   if(navigator.appName !='Microsoft Internet Explorer') 
		{			
			window.sidebar.addPanel(title, url, "")
		}
		else   
		{			
			window.external.AddFavorite(url, title); // IE/Win
		}             
}
// Open pop-up for Exhaustive_Attribute_Selection_Box with respect to attributeGroup_Id.
function modalWin(page)
{
	if (navigator.appName =='Netscape')
	{   
		properties='dialogWidth:750px;dialogHeight:525px;dependent=YES;resizable=yes;scrollbars=yes;toolbar=no;location=no;addressbar=no;directories=no;status=no; linemenubar=no;modal=yes';     
		window.showModalDialog(page,"dialog",properties); 
	}
	else                                                                                                                
	{	  
window.open(page,'dialog','height=525,width=750,dependent=YES,left=150,top=100,resizable=yes,scrollbars=yes,toolbar=no,location=0,directories=no,status=no,linemenubar=no,modal=yes');
	}                         
}                                                          
                     
/*  
	fnSubmit is function that is used to modify parent window url after selecting attributes 
	from Exhaustive[pop-up] for filtering.		
*/
   
function fnSubmit(query_string){   
	if(query_string=='')
	{
	  window.close();
	}
	else
	{
		if(navigator.appName !='Microsoft Internet Explorer') 
		{
			parent.window.opener.location= "index.php?attributes="+query_string;
			window.close();
		}
		else if(navigator.appName =='Netscape')    
		{		
			window.opener.location.pathname = "index.php?attributes="+query_string;
			self.close();   
		}        
		else  
		{     
			if(parent.window.location)
			{  			 
			  parent.window.opener.location="index.php?attributes="+query_string;		  			  			       
			}                          
			window.close();         
		}           
	}    
}
      
/*  
	This "removeFromSession" function is used to remove the selected attribute_id 
	from the session and update the filter attribute_list in the exhaustive pop-up.
*/
function removeFromSession(attribute)
{	
	var url = '/ajax_handler.php?removeAttribute='+encodeURIComponent(attribute)+'&attributes='+encodeURIComponent(attribute); 
	new Ajax.Request(url, {		
	method: 'get',       
	onComplete: function() 
		{
			document.body.style.cursor = "default";
		},
	onSuccess: function(result) 
	{    
	  document.getElementById('exhaustive').innerHTML = result.responseText; 			  
	}   
});        
return false;	
}       
 
//function to check wheather entered value is numeric or not.
function isNumeric(elem){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;  
	}else{
		alert("Enter Numeric Value");
		elem.focus();
		return false;
	}
}

                                   
          



