
function findCombination()
{
	//create a temporary 'choice' array containing the choices of the customer
	var choice = new Array();
	var key;
	var attribute;
	var temp_html='';
	$('select[id^="group_"]').each(function() {
		choice[parseInt(this.name)]	= parseInt(this.value);
	});
	for (key in combination)   {
	   if(combination[key].sort().toString() == choice.sort().toString()){
			attribute	= key;
	   }
	}
	
	if(combination_onsale[attribute]){
		$("tr[id^='instock']").show();
		$("tr[id^='outofstock']").hide();
	}else{
		$("tr[id^='instock']").hide();
		$("tr[id^='outofstock']").show();
	}
	$("#product_attribute_id").attr('value',attribute);
}

function change_image(image_SKU){
	$("#pic_mid").attr('src',image_host+"product_images/"+image_SKU+"/0.jpg");
	$("a[class='thickbox']").attr('href',image_host+"product_images/"+image_SKU+"/0.jpg");
	$("img[id^='small_']").css({ "border": "1px solid #fff" });
	$("#small_"+image_SKU).css({ "border": "1px solid #c00" }); 
}

function change_tab(id){
	$("li[id^='tabtittle_']").removeClass("actives");
	$("li[id='tabtittle_"+id+"']").addClass("actives");
	$("div[id^='tabcontents_']").hide();
	$("div[id='tabcontents_"+id+"']").show();
}





function rate(obj,oEvent){ 
	var imgSrc = '/application/views/default/images/starblank.gif'; //blank-star
	var imgSrc_2 = '/application/views/default/images/starfull.gif'; //full-star
	//--------------------------------------------------------------------------- 
	var e = oEvent || window.event; 
	var target = e.target || e.srcElement; 
	var imgArray = obj.getElementsByTagName("img"); 
	for(var i=0;i<imgArray.length;i++){ 
	   imgArray[i]._num = i; 
	   imgArray[i].onclick=function(){ 
			obj.rateFlag=true; 
			$("#grade").attr('value',this._num+1);
		//	alert(this._num+1);       //this._num+1 Write to the database this figure as the basis of score
			if(target.tagName=="IMG"){ 
				for(var j=0;j<imgArray.length;j++){ 
					if(j<=target._num){ 
						imgArray[j].src=imgSrc_2; 
					} else { 
						imgArray[j].src=imgSrc; 
					} 
				} 
			} else { 
				for(var k=0;k<imgArray.length;k++){ 
					imgArray[k].src=imgSrc; 
				} 
			} 
	   }; 
	} 
	if(obj.rateFlag) return; 

	if(target.tagName=="IMG"){ 
		for(var j=0;j<imgArray.length;j++){ 
			if(j<=target._num){ 
			 imgArray[j].src=imgSrc_2; 
			} else { 
			 imgArray[j].src=imgSrc; 
			} 
		} 
	} else { 
		for(var k=0;k<imgArray.length;k++){ 
			imgArray[k].src=imgSrc; 
		} 
	} 
} 



$().ready(function() {

	$('#top_write_review').click(function(){
		$("li[id^='tabtittle_']").removeClass("actives");
		$("li[id='tabtittle_3']").addClass("actives");
		$("div[id^='tabcontents_']").hide();
		$("div[id='tabcontents_3']").show();
		$('html,body').animate({
			scrollTop:500
		},1000);
		$("#write_review").show();
		return false;
	});
	$('#top_read_review').click(function(){
		$("li[id^='tabtittle_']").removeClass("actives");
		$("li[id='tabtittle_3']").addClass("actives");
		$("div[id^='tabcontents_']").hide();
		$("div[id='tabcontents_3']").show();
		$('html,body').animate({
			scrollTop:500
		},1000);
		$("#write_review").hide();
		return false;
	});
	$('#bottom_write_review').click(function(){
		$("#write_review").show();
		return false;
	});
	$('#bottom_read_review').click(function(){
		$("#write_review").hide();
		return false;
	});

	$('#form_submit').click(function(){
		$("#product_form").submit();	
		return false;
	});
	$('#review_submit').click(function(){
		$("#review_form").submit();	
		return false;
	});

});

