﻿// JScript 文件
function AJAX(func,method,url,async,user,password,data,efunc)
{
    var req=new XMLHttpRequest();
    if (req)
    {
        req.onreadystatechange=function()
        {
            if (req.readyState==4&&req.status==200)
            {
                if(func)func(req);
            }
            else if (req.readyState==4&&req.readyState>200)
            {
                if(efunc)efunc(req);
            }
            if (req.readyState==4)
            {
                req.onreadystatechange=emptyFunc;
            }
        };
        method=method.toUpperCase();
        req.open(method,url,async,user,password);
        if(method=='POST')
        {
            req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        }
        if(data)
        {
            req.send(data);
        }
        else
        {
            req.send(null);
        }
    }
    return req;
}

if (window.ActiveXObject && !window.XMLHttpRequest)
{
    window.XMLHttpRequest=function()
    {
        var msxmls=new Array('Msxml2.XMLHTTP','Microsoft.XMLHTTP');
        for(var i=0;i<msxmls.length;i++)
        {
            try
            {
                return new ActiveXObject(msxmls[i]);
            }
            catch(e)
            {
            }
        }
        return null;
    };
}
function emptyFunc()
{
}  


//----------------------------------------------------------------------------------
function $(ctl_id) {
    return document.getElementById(ctl_id);
}
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function fn_get_selmemo_prod(is_hidden) {
    var a_sel=[['','In All Category'],['2','Granites'],['1','Marbles'],['25','Travertine'],['26','Sandstone'],['27','Limestone'],['28','Slate'],['29','Basalt (Lava)'],['30','Andesite'],['3','Artificial Stones'],['4','Stone Blocks '],['6','Laminated Panels'],['7','Mosaic & Patchwork'],['8','Craftworks'],['9','Stone Furnitures'],['10','Landscaping Stones'],['17','Tombstones & Monuments'],['18','Maintenance Materials'],['19','Stone Machineries'],['20','Tools'],['24','Others']];
    var s_sel='';
    if (is_hidden) {
        s_sel += '<select id="search_sel_product" name="search_sel_product"  style="width: 160px;" style="display:none">';
    }
    else {
        s_sel += '<select id="search_sel_product" name="search_sel_product"  style="width: 160px;">';
    }
    
    for (var ni=0;ni<a_sel.length;ni++) {
        s_sel += ('<option value=' + a_sel[ni][0] + '>' + a_sel[ni][1] + '</option>');
    }
    s_sel += '</select>';
    return s_sel;
}

var s_sel_date=new String('');
function fn_get_selmemo_date() {
    var a_sel=[['','Date All'],['0','today'],['7','7 days'],['15','15 days'],['30','30 days'],['180','half year']];
    var s_sel='';
    s_sel += '<select id="search_sel_date" name="search_sel_date"  style="width: 96px;">';
    for (var ni=0;ni<a_sel.length;ni++) {
        s_sel += ('<option value=' + a_sel[ni][0] + '>' + a_sel[ni][1] + '</option>');
    }
    s_sel += '</select>';
    return s_sel;
}

var s_sel_nation=new String('');
var v_tt_nation=null;
AJAX(fn_get_selmemo_nation,'post','/ajax/ajax_common.aspx',true,null,null,'GetNation',null);
function fn_get_selmemo_nation(req) {
    var s_sel='';
    s_sel += '<select id="search_sel_nation" name="search_sel_nation" style="width:200;">';
    s_sel += req.responseText;
    s_sel += '</select>';
    s_sel_nation = s_sel;
}
var aNationDesc=null;
AJAX(fn_get_selmemo_nation_desc,'post','/ajax/ajax_common.aspx',true,null,null,'GetNationDesc',null);
function fn_get_selmemo_nation_desc(req) {
    eval(req.responseText);
}

var s_sel_category=new String('');
var g_is_sel_category=false;
function fn_get_selmemo_category(sel_index) {
    var s_sel='';
    var s_sel_0='';if (Number(sel_index)==0) s_sel_0='selected';
    var s_sel_1='';if (Number(sel_index)==1) s_sel_1='selected';
    var s_sel_2='';if (Number(sel_index)==2) s_sel_2='selected';
    s_sel += '<select id="search_sel_category" name="search_sel_category" style="width:96px;" onchange="g_is_sel_category=true;s_search_keyword_size=a_search_keyword_size[this.selectedIndex][1];s_txt_search_keyword = fn_get_txt_search_keyword();if (this.selectedIndex==0) fn_create_select_product(); else if (this.selectedIndex==1) fn_create_select_forbuy(); else fn_create_select_company();">';
    s_sel += '<option value=0 '+s_sel_0+'>Products</option>';
    s_sel += '<option value=1 '+s_sel_1+'>Buying leads</option>';
    s_sel += '<option value=2 '+s_sel_2+'>Companies</option>';
    s_sel += '</select>';
    return s_sel;
}
//----------------------------------------------------------------------------
function fn_menuStyleCtrl(e) {
    return;
    var srcElmt = e.srcElement||e.target;
    fn_menuSearch(srcElmt);
}

