var InitSchemeExtends = new Class({ 
    Extends : InitScheme,
    
    initialize: function(initFormId){ 
       this.parent(initFormId); 
       this.initForm.removeEvents('submit');
       
       var alias = this;
	   var fn = function() {
		   var usermoneyObj = $('isNeedUpdateId');
	    	if(usermoneyObj!=null){
	    	   getUserMoney();
	    	}
	    	if(alias.isBeforehand()){
	    		var saleType = getRadioVal(alias.initForm,"saleType");
	    		var heightpx = 0;
		    	if(checkSysFirefox()&&saleType == alias.saleTypes.share){
		    		heightpx = 195;
		    	}else if(checkSysFirefox()&&saleType == alias.saleTypes.self){
		    		heightpx = 115;
		    	}else if(saleType == alias.saleTypes.share){
		    		heightpx = 210;
		    	}else{
		    		heightpx = 120;
		    	}
				$floater({
					height:heightpx,
					width:548,
					src: Betzc.base+'/html/sp/beforehandschemeconfirm.html?noCache='+new Date().getTime(),
					title:'盈彩网',
					cover:true,
					beforeClose:function(){
					}
				});	
	    	}else{
	    		var isPoly = alias.isPoly();
		    	if(isPoly){
		    		var saleType = getRadioVal(alias.initForm,"saleType");
		    		var heightpx = 0;
			    	var timestr = $('selected_scheme_endtime').get('text');
			    	if(checkSysFirefox()&&saleType == alias.saleTypes.share){
			    		heightpx = 445;
			    	}else if(checkSysFirefox()&&saleType == alias.saleTypes.self){
			    		heightpx = 368;
			    	}else if(saleType == alias.saleTypes.share){
			    		heightpx = 460;
			    	}else{
			    		heightpx = 373;
			    	}
			    	
					$floater({
						height:heightpx,
						width:538,
						src: Betzc.base+'/html/sp/schemeconfirm.html?noCache='+new Date().getTime(),
						title:'盈彩网<span style="color:#794E4F;font-size:12px;">&nbsp;&nbsp;本方案截止时间：<span style="color:#CC0000;">'+timestr+'</span></span>',
						cover:true,
						beforeClose:function(){
						}
					});
		    	}else{
		    		var saleType = getRadioVal(alias.initForm,"saleType");
		    		var heightpx = 0;
		    		var timestr = $('selected_scheme_endtime').get('text');
			    	if(checkSysFirefox()&&saleType == alias.saleTypes.share){
			    		heightpx = 255;
			    	}else if(checkSysFirefox()&&saleType == alias.saleTypes.self){
			    		heightpx = 175;
			    	}else if(saleType == alias.saleTypes.share){
			    		heightpx = 270;
			    	}else{
			    		heightpx = 180;
			    	}
					$floater({
						height:heightpx,
						width:548,
						src: Betzc.base+'/html/sp/singleschemeconfirm.html?noCache='+new Date().getTime(),
						title:'盈彩网<span style="color:#794E4F;font-size:12px;">&nbsp;&nbsp;本方案截止时间：<span style="color:#CC0000;">'+timestr+'</span></span>',
						cover:true,
						beforeClose:function(){
						}
					});
		    	}
	    	}
		};
		var spbuyschemeinput = $('sp_buy_scheme_inputid');
		spbuyschemeinput.addEvent('click', function(e) {
			new Event(e).stop();//停止表单的提交事件
			
			if(alias.checkSchemeForm()){
				LoingDialog.show({
					el : null,
					method : fn
				});
			}
		});
    },
    
    sumbitscheme : function(childobj){
        var alias = this;
 	    var formActionUrl = alias.initForm.get('action');
		alias.initForm.set('action', formActionUrl.replace(/![a-zA-Z]+./ig, '!init.'));
		alias.initForm.set('target', null);
		if(alias.isUploadFile()){
			alias.initForm.formUpload(schemeFormOption);
		}else{
			alias.initForm.getElements('input[type=file]').set('disabled',true);
			var tempchilddivobj = childobj.document.getElementById('childsubmit_divid');
			var tempchildwaitdivobj = childobj.document.getElementById('childsubmitwaiting_divid');
			var schemeFormOption = {
					onRequest: function(instance){
				        tempchilddivobj.style.display = 'none';
				        tempchildwaitdivobj.style.display = '';
					},
				    onSuccess: function(responseText, responseXML){
						var request_token_el = alias.initForm.elements['request_token'];
						if(request_token_el != null){
							request_token_el.value = new Date().getTime() + Math.random();
						}
				        tempchilddivobj.style.display = '';
				        tempchildwaitdivobj.style.display = 'none';
				    	var jsonObj = JSON.decode(responseText);
				    	if(jsonObj.success=='false'){
				    		alert(jsonObj.msg);
				    	}else{
				    		alias.initForm.getElements('input[type=file]').set('disabled',false);
					    	window._tipsHandle.close();
							$floater({
								height:200,
								width:548,
								src:Betzc.base+'/scheme!showSumbitScheme.action?schemeNum='+jsonObj.msg,
								title:"盈彩网",
								cover:true,
								beforeClose:function(){
								}
							});
				    	}
					   var usermoneyObj = $('isNeedUpdateId');
				    	if(usermoneyObj!=null){
				    	   getUserMoney();
				    	}

					},
					onFailure: function(instance){
				        tempchilddivobj.style.display = '';
				        tempchildwaitdivobj.style.display = 'none';
						window.alert("提交出错了,可能是网络故障,请重试!");
					}
			};
			alias.initForm.set('send', schemeFormOption);
			alias.initForm.send();
		}
    },
    
	/**
	 * 初始化调用
	 */
	saleTypeAddEvents : function (obj){
		obj.trs[obj.saleTypes.share] = ['tr_minJoinCost','tr_joinCost','tr_baodiCost'];
		obj.trs[obj.saleTypes.self] = [];
		
		if(!obj.isBeforehand()){
		   var arr = obj.initForm.getElements('input[_name=multiple]');
			arr.addEvents({
				'blur' : function(){
					this.className='header_searchinput';
					obj.chkMultiple(this);
				},
				'focus' : function(){
					this.className='header_searchclick'
				},
				'keyup' : function(e){
					var mul = parseInt(this.value, 10);
					if(mul>window.MAX_MULTIPLE){
						new Event(e).stop();
						this.value = window.MAX_MULTIPLE;
					}
					for(var i=0;i<arr.length;i++){
						var tempmultipleobj = arr[i];
						if(tempmultipleobj!=this){
							tempmultipleobj.value = this.value;
						}
					}
					obj.updateBetCost();
				}
			});
			
			 var arr1 = obj.initForm.getElements('img[_name=multiple_ad]');
			  if(arr1.length>0){
				arr1.addEvents({
					'click':function(){
						var _value=this.get('_value');
						var othermultiple = $('_othercountpeitouid');
						var val = parseInt(othermultiple.value);
						if(isNaN(val)){
							val = 1;
						}
						if(_value>0){
							val++;
						}
						else{
							val--;
						}
						val = val > window.MAX_MULTIPLE ? window.MAX_MULTIPLE:val;
						val = val < 1 ? 1 : val;
						
						var arrtemp = obj.initForm.getElements('input[_name=multiple]');
						for(var i=0;i<arrtemp.length;i++){
							var tempmultipleobj = arrtemp[i];
							if(tempmultipleobj!=this){
								tempmultipleobj.value = val;
							}
						}
						//
						obj.updateBetCost();
						
					}
				});
			  }
		}	
	},
    
    /**
	 * 切换购买方式
	 */
	chgSaleType: function (el,event){
		var initScheme = this;
		var isPoly = initScheme.isPoly();
	    	     
		var saveTypeObj = null;
		saveTypeObj = el;
           
	    //切换购买方式
        initScheme.stChange(el,event);
      
		var arr = initScheme.initForm.elements['saleType'];
		if(!arr.length) arr = [arr];
		
		// 更变对应label的颜色
		var tempObj;
		for(var i=0,len=arr.length;i<len;i++){
			tempObj = initScheme.initForm.getElement('label[for='+arr[i].id+']');
			tempObj.className = (el.id == arr[i].id)?'font14char redboldchar':'font14char boldchar';
		}
	
	   var usermoneyObj = $('isNeedUpdateId');
    	if(usermoneyObj!=null){
    	   getUserMoney();
    	}
	
		$('tb_singleandpoly').setStyle('display', ''); 
		$('tr_peitou').setStyle('display', isPoly?'none':''); 
    	
		var secretarr = initScheme.initForm.elements['secretType'];
		if(!secretarr.length) secretarr = [secretarr];
		
		// 更变对应label的颜色
		var secrettempObj;
		for(var i=0,len=secretarr.length;i<len;i++){
			secrettempObj = initScheme.initForm.getElement('label[for='+secretarr[i].id+']');
			secretarr[i].checked = (secrettempObj.className=='char12redbold')?true:false;
		}
				    	
	},
	
	/**
	 * 更新赔投数
	 * 由子类覆盖
	 */
	updateInputValue : function (obj){
		this.initForm.getElements('input[_name=multiple]').each(function(item){
			item.value = 1;
		});
	},
	
	/**
	 * 更变对应label的颜色
	 * 由子类覆盖
	 */
	updateBetUnitsLabel : function (){
	}
	
});

function childwinopentarget(url){
	window._tipsHandle.close();
	window.open(url,'_blank');
 }

function userloginsp(){
    LoingDialog.show( {
		method : function() {
			   var usermoneyObj = $('isNeedUpdateId');
		       if(usermoneyObj!=null){
		    	   getUserMoney();
		       }
		}
});
}

function getUserMoney(){
   var usermoneyUrl = Betzc.base + '/user!userMoney.action';
   var req = new Request({
	 	 url: usermoneyUrl,
	     method:'get' ,
	     onSuccess: function(responseText) {
			if(isJsonString(responseText)){
	    		var jsonObj = JSON.decode(responseText);
				if(jsonObj.success){
					$('isNeedUpdateId').setProperty('text',jsonObj.msg+'元');
					$('isNeedUpdateSpanId').setStyle('display', '');
				}
	    	}
	     }
	 }).send();
}

function checkSysFirefox(){
	var isFirefox = false;
	try{
	    var Sys = {};
	    var ua = navigator.userAgent.toLowerCase();
	    var s;
	    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
	    (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
	    (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
	    (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
	    (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
	    isFirefox = Sys.firefox;
	}catch(e){
		isFirefox = false;
	}
	return isFirefox;
}
