/*  @xkshow 2010/01
 * 
 *   public js * values 
 */
//check email
function ismail(mail){  
   var em = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
   if(em.test(mail)){
      return true;
   }else{
      return false;
   } 
} 
//reset image
function resetImg(ImgD,W,H){ 
	var flag = false; 
	var oldImage = new Image(); 
	    oldImage.src = ImgD.src; 
	if(oldImage.width>0 && oldImage.height>0){ 
		flag=true; 
//		if(oldImage.width/oldImage.height>= W/H){ 
//		      if(oldImage.width>=W){
//		          ImgD.width = W; 
//		          ImgD.height = (oldImage.height*H)/oldImage.width;
//		      }else{ 
//		          ImgD.width = oldImage.width;
//		          ImgD.height = oldImage.height; 
//		      } 
//		      //ImgD.alt= ""; 
//		}else{ 
//		      if(oldImage.height>=H){
//		          ImgD.height = H; 
//		          ImgD.width = (oldImage.width*W)/oldImage.height; 
//		      }else{ 
//		          ImgD.width = oldImage.width;
//		          ImgD.height = oldImage.height; 
//		      } 
//		      //ImgD.alt=""; 
//		} 
		var dW = oldImage.width; 
	    var dH = oldImage.height;
	    var oWh = dW/dH;
	    var wh = W/H;
	    if(dW>=W) {
	        dW = W; 
	    }else{
	    	dW = W; 
	    }
	    if(dH>=H) {
	        dH = H;
	    }else{
	    	dH = H;
	    }
		if(dW > 0 && dH > 0){
	    	ImgD.width = dW;
	    	ImgD.height = dH;
	    }
	}
//    var state=ImgD.readyState;
//    var oldImage = new Image();
//    	oldImage.src = ImgD.src;
//    var dW=oldImage.width; 
//    var dH=oldImage.height;
//    if(dW>W || dH>H) {
//        a=dW/W; 
//        b=dH/H; 
//        if(b>a){ 
//        	a=b;
//        }
//        dW=dW/a; 
//        dH=dH/a;
//    }
//    if(dW > 0 && dH > 0){
//    	ImgD.width=dW;
//    	ImgD.height=dH;
//    }
//    if(state!='complete' || ImgD.width>W || ImgD.height>H) {
//        setTimeout("ResizeImage(null,"+W+","+H+")",40); 
//    }
}
//图片显示
function avPic(imgSrc){
	    document.getElementById("loadPic").innerHTML = "";
	    var loadpic = document.getElementById("loadPic");
	    loadpic.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc.value; 
	    loadpic.style.width = "100px";
	    loadpic.style.height = "67px";
}

function myShares(stat,title){
	//vars
	var myurl = window.location.href;
	//alert(myurl);
	//
	if(stat=='qqbook'){
	   //window.open('http://imgcache.qq.com/qzone/app/qzshare/news_share.html#url='+myurl,'share','scrollbars=no,width=900,height=570,status=no,resizable=yes');
	   window.open('http://shuqian.qq.com/post?from=3&title='+encodeURIComponent(title)+'&uri='+encodeURIComponent(myurl)+'&jumpback=2&noui=1','share','scrollbars=no,width=900,height=570,status=no,resizable=yes');
	}
	if(stat=='qqzone'){
	    window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+escape(myurl)+'&rtitle='+escape(title)+'&rcontent='+escape(title),'share','scrollbars=no,width=900,height=570,status=no,resizable=yes');
	}	
	if(stat=='kaixin001'){
		window.open('http://www.kaixin001.com/~repaste/repaste.php?&rurl='+escape(myurl)+'&rtitle='+escape(title)+'&rcontent='+escape(title),'share','scrollbars=no,width=900,height=570,status=no,resizable=yes');
	}
	if(stat=='tao'){
		window.open('http://share.jianghu.taobao.com/share/addShare.htm?url='+myurl,'share','scrollbars=no,width=900,height=570,status=no,resizable=yes');
	}
	if(stat=='baidu_hi'){
		window.open('http://apps.hi.baidu.com/share/?url='+myurl,'share','scrollbars=no,width=900,height=570,status=no,resizable=yes');
	}
	if(stat=='google'){
		window.open('http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+myurl+'&title='+title,'share','scrollbars=no,width=900,height=570,status=no,resizable=yes');
	}
	if(stat=='vivi'){
		window.open('http://vivi.sina.com.cn/collect/icollect.php?pid=free9.net&title='+escape(title)+'&url='+myurl+'&desc='+escape(title),'share','scrollbars=no,width=900,height=570,status=no,resizable=yes');
	}
	if(stat=='yahoo'){
		window.open('http://myweb.cn.yahoo.com/popadd.html?url='+encodeURIComponent(myurl)+'&title='+encodeURIComponent(title),'share','scrollbars=no,width=900,height=570,status=no,resizable=yes');
	}
}

/*
 *  copy url 
 */
function copy_url(vid){
    var clipBoardContent = "http://"+location.host+"/av.shtml?action=details&id="+vid;// get local url
	//alert(clipBoardContent);
	if (window.clipboardData){
		window.clipboardData.setData("Text", clipBoardContent);
	}else if (window.netscape){
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance
	
		(Components.interfaces.nsIClipboard);
		if (!clip)
			return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance
	
		(Components.interfaces.nsITransferable);
		if (!trans) 
			return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance
	
		(Components.interfaces.nsISupportsString);
		var copytext=clipBoardContent;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) 
			return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	alert("Copy success, you can send to your dear friends!");
}

function copy_urlIn(myUrl){
    var clipBoardContent = myUrl;//get in url
	//alert(clipBoardContent);
	if (window.clipboardData){
		window.clipboardData.setData("Text", clipBoardContent);
	}else if (window.netscape){
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance
	
		(Components.interfaces.nsIClipboard);
		if (!clip)
			return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance
	
		(Components.interfaces.nsITransferable);
		if (!trans) 
			return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance
	
		(Components.interfaces.nsISupportsString);
		var copytext=clipBoardContent;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) 
			return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	alert("Copy success, you can send to your dear friends!");
}

