//function $(obj){
//	return document.getElementById(obj);
//}
function isEmail(str){
	var reEml = /^[\w\-\.]+@[a-z0-9]+(\-[a-z0-9]+)?(\.[a-z0-9]+(\-[a-z0-9]+)?)*\.[a-z]{2,4}$/i;
	var isOk = reEml.test(str);
    if (isOk)
		return true;
	else
		return false;
}
//js获取url参数的function
function requestUrlPara(paras)
{ 
	var url = location.href;   
	var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");   
	var paraObj = {}   
	for (i=0; j=paraString[i]; i++){   
		paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);   
	}   
	var returnValue = paraObj[paras.toLowerCase()];   
	if(typeof(returnValue)=="undefined"){   
		return "";   
	}else{   
		return returnValue;   
	}   
} 

function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value)
//设定Cookie值
{
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
function DelCookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function LoginCheck(){
	var obj=document.getElementById("loginForm");
	if(obj.username.value.length<6){
		alert("用户名不能少于6个字符");
		obj.username.focus();
		return false;
	}
	else if(obj.password.value.length<6){
		alert("密码长度不能少于6个字符");
		obj.password.focus();
		return false;
	}
	else
		return true;
		
}
function ResetPswCheck(){
	var obj=document.getElementById("ResetPswForm");
	if(obj.username.value.length<6){
		alert("用户名不能少于6个字符");
		obj.username.focus();
		return false;
	}
	else if(!isEmail(obj.email.value)){
		alert("你的邮件地址输入不正确!");
		obj.email.focus();
		return false;
	}else if(obj.checkCode.value==''){
		alert("验证码不能为空");
		obj.checkCode.focus();
		return false;
	}
	else
		return true;
}

//提交注册检验
function RegisterCheck()
{
	var obj=document.getElementById("registerForm");
	if(obj.username.value == " "){
		obj.username.focus();
		return false;
	}
	if(obj.password.value==" "){
		obj.password.focus();
		return false;
	}
	if(obj.repassword.value==" "){
		obj.repassword.focus();
		return false;
	}
	
	
	if(obj.email.value==" "){
		obj.email.focus();
		return false;
	}
	
	if(obj.checkCode.value==" "){
		obj.checkCode.focus();
		return false;
	}
	
}



//搜索
function luckyDrawSearch(){
	var searchPrize=document.getElementById('s1_value').value;
	var searchGame=document.getElementById('s2_value').value;
	var searchGold=document.getElementById('s3_value').value;
	var searchkey=document.getElementById('searchkey').value;
	if((searchPrize=='0' || searchPrize=='') && (searchGame=='0' || searchGame=='') && (searchkey=='' || searchkey=='关键字') && (searchGold=='' || searchGold=='0'))
		alert('请指定搜索条件'); 
	else
		top.location.href='advancedsearch.php?action=search&searchPrize='+searchPrize+'&searchGame='+searchGame+'&searchkey='+searchkey+'&searchGold='+searchGold+'&random='+Math.random();
}
function RegisterAjaxCheck(name,value){
	 Ajax.call( 'Ajax_RegisterCheck.php?name='+name, 'value='+value , RegisterAjaxCheckDone , 'GET', 'TEXT', true, true );
}
function RegisterAjaxCheckRepassword(){
	var password=document.getElementById("password").value;
	var repassword=document.getElementById("repassword").value;
	if(password != repassword)
		alert("no");
}

function checkRepassword()
{
	res = true;
	var password=document.getElementById("password").value;
	var repassword=document.getElementById("repassword").value;
	if(password ==""){
		document.getElementById("ajax_password").innerHTML = "<font color='#FF0000'>密码不能为空</font>";
		document.getElementById("ajax_password").focus();
		res = true;
	}else if(	password != repassword){
		document.getElementById("ajax_repassword").innerHTML = "<font color='#FF0000'>两次密码不一致</font>";
		document.getElementById("ajax_repassword").focus();
		res = true;
	}else{
		document.getElementById("ajax_repassword").innerHTML = "";
	}
	return res;
}

function RegisterAjaxCheckDone(result){
	var arr=result.split("@");
	document.getElementById("ajax_"+arr[0]).innerHTML = arr[1];
	document.getElementById(arr[2]).innerHTML = arr[3];
}
function RandomCheckCode(){
	document.getElementById('checkCodeIMG').src='checkCode.php?rand='+Math.random();
}
function MsgJSload(){
}
//
function setPrizeFocus(id){
	/*
	for(i=1;i<=all;i++){
		if(i==id)
			document.getElementById("focusPic"+i).className="activeImg";
		else
			document.getElementById("focusPic"+i).className="";
	}
	//$("prizeFocusLink").href=$("focusLink"+id).href;
	*/
	document.getElementById("prizeFocusPic").src=document.getElementById("thumb_img_"+id).value;
}
function dianping(id,author,time,content){
	/*
	window.location.href="#sendComment";
	html="[引用--->]"+author+" 在"+" ["+time+"] 说: "+content+"[<---引用]";
	alert('id='+id+',html='+html);
	$("refer_comID").value=id;
	$("refer_comm").innerHTML=html;
	*/
}

function add2bookmark(title,url) {
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}

function selectPrizeTab(id){
	for(i=1;i<4;i++){
		if(i==id){
			document.getElementById("menu"+i).className="floatLeft menuHover";
			document.getElementById("selectTab"+i).style.display="block";
		}else{
			document.getElementById("menu"+i).className="floatLeft menuOut";
			document.getElementById("selectTab"+i).style.display="none";
		}	
	}
}
function headerSelect(id){
	SetCookie("headerNav",id);
	for(i=1;i<=7;i++){
		obj=document.getElementById("nav"+i);
		if(i==id){
			if(obj)
				obj.src="../images/lottery/navigation/mouseon_00"+i+".gif";
		}else{
			if(obj)
				obj.src="../images/lottery/navigation/mouseout_00"+i+".gif";
		}
	}
}
function headerOver(id){
	nav=GetCookie("headerNav");
	if(id==nav)
		document.getElementById("nav"+id).src="../images/lottery/navigation/mouseon_00"+id+".gif";
	else
		document.getElementById("nav"+id).src="../images/lottery/navigation/mouseover_00"+id+".gif";
}
function headerOut(id){
	nav=GetCookie("headerNav");
	if(id==nav)
		document.getElementById("nav"+id).src="../images/lottery/navigation/mouseon_00"+id+".gif";
	else
		document.getElementById("nav"+id).src="../images/lottery/navigation/mouseout_00"+id+".gif";
}
function headerAutoSelect(){
	nav=GetCookie("headerNav");
	if(nav==null)
		nav=1;
	headerSelect(nav)
}

function imgResize(ImgD,FitWidth,FitHeight) 
{ 
	var image=new Image(); 
	image.src=ImgD.src; 
	if(image.width>0 && image.height>0) 
	{ 
		if(image.width/image.height>= FitWidth/FitHeight) 
		{ 
			if(image.width>FitWidth) 
			{ 
				ImgD.width=FitWidth; 
				ImgD.height=(image.height*FitWidth)/image.width; 
			} 
			else 
			{ 
				ImgD.width=image.width; 
				ImgD.height=image.height; 
			} 
		} 
		else 
		{ 
			if(image.height>FitHeight) 
			{ 
				ImgD.height=FitHeight; 
				ImgD.width=(image.width*FitHeight)/image.height; 
			} 
			else 
			{ 
				ImgD.width=image.width; 
				ImgD.height=image.height; 
			} 
		} 
	} 
} 
function browser(){
	if (window.XMLHttpRequest) {
		if (!window.ActiveXObject){
			return "firefox";
		}else{
			return "ie7";
		}
	}else{
		return "ie6";
	}
}
function Share_1(prize){
	alert("抽奖机会……囧");
}
function Share_2(prize){
	var url=document.URL;
	str="嗨，好久不见啊，我和朋友最近做了个网站很好玩，还有免费奖品送给你："+prize+",快来领取啦！("+url+")";
	mybrowser=browser();
	if(mybrowser=="ie7" || mybrowser=="ie6"){
		window.clipboardData.setData('text', str); 
		alert("奖品名称和地址已经复制到粘贴板\n\n你可以使用Ctrl+V 或单击鼠标右键使用\"粘贴\"功能，将好运分享给你的朋友!");
	}else{
		alert("对不起，你的浏览器不支持此复制功能！\n\n请使用：CTRL+C，或右键单击选择复制红色区域内容！");
		document.getElementById("hidden2showinput").value=str;
		document.getElementById("hidden2show").style.display="block";
		document.getElementById("hidden2show").style.borderColor="#FF0000";
		document.getElementById("share2link").style.display="none";
	}
}
function Share_3(goods_id){
	str="<script type=\"text/javascript\" src=\"http://www.shiyixia.com/innerPrize.php?goods_id='"+goods_id+"'\">";
	mybrowser=browser();
	if(mybrowser=="ie7" || mybrowser=="ie6"){
		window.clipboardData.setData('text', str); 
		alert("引用代码已经复制至你的系统粘贴板!");
	}else{
		alert("对不起，你的浏览器不支持此复制功能！\n\n请使用：CTRL+C，或右键单击选择复制红色区域内容！");
		document.getElementById("hidden2showinput").value=str;
		document.getElementById("hidden2show").style.display="block";
		document.getElementById("hidden2show").style.borderColor="#FF0000";
	}
}
function syxGameVote(game_id,vote){
	if(!game_id)
		alert('没有指定游戏');
	else
		// Ajax.call('vote_do.php?game_id='+game_id+'&vote='+vote ,'div='+div,  AjaxNotice , 'GET', 'TEXT', true, true );
		$.post('vote_do.php',{game_id:game_id,vote:vote},function(result){
			arr=result.split('@');
			if(arr[0]=='success'){
				syxBox.msg('投票成功','','');
				$('#gamevote_'+vote).html(arr[1]);
			}
			else
				syxBox.msg(arr[1],'','');
		});
}
function add2collect(goods_id){
	 Ajax.call( 'collectOk.php?target=_self&goods_id='+goods_id ,'div=add2collectdiv' , AjaxNotice , 'GET', 'TEXT', true, true );
}
function comment_reply(comment_id){
	window.location.href='#sendComment'; 
	document.getElementById('parent_id').value=comment_id;
	document.getElementById('parent_content').style.display='block';
	Ajax.call('get_a_comment.php','comment_id='+comment_id,comment_reply_content,'GET','TEXT',true,true);
}
function comment_reply_content(result){
	document.getElementById('parent_content').innerHTML="引用："+result;
	document.getElementById('commentContent').focus();
}
function add2cart(goods_id,div){
	//alert(goods_id);
	//Ajax.call('add2cart.php?goods_id='+goods_id,'div='+div , AjaxNotice , 'GET', 'TEXT', true, true );
	document.getElementById("doFrame").src="add2cart.php?goods_id="+goods_id;
}
function showComment(goods_id,page){
	Ajax.call( 'prizeComment.php?page='+page, 'goods_id='+goods_id , showHTML , 'GET', 'TEXT', true, true );
	//$.get("prizeComment.php",{page:page,goods_id:goods_id},function(data){$('ajaxComment').innerHTML=data;}); 
}
function showHTML(result){
	document.getElementById('ajaxComment').innerHTML=result;
}
function Ajaxeval(result){
	//$('ajaxResult').innerHTML=result;
	eval(result);
}
function pause(obj,iMinSecond){ 
	if (window.eventList==null) window.eventList=new Array(); 
	var ind=-1; 
	for (var i=0;i<window.eventList.length;i++){ 
		if (window.eventList[i]==null) { 
			window.eventList[i]=obj; 
			ind=i; 
			break; 
		} 
	} 
	if (ind==-1){ 
		ind=window.eventList.length; 
		 window.eventList[ind]=obj; 
	} 
	setTimeout("GoOn(" + ind + ")",iMinSecond); 
} 
function GoOn(ind){ 
	var obj=window.eventList[ind]; 
	window.eventList[ind]=null; 
	if(obj.next) 
		obj.next(); 
	else 
		obj(); 
} 
function AjaxNotice(result){
	arr=result.split("@SPLIT@");
	if(arr.length==2){
	/*
		$(arr[0]).style.display='block';
		$(arr[0]).innerHTML="<span style='color:666; background-color:#fc9; border:1px solid #666; padding:5px 10px; text-align:left;'>"+arr[1]+"</span>";
		pause(this,3000);
		this.next=function(){ 
			$(arr[0]).style.innerHTML='';
			$(arr[0]).style.display='none';
		}
	*/
	syxBox.msg(arr[1],'5','');
	}else
		eval(arr[2]);
}
function cut_str(str, len, hasDot) 
{ 
	var newLength = 0; 
	var newStr = ""; 
	var chineseRegex = /[^\x00-\xff]/g; 
	var singleChar = ""; 
	var strLength = str.replace(chineseRegex,"**").length; 
	for(var i = 0;i < strLength;i++) 
	{ 
		singleChar = str.charAt(i).toString(); 
		if(singleChar.match(chineseRegex) != null){ 
			newLength += 2; 
		}else{ 
			newLength++; 
		}if(newLength > len){ 
			break; 
		}
		newStr += singleChar; 
	} 
	if(hasDot && strLength > len) { 
		newStr += "..."; 
	} 
	newStr=newStr.replace("\"","'");
	return newStr; 
}
/**
 *返回用户金币、银币、铜币数 
 *如：user_money_format(1989,"金币：gold，银币：silver，铜币：copper");
 *返回：string "金币：19，银币：8，铜币：9"
 *参数：user_money
 *futao 20090324
 */
function user_money_format(money,str){
	var gold	=	parseInt(money/100);
	var silver	=	parseInt(money%100/10);
	var copper	=	money%100%10;
	
	str=str.replace("gold",gold);
	str=str.replace("silver",silver);
	str=str.replace("copper",copper);

	return str;
}


//获取用户等级
function getUserRankFormat(rank)
{
	switch (rank){
		case 1:
		    return "普通用户";
			break;
		case 2:
		    return "vip1用户";
			break;
		case 3:
		    return "vip2用户";
			break;
		case 4:
		    return "vip3用户";
			break;
		case 5:
		    return "vip4用户";
			break;
		case 6:
		    return "vip5用户";
			break;
		case 7:
		    return "vip终生用户";
			break;
	}
}


//除法函数，用来得到精确的除法结果
//调用：	chu(arg1,arg2)
//返回值：	arg1除以arg2的精确结果
//shiyixia  20090425
function chu(arg1,arg2){
	var t1=0,t2=0,r1,r2;
	try{t1=arg1.toString().split(".")[1].length}catch(e){}
	try{t2=arg2.toString().split(".")[1].length}catch(e){}
	with(Math){
		r1=Number(arg1.toString().replace(".",""))
		r2=Number(arg2.toString().replace(".",""))
		return (r1/r2)*pow(10,t2-t1);
	}
}
Number.prototype.chu = function (arg){
	return chu(this, arg);
}
//---

//乘法函数，用来得到精确的乘法结果
//调用：	cheng(arg1,arg2)
//返回值：	arg1乘以arg2的精确结果
//shiyixia  20090425
function cheng(arg1,arg2)
{
	var m=0,s1=arg1.toString(),s2=arg2.toString();
	try{m+=s1.split(".")[1].length}catch(e){}
	try{m+=s2.split(".")[1].length}catch(e){}
	return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
}
Number.prototype.cheng = function (arg){
	return cheng(this, arg);
}
//---

//加法函数，用来得到精确的加法结果
//调用：	jia(arg1,arg2)
//返回值：	arg1加上arg2的精确结果
//shiyixia  20090425
function jia(arg1,arg2){
	var r1,r2,m;
	try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
	try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
	m=Math.pow(10,Math.max(r1,r2))
	return (arg1*m+arg2*m)/m
}
Number.prototype.jia = function (arg){
	return jia(this, arg);
}
//---

function float2int(value){
	var newValue=Math.round(value);
	return newValue;
}
function updateUserInfo()
{
	userInfoFrame.location.href="popListWindow.php";

}
//判断是否显示我的宝地浮动条
function is_show_FloatDIV(url){
	var arr1=url.split('/');
	var arr2=arr1[arr1.length-1].split('.');
	var display='block';
	if(arr2[0]=='myGoldenGate')
		display='none';
	document.getElementById('FloatDIV').style.display=display;
}

//复制粘贴
function copyToClipboard(txt) {    
     if(window.clipboardData) {    
             window.clipboardData.clearData();    
             window.clipboardData.setData("Text", txt);    
     } else if(navigator.userAgent.indexOf("Opera") != -1) {    
          window.location = txt;    
     } else if (window.netscape) {    
          try {    
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    
          } catch (e) {    
               alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");    
          }    
          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);    
          if (!clip)    
               return;    
          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);    
          if (!trans)    
               return;    
          trans.addDataFlavor('text/unicode');    
          var str = new Object();    
          var len = new Object();    
          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);    
          var copytext = txt;    
          str.data = copytext;    
          trans.setTransferData("text/unicode",str,copytext.length*2);    
          var clipid = Components.interfaces.nsIClipboard;    
          if (!clip)    
               return false;    
          clip.setData(trans,null,clipid.kGlobalClipboard);    
     }    
}   

