var Opera= ( navigator.userAgent.indexOf("Opera" ) != -1 );
var MSIE = ( navigator.userAgent.indexOf( "MSIE" ) != -1 ) && !Opera;
var Gecko= ( navigator.userAgent.indexOf("Gecko/") != -1 ) && !Opera;

function addEvent(obj, eventName, fn){

    var prev = obj[eventName];
    obj[eventName] = prev ? function() { fn() ; prev() } : fn;
}

document.pushBeforeOnLoad = function(fn){
	var prev = document.beforeOnload;
	document.beforeOnload = prev ? function(){ prev(); fn(); } : fn;
};

document.unshiftBeforeOnLoad = function(fn){
	var prev = document.beforeOnload;
	document.beforeOnload = prev ? function(){ fn(); prev(); } : fn;
}


// 指定のcookie文字列を返す
function getCookie(name){

	name += '=';
	var str   = document.cookie + ';';
	var start = str.indexOf(name);
	if( start != -1 ){
		var end = str.indexOf( ';' , start );
		return decodeURI(str.substring( start + name.length, end ));
	}
	return false;
}


//通信
function createXMLHttpRequest(){
	if(window.XMLHttpRequest){             // Mozilla, Firefox, Safari, IE7
		return new XMLHttpRequest();
	}else if(window.ActiveXObject){       // IE5, IE6
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");    // MSXML3
		}catch(e){
			return new ActiveXObject("Microsoft.XMLHTTP"); // MSXML2
		}
	}else{
		return null;
	}
}


function selectValue(select,input){
	input.value = select.options[select.selectedIndex].value;
	select.selectedIndex = 0;
}


function simpleXMLHttpRequest(url,vars,fn){
	var xmlhttp = createXMLHttpRequest();
	if(xmlhttp){
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					if(xmlhttp.responseText==''){
						fn();
					}else{
						alert(xmlhttp.responseText);
					}
				}else{
					alert('http error '+xmlhttp.status);
				}
			}
		}
		xmlhttp.open("POST",url);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(vars);
	}else{
		alert('XMLHttpRequestがサポートされていません。');
	}
}

function removeWhitespaceNodes(node){
	var i=0;
	while(node.childNodes[i]){
		if(node.childNodes[i].nodeType==3){
			if( node.childNodes[i].nodeValue.match(/^[\b\t\n]+$/) ){
				node.removeChild(node.childNodes[i]);
				continue;
			}
			
		}else if(node.childNodes[i].nodeType==1){
			removeWhitespaceNodes(node.childNodes[i]);
		}
		i++;
	}
}

function removeAllWhitespaceNodes(){
	removeWhitespaceNodes(document.body);
}


