/* ================================ 渠道Tips ================================ */
var channelInfo = new Array();
channelInfo["sms"] 	= {
	className 	: "viaSms", 
	url 		: "#", 
	text 		: "如何用手机短信发字条?",
	tipsId		: "scripFromSms"
};
channelInfo["3g"] 	= {
	className 	: "viaWap", 
	url 		: "#", 
	text 		: "如何用手机上网发字条?",
	tipsId		: "scripFromCell"
};
channelInfo["mqq"] 	= {
	className 	: "viaWeb", 
	url 		: "http://mobile.qq.com/download_cm.jsp?from=lovewall", 
	text 		: "",
	tipsId		: ""
};
channelInfo[""] 	= {
	className 	: "viaWeb", 
	url 		: appPrefix+"/step1.jsp", 
	text 		: "",
	tipsId		: ""
};

/* ================================ item属性对应字条样式 ================================ */
var sharp 	= new Array();	//item的形状属性
var layout 	= new Array();	//item的布局属性
var color 	= new Array();	//item的色调属性
/*	  item属性	  className			  含义		*/
sharp["square"] = "square";			//正方形
sharp["rec"] 	= "rectangle";		//长方形
layout["up"] 	= "layoutTop";		//上
layout["under"] = "layoutBottom";	//下
layout["left"] 	= "layoutLeft";		//左
layout["right"] = "layoutRight";	//右
layout["in1"] 	= "layoutCenterT1";	//中1
layout["in2"] 	= "layoutCenterT2";	//中2
color["black"] 	= "colorBlack";		//黑
color["white"] 	= "colorWhite";		//白
color["red"] 	= "colorRed";		//红
color["yellow"] = "colorYellow";	//黄
color["lime"] 	= "colorLime";		//莱姆色
color["cyan"] 	= "colorCyan";		//青色
color["blue"] 	= "colorBlue";		//蓝色
color["fuchsia"]= "colorFuchsia";	//
color["gray"] 	= "colorGray";		//
color["silver"] = "colorSilver";	//
color["maroon"] = "colorMaroon";	//
color["olive"] 	= "colorOlive";		//
color["green"] 	= "colorGreen";		//
color["teal"] 	= "colorTeal";		//
color["navy"] 	= "colorNavy";		//
color["purple"] = "colorPurple";	//
		
