// JavaScript
function goSel(sel){
	sel = Number(sel);
	switch(sel){
	case 1:
		document.v.variation.value="fit";
		return ture;
	case 2:
		document.v.variation.value="wheel";
		return ture;
	}
}

function HelpWinOpen(HELPHref1,WinNo,W,H){
	var HELPWin=window.open(HELPHref1,WinNo,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+W+',height='+H+'');
 
	if(navigator.appVersion.charAt(0)>=3){HELPWin.focus()} 
}

function openInquiry(lng)
{
	if (lng == 'e') {
		HELPHref1='http://www.sisiku.com/formmail/e_formmail.htm';
	} else {
		HELPHref1='http://www.sisiku.com/formmail.htm';
	}
	
	WinNo='inquiry';
	W=650;
	H=720;
	HelpWinOpen(HELPHref1,WinNo,W,H);
}


//step
function submitStep() {
	document.getElementById('mode').value = 'step';
	document.form.submit();
}
//expert
function submitExpert() {
	document.getElementById('mode').value = 'expert';
	document.form.submit();
}
//direct
function submitDirect() {
	document.getElementById('mode').value = 'direct';
	document.form.submit();
}

//
function goNext(lng){
	var p_class_id = document.form.class_id.value;

	var param = "";
	switch(p_class_id){
	case 'step':
		param = getClsClasp();
		document.form.action='index.php?lng='+ lng +'&mode='+ param;
		break;
	case 'step2':
		param = getParams2('classification', 'clasp_code') + getRadio('attachment_kind');
		document.form.action='index.php?lng='+ lng +'&mode=step3'+param;
		break;
	case 'step3':
		var classification = document.form.classification.value;
		if (Number(classification) == 1) {
			param = getParams1('classification') + getRadio('diameter');
		} else {
			param = getParams3('classification', 'clasp_code', 'attachment_kind') + getRadio('diameter');
		}
		document.form.action='index.php?lng='+ lng +'&mode=step4'+param;
		break;
	case 'step4':
		var classification = document.form.classification.value;
		if (Number(classification) == 1) {
			param = getParams2('classification', 'diameter') + getRadio('kg_loading');
		} else {
			param = getParams4('classification', 'clasp_code', 'attachment_kind', 'diameter') + getRadio('kg_loading');
		}
		document.form.action='index.php?lng='+ lng +'&mode=step5'+param;
		break;
	case 'step5':
		var classification = document.form.classification.value;
		if (Number(classification) == 1) {
			param = getParams3('classification', 'diameter' ,'kg_loading')  + getRadio('wheel_kind');
		} else {
			param = getParams5('classification', 'clasp_code', 'attachment_kind', 'diameter' ,'kg_loading')  + getRadio('wheel_kind');
		}
		document.form.action='result_list.php?lng='+ lng +'&mode=result'+param;
		break;
	default:
		document.form.action='index.php?lng='+ lng +'&mode=step';
		break;
	}
	document.form.submit();
	return true;
}

//
function getRadio(key) {
	var val;
    var i;
	if (document.forms[0].elements[key].length) {
	    for (i = 0; i < document.forms[0].elements[key].length; i++) {
	        if (document.forms[0].elements[key][i].checked) {
	            val = document.forms[0].elements[key][i].value;
	       	}
	   	}
	} else {
	  val = document.forms[0].elements[key].value;
	}
	return "&" + key + "=" + val;
}

function getClsClasp() {
	var val;
    var i;
	if (document.form.clf_clasp.length) {
	    for (i = 0; i < document.form.clf_clasp.length; i++) {
	        if (document.form.clf_clasp[i].checked) {
	            val = document.form.clf_clasp[i].value;
	       	}
	   	}
	} else {
	  val = document.form.clf_clasp.value;
	}

	val = Number(val);
	switch(val){
	case 1:
		return "step3&classification=1";
	default:
		return "step2&classification=2&clasp_code="+val;
	}
    
}

function getParams1(key) {
	var val = document.forms[0].elements[key].value;
	return "&" + key + "=" + val;
}

function getParams2(key1, key2) {
	return getParams1(key1) + getParams1(key2);
}

function getParams3(key1, key2, key3) {
	return getParams2(key1, key2) + getParams1(key3);
}

