//得到select项的个数		//重新覆盖了原来的size函数。不覆盖又没办法用下面的。
jQuery.fn.size = function(){   
     return jQuery(this).get(0).options.length;   
}
 
//获得选中项的索引   
jQuery.fn.getSelectedIndex = function(){   
     return jQuery(this).get(0).selectedIndex;   
}   

//获得当前选中项的文本   
jQuery.fn.getSelectedText = function(){   
    if(this.size() == 0) return "下拉框中无选项";   
    else{   
        var index = this.getSelectedIndex();         
        return jQuery(this).get(0).options[index].text;   
    }   
}   

//获得当前选中项的值   
jQuery.fn.getSelectedValue = function(){   
    if(this.size() == 0)    
        return "下拉框中无选中值";   
       
    else 
        return jQuery(this).val();   
}   

//设置select中值为value的项为选中   
jQuery.fn.setSelectedValue = function(value){   
    jQuery(this).get(0).value = value;   
}   

//设置select中文本为text的第一项被选中   
jQuery.fn.setSelectedText = function(text)   
{   
    var isExist = false;   
    var count = this.size();   
    for(var i=0;i<count;i++)   
    {   
        if(jQuery(this).get(0).options[i].text == text)   
        {   
            jQuery(this).get(0).options[i].selected = true;   
            isExist = true;   
            break;   
        }   
    }   
    if(!isExist)   
    {   
        alert("下拉框中不存在该项");   
    }   
}   
//设置选中指定索引项   
jQuery.fn.setSelectedIndex = function(index)   
{   
    var count = this.size();       
    if(index >= count || index < 0)   
    {   
        alert("选中项索引超出范围");   
    }   
    else 
    {   
        jQuery(this).get(0).selectedIndex = index;   
    }   
}   
//判断select项中是否存在值为value的项   
jQuery.fn.isExistItem = function(value)   
{   
    var isExist = false;   
    var count = this.size();   
    for(var i=0;i<count;i++)   
    {   
        if(jQuery(this).get(0).options[i].value == value)   
        {   
            isExist = true;   
            break;   
        }   
    }   
    return isExist;   
}   
//向select中添加一项，显示内容为text，值为value,如果该项值已存在，则提示   
jQuery.fn.addOption = function(text,value)   
{   
    if(this.isExistItem(value))   
    {   
        alert("待添加项的值已存在");   
    }   
    else 
    {   
        jQuery(this).get(0).options.add(new Option(text,value));   
    }   
}   
//删除select中值为value的项，如果该项不存在，则提示   
jQuery.fn.removeItem = function(value)   
{       
    if(this.isExistItem(value))   
    {   
        var count = this.size();           
        for(var i=0;i<count;i++)   
        {   
            if(jQuery(this).get(0).options[i].value == value)   
            {   
                jQuery(this).get(0).remove(i);   
                break;   
            }   
        }           
    }   
    else 
    {   
        alert("待删除的项不存在!");   
    }   
}   
//删除select中指定索引的项   
jQuery.fn.removeIndex = function(index)   
{   
    var count = this.size();   
    if(index >= count || index < 0)   
    {   
        alert("待删除项索引超出范围");   
    }   
    else 
    {   
        jQuery(this).get(0).remove(index);   
    }   
}   
//删除select中选定的项   
jQuery.fn.removeSelected = function()   
{   
    var index = this.getSelectedIndex();   
    this.removeIndex(index);   
}   
//清除select中的所有项   
jQuery.fn.clearAll = function()   
{   
    jQuery(this).get(0).options.length = 0;   
}


