﻿// Search Result

function post_item(Obj,Com_Name,Price,Rate,Mshop,Shop,ShopId,product_id){
	
	var sort_val = document.getElementsByName("sort_type")[0].getElementsByTagName("option")[document.getElementsByName("sort_type")[0].selectedIndex].value;
	
	switch(sort_val){
		case "1":sort_val="desc";break;
		case "2":sort_val="asc";break;
	}
	var Val = "";

	var Com = encodeURIComponent(Com_Name);
	var Mshop = encodeURIComponent(Mshop);
	var Shop = encodeURIComponent(Shop);
	Com = Com.replace(/%20%20/gi,"%20");
	if(Obj.href.indexOf("?") > 0){
		var str	= Obj.href;
		str	= str.substring(0,Obj.href.indexOf("?"));
		Val = str + "keyword=" + Com + "&category=&price_max=" +Price+ "&price_min=" +Price + "&rate_max=" + Rate+ "&rate_min=" + Rate + "&merchant=" + Mshop + "&shop=" + Shop + "&sub_store=" + ShopId + "&sort_order=" +sort_val+ "&" + "&product_id=" +product_id+ "&";
		//Obj.href = str + "?keyword=" + Com + "&price=" +Price + "&rate=" + Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&shopid=" + ShopId + "&sort_order=" +sort_val;
		
	}else{
		Val = "keyword=" + Com + "&category=&price_max=" +Price+ "&price_min=" +Price + "&rate_max=" + Rate+ "&rate_min=" + Rate + "&merchant=" + Mshop + "&shop=" + Shop + "&sub_store=" + ShopId + "&sort_order=" +sort_val+ "&" + "&product_id=" +product_id+ "&";
		//Obj.href += "?keyword=" + Com + "&price=" +Price + "&rate=" +Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&shopid=" + ShopId + "&sort_order=" +sort_val;
	}
	
	Cookie.set("Search_direct",Val);
	Cookie.set("ref_url",Obj.href);
}

function post_item_width(Obj,Com_Name,Price,Rate,Mshop,Shop,ShopId,product_id){
	
	var sort_val = document.getElementsByName("sort_type")[0].getElementsByTagName("option")[document.getElementsByName("sort_type")[0].selectedIndex].value;
	
	switch(sort_val){
		case "1":sort_val="desc";break;
		case "2":sort_val="asc";break;
	}
	var Val = "";

	var Com = encodeURIComponent(Com_Name);
	var Mshop = encodeURIComponent(Mshop);
	var Shop = encodeURIComponent(Shop);
	Com = Com.replace(/%20%20/gi,"%20");
	if(Obj.href.indexOf("?") > 0){
		var str	= Obj.href;
		str	= str.substring(0,Obj.href.indexOf("?"));
		Val = str + "keyword=" + Com + "&category=&price_max=" +Price+ "&price_min=" +Price + "&rate_max=" + Rate+ "&rate_min=" + Rate + "&merchant=" + Mshop + "&shop=" + Shop + "&sub_store=" + ShopId + "&sort_order=" +sort_val+ "&" + "&product_id=" + product_id + "&";
		//Obj.href = str + "?keyword=" + Com + "&price=" +Price + "&rate=" + Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&shopid=" + ShopId + "&sort_order=" +sort_val;
		
	}else{
		Val = "keyword=" + Com + "&category=&price_max=" +Price+ "&price_min=" +Price + "&rate_max=" + Rate+ "&rate_min=" + Rate + "&merchant=" + Mshop + "&shop=" + Shop + "&sub_store=" + ShopId + "&sort_order=" +sort_val+ "&" + "&product_id=" + product_id + "&";
		//Obj.href += "?keyword=" + Com + "&price=" +Price + "&rate=" +Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&shopid=" + ShopId + "&sort_order=" +sort_val;
	}
	
	Cookie.set("Search_width_direct",Val);
	Cookie.set("ref_url",Obj.href);
}