function getParams4(key1, key2, key3, key4) {
	return getParams3(key1, key2, key3) + getParams1(key4);
}

function getParams5(key1, key2, key3, key4, key5) {
	return getParams4(key1, key2, key3, key4) + getParams1(key5);
}

function getParams6(key1, key2, key3, key4, key5,key6) {
	return getParams5(key1, key2, key3, key4, key5) + getParams1(key6);
}


// Back
function goBack(lng){
	var p_class_id      = document.forms[0].elements['class_id'].value;

	var param = "";
	
	switch(p_class_id){
	case 'step2':
		var classification = document.form.classification.value;
		if (Number(classification) == 1) {
			param = getParams1('classification');
		} else {
			param = getParams2('classification', 'clasp_code');
		}
		document.forms[0].action='index.php?lng='+ lng +'&mode=step' + param;
		break;
	case 'step3':
		var classification = document.form.classification.value;
		if (Number(classification) == 1) {
			param = getParams1('classification');
			document.forms[0].action='index.php?lng='+ lng +'&mode=step'+param;
		} else {
			param = getParams3('classification', 'clasp_code', 'attachment_kind');
			document.forms[0].action='index.php?lng='+ lng +'&mode=step2'+param;
		}
		break;
	case 'step4':
		var classification = document.form.classification.value;
		if (Number(classification) == 1) {
			param = getParams2('classification', 'diameter');
		} else {
			param = getParams4('classification', 'clasp_code', 'attachment_kind', 'diameter');
		}
		document.forms[0].action='index.php?lng='+ lng +'&mode=step3'+param;
		break;
	case 'step5':
		var classification = document.form.classification.value;
		if (Number(classification) == 1) {
			param = getParams3('classification', 'diameter', 'kg_loading');
		} else {
			param = getParams5('classification', 'clasp_code', 'attachment_kind', 'diameter', 'kg_loading');
		}
		document.forms[0].action='index.php?lng='+ lng +'&mode=step4'+param;
		break;
	case 'result':
		var classification = document.form.classification.value;
		if (Number(classification) == 1) {
			param = getParams4('classification', 'diameter', 'kg_loading', 'wheel_kind');
		} else {
			param = getParams6('classification', 'clasp_code', 'attachment_kind', 'diameter', 'kg_loading', 'wheel_kind');
		}
		document.forms[0].action='index.php?lng='+ lng +'&mode=step5'+param;
		break;
	default:
		return false;
	}
	document.forms[0].submit();
	return true;
}


function CheckValue() {
	text = document.form.seiban.value;

	switch (text) {
		case "NJK":
		    window.open("http://www.sisiku.com/product/njk/casters_njk.pdf");
		    return false;
		case "SJ":
		    window.open("http://www.sisiku.com/product/sj/casters_sj.pdf");
		    return false;
		case "SC":
		    window.open("http://www.sisiku.com/product/sj/casters_sj.pdf");
		    return false;
		case "SA-SO":
		    window.open("http://www.sisiku.com/product/saso/casters_saso.pdf");
		    return false;
		case "CS-U":
		    window.open("http://www.sisiku.com/pdf/adjustfoot.pdf");
		    return false;
		case "CS-S":
		    window.open("http://www.sisiku.com/pdf/adjustfoot.pdf");
		    return false;
		case "CI-U":
		    window.open("http://www.sisiku.com/pdf/adjustfoot.pdf");
		    return false;
		case "CI-S":
		    window.open("http://www.sisiku.com/pdf/adjustfoot.pdf");
		    return false;
		case "CHS-T":
		    window.open("http://www.sisiku.com/pdf/adjustfoot.pdf");
		    return false;
		default:
		    break;
	}
	return true;
}


function clearForm(inp) {
	elems = inp.elements.length;
	for (var i=0; i<elems; i++) {
		var ele = inp.elements[i];
		if (inp.elements[i].type == "text" ||
			inp.elements[i].type == "textarea") {
			inp.elements[i].value = "";
		}
		else if (inp.elements[i].type == "select-one") {
			inp.elements[i].selectedIndex = 0;
			if (ele.onchange) {
				ele.onchange();
			}
		}
		else if (inp.elements[i].type == "checkbox") {
			inp.elements[i].checked = false;
		}
	}
}
