<!--
error_not_input	      = '型番や製品名を入力してください。';
error_invalid_checked = '比較したい製品は、2つ以上5つ以下を選んでください。';
error_invalid_number  = '価格には数値のみを入力してください。カンマなど数値以外は入れないでください。';
error_overflow_number = '価格に入力した数値が大きすぎます。';
error_overflow_text   = '３０字以内で入力してください。';
valuetext = 'キーワードや製品名・型番をご入力ください。';


function check_comparison() {
	rObj = new RegExp("/product/comparison/$");
    if (document.URL.match(rObj)) {
		if(document.forms['fm2'].elements['cb[]'] != undefined){
	        setTimeout("disable_checkbox()", 1000 * 0.01 );
	    }
	}
}

function disable_checkbox(obj,len,setDisabled){
		obj = document.forms['fm2'].elements['cb[]'];
		len = obj.length;
		chkcnt = 0;
		
		for(ix=0; ix<len; ix++) {
			if (obj[ix].checked) chkcnt++;
		}

		if (chkcnt >= 5) {
	        setDisabled = true;
	    }
	    else {
	        setDisabled = false;
	    }
		
		for(ix=0; ix<len; ix++) {
        if (obj[ix].checked == false) {
            obj[ix].disabled = setDisabled;
        }
    }
}

function f_search_submit() {
	if(document.fm1.search_text.value == valuetext) {
		document.fm1.search_text.value = '';
	}
	check_form_value('none', 'none')
    if (document.fm1.page) {
        document.fm1.page.value = 1;
    }
    return f_submit();
}

function f_submit() {
    document.fm1.submit();
    return false;
}

function f_search(nm, val) {
	
	check_form_value(nm, val);
	
	obj	= document.forms['fm1'].elements[nm];
	if (obj) obj.value = val;

    document.fm1.page.value = 1;

    f_submit();
}

function f_search_cat(nm, val, type) {
    document.fm1.action = document.fm1.base_path.value+'/'+val+'/';
	f_search(nm, val);
}

function f_search_cattop(nm, val, type) {
    document.fm1.type.value = type;
    document.fm1.base_id.value = val;
    f_search(nm, val);
}

function f_pagectl(off, sort) {
	check_form_value('none', 'none')
    document.fm1.page.value  = off;
    document.fm1.sort.value = sort;
    f_submit();
}

function f_comparison() {
    document.fm2.ids.value = document.fm1.result_ids.value;
    document.fm2.submit();
}

function f_exec() {
    document.fm2.exec.value = 1;
    document.fm2.submit();
}

function f_comparison_submit() {
	obj	   = document.forms['fm2'].elements['cb[]'];
	len	   = obj.length;
	chkcnt = 0;
	for(ix=0; ix<len; ix++) {
		if (obj[ix].checked) chkcnt++;
		if (chkcnt > 5) break;
	}
	
	if (chkcnt < 2 || chkcnt > 5) {
		alert(error_invalid_checked);
		return false;
	}
    document.fm2.exec.value = 1;
    document.fm2.submit();
}

function f_comparison_submit2() {
	obj	   = document.forms['fm2'].elements['cb[]'];
	len	   = obj.length;
	chkcnt = 0;
	ids = new Array();
	for(ix=0; ix<len; ix++) {
		if (obj[ix].checked) {
			ids[chkcnt] = obj[ix].value;
			chkcnt++;
		}
		if (chkcnt > 5) break;
	}
	
	if (chkcnt < 2 || chkcnt > 5) {
		alert(error_invalid_checked);
		return false;
	}
	
    document.comparison_result.ids.value = ids.join('_');
    document.comparison_result.exec.value = 1;
    document.comparison_result.submit();
}

function f_checkbox() {
    obj     = document.forms['fm2'].elements['cb[]'];
    chkcnt  = 0;
    len     = obj.length;
    for(ix=0; ix<len; ix++) {
        if (obj[ix].checked) {
            chkcnt++
        }
    }
    if(chkcnt >= 6) {
		alert(error_invalid_checked);
		setDisabled = true;
	}else if (chkcnt >= 5) {
        setDisabled = true;
    }
    else {
        setDisabled = false;
    }
    for(ix=0; ix<len; ix++) {
        if (obj[ix].checked == false) {
            obj[ix].disabled = setDisabled;
        }
    }
}

function check_numeric (str) {
    if (str != "") {
        //return !str.match(/[^0-9０-９　\s]+/) 
        str = str.replace(/０/g, 0);
        str = str.replace(/１/g, 1);
        str = str.replace(/２/g, 2);
        str = str.replace(/３/g, 3);
        str = str.replace(/４/g, 4);
        str = str.replace(/５/g, 5);
        str = str.replace(/６/g, 6);
        str = str.replace(/７/g, 7);
        str = str.replace(/８/g, 8);
        str = str.replace(/９/g, 9);
        return !str.match(/[^0-9 \s]+/) 
    }
    return true;
}

function check_numeric_range(str) {
    if (str != "") {
        if (str > 2147483647) return false;
    }
    return true;
}

