﻿function class_Form(element)
{
	var form=$(element);
	var inputs=form.find(":input");
	var shutup=false;

	for(var i=0;i<inputs.length;i++){if(inputs[i].name!="")eval("var "+inputs.eq(i).attr("name")+"=form.find(\"[name='"+inputs[i].name+"']\")");}

	this.Init=function()
	{
		form.submit(form_Submit);
		rechargeservice.click(rechargeservice_Click);

		var date=new Date();
		shipdate.css("cursor","pointer");
		shipdate.attr("readOnly",true);
		shipdate.attr("min",date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate());
		shipdate.click(function(){$.SetDate(this);});

		returndate.css("cursor","pointer");
		returndate.attr("readOnly",true);
		returndate.attr("min",date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate());
		returndate.click(function(){$.SetDate(this);});

		for(var i=0;i<10;i++){var option=$("<option/>");option.attr("text",date.getFullYear()+i);option.attr("value",date.getFullYear()+i);expyear.append(option);}
		var ms="January,February,March,April,May,June,July,August,September,October,November,December".split(",");
		for(var i=0;i<ms.length;i++){var option=$("<option/>");option.attr("text",ms[i]);option.attr("value",(i+1));expmonth.append(option);}

		//只为自己的号码进行Recharge
		phonenumber.change(phonenumber_change);
	}

	function phonenumber_change(e)
	{
		$.ClearError();
		if(this.value=="")
		{
			$(this).removeAttr("notus");
			return;
		}
		var fnResponse=function(json)
		{
			if(json.error==true)
			{
				$.ShowError(phonenumber,"Your number is not the scope of our services.");
				phonenumber.focus();
				phonenumber.attr("notus","true");
			}
			else
			{
				phonenumber.removeAttr("notus");
			}
		};
		url="/order_recharge.aspx?act=verifynumber&phonenumber="+this.value;
		$.getJSON(url,fnResponse);
	}

	function form_Submit(e)
	{
		$.ClearError();
		if(phonenumber.attr("notus")=="true")
		{
			$.ShowError(phonenumber,"Your number is not the scope of our services.");
			phonenumber.focus();
			return false;
		}
		var result=$.CheckEmpty();
		if(result==false)
			return false;
		session.val(Math.random());
		cardnumber.val(cardnumber.val().replace(/[^0-9]/g,""));
		return true;
	}

	function rechargeservice_Click()
	{
		if(this.value=="1")
		{
			shipdate.attr("disabled",false);
			returndate.attr("disabled",false);
			shipdate.parents("tr:first").find("th b").show();
			precard.attr("disabled",true);
			precard.parents("tr:first").find("th b").hide();
		}
		else
		{
			shipdate.attr("disabled",true);
			returndate.attr("disabled",true);
			shipdate.parents("tr:first").find("th b").hide();
			precard.attr("disabled",false);
			precard.parents("tr:first").find("th b").show();
		}
	}
}
