﻿// JScript 文件
 

 $(document).ready(function(){ 
	        
		 ExchangRateUpdate();
		 /////set up keyboard enter--------------
		 LoadFiled("ep","","Carrier");
		 LoadFiled("air","","Carrier");
		  $(".TraceKey").keydown(function(e){
			  if(e.keyCode==13) {
				    var ids=$(document.activeElement).attr("id");
				
				  var kws=$("#"+ids).val();
				// alert(kws);
				$("#"+ids+"_bt").click();
				 // SearchWeb(kws);
				  return false; ///no submit
				  }
			  });
		 
		 
		 //////----------Scall to-----------------
			 
			  $('a[href*=#]').click(function(){
        			if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname){
           				var $target = $(this.hash);
          				$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
           				if ($target.length){
                  			var targetOffset = $target.offset().top;
                  			$('html,body').animate({scrollTop: targetOffset}, 1000);
                			return false;
             			}
         			}
   			 });
			  ////////////////////////////////
 
		});


function SearchWeb(kws)
{ 
 $("#searching").show();
	$.ajax({
        url:encodeURI("/AjaxLoad.aspx?Act=Search&kws="+kws),
        type:"get",
        dataType:"text",
        cache:false,
        success:function (msg){
        // alert(msg);
          $("#typeContent").html(msg);
		   $("#searching").hide();
		  // $("#Table_pageContent").hide();
            }
		 });
}

function LoadFiled(type,val,cls)
{ 
	if(val!="" && cls=="Carrier")
	{
		cls="Weight"
		LoadFiled(type,val,cls); 
		cls="Destination"
		LoadFiled(type,val,cls);
		cls="Descrip"
		LoadFiled(type,val,cls);
		$("#rs_"+type+"_price").html("<img src='/img/Field_loading.gif' />"); 	 
	} 
	 $("#"+type+"_"+cls).slideUp('slow');
	 var usrl="/AjaxLoad.aspx?Act=LoadFiled&type="+type+"&val="+val+"&cls="+cls;
		 $.ajax({
			url:encodeURI(usrl),
			type:"post",
			dataType:"text",
			cache:false,
			success:function (msg){
				
				$("#"+type+"_"+cls).slideDown('fast');
			 $("#"+type+"_"+cls).html(msg);  
				},
			error: function () { } 
		}); 
   
}
 
function LoadPrice(type)
{
	
	
	var v_wgh=$("#"+type+"_Weight_sel").val();
	var v_des=$("#"+type+"_Destination_sel").val();
	var v_wgh_num=$("#"+type+"_Weight_num").val();
	 var alt="";
	 if (v_wgh=="") alt+="[Weight Reference:]";
	 if (v_des=="") alt+="[Destination / Code:]";
	
	 $("#rs_"+type+"_price").html(  "<img src='/img/Field_loading.gif' /><span class='ReMark'>" +(alt!=""? "Please Choose "+alt: "")+"</span>"); 	 
	//alert(alt);
	 var regu =/^[0-9 ]{0,10}[.]{0,1}[0-9]{0,5}$/;
	var re = new RegExp(regu); 
	if(v_wgh_num.search(re) == -1) 
	{$("#"+type+"_w_info").html("Shoul be a number!"); return false; } else  {$("#"+type+"_w_info").html(""); }
 
	if(v_wgh!="" && v_des!="" )
	{
		 
	 	var usrl="/AjaxLoad.aspx?Act=LoadPrice&v_wgh="+v_wgh+"&v_des="+v_des+"&v_wgh_num="+v_wgh_num;
	 	//alert(usrl);
		 $.ajax({
			url:encodeURI(usrl),
			type:"get",
			dataType:"json",
			cache:false,
			success:function (msg){ 
			//  alert(msg);
			// $("#"+type+"_Weight_sel").fadeIn('slow');
			  if(msg.w_id!=0  && msg.w_id!=null )   $("#"+type+"_Weight_sel").attr("value", msg.w_id); //$("#"+type+"_Weight_sel")[0].options[msg.w_id].selected = true; 
			  $("#rs_"+type+"_price").html(msg.price); 
				},
			error: function () {} 
		}); 
	}
		 
}
  

function TraceShippment(TraceType,Num)
{
	var Keys=$("#Trace_key_" +Num ).val();  
	var SelKey=$("#Trace_sel_" +Num ).val();  
	if(SelKey==null) SelKey="";
    var usrl="";
	
	if(Keys=="") 
	{
		$("#Trace_rs_" +Num ).hide("slow");
		$("#Trace_rs_" +Num ).html("");
		return true; 
	}
	else
	{
		
		$("#Trace_rs_" +Num ).html("<img src='/img/loadingAnimation.gif' style='float:left;' />");
		$("#Trace_rs_" +Num ).fadeIn("slow");
		$("#Trace_Stat_" +Num ).fadeOut("slow"); 
		$("#Trace_key_" + Num + "_bt" ).fadeOut("slow");
		usrl="/AjaxLoad.aspx?Act=LoadTraceLocal&TraceType="+TraceType+"&Key="+Keys+"&SelKey="+SelKey
	  
	}
 
   // alert(TraceType+Num+usrl);
	$.ajax({
        url:encodeURI(usrl),
        type:"post",
        dataType:"text",
        cache:false,
        success:function (msg){ 
		// alert(msg);
		 $("#Trace_rs_" +Num ).html(msg); 
		 $("#Trace_rs_" +Num ).fadeIn("slow"); 
		 $("#Trace_Stat_" +Num ).fadeIn("slow"); 
		  $("#Trace_key_" + Num + "_bt" ).fadeIn("slow"); 
		//alert($(window.frames[Keys + "_fr"].document).src);
            },
		error: function () { $("#Trace_rs_" +Num ).html("Loading Erro: "+usrl);$("#Trace_rs_" +Num ).fadeIn("slow");  $("#Trace_Stat_" +Num ).fadeIn("slow"); $("#Trace_key_" + Num + "_bt" ).fadeIn("slow"); return false;} 
 	}); 
	
}