//星野追加
function check_form_value(nm, val){
	if(document.forms['tmp_data'] != null){
	
		if(document.forms['tmp_data'].elements['tmp_data_nm'].value != 'default'){
			if(document.forms['fm1'].elements[document.forms['tmp_data'].elements['tmp_data_nm'].value].value != document.forms['tmp_data'].elements['tmp_data_val_before'].value){
				document.forms['fm1'].elements[document.forms['tmp_data'].elements['tmp_data_nm'].value].value = document.forms['tmp_data'].elements['tmp_data_val_before'].value;
			}
		}
		
		if(nm != 'none'){
			document.forms['tmp_data'].elements['tmp_data_nm'].value = nm;
			document.forms['tmp_data'].elements['tmp_data_val_before'].value = document.forms['fm1'].elements[nm].value;
			document.forms['tmp_data'].elements['tmp_data_val'].value = val;
			
			if(document.forms['tmp_data'].elements['tmp_data_nm'].value == 'search_primary'){
				document.forms['tmp_data'].elements['tmp_data_val_before'].value = document.forms['fm1'].elements['search_primary'].value;
			}
		}else if(nm == 'none'){
		
			for(i=0; i<document.forms['fm1'].elements.length; i++) {
				if(document.forms['fm1'].elements[i].name == document.forms['tmp_data'].elements['tmp_data_nm'].value){
					document.forms['fm1'].elements['base_id'].value = null;
					document.forms['fm1'].elements['type'].value = null;
				}
			}
		
		
		}
	}
}


function debug_alert(){
	alert(document.forms['fm1'].elements[document.forms['tmp_data'].elements['tmp_data_nm'].value].value);
	
}

function onoffrefinesearch(name){
	var ckName2 = "yamaha_product_search";
	var ckDays2 = 2;
	
	if(document.getElementById(name).style.display == 'none'){
		document.getElementById(name).style.display = 'block';
		var disp = 'on';
	}else{
		document.getElementById(name).style.display = 'none';
		var disp = 'off';
	}
	
	SetCookie( ckName2 , disp );
}

function onoffrefinesearch2(name){
	var ckName2 = "yamaha_product_search";
	var ckDays2 = 2;

    if(name == 'refineSearchTop'){
        var put1 = document.getElementById('refineSearchstr1').innerHTML;
        var put2 = document.getElementById('refineSearchTop').innerHTML;
    
        document.getElementById('refineSearchstr1').innerHTML = put2;
        document.getElementById('refineSearchTop').innerHTML = put1;
    } else {
        var put1 = document.getElementById('refineSearchstr2').innerHTML;
        var put2 = document.getElementById('refineSearchBottom').innerHTML;
    
        document.getElementById('refineSearchstr2').innerHTML = put2;
        document.getElementById('refineSearchBottom').innerHTML = put1;
    }
    
    if(document.getElementById('refinesearchonoff').innerHTML == 'on'){
        var disp = 'off';
        document.getElementById('refinesearchonoff').innerHTML = 'off';
    }else{
        var disp = 'on';
        document.getElementById('refinesearchonoff').innerHTML = 'on';
    }
    
	SetCookie( ckName2 , disp );
}

function numericCheck(num) {
    var str = num.toString();
	var char1 = new Array('０','１','２','３','４','５','６','７','８','９');
	var char2 = new Array(0,1,2,3,4,5,6,7,8,9);
	var count;
	
	while(str.match(/[０-９]/)){
		for(count = 0; count < char1.length; count++){
			str = str.replace(char1[count], char2[count]);
		}
	}
    if (str.match(/^[0-9]+$/)) {
		return true;
    } else {
		return false;
	}
} 

function searchformsubmit(searchform, text){

	if (searchform == 'search3' || searchform == 'search4') {
		prices = new Array(document.getElementById(searchform).search_price_range_low.value, document.getElementById(searchform).search_price_range_high.value);

		for(i=0; i<=1; i++) {
			if (prices[i] != ''){
				if(numericCheck(prices[i]) == false){
					alert('価格には数値のみを入力してください。カンマなど数値以外は入れないでください。');
					return false;
				}
			}
		}
	}
	
	if (searchform == 'search3') {
		searchform = 'search1';
	} else if (searchform == 'search4') {
		searchform = 'search2';
	}
	
	if(document.getElementById(searchform).search_text.value == valuetext) {
		document.getElementById(searchform).search_text.value = '';
	}
	if(document.getElementById(searchform).search_text.value != text){
		for(i=0; i<document.getElementById(searchform).length; i++) {
			if(document.getElementById(searchform).elements[i].name != 'search_text' && document.getElementById(searchform).elements[i].name != 'search_accessory'){
				document.getElementById(searchform).elements[i].value = '';
			}
		}
	}
	
}

function comparisoncheckall(){
	obj	= document.forms['fm2'];
	
	len = obj.length;
	chkcnt = 0;
	
	for(ix=0; ix<len; ix++) {
		if (obj[ix].type == 'checkbox'){
			obj[ix].checked = 'checked';
		}
	}
}

function countNews(id){
    http = false;
    if(window.XMLHttpRequest) {
    　　　http = new XMLHttpRequest();
    } else if(window.ActiveXObject) {
　　　try {
　　　　　　http = new ActiveXObject("Msxml2.XMLHTTP");
　　　} catch(e) {
　　　　　　http = new ActiveXObject("Microsoft.XMLHTTP");
　　　}
    }

    http.open("POST", '/newscount.php', false);
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    http.send('i=' + id);
}

function putTextValueOn() {
    if (document.fm1.search_text.value == valuetext) {
        document.fm1.search_text.value = '';
        document.fm1.search_text.style.color = '#000000';
    } else {
        document.fm1.search_text.style.color = '#000000';
    }
}

function putTextValueOff() {
    if(document.fm1.search_text.value == ''){
        document.fm1.search_text.value = valuetext;
        document.fm1.search_text.style.color = '#9F9F9F';
    } else {
        document.fm1.search_text.style.color = '#000000';
    }
}

window.onload = check_comparison;

//-->
