
var downUrl = "/2011/common/down.vm";
var htmlUrl = "/2011/common/file.vm";
var number = 60;
var S_NUMBER_TIME = 60;
	function sendmobilesms(mobile){
		if(trim(mobile)==""){
			alert("请输入手机号码");
			document.uform.mobile.focus();
			return;
		}
		var url = '/validateMoblie.do';
		var args = 'eventSubmit_sendmobilesms=' + mobile;
    	var myAjax = new Ajax.Request(url,
    	    {method: 'post', parameters: args, onComplete: sendmobilesms_response}
    	);
	}
	function sendmobilesms_response(originalRequest) {
		if(originalRequest.status==200){
		    if(originalRequest.responseText=="0"){
                 alert("成功发送手机验证码.");
			}else if(originalRequest.responseText=="1"){

                 alert("手机号码不正确.");
			}else if(originalRequest.responseText=="2"){
                 alert("该手机已经注册，请不要重新注册.");
			}
			else{
				 alert("发送失败!");
			}
		}
    }
    
/** 设置分组 **/
function saveType(userId,friendId){
	var type = document.getElementById(userId+friendId).value;
	if(type==0){
		return ;
	}
	else{
		$.post("/gw/downhong.do?__method=SaveType",{type:type,userId:userId,friendId:friendId},function (data){
		if(data=="1"){
			alert("分组成功");
			document.location.reload();
		}
		else if(data=="2"){
			alert("登录后才能进行取消关注。");
		}		
		else{
			alert("系统忙，请稍候再试。");
		}});
	}
}

function saveFriend(friendId){
		$.post("/gw/downhong.do?__method=SaveFriend",{friendId:friendId},function (data){
		if(data=="1"){
			alert("关注成功！");
			//document.getElementById('span_saveFriend').innerHTML='<img src=\"/2011/images/icon_going.gif\">已关注';
		}
		else if(data=="2"){
			alert("登陆后才能加关注，成为好友");
		}		
		else if(data=="3"){
			alert("已关注！");
		}		
		else if(data=="4"){
			alert("不能关注自己！");
		}			
		else{
			alert("系统忙，请稍候再试！");
		}});
}

/** 取消关注  **/
function deleteFriend(friendId){
	if(confirm("是否取消关注?")){
		$.post("/gw/downhong.do?__method=DeleteFriend",{friendId:friendId},function (data){
		if(data=="1"){
			alert("取消关注成功");
			var d = document.getElementById("li_"+friendId);
			d.parentNode.removeChild(d);
		}
		else if(data=="2"){
			alert("登录后才能进行取消关注。");
		}		
		else{
			alert("系统忙，请稍候再试。");
		}});
	}
}

function favorites(diaryId){
		$.post("/gw/downhong.do?__method=Favorites",{diaryId:diaryId},function (data){
		if(data=="1"){
			alert("收藏成功。");
		}
		else if(data=="2"){
			alert("登录后才能进行收藏。");
		}
		else if(data=="3"){
			alert("已收藏。");
		}
		else{
			alert("系统忙，请稍候再试。");
		}
	});
}

function deleteFavorite(diaryId){
	if(confirm("是否删除收藏?")){
			$.post("/gw/downhong.do?__method=DeleteFavorite",{diaryId:diaryId},function (data){
			if(data=="1"){
				alert("删除成功。");
				var d = document.getElementById("li_"+diaryId);
				d.parentNode.removeChild(d);
			}
			else if(data=="2"){
				alert("登录后才能进行删除。");
			}		
			else{
				alert("系统忙，请稍候再试。");
			}});
	}
}

/** 139分享 **/
function share139(title){
	window.open("http://www.139.com/share/share.php?tl=953010052&source=shareto139_hongduanzi&title="+encodeURIComponent(title),'_blank','width=490,height=340');
}
		
/** 弹出下载页面 **/
function getDownPage(diaryId){
	getNewDivPage(downUrl,diaryId);
}

/** 弹出层页面 **/
function getNewDivPage(url,diaryId){
	jQuery.openPopupLayer({
		name: "jmpopups",
		width: 550,
		url: url+"?id="+diaryId
	});
}

//得到整个页面,用于列表页面读取
function getPage(url,param,div){
	//对中文进行编码
	param = encodeURI(param);
	document.getElementById(div).innerHTML = "<div style=\"text-align:center; line-height:30px; padding-top:50px;\"><img src=\"/2011/images/down/loading.gif\" width=\"66\" height=\"66\" /><br />数据正在加载中，请稍等……</div>";
	jQuery.ajax({
		type:"GET", 
		url:url+"?div="+div+param,
		async: true,
		dataType: "html",
		success: function(data){
			document.getElementById(div).innerHTML = data;
		}
	});
}

