﻿/*======================================================================*\
|| #################################################################### ||
|| # AT Movie 1.0                                                     # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2008-2009 AnhTrang.Org . All Rights Reserved.         # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ----------- AT MOVIE IS FREE SOFTWARE - OPEN SOURCE ------------ # ||
|| # http://www.anhtrang.org | http://www.anhtrang.org/support.html   # ||
|| #################################################################### ||
\*======================================================================*/

var http = createRequestObject();
var field = '';
		   var loadingText = "<center><img src='"+site+"/images/loading.gif'><br><b>Đang tải dữ liệu ...</b></center>";
		   var loadingfilm = '<center><embed id="ld" wmode="transparent" name="ld" src="http://anhtrang.org/phim/images/loading.swf" width="200" height="180" allowfullscreen="true" allowscriptaccess="always" /></center>';
function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}

function handleResponse() {
	try {
		if((http.readyState == 4)&&(http.status == 200)){
			response = http.responseText;
			field.innerHTML = response;
			//field.scrollIntoView();
			if(!response) window.location.href = url;
		}
  	}
	catch(e){}
	finally{}
}

function str_replace(search, replace, str){
	var ra = replace instanceof Array, sa = str instanceof Array, l = (search = [].concat(search)).length, replace = [].concat(replace), i = (str = [].concat(str)).length;
	while(j = 0, i--)
		while(str[i] = str[i].split(search[j]).join(ra ? replace[j] || "" : replace[0]), ++j < l);
	return sa ? str : str[0];
}
function do_search() {
	tab = document.getElementById("t").value;
	kw = document.getElementById("keyword").value;
	kw = str_replace(' ', '-', kw);
	kw = str_replace('%20', '-', kw);
	if (!kw) alert('Bạn chưa nhập từ khóa');
	else {
		kw = encodeURIComponent(kw);
		window.location.href = site+'/?act=search/'+kw+'/'+tab;	
	}
  return false;
}
function addText(elname, wrap1, wrap2) {
	if (document.selection) { // for IE 
		var str = document.selection.createRange().text;
		document.forms['add'].elements[elname].focus();
		var sel = document.selection.createRange();
		sel.text = wrap1 + str + wrap2;
		return;
	} else if ((typeof document.forms['add'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var txtarea = document.forms['add'].elements[elname];
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var oldScrollTop = txtarea.scrollTop;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
		txtarea.selectionStart = s1.length;
		txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		txtarea.scrollTop = oldScrollTop;
		txtarea.focus();
		return;
	} else {
		insertText(elname, wrap1 + wrap2);
	}
}
var submitcount=0;
   function checkSubmit() {

      if (submitcount == 0)
      {
      submitcount++;
      document.Surv.submit();
      }
   }
function wordCounter(field, countfield, maxlimit) {
wordcounter=0;
for (x=0;x<field.value.length;x++) {
      if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}
      if (wordcounter > 250) {field.value = field.value.substring(0, x);}
      else {countfield.value = maxlimit - wordcounter;}
      }
   }
function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
      {field.value = field.value.substring(0, maxlimit);}
      else
      {countfield.value = maxlimit - field.value.length;}
  }
