﻿var width = 192;
var height = 200;

function Show (URL, type)
{
HideItem ("pnlTV");
ShowItem ("TVContent");
var code; 
var code1 = "<img src='" + URL + "' border='0' width=" + width + " height=" + height + " />";
if (type == 0)
	code =  "<EMBED pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/' align=baseline src='" + URL + "'" +
			"PLAYCOUNT='1' LOOP='1' width=" + width + " height=" + height + " type=audio/x-pn-realaudio-plugin autostart=\"true\" ShowStatusBar='0' ShowControls='1' controls=\"ControlPanel\" menu=false wmode=Transparent console=\"Clip1\" border=\"0\">";
else 	code =	"<img src='../img/speaker.jpg' width='192'>" +
		"<EMBED pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/' align=baseline src='" + URL + "'" +
			"PLAYCOUNT='1' LOOP='1' width=" + width + " height='30' type=audio/x-pn-realaudio-plugin autostart=\"true\" ShowStatusBar='0' ShowControls='1' controls=\"ControlPanel\" menu=false wmode=Transparent console=\"Clip1\" border=\"0\">";
if (URL.indexOf (".swf") || URL.indexOf (".wmv"))
   GetElement ('TVContent').innerHTML = code;			
else if (URL.indexOf (".gif"))
   GetElement ('TVContent').innerHTML = code1;	
else  GetElement ('TVContent').innerHTML = "Lỗi, mời bạn chọn lại";			
}

function popupWin(url)
		{
		window.open(url, '', 'resizable=yes,width=500,height=450,top=75,left=220,scrollbars=yes');
		}
		
function GetElement(id)
		{
		var itm = null;

		if (document.getElementById)
				{
				itm = document.getElementById(id);
				}

		else if (document.all)
				{
				itm = document.all[id];
				}

		else if (document.layers)
				{
				itm = document.layers[id];
				}

		return itm;
		}
		
function ShowItem(id)
		{
		var itm = null;
		itm = GetElement(id);

		if (!itm)
				{
				}

		else if (itm.style)
				{
				itm.style.display = "";
				}

		else
				{
				itm.visibility = "show";
				}
		}

function HideItem(id)
		{
		var itm = null;
		itm = GetElement(id);

		if (!itm)
				{
				}

		else if (itm.style)
				{
				itm.style.display = "none";
				}

		else
				{
				itm.visibility = "none";
				}
		}
function VideoClick(id)
{	
switch (id){
case "VRClick":
	if (document.all("VRClick",0).style.display == "none")
	{ document.all("VRClick",0).style.display = ""; }
	else { document.all("VRClick",0).style.display = "none";}
	document.all("RadiClick",0).style.display="none";
	break;
case "RadiClick":
	if (document.all("RadiClick",0).style.display == "none")
	{ document.all("RadiClick",0).style.display = ""; }
	else { document.all("RadiClick",0).style.display = "none";}
	document.all("VRClick",0).style.display="none";
	break;
}
	return;
}
//////Ajax
function getAllQuery() {
  var strURL = document.location.href;
  var query = strURL.substr(strURL.indexOf("#")+1);
  return query;
}

function getQuery(variable) {
  var strURL = document.location.href;
  var query = strURL.substr(strURL.indexOf("#")+1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return "";
}

function gotoTop()
{
	window.scrollTo(0,0);
}
var xmlHttp;
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}

function startRequest(strUrl, strDivName, strObj) {
	createXMLHttpRequest();
	if (strDivName == "BodyContent"){
	window.scrollTo(0,0);
	};
	if (strObj!=null && strObj!="")
		strUrl = strUrl + document.getElementById(strObj).value;
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				document.getElementById(strDivName).innerHTML = xmlHttp.responseText;
			}
		}
		else
			document.getElementById(strDivName).innerHTML = "<br><p align=\"center\"><img border=\"0\" src=\"images/loading.gif\"></p><br>";
	};
	xmlHttp.open("GET",strUrl, true);
	xmlHttp.send(null);
}

