﻿//字符串验证
    function validateStr(str,type)
    {
        var rtn = false;
        var patrn;
        switch(type)
        {
            
            case 1:
                patrn = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;break;     //Email
           
            default:
                break;
        }
        var rs = patrn.match(str);
        if(rs)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    function sendMail(strId)
    {
        var ch=check();
        if(ch)
        {
            var url = 'http://www.carsfun.com/tools/ajax_session.aspx';
            var pars = "action=sm&gid="+strId+"&fname="+$F("txtFriendName")
            +"&fmail="+$F("txtFriendEmail")+"&myname="+$F("txtMyName")+"&mymail="+$F("txtEmail")+"&body="+$F("txtbody")+"&ra="+Math.random();
            var myAjax = new Ajax.Request(url,{method: 'get',parameters: pars,onComplete: function(res){
                                   alert("感谢您的推荐，请提醒您的朋友查收邮件！");
                                   $("email").style.display="none";
                                   
                                }});
        }
    }
    function check()
    {
        var rs;
        var txtFriendName=$("txtFriendName");
        
        if(txtFriendName.value.trim()=="")//好友名字
        {
            $("sp1").style.display="";
            rs= false;
        }
        else
        {
             $("sp1").style.display="none";
             rs=true;
        }
        
        if($("txtFriendEmail").value.trim()=="")//好友email
        {
            $("sp2").style.display="";
            rs= false;
        }
        else if(validateStr($("txtFriendEmail").value,1)==false)
        {
            $("sp2_2").style.display="";
            $("sp2").style.display="none";
            rs= false;
        }
        else
        {
            $("sp2").style.display="none";
            $("sp2_2").style.display="none";
            rs=true;
        }
        
        if($("txtMyName").value.trim()=="")//我的名字
        {
            $("sp3").style.display="";
            rs= false;
        }
        else
        {
            $("sp3").style.display="none";
            rs= true;
        }
        
        if($("txtEmail").value.trim()=="")
        {
            $("sp4").style.display="";
            rs=  false;
        }
        else if(validateStr($("txtEmail").value,1)==false)
        {
            $("sp4_2").style.display="";
            $("sp4").style.display="none";
            rs=  false;
        }
        else
        {
            $("sp4").style.display="none";
            $("sp4_2").style.display="none";
            rs= true;
        }
        return rs;
    }
     String.prototype.trim = function() {
        var reExg = /^\s+(.*?)\s+$/;
        return this.replace(reExg,"$1");
    };
    
    function yuding(strId)
        {
            var chy=checkYuding();
            if(chy)
            {
                var url = 'http://www.carsfun.com/tools/ajax_session.aspx';
                var pars = "action=yuding&gid="+strId
                +"&mn="+$F("txtcompanyName")+"&ma="+$F("txtcompanyAddress")+"&un="+$F("txtUserName")+"&ut="+$F("txtUserTel")+"&ue="+$F("txt_y_email")+"&ra="+Math.random();
                var myAjax = new Ajax.Request(url,{method: 'get',parameters: pars,onComplete: function(res){
                                        if(res.responseText=="1")
                                        {
                                            alert("预订成功，我们会及时与您联系.请您耐心等待.");
                                        }
                                        else
                                        {
                                            alert("网络问题,请重试");
                                        }
                                       $("yuding").style.display="none";
                                       
                                    }});
            }
        }
        
        function checkYuding()
        {
            var rs;
            var txtUserName=$("txtUserName");
            
            if(txtUserName.value.trim()=="")
            {
                $("sp_y3").style.display="";
                rs= false;
            }
            else
            {
                 $("sp_y3").style.display="none";
                 rs=true;
            }
            
            if($("txtUserTel").value.trim()=="")//tel
            {
                $("sp_y4").style.display="";
                rs= false;
            }
            else
            {
                $("sp_y4").style.display="none";
                rs= true;
            }
            
            return rs;
        }

function voteReview(reviewId,value,obj)
        {
            var url = 'http://www.carsfun.com/tools/ajax_session.aspx';
            var pars = "action=review&rid="+reviewId+"&v="+value+"&ra="+Math.random();
            var myAjax = new Ajax.Request(url,{method: 'get',parameters: pars,onComplete: function(res){
           
                                   if(res.responseText=="-1")
                                   {
                                        var re =window.location.href;
                                        window.location.href="http://www.carsfun.com/member/login.aspx?returnurl="+encodeURIComponent(re);
                                        return;
                                   }
                                   if(res.responseText=="1")
                                   {
                                        obj.parentNode.nextSibling.nextSibling.innerHTML=Number(obj.parentNode.nextSibling.nextSibling.innerHTML)+1;
                                   }
                                   
                                }});
            
        }
        function voteZiXun(reviewId,value,obj)
        {
            var url = 'http://www.carsfun.com/tools/ajax_session.aspx';
            var pars = "action=zixun&zid="+reviewId+"&v="+value+"&ra="+Math.random();
            var myAjax = new Ajax.Request(url,{method: 'get',parameters: pars,onComplete: function(res){
          
                                   if(res.responseText=="-1")
                                   {
                                        var re =window.location.href;
                                        window.location.href="http://www.carsfun.com/member/login.aspx?returnurl="+encodeURIComponent(re);
                                        return;
                                   }
                                   if(res.responseText=="1")
                                   {
                                        obj.parentNode.nextSibling.nextSibling.innerHTML=Number(obj.parentNode.nextSibling.nextSibling.innerHTML)+1;
                                   }
                                   
                                }});
        }
        var oldPriceSize=0;
        var oldPriceStuff=0;
        var CURRENT_COUNTSize=0;
        var CURRENT_COUNTStuff=0
        var current_count=0;
        var currentPrice_arr_Size = new Array();
        var currentPrice_arr_Stuff = new Array();
        var currentPrice_arr = new Array();
        function changePriceSticker(obj)
        {
            var price = $("ltlMemberPrice","ltlYuDing","ltlJianQian","ltlCuxiao","ltlLijijian","ltlVipPrice","ltlQingcangPrice","ltlErshouPrice","ltlQianggouPrice");
            var tmpPrice;
            var totalPrice=0;
            var price_id =obj.options[obj.selectedIndex].value.split("_");
          
                
                if(CURRENT_COUNTSize==0)
                {
                    for(var i=0;i<price.length;i++)
                    {
                        if(price[i]!=null)
                        {
                            tmpPrice=parseFloat(price[i].innerHTML);
                            currentPrice_arr_Size[i] = tmpPrice;//获取各种初始价格
                            totalPrice=tmpPrice +parseFloat(price_id[0]);
                            price[i].innerHTML = totalPrice.toFixed(2);
                        }
                    }
                    CURRENT_COUNTSize=1;
                }
                else
                {
                    for(var i=0;i<price.length;i++)
                    {
                        if(price[i]!=null)
                        {
                            tmpPrice=parseFloat(currentPrice_arr_Size[i]);
                            totalPrice=tmpPrice+parseFloat(price_id[0]);
                            price[i].innerHTML = totalPrice.toFixed(2);
                        }
                    }
                }
        }
        
        function changePrice()
        {
            var price = $("ltlMemberPrice","ltlYuDing","ltlJianQian","ltlCuxiao","ltlLijijian","ltlVipPrice","ltlQingcangPrice","ltlErshouPrice","ltlQianggouPrice");
            var ddlStickerSize =$("ddlStickerSize");
            var ddlStickerStuff=$("ddlStickerStuff");
            var priceSize;var priceStuff;
            if($("div_stickerSizeMain").style.display=="")
            {
                priceSize=ddlStickerSize.options[ddlStickerSize.selectedIndex].value.split("_");
            }
            else
            {
                priceSize = new Array();
                priceSize[0]="0.00";
                priceSize[1]="0";
            }
            if($("div_sitckerStuffMain")=="")
            {
                priceStuff=ddlStickerStuff.options[ddlStickerStuff.selectedIndex].value.split("_");
            }
            else
            {
                priceStuff= new Array();
                priceStuff[0]="0.00";
                priceStuff[1]="0";
            }
            var tmpPrice = parseFloat(priceSize)+parseFloat(priceStuff);
            var totalPrice=0;
            if(current_count==0)
            {
                for(var i=0;i<price.length;i++)
                {
                    if(price[i]!=null)
                    {
                        currentPrice_arr[i] = parseFloat(price[i].innerHTML);
                        totalPrice = currentPrice_arr[i] +tmpPrice;
                        price[i].innerHTML=parseFloat(totalPrice).toFixed(2);
                    }
                }
                current_count=1;
            }
            else
            {
                for(var i=0;i<price.length;i++)
                {
                    if(price[i]!=null)
                    {
                        totalPrice = currentPrice_arr[i] +tmpPrice;
                        price[i].innerHTML=parseFloat(totalPrice).toFixed(2);
                    }
                }
            }
        }
        
        function changeStuffSticker(obj)
        {
            var price = $("ltlMemberPrice","ltlYuDing","ltlJianQian","ltlCuxiao","ltlLijijian","ltlVipPrice","ltlQingcangPrice","ltlErshouPrice","ltlQianggouPrice");
            var tmpPrice;
            var totalPrice=0;
            var price_id =obj.options[obj.selectedIndex].value.split("_");
          
                
                if(CURRENT_COUNTStuff==0)
                {
                    for(var i=0;i<price.length;i++)
                    {
                        if(price[i]!=null)
                        {
                            tmpPrice=parseFloat(price[i].innerHTML);
                            currentPrice_arr_Stuff[i] = tmpPrice;//获取各种初始价格
                            totalPrice=tmpPrice +parseFloat(price_id[0]);
                            price[i].innerHTML = totalPrice.toFixed(2);
                        }
                    }
                    CURRENT_COUNTStuff=1;
                }
                else
                {
                    for(var i=0;i<price.length;i++)
                    {
                        if(price[i]!=null)
                        {
                            tmpPrice=parseFloat(currentPrice_arr_Stuff[i]);
                            totalPrice=tmpPrice+parseFloat(price_id[0]);
                            price[i].innerHTML = totalPrice.toFixed(2);
                        }
                    }
                }
        }