/* - - - - - - - - - - - - - - - - - - - - - - -
Ajax Javascript
 - - - - - - - - - - - - - - - - - - - - - - - */
var ie45,ns6,ns4,dom;
if (navigator.appName=="Microsoft Internet Explorer") ie45=parseInt(navigator.appVersion)>=4;
else if (navigator.appName=="Netscape"){  ns6=parseInt(navigator.appVersion)>=5;  ns4=parseInt(navigator.appVersion)<5;}
dom=ie45 || ns6;

var http=createRequestObject();
var objectId = '';
var loadok = 0;

function createRequestObject(htmlObjectId){
    var obj;
    var browser = navigator.appName;
    
    if(browser == "Microsoft Internet Explorer"){
        obj = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        obj = new XMLHttpRequest();
    }
    return obj;    
}

function do_write_faqs(f) {
		var re =/^[a-z][a-z0-9]+[@][a-z0-9]+([.][a-z]+)+$/gi;
		var name = f.name.value;
		if (name == '') {
			alert('Vui long nhap ten cua ban');
			f.name.focus();
			return false;
		}

		var email = f.email.value;
		if (email == ''){
			alert("Xin nhap dia chi Email");
			f.email.focus();
			return false;
		}
		if (email.match(re)==null)
		{
			alert('Email khong hop le');
			f.email.focus();
			return false;
		}	
		var title = f.title.value;
		if (title == '') {
			alert('Vui long nhap tieu de');
			f.title.focus();
			return false;
		}
		
	
	var strpara = 'name='+encodeURIComponent(name)+'&email='+encodeURIComponent(email)+'&title='+encodeURIComponent(title);
	
	furl = 'index.php?vnTRUST=act:faqs|do:write|do_submit:1';
	send_post(furl,strpara,'ext_faqs_question');
	return false;
}

function send_post(strurl, parameters,objId) {      
  objectId = objId;
  //lert (parameters);
  //alert (parameters);
  http.open('POST', strurl, true);
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", parameters.length);
  http.setRequestHeader("Connection", "close");
  http.onreadystatechange = handleResponse;
  http.send(parameters);
}

function do_maillist(f) {
	furl = 'act:mail_list|f_email:'+f.f_email.value;
	sendReq('index.php', 'vnTRUST', furl,'ext_maillist');
	return false;
}

function do_sendmail(f) {
	furl = 'act:tellfriend|f_email:'+f.f_email.value;
	sendReq('index.php', 'vnTRUST', furl,'ext_tellfriend');
	return false;
}

function sendReq(serverFileName, variableNames, variableValues,objId) {
	var paramString = '';
	
	objectId = objId;
	
	variableNames = variableNames.split(',');
	variableValues = variableValues.split(',');
	
	for(i=0; i<variableNames.length; i++) {
		paramString += variableNames[i]+'='+variableValues[i]+'&';
	}
	paramString = paramString.substring(0, (paramString.length-1));
			
	if (paramString.length == 0) {
	   	http.open('get', serverFileName);
	}
	else {
		http.open('get', serverFileName+'?'+paramString);
	}
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
	
	if (http.readyState == 4) {
		responseText = http.responseText;
		getobj(objectId).innerHTML = responseText;
    } else {
		getobj(objectId).innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0' style='margin-top:10px' align=center><tr><td align='center' width='81%'> &nbsp; <img src='images/loading.gif' border=0></td></tr><tr><td align='center' width='81%'> &nbsp; &#272;ang l&#7845;y d&#7919; li&#7879;u ...</strong></td></tr></table>";
	}
		
}

function change_icon(imgDocID,url) {
document.images[imgDocID].src = url;
}  

function showhide(id) {
el = document.all ? document.all[id] :   dom ? document.getElementById(id) :   document.layers[id];
els = dom ? el.style : el;
  if (dom){
    if (els.display == "none") {
        els.display = "";
      } else {
        els.display = "none";
      }
    }
  else if (ns4){
    if (els.display == "show") {
        els.display = "hide";
      } else { 
      els.display = "show";
         }
  }
}

function getobj(id) {
el = document.all ? document.all[id] :   dom ? document.getElementById(id) :   document.layers[id];
return el;
}

function showobj(id) {
obj=getobj(id);
els = dom ? obj.style : obj;
 	if (dom){
	    els.display = "";
    } else if (ns4){
        els.display = "show";
  	}
}

function hideobj(id) {
obj=getobj(id);
els = dom ? obj.style : obj;
 	if (dom){
	    els.display = "none";
    } else if (ns4){
        els.display = "hide";
  	}
}

// khong the phong to cua so
function openPopUp(url, windowName, w, h, scrollbar) {
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
   win = window.open(url, windowName, winprops);
   if (parseInt(navigator.appVersion) >= 4) { 
       	win.window.focus(); 
   } 
}

// co the phong to cua so
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}

//============================================================

var horizontal_offset="9px" //horizontal offset of hint box from anchor link
/////No further editting needed
var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

//===============================================
function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox


//Highlight form element- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com

var highlightcolor= "FFFCE8";

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)&&which.name != "Đong y" &&which.name != "Huy"){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))

eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}

function is_num(event,f){
	if (event.srcElement) {kc =  event.keyCode;} else {kc =  event.which;}
	if ((kc < 47 || kc > 57) && kc != 8 && kc != 0) return false;
	return true;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}




function check_search (f){
	if (f.keyword.value.length <2 ) {
		alert(note_search);
		f.keyword.focus();
		return false;
	}
		return true;	
}
/*===========================================FAQ=====================================================*/


function show_write_faqs() {
	furl = 'act:faqs|do:write';
	sendReq('index.php','vnTRUST', furl,'ext_faqs');
	return false;
}


function show_faqs(id) {
	furl = 'act:faqs|do:view|f_id:'+id;
	sendReq('index.php','vnTRUST',furl,'ext_faqs');
	return false;
}
/*===========================================gallery=====================================================*/


function play_song(song_id) {
	furl='act:playsong'+'|song_id:'+song_id+'|sub:play';
	sendReq('index.php','vnTRUST', furl,'ext_play');
}

