﻿///<reference path="../jquery/jquery-1.3.2-vsdoc.js" />
///这个不能删。兼容就的方式
$(function(){
    $("#VoteSubBtn").click(function(){
        var parent = $(this).parent().parent();
        var a,b;
        if(typeof checkfunction == "function")
            if(!checkfunction(parent))
                return false;
        var oriUrl = $("#VoteForm ").attr("action"); 
        if(parent.children("[name='gotourl']"))a=parent.children("[name='gotourl']").val();
        if(parent.children("[name='para']"))b=parent.children("[name='para']").val();
         if(a&&b){$("#VoteForm").attr("action",oriUrl+"?gotourl="+a+"&para="+b);}
         $("#VoteForm").submit();
    })
})
///下边这个主要是为了兼容同一页面上多个vote的情况，ID不能多个
$(function(){
    $("[name='VoteSubBtn']").click(function(){
        var parent = $(this).parent().parent();
        var a,b;
        if(typeof checkfunction == "function")//可以在页面上添加function checkfunction
            if(!checkfunction(parent))
                return false;
        var voteform = parent.find("#VoteForm ");
        var oriUrl = voteform.attr("action"); 
        if(parent.children("[name='gotourl']"))a=parent.children("[name='gotourl']").val();
        if(parent.children("[name='para']"))b=parent.children("[name='para']").val();
         if(a&&b){voteform.attr("action",oriUrl+"?gotourl="+a+"&para="+b);}
         voteform.submit();
    })
})

$("#dfe").each(function(){
    $(this).children("input,textarea,select")
})
function voter(){
   var votername = escape($("#votername").val());
    var voterphone = escape($("#voterphone").val());
    var voteremail= escape($("#voteremail").val());
    var voternote = escape($("#voternote").val());
    $.ajax({
		    url:'/myweb/webpost/InteractionResearchSubmit.ashx',
		    type:'POST',
		    data:{
		        type:"5",
		        votername:votername,
		        voterphone:voterphone,
		        voteremail:voteremail,
		        voternote:voternote,
		        coluid:$("#rescoluid").val(),
		        timestamp:new Date()
		    },
		     success:function(data){
		        if(data=="0")
		            alert("错误");
		        else
		        {
		            alert("提交成功");
		            var url=$("#VoteUrl").val();
		            if(typeof(url)!="undefined"){document.location = url;}
		        }
		     }
	})
}

function singlevoter(){
    var votername = escape($("#votername").val());
    var voterphone = escape($("#voterphone").val());
    var voteremail= escape($("#voteremail").val());
    var voternote = escape($("#voternote").val());
    var submitid ="";
    var paras = document.location.search;
    if(paras!="")
    {
        paras = paras.substring(1,paras.length).split('&');        
        for (i=0;i<paras.length;i++)   {
            key = paras[i].split('=');           
            if(key[0] == "submitid")
            {
                submitid = key[1];
                break;
            }
        }
    }
    $.ajax({
		    url:'/myweb/webpost/InteractionResearchSubmit.ashx',
		    type:'POST',
		    data:{
		        type:"6",
		        votername:votername,
		        voterphone:voterphone,
		        voteremail:voteremail,
		        voternote:voternote,
		        submitid:submitid,
		        timestamp:new Date()
		    },
		     success:function(data){
		        if(data=="0")
		            alert("错误");
		        else
		        {
		            alert("提交成功");
		            var url=$("#VoteUrl").val();
		            if(typeof(url)!="undefined"){document.location = url;}
		        }
		     }
	})
}

