
function pngfix(){
   var arVersion = navigator.appVersion.split("MSIE");
   var version = parseFloat(arVersion[1]);
   if ((version >= 5.5)&& (version < 7)) 
   {
      for(var j=0; j<document.images.length; j++)
      {
         var img = document.images[j];
         var imgName = img.src.toUpperCase();
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : "";
            var imgClass = (img.className) ? "class='" + img.className + "' " : "";
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
            var imgStyle = "display:inline-block;" + img.style.cssText; 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle;
            if (img.align == "right") imgStyle = "float:right;" + imgStyle;
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"; 
            img.outerHTML = strNewHTML;
            j = j-1;
            
         }
      }
      //解决背景透明问题
      for(var j=0; j<jQuery("div,span,li,input,textarea,a").length; j++)
      {
         var divObj = jQuery("div,span,li,input,textarea,a").get(j);
         bgImg = jQuery(divObj).css('background-image');
         if(!bgImg) continue;
         
         var imgName = bgImg.toUpperCase();
         if (imgName.substring(imgName.length-5, imgName.length-2) == "PNG")
         {
            imgSrc = bgImg.replace('url("','');
            imgSrc = imgSrc.replace('")','');
            //divObj.style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src="+imgSrc+",sizingMethod=scale)";
            jQuery(divObj).css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+imgSrc+",sizingMethod=crop)");
            //jQuery(divObj).css('background','none');
            
         }
      }
   }  
}
//刷新验证码图片
function refreshVerifyImg(){
	s = '/index/verify?n='+Math.random();
	jQuery('#verify-img').attr('src',s);
	jQuery('#verifyCode').val('');
}
/**
 * Show Message
 * @msgId 要显示信息的HTML元素ID
 * @msgContent 要显示的信息内容
 * @type error|notice|success
 * @type autoHide 自动消失
 */
