﻿// JavaScript Document
// global menu state

// Javascript code
var xmlhttp=null;
var url="intMenu.aspx";

// specifications for menu contents and menubar image associations
var menus = new Array();

function loadURLInt(url){
		
	xmlhttp=null;
	var para=null;
	if (url==null){
		url="intMenu.aspx";
	}

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
		
	if (xmlhttp!=null)
	{
		if (url=="intMenu.aspx"){
			document.getElementById("main").style.display="none";
			document.getElementById("wait").style.display="block";
			xmlhttp.onreadystatechange = state_ChangeURL
		}else if (url=="vanban/raovat.htm"){
			xmlhttp.onreadystatechange = state_ChangeID
		}else if (url=="downLoad.aspx"){
			
			if (document.getElementById("main"))
				document.getElementById("main").style.display="none";
			if (document.getElementById("wait"))	
				document.getElementById("wait").style.display="block";
			
				document.getElementById("mTop").style.display="block";
				document.getElementById("topTitle").style.paddingTop="5px";
				document.getElementById("topTitle").style.paddingBottom="5px";
				document.getElementById("topTitle").innerHTML="Thông tin khảo sát thị trường";
				xmlhttp.onreadystatechange = state_ChangeMail
		}else{
			
			var s=url.indexOf("formMail.aspx");
			
			if (s!=-1){ 
				
				var p=url.split("=");
				
				if (p.length==2){
					if (document.getElementById("main"))
						document.getElementById("main").style.display="none";
					if (document.getElementById("wait"))	
						document.getElementById("wait").style.display="block";
				}
				
				
				if (p[1]=="CON"){
					document.getElementById("topTitle").innerHTML="Liên hệ";
				}else if (p[1]=="DKY"){
					document.getElementById("topTitle").innerHTML="Đăng ký thành viên";
				//}else if (p[1]=="BCH"){
				//	document.getElementById("topTitle").innerHTML="Bình chọn sản phẩm";
				}else if (p[1]=="IMG&ID"){
					xmlhttp.onreadystatechange = state_ChangeImage
					xmlhttp.open("GET", url, true);
					xmlhttp.send(null);
					return;
				}else{
					document.getElementById("topTitle").innerHTML="Phiếu khảo sát";
				}		

				document.getElementById("mTop").style.display="block";
				document.getElementById("topTitle").style.paddingTop="5px";
				document.getElementById("topTitle").style.paddingBottom="5px";
				xmlhttp.onreadystatechange = state_ChangeMail
				
			}else{
				//application/x-www-form-urlencoded
				var hs=url.split("?");
				url=hs[0];
				para=String(hs[1]);
				document.getElementById("txtDiv").style.display="block";
				xmlhttp.open("POST", url, true);
				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xmlhttp.onreadystatechange = state_sendMail
				xmlhttp.send(para);
			}	
		}
		
		if (para==null){
			xmlhttp.open("GET", url, true);
			xmlhttp.send(null);
		}	

	}
	else
	{
		alert("Your browser does not support XMLHTTP.")
	}
}

function state_ChangeURL()
{
	
	if (xmlhttp.readyState==4)
 	{
		// if "OK"
 	    if (xmlhttp.status==200)
		{
			document.getElementById("mnu").innerHTML=xmlhttp.responseText;
			initMenus();
		}
		else
   		{
    		alert("Problem retrieving XML data")
   		}
		
   	}
}

function state_ChangeID()
{
	
	if (xmlhttp.readyState==4)
 	{
		// if "OK"
 	    if (xmlhttp.status==200)
		{	
			document.getElementById("tDLeft").innerHTML=xmlhttp.responseText;
		}
		else
   		{
    		alert("Problem retrieving XML data")
   		}
		
   	}
}

function state_ChangeMail()
{
	
	if (xmlhttp.readyState==4)
 	{
		// if "OK"
 	    if (xmlhttp.status==200)
		{	
			if (document.getElementById("wait"))
				document.getElementById("wait").style.display="none";
				
			document.getElementById("mTD").innerHTML=xmlhttp.responseText;
			
		}
		else
   		{
    		alert("Problem retrieving XML data")
   		}
		
   	}
}


function state_ChangeImage()
{
	
	if (xmlhttp.readyState==4)
 	{
		// if "OK"
 	    if (xmlhttp.status==200)
		{	
			findElementByID("tab2").innerHTML=xmlhttp.responseText;
		}
		else
   		{
    		alert("Problem retrieving XML data")
   		}
		
   	}
}


function state_sendMail()
{
	
	if (xmlhttp.readyState==4)
 	{
		// if "OK"
 	    if (xmlhttp.status==200)
		{	
			document.getElementById("txtDiv").style.display="none";
			alert(xmlhttp.responseText);
			
		}
		else
   		{
    		alert("Problem retrieving XML data")
   		}
		
   	}
}

  function loadFlash(name){
	
	var foot   = document.getElementById("flashBot");
	var head   = document.getElementById("flashTop");
	var typeBR = "IE";
	
	if (foot.hasChildNodes()){
	
		var childBot = foot.firstChild;
		var childTop = null;
		
		if (childBot.nodeType==1){
			head = document.getElementById("flashTop");
			childTop = head.firstChild;
			head.replaceChild(childBot, childTop);
		}else{
			typeBR = "FF";
			if (head!=null){
				var prent = foot.parentNode;
				prent.replaceChild(foot, head);
			}	
		}
	}

	var film = "Movie/" + name;
	
	var text="";
	

	if (typeBR=="IE"){
		document.mediaplayer.controls.stop();
		document.getElementById("movieTop").style.display="block";
		document.getElementById("movieTop").scrollIntoView(true);  
		document.getElementById("flashTop").style.display="block";
		document.getElementById("mTop").style.display="block";
		document.mediaplayer.URL=film;
		document.mediaplayer.controls.play();
	}else{
  		text = "<embed type='application/x-mplayer2' src='" + film + "' name='Player' width='450' height='400'></embed>";
		document.getElementById("movieTop").innerHTML=text;
		document.getElementById("movieTop").scrollIntoView(true);  
		document.getElementById("mTop").style.display="block";
	}
	
	var idText = name.split(".");
	var id     = idText[0];
	text=document.getElementById(id).innerHTML;
	document.getElementById("topTitle").innerHTML=text;
	
	return;	
 }

 function SetTabTable(TabName1, TabName2, ID)
{
    try
    {
        findElementByID(TabName2).className = "tabhide";
        findElementByID(findElementByID(TabName2).headers).style.display = "none";
        
        findElementByID(TabName1).className = "tabshow";
        findElementByID(findElementByID(TabName1).headers).style.display = "block";
        
        if (ID!="0"){
			loadURLInt("formMail.aspx?TM=IMG&ID="+ID);
		}
			
    }
    catch(ex){}
}

//-----------------------------------------------
function findElementByID(idName)
{
	return document.getElementById(idName);
}