function startPostRequest(strUrl, strDivName, strObj) {
	createXMLHttpRequest();
	window.scrollTo(0,0);
	if (strObj!=null && strObj!="")
		strUrl = strUrl + document.getElementById(strObj).value;
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				document.getElementById(strDivName).innerHTML = xmlHttp.responseText;
			}
			endProcess();
		}
		else
			startProcess();
	};
	var strQuery = strUrl.substr(strUrl.indexOf('?')+1,strUrl.length);
	xmlHttp.open("POST",strUrl, true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlHttp.send(strQuery);
}

function startSearch(strDivName) {
	createXMLHttpRequest();
	window.scrollTo(0,0);
	var intFeatures = document.getElementById('cbFeatures').value;
	var strPriceFrom = document.getElementById('txtPriceFrom').value;
	var strPriceTo = document.getElementById('txtPriceTo').value;
	var blnSearchPro = document.getElementById('rSearchWhat').checked;
	var strSearchWhat;
	if (!blnSearchPro)
		strSearchWhat = "news";
	else
		strSearchWhat = "prod";

	var intCondition = document.getElementById('cbCondition').value;
	var intSearchIn;
	if (strSearchWhat=="news")
		intSearchIn = document.getElementById('cbSearchInNews').value;
	else
		intSearchIn = document.getElementById('cbSearchInPro').value;
	var strByDate = "";
	if (document.getElementById('cbMonth')!=null){	
		var intMonth = document.getElementById('cbMonth').value;
		var intDate = document.getElementById('cbDate').value;
		var intYear = document.getElementById('cbYear').value;
		strByDate = intMonth+"/"+intDate+"/"+intYear;
	}
	var intPerPage = document.getElementById('cbPerPage').value;
	var strKeyword = document.getElementById('txtKeyword').value;
	
	var strQuery = "search.asp?features="+intFeatures+"&pricefrom="+strPriceFrom+"&priceto="+strPriceTo;
		strQuery = strQuery+"&searchwhat="+strSearchWhat+"&intcondition="+intCondition+"&keyword="+strKeyword;
		strQuery = strQuery+"&searchin="+intSearchIn+"&bydate="+strByDate+"&perpage="+intPerPage;
	strUrl = strQuery;
	
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				document.getElementById(strDivName).innerHTML = xmlHttp.responseText;
			}
			endProcess();
		}
		else
			startProcess();
	};
	xmlHttp.open("GET",strUrl, true);
	xmlHttp.send(null);
}

function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}


function sconfirm(strMess,strURL){
	var yn;
	yn=window.confirm(strMess);
	if (yn==true){
		document.location.href=strURL;
		}
}
function askconf(strMess){
	var yn;
	yn=window.confirm(strMess);
	if (yn==true){
		return true;
		}
	return false;
}
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
}
function winopen(url){
	window.open(url);
}

function insertStr(strValue,anh){

	window.opener.document.form1[anh].value=strValue;
}






isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");

function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.theLayer : document.getElementById("theLayer");  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
  
	if (isIE&&event.srcElement.id=="dragbar"||isNN&&e.target.id=="dragbar"){
		offsetx=isIE? event.clientX : e.clientX
		offsety=isIE? event.clientY : e.clientY
		
		tempx=parseInt(crossobj.style.left)
		tempy=parseInt(crossobj.style.top)
		
		ddEnabled=true
		document.onmousemove=drag_drop
	}

}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function moveCenter()
{
	obj = document.getElementById("theLayer");
	obj.style.left=(document.body.scrollLeft+parseInt((document.body.clientWidth-350)/2))+"px";
	obj.style.top=(document.body.scrollTop+parseInt((document.body.clientHeight-250)/2))+"px";

}
function show_hide()
{
	if (isIE||isNN)
	{
		if (whichDog.style.visibility=="hidden")
		{
			whichDog.style.visibility="visible";
			moveCenter();
		}
		else
		{
			whichDog.style.visibility="hidden";
		}
	}
	else if (isN4)
	{
		if (document.theLayer.visibility=="hide")
		{		
			document.theLayer.visibility="show";
			moveCenter();
		}
		else
		{
			document.theLayer.visibility="hide";
		}
	}
}



function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body
}

