//-----------------------------------------------------------------------------
//									 SEARCH.js
//								Author: Thomas Duc
//								created: Jan 1 2008
//
//						must have the scriptaculous.j installed
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
var additionalRequest = '' ;
var originOfLogin ='';
var isLoggedIn	  = false ;
var last_item_viewed = '';
var isSellingNow = false ;


	function findPosY(obj) 
	{ //inspired by Peter-Paul Koch - www.quirksmode.org
		var curtop = 0;
		if (obj.offsetParent) 
		{
			while (obj.offsetParent) 
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y) {curtop += obj.y;}
		return curtop;
	}

	function moveComments() 
	{
		var form = $('fade');
		var curPos = findPosY(form);
		
		if (window.innerHeight) 
		{
			pos = window.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop) 
		{
			pos = document.documentElement.scrollTop;
		}
		else if (document.body) 
		{
			pos = document.body.scrollTop;
		}
		if(pos > curPos) 
		{
			curPos = pos;
			form.style.top = ++curPos + 'px';
		}
		
		
		if(pos < curPos)
		{
			if(pos > 2) 
			{
				curPos = pos;
				form.style.top = ++curPos + 'px';
			}
			else if(pos <= 2) 
			{
				curPos = pos;
				form.style.top = 2 + 'px';
			}
		}
		var temp = setTimeout('moveComments()',50);
	}
	
	
	//-----------------------------------------------------------------------------
	function checkEmail() 
	{
		email1 = document.registration_form.registration_email_check.value;
		email2 = document.registration_form.registration_email.value;
		if ( email1 == email2) {document.registration_form.email_img.style.display="inline";}
		else document.registration_form.email_img.style.display="none";
	}

	//-----------------------------------------------------------------------------
	function checkPass() 
	{
		if (document.registration_form.registration_password.value==document.registration_form.registration_password_check.value) document.registration_form.pass_img.style.display="inline";
		else document.registration_form.pass_img.style.display="none";
	}
	
	
	//-----------------------------------------------------------------------------
	function checkEmailValidity(email) 
	{
		return (email.indexOf(".") > 2) && (email.indexOf("@") > 0); 	
	}		
	
	
	//-----------------------------------------------------------------------------
	function  askQuestion()
	{
		var form		   = $('ask_question_form');
		var id			   = Form.Element.getValue(form['id']);
		var message		   = Form.Element.getValue(form['message']);
		var question_type  = Form.Element.getValue(form['question_type']);
		var postquestionok = Form.Element.getValue(form['postquestionok']);
		
		//remove potentially dangerous strings from the request
		message = message.replace(/&/,'');

		
		additionalRequest = '&postquestionok=' + postquestionok +
							'&question_type=' + question_type + 
							'&message=' + message +
							'&id=' + id ;							
		 auction_Details(id);
	}
	
	//-----------------------------------------------------------------------------
	function  askQuestionNotLoggedIn(id)
	{
		layer = 'auction_' + id;
		$(layer).style.display= "block";			
		$(layer).update('You need to login in order to ask a question, thank you');
		setTimeout ( "Effect.Fade($(layer), {duration: 1.0,afterFinish: function(evt) {$(layer).style.display = 'none';}})", 3000 );		
	}
	

//-----------------------------------------------------------------------------

	function  auction_Details(id)
	{
		if (id== 0) id = last_item_viewed;
		else last_item_viewed = id ; 
		
		url="auctiondetailstest.php?id=" + id + additionalRequest;
		
		document.getElementById('auction_detail').style.display = 'block';
		document.getElementById('fade').style.display			= 'block';
		$('result_detail').update("<div style='text-align:center;width:750px;height:100%;margin-top:50%'> <img src='themes/idonowidont/img/load.gif' height='32' > </div>");
		
		new Ajax.Request(url, 
		{
			method: 'get',
			onSuccess: function(transport) 
			{
				moveComments();
				$('result_detail').innerHTML = transport.responseText;
			},
			onFailure: function(transport) 
			{
				alert("couldn't communicate with the site, please try again");
			}
		});
		additionalRequest = '';
	}



