﻿function copyToClipBoard(){ 
var clipBoardContent=document.location; 
clipBoardContent+='\r\n'; 
window.clipboardData.setData("Text",clipBoardContent); 
alert("Copy success!"); 
}  
function LoadLoginInfo()
{
  var today = new Date();
  $.ajax({
      type:"POST",
      url:"/Ajax/DataUpdate.aspx?Type=11&time=" + today.getTime(),
      dataType:"html",
      data:"",
      beforeSend:function()
      {},
      success:function(result)
      {
        $("#logindiv").html(result);
      }             
       });    
}
function KeywordSearch(keywords)
           {
               if(keywords != "")
               {
                   location.href=  "/SearchList.aspx?keyword=" + escape(keywords);
               }
               else
               {
                   alert("please input keywords");
               }
           }
function changeCurrencies(selectedvalue,CurrenciesId)
           { 
             if( $("#CanCurrentCurrencies").val() == "false")
             {
               alert("Sorry! you can change currencies this time!");
               $("#" + CurrenciesId)[0].selectedIndex = 0;
             }
             else
             {
             
               $.ajax({
               type:"POST",
               url: "/Ajax/DataUpdate.aspx?Type=3&currency=" + selectedvalue,
               dataType:"html",
               data:"",
               success:function(result)
               {
                   window.location.reload();
                   //alert(result);
               }
                    });                 
             }
           }
           
           function Subscribe()
           {    
               $.ajax({
               type:"POST",
               url: "/Ajax/DataUpdate.aspx?Type=2&email=" + $("#TextBoxSubscribe").val(),
               dataType:"html",
               data:"",
               success:function(result)
               {
                   alert(result);
               }
                    });
           }
           
           function GoHelpPage()
           {
               window.location.href= "/Help/";
           }
           
           function checkinputbuy(buy,hiddenProductId)
		   {
		         if (/^[-+]?\d+(\.\d+)?$/.test( buy.value )) 
		         {
			                      //var ret = true;
		              $.ajax({
                      type:"POST",
                      url:   "/Ajax/DataUpdate.aspx?Type=5&productid=" + $("#"+hiddenProductId).val() + "&qty=" +  $("#Qty").val(),
                      dataType:"html",
                      data:"",
                      success:function(result)
                      {
                         //alert(result);
                         if(result=="false")
                         {
                              alert("Sorry, the quality of the product does not exist,Please try another quality");
                              buy.value="";
                              buy.focus();
                              return false;
                          } 
                          else
                          {
                               return true;
                           }                                
                                     
                        }
                              });
                                        
                          //alert("return:" + ret)
                          // return ret;       
			    }    
		        else
			    {
			         alert("Please input Qty value!");
			         buy.value= "";
			         buy.focus();
			         return false;
			    }
		  }
		  
		  function AddToFavorite(proId)
          {
              window.location.href=  "/Member/MyFavorites.aspx?id="+proId;
          }
                      
          //加入购物车          function ItemAddToCart(qty,proId,sizeId, colorId)
          {
             if (/^[-+]?\d+(\.\d+)?$/.test(  $("#Qty").val() )) //验证输入的数量             { 
                 var url =   "/ShoppingCart/ShoppingCart.aspx?qty=" + qty + "&proId=" + proId + "&sizeId=" + sizeId + "&colorId=" + colorId;
                 var popup=window.open(url,"shoppingcarts");

                 popup.focus();
             }
             else
             {
                 alert("Please the correct input Qty value!");
             } 
          }
          
          function OutputPriceHTML(hiddenProductId)
          {
              $.ajax({
              type:"POST",
              url:"/Ajax/DataUpdate.aspx?Type=4&productid=" + $("#"+hiddenProductId).val(),
              dataType:"html",
              data:"",
              beforeSend:function()
              {
                 //
              },
              success:function(result)
              {
                 $("#divprices").html(result);
              },
              complete:function()
              {
                 $("#divpriceloading").html("");
              }
             
              
                    });
          }
          
          
          function shopcartcheckinputbuy(buyid,productid,  orignalValue,orignalMemo,shoppingId, memo)
          {
             if($("#" + buyid).val()!=orignalValue || $("#" + memo).val()!=orignalMemo)
             { 
                 if (/^[-+]?\d+(\.\d+)?$/.test( $("#" + buyid).val() )) 
		         { 
		            $.ajax({
                    type:"POST",
                    url:  "/Ajax/DataUpdate.aspx?Type=6&productid=" + productid + "&qty=" + $("#" + buyid).val() + "&cartid=" + shoppingId + "&memo=" + $("#" + memo).val(),
                    dataType:"html",
                    data:"",
                    success:function(result)
                    { 
                       if(result=="true")
                       { 
                         alert("updated");
                         var reloadurl =   "/ShoppingCart/ShoppingCart.aspx";
                         window.location.href(reloadurl);
                        } 
                      else
                       {
                          alert(result);
                          $("#" + buyid).val(orignalValue);
                        }                                
                          
                   }
                       });        
	           }   
		      else
		      {
		         alert("Please input Qty value!");
		         $("#" + buyid).val(orignalValue);  
		         return false;
		      }
	        } 
         }


       function UpdatedAmount()
       {
          var items = $('input[@type=checkbox][@checked]');
          var ids="0";
          items.each(function(i){
          ids = ids+"," + items[i].value;
          });
       
          // alert(ids);
          $.ajax({
          type:"POST",
          url:  "/Ajax/DataUpdate.aspx?Type=7&cartIds=" +  ids,
          dataType:"html",
          data:"",
          success:function(result)
          { 
                   // alert(result);
             $("#AmountDiv").html(result);
                                                 
          }
          });        
       }
       
       
       function GetRecommandItemsAtProductViewpage(hiddenProductId)
       {
          $.ajax({
          type:"POST",
          url:  "/Ajax/DataUpdate.aspx?Type=8&productid=" +  $("#"+hiddenProductId).val(),
          dataType:"html",
          data:"",
          success:function(result)
          {  
             $("#recommandDiv").html(result);
                                                 
          },
          complete:function()
          {
             $("#divFeaturedloading").html("");
          }
              
          });        
       }
       
       function DisplayBigPic(imgId,picUrl)
       {
            //alert(imgId);
            //alert($("#" + imgId).attr("src") );
             $("#" + imgId).attr({ src: picUrl });
       }
       
        function CheckProductFileName(filename)
        {     
          $.ajax({
          type:"POST",
          url:  "/Ajax/DataUpdate.aspx?Type=9&filename=" +  $("#"+filename).val(),
          dataType:"html",
          data:"",
          success:function(result)
          {  
             alert(result);
                                                 
          }
          });        
              
        }
        
        function LoadProductPrice(id)
        {     
           var today = new Date();  
           $.ajax({
              type:"POST",
              url:"/Ajax/DataUpdate.aspx?productid="+ id + "&Type=10&time=" + today.getTime(),
              dataType:"html",
              data:"",
              beforeSend:function()
              {
                 //
              },
              success:function(result)
              {
                 $("#div" + id).html(result);
              }              
              
                    });
        }
       
      
       
//全选或取消全选 数据库列表的checkbox
function SelectAll(obj,cbName)
{
	var objForm=obj.form;
	var CheckBoxName=cbName;
	
	if(obj.tagName=="INPUT")
	{
		if(obj.type.toUpperCase()!="CHECKBOX")
		{
		   // alert("test1");
			if(obj.checked==true)
			{
				obj.checked=false;
			}else
			{
				obj.checked=true;
			}
		}
	}
	if(objForm)
	{
	    for(var iTemp=0;iTemp<objForm.elements.length;iTemp++)
		{
		    if((objForm.elements[iTemp].name.indexOf(CheckBoxName)+CheckBoxName.length)==objForm.elements[iTemp].name.length)
			{
				if(objForm.elements[iTemp].tagName=="INPUT")
				{
				    if(objForm.elements[iTemp].type.toUpperCase()=="CHECKBOX")
					{	
						objForm.elements[iTemp].checked=obj.checked;
					}
				}
			}
		}
	}
}