
//var illegalCharacters = "<,>,',',;,!,-,{,(,),},\";,;//,frame,iframe";
var illegalCharacters = "<,>,',',-,{,(,),},\";,;//,frame,iframe";

function makeEBook(){
	var allId=document.getElementsByName('checkbox');
	var pars='';
	var pushCount=0;
	for(i=0;i<allId.length;i++){
		if(allId[i].checked){
			pushCount++;
			  if(pars!="")
			  	pars=pars+",";
			  pars=pars+allId[i].value;
			}
	}
	pars = getCaseId(pars);
	if(getCaseIdCount()+pushCount<2){
	 	alert('最少选择二条记录！');
	 	return ;
	}
		 
	var imgurl = document.getElementById("refUrl").value;
	var name = document.getElementById("name").value;
	var des = document.getElementById("des").value;
	
	if(trim(name)==""){
		alert("请输入电子书名称");
		document.getElementById("name").focus();
		return;
	}
	if(trim(des)==""){
		alert("请输入电子书介绍");
		document.getElementById("des").focus();
		return;
	}
		
	var typeName=CheckRadio("categoryGroup");
	if(typeName==false){
		alert("请选择分类");
		return;
	}

	$.get("/2010/index.do?__method=MakeEBook", {pars:pars,name:name,des:des,typeName:typeName,imgurl:imgurl,random:Math.random()},function(data){
	if(data==1){
		alert("您好！发布红段子，请先登录/注册!");
	}else if(data==2){
		alert("恭喜您，发布作品成功！如需浏览作品，请到“会员空间”查看");
		document.getElementById("name").value = "";
		document.getElementById("des").value = "";
		document.getElementById("refUrl").value = "";
	}
	else if(data==4){
		alert("发布的内容包含非法字符!!!");
	}
	else{
		alert("发布的内容包含非法字符!!!");
	}
	}); 
	
}

function redbooksubmit(){
	var content= document.getElementById("redcontent").value;
	var typeName=CheckRadio("redbook");
	var tagName = $("#switchArea").val();
	if(typeName==false){
		alert("请选择分类");
		document.getElementById("redcontent").focus();
		return;
	}
	if(content.length<30){
		alert("内容不能少于30个字符！");
		document.getElementById("redcontent").focus();
		return;
	}
	
	if(content.length>140){
		alert("字数大于140个字，请重新编辑再发布");
		document.getElementById("redcontent").focus();
		return;
	}
	
	if(content=="小说作品内容要求具有情节性、趣味性和符合主题分类形式的完整故事内容"){
		alert("内容不能少于30个字符！");
		document.getElementById("redcontent").focus();
		return;
	}
	
	if(isIllChar(content)){
		alert("输入的内容包含非法字符!");
		return ;
	}
	
	document.getElementById("span_button2").innerHTML ="<input type=\"image\" onclick=\"alert('发布中，请稍候...');return false;\" src=\"/2011/images/btn_publish.gif\" alt=\"发布\" value=\"发布\" class=\"btn_pub\" id=\"btn_sms\" />";
	
	$.get("/2010/index.do?__method=UpRedSms", { diaryType:3,content:content, typeName: typeName ,ployid:"1",imgurl:"",random:Math.random()},function(data){
		if(data==1){
			alert("您好！发布红段子，请先登录/注册!");
		}else if(data==2){
			alert("恭喜您，发布作品成功！如需浏览作品，请到“会员空间”查看");
			document.getElementById("redcontent").value = "";
			CancleRadio("sms");
		}
		else if(data==4){
			alert("发布的内容包含非法字符!!!");
		}
		else{
			alert("网络错误，请稍候再试！");
		}
		document.getElementById("span_button2").innerHTML ="<input type=\"image\" onclick=\"redbooksubmit();return false;\" src=\"/2011/images/btn_publish.gif\" alt=\"发布\" value=\"发布\" class=\"btn_pub\" id=\"btn_sms\" />";
	}); 

}

