document.getElementById('userID').value = document.getElementById('userID').value!='' ? document.getElementById('userID').value : getCookie('hjsm_userid');

window.onload = function (){
	document.getElementById('account').focus();
};
var payType;
var payWay = new Array(
	'网上银行支付订单',
	'嘟嘟牛网上充值订单',
	'手机语音充值订单',
	'神州行充值订单',
	'手机短信充值订单',
	'互联星空充值订单',
	'联通卡充值订单',
	'eBilling电话充值订单',
	'财付通充值订单'
);
var compWay = new Array(
	'请您在新打开的页面上完成充值',
	'请您在嘟嘟牛软件中完成充值',
	'请您在新打开的页面上完成充值',
	'请您在新打开的页面上完成充值',
	'请您在新打开的页面上完成充值',
	'请您在新打开的页面上完成充值',		
	'请您在新打开的页面上完成充值',
	'请您在新打开的页面上完成充值'
);

if(getCookie('hjsm_username')){
	var c_username;
	var p_username = decodeURIComponent(getCookie('hjsm_p_username'));
	var h_username = decodeURIComponent(getCookie('hjsm_username'));
	if(p_username.indexOf('@')==-1 && p_username!='null')
	{
		p_username = p_username;//+'@tom.com'
	}
    c_username = (p_username!='null') ? p_username : h_username;
	document.getElementById('account').value = c_username;
}


var payActions = new Array(
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/create_mobile_user.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php',
	'http://hjsm.tom.com/new_hj/user/pay/channel_router.php'
);
/**
 *  默认写如浮出层外围的层
 */
function hideHtml(name, innhtml, ih, iw){
    window.scroll(0,0);
    var width  = Math.max(document.body.scrollWidth, window.screen.width);
    width = width - 21;
    var height = Math.max(document.body.scrollHeight, window.screen.height);
    var top  = Math.max(0, Math.round((window.screen.height - ih - 150) / 2));
    var left = Math.max(0, Math.round((document.body.scrollWidth  - iw) / 2));
    height += 200;

	var html = 
	'  <div style=" -moz-opacity: 0.8;filter:Alpha(opacity=70);opacity:0.5;background:#ffffff; height:'+height+'px;' +
	'       width:'+width+'px; position:absolute; left: 0px; top: 0px; display:none;' +
	'       background-color: #CCCCCC; layer-background-color: #CCCCCC; ' +
	'       border: 1px none #000000; overflow: auto; z-index:65533" ' +
	'       id='+name+'_bg name='+name+'_bg>' +
	'    <iframe frameborder="0" border="0" width="'+width+'px" height="'+height+'px" src="about:blank"></iframe>' +
	'  </div>' +
	'  <div id='+name+'_info name='+name+'_info' +
	'       align="left"  style="text-align:center; position:absolute; withd:600px;height:500px;' +
	'       top: '+top+'px; left: '+left+'px; background-color: #0000FF; ' +
	'       margin:0 auto; display:none; height:10px; width:10px; z-index:65534">' +
	        innhtml +
	'  </div>';
	//salert(html);
    document.write(html);	
}
/**
 * 写入提交订单的浮出层
 */
function hidePayConfirmDiv(submit_func,type){
  //alert(type);
  var title_img = "",submit_img='btn_07.gif',cancel_img='btn_08.gif';
  var html ='';
  if(type == 1){
  	title_img = "title_01.gif";
  	submit_img = 'btn_03.gif';
  	cancel_img = 'btn_04.gif';
  }else if(type==3){
  	title_img = "title_03.gif";
  }else if(type==4){
  	title_img = "title_02.gif";
  }else if(type==6){
  	title_img = "title_05.gif";
  }else if(type==2){
  	title_img = "title_08.gif";
  }else if(type==9){
	  title_img = "title_zfb_02.gif";
	  submit_img = "btn_zfb.gif";
	  cancel_img = "btn_04.gif";
  }else if(type==10)
  {
	  title_img="title_ltk.gif";
  }
  else if(type==11)
  {
	  title_img="title_eBilling.gif";
  }
    else if(type==12)
  {
	  title_img="title_cft.gif";
  }

	  html += '<div class="tMain" style="width:500px;">'+
		'<div class="close"><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/close.gif" alt="关闭" onclick=\'closeDiv("div_redeem_confirmed");\'/></div>'+
		'<div class="titleTxt"><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/'+title_img+'"/></div>'+
		'<ul>'+
		'	<li>充值账号：<span class="bold" id="number"></span></li>'+
		'	<li>充值金额：<span class="bold fRed" id="m"> 元</span></li>'+
		'	<li>支付方式：<span class="bold" id="pay_type"></span></li>'+
		'</ul>'+
		'<div class="btn">'+
		'	<a href="#" onclick="'+submit_func+'"><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/'+submit_img+'" /></a>'+
		'	<a href="#" onclick=\'closeDiv("div_redeem_confirmed");\'><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/'+cancel_img+'" /></a>'+
		'</div>'+
	'</div>	';

  hideHtml("div_redeem_confirmed", html, 300, 300);	
}
/**
 * 特殊处理语音短信浮出层
 */
