/**
 * Validate Check
 *
 *  @param   Form Object 
 *  @return  boolean
 *
 */
function Validate_ErrorCheck(theObj)
{
    for(i=0;i < theObj.elements.length;i++){
        if (theObj.elements[i].lang == 'undefined' || theObj.elements[i].lang == '') {
            continue;
        }
        lang_type = theObj.elements[i].lang.split(":");
        if(theObj.elements[i].maxLength != 'undefined' || theObj.elements[i].maxLength != ''){
            if( !Maxlength_Check(theObj.elements[i], lang_type[0]) ){
                theObj.elements[i].style.backgroundColor = 'pink';
                return false;
            }
        }
        if( lang_type[2] == 1 ){
            if( !Input_Check(theObj.elements[i], lang_type[0]) ){
                theObj.elements[i].style.backgroundColor = 'pink';
                return false;
            }
        }
        if( lang_type[1] == 'em_size' ){
            if( !Only_Zenkaku(theObj.elements[i], lang_type[0]) ){
                theObj.elements[i].style.backgroundColor = 'pink';
                return false;
            }
        }
        if( lang_type[1] == 'integer' ){
            if( !Only_Integer(theObj.elements[i], lang_type[0]) ){
                theObj.elements[i].style.backgroundColor = 'pink';
                return false;
            }
        }
        theObj.elements[i].style.backgroundColor = 'white';
    }
    return true;
}

/**
 *  Length Over Check
 *
 *  @param   this Element 
 *  @param   this Element Name
 *  @return  boolean
 *
 */
function Maxlength_Check(theEle, theName){
    var length      = theEle.value.length; /* Input Value Length */
    var maxlength   = theEle.maxLength; /* Accept Value Length */
    if( length > maxlength ){
        alert('「' + theName + '」は、' + maxlength + '文字以内で入力してください');
        theEle.focus();
        return false;
    }
    return true;
}

/**
 *  Input Check
 *
 *  @param   this Element 
 *  @return  boolean
 *
 */
function Input_Check(theEle, theName){
    var str=theEle.value; /* Input Value */
    if(!str){
        alert('「' + theName + '」は入力必須項目です');
        theEle.focus();
        return false;
    }
    return true;
}

/**
 *  Zenkaku Check
 *
 *  @param   this Element 
 *  @param   this Element Name
 *  @return  boolean
 *
 */
function Only_Zenkaku(theEle, theName){
    var str=theEle.value; /* Input Value */
    var txt = 'ｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜｦﾝｧｨｩｪｫｬｭｮｯｰ､｡｢｣ﾞﾟ';
    for(var i=0; i<str.length; i++){
    /* It escapes in the character-code by one character, and if the length is four characters or more, em-sizes */
        var len=escape(str.charAt(i)).length;
        if(len<4 && !str.charAt(i).match(/[0-9a-zA-Z\n\r]+/g) && str.charAt(i).indexOf(' ') == -1){
//      if(len<4){
            alert('「' + theName + '」に半角記号・半角カナが含まれています');
            theEle.focus();
            return false;
        }
    	if (txt.indexOf(str.charAt(i),0) >= 0) { 
            alert('「' + theName + '」に半角記号・半角カナが含まれています'); 
            theEle.focus();
            return false; 
        }
        
    }
    return true;
}

/**
 * Integer Check
 *  @param   this Element 
 *  @param   this Element Name
 *  @return  boolean *
 */
function Only_Integer(theEle, theName){
    var str = theEle.value;
    if( str.match( /[^0-9]+/ ) ) {
        alert('「' + theName + '」は半角数字のみで入力して下さい');
        return false;
    }
    return true;
}
