//===================================================================
// 【汎用関数】
//
function zeroPadding( number, width ){
	if( width > 10 ){
		alert( '10桁以上には対応しておりません' );
		return( 0 );
	}else{
		var tmpStr = "000000000"+number;
		tmpStr = tmpStr.substr( tmpStr.length - width );
		return( tmpStr );
	}
}

function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len) {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
}

function setCookie(key, val, tmp) {
    tmp = key + "=" + escape(val) + "; ";
    // tmp += "path=" + location.pathname + "; ";
    tmp += "expires=Fri, 31-Dec-2030 23:59:59; ";
    document.cookie = tmp;
}

function clearCookie(key) {
    document.cookie = key + "=" + "xx; expires=1-Jan-1997 00:00:00;";
}





// アプリケーション名取得
// appId:ブラウザ種別
//         0:IE
//         1:Netscape(Mozilla)
//         2:Opera
// return  0:'Microsoft Internet Explorer'
//         1:'Netscape'
//         2:'Opera'
function getAppName(appId) {
    var name;
    if(appId == 0) {
        return 'Microsoft Internet Explorer';
    } else if(appId == 1) {
        return 'Netscape';
    } else if(appId == 2) {
        return 'Opera';
    } else {
        return 'Microsoft Internet Explorer';
    }
}

function isMatch(appId, name) {
    if (appId == 2) {
        agent = navigator.userAgent;
        if (agent.indexOf(name, 0) != -1) {
            return 1;
        } else {
            return 0;
        }
    } else if (appId == 0 || appId == 1) {
        if (navigator.appName == name){
            if (navigator.userAgent.indexOf('Opera', 0) != -1) {
                return 0;
            }
            return 1;
        } else {
            return 0;
        }
    }
}

// タグ名+class属性名指定によるフォントサイズ変更
function changeFontSizeByTagNameAndClassName(appId, tagName, tagAttribute, fontSize) {
    var name = getAppName(appId);
    if (isMatch(appId, name)) {
        var elements = document.getElementsByTagName(tagName);
        for (i = 0; i < elements.length; i++) {
            if(elements[i].getAttribute('className') == tagAttribute ||
               elements[i].getAttribute('class') == tagAttribute) {
               elements[i].style.fontSize = fontSize;
            }
        }
    }
}

// id属性指定によるフォントサイズ変更
function changeFontSizeById(appId, id, fontSize) {
    var name = getAppName(appId);
    if (isMatch(appId, name)) {
        var element = document.getElementById(id);
        element.style.fontSize = fontSize;
    }
}

// id属性+タグ名指定によるフォントサイズ変更
function changeFontSizeByIdAndTagName(appId, id, tagName, fontSize) {
    var name = getAppName(appId);
    if (isMatch(appId, name)) {
        var element = document.getElementById(id);
        var elements = element.getElementsByTagName(tagName);
        for (i = 0; i < elements.length; i++) {
            elements[i].style.fontSize = fontSize;
        }
    }
}

// タグ名(番号指定)+属性名指定による属性値変更
function setAttributeByTagNameAndAttribute(appId, tagName, number, tagAttribute, value) {
    var name = getAppName(appId);
    if (isMatch(appId, name)) {
        var elements = document.getElementsByTagName(tagName);
        if(elements[number]){
            elements[number].setAttribute(tagAttribute, value);
        }
    }
}

// タグ名+属性名指定による属性値変更
function setAttributeAllByTagNameAndAttribute(appId, tagName, tagAttribute, value) {
    var name = getAppName(appId);
    if (isMatch(appId, name)) {
        var elements = document.getElementsByTagName(tagName);
        for (i = 0; i < elements.length; i++) {
            elements[i].setAttribute(tagAttribute, value);
        }
    }
}

// id属性指定によるスタイル変更
function setStyleById(appId, id, style, value) {
    var name = getAppName(appId);
    if (isMatch(appId, name)) {
        var element = document.getElementById(id);
        changeStyle(element, style, value);
     }
}

// タグ名+class属性名指定によるスタイル変更
function setStyleByTagNameAndClassName(appId, tagName, tagAttribute, style, value) {
    var name = getAppName(appId);
    if (isMatch(appId, name)) {
        var elements = document.getElementsByTagName(tagName);
        for (i = 0; i < elements.length; i++) {
            if(elements[i].getAttribute('className') == tagAttribute ||
               elements[i].getAttribute('class') == tagAttribute) {
                changeStyle(element[i], style, value);
            }
        }
    }
}