function smssubmit(){
	var content=$("#smscontent").val();
	var typeName=CheckRadio("sms");
	var tagName = $("#switchArea").val();

	
	if(typeName==false){
		alert("请选择分类");
		$("#smscontent").focus();
		return;
	}
	if(content.length<30){
		alert("内容不能少于30个字符！");
		$("#smscontent").focus();
		return;
	}
	if(content.length>140){
	alert("字数大于140个字，请重新编辑再发布");
		$("#smscontent").focus();
		return;
	}
	
	if(isIllChar(content)){
		alert("输入的内容包含非法字符!");
		return ;
	}
	
	document.getElementById("span_button1").innerHTML ="<input type=\"image\" onclick=\"alert('发布中，请稍候...');return false;\" src=\"/2011/images/btn_publish.gif\" alt=\"发布\" value=\"发布\" class=\"btn_pub\" id=\"btn_sms\" />";
	
	$.get("/2010/index.do?__method=UpRedSms", { content:content, typeName: typeName ,ployid:"1",imgurl:"",random:Math.random(),tagName: tagName},function(data){
		if(data==1){
			alert("您好！发布红段子，请先登录/注册!");
		}else if(data==2){
			alert("恭喜您，发布作品成功！如需浏览作品，请到“会员空间”查看");
			$("#smscontent").val("");
			CancleRadio("sms");
		}
		else if(data==4){
			alert("发布的内容包含非法字符!!!");
		}
		else{
			alert("网络错误，请稍候再试！");
		}
		document.getElementById("span_button1").innerHTML ="<input type=\"image\" onclick=\"smssubmit();return false;\" src=\"/2011/images/btn_publish.gif\" alt=\"发布\" value=\"发布\" class=\"btn_pub\" id=\"btn_sms\" />";
	}); 
}
function smsTopicsubmit(){
	var content=$("#smscontent").val();
	var topicName=CheckRadio("topicName");
	var strKeyword=CheckRadio("strKeyword");
	var typeName=CheckRadio("sms");
	if(typeName==false){
		alert("请选择分类");
		$("#smscontent").focus();
		return;
	}
	if(content.length<30){
		alert("内容不能少于30个字符！");
		$("#smscontent").focus();
		return;
	}
	if(content.length>140){
		alert("字数大于140个字，请重新编辑再发布");
		$("#smscontent").focus();
		return;
	}
	$.get("/2010/index.do?__method=UpRedTopic", { content:content, typeName: typeName , topicName: topicName ,ployid:"0",imgurl:"",random:Math.random()},function(data){
		if(data==1){
			alert("您好！发布红段子，请先登录/注册!");
		}else if(data==2){
			alert("恭喜您，发布作品成功！如需浏览作品，请到“会员空间”查看");
			$("#smscontent").val("");
		}else if(data==3){
			alert("你发布的内容不含有“"+topicName+"”话题所包含的关键字:"+strKeyword+"，请重新编辑内容。");
		}
		else if(data==4){
			alert("发布的内容包含非法字符!!!");
		}
		else{
			alert("网络错误，请稍候再试！");
		}
	}); 
}

function mmssubmit(){
	imgurl=$("#refUrl").val(); 
	title=$("#titlemms").attr("value");
	var typeName=CheckRadio("mms");
	var tagName = $("#switchArea").val();
	if(title==""){
		alert("标题不能为空！");
		$("#titlemms").focus();
		return;
	}
	if(typeName==false){
		alert("请选择分类");
		return;
	}
	if(imgurl==""||imgurl.length<1){
		alert("必须上传图片！");
		return;
	}
	
	if(isIllChar(title)){
		alert("输入的标题包含非法字符!");
		return ;
	}
	
	
	document.getElementById("span_button3").innerHTML ="<img style=\"cursor:hand\" onclick=\"alert('发布中，靖稍候');return;\" src=\"/2011/images/btn_publish.gif\" alt=\"发布\" value=\"发布\" class=\"btn_pub\" id=\"btn_mms\" />";
	
	$.get("/2010/index.do?__method=UpRedMms", { content:" ",typeName: typeName ,ployid:"1",imgurl:imgurl,title:title,random:Math.random(),tagName: tagName},function(data){
	if(data==1){
			alert("您好！发布红段子，请先登录/注册!");
		}else if(data==2){
			alert("恭喜您，发布作品成功！如需浏览作品，请到“会员空间”查看");
			$("#refUrl").val("");
			$("#titlemms").val("");
			CancleRadio("mms");
		}
		else if(data==4){
			alert("发布的内容包含非法字符!!!");
		}
		else{
			alert("网络错误，请稍候再试！");
		}
		document.getElementById("span_button3").innerHTML ="<img style=\"cursor:hand\" onclick=\"mmssubmit();\" src=\"/2011/images/btn_publish.gif\" alt=\"发布\" value=\"发布\" class=\"btn_pub\" id=\"btn_mms\" />";
	}); 
}

function xssubmit(){
	var typeName=CheckRadio("xs");
	if(typeName==false){
		alert("请选择分类");
		$("#smscontent").focus();
		return;
	}
	
	var content=$("#xscontent").val(); 
	var t=CheckRadio("story_face");
	var imgurl="";

	if(t==2){
		imgurl=$("#refUrl").val(); 
	}else{
		imgurl='/uploads/diary/20100527/02/12748982738971084.jpg';
	}
	title=document.getElementById("xstitle").value;
	if(title.length<1){
			alert("标题不能为空！");
		$("xstitle").focus();
		return;
	}
	
	if(content.length<200){
		alert("内容不能少于200个字符！");
		$("#smscontent").focus();
		return;
	}
	if(content.length>8000){
		alert("内容不能多于8000个字符！");
		$("#smscontent").focus();
		return;
	}
	$.post("../2010/index.do?__method=UpRedxs", { content:content, typeName: typeName ,ployid:"0",imgurl:imgurl,title:title,random:Math.random()},function(data){
		if(data==1){
			alert("您好！发布红段子，请先登录/注册!");
		}else if(data==2){
			alert("恭喜您，发布作品成功！如需浏览作品，请到“会员空间”查看");
			$("#xscontent").val("");
			 document.getElementById("xstitle").value="";
			 CancleRadio("xs");
		}
		else if(data==4){
			alert("发布的内容包含非法字符!!!");
		}
		else{
			alert("网络错误，请稍候再试！");
		}
	}); 
}