function g(arg)
{
	var obj=document.getElementById(arg);
	return obj;
}
function gn(arg) 
{
    var obj = document.getElementsByName(arg);
	return obj;
}
function gt(arg) 
{
	var obj = document.getElementsByTagName(arg);
	return obj;
}
function gc(arg) 
{
	var obj = document.createElement(arg);
	return obj;
}
function getPosition(obj)
{
	var left=0,top=0,arr=new Array();
	left+=obj.offsetLeft;
	top+=obj.offsetTop;
	arr[0]=left;
	arr[1]=top;
	return arr;
}
function getSize(obj)
{
	var width=0,height=0,arr=new Array();
	width+=obj.offsetWidth;
	height+=obj.offsetHeight;
	arr[0]=width;
	arr[1]=height;
	return arr;
}
function getWebSize()
{
	var width=0,height=0;arr=new Array();
	with(document.documentElement)
	{
		width=(clientWidth>scrollWidth)?clientWidth:scrollWidth;
		height=(clientHeight>scrollHeight)?clientHeight:scrollHeight;
	}
	arr[0]=width;
	arr[1]=height;
	return arr;
}
function getBodySize()
{
	var width=0,height=0;arr=new Array();
	with(document.documentElement)
	{
		width=clientWidth;
		height=clientHeight;
	}
	arr[0]=width;
	arr[1]=height;
	return arr;
}
function getScrollSpace()
{
	var left=0,top=0;arr=new Array();
	with(document.documentElement)
	{
		left=scrollLeft;
		top=scrollTop;
	}
	arr[0]=left;
	arr[1]=top;
	return arr;
}
function suitID(arg)
{
	var reg=/^[\w\u4E00-\u9FA5]+$/;
	return reg.test(arg);
}
function isInt(arg)
{
	var reg=/^[1-9]\d*$/;
	return reg.test(arg);
}
function isUInt(arg)
{
	var reg=/^[0-9]\d*$/;
	return reg.test(arg);
}
function suitName(arg)
{
	var reg=/^\w{6,}$/;
	return reg.test(arg);
}
function postNum(arg)
{
	var reg=/^[1-9]\d{5}$/;
	return reg.test(arg);
}
function suitEmail(arg)
{
	var reg=/^[0-9a-zA-Z]+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	return reg.test(arg);
}
function webUrl(arg)
{
	var str=arg.substring(0,7)
	if(str!="http://")
	{
		return false;
	}
	return true;
}
function urlEncode(str){ 
  var ret=""; 
  var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%"; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    var c=str2asc(chr); 
    //tt+= chr+":"+c+"n"; 
    if(parseInt("0x"+c) > 0x7f){ 
      ret+="%"+c.slice(0,2)+"%"+c.slice(-2); 
    }else{ 
      if(chr==" ") 
        ret+="+"; 
      else if(strSpecial.indexOf(chr)!=-1) 
        ret+="%"+c.toString(16); 
      else 
        ret+=chr; 
    } 
  } 
  return ret; 
} 
function urlDecode(str)
{ 
	var ret=""; 
	for(var i=0;i<str.length;i++)
	{ 
		var chr = str.charAt(i); 
		if(chr == "+")
		{
			ret+=" "; 
		}else if(chr=="%")
		{ 
			var asc = str.substring(i+1,i+3); 
	 		if(parseInt("0x"+asc)>0x7f)
			{ 
	  		ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
	  		i+=5; 
	 		}else
			{
				ret+=asc2str(parseInt("0x"+asc)); 
	  			i+=2; 
	 		} 
			}else
			{ 
	  			ret+= chr; 
			} 
	} 
  	return ret; 
}
function autoSize(obj,x,y)
{
	var img=new Image();
	img.src=obj.src;
	var maxWidth=x;
	var maxHeight=y;
	var imgWidth=img.width;
	var imgHeight=img.height;
	var mwh=maxWidth/maxHeight;
	var wh=imgWidth/imgHeight;
	if(imgWidth<=maxWidth && imgHeight<=maxHeight)
	{
		return;
	}
	else
	{
		if(wh>=mwh)
		{
			$(obj).width(maxWidth);
			$(obj).height(maxWidth/wh);
		}
		if(wh<mwh)
		{
			$(obj).width(maxHeight*wh);
			$(obj).height(maxHeight);
		}
	}
}

function addFavorite(url,title){
    if (document.all){
       window.external.addFavorite(url,title);
    }else if (window.sidebar){
       window.sidebar.addPanel(title,url,"");
    }
}
function setHomepage(url)
{
    if (document.all){
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(url);
    }else if (window.sidebar){
        if(window.netscape){
             try{
                  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
             }catch (e){
                   alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );
             }
    }
	var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
	prefs.setCharPref('browser.startup.homepage',url);}
}
function ajax() 
{
	var http;
	try {
		http = new ActiveXObject("Microsoft.XMLHTTP"); //IE高版本的浏览器(5.5+)
	}
	catch (e) {
		try {
			http = new ActiveXObject("Msxml2.XMLHTTP"); //IE低版本的浏览器
		}
		catch (e) {
			try {
				http = new XMLHttpRequest(); //Firefox,opera,Safari浏览器
			}
			catch (e2) {
				http = false;  //所有浏览器都报错，则http为false
			}
		}
	}
	if (!http) {
		alert("Your computer cannot support the Ajax!");
		return false;
	}
	return http;
}
function ajax_returnresponse(http) 
{
	var state = http.readyState;
	if (state < 4) {
		return false;
	}
	if (state == 4 && http.status == 200) {
		return true;
	}
}
function addOption(s_sel,o_value,o_text)
{
	s_sel.options[s_sel.length]=new Option(o_text,o_value);
}
function mtvFlash(xur,xw,xh)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+xw+'" height="'+xh+'">');
	document.write('<param name="movie" value="' + xur + '">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="menu" value="false">');
	document.write('<embed src="' + xur + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + xw + '" height="' + xh + '"></embed>');
	document.write('</object>');
		
}
function oneInStr(str,subStr)
{
	if(subStr=="" || str=="")
		return false;
	if(str.indexOf(subStr)==str.lastIndexOf(subStr))
		return true;
	else
		return false;
}
function closeTop()
{
	var topHref=top.location.href;
	var href=window.location.href;
	if(topHref==href)
	{
		document.body.innerHTML="";
		window.location.replace("/");
	}
}
function intNotMinus(arg)
{	
	var reg=/^\d+$/;
	return reg.test(arg);
}
function floatNotMinus(arg)
{	
	var reg=/^\d+(\.\d+)?$/;
	return reg.test(arg);
}
function lenStr(arg)
{
	var str = arg;
	str = str.replace(/[^\x00-\xff]/g,"xx")
	return str.length;
}
function cutStr(str,enLength)
{
	var zhNum=0;
	var enNum=0;
	var endIndex=0;
	for(var i=0;i<enLength;i++)
	{
		if(str.charCodeAt(i)>255)
			zhNum+=2;
		else
			enNum+=1;
		endIndex+=1;
		if(zhNum+enNum==enLength) 
		{
			return(str.substring(0,endIndex));
			break;
		}
		if(zhNum+enNum>enLength)
		{
			return(str.substring(0,endIndex-1)); 
			break;
		}
	}
}
