var httpObj;
var timerId;
var timeout_sec = 10;
var mouseclientX;
var mouseclientY;

function httpRequest(target_url, funcitonReference) {
    try {
        if(window.XMLHttpRequest) {
            httpObj = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
            httpObj = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            httpObj = false;
        }
    } catch(e) {
        httpObj = false;
    }
    if(! httpObj) {
        httpObjGenerateFail();
    }
//    timerId = setInterval('timeoutCheck()', 1000);

    httpObj.open("GET", target_url, true);
    httpObj.onreadystatechange = function() {
        if (httpObj.readyState == 4) {
            clearInterval(timerId);
            if (httpObj.status == 200) {
                funcitonReference(httpObj.responseText);
            } else {
                //alert(httpObj.status + ' : ' + httpObj.statusText);
                return false;
            }
        }
    }
    httpObj.send('');
}

function httpPostRequest(target_url, post_data, funcitonReference) {
    try {
        if(window.XMLHttpRequest) {
            httpObj = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
            httpObj = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            httpObj = false;
        }
    } catch(e) {
        httpObj = false;
    }
    if(! httpObj) {
        httpObjGenerateFail();
    }
    // タイマーをセット
    //timerId = setInterval('timeoutCheck()', 1000);

    httpObj.open("POST", target_url, true);
    httpObj.onreadystatechange = function() {
        if (httpObj.readyState == 4) {
            clearInterval(timerId);
            if (httpObj.status == 200) {
                funcitonReference(httpObj.responseText);
            } else {
                alert(httpObj.status + ' : ' + httpObj.statusText);
                return false;
            }
        }
    }
    //alert(post_data);
    httpObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    httpObj.send(post_data);
}

function httpObjGenerateFail() {
    alert('ご利用のブラウザーでは、当サイトをご利用頂けません。');
    return false;
}

function timeoutCheck() {
    timeout_sec --;
    if(timeout_sec <= 0) {
        clearInterval(timerId);
        httpObj.abort();
        alert('タイムアウトです。');
        return false;
    }
}

function addListener(elem, eventType, func, cap) {
	if(!elem){
		return false;
	}else if(elem.addEventListener) {
        elem.addEventListener(eventType, func, cap);
    } else if(elem.attachEvent) {
        elem.attachEvent('on' + eventType, func);
    } else {
        alert('ご利用のブラウザーはサポートされていません。');
        return false;
    }
} 

function popUp(URL ,width, height) {
	var day = new Date();
	var id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height+',left = 0,top = 0');");
}

function action() {}

function GetBrowser(){
   OP = (navigator.userAgent.indexOf("Opera",0) != -1)?1:0;
   N6 = document.getElementById;
   IE = document.all;
   N4 = document.layers;

   if (OP){
      document.onmousemove = MoveOP;
   }else if (IE){
      document.onmousemove = MoveIE;
   }else if (N6){
      window.addEventListener("mousemove", MoveN6, true);
   }else if (N4){
      window.captureEvents(Event.MOUSEMOVE);
      window.onmousemove = MoveN4;
   }
}

function MoveOP(){
  mouseclientX = window.event.clientX;
  mouseclientY = window.event.clientY;
}
function MoveN6(e){
  mouseclientX = e.pageX;
  mouseclientY = e.pageY;
}
function MoveIE(){
  mouseclientX = window.event.clientX + document.documentElement.scrollLeft;
  mouseclientY = window.event.clientY + document.documentElement.scrollTop;
}
function MoveN4(e){
  mouseclientX = myX + e.x;
  mouseclientY = myY + e.y;
}

function checkBrowser()
{
  var uName = navigator.userAgent;
  if (uName.indexOf("Safari") > -1) return "Safari";
  if (uName.indexOf("Opera") > -1) return "Opera";
  if (uName.indexOf("MSIE") > -1) return "Internet Explorer";
  return "Netscape";
}

function sendToiTunes(rss_url){
	if  (checkBrowser() == 'Safari')
	{
	  document.location.href = rss_url;
	}else
	{
      subWin = window.open(rss_url,"sample","screenX=20,screenY=50,left=20,top=50,width=320,height=240");
	  subWin.location.href = "RSSdownloaded.html";
    }
}

/*
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
*/

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
}

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
}


// Query String から 配列を返す
function getParameter(){
  str = location.search;
  var dec = decodeURIComponent;
  var par = new Array, itm;
  if(typeof(str) == 'undefined') return par;
  if(str.indexOf('?', 0) > -1) str = str.split('?')[1];
  str = str.split('&');
  for(var i = 0; str.length > i; i++){
    itm = str[i].split("=");
    if(itm[0] != ''){
      par[itm[0]] = typeof(itm[1]) == 'undefined' ? true : dec(itm[1]);
    }
  }
  return par;
}
// 配列 から Query Stringを返す
function setParameter(par){
//  var enc = encodeURIComponent;
  var str = '', amp = '';
  if(!par) return '';
  for(var i in par){
    str = str + amp + i + "=" + encodeURIComponent(par[i]);
    amp = '&'
  }
  return str;
}

function changeParameter(paramName,paramValue){
	var params = getParameter();
	params[paramName] = paramValue;
//	alert(location.href + "?" + setParameter(params));
	location.search = "?" + setParameter(params);
}


function getRadioValue(formname,radioname){
    for (i=0;i <document.forms[formname][radioname].length;i++){
      if (document.forms[formname][radioname][i].checked)
	      value = document.forms[formname][radioname][i].value;
    }
    return value;
}
