_d = document;
_nv=navigator.appVersion.toLowerCase();
_f=false;_t=true;
h_ie4=(!_d.getElementById&&_d.all)?_t:_f;
h_ie5=(_nv.indexOf("msie 5.0")!=-1)?_t:_f;
h_ie55=(_nv.indexOf("msie 5.5")!=-1)?_t:_f;
h_ie6=(_nv.indexOf("msie 6.0")!=-1)?_t:_f;
isIE=(h_ie5||h_ie55||h_ie6)?_t:_f;

var text_enter_url = "请输入连接网址";
var text_enter_txt = "请输入连接说明";
var text_enter_image = "请输入图片网址";
var text_enter_sound = "请输入声音文件网址";
var text_enter_swf = "请输入FLASH文件地址";
var text_enter_ra = "请输入Real音乐网址";
var text_enter_rm = "请输入Real影片网址";
var text_enter_wmv = "请输入Media影片网址";
var text_enter_wma = "请输入Media音乐网址";
var text_enter_mov = "请输入QuichTime音乐网址";
var text_enter_sw = "请输入ShockWave音乐网址";
var text_enter_email = "请输入邮件网址";
var error_no_url = "您必须输入网址";
var error_no_txt = "您必须输入连接说明"
var error_no_title = "您必须输入首页主题";
var error_no_email = "您必须输入邮件网址";
var error_no_gset = "必须正确按照格式输入";
var error_no_gtxt = "必须输入文字";
var text_enter_guang1 = "文字的长度，颜色和边界大小";
var text_enter_guang2 = "要产生效果的文字！";
var text_enter_points = "请输入数字：如1000(即积分限制在1000点以下的用户不能浏览！)";
var error_no_points = "您必须输入数值，如1000";
var text_enter_money = "请输入数字：如1000(即金钱限制在1000以下的用户不能浏览！)";
var error_no_money = "您必须输入数值，如1000";
var text_enter_power = "请输入数字，如1000(即威望限制在1000以下的用户不能浏览！)";
var error_no_power = "您必须输入数值，如1000";
var text_enter_post = "请输入数字，如1000(即限制文章在1000以下的用户不能浏览！)";
var error_no_post = "您必须输入数值，如1000";
var text_enter_usercp = "请输入数字，如(即魅力限制在1000以下的用户不能浏览！)";
var error_no_usercp = "您必须输入数值，如1000";
var text_enter_usemoney = "请输入数字，如1000(即只有用户支付了1000点金钱才能浏览！)";
var error_no_usemoney = "您必须输入数值，如1000";



function HDLabEditor_GetCssID(HDLabEditorName) 
{
	cssID = HDLabEditorName;
	while (cssID.substring(0,1) == '_') 
	{
		cssID = cssID.substring(1);
	}
	return cssID;
}

function HDLabEditor_SetButtonStyle(buttonTD,style,checkstyle) 
{
	if (buttonTD == null) return;
	if (buttonTD.className != checkstyle)
		buttonTD.className = style;
	
}

function HDLabEditor_GetClassSubName(className) 
{
	underscore = className.indexOf("_");
	if (underscore < 0) return className;
	return className.substring(underscore+1);
}

function HDLabEditor_ButtonOver(theTD,HDLabEditorName,imageOver,imageDown)
{
	HDLabEditor_SetButtonStyle(theTD,HDLabEditor_GetCssID(HDLabEditorName)+'_ButtonOver',null);
	if(imageOver == 1 & theTD.childNodes.length && theTD.childNodes[0].tagName == "IMG"){
		oldSrc = theTD.childNodes[0].src;
		if (oldSrc.indexOf('.over.') == -1) {
			theTD.childNodes[0].src=oldSrc.substring(0, oldSrc.length-4) + ".over.gif";
		}
	}
}

function HDLabEditor_ButtonOut(theTD,HDLabEditorName,imageOver,imageDown) {
	HDLabEditor_SetButtonStyle(theTD,HDLabEditor_GetCssID(HDLabEditorName)+'_ButtonNormal',null);
	document.body.style.cursor = 'default';
	
	theTD.style.backgroundImage='';
	
	if(theTD.childNodes.length && theTD.childNodes[0].tagName == "IMG"){
		oldSrc = theTD.childNodes[0].src;
		if (oldSrc.indexOf('.over.') > 0) {
			theTD.childNodes[0].src=oldSrc.substring(0, oldSrc.length-9) + ".gif";
		}
		if (oldSrc.indexOf('.down.') > 0) {
			theTD.childNodes[0].src=oldSrc.substring(0, oldSrc.length-9) + ".gif";
		}
	}
}

