﻿function confirmLocation(url, mess){
	if( !url || !mess){
		return false;
	}
	if( confirm(mess) ){
		location.href = url;
	}
	return false;
}

function confirmMessage(mess){
	f = confirm(mess);
	return f;
}

function all_check(cobj,formname,idname){
	Arr = document.forms[formname].elements[idname];
	if(Arr.length > 0){
		for(i = 0;i < Arr.length;i++){
			Arr[i].checked = cobj.checked;
		}
	}else{
		Arr.checked = cobj.checked;
	}
}


function serializeForm(form_name){
	if(!form_name){
		return false;
	}
	target_form = document.forms[form_name].elements;

	serialize_src = "";
	for( i=0; i<target_form.length; i++  ){
		if(target_form[i].type && target_form[i].value){
			if(target_form[i].type == "checkbox"){
				if(target_form[i].checked == true){
					serialize_src += target_form[i].name+"="+target_form[i].value + "&";
				}
			} else if(target_form[i].type == "radio"){
				if(target_form[i].checked == true){
					serialize_src += target_form[i].name+"="+target_form[i].value + "&";
				}
			}else{
				serialize_src += target_form[i].name+"="+target_form[i].value + "&";
			}
		}
	}
	return serialize_src;
}

function requestPost(request_url,form_data){
	if(!form_data){
		form_data = '';
	}
	method_type = "POST";
	async_type = false;
	var req = Spry.Utils.loadURL(method_type, request_url, async_type,null,{postData:form_data ,headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" }});
	resText = req.xhRequest.responseText;
	return resText;
}

function asyncSubmit(url,form_name){
	postStr = serializeForm(form_name);
	html = requestPost(url,postStr);
	alert(html);
}


function SetUriValue(request_uri, set_dom_id, selfObj){
	if(selfObj){
		selfObj.disabled = true;
	}
	var method_type = "POST";
	var async_type = true;
	var call_back = function(req){
		html = req.xhRequest.responseText;
		document.getElementById(req.setInnerHTML).innerHTML = html;
		selfObj.disabled = false;
	}
	var req = Spry.Utils.loadURL(method_type, request_uri, async_type,call_back,{'setInnerHTML':set_dom_id});
}

function SetInnerHTML(set_dom_id, value){
	document.getElementById(set_dom_id).innerHTML = value;
}

function imgChange( target_id, img_tag_name ,url, target_id2, w, h, alt, item_name ) {
	//zoom idを切り替え
	if(document.getElementById(target_id)){
		document.getElementById(target_id).href=url;
	}

	//画像幅を変更
	if(document.getElementById(target_id2)){
		document.getElementById(target_id2).width  = w;
		document.getElementById(target_id2).height = h;
	}
	
	// alt属性
	if(alt != ''){
		document.getElementById(target_id2).alt = alt;
	} else {
		document.getElementById(target_id2).alt = item_name;
	}
	setTimeout(function() {
		//画像パスの変更
		document.images[img_tag_name].src = url;
	}, 100)
}

function ItemImgWindowOpen( url, max ) {

	// 商品画像のURLを最大画像のパスへ置換
	newUrl = url.replace( /(https?)(:\/\/[-_.!~*\'()a-zA-Z0-9;?:\@&=+\$,%#]+)\/(img)\/([0-9]+)\/([0-9]+)\/([0-9]+)\/([0-9]+.jpg)$/, "$1$2\/$3\/$4\/$5\/" + max + "\/$7");

	// 別画面で表示
	window.open( newUrl, "_blank" );
}

// 入力値チェック
function search(){
	var len = document.forms.length;
	for( i=0; i < len; i++ ){
		if( document.forms[i].name == 'search_form' ){
			el = document.forms[i].elements;
			for( j=0; j < el.length; j++ ){
				data = el[j];
				if( data.name == 'lc' ){
					//if( isNaN( data.value ) ){
					if (data.value.match(/[^0-9]/g)){
						alert("価格は半角数字で入力してください");data.focus();return;
					}
				}
				if( data.name == 'uc' ){
					//if( isNaN( data.value ) ){
					if (data.value.match(/[^0-9]/g)){
						alert("価格は半角数字で入力してください");data.focus();return;
					}
				}
			}
		}
	}
	document.search_form.submit();
}
