/**
 *
 * IE判定
 *
 */
function isMSIE() {
    if (window.opera) { //Operaの時
        return false;
    } else if (document.all) {
        return true;
    } else {
        return false;
    }
}

function isIE6() {
	if (typeof document.documentElement.style.maxHeight != "undefined") {
		return false;
	}
	else {
		return true;
	}
}

function doc(ID) {
    if (isMSIE()) {
        if (!document.all(ID)) {
            return false;
        } else {
            return document.all(ID);
        }
    } else {
        if (!document.getElementById(ID)) {
            return false;
        } else {
            return document.getElementById(ID);
        }
    }
}

// XMLHttpRequest取得
function getXMLObj() {
    var objXML = null;
    if (window.XMLHttpRequest) {
        objXML = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            objXML = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                objXML = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                return null;
            }
        }
    }
    return objXML;
}

/**
 *
 * 画像切り替え
 *
**/
function imgFlip(base, flip) {
  var imgs = document.images;
  if (!document.images) {
    return false;
  }
  var pre = new Array();
  for (var i = 0; i < imgs.length; i++) {
    var src = imgs[i].src;
    if (src.match(base)) {
      // 画像先読み
      pre[i] = new Image();
      pre[i].src = src.replace(base, flip);

      // ロールオーバー設定
      imgs[i].onmouseover = function() {
        this.src = this.src.replace(base, flip);
      }
      imgs[i].onmouseout = function() {
        this.src = this.src.replace(flip, base);
      }
    }
  }
}

/**
 *
 * 別窓オープン設定
 * classにexternalを指定したaタグは別窓で開く
 *
 */
function external() {
    if (!document.getElementsByTagName) {
        return;
    }
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href")) {
            if (anchor.getAttribute("className") == "external" || anchor.getAttribute("class") == "external") {
                anchor.target = "_blank";
            }
        }
    }
}

/**
 *
 * イベント追加
 *
**/
function addEvent(elm, eventName, func) {
  if (elm.addEventListener) {
    elm.addEventListener(eventName, func, false);
    return true;

  } else if (elm.attachEvent) {
    elm.attachEvent("on"+eventName, func);
    return true;

  } else {
    return false;

  }
}

/**
 *
 * 現在のページの項目の色を変える
 *
**/
function currentPage() {
    if (!document.getElementsByTagName) {
        return;
    }
	var elm = document.getElementById("MenuBody");
    if (!elm) {
		return;
	}

    var anchors = elm.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
		var docURL = document.URL.replace('index.html', '');
		docURL = docURL.replace('index.php', '');
		var menuURL = anchor.href;
        if (!menuURL.match(/^.*(\.html|\.php|\.shtml)$/)) {
          menuURL += "/";
        }
        menuURL = menuURL.replace('index.html', '');
        menuURL = menuURL.replace('index.php', '');
        if (docURL == menuURL && anchor.getElementsByTagName("img").length == 0) {
			anchor.removeAttribute("href");
            anchor.style.color = "#0000FF";
            anchor.style.backgroundColor = "#FFFF00";
        }
    }
}

/**
 *
 * Googleマップセット
 *
**/
function set_google_map(url, width, height, alt) {
  var map;
  if (isMSIE()) {
    map = "<iframe src=\""+ url +"\" width=\""+ width +"\" height=\""+ height +"\">"+ alt +"</iframe>";
  } else {
    map = "<object data=\""+ url +"\" width=\""+ width +"\" height=\""+ height +"\">"+ alt +"</object>";
  }
  document.write(map);
}

