function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function menu_display() {
	if(menu==1){
		document.getElementById("menu_display").style.display="none";
	}
}
function copy(id){
	var obj = document.getElementById(id);
	obj.select();
	window.clipboardData.setData("Text",obj.value);
	alert("复制成功！");
}

function setImageProperties(){
	var aa = document.getElementById("codecry1");
	var bb = aa.firstChild.nodeValue;
	var cc = String(bb);
	var dd = cc.indexOf("width");
	var input = document.getElementById("width");	
	document.getElementById("width").disabled=false;
	var ff = cc.split('width="')[1];
	var gg = ff.indexOf('"');
	input.value = cc.substr(dd+7,gg);
	input.select();
}

function setHeight() {
	var aa = document.getElementById("codecry1");
	var bb = aa.firstChild.nodeValue;
	var cc = String(bb);
	var dd = cc.indexOf("height");
	var input = document.getElementById("height");	
	document.getElementById("height").disabled=false;
	//var ee = cc.indexOf('width="');
	var ff = cc.split('height="')[1];
	var gg = ff.indexOf('"');
	input.value = cc.substr(dd+8,gg);
	input.select();
}

function changeImage() {
	document.onkeyup = function(e){
			if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			if(keycode>=96 && keycode<=105 || keycode>=48 && keycode<=57){
					changeImage3();
				} else {//输入的内容非数字
				setImageProperties();
			}
	}
}


//改变textarea中值的 功能，可以被changeImage调用。
function changeImage3() {
	var aa = document.getElementById("codecry1");
				var bb = aa.firstChild.nodeValue;
				var cc = String(bb);
				var dd = cc.indexOf("width");
				if (dd == -1) return
				var input = document.getElementById("width");
				//var imgwidth = cc.substr(dd+7,3);
				var ee = cc.substr(0,dd);
				var newwidth = document.getElementById("width");
				var ff = newwidth.value;
	
				//不保持宽高比例
				if(document.getElementById("checkbox").checked ==false) {
					//sina 的判断
				var hh = cc.indexOf("<object");
				var gg = document.getElementById("height").value;
				if (hh != -1) {
					var jj = cc.indexOf("<embed");
					var kk = cc.indexOf("<param");
					var ss = cc.substring(kk,jj);//yong
					var tt = cc.indexOf("</embed>");
					var uu = cc.substring(jj,tt);
					var oo = uu.indexOf("width");
					var yy = uu.substring(0,oo);
		
					aa.firstChild.nodeValue = "<object " + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' + ">" + ss + yy + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' +"></embed></object>";
					return
				} 
				//end
					aa.firstChild.nodeValue = ee + "" + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' +"></embed>";
					return
				}//不保持宽高比例结束
				var gg = parseInt(ff*(312/416));
				document.getElementById("height").value = gg;
				//sina 的判断
				var hh = cc.indexOf("<object");
				if (hh != -1) {
					var jj = cc.indexOf("<embed");
					var kk = cc.indexOf("<param");
					var ss = cc.substring(kk,jj);//yong
					var tt = cc.indexOf("</embed>");
					var uu = cc.substring(jj,tt);
					var oo = uu.indexOf("width");
					var yy = uu.substring(0,oo);
					aa.firstChild.nodeValue = "<object " + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' + ">" + ss + yy + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' +"></embed></object>";
					return
				} 
				//end
				aa.firstChild.nodeValue = ee + "" + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' +"></embed>";
}