function ExpendCart(CartID)
{
	 
	$.ajax({
        url:"/AjaxLoad.aspx?Act=ExpendCart&Cart_ID="+CartID,
        type:"post",
        dataType:"text",
        cache:false,
        success:function (msg){ 
		// alert(msg);
 		$("#cart_"+CartID).html(msg);
		$("#cart_"+CartID).toggle('slow');
            }
 	}); 
	 
	 
}


 
function ExchangRateUpdate()
{   
//alert();
	var cr1=$("#Cr1").val()==null || $("#Cr1").val()=="" ?"USD" : $("#Cr1").val()  ;
	var cr2=$("#Cr2").val()==null || $("#Cr2").val()=="" ? "CNY" : $("#Cr2").val() ;
	  $("#exchangerate").fadeIn("slow");
	 $("#exchangerate").html("<img src='/img/loadingAnimation.gif' />");
	$.ajax({
        url:encodeURI("/AjaxLoad.aspx?Act=ExchangRateUpdate&cr1="+cr1+"&cr2="+cr2),
        type:"get",
        dataType:"html",
        cache:false,
        success:function (msg){
		 // 	alert(msg);
         $("#exchangerate").html(msg);
		
		
		   $("#exchangerate").pngFix();
		  
            }
		 });
	
}

 
function slider(totalP)
{
 
 var index = 0;
	 $("#btn span").mouseover(function(){
		index  =  $("#btn span").index(this);
		showImg("img",index);
	});	
	 //滑入 停止动画，滑出开始动画.
	 $('#imgnav').hover(function(){
			  if(MyTime){
				 clearInterval(MyTime);
			  }
	 },function(){
			  MyTime = setInterval(function(){
			    showImg("img",index)
				 
				index++;
				if(index==totalP){index=0;}
			  } , 5000);
	 });
	 //自动开始
	 var MyTime = setInterval(function(){
		showImg("img",index);
	 
		index++;
		if(index==totalP){index=0;}
	 } , 5000);
}

function sliderTop(totalP)
{
 
 var TopI = 0; 
	 $('#imgnav2').hover(function(){
			  if(MyTime){
				 clearInterval(MyTime);
			  }
	 },function(){
			  MyTime = setInterval(function(){ 
				showImg("img2",TopI)
				TopI++;
				if(TopI==totalP){TopI=0;}
			  } , 6000);
	 });
	 //自动开始
	 var MyTime = setInterval(function(){ 
		showImg("img2",TopI)
		TopI++;
		if(TopI==totalP){TopI=0;}
	 } , 6000);
}

 
//关键函数：通过控制i ，来显示不通的幻灯片
function showImg(id,i){
		$("#"+id+" img")
			.eq(i).stop(true,true).fadeIn(800)
			.parent().siblings().find("img").hide();
		$("#"+id+"_msg li")
			.eq(i).stop(true,true).fadeIn(800)
			.siblings().hide();
		 $("#btn span")
			.eq(i).addClass("hov")
			.siblings().removeClass("hov");
}

function changLang_BO(lang)
{
    
 
   $.ajax({
        url:"/Adm/Ajax.aspx?tbl=ChangLang&Lang="+lang+"&rnd="+Math.random(),
        type:"post",
        dataType:"text",
        cache:false,
        success:function (msg){
        //  alert(msg);
		 	window.location=location;
          // $("#"+subinput).html(msg);
            }
 	}); 
   
	 
}

function OpenWinds(url,w,h,id_container,z)
{
 ///////////////////////////////////////////////////////////////////////////////////////
 	  
       // var ss=$("#"+id_container).html()
  		 $("#"+id_container).toggle("slow");
	 
		//alert(ss);
		if(url!=""){ ////z> 500 means open the [add product box], need refresh
			$.ajax({
				url:url,  
				type:"get",
				dataType:"text",
				cache:false,
				success:function (msg){
					// alert(msg);
					$("#talkcontent").html(msg);
					
					},
				error:function (){$("#"+id_container).html("<DIV class='ui-state-error ui-corner-all'><span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span><strong>ALERT:</strong>THERE ARE HACE ERRO WHEN LOAD THE PAGE:"+url+", PLEASE CONTACT THE ADMINISTRATOR!</DIV>");}
			 });
		 
		}
		
	 
			
	 
 } 

 

 
