﻿var colorDown='#8592B5';
var colorOver='#b5bdd6';

var bNext=true;

// Cell_SetColor
  function Cell_SetColor(cell, backgroundColor, borderColor){
    if(backgroundColor!=null){
      cell.bgColor=backgroundColor;
      cell.borderColor=backgroundColor;
    }
    if(borderColor!=null){
      cell.style.borderLeft=borderColor;
      cell.style.borderRight=borderColor;
      cell.style.borderTop=borderColor;
      cell.style.borderBottom=borderColor;
    }
  }

// Row_SetColor
  function Row_SetColor(row, backgroundColor, borderColor, start, len){
    var i=0;
    var ocell=null;
    for(i=start;i<len;i++){
      ocell=row.cells(i);
      if(backgroundColor!=null){
        ocell.bgColor=backgroundColor;
        ocell.borderColor=backgroundColor;
      }
      if(borderColor!=null){
        if(i==start) ocell.style.borderLeft=borderColor;
        if(i+1==len) ocell.style.borderRight=borderColor;
        ocell.style.borderTop=borderColor;
        ocell.style.borderBottom=borderColor;
      }
    }
  }
//

function doChangeOrder(){
  Form1.txtState.value='';
  var err=isNaN(Form1.txtQuantity.value);
  if(!err){
    err=parseInt(Form1.txtQuantity.value)<0||parseInt(Form1.txtQuantity.value)!=Form1.txtQuantity.value;
    Form1.txtQuantity.value=Math.abs(parseInt(Form1.txtQuantity.value));
  }else Form1.txtQuantity.value='0';
  if(err){
    alert('注文数エラー! 再度入力してください。');
    Form1.txtQuantity.focus();
    return false;
  }
  Form1.txtState.value='changed';
  return true;
}

function doBack(){
//  setFile(doucment, 'goodslist.aspx', '?GoodsKindID='+parent.Top.document.Form1.txtCurrentPageID.value+'&SearchKey='+parent.Top.document.Form1.txtSearch.value);
  document.location='GoodsList.aspx?kindID=1';
  return false;
}

function doGoodsOrder(goodsID){
  Form1.txtState.value="n"+goodsID;
  return true;
}

function doRefersh(){
  parent.Cart.document.location='cart.aspx';
}

function doInformation(){
  document.location="BuyerInformation.aspx";
  return false;
}

function doLogout(){
  Form1.txtState.value='logout';
  return true;
}

function doLogin(){
  var oObjects=new Array(2);
  var oLabels=new Array(2);
  
  oObjects[0]=document.all('txtUser');
  oObjects[1]=document.all('txtPassword');

  oLabels[0]="入力エラー! ユーザーを再度入力してください。";
  oLabels[1]="入力エラー! パスワードを再度入力してください。";

  if(!Chk_Value(oObjects, oLabels)) return false;

  document.all('txtState').value='login';
  //Form1.submit();
  return true;
}

function setFile(oFrame, file, para){
  if(!testASPX(oFrame, file)) oFrame.location=file+para;
/*
  var next=false;
  var n=0;
  while(!next&&n<100){
    try{
      oFrame.document.Form1.submit();
      next=true;
    }catch(e){
    }
    n++;
  }
*/
}

function doCartLoginCallRef(){
  if(Form1.txtRefresh.value==''){
    Form1.txtRefresh.value='false';
    setFile(parent.GoodsList.document, 'goodsrecommend.aspx', '');
  }
}

function doRef(){
  parent.GoodsList.document.Form1.submit();
}

function doRef2(){
  //parent.Cart.document.Form1.submit();
}

function testASPX(oFrame, ASPXName){
  return oFrame.location.toString().toLowerCase().lastIndexOf(ASPXName)>=0;
}

function doDelete(goodsID){
/*
  var bCart=document.location.toString().toLowerCase().lastIndexOf('cart.aspx')>=0;
  var bAccount=parent.GoodsList.document.location.toString().toLowerCase().lastIndexOf('account.aspx')>=0;
  bNext=false;
  if(confirm('削除，確認？')){
    Form1.txtState.value=goodsID;
    var oForm=null;
    if(bCart){
      if(bAccount) oForm=parent.GoodsList.document.Form1;
    }else oForm=parent.Cart.document.Form1;
    if(oForm!=null){
      oForm.txtState.value=goodsID;
      oForm.submit();
    }
    return true;
  }else return false;
*/

  if(confirm('削除，確認？')){
    Form1.txtState.value="d"+goodsID;
    return true;
  }else return false;
  
}


function doClear(){
  if(confirm('全商品クリア，確認？')){
    Form1.txtState.value='clear';
    return true;
  }else return false;
}

function doDetail(url){
  if(bNext) document.location=url;
  else bNext=true;
  return false;
}

function doAccount(){
  document.location='account.aspx';
  return false;
}

  function LTrim(str){
    if(str=="") return "";
    var left=0;
    for(; left<str.length; left++) if(str.charAt(left)!=" ") break;
    return str.substring(left);
  }
  
  function RTrim(str){
    if(str=="") return "";
    var right=str.length-1;
    for(; right>=0; right--) if(str.charAt(right)!=" ") break;
    return str.substring(0, right+1);
  }

  function Trim(str){
    return RTrim(LTrim(str));
  }

  function Chk_Value(oObjects, oLabels){
    for(var i=0; i<oObjects.length; i++){
      if(Trim(oObjects[i].value)==""){
        alert(oLabels[i]);
        oObjects[i].focus();
        return false;
      }
    }
    return true;
  }

