// JavaScript Document

function proxycall(url, params, target){
	//var url = "proxy/mail.asp";		
	//alert(json_string(params));
	var callback = JSON_getValue(params, "callback");
	//alert(callback);
	var opt = {	
		method: 'post',		
		postBody: JSON2URL(params),
		//evalScripts: true,
		onSuccess: function(t){
			$(target).innerHTML = t.responseText;
			//callback();
			//alert(callback);
		},
		onComplete:function(t){
			//alert(callback);
			callback();
		},
		on404: function(t) {
			//alert('Error 404: location "' + t.statusText + '" was not found.');
			callback();
		},
		onFailure: function(t) {
			//alert('Error ' + t.status + ' -- ' + t.statusText);
			callback();
		}
	}

	new Ajax.Request(url, opt);
}	


function webcall_callback(params, target){
	var url = "proxy/webservice.asp";		
	//alert(json_string(params));
	var callback = JSON_getValue(params, "callback");

	//alert(callback);
	var opt = {	
		method: 'post',		
		postBody: JSON2URL(params),
		//evalScripts: true,
		onSuccess: function(t) {
			$(target).innerHTML = t.responseText;
			//alert(callback);
			callback();
		},
		on404: function(t) {
			//alert('Error 404: location "' + t.statusText + '" was not found.');
		},
		onFailure: function(t) {
			//alert('Error ' + t.status + ' -- ' + t.statusText);
		}
	}

	new Ajax.Request(url, opt);
}	


function webcall(params, target){
	//alert(JSON2URL(params));
	var url = "proxy/webservice.asp";		
	//alert(json_string(params));
	var opt = {	
		method: 'post',		
		postBody: JSON2URL(params),
		//evalScripts: true,
		onSuccess: function(t) {
			$(target).innerHTML = t.responseText;
		},
		on404: function(t) {
			//alert('Error 404: location "' + t.statusText + '" was not found.');
		},
		onFailure: function(t) {
			//alert('Error ' + t.status + ' -- ' + t.statusText);
		}
	}

	new Ajax.Request(url, opt);
}	

function webcalln(params, target){
	//alert(JSON2URL(params));
	var url = "proxy/webservicen.asp";		
	//alert(json_string(params));
	var opt = {	
		method: 'post',		
		postBody: JSON2URL(params),
		//evalScripts: true,
		onSuccess: function(t) {
			$(target).innerHTML = t.responseText;
		},
		on404: function(t) {
			//alert('Error 404: location "' + t.statusText + '" was not found.');
		},
		onFailure: function(t) {
			//alert('Error ' + t.status + ' -- ' + t.statusText);
		}
	}

	new Ajax.Request(url, opt);
}

function JSON_getValue(params, p){
	return 	params[p];
}

function JSON2URL(params){
	var result = "";
	for (p in params){
		if (result){
			result += '&';
		}
		result += p + "=" + params[p];	
	}
	return result;
}

function findClass(keywords){
	alert("找 '" + keywords + "'");	
	webcall({
				servicename:'webmarketnet',
				Operation:'ClassSearch',
				webid:'ms',
				dispid:'0100',
				SearchString:keywords,
				xslfile:'GetDisplayListXml.xsl'}, 'content');
	//http://scedna.sce.pccu.edu.tw/webmarketnet/pay/ClassSearch.aspx?WebId=MS&DispId=0100&SearchString=%E8%8B%B1%E6%AA%A2
	
}