jQuery.noConflict();
jQuery.ajaxSetup({cache:false});

function GoPage(paging_id,page)
{
    var i = jQuery(paging_id).find("strong:first").text();  //取得当前页码
    var j = parseInt(page);  //要转到的页码
    var z = parseInt(jQuery(paging_id).find("a:last").text());  //最后一页的页码
   
    if(z <= 10)
    {
	    jQuery(paging_id).html("")
	    for(m=1;m<=z;m++)
	    {
		    if(m == j)
		    {
			    if(m == z)
			    {
				    jQuery(paging_id).append("<strong>" + j + "</strong><a href=\"#\" style=\"display:none;\">" + j + "</a>");
			    }
			    else
			    {
				    jQuery(paging_id).append("<strong>" + j + "</strong>");
			    }
		    }
		    else
		    {
			    jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','" + m + "')\">" + m + "</a>");
		    }
	    }
    }
	else
	{
	    if(j < 7)
		{
		    jQuery(paging_id).html("")
			for(m=1;m<=7;m++)
			{
			    if(m == j)
			    {
				   jQuery(paging_id).append("<strong>" + j + "</strong>");
			    }
			    else
			    {
			 	   jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','" + m + "')\">" + m + "</a>");
			    }
			}
			jQuery(paging_id).append("<font>...</font>");
			jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','" + (z-1) + "')\">" + (z-1) + "</a>")
			jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','" + z + "')\">" + z + "</a>")
		}

		if(j>=7 && j<=(z-6))
		{
		    jQuery(paging_id).html("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','1')\">1</a>")
			jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','2')\">2</a><font>...</font>")
		    for(m=(j-2);m<=(j+2);m++)
		    {
		 	    if(m == j)
				{
				    jQuery(paging_id).append("<strong>" + j + "</strong>");
				}
				else
				{
				    jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','" + m + "')\">" + m + "</a>");
				}
			}
			jQuery(paging_id).append("<font>...</font>");
			jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','" + (z-1) + "')\">" + (z-1) + "</a>")
			jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','" + z + "')\">" + z + "</a>")
		}

		if(j>(z-6) && j<=z)
		{
		    jQuery(paging_id).html("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','1')\">1</a>")
			jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','2')\">2</a><font>...</font>")
		    for(m=(z-6);m<=z;m++)
		    {
		 	    if(m == j)
				{
				    if(m == z)
				    {
				 	    jQuery(paging_id).append("<strong>" + j + "</strong><a href=\"#\" style=\"display:none;\">" + j + "</a>");
				    }
					else
					{
						jQuery(paging_id).append("<strong>" + j + "</strong>");
					}
				}
				else
				{
				    jQuery(paging_id).append("<a href=\"javascript:void(0)\" onclick=\"GoPage('" + paging_id + "','" + m + "')\">" + m + "</a>");
				}
			}
		}
	}
	
	show_order_list("",page,"")
}

function previous_page(paging_id)
{
	var i = parseInt(jQuery(paging_id).find("strong:first").text());
	if( (i-1) > 0 )
	{
		GoPage(paging_id,(i-1))
	}
}

function next_page(paging_id)
{
	var i = parseInt(jQuery(paging_id).find("strong:first").text());
	var z = parseInt(jQuery(paging_id).find("a:last").text());
	if( i < z )
	{
		GoPage(paging_id,(i+1))
	}
}

function dialog_move(down_id,move_id)
{	
	jQuery(down_id).mousedown
	(
		function(e)
		{	
			var fx = e.pageX - jQuery(move_id).css("left").replace(/px/,"")
			var fy = e.pageY - jQuery(move_id).css("top").replace(/px/,"")
			
			jQuery(move_id).bind
			(
				"mousemove",
				function(e)
				{	
					jQuery(move_id).css
					({
						"left":(event.clientX - fx) + "px",
						"top":(event.clientY - fy) + "px"
					})
				}
			)
						
		}
		
	).mouseup(function(){jQuery(move_id).unbind("mousemove")})
}

function print_div(print_id)
{
	jQuery(print_id).printElement()
}

function checkbox_select(select_id,input_name,color1,color2)
{
	if(jQuery(select_id).prop("checked") == true)
	{
		jQuery("input[name='" + input_name + "']").prop({"checked":true})
		jQuery("input[name='" + input_name + "']").parent().parent().css({"background-color":color1}).unbind("mouseout")
	}
	else
	{
		jQuery("input[name='" + input_name + "']").prop({"checked":false})
		jQuery("input[name='" + input_name + "']").parent().parent()
		.bind
		(
			"mouseout",
			function(){jQuery(this).css({"background-color":color2})}
		)
		.css({"background-color":color2})
	}
}