//-----------------------------------------------------------------------------
// function enabling the bidding interface. 
//
	function  bid_details(id)
	{
		if (id== 0) id = last_item_viewed;
		else last_item_viewed = id ; 
		
		layer = 'auction_' + id;
		
		url="http://www.dev.idonowidont.com/biddetailstest.php?id=" + id + additionalRequest;
				
		$(layer).style.display= "block";			
		$(layer).update('Authenticating...');

								
		new Ajax.Request(url, 
		{
			method: 'get',
			onSuccess: function(transport) 
			{
			
				switch (transport.responseText)
				{
					case 'LOGIN': $(layer).style.display= "block";			
								  $(layer).update('You need to login in order to bid, thank you');
								  setTimeout ( "Effect.Fade($(layer), {duration: 1.0,afterFinish: function(evt) {$(layer).style.display = 'none';}})", 3000 );
								  break;
								  
					case 'CLOSED': $(layer).style.display= "block";			
								  $(layer).update("Sorry, this auction is closed, you can't bid anymore");
								  setTimeout ( "Effect.Fade($(layer), {duration: 1.0,afterFinish: function(evt) {$(layer).style.display = 'none';}})", 3000 );
								  break;
								  
					case 'SELLER': $(layer).style.display= "block";			
								   $(layer).update("You are the seller, you can't bid");
								   setTimeout ( "Effect.Fade($(layer), {duration: 1.0,afterFinish: function(evt) {$(layer).style.display = 'none';}})", 3000 );	
								  break;
					
					case 'RESERVE': $(layer).style.display= "block";			
								   $(layer).update("The reserve price has been reach already, this auction is closed");
								   setTimeout ( "Effect.Fade($(layer), {duration: 1.0,afterFinish: function(evt) {$(layer).style.display = 'none';}})", 3000 );	
								  break;
								  
					default:	
								$('fade').style.display='block';
								moveComments();
								$('bid_details').style.display='block';
								$('bid_details_result').innerHTML = transport.responseText ;
								$(layer).style.display= "none";	
								break;  
				}
				
			},
			onFailure: function(transport) 
			{
				alert("couldn't communicate with the site, please try again");
			}
		});
		
		additionalRequest = '';
	}




//-----------------------------------------------------------------------------
function  watchItem(id)
{
	url="itemwatchtest.php?id=" + id ;
	layer = 'auction_' + id;
	new Ajax.Request(url, 
	{
		method: 'get',
  		onSuccess: function(transport) 
  		{
			$(layer).style.display= "block";			
			$(layer).update(transport.responseText);
			setTimeout ( "Effect.Fade($(layer), {duration: 1.0,afterFinish: function(evt) {$(layer).style.display = 'none';}})", 3000 );
    	},
    	onFailure: function(transport) 
    	{
    		alert("couldn't communicate with the site, please try again");
    	}
   	});	
}


//-----------------------------------------------------------------------------
function cancel()
{
	if ((originOfLogin == 1)|| (originOfLogin == 0) )// login without anything else
	{
		$('fade').style.display = 'none';
	}
	
	$('login_page').style.display = 'none';
}


//-----------------------------------------------------------------------------
function loginMemberArea()
{
	if (isLoggedIn) 
	{
		//already logged in and trying to reach membersarea
		document.location.href='membersareatest.php'; 
	}
	else 
	{
		$('login_page').style.display='block';
	}
}

