function getbyid(id_name) {
	if (document.getElementById)
	{
		return document.getElementById(id_name);
	}
	else if (document.all)
	{
		return document.all[id_name];
	}
	else if (document.layers)
	{
		return document.layers[id_name];
	}
	else
	{
		return null;
	}
}

function openAWindow( pageToLoad, winName, width, height, center, scroll) {
	xposition=0;
	yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
  	xposition = (screen.width - width) / 2;
  	yposition = (screen.height - height) / 2;
  }

  args = "width=" + width + "," + "height=" + height + "," + "location=0," + "scrollbars=" + scroll + "," + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;

  window.open( pageToLoad, winName, args );
}

function showCateSelect(select_id,select_value,lang) {
	if(lang == 'en') {
		lang_id = 1;
	}
	else {
		lang_id = 0;
	}
	
	var the_list = document.getElementById(select_id);
	
	the_list.options.length = 0;
	the_list.options[0] = new Option('--- Chọn danh mục','0');
	
	for(k in js_cate) {
		var idx = the_list.options.length;
		the_list.options[idx] = new Option(js_cate[k][lang_id],k);
		
		if(select_value == k)
			the_list.options[idx].selected = true;
	}
		 
}

function select_list( the_list, the_value ) {
 var the_list = getbyid(the_list);
 var option_count = the_list.options.length;

 for ( i = 0; i < option_count; i++ )
 {
  if ( the_value == the_list.options[i].value )
  {
   the_list.options[i].selected = true;
   break;
  }
 }
}

function dr(text) {
	document.write(text);
}

function showLeftCate(lang) {
	if(lang == 'en') {
		lang_id = 1;
	}
	else {
		lang_id = 0;
	}
	 
	var html = '';
	
	html += '<table width="227" border="0" cellpadding="0" cellspacing="0" bgcolor="#8FCA49">';
	              
	for(k in js_cate) {  
		html += '<tr><td height="32" background="images/left.jpg" style="background-repeat:no-repeat" class="txt_left"><a href="product.php?cid=' + k + '" class="txt_left">' + js_cate[k][lang_id] + '</a></td></tr>';  
	}
	
	html += '</table>';
	
	return html;
	
}

function showroom_photo(img_src,img_w,img_h) {
	openAWindow('showroom_photo.php?img=' + img_src,'_blank',img_w,img_h,1,0);
}

function is_valid_email(email) {

 return /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(email);
}

function showCateHdr(cid,lang) {
	if(lang == 'en') {
		lang_id = 1;
	}
	else {
		lang_id = 0;
	}	
	
	return '<div class=cate_hdr>' + js_cate[cid][lang_id] + '</div>';
}

showroom_i = 0;

function run_showroom() {
	if(showroom_i > showroom_img.length - 1)
		showroom_i = 0;	
	
	getbyid('showroom_ctn').innerHTML = '<a href="javascript:;" onclick="showroom_photo(\'' + showroom_img[showroom_i][1] + '\',\'' + showroom_img[showroom_i][2] + '\',\'' + showroom_img[showroom_i][3] + '\')"><img src="create_image.php?dir=showroom&thumb_size=130&file_name=' + showroom_img[showroom_i][1] + '" border=0></a>';
	showroom_i++;
}