function HDLabEditor_ButtonDown(theTD,HDLabEditorName,imageOver,imageDown) {
	document.body.style.cursor = 'default';
	HDLabEditor_SetButtonStyle(theTD,HDLabEditor_GetCssID(HDLabEditorName)+'_ButtonDown',null);
	
	if(imageDown == 1 && theTD.children.length && theTD.children[0].tagName == "IMG"){
		oldSrc = theTD.children[0].src;
		if (oldSrc.indexOf('.over.') > 0) {
			theTD.children[0].src=oldSrc.substring(0, oldSrc.length-9) + ".down.gif";
		}
	}
}

function HDLabEditor_ButtonUp(theTD,HDLabEditorName,imageOver,imageDown) {
	document.body.style.cursor = 'auto';
	HDLabEditor_SetButtonStyle(theTD,HDLabEditor_GetCssID(HDLabEditorName)+'_ButtonOver',null);
	
	if(imageOver == 1 && theTD.children.length && theTD.children[0].tagName == "IMG"){
		oldSrc = theTD.children[0].src;
		if (oldSrc.indexOf('.over.') == -1) {
			theTD.children[0].src=oldSrc.substring(0, oldSrc.length-4) + ".over.gif";
		}
	}
	
}

function HDLabEditor_Bold(HDLabEditorName) 
{
	fontbegin="[B]";
	fontend="[/B]";
	fontchuli(HDLabEditorName);
}
function HDLabEditor_Italic(HDLabEditorName) 
{
	fontbegin="[I]";
	fontend="[/I]";
	fontchuli(HDLabEditorName);
}
function HDLabEditor_Underline(HDLabEditorName) 
{
	fontbegin="[U]";
	fontend="[/U]";
	fontchuli(HDLabEditorName);
}

function HDLabEditor_JustifyCenter(HDLabEditorName) 
{
	fontbegin="[center]";
	fontend="[/center]";
	fontchuli(HDLabEditorName);
}
function HDLabEditor_JustifyLeft(HDLabEditorName) 
{
	fontbegin="[left]";
	fontend="[/left]";
	fontchuli(HDLabEditorName);
}
function HDLabEditor_JustifyRight(HDLabEditorName) 
{
	fontbegin="[right]";
	fontend="[/right]";
	fontchuli(HDLabEditorName);
}
function HDLabEditor_JustifyFull(HDLabEditorName) 
{
	fontbegin="[full]";
	fontend="[/full]";
	fontchuli(HDLabEditorName);
}

function HDLabEditor_Quote(HDLabEditorName)
{
	fontbegin="[Quote]";
	fontend="[/Quote]";
	fontchuli(HDLabEditorName);
}

function HDLabEditor_Fly(HDLabEditorName)
{
	fontbegin="[Fly]";
	fontend="[/Fly]";
	fontchuli(HDLabEditorName);
}

function HDLabEditor_Move(HDLabEditorName)
{
	fontbegin="[Move]";
	fontend="[/Move]";
	fontchuli(HDLabEditorName);
}

function HDLabEditor_SetFontSize(HDLabEditorName,name,size)
{
	fontbegin="[size="+size+"]";
	fontend="[/size]";
	fontchuli(HDLabEditorName);
}

function HDLabEditor_SetFontFace(HDLabEditorName,name,font)
{
	fontbegin="[face="+font+"]";
	fontend="[/face]";
	fontchuli(HDLabEditorName);
}

function HDLabEditor_SetFontForeColor(HDLabEditorName,name,color)
{
	fontbegin="[color="+color+"]";
	fontend="[/color]";
	fontchuli(HDLabEditorName);
}

