﻿function PicFixSize(widths,heights,photosrc){
   var imgsrc = photosrc;
   var photowidth = 0;
   var photoheight = 0;
   var photo = new Image();
   while(photowidth ==0 || photoheight == 0)
   {
      photo.src = photosrc
      photowidth = photo.width;
      photoheight = photo.height;
   }
   if(photowidth > widths || photoheight > heights){
      if(photowidth > widths && photoheight > heights){
         height = heights;
         width = (photowidth * height) / photoheight;
         if(width > widths){
            var tmpwidth = width;
            width = widths;
            height = (height * width) / tmpwidth;
         }
      }
      if(photowidth > widths && photoheight <= heights){
         width = widths;
         height = (photoheight * width) / photowidth; 
      }
      if(photowidth <= widths && photoheight > heights){
         height =heights;
         width = (photowidth * height) / photoheight;
      }
   }
   else{
      width = photowidth;
      height = photoheight;  
   }
   return('<a href="#" onclick="NewImg(\'' + imgsrc +'\')"><img src=' + imgsrc + ' width=' + width + ' height=' + height +' border=0 align=left></a>')
}

function NewImg(imgurl) {
   newwin=window.open('about:blank','','top=10');
   newwin.document.write('<body leftmargin=0 topmargin=0><img src='+imgurl+' onload="self.resizeTo(this.offsetWidth+10, this.offsetHeight+30);">');
}

function OpenWindow(htmurl,widths,heights)
{
   var paramet = 'toolbar=no,resizable=no,scrollbars=no,width='+ widths + ',height=' + heights;
   newWindow = window.open(htmurl,"newWin",paramet);
   newWindow.focus();
}

//动态菜单--------------------------------------------------------------------
var hideTimer = "";
var highlighting = "";

function showmenu(theMenu,id){
   for (i = 0; i <theMenu.length; i++){
      theMenu[i].style.display ='none';
   }
   
   theMenu[id].style.display ='';
   high(id)
   if (hideTimer){
      cancelhide();
   }
}

function hidemenu(id){
   var interval = 5000;
   hideTimer = window.setTimeout("hide(document.all.menu," + id + ");", interval);
}

function hide(theMenu,id){
   theMenu[id].style.display ='none';
}

function cancelhide(){
   window.clearTimeout(hideTimer);
}

function high(id){
   low(document.all.menulist,id)
   highlighting = setInterval("highlightit(document.all.menulist," + id + ");",60)
}

function highlightit(cur,id){
   if (cur[id].filters.alpha.opacity< 75)
      cur[id].filters.alpha.opacity+=5;
   else if (window.highlighting)
   clearInterval(highlighting);
}

function low(cur,id){
   clearInterval(highlighting);
   cur[id].filters.alpha.opacity=25;
}

function init_hidemenu(theMenu){
   for (i = 0; i <theMenu.length; i++){
      theMenu[i].style.display ='none';
   }
}
//------------------------------------

function CheckLogonForm(theForm){
   var Email = theForm.Email.value;
   if(Email == ""){
      alert("请输入您的e-mail!");
      theForm.Email.focus();
      return  (false);
   }
   var Pwd = theForm.Pwd.value;
   if(Pwd == ""){
      alert("请输入您的密码!");
      theForm.Pwd.focus();
      return  (false);
   }
}

function CheckSearchProductForm(theForm){
   var SearchKey = theForm.SearchKey.value;
   if(SearchKey == ""){
      alert("请输入您要搜索的关键字!");
      theForm.SearchKey.focus();
      return  (false);
   }
}

function onlynumber(){
if (!((event.keyCode>47 && event.keyCode<58)))
   event.keyCode=0;
}

function onlytelcode(){
if (!((event.keyCode>44 && event.keyCode<58)))
   event.keyCode=0;
}

//检测订购表单
function CheckOrder(theForm){
   var ProductNumber = theForm.ProductNumber.value;
   var OrderNumber = theForm.number.value;
   if (OrderNumber == "" || OrderNumber <= 0 ){
      alert("请输入订购数量!");
      theForm.number.focus();
      return (false);
   }
   else{
      if (parseInt(ProductNumber) >= 0){
	     if(parseInt(OrderNumber) > parseInt(ProductNumber)){
            alert("您输入的订购数量不能大于库存量!");
		    theForm.number.value = ProductNumber;
            theForm.number.focus();
            return (false);
         }
   	  }
   }
}

//删除临时订单
function delorder(ID){
   if (confirm("确定要删除吗?")) {
      window.location=("deltmporder.aspx?ID=" + ID );
   }
   else{
     // return (false);
   }
}