function fn_menuSearch(ev) {
    while (ev.tagName != "LI") {
        ev = ev.parentNode;
    }
    
    var ArrayLi = document.getElementById("sm").getElementsByTagName("li");
    for(var i=0;i<ArrayLi.length;i++) {
        ArrayLi[i].className = "newmenubtn";
    }
           
    ev.className = "newmenubtndown";
    var evID = ev.id;

    var s_key=fn_get_keywords(evID);
    
    if (evID=='l1' || evID=='l0') {
        fn_create_select_product(s_key);
    }
    else if (evID=='l2') {
        fn_create_select_forbuy(s_key);
    }
    else if (evID=='l3') {
        v_tt_nation=window.setTimeout('fn_create_select_company("'+s_key+'")',1);
    }
    else /*if (evID=='l5')*/ {
        
    }
}

function fn_get_keywords(evID) {
    var s_href=window.location.href.toLocaleLowerCase();

    if (evID=='l1' || evID=='l0') {
        var regex_01=/http:\/\/product.stonebtb.com\/search\/[a-zA-Z_\(\)]+8(.+).shtml/;
        var regex_02=/http:\/\/product.stonebtb.com\/search\/(.+).shtml/;
        var regex_03=/key=(.*)&/;
        var regex_04=/key=(.*)/;
        var regex_sp=/_+/gi;
        var s_key=String('');
        
        if (regex_01.test(s_href)) {
            var regexec=regex_01.exec(s_href);
            s_key=unescape(regexec[1]);
            s_key=s_key.replace(regex_sp,' ');
        }
        else if (regex_02.test(s_href)) {
            var regexec=regex_02.exec(s_href);
            s_key=unescape(regexec[1]);
            s_key=s_key.replace(regex_sp,' ');
        }
        else if (regex_03.test(s_href)) {
            var regexec=regex_03.exec(s_href);
            s_key=unescape(regexec[1]);
            s_key=s_key.replace(regex_sp,' ');
        }
        else if (regex_04.test(s_href)) {
            var regexec=regex_04.exec(s_href);
            s_key=unescape(regexec[1]);
            s_key=s_key.replace(regex_sp,' ');
        }
        if (s_key.length>0) return s_key.trim();
    }
    else if (evID=='l2') {
        var regex_03=/key=(.*)&/;
        var regex_04=/key=(.*)/;
        var regex_sp=/_+/gi;
        var s_key=String('');
        
        if (regex_03.test(s_href)) {
            var regexec=regex_03.exec(s_href);
            s_key=unescape(regexec[1]);
            s_key=s_key.replace(regex_sp,' ');
        }
        else if (regex_04.test(s_href)) {
            var regexec=regex_04.exec(s_href);
            s_key=unescape(regexec[1]);
            s_key=s_key.replace(regex_sp,' ');
        }
        if (s_key.length>0) return s_key.trim();
    }
    else if (evID=='l3') {
        var regex_03=/key=(.*)&/;
        var regex_04=/key=(.*)/;
        var regex_sp=/_+/gi;
        var s_key=String('');
        
        if (regex_03.test(s_href)) {
            var regexec=regex_03.exec(s_href);
            s_key=unescape(regexec[1]);
            s_key=s_key.replace(regex_sp,' ');
        }
        else if (regex_04.test(s_href)) {
            var regexec=regex_04.exec(s_href);
            s_key=unescape(regexec[1]);
            s_key=s_key.replace(regex_sp,' ');
        }
        if (s_key.length>0) return s_key.trim();
    }
    else if (evID=='l4') {
    }
    
    s_key=s_key.trim();
    return s_key;
}

//-------------------------------------------------------------------------------
var a_search_keyword_size=[
    ['product.stonebtb.com','28'],
    ['buy.stonebtb.com','22'],
    ['company.stonebtb.com','25']
];
var s_search_keyword_size='28';
for (var ni=0;ni<a_search_keyword_size.length;ni++) {
    var s_cur_url=window.location.href.toLowerCase();
    if (s_cur_url.indexOf(a_search_keyword_size[ni][0])>=0) {
        s_search_keyword_size=a_search_keyword_size[ni][1];
        break;
    }
}

