function Sleep( T ){ 
   var d1 = new Date().getTime(); 
   var d2 = new Date().getTime(); 
   while( d2 < d1+1000*T ){    //wait T sec. 
       d2=new Date().getTime(); 
   } 
   return; 
} 

function ReloadPage(){
  Sleep(0.3);
  location.reload(true);
}

function submitLangForm(str)
{
  document.langform.lang.value = str;
  document.langform.submit();
  ReloadPage();
}

function submitPictFrameForm()
{
  document.pictframeform.submit();
}

function submitReiautoFrameForm()
{
  document.reiautoform.submit();
}

function submitTangoFrameForm()
{
  document.tangoform.submit();
}

function submitIrasutoFrameForm()
{
  document.irasutoform.submit();
}

function submitAisatuFrameForm()
{
  for (var i = 0; i < document.aisatuform.aisatu.length; i++) {
    if (document.aisatuform.aisatu[i].checked) {
	  document.aisatuform.id.value = i;
      break;
    }
  }
  document.aisatuform.submit();
}

function submitOiwaiFrameForm()
{
  for (var i = 0; i < document.oiwaiform.oiwai.length; i++) {
    if (document.oiwaiform.oiwai[i].checked) {
	  document.oiwaiform.id.value = i;
      break;
    }
  }
  document.oiwaiform.submit();
}

function submitOwabioreiFrameForm()
{
  for (var i = 0; i < document.owabioreiform.owabiorei.length; i++) {
    if (document.owabioreiform.owabiorei[i].checked) {
	  document.owabioreiform.id.value = i;
      break;
    }
  }
  document.owabioreiform.submit();
}

function submitOshiraseFrameForm()
{
  for (var i = 0; i < document.oshiraseform.oshirase.length; i++) {
    if (document.oshiraseform.oshirase[i].checked) {
	  document.oshiraseform.id.value = i;
      break;
    }
  }
  document.oshiraseform.submit();
}

function submitKoibitoFrameForm()
{
  for (var i = 0; i < document.koibitoform.koibito.length; i++) {
    if (document.koibitoform.koibito[i].checked) {
	  document.koibitoform.id.value = i;
      break;
    }
  }
  document.koibitoform.submit();
}

function submitKantanbunFrameForm()
{
  for (var i = 0; i < document.kantanbunform.kantanbun.length; i++) {
    if (document.kantanbunform.kantanbun[i].checked) {
	  document.kantanbunform.id.value = i;
      break;
    }
  }
  document.kantanbunform.submit();
}

function CheckMailAddress(val) {
  return val.match(/[\w\.\-]+@([\w\-]+\.)+[\w\-]+/i);
}

function CheckAscii(val) {
  // except control letter
  return val.match(/^[\x20-\x7e]+$/i);
}

function CheckStr(val) {
  return val.match(/^[a-z\d\w]+$/i);
}

function submitAtesakiForm()
{
  if (!CheckMailAddress(document.atesakiform.send_mail.value)) {
    document.atesakiform.send_mail.value = "";
    return;
  }
  if (!CheckMailAddress(document.atesakiform.my_mail.value)) {
    document.atesakiform.my_mail.value = "";
    return;
  }
  if (!CheckAscii(document.atesakiform.my_name.value)){
    document.atesakiform.my_name.value = "";
    return;
  }
  document.atesakiform.my_name_tmp.value = escape(document.atesakiform.my_name.value);
  document.atesakiform.submit();
}

function submitOtoiawaseForm()
{
  if (document.otoiawaseform.radiobutton[0].checked) {
      if (!CheckMailAddress(document.otoiawaseform.my_email.value)) {
        document.otoiawaseform.my_email.value = "";
        return;
      }
    document.otoiawaseform.my_name_hid.value = base64encode(utf16to8(document.otoiawaseform.my_name.value));
    document.otoiawaseform.my_inquiry_hid.value = base64encode(utf16to8(document.otoiawaseform.my_inquiry.value));
    document.otoiawaseform.submit();
  }
}

function downloadItem(strurl)
{
  if (document.douiform.radiobutton[0].checked) {
    location.href = strurl;
  }
}
