$(function(){
    $("#search").click(function(){
        return jsubmit()
    });
    $("#search2").click(function(){
        return jsubmitsearch()
    });
    $("#kw").focus();

})
// #号和&符号转义
function strCode(str) {
    if(encodeURIComponent) {
        return encodeURIComponent(str);
    }
    if(escape) {
        return escape(str);
    }
}

function jsubmit(type) {
    if(type == 1){
        var kw = $("#kw1").val();
    }else{
       var kw = $("#kw").val();
    }
    if(type == 1){
        var kwtype = $("#kwtype1").val();
    }else{
        var kwtype = $("#kwtype").val();
    }

    if (kw == "") {
        alert("Invalid input !");
        return false;
    }
    else {
        var re1;
        // 第二个参数中的 g 表示全部匹配,i表示忽略大小写
        var regspace = new RegExp(" ", "gi");
        var regzhong = new RegExp("-", "gi");
        var string = strCode(kw.replace(regspace, '_').replace(regzhong, '^'));
        re1 = string.replace(/%/g, "%25");
        re1 = re1.replace(/(^_*)|(_*$)/g, "");
        var static_url = re1 ;
        if(kwtype =='inquiry'){
            var seoUrl = "/inquiry-" + static_url + "/";
        }else if(kwtype == "product"){
            var seoUrl = "/q-" + static_url + "/";
        }else{
            var seoUrl = "/manufacturer-" + static_url + "/";
        }
        window.location.href = seoUrl;
    }
}

function jsubmitsearch() {  
                var kw = $("#kw1").val();
		var kwtype = $("#kwtype1").val();
		if (kw == "") {
			alert("Invalid input !");
			return false;
		}
		else {
			var re1;
			// 第二个参数中的 g 表示全部匹配,i表示忽略大小写
			var regspace = new RegExp(" ", "gi");
			var regzhong = new RegExp("-", "gi");
			var string = strCode(kw.replace(regspace, '_').replace(regzhong, '^'));
			re1 = string.replace(/%/g, "%25");
            re1 = re1.replace(/(^_*)|(_*$)/g, "");
			var static_url = re1 ;
            if(kwtype =='inquirie'){
                var seoUrl = "http://www.frbiz.com/inquiry-" + static_url + "/";
            }else if(kwtype == "product"){
                var seoUrl = "http://www.frbiz.com/q-" + static_url + "/";
            }else{
                var seoUrl = "http://www.frbiz.com/manufacturer-" + static_url + "/";
            }
			window.location.href = seoUrl;
		}
}


$(function(){
    var flag = 0
    $("#selectAll").click(function(){
        if(flag == 0){
            $(".productlist").attr("checked", true);
            flag =1;
            $(this).text("Clear all items");

        }else{
            $(".productlist").attr("checked", false);
            $(this).text("Select all items");
            flag =0;
        }
    })
    $("#selectAll").mouseover(function(){
        $(this).css("cursor","pointer");
    })
})

function quireall(){
    var pids = '';
    var title = '';
    $(".productlist").each(function(){
        if($(this).attr("checked") == true){
            if(pids == ''){
                pids += $(this).val();
            }else{
                pids += "|"+$(this).val();
            }
            title = $(this).attr('title');
        }
    })

    if(pids == ''){
        alert("please select product!");
        return false;
    }
    var url = "/index.php?r=inquiry/inquiry&pid=" + pids+"&topic=inquiry for "+title;
    location.href=url;
}

var a1 = 0;
var a2 = 0;
function blurs(a){
    var show = document.getElementById('p_o');
    show.style.visibility='visible';
    a1 = 1;
}

function blur_more(){
    var show = document.getElementById('ph');
    if(show.style.display=='none'){
         show.style.display='block';
    }else{
        show.style.display='none';
    }
   
   
}

document.onclick = cleanDiv;
function cleanDiv(){
    
    if(a1 == '1'){
        document.getElementById('p_o').style.visibility='hidden';
        a1 = 0;
    }
}

function get_pos(div){
    var pos={'left':0,'top':0}
    while(1){
        if(!div){
            break;
        }
        pos['left']+=div.offsetLeft;
        pos['top']+=div.offsetTop;
        div=div.offsetParent;
    }
    return pos;
 }

    var t=0;
    var last_width=0;
    function width_ie(e){
        window.setTimeout(function(){
            var main = document.getElementById('ie_w');
            var body_width=document.body.scrollWidth;
            var w=parseInt(main.offsetWidth);
            var is_big=0;
            if(!t){
                last_width=body_width;

            }
            if(body_width>last_width){
                is_big=1;
            }
            last_width=body_width;
            t=1;

            if(w<930){
                main.style.width='930px';
                last_width=parseInt(main.offsetWidth);
            }else{
                if(is_big){
                    main.style.width='100%';

                }

            }

        },100);
    }
    if(window.attachEvent){
        window.attachEvent('onresize',width_ie);
    }
