// JavaScript Document
function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
    var form     = document.forms['f1'];
    var word = form.word.value;
    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str){
    document.getElementById("result").innerHTML = str;
}
// Post
// JavaScript Document
function xmlhttpPostBlock(strURL,f) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageBlock(self.xmlHttpReq.responseText,f);
        }
    }
    self.xmlHttpReq.send(getquerystringBlock(f));
}

function getquerystringBlock(f) {
    var form     = document.forms[f];	
    var word = escape(form.block_name.value);
	word+="&block_class="+escape(form.block_class.value);
	word+="&block_style="+escape(form.block_style.value);
	word+="&block_width="+escape(form.block_width.value);
	word+="&block_height="+escape(form.block_height.value);
	word+="&block_begin="+escape(form.block_begin.value);
	word+="&block_end="+escape(form.block_end.value);

	word+="&page_id="+escape(form.page_id.value);	
	word+="&block_p="+escape(form.block_p.value);
	word+="&block_id="+escape(form.block_id.value);
	word+="&edited="+escape(form.edited.value);
	word+="&block_name_old="+escape(form.block_name_old.value);
	word+="&block_position="+escape(form.block_position.value);
	
    qstr = 'block_name=' + word;  // NOTE: no '?' before querystring
    return qstr;
}

function updatepageBlock(str,f){
    document.getElementById(f).innerHTML = str;
}

// JavaScript Document
function xmlhttpPostModule(strURL,f) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageModule(self.xmlHttpReq.responseText,f);
        }
    }
    self.xmlHttpReq.send(getquerystringModule(f));
}

function getquerystringModule(f) {
    var form     = document.forms[f];	
    var word = escape(form.block_id.value);
	var m=form.modules_list;
	var list='&modules_arr=';
	for(var i=0; i<m.length; i++)
	{
		if(m[i].selected)
			list+=escape(m[i].value)+"~~~";
	}
	word+=list;
	word+="&page_id="+escape(form.page_id.value);	
    qstr = 'block_id=' + word;  // NOTE: no '?' before querystring
    return qstr;
}

function updatepageModule(str,f){
    document.getElementById(f).innerHTML = str;
}
// Get
function xmlhttpGet(strURL,word,_item,update) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4 && update==1) {
            updatepageGet(self.xmlHttpReq.responseText,_item);
        }
    }
    self.xmlHttpReq.send(getquerystringGet(word));
}

function getquerystringGet(word) {   // word : id=2&name=ducchung_g7media
    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepageGet(str,_item){
    document.getElementById(_item).innerHTML = str;
}

//
function xmlhttpPostPostion(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepagePostion(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystringPostion());
}

function getquerystringPostion() {
  return true;
}

function updatepagePostion(str){
    //document.getElementById("result").innerHTML = str;
	 return true;
}