cate_typeid = new Array();
cate_typeid[1] = 'KIẾN THỨC';
cate_typeid[2] = 'DỊCH VỤ';

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 is_valid_email(email) {

 return /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(email);
}

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) {
 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][0],k);
		
		if(select_value == k)
			the_list.options[idx].selected = true;
				
		var catfather = new Object();
		
		eval('catfather = js_catfather' + k + ';');		
  
  	var ic = 0;

		for(l in catfather) {
		 	the_list.options[the_list.options.length] = new Option(' » ' + catfather[l][0], l);
		 	if(select_value == l)
		 		the_list.options[the_list.options.length-1].selected = true;
		 		 
		 	ic++;
		}

	  if(ic > 0) {
	   	the_list.options[idx].style.color = '#ff0000';
	  }
	}
		 
}

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() {
 
 var html = '';

 html += '<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableall">';
 html += ' <tr><td>';
 html += '  <table width="100%" border="0" cellpadding="0" cellspacing="0">';
                
 for(k in js_cate) {
  html += '  <tr><td width="23"><img src="images/ic_leftmenu.gif" width="23" height="18" /></td>';
  html += '  <td bgcolor="#0562A7" class="menutop">' + js_cate[k][0] + ' </td></tr>';
     
	var catfather = new Object();
		
	eval('catfather = js_catfather' + k + ';');		
		
	for(l in catfather) {
		 
		html += ' <tr><td height="1" colspan="2"></td></tr>';
		html += ' <tr><td><img src="images/ic_submenuleft.gif" width="23" height="18" /></td>';
		html += ' <td bgcolor="#D7E8F8" class="submenuleft"><a href="tour.php?cate=' + k + '&subid=' + l + '">' + catfather[l][0] + '</a> </td></tr>';
  }
 }

 html += '   </table>';
 html += '  </td></tr>';
 html += '</table>';
 
 return html;
 
}

function showCateText(typeid,cateid,subcate,lnk) {
	eval('cate_text = js_cate' + typeid + '[' + cateid + '][0];');
	if(lnk)
		cate_text = '<a href="index.php?typeid=' + typeid + '&cid=' + cateid + '">' + cate_text + '</a>';		
	subcate_text = '';
	//alert(cate_text);
	//return;
	if(subcate) {
		eval('js_data = js_catfather' + cateid + ';');		
		if(lnk)
			subcate_text = ' / ' + '<a href="index.php?typeid=' + typeid + '&cid=' + cateid + '&subid=' + subcate + '">' + js_data[subcate][0] + '</a>';
		else
			subcate_text = ' / ' + js_data[subcate][0];		
	}
	
	document.write(cate_text + subcate_text);
}

function showArticleNav(typeid,cateid,subcate,lnk) {
	catetype_text = cate_typeid[typeid];
	if(lnk)
		catetype_text = '<a href="index.php?typeid=' + typeid + '">' + cate_typeid[typeid] + '</a>';
		
	eval('cate_text = js_cate' + typeid + '[' + cateid + '][0];');
	if(lnk)
		cate_text = '<a href="index.php?typeid=' + typeid + '&cid=' + cateid + '">' + cate_text + '</a>';		
	subcate_text = '';
	//alert(cate_text);
	//return;
	if(subcate) {
		eval('js_data = js_catfather' + cateid + ';');		
		if(lnk)
			subcate_text = ' / ' + '<a href="index.php?typeid=' + typeid + '&cid=' + cateid + '&subid=' + subcate + '">' + js_data[subcate][0] + '</a>';
		else
			subcate_text = ' / ' + js_data[subcate][0];		
	}
	
	document.write(catetype_text + ' / ' + cate_text + subcate_text);
}

function showCatetypeSearch(select_id,typeid,cateid,subcate) {
	frm = document.forms['frmAdvSearch'];
			
 var the_list = document.getElementById(select_id);
 
	the_list.options.length = 0;
	the_list.options[0] = new Option('Tất cả danh mục','0');

	if(typeid == 0)
		return;

		
	var js_cate = new Object();
	eval('js_cate = js_cate' + typeid + ';');
	
	for(k in js_cate) {
  	var idx = the_list.options.length;
		the_list.options[idx] = new Option(js_cate[k][0],k + '/0');
		
		if(cateid == k)
			the_list.options[idx].selected = true;
				
		var catfather = new Object();
		
		eval('catfather = js_catfather' + k + ';');		

		for(l in catfather) {
		 	the_list.options[the_list.options.length] = new Option(' » ' + catfather[l][0], k + '/' + l);		 
		 
			if(subcate == l)
				the_list.options[the_list.options.length-1].selected = true;

		}

	}
		 	
}