//by maxz 
function ajax_get(url,div)
{
	var ajax = new myAjax(); 
	var ajax_o = new Ajax_callback_object();
	ajax_o.div = div;
	//ajax_o.divtype = divtype;
	ajax.get(url,ajax_o);
	return false;
}

 


function ajax_post(url,q,div)
{
	//var q = generate_post_query(form);
	var ajax = new myAjax(); 
	var ajax_o = new Ajax_callback_object();
	ajax_o.div = div;
	ajax.post(url,q,ajax_o);
}

function Ajax_callback_object() {
	//this.divtype = 1;
	this.div = '';
	this.callback = show_div;
	
	function show_div(response){
		if($('joinpost_btn')) $('joinpost_btn').disabled = false;
		//if(this.divtype == 1) 
		  document.getElementById(this.div).innerHTML=response;
		//else
			//setInnerHTML(document.getElementById(this.div),response);
	}
}

/*
* 描述：跨浏览器的设置 innerHTML 方法
* 允许插入的 HTML 代码中包含 script 和 style
*/
var setInnerHTML = function (el, htmlCode) {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
        htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
        htmlCode = htmlCode.replace(/<script([^>]*)>/gi,
                                    '<script$1 defer>');
        el.innerHTML = '';
        el.innerHTML = htmlCode;
        el.removeChild(el.firstChild);
    } else {
        var el_next = el.nextSibling;
        var el_parent = el.parentNode;
        el_parent.removeChild(el);
        el.innerHTML = htmlCode;
        if (el_next) {
            el_parent.insertBefore(el, el_next)
        } else {
            el_parent.appendChild(el);
        }
    }
}


function generate_post_query(f){
	var q='';
	for(var i=0;i<f.elements.length;i++){
		if(i!=0);q+='&';
		q+=f.elements[i].name+'='+f.elements[i].value;
	}
	return q;
}

function create_xmlhttp() { 
	if(window.XMLHttpRequest) { 
	// Non-IE browsers 
		req = new XMLHttpRequest(); 
	} else if(window.ActiveXObject) { 
	// IE 
		req = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	return req; 
} 
	
// ajax class 
function myAjax() { 
	this.xmlhttp = create_xmlhttp(); 
    
	this.get = ajax_get; 
	this.post = ajax_post; 
	
	this.response = ''; 
	this.callback_object = ''; 
	
	function ajax_get(url,callback_object) { 
	
		this.callback_object = callback_object; 
		
		var this_obj = this; 

		this.xmlhttp.onreadystatechange = function() { 
			if(this_obj.xmlhttp.readyState == 4) { 
				if(this_obj.xmlhttp.status == 200) { 
				     //alert(this_obj.xmlhttp.getAllResponseHeaders());
					this_obj.callback_object.callback(this_obj.xmlhttp.responseText);
					
				} else { 
					alert('There was a problem with the request. ('+this_obj.xmlhttp.status+')'); 
				} 
			} 
		} 
		this.xmlhttp.open("GET", url, true); 
		this.xmlhttp.setRequestHeader("If-Modified-Since","0");
		this.xmlhttp.send(null);
		
		return true; 
	}
	

    
	function ajax_post(url, query, callback_object) { 
	
		this.callback_object = callback_object; 
	
		var this_obj = this; 
	
		this.xmlhttp.onreadystatechange = function() { 
			if(this_obj.xmlhttp.readyState == 4) { 
				if(this_obj.xmlhttp.status == 200) { 
					this_obj.callback_object.callback(this_obj.xmlhttp.responseText);
				} else { 
					alert('There was a problem with the request. (' + this_obj.xmlhttp.status + ')'); 
				} 
			} 
		} 
	  
		this.xmlhttp.open('POST', url); 
		this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		this.xmlhttp.setRequestHeader("If-Modified-Since","0");
		this.xmlhttp.send(query); 
		return true; 
	} 
} 

function page(lid,pid){
document.getElementById("comment_load").innerHTML="<div style='padding:30px;text-align:center'><img src='../../images/loading2.gif'/>数据加载中...</div>";
ajax_get("../../comment.asp?zt_id="+lid+"&page="+pid+"","comment");
}

function page2(dourl,pid){
//document.getElementById("comment_load").innerHTML="<div style='padding:30px;text-align:center'><img src='/images/loading2.gif'/>数据加载中...</div>";
//window.location.href = dourl+"&page="+pid;
ajax_get(dourl+"&page="+pid+"","asklist");
}


function showcontent(txt){
	document.getElementById('comment_content').value=txt;
}

ie = (document.all)? true:false 
if (ie)
{ 
	function ctlent(eventobject)
	{
		if(event.ctrlKey && window.event.keyCode==13)
		{
			submit_comment();
		}
	} 
}

function insertTags(tagOpen, tagClose, sampleText) {
    var txtarea = document.getElementById("comment_content");
	// IE
	if(document.selection) {
		var theSelection = document.selection.createRange().text;
		if(!theSelection) { theSelection=sampleText;}
		txtarea.focus();
		if(theSelection.charAt(theSelection.length - 1) == " "){
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}
	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
 		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		var myText = (txtarea.value).substring(startPos, endPos);
		if(!myText) { myText=sampleText;}
		if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " "; 
		} else {
			subst = tagOpen + myText + tagClose; 
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();
		var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
		txtarea.selectionStart=cPos;
		txtarea.selectionEnd=cPos;
	// All others
	} else {
		tagOpen=tagOpen.replace(/\n/g,"");
		tagClose=tagClose.replace(/\n/g,"");
		document.infoform.infobox.value=tagOpen+sampleText+tagClose;
		txtarea.focus();
	}
	if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}