function ScripBuilder2(){
	var buildHead = function(scrip, positions){
		var headDiv = document.createElement("div");
		headDiv.setAttribute("class", "Num");
		headDiv.setAttribute("className", "Num");		

		var scripNo = document.createTextNode("字条编号：" + scrip.iRealScripNo);
		headDiv.appendChild(scripNo);
		
		var closeImg = document.createElement("img");
		closeImg.setAttribute("src", "http://source1.qq.com/lovewall/item_3/lovewall/images/icon_scrip_close.gif");
		closeImg.style.cssText = "height:9px;width:9px";
		closeImg.setAttribute("alt", "关闭字条");		
		if(typeof delMessage == "function"){
			Event.observe(closeImg, "click", delMessage, scrip.iRealScripNo);
		}	
		//headDiv.appendChild(closeImg);
		
		var minimizeImg = document.createElement("img");
		minimizeImg.setAttribute("src", "http://source1.qq.com/lovewall/item_3/lovewall/images/icon_scrip_minimize.gif");
		minimizeImg.setAttribute("alt", "最小化字条");
		minimizeImg.style.cssText = "height:9px;width:9px";
		if(typeof dbrun == "function"){
			Event.observe(minimizeImg, "click", dbrun, scrip.iRealScripNo);		
		}
		headDiv.appendChild(minimizeImg);

		return headDiv;
	}
	var buildBody = function(scrip, positions){
		var contentP = document.createElement("p");
		contentP.setAttribute("class","Detail");
		contentP.setAttribute("className", "Detail");
		
		var contentImg = document.createElement("img");
		
		var upMark = scrip.upMark;
		var url = getItemDefault(upMark, "s");
		if(scrip.items.length > 0 && scrip.items[0].sPayStatus != "N"){
			url = scrip.items[0].sItemBaseUrl + scrip.items[0].sItemUrl;
			if(scrip.version == "v3"){
				url = url.substring(0,url.lastIndexOf("_"))+"_50-50-V3"+url.substring(url.lastIndexOf("."));
			}
			if(url.length == 0 && scrip.sMood.length != 0){
				url = scrip.sMood;
			}
		}
		contentImg.setAttribute("src",url);
		contentImg.setAttribute("class","Heart");
		contentImg.setAttribute("className", "Heart");
		contentP.appendChild(contentImg);
		
		var receiverSpan = document.createElement("span");
		receiverSpan.setAttribute("class","Head");
		receiverSpan.setAttribute("className", "Head");
		receiverSpan.innerHTML = scrip.sRecvNick;
		contentP.appendChild(receiverSpan);
		
		var contentBr = document.createElement("br");
		contentP.appendChild(contentBr);
		
		var contentSpan = document.createElement("span");
		contentSpan.innerHTML = scrip.sScrip;
		contentP.appendChild(contentSpan);

		return contentP;
	}
	var buildChannel = function(scrip, positions){
		var channelP = document.createElement("p");
		channelP.setAttribute("class","Channel");
		channelP.setAttribute("className", "Channel");
				
		var hr = "";
		var cont = "";
		var key = "";
		if("mqq" == scrip.upMark){
			hr = "http://mobile.qq.com/download_cm.jsp?from=lovewall";
			cont = "立即下载手机QQ";
		}
		else if("3g" == scrip.upMark){
			hr = "http://3gqq.qq.com?from=lovewall";
			cont = "来自手机腾讯网";
			key = "scripFromCell";
		}
		else if("sms" == scrip.upMark){
			hr = "#";
			cont = "用手机发表字条";
			key = "scripFromSms";
		}
		
		var channelA = document.createElement("span");
		//channelA.setAttribute("href", hr);
		channelA.style.cursor = "hand";
		if(typeof showChannelTips == "function"){
			Event.observe(channelA, "mousemove", showChannelTips, key);
		}
		if(typeof hideChannelTips == "function"){
			Event.observe(channelA, "mouseout", hideChannelTips, key);
		}
		var channelText = document.createTextNode(cont);
		channelA.appendChild(channelText);
		channelP.appendChild(channelA);

		return channelP;
	}
	var buildSign = function(scrip, positions){
		var signP = document.createElement("p");
		signP.setAttribute("class","Sign");
		signP.setAttribute("className", "Sign");
		
		var signText = document.createTextNode(scrip.sNick);
		signP.appendChild(signText);
		return signP;
	}
	var buildComment = function(scrip, positions){
		var disP = document.createElement("p");
		disP.setAttribute("class","Dis");
		disP.setAttribute("className", "Dis");
		//disP.setAttribute("onclick","showDis("+scrip.iRealScripNo+")");
		//disP.onclick = showDis;
		var disText = document.createTextNode("评论(" + scrip.sDiscussCount +")");
		disP.appendChild(disText);
		
		if(typeof showCommit == "function"){
			Event.observe(disP, "click", showCommit, scrip.iRealScripNo);
		}

		return disP;
	}
	var buildDate = function(scrip, positions){
		var dateP = document.createElement("p");
		dateP.setAttribute("class","Date");
		dateP.setAttribute("className", "Date");
		dateP.innerHTML = scrip.sUpTime;

		return dateP;
	}
	var buildStyle = function(scrip, positions){
		var styleDiv = document.createElement("div");
		styleDiv.setAttribute("class", "Style"+scrip.sColor);
		styleDiv.setAttribute("className", "Style"+scrip.sColor);
		return styleDiv;
	}
	var buildFrame = function(scrip, positions){
		var scripDiv = document.createElement("div");
		scripDiv.setAttribute("scripType", "v2");
		scripDiv.setAttribute("id", scripIdPrefix + scrip.iRealScripNo);
		scripDiv.setAttribute("class", "Message");
		scripDiv.setAttribute("className", "Message");
		scripDiv.style.cssText = "position:absolute; left:"+positions.x+"px;top:"+positions.y+"px;z-index:"+positions.z;
		
		if(typeof handleDown == "function"){
			Event.observe(scripDiv, "mousedown", handleDown, scrip.iRealScripNo);
		}
		if(typeof dbrun == "function"){
			Event.observe(scripDiv, "dblclick", dbrun, scrip.iRealScripNo);	
		}
		
		return scripDiv;
	}
	this.assemble = function(scrip, positions){
		var frame = buildFrame(scrip, positions);
		var style = buildStyle(scrip, positions);
		var head = buildHead(scrip, positions);
		var body = buildBody(scrip, positions);
		var channel = buildChannel(scrip, positions);
		var sign = buildSign(scrip, positions);
		var comment = buildComment(scrip, positions);
		var date = buildDate(scrip, positions);
		style.appendChild(head);
		style.appendChild(body);
		style.appendChild(channel);
		style.appendChild(sign);
		style.appendChild(comment);
		style.appendChild(date);
		frame.appendChild(style);
		return frame;
	}
}