//提交订单
function SettleAccounts(){
		
		if (Math.round(parseFloat(sumnumber.innerText))== 0 )
			{
				alert("您还没有购买商品!");
		  	return ; 
			}
		else	
				if ( confirm("您确定要提交订单吗?")) {
				   window.shoppingcart.action = "settleacount.aspx";
				   window.shoppingcart.submit();
				   return true;
				}
}

//继续订购
function ContinueBuy(){
   window.shoppingcart.action = "continuebuy.aspx"
   window.shoppingcart.submit();
}

function UpdateOrder(){
   window.shoppingcart.action = "updateorder.aspx"
   window.shoppingcart.submit();
}

//自动更新核算订单
function keyupeventcount(ProductNumber){
	var sumnumbers = 0;
	var sumconsultmoneys = 0;
	var summembermoneys = 0;
	if(shoppingcart.number[0] != null) {
		for(i=0;i<shoppingcart.number.length;i++) {
			if(shoppingcart.number[i].value == "" || parseFloat(shoppingcart.number[i].value) <= 0){
			   shoppingcart.number[i].value = 1;
			}
			else{
			   if (ProductNumber >= 0){
                  if(shoppingcart.number[i].value > ProductNumber){
				     shoppingcart.number[i].value = ProductNumber;
			      }
			   }
			}
			if(parseFloat(shoppingcart.number[i].value) < 10)
			   shoppingcart.number[i].value = Math.round(parseFloat(shoppingcart.number[i].value));
			   allconsultmoney[i].innerHTML = "&nbsp;" + Math.round(parseFloat(consultprice[i].innerText) * parseFloat(shoppingcart.number[i].value)*100)/100;
			   allmembermoney[i].innerHTML = "&nbsp;" + Math.round(parseFloat(memberprice[i].innerText) * parseFloat(shoppingcart.number[i].value)*100)/100;
			   savemoney[i].innerHTML= "&nbsp;" + Math.round((parseFloat(consultprice[i].innerText) * parseFloat(shoppingcart.number[i].value) - parseFloat(memberprice[i].innerText) * parseFloat(shoppingcart.number[i].value))*100)/100;
			   sumconsultmoneys += Math.round(parseFloat(consultprice[i].innerText) * parseFloat(shoppingcart.number[i].value)*100)/100;
			   summembermoneys += Math.round(parseFloat(memberprice[i].innerText) * parseFloat(shoppingcart.number[i].value)*100)/100;
			   sumnumbers += Math.floor(shoppingcart.number[i].value);

		}
		sumconsultmoney.innerHTML =  Math.round(sumconsultmoneys*100)/100;
		summembermoney.innerHTML =  Math.round(summembermoneys*100)/100;
		sumsavemoney.innerHTML = sumconsultmoneys - summembermoneys;
        sumnumber.innerHTML = sumnumbers;
        shoppingcart.summoney.value = Math.round(sumconsultmoneys*100)/100;
		shoppingcart.factmoney.value =  Math.round(summembermoneys*100)/100;   
	}
	else {
		if(shoppingcart.number.value == "" || parseFloat(shoppingcart.number.value) <= 0) {
			shoppingcart.number.value = 1;
	    }
		else{
           if (ProductNumber >= 0){
              if(shoppingcart.number.value > ProductNumber){
			     shoppingcart.number.value = ProductNumber;
		      }
		   }
		}
	   allconsultmoney.innerHTML = "&nbsp;" + Math.round(parseFloat(consultprice.innerText) * parseFloat(shoppingcart.number.value)*100)/100;
	   allmembermoney.innerHTML = "&nbsp;" + Math.round(parseFloat(memberprice.innerText) * parseFloat(shoppingcart.number.value)*100)/100;
       savemoney.innerHTML = "&nbsp;" + Math.round((parseFloat(consultprice.innerText) * parseFloat(shoppingcart.number.value) - parseFloat(memberprice.innerText) * parseFloat(shoppingcart.number.value))*100)/100;
	   sumconsultmoney.innerHTML = Math.round(parseFloat(consultprice.innerText) * parseFloat(shoppingcart.number.value)*100)/100;
       summembermoney.innerHTML = Math.round(parseFloat(memberprice.innerText) * parseFloat(shoppingcart.number.value)*100)/100;
       sumsavemoney.innerHTML = Math.round((parseFloat(consultprice.innerText) * parseFloat(shoppingcart.number.value) - parseFloat(memberprice.innerText) * parseFloat(shoppingcart.number.value))*100)/100;
       sumnumber.innerHTML = Math.floor(shoppingcart.number.value); 
	   shoppingcart.summoney.value = Math.round(parseFloat(consultprice.innerText) * parseFloat(shoppingcart.number.value)*100)/100;
	   shoppingcart.factmoney.value =  Math.round(parseFloat(memberprice.innerText) * parseFloat(shoppingcart.number.value)*100)/100;
	}
}