function fontchuli(HDLabEditorName)
{
	if ((document.selection)&&(document.selection.type == "Text")) 
	{
		var range = document.selection.createRange();
		var ch_text=range.text;
		range.text = fontbegin + ch_text + fontend;
	} 
	else 
	{
		var editor=HDLabEditor_GetHiddenField(HDLabEditorName);
		editor.value=fontbegin + editor.value + fontend;
		editor.focus();
	}
}

function HDLabEditor_CreateLink(HDLabEditorName)
{
	var FoundErrors = '';
	var enterURL   = prompt(text_enter_url, "http://");
	var enterTxT   = prompt(text_enter_txt, enterURL);
	if (!enterURL)    
	{
		FoundErrors += "\n" + error_no_url;
	}
	if (!enterTxT)    
	{
		FoundErrors += "\n" + error_no_txt;
	}
	if (FoundErrors)  
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[URL="+enterURL+"]"+enterTxT+"[/URL]");
}

function HDLabEditor_CreateEmailLink(HDLabEditorName)
{
	var emailAddress = prompt(text_enter_email,"");
	if (!emailAddress) 
	{ 
		alert(error_no_email); 
		return; 
	}
	AddText(HDLabEditorName,"[EMAIL]"+emailAddress+"[/EMAIL]");
}

function HDLabEditor_InsertImage(HDLabEditorName)
{
	
	
	txt2=prompt("图片的宽度、高度","500,400");
	if (txt2!=null) 
	{
	    var FoundErrors = '';
	    var enterURL   = prompt(text_enter_image, "http://");
	    if (!enterURL) 
	    {
		    FoundErrors += "\n" + error_no_url;
	    }
	    if (FoundErrors) 
	    {
		    alert("错误！"+FoundErrors);
		    return;
	    }
	    AddTxt="[IMG="+txt2+"]"+enterURL;
		AddText(HDLabEditorName,AddTxt);
		AddTxt="[/IMG]";
		AddText(HDLabEditorName,AddTxt);
				
	     
	}
	else
	{
	    var FoundErrors = '';
	    var enterURL   = prompt(text_enter_image, "http://");
	    if (!enterURL) 
	    {
		    FoundErrors += "\n" + error_no_url;
	    }
	    if (FoundErrors) 
	    {
		    alert("错误！"+FoundErrors);
		    return;
	    }
	    AddTxt="[IMG=500,400]"+enterURL;
		AddText(HDLabEditorName,AddTxt);
		AddTxt="[/IMG]";
		AddText(HDLabEditorName,AddTxt);
	
	    
	}
	
		
	
}





function HDLabEditor_Glow(HDLabEditorName)
{
	var FoundErrors = '';
	var enterSET   = prompt(text_enter_guang1, "255,red,2");
	var enterTxT   = prompt(text_enter_guang2, "文字");
	if (!enterSET)    
	{
		FoundErrors += "\n" + error_no_gset;
	}
	if (!enterTxT)    
	{
		FoundErrors += "\n" + error_no_gtxt;
	}
	if (FoundErrors)  
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[glow="+enterSET+"]"+enterTxT+"[/glow]");
}	

function HDLabEditor_Shadow(HDLabEditorName)
{
	var FoundErrors = '';
	var enterSET   = prompt(text_enter_guang1, "255,blue,1");
	var enterTxT   = prompt(text_enter_guang2, "文字");
	if (!enterSET)    
	{
		FoundErrors += "\n" + error_no_gset;
	}
	if (!enterTxT)    
	{
		FoundErrors += "\n" + error_no_gtxt;
	}
	if (FoundErrors)  
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[SHADOW="+enterSET+"]"+enterTxT+"[/SHADOW]");
}

function HDLabEditor_Sound(HDLabEditorName)
{
	var FoundErrors = '';
	var enterURL   = prompt(text_enter_sound, "http://");
	if (!enterURL) 
	{
		FoundErrors += "\n" + error_no_url;
	}
	if (FoundErrors) 
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[SOUND]"+enterURL+"[/SOUND]");
}
	
function AddText(HDLabEditorName,text) 
{
	var editor=HDLabEditor_GetHiddenField(HDLabEditorName);
	if (editor.createTextRange && editor.caretPos) 
	{      
		var caretPos = editor.caretPos;      
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	}
	else 
		editor.value += text;
	editor.focus(caretPos);
}