function ScripBuilder3Simple(){
	var buildBg = function(){
		var bgSpan = document.createElement("span");
		bgSpan.setAttribute("class", "bg");
		bgSpan.setAttribute("className", "bg");
		bgSpan.innerHTML = " ";
		return bgSpan;
	}
	var buildItem = function(scrip, positions){
		var itemSpan = document.createElement("span");
		itemSpan.setAttribute("class", "item");
		itemSpan.setAttribute("className", "item");
		var upMark = scrip.upMark;
		var url = getItemDefault(upMark, "c");
		if(scrip.items.length > 0 && scrip.items[0].sPayStatus != "N"){
			var _url = scrip.items[0].sItemBaseUrl + scrip.items[0].sItemUrl;
			if(scrip.version == "v3"){
				_url = _url.substring(0,_url.lastIndexOf("_"))+"_50-50-V3"+_url.substring(_url.lastIndexOf("."));
			}
			if(_url.length != 0){
				url = _url;
			}
			/*
			if(url.length == 0 && scrip.sMood.length != 0){
				url = scrip.sMood;
			}
			*/
		}
		itemSpan.style.cssText = "background:url("+url+") left top no-repeat;";
		return itemSpan;
	}
	var buildTo = function(scrip, positions){		
		var toStrong = document.createElement("span");
		toStrong.setAttribute("class","to");
		toStrong.setAttribute("className", "to");
		toStrong.setAttribute("id",scripIdPrefix + scrip.iRealScripNo + "_title");
		toStrong.innerHTML = f13580_parseTitle(scrip.scrip_title);
		return toStrong; 
	}
	var buildContent = function(scrip, positions){
		var contentP = document.createElement("span");
		contentP.setAttribute("class","content");
		contentP.setAttribute("className", "content");
		contentP.setAttribute("id",scripIdPrefix + scrip.iRealScripNo + "_content");
		contentP.innerHTML = f13580_parseContent(scrip.scrip_content);
		return contentP;
	}
	var buildFooter = function(scrip, positions){
		var dateSpan = document.createElement("span");
		dateSpan.setAttribute("class","footer");
		dateSpan.setAttribute("className", "footer");
		// var scripTime = scrip.sUpTime.substring(0,scrip.sUpTime.indexOf(" "));
		dateSpan.innerHTML = ' ';
		return dateSpan;
	}
	var buildFrom = function(scrip, positions){
		var formStrong = document.createElement("strong");
		formStrong.setAttribute("class","from");
		formStrong.setAttribute("className", "from");
		formStrong.innerHTML = scrip.sNick;
		return formStrong;
	}
	var buildDate = function(scrip, positions){
		var dateSpan = document.createElement("span");
		dateSpan.setAttribute("class","date");
		dateSpan.setAttribute("className", "date");
		var scripTime = scrip.sUpTime.substring(0,scrip.sUpTime.indexOf(" "));
		dateSpan.innerHTML = scripTime;
		return dateSpan;
	}
	var buildComment = function(scrip, positions){
		var commentA = document.createElement("a");
		commentA.setAttribute("class", "comment");
		commentA.setAttribute("className", "comment");
		commentA.setAttribute("href", appPrefix+"/note.jsp?scrip="+scrip.iRealScripNo);
		commentA.setAttribute("title", "我要评论");
		commentA.setAttribute("target", "_blank"); 
		commentA.innerHTML = "评论("+scrip.sDiscussCount+")";		
		return commentA;
	} 
	var buildChannel = function(scrip, positions){
		var className 	= channelInfo[scrip.upMark].className;
		var text 		= channelInfo[scrip.upMark].text;
		var url 		= channelInfo[scrip.upMark].url;
		var tipsId		= channelInfo[scrip.upMark].tipsId;
		
		var channelA = document.createElement("span");
		channelA.setAttribute("class"		, className);
		channelA.setAttribute("className"	, className);
		//channelA.setAttribute("href"		, url);
		channelA.style.cursor = "hand";
		channelA.setAttribute("title"		, text);
		channelA.innerHTML = text;
		if(typeof showChannelTips == "function"){
			Event.observe(channelA, "mousemove", showChannelTips, tipsId);
		}
		if(typeof hideChannelTips == "function"){
			Event.observe(channelA, "mouseout", hideChannelTips, tipsId);
		}
		return channelA;
	}	
	var buildResize = function(scrip, positions){
		var resizeA = document.createElement("del");
		resizeA.setAttribute("class", "maximize");
		resizeA.setAttribute("className", "maximize");
		resizeA.setAttribute("title", "修改");
		resizeA.innerHTML = "修改";		
		if(typeof handleDown == "function"){
			// Event.observe(resizeA, "click", dbrun, scrip.iRealScripNo);		
			Event.observe(resizeA, "click", f13580_start_editor, scrip.iRealScripNo);	
		}
		return resizeA;
	}
	var buildClose = function(scrip, positions){
		var closeA = document.createElement("del");
		closeA.setAttribute("class","close");
		closeA.setAttribute("className", "close");
		closeA.setAttribute("title", "删除");
		closeA.innerHTML = "删除";		
		if(typeof delMessage == "function"){
			Event.observe(closeA, "click", delMessage, scrip.iRealScripNo);
		}		
		return closeA;
	}
	var buildScrip = function(scrip, positions){
		var scripDiv = document.createElement("li");
		scripDiv.setAttribute("scripType", "v3simple");
		scripDiv.setAttribute("id", scripIdPrefix + scrip.iRealScripNo);
		scripDiv.setAttribute("class", "preview");
		scripDiv.setAttribute("className", "preview");
		// scripDiv.style.cssText = "left:"+positions.x+"px;top:"+positions.y+"px;z-index:"+positions.z;
		scripDiv.style.cssText = "left:"+scrip.pos_x+"px;top:"+scrip.pos_y+"px;z-index:"+scrip.pos_z;
		if(typeof handleDown == "function"){
			Event.observe(scripDiv, "mousedown", handleDown, scrip.iRealScripNo);
		}
		if(typeof dbrun == "function"){
			Event.observe(scripDiv, "dblclick", dbrun, scrip.iRealScripNo);	
		}		
		return scripDiv;
	}
	this.assemble = function(scrip, positions){
		if(!scrip || scrip.iRealScripNo<0) return;
		//var bg		= buildBg(scrip, positions);
		//var item 	= buildItem(scrip, positions);
		var to 		= buildTo(scrip, positions);
		var content = buildContent(scrip, positions);			
		//var from 	= buildFrom(scrip, positions);		
		//var date 	= buildDate(scrip, positions);		
		//var comment = buildComment(scrip, positions);
		//var channel	= buildChannel(scrip, positions);
		var resize 	= buildResize(scrip, positions);
		var close 	= buildClose(scrip, positions);
		var scrip 	= buildScrip(scrip, positions);
		//var footer = buildFooter(scrip, positions);
		
		// scrip.appendChild(bg);
		// scrip.appendChild(item);
		scrip.appendChild(to);
		// content.appendChild(footer);
		scrip.appendChild(content);
		// scrip.appendChild(from);
		// scrip.appendChild(date);
		// scrip.appendChild(comment);
		// scrip.appendChild(channel);
		scrip.appendChild(resize);
		scrip.appendChild(close);
		
		return scrip;
	}
}

