﻿// JScript 文件

/* begin chenhuiUD*/
/* 是否显示shop cart数量*/
var booltxtQuantity=1;
function updateTypeQuantity(id1,id2)
{
    if(booltxtQuantity==1)
    {
       document.getElementById(id2).style.display="";
       document.getElementById(id1).style.display="none";
       booltxtQuantity=0;
    }
    else
    {
      document.getElementById(id2).style.display="none";
      document.getElementById(id1).style.display="";
      booltxtQuantity=1;
    }
}
/* end chenhuiUD*/
function show_img(imgurl,id)
{   
    //alert("aa");
    var tempstr ="this.style.visibility='visible';document.getElementById(\"loaderInfo\").style.display='none'";
   
	 document.getElementById("img_show" + id).innerHTML="<div id='loaderInfo'><img src='/images/ajax-loader.gif'><br />&nbsp;&nbsp;&nbsp;Loading...</div><img onerror=javascript:this.src='/images/uploadpic/noimage.gif' onload=" + tempstr + " src='/images/uploadpic/"+ imgurl + "' />";
//	 alert(document.getElementById("img_show" + id).innerHTML);
}

function show_img_clear(id)
{
    
	document.getElementById("img_show" + id).innerHTML ="";
}

function show_img_paimai(imgurl,id)
{   
    var tempstr ="this.style.visibility='visible';loaderInfo.style.display='none'";
	document.getElementById("img_show" + id).innerHTML="<div id='loaderInfo'><img src='images/ajax-loader.gif'><br />&nbsp;&nbsp;&nbsp;Loading...</div><img onerror=javascript:this.src='images/uploadpic/noimage.gif' onload=" + tempstr + " src='images/paimai_upload/"+ imgurl + "' />";
}


/**
* AJAX Buy Shop
* @param ProductID 
*
*
**/
var firstAddToCart = false;
var obj_x,obj_y;

