var app = {
  isInit:true
}

var cookie = new Cookie("recommendState");

var Maker = function(makerName,name,spec,price,design,support,soft,game,battery,portability,hasNote,explanation){
 this.makerName = makerName;
 this.name = name;
 this.spec = spec;
 this.price = price;
 this.design = design;
 this.support = support;
 this.soft = soft;
 this.game = game;
 this.battery = battery;
 this.portability = portability;
 this.hasNote = hasNote;
 this.explanation = explanation;
 this.userMatch;
}

Maker.prototype.judgeUserMatch = function(makerName,spec,price,design,support,soft,game,battery,portability,kind,work){
  var spec = spec -0;
  var price = price -0;
  var support = support -0;
  var design = design -0;
  var soft = soft -0;
  var game = game -0;
  var battery = battery -0;
  var portability = portability -0;
  var work = work -0;
  
  //for lenobo only
  if(work == 1){
  	if(makerName == "lenobo"){
		return true;
	}  	 
  }
  
  if((this.spec + this.price) <= (spec + price - 3)){
  	    return false;
  }

  if(this.design <= design -3){
  		return false;
  }
  
  if(this.support <= support -3){
  		return false;
  }

  if(this.soft <= soft -3){
  		return false;
  }
  
  if(this.game <= game -3){
  		return false;
  }
  
  if(this.battery <= battery -3){
  	if(kind == 2 || kind == 3){ //NotePC ,allpc case
	   	return false; 
	}
  }
  
  if(this.portability <= portability -3){
    if(kind == 2 || kind == 3){ //NotePC ,allpc case
	   	return false; 
	}
  }
  
  if(this.hasNote == false){
  	 if(kind == 1){ //DesktopPC case
  		return false;
	 }
  }

  return true;

}

function $(e){
return document.getElementById(e);
}

function radioValue(element){
	var len;
	len = document.getElementsByName(element).length;
	for (var i=0;i<len;i++) {
	  if (document.getElementsByName(element)[i].checked){
		return document.getElementsByName(element)[i].value;
	  }
    }
}

var MakerArray = new Array();

