/**
 * @author supertaoer@gmail.com
 */
/**
 * make html select from json
 * @param JSON data
 * @return string
 */

/**
 * access an url by http::get method
 * @param string url
 * @param referer function callBack
 * @return JSON
 */
function getUrlByAjax(url, callBack) {
	
	$.getJSON(
		url,
		callBack);
};

/**
 * make base select html
 * @param JSON data
 * 
 * @return string
 */
function jsonToHtmlSelect(data, htmlId, htmlName, htmlValue, defaultString) {
	
	var str = '<select id="' + htmlId + '" name="' + htmlId + '" class="cbsmSelect">';

	str += '<option value="0">请选择' + defaultString + '...</option>';

	$.each(data, function(i, item){
		
		if ( String == item.constructor) {
		
			str += '<option value="' + i + '">' + item + '</option>';
		} else {
			
			str += '<option value="' + item[htmlName] + '">' + item[htmlValue] + '</option>';
		} 
	});
	
	str += '</select>';
	
	return str;
}

/**
 * make base radio html
 * @param JSON data
 * 
 * @return string
 */
function jsonToHtmlRadio(data, htmlId, htmlName, htmlValue) {
	
	var str = '';
	
	$.each(data, function(i, item){
		
		if ( String == item.constructor) {
		
			str += '<input type="radio" id="' + htmlId + '" name="' + htmlId + '" value="' + i + '" />&nbsp;<label for="' + htmlId + '">' + item + '</label>';
		} else {
			
			str += '<input type="radio" id="' + htmlId + '" name="' + htmlId + '" value="' + item[htmlName] + '" />&nbsp;<label for="' + htmlId + '">' + item[htmlValue] + '</label>';
		} 
	});
	
	return str;
}