﻿//ie6 ImageCache
try {document.execCommand("BackgroundImageCache", false, true);} catch(err) {}

function closeThickBox(){try{tb_remove();}catch(e){}}

function copytxt(sTxt,sMsg) { 
	if (window.clipboardData) { 
		window.clipboardData.setData("text",sTxt);
		alert(sMsg||'复制完毕！');
	}else{ 
		alert('请手动复制以下内容！\n'+sTxt+'');
	} 
	return false; 
}

$(document).ready(function(){
	getMemPhotos();
	$('.cssAddFriend').click(function(){
		$.get('/Public/Apps/ajax_Mem.asp',{cmd:'AddFriend',id:$(this).attr('jnkc')},function(data){alert(data);});
		return false;
	});
	$('img[Icon]').each(function(i){
		$(this).css({'width':'16px','height':'16px','vertical-align':'middle','cursor':'pointer','background':'url(/Public/img/icon1.gif) no-repeat 0 -'+(parseInt($(this).attr('Icon'))*20-20)+'px'});
	});
	$('.cssResizeImg').each(function(){
		resizeImg($(this),$(this).attr('jnkc'));
	});
	/*------------- 20090210 ------------*/
	//all/none
	var ms = false;
	$("a#chkAll").click(function(){
		ms = !ms;
		$("input[name=chkID]").attr('checked',ms);
		return false;
	});

	$("a#chkAnti").click(function(){
		$("input[name=chkID]").each(function(i){
			$(this).attr('checked',!$(this).attr('checked'));
		});
		return false;
	});
});

function fmtForm(vDom){
	var o = vDom||$(document.body);
	$('input.cssIsDate',o)
		.css('ime-mode','disabled')
		.each(function(i){
			$(this).datepicker($.extend({showOn:'both',buttonImageOnly:true,buttonImage:'/Public/plugin/DatePicker/calendar3.gif'},$.datepicker.regional['zh-CN']));
		});
	$('input.cssIsImg',o)
		.css('ime-mode','disabled')
		.each(function(i){
			var obj = $(this);
			var sName = obj.attr('name');
			var sUrl = obj.parents('form').find('input#JFB_UploadFile_URL').val();
			obj.after('<iframe name="JFB_UploadIframe_'+ sName +'" src="'+ sUrl +'&call=fileup2input&for='+ sName +'&j=form&jT=Img&tmp='+ Math.random() +'" width="100%" height="30" frameborder="0" AllowTransparency></iframe>');
		});
	$('input.cssIsFile',o)
		.css('ime-mode','disabled')
		.each(function(i){
			var obj = $(this);
			var sName = obj.attr('name');
			var sUrl = obj.parents('form').find('input#JFB_UploadFile_URL').val();
			obj.after('<iframe name="JFB_UploadIframe_'+ sName +'" src="'+ sUrl +'&call=fileup2input&for='+ sName +'&j=form&jT=File&tmp='+ Math.random() +'" width="100%" height="30" frameborder="0" AllowTransparency></iframe>');
		});
	$('input.cssIsNum',o)
		.css('ime-mode','disabled')
		.each(function(i){
			$(this).blur(function(){
				var obj = $(this);
				if(obj.val()!=''){
					if (isNaN(obj.val())){
						alert('请正确输入数字！');
						obj.focus();
						return false;
					}
				} else {
					obj.val(0);
				}
			});
		});
	$('input.cssIsMemID',o)
		.each(function(i){
			var obj = $(this);
			if (!obj.data('fmt')){
				obj.data('fmt',true)
					.after(' <span/>')
					.change(function(){
						if (isNaN(obj.val())){return false;}
						$.getJSON('/Public/Apps/ajax_Mem.asp',{cmd:'getMemPhotos',chkID:obj.val()},function(data){
							if($(data).size()==0){
								obj.next().html('会员号错误！');
							}else{
								obj.next().html(data[0].MemName);
							}
						});
					});
			}
		});
	$('select.cssSel2Txt',o)
		.each(function(i){
			var obj = $(this);
			obj.change(function(){
				if(this.selectedIndex!=0){
					obj.prev().val(this.options[this.selectedIndex].text);
					this.selectedIndex=0;
				}
			});
		});
	$('button[name=JFB_UploadButton]',o)
		.each(function(i){
			var obj = $(this);
			var sName = 'filebase';
			var sUrl = obj.parents('form').find('input#JFB_UploadFile_URL').val();
			obj.click(function(){
				$.prompt('<input type="hidden" name="'+ sName +'" value="base" /><iframe name="JFB_UploadIframe_'+ sName +'" src="'+ sUrl +'&call=fileup2input&for='+ sName +'&j=win&jT=File&tmp='+ Math.random() +'" width="100%" height="300" frameborder="0" AllowTransparency></iframe>',{
					callback: function(v,m,f){
						if (v){
							//alert(f[sName]);
						}
					},
					width:700,
					height:360,
					buttons:{'关闭窗口':true}
				});
			});
		});
}
function fileup2input(vJSON,vfld){
	$('iframe[name=JFB_UploadIframe_'+vfld+']').siblings('input[name='+vfld+']').val(vJSON['FilePath']);
}
function resizeImg(o,w){
	o = o||$('body');
	if (o.attr('nodeName').toLowerCase()=='body') return;
	w = parseInt(w || 500);
	$('img',o).each(function(i){
		$(this).load(function(){if (parseInt($(this).attr('width'))>w) $(this).attr('width',w);});
		if (parseInt($(this).attr('width'))>w) $(this).attr('width',w);
	});
}
/*------------- 载入会员头像 ------------*/
function getMemPhotos(vDom){
	//<img class="cssMemPhoto" jnkc="123456($MemID$)" />
		var o = vDom||$(document.body);
		var aryPhotoID = {};
		var sPhotoID = 0;
		aryPhotoID[0] = true;
		$('img.cssMemPhoto',o).each(function(i){
			var id = $(this).attr('jnkc');
			if (!aryPhotoID[id]&&!isNaN(id)){sPhotoID += ','+id;aryPhotoID[id] = true;}
			setMemURL($(this),id);
		});
		$('.cssMemName',o).each(function(i){
			var id = $(this).attr('jnkc');
			if (!aryPhotoID[id]&&!isNaN(id)){sPhotoID += ','+id;aryPhotoID[id] = true;}
			if (id.length>4){setMemURL($(this),id);}
		});
		if (sPhotoID!=0){
			$.getJSON('/Public/Apps/ajax_Mem.asp',{cmd:'getMemPhotos',chkID:sPhotoID},function(data){
				$.each(data,function(i,a){
					$('img.cssMemPhoto[jnkc='+a.MemID+']',o).attr('src',a.Photo);
					$('img.cssMemPhoto[jnkc='+a.MemID+']',o).attr('title',a.MemName);
					$('.cssMemName[jnkc='+a.MemID+']',o).html(a.MemName);
					$('.cssMemName[jnkc='+a.MemID+']',o).attr('title',a.MemName);
				});
			});
		}
}