function ScripBuilder3Full(){
	var buildItem = function(scrip, positions){
		var itemSpan = document.createElement("span");
		itemSpan.setAttribute("class", "item");
		itemSpan.setAttribute("className", "item");
		var upMark = scrip.upMark;
		var url = getItemDefault(upMark, "h");
		if(scrip.items.length > 0 && scrip.items[0].sPayStatus != "N"){
			url = scrip.items[0].sItemBaseUrl + scrip.items[0].sItemUrl;
			if(url.length == 0 && scrip.sMood.length != 0){
				url = scrip.sMood;
			}
		}
		itemSpan.style.cssText = "background:url("+url+")";
		return itemSpan;
	}
	var buildNumber = function(scrip, positions){		
		var numberSpan = document.createElement("span");
		numberSpan.setAttribute("class","number");
		numberSpan.setAttribute("className", "number");
		numberSpan.innerHTML = "字条编号:"+scrip.iRealScripNo;
		return numberSpan;
	}
	var buildTo = function(scrip, positions){		
		var toStrong = document.createElement("strong");
		toStrong.setAttribute("class","to");
		toStrong.setAttribute("className", "to");
		toStrong.innerHTML = scrip.sRecvNick;
		return toStrong;
	}
	var buildContent = function(scrip, positions){
		var contentP = document.createElement("span");
		contentP.setAttribute("class","content");
		contentP.setAttribute("className", "content");
		contentP.innerHTML = scrip.sScrip;
		return contentP;
	}
	var buildFrom = function(scrip, positions){
		var formStrong = document.createElement("strong");
		formStrong.setAttribute("class","from");
		formStrong.setAttribute("className", "from");
		formStrong.innerHTML = scrip.sNick;
		return formStrong;
	}
	var buildDate = function(scrip, positions){
		var dateSpan = document.createElement("span");
		dateSpan.setAttribute("class","date");
		dateSpan.setAttribute("className", "date");
		//var scripTime = scrip.sUpTime.substring(0,scrip.sUpTime.indexOf(" "));
		var scripTime = scrip.sUpTime;
		dateSpan.innerHTML = scripTime;
		return dateSpan;
	}
	var buildComment = function(scrip, positions){
		var commentA = document.createElement("a");
		commentA.setAttribute("class", "comment");
		commentA.setAttribute("className", "comment");
		commentA.setAttribute("href", appPrefix+"/note.jsp?scrip="+scrip.iRealScripNo);
		commentA.setAttribute("title", "我要评论");
		commentA.setAttribute("target", "_blank"); 
		commentA.innerHTML = "我要评论("+scrip.sDiscussCount+")";		
		return commentA;
	}
	var buildChannel_ = function(scrip, positions){
		var className;
		var text;
		var url;
		className = "viaWeb";
		url = "#";
		text = "点击发字条";
		
		var channelA = document.createElement("a");
		channelA.setAttribute("class", className);
		channelA.setAttribute("className", className);
		channelA.setAttribute("href", "#");
		channelA.setAttribute("title", text);
		channelA.innerHTML = text;		
		return channelA;
	}
	var buildChannel = function(scrip, positions){
		var className 	= channelInfo[scrip.upMark].className;
		var text 		= channelInfo[scrip.upMark].text;
		var url 		= channelInfo[scrip.upMark].url;
		var tipsId		= channelInfo[scrip.upMark].tipsId;
		
		var channelA = document.createElement("span");
		channelA.setAttribute("class", className);
		channelA.setAttribute("className", className);
		//channelA.setAttribute("href", url);
		channelA.style.cursor = "hand";
		channelA.setAttribute("title", text);
		channelA.innerHTML = text;
		if(typeof showChannelTips == "function"){
			Event.observe(channelA, "mousemove", showChannelTips, tipsId);
		}
		if(typeof hideChannelTips == "function"){
			Event.observe(channelA, "mouseout", hideChannelTips, tipsId);
		}
		return channelA;
	}		
	var buildResize = function(scrip, positions){
		var resizeA = document.createElement("del");
		resizeA.setAttribute("class", "minimize");
		resizeA.setAttribute("className", "minimize");
		resizeA.setAttribute("title", "最小化字条");
		resizeA.innerHTML = "最小化字条";
		if(typeof handleDown == "function"){
			Event.observe(resizeA, "click", dbrun, scrip.iRealScripNo);		
		}
		return resizeA;
	}
	var buildClose = function(scrip, positions){
		var closeA = document.createElement("del");
		closeA.setAttribute("class","close");
		closeA.setAttribute("className", "close");
		closeA.setAttribute("title", "关闭字条");
		closeA.innerHTML = "关闭字条";		
		if(typeof delMessage == "function"){
			Event.observe(closeA, "click", delMessage, scrip.iRealScripNo);
		}		
		return closeA;
	}
	var buildScrip = function(scrip, positions){
		var scripDiv = document.createElement("li");
		scripDiv.setAttribute("scripType", "v3full");
		scripDiv.setAttribute("id", scripIdPrefix + scrip.iRealScripNo);
		var styleText = buildV3FullStyle(scrip);
		scripDiv.setAttribute("class", styleText);
		scripDiv.setAttribute("className", styleText);;
		scripDiv.style.cssText = "left:"+positions.x+"px;top:"+positions.y+"px;z-index:"+positions.z;		
		if(typeof handleDown == "function"){
			Event.observe(scripDiv, "mousedown", handleDown, scrip.iRealScripNo);
		}
		if(typeof dbrun == "function"){
			Event.observe(scripDiv, "dblclick", dbrun, scrip.iRealScripNo);	
		}		
		return scripDiv;
	}
	this.assemble = function(scrip, positions){		
		var item 	= buildItem(scrip, positions);
		var number	= buildNumber(scrip, positions);
		var to 		= buildTo(scrip, positions);
		var content = buildContent(scrip, positions);			
		var from 	= buildFrom(scrip, positions);		
		var date 	= buildDate(scrip, positions);		
		var comment = buildComment(scrip, positions);		
		var channel	= buildChannel(scrip, positions);
		var resize 	= buildResize(scrip, positions);
		var close 	= buildClose(scrip, positions);
		var scrip 	= buildScrip(scrip, positions);
		
		scrip.appendChild(item);
		scrip.appendChild(number);
		scrip.appendChild(to);
		scrip.appendChild(content);
		scrip.appendChild(from);
		scrip.appendChild(date);
		scrip.appendChild(comment);
		scrip.appendChild(channel);
		scrip.appendChild(resize);
		//scrip.appendChild(close);
		
		return scrip;
	}
}

