var W = screen.width;//取得屏幕分辨率宽度
var H = screen.height;//取得屏幕分辨率高度
var dragarr = new Array();

function M(id){
	return document.getElementById(id);//用M()方法代替document.getElementById(id)
}

var pos_x = [30,250,470,690,30,250,470,690];
var pos_y = [10,180,330,80,200]; 
function initDrag(){
	for(var l=dragarr.length-1; l>=0; l--){
		drag(document.getElementById(dragarr[l]),l);
	}
}
//div拖动
function drag(o,oindex) 
{
	var dbl = (oindex<12);
	var dbidx = Math.floor(Math.random()*2);
	if (typeof o == "string") o = document.getElementById(o);
	var ocn = $(o).children();
	$($(ocn).get(2)).css("background-image","url(/images/wish/a"+dbidx+"_b.gif)");
	o.style.left = (pos_x[parseInt(oindex%4)]+Math.floor(Math.random()*40)-Math.floor(Math.random()*20)+(dbl?0:20))+"px";
	o.style.top = (pos_y[parseInt(oindex/4)]+Math.floor(Math.random()*30)-Math.floor(Math.random()*10)+(dbl?0:40))+"px";
    o.orig_index = o.style.zIndex; 
    o.onmousedown = function(a)  
    {  
        this.style.cursor = "move";  
        this.style.zIndex = 10000+oindex;  
        var d=document;  
        if(!a)a=window.event;  
        var x = a.clientX+d.body.scrollLeft-o.offsetLeft;  
        var y = a.clientY+d.body.scrollTop-o.offsetTop;
        d.ondragstart = "return false;"  
        d.onselectstart = "return false;"  
        d.onselect = "document.selection.empty();"  
                  
        if(o.setCapture)  
            o.setCapture();  
        else if(window.captureEvents)  
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);  
	    
        d.onmousemove = function(a)  
        {  
           
			if(!a)a=window.event;  
            o.style.left = (a.clientX+document.body.scrollLeft-x)+"px";  
            o.style.top = (a.clientY+document.body.scrollTop-y)+"px";  
            o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;  
            o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
			if(parseInt(o.style.top.replace("px",""))> 400)
			{	
				o.style.top = 400+"px";
			}
			if(parseInt(o.style.top.replace("px",""))<5)
			{			
				o.style.top =5+"px";
			}
			if(parseInt(o.style.left.replace("px",""))>725)
			{			
					o.style.left = 725+"px";
			}
			if(parseInt(o.style.left.replace("px",""))<22)
			{			
					o.style.left = 22+"px";
			}				
			
		}  

        d.onmouseup = function()  
        {  
            if(o.releaseCapture)  
                o.releaseCapture();  
            else if(window.captureEvents)  
                window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);  
            d.onmousemove = null;  
            d.onmouseup = null;  
            d.ondragstart = null;  
            d.onselectstart = null;  
            d.onselect = null;  
            o.style.cursor = "normal";  
			//alert(document.getElementById("divcount").value);
            o.style.zIndex = parseInt(document.getElementById("divcount").value)+1;  
			document.getElementById("divcount").value=parseInt(document.getElementById("divcount").value)+1;  
        }  
    }
}

function toWish(){
	$('#swear').show('slow');
}

function resetSended(){
	$('#sending').hide();
	$('#submitbtn').removeAttr('disabled');
	changeImg($('#_l_regVCode'));
}
function sended(){
	$('#sending').hide();
	alert('发送寄语成功!');
	parent.location.href='/wish/net?t='+nowTime()+'#wishcontent';
}

function checkWish(){
	var name = $.trim(M('w_nickName').value);
	if(name=='') {alert('请输入您的昵称！');return false;}
	if(name.length>10) {alert('昵称最多只能10个字符！');return false;}
	var context = $.trim(M('w_context').value);
	if(context=='') {alert('请输入寄语内容！');return false;}
	if(context.length<6) {alert('寄语内容不能少于6个字符！');return false;}
	if(context.length>100) {alert('寄语内容最多只能100个字符！');return false;}
	var vc = $.trim(M('l_regVCode').value);
	if(vc=='') {alert('请输入验证码！');return false;}
	if(vc.length!=4) {alert('验证码不正确！');return false;}
	$('#sending').show();
	$('#submitbtn').attr("disabled","disabled");
	$.post("/wish/net!save",
		{'nickName':name,'context':context,'vc':vc,'t':nowTime()},
		function(data){
			if(data){
			 	alert(data);
				$('#sending').hide();
				$('#submitbtn').removeAttr('disabled');
				changeImg($('#_l_regVCode'));
			 }
			 else {
				$('#sending').hide();
				alert('发送寄语成功!');
				parent.location.href='/wish/net?t='+nowTime()+'#wishcontent';
			}
		}
	);
	return false;
}