function init(){
  var dell = new Maker('dell','<a href="http://click.linksynergy.com/fs-bin/click?id=xsv0FDnJs1M&offerid=133147.10002533&type=3&subid=0" rel="nofollow" target="_blank" >デル</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=xsv0FDnJs1M&bids=133147.10002533&type=3&subid=0" >',5,5,4,4,3,4,2,3,true,'高いコストパフォーマンスが魅力、世界有数の大パソコンメーカー、キャンペーンも多い');
  var mouse   = new Maker('mousecomputer','<a href="http://click.linksynergy.com/fs-bin/click?id=xsv0FDnJs1M&offerid=92827.10000001&type=3&subid=0" rel="nofollow" target="_blank" >マウスコンピュータ</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=xsv0FDnJs1M&bids=92827.10000001&type=3&subid=0" >',5,5,3,2,1,5,2,2,true,'知名度こそ低いがコストパフォーマンスは日本最高,一見の価値あり');
  var dospara = new Maker('dospara','<a href="http://www.accesstrade.net/at/c.html?rk=01000gew0012gl" rel="nofollow" target="_blank">ドスパラ<img src="http://www.accesstrade.net/at/r.html?rk=01000gew0012gl" width="1" height="1" border="0" alt="" /></a>',5,5,2,1,1,5,2,2,true,'マウスコンピュータに並ぶコストパフォーマンス、スペックを求めるならここ！出荷も速い！');
  var koubou =  new Maker('パソコン工房','<a href="http://click.linksynergy.com/fs-bin/click?id=xsv0FDnJs1M&offerid=83593.10000010&type=3&subid=0" target="_blank"  >パソコン工房</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=xsv0FDnJs1M&bids=83593.10000010&type=3&subid=0" >',4,4,2,1,1,5,2,2,true,'リーゾナブルに自分にあったパソコンが発注できるBTOパソコンメーカー');
  var fujitsu = new Maker('fujitsu','<a href="http://click.linksynergy.com/fs-bin/click?id=xsv0FDnJs1M&offerid=86322.10000196&type=3&subid=0" rel="nofollow" target="_blank" >富士通</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=xsv0FDnJs1M&bids=86322.10000196&type=3&subid=0" >',2,3,3,5,5,2,5,5,true,'バランスの良さはピカイチ、日本パソコン界のトップメーカー、国内シェアも高い');
  var nec     = new Maker('NEC','<a href="http://click.linksynergy.com/fs-bin/click?id=xsv0FDnJs1M&offerid=131725.10000028&type=3&subid=0" >NEC</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=xsv0FDnJs1M&bids=131725.10000028&type=3&subid=0" >',2,3,3,5,5,2,5,5,true,'サポート体制が整っていて抜群の安定感を誇る日本メーカー。国内シェアも高い');
  var hp      = new Maker('HP','<a Href="http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=2428064&pid=876298913" rel="nofollow" target="_blank" ><img Src="http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=2428064&pid=876298913" height="1" width="1" Border="0">HP</a>',4,4,3,3,2,3,2,2,true,'価格、デザインともに充実した世界有数のパソコンメーカー');
  var lenobo  = new Maker('lenobo','<a href="http://click.linksynergy.com/fs-bin/click?id=xsv0FDnJs1M&offerid=127284.10000055&type=3&subid=0" >Lenovo</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=xsv0FDnJs1M&bids=127284.10000055&type=3&subid=0" >',2,3,3,3,2,2,4,3,false,'ビジネス用途で使用するならばこれ、セキュリティ、効率性を重視したビジネスパソコンが得意');
  var toshiba = new Maker('東芝','<a Href="http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=2428064&pid=876298948"  rel="nofollow" target="_blank" ><img Src="http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=2428064&pid=876298948" height="1" width="1" Border="0">東芝ダイレクトＰＣ</a>',2,3,3,4,4,2,5,3,false,'ダイナブックで有名。信頼性が高いノートパソコン');
  var sony = new Maker('SONY','<a href="http://click.linksynergy.com/fs-bin/click?id=xsv0FDnJs1M&offerid=51141.20000861&type=3&subid=0" rel="nofollow" target="_blank" >SONY</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=xsv0FDnJs1M&bids=51141.20000861&type=3&subid=0" >',2,2,5,4,5,2,5,5,true,'デザインを重視する人は要チェック、様々なカラーデザインに対応');
  
  MakerArray.push(dell);
  MakerArray.push(mouse);
  MakerArray.push(dospara);
  MakerArray.push(koubou);
  MakerArray.push(fujitsu);
  MakerArray.push(nec);
  MakerArray.push(sony);
  MakerArray.push(lenobo);
  MakerArray.push(hp);
  MakerArray.push(toshiba);
 
  var isSetResult = true;
  
  if(Cookie.enabled){  

     if(cookie.kind != undefined){
	   //if(cookie.position == 'result'){
	   	 $('question').style.display = "none";
		 setResult();
		 isSetResult = false;	 	   
	   //}	   
	 }  
  }
  app.isInit = false;
  
  if(isSetResult){
    $('result').onclick = setResult;
  }
  
  $('desktop').onclick = function(){setQuestionnaire("desktop")};
  $('notebook').onclick = function(){setQuestionnaire("notepc")};
  $('allpc').onclick = function(){setQuestionnaire("allpc")};
  
}

function setQuestionnaire(pckind){
   var listForNote = document.getElementsByName('noteonly');
   var listForDesktop = document.getElementsByName('desktoponly');

   if(pckind == "desktop"){
     for(var i=0;i < listForNote.length;i++){
       listForNote[i].style.display = "none";
     }
	 for(var i=0;i < listForDesktop.length;i++){
       listForDesktop[i].style.display = "";
     }	 
   }else if(pckind == "notepc"){
     for(var i=0;i < listForNote.length;i++){
       listForNote[i].style.display = "";
     }
	 for(var i=0;i < listForDesktop.length;i++){
       listForDesktop[i].style.display = "none";
     }
   }else{
     for(var i=0;i < listForNote.length;i++){
       listForNote[i].style.display = "";
     }
	 for(var i=0;i < listForDesktop.length;i++){
       listForDesktop[i].style.display = "";
     }
   }
   
}