function buildV3FullStyle(scrip){	
	var items = scrip.items;
	var styleText = "complete rectangle rectangle_layoutLeft colorWhite";
	if(scrip.items.length > 0 && scrip.items[0].sPayStatus == "N"){
		return styleText;
	}
	for(var i = 0; i < items.length; i++){
		var sItemShape 	= items[i].sItemShape;
		var sItemLayout = items[i].sItemLayout;
		var sItemColor 	= items[i].sItemColor;		
		styleText = "complete"+" "+sharp[sItemShape]+" "+sharp[sItemShape]+"_"+layout[sItemLayout]+" "+color[sItemColor];		
		
		if(styleText.indexOf("undefined") != -1){
			styleText = "complete rectangle rectangle_layoutLeft colorWhite";
		}
		
		return styleText;
	}
	return styleText;
}
function getItemDefault(upMark, sizeFlag){
	var url = "http://source1.qq.com/lovewall/item_3/lovewall/images/scrip/default/web_"+sizeFlag+".gif";
	if(upMark == "sms"){
		url = "http://source1.qq.com/lovewall/item_3/lovewall/images/scrip/default/sms_"+sizeFlag+".gif";
	}else
	if(upMark == "3g"){
		url = "http://source1.qq.com/lovewall/item_3/lovewall/images/scrip/default/3g_"+sizeFlag+".gif";
	}
	return url;
}