// スタイル変更
function changeStyle(element, style, value){
   switch(style) {
    case 'background':
        element.style.background = value;
        break;
    case 'backgroundAttachment':
        element.style.backgroundAttachment = value;
        break
    case 'backgroundColor':
        element.style.backgroundColor = value;
        break;
    case 'backgroundImage':
        element.style.backgroundImage = value;
        break;
    case 'backgroundPosition':
        element.style.backgroundPosition = value;
        break;
    case 'backgroundRepeat':
        element.style.backgroundRepeat = value;
        break;
    case 'border':
        element.style.border = value;
        break;
    case 'borderBottom':
        element.style.borderBottom = value;
        break;
    case 'borderBottomColor':
        element.style.borderBottomColor = value;
        break;
    case 'borderBottomStyle':
        element.style.borderBottomStyle = value;
        break;
    case 'borderBottomWidth':
        element.style.borderBottomWidth = value;
        break;
    case 'borderColor':
        element.style.borderColor = value;
        break;
    case 'borderLeft':
        element.style.borderLeft = value;
        break;
    case 'borderLeftColor':
        element.style.borderLeftColor = value;
        break;
    case 'borderLeftStyle':
        element.style.borderLeftStyle = value;
        break;
    case 'borderLeftWidth':
        element.style.borderLeftWidth = value;
        break;
    case 'borderRight':
        element.style.borderRight = value;
        break;
    case 'borderRightColor':
        element.style.borderRightColor = value;
        break;
    case 'borderRightStyle':
        element.style.borderRightStyle = value;
        break;
    case 'borderRightWidth':
        element.style.borderRightWidth = value;
        break;
    case 'borderStyle':
        element.style.borderStyle = value;
        break;
    case 'borderTop':
        element.style.borderTop = value;
        break;
    case 'borderTopColor':
        element.style.borderTopColor = value;
        break;
    case 'borderTopStyle':
        element.style.borderTopStyle = value;
        break;
    case 'borderTopWidth':
        element.style.borderTopWidth = value;
        break;
    case 'borderWidth':
        element.style.borderWidth = value;
        break;
    case 'bottom':
        element.style.bottom = value;
        break;
    case 'captionSide':
        element.style.captionSide = value;
        break;
    case 'clear':
        element.style.clear = value;
        break;
    case 'clip':
        element.style.clip = value;
        break;
    case 'color':
        element.style.color = value;
        break;
    case 'cursor':
        element.style.cursor = value;
        break;
    case 'direction':
        element.style.direction = value;
        break;
    case 'display':
        element.style.display = value;
        break;
    case 'emptyCells':
        element.style.emptyCells = value;
        break;
//        case 'float':
//            element.style.float = value;
//            break;
    case 'font':
        element.style.font = value;
        break;
    case 'fontFamily':
        element.style.fontFamily = value;
        break;
    case 'fontSize':
        element.style.fontSize = value;
        break;
    case 'fontStretch':
        element.style.fontStretch = value;
        break;
    case 'fontStyle':
        element.style.fontStyle = value;
        break;
    case 'fontVariant':
        element.style.fontVariant = value;
        break;
    case 'fontWeight':
        element.style.fontWeight = value;
        break;
    case 'height':
        element.style.height = value;
        break;
    case 'left':
        element.style.left = value;
        break;
    case 'letterSpacing':
        element.style.letterSpacing = value;
        break;
    case 'lineHeight':
        element.style.lineHeight = value;
        break;
    case 'listStyle':
        element.style.listStyle = value;
        break;
    case 'listStyleImage':
        element.style.listStyleImage = value;
        break;
    case 'listStylePosition':
        element.style.listStylePosition = value;
        break;
    case 'listStyleType':
        element.style.listStyleType = value;
        break;
    case 'margin':
        element.style.margin = value;
        break;
    case 'marginBottom':
        element.style.marginBottom = value;
        break;
    case 'marginLeft':
        element.style.marginLeft = value;
        break;
    case 'marginRight':
        element.style.marginRight = value;
        break;
    case 'marginTop':
        element.style.marginTop = value;
        break;
    case 'maxHeight':
        element.style.maxHeight = value;
        break;
    case 'maxWidth':
        element.style.maxWidth = value;
        break;
    case 'minHeight':
        element.style.minHeight = value;
        break;
    case 'minWidth':
        element.style.minWidth = value;
        break;
    case 'overflow':
        element.style.overflow = value;
        break;
    case 'padding':
        element.style.padding = value;
        break;
    case 'paddingBottom':
        element.style.paddingBottom = value;
        break;
    case 'paddingLeft':
        element.style.paddingLeft = value;
        break;
    case 'paddingRight':
        element.style.paddingRight = value;
        break;
    case 'paddingTop':
        element.style.paddingTop = value;
        break;
    case 'pageBreakAfter':
        element.style.pageBreakAfter = value;
        break;
    case 'pageBreakBefore':
        element.style.pageBreakBefore = value;
        break;
    case 'position':
        element.style.position = value;
        break;
    case 'right':
        element.style.right = value;
        break;
    case 'scrollbar3dLightColor':
        element.style.scrollbar3dLightColor = value;
        break;
    case 'scrollbarArrowColor':
        element.style.scrollbarArrowColor = value;
        break;
    case 'scrollbarBaseColor':
        element.style.scrollbarBaseColor = value;
        break;
    case 'scrollbarDarkshadowColor':
        element.style.scrollbarDarkshadowColor = value;
        break;
    case 'scrollbarFaceColor':
        element.style.scrollbarFaceColor = value;
        break;
    case 'scrollbarHighlightColor':
        element.style.scrollbarHighlightColor = value;
        break;
    case 'scrollbarShadowColor':
        element.style.scrollbarShadowColor = value;
        break;
    case 'scrollbarTrackColor':
        element.style.scrollbarTrackColor = value;
        break;
    case 'tableLayout':
        element.style.tableLayout = value;
        break;
    case 'textAlign':
        element.style.textAlign = value;
        break;
    case 'textDecoration':
        element.style.textDecoration = value;
        break;
    case 'textIndent':
        element.style.textIndent = value;
        break;
    case 'textTransform':
        element.style.textTransform = value;
        break;
    case 'top':
        element.style.top = value;
        break;
    case 'verticalAlign':
        element.style.verticalAlign = value;
        break;
    case 'visibility':
        element.style.visibility = value;
        break;
    case 'width':
        element.style.width = value;
        break;
    case 'wordSpacing':
        element.style.wordSpacing = value;
        break;
    case 'zIndex':
        element.style.zIndex = value;
        break;
    }
}

