﻿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) {
	createXMLHttpRequest();
	window.scrollTo(0,0);
	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/processBar.gif\"></p><br>";
	};
	xmlHttp.open("GET",strUrl, true);
	xmlHttp.send(null);
}

function startPostRequest(strUrl, strDivName) {
	createXMLHttpRequest();
	window.scrollTo(0,0);
	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/processBar.gif\"></p><br>";
	};
	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 chkFrmRegMail(){
	var strRegName = document.frmRegReceivePrice.txtMailName.value;
	var strRegMail = document.frmRegReceivePrice.txtMailAddress.value;

	if(strRegName=="")
	{
		alert("Bạn chưa nhập họ tên.");
		document.frmRegReceivePrice.txtMailName.focus();
		return false;
	}
	if(strRegMail=="")
	{
		alert("Bạn chưa nhập địa chỉ email.");
		document.frmRegReceivePrice.txtMailAddress.focus();
		return false;
	}
	if (strRegMail.indexOf('@',0)==-1 || strRegMail.indexOf('.')==-1)
	{
		alert ("Địa chỉ email nhập sai quy cách.");
		document.frmRegReceivePrice.txtMailAddress.focus();
		return false;
	}
	else
	{
		var strQuery = "regNewsLetter.asp?hoten="+strRegName+"&email="+strRegMail;
    	strQuery = strQuery.replace(/ /g,"[sPaCe]")
    	strQuery = strQuery.replace(/\n/g,"[nEwLiNe]")
    	startPostRequest(strQuery,'BodyContent');
	}
}

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 msgBoxAlert(strMess,strURL)
{
	window.alert(strMess);
	document.location.href=strURL;
}
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;
}
function chkForm(fElement)
{
	//var fElement = document.webmail;
	if(fElement.txtMailID.value=="")
	{
		window.alert("Please entry your Mail ID.");
		fElement.txtMailID.focus();
		return false;
	}
	if(fElement.f_pass.value=="")
	{
		window.alert("Please entry your Password.");
		fElement.f_pass.focus();
		return false;
	}
	fElement.f_email.value=fElement.txtMailID.value+"@vicomnet.vn";
	return true;														
}

function chkFrmContact()
{
	var obj = document.frmContact;
    var strSID = obj.txtSID.value;
    var strFullname = obj.txtName.value;
    var strAdd = obj.txtAddress.value;
    var strTel = obj.txtTel.value;
    var strFax = obj.txtFax.value;
    var strEmail = obj.txtEmail.value;
    var strSubject = obj.txtSubject.value;
    var strContent = obj.txtContent.value;

	if(obj.txtName.value=="")
	{
		alert("Please entry the Individual/Organize name.");
		obj.txtName.focus();
		return false;
	}
	
	if(obj.txtAddress.value=="")
	{
		alert("Please entry your Address.");
		obj.txtAddress.focus();
		return false;
	}
	
	if(obj.txtEmail.value=="")
	{
		alert("Please entry your E-mail.");
		obj.txtEmail.focus();
		return false;
	}
	
	if (obj.txtEmail.value.indexOf('@',0)==-1 || obj.txtEmail.value.indexOf('.')==-1)
	{
		window.alert("The E-mail you entry invalid.");
		obj.txtEmail.focus();
		return false;
	}
												
	if(obj.txtSubject.value=="")
	{
		alert("Please entry the Subject.");
		obj.txtSubject.focus();
		return false;
	}
	
	if(obj.txtContent.value=="")
	{
		alert("Please entry the Content.");
		obj.txtContent.focus();
		return false;
	}

	var strQuery = "/en/include/contactAct.asp?hoten="+strFullname+"&diachi="+strAdd+"&tel="+strTel+"&fax="+strFax+"&email="+strEmail+"&chude="+strSubject+"&noidung="+strContent+"&sid="+strSID;
	strQuery = strQuery.replace(/ /g,"[sPaCe]")
	strQuery = strQuery.replace(/\n/g,"[nEwLiNe]")
	startPostRequest(strQuery,'BodyContent');
}