function AddToShopCart(ProductID,ServerID,ev)
    {
       
        alert_msg_Timer_value = 5;
		clearTimeout(alert_msg_Clock);
		                
		ev= ev || window.event; 
		obj_x = ev.clientX;
		obj_y = ev.clientY;
		
        var xmlHttp;
	    if (window.ActiveXObject) { 
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    } 
		else if (window.XMLHttpRequest) {
			    xmlHttp = new XMLHttpRequest();
		    }
		    else
		    {
		        alert("no");
		    }
		
	    var now= new Date();
	    // url="/AjaxFolds/Ajax_BuyProduct.aspx?ProductID=" + ProductID + "&ServerID=" + ServerID + "&key=" + Math.random();
        url="/AjaxFolds/Ajax_BuyProduct.aspx?ProductID=" + ProductID + "&key=" + Math.random();
        if(ServerID.length >0)
        {
            url += "&ServerID=" + ServerID;
        }
        xmlHttp.onreadystatechange = function(){
        if(xmlHttp.readyState == 4) {
			    if(xmlHttp.status == 200) {
				    var AllHtml =xmlHttp.responseText;
				   //alert("aa" + ProductID + "bb" + AllHtml);
				     chenhui_GetProductTotalCount();
                     chenhui_GetProductTotalPrice();
				    var viewhtml = "";
				    if(AllHtml == "1")
				    {
				         FlyToCart(ProductID);
				        ViewShopCart(0,ProductID,1);//update ShopCart Num
				        
				    }
				    else
				    {
				        //alert(AllHtml);
				            viewhtml += "<div class=\"htmlInfoStyle\"> <img id=\"ok_cart_id\" src=\"images/ok_no_Cart.gif\" /> <span class=\"bigMoneyStyle\"> " + AllHtml + " </span></div>";
		                    global_frame_new("title", viewhtml,op);
				    }
				    xmlHttp = null;
			    }
		    }
        
        }
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
        return false;
    }
    
    
        

        function cutNum(indexNum,ProductID){
            var obj_text = document.getElementById("text" + indexNum);
	        obj_text.value = parseInt(obj_text.value) -1;
	        UpdateShopCart(ProductID,obj_text,0);
        }
        
        function AddNum(indexNum,ProductID){
             var obj_text = document.getElementById("text" + indexNum);
	        obj_text.value = parseInt(obj_text.value) +1;
	        UpdateShopCart(ProductID,obj_text,0);
        }
    
    
    /**
    * AJAX 
    * @param isThree 
    *
    *
    **/
    function ViewShopCart(isThree,ProductID,boolalert)
    {
         
        var xmlHttp;
	    if (window.ActiveXObject) { 
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    } 
		else if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }else{
            alert("no");
        }
	    
	    var now= new Date();
        url="/AjaxFolds/Ajax_UpdateTopShopingCart.aspx?key=" + now.getMilliseconds();
        xmlHttp.onreadystatechange = function(){
        
        if(xmlHttp.readyState == 4) {
			    if(xmlHttp.status == 200) {
				    var AllHtml =xmlHttp.responseText;

				    //alert(AllHtml);
//				    return false;
				    
//				    var arr = AllHtml.split('$$$$$');
//				    document.getElementById("Ajax_ShopCartCount").innerHTML = arr[0];
//				    document.getElementById("hid_TotalPrice").value =  arr[1];
//				    document.getElementById("Ajax_ShopCartPrice").innerHTML = curr_MoneyType + " " + accMul(arr[1],curr_Rate.toString());
//				    
//				    if(boolalert ==1)
//				    {
//				        var curr_count_str = "";
//		                var curr_price_str = "";
////		                var viewhtml="<div class=\"htmlInfoStyle\">";
//		                var viewhtml = "<div class=\"htmlInfoStyle\"> <img id=\"ok_cart_id\" src=\"images/ok_Cart.gif\" />";
//		                if(firstAddToCart)
//		                {
//		                   viewhtml += "  <span class=\"bigMoneyStyle\"> <img id=\"ok_cart_id\" src=\"images/loading_ajax.gif\" /> </span></div>";
//		                }
//		                else
//		                {
//		                  viewhtml += "<span class=\"bigMoneyStyle bigMoneyStyle_wrap\"> Total : " + arr[0] + " Items " + document.getElementById("Ajax_ShopCartPrice").innerHTML + " </span></div>";

//		                }
//		
//		                global_frame_new("title", viewhtml,op);
//		            }
//				    
//				    if(isThree == 1)
//				    {
//				        document.getElementById("BigPrice_Ajax").innerHTML = curr_MoneyType + " " + accMul(arr[1],curr_Rate.toString());
//				    }
                    //alert("已经成功添加到购物车!");
				    xmlHttp = null;
				   
			    }
		    }
        
        }
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
        return false;
    }
    
    /**
    * AJAX CheckOut
    * @param ProductID:    
    * @param ProductNum:    
    * @param TotalPriceID:  
    * @param Price:         
    **/
    function UpdateShopCart(ProductID,ProductNum,boolalert)
    {   
        
        var xmlHttp;
	    if (window.ActiveXObject) { 
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    } 
		else if (window.XMLHttpRequest) {
			    xmlHttp = new XMLHttpRequest();
		    }
		    else
		    {
		        alert("no");
		    }
	    
	    var now= new Date();
	    
	    url="/AjaxFolds/Ajax_UpdateShopCart.aspx?ProductID=" + ProductID + "&ProductNum=" + ProductNum.value + "&key=" + now.getMilliseconds();
        xmlHttp.onreadystatechange = function(){
        if(xmlHttp.readyState == 4) {
        
               ViewShopCart(0,ProductID,boolalert);//更新顶部购物车显示的数量
               
			    if(xmlHttp.status == 200) {
				    var AllHtml =xmlHttp.responseText;
				    //alert(AllHtml);
				    //alert(document.getElementById("Ajax_UpdateShopCart_View").innerHTML);
				     var arr = AllHtml.split('$$$$$');
				    if (arr[0]=="0")
				    {
				        alert("Unable to add,not enough inventory!");
				        window.location.reload();
				        document.getElementById("Ajax_UpdateShopCart_View").innerHTML = arr[1];
				        
				        
				    }
				    else
				    {
				         window.location.reload();
				        document.getElementById("Ajax_UpdateShopCart_View").innerHTML = arr[1];
				         
				    }
				    
				    xmlHttp = null;
				    
			    }
		    }
        
        }
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
        return false;
    }
    
    /**
    * AJAX CheckOut页面..更改购物车 数量
    * @param ProductID:     商品ID
    * @param ProductNum:    商品数量
    * @param TotalPriceID:  控制改变商品总价格的ID
    * @param Price:         商品的单价
    **/
    function UpdateShopCartDel(ProductID)
    {   
       
        var xmlHttp;
	    if (window.ActiveXObject) { 
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    } 
		else if (window.XMLHttpRequest) {
			    xmlHttp = new XMLHttpRequest();
		    }
		    else
		    {
		        alert("no");
		    }
	    
	    var now= new Date();
	    
	    url="/AjaxFolds/Ajax_UpdateShopCart.aspx?ProductID=" + ProductID + "&key=" + now.getMilliseconds();
	    //alert(url);
        xmlHttp.onreadystatechange = function(){
        if(xmlHttp.readyState == 4) {
        
                ViewShopCart(0,ProductID,0);//更新顶部购物车显示的数量
                
			    if(xmlHttp.status == 200) {
				    var AllHtml =xmlHttp.responseText;
				    //alert(AllHtml);
				    //alert(document.getElementById("Ajax_UpdateShopCart_View").innerHTML);
				    var arr = AllHtml.split('$$$$$');
				    document.getElementById("Ajax_UpdateShopCart_View").innerHTML = arr[1];
				     window.location.reload();
				    xmlHttp = null;
				    
			    }
		    }
        
        }
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
        return false;
    }
    
    function UpdateShopCartFalse()
    {
        document.getElementById("Ajax_UpdateShopCart_View").style.display = "none";
        setTimeout("document.getElementById('Ajax_UpdateShopCart_View').style.display = 'block';",300); 
    }
    
  

