function showContent(id){
	for(i=0;i<=2;i++){
		$("#show-content-"+i).css('display','none');
	}			
	var offset = $("#support"+id).offset();
	$("#show-content-"+id).css({'display':'block','position':'absolute','left':offset.left+10,'top':offset.top+35});
}
function hideContent(id){
	$("#show-content-"+id).css('display','none');
}
showtime = 0;
function changtab(id,count,clear){
	for(i=1;i<=count;i++){
		document.getElementById('menu_'+i).className='menu-normal';
	}
	document.getElementById('menu_'+id).className='menu-active';
	if(clear==1) clearInterval(showtime);
}
function mouseout(id,count){
	showtime = setInterval(function() {changtab(id,count,1)},3000);
}
function trim(sString){
	while(sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while(sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
return sString;
}
function checkblank(str){
	if(trim(str) == '') return true;
	else return false;
}
function checknewsletter(){
	if(document.getElementById("let_email").value == ''){
		alert("Bạn chưa nhập Email");
		document.getElementById("let_email").focus();
		return false;
	}
	if(!isEmail(document.getElementById("let_email").value)){
		alert("Email không đúng định dạng");
		document.getElementById("let_email").focus();
		return false;
	}
	document.newletter.submit();
}
function isEmail(str) {
	var email=/^[A-Za-z0-9][\w-.]+@[A-Za-z0-9]([\w-.]+[A-Za-z0-9]\.)+([A-Za-z]){2,4}$/i;
	return(email.test(str));
}
function checkcompare(){
	if(document.getElementById("iComCat").value==0){
		alert("Bạn chưa chọn loại sản phẩm");
		$("#iComCat").focus();
		return false;	
	}	
	if(document.getElementById("product_one").value==0){
		alert("Bạn chưa chọn sản phẩm thứ nhất");
		$("#product_one").focus();
		return false;	
	}
	if(document.getElementById("product_two").value==0){
		alert("Bạn chưa chọn sản phẩm thứ hai");
		$("#product_two").focus();
		return false;	
	}
	document.compare.submit();
}
function showSupplier(id,divid,cat_id){
	var iCat = $('#'+cat_id).val();
	$.get("/vn/show_compare.php", {type:'sup',id:id,iCat:iCat},
	function(data){
	  $("#"+divid).html(data);
	});	
}
function showCategory(cat_id,o_divid,t_divid){
	$.get("/vn/show_compare.php", {type:'cat',iCat:cat_id},
	function(data){
		$("#"+o_divid).html(data);
		$("#"+t_divid).html(data);
	});	
}
function setCookie( name, value, expires, path, domain, secure ){
	deleteCookie('cookie_page', '/', '');
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );
}
function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var i = '';
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}
function deleteCookie( name, path, domain) {
	if ( getCookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
