﻿//获得地址栏参数
function getQueryString(queryname) {
    var qKeys = {};
    var re = /[?&]([^=]+)(?:=([^&]*))?/g;
    var matchInfo;
    while(matchInfo = re.exec(location.search)){
	    qKeys[matchInfo[1]] = matchInfo[2];
    }
    return typeof(qKeys[queryname])=='undefined'?'':qKeys[queryname];
}

//去除字符串两端的空格
String.prototype.trim　= function()
{
    // 用正则表达式将前后空格
    // 用空字符串替代。
    var t = this.replace(/(^\s*)|(\s*$)/g, "");
    return t.replace(/(^　*)|(　*$)/g, "");
} 

//获得字符串长度，一个中文算两个字符
function getLength(val){
    return val.replace(/[^\x00-\xff]/g, "**").length;
}

function addBookmark(title) {
    var url=parent.location.href;
    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 SetHome(obj,vrl){
    try{
        obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
    }
    catch(e){
        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',vrl);
        }
    }
} 

function ShowHide(a,l){
    a=$("#"+a);
    l=$("#"+l);
    l.hide();
    
    a.mouseover(function(){
        l.show();
    });
    
    a.mouseout(function(){
        l.hide();
    });
}

//表单只允许提交一次
function submitonce(f){
    if (document.all || document.getElementById)
	{
		for (i=0; i<f.elements.length; i++)
		{
			var ctl = f.elements[i];
			var ctlType = ctl.type.toLowerCase();
			if (ctlType == 'submit' || ctlType == 'button' || ctlType == 'reset')
			{
				ctl.disabled = true;
			}
		}
	}
}

//HTML编码
String.prototype.htmlEncode = function()
{
	var s = this.replace(/&/g, '&amp;');
	s = s.replace(/[ 　]*\r/g, '');
	s = s.replace(/  /g, '&nbsp; ');
	s = s.replace(/\t/g, '&nbsp; &nbsp; ');
	s = s.replace(/\"/, '&quot;');
	s = s.replace(/\'/, '&#39;');
	s = s.replace(/</g, '&lt;');
	s = s.replace(/>/g, '&gt;');
	s = s.replace(/\n/g, '<BR>');
	return s.shitEncode();
}

function textChange(ctl,text){
    ctl=$("#"+ctl);
    ctl.val(text);
    ctl.focus(function(){
        if(ctl.val()==text){
            ctl.val("");
        }
    });
    ctl.blur(function(){
        if(ctl.val()==""){
            ctl.val(text);
        }
    });
}

//HTML编码
String.prototype.htmlEncode = function()
{
	var s = this.replace(/&/g, '&amp;');
	s = s.replace(/[ 　]*\r/g, '');
	s = s.replace(/  /g, '&nbsp; ');
	s = s.replace(/\t/g, '&nbsp; &nbsp; ');
	s = s.replace(/\"/, '&quot;');
	s = s.replace(/\'/, '&#39;');
	s = s.replace(/</g, '&lt;');
	s = s.replace(/>/g, '&gt;');
	s = s.replace(/\n/g, '<BR>');
	return s.shitEncode();
}

//输出一个Flash的图片轮换列表
LCFlashList = {
    show : function(option){
        var flash = option.flashFile;
        var textHeight = option.showText == true ? 18 : 0;
        var width = option.width;
        var height = option.height-textHeight;
        var totalHeight = option.height;
        var textList = '';
        var imageList = '';
        var urlList = '';
        for(i = 0; i < option.list.length; i++){
            textList += option.list[i].text+'|';
            imageList += option.list[i].image+'|';
            urlList += option.list[i].url+'|';
        }
        if(imageList.length>0){
            textList = textList.substr(0,textList.length-1);
            imageList = imageList.substr(0,imageList.length-1);
            urlList = urlList.substr(0,urlList.length-1);
        }
        var flashCode = "";
        flashCode += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' ";
        flashCode += "width='"+width+"' ";
        flashCode += "height='"+totalHeight+"'>";
        flashCode += "<param name='allowScriptAccess' value='sameDomain'/>";
        flashCode += "<param name='movie' value='"+flash+"'/>";
        flashCode += "<param name='quality' value='high'/>";
        flashCode += "<param name='bgcolor' value='#F0F0F0'/>";
        flashCode += "<param name='menu' value='false'/>";
        flashCode += "<param name='wmode' value='opaque'/>";
        flashCode += "<param name='FlashVars' value='pics="+imageList+"&links="+urlList+"&texts="+textList+"&borderwidth="+width+"&borderheight="+height+"&textheight="+textHeight+"'/>";
        flashCode += "<embed src='"+flash+"' wmode='opaque' menu='false' bgcolor='#ffffff' quaility='high' ";
        flashCode += "allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' ";
        flashCode += "width='"+width+"' height='"+totalHeight+"' FlashVars='pics="+imageList+"&links="+urlList+"&texts="+textList+"&borderwidth="+width+"&borderheight="+height+"&textheight="+textHeight+"'/>";
        flashCode += "</object>";
        document.write(flashCode);
    }
}

//输出Flash动画对象
LCFlash = {
    show : function(option){
        var flash = option.flashFile;
        var width = option.width;
        var height = option.height;
        var wmode = option.wmode;
        
        var flashCode = "";
        flashCode += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' ";
        flashCode += "width='"+width+"' ";
        flashCode += "height='"+height+"'>";
        flashCode += "<param name='allowScriptAccess' value='sameDomain'/>";
        flashCode += "<param name='movie' value='"+flash+"'/>";
        flashCode += "<param name='quality' value='high'/>";
        flashCode += "<param name='menu' value='false'/>";
        flashCode += "<param name='wmode' value='"+wmode+"'/>";
        flashCode += "<embed src='"+flash+"' wmode='"+wmode+"' menu='false' quaility='high' ";
        flashCode += "allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' ";
        flashCode += "width='"+width+"' height='"+height+"'/>";
        flashCode += "</object>";
        document.write(flashCode);
    }
}

$.fn.mwfgrid = function(){
    function ExitsSelect(row){
        try{
            return row.find(".ckb_edit").attr("checked");
        }catch(e){return false;}
    }
    function SetClass(row,cls){
        row.removeClass("hover").removeClass("select").addClass(cls);
    }
    function SetCheck(rows,check){
        if(check){
            SetClass(rows,"select");
            rows.find(".ckb_edit").attr("checked","checked");
        }else{
            SetClass(rows,"");
            rows.find(".ckb_edit").attr("checked","");
        }
    }
    $(this).each(function(){
        var grid=$(this);
        grid.find(".row").mouseover(function(){
            var row = $(this);
            if(!ExitsSelect(row))
                SetClass(row,"hover");
        }).mouseout(function(){
            if(ExitsSelect($(this)))
                SetClass($(this),"select");
            else
                SetClass($(this),"");
        });
        
        grid.find(".row .ckb_edit").click(function(){
            if(ExitsSelect($(this).parents(".row")))
                SetClass($(this).parents(".row"),"select");
        });
        grid.find(".ckb_sel").click(function(){
            SetCheck(grid.find(".row"),$(this).attr("checked"));
        });
    });
}


function formsubmit(form,url){
    $(form).attr("action",url).submit();
}