var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var is_safari = (userAgent.indexOf('webkit') != -1 || userAgent.indexOf('safari') != -1);
//msie 6.0

function FloatWin(obj, w, h, gurl)
{
	var de=document.documentElement;
    var db=document.body;
    var clientW  = de.clientWidth ? de.clientWidth  : db.clientWidth;
    var clientH = de.clientHeight ? de.clientHeight : db.clientHeight;
 	var scrollTop    = de.scrollTop ? de.scrollTop : db.scrollTop;
	var height=$("body").height()+5;
	var top  =(clientH-h)/2+scrollTop-50;
	var left =(clientW-w)/2;
	
	//alert(scrollTop+'==='+top+'==='+h);
	if($("#FloatBg").length>0)
	{
		$("#FloatBg").show().css({"filter":"Alpha(Opacity=65)","opacity":"0.65"});
	}
	else
	{  
		$("body").append('<div id="FloatBg" style="width:'+clientW+'px;height:'+height+'px;"></div>');
	}
	$("#FloatBg").click(function(){FloatClose();});
	
	if($("#FloatDiv").length>0) $("#FloatDiv").remove();
	
	market= obj.href.indexOf('ajax.php?do=market_menu')>=0 ? ' market' : ''; 
	
	$("body").append('<div id="FloatDiv" style="top:'+top+'px;left:'+left+'px;width:'+w+'px;height:'+h+'px;"><div class="ft_box"><div class="flogo '+market+'"></div><div class="fclose"><a href="javascript:FloatClose();">X</a></div><div class="ftitle"><strong>'+obj.title+'</strong></div><div class="fcon"><img src="images/ajax-loader.gif"> Loading...</div></div></div>');
	
	if(is_ie) { pngfix(); $("#body select").css("visibility","hidden");}

	if($("#FloatDiv").length>0)
	{
		$(window).scroll(function(){
			var offsetTop = (clientH-h)/2 + $(window).scrollTop()-50 + "px";     
			$("#FloatDiv").animate({ top: offsetTop }, { duration: 100, queue: false });     
		});
	}
	gurl = (gurl!='') ? gurl : 0;
	//window.open(obj.href+'?infloat=1&gurl='+gurl);
	$.get(obj.href,{infloat:1,gurl:gurl,t:Math.random()},function(data,textStatus){
			$("#FloatDiv .fcon").html(data);
	},"TEXT");
}

function FloatClose()
{
  $("#FloatDiv").fadeOut("slow").remove();
  $("#FloatBg").fadeOut("slow").remove();
  if(is_ie) {$("#body select").css("visibility","visible");}
  try{
	  clearInterval(ft);
  }catch(e){
	  
  }	
}
function reload_this()
{ 
	window.location.reload();
}

function objToString(obj) 
{ 
	var str = "{"; 
	for(attr in obj) 
	{ 
		tmp = attr + " => " + obj[attr] + " <br>"; 
		str += tmp; 
	} 
	str += "}"; 
	document.write(str); 
} 

String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

//Count string byte number, return integer
String.prototype.ByteCount = function()
{
	txt = this.replace(/(<.*?>)/ig,"");
	txt = txt.replace(/([\u0391-\uFFE5])/ig, "11");
	var count = txt.length;
	return count;
}

//该变字符双单字节
function D2S (str) {
        var i;
        var result='';
        for(i=0; i < str.length; i++)
        {
                code = str.charCodeAt(i);

                if (code == 12290)
                {
                        result += String.fromCharCode(46);
                }
                else if (code == 183)
                {
                        result += String.fromCharCode(64);
                }
                else if(code >= 65281 && code<65373)
                {
                        result += String.fromCharCode(str.charCodeAt(i)-65248);
                }
                else
                {
                        result += str.charAt(i);
                }
        }
		result=result.trim();
        return result;
}

//手机号码验证
function isMobile(str)   
{   
	if(/^13\d{9}$/g.test(str) || (/^15[0-35-9]\d{8}$/g.test(str)) || (/^18[05-9]\d{8}$/g.test(str)))
	{    
        return true;   
	}
	else
	{   
        return false;   
	}   
}

function isUsername(str)
{   var RegEx =/['|,|*]$/; 
	if(!RegEx.test(str)) 
		return true;
	else
		return false; 	
}

function isPasswd(str)
{   var RegEx =/^([A-Za-z0-9]){6,20}$/; 
	if(RegEx.test(str)) 
		return true;
	else
		return false; 	
}

function isEmail(str)
{   var RegEx = /.+@.+\.[a-zA-Z]{2,4}$/; 
	if(RegEx.test(str)) 
		return true;
	else
		return false; 	
}

function check_durty_words(str)
{
	var durty_words  = new Array("admin","select","update","insert","root");
	var filter_words = new Array("'","*");
	for(i=0;i<durty_words.length;i++)
	{
		if (str==durty_words[i]) //thisinput.indexOf(durty_words[i])	>=	0
		{
			return durty_words[i];
		}
	}
	for(i=0;i<filter_words.length;i++)
	{
		if (str.indexOf(filter_words[i])	>=	0) //thisinput.indexOf(durty_words[i])	>=	0
		{
			return filter_words[i];
		}
	}
	return false;
}

function checkso()
{
	var n1=(lang=='cn' ? '请输入关键词' : 'Please input keywords');
	var n2=(lang=='cn' ? '至少2个字符' : 'At lease two characters');
	if($('#rsearch').val()=='')
	{
		alert(n1); return false;
	}
	if($('#rsearch').val().length<2)
	{
		alert(n2); return false;
	}
}
function goToRest(rest)
{
	if(rest=='') return;
	location.href=(lang=='cn' ? '' : 'e')+"menu.php?sn="+rest;
}