/**
 *
 * カレンダー切り替え
 *
**/
function calendar_change(id, addval) {
  if (addval == 0) {
    var dt = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
  } else {
    var dt = new Date(parseInt(doc('CalYear').value), parseInt(doc('CalMonth').value)-1+addval, 1);
  }

  if (doc("CalendarOut")) {
    var elm = doc("CalendarOut");
    var univ = 0;
  } else {
    var elm = doc("CalendarOutUniv");
    var univ = 1;
  }

  var url = "/setting/calendar.php";

  var objXML = getXMLObj();
  if (objXML) {
    objXML.onreadystatechange = function() {
      if (objXML.readyState == 4) {
        if (objXML.status == 200) {
          elm.innerHTML = objXML.responseText;
        } else {
          alert(objXML.status);
          return false;
        }
      }
    }
    objXML.open('post', url, true);
    objXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
    objXML.send('year=' + encodeURI(dt.getFullYear()) + '&month='+encodeURI(dt.getMonth()+1)+"&univ="+univ);
  }
}
/**
 *
 * OS判定
 *
**/
function get_os() {
	var os;
	var ua = navigator.userAgent;

	if (ua.match(/Win(dows )?NT 6\.1/)) {
		// Windows 7
		os = "Windows 7";  

	} else if (ua.match(/Win(dows )?NT 6\.0/)) {
		// Windows Vista
		os = "Windows Vista";

	} else if (ua.match(/Win(dows )?NT 5\.2/)) {
		// Windows Server 2003
		os = "Windows Server 2003";

	} else if (ua.match(/Win(dows )?(NT 5\.1|XP)/)) {
		// Windows XP
		os = "Windows XP";

	} else if (ua.match(/Win(dows)? (9x 4\.90|ME)/)) {
		// Windows ME
		os = "Windows ME";

	} else if (ua.match(/Win(dows )?(NT 5\.0|2000)/)) {
		// Windows 2000
		os = "Windows 2000";

	} else if (ua.match(/Win(dows )?98/)) {
		// Windows 98
		os = "Windows 98";

	} else if (ua.match(/Win(dows )?NT( 4\.0)?/)) {
		// Windows NT
		os = "Windows NT";

	} else if (ua.match(/Win(dows )?95/)) {
		// Windows 95
		os = "Windows 95";

	} else if (ua.match(/Mac|PPC/)) {
		// Macintosh
		os = "Mac OS";

	} else if (ua.match(/Linux/)) {
		// Linux
		os = "Linux";

	} else if (ua.match(/(Free|Net|Open)BSD/)) {
		// BSD 系
		os = RegExp.$1 + "BSD";

	} else if (ua.match(/SunOS/)) {
		// Solaris
		os = "Solaris";

	} else {
		// 上記以外 OS
		os = "N/A";

	}

	return os;
}

/**
 *
 * フォントセット
 *
**/
function set_fontfamily()  {
	switch (get_os()) {
		case "Windows Server 2003":
		case "Windows XP":
		case "Windows 2000":
		case "Windows ME":
		case "Windows NT":
		case "Windows 98":
		case "Windows 95":
		//case "Windows 7":
			$("body").css('font-family', '"ＭＳ Ｐゴシック", "MS PGothic", "sans-serif"');
			$(".common_dl > dt").css('padding-top', '3px').css('padding-bottom', '3px');
			$(".common_dl > dd").css('line-height', '150%');
			$(".link_arrow").css('background-position', 'left top').css('padding-bottom', '2px');
			break;
		default:
			break;
	}
}

/**
 *
 * トップページメニュー
 *
**/
function menu_change(menu) {
	$.ajax({
		url: "topmenu/" + menu + ".html",
		cache: false,
		success: function(html){
			$("#MenuButton > ul > li > a").css('color', '#0000ff').css('font-weight', 'normal');
			switch (menu) {
				case 'hennyu':
					$("#MenuHennyu > a").css('color', '#333333').css('font-weight', 'bold');
					break;
				case 'insi':
					$("#MenuInsi > a").css('color', '#333333').css('font-weight', 'bold');
					break;
				case 'daigaku':
					$("#MenuUniv > a").css('color', '#333333').css('font-weight', 'bold');
					break;
				case 'web':
					$("#MenuWeb > a").css('color', '#333333').css('font-weight', 'bold');
					break;
				case 'job':
					$("#MenuJob > a").css('color', '#333333').css('font-weight', 'bold');
					break;
				case 'other':
					$("#MenuOther > a").css('color', '#333333').css('font-weight', 'bold');
					break;
				default:
					$("#MenuHennyu > a").css('color', '#333333').css('font-weight', 'bold');
					break;
			}
			$("#Menu").html(html);
			$.cookie('_cyuouzemi_menu', menu);
		}
	});
	return false;
}




function show_coupon() {
window.open('coupon.html', 'coupon', 'width=470,  height=550, scrollbars=no, resizable=no, menubar=no, toolbar=no, location=no, directories=no, status=no, resizable=no');
}