/*==========================================================
親タグを探す
第一引数：対象となるオブジェクト
第二引数：探す親オブジェクトのタグ名
==========================================================*/
document.getParentByTagName=function(myObj,parentTagName){
	var parentObj=myObj;
	while(parentObj.tagName!=parentTagName.toUpperCase()){
		parentObj=parentObj.parentNode;
	}
	return parentObj;
}




/*==========================================================
ポップアップウィンドウを開く
第一引数：url
第二引数：ウィンドウネーム
第三引数：ウィンドウの幅
第四引数：ウィンドウの高さ
==========================================================*/
function openWin(url,wName,w,h) {

	if((checkOS().indexOf("win")&&checkBrowser().indexOf("ie"))||checkBrowser().indexOf("firefox")){
		w=eval(w)+17;
		h=eval(h)+17;
	} else 
	if(checkBrowser().indexOf("netscape")){
		w=eval(w)-2;
		h=eval(h)-2;
	} else 
	if(checkBrowser().indexOf("safari")){
/*
		w=eval(w)+1;
		h=eval(h)+1;
*/
	}
	wProperty='toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,width='+w+',height='+h;
	pw=window.open (url,wName,wProperty);
	pw.focus();
}

/*==========================================================
aタグ内のhref属性にhttp://が含まれていたらtargetを変える
body onloadに設置を推奨
==========================================================*/
function changeTarget(){

	targetDocs=document;
	if(document.domain!=""){
		linkObj=targetDocs.getElementsByTagName("a")
		for(i=0; i<linkObj.length; i++){
			cond_01 = linkObj[i].href!=undefined;
			cond_02 = linkObj[i].href.indexOf('http://',0)==0;
			cond_03 = linkObj[i].href.indexOf(document.domain,0)==-1;
			if(cond_01 && cond_02 && cond_03){
				linkObj[i].target="_blank";
			}
		}
	}
}

/*==========================================================
OS判別
==========================================================*/
function checkOS(){
	agent = navigator.userAgent.toLowerCase();
	//winかどうか
	if((agent.indexOf("windows")!=-1)){
		os="win"
	}else 

	//macかどうか
	if(browserName=(agent.indexOf("mac")    !=-1)){
		os="mac";
	}else{
		os="other";
	}
	return os;
}


/*==========================================================
ブラウザ判別
winie,winfirefox,macie,macsafariなどが戻り値となる
==========================================================*/
function checkBrowser(){
	agent = navigator.userAgent.toLowerCase();
	var browserName="";
	//safariかどうか
	if(agent.indexOf("safari")!=-1){
		browserName+="safari";
	}else 

	//オペラかどうか(オペラはMSIEを吐くので、IEより先に判別する必要あり)
	if(agent.indexOf("opera")!=-1){
		browserName+="opera";
	}else 

	//firefoxかどうか
	if(agent.indexOf("firefox")!=-1){
		browserName+="firefox";
	}else

	//Netscapeかどうか
	if(agent.indexOf("gecko")!=-1){
		browserName+="gecko";
	}else 
	//IEかどうか
	if(agent.indexOf("msie")!=-1){
		browserName+="ie";
	}
	return browserName;
}

/*==========================================================
テーブルの背景を交互に変える
==========================================================*/
/*==========下位互換用==========*/
function setTableColor(oTable,color01,color02){
	setTableColorById(oTable,color01,color02);
}

/*==========指定IDのテーブル色を変える==========*/
/*
第一引数：テーブルのID名
第二引数：色その1
第三引数：色その2
*/

function setTableColorById(oTable,color01,color02){
	targetTable=document.getElementById(oTable);
	targetTr=targetTable.getElementsByTagName('TR');
	for(i=0; i<targetTr.length; i++){
		TrColor = (i%2) ? color01:color02;
		targetTr[i].style.backgroundColor=TrColor;
	}
}

/*==========指定classのテーブル色を変える(要prototype.js)==========*/
/*
第一引数：テーブルのクラス名
第二引数：色その1
第三引数：色その2
*/
function setTableColorByClassName(oTable,color01,color02){
	//ターゲットとなるテーブルにあるtrタグの配列
	targetTr     = new Array();
	//上記からその中にあるテーブルにあるtrを除いた配列
	realTargetTr = new Array();

	targetTable=document.getElementsByClassName(oTable);
	for(i=0; i<targetTable.length; i++){
		targetTr[i]=targetTable[i].getElementsByTagName('TR');

		for(j=0; j<targetTr[i].length; j++){
			if(targetTr[i][j].parentNode.parentNode.tagName.toLowerCase()=="table" &&
			  targetTr[i][j].parentNode.parentNode.className            ==oTable){
				realTargetTr.push(targetTr[i][j]);
			}
		}
	}
	for(j=0; j<realTargetTr.length; j++){
		TrColor = (j%2) ? color01:color02;
		realTargetTr[j].style.backgroundColor=TrColor;
	}

}

