var votestep = 1;

$(document).ready(function(){
	 $('#vote1div').html("<br><br><br><br><br><br><br><br><br><br><br><br><br><center><img src='/images/loading.gif' ></center>");
	 $.ajax({
		url : 'index.php?controller=Default&action=Voteajax&proclassid=1',
		type : 'POST',
		dataType : 'html',
		success: function(html){
			var Template = html;
			$('#vote1div').html(html);
		}
	});
});

//選中
function changeoption(proid,proclassid,itemid,pid,imgmax,flag){
	var maxpro = document.getElementById("item" + proclassid + "_" + itemid).value;

	for(var i=0; i<maxpro; i++){
		if(flag==1){
			if(pid==i){
				document.getElementById("images" + proclassid + "_" + itemid + "_" + pid).src ='images/cancel_a2.gif';
				document.getElementById("xuan" + proclassid + "_" + itemid).value = proid;
			}else{
				document.getElementById("images" + proclassid + "_" + itemid + "_" + i).src ='images/select_a.gif';
			}
		}else{
			if(pid==i){
				document.getElementById("images" + proclassid + "_" + itemid + "_" + pid).src ='images/selected.gif';
				document.getElementById("xuan" + proclassid + "_" + itemid).value = proid;
			}else{
				document.getElementById("images" + proclassid + "_" + itemid + "_" + i).src ='images/selected_out.gif';
			}		
		}
	}
}

//判斷是否完成該頁投票
function checkvote(proclassid){
	var maxitem = document.getElementById("item"+proclassid+"num").value;
	
	for(var i=0; i<maxitem; i++){
		if(document.getElementById("xuan" + proclassid + "_" + i).value==0){
			alert("請完成所有項目的投票！");
			window.location="#pt" + proclassid + "_" + i;
			return false;
		}		
	}

	if(proclassid==3){
		//alert("你已經完成所有項目的投票！");	
		//統計產品id
		var allpro = "";
		for(var i=1; i<4; i++){
			var maxitem = document.getElementById("item"+i+"num").value;
			for(var j=0; j<maxitem; j++){
				if(allpro==''){
					allpro = document.getElementById("xuan"+i+"_"+j).value;
				}else{
					allpro = allpro + "," + document.getElementById("xuan"+i+"_"+j).value;				
				}
			}
		}
	
		document.form1.allpro.value = allpro;
		document.form1.submit();
	}else{
	 	 $('#vote' + (proclassid) + 'div').hide();

		 if((proclassid+1)>votestep){
			 $('#vote' + (proclassid+1) + 'div').html("<br><br><br><br><br><br><br><br><br><br><br><br><br><center><img src='/images/loading.gif' ></center>");
			 $.ajax({
				url : 'index.php?controller=Default&action=Voteajax&proclassid=' + (proclassid+1),
				type : 'POST',
				dataType : 'html',
				success: function(html){
					var Template = html;
					$('#vote' + (proclassid+1) + 'div').html(html);
					$('#vote' + (proclassid+1) + 'div').show();
					votestep = proclassid+1;

						//omt start
						var s=s_gi('hkmhkmos-dev');
						if((proclassid+1)==2){
						s.pageName="more :美容大賞8th :參加投票_投票P2";
						s.channel="美容大賞8th";
						s.events="event5";
						}

						if((proclassid+1)==3){
						s.pageName="more :美容大賞8th :參加投票_投票P3";
						s.channel="美容大賞8th";
						s.events="event6";
						}

					  	void(s.t());
						//omt end
				}
			 });
		 }else{
			$('#vote' + (proclassid+1) + 'div').show();
		 }

	 	document.documentElement.scrollTop = 0;
	}

}

//上一步
function prevote(proclassid){
	 $('#vote' + (proclassid) + 'div').hide();
	 $('#vote' + (proclassid-1) + 'div').show();
	 document.documentElement.scrollTop = 0;
}


//無圖mouseout
function nophotoout(proid,proclassid,itemid,pid){
	if(document.getElementById("xuan" + proclassid + "_" + itemid).value!=proid){
		document.getElementById("images" + proclassid + "_" + itemid + "_" + pid).src ='images/selected_out.gif';
	}
}

//黑屏效果
function openscreen(photo){
	var div = document.getElementById("m_area");
	var temp = '';
	temp=temp + '<div align="left" style="width:700px; color:#333; height:460px;background:#fff; margin:auto; font-size:12px;">';
	temp=temp + '<img src="' + photo + '" style="width:690px;height:415px;border:solid 5px #FFFFFF;">';
	temp=temp + '<div style="text-align:center"><a href="javascript:parent.fb.end(true);"><img src="images/close1.jpg" onmouseover=this.src="images/close.jpg" onmouseout=this.src="images/close1.jpg"></a></div>';
	temp=temp + '</div>';
	div.innerHTML = temp;
	fb.anchors.length = 0;
	fb.loadAnchor("#m_area","width:700 height:460 scrolling:yes sameBox:false", "");
}