function showMsg(msgId,msgContent,type,autoHide){
	jQuery('#'+msgId).addClass('tappy-msg').removeClass('tappy-success-msg').removeClass('tappy-notice-msg').removeClass('tappy-error-msg');
	if(typeof(type)=='undefined') type='notice';
	switch(type){
		case 'error':
		case 'notice':
		case 'success':
			jQuery('#'+msgId).html(msgContent).addClass('tappy-'+type+'-msg').show();
			break;
	}
	if(typeof(autoHide)!='undefined'){
		if(autoHide){
			jQuery('#'+msgId).slideUp(7000);
			jQuery('#'+msgId).hide();
		}
	}
}
function setListBox(lbxId){
	if(lbxId){
		sv = jQuery('#'+lbxId).attr('selectValue');
		jQuery('#'+lbxId).val(sv);
	}
}
function tabLocation(opt){
	tabId = opt.tabId
	frmId = opt.iframeId;
	url   = '';
	if(typeof(opt.url)!='undefined')
		url   = opt.url;
	jQuery(document).ready(function(){
		jQuery('#'+tabId+' li').click(function(){
			if(!jQuery(this).hasClass('current')){
				jQuery('#'+tabId+' li').removeClass('current');
				jQuery(this).addClass('current');
				jQuery('#'+frmId).attr('src',this.id);
			}
		});
		if(url!=''){
			srcUrl = jQuery('#'+frmId).attr('src');
			if(srcUrl==url){
				return ;
			}
			jQuery('#'+tabId+' li').removeClass('current');
			setCurrent = false;
			for(i=0;i<jQuery('#'+tabId+' li').length;i++){
				e = jQuery('#'+tabId+' li').get(i);
				if(url.indexOf(e.id)!=-1){
					jQuery(e).addClass('current');
					setCurrent = true;
					break;
				}
			}
			if(!setCurrent){
				firstLi = jQuery('#'+tabId+' li').get(0);
				if(firstLi){
					jQuery('#'+frmId).attr('src',firstLi.id);
					jQuery(firstLi).addClass('current');
				}
			}
			jQuery('#'+frmId).attr('src',url);
			
		}else{
			firstLi = jQuery('#'+tabId+' li').get(0);
			if(firstLi){
				jQuery('#'+frmId).attr('src',firstLi.id);
				jQuery(firstLi).addClass('current');
			}
		}
	});
}
function setCookie(name, value, hours){
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  curHost = window.location.host;
  hosts = curHost.split('.');
  if(hosts.length==4 && hosts[3]=='cn'){
	  d = hosts[1]+'.'+hosts[2]+'.'+hosts[3];
  }else if(hosts.length==3){
	  d = hosts[1]+'.'+hosts[2];
  }else{
	  d = '';
  }
  document.cookie = name + "=" + escape(value) + expire + ";domain="+d+";" + "path=/;";
}
function getCookie(name){
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
/**
 * 头尾去空格
 */
function trim(s) {
    return s.replace(/^\s+|\s+$/, ''); 
}
function refreshVerifyImg(){
	s = '/index/verify?n='+Math.random();
	jQuery('#verify-img').attr('src',s);
	jQuery('#verifyCode').val('');
}
function setCheckBox(boxname,selectValue){
	if(typeof(selectValue)!='undefined'){
    	jQuery('input[@name="'+boxname+'"][@value="'+selectValue+'"]').attr('checked',true);
    }else{
    	if(jQuery(boxname).attr('selectValue')==jQuery(boxname).val()){
  	  	    jQuery(boxname).attr('checked',true);
  	    }
    }
}







function hideBlock(e){
	jQuery(e).css('display','none')
}
function showBlock(frmBlockId,aName){
	d = jQuery(frmBlockId).css('display');
	if(d=='none'){
		jQuery(frmBlockId).css('display','');
	}
	pos = location.href.indexOf('#');
	if(aName!=''){
		if(pos==-1)
			location.href= location.href + '#' + aName;
		else{
			location.href= location.href.substring(0,pos) + '#' + aName;
		}
	}
}
function loadHtml(url,toId,callback){
	jQuery.get(url,function(data){
		jQuery('#'+toId).html(data);
		if(typeof(callback)=='function'){
			callback();
		}
	});
}
function tappyXslt(url,xsl,target){
	jQuery.get(url,function(data){
		getTransform(data,xsl,target);
	});
}
function getTransform(xml,xslFile,loaderId){
	var targetDiv = jQuery('#'+loaderId);
	var dom = parseXML(xml);
	try{
		var xslObj = new ActiveXObject("Microsoft.XMLDOM");
		xslObj.async = false;
		xslObj.load(xslFile);
		targetDiv.html(dom.transformNode(xslObj));
	} catch (error) {
		try{
			var xslDoc = document.implementation.createDocument("", "", null);
			xslDoc.async = false;
			xslDoc.load(xslFile);
			var oProcessor = new XSLTProcessor();
			oProcessor.importStylesheet(xslDoc);
			fragment = oProcessor.transformToFragment(dom, document);
			targetDiv.html('');
			targetDiv.append(fragment);
			
		} catch (error2) {
		}
	}
	translatePage(document);
}



function parseXML(xml) {
	var dom;
	try{
		dom = new ActiveXObject("Microsoft.XMLDOM");
		dom.async = false;
		dom.loadXML(xml);
	} catch (error) {
		try{
			var parser = new DOMParser();
			dom = parser.parseFromString(xml, "text/xml");
			delete parser;
		} catch (error2) {
		}
	}
	return dom;
}
function _print(pid){
	var headstr = "<html><head><title></title>";
	headstr+="<style>p,div,span,td{font-size:14px;line-height:1.5em;padding:0px;margin:0px;}body{margin:20px 10px;background-color:#fff}</style></head><body>";
	var footstr = "</body>";
	var newstr = jQuery('#'+pid).html();
	oldstr = jQuery('body').html();
	jQuery('body').html(headstr+newstr+footstr);
	window.print(); 
	jQuery('body').html(oldstr);
}

//cbx:对象或id或合科jQuery要求的字串
//function setCheckBox(cbx){
//    if(jQuery(cbx).attr('selectValue')==jQuery(cbx).val()){
//  	  	    jQuery(cbx).attr('checked',true);
//  	    }
//}

function translateElements( targetDocument, tag, propertyToSet){
	var e = targetDocument.getElementsByTagName(tag) ;
	var sKey, s ;
	for ( var i = 0 ; i < e.length ; i++ ){
		if ( sKey = e[i].getAttribute( 'tappyLang' ) ){
			if ( s = tappyLang[ sKey ] ){
				eval( 'e[i].' + propertyToSet + ' = s' ) ;
			}
		}
	}
}
function translatePage( targetDocument ){
	translateElements( targetDocument, 'INPUT', 'value' ) ;
	translateElements( targetDocument, 'SPAN', 'innerHTML' ) ;
	translateElements( targetDocument, 'LABEL', 'innerHTML' ) ;
	translateElements( targetDocument, 'OPTION', 'innerHTML', true ) ;
	translateElements( targetDocument, 'DIV', 'innerHTML', true ) ;
}
/**
 * 预览图片
 * @param string picFileName
 * @param string fileName
 */
function picPreview (picFileName,fileName){
	if(jQuery('#'+picFileName)){
		var vPicFileName = jQuery('#'+picFileName).attr(fileName);
		if(typeof(vPicFileName)!='undefined' && vPicFileName!=''){
			if(vPicFileName.indexOf('.swf')!=-1){
				var embedE = document.createElement("embed");
				embedE.src = vPicFileName;
				embedE.width = '100px';
				embedE.height= '70px';
				embedE.type  = 'application/x-shockwave-flash';
				embedE.setAttribute('play',true);
				embedE.setAttribute('loop',true);
				embedE.setAttribute('menu',true);
				embedE.id = 'pic';
				jQuery('#'+picFileName).html('');
				jQuery('#'+picFileName).append(jQuery(embedE)[0]);
			}else{
				var imgE = document.createElement("img");
				imgE.src = vPicFileName;
				imgE.style.width = "100px";
				imgE.style.height= "70px";
				imgE.border= 1;
				imgE.style.borderColor = '#999';
				imgE.id = 'pic';
				var aE = document.createElement("a");
				aE.href= vPicFileName;
				aE.target = '_blank';
				aE.appendChild(imgE);
				jQuery('#'+picFileName).html('');
				jQuery('#'+picFileName).append(jQuery(aE)[0]);
			}
		}
	}
}
function isAllowUpload(checkValue,fileExtList){
    checkValue      = checkValue.toLowerCase();
    fileExtList     = fileExtList.toLowerCase();

    extListArray    = fileExtList.split(",");
    checkValueArray = checkValue.split(".");
    flag            = 0;
    if (checkValueArray.length<=1)
        return false;
    valueExt        = checkValueArray[checkValueArray.length-1];

    for(i=0;i<extListArray.length;i++){
    	strExt = extListArray[i].length;
    	if (valueExt==extListArray[i])
    	{
    		flag=1
    		break;
    	}
    }
    if (flag!=1){
        return false;
    }
    return true;	     
}
function popThickBox(url,t,w,h){
	if(url.indexOf('&')!=-1){
		url=url+'&';
	}else{
		url=url+'?';
	}
	g=false;
	url+='&KeepThis=true&TB_iframe=true&height='+h+'&width='+w;
	tb_show(t,url,g);
}
function setNumList(objName,startNum,endNum,selectValue){
	startNum = parseInt(startNum);
	endNum   = parseInt(endNum);
	selectValue   = parseInt(selectValue);
	len = endNum - startNum+1;
	num = startNum;
	
	for(i=0;i<len;i++){
		jQuery('<option></option>').attr('value',num).attr('text',num).appendTo(objName);
		num++;
	}
	jQuery(objName).val(selectValue);
}
var TappyOverlay ={
	imgLoader : '/common/img/ajax-loader.gif',
	TB_WIDTH :300,
	TB_HEIGHT:150,
	waiting:function(w,h){
		if(typeof w!='undefined'){
			this.TB_WIDTH = w;
		}
		if(typeof h!='undefined'){
			this.TB_HEIGHT = h;
		}
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			jQuery("body","html").css({height: "100%", width: "100%",textAlign:'center'});
			jQuery("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window' ></div>");
				jQuery("#TB_overlay").click(this.stop);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window' ></div>");
				jQuery("#TB_overlay").click(this.stop);
			}
		}
		
		if(this._detectMacXFF()){
			jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		jQuery("body").append("<div id='loadImg' class='loadingMsgPannel'><div id='loadingMsg' class='loadingMsg'><img src='"+this.imgLoader+"' /><br/>Loading...</div></div>");//add loader to the page
		jQuery('#loadImg').show();//show loader
		//jQuery('#TB_window').show();//show loader
		document.onkeyup = function(e){ 	
			if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			if(keycode == 27){ // close
				TappyOverlay.stop();
			}	
		};
	},
	msg:function(c,alignTop){
		//alignTop:居上对齐
		if(document.getElementById("TB_window") !== null){
			//jQuery('#loadingMsg').html(c);
			caption ='';
			ajaxContentW = parseInt(this.TB_WIDTH)-30;
			ajaxContentH = parseInt(this.TB_HEIGHT)-40;
			jQuery("#TB_window").html('');
			jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>"+wikiLang.CLOSE+"</a> "+wikiLang.PRESS_ESC_KEY+"</div></div><div id='TB_ajaxContent' ></div>");
			jQuery('#TB_ajaxContent').html(c);
			if(typeof alignTop!='undefined' && alignTop==true){
				
			}else{
				jQuery('#TB_ajaxContent').css('text-align','center');
				//jQuery('#TB_ajaxContent').css('line-height',ajaxContentH+'px');
				h = parseInt(ajaxContentH/2)+20;
				//jQuery('#TB_ajaxContent').css('margin-top',h+'px');
				jQuery('#TB_ajaxContent').css('margin-left','auto');
				jQuery('#TB_ajaxContent').css('margin-right','auto');
			}
			this._position();
			jQuery('#loadImg').remove();
			jQuery("#TB_closeWindowButton").click(this.stop);
			jQuery("#TB_window").css({display:"block"});
		}
	},
	_position:function() {
		jQuery("#TB_window").css({marginLeft: '-' + parseInt((this.TB_WIDTH / 2),10) + 'px', width: this.TB_WIDTH + 'px'});
		if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
			jQuery("#TB_window").css({marginTop: '-' + parseInt((this.TB_HEIGHT / 2),10) + 'px'});
			
		}
	},
	stop:function(){
		jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
		jQuery("#loadImg").remove();
		if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
			//jQuery("body","html").css({height: "auto", width: "auto"});
			jQuery("html").css("overflow","");
		}
		document.onkeydown = "";
		document.onkeyup = "";
		return false;
	},
	_detectMacXFF:function(){
		var userAgent = navigator.userAgent.toLowerCase();
  		if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    		return true;
    	}
	}
};