function loadCityData(stateid, objcityid)
{
	var requesturl = '?Checks_ajax&type=citydata&stateid='+stateid;
	new Ajax.Request(requesturl,
	  {
		method: 'get',
		onSuccess: function(transport){
			var citydata;
			eval(transport.responseText);
			loadtolist(citydata, objcityid);
		},
		onFailure: function(){
		}
	  });
}

function loadSortData(tradecode, objsortid)
{
	var requesturl = '?Checks_ajax&type=sortdata&tradecode='+tradecode;
	new Ajax.Request(requesturl,
	  {
		method: 'get',
		onSuccess: function(transport){
			var sortdata;
			eval(transport.responseText);
			loadtolist(sortdata, objsortid);
		},
		onFailure: function(){
		}
	  });
}


function loadtolist(arrdata, objid)
{
	var obj = document.getElementById(objid);
	obj.options.length = 0;
	obj.options.length = arrdata.length;
	for(var i=0; i<arrdata.length; i++)
	{
		obj.options[i].text = arrdata[i][1];
		obj.options[i].value = arrdata[i][0];
	}
	return;
}

var preloadimg = new Array();
function updateFileList(arrfileinfo, divid)
{
	var objdiv = document.getElementById(divid);
	var fileitems = '';
	for(var i=0; i<arrfileinfo.length; i++)
	{
		preloadimg[i] = new Image();
		preloadimg[i].src = arrfileinfo[i][2];
		fileitems += '<li>' + arrfileinfo[i][1] + '&nbsp;&nbsp; [<a href="javascript:void(0)" onclick="insertImage(\'' + arrfileinfo[i][2] + '\', \'body1\')" title="将图片插入到编辑器中">插入</a>] [<a href="javascript:deleteFile('+ arrfileinfo[i][0] +', \'' + arrfileinfo[i][2] + '\')" onclick="return confirm(\'删除图片后，编辑框中已经插入的该图片也一会并删除。确定要从服务器上将该文件删除吗？\')" title="从服务器上将该文件删除">删除</a>]</li>';
	}
	fileitems = "<ol>" + fileitems + "</ol>";
	objdiv.innerHTML = fileitems;
}

function insertImage(value, instancename)
{
	value = '<img src="' + value + '" />';
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(instancename) ;

	// Check the active editing mode.
	if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
	{
		// Insert the desired HTML.
		oEditor.InsertHtml( value ) ;
	}
	else
		alert( 'You must be on WYSIWYG mode!' ) ;
}

function SetContents(instancename, strhtml)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(instancename) ;

	// Set the editor contents (replace the actual one).
	oEditor.SetHTML( strhtml ) ;
}

function insertHTML ( strhtml, instancename )
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(instancename) ;

	// Check the active editing mode.
	if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
	{
		// Insert the desired HTML.
		oEditor.InsertHtml( strhtml ) ;
	}
	else
	{
		alert( 'You must be on WYSIWYG mode!' ) ;
	}
}

function insertYouTube(str, instancename)
{
	str = '[youtube]' + str + '[/youtube]';
	insertHTML(str, instancename);
}

function GetContents(instancename)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(instancename) ;

	// Get the editor contents in XHTML.
	return oEditor.GetXHTML( true ) ;		// "true" means you want it formatted.
}