//下面是其他的相册 自定义大小
function setImageProperties2(){
	var aa = document.getElementById("code1");
	var bb = aa.firstChild.nodeValue;
	var cc = String(bb);
	var dd = cc.indexOf("width");
	var ff = cc.indexOf("[flash=");
	var pp = cc.indexOf("[flash,");
	var ee = cc.indexOf("[swf=");
	var input = document.getElementById("width2");
	if(dd>-1){//其余有width
		var hh = cc.split('width="')[1];
		var gg = hh.indexOf('"');
		input.value = cc.substr(dd+7,gg);
	} else if(ff>-1) {//太太帮，21cn
		var ii = cc.split("[flash=")[1];
		var jj = ii.indexOf(",");
		input.value = cc.substr(ff+7,jj);
	} else if(pp>-1) {//Qzone日志
		var qq = cc.split("[flash,")[1];
		var rr = qq.indexOf(",");
		input.value = cc.substr(pp+7,rr);
	} else {//中国博客
		var kk = cc.split("[swf=")[1];
		var oo = kk.indexOf(",");
		input.value = cc.substr(ee+5,oo);
	}
	input.select();
}
//下面的自定义相册
//有关键字width，height的
function changeImage4() {
	var aa = document.getElementById("code1");
				var bb = aa.firstChild.nodeValue;
				var cc = String(bb);
				var dd = cc.indexOf("width");
				if (dd == -1) return
				var input = document.getElementById("width2");
				//var imgwidth = cc.substr(dd+7,3);
				var ee = cc.substr(0,dd);
				var newwidth = document.getElementById("width2");
				var ff = newwidth.value;
	
				//不保持宽高比例
				if(document.getElementById("checkbox2").checked ==false) {
					//sina 的判断
				var hh = cc.indexOf("<object");
				var gg = document.getElementById("height2").value;
				if (hh != -1) {
					var jj = cc.indexOf("<embed");
					var kk = cc.indexOf("<param");
					var ss = cc.substring(kk,jj);//yong
					var tt = cc.indexOf("</embed>");
					var uu = cc.substring(jj,tt);
					var oo = uu.indexOf("width");
					var yy = uu.substring(0,oo);
		
					aa.firstChild.nodeValue = "<object " + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' + ">" + ss + yy + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' +"></embed></object>";
					return
				} 
				//end
					aa.firstChild.nodeValue = ee + "" + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' +"></embed>";
					return
				}//不保持宽高比例结束
				var gg = parseInt(ff*(312/416));
				document.getElementById("height2").value = gg;
				//sina 的判断
				var hh = cc.indexOf("<object");
				if (hh != -1) {
					var jj = cc.indexOf("<embed");
					var kk = cc.indexOf("<param");
					var ss = cc.substring(kk,jj);//yong
					var tt = cc.indexOf("</embed>");
					var uu = cc.substring(jj,tt);
					var oo = uu.indexOf("width");
					var yy = uu.substring(0,oo);
					aa.firstChild.nodeValue = "<object " + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' + ">" + ss + yy + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' +"></embed></object>";
					return
				} 
				//end
				aa.firstChild.nodeValue = ee + "" + "width=" + '"'+ff+'"' +  " " + "height="+ '"'+ gg +'"' +"></embed>";


}
//太太帮 21cn
function changeImage5() {
	var aa = document.getElementById("code1");
				var bb = aa.firstChild.nodeValue;
				var cc = String(bb);
				var dd = cc.indexOf("[flash=");
				var qq = cc.split("[flash=")[1];
				var ww = cc.indexOf("http");
				var end = cc.substring(ww);
				var input = document.getElementById("width2");
				//var imgwidth = cc.substr(dd+7,3);
				//var ee = cc.substr(0,dd);
				var newwidth = document.getElementById("width2");
				var ff = newwidth.value;
				var gg = document.getElementById("height2").value;
				//不保持宽高比例
				if(document.getElementById("checkbox2").checked ==false) {
					aa.firstChild.nodeValue = "[flash=" +ff+"," + gg+']' + end;
					return
				}//不保持宽高比例结束
				var gg = parseInt(ff*(312/416));
				document.getElementById("height2").value = gg;
				aa.firstChild.nodeValue = "[flash=" +ff+"," + gg+']' + end;
}
//Qzone 日志
function changeImage6() {
	var aa = document.getElementById("code1");
				var bb = aa.firstChild.nodeValue;
				var cc = String(bb);
				var dd = cc.indexOf("[flash,");
				var qq = cc.split("[flash,")[1];
				var ww = cc.indexOf("http");
				var end = cc.substring(ww);
				var input = document.getElementById("width2");
				//var imgwidth = cc.substr(dd+7,3);
				//var ee = cc.substr(0,dd);
				var newwidth = document.getElementById("width2");
				var ff = newwidth.value;
				var gg = document.getElementById("height2").value;
				//不保持宽高比例
				if(document.getElementById("checkbox2").checked ==false) {
					aa.firstChild.nodeValue = "[flash," +ff+"," + gg+']' + end;
					return
				}//不保持宽高比例结束
				var gg = parseInt(ff*(312/416));
				document.getElementById("height2").value = gg;
				aa.firstChild.nodeValue = "[flash," +ff+"," + gg+']' + end;

}
//中国博客
function changeImage7() {
	var aa = document.getElementById("code1");
				var bb = aa.firstChild.nodeValue;
				var cc = String(bb);
				var dd = cc.indexOf("[swf=");
				var qq = cc.split("[swf=")[1];
				var ww = cc.indexOf("http");
				var end = cc.substring(ww);
				var input = document.getElementById("width2");
				//var imgwidth = cc.substr(dd+7,3);
				//var ee = cc.substr(0,dd);
				var newwidth = document.getElementById("width2");
				var ff = newwidth.value;
				var gg = document.getElementById("height2").value;
				//不保持宽高比例
				if(document.getElementById("checkbox2").checked ==false) {
					aa.firstChild.nodeValue = "[swf=" +ff+"," + gg+']' + end;
					return
				}//不保持宽高比例结束
				var gg = parseInt(ff*(312/416));
				document.getElementById("height2").value = gg;
				aa.firstChild.nodeValue = "[swf=" +ff+"," + gg+']' + end;

}

