﻿// JScript 文件

function Jspages(pidParam, page ,tabcontParam)
 {
   var actions = "review";
   var tabconetents ="";
    switch(tabcontParam)
    {
     case "5":
       actions ="review";
       tabconetents ="tabcontent5";
       break;
     case "6":
       actions ="customs";
       tabconetents ="tabcontent6";
       break;
    }

    var url ="/ajax.aspx?pid="+pidParam+"&page="+page+"&action="+actions+"";
       $.ajax({
	 	   type:"get",
		   url :url,
		   beforeSend:function(XMLHttpRequest)
		    {
		       $(tabconetents).html("&nbsp;&nbsp;&nbsp;&nbsp;<img src=/images/ajax.gif />");
		    },
		   success:function(msg)
		    {   
		        document.getElementById(tabconetents).innerHTML = msg;
		    },
	       error:function(){
            
                }
           });
 
 }
 
 
 //添加
 function addQuestion(pidParam)
 {
    var questionConts = document.getElementById("ctomquest").value;
    if(questionConts == "")
    {
      document.getElementById("Errors").innerHTML = "<font color='red'>Please fill out your message.</font>";
    }
    //非登录用户
    var email="";
    var cookis = GetCookie("uid");
    //alert(cookis);
    if(cookis==null||cookis=="")
    {
        email=document.getElementById("txtEmail2").value;
        if(email.length==0)
        {
          document.getElementById("Errors").innerHTML = "<font color='red'>Please enter your Email!</font>";
          return;
        }
        else
        {
            var isEmail=isMail(email);
            if(!isEmail)
            {
                document.getElementById("Errors").innerHTML = "<font color='red'>Please enter your right Email address!</font>";
                return;
            }
        }
    }
    var url="";
    var action=document.getElementById("sltAction2").value;
    var infor=document.getElementById("chkQuestion").checked;//alert(infor);
    if(action=="review")
    {
        url="/ajax.aspx?pid="+pidParam+"&content="+questionConts+"&action=addReview"+"&email="+email+"&infor="+infor;
     }
     else
     {
        url="/ajax.aspx?pid="+pidParam+"&content="+questionConts+"&action=addQustion"+"&email="+email+"&infor="+infor;
     }
    //alert(url);
    
       $.ajax({ 
          type:"get", 
          url: url,
          beforeSend: function(XMLHttpRequest){ },
          success:function(Message){  
           if(Message =="succreview")
           {
             document.getElementById("Errors").innerHTML ="<font color='red'>Thank you, your message will appear soon after reviewed.</font>";
           }
           else if(Message=="succquestion")
           {
                document.getElementById("Errors").innerHTML ="<font color='red'>Thank you, your question has been received, we will reply to you ASAP.</font>";
           }
           else if(Message == "Error")
           {
            document.getElementById("Errors").innerHTML ="<font color='red'>try Again!</font>";
           }
           else if(Message == "Coms")
           {
             document.getElementById("Errors").innerHTML ="<font color='red'>can not null!</font>";
           }          
           else if(Message =="Prod")
           {
             document.getElementById("Errors").innerHTML ="<font color='red'>select product!</font>";
           }
           else if(Message == "Exit")
           {
            document.getElementById("Errors").innerHTML ="<font color='red'>You have submitted comment for this item already.</font>";
           }
          }, 
        error:function(){
             document.getElementById("Errors").innerHTML ="<font color='red'>Program Error!</font>";
                }
           });     
 }
 
 function isMail(mail)
 {
    var patrn = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; 
    if (!patrn.test(mail)) 
        return false; 
    else 
        return true; 
}

 function addReview(pidParam)
 {
    var questionConts = document.getElementById("ctoReview").value;
    var email="";
    if(questionConts=="")
    {
        document.getElementById("ErrorRew").innerHTML="<font color='red'>Please fill out your message.</font>";
        return;
    }
    //非登录用户
    var cookis = GetCookie("uid");
    //alert(cookis);
    if(cookis==null||cookis=="")
    {
        email=document.getElementById("txtEmail").value;
        if(email.length==0)
        {
          document.getElementById("ErrorRew").innerHTML = "<font color='red'>Please enter your Email!</font>";
          return;
        }
        else
        {
            var isEmail=isMail(email);
            if(!isEmail)
            {
                document.getElementById("ErrorRew").innerHTML = "<font color='red'>Please enter your right Email address!</font>";
                return;
            }
        }
    }
    var url="";
    var action=document.getElementById("sltAction").value;
    var infor=document.getElementById("chkReview").checked;//alert(infor);
    if(action=="review")
    {//url="/ajax.aspx?pid="+pidParam+"&content="+questionConts+"&action=addQustion"
        url="/ajax.aspx?pid="+pidParam+"&content="+questionConts+"&action=addReview"+"&email="+email+"&infor="+infor+"";
     }
     else
     {
        url="/ajax.aspx?pid="+pidParam+"&content="+questionConts+"&action=addQustion"+"&email="+email+"&infor="+infor+""
     }
    
     $.ajax({ 
          type:"get", 
          url: url,
          beforeSend: function(XMLHttpRequest){ },
          success:function(Message){  
           if(Message =="succreview")
           {
             document.getElementById("ErrorRew").innerHTML ="<font color='red'>Thank you, your message will appear soon after reviewed.</font>";
           }
           else if(Message=="succquestion")
           {
                document.getElementById("ErrorRew").innerHTML ="<font color='red'>Thank you, your question has been received, we will reply to you ASAP.</font>";
           }
           else if(Message == "Error")
           {
            document.getElementById("ErrorRew").innerHTML ="<font color='red'>Try Again!</font>";
           }
           else if(Message == "Coms")
           {
             document.getElementById("ErrorRew").innerHTML ="<font color='red'>Can not null!</font>";
           }          
           else if(Message =="Prod")
           {
             document.getElementById("ErrorRew").innerHTML ="<font color='red'>Select product!</font>";
           }
           else if(Message == "Exit")
           {
            document.getElementById("ErrorRew").innerHTML ="<font color='red'>You have submitted comment for this item already.</font>";
           }
           else if(Message == "FAL")
           {
           document.getElementById("ErrorRew").innerHTML ="<font color='red'>You have failed submit comment for this item already.</font>";
           }
          }, 
        error:function(){
             document.getElementById("ErrorRew").innerHTML ="<font color='red'>Program Error!</font>";
                }
           });
 }
 
 
 function addvotef(fidParam ,catelx)
 {
    var url="/ajax.aspx?fids="+fidParam+"&catelx="+catelx+"&action=addVote";
   // alert(url);
      $.ajax({ 
          type:"get", 
          url: url,
          beforeSend: function(XMLHttpRequest){ },
          success:function(Message){
              var returnstr = "";
              var a = Message.split(',');
               if(a[0] == "SUCCESS")
                 {
                   if(catelx == "addYes")
                     document.getElementById("addyes"+fidParam).innerHTML= a[1];
                   else
                     document.getElementById("addnot"+fidParam).innerHTML= a[1];
                 }
               else
                 {
                   document.getElementById("votemsg"+fidParam).innerHTML= "<font color='red'>"+a[1]+"</font>";
                   // alert("<font color='red'>"+a[1]+"</font>");
                 }
            }
          });          
  }
 
 
 function  change(osel)
 {
       var countryID = osel.options[osel.selectedIndex].value;
       var prodID  = document.getElementById("pID").value ;
	   var url="/ajax.aspx?cyID="+countryID+"&pID="+prodID+"&action=ship";
	   //alert(url);   
      $.ajax({ 
          type:"get", 
          url: url,
          beforeSend: function(XMLHttpRequest){ },
          success:function(Message){
	             document.getElementById("pst_shipp").innerHTML="";
	             document.getElementById("pst_shipp").innerHTML =Message;
            },
          error:function(){
             document.getElementById("pst_shipp").innerHTML="Error!";
           } 
          });    
  }
 
 function chanages(osel)
 {
      var countryID = osel.options[osel.selectedIndex].value;
      var url="/ajax.aspx?cyID="+countryID+"&action=countryship";
      $.ajax({ 
      type:"get", 
      url: url,
      beforeSend: function(XMLHttpRequest){ },
      success:function(Message){
             var Array = Message.split("|||");
             if(Array[0]=="Free")
             {
                document.getElementById("ctl00_ContentPlaceHolder2_Free").innerHTML ="Free to "+Array[1];
                document.getElementById("ctl00_ContentPlaceHolder2_pst_shipp").value ="Free";
             }
             else
             {
                document.getElementById("ctl00_ContentPlaceHolder2_Free").innerHTML ="";
                document.getElementById("ctl00_ContentPlaceHolder2_pst_shipp").value =Array[1];
             }
        },
      error:function(){
         document.getElementById("ctl00_ContentPlaceHolder2_pst_shipp").value="Error!";
       } 
      });
 }
 
    //修改货币类型
      function change_currency(cy)
        {
      	   var url = "/changecurrent.aspx?c="+cy.value;
		    $.ajax({
	 	    type:"get",
		    url:url,
		    //timeout: 3000,
		    beforeSend:function(){ },
		    success:function(msg){
			      top.window.location.reload(true);   
		    },
		     error:function(){
             
                }
           });
      }      
 //选择map时改变价格
  function changeMap(obj,pid)
  {
      document.getElementById("divEmail").style.display="none";
      document.getElementById("ctl00_ContentPlaceHolder2_ImageButton1").style.display="";
      var url = "/ajax.aspx?action=map"+"&pid="+pid+"&type="+obj;//alert(url);
	        $.ajax({
 	        type:"get",
	        url:url,
	        beforeSend:function(){ },
	        success:function(msg){
		          $("#pstr").html(msg);   
	        },
	         error:function(){
             
                }
           });
  }

   //选择颜色
   function selecColor(colorParam ,colorjsParam)
   {
      var cookename="colors";
      document.getElementById("ErrorMsg").innerHTML="";
       if(colorParam != "")
        {
            // SetCookie(cookename,colorParam);
             var cookis =  GetCookie(cookename);
             if(cookis != ""|| cookis != null)
             {
                DelCookie(cookename);
                SetCookie(cookename,colorParam);
             }
             else
             {
                DelCookie(cookename);
                 SetCookie(cookename,colorParam);
             }         
        }
       var colorvalue = "sColor"+colorParam;
       var array = colorjsParam.split('-');
       for(var i=0 ; i<array.length; i++)
       {
           
           document.getElementById("sColor"+array[i]).setAttribute("class", "colorChange");
           document.getElementById("sColor"+array[i]).setAttribute("className", "colorChange");
       }
       document.getElementById(colorvalue).setAttribute("class", "colorSelect");
       document.getElementById(colorvalue).setAttribute("className", "colorSelect");
      // alert(colorvalue);
   }
   
   
   //检查用户是否选择了颜色 
   function checkColor(colorcount,mFlag,pid)
   {
        //alert(colorcount+mFlag);
       var cookename = "colors";
       var cookis =  GetCookie(cookename);
       //alert("cookis"+cookis);
       if(parseInt(colorcount)>1)
       {
         if(cookis == "" || cookis == null)
          {
            document.getElementById("ErrorMsg").innerHTML =" Please choose the color!";
           return false ;
          }
       }
       else
       {
          if(cookis == "" || cookis == null)
          {
            SetCookie("colors","Black");
           }
       }
       //记录选择的地图
       if(mFlag=="y")
       {
           var map="bb";
           if(exist("rdoA")&&document.getElementById("rdoA").checked==true)
           {
                map="a";
           }
           if(exist("rdoE")&&document.getElementById("rdoE").checked==true)
           {
                map="e";
           }
           if(exist("rdoU")&&document.getElementById("rdoU").checked==true)
           {
                map="u";
           }
           if(exist("rdoN")&&document.getElementById("rdoN").checked==true)
           {
                map="n";
           }
           if(map=="bb")
           {
                document.getElementById("ErrorMsg").innerHTML =" Please choose the map!";
                return false;
           }
           else
           {
                SetCookie(pid,map);//地图类型
           }
       }
       return true;
   }
 
 function exist(id){
    var s=document.getElementById(id);
    if(s){return true;}
    else{return false;}
   }
   
    //color
function changeImgs(color ,prod){
document.getElementById("productImg").src="/Upload/product/default/"+prod+"/"+color+".JPG";
} 

function chkEmail()
{
    var pno=document.getElementById("h2pno").innerHTML;
    //alert(pno);
    var email=document.getElementById("ctl00_ContentPlaceHolder2_txtEmail").value;

    var name=document.getElementById("ctl00_ContentPlaceHolder2_txtName").value;
    if(name.length==0)
    {
        document.getElementById("ctl00_ContentPlaceHolder2_gMsg").innerHTML="Please input your name!";
    }
    else if(!isMail(email))
    {
        document.getElementById("ctl00_ContentPlaceHolder2_gMsg").innerHTML="Email is wrong!";
    }
    else
    {
        $.get("/ajax.aspx?action=groupbuy&uemail="+email+"&pno="+pno+"&uname="+name, function(data){
  document.getElementById("ctl00_ContentPlaceHolder2_gMsg").innerHTML=data;
});
    }
}

function replyReview(obj)
{
   SetCookie("rrid",obj);//alert(obj);
   document.getElementById("ctoReview").focus();
}

function replyQuestion(obj)
{
    SetCookie("rqid",obj);
    document.getElementById("ctomquest").focus();
}

 
