/***************************************************
	Dev: Mr.Xicooc
	jbtq82002@yahoo.com
****************************************************/
var ad_path  = "http://www.bwlaws.com/getAd.php";
var img_path = "http://www.bwlaws.com/adv/image/";
var fla_path = "http://www.bwlaws.com/adv/flash/";
var global_path = "http://www.bwlaws.com/";


/* Rotate Image */
function ranBg()
{
	/*
	var rN = Math.floor(Math.random()*5);
	document.write('<img name="rImage" width="960" src="'+global_path+'images/bg/bg_'+rN+'.jpg" />');
	*/
	new fadeshow(fadeimages, 960, 235, 0, 7000, 1, "R")
}

function closeBox(id){$('#'+id).hide(); return false;}
function showBox(id){$('#'+id).show(); return false;}

/* Change Language */
function changeLanguage(lan)
{
	var cur = location.href.toString();
	if(cur.indexOf("/en") != -1)
	{
		if(lan=="vn"){
			location.href = cur.replace("/en", "/vn");
		} else if(lan=="jp"){
			location.href = cur.replace("/en", "/jp");
		}
		return false;
	}
	else if(cur.indexOf("/jp") != -1)
	{
		if(lan=="vn"){
			location.href = cur.replace("/jp", "/vn");
		} else if(lan=="en"){
			location.href = cur.replace("/jp", "/en");
		}
		return false;
	}
	else if(cur.indexOf("/vn") != -1)
	{
		if(lan=="en"){
			location.href = cur.replace("/vn", "/en");
		} else if(lan=="jp"){
			location.href = cur.replace("/vn", "/jp");
		}
		return false;
	}
}

/* Check Email */
function checkEmail(input, errId, message)
{
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(input.value)) {
		$("#"+errId).html(message);
		return false;
	}
}

function AddBookmark()
{
	var title = document.title;
	var url = window.location.href.toString();
	if (window.sidebar) {window.sidebar.addPanel(title, url,"")}
	else if( window.external ) {window.external.AddFavorite( url, title)}
	else if(window.opera && window.print) {return true}
}

function CreateBookmarkLink()
{
	if (window.external){document.write('<a href="javascript:AddBookmark();">Add to Favorites</a>')}
	else if (window.sidebar){document.write('<a href="javascript:AddBookmark();">Bookmark Page</a>')}
	else if (window.opera && window.print){document.write('<a href="javascript:AddBookmark();">Add Bookmark</a>')}
}
function searchNews(link)
{
	var k = $.trim($("#nKeyword").val());
	if(k!="")
	{
		location.href = link+'?m=s&df=&dt=&k=' + k;
		return true;
	}
	$("#nKeyword").focus();
	return false;
}
function keyCatch(e, link)
{
	if(window.event && window.event.keyCode == "13") { searchNews(link); }
	else if(e.which) { if(e.which == 13) { searchNews(link); } }
}

function popImage(imageURL,imageTitle)
{
	PositionX = 0;
	PositionY = 0;
	defaultWidth  = 500;
	defaultHeight = 500;
	var AutoClose = true;

	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document)
	{
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
		writeln('width=300-(document.body.clientWidth-document.images[0].width);');
		writeln('height=300-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["MiQu"].width;');writeln('window.innerHeight=document.images["MiQu"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		if (!AutoClose) {writeln('</head><body bgcolor="#000" scroll="no" onload="reSizeToImage();doTitle();self.focus()">');}
		else {writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');}
		writeln('<img name="MiQu" src='+imageURL+' style="display:block"></body></html>');
		close();		
	}
}

function goTop()
{
	window.scrollTo(0,0)
}

function findPos(obj)
{
	var curleft=curtop=0;
	if(obj.offsetParent)
	{
		curleft=obj.offsetLeft;
		curtop=obj.offsetTop;
		while(obj=obj.offsetParent)
		{
			curleft+=obj.offsetLeft;
			curtop+=obj.offsetTop;
		}
	}
	return[curleft,curtop];
}
function getPosition(e)
{
	e=e||window.event;var cursor={x:0,y:0};if(e.pageX||e.pageY){cursor.x=e.pageX;cursor.y=e.pageY;}
	else{var de=document.documentElement;var b=document.body;cursor.x=e.clientX+
	(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0);cursor.y=e.clientY+
	(de.scrollTop||b.scrollTop)-(de.clientTop||0);}
	return cursor;
}

function HTMLEncode(wText){if(typeof(wText)!="string"){wText=wText.toString();};wText=wText.replace(/&/g,"&amp;");wText=wText.replace(/>/g,"&gt;");wText=wText.replace(/</g,"&lt;");wText=wText.replace(/'/g,"&39;");wText=wText.replace(/"/g,"&quot;");return wText;}

/****************************************
******* Advert Functions ****************
*****************************************/
function getBigAd(code, className, jObj)
{
	$.getJSON(ad_path + "?code=" + code,
        function(data)
        {
          	$.each(data.items, function(i,item){
	            if(item.type == "0")
				{
					$(jObj).append("<div class='"+className+"'><img src='"+img_path + item.media.m+"' width='"+item.width+"' height='"+item.height+"' border='0' style='cursor:pointer' onclick='"+item.link+"' /></div>");
				}
				else if(item.type == "1")
				{
					fObj = fla_path + item.media.m;
					$(jObj).append('<div class="'+className+'"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+item.width+'" height="'+item.height+'"><param name="movie" value="'+fObj+'" /><param name="quality" value="high" /><param name="wmode" value="transparent"><embed src="'+fObj+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+item.width+'" height="'+item.height+'" wmode="transparent"></embed></object></div>');
				}
        });
    });
}					
/*****************************************/
/******* Original functions **************/
/*****************************************/

function select_list(the_value, 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 radio_list(the_value,the_list)
{
	var name_count = the_list.length;	
	for (i=0; i<name_count; i++){
		if (the_value == the_list[i].value){
			the_list[i].checked	= true;
			break;
		}
	}
}

function checkbox(the_value,the_list)
{
	if (the_value == the_list.value){
		the_list.checked = true;
	}
}

function select_switch(form, status) {
	for (i = 0; i < form.length; i++) {
		form.elements[i].checked = status;
	}
}

function checkCheckboxes(the_form, the_box){
   var elts      = (typeof(document.forms[the_form].elements[the_box]) != 'undefined') ? document.forms[the_form].elements[the_box] : document.forms[the_form].elements[the_box];
   var elts_cnt  = (typeof(elts.length) != 'undefined') ? elts.length : 0;
	err=false;	
	if (elts_cnt) {
		for (var i = 0; i < elts_cnt; i++){
			if(elts[i].checked == true){
				err=true;
				break;
			}
		} 		
	}
	else if(document.forms[the_form].elements[the_box].checked==true){
		err=true;		
	}		
	return err;
}
/* Open normal popup */
function showme(the_url, the_width, the_height, the_menu)
{
	if ( the_width == 0 ){ the_width	= screen.width; }
	if ( the_height == 0 ){	the_height	= screen.height; }

	left_val	= (the_width > 0) ? (screen.width - the_width)/2 : 0;
	top_val		= (the_height > 0) ? (screen.height - the_height)/2 - 30 : 0;
	if (top_val < 0){ top_val	= 0; }
	if (the_menu == ""){ the_menu	= "no";	}
	window.open(the_url, "", "menubar="+ the_menu +", toolbar="+ the_menu +", scrollbars=yes, resizable=yes, width="+ the_width +", height="+ the_height +", top="+ top_val +", left="+ left_val);
}