//thoi gian tu dong an di cua auto hide message
var time_out = 1000;

//khoi tao bien dung chung
var show_alert_interval = "";
var hide_alert_interval = "";
var current_focus = null;
//function dung chung
function msgOncroll() {
	var top_magin = document.documentElement.scrollTop; 
	var d = document.getElementById("div_bg_message"); 
	d.style.top = top_magin+"px";
	d = document.getElementById("div_bg_content"); 
	d.style.top = top_magin+'px';
}

function closeMessage() {
	window.onscroll = null;
	var d = document.getElementById("div_bg_message"); 
	if (d!=null)
		document.body.removeChild(d);
	d = document.getElementById("div_bg_content"); 
	if (d!=null)
		document.body.removeChild(d);
	
	if (( current_focus != null )&&( current_focus != "" )) {
		current_focus.focus();
		current_focus = null;
	}
	
}

function sendEvent(typ,prm) { thisMovie("lightbox_mediaplayer").sendEvent(typ,prm); };

function thisMovie(movieName) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
};

function closeVideoMessage() {
	sendEvent('stop');
	var d = document.getElementById("div_bg_message"); 
	d = document.getElementById("div_bg_message");
	if (d!=null)
		document.body.removeChild(d);
	d = document.getElementById("div_bg_content"); 
	if (d!=null)
		document.body.removeChild(d);
	d = document.getElementById("div_bg_content"); 
}
function darkBackground() {
	var div_bg = document.getElementById("div_bg_message") ;
	div_bg.style.backgroundColor = "#000000";
	div_bg.style.filter = "Alpha(Opacity=50)";
	div_bg.style.MozOpacity = "0.5";
}
function lightBackground() {
	var div_bg = document.getElementById("div_bg_message") ;
	div_bg.style.backgroundColor = "#ffffff";
	div_bg.style.filter = "Alpha(Opacity=0)";
	div_bg.style.MozOpacity = "0";
}
function backgroundClick() {
	darkBackground();
	setTimeout("lightBackground()",100);
}
//end - function dung chung

/*
- msg: text
- focus_obj (object): focus this object after close message
*/

function gAlert(msg,focus_obj) {
	//top
	var top_magin = document.documentElement.scrollTop;
	window.onscroll = msgOncroll;
	
	var div_bg = document.createElement("div") ;
	div_bg.id = "div_bg_message"; 
	div_bg.style.position = 'absolute';
	div_bg.style.left = '0px';
	div_bg.style.top =  top_magin+'px';
	div_bg.style.width = '100%';
	div_bg.style.height = '100%';
	div_bg.style.zIndex = '9999';
	div_bg.onmousedown = darkBackground;
	div_bg.onmouseup = lightBackground;
	div_bg.style.backgroundColor = "#ffffff";
	
	document.body.appendChild(div_bg);
	
	var div_contain = document.createElement("div") ;
	div_contain.id = "div_bg_content";
	div_contain.style.position = 'absolute';
	div_contain.style.left = '0px';
	div_contain.style.top =  top_magin+'px';
	div_contain.style.zIndex = '10000';
	div_contain.style.width = '100%';
	div_contain.align = "center";
	
	document.body.appendChild(div_contain);
	
	var div_msg = document.createElement("div") ;
	div_msg.id = "message_content";
	var close_msg = "closeMessage()";
	current_focus = focus_obj;
	var s = "<div  style='background-color:#eeeeee; padding:5px; color:#d91616; font-weight:bold;height:16px'><a href='javascript:closeMessage()' title='&#272;&#243;ng'><img src='images/ico_close.gif' border='0' align='right'></a><font color='#04bd00'>Quangcao</font><font color='#ff9c00'>Dientu</font><font color='#8c8c8c'>.com.vn</font></div>";
	s += "<div style='padding:10px; color:#333333;'>"+msg+"</div>";
	s += "<div align='center'  style='background-color:#eeeeee; padding:5px; color:#d91616; font-weight:bold;height:18px'><input type='button' class='button' value='OK' onclick='closeMessage()'></div>";
	//note: class button from style.css
	div_msg.innerHTML = s;
	div_contain.appendChild(div_msg);
	
}

function gConfirm(msg,function_name) {
	//top
	var top_magin = document.documentElement.scrollTop;
	window.onscroll = msgOncroll;
	
	var div_bg = document.createElement("div") ;
	div_bg.id = "div_bg_message"; 
	div_bg.style.position = 'absolute';
	div_bg.style.left = '0px';
	div_bg.style.top =  top_magin+'px';
	div_bg.style.width = '100%';
	div_bg.style.height = '100%';
	div_bg.style.zIndex = '9999';
	//div_bg.onclick = backgroundClick;
	div_bg.onmousedown = darkBackground;
	div_bg.onmouseup = lightBackground;
	div_bg.style.backgroundColor = "#ffffff";
	document.body.appendChild(div_bg);
	
	var div_contain = document.createElement("div") ;
	div_contain.id = "div_bg_content";
	div_contain.style.position = 'absolute';
	div_contain.style.left = '0px';
	div_contain.style.top =  top_magin+'px';
	div_contain.style.zIndex = '10000';
	div_contain.style.width = '100%';
	div_contain.align = "center";
	
	document.body.appendChild(div_contain);
	
	var div_msg = document.createElement("div") ;
	div_msg.id = "message_content";
	
	var s = "<div  style='background-color:#eeeeee; padding:5px; color:#d91616; font-weight:bold;height:16px'><a href='javascript:closeMessage()' title='&#272;&#243;ng'><img src='images/ico_close.gif' border='0' align='right'></a><font color='#04bd00'>Quangcao</font><font color='#ff9c00'>Dientu</font><font color='#8c8c8c'>.com.vn</font></div>";
	s += "<div style='padding:10px; color:#333333; '>"+msg+"</div>";
	s += "<div align='center'  style='background-color:#eeeeee; padding:5px; color:#d91616; font-weight:bold;height:18px'><input type='button' class='msg_button1' value='C&#243;' onclick='closeMessage();"+function_name+"'>&nbsp;<input type='button' class='msg_button1' value='Kh&#244;ng' onclick='closeMessage();'></div>";
	
	div_msg.innerHTML = s;
	div_contain.appendChild(div_msg);
}