function CheckRadio(radioName){
	var theRadio=document.getElementsByName(radioName);
    var theRadioLen = theRadio.length;
    var theRadioValue = false;
    if (theRadioLen == undefined){
        if (theRadio.checked){
            theRadioValue = theRadio.value;
        }
    }else{
        for (theRadioI=0;theRadioI<theRadioLen;theRadioI++){
            if (theRadio[theRadioI].checked){
                theRadioValue = theRadio[theRadioI].value;
                break;
            }
        }
    }
    return theRadioValue;
}
function CancleRadio(radioName){
	var theRadio=document.getElementsByName(radioName);
	var theRadioLen = theRadio.length;

	
	if (theRadioLen == undefined){
		theRadio.checked=false;
    }else{
        for (theRadioI=0;theRadioI<theRadioLen;theRadioI++){
            if (theRadio[theRadioI].checked){
                theRadio[theRadioI].checked=false;
                break;
            }
        }
    }
}

function up_img_sub(upload_image_uri){
	$("#refUrl").val(upload_image_uri);
	document.getElementById("span_upload_message").style.display = "none";
	document.getElementById("eventSubmit_UploadImage").disabled = false; 
    alert("上传成功"+ $("#refUrl").val());	
    document.getElementById("span_newFile").innerHTML ="<input name=\"NewFile\" id=\"NewFile\" type=\"file\" />";
}
 
function check(theForm){
 	var filename=document.getElementById("NewFile").value;
	if(trim(filename)==""){
    	alert("请选择要上传的图片.");
    	return false;
    }
   
    if(filename.substring(filename.length-3).toLowerCase()!="gif"&&filename.substring(filename.length-3).toLowerCase()!="jpg"&&filename.substring(filename.length-4).toLowerCase()!="jpeg"&&filename.substring(filename.length-3).toLowerCase()!="png"){
		alert("选择的文件格式错误(支持gif、jpg、jpeg、png等格式)");
		return false;
	}
	
    document.getElementById("eventSubmit_UploadImage").disabled = true; 
    document.getElementById("span_upload_message").style.display = "";
    
    return true;
}

function fileSelect(){
	document.getElementById("NewFile").click();
	document.getElementById("img_path").value=document.getElementById("NewFile").value;
	document.getElementById("img_path").select();
}

function isIllChar(str){
	var arr=illegalCharacters.split(",");
	for(var i=0 ;i<arr.length;i++){
		if(str.indexOf(arr[i])!=-1){
			return true;
		}
	}
	return false;
}

/** 新浪红小说发布 **/
function redbooksubmit2(){
	var content= document.getElementById("redcontent").value;
	var typeName = '462';

	if(content.length<30){
		alert("内容不能少于30个字符！");
		document.getElementById("redcontent").focus();
		return;
	}
	
	if(content.length>140){
		alert("字数大于140个字，请重新编辑再发布");
		document.getElementById("redcontent").focus();
		return;
	}
	
	if(content=="小说作品内容要求具有情节性、趣味性和符合主题分类形式的完整故事内容"){
		alert("内容不能少于30个字符！");
		document.getElementById("redcontent").focus();
		return;
	}
	
	if(isIllChar(content)){
		alert("输入的内容包含非法字符!");
		return ;
	}
	
	document.getElementById("span_button2").innerHTML ="<input src=\"/act/sinavnovel/images/btn_fabu.jpg\" id=\"btn_sms\" type=\"image\" class=\"btn_submit\" onclick=\"alert('发布中，请稍候 。。。');return false;\"/>";
	
	$.get("/2010/index.do?__method=UpRedSms2", { diaryType:3,content:content, typeName: typeName ,ployid:"1",imgurl:"",random:Math.random()},function(data){
		if(data==1){
			alert("您好！发布红段子，请先登录/注册!");
		}
		else if(data==5){
			alert("您好！发布微小说，请先绑定新浪微博帐号!");
		}
		else if(data==2){
			alert("恭喜您，发布作品成功！如需浏览作品，请到“会员空间”查看");
			document.getElementById("redcontent").value = "#微小说#";
		}
		else if(data==4){
			alert("发布的内容包含非法字符!!!");
		}
		else{
			alert("网络错误，请稍候再试！");
		}
		document.getElementById("span_button2").innerHTML ="<input src=\"/act/sinavnovel/images/btn_fabu.jpg\" id=\"btn_sms\" type=\"image\" class=\"btn_submit\" onclick=\"redbooksubmit2();return false;\"/>";
	}); 

}