var s_txt_search_keyword = fn_get_txt_search_keyword();

function fn_get_txt_search_keyword() {
    var s_hidtopsearchtxt = $('hidtopsearchtxt').value;
    if (s_hidtopsearchtxt == '' || s_hidtopsearchtxt == 'Your Keyword') s_hidtopsearchtxt = 'Your Keyword';
    var s_ret=new String('');
    //s_ret += "<input name=\"search_keyword\" id=\"search_keyword\" type=\"text\" value=\"Your Keyword\" size=\""+s_search_keyword_size+"\" ";
    s_ret += "<input name=\"search_keyword\" id=\"search_keyword\" type=\"text\" value=\"" + s_hidtopsearchtxt + "\" size=\""+s_search_keyword_size+"\" ";
    s_ret += "onclick=\"if (value=='Your Keyword') value='';\" ";
    s_ret += "onblur=\"if (value=='') value='Your Keyword';\" ";
    s_ret += "/>";
    return s_ret;
}

fn_init_create_select();
function fn_init_create_select() {
    var s_cur_url=window.location.href.toLowerCase();
    if (s_cur_url.indexOf('product.stonebtb.com/search')>=0) {
        fn_menuSearch($('l1'));
    }
    else if (s_cur_url.indexOf('www.stonebtb.com/product')>=0) {
        fn_menuSearch($('l1'));
    }
    else if (s_cur_url.indexOf('company.stonebtb.com/search')>=0) {
        fn_menuSearch($('l3'));
    }
    else if (s_cur_url.indexOf('www.stonebtb.com/company')>=0) {
        fn_menuSearch($('l3'));
    }
    else if (s_cur_url.indexOf('buy.stonebtb.com/search')>=0) {
        fn_menuSearch($('l2'));
    }
    else if (s_cur_url.indexOf('www.stonebtb.com/buy')>=0) {
        fn_menuSearch($('l2'));
    }
    else if (s_cur_url.indexOf('sell.stonebtb.com/search')>=0) {
        fn_menuSearch($('l2'));
    }
    /*else if (s_cur_url.indexOf('www.stonebtb.com/sell')>=0) {
        fn_menuSearch($('l4'));
    }
    else if (s_cur_url.indexOf('www.stonebtb.com/tradeshow')>=0) {
        fn_menuSearch($('l5'));
    }
    else if (s_cur_url.indexOf('www.stonebtb.com/news')>=0) {
        fn_menuSearch($('l6'));
    }
    else if (s_cur_url.indexOf('www.stonebtb.com/pic')>=0) {
        fn_menuSearch($('l7'));
    }
    else if (s_cur_url.indexOf('www.stonebtb.com/quarry')>=0) {
        fn_menuSearch($('l8'));
    }
    else if (s_cur_url.indexOf('account.stonebtb.com')>=0) {
        fn_menuSearch($('l9'));
    }
    else if (s_cur_url.indexOf('forseller/search')>=0) {
    }*/
    else {
        fn_menuSearch($('l0'));
    }
}

function fn_create_select_product(s_key) {
    if (s_key==null) s_key="";
    if (g_is_sel_category) s_key=$("search_keyword").value.trim();
    
    var s_tmp=s_txt_search_keyword;
    if (s_key.length>0) s_tmp=s_tmp.replace("Your Keyword",s_key);
    
    var s_innerHTML=new String('');
    s_innerHTML += s_tmp;
	s_innerHTML += fn_get_selmemo_category(0);
	s_innerHTML += fn_get_selmemo_prod();
	s_innerHTML += "&nbsp;&nbsp;<input type=image id=\"btn_topSearch\" name=\"btn_topSearch\" src=\"/images/topsearch.gif\" onclick=\"return fn_search_prod();\" style=\"width:68px;height:21px;\" align=\"absmiddle\" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"http://search.stonebtb.com/\" target=\"_blank\">More search options</a>";
    $('topsearch_bar').innerHTML=s_innerHTML;
}

function fn_create_select_forbuy(s_key) {
    if (s_key==null) s_key="";
    if (g_is_sel_category) s_key=$("search_keyword").value.trim();
    
    var s_tmp=s_txt_search_keyword;
    if (s_key.length>0) s_tmp=s_tmp.replace("Your Keyword",s_key);

    var s_innerHTML=new String('');
    s_innerHTML += s_tmp;
	s_innerHTML += fn_get_selmemo_prod('true');
	s_innerHTML += fn_get_selmemo_category(1);
	s_innerHTML += fn_get_selmemo_date();
	s_innerHTML += "&nbsp;&nbsp;<input type=image id=\"btn_topSearch\" name=\"btn_topSearch\" src=\"/images/topsearch.gif\" onclick=\"return fn_search_forbuy();\" style=\"width:68px;height:21px;\" align=\"absmiddle\" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"http://search.stonebtb.com/\" target=\"_blank\">More search options</a>";
    $('topsearch_bar').innerHTML=s_innerHTML;
}

