/*
//共通JAVASCRIPT
*/

var co = "..";


//
//共通ファイルの読み込み
//
//document.write("<LINK rel='stylesheet' href='"+ co + "/css/common.css' type='text/css'>");


//
//ロールオーバー
//
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//
//CSS
//

function getOS() {
	var UA  = navigator.userAgent.toUpperCase();
	if (UA.indexOf("SAFARI") >= 0) return "Safari";
	if (UA.indexOf("MAC") >= 0) return "MacOS";
	if (UA.indexOf("WIN") >= 0) return "Windows";
	return "";
}
function getBrName() {
	var AN  = navigator.appName.toUpperCase();
	if (AN.indexOf("NETSCAPE") >= 0)  return "Netscape";
	if (AN.indexOf("MICROSOFT") >= 0) return "Explorer";
	return "";
}
function getBrVer() {
	var browser = getBrName();
	var version = 0;
	var s = 0;
	var e = 0;
	var appVer  = navigator.appVersion;
	if (browser == "Netscape") {
		s = appVer.indexOf(" ",0);
		version = eval(appVer.substring(0,s));
		if (version >= 5) version++;
	}
	if (browser == "Explorer") {
		appVer  = navigator.userAgent;
		s = appVer.indexOf("MSIE ",0) + 5;
		e = appVer.indexOf(";",s);
		version = eval(appVer.substring(s,e));
	}
	return version;
}

//ロールオーバー
function rollOverMenu(e){
	var box = document.getElementById(e);
	//読み込むCSS
	box.className = 'tdButton_over';
}

//ロールアップ
function rollUpMenu(e){
	var box = document.getElementById(e);
	box.className = 'tdButton'; //読み込むCSS
}


//
//入力チェック
//
function checkFunc( id,text,act ){
	var elem = document.getElementById( id );
	//先頭と後ろの半角・全角スペースを削除
	elem.value = elem.value.replace(/^\s+|\s+$/g, "");
	elem.value = elem.value.replace(/^　|　$/g, "");
	
	var fg = 0;
	switch ( act ){
		//存在チェック
		case 0:
			if( elem.value == "" ){ fg = 1;}
			break;
		//数字チェック
		case 1:
			if (  elem.value != "" && !elem.value.match(/[0-9]/)){ fg = 1;}
			break;
		//英数字チェック
		case 2:
			if ( elem.value != "" && !elem.value.match(/[0-9a-zA-Z]/)){ fg = 1;}
			break;
		//メールアドレスチェック
		case 3:
			if(  elem.value != "" && !elem.value.match(/^[\w\._-]+@[\w\.-]+\.\w{2,}$/)){ fg = 1;}
			break;
		//全角カタカナチェック
		case 5:
			if (  elem.value != "" && elem.value.match(/[^ァ-ヴー 　]/)){ fg = 1;}
			break;
		//　半角英字のみチェック
		case 6:
			if ( elem.value != "" && elem.value.match(/[^a-zA-Z ]/)){ fg = 1;}
			break;
	}
	
	if( fg == 0 ) { return true;}
	else{
		alert( text );
		elem.value = "";
		elem.focus();
		return false;
	}
}


//等価チェック
function equalCheck( id , id2 , text ){
	var elem = document.getElementById( id );
	var elem2 = document.getElementById( id2 );
	
	if( elem.value != elem2.value ){
		alert( text );
		elem.value = "";
		elem2.value = "";
		elem.focus();
		return false;
	}else{ return true; }
}


/*
* 文字数チェック
*/
function mojiCountCheck( id,_count,text ){
	var elem = document.getElementById( id );

	if( elem.value.length < _count ){
		alert( text );
		elem.value = "";
		elem.focus();
		return false;
	}else{ return true; }
}


/*
* 画像チェック
*/
function imgCheck( _id,_text ){
	var elem	= document.getElementById( _id );
	var fg		= 0;
	
	// 入力チェック
	if( elem.value == "" ) fg = 1;
	
	// 結果
	if( fg == 0 ) { return true;}
	else{
		alert( _text );
		elem.value = "";
		elem.focus();
		return false;
	}
}


function is_Confrim( a,b ){
	var res = confirm( b );
	
	if( res == true ){
		location.href = a;
	}else{
		return false;
	}
}


/*
* 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 cookieCheck( _co ){
	tmp = "cookiecheck="+escape('true')+"; ";
	document.cookie = tmp;

	cookiecheck = getCookie("cookiecheck");
	
	if ( cookiecheck != "true" ){
		// なんもなければオフ
		location.href= _co + '/cookieErr/';
	}

	tmp = "cookiecheck="+escape('')+"; ";
	document.cookie = tmp;
}


function storeCaret (textEl) 
{
	if (textEl.createTextRange) 
	{
    	textEl.caretPos = document.selection.createRange().duplicate();
	}
}

function insertAtCaret (textEl) 
{
	text = "{B [タグワードをいれてください] B}";
    if (textEl.createTextRange && textEl.caretPos) 
		{
			var caretPos = textEl.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
    }
    else
		{
			var begin = textEl.value.substr(0, textEl.selectionStart);
			var end = textEl.value.substr(textEl.selectionEnd);
			textEl.value = begin + text + end;
		}     
}

function insertAtCaretLink (textEl, URL, Target) 
{
	text = "{A [" + Target + "][" + URL + "][タグワードをいれてください] A}";
    if (textEl.createTextRange && textEl.caretPos) 
		{
			var caretPos = textEl.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
    }
    else
		{
    	var begin = textEl.value.substr(0, textEl.selectionStart);
			var end = textEl.value.substr(textEl.selectionEnd);
			textEl.value = begin + text + end;
		}     
}

function Is_SendImgPath( id1 , id2 ){
	document.getElementById( id2 ).value = document.getElementById( id1 ).value;
}

function insertAtEventImage(textEl) 
{
	text = "{IMG [arrow.gif] IMG}";
    if (textEl.createTextRange && textEl.caretPos) 
		{
			var caretPos = textEl.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
    }
    else
		{
			var begin = textEl.value.substr(0, textEl.selectionStart);
			var end = textEl.value.substr(textEl.selectionEnd);
			textEl.value = begin + text + end;
		}     
}
