//zarz
function switch_obj_disabled(obj) {
    try {
        obj.disabled = !obj.disabled;
    } catch(e) {
        return false;
    }
    return true;
}

function switch_obj_readonly(obj) {
    try {
        obj.readOnly = !obj.readOnly;
    } catch(e) {
        return false;
    }
    return true;
}

function removeObj(id) {
    try {
        var o = document.getElementById(id);
    } catch(e) {
        return false;
    }
    try {
        o.parentElement.removeChild(o);
    } catch(e) {
        try {
            o.parentNode.removeChild(o);
        } catch(e) {
            return false;
        }
    }
    return true;
}

function explodeStr(str) {
    str_r = new Array();
	var separators = "|";
	var includeEmpties = 1;
    str_r = explode(str, separators, includeEmpties);
    return str_r;
    //return true;
}
function explode(inputstring, separators, includeEmpties) {
	inputstring = new String(inputstring);
	separators = new String(separators);
	
	if(separators == "undefined") {
		separators = "|";
	}
	
	fixedExplode = new Array(1);
	currentElement = "";
	count = 0;
	for(x=0; x < inputstring.length; x++) {
		str = inputstring.charAt(x);
		if(separators.indexOf(str) != -1) {
		    if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) { }
		    else {
				fixedExplode[count] = currentElement;
				count++;
				currentElement = ""; 
				} 
			}
		    else { currentElement += str; }
	}
	
	if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
	    fixedExplode[count] = currentElement; 
	}
	return fixedExplode;
	
}

function analyseStr(str,return_section) {
	//var r_code, r_text, temp;
	var section = return_section;
	var i = str.indexOf('|');//获得第一个'|'的位置	
	
	if (i<0) {
	    alert("错误！");
	    //switch_obj_disabled(btn_me);
	    return false;
	}	
	//alert(str);
	var i_2 = str.indexOf('|', i+1);//获得第二个'|'的位置
	//alert(i_2);
	var i_3 = i_2-2;
	
	alert_msg = str.substr(i+1,i_3);
	//alert(alert_msg);
	r_text = str.substr(i_2+1);
	
	if (section == 'none' || section == '1') {
	    return str.substr(0,i);	
	}
	
	if (section == 'msg' || section == '2') {
	    return alert_msg;	
	}
	
	if (section == 'text' || section == '3') {
	    return r_text;	
	}

    //return true;
}

function clear_content(id){
    document.getElementById(id).innerHTML = "";
}

//
function erase_msg(id,attribute){
	if(attribute == "value"){
	    document.getElementById(id).value = "";		
	}else{
	    if(attribute == null){
	        document.getElementById(id).style.display = "none";		
	    }
	
	}
}

function AJAX_cp(){

	var ajaxIndentity = 0;
	var nameSpace = "http://toodou.com/";

	var getAJAXIdentity = function(){
	    return "AJAX" + (ajaxIndentity++);
    }//end GetAJAXIdentity()
    
    //Overridden toString method.
    this.toString = function(){
		return "AJAX Framework Class";
	}//end toString()
    
    //Method for error handling.
    this.onError = function(error){
		alert(error);
    };//end onError()

    //Call a page with a callback function name.
    this.callPage = function(url, callbackFunction){
	    var iframe = document.createElement("IFRAME");
	    var IE = (navigator.appName.indexOf("Microsoft") >= 0);
        iframe.id = getAJAXIdentity();
        
        if(IE){
			iframe.style.display = "none";
			document.appendChild(iframe);
		}
		else{
			iframe.style.display = "none";
			document.body.appendChild(iframe);
		}//end if
		
	    iframe.src = url;

	    if(IE){
			iframe.onreadystatechange = function(){
				if(this.readyState == "complete"){
					callbackFunction(document.frames[iframe.id].document.body.innerHTML);
					document.removeChild(iframe);
				}//end if
			};
	    }
	    else{
			iframe.addEventListener("load", function(){
				callbackFunction(document.getElementById(iframe.id).contentDocument.body.innerHTML);
				document.body.removeChild(document.getElementById(iframe.id));
			}, false);
	    }//end if
	};//end callPage()
	
	//Method for returning the namespace
	this.getNameSpace = function(){
		return ns;
	}//end getNameSpace()
}

function get_uri_content(url, callbackFunction) {
    //
    var tmp = new AJAX_cp();
    tmp.callPage(url, callbackFunction);
}