﻿// JScript 文件
String.prototype.trim = function()  
{  
	return this.replace(/(^\s*)|(\s*$)/g, "");  
}

function $(val)
{
    return document.getElementById(val);
}

function JsOnfocusTextBox(obj)
{
    if(obj != null)
    {
        obj.className='btn_onfocus';
        
        if(obj.value == "请输入产品关键字")
        {
            obj.value = "";
            obj.focus();
        }
    }
}

function JsOnblurTextBox(obj)
{
    if(obj != null)
    {
        obj.className='btn_onblur';
        
        if(obj.value == "")
        {
            obj.value = "请输入产品关键字";
        }
    }
}

function JsSearchProduct(obj_select,obj_input)
{
    if (obj_select.options.selectedIndex >= 0 && obj_input.value.trim() != "" && obj_input.value.trim() != "请输入产品关键字")
    {
        window.location.href = "Product.aspx?ClassID="+encodeURIComponent(obj_select.options.value)+"&ProductName=" + encodeURIComponent(obj_input.value.trim());
    }
    else if (obj_select.options.selectedIndex > 0 && (obj_input.value.trim() == "" || obj_input.value.trim() == "请输入产品关键字"))
    {
        window.location.href = "Product.aspx?ClassID="+encodeURIComponent(obj_select.options.value);
    }
    
    return false;
}

function JsSearchProductPress(obj_select,obj)
{
    if(event.keyCode == 13)
    { 
        JsSearchProduct(obj_select,obj);
        return false;
    }
}

function JsClosedAffiche(obj)
{
    if(obj != null)
    {
        obj.style.display = "none";
    }
}

//邮件校验 
//通过校验返回ture,否则返回false
function isEmail(str)
{
    if(str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function JsCheckMessage()
{
    if(document.aspnetForm.ctl00_PageBody_txt_ClientName.value.trim() == "")
    {
        alert("请输入姓名!");
        return false;
    }
    
    if (document.aspnetForm.ctl00_PageBody_radio_boy.checked == false && document.aspnetForm.ctl00_PageBody_radio_girl.checked == false)
    {
        alert("请选择性别!");
        return false;
    }
    
    if(document.aspnetForm.ctl00_PageBody_txt_Title.value.trim() == "")
    {
        alert("请输入标题!");
        return false;
    }
    
    if(document.aspnetForm.ctl00_PageBody_txt_Content.value.trim() == "")
    {
        alert("请输入内容!");
        return false;
    }
    
    if(document.aspnetForm.ctl00_PageBody_txt_Mobile.value.trim() == "")
    {
        alert("请输入联系电话!");
        return false;
    }
    
    if(document.aspnetForm.ctl00_PageBody_txt_Email.value.trim() == "")
    {
        alert("请输入电子邮箱!");
        return false;
    }
    
    if(document.aspnetForm.ctl00_PageBody_txt_Validate.value.trim() == "")
    {
        alert("请输入验证码!");
        return false;
    }
    
    if(!isEmail(document.aspnetForm.ctl00_PageBody_txt_Email.value.trim()))
    {
        alert("请输入正确的电子邮箱!");
        return false;
    }
   
    return true;
}

function JsOpenWindow(url,name,iWidth,iHeight)
{
    var url;                             //转向网页的地址;
    var name;                            //网页名称，可为空;
    var iWidth;                          //弹出窗口的宽度;
    var iHeight;                         //弹出窗口的高度;
    //获得窗口的垂直位置
    var iTop = (window.screen.availHeight-30-iHeight)/2;        
    //获得窗口的水平位置
    var iLeft = (window.screen.availWidth-10-iWidth)/2;           
    window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no');
}