function fn_create_select_forsell() {
}

function fn_create_select_company(s_key) {
    window.clearTimeout(v_tt_nation);
    if (s_sel_nation.length==0) {
        v_tt_nation=window.setTimeout('fn_create_select_company("'+s_key+'")',10);
        return;
    }
    if (s_key==null) s_key="";
    if (g_is_sel_category) s_key=$("search_keyword").value.trim();
    
    var s_tmp=s_txt_search_keyword;
    if (s_key.length>0) s_tmp=s_tmp.replace("Your Keyword",s_key);
    
    var s_innerHTML=new String('');
    s_innerHTML += s_tmp;
	s_innerHTML += fn_get_selmemo_category(2);
	s_innerHTML += s_sel_nation;
	s_innerHTML += "&nbsp;&nbsp;<input type=image id=\"btn_topSearch\" name=\"btn_topSearch\" src=\"/images/topsearch.gif\" onclick=\"return fn_search_company('"+s_key+"');\" style=\"width:68px;height:21px;\" align=\"absmiddle\" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"http://search.stonebtb.com/\" target=\"_blank\">More search options</a>";
    $('topsearch_bar').innerHTML=s_innerHTML;
}

function fn_create_select_tradeshow() {
}


//----------------------------------------------------------
function fn_loginEvent(){
    if(LoginFocus=="m_ID"){
       if ($('m_ID').value!='' && $('m_PWD').value!='') {
            fn_loginCheck();
        }
        else if ($('m_ID').value!='' && $('m_PWD').value=='') {
            $('m_PWD').focus();
        }
        return false;
    }else if(LoginFocus=="m_PWD"){
        if ($('m_PWD').value!='' && $('m_ID').value!='') {
            fn_loginCheck();
        }
        else if ($('m_PWD').value!='' && $('m_ID').value=='') {
            $('m_ID').focus();
        }
        return false;
    }else if(LoginFocus=="Inquire"){
        return false;
    }
}


function fn_search_prod() {
    if(LoginFocus != "btn_topSearch"){
        fn_loginEvent();
        return false;
    }

    var a_sel_url=[['','Allproducts'],['2','Granites'],['1','Marbles'],['25','Travertine'],['26','Sandstone'],['27','Limestone'],['28','Slate'],['29','Basalt_(Lava)'],['30','Andesite'],['3','Artificial_Stones'],['4','Stone_Blocks '],['6','Laminated_Panels'],['7','Mosaic_Patchwork'],['8','Craftworks'],['9','Stone_Furnitures'],['10','Landscaping_Stones'],['17','Tombstones_Monuments'],['18','Maintenance_Materials'],['19','Stone_Machineries'],['20','Tools'],['24','Others']];
    var s_key=$('search_keyword').value.trim();
    s_key = s_key=='Your Keyword' ? '':s_key;
    reg=/ +/gi;
    s_key=s_key.replace(reg,'_');
    if (s_key.length==0) s_key='_';

    var s_url=new String('');
    s_url += "http://product.stonebtb.com/search_";
    s_url += a_sel_url[$('search_sel_product').selectedIndex][1];
    s_url += "8"+escape(s_key);
    s_url += ".shtml";
    document.forms[0].action=s_url;
    
    return true;
}

function fn_search_forbuy() {
    var s_key=$('search_keyword').value.trim();
    s_key = s_key=='Your Keyword' ? '':s_key;
    var s_url=new String('');
    if (s_key.length==0)
    {
        s_url += "http://buy.stonebtb.com/search";
        s_url += "/" + ($('search_sel_date').value=='' ? 'AllDay' : $('search_sel_date').value);
        s_url += "/" + "AllCountry.shtml";
    }
    else if (s_key.length>0)
    {
        var regex=/ +/gi;
        s_key=escape(s_key.replace(regex,'_'));
        s_url += "http://buy.stonebtb.com/search_"+s_key;
        s_url += "/" + ($('search_sel_date').value=='' ? 'AllDay' : $('search_sel_date').value);
        s_url += "/" + "AllCountry.shtml";
    }

    document.forms[0].action=s_url;

    return true;
}

function fn_search_forsell() {
    var s_url=new String('');
    
    document.forms[0].action=s_url;
    return true;
}