//-----------------------------------------------------------------------------
function login()
{
	
	url="logintest.php?";
	
	var username = $('username_input').value;
	var password = $('password_input').value;
	post_data = 'username=' + username + '&password=' + password + '&loginok=yes' + '&islogin=yes'  ;
	
	$('login_button_ok').innerHTML="<img src='themes/idonowidont/img/load.gif' height='16' >";
	
	new Ajax.Request(url, 
	{
		method: 'post',
		postBody:post_data,
  		onSuccess: function(transport) 
  		{
			switch (transport.responseText)
			{
				case 'INVALID LOGIN' :
									$('login_page').style.background = "#e93605";
									setTimeout ( "$('login_page').style.background = '#cccccc';", 200 );
									$('username_input').value = '';
									$('password_input').value = '';
									
									
									$('login_result_message').innerHTML =   transport.responseText;
									$('login_result_message').style.display = "block";
									setTimeout ( "Effect.Fade($('login_result_message'), {duration: 1.0,afterFinish: function(evt) {$('login_result_message').style.display = 'none';}})",2500 ); 										break; 
										
				default:			
									// This section establishes which layer called the login window 
									switch (originOfLogin)
									{
										case 0 :document.location.href='membersareatest.php'; break;	// memebers area
										case 1 : $('fade').style.display = 'none'; 
												 $('register_item').style.display = 'none'; 
												 break;													// login without anything else
										case 2 : auction_Details(0); break;								// inside auctionDetails,reload div
										case 3 : $('login_before_sell').style.display = 'none';			// selling process, do nothing but replace old value
												 $('register_before_sell').style.display = 'none';
												 $('publish_button').style.display = 'block';
												 break;
										case 4 : history.go(0); break;				// identify the user in the paypal system
												 
									}

									isLoggedIn = true ; // the user is now loggedin
									$('login_page').style.display = 'none';
									$('login_item').style.display = 'none';
									$('logout_item').style.display = 'block';
									

									$('login_item_sell').innerHTML = '<a href="javascript:document.location.href=\'http://www.idonowidont.com/newsite.php?option=logout\'">LOGOUT</a>';
									
									$('pwd_item').innerHTML = "<a href=\"javascript:document.location.href='www.idonowidont.com/membersareatest.php'\">MEMBER AREA</a>";
									$('publish_button').style.display = 'block';
									$('authenticate_sell').style.display='none';
									break;	
			}
				$('login_button_ok').innerHTML="";
    	},
    	onFailure: function(transport) 
    	{
    		alert("couldn't communicate with the site, please try again");
			$('login_button_ok').innerHTML="";
    	}
   	});	

		
}
//-----------------------------------------------------------------------------
// function rgister, this function register the new user to the system
function registerUser()
{
	url="registertest.php?option=submit_user";
	var post_data = '';
	
	var accounttype					= $('accounttype').value;
	accounttype = 'Individual';
	
	var registration_full_name		= $('registration_full_name').value;
	var registration_address		= $('registration_address').value;
	var registration_city			= $('registration_city').value;
	var registration_state			= $('registration_state').value;
	var registration_zip			= $('registration_zip').value;
	var registration_email			= $('registration_email').value;
	var registration_email_check	= $('registration_email_check').value;
	var registration_news_letter	= $('registration_news_letter').value;
	var registration_username		= $('registration_email').value; //$('registration_username').value;
	var registration_password		= $('registration_password').value;
	var registration_password_check = $('registration_password_check').value;
	var registration_year			= $('registration_year').value;
	var pin_value					= $('pin_value').value;
	var pin2						= $('pin2').value;
	var ack_terms					= $('ack_terms').checked;
	var registerok					=  "Register";//$('registerok').value;

	
	if (!checkEmailValidity(registration_email))
	{
		alert( 'your email is incorrect, please verify');
	}
	else
	{
	
	if (ack_terms.checked == false) 
	{
		alert ('You need to agree with the terms of service to register, YO')	
	}
	else
	{
	
	if (registration_username == '')
	{
		alert ('Enter a username please')	
	}
	else
	{
		
	if (registration_password == '')
	{
		alert ('Enter a password please')	
	}
	else
    if (pin2 == '')
	{
		alert ('Type the pin please')	
	}
	else
	{
		$('registration_button_img').style.display = 'block';
		
		post_data ='registerok=Submit&registration_full_name=' + registration_full_name +
			   '&registration_address=' + registration_address +			  
			   '&registration_city=' + registration_city + 
			   'mars&registration_state=' + registration_state + 
			   '&registration_zip=' + registration_zip + 
			   '&registration_email=' + registration_email +
			   '&registration_news_letter=' + registration_news_letter + 
			   '&registration_username=' + registration_username + 
			   '&registration_password=' + registration_password + 
			   '&pin_value='+ pin_value + '&pin2='+ pin2 +
			   '&year=' + registration_year +
			   '&ack_terms='+ ack_terms;
				
			new Ajax.Request(url, 
			{	
				method: 'post',
				postBody:post_data,
				onSuccess: function(transport) 
				{
					switch(transport.responseText)
					{
						case 'USER' : alert('sorry, this username is already taken, please choose another one');
									break;
								  
						case 'EMAIL': alert('sorry, '+ registration_email +' is already used, please choose another one');
									break;
								  
						case  'PIN' :alert('please enter the pin as marked')
									break;
									
									
						default:	
									alert(transport.responseText);
									
									// if in the middle of selling, finishes the sell process
									if (isSellingNow)
									{
										$('sell_item_interface').style.display  = 'block' ;
										$('publish_button').style.display		= 'block' ;
										$('authenticate_sell').style.display	= 'none'  ;
										isSellingNow = false;
									}
									else
									{	
                                        if(originOfLogin !=2)
                                        {
                                            $('fade').style.display="none";
                                        }
                                        else
                                        {
                                            //if registration was done inside an auction
                                            $('register_auction_detail').style.display="none";
                                            $('login_auction_detail').style.display="none";
                                        }
                                        
									}
									
									$('light').style.display="none";
									$('registration_full_name').value ='';
									$('registration_address').value ='';
									$('registration_city').value ='';
									$('registration_state').value ='';
									$('registration_zip').value ='';
									$('registration_email').value ='';
									$('registration_email_check').value ='';
									$('registration_news_letter').value ='';
									//$('registration_username').value ='';
									$('registration_password').value ='';
									$('registration_password_check').value ='';
									$('registration_year').value ='';
									//$('pin_value').value ='';
									
									//$('registration_pin').value ='';
									$('ack_terms').checked ='';
									$('registerok').value ='';
									break;
					}
				},
				onFailure: function(transport) 
				{
					alert("couldn't communicate with the site, please try again");
				}
			});	
			$('registration_button_img').style.display = 'none';
	
		}
		}
	}
	}
}