//控件输入
function onlyNum(obj) 
    {
        if(obj.value != obj.value.replace(/\D/g,''))
        {
            if(obj.value.replace(/\D/g,'') == "")
            {
                obj.value = "1";
                obj.onchange();
            };
            obj.value=obj.value.replace(/\D/g,'');
            //return;
        }
        else
        {
            if(obj.value == "")
            {
               obj.value = "1";
               obj.onchange();
            }
        }
    } 
    
//求单选按纽的值，传radio名字作为参数。未选返回false；有选择项，返回选项值。
function getRadioValue(name){
    var radioes = document.getElementsByName(name);
    for(var i=0;i<radioes.length;i++)
    {
         if(radioes[i].checked){
          return radioes[i].value;
          //alert(radioes[i].value);
         }
    }
    return false;
}

function set_JS_SendAreaMoney()//送货
{   
    document.getElementById("tb_JS_SendAreaMoney").value = getRadioValue("radio_Area");
}

function set_JS_PayType()//支付方式
{
   document.getElementById("tb_JS_PayType").value = getRadioValue("radio_PayType");
}


    var flyingSpeed = 15;
	var shopping_cart_div = false;
	var flyingDiv = false;
	var currentProductDiv = false;
	
	var shopping_cart_x = false;
	var shopping_cart_y = false;
	
	var fly_diffX = false;
	var fly_diffY = false;
	
	var currentXPos = false;
	var currentYPos = false;


function FlyToCart(productId)
	{
		//if(!shopping_cart_div)shopping_cart_div = document.getElementById('ok_cart_id');//CartInfo//ok_cart_id
		
		shopping_cart_div = document.getElementById('img_Fly_'+productId);
		
		if(!flyingDiv){
		flyingDiv = document.createElement('DIV');
		flyingDiv.style.position = 'absolute';
		flyingDiv.style.zIndex=9999;
		document.body.appendChild(flyingDiv);
		}	
		
		//获得购物车的位置
		shopping_cart_x = shoppingCart_getLeftPos(shopping_cart_div);
		shopping_cart_y = shoppingCart_getTopPos(shopping_cart_div);
		
		//获取当前商品位置
		currentProductDiv = document.getElementById('slidingProduct' + productId);//slidingProduct//img_Fly_
		currentXPos = shoppingCart_getLeftPos(currentProductDiv);
		currentYPos = shoppingCart_getTopPos(currentProductDiv);
	    
		fly_diffX = shopping_cart_x - currentXPos;
		fly_diffY = shopping_cart_y - currentYPos;
	
		var shoppingContentCopy = currentProductDiv.cloneNode(true);
		shoppingContentCopy.id='';
		flyingDiv.innerHTML = '';
		flyingDiv.style.left = currentXPos + 'px';
		flyingDiv.style.top = currentYPos + 'px';
		flyingDiv.appendChild(shoppingContentCopy);
		flyingDiv.style.display='block';
		flyingDiv.style.width = currentProductDiv.offsetWidth + 'px';
		flyingDiv.style.zoom = null;
		flyToBasketN(productId);
		
	}
	
function flyToBasketN(productId)
	{
		var maxDiff = Math.max(Math.abs(fly_diffX),Math.abs(fly_diffY));
		var moveX = (fly_diffX / maxDiff) * flyingSpeed;
		var moveY = (fly_diffY/ maxDiff) * flyingSpeed;
		
		var startZoom;
		var endZoom;
		startZoom=1;
		endZoom=0.1;
		currentXPos = currentXPos + moveX;
		currentYPos = currentYPos + moveY ;
		
		flyingDiv.style.left = Math.round(currentXPos) + 'px';
		flyingDiv.style.top = Math.round(currentYPos) + 'px';
		if(!flyingDiv.style.zoom){
			flyingDiv.style.zoom = startZoom;
		}else{
			flyingDiv.style.zoom = (flyingDiv.style.zoom -endZoom)*0.95+endZoom;
		}
		
		
		if(moveX>0 && currentXPos > shopping_cart_x){
			flyingDiv.style.display='none';		
		}
		if(moveX<0 && currentXPos < shopping_cart_x){
			flyingDiv.style.display='none';		
		}
		
		if(flyingDiv.style.display=='block'){
			
			setTimeout('flyToBasketN("' + productId + '")',10);
		}
		else{
			
		}
	}
	
	