function HDLabEditor_SetSpecilContent(HDLabEditorName,name,value) {
	switch(value)
	{
		case "Money":
			money(HDLabEditorName);
			break;
		case "Point":
			point(HDLabEditorName);
			break;
		case "UserCP":
			usercp(HDLabEditorName);
			break;
		case "Power":
			power(HDLabEditorName);
			break;
		case "Post":
			article(HDLabEditorName);
			break;
		case "replyview":
			replyview(HDLabEditorName);
			break;
		case "UseMoney":
			usemoney(HDLabEditorName);
			break;
		default:
	}
}

function point(HDLabEditorName) 
{
	var FoundErrors = '';
	var enterpoints = prompt(text_enter_points,"1000");
	if(!enterpoints)
	{
		FoundErrors += "\n" + error_no_points;
	}
	if (FoundErrors)
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[Point="+enterpoints+"][/Point]");
}

function money(HDLabEditorName)
{
	var FoundErrors = '';
	var entermoney  =prompt(text_enter_money,"1000");
	if (!entermoney)
	{
		FoundErrors += "\n" + error_no_money;
	}
	if (FoundErrors)
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[Money="+entermoney+"][/Money]");
}

function usemoney(HDLabEditorName)
{
	var FoundErrors = '';
	var entermoney  =prompt(text_enter_usemoney,"1000");
	if (!entermoney)
	{
		FoundErrors += "\n" + error_no_usemoney;
	}
	if (FoundErrors)
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[UseMoney="+entermoney+"][/UseMoney]");
}

function usercp(HDLabEditorName)
{
	var FoundErrors = '';
	var enterusercp  =prompt(text_enter_usercp,"1000");
	if (!enterusercp)
	{
		FoundErrors += "\n" + error_no_usercp;
	}
	if (FoundErrors)
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[UserCP="+enterusercp+"][/UserCP]");
}

function power(HDLabEditorName)
{
	var FoundErrors = '';
	var enterpower  =prompt(text_enter_power,"1000");
	if (!enterpower)
	{
		FoundErrors += "\n" + error_no_power;
	}
	if (FoundErrors)
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[Power="+enterpower+"][/Power]");
}

function article(HDLabEditorName)
{
	var FoundErrors = '';
	var enterpost  =prompt(text_enter_post,"1000");
	if (!enterpost)
	{
		FoundErrors += "\n" + error_no_post;
	}
	if (FoundErrors)
	{
		alert("错误！"+FoundErrors);
		return;
	}
	AddText(HDLabEditorName,"[Post="+enterpost+"][/Post]");
}

function replyview(HDLabEditorName)
{
	AddText(HDLabEditorName,"[replyview][/replyview]");
}

function HDLabEditor_InsertFlash(HDLabEditorName) 
{
	txt2=prompt("Flash高度，宽度","500,350");
	if(txt2!=null) 
	{
       txt=prompt("Flash 文件的地址","http://");
       if (txt!=null) 
		{
			if (txt2=="") 
			{             
				AddTxt="[flash=500,350]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/flash]";
				AddText(HDLabEditorName,AddTxt);
            } 
            else 
            {
				AddTxt="[flash="+txt2+"]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/flash]";
				AddText(HDLabEditorName,AddTxt);
			}  
		}
	}
}

function HDLabEditor_InsertDir(HDLabEditorName)
{
	txt2=prompt("Shockwave文件的宽度，高度","500,350");
	if (txt2!=null) 
	{
		txt=prompt("Shockwave文件的地址","请输入地址");
		if (txt!=null) {
			if (txt2=="") {
				AddTxt="[dir=500,350]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/dir]";
				AddText(HDLabEditorName,AddTxt);
			} else {
				AddTxt="[dir="+txt2+"]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/dir]";
				AddText(HDLabEditorName,AddTxt);
			}         
		} 
	}
}
       
