function in_array(string, array){
   for (var i = 0; i < array.length; i++){
	  if(array[i] == string){
		 return true;
	  }
   }
	return false;
}

function jqueryHash(){
	var hash = window.location.hash;
	hash  = hash.replace('#','');
	if( hash == '' ){
		return 1;
	}else{
		return hash;
	}
}
jQuery.inputHighlight = function(color){  
    $("input[type='text'],input[type='file'],input[type='password'],textarea").each(function(){  
        $(this).focus(function(){  
            $(this).css({"background" : color});  
        });
        $(this).blur(function(){  
            $(this).css({"background" : "white"});  
        }); 
    });  
}


function ShowForexRate(){
	var sHtml = '';
	sHtml = sHtml.concat('<table width="100%" border="0" cellspacing="0" cellpadding="3" class="forex">');
	vForexs.length = vForexs.length-1;
	for(var i=0;i<vForexs.length;i++){
		sHtml = sHtml.concat('<tr>');
		sHtml = sHtml.concat('<td class="code" width="50%">').concat(vForexs[i]).concat('</td>');
		sHtml = sHtml.concat('<td>').concat(vCosts[i]).concat('</td>');
		sHtml = sHtml.concat('</tr>');
	}
	sHtml = sHtml.concat('</table>');
	$('#ShowForexRate').html(sHtml);
}


$(document).ready(function(){	
	$('#header_search_submit').click(function(){
		if( Trim($('#keywords').val()) == '' ){
			alert('Xin hãy nhập từ khóa tìm kiếm');
			$('#keywords').focus();
		}else{
			if( Trim($('#keywords').val()).length <3 ){
				alert('Từ khóa tối thiểu phải 3 ký tự');
				$('#keywords').focus();
			}else{
				window.location.href = server+'product/search/'+$('#keywords').val();	
			}
		}
	});
	
	$('.navbar li.cat').mouseover(function(){
		$(this).addClass('hover');
	}).mouseleave(function(){
		$(this).removeClass('hover');
	});
	
	$('#sucuritiy_code_refresh, #sucuritiy_code_img').click(function(){
		$('#sucuritiy_code_img').attr('src', $('#sucuritiy_code_img').attr('src')+'?'+Math.random() )
	});
	
	
	$('.productPicView .other_image a').click(function(){
		var pic = $(this).attr('href');
		var picview = $(this).attr('rel');
		$.post(server+"product_view.php", {
			pic:pic,
			picview:picview
		},
		function(data){
			$('#productPicView').html(data);
			$('#productPicView a').colorbox({
				overlayClose:true								
			});
		});
		return false;												   
	});
	
});

