
if (!("console" in window) || !("firebug" in console))
{	
	var names, i;
    names = ["log", "debug", "info", "warn", "error", 
    "assert","assertEquals","assertNotEquals","assertGreater","assertNotGreater","assertLess",
    "assertNotLess","assertContains","assertNotContains","assertTrue","assertFalse",
    "assertNull","assertNotNull","assertUndefined","assertNotUndefined","assertInstanceOf",
    "assertNotInstanceOf","assertTypeOf","assertNotTypeOf",
     "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for ( i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

var g_referrer, host, pathName, projectName, g_basePath, g_url;
	g_referrer = document.referrer;
	host = window.location.protocol + "//" + window.location.host;
	pathName = window.location.pathname;
	projectName = pathName.split("/")[1];
	g_basePath = host + "/";
	if(host.indexOf("qianquan.com") < 0 && host.indexOf("118.144.88") < 0 && projectName.indexOf(".") < 0){
		g_basePath += projectName + "/";
	}
	g_url = window.location.href;


function get_parameter_from_url(name) {
	var value, queryStr, ps, i , re, n, v;
	value = null;
	if (g_url.indexOf('?') > 0) {
		queryStr = window.location.search;
		queryStr = queryStr.substring(1);
		ps = queryStr.split('&');
		for ( i = 0; i < ps.length; ++i) {
			re = /(.*)=(.*)/;
			if (re.test(ps[i])) {
				n = RegExp.$1;
				v = RegExp.$2;
				if (n.trim() == name) {
					value = v;
					if (isNaN(value)) {
						value = decodeURIComponent(value);
					}
				}
			}
		}
	}
	return (value);
}

String.prototype.appendParam = function(paramName, val) {
	var newStr = this;
	if (this.indexOf(paramName) < 0) {
		// add
		if (this.indexOf("?") >= 0) {
			newStr = this + "&" + paramName + "=" + val;
		} else {
			newStr = this + "?" + paramName + "=" + val;
		}
	} else {
		// replace
		var regx = new RegExp(paramName + "=" + "[\\w|\\d]*(&|$)");
		newStr = this.replace(regx, paramName + "=" + val + "$1");
	}
	return newStr;
}

//对于其它的函数，建议直接使用dojo本身的吧, 因dojo.js在top0.jsp中已引入.
//如: vqq_http_get(dojo.xhrGet)
function vqq_http_get(url, callback, thisObj) {
	var getUrl, random, status;
	random = Math.random();
	getUrl = url.appendParam("random", random);
	var ss = getUrl.split(g_basePath)[1];  
	getUrl = g_basePath + "api/" + ss;
	status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}
	dojo.xhrGet( {
		url : getUrl,
		handleAs :"json",
		load : function(data) {
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
		  if(callback){
			 callback(data, thisObj);
		   }
		},
		error : function(error, args) {
			console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				status.innerHTML = "糟糕！好像网络或者服务器发生了点故障，请您刷新页面试试...";
			}
		}
	});
}


//如：vqq_http_post(dojo.xhrPost)
function vqq_http_post(url, callback, formId, thisObj) {
	var status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}

	var ss = url.split(g_basePath)[1]; 
	url = g_basePath + "api/" + ss;
	dojo.xhrPost( {
		url :url,
		form :formId,
		handleAs :"json",
		load : function(data) {
			// console.log(data);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
			if(callback){
				callback(data, thisObj);
			}else{
				if (!data.result) {
					alert(data.err);
					return;
				} else {
					alert(data.msg);
				}
			}
		},
		error : function(error, args) {
			 console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				status.innerHTML = "糟糕！好像网络或者服务器发生了点故障，请您刷新页面试试...";
			}
		}
	});
}

//create_form_to_post()
function create_form_to_post(url, postData, callback) {
	var getUrl, form, k, input, status;
	form = dojo.doc.createElement("form");
	form.setAttribute("id", new Date().getMilliseconds());
	dojo.body().appendChild(form);
	for (k in postData) {
		if(postData[k] != null && postData[k] != undefined )
		input = vqq_create_hide_input(form, {name: k, value: postData[k]});
	}
	//console.log(form);
	status = dojo.byId("httpStatus");
	if(status){
		status.style.display = "";
	}
	var ss = url.split(g_basePath)[1];  
	getUrl = g_basePath + "api/" + ss;	
	dojo.xhrPost( {
		url :getUrl,
		form :form,
		handleAs :"json",
		load : function(data) {
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "none";
			}
			if(callback){
				callback(data, postData);
			}else{
				if (data && data.result != undefined && !data.result) {
					alert(data.err);
				} else if(data && data.result != undefined && data.result) {
					alert(data.msg);
				}
			} 	
		},
		error : function(error, args) {
			//console.log("error: %o", error);
			var status = dojo.byId("httpStatus");
			if(status){
				status.style.display = "";
				dojo.addClass(status, "errorStatus");
				status.innerHTML = "糟糕！好像网络或者服务器发生了点故障，请您刷新页面试试...";
			}
		}
	});
	dojo.destroy(form);
}

//vqq_create_element() == dojo.createElement();
function vqq_create_element(name, parent, attrs) {
	if (parent == null)
		return null;
	var e, str, k; 
	if(dojo.isIE && name=="img"){
		str = "<img onerror=\"this.src='" + basePath + "images/default/defaultLogo.jpg'\" ";
		if (attrs) {
			for (k in attrs){
				str += (k + "='" + attrs[k] + "' ");
			}
		}
		parent.innerHTML += str + " />";
		return parent.lastChild;
	}
	if(dojo.isIE && name=="input"){
		var str = "<input ";
		if (attrs) {
			for (k in attrs){
				str += (k + "='" + attrs[k] + "' ");
			}
		}
		parent.innerHTML += str + "/>";
		return parent.lastChild;
	}
	e = dojo.doc.createElement(name);
	parent.appendChild(e);
	if (attrs) {
		for (k in attrs) {
			if(dojo.isIE > 5){
				if(k == "style"){
					e.style.cssText = attrs[k];
				}
				else if(k == "onclick"){
					e.onclick = attrs[k];
				}
				else if(k == "class"){
					e.className = attrs[k];
				}
				else if(k == "type"){
					//
				}
				else{
					// e.setAttribute(k, attrs[k]);
					e[k] = attrs[k];
				}
			}else{
				e.setAttribute(k, attrs[k]);
			}
		}
	}
	if(name == "img"){
		e.setAttribute("onerror", "this.src = '" + basePath + "images/default/defaultLogo.jpg'");
	}
	return e;
}
// suggestion end 


function cancel_onClick_event(evt) {
	var evt = evt || event;
	if (evt.preventDefault) {
		evt.preventDefault();
		evt.stopPropagation();
	}
	else {
		evt.cancelBubble = true;
		evt.returnValue = false;
	}	
}