function HDLabEditor_InsertRealPlay(HDLabEditorName) 
{
	txt2=prompt("视频的宽度，高度","550,400");
	if (txt2!=null) 
	{
		txt=prompt("视频文件的地址","请输入");
		if (txt!=null) {
			if (txt2=="") {
				AddTxt="[rm=550,400]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/rm]";
				AddText(HDLabEditorName,AddTxt);
			} else {
				AddTxt="[rm="+txt2+"]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/rm]";
				AddText(HDLabEditorName,AddTxt);
			}         
		} 
	}
}
	
	
function HDLabEditor_InsertMedia(HDLabEditorName)
{
	txt2=prompt("视频的宽度，高度","550,400");
	if (txt2!=null) 
	{
		txt=prompt("视频文件的地址","请输入");
		if (txt!=null) {
			if (txt2=="") {
				AddTxt="[mp=550,400]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/mp]";
				AddText(HDLabEditorName,AddTxt);
			} 
			else 
			{
				AddTxt="[mp="+txt2+"]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/mp]";
				AddText(HDLabEditorName,AddTxt);
			}         
		} 
	}
}


function HDLabEditor_InsertQuickTime(HDLabEditorName)
{
	txt2=prompt("视频的宽度，高度","550,400");
	if (txt2!=null) 
	{
		txt=prompt("视频文件的地址","请输入");
		if (txt!=null) {
			if (txt2=="") {
				AddTxt="[qt=550,400]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/qt]";
				AddText(HDLabEditorName,AddTxt);
			} else {
				AddTxt="[qt="+txt2+"]"+txt;
				AddText(HDLabEditorName,AddTxt);
				AddTxt="[/qt]";
				AddText(HDLabEditorName,AddTxt);
			}         
		} 
	}
}


function HDLabEditor_CSharpButton(HDLabEditorName)
{
	fontbegin="[code language=\"c#\"]";
	fontend="[/code]";
	fontchuli(HDLabEditorName);
}

function HDLabEditor_VBButton(HDLabEditorName)
{
	fontbegin="[code language=\"vb\"]";
	fontend="[/code]";
	fontchuli(HDLabEditorName);
}

function AddFileToHidden(fileName)
{
	var editor=HDLabEditor_GetHiddenField('UpFiles');
	if(editor.value != "")
	{
		editor.value += "," + fileName;
	}
	else
	{
		editor.value = fileName;
	}
}


function HDLabEditor_GetHiddenField(HDLabEditorName) {
	return document.getElementById(HDLabEditorName);
}

function QuickReply(eventobject)
{
	if(event.ctrlKey && window.event.keyCode==13)
	{
		__doPostBack(eventobject,'Save');
	}
}

function HDLabEditor_Smiley(HDLabEditorName)
{
	var addTxt = showModalDialog('dialog/emot.aspx?HDLabEditorName=' + HDLabEditorName, window, "dialogWidth:350px;dialogHeight:200px;help:no;scroll:no;status:no");
	if(addTxt != null)
	{
		AddText(HDLabEditorName,addTxt);
	}
}

function HDLabEditor_FontForeColorPicker(HDLabEditorName)
{
	var addTxt = showModalDialog('dialog/selColor.htm?action=forecolor&HDLabEditorName=' + HDLabEditorName, window, "dialogWidth:350px;dialogHeight:240px;help:no;scroll:no;status:no");
	if(addTxt != null)
	{
		addTxt = '[color=' + addTxt + '][/color]';
		AddText(HDLabEditorName,addTxt);
	}
}

function HDLabEditor_FontBackColorPicker(HDLabEditorName)
{
	var addTxt = showModalDialog('dialog/selColor.htm?action=backcolor&HDLabEditorName=' + HDLabEditorName, window, "dialogWidth:350px;dialogHeight:240px;help:no;scroll:no;status:no");
	if(addTxt != null)
	{
		addTxt = '[backcolor=' + addTxt + '][/backcolor]';
		AddText(HDLabEditorName,addTxt);
	}
}

function HDLabEditor_InsertTable(HDLabEditorName)
{
	fontbegin="[Table]";
	fontend="[/Table]";
	fontchuli(HDLabEditorName);
}

function HDLabEditor_FindReplace(HDLabEditorName)
{
	showModalDialog('dialog/findreplace.htm?HDLabEditorName=' + HDLabEditorName, window, "dialogWidth:320px;dialogHeight:160px;help:no;scroll:no;status:no");
}

function HDLabEditor_Help(HDLabEditorName)
{
	showModalDialog('dialog/help.htm?HDLabEditorName=' + HDLabEditorName, window, "dialogWidth:720px;dialogHeight:400px;help:no;scroll:no;status:no");
}