//得到整个页面,用于列表页面读取
function getActionPage(url,method,param,div){
	//对中文进行编码
	param = encodeURI(param);
	document.getElementById(div).innerHTML = "<div style=\"text-align:center; line-height:30px; padding-top:50px;\"><img src=\"/2011/images/down/loading.gif\" width=\"66\" height=\"66\" /><br />数据正在加载中，请稍等……</div>";
    $.get(url+"?__method="+method+param,function(data){
        document.getElementById(div).innerHTML = data;
    });
}

//得到整个页面，用于静态页面读取
function getHtmlPage(url,div){
	if(true){
		var str = document.getElementById(div).innerHTML;
		if(str.length>0){
			return ;
		}
	}
	
	//对中文进行编码
	document.getElementById(div).innerHTML = "<div style=\"text-align:center; line-height:30px; padding-top:50px;\"><img src=\"/2011/images/down/loading.gif\" width=\"66\" height=\"66\" /><br />数据正在加载中，请稍等……</div>";
	jQuery.ajax({
		type:"POST", 
		url:htmlUrl+"?pageUrl="+url,
		async: true,
		dataType: "html",
		success: function(data){
			document.getElementById(div).innerHTML = data;
		}
	});
}

function downDiary(tid){
	showdiv = document.getElementById("showmsgs");
	var verifyode = document.getElementById("verifyCode11").value;
	var usermobile1= document.getElementById("dmobile1").value;
	if(!checkChinaMobileNum(usermobile1)){
		alert("您输入的不是移动手机号码，请重新输入！");
		document.getElementById("dmobile1").focus();
		return;
	}
	if(verifyode==""||verifyode.length<6){
		showdiv.innerHTML="请输入短信验证码，进行下载！";
		document.getElementById("verifyCode11").focus();
		return;
	}
	document.getElementById("downButton").disabled=true;
	$.post("/gw/downhong.do?__method=Down",{mobile:usermobile1 ,tid:tid ,verifyCode:verifyode},function (data){
	showdiv=document.getElementById("showmsgs");
		   			if(data=="1"){
        				showdiv.innerHTML="短信已下发，请注意查收！"  		
        				document.getElementById("verifyCode11").value = "";
        			}
		   			else if(data=="11"){
        				showdiv.innerHTML="小小说已下发，请注意查收！"  		
        				document.getElementById("verifyCode11").value = "";
        			}
        			else if(data=="2"){
        				showdiv.innerHTML="验证码错误请重新输入！" 
        				document.getElementById("verifyCode11").focus();
        			}else if(data=="3"){
        				showdiv.innerHTML="该作品不能够被下载！"; 
        			}
        			else if(data=="4"){
        				showdiv.innerHTML="您还不是红段子会员！"; 
        			}
        			else if(data=="5"){
        				showdiv.innerHTML="验证码与手机号码不匹配!";
						document.getElementById("dmobile1").focus();
        			}
        			else {
        				showdiv.innerHTML="系统繁忙，请稍候再试！"; 
        			}
        			document.getElementById("downButton").disabled=false;
    }
);
}

/** 获取短信验证码 **/
function getCode(){
	showdiv=document.getElementById("showmsgs");
	var usermobile1= document.getElementById("dmobile1").value;
	if(usermobile1.length<11||(!checkChinaMobileNum(usermobile1))){
		showdiv.innerHTML="您输入的不是移动手机号码，请重新输入！";
		document.getElementById("dmobile1").focus();
		return;
	}
			
	document.getElementById("code").style.display = "none";
	showdiv.innerHTML = "获取验证码中，请稍候。。。";
			
	$.post("/gw/downhong.do?__method=SmsCode",{mobile:usermobile1,num:Math.random()},function (data){
		if(data=="1"){
			showdiv.innerHTML="验证信息已下发，请注意查收！" 
		    timeID = setInterval(processInterval,1000); 
		}
		else if(data=='6'){
			showdiv.innerHTML="您输入的不是广东移动手机号码，请重新输入！"; 
		    document.getElementById("code").style.display = "";
		}
		else {
			showdiv.innerHTML="网络错误，请稍候再试！"; 
		    document.getElementById("code").style.display = "";
		}
	});
}

