//--------------------------------------------- 组合出完整的查询条件 ----------------------------------------------------
function fun_query(frm)
{
  var strquery=" and ";
  var arrRegions;
  strquery = strquery + fun_getvalue(frm.dr_varietal.options[frm.dr_varietal.selectedIndex].value,"","main_varietal_id","i","=");
  
  if(frm.dr_region.options[frm.dr_region.selectedIndex].value != "")
  {
    arrRegions=(frm.dr_region.options[frm.dr_region.selectedIndex].value).split(",");
    if(arrRegions[1] == 0 & arrRegions[2] == 0) strquery = strquery + " and " + fun_getvalue(arrRegions[0],"","nation","i","=");
    if(arrRegions[1] != 0 & arrRegions[2] == 0)
      {
        strquery = strquery + " and " + fun_getvalue(arrRegions[0],"","nation","i","=");
        strquery = strquery + " and " + fun_getvalue(arrRegions[1],"","city","i","=");
      }
    if(arrRegions[1] != 0 & arrRegions[2] != 0)
      {
        strquery = strquery + " and " + fun_getvalue(arrRegions[0],"","nation","i","=");
        strquery = strquery + " and " + fun_getvalue(arrRegions[1],"","city","i","=");
        strquery = strquery + " and " + fun_getvalue(arrRegions[2],"","region","i","=");
      }
  }
  
  strquery = strquery + " and " + fun_getvalue(frm.dr_type.options[frm.dr_type.selectedIndex].value,"","wine_type_id","i","=");
  strquery = strquery + " and " + fun_getvalue(frm.dr_winery.options[frm.dr_winery.selectedIndex].value,"","winery_id","i","=");
  
  if(frm.dr_vintage1.options[frm.dr_vintage1.selectedIndex].value != "" & frm.dr_vintage2.options[frm.dr_vintage2.selectedIndex].value != "") 
    { strquery = strquery + " and " + fun_getvalue(frm.dr_vintage1.options[frm.dr_vintage1.selectedIndex].value,frm.dr_vintage2.options[frm.dr_vintage2.selectedIndex].value,"vintage","i","between"); }
  if(frm.dr_vintage1.options[frm.dr_vintage1.selectedIndex].value != "" & frm.dr_vintage2.options[frm.dr_vintage2.selectedIndex].value == "") 
    { strquery = strquery + " and " + fun_getvalue(frm.dr_vintage1.options[frm.dr_vintage1.selectedIndex].value,3000,"vintage","i","between"); }
  if(frm.dr_vintage1.options[frm.dr_vintage1.selectedIndex].value == "" & frm.dr_vintage2.options[frm.dr_vintage2.selectedIndex].value != "") 
    { strquery = strquery + " and " + fun_getvalue(1000,frm.dr_vintage2.options[frm.dr_vintage2.selectedIndex].value,"vintage","i","between"); }
  
  if(frm.dr_price.options[frm.dr_price.selectedIndex].value != "") strquery = strquery + " and " + fun_getvalue(arrPrice[parseInt(frm.dr_price.options[frm.dr_price.selectedIndex].value) * 2 - 1],arrPrice[parseInt(frm.dr_price.options[frm.dr_price.selectedIndex].value) * 2],"price","i","between");

  frm.txtQuery.value = strquery;
}

//--------------------------- Reset操作，清空各种查询条件 --------------------------
function fun_reset(theform)
{
  document.frm_keywords.txt_keywords.value="";
	theform.dr_varietal.options[0].selected=true;
  theform.dr_region.options[0].selected=true;
  theform.dr_type.options[0].selected=true;
  theform.dr_winery.options[0].selected=true;
  theform.dr_vintage1.options[0].selected=true;
  theform.dr_vintage2.options[0].selected=true;
  theform.dr_price.options[0].selected=true;
}

//-------------------- 显示消息层，时间为5秒 -----------------------
var MyInterval="";
function fun_confirm(pid,point,category)
{
  window.open('b_save_value.asp?pid=' + pid + '&nocache=' + No_cache(),'','height=0,width=0,top=2200,left=1810');
  //if(category!=1)
 // txt_point.value = 0;
//  else
  txt_point.value = point;
	
  define_posotion();
	if(popbox.style.display == 'block') popbox.style.display='none';
	
	if(MyInterval!=""){
		window.clearInterval(MyInterval);
		MyInterval="";
	}
	
  popbox.style.display='block';
  MyInterval = window.setInterval("popbox.style.display='none';",5000) 	
}
//-------------------- 加入MY FAVORITES用,显示消息层，时间为5秒 -----------------------
var MyInterval="";
function fun_add_to_favorites(pid)
{
  window.open('add_to_favorites.asp?pid=' + pid +  '&nocache=' + No_cache(),'','height=0,width=0,top=2200,left=1810');
 
	
  define_posotion1();
	if(popbox1.style.display == 'block') popbox1.style.display='none';
	
	if(MyInterval!=""){
		window.clearInterval(MyInterval);
		MyInterval="";
	}
	
  popbox1.style.display='block';
  MyInterval = window.setInterval("popbox1.style.display='none';",5000) 	
}

//---------------------- 弹出窗口的位置确定 ------------------------
function define_posotion()
{
  var newX,newY

  newX = (document.body.clientWidth-90)/2;              
  newY = (document.body.clientHeight-80)/2 + document.body.scrollTop;           
  
  popbox.style.left=newX;           
  popbox.style.top=newY;
}
//---------------------- 弹出窗口的位置确定 ------------------------
function define_posotion1()
{
  var newX,newY

  newX = (document.body.clientWidth-90)/2;              
  newY = (document.body.clientHeight-80)/2 + document.body.scrollTop;           
  
  popbox1.style.left=newX;           
  popbox1.style.top=newY;
}

//-------------------- 进行关键词查询 -----------------------
function fun_keywords(theform)
{
   if(theform.txt_keywords.value == "")
    { 
	  alert("Please enter the key words you want to search for. ");
	  return false;
	}
  else
    {
      var searchfor,i,keyword,condition;
      condition="";
      searchfor =  theform.txt_keywords.value.replace("'","''");
      var strSearch = new String(searchfor);
      i = strSearch.indexOf(' ');
      
      if(i>-1){
      
      if (i==0){
      strSearch=strSearch.substring(1,strSearch.length);
      
      }
      while(i>0)
	  {
	   keyword = strSearch.substring(0,i);
	   condition += " and wine_name like '%"+keyword+"%'";
	   
	   strSearch = strSearch.substring(i+1,strSearch.length);
	   
	   i = strSearch.indexOf(' ');  
	  
	  }
	   condition += " and wine_name like '%"+strSearch+"%'";
	   
	  }else{
	   condition += " and wine_name like '%"+strSearch+"%'";}
		   
		   
		     
      
      
	  theform.txtQuery.value=condition;
	}
}


function fun_check_page(page)
{
    if((page.length == 0) | isNaN(page)) 
	{
	  alert("Please input a valid page number! ");
	  return false;
	}
}