//确认保存订单
function OrderConfirm(theForm)
{
   if ( confirm("您确定要提交订单吗？"))
   {
      return (true);
   }
   else
   {
      return (false);
   }
}

//删除帐单
function delbill(id,page){
   if ( confirm("您确定要删除订单吗?")) {
      window.location=("deletebill.aspx?id=" + id + "&page=" + page);
   }
   else
   {
      //return (false);
   }
}


function CheckOrderLogon(theForm){
   var Email = theForm.Email.value;
   var len = Email.length;
   if (theForm.Email.value == ""){
      alert("请输入您的Email!");
      theForm.Email.focus();
      return (false);
   }
   else{
      var Email_rule = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
      if (!accord(Email_rule,Email) || Email.length < 7 ){
         alert("您输入的E-Mail有误!");
	     theForm.Email.focus();
	     return (false);
      }
      else{
         if (Email.indexOf("@",1) == -1 || Email.indexOf(".",1) == -1){
            alert("您输入的E-Mail有误!");
            theForm.Email.focus();
			return false;
         }
         if (Email.charAt(1) == "." || Email.charAt(1) == "@"){
            alert("您输入的E-Mail有误!");
            theForm.Email.focus();
			return false;
         }
         if (Email.charAt(len-1) == "." || Email.charAt(len-1) == "@"){
            alert("您输入的E-Mail有误!");
            theForm.Email.focus();
			return false;
         }
      }
   }
}

function accord(rule,datas)
{
   var checkOKpass = rule;
   var checkStrpass = datas;
   var allValidpass = true;
   for (i = 0;  i < checkStrpass.length;  i++)
   {
      ch = checkStrpass.charAt(i);
      for (j = 0;  j < checkOKpass.length;  j++)
         if (ch == checkOKpass.charAt(j))
         break;
         if (j == checkOKpass.length)
         {
            allValidpass = false;
            break;
         }
   }
   return allValidpass;
}

function debar(rule,datas) 
{
   var checkOKpass = rule;
   var checkStrpass = datas;
   for (i = 0; i < checkStrpass.length; i++)
   {
      ch = checkStrpass.charAt(i);
      for (j = 0; j < checkOKpass.length; j++)
	  {
         if (ch == checkOKpass.charAt(j)) 
			return true;
         if (j == checkOKpass.length)
            break; 
      }
   }
   return false;
}
//检测会员注册订单
function CheckOrderReg(theForm){
   var Email = theForm.Email.value;
   var len = Email.length;
   if (theForm.Email.value == ""){
      alert("请输入您的Email!");
      theForm.Email.focus();
      return (false);
   }
   else{
      var Email_rule = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
      if (!accord(Email_rule,Email) || Email.length < 7 ){
         alert("您输入的E-Mail有误!");
	     theForm.Email.focus();
	     return (false);
      }
      else{
         if (Email.indexOf("@",1) == -1 || Email.indexOf(".",1) == -1){
            alert("您输入的E-Mail有误!");
            theForm.Email.focus();
			return false;
         }
         if (Email.charAt(1) == "." || Email.charAt(1) == "@"){
            alert("您输入的E-Mail有误!");
            theForm.Email.focus();
			return false;
         }
         if (Email.charAt(len-1) == "." || Email.charAt(len-1) == "@"){
            alert("您输入的E-Mail有误!");
            theForm.Email.focus();
			return false;
         }
      }
   }

   var Pwd = theForm.Pwd.value;
   var Pwd1 = theForm.Pwd1.value;
   if (Pwd == "" ){
      alert("请输入您的密码!");
      theForm.Pwd.focus();
      return (false);
   }
   else{
	  if (Pwd.length < 6){
         alert("您输入的密码长度不够6位!");
         theForm.Pwd.focus();
         return (false);
	  }
   }	  
   if (Pwd1 == "" ){
      alert("请输入您的确认密码!");
      theForm.Pwd1.focus();
      return (false);
   }
   if (Pwd != Pwd1){
		 alert("您输入的密码和确认密码不一样!");
         theForm.Pwd1.focus();
         return (false);
   }
}

function CheckPwd(theForm){
   var Pwd = theForm.Pwd.value;
   var Pwd1 = theForm.Pwd1.value;
   var Pwd2 = theForm.Pwd2.value;
   if (Pwd == "" ){
      alert("请输入您的密码!");
      theForm.Pwd.focus();
      return (false);
   }
   if (Pwd1 == "" ){
      alert("请输入您的新密码!");
      theForm.Pwd1.focus();
      return (false);
   }
   else{
      if (Pwd1.length < 6){
         alert("您输入的密码长度不够6位!");
         theForm.Pwd1.focus();
         return (false);
	  }
   }	  
   if (Pwd1 != Pwd2){
		 alert("您输入的密码和确认密码不一样!");
         theForm.Pwd1.focus();
         return (false);
   }
}
