
// ”Žšƒ`ƒFƒbƒNFTEL,FAX,ZIPA   ”¼Šp{‘SŠp
// ‚O ‚P ‚Q ‚R ‚S ‚T ‚U ‚V ‚W ‚X, ‚O=65296  ‚X=65305
// 0 1 2 3 4 5 6 7 8 9,  0=48   9=57
function isNumber(o,warning){
  for (i=0; i<o.value.length; i++){
       if ( ! ((65296 <= o.value.charCodeAt(i) && o.value.charCodeAt(i) <=65305)
               || (48 <= o.value.charCodeAt(i) && o.value.charCodeAt(i) <=57))) {
           if ( warning != null ) alert(warning);
           o.focus();
           o.select();
           return false;
       }
   }
   return true;
}
function isKanji(o,warning){
  scope = new String("<>&\"'");
  for (i=0;i<o.value.length;i++){
    if(scope.indexOf(o.value.charAt(i))!=-1){
      if ( warning != null ) alert(warning);
      o.focus();
      o.select();
      return false;
    }
  }
  return true;
}
function fullNumberToHalf(o){
    var ret = "";
    for (i=0; i<o.value.length; i++){
        if (65296 <= o.value.charCodeAt(i) && o.value.charCodeAt(i) <=65305) {
            ret = ret + String.fromCharCode(o.value.charCodeAt(i) - 65296 + 48);
        } else ret = ret + o.value.charAt(i);
    }
    return ret;
}



// ‚Ÿ‚ ‚¡‚¢‚£‚¤‚¥‚¦‚§‚¨‚©‚ª‚«‚¬‚­‚®‚¯‚°‚±‚²‚³‚´‚µ‚¶‚·‚¸‚¹‚º‚»‚¼‚½‚¾‚¿‚À‚Á‚Â‚Ã‚Ä‚Å‚Æ‚Ç‚È‚É‚Ê‚Ë‚Ì‚Í‚Î‚Ï‚Ð‚Ñ‚Ò‚Ó‚Ô‚Õ‚Ö‚×‚Ø‚Ù‚Ú‚Û‚Ü‚Ý‚Þ‚ß‚à‚á‚â‚ã‚ä‚å‚æ‚ç‚è‚é‚ê‚ë‚ì‚í‚î‚ï‚ð‚ñ  - [
// ‚Ÿ = 12353  ‚ñ = 12435@- = 45 [@= 12540
function isHiragana(o,warning){
   for (i=0; i<o.value.length; i++){
       if (  (o.value.charCodeAt(i) != 45)
          && (o.value.charCodeAt(i) != 12540)
          && (o.value.charCodeAt(i) < 12353 || o.value.charCodeAt(i) > 12435)) {
           if ( warning != null ) alert(warning);
           o.focus();
           o.select();
           return false;
       }
   }
   return true;
}


function isValidEmail(o,warning) {
    var locAt;
    var locPeriod;
    var okEmail;
    if (o.value.length==0) {return false;}
    locAt = o.value.indexOf("@");
    okEmail = ((locAt != -1) && (locAt != 0)
              && (locAt != (o.value.length - 1))
              && (o.value.indexOf("@", locAt + 1) == -1));
    if (okEmail) {
        // so far, so good
        locPeriod = o.value.indexOf(".");
        okEmail = ((locPeriod != -1) && (locPeriod != (o.value.length - 1)));
    }
    if ( okEmail == false ) {
        if ( warning != null ) alert(warning);
        o.focus();
        o.select();
        return false;
    }
    return okEmail;
}


/**
 *  function:   trim the string
 *  return  not null: the trim string(not space)
 *          null:     the string is null or length is 0
 */
