﻿$(document).ready(function(){
	correctPNG();
	
	//产品菜单
	/*
	$('.pc_link',this).click(function(){
		var id=this.id;
		var subid='#sub_'+id;
		if($(subid).length>0){
			$(subid).toggle();
			return false;
		}
	});
	*/
	//下载文件
	$('.downloadlink',this).click(function(){
		var strid=this.id;
		$.ajax({
			type:'GET',
			url:'/download.php',
			data:{id:strid},
			dataType:'json',
			success:function(a){
				var id=a.id;
				var errnums=a.errnums;
				var errmsg=a.errmsg;
				var pw=a.pw;
				var url=a.url;
				if(errnums==1){
					alert(errmsg);
				}else{
					if(pw==1){
						tipsWindown("Message","iframe:"+url,"420","180","true","","true","leotheme");
					}else{
						tipsWindown("Message","text:"+errmsg,"420","150","true","","true","msg");
					}
				}
			},
			error:function(XMLHttpRequest, textStatus, errorThrown){
				//var html="XMLHttpRequest.status : "+XMLHttpRequest.status+"\r";
				//var html=html+"XMLHttpRequest.readyState : "+XMLHttpRequest.readyState+"\r";
				//var html=html+"textStatus : "+textStatus+"\r";
				//alert(html);
				alert(errorThrown);
			},
			onerror:function(){alert("服务器发生错误，请联络系统管理员！");}
		});
	});
});

function img_auto_resize(p,w,h){
	var pw,ph;
	var c;
	pw = p.width;
	ph = p.height;
	if(w>0 && pw>w){ph=ph*(w/pw);pw=w;}
	if(h>0 && ph>h){pw=pw*(h/ph);ph=h;}
	p.width=pw;
	p.height=ph;
}

function checkNumber(par_val){
	if(par_val==""){
		return false;
	}else{
		for(i=0; i<par_val.length; i++){
			if (par_val.substring(i, i+1)!="."){
				if (par_val.substring(i, i+1)<"0" || par_val.substring(i, i+1)>"9"){
					return false;
				}
			}
		}
		return true;
	}
}

//使用 IE6.0 和 IE5.5 中的 PNG 格式的背景透明
// correctly handle PNG transparency in Win IE 5.5 & 6.0
function correctPNG(){
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version < 7.0) && (document.body.filters)){
		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;
			}
		}
	}
}

//刷新验证码
function reloadSecurityCode(obj){
	var strlink=$('#'+obj).attr('src');
	strlink+=strlink.indexOf('?')=='-1'?"?":"&";
	strlink+="thistime="+Math.random();
	$('#'+obj).attr("src",strlink);
}

//复制到剪贴板 并且提示
function CopyToClipBoard(content,tip){
	window.clipboardData.setData("Text",content);
	if(tip!='')alert(tip);
}