function post_item_text(Obj,Com_Name,Rate,Mshop,Shop,ShopId,Link_Url){
	
	var sort_val = document.getElementsByName("sort_type")[0].getElementsByTagName("option")[document.getElementsByName("sort_type")[0].selectedIndex].value;
	var Val = "";
	
	switch(sort_val){
		case "1":sort_val="desc";break;
		case "2":sort_val="asc";break;
	}
	var search_txt = "vc_url=";
	var Com = encodeURIComponent(Com_Name);
	var Mshop = encodeURIComponent(Mshop);
	var Shop = encodeURIComponent(Shop);
	//var Link_Url = Link_Url.substring(Link_Url.lastIndexOf(search_txt)+search_txt.length,Link_Url.length);
	var Link_Url = encodeURIComponent(Link_Url);

	Com = Com.replace(/%20%20/gi,"%20");
	if(Obj.href.indexOf("?") > 0){
		var str	= Obj.href;
		str	= str.substring(0,Obj.href.indexOf("?"));
		Val = str + "&keyword=" + Com + "&link=" +Link_Url + "&rate=" + Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&";
	//	Obj.href = str + "?keyword=" + Com + "&link=" +Link_Url + "&rate=" + Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&shopid=" + ShopId + "&sort_order=" +sort_val;
		
	}else{
		Val = "&keyword=" + Com + "&link=" +Link_Url + "&rate=" + Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&";
		//Obj.href += "?keyword=" + Com + "&link=" +Link_Url + "&rate=" +Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&shopid=" + ShopId + "&sort_order=" +sort_val;
	}
	
	
	Cookie.set("Search_text_link",Val);
	Cookie.set("ref_url",Obj.href);
}

function post_item_img(Obj,Com_Name,Rate,Mshop,Shop,ShopId,Link_Url,img_Url){
	
	
	
	var sort_val = document.getElementsByName("sort_type")[0].getElementsByTagName("option")[document.getElementsByName("sort_type")[0].selectedIndex].value;
	var Val = "";
	
	switch(sort_val){
		case "1":sort_val="desc";break;
		case "2":sort_val="asc";break;
	}
	var search_txt = "vc_url=";
	var Com = encodeURIComponent(Com_Name);
	var Mshop = encodeURIComponent(Mshop);
	var Shop = encodeURIComponent(Shop);
	//var Link_Url = Link_Url.substring(Link_Url.lastIndexOf(search_txt)+search_txt.length,Link_Url.length);
	var Link_Url = encodeURIComponent(Link_Url);
	var img_Url = encodeURIComponent(img_Url);

	Com = Com.replace(/%20%20/gi,"%20");
	if(Obj.href.indexOf("?") > 0){
		var str	= Obj.href;
		str	= str.substring(0,Obj.href.indexOf("?"));
		Val = str + "&keyword=" + Com + "&link=" +Link_Url + "&rate=" + Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&src=" + img_Url + "&" ;
	//	Obj.href = str + "?keyword=" + Com + "&link=" +Link_Url + "&rate=" + Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&shopid=" + ShopId + "&sort_order=" +sort_val;
		
	}else{
		Val = "&keyword=" + Com + "&link=" +Link_Url + "&rate=" + Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&src=" + img_Url + "&";
		//Obj.href += "?keyword=" + Com + "&link=" +Link_Url + "&rate=" +Rate + "&mshop=" + Mshop + "&shop=" + Shop + "&shopid=" + ShopId + "&sort_order=" +sort_val;
	}
	
	
	Cookie.set("Search_img_link",Val);
	Cookie.set("ref_url",Obj.href);
}