function doSend(logon){
  Form1.txtState.value='';

  if(logon!=1){
    var oObjects=new Array(4);
    var oLabels=new Array(4);
  
    oObjects[0]=Form1.txtUser_N;
    oObjects[1]=Form1.txtPinYin_N;
    oObjects[2]=Form1.txtAddress_N;
    oObjects[3]=Form1.txtEMail_N;

    oLabels[0]="入力エラー! ";
    oLabels[1]="入力エラー! ";
    oLabels[2]="入力エラー! ";
    oLabels[3]="入力エラー! ";

    if(oObjects[0]!=null){
      if(!Chk_Value(oObjects, oLabels)) return false;
    }

    if(Trim(Form1.txtTelephone_N.value)==""&&Trim(Form1.txtMobile_N.value)==""){
      alert("入力エラー! 電話番号\携帯を再度入力してください。");
      Form1.txtTelephone_N.focus();
      return false;
    }
  }

  Form1.txtState.value='send';
  return true;
}


function doSaveInfo(){

  Form1.txtState.value='';

  var oObjects=new Array(4);
  var oLabels=new Array(4);
  
  oObjects[0]=Form1.txtUser_N;
  oObjects[1]=Form1.txtPinYin;
  oObjects[2]=Form1.txtAddress;
  oObjects[3]=Form1.txtEMail;

  oLabels[0]="入力エラー!";
  oLabels[1]="入力エラー!";
  oLabels[2]="入力エラー!";
  oLabels[3]="入力エラー!";

  if(oObjects[0]!=null){
    if(!Chk_Value(oObjects, oLabels)) return false;
  }

  if(Trim(Form1.txtTelephone.value)==""&&Trim(Form1.txtMobile.value)==""){
    alert("入力エラー! 電話番号\携帯を再度入力してください。");
    Form1.txtTelephone.focus();
    return false;
  }

  if(Form1.txtOldPassword.value!=''){
    Form1.txtPassword_N.value=Trim(Form1.txtPassword_N.value);
    Form1.txtConfirmPassword.value=Trim(Form1.txtConfirmPassword.value);
    var oObjects2=new Array(1);
    var oLabels2=new Array(1);
    oObjects2[0]=Form1.txtPassword_N;
    oLabels2[0]="入力エラー! 新パスワードを再度入力してください。";
    if(!Chk_Value(oObjects2, oLabels2)) return false;
    if(Form1.txtPassword_N.value!=Form1.txtConfirmPassword.value){
      alert("入力エラー! 確認パスワードを再度入力してください。");
      Form1.txtConfirmPassword.focus();
      return false;
    }
    if(Form1.txtPassword_N.value.length<1){
      alert("入力エラー! 新パスワード入力必要。");
      Form1.txtPassword.focus();
      return false;
    }
  }

  Form1.txtState.value='saveinfo';
  return true;
}

function doSetPage(o){
  Form1.txtCurrentPage.value=o;
  Form1.submit();
}

function doCmdSetPage(){
  var err=isNaN(Form1.txtSetPage.value);
  if(err){
    alert('正しいページ数を入力してください!');
    Form1.txtSetPage.focus();
    return false;
  }else{
    Form1.txtCurrentPage.value=Form1.txtSetPage.value;
    Form1.txtSetPage.value='';
    Form1.submit();
  }
}


  var _currentPage=null;
  var _currentPageID="";

  var _firstES=true;
  
  
  function ChoiceShowType(o){
    Form1.ShowType.value=o;
    Form1.submit();
  }
  
  function PageGoodsKind(oPage, id){
    try{
      try{
        var test=parent.GoodsList.document.Form1.txtGoodsKindID.value;
        if(_currentPage==oPage) return;
      }catch(e1){
      }
      var smt=true;
      if(_currentPage!=null){
        _currentPage.className="PageNormal";
      }else smt=false;
      _currentPage=oPage;
      _currentPage.className="PageChoiced";
      _currentPageID=id;

      parent.Top.document.Form1.txtCurrentPageID.value=id;
      var test=parent.GoodsList.document.Form1.txtGoodsKindID.value;
      if(smt){
          parent.GoodsList.document.Form1.txtGoodsKindID.value=id;
          parent.GoodsList.document.Form1.submit();
      }
    }catch(e){
      parent.GoodsList.document.location='GoodsList.aspx?kindID='+id+'&SearchKey='+parent.Top.document.Form1.txtSearch.value;
    }
  }

  function PageOver(oPage){
    if(_currentPage==oPage) return;
    oPage.className="PageWant";
  }

  function PageOut(oPage){
    if(_currentPage==oPage) return;
    oPage.className="PageNormal";
  }

  function DoSearchKey(){
      try{
        parent.GoodsList.document.Form1.txtSearchKey.value=Form1.txtSearch.value;
        parent.GoodsList.document.Form1.submit();
      }catch(e){
        parent.GoodsList.document.location='GoodsList.aspx?GoodsKindID='+Form1.txtCurrentPageID.value+'&SearchKey='+Form1.txtSearch.value;
      }
      return false;
  }