
/* -------------------------------------------------------------------------------- */

function intval(str)
{
	return parseInt(str);
}

function rawurlencode(str)
{
	str = str.replace(/&quot;/ig,'"');
	str = str.replace(/&lt;/ig,'<');
	str = str.replace(/&gt;/ig,'>');
	str = str.replace(/&#39;/ig,'\'');
	str = str.replace(/&amp;/ig,'&');
	
	str = encodeURIComponent(str);
	
	return str;
}

function rawurldecode(str)
{
	str = decodeURIComponent(str);
	
	/*
		str = str.replace(/&/g,'&amp;');
		str = str.replace(/"/g,'&quot;');
		str = str.replace(/</g,'&lt;');
		str = str.replace(/>/g,'&gt;');
		str = str.replace(/\'/g,'&#39;');
	*/
	
	return str;
}

function parse_query(str)
{
	var query_obj = {};
	
	if(str && str.length > 0){
		var tmp = str.split('&');
		var i,tmp2,key,value;
		
		for(i=0; i<tmp.length; i++){
			if(tmp[i] && tmp[i].length > 0){
				tmp2 = tmp[i].split('=');
				key = rawurldecode(tmp2[0]);
				value = rawurldecode(tmp2[1]);
				
				if(!query_obj[key]){query_obj[key] = '';}
				
				query_obj[key] += value;
			}
		}
	}
	
	return query_obj;
}

function get_now_time()
{
	var make_time = new Date();
	return Math.floor(make_time.getTime()/1000);
}

/* -------------------------------------------------------------------------------- */

function my_add_onload(func)
{
	if(window.addEventListener){window.addEventListener('load', func, false);}
	else if(window.attachEvent){window.attachEvent('onload', func);}
	else{window.onload = func;}
}

/* -------------------------------------------------------------------------------- */

function enable_form_input(p_form)
{
	if(!p_form){return false;}
	
	var param, i;
	
	param = p_form.elements;
	if(!param){return false;}
	
	for(i=0; i<param.length; i++){param[i].disabled = false;}
	
	return true;
}

function disabled_form_input(p_form)
{
	if(!p_form){return false;}
	
	var param, i;
	
	param = p_form.elements;
	if(!param){return false;}
	
	for(i=0; i<param.length; i++){param[i].disabled = true;}
	
	return true;
}

/* -------------------------------------------------------------------------------- */

/* ポップアップウィンドウ */
function popWin(getURL,sizeX,sizeY,target)
{
	var putOption = 'scrollbars=yes,close=yes,width='+sizeX+',height='+sizeY;
	var windowHandler = null;
	
	if(screen.width <= sizeX || screen.height <= sizeY){putOption = '';}
	
	if(target){windowHandler = window.open(getURL,target,putOption);}
	else{windowHandler = window.open(getURL,'_blank',putOption);}
	
	windowHandler.focus();
	
	return windowHandler;
}

/* -------------------------------------------------------------------------------- */

/* イメージのスワップ */
function imgSwap(imgID,imgFile,imgWidth,imgHeight)
{
	if(document.images[imgID]){
		document.images[imgID].src = imgFile;
		if(imgWidth > 0){document.images[imgID].width = imgWidth;}
		if(imgHeight > 0){document.images[imgID].height = imgHeight;}
		return true;
	}
	return false;
}

/* -------------------------------------------------------------------------------- */

/* 名前をキーにして 名前=値 の値を返す */
function name2value(inStr,inName)
{
	var start = inStr.indexOf(inName+'=');
	
	if(start < 0){return '';}
	
	var end = inStr.indexOf(';',start);
	return inStr.substring(start + inName.length + 1,end);
}

/* クッキーをいただきます */
function getCookie(inName)
{
	return unescape(name2value(document.cookie+' ;',inName));
}

/* クッキーをプレゼントします */
function setCookie(inName,inValue,inHold)
{
	var expires_str;
	
	expires_str = '';
	
	if(inHold > 0){
		var today = new Date();
		var nowTime = today.getTime() + inHold * 1000;
		today.setTime(nowTime);
		
		expires_str = today.toGMTString();
	}
	
	document.cookie = '' + inName + '=' + inValue + '; expires=' + expires_str;
}

/* -------------------------------------------------------------------------------- */

if(document.all){
	if(document.styleSheets){
		document.styleSheets[document.styleSheets.length-1].addRule('img', '-ms-interpolation-mode: bicubic;');
	}
}

/* -------------------------------------------------------------------------------- */

/* NPE column layout fix */

my_add_onload( function(){
	var e0, e1, i, j, this_height, max_height;
	
	e0 = document.getElementsByTagName('div');
	
	for(i=0; i<e0.length; i++){
		if(e0[i].className == 'pdp_layout_container'){
			e1 = e0[i].getElementsByTagName('div');
			max_height = 0;
			
			for(j=0; j<e1.length; j++){
				switch(e1[j].className){
					case 'pdp_layout_contents_left':
					case 'pdp_layout_menu_left':
					case 'pdp_layout_contents_right':
					case 'pdp_layout_menu_right':
						this_height = e1[j].clientHeight;
						if(this_height > max_height){max_height = this_height;}
					break;
				}
			}
			
			e0[i].style.height = '' + max_height + 'px';
		}
	}
} );