//-----------------------------------------------------------------------------
function emailAFriend(id, ownedby)
{
	url="auctionfriendtest.php?";
	var post_data = '';
	var layer = 'auction_' + id;
	
	if (ownedby == -1)
	{
		var form = $('send_email_form');
		
		var name = Form.Element.getValue(form['friendname']);
		var email = Form.Element.getValue(form['friendemail']);
		var comments = escape( Form.Element.getValue(form['comments']));
		
		var auctionid = Form.Element.getValue(form['auctionid']); 
		var ownerid = Form.Element.getValue(form['ownerid']); 
		var postquestionok = Form.Element.getValue(form['postquestionok']); 
		
		post_data = 'postquestionok=' + postquestionok + '&friendname=' + name + '&friendemail=' + email + '&comments=' + comments + '&auctionid=' + id;
	}
	else
	{
			post_data+= 'owner=' + ownedby + '&auctionid=' + id;
	}



	
	new Ajax.Request(url, 
	{
		method: 'post',
		postBody:post_data,
  		onSuccess: function(transport) 
  		{
			if (transport.responseText == "LOGIN")
			{
				$('send_email').update("<div style='width:100%;text-align:center;margin-top:110px'>You need to login to email</div>");
                $('send_email').style.display = 'inline';
				setTimeout ( "Effect.Fade($('send_email'), {duration: 1.0,afterFinish: function(evt) {$('send_email').style.display = 'none';}})", 2500 );
			}
			else
			{
				$('send_email').style.display= "block";			
				$('send_email').update(transport.responseText);
				if (id == -1)
				{
					setTimeout ( "Effect.Fade($('send_email'), {duration: 1.0,afterFinish: function(evt) {$('send_email').style.display = 'none';}})", 2500 );
				}
			}
		},
    	onFailure: function(transport) 
    	{
    		alert("couldn't communicate with the site, please try again");
    	}
   	});	

}



//----------------------------------------------------------------------------
//--  OBJECTS
//--  SEARCH_QUERY :
//--  Object used to exchange data between the server and the  page 
//----------------------------------------------------------------------------

