var RESPONSE_CODE_SYSTEM_ERROR = -10000;
var RESPONSE_CODE_NO_LOGIN = 10000;

function getHtml(resourceAddress){
	
	var html_ = "";
	
	try{		
		$.ajax({type:"POST",
			    dataType:"html",
				async:false,
				url:resourceAddress, 
		        success:function (html) {
			     	html_ = html;
		    	},error:function(e){
		    		html_ = getResponseErrorData();
		    	}
		 });	 
	 }catch(e){ 
	 	html_ = getResponseErrorData();
	 }
	 
	 return html_;	
}

function getScript(resourceAddress,success){
	
	//response - 包含来自请求的结果数据
	//status - 包含请求的状态（"success", "notmodified", "error", "timeout" 或 "parsererror"）
	success = success || function(response,status){};
	
	$.getScript(resourceAddress,success);
	
}

function getScriptSync(resourceAddress,success){
	$.ajax({
		  url: resourceAddress,
		  dataType: "script",
		  async:false,
		  success: success
	});
}

function addCSS(href) {
    var link = document.createElement('link');
    link.type = 'text/css';
    link.rel = 'stylesheet';
    link.href = href;
    document.getElementsByTagName("head")[0].appendChild(link);
}

function submitForm(formId,callback){

	callback = callback || function(p){};
	
	var	ajaxReq = function(){
								try{ 	
									$("#"+formId).ajaxSubmit({//依赖jquery.form.js文件
														dataType : "json",
														async : false,
														success : function (json) {								
															callback(json);									
														},
														error : function(){
															callback(getResponseErrorData());
														}
													});
								 }catch(e){ 	
								 	callback(getResponseErrorData()); 	
								 }
							 };
	
	loadJqueryFormJS(ajaxReq);
							 	
}

var jqueryFormJSisExist = false;
function loadJqueryFormJS(success){

	if(!jqueryFormJSisExist){
		$.getScript("gpsonline/js/jquery.form.js",function(){
										jqueryFormJSisExist = true;
										success();
									});
	}else{
		success();
	}
}

function doRequest(requestAddress,parms,callback){
	
	callback = callback || function(p){};
	
	try{ 
		$.ajax({
				type : "POST",
			    dataType : "json",
				async : false,
				url : requestAddress, 
				data : parms,
		        success : function (json) {        	
			     	callback(json);		     	
		    	},
		    	error : function(e){	    	
		    		callback(getResponseErrorData());		    		
		    	}
		 });		 
	 }catch(e){	 	
	 	callback(getResponseErrorData());	 	
	 }	
}

function asyncdoRequest(requestAddress,parms,callback){
	
	callback = callback || function(p){};
	
	try{ 
		$.ajax({
				type : "POST",
			    dataType : "json",
				url : requestAddress, 
				data : parms,
		        success : function (json) {        	
			     	callback(json);		     	
		    	},
		    	error : function(e){	    	
		    		callback(getResponseErrorData());		    		
		    	}
		 });		 
	 }catch(e){	 	
	 	callback(getResponseErrorData());	 	
	 }	
}

function getResponseErrorData(){
	return {flag:false,statecode : RESPONSE_CODE_SYSTEM_ERROR};
}