function hidePayConfirmMobileInfoDiv(submit_func,type){
  var info = "";
  if(type == 5){
  	info = "手机短信充值订单";
  }else{
  	info = "手机包月充值订单";
  }
  var html ='';
   html += '<div class="tMain" style="width:500px;">'+
		'<div class="close"><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/close.gif" alt="关闭" onclick=\'closeDiv("div_redeem_confirmed")\'/></div>'+
		'<div class="titleTxt"><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/title_04.gif"/></div>'+
		'<ul>'+
		'	<li>充值账号：<span class="bold" id="number"></span></li>'+
		'	<li>手机号：<span class="bold fRed" id="m"> 元</span></li>'+
		'	<li>支付方式：<span class="bold" >手机短信</span></li>'+
		'</ul>'+
		'<div class="btn">'+
		'	<a href="#" onclick="'+submit_func+'"><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/btn_07.gif" /></a>'+
		'	<a href="#" onclick=\'closeDiv("div_redeem_confirmed")\'><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/btn_08.gif" /></a>'+
		'</div>'+
	'</div>	';
 
	hideHtml("div_redeem_confirmed", html, 300, 300);	
}
/**
 * 写入提交订单完成的浮出层
 */
function hidePayCompleteDiv(type){
	var html ='<div class="tMain">'+
	'<div class="close"><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/close.gif" alt="关闭" onclick=\'closeDiv("div_redeem_completed")\'/></div>'+
	'<div class="titleTxt"><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/title_10.gif" alt="充值" /></div>'+
	'<ul class="wider">'+
	'<li><a href="#" target="_blank"><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/icon_06.gif" alt="新打开页面" border="0" /></a>&nbsp;请您在新打开的页面上完成充值。</li>'+
	'<li>请根据情况点击下面按钮，完成充值后再关闭此窗口。</li>'+
	'<li>&nbsp;</li>'+
	'</ul>'+
	'<div class="btn">'+
	'	<a href="#"  onclick=\'closeCompleteDiv("div_redeem_completed")\'><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/btn_05.gif" alt="已充值成功，到推荐榜看书>>" /></a>'+
	'	<a href="#" onclick=\'closeDiv("div_redeem_completed")\'><img src="http://pic.hjsm.tom.com/hj_site/payCenter/images/btn_06.gif" alt="使用其他充值方式" /></a>'+
	'</div>'+
'</div>'; 
      hideHtml("div_redeem_completed", html, 300, 300);
}
/**
 *  层的显示和展现的方法(可以写入MyTool的方法列表)
 */
function hjsDisplayElement(id,display){
	var element = document.getElementById(id);	
	if(element){
		element.style.display = (display)? "block":"none";	
	}
}

function getTextValue(id){
	var item = document.getElementById(id);
	if(item){
		return item.value;	
	}
}
/**
 *  检查两次用户输入账号的正确性
 */
function checkAccount(){
	if(getTextValue("account") != getTextValue("accountCheck")){
		document.getElementById("accountMsg").innerHTML = "有误，请重新输入";
	}else{
		document.getElementById("accountMsg").innerHTML = "正确";
	}
}
/**
 * 显示一个层
 */
function showDiv(name){
	 window.scroll(0,0);
	 //alert('showDiv');
     hjsDisplayElement(name + "_bg", true);
     hjsDisplayElement(name + "_info", true);			
}
/**
 * 关闭浮出层
 */