function search_query() 
{
	//PROPERTIES
	this.menu0		= ""; //default value
	this.menu1		= "";
	this.menu2		= "";
	this.menu3		= "";
	this.menu4 	    = "";
	this.menu5 	    = "";
	this.menu6 	    = "";
	
	this.request    = "";
    
	this.page	   =  1;
	
    this.ordername  = '';
    this.orderType  = 'DESC';
	
 	//--FUNCTIONS
	this.send       = search_item  ; 		// sends to the server via a string
	this.order		= order_item   ;
	this.clear		= search_clear ;
}
var query  = new search_query() ;
var Image1 = new Image(30,30)   ;
Image1.src = 'themes/idonowidont/img/load.gif' ;


//----------------------------------------------------------------------------
function order_item(item_to_order)
{
	this.ordername = item_to_order;
	search_item('', '');
}


//----------------------------------------------------------------------------
// function used when switching major category (wedding dress and Jewelry)
function search_clear(root)
{
	query.page	   =  1;
	query.menu1    = "";
	query.menu2    = ""  ;
	query.menu3	   = ""  ;
	query.menu4    = ""  ;
	query.menu5    = ""  ;
	query.menu6    = ""  ;
	query.request  = ""  ;
	//search_item(root,'menu0');
}


//--------------------------- search item--------------------------------
function search_item(element, menu)
{
	//empty the query if we change category
	if (menu == 'menu1') 
	{
		//if (element == 'Wedding Dresses') query.menu0 = 'Wedding Dresses';
		//else query.menu0 = 'Jewelry';
		query.menu1    = ""  ;
		query.menu2    = ""  ;
		query.menu3	   = ""  ;
		query.menu4    = ""  ;
		query.menu5    = ""  ;
		query.menu6    = ""  ;
	}
	
	query[menu]   = element;
	query.request = '' ; 
	tab			  = "";
	
	
	if(query.menu1 !=  "") 
	{
		if (query.request != "") tab = "|";  
		query.request +=  tab + query.menu1;
		
		switch(query.menu1)
		{
		
			case 'Wedding Dresses':
				$('color_menu').style.display	= "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display		= "none";
				$('shape_menu').style.display	= "none";
				$('weight_menu').style.display	= "none";
				$('stone_menu').style.display	= "none";
				$('metal_menu').style.display	= "none";	
				$('gender_menu').style.display	= "none";								
				$('style_menu').style.display	= "none";
				$('band_menu').style.display	= "none";		
				$('dress_size').style.display	= "block";		
				$('dress_color').style.display	= "block";
				$('dress_style').style.display	= "block";
				break;
				
				
			case 'Jewelry':
				$('color_menu').style.display	= "block";
				$('clarity_menu').style.display = "block";
				$('cut_menu').style.display		= "block";
				$('shape_menu').style.display	= "block";
				$('weight_menu').style.display	= "block";
				$('stone_menu').style.display	= "block";
				$('metal_menu').style.display	= "none";	
				$('gender_menu').style.display	= "none";								
				$('style_menu').style.display	= "none";
				$('band_menu').style.display	= "none";		
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";
				
				break;
		
			case 'Diamond Rings':
				$('color_menu').style.display	= "block";
				$('clarity_menu').style.display = "block";
				$('cut_menu').style.display		= "block";
				$('shape_menu').style.display	= "block";
				$('weight_menu').style.display	= "block";
				$('stone_menu').style.display	= "none";
				$('metal_menu').style.display	= "none";	
				$('gender_menu').style.display	= "none";								
				$('style_menu').style.display	= "none";
				$('band_menu').style.display	= "none";		
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";				
				break;

				
			case 'Loose Diamonds':		
				$('color_menu').style.display	= "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display		= "none";
				$('style_menu').style.display	= "none";
								
				$('shape_menu').style.display	= "block";
				$('weight_menu').style.display	= "block";
				
				$('stone_menu').style.display	= "none";
				$('metal_menu').style.display	= "none";	
				$('gender_menu').style.display	= "none";
				$('band_menu').style.display	= "none";	
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";																
				break;
							
			case 'Gemstone Rings':
				$('color_menu').style.display	= "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display		= "none";
				$('shape_menu').style.display	= "none";
				$('weight_menu').style.display	= "none";
				$('gender_menu').style.display	= "none";
				$('style_menu').style.display	= "none";
				$('dress_size').style.display	= "none";				
				$('dress_color').style.display	= "none";																						
				$('stone_menu').style.display   = "block";
				$('metal_menu').style.display   = "block";												
				$('band_menu').style.display	= "none";		
				$('dress_style').style.display	= "none";				
				break;

			case 'Wedding Bands':			
				$('color_menu').style.display   = "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display     = "none";
				$('shape_menu').style.display   = "none";
				$('weight_menu').style.display  = "none";
				$('stone_menu').style.display   = "none";
				$('style_menu').style.display   = "none";
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";				
							
				$('metal_menu').style.display  = "block";			
				$('gender_menu').style.display = "block";	
				$('band_menu').style.display   = "block";						
										
				break;
				
			case 'Bracelets':
			case 'Necklaces':
				$('color_menu').style.display   = "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display     = "none";
				$('shape_menu').style.display   = "none";
				$('weight_menu').style.display  = "none";
				$('style_menu').style.display   = "none";
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";				
				
				$('stone_menu').style.display   = "block";
				$('metal_menu').style.display   = "block";			
				$('gender_menu').style.display  = "block";
	
				break;
	
			case 'Earrings':
			
				$('color_menu').style.display	= "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display		= "none";
				$('shape_menu').style.display   = "none";
				$('weight_menu').style.display  = "none";
				$('gender_menu').style.display  = "none";
				$('band_menu').style.display	= "none";		
				$('band_menu').style.display	= "none";	
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";				
								
				$('style_menu').style.display  = "block";
				$('stone_menu').style.display  = "block";
				$('metal_menu').style.display  = "block";			
				
				break;
										
		}
		
	}
	
	if(query.menu2 !=  "") 
	{
		if (query.request != "") tab = "|";  
		query.request +=  tab + query.menu2;
	}
	if(query.menu3 !=  "") 
	{
		if (query.request != "") tab = "|";  
		query.request +=  tab + query.menu3;
	}
	if(query.menu4 !=  "")
	{
		if (query.request != "") tab = "|";  
		query.request +=  tab + query.menu4;
	}
	
	
	if(query.menu5 !=  "")
	{
		if (query.request != "") tab = "|";  
		query.request +=  tab + query.menu5;
	}
	
	if(query.menu6 !=  "")
	{
		if (query.request != "") tab = "|";  
		query.request +=  tab + query.menu6;
	}
	
	query.request += "&page=" + query.page;

	
	if (query.ordername != "") 
	{
		if (query.orderType == 'DESC') query.orderType = 'ASC';
		else query.orderType = 'DESC' ;
		query.request += "&orderFilter=" + query.ordername + "&orderType=" + query.orderType  ;

	}
	
}
var xmlHttp; 