var Vote = {
	id:null,
	length:1.0,
	coluid:null,
	obj:new Object(),
	Init:function(v,l){
		Vote.id = v;
		Vote.length = parseFloat(l);
		Vote.coluid = $("#rescoluid").val();
		$.ajax({
		    url:'/myweb/webpost/InteractionResearchSubmit.ashx',
		    type:'POST',
		    data:{
		        type:"0",
		        id:v,
		        coluid:Vote.coluid,
		        timestamp:new Date()
		    },
		    success:function(data){
		    data = data.replace(/\r?\n/ig,"<br>");
		        var jsonstring = eval("("+data+")"); 
		        var submitid = jsonstring.SubmitID;
		        var id = jsonstring.ID;
		        var title = jsonstring.Title;
		        var desc = jsonstring.Desc;
		        var sum = jsonstring.Sum;
		        var order = jsonstring.Order;
		        var op1 = jsonstring.Op1;
		        var op2 = jsonstring.Op2;
		        var op1Desc = jsonstring.Op1Desc;
		        var op2Desc = jsonstring.Op2Desc;
		        var op1Count = jsonstring.Op1Count;
		        var op2Count = jsonstring.Op2Count;
		        var voteCount = jsonstring.Count;
		        Vote.id = id;
		        $("#research_title").html(title);
		        $("#research_desc").html(desc);
		        $(".research_op1").each(function(){$(this).html(op1);});
		        $(".research_op2").each(function(){$(this).html(op2);});
		        $("#research_op1desc").html(op1Desc);
		        $("#research_op2desc").html(op2Desc);
		        $("#research_op1count").html(op1Count);
		        $("#research_op2count").html(op2Count);
		        $("#research_sum").html(sum);
		        $("#research_op1pic").find("img").attr("height",op1Count/Vote.length);
		        $("#research_op2pic").find("img").attr("height",op2Count/Vote.length);
		        $("#votecount").html(voteCount);
		        
		    }
		})
	},
	Join:function(g){
	    $.ajax({
		    url:'/myweb/webpost/InteractionResearchSubmit.ashx',
		    type:'POST',
		    data:{
		        type:"1",
		        id:Vote.id,
		        value:g,
		        timestamp:new Date()
		    },
		    success:function(data){
		    data = data.replace(/\r?\n/ig,"<br>");
		        var jsonstring = eval("("+data+")"); 
		        if(jsonstring.Order=="true")
		        {
		            alert("您已经投票了");
		        }
		        else
		        {
		            if($("#showalert").val()=="1")
		            {
		                if(typeof($("#alertnext").val())!="undefined")
		                    alert($("#alertnext").val());
		                else
		                    alert("感谢您的参与");		        		            
		            }	        		            
		            var sum = jsonstring.Sum;
		            var op1Count = jsonstring.Op1Count;
		            var op2Count = jsonstring.Op2Count;
		            var submitID = jsonstring.SubmitID;
		            $("#research_op1count").html(op1Count);
		            $("#research_op2count").html(op2Count);
		            $("#research_sum").html(sum);
		            $("#research_op1pic").find("img").attr("height",op1Count/Vote.length);
		            $("#research_op2pic").find("img").attr("height",op2Count/Vote.length);
		            
		            var url=$("#VoteUrl").val();

		            if(typeof(url)!="undefined"){
		                var showtype=$("#VoteUrl").attr("showtype"); 

		                if(showtype=="1")
		                {
		                    window.open(url+"?submitid="+submitID, "填写用户信息");
		                }
		                else
		                {
		                    document.location = url;
		                }
		            }
		        }
		    }
		})
	},
	Next:function(g){
	    $.ajax({
		    url:'/myweb/webpost/InteractionResearchSubmit.ashx',
		    type:'POST',
		    data:{
		        type:"2",
		        id:Vote.id,
		        value:g,
		        usecookie:$("#usecookie").val(),
		        coluid:Vote.coluid,
		        timestamp:new Date()
		    },
		    success:function(data){
		    data = data.replace(/\r?\n/ig,"<br>");
		        var jsonstring = eval("("+data+")"); 
		        if(jsonstring.Order=="true")
	            {
	                alert("您已经投过票了");
	                return;
	            }
		        if(jsonstring.ID=="")
		        {
		            alert("此次投票结束，感谢您的参与");
		            
		            var sum = jsonstring.Sum;
		            var op1Count = jsonstring.Op1Count;
		            var op2Count = jsonstring.Op2Count;
		            $("#research_op1count").html(op1Count);
		            $("#research_op2count").html(op2Count);
		            $("#research_sum").html(sum);
		            $("#research_op1pic").find("img").attr("height",op1Count/Vote.length);
		            $("#research_op2pic").find("img").attr("height",op2Count/Vote.length);
		            
		            var url=$("#VoteUrl").val();
		            if(typeof(url)!="undefined"){
		                var showtype=$("#VoteUrl").attr("showtype"); 
		                if(showtype=="1")
		                {
		                    window.open(url, "填写用户信息");
		                }
		                else
		                {
		                    document.location = url;
		                }
		            }
		            
		            
		            return;
		        }
		        else
		        {
		            if($("#showalert").val()=="1")
		            {
		                if($("#alertnext").val()!="")
		                    alert($("#alertnext").val());
		                else
		                    alert("感谢您的参与");		        		            
		            }
		            var sum = jsonstring.Sum;
		            var op1Count = jsonstring.Op1Count;
		            var op2Count = jsonstring.Op2Count;
		            $("#research_op1count").html(op1Count);
		            $("#research_op2count").html(op2Count);
		            $("#research_sum").html(sum);
		            $("#research_op1pic").find("img").attr("height",op1Count/Vote.length);
		            $("#research_op2pic").find("img").attr("height",op2Count/Vote.length);
		        }
		        Vote.Init(jsonstring.ID,Vote.length);
		    }
		})
	},
	PreInit:function(){
	    $.ajax({
	        url:'/myweb/webpost/InteractionResearchSubmit.ashx',
	        type:'POST',
	        data:{
	            type:"3",
	            id:Vote.id,
	            coluid:Vote.coluid,
	            timestamp:new Date()
	        },
	        success:function(data){
	            data = data.replace(/\r?\n/ig,"<br>");
	            var jsonstring = eval("("+data+")"); 
	            if(jsonstring.ID=="")
	            {
	                alert("已经是第一个选项了");
	            }
	            else
	            {
	                if(jsonstring.Order=="false")
	                {
	                    alert("请选择当前项");
	                }
	                else
	                {
	                    var id = jsonstring.ID;
	                    var title = jsonstring.Title;
	                    var desc = jsonstring.Desc;
	                    var sum = jsonstring.Sum;
	                    var order = jsonstring.Order;
	                    var op1 = jsonstring.Op1;
	                    var op2 = jsonstring.Op2;
	                    var op1Desc = jsonstring.Op1Desc;
	                    var op2Desc = jsonstring.Op2Desc;
	                    var op1Count = jsonstring.Op1Count;
	                    var op2Count = jsonstring.Op2Count;
	                    Vote.id = id;
	                    $("#research_title").html(title);
	                    $("#research_desc").html(desc);
	                    $(".research_op1").each(function(){$(this).html(op1);});
	                    $(".research_op2").each(function(){$(this).html(op2);});
	                    $("#research_op1desc").html(op1Desc);
	                    $("#research_op2desc").html(op2Desc);
	                    $("#research_op1count").html(op1Count);
	                    $("#research_op2count").html(op2Count);
	                    $("#research_sum").html(sum);
	                    $("#research_op1pic").find("img").attr("height",op1Count/Vote.length);
	                    $("#research_op2pic").find("img").attr("height",op2Count/Vote.length);
	                }
	            }
    	        
	        }
	    })
	},
	NextInit:function(){
		$.ajax({
		    url:'/myweb/webpost/InteractionResearchSubmit.ashx',
		    type:'POST',
		    data:{
		        type:"4",
		        id:Vote.id,
		        coluid:Vote.coluid,
		        timestamp:new Date()
		    },
		    success:function(data){
		    data = data.replace(/\r?\n/ig,"<br>");
		        var jsonstring = eval("("+data+")"); 
		        if(jsonstring.ID=="")
		        {
		            alert("已经是最后一个选项了");
		        }
		        else
		        {
		            if(jsonstring.Order=="false")
	                {
	                    alert("请选择当前项");
	                }
	                else
	                {
		                var id = jsonstring.ID;
		                var title = jsonstring.Title;
		                var desc = jsonstring.Desc;
		                var sum = jsonstring.Sum;
		                var order = jsonstring.Order;
		                var op1 = jsonstring.Op1;
		                var op2 = jsonstring.Op2;
		                var op1Desc = jsonstring.Op1Desc;
		                var op2Desc = jsonstring.Op2Desc;
		                var op1Count = jsonstring.Op1Count;
		                var op2Count = jsonstring.Op2Count;
		                Vote.id = id;
		                $("#research_title").html(title);
		                $("#research_desc").html(desc);
		                $(".research_op1").each(function(){$(this).html(op1);});
		                $(".research_op2").each(function(){$(this).html(op2);});
		                $("#research_op1desc").html(op1Desc);
		                $("#research_op2desc").html(op2Desc);
		                $("#research_op1count").html(op1Count);
		                $("#research_op2count").html(op2Count);
		                $("#research_sum").html(sum);
		                $("#research_op1pic").find("img").attr("height",op1Count/Vote.length);
		                $("#research_op2pic").find("img").attr("height",op2Count/Vote.length);
		            }
		        }
		    }
		})
	}
}
	
 