function popupImage(src, title, note, css, border) {
var ppimgNW;
  if (border==null) border = 0;
  if (note==null) note = '';
  if (ppimgNW != null) ppimgNW.close();

  ppimgNW = window.open('','POPUPIMAGE','width=1,height=1');
  var doc = ppimgNW.document;
  doc.write('<html>');
  doc.write('<head>');

  if (title!=null) doc.write('<title>'+ title +'</title>');
  doc.write('<style> body {'+css+'} #ppImgText{'+ css +'} #ppImg{cursor:hand}</style></head>');
  doc.write('<body oncontextmenu="return false" leftmargin="0" topmargin="' + border + '">');
  doc.write('<div align="center">');
  doc.write('<img src="' + src + '" id="ppImg" onclick="self.close();" title="Close">');
  doc.write('</div>');
  doc.write('<div style="height:1; width:'+ border +'; font-size:4pt">');
  doc.write('</div>');
  doc.write('<div id="ppImgText" align="center">');
  doc.write('<Font face=Tahoma size=2>'+note+'</Font>');
  doc.write('</div>');
  doc.write('</body>');
  doc.write('</html>');

  doc.write('<' + 'script>');
  doc.write('var resized = false;');
  doc.write('function doResize() {');
  doc.write('  var imgW = ppImg.width, imgH = ppImg.height;');     
  if (note=='' || note==null) {addH=35} else {addH=60};
  doc.write('  window.resizeTo(imgW + 8 +' + border*2 +', imgH + ppImgText.offsetHeight + '+addH+' + '+ border*2 +');');
  doc.write('  setTimeout("doResize()",1000);');

  doc.write('}');
  doc.write('doResize(); ');
  doc.write('</' + 'script>');
}

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() //coded by PhongTran
{
	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 zoomImg(obj,intType) //coded by PhongTran
{
	var wObj = document.getElementById(obj);
	if(intType==0)
		objW = eval(wObj.width - 50);
	else
		objW = eval(wObj.width + 50);
	wObj.width = objW;
}

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
		ifrobj = document.getElementById? document.getElementById("ifrMask") : document.all.ifrMask
		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
		}
		//coded by PhongTran
		ifrobj.style.width = document.body.scrollWidth-5;
		ifrobj.style.height = document.body.scrollHeight;
		
		crossobj.style.left=horzpos+"px"
		crossobj.style.top=vertpos+"px"
		ifrobj.style.left="0px"
		ifrobj.style.top="0px"
		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"
		ifrobj.style.display=''
		ifrobj.style.visibility="visible"
		//coded by PhongTran
		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(){ //coded by PhongTran
	crossobj.style.visibility="hidden"
	ifrobj.style.visibility="hidden"
	ifrobj.style.display = "none"
	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) //coded by PhongTran
{										
	if(intModule==1)
		startRequest('include/inc_message.asp','BodyContent');
	else if(intModule==21)
		startRequest('include/page.ascx','BodyContent');
	else if (intModule==22)
		startRequest('include/inc_vimipe.asp','BodyContent');
	else if (intModule==23)
		startRequest('include/inc_partners.asp','BodyContent');
	else if (intModule==24)
		startRequest('include/inc_policy.asp','BodyContent');
	else if (intModule==41)
		startRequest('include/inc_webdesign.asp','BodyContent');
	else if (intModule==42)
		startRequest('include/inc_software.asp','BodyContent');
	else if (intModule==43)
		startRequest('include/inc_cuslist.asp?page='+getQuery("page"),'BodyContent');
	else if (intModule==5)
		startRequest('include/inc_news.asp','BodyContent');
	else if (intModule==51)
		startRequest('include/inc_newsCat.asp?catID='+getQuery("catID")+'&page='+getQuery("page"),'BodyContent');
	else if (intModule==52)
		startRequest('include/inc_newsdetail.asp?targetID='+getQuery("targetID"),'BodyContent');
	else if (intModule==7)
		startRequest('include/inc_webmail.asp','BodyContent');
	else if (intModule==8)
		startRequest('include/inc_contact.asp','BodyContent');
	else if (intModule==10)
		startRequest('include/inc_search.asp','BodyContent');
	else
		startRequest('mod.aspx','BodyContent');
}