function shoppingCart_getTopPos(inputObj)
	{
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
		if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
	  }
	  return returnValue;
	}
	
function shoppingCart_getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null){
		if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
	  }
	  return returnValue;
	}
	
	

/******************  Begin cart 2 **************/

function global_frame_new(title, html, option) {
    if(document.getElementById("wid"))
    {
        CloseMsg();
    }
	var msg_box_html = "<div class=\"layer_global_main\">";
	msg_box_html += " <div id=\"_head\" class=\"layer_global_title\"  onmousedown=\"Milan_StartMove(event,this.parentNode.parentNode);\" onmouseup=\"Milan_StopMove(event);\">";
	msg_box_html += "<h3>title</h3>";
	msg_box_html += "<img src=\"images/close_js.gif\" class=\"close_button\" onclick=\"CloseMsg(\'wid\');\" /> </div>";
	msg_box_html += "<div class=\"layer_global_cont clearfix\">";
	msg_box_html += "<div > " + html + "</div>";
	msg_box_html += "</div>";
	msg_box_html += "<div class=\"global_tip_button\"> <span id=\"alert_timer_view\"> 10 s </span> <a id=\"wid_submit\" href=\"/EVE_Online_EditeCart.aspx\" class=\"bt_tx2\">Editing Cart</a> <a id=\"wid_cancel\"  href=\"/EVE_Online_CheckOut_1.aspx\" class=\"bt_tx_c2\">Check Out</a> </div>";
	msg_box_html += "</div>";
    var op = {
		div_class: 'layer_global',
        div_width: 350,
        div_height: '',
        submit_class: 'bt_tx2',
        cancel_class: 'bt_tx_c2',
        time_out: 0,
        zIndex: 99
    };
	 
	Object.extend(op, option);
	var msg_box=document.createElement("div");
	msg_box.setAttribute("id","wid");
	msg_box.className = "layer_global";
	msg_box.style.zIndex=999;
	
	msg_box.innerHTML = msg_box_html;
	 try {
            document.body.appendChild(msg_box);
        } catch(e) {
            return false;
        };
		
	var divId=document.getElementById("wid");
	divId.style.width = op.div_width + "px";
	//divId.style.height = op.div_height + "px";
	
	divId.style.left= obj_x + document.documentElement.scrollLeft - divId.clientWidth -20 +"px";
	divId.style.top=obj_y + document.documentElement.scrollTop - divId.clientHeight - 20 +"px";
	
	alert_msg_Timer();
}
  
Object.extend = function(destination, source) {
     for (property in source) {
       destination[property] = source[property];
     }
     return destination;
}

Object.prototype.extend = function(object) {
     return Object.extend.apply(this, [this, object]);
} 
 
function CloseMsg(){
		document.body.removeChild(document.getElementById("wid"));
	}

var alert_msg_Timer_value = 50;
var alert_msg_Clock;
var msg_box_offset_x;
var msg_box_offset_y;
var boolmove = false;
function Milan_StartMove(oEvent,div_id)
{
	boolmove = true;
    var whichButton;
    if(document.all&&oEvent.button==1) whichButton=true;
    else { if(oEvent.button==0)whichButton=true;}
    if(whichButton)
    { 
        var oDiv=div_id;
        msg_box_offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft);
        msg_box_offset_y=parseInt(oEvent.clientY-oDiv.offsetTop);
        document.documentElement.onmousemove=function(mEvent)
        {    
            var eEvent;
            if(document.all) eEvent=event;
            else{eEvent=mEvent;}
            var oDiv=div_id;
            var x=eEvent.clientX-msg_box_offset_x;
            var y=eEvent.clientY-msg_box_offset_y;
            oDiv.style.left=(x)+"px";
            oDiv.style.top=(y)+"px";
            var d_oDiv=document.getElementById("disable_"+oDiv.id);
            //d_oDiv.style.left=(x)+"px";
            //d_oDiv.style.top=(y)+"px";
        }
    }
}

function alert_msg_Timer(){
	//alert("af");
	if(!boolmove)
	{
		document.getElementById("alert_timer_view").innerHTML = alert_msg_Timer_value + " s ";
		alert_msg_Timer_value --;
	}
	if(alert_msg_Timer_value <-1)
	{
		clearTimeout(alert_msg_Clock);
		CloseMsg();
	}
	else
	{
		alert_msg_Clock = setTimeout("alert_msg_Timer();",1000);
	}
	
};
function Milan_StopMove(oEvent){boolmove = false;document.documentElement.onmousemove=null; };
var op = {div_width:360};

/*******************        End cart 2 ***********/