function setResult(){

  var spec,price,design,support,soft,game,battery,portability,kind,video,movie,work,space,tv,boot,extention;
  if(app.isInit == false){
	spec = radioValue('spec') -0;
    price = radioValue('price') -0;
	design = radioValue('design') -0;
	support = radioValue('support') -0;
	soft = radioValue('soft') -0;
	game = radioValue('game') -0;
	battery = radioValue('battery')-0;
	portability = radioValue('portability') -0;
	kind = radioValue('kind')-0;
	video = radioValue ('video')-0;
	movie = radioValue('movie')-0;			
	work = radioValue('work')-0;
	space = radioValue('space')-0;
	tv = radioValue('tv')-0;
	boot = radioValue('boot')-0;
	extention = radioValue('extention')-0;
	
	cookie.spec = spec +"";
	cookie.price = price +"";
	cookie.design = design +"";
	cookie.support = support +"";
	cookie.soft = soft +"";
	cookie.game = game + "";
	cookie.battery = battery +"";
	cookie.portability = portability +"";
	cookie.kind = kind +"";
	cookie.video = video +"";
	cookie.movie = movie +"";
	cookie.work = work +"";
	cookie.space = space +"";
	cookie.tv = tv +"";
	cookie.boot = boot +"";
	cookie.extention = extention + "";
	cookie.position = 'result' +"";
	cookie.store(10,"/");
  }else{
    spec = cookie.spec -0;
	price = cookie.price -0;
	design = cookie.design -0;
	support = cookie.support -0;
	soft = cookie.soft -0;
	game = cookie.game -0;
	battery = cookie.battery -0;
	portability = cookie.portability -0;
	kind = cookie.kind -0;
	video = cookie.video -0;
	movie = cookie.movie -0;
	work = cookie.work -0;
	space = cookie.space -0;
	tv = cookie.tv -0;
	boot = cookie.boot -0;
	extention = cookie.extention -0;
	position = cookie.position -0;  
  }
	
	var html = '<h2>おすすめメーカー</h2><table border="2" bordercolor="#006633">';
	
	for(var i=0;i<MakerArray.length;i++){	
		MakerArray[i].userMatch = MakerArray[i].judgeUserMatch(MakerArray[i].makerName,spec,price,design,support,soft,game,battery,portability,kind,work);
		if(MakerArray[i].userMatch){
		  html += '<tr><td align="center" bgcolor="#EEEEEE" width="100">' + MakerArray[i].name + '</td>';
		  html += '<td bgcolor="#CCFFFF">' + MakerArray[i].explanation + '</td></tr>';
		}
	}
	html += '</table>';
	
	html += '<h2>チェックリスト</h2><ul class="bg">';	
	
	if(design == 5){
		html += '<li>・デザイン重視ならこんなパソコンもおすすめ=><a href="http://click.linksynergy.com/fs-bin/click?id=xsv0FDnJs1M&offerid=240430.10003460&type=3&subid=0" >Design Studio</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=xsv0FDnJs1M&bids=240430.10003460&type=3&subid=0" ></li>';
	}
	
	if(game >= 4){
	    html += '<li>・３Dゲームを行いたいなら<strong>グラフィックアクセレレーター</strong>（<strong>グラフィックボード</strong>)は必須、パソコン購入前にグラフィックアクセレレーターが入っているかよく確認しておこう<br>=><a href="grabo.html">グラフィックボードの選び方</a></li>';
	}
	if(spec + price >= 9){
		if(kind == 3){
			html += '<li>・デスクトップパソコンは<strong>性能の割に安い</strong>のでおすすめ<br>=><a href="desktop.html">デスクトップパソコンの選び方</a></li>';
		}
	}
	if(support + soft >= 8){
		html += '<li>・不意のトラブルを避けるために<strong>ウイルスバスター</strong>をつけておこう、またメーカー保証には加入しておこう。<br>=><a href="virus.html">ウイルスバスターって必要?</a></li>';
	}
	if(space >= 4){
	   if(kind == 1 || kind ==3){
	     if(space == 5){
		   html += '<li>・本体（箱)とモニターが一つになった一体型のデスクトップパソコンが省スペースでおすすめ,マウス、キーボードもコードレス型がおすすめ。<br>=><a href="desktop.html">デスクトップパソコンの選び方</a>/<a href="wireless.html">ワイヤレスマウス・キーボードってどう？</a></li>';
		 }else{
		   html += '<li>・本体(箱)とモニターが一つになった一体型デスクトップパソコンもしくわスリム型のパソコンを選ぼう。マウス、キーボードもコードレス型がおすすめ</li>';
		 }
	   }
	}
	if(video == 1){	    
	  if(movie == 1){
		 html += '<li>・ブルーレイディスクに編集したビデオを保存したい場合は<strong>ブルーレイディスクドライブ</strong>を搭載させよう。もちろんブルーレイの映画の鑑賞も可能だ<br>=><a href="drive.html">DVD,BDの選び方</a></li>';
	  }else{
	     html += '<li>・ブルーレイディスクに編集したビデオを保存したい場合は<strong>ブルーレイディスクドライブ</strong>を搭載させよう<br>=><a href="drive.html">DVD,BDの選び方</a></li>';
	  }
	}else{
	  if(movie == 1){
	  	  html += '<li>・ブルーレイの映画を鑑賞したい場合は<strong>ブルーレイコンボドライブ</strong>を搭載しよう。コンボドライブはBDの書き込みはできないが読み込みは可能<br>=><a href="drive.html">DVD,BDの選び方</a></li>';
	  }
	}
	
	if(tv == 1){
		html += '<li>・よくテレビを録画する場合はハードディスクを2TBくらい積んでも良い。また地デジチューナーを忘れずに付けよう。<br>=><a href="tv.html">テレビパソコンってどう?</a></li>'
	}
	if(tv == 2){
		html += '<li>・パソコンでテレビを見れるように地デジチューナーを必ず付けよう。<br>=><a href="tv.html">テレビパソコンってどう?</a></li></li>';
	}
	if(boot == 1){
	    html += '<li>・ハードディスクの代わりに<strong>SSD</strong>が搭載されたパソコンだと起動が通常の半分以下になりおすすめ<br>=><a href="ssd.html">SSDって何？</a></li>';
	}
	if(extention == 1){
	  if(space >= 4){
		html += '<li>・デスクトップの大型パソコンを選べば、なにか足りないときに手軽に機能が追加できる。しかし省スペース化とは相反するので考える必要がある。<br>=><a href="desktop.html">デスクトップパソコンの選び方</a></li>';
	  }else{
	    html += '<li>・デスクトップの大型パソコンを選べば、なにか足りないときに手軽に機能が追加できる。<br>=><a href="desktop.html">デスクトップパソコンの選び方</a></li>';
	  }
	}
	if(work == 2){
		html += '<li>・レポート作成を行うならばWORD,EXCELは入れておいた方が良い<br>=><a href="office.html">オフィスを安く手に入れるには？</a></li>';
	}
	if(work == 1){
		html += '<li>・WORD,EXCEL,POWERPOINTを忘れずに入れておこう<br>=><a href="office.html">オフィスを安く手に入れるには？</a>/<a href="business.html">仕事用パソコンの選び方</a></li>';
	}
			
	html += '</ul>';
			
	$('question').style.display = "none";
	$('recommendResult').innerHTML = html;	
	$('result').value = "アンケートに戻る";
	$('result').onclick = returnQuestion;
}

function returnQuestion(){
    cookie.position = 'questionnaire';
    $('question').style.display = "";
	$('recommendResult').innerHTML = "";
    $('result').value = "結果を表示";
	$('result').onclick = setResult;
}