function set_Widget(){
	var widget = new Array();
	
	widget[0] = ["standard%2f01","スタンダード（タテ）","01"];
	widget[1] = ["standard_wide","スタンダード（ヨコ）","59"];
	widget[2] = ["standard_fixed","スタンダード規定バナーサイズ（タテ）","01"];
	widget[3] = ["standard_fixed_wide","スタンダード規定バナーサイズ（ヨコ）","59"];
	widget[4] = ["text","テキストウィジェット","03"];
	widget[5] = ["decoration","デコレーションウィジェット","04"];
	widget[6] = ["flash%2f06","ぼよよんウィジェット","62"];
	widget[7] = ["flash%2f05","フロートウィジェット","53"];
	widget[8] = ["flash%2f04","ぺらぺらウィジェット","46"];
	widget[9] = ["flash%2f03","スクロールウィジェット","32"];
	widget[10] = ["flash%2f02","スライドウィジェット","18"];
	widget[11] = ["flash%2f01","ラウンドウィジェット","05"];
	widget[12] = ["kami","かみしばいウィジェット","58"];
	widget[13] = ["bar","ウィジェットバー","66"];
	widget[14] = ["search","サーチウィジェット","06"];
	widget[15] = ["cloud","クラウドウィジェット","07"];
	
	var img_array = new Array();
	
	var url = "/s/affiliates/widgets_setup/";
	
	for(var i=0;i<widget.length;i++){
		//document.write('<li><a href="' + url + decodeURIComponent(widget[i][0]) +'/form.php" onmouseover="open_thum(this,\'' + widget[i][2] + '\');" onclick="search_Widget(this,\''+widget[i][0]+'\');return false;">' + widget[i][1] + '</a></li>');
		document.write('<li><a href="' + url + decodeURIComponent(widget[i][0]) +'/form.php" onclick="search_Widget(this,\''+widget[i][0]+'\');return false;">' + widget[i][1] + '</a></li>');
		img_array[i] = document.createElement("img");
		img_array[i].src = "/s_parts/img/widgetlist_" + widget[i][2] + ".jpg";
	}
	img_array[i+1] = document.createElement("img");
	img_array[i+1].src = "/s_parts/img/widgetlist_02.jpg";
	img_array[i+2] = document.createElement("img");
	img_array[i+2].src = "/s_parts/img/widgetlist_33.jpg";

	
}
function search_Widget(Obj,name){
	var price = Obj.parentNode.parentNode.parentNode.getElementsByTagName("span")[0].innerHTML;
	price = price.replace(/,/ig,"");
	var name = name;
	
	var value = {
		keyword:document.getElementsByName("keyword")[0].value,
		merchant:document.getElementsByName("merchant")[0].selectedIndex,
		sub_store:document.getElementsByName("sub_store")[0].value,
		category:document.getElementsByName("category")[0].selectedIndex,
		sort_type:document.getElementsByName("sort_type")[0].selectedIndex,
		price_min:document.getElementsByName("price_min")[0].value,
		price_max:document.getElementsByName("price_max")[0].value
		//rate_min:document.getElementsByName("rate_min")[0].selectedIndex,
		//rate_max:document.getElementsByName("rate_max")[0].selectedIndex
	};
	
	if(value.sort_type == 0){
		value.price_min = price;
	}else{
		value.price_max = price;
	}
	
	
	var Val ="";
	for(i in value){
		Val += i + "=" + encodeURIComponent(value[i]) + "&";
	}
	
	name = "Search_"+ name;

	Cookie.set(name,Val);
	
	Cookie.set("ref_url",Obj.href);
	
	location.href = Obj.href;
}

function open_Widget(Obj){
	Obj.parentNode.getElementsByTagName("div")[0].style.display = "block";
}
function close_Widget(Obj){
	Obj.parentNode.parentNode.parentNode.style.display = "none";
	document.getElementById("Wid_Thum").style.display = "none";
}

var open_thum_timer ;
function open_thum(Obj,src){
	var div = document.getElementById("Wid_Thum");
	
	clearTimeout(open_thum_timer);

	var Name = Obj.offsetParent.tagName;
	var OBJ = Obj;
	var Y = 0;
	var X = 0;
	if(Name != "HTML" && Name != "BODY"){
		while(Name != "HTML" && Name != "BODY"){
			Y += OBJ.offsetTop;
			OBJ = OBJ.offsetParent;
			Name = OBJ.tagName;
			X += OBJ.offsetLeft;
		}
		X += Obj.offsetLeft;
	}else{
		Y = Obj.offsetTop;
		X = OBJ.offsetLeft;
	}



	with(div){
		getElementsByTagName("img")[1].src = "/s_parts/img/widgetlist_" + src + ".jpg";
		getElementsByTagName("a")[0].onclick = function(){
			close_thum();
			return false;
		}
		getElementsByTagName("a")[0].href ="#"; 
		div.onmouseover = function(){
			clearTimeout(open_thum_timer);
		}
		div.onmouseout = function(){
			open_thum_timer = setTimeout(close_thum,3000);
		}
		style.display = "block";
		
		var UA = navigator.appVersion;
		if(UA.indexOf("MSIE 6.0") <= 0){
			Y = Y - div.offsetHeight -3;
		}else{
			Y = Y - div.offsetHeight -3;
			//Y = Y - div.offsetHeight -185;
		}
		
		var pl = navigator.platform;
		if(pl.indexOf("Win") < 0){
			Y -= 18;
		}

		
		style.top = Y + "px";
		style.left = X + "px";
	}

	open_thum_timer = setTimeout(close_thum,3000);

}
function close_thum(){
	document.getElementById("Wid_Thum").style.display = "none";
}

// z2h
function z2h(value){
	han = "0123456789";
	zen = "０１２３４５６７８９";
	str = ""; 
	for (i=0; i<value.length; i++) {
		c = value.charAt(i);
		n = zen.indexOf(c,0);
		if (n >= 0) c = han.charAt(n); str += c; 
	}
	str = str.replace(/[,，、]/g,"");
	str = str.replace(/[．]/g,".");
	if(!isNaN(str)){
		return str;	
	}else{
		return "";	
	}
}