﻿

//表单效果
$(function(){
	//输入框的效果
	$(".text").focus(function(){
		$(this).addClass("text-onfocus");						  
	}).blur(function(){
		$(this).removeClass("text-onfocus");
	});
	//表单块效果
	//$("div.Form div.Title").css("cursor","pointer").click(function(){
	//	$(this).next("div.Content").slideToggle("slow");									   
	//})
})

//表单提交
$(function(){
	var valid=$("#HankxForm").validate({
			submitHandler: function(form) {
				$(":submit",form).blur().addClass("loading").addClass("disabled").get(0).disabled=true;
				$(form).ajaxSubmit({
					success:function(msg)
					{
						//alert(msg);						
						var d=System.Msg.HtmlToJson(msg);
						switch(parseInt(d.code))
						{
							case 0:
								if(!_close){
									var _close=function(){
										System.Location(d.redirect);
										return true;
									}
								}
								$(":submit",form).removeClass("loading");
								top.System.Dialog.Success(d.title,d.description,{onclose:_close,onsubmit:_close});
								break;
							case -1:
								top.System.Dialog.Error('Unkown Error',msg);
								$(":submit",form).removeClass("disabled").removeClass("loading").get(0).disabled=false;
								break;
							default:
								top.System.Dialog.Error(d.title,d.description);
								$(":submit",form).removeClass("disabled").removeClass("loading").get(0).disabled=false;
								break;
						}
					}
				});
				return false; 
			}
	});
})



//上传图片
function UploadImage(ImageTo,InputType)
{
	var Action='upload';
	var FileName='';
	if(InputType=='input')
	{
		FileName=$("input[name="+ImageTo+"]").val();
		
		if(FileName.length>5)
		{
			Action='preview';
		}
	}
	top.System.Dialog.Open('图片管理器',System.Directory.SystemFiles+"/upload/image.asp?action="+Action+"&PageUID="+System.Page.UID+"&imageto="+escape(ImageTo)+"&InputType="+escape(InputType)+"&FileName="+FileName,{id:"UploadImage",width:"600px",zindex:1020});

}

function InsertImage(name,value,type){
	top.System.Dialog.Hide('UploadImage','',true);
	switch(type.toLowerCase()){
		case "input":
			InsertToInput(name,value);
			break;
		case "fckeditor":
			InsertToFCK(name,'<img src=\"'+value+'\"/>');
			break;				
	}
	
}
function InsertToInput(name,value){
	$("input[name="+name+"]").val(value);
}
function InsertToFCK(name,value)
{
	var oEditor = FCKeditorAPI.GetInstance(name) ;
	if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
	{
		oEditor.InsertHtml(value) ;
	}
	else{
		alert( '必须切换到编辑模式才能插入' ) ;
	}
}

//模板选择
function SelectTemplate(name,options){
	var settings=$.extend({},{id:"SelectTemplate",width:"700px"},options);
	top.System.Dialog.Open("模板选择器",System.Directory.SystemFiles+"/template/select.asp?action=select&datato="+name+"&file="+$("#"+name).val(),settings);		
}
function InsertTemplate(name,value){
	top.System.Dialog.Hide('SelectTemplate','',true);
	$("input[name="+name+"]").val(value);
}