//*********************************************************
//Multiple  AjaxObj
function set_multi(strURL1,strURL2,strDiv1,strDiv2){
   ajaxObj = XMLHttp();
   xmlhttp_Post(ajaxObj,strURL1,strDiv1);

   ajaxObj2 = XMLHttp();
   xmlhttp_Post(ajaxObj2,strURL2,strDiv2);
}

//*********************************************************
//刪除資料
function set_exec(strURL1,strURL2,divType1,divType2){
   ajaxObj = XMLHttp();
   xmlhttp_Post(ajaxObj,strURL1,divType1);
   alert('執行完成');
   if (strURL2 != 'undefined'){
      ajaxObj2 = XMLHttp();
      xmlhttp_Post(ajaxObj2,strURL2,divType2);
   }
}

//*********************************************************
//reflash single xmlhttpPost  (only for divArea0)
function set_single(strURL1,divType){
   ajaxObj = XMLHttp();
   xmlhttp_Post(ajaxObj,strURL1,divType);
}


//--------------------------------------------------------- 
// 多重 xmlhttpPost
XMLHttp = function(){
    var xmlHttpReq = false;
    var self = this;
   
    if (typeof XMLHttpRequest != 'undefined')
        return new XMLHttpRequest();
    else if (window.ActiveXObject) {
        var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp", "MSXML2.XmlHttp.3.0",  "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.5.0"];
        for (var i = avers.length -1; i >= 0; i--) {
          try {httpObj = new ActiveXObject(avers[i]);
             return httpObj;
          } catch(e) {}
        }
    }

    self.open('POST', strURL, true);
    self.onreadystatechange = function() {
        if (self.readyState == 4) {
            updatepage(self.responseText,divType);
        }else{
        	  updatepage_loading(divType);
        } 
    }
    self.send(null);

}

function xmlhttp_Post(obj,strURL,divType) {
	  obj.open('POST', strURL, true);
    obj.onreadystatechange = function() {
        if (obj.readyState == 4) {
            updatepage(obj.responseText,divType);
        }//else{
        //	  updatepage_loading(divType);
        //} 
    }
    obj.send(null);
}


//---------------------------------------------------------
//單一 xmlhttpPost
function xmlhttpPost(strURL,divType,valPar) {
    var xmlHttpReq = false;
    var self = this;
    
    if (divType == undefined){divType="divMain";}  
    if (window.XMLHttpRequest) {                  // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();  
    }else if (window.ActiveXObject) {             // IE7 / IE6  / 3.0或4.0或5.0 
        try {  self.xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
            	      try {
                        self.xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP.3.0");
                    } catch (e) {}
            	}
        }
    }

    if (!self.xmlHttpReq) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader("If-Modified-Since","0"); 
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText,divType);
        }//else{
        	  //updatepage_loading(divType);
        //} 
    }
    self.xmlHttpReq.send(null);
}

//---------------------------------------------------------
function updatepage(str,divType){
    document.getElementById(divType).innerHTML = str;
}

function updatepage_loading(divType){
	  var loadstatustext="<p align=center style='font-size:15px;color:#fa08b3;font-family:Comic Sans MS;'><img src='images/loading.gif' alt='資料讀取中' /><br><br>Loading...<br></p>";
    document.getElementById(divType).innerHTML = loadstatustext;
}

function show(num)
{
   obj = document.getElementById('qa'+num);
   if (obj.style.display=="none")
   	   obj.style.display="block";
   else
   	   obj.style.display="none";
}	


//*********************************************************
/* Top Tag setting */
function selectTag(selfObj){
	var tag = document.getElementById("tags").getElementsByTagName("li");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "";
	}
	selfObj.parentNode.className = "selectTag";
}