function trim(string){
  var del = 0;
  if(string==null || string.length==0){
    return null;
  }
  for(var i = 0; i < string.length; i++){
    var strTemp = string.charAt(i);
    if(strTemp != ' ' && strTemp != '@'){
      break;
    }else{
      del = i;
    }
  }
  if((del == string.length-1) && (string.charAt(string.length-1) == ' ' || string.charAt(string.length-1) == '@')){
    return null;
  }else{
    if(del != 0){
      string = string.substring(del + 1);
    }
  }
  del = string.length - 1;
  for(var i = string.length-1; i >= 0; i--){
    var strTemp = string.charAt(i);
    if(strTemp != ' ' && strTemp != '@'){
      del = i;
      break;
    }else{
      del = i;
    }
  }
  if(del == string.length - 1){
    return string;
  }else{
    return (string.substring( 0, del + 1));
  }
}


function isInputEmpty(o,warning){
   if (trim(o.value)==null){
       if ( warning != null ) alert(warning);
       o.focus();
       o.select();
       return true;
   }
   return false;
}

function lessLength(o,len,warning){
   if (o.value.length < len){
       if ( warning != null ) alert(warning);
       o.focus();
       o.select();
       return true;
   }
   return false;
}

/******************************************************************
   validate_date()

   Validates date output from convert_date().  Checks
   day is valid for month, leap years, month !> 12,.


   Notes: Please feel free to use/edit this script.
   If you do please keep my comments and details
   intact and notify me via a quick Email to the address above.  Enjoy!
*******************************************************************/
function validate_date(day2, month2, year2)
{
var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
var inpDate = day2 + month2 + year2;
var filter=/^[0-9]{2}[0-9]{2}[0-9]{4}$/;

//Check ddmmyyyy date supplied
if (! filter.test(inpDate))
  {
  return false;
  }
/* Check Valid Month */
filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;
if (! filter.test(month2))
  {
  return false;
  }
/* Check For Leap Year */
var N = Number(year2);
if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )
  	{
   DayArray[1]=29;
  	}
/* Check for valid days for month */
for(var ctr=0; ctr<=11; ctr++)
  	{
   if (MonthArray[ctr]==month2)
   	{
      if (day2<= DayArray[ctr] && day2 >0 )
        {
        inpDate = day2 + '/' + month2 + '/' + year2;
        return inpDate;
        }
      else
        {
        return false;
        }
   	}
   }
}


function isPassWord(o,warning){

    cnst="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    cnst +="!\"#$%&'()=`|~{+*}<>?_-^\\@[;:],./";

    for (i=0;i<o.value.length;i++){
        if (cnst.indexOf(o.value.charAt(i),0)==-1){
            alert(warning);
            o.focus();
            o.select();
            return false;
            break;
        }
    }
    return true;
}

function isRadioChecked(o,wanning){
  sw="na";
  if(o.length == null){
    if(o.checked == false){
      sw = "na";
    }else{
      sw = "ok";
    }
  }else{
    for(i=0; i<o.length; i++){
      if(o[i].checked){
        sw="ok";
      }
    }
  }
  if(sw!="ok"){
    alert(wanning);
    o[0].focus();
    return false;
  }
  return true;
}

function isCheckBoxChecked(o,leastnum,lessnum,wanning){
  count=0;
  if( o == null){
    alert(wanning);
    return false;
  }
  if(o.length == null){
    if(o.checked == false){
    }else{
      count++;
    }
  }else{
    for(i=0;i<o.length;i++){
      if(o[i].checked){
        count++;
      }
    }
  }
  if(o.length == null) {
    if(count < leastnum){
      alert(wanning);
      return false;
    }else{
      return true;
    }
  }else{
    if(count<leastnum || count>lessnum){
      alert(wanning);
      o[0].focus();
      return false;
    }else{
      return true;
    }
  }
}
//COME FROM COMMON.JS

/**
 *  function:   check the string is half number or not.
 *  return  true:   is half number
 *          false:  is not half number
 */
function isHalfNum(o,warning){
    if (o.value.length > 0){
        if (isNaN(o.value)){
            alert(warning);
            o.focus();
            o.select();
            return false;
        }
    }
    return true;
}

function isCheckBoxCheckedNull(o,wanning){

  sw="na";
  if(o.length == null){
    if(o.checked == false){
      sw = "na";
      alert(wanning);
      o.focus();
      return false;
    }else{
      sw = "ok";
    }
  }else{
    for(i=0; i<o.length; i++){
      if(o[i].checked){
        sw="ok";
      }
    }
  }
  if(sw!="ok"){
    alert(wanning);
    if(o.length!=1){
      o[0].focus();
    }else{
      o.focus();
    }
    return false;
  }
  return true;
}