/** 获取android客户端 **/
function getAPKDown(mobile){
	$.post("/gw/downhong.do?__method=APKDown",{mobile:mobile},function (data){
		if(data=="1"){
           alert("地址已下发到您绑定的手机上，请注意查收！");
		}
		else {
		   alert("网络错误，请稍候再试！"); 
		}
	});
}

function getAPKDown001(mobile){
	$.post("/gw/downhong.do?__method=APKDown001",{mobile:mobile},function (data){
		if(data=="1"){
           alert("地址已下发到您绑定的手机上，请注意查收！");
		}
		else {
		   alert("网络错误，请稍候再试！"); 
		}
	});
}

/** 重新获验证码倒计时 **/
function processInterval(){
	if(number<=0){
		clearInterval(timeID);
		timeID=0;
		number=S_NUMBER_TIME;
		if(document.getElementById("info_display")){
			document.getElementById("info_display").innerHTML = "";
		}
		if(document.getElementById("code")){
			document.getElementById("code").style.display = "";
		}
	}
	else{
		if(document.getElementById("info_display")){
			document.getElementById("info_display").innerHTML="<b>" + (--number) + "</b>秒内未收到，请重新获取验证码";
		}
	}
}
				
/** 订阅 **/
function subscribe(tagName){
	$.post("/gw/subscribe.do?__method=Subscribe",{tagName:tagName,diaryType:1 },function (data){
		if(data=="1"){
        	alert('该分类已经订阅');  		
        }
        else if(data=="2"){
        	alert('已订阅成功');
        }else if(data=="3"){
        	alert('订阅失败');
        }
        else if(data=="0"){
        	var k=window.showModalDialog("/2011/modal.htm",null,"dialogWidth=480px;dialogHeight=160px");    
        	if(k=="true"){
        		window.open("http://www.hongduanzi.org/2011/login.vm");
        	}
        }
    }
);
}


/** 刷新验证码 **/
function flushCode(){  
	var imgSrc = $("#imgObj");  
	var src = imgSrc.attr("src");  
	var url = chgUrl(src);
	imgSrc.attr("src",url);
}

//时间戳,为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳  
function chgUrl(url){  
	var timestamp = (new Date()).valueOf();  
	if((url.indexOf("&")>=0)){  
		url = url + "×tamp=" + timestamp;  
	}else{  
		url = url + "?timestamp=" + timestamp;  
	}  
	return url;  
} 

function checkChinaMobileNum(num){  
    if(num==null||num=="")
    	return true;
	if(num.length!=11)
		return false;
    var  pattern=/^13[4-9]\d{8}$|15[0-9]{9,9}$|18[0-9]{9,9}/;
     if (pattern.test(num))
         return true;
     else
         return false;
} 

/** 是否为整数 **/
function isNumber(str){
	str=String(str) ;
	var number_chars = "1234567890";
	var i;
	for (i=0;i<str.length;i++){
		if (number_chars.indexOf(str.charAt(i))==-1) 
			return false;
	}
	return true;
}
	
/** 去空格 **/
function trim(str){
    return rtrim(ltrim(str));
}

/** 去右空格 **/
function rtrim(str){
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1){
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}