function enlarge(title, which, e, position, imgwidth, imgheight){
	if (isIE||isNN){
		crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
		if (position=="center"){
			pgyoffset=isNN? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
			horzpos=isNN? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
			vertpos=isNN? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
			if (window.opera && window.innerHeight) //compensate for Opera toolbar
			vertpos=pgyoffset+window.innerHeight/2-imgheight/2
			vertpos=Math.max(pgyoffset, vertpos)
		}
		else{
			var horzpos=isNN? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
			var vertpos=isNN? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
		}
		crossobj.style.left=horzpos+"px"
		crossobj.style.top=vertpos+"px"
		var strHTML = '<table border="0" cellpadding="0" style="border-collapse: collapse">'
		strHTML = strHTML + '<tr><td><table border="0" cellpadding="0" style="border-collapse: collapse" width=100%>'
		strHTML = strHTML + '<tr><td id="dragbar">&nbsp;'+title+'</td><td width="20" align="center" id="closetext" onClick="closepreview()"><img alt="Close" border="0" src="images/i_close.gif" width="16" height="16"></td></tr></td></tr></table>'
		strHTML = strHTML + '<tr><td title="Close" onClick="closepreview()"><img src="'+which+'"></td></tr></table>'

		crossobj.innerHTML= strHTML
		crossobj.style.visibility="visible"
		document.getElementById("divOpacity").style.width = document.body.scrollWidth;
		document.getElementById("divOpacity").style.height = document.body.scrollHeight;
		document.getElementById("divOpacity").style.visibility="visible";
		return false
	}
	else //if NOT IE 4+ or NS 6+, simply display image in full browser window
		return true
}

function closepreview(){
	crossobj.style.visibility="hidden"
	document.getElementById("divOpacity").style.width = 0;
	document.getElementById("divOpacity").style.height = 0;
	document.getElementById("divOpacity").style.visibility="hidden";
}

function drag_drop(e){
	if (isIE&&ddEnabled){
		crossobj.style.left=tempx+event.clientX-offsetx+"px"
		crossobj.style.top=tempy+event.clientY-offsety+"px"
	}
	else if (isNN&&ddEnabled){
		crossobj.style.left=tempx+e.clientX-offsetx+"px"
		crossobj.style.top=tempy+e.clientY-offsety+"px"
	}
	return false
}

function jumpOtherProd()
{
	var intPID = document.getElementById('cbOtherProducts').value;
	document.location.href='#module=101&pID='+intPID;
	startRequest('proDetail.asp?pID='+intPID,'BodyContent','');
}

function getContent(intModule)
{
	if(intModule==100)
		startRequest('proList.asp?subID='+getQuery("subID")+'&prodStatus='+getQuery("prodStatus")+'&page='+getQuery("page"),'BodyContent','');
	else if(intModule==101)
		startRequest('proDetail.asp?pID='+getQuery("pID"),'BodyContent','')
	else if (intModule==200)
		startRequest('intro.asp','BodyContent','');
	else if (intModule==300)
		startRequest('news.asp','BodyContent','');
	else if(intModule==301)
		startRequest('newsDetail.asp?newsID='+getQuery("newsID"),'BodyContent','')
	else if (intModule==400)
		startRequest('pricelist.asp','BodyContent','');
	else if (intModule==500)
		startRequest('search.asp?features='+getQuery("features")+'&intcondition='+getQuery("intcondition")+'&keyword='+getQuery("keyword")+'&searchin='+getQuery("searchin")+'&searchwhat='+getQuery("searchwhat")+'&bydate='+getQuery("bydate")+'&perpage='+getQuery("perpage")+'&pricefrom='+getQuery("pricefrom")+'&priceto='+getQuery("priceto")+'&page='+getQuery("page"),'BodyContent','');
	else if (intModule==600)
		startRequest('downhome.asp','BodyContent','');
	else if (intModule==601)
		startRequest('downlist.asp?inttype='+getQuery("inttype")+'&gID='+getQuery("gID")+'&cID='+getQuery("cID")+'&page='+getQuery("page"),'BodyContent','');
	else if (intModule==700)
		startRequest('faqs.asp','BodyContent','');
	else if (intModule==701)
		startRequest('service.asp','BodyContent','');
	else if (intModule==702)
		startRequest('support.asp','BodyContent','');
	else if (intModule==800)
		startRequest('contact.asp','BodyContent','');
	else
		startRequest('home.asp','BodyContent','');
}