function closeDiv(name){
     hjsDisplayElement(name + "_bg", false);
     hjsDisplayElement(name + "_info", false);		
}
//关闭订单充值完成时浮出层(做跳转处理)
function closeCompleteDiv(){
	closeDiv('div_redeem_completed');	
	window.location.href="http://html.hjsm.tom.com/vip.html";
}
//显示订单充值浮出层(做特殊赋值处理)
function showConfirmDiv(type){
        showDiv("div_redeem_confirmed");
		//赋值   显示内容----->type
		document.getElementById("number").innerHTML = getTextValue('account');
		
		//userID 赋值：

		if(type == 1 || type==9  || type==12){
			document.getElementById("m").innerHTML = money;
			document.getElementById("pay_type").innerHTML = banks[markID][2];	
			//alert(mark);
			document.getElementById('productQuantity').value=money;
			//alert(banks[mark-1][2]);
			document.getElementById('bankID').value = mark;	
			//alert(document.getElementById('bankID').value);
		}else if(type == 5 || type == 7){
			document.getElementById("m").innerHTML = getTextValue('mobile');
			document.getElementById('mobilePhone').value=getTextValue('mobile');
			//赋值   提交内容		
			document.getElementById('cardTypeID').value = money;
		}
		else{
			document.getElementById("m").innerHTML = moneyString;
			document.getElementById("pay_type").innerHTML = banks[markID-1][2];
			//赋值   提交内容		
			document.getElementById('cardTypeID').value = money;
		}
		//var a = payActions[type-1];
		document.pay_confirm.method = 'POST';
		if(type == 7){
			if(document.getElementById("a").checked){
				document.pay_confirm.action = payActions[type];	
			}else{
				document.pay_confirm.action = 'http://hjsm.tom.com/new_hj/user/pay/channel_router.php';
			}
		}else{
			document.pay_confirm.action = payActions[type];
		}

}


/**
 * 写入浮出层的html(页面加载时调用)
 */
function writeHideHtml(submit_func,type){
	
	payType = type;
	if(type == 5 || type == 7){
		hidePayConfirmMobileInfoDiv(submit_func,type);		
	}else{
		hidePayConfirmDiv(submit_func,type);		
	}
	
	hidePayCompleteDiv(type);	
}

/**
 *  充值时，检查所填写的值和浮出层
 */
function confirm_click(type){
	//对dodonew的检查
	if(type == 2){
		 if (typeof(ddnPayment)!='undefined' && ddnPayment) {
		  //alert("可以使用DDN");
		 } else {
		     alert("嘟嘟牛软件不可用");
		     document.getElementById('account').disabled = true;
		     document.getElementById('accountCheck').disabled = true;
		     document.getElementById('moneyItem').disabled = true;
		     
		     return false;
		 }		
	}//end if;
	/*if(getCookie('hjsm_userid') == 0 ||getCookie('hjsm_userid') == null || getCookie('hjsm_userid') == '' ){
		alert('请先登陆或输入要充值的幻剑账号');	
		return false;
	}
	*/
	if(!valideForm()){
		return false;	
	}
	//document.getElementById('userID').value = getCookie('hjsm_userid');
	showConfirmDiv(type);	
}

if (typeof(clickUrl) == 'undefined') 
{
	var clickUrl = "http://stat.hjsm.tom.com";
}

/**
 *  点击去银行充值或继续充值，向接口提交数据
 */
function pay_complete(){

	closeDiv('div_redeem_confirmed');	
	if(!valideForm()){
		return false;	
	}
	showDiv('div_redeem_completed');

	//记录行为
	 if(payType == 1){
		var u = encodeURI(getTextValue('account'));
		var hjb = getTextValue("moneyItem")*10;
		addScript(clickUrl + "/dowhat/uat.php?t=6&u="+u+"&b="+hjb,'dowhat');
	 }
	document.pay_confirm.submit();
}



function addScript(src,id)
{
    var g = document.createElement("script");
    g.type = "text/javascript";
	g.id = id;
    g.src = src;
    document.getElementsByTagName('head')[0].appendChild(g);
}

/**********************************Cookie  操作*********************************************/
function setCookie(name, value, expire){
 var Days = expire; 
 var exp = new Date();
 exp.setTime(exp.getTime() + Days*24*60*60*1000);
 document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();  
}
function getCookie(name){
 var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
 if(arr != null){
  return unescape(arr[2]); 
 }
 return null;
}
function delCookie(name){//删除cookie{
 var exp = new Date();
 exp.setTime(exp.getTime() - 1);
 var cval=getCookie(name);
 if(cval!=null) {
  document.cookie= name + "="+cval+";expires="+exp.toGMTString();
 }
}



/**********************************Cookie  操作*********************************************/