function show_province(province_id,district_id)
{
	jQuery(province_id).load
	(
		"/communal/server/tools.aspx?option=province",
		function()
		{
			jQuery(district_id).load("/communal/server/tools.aspx?option=district")
			jQuery("#user_province").change
			(
				function()
				{
					jQuery(district_id).load("/communal/server/tools.aspx?option=district&district=" + encodeURI(jQuery("#user_province").val()))
				}
			)
		}
	)
}

function show_subscribe_date(subscribe_date_id)
{
	jQuery(subscribe_date_id).load
	(
		"/communal/server/tools.aspx?option=subscribe_date",
		function()
		{
			jQuery(subscribe_date_id).find("select").change
			(
				function()
				{
					check_value("#user_periods")
				}
			)
			check_value("#user_periods")
			check_value("#user_amount")
		}
	)
}

function check_value(id,ischeck)
{
	var val = new Array;
	var new_val = "";
	
	val = jQuery(id).val().split('');
	
	for(i=0;i<val.length;i++)
	{
		if( val[i] != " " )
		{
			new_val += val[i];
		}
	}
	
	jQuery(id).val(new_val);
	
	switch(id)
	{
		case "#user_name":
			if( new_val.length < 2 || isNaN(new_val) == false )
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />");
				if(ischeck == "1")
				{
					jQuery("#user_mobile").val("");
					jQuery("#user_mobile").attr({"disabled":"disabled"});
					jQuery("#user_mobile_judge").html("");
				}
			}
			else
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />");
				jQuery("#user_recipients").val(jQuery(id).val())
			 	check_value("#user_recipients")
				if(ischeck == "1")
				{
					jQuery("#user_mobile").removeAttr("disabled");
				}
			}
			break;
		
		case "#user_mobile":
			if(new_val.length < 11 || isNaN(new_val) == true)
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />");
			}
			else
			{
				var i = new_val.substring(0,2);
				if(i != "13" && i != "15" && i != "18")
				{
					jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />");
				}
				else
				{
					jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />");
					if( ischeck == "1" )
					{
						check_pay();
					}
				}
			}
			break;
			
		case "#user_address":
			if( new_val.length < 5 )
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />");
			}
			else
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />");
			}
			break;
			
		case "#user_postcode":
			if( new_val.length < 6 || isNaN(new_val))
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />");
			}
			else
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />");
			}
			break;
			
		case "#user_recipients":
			if( new_val.length < 2 || !isNaN(new_val) )
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />");
			}
			else
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />");
			}
			break;
			
		case "#user_periods":
			var i = parseInt(jQuery("#user_start_year").val(),10)
			var j = parseInt(jQuery("#user_finish_year").val(),10)
			var m = parseInt(jQuery("#user_start_month").val(),10)
			var n = parseInt(jQuery("#user_finish_month").val(),10)
			
			if(j-i < 0)
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />")
				jQuery("#user_periods").val("-1")
			}
			else
			{
				if(j-i == 0)
				{
					if(n-m < 0)
					{
						jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />")
						jQuery("#user_periods").val("-1")
					}
					else
					{
						jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />")
						jQuery("#user_periods").val(j-i-m+n+1)
					}
				}
				else
				{
					jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />")
					jQuery("#user_periods").val((j-i)*12-m+n+1)
				}
			}
			break;
			
		case "#user_amount":
			if(isNaN(new_val) || new_val.substring(0,1) == "0")
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />");
			}
			else
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />");
			}
			break;
		
		case "#user_invoice_title":
			if( new_val.length < 2 || !isNaN(new_val) )
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />");
			}
			else
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />");
			}
			break;
			
		case "#user_invoice_address":
			if( new_val.length < 5 )
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/error.gif\" alt=\"错误\" />");
			}
			else
			{
				jQuery(id + "_judge").html("<img src=\"/communal/images/validity.gif\" alt=\"正确\" />");
			}
			break;
	}
}

function loginout()
{
	jQuery.ajax
	({
		url:"/communal/server/tools.aspx?option=loginout",
		success:function(){top.location = "/manage/login/login.shtml";}
	})
}