function isCheckBoxCheckedLess(o,leastnum,wanning){
  count=0;
  if(o.length == null){
    if(o.checked == false){
    }else{
      count++;
    }
  }else{
    for(i=0;i<o.length;i++){
      if(o[i].checked){
        count++;
      }
    }
  }
  if(o.length != null) {
    if(count<leastnum){
      alert(wanning);
      o[0].focus();
      return false;
    }else{
      return true;
    }
  }
}

function isCheckBoxCheckedMore(o,lessnum,wanning){
  count=0;
  if(o.length == null){
    if(o.checked == false){
    }else{
      count++;
    }
  }else{
    for(i=0;i<o.length;i++){
      if(o[i].checked){
        count++;
      }
    }
  }
  if(o.length != null) {
    if(count>lessnum){
      alert(wanning);
      o[0].focus();
      return false;
    }else{
      return true;
    }
  }
}

//COME FROM Project.js

/*
fuction:judge if the japanese is composed of half number or half english.
*/
function isHalfEnglishAndNumber(o,warning) {
 scope = new String("1234567890abcdefghijkmlnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
 for (i=0;i<o.value.length;i++) {
   if(scope.indexOf(o.value.charAt(i))==-1){
     o.focus();
     o.select();
     alert(warning);
     return false;
   }
 }
 return true;
}

/*
fuction:judge if the japanese is composed of  half english.

*/
function isHalfEnglish(o,warning){
 scope = new String("abcdefghijkmlnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
 for (i=0;i<o.value.length;i++) {
   if(scope.indexOf(o.value.charAt(i))==-1){
     o.focus();
     o.select();
     alert(warning);
     return false;
   }
 }
 return true;
}
/*
fuction:judge if the japanese is composed of  Big English.

*/
function isBigEnglish(o,warning){
  scope = new String("ABCDEFGHIJKLMNOPQRSTUVWXYZ‚`‚a‚b‚c‚d‚e‚f‚g‚h‚i‚j‚k‚l‚m‚n‚o‚p‚q‚r‚s‚t‚u‚v‚w‚x‚y");
  for (i=0;i<o.value.length;i++) {
   if(scope.indexOf(o.value.charAt(i))==-1){
     o.focus();
     o.select();
     alert(warning);
     return false;
   }
 }
 return true;
}


/*
fuction:judge if the japanese is composed of  Small English.

*/
function isSmallEnglish(o,warning){
  scope = new String("abcdefghijkmlnopqrstuvwxyz‚‚‚‚ƒ‚„‚…‚†‚‡‚ˆ‚‰‚Š‚‹‚Œ‚‚Ž‚‚‚‘‚’‚“‚”‚•‚–‚—‚˜‚™‚š");
  for (i=0;i<o.value.length;i++) {
   if(scope.indexOf(o.value.charAt(i))==-1){
     o.focus();
     o.select();
     alert(warning);
     return false;
   }
 }
 return true;
}

/*
fuction:judge if the japanese is composed of Furi.

*/
function isFuri(o,warning){
  scope = new String("‚ ‚¢‚¤‚¦‚¨‚©‚«‚­‚¯‚±‚³‚µ‚·‚¹‚»‚½‚¿‚Â‚Ä‚Æ‚È‚É‚Ê‚Ë‚Ì‚Í‚Ð‚Ó‚Ö‚Ù‚Ü‚Ý‚Þ‚ß‚à‚â‚ä‚æ‚ç‚è‚é‚ê‚ë‚í‚ð‚ñ‚Ÿ‚¡‚£‚¥‚§‚Á‚á‚ã‚åABuv[‚ª‚¬‚®‚°‚²‚´‚¶‚¸‚º‚¼‚¾‚À‚Ã‚Å‚Ç‚Î‚Ñ‚Ô‚×‚Ú‚Ï‚Ò‚Õ‚Ø‚Û");
  for (i=0;i<o.value.length;i++) {
   if(scope.indexOf(o.value.charAt(i))==-1){
     o.focus();
     o.select();
     alert(warning);
     return false;
   }
 }
 return true;
}

/*
fuction:judge if the japanese is composed of FullKataKana.
*/
function isFullKataKana(o,warning){
  scope = new String("ƒAƒCƒEƒGƒIƒJƒLƒNƒPƒRƒTƒVƒXƒZƒ\ƒ^ƒ`ƒcƒeƒgƒiƒjƒkƒlƒmƒnƒqƒtƒwƒzƒ}ƒ~ƒ€ƒƒ‚ƒ„ƒ†ƒˆƒ‰ƒŠƒ‹ƒŒƒƒƒ’ƒ“ƒ@ƒBƒDƒFƒHƒbƒƒƒ…ƒ‡ABuv[ƒKƒMƒOƒQƒSƒUƒWƒYƒ[ƒ]ƒ_ƒaƒdƒfƒhƒoƒrƒuƒxƒ{ƒpƒsƒvƒyƒ|");
  for (i=0;i<o.value.length;i++) {
   if(scope.indexOf(o.value.charAt(i))==-1){
     o.focus();
     o.select();
     alert(warning);
     return false;
   }
 }
 return true;
}

/*
fuction:judge if the japanese is composed of FullKanji.

*/
function isFullKanji(o,warning){
  scope1 = new String("abcdefghijkmlnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  scope2 = new String("±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝ¤¡¢£°¶Þ·Þ¸Þ¹ÞºÞ»Þ¼Þ½Þ¾Þ¿ÞÀÞÁÞÂÞÃÞÄÞÊÞËÞÌÞÍÞÎÞÊßËßÌßÍßÎß");
  for (i=0;i<o.value.length;i++) {
   if((scope1.indexOf(o.value.charAt(i))!=-1)
      ||(scope2.indexOf(o.value.charAt(i))!=-1)){
     o.focus();
     o.select();
     alert(warning);
     return false;
   }
  }
  return true;
}
function hasChecked(form,param,warning){
  for(var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
    if((e.name==param)&&(e.checked==true)){
      return true;
    }
  }
  alert(warning);
  return false;
}

function selectFunction(num,o,warning){

  if(num==00) {

    return true;
  }
  if(num==01){
    if(isHalfEnglishAndNumber(o,warning)==true) return true;
    else return false;
  }
  if(num==02){
    if(isHalfEnglish(o,warning)==true) return true;
    else return false;
  }
  if(num==03){
    if(isNumber(o,warning)==true) return true;
    else return false;
  }
  if(num==04){
    if(isBigEnglish(o,warning)==true) return true;
    else return false;
  }
  if(num==05){
    if(isSmallEnglish(o,warning)==true) return true;
    else return false;
  }
  if(num==06){
    if(isFullKanji(o,warning)==true) return true;
    else return false;
  }
  if(num==07){
    if(isFuri(o,warning)==true) return true;
    else return false;
  }
  if(num==08){
    if(isFullKataKana(o,warning)==true) return true;
    else return false;
  }
  return true;
}


//mainly used in questionnaire project judge if all text has been filled value
//  or no text has been filled value
function isValidTel(o1,o2,o3){
  if(o1.value.length==0&&o2.value.length==0&&o3.value.length==0){
    return true;
  }
  else if(o1.value.length>0&&o2.value.length>0&&o3.value.length>0){
    return true;
  }
  else return false;
}
//mainly used in questionnaire project judge if all text has been filled value
//  or no text has been filled value
function isValidFAX(o1,o2,o3){
  if(o1.value.length==0&&o2.value.length==0&&o3.value.length==0){
    return true;
  }
  else if(o1.value.length>0&&o2.value.length>0&&o3.value.length>0){
    return true;
  }
  else return false;
}
//mainly used in questionnaire project judge if all text has been filled value
//  or no text has been filled value
function isValidZipcode(o1,o2){
  if(o1.value.length==0&&o2.value.length==0){
    return true;
  }
  else if(o1.value.length>0&&o2.value.length>0){
    return true;
  }
  else return false;
}