﻿function removejscssfile(filename, filetype){
    var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
    var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
    var allsuspects=document.getElementsByTagName(targetelement)
    for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
        if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
            allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
    }
}

function loadjscssfile(filename, filetype){
    if (filetype=="js"){ //if filename is a external JavaScript file
    var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype=="css"){ //if filename is an external CSS file
        var fileref=document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

function writeloginid(indentifyid){
    setCookie("loginid",indentifyid);
}

/*
function getclientid(){
    var clientid=getCookie("clientid");
    if (clientid==null || clientid==""){
        clientid = new UUID();
        setCookie("clientid",clientid);
    };
    return clientid;
}
*/

function htmlentities(s){
//「& → &amp;」「< → &lt;」「> → &gt;」「" → &quot;」「 ' → &#39;」
    var r=s.replace("<","＜");
    r=r.replace(">","＞");
    r=r.replace(";","");
    r=r.replace(",","，");
    return r;
}


//cookie 関連
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) {
    var tmp = key + "=" + escape(val) + "; ";
    //tmp += "path=/; ";
    tmp += "expires=Tue, 31-Dec-2030 23:59:59;; ";
    document.cookie = tmp;
}
function setCookietemp(key, val) {
    var tmp = key + "=" + escape(val) + "; ";
    //tmp += "path=/; ";
     document.cookie = tmp;
}
function clearCookie(key) {
    document.cookie = key + "=" + "xx; expires=Tue, 1-Jan-1980 00:00:00;";
}