function showComment(num,film_id,page) {
	field = document.getElementById("comment_field");
	field.innerHTML = loadingText;
	http.open('POST',  site+'/index.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = handleResponse;
    http.send('showcomment=1&num='+num+'&film_id='+film_id+'&page='+page); 
  return false; 
}
function comment_check_values() {
	film_id = encodeURIComponent(document.getElementById("film_id").value);
	num = encodeURIComponent(document.getElementById("num").value);
	comment_poster = encodeURIComponent(document.getElementById("comment_poster").value);
	comment_content = encodeURIComponent(document.getElementById("comment_content").value);
	try {
	    document.getElementById("comment_loading").innerHTML = loadingText;
		document.getElementById("comment_loading").style.display = "block";
		http.open('POST',  site+'/index.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		http.onreadystatechange = function() {
											try {
												if((http.readyState == 4)&&(http.status == 200)){
													var response = http.responseText;
													if (response == 'OK') {
														film_id = encodeURIComponent(document.getElementById("film_id").value);
														num = encodeURIComponent(document.getElementById("num").value);
														showComment(num,film_id,1);
													}
													else document.getElementById("comment_loading").innerHTML = response;

												}
											}
											catch(e){}
											finally{}
										};
		http.send('comment=1&film_id='+film_id+'&num='+num+'&comment_poster='+comment_poster+'&comment_content='+comment_content);
		document.getElementById("submit").disabled=true;document.getElementById("submit").value="Wait...";
	}
	catch(e){}
	finally{}
  return false;
}
function showNews(num,news_id,page) { 
	field = document.getElementById("news_field");
	field.innerHTML = loadingText;
	http.open('POST',  site+'/index.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = handleResponse;
    http.send('shownews=1&num='+num+'&news_id='+news_id+'&page='+page); 
  return false; 
} 
function showRequest(num,page) {
	field = document.getElementById("request_field");
	field.innerHTML = loadingText;
	http.open('POST',  site+'/index.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = handleResponse;
    http.send('showrequest=1&num='+num+'&page='+page); 
  return false; 
}
function request_check_values() {
	num = encodeURIComponent(document.getElementById("num").value);
	request_name = encodeURIComponent(document.getElementById("request_name").value);
	request_email = encodeURIComponent(document.getElementById("request_email").value);
	try{
			document.getElementById("request_loading").innerHTML = loadingText;
			document.getElementById("request_loading").style.display = "block";
			http.open('POST',  site+'/index.php');
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
			http.onreadystatechange = function() {
											try {
												if((http.readyState == 4)&&(http.status == 200)){
													var response = http.responseText;
													if (response == 'OK') {
														num = encodeURIComponent(document.getElementById("num").value);
														showRequest(num,1);
													}
													else document.getElementById("request_loading").innerHTML = response;
													
												}
											}
											catch(e){}
											finally{}
										};
			http.send('request=1&num='+num+'&request_name='+request_name+'&request_email='+request_email);
			//document.getElementById("send").disabled=true;document.getElementById("send").value="Wait...";
		}
	  catch(e){}
	  finally{}
	return false;
}
function showBroken(film_id,episode_id) {
	try {
		document.getElementById("broken_field").innerHTML = loadingText;
		document.getElementById('broken_field').style.display='block';
		http.open('POST', site+'/index.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = function() {
			if((http.readyState == 4)&&(http.status == 200)){
				document.getElementById("broken_field").innerHTML = http.responseText;
			}
		}
		http.send('broken=1&film_id='+film_id+'&episode_id='+episode_id);
	}
	catch(e){}
	finally{}
	return false;
}
function showFilm(num,page,number,apr,cat_id) { 
    field = document.getElementById('list_type_'+num);
	field.innerHTML = loadingText;
	http.open('POST', site+'/index.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = handleResponse;
    http.send('showfilm=1&num='+num+'&page='+page+'&number='+number+'&apr='+apr+'&cat_id='+cat_id); 
  return false; 
}
function showTrailer(num,apr,page) { 
    field = document.getElementById("trailer_loading");
	field.innerHTML = loadingText;
	http.open('POST', site+'/index.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = handleResponse;
    http.send('showtrailer=1&num='+num+'&apr='+apr+'&page='+page); 
  return false; 
}
function rating(like,dislike,movie_id) {
	field = document.getElementById("rating_field");
	field.innerHTML = loadingText;
	http.open('POST',  site+'/index.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = handleResponse;
    http.send('rating=1&like='+like+'&movie_id='+movie_id+'&dislike='+dislike); 
  return false; 
}
function player(episode_id) {
	try {
		field = document.getElementById("player_field");
		field.scrollIntoView();
		field.innerHTML = loadingfilm;
		http.open('POST', site+'/index.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = handleResponse;
		http.send('watch=1&episode_id='+episode_id);
	}
	catch(e){}
	finally{}
	return false;
}
function showTv(tvid) {
	try {
		tg = document.getElementById('frmtivi').tvmonth.value+'/'+document.getElementById('frmtivi').tvday.value+'/'+document.getElementById('frmtivi').tvyear.value;
		field = document.getElementById("tivifield");
		field.innerHTML = loadingText;
		http.open('POST', site+'/index.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = handleResponse;
		http.send('showtivi=1&lpid='+tvid+'&Date='+tg);
	}
	catch(e){}
	finally{}
	return false;
}
function chanel(ch,w,h) {
	try {
	var link = '';
		field = document.getElementById("chanelfield");
		field.innerHTML = loadingText;
		switch(ch) {
		case 'vtv1': link = 'http://vtc.com.vn/playstream.swf?id=15&tp=l';
		break;
		case 'vtv2':	link = 'http://vtc.com.vn/playstream.swf?id=23&tp=l';
		break;
		case 'vtv3':	link = 'http://vtc.com.vn/playstream.swf?id=3&tp=l';
		break;
		case 'vtv4':	link = 'http://vtc.com.vn/playstream.swf?id=2&tp=l';
		break;
		case 'hanoi': link = 'http://vtc.com.vn/playstream.swf?id=5&tp=l';
		break;
		case 'htv7':	link = 'http://vtc.com.vn/playstream.swf?id=24&tp=l';
		break;
		case 'htv9': link = 'http://vtc.com.vn/playstream.swf?id=4&tp=l';
		break;
		case 'vtc1': link = 'http://vtc.com.vn/playstream.swf?id=10&tp=l';
		break;
		case 'vtc2': link = 'http://vtc.com.vn/playstream.swf?id=11&tp=l';
		break;
		case 'vtc8': link = 'http://vtc.com.vn/playstream.swf?id=20&tp=l';
		break;
		case 'vtc9': link = 'http://vtc.com.vn/playstream.swf?id=21&tp=l';
		break;
		case 'vtc10': link = 'http://vtc.com.vn/playstream.swf?id=22&tp=l';
		break;
		case 'vov1': link = 'http://vtc.com.vn/playstream.swf?id=29&tp=l';
		break;
		case 'vov2': link = 'http://vtc.com.vn/playstream.swf?id=28&tp=l';
		break;
		case 'vov3': link = 'http://vtc.com.vn/playstream.swf?id=27&tp=l';
		break;
		case 'vov5': link = 'http://vtc.com.vn/playstream.swf?id=25&tp=l';
		break;
		default: link = 'http://vtc.com.vn/playstream.swf?id=3&tp=l';
		}
		var width = "480";
		var height = "378";
		player = '<div class="box-top">Truyền Hình Trực Tuyến</div><div class="box-content">';
		player += '<iframe ALLOWTRANSPARENCY="true" src="'+link+'" width="'+width+'" height="'+height+'" frameborder="0" scrolling="no"></iframe>';
		player += '<br><a href="javascript:void(0,0);" onclick=\'document.getElementById("chanelfield").innerHTML=""\'>Không xem nữa. Tắt Tivi đi nào!</a>';
		player += '<br><a href="javascript:void(0,0);" onclick=\'chanel("vtv1","","");\'>VTV1</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vtv2","","");\'>VTV2</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vtv3","","");\'>VTV3</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vtv4","","");\'>VTV4</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("hanoi","","");\'>Hà Nội</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("htv7","","");\'>HTV7</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("htv9","","");\'>HTV9</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vtc1","","");\'>VTC1</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vtc2","","");\'>VTC2</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vtc8","","");\'>VTC8</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vtc9","","");\'>VTC9</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vtc10","","");\'>VTC10</a><br>';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vov1","","");\'>VOV1</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vov2","","");\'>VOV3</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vov3","","");\'>VOV4</a> | ';
		player += '<a href="javascript:void(0,0);" onclick=\'chanel("vov5","","");\'>VOV5</a> | ';	
		player += '<a href="javascript:void(0,0);" onclick=\'document.getElementById("chanelfield").innerHTML=""\'>Thoát</a></div><div class="box-bottom"></div>';
		field.innerHTML = player;
	}
	catch(e){}
	finally{}
	return false;
}
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

function applyType(obj, value) {
    var arrType = document.getElementsByName('searchType');
    for (var i = 0; i < arrType.length; i++) {
        arrType[i].className = '';
    }
    obj.className = 'curnav';
	document.getElementById("frmsearch").t.value = value;
}
function change_language(lang) {
		try{
			http.open('POST',  site+'/index.php');
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = function () {
											try {
												if((http.readyState == 4)&&(http.status == 200)){
												var response = http.responseText;
													if (response) {
														window.location.reload(true);
													}
												}
											}
											catch(e){}
											finally{}
										}
			http.send('language_name='+lang);
		}
		catch(e){}
		finally{}
	return false;
}
function openWindow(filename, winname, width, height, feature) {
    var features, top, left;
    var reOpera = /opera/i;
    var winnameRequired = ((navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) || reOpera.test(navigator.userAgent));

    left = (window.screen.width - width) / 2;
    top = (window.screen.height - height) / 2;
    if (feature == '')
        features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",status=0,location=0";
    else
        features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + "," + feature;
    newwindow = window.open(filename, winname, features);
    newwindow.focus();
}