//通过这个函数去调用所有的其他函数
function changeImage8() {
	var aaa = document.getElementById("code1");
	var bbb = aaa.firstChild.nodeValue;
	var ccc = String(bbb);
	var ddd = ccc.indexOf("width");
	var fff = ccc.indexOf("[flash=");
	var ppp = ccc.indexOf("[flash,");
	var eee = ccc.indexOf("[swf=");
	//var input = document.getElementById("width2");
	if(ddd>-1){//有width，height的关键字
		changeImage4();
		return;
	} else if(fff>-1) {//太太帮，21cn
		changeImage5();
		return;
	} else if(ppp>-1) {//Qzone日志
		changeImage6();
		return;
	} else {//中国博客
		changeImage7();
		return;
	}
}

//初试化函数
function init() {
	document.onkeyup = function(e){
			if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			if(keycode>=96 && keycode<=105 || keycode>=48 && keycode<=57){
					changeImage8();
				} else {//输入的内容非数字
				setImageProperties2();
			}
	}
}

//下面是两个功能函数
function checkbox_disable() {
	document.getElementById("height").disabled = document.getElementById("checkbox").checked
	if(document.getElementById("checkbox").checked==true) {
	var aa =  parseInt(document.getElementById("width").value*(312/416))
	document.getElementById("height").value = aa;
	changeImage3();
	}
}

function checkbox_disable2() {
	document.getElementById("height2").disabled = document.getElementById("checkbox2").checked
	if(document.getElementById("checkbox2").checked==true) {
	var aa =  parseInt(document.getElementById("width2").value*(312/416))
	document.getElementById("height2").value = aa;
	changeImage8();
	}
}




//作品展示预览
function work_pre(num) {
	//魔力秀网页地址
	var aa = document.getElementById("a1").value;
	var bb = aa.split("molihe-");
	var cc = bb[1].split("-")[1];
	document.getElementById("a1").value = bb[0]+"molihe-"+num+"-"+cc;
	//空间展示地址
	var dd = document.getElementById("codecry1").value;
	var ff = document.getElementById("code1").value;

	 if(dd.indexOf("molihe_play-") !=-1){
		document.getElementById("codecry1").value = dd.replace(/molihe_play-\d/,"molihe_play-"+num);
	} else {
		document.getElementById("codecry1").value = dd.replace(/molihe-\d/g,"molihe-"+num);
}
	document.getElementById("code1").value = ff.replace(/molihe-\d/g,"molihe-"+num);

}
