﻿// JScript 文件

function ltrim(s) { return s.replace(/^\s*/, ""); }
//去右空格;
function rtrim(s) { return s.replace(/\s*$/, ""); }
//左右空格;
function trim(s) { return rtrim(ltrim(s)); }


function prosearch() {
    var pn = escape(trim(document.getElementById("pn").value));
    if (pn.length < 3 || pn == "search%20our%20products") {
        alert("Please input more than 3 characters.");
        return;
    }
    else {
        window.parent.location.href = '/OfferSearch/' + pn + '/1.html';
    }
}


function gosearch() {
    var k = trim(document.getElementById("key").value);
    var type = trim(document.getElementById("type").value);
    if (k.length < 3) {
        alert("Please input more than 3 characters.");
        return;
    }

    if (k != '') {
        switch (type) {
            case 'productname':
                var patn = /^[0-9]{2,7}-[0-9]{1,2}-[0-9]{1}$/
                if (patn.test(k)) {
                    //window.parent.location.href = '/search.aspx?type=cas&k=' + k;
                    goNewurl('/search.aspx?type=cas&k=' + k);
                }

                else {
                    //window.parent.location.href = '/search.aspx?type=productname&k=' + escape(k);
                    goNewurl('/search.aspx?type=productname&k=' + escape(k));
                }

                break;
            case 'cas':
                var patn = /^[0-9]{2,7}-[0-9]{1,2}-[0-9]{1}$/
                if (patn.test(k)) {
                    //window.parent.location.href = 'http://www.lookchem.com/search.aspx?type=cas&k=' + k;
                    goNewurl('http://www.lookchem.com/search.aspx?type=cas&k=' + k);
                    break;
                }
                else {
                    alert("Please enter a valid cas number.");
                }
                break
            case 'buy':
                //window.parent.location.href = 'http://www.lookchem.com/ForSeller/search.aspx?type=buy&k=' + k;
                goNewurl('http://www.lookchem.com/ForSeller/search.aspx?type=buy&k=' + k);
                break
            case 'formula':
                //window.parent.location.href = 'http://www.lookchem.com/search.aspx?type=formula&k=' + k;
                goNewurl('http://www.lookchem.com/search.aspx?type=formula&k=' + k);
                break
            case 'suppliers':
                //window.parent.location.href = 'http://www.lookchem.com/Suppliers_Search.aspx?type=suppliers&k=' + k;
                goNewurl('http://www.lookchem.com/Suppliers_Search.aspx?type=suppliers&k=' + k);
                break
            case 'msds':
                //window.parent.location.href = 'http://www.lookchem.com/msds.aspx?type=msds&k=' + k;
                goNewurl('http://www.lookchem.com/msds.aspx?type=msds&k=' + k);
                break
            default:
        }
    }
    else {
        alert("Please enter keyword.");
    }
}   
