var domReady = function(){};
var loadValues = function(){return false};
var clientCheck = function(){return false};

$(document).ready(function(){
	initLinks();
	domReady();
	$('.smallButton img').mouseover(smallButtonOverJpg).mouseout(smallButtonOutJpg);
});

function sitead(){
	var content = '<a href="http://pay.aobi.com/site/cardinfo/cardinfoall1.html"><div style="width:182px; height:180px;"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="182" height="180">'
	  + '<param name="movie" value="' + resourcePath + '/flash/1.swf" />'
	  + '<param name="quality" value="high" />'
	  + '<param name="wmode" value="transparent">'
	  + '<embed src="' + resourcePath + '/flash/1.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="182" height="180" wmode="transparent"></embed>'
	  + '</object></div></a>';
	$('#cardad').attr('innerHTML',content);
}

function initLinks(){
	//判断是否加载了jquery.query插件
	if($.query != undefined){
		var repay = $.query.get('repay');
		if(repay=='true'){
			$('#payLink').css('color', '');
			var txt = $('#repayLink').text();
			$('#repayLink').after('<span style="color:#ff7a22;">' + txt + '</span>');
			$('#repayLink').remove();
			$('.payWayBar a').each(function(){
				$(this).attr('href',$(this).attr('href') + '?repay=true');
			});
			$('#main .title').children('img:first').attr('src', resourcePath + '/images/site/ruby_again_title.jpg')
		}else{
			$('#repayLink').css('color', '');
			var txt = $('#payLink').text();
			$('#payLink').after('<span style="color:#ff7a22;">' + txt + '</span>');
			$('#payLink').remove();
		}
	}
}

function check(){
	if(!loadValues()){
		return false;
	}
	
	if(!clientCheck()){
		return false;
	}
	
	return true;
}

function showDialog(){
	
	var TB_WIDTH = 590; 
	var TB_HEIGHT = 355; 
	
	$("#dialog").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#dialog").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
	
	var popupHeight = $('#dialog').height();
	var popupWidth = $('#dialog').width();
	
	var screenHeight = window.screen.availHeight;
	var scrollHeight = document.body.scrollHeight;
	var blockHeight = screenHeight - 140;
	if(screenHeight < scrollHeight){
		blockHeight = scrollHeight + 15;
	}

	$('#block').css({
		'display':'block',
		'height':blockHeight
	});
	$('#dialog').css({
		'display':'block'
	});
}

function closeDialog(isChangeImg){
	$('#block').css('display', 'none');
	$('#dialog').css('display', 'none');
	if(isChangeImg){
		changeImg();
	}
}

function closeTB(isChangeImg){
	if(isChangeImg){
		changeImg();
	}
	tb_remove();	
}

function serverCheck(arr, callback){
	var now = new Date();
	arr['rnd'] = now.getTime(); 
	$.get("/checkpayruby.jsp", arr,	function(data){checkServerCallBack(data, callback);});
	$('#checkButton').css('display', 'none');
	$('#loading').css('display', '');
}

function checkServerCallBack(data, callback){
	$('#checkButton').css('display', '');
	$('#loading').css('display', 'none');
	
	var elementId = null;
	var values = data.split('|');
	var elementId = getIdByErrorType(values[0], values[1]);
	
	if(elementId != null){
		if(elementId != ""){
			showValidate(elementId, values[1]);
			changeImg();
		}
		return;
	}
	
	var c = new callback();
	c.userName = values[1];
	c.money = values[2];
	c.fun();
}

function serverAccountCheck(arr, callback){
	if(arr['CheckType']==undefined){
		arr['CheckType'] = 'CheckAccount';
	}
	var now = new Date();
	arr['rnd'] = now.getTime(); 
	$.get("/checkpayruby.jsp", arr,	function(data){checkServerAccountCallBack(data, callback);});
}

function serverCheckVPay(arr, callback){
	arr['CheckType'] = 'CheckVPay';
	serverAccountCheck(arr, callback);
}

function checkServerAccountCallBack(data, callback){
	var elementId = null;
	var values = data.split('|');
	var elementId = getIdByErrorType(values[0], values[1]);
	
	if(elementId != null){
		if(elementId != ""){
			showValidate(elementId, values[1]);
			changeImg();
		}
		return;
	}
	
	var c = new callback();
	c.userName = values[1];
	c.fun();
}

function AccountFocus(){
	hideValidate('AccountValidate');
}

function ConfirmAccountFocus(){
	hideValidate('ConfirmAccountValidate');
}

function AccountBlur(){
	var tempAccount = $('#Account').val();

	if(tempAccount.length != 0){
		if(isNaN(tempAccount) || tempAccount.length != 9){
			showValidate('AccountValidate', '请输入9位数字型的奥银帐号！');
		}
	}
}

function ConfirmAccountBlur(){
	var tempAccount = $('#Account').val();
	var tempConfirmAccount = $('#ConfirmAccount').val();
	
	if(tempAccount != tempConfirmAccount){
		showValidate('ConfirmAccountValidate', '两次输入的奥银帐号不一致，请重新输入！');
	}
}

function checkAccount(account, confirmAccount){
	if(account.length == 0){
		showValidate('AccountValidate', '你还没填写奥银帐号！');
		return false;
	}
	
	if(isNaN(account)){
		showValidate('AccountValidate', '请输入9位数字型的奥银帐号！');
		return false;
	}
	
	if(confirmAccount.length == 0){
		showValidate('ConfirmAccountValidate', '请再次输入奥银帐号！');
		return false;
	}
	
	if(isNaN(confirmAccount)){
		showValidate('ConfirmAccountValidate', '请输入9位数字型的奥银帐号！');
		return false;
	}
	
	if(account != confirmAccount){
		showValidate('ConfirmAccountValidate', '两次输入的奥银帐号不一致，请重新输入！');
		return false;
	}
	
	return true;
}

function checkAobiMoney(aobiMoney){
	if(isNaN(aobiMoney)){
		showValidate('AobiMoneyValidate', '请输入数字型的奥币！');
		return false;
	}
	
	var intAobiMoney = parseInt(aobiMoney);
	if(intAobiMoney > 120){
		showValidate('AobiMoneyValidate', '充值的奥币不能超过120！');
		return false;
	}
	
	if(intAobiMoney < 1){
		showValidate('AobiMoneyValidate', '充值的奥币应该大于0！');
		return false;
	}
	
	return true;
}

function fade(elementId){
	var elem = $("#" + elementId);
	if(elem.css('display') == 'none'){
		elem.fadeIn("slow"); 
	}else{
		elem.fadeOut("fast"); 
	}
}