function ajaxFunction()
{
  
  var xmlHttp;
  
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
return xmlHttp;
}
function search_item00(element, menu)
{
	xmlHttp=ajaxFunction()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	 return
	}
	xmlHttp.onreadystatechange=function()
    {
      if(xmlHttp.readyState==4)
        {
		 var result=xmlHttp.responseText;
	
	document.getElementById('resultset').innerHTML=result;
	//alert(result);
        }
    }
		//alert("test");	
				//empty the query if we change category
		if (menu == 'menu1') 
		{
			//if (element == 'Wedding Dresses') query.menu0 = 'Wedding Dresses';
			//else query.menu0 = 'Jewelry';
			query.menu1    = ""  ;
			query.menu2    = ""  ;
			query.menu3	   = ""  ;
			query.menu4    = ""  ;
			query.menu5    = ""  ;
			query.menu6    = ""  ;
		}
		
		query[menu]   = element;
		query.request = '' ; 
		tab			  = "";
		
		
		if(query.menu1 !=  "") 
		{
			if (query.request != "") tab = "|";  
			query.request +=  tab + query.menu1;
			
		
			switch(query.menu1)
		{
		
			case 'Wedding Dresses':
				$('color_menu').style.display	= "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display		= "none";
				$('shape_menu').style.display	= "none";
				$('weight_menu').style.display	= "none";
				$('stone_menu').style.display	= "none";
				$('metal_menu').style.display	= "none";	
				$('gender_menu').style.display	= "none";								
				$('style_menu').style.display	= "none";
				$('band_menu').style.display	= "none";
				$('stone_brace').style.display   ="none";
				$('stone_neck').style.display   = "none";
				$('stone_ear').style.display  = "none";
				$('weight_ld').style.display	= "none";
				$('dress_size').style.display	= "block";		
				$('dress_color').style.display	= "block";
				$('dress_style').style.display	= "block";
				$('brand_menu').style.display  = "none";
				break;
				
				
			case 'Jewelry':
				$('color_menu').style.display	= "block";
				$('clarity_menu').style.display = "block";
				$('cut_menu').style.display		= "block";
				$('shape_menu').style.display	= "block";
				$('weight_menu').style.display	= "block";
				$('stone_menu').style.display	= "block";
				$('metal_menu').style.display	= "none";	
				$('gender_menu').style.display	= "none";								
				$('style_menu').style.display	= "none";
				$('band_menu').style.display	= "none";		
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";
				$('stone_brace').style.display   = "none";
				$('weight_ld').style.display	= "none";
				$('stone_neck').style.display   = "none";
				$('stone_ear').style.display  = "none";
				$('brand_menu').style.display  = "none";
				
				break;
		
			case 'Diamond Rings':
				
				$('weight_menu').style.display	= "block";
				$('color_menu').style.display	= "block";
				$('clarity_menu').style.display = "block";
				$('cut_menu').style.display		= "block";
				$('shape_menu').style.display	= "block";
				$('stone_menu').style.display	= "none";
				$('metal_menu').style.display	= "none";	
				$('gender_menu').style.display	= "none";								
				$('style_menu').style.display	= "none";
				$('band_menu').style.display	= "none";		
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";
				$('stone_brace').style.display   = "none";
				$('weight_ld').style.display	= "none";
				$('stone_neck').style.display   = "none";
				$('stone_ear').style.display  = "none";
				$('brand_menu').style.display  = "none";
				break;

				
			case 'Loose Diamonds':		
				$('color_menu').style.display	= "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display		= "none";
				$('style_menu').style.display	= "none";
								
				$('shape_menu').style.display	= "block";
				$('weight_menu').style.display	= "none";
				$('weight_ld').style.display	= "block";
				
				$('stone_menu').style.display	= "none";
				$('metal_menu').style.display	= "none";	
				$('gender_menu').style.display	= "none";
				$('band_menu').style.display	= "none";	
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";
				$('stone_brace').style.display   = "none";
				$('stone_neck').style.display   = "none";
				$('stone_ear').style.display  = "none";
				$('brand_menu').style.display  = "none";
				break;
							
			case 'Gemstone Rings':
				$('color_menu').style.display	= "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display		= "none";
				$('shape_menu').style.display	= "none";
				$('weight_menu').style.display	= "none";
				$('gender_menu').style.display	= "none";
				$('style_menu').style.display	= "none";
				$('dress_size').style.display	= "none";				
				$('dress_color').style.display	= "none";																						
				$('stone_menu').style.display   = "block";
				$('metal_menu').style.display   = "block";												
				$('band_menu').style.display	= "none";		
				$('dress_style').style.display	= "none";
				$('stone_brace').style.display   = "none";
				$('stone_neck').style.display   = "none";
				$('weight_ld').style.display	= "none";
				$('stone_ear').style.display  = "none";
				$('brand_menu').style.display  = "none";
				break;

			case 'Wedding Bands':			
				$('color_menu').style.display   = "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display     = "none";
				$('shape_menu').style.display   = "none";
				$('weight_menu').style.display  = "none";
				$('stone_menu').style.display   = "none";
				$('style_menu').style.display   = "none";
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";
				$('stone_brace').style.display   = "none";
				$('weight_ld').style.display	= "none";
				$('stone_neck').style.display   = "none";
				$('stone_ear').style.display  = "none";
				$('brand_menu').style.display  = "none";
							
				$('metal_menu').style.display  = "block";			
				$('gender_menu').style.display = "block";	
				$('band_menu').style.display   = "block";	
				
										
				break;
				
			case 'Bracelets':
				$('color_menu').style.display   = "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display     = "none";
				$('shape_menu').style.display   = "none";
				$('weight_menu').style.display  = "none";
				$('style_menu').style.display   = "none";
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";
				$('band_menu').style.display   = "none";
				$('weight_ld').style.display	= "none";
				$('stone_neck').style.display   = "none";
				$('stone_ear').style.display  = "none";
				
				$('stone_menu').style.display   = "none";
				$('stone_brace').style.display   = "block";
				$('metal_menu').style.display   = "block";			
				$('gender_menu').style.display  = "block";
				$('brand_menu').style.display  = "none";
	
				break;
			case 'Necklaces':
				$('color_menu').style.display   = "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display     = "none";
				$('shape_menu').style.display   = "none";
				$('weight_menu').style.display  = "none";
				$('style_menu').style.display   = "none";
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";
				$('band_menu').style.display   = "none";
				$('weight_ld').style.display	= "none";
				$('stone_ear').style.display  = "none";
				
				$('stone_menu').style.display   = "none";
				$('stone_brace').style.display   = "none";
				$('stone_neck').style.display   = "block";
				$('metal_menu').style.display   = "block";			
				$('gender_menu').style.display  = "block";
				$('brand_menu').style.display  = "none";
	
				break;
	
			case 'Earrings':
			
				$('color_menu').style.display	= "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display		= "none";
				$('shape_menu').style.display   = "none";
				$('weight_menu').style.display  = "none";
				$('gender_menu').style.display  = "none";
				$('band_menu').style.display	= "none";		
				$('band_menu').style.display	= "none";	
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";
				$('weight_ld').style.display	= "none";
				$('stone_neck').style.display   = "none";
				$('stone_brace').style.display   = "none";
				$('stone_menu').style.display  = "none";
					
				
				$('stone_ear').style.display  = "block";
				$('style_menu').style.display  = "block";
				$('metal_menu').style.display  = "block";
				$('brand_menu').style.display  = "none";
						
				
				break;
				case 'Watches':
			
				$('color_menu').style.display	= "none";
				$('clarity_menu').style.display = "none";
				$('cut_menu').style.display		= "none";
				$('shape_menu').style.display   = "none";
				$('weight_menu').style.display  = "none";
				$('gender_menu').style.display  = "block";
				$('brand_menu').style.display  = "block";
				$('band_menu').style.display	= "none";		
				$('dress_size').style.display	= "none";
				$('dress_color').style.display	= "none";
				$('dress_style').style.display	= "none";
				$('weight_ld').style.display	= "none";
				$('stone_neck').style.display   = "none";
				$('stone_brace').style.display   = "none";
				$('stone_menu').style.display  = "none";
					
				
				$('stone_ear').style.display  = "none";
				$('style_menu').style.display  = "none";
				$('metal_menu').style.display  = "none";
				
						
				
				break;
										
		}
			
		}
		
		if(query.menu2 !=  "") 
		{
			if (query.request != "") tab = "|";  
			query.request +=  tab + query.menu2;
		}
		if(query.menu3 !=  "") 
		{
			if (query.request != "") tab = "|";  
			query.request +=  tab + query.menu3;
		}
		if(query.menu4 !=  "")
		{
			if (query.request != "") tab = "|";  
			query.request +=  tab + query.menu4;
		}
		
		
		if(query.menu5 !=  "")
		{
			if (query.request != "") tab = "|";  
			query.request +=  tab + query.menu5;
		}
		
		if(query.menu6 !=  "")
		{
			if (query.request != "") tab = "|";  
			query.request +=  tab + query.menu6;
		}
		
		query.request += "&page=" + query.page;

		
		if (query.ordername != "") 
		{
			if (query.orderType == 'DESC') query.orderType = 'ASC';
			else query.orderType = 'DESC' ;
			query.request += "&orderFilter=" + query.ordername + "&orderType=" + query.orderType  ;

		}
		
		url="stonecategories.php?category=" + query.request ;
					
				//alert(url);
				xmlHttp.open("GET",url,true);
				xmlHttp.send(null)	
			
				
		}