function setMemURL(o,i){
	var obj = (o.attr('nodeName').toLowerCase() == 'a')?o:o.parent('a');
	//if (obj.attr('href') == '#'){}
	obj.attr({href:'http://u'+i+'.togsun.com/',target:'_blank'});
}

function getImgInput(){
	$('input.cssImgInput').each(function(i){
		var o = $(this);
		var obj = $(document.createElement('span'));
		obj.html('&nbsp;<button type="button">上传及选定图片</button>');
		o.after(obj);
		$('button',obj).click(function(){var win=window.open('http://club.togsun.com/Layout.asp?j=MyAlbum.AlbumPhoto&doID=2&Mode='+o.attr('id'));win.focus();});
	});
}

/*------------- 20090210 ------------*/

//addFav
function myAddPanel(title,url,desc)
{
	if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))//Gecko
	{window.sidebar.addPanel(title,url,desc);}
	else//IE
	{window.external.AddFavorite(url,title);	}
}

//carousel
function mycarousel_initCallback(carousel)
{
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
	    carousel.startAuto(0);
	}, function() {
	carousel.startAuto();
	});

	carousel.buttonPrev.bind('click', function() {
	    carousel.startAuto(0);
	}, function() {
	carousel.startAuto();
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
	    carousel.stopAuto();
	}, function() {
	carousel.startAuto();
	});
}

//tab show
function tabShow(list,detail,n){
	$(list).each(function(i){
		if (!isNaN(n)){$("#"+ detail + i +"").hide();}
		$(this).click(function(){
			$(list).removeClass("active");

			$('div[id^='+ detail +']').hide();
			$(this).toggleClass("active");
			$("#"+ detail + i +"").fadeIn("slow");
			return false;
		});
	});
	if (!isNaN(n)){$(list).eq(n).click();}
}


function chgMouseClass(o,cOver,cOut){
	o.each(function(i){
		$(this).hover(
			function () {
				$(this).removeClass(cOut);
				$(this).addClass(cOver);
			},
			function () {
				$(this).removeClass(cOver);
				$(this).addClass(cOut);
			}
		)
	});
}

function editForm(editJSON,o){
	var oRoot = o || $('body');
	for (var i in editJSON){
		var obj = $("*[name="+i+"]",oRoot);
		if (obj.attr("type")=="checkbox"||obj.attr("type")=="radio"){
			obj.val((editJSON[i]+'').replace(/ /g,'').split(","));
		} else {
			obj.val(editJSON[i]||'');
		}
	}
}


// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days){
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name){
	createCookie(name,"",-1);
}
// /cookie functions


/*********************************************
* 对表格加样式表(使表格各行颜色交替变色)
*
* @name		jListTable
* @param	c1 偶数行显示的颜色 0,2,4,6...
* @param	c2 奇数行显示的颜色 1,3,5,7...
* @param	cm 鼠标移动上去时的颜色
* @param	fn 点击某个TD时的回调函数
* @example $(function(){$('.tableLine').jListTable('csstr1','csstr2','csstr3',function(obj){var ck = jQuery('td',obj).get(0).firstChild; ck.checked = !ck.checked;})});
***********************************************/
jQuery.fn.jListTable = function(c1, c2, cm, fn){
	if(!(c1 && c2)) return; //判断有没得参数传入
	var css, obj;
	this.each(function(){ //选中了多少个表格
		obj = jQuery('tr',jQuery(this));
		obj.each(function(i){ // 选中表格中的 TR 加 CSS
			css = i % 2 == 0 ? c1 : c2;
			jQuery(this).addClass(css);
		});

		if(cm){ //如果有第三个参数
			obj.hover(function(){
				jQuery(this).addClass(cm);
			},
			function(){
				jQuery(this).removeClass(cm);
			});
		}
		if(fn && 'function' == typeof(fn)){ //用来处理点击事件的回调函数
			obj.click(function(e){
				//event = jQuery.event.fix( event || window.event || {} );
				var cn = e.target;
				var tn = cn.nodeName.toLowerCase();
				if( cn && tn == 'td'){
					cn = jQuery(cn).parent();
					fn.call(this,cn,tn,e); //返回点击所在的tr对象，点击触发的tag，event
				}else if( cn && tn != 'tr'){
					cn = jQuery(cn).parent().parent();
					fn.call(this,cn,tn,e);
				}
			});
		}
	});
}
