﻿function redirect(type, txtId)
{
	if(txtId == undefined)
	{
		txtId = "txtkeyword";
	}
    var keyword = document.getElementById(txtId).value;
    if(keyword == "")
        window.location = "/"; 
    else
        window.location = replaceURL("", "", keyword);
}


function redirectB(type)
{
    redirect(type,"txtkeywordB");
}

function ii(e)
{
	e=e||window.event;
	if(e.keyCode==13)
	{
		if(isIE)
		{e.returnValue=false}
		else{e.preventDefault()}

		redirectB();
		return 
	}
}

function replaceURL(key,value,keyword)
{
    var para = location.search;
    // alert(para); 
    var paras;
    if(location.search.indexOf("?para=")==0)
    {
        para=para.replace("?para=","");
        paras=para.split("|");
        para="";
        for(var i=0;i<paras.length;i=i+2)
        {
            if(paras[i]==key)
            {
                paras[i+1]=value;
                para=paras.join("|");
                break;
            }
        }
        para="?para="+para;
    }
    return location.href.replace(/^http:\/\/([^/]+)\/([^/]+)\/([^/]*)(\/(((\d+).html)?(\?para=([^&]*))?)?)?$/,"http://$1/$2/"+encodeURI(keyword.replace(/\s+/g,' '))+"/"+para);
}

function urlEncode(url)
{
    url=encodeURI(htmlEncode(url));
    //url=htmlEncode(url);
    url=url.replace(/\//g,"%2f");
    url=url.replace(/\./g,"%2e");
    url=url.replace(/\?/g,"%3f");
    url=url.replace(/#/g,"%23");
    url=url.replace(/&/g,"%26");
    return url;
}

function htmlEncode(html) 
{ 
    return html.replace(/&/g, '&amp').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); 
}

function htmlDecode(html) 
{ 
    return html.replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&lt;/g, '<').replace(/&gt;/g, '>'); 
}

function s(o,type)
{
        var keyword=document.getElementById("txtkeyword").value;
        if(keyword == "")
        { 
            window.location = "/"; 
        } 
        else
        { 
            var url=location.href;
            window.location=replaceURL("","",keyword).replace(type,o);
        }   
    
}

function display()
{
    document.getElementById('index_pop').style.display="block"; 
}

function disappear()
{
    document.getElementById('index_pop').style.display="none"; 
}
        
        