/** 去左空格 **/
function ltrim(str){
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1){
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

//=============================================================
/**
 *弹出注册窗口
 */

function alertWin4(){ 
	var titleheight = "22px"; // 提示窗口标题高度 
	var bordercolor = "#666699"; // 提示窗口的边框颜色 
	var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色 
	var titlebgcolor = "#666699"; // 提示窗口的标题背景色
	var bgcolor = "#FFFFFF"; // 提示内容的背景色
	var txtcolor="#2E2A2A";// 提示内容文字色
	var w=368;
	var h=139;
	
	var evty = getEvent();
	
	Y = evty.clientY+document.documentElement.scrollTop;
	
	var iWidth = document.documentElement.clientWidth; 
	var iHeight = document.documentElement.clientHeight; 
	var bgObj = document.createElement("div"); 
	bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:9999999;";
	document.body.appendChild(bgObj); 
	
	var msgObj=document.createElement("div");
	msgObj.style.cssText = "position:absolute;font:12px '宋体';top:"+Y+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:left;line-height:22px;z-index:10000000;";
	document.body.appendChild(msgObj);
	
	var closeBtn=document.createElement("div");
	closeBtn.style.cssText = "background: url(../2010/images/toutou2.gif) no-repeat left top;width:368px;height:26px;overflow:hidden;font-size:14px;color:#fff;font-weight:bold;width:96%;height:26px;overflow:hidden;line-height:26px;padding:0px 10px;";
	closeBtn.innerHTML = "<a href='javascript:void(0);' title='关闭' style='cursor:hand;color:#fff;margin-right:10px;line-height:26px;font-family:Arial,Helvetica, sans-serif;float:right;text-decoration: none;'>X</a><span>新用户注册</span>";
	msgObj.appendChild(closeBtn);
	
	closeBtn.onclick = function(){ 
	document.body.removeChild(bgObj); 
	document.body.removeChild(msgObj); 
	} 
	
	var to=document.createElement("div");
	to.style.cssText = "width:348px;overflow:hidden;background:#fff url(../2010/images/dd_bg.gif) repeat-x left bottom;padding:30px 10px 30px 10px;";
	to.innerHTML = " 发送短信 <font style='font-family:Arial Black;font-size: 15px;color:#FE7715;font-style: italic;margin:0px 3px;'>HD</font>到<font style='font-family:Arial Black;font-size: 15px;color:#FE7715;font-style: italic;margin:0px 3px;'>106582020</font>注册红段子会员注册完成后，登录我的红段子完善个人相关资料。";
	msgObj.appendChild(to);
	
	var moveX = 0;
	var moveY = 0;
	var moveTop = 0;
	var moveLeft = 0;
	var moveable = false;
	var docMouseMoveEvent = document.onmousemove;
	var docMouseUpEvent = document.onmouseup;
	msgObj.onmousedown = function() {
	var evt = getEvent();
	
	moveX = evt.clientX;
	moveY = evt.clientY;
	moveTop = parseInt(msgObj.style.top);
	moveLeft = parseInt(msgObj.style.left);
	
	document.onmousemove = function() {
	   if (moveable) {
	    var evt = getEvent();
	    var x = moveLeft + evt.clientX - moveX;
	    var y = moveTop + evt.clientY - moveY;
	    if ( x > 0 &&( x + w < iWidth) && y > 0 && (y + h < iHeight) ) {
	     msgObj.style.left = x + "px";
	     msgObj.style.top = y + "px";
	    }
	   } 
	};
	document.onmouseup = function () { 
	   if (moveable) { 
	    document.onmousemove = docMouseMoveEvent;
	    document.onmouseup = docMouseUpEvent;
	    moveable = false; 
	    moveX = 0;
	    moveY = 0;
	    moveTop = 0;
	    moveLeft = 0;
	   } 
	};
	}
	
	
	    // 获得事件Event对象，用于兼容IE和FireFox
	    function getEvent() {
	     return window.event || arguments.callee.caller.arguments[0];
	    }
}  

/**
 * 弹出找回密码窗口
 */
function alertWin6(){ 
	var titleheight = "22px"; // 提示窗口标题高度 
	var bordercolor = "#666699"; // 提示窗口的边框颜色 
	var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色 
	var titlebgcolor = "#666699"; // 提示窗口的标题背景色
	var bgcolor = "#FFFFFF"; // 提示内容的背景色
	var txtcolor="#2E2A2A";// 提示内容文字色
	var w=368;
	var h=139;

	var iWidth = document.documentElement.clientWidth; 
	var iHeight = document.documentElement.clientHeight; 
	var bgObj = document.createElement("div"); 
	bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:9999999;";
	document.body.appendChild(bgObj); 

	var msgObj=document.createElement("div");
	msgObj.style.cssText = "position:absolute;font:12px '宋体';top:"+(iHeight-h)/3+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:left;line-height:22px;z-index:10000000;";
	document.body.appendChild(msgObj);

	var closeBtn=document.createElement("div");
	closeBtn.style.cssText = "background: url(../2010/images/toutou2.gif) no-repeat left top;width:368px;height:26px;overflow:hidden;font-size:14px;color:#fff;font-weight:bold;width:96%;height:26px;overflow:hidden;line-height:26px;padding:0px 10px;";
	closeBtn.innerHTML = "<a href='#' title='关闭' style='cursor:hand;color:#fff;margin-right:10px;line-height:26px;font-family:Arial,Helvetica, sans-serif;float:right;text-decoration: none;'>X</a><span>获取用户密码</span>";
	msgObj.appendChild(closeBtn);

	closeBtn.onclick = function(){ 
	document.body.removeChild(bgObj); 
	document.body.removeChild(msgObj); 
	} 

	var to=document.createElement("div");
	to.style.cssText = "width:348px;overflow:hidden;background:#fff url(images/dd_bg.gif) repeat-x left bottom;padding:30px 10px 30px 10px;";
	to.innerHTML = " 发送短信 <font style='font-family:Arial Black;font-size: 15px;color:#FE7715;font-style: italic;margin:0px 3px;'>G</font>到<font style='font-family:Arial Black;font-size: 15px;color:#FE7715;font-style: italic;margin:0px 3px;'>1065820201</font>获取密码完成后，登录我的红段子完善个人相关资料。";
	msgObj.appendChild(to);

	var moveX = 0;
	var moveY = 0;
	var moveTop = 0;
	var moveLeft = 0;
	var moveable = false;
	var docMouseMoveEvent = document.onmousemove;
	var docMouseUpEvent = document.onmouseup;
	msgObj.onmousedown = function() {
	var evt = getEvent();
	moveX = evt.clientX;
	moveY = evt.clientY;
	moveTop = parseInt(msgObj.style.top);
	moveLeft = parseInt(msgObj.style.left);

	document.onmousemove = function() {
	   if (moveable) {
	    var evt = getEvent();
	    var x = moveLeft + evt.clientX - moveX;
	    var y = moveTop + evt.clientY - moveY;
	    if ( x > 0 &&( x + w < iWidth) && y > 0 && (y + h < iHeight) ) {
	     msgObj.style.left = x + "px";
	     msgObj.style.top = y + "px";
	    }
	   } 
	};
	document.onmouseup = function () { 
	   if (moveable) { 
	    document.onmousemove = docMouseMoveEvent;
	    document.onmouseup = docMouseUpEvent;
	    moveable = false; 
	    moveX = 0;
	    moveY = 0;
	    moveTop = 0;
	    moveLeft = 0;
	   } 
	};
	}


	    // 获得事件Event对象，用于兼容IE和FireFox
	    function getEvent() {
	     return window.event || arguments.callee.caller.arguments[0];
	    }
	}  

/** 首页短信view **/
function changsmsView(id,content){				
			var showstr = '<p> '+content+'</p>'+
            	'<em><a onClick="getDownPage(\''+id+'\');return false;" href="#"><img height="26" alt="下载到手机" width="117" src="images/btn_download_2.gif" /></a> </em>';
			//$("p.intro") 选取所有 class="intro" 的 <p> 元素。 $("p").html("W3School");
			$("div.b_sms").html(showstr);
			
}

function chgIptTips(obj){
	if(obj.value==""){
		document.getElementById('redcontent').value="小说作品内容要求具有情节性、趣味性和符合主题分类形式的完整故事内容";
		//$(obj).removeClass("act");
	}
}

function chgIptNYXFTips(obj){
	if(obj.value==""){
		document.getElementById('smscontent').value="请以“#所在城市#作品内容”的形式填写";
		//$(obj).removeClass("act");
	}
}

function chgIptNYXFMMStTips(obj){
	if(obj.value==""){
		document.getElementById('titlemms').value="请以“#所在城市#作品标题”的形式填写";
		//$(obj).removeClass("act");
	}
}


function clearIptTips(obj){
	if(obj.value=="小说作品内容要求具有情节性、趣味性和符合主题分类形式的完整故事内容"){
		document.getElementById('redcontent').value="";
	}
	//$(obj).addClass("act");
}
function clearIptNYXFTips(obj){
	if(obj.value=="请以“#所在城市#作品内容”的形式填写"){
		document.getElementById('smscontent').value="";
	}
	//$(obj).addClass("act");
}
function clearIptNYXFMMStTips(obj){
	if(obj.value=="请以“#所在城市#作品标题”的形式填写"){
		document.getElementById('titlemms').value="";
	}
	//$(obj).addClass("act");
}
/** 注册139 **/
function resgisterTo139(mobile){
	if(mobile==""){
		return ;
	}
	else{
		$.post("/gw/downhong.do?__method=ResgisterTo139",{mobile:mobile},function (data){
		if(data=="-1"){
			alert("系统忙，请稍候再试。");
		}
		else if(data=="0"){
			alert("["+mobile+"]已经注册。");
		}
		else{
			alert("注册移动微博成功。");
		}});
	}
}

/** 推荐作品 **/
function recommendDiary(diaryID){

		$.post("/diaryRecommend.do",{diaryID:diaryID},function (data){
		if(data=="0"){
			alert("您好！推荐红段子作品，请先登录/注册");
		}
		else if(data=="2"){
     		alert("对不起，今天您对该作品的推荐次数已达5次，请明天再继续推荐，谢谢！");
		}
		else if(data=="1"){
			alert("推荐成功。");
		}
		else{
			alert("系统繁忙，请稍后再试。");
		}});
	
}