function fn_search_company() {
    var s_key=$('search_keyword').value.trim();
    s_key = s_key=='Your Keyword' ? '':s_key;
    s_key=s_key.replace(/(^\.*)|(\.*$)/g, "");
    s_key=s_key.replace('&',"");
    
    var s_url=new String('');
    if (s_key.length==0)
    {
        s_url += "http://company.stonebtb.com/search/";
        s_url += aNationDesc[$('search_sel_nation').selectedIndex] + ".shtml";
    }
    else if (s_key.length>0)
    {
        var regex=/ +/gi;
        s_key=escape(s_key.replace(regex,'_'));
        s_url += "http://company.stonebtb.com/search_" + s_key + "/";
        s_url += aNationDesc[$('search_sel_nation').selectedIndex] + ".shtml";
    }

    document.forms[0].action=s_url;

    return true;
}

function killerror() {
	return true;
}

window.onError = killerror;

//----------------------------------------------------------------
/*
var MenuStr = "<div class=\"topLink\"><div class=\"in\"><div class=\"FR\"><a href=\"http://www.stonebtb.com/\"  title=\"International Stone Web\">Home</a> | <a href=\"http://reg.stonebtb.com/\" target=\"_blank\" title=\"Join International Stone Web\">Join Now</a> | <a href=\"http://login.stonebtb.com/\" title=\"Sign In International Stone Web\" id=\"TMember\">Sign In</a> | <a href=\"http://www.stonebtb.com/siteMap.aspx\" target=\"_blank\" title=\"Site Map Of International Stone Web\">Site Map</a> | <a id=\"btn_msg\" href=\"http://im.stonebtb.com\" onclick=\"return fn_check_isLogin();\" target=\"_blank\" title=\"Messenger Of International Stone Web\">Open Stone Messenger</a> | <a href=\"http://help.stonebtb.com/\" title=\"Help Center Of International Stone Web\">Help</a> | <a href=\"http://china.stonebtb.com/\" title=\"stone of china\"><span class='red'>中文站</span></a> | <a href=\"http://www.stonebtb.com/video/OurVideo/\" title=\"Our Video\" target=\"_blank\"><span class='red'>Our Video</span></a></div>";
    MenuStr +="<a href=\"#\" onclick=\"this.style.behavior='url(#default#homepage)';this.setHomePage(window.location.href);return false\" title=\"STONEBTB.com\">Make STONEBTB.com your home page</a> | <a href=\"#\" onClick=\"window.external.addFavorite('http://www.stonebtb.com','STONEBTB');\" title=\"STONEBTB.com\">Add to Favorites</a></div></div>";
   
var myDiv = document.createElement("div");
var mainDiv = document.getElementsByTagName("div").item(0);
document.getElementsByTagName("form").item(0).insertBefore(myDiv, mainDiv);
myDiv.innerHTML = MenuStr;
*/
//-----------------------------------------------------------------
function fn_js_CtrlImges(img,w,h){
        var iW = w;
        var iH = h;
        var oW = img.width;
        var oH = img.height;
    
        if(img.width>iW && img.height>iH){
	        if(oW/iW > oH/iH){
		        img.width = iW;
		        img.height = parseInt(iW/oW * oH);
	        }
	        else{
		        img.height = iH;
		        img.width  = parseInt(iH/oH * oW);
	        }
	        return true;
        }
        if(oW>iW){
	        img.width = iW;
	        img.height = parseInt(iW * (oH/oW));
        }else if(oH>iH){
	        img.height = iH;
	        img.width  = parseInt(iH * (oW/oH));
        }
        return true;
}

//--------------------------------------------------------
/*
var TNavi = $("TNavi");
var CNode = TNavi.childNodes;
var Len = CNode.length;
var Url = new String(window.location);
var TempStr;
for(var i = 0;i < Len ; i++){
    CNode[i].setAttribute("className","topbtn");
    var Node = CNode[i].childNodes;
    TempStr = new String(Node[0].getAttribute("href"));
    if(Url.indexOf(TempStr) != -1){
        CNode[i].setAttribute("className","topbtnup");
    }
}

*/


/* 2010-10-19
var TagBuy = $("btn_top_forbuyers");
var TagSell = $("btn_top_forsellers");
var Url = new String(window.location);
var TempStr1 = "buy.stonebtb.com";
var TempStr2 = "sell.stonebtb.com";
if(Url.indexOf(TempStr1) != -1){
    TagSell.setAttribute("className","");
    TagSell.setAttribute("className","newforselldown");
}else if(Url.indexOf(TempStr2) != -1){
    TagBuy.setAttribute("className","");
    TagBuy.setAttribute("className","newforbuydown");
}
*/