//message tu dong an
function autohide_alert(msg) {
	//top
	var top_magin = document.documentElement.scrollTop;
	window.onscroll = msgOncroll;
	
	var div_bg = document.createElement("div") ;
	div_bg.id = "div_bg_message"; 
	div_bg.style.position = 'absolute';
	div_bg.style.left = '0px';
	div_bg.style.top =  top_magin+'px';
	div_bg.style.width = '100%';
	div_bg.style.height = '100%';
	div_bg.style.zIndex = '9999';
	div_bg.style.backgroundColor = "#ffffff";
	div_bg.style.filter = "Alpha(Opacity=0)";
	div_bg.style.MozOpacity = "0";
	document.body.appendChild(div_bg);
	
	var div_contain = document.createElement("div") ;
	div_contain.id = "div_bg_content";
	div_contain.style.position = 'absolute';
	div_contain.style.left = '0px';
	div_contain.style.top =  top_magin+'px';
	div_contain.style.zIndex = '10000';
	div_contain.style.width = '100%';
	div_contain.align = "center";
	
	document.body.appendChild(div_contain);
	
	var div_msg = document.createElement("div") ;
	div_msg.id = "message_content";
	
	var s = "<div  style='background-color:#eeeeee; padding:5px; color:#d91616; font-weight:bold;height:16px'><a href='javascript:close_alert();closeMessage();' title='&#272;&#243;ng'><img src='images/ico_close.gif' border='0' align='right'></a><font color='#04bd00'>Quangcao</font><font color='#ff9c00'>Dientu</font><font color='#8c8c8c'>.com.vn</font></div>";
	s += "<div style='padding:10px; color:#333333;'>"+msg+"</div>";
	s += "<div align='center'  style='background-color:#eeeeee; padding:5px; color:#d91616; font-weight:bold;height:18px'><input type='button' class='button' value='OK' onclick='close_alert();closeMessage();'></div>";
	
	div_msg.innerHTML = s;
	div_msg.style.filter = "Alpha(Opacity=100)";
	div_msg.style.MozOpacity = "1";
	div_contain.appendChild(div_msg);

	//show message progress
	//show_alert_interval = setInterval("show_alert()",100);
	t = setTimeout("hide_message()",time_out);
}
var t = '';
function show_alert() {
	var div_msg = document.getElementById("message_content"); 
	var t = parseFloat(div_msg.style.MozOpacity);
	if (t < 1) {
		div_msg.style.MozOpacity = t+0.1;
		div_msg.style.filter = "Alpha(Opacity="+((t+0.1)*100)+")";
	} else {
		clearInterval(show_alert_interval);
		
	}
}

function hide_message() {
	hide_alert_interval = setInterval("hide_alert()",100);
}
function hide_alert() {
	var div_msg = document.getElementById("message_content"); 
	if (div_msg!=null) {
		var t = parseFloat(div_msg.style.MozOpacity);
		if (t > 0) {
			div_msg.style.MozOpacity = t-0.1;
			div_msg.style.filter = "Alpha(Opacity="+((t+0.1)*100)+")";
		} else {
			clearInterval(hide_alert_interval);
			closeMessage();
		}
	} else {
		if (hide_alert_interval!="") clearInterval(hide_alert_interval);
	}
}
function close_alert() {
	if (show_alert_interval!="") clearInterval(show_alert_interval);
	if (hide_alert_interval!="") clearInterval(hide_alert_interval);
	if (t!='') clearTimeout(t);
	closeMessage();
}

function videoLightbox(video,img) {
	//top
	var top_magin = document.documentElement.scrollTop;
	
	var div_bg = document.createElement("div") ;
	div_bg.id = "div_bg_message"; 
	div_bg.style.position = 'absolute';
	div_bg.style.left = '0px';
	div_bg.style.top =  top_magin+'px';
	div_bg.style.width = '100%';
	div_bg.style.height = '100%';
	div_bg.style.zIndex = '9999';
	div_bg.onmousedown = darkBackground;
	div_bg.onmouseup = lightBackground;
	div_bg.style.backgroundColor = "#ffffff";
	
	document.body.appendChild(div_bg);
	
	var div_contain = document.createElement("div") ;
	div_contain.id = "div_bg_content";
	div_contain.style.position = 'absolute';
	div_contain.style.left = '0px';
	div_contain.style.top =  top_magin+'px';
	div_contain.style.zIndex = '10000';
	div_contain.style.width = '100%';
	div_contain.align = "center";
	
	document.body.appendChild(div_contain);
	
	var div_msg = document.createElement("div") ;
	div_msg.id = "message_content";
	var s = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="Table_Border"><tr><td class="main_header1"><a href="javascript:closeVideoMessage()" title="Close"><img src="images/x.gif" border="0" align="right" hspace=5></a>VIDEO CLIP</td></tr><tr><td style="padding:5px"><span id="lightbox_preview"></span></td></tr></table>';
	//note: class button from style.css
	div_msg.innerHTML = s;
	div_contain.appendChild(div_msg);
	play_lightbox_video(video,img);
}


