function ow(wname)
{
	if ( wname == window.name)
	   return true ;
	var width = 600 ;
	var height = 400 ;
	var x = 0;
	var y= 0 ;
	var menubar = "yes" ;
	var toolbar = "yes" ;
	var status = "yes" ;
	width = screen.availWidth;
	height = screen.availHeight;
	var win = window.open(	"",
							wname,
							"toolbar=" + toolbar
							+ ",status=" + status
							+ ",menubar=" + menubar
							+ ",width=" + width
							+ ",height=" + height
							+ ",location=yes,directories=yes,scrollbars=yes,resizable=yes");
	if( win != null)
	{
		win.moveTo(x,y);
		win.focus();
   		win.document.open();
   		win.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\n");
   		win.document.write("<title>查询进行中...请稍候...</title>查询进行中...请稍候...");
   		win.document.close() ;
	}
   	return true ;
}

function doSearchEx()
{
	if( doValidate() == false)
	{
		//alert("fail to doValidate()");
		return false;
	}
	
	if( doSearch() == false)
	{
		return false;
	}
	
	document.FormSearch.cuid.value = GetCookie("uid");
	//myuid = GetCookie("uid");
	//alert("myuid="+myuid+",uid="+document.FormSearch.cuid.value);
	//alert("myuid="+myuid);
	
	ow('ksou_adv_search');
}

function doValidate()
{
	//Check the price first
	var nIndex = document.FormSearch.category.selectedIndex;
	var LowPrice = 0;
	var HighPrice = 0;
	//alert("index="+nIndex);
	switch( nIndex)
	{
		case 0:
			LowPrice = document.FormSearch.value_0_0.value;
			HighPrice = document.FormSearch.value_0_1.value;
			break;
		case 1:
			LowPrice = document.FormSearch.value_1_0.value;
			HighPrice = document.FormSearch.value_1_1.value;
			break
		case 2:
			LowPrice = document.FormSearch.value_2_0.value;
			HighPrice = document.FormSearch.value_2_1.value;
			break;
		case 3:
			LowPrice = document.FormSearch.value_3_0.value;
			HighPrice = document.FormSearch.value_3_1.value;
			break;
		case 4:
			LowPrice = document.FormSearch.value_4_0.value;
			HighPrice = document.FormSearch.value_4_1.value;
			break;
		default:
			LowPrice = 0;
			HighPrice = 0;
			bValid = "true";
			break;
	}
	
	if( parseInt(HighPrice,10) < parseInt(LowPrice,10))
	{
		alert("最高价"+ HighPrice + "小于最低价"+ LowPrice+",请检查你的查询条件,谢谢");
		return false;
	}
	else
	{
		//alert("nIndex="+nIndex+",最高价"+ HighPrice + ",最低价"+ LowPrice);
		return true;
	}
}

function doSearch() 
{
    setAllSelectedTrue(document.FormSearch.brandList0);
    setAllSelectedTrue(document.FormSearch.brandList1);
    setAllSelectedTrue(document.FormSearch.brandList2);
    setAllSelectedTrue(document.FormSearch.brandList3);
    setAllSelectedTrue(document.FormSearch.brandList4);
}

function doReset() 
{
	//alert("doReset");
    document.FormSearch.reset();
    deleteAllFromDestList(document.FormSearch.srcList0, document.FormSearch.brandList0);
   	deleteAllFromDestList(document.FormSearch.srcList1, document.FormSearch.brandList1);
    deleteAllFromDestList(document.FormSearch.srcList2, document.FormSearch.brandList2);
    deleteAllFromDestList(document.FormSearch.srcList3, document.FormSearch.brandList3);
    deleteAllFromDestList(document.FormSearch.srcList4, document.FormSearch.brandList4);
}


function setAllSelectedTrue(brandList){
	if(brandList.length>8){
        alert("每次搜索，品牌至多只能选择8个！");
        return false;
    }
    var value = "";
    var nPos = 0;
    var nLength = 0;
    //alert("setAllSelectTrue, brandListLength="+brandList.length);
	for(var k=0;k<brandList.length;++k)
    {
    	brandList.options[k].selected=true;
    	//brandList.value = brandList.valuebrandList.options[k].value;
    	nPos = brandList.options[k].value.lastIndexOf(",");
    	if( nPos > 0 )
    	{
    		nLength = brandList.options[k].value.length;
    		//alert("k="+" value="+brandList.options[k].value+" nPos="+nPos+" nLength="+nLength);
    		var strString = brandList.options[k].value.substring(nPos + 1, nLength);
    		brandList.options[k].value = strString;
    		//alert("cut value to "+brandList.options[k].value);
    	}
    	if( k == 0)
    	{
    		value = brandList.options[k].value;
    		//alert("value=" + value);
    	}
    	else
    	{
    		
    		value = value + "," + brandList.options[k].value;
    		//alert("value=" + value);
    	}
    }
    if( brandList.length > 0)
    {
    	brandList.options[brandList.length - 1].value = value;
    	//alert("final value="+brandList.options[brandList.length - 1].value);
	}
}

function clickRadio(t){
    t.checked=!t.checked;
}

function ShowDiv(DivId)
{
	document.all[DivId].style.display='';
	return 0;
}
function HideDiv(DivId)
{
	document.all[DivId].style.display='none';
	return 0;
}

function LoadDiv()
{
	var nIndex = document.FormSearch.category.selectedIndex;
	doReset();
	document.FormSearch.category.selectedIndex = nIndex;
	switch( nIndex)
	{
		case 0:
			ShowDiv('div0');
			HideDiv('div1');
			HideDiv('div2');
			HideDiv('div3');
			HideDiv('div4');
			break;
		case 1:
			HideDiv('div0');
			ShowDiv('div1');
			HideDiv('div2');
			HideDiv('div3');
			HideDiv('div4');
			break;
		case 2:
			HideDiv('div0');
			HideDiv('div1');
			ShowDiv('div2');
			HideDiv('div3');
			HideDiv('div4');
			break;
		case 3:
			HideDiv('div0');
			HideDiv('div1');
			HideDiv('div2');
			ShowDiv('div3');
			HideDiv('div4');
			break;
		case 4:
			HideDiv('div0');
			HideDiv('div1');
			HideDiv('div2');
			HideDiv('div3');
			ShowDiv('div4');
			break;
	}
	
}



function addSrcToDestListEx(srcList, brandList)
{
    var si=brandList.length;
    //alert("srcList.length="+srcList.length);
	//alert("srcList.options[1].value="+srcList.options[1].value);
    for(var i=0;i<srcList.length;++i){
        if (srcList.options[i].selected) si++;
        if (si>8) break;
    }
    if (si>8){
        alert("每次搜索，品牌至多只能选择8个！");
        return ;
    }
    addSrcToDestList(srcList, brandList);
}

function clickRadio(t)
{
    t.checked=!t.checked;
}
