﻿// JavaScript Document
function setFontSize(px){

    var t=document.getElementsByTagName("div");
	 for (var i = 0; i < t.length; i++) { 
		if(t[i].className=="content_art"){
			t[i].style.fontSize=px+"px";
		}
 	 }
}
$(function(){
	var tmpInterval;
	var delay = 150;
	$('#search').find("dl").each(function(){
		$(this).find("dt:first").toggleClass("active").next().toggle().end().end().find("dt").mouseover(function(){
			tmpref = this;
			clearTimeout(tmpInterval);
			tmpInterval = setTimeout("loadTab(tmpref)", delay);
		}).mouseout(function(){
			clearTimeout(tmpInterval);
		});
	});
});

function loadTab(e){
	$(e).parent().find(".active").toggleClass("active").next().toggle();
	$(e).blur().toggleClass("active").next().toggle();
}
function AlbumDrawImage(ImgD,size){ 
var image=new Image(); 
image.src=ImgD.src; 
	if (image.width > image.height){
		ImgD.width=size; 
		ImgD.height=(image.height*size)/image.width; 
	}else{
		ImgD.height=size; 
		ImgD.width=(image.width*size)/image.height;
	}
}
function copyToClipBoard()
{
 var clipBoardContent=window.document.title;
 clipBoardContent+='\r\n' + window.document.location.href;
 window.clipboardData.setData("Text",clipBoardContent);
 alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友！\r\n\r\n内容如下：\r\n" + clipBoardContent);
}

function ShowValidateCode()
{
if($('#ImgSpan').html()==''){
	$('#ImgSpan').html('<img src="/Universal/ValidateCode.aspx?id=1&timeStamp="new Date().getTime() name="ValidateCode" height="20" id="ValidateCodeImg"/>');
}
}
//
var isMoveLoadding=false;
function ShowLoadding()
{
	var div = document.getElementById('divLoadding');
	if(div){}
	else
	{
		var body = document.getElementsByTagName('body').item(0);
        div = document.createElement('div');
        div.id = "divLoadding";
		div.innerHTML="正在执行，请稍候……";
		body.appendChild(div);
	}
	isMoveLoadding=true;
	moveLoadding();
}
function moveLoadding()
{
	var div = document.getElementById('divLoadding');
	if (isMoveLoadding){
        div.style.right = '0px';
        div.style.top = document.documentElement.scrollTop+'px';
		div.style.display = '';
        setTimeout('moveLoadding()', 300);
	}
}
function HideLoadding()
{
	isMoveLoadding=false;
	var div = document.getElementById('divLoadding');
	div.style.display = 'none';
}
function ClearErrorMsg()
{
	$("div.msg").each(function(){$(this).html('');$(this).hide();});
}
//给Checkbox提供全选功能
function SelectGroupBox(self, prefix)
{
	if(!prefix){prefix='';}
	if(self.name=='SelectAll'+prefix){
		var all = self.checked;
		$("input[@name=SelectID"+prefix+"]").each(function(){$(this).attr('checked',all);});
	}else{
		var all = true;
		$("input[@name=SelectID"+prefix+"]").each(function(){if(!$(this).attr('checked'))all=false;});
		$("input[@name=SelectAll"+prefix+"]").attr('checked', all);
	}
}
//检查Checkbox至少要选中一条
function IsCheckedOne(frm,prefix)
{
	if(!prefix){prefix='';}
	var one = false;
	$("input[@name=SelectID"+prefix+"]").each(function(){if($(this).attr('checked'))one=true;});
	return one;
}
function AjaxPost(url, frm, cnfirm, needchecked)
{
	ClearErrorMsg();
	var doit=true;
	if(needchecked==true)
	{
		if(!IsCheckedOne())
		{
			alert('请至少选择一条记录');
			doit = false;
			return;
		}
	}
	if(cnfirm==true)
	{
		if(!confirm('你确定要执行该操作？'))
		{
			doit=false;
		}
	}
	if(doit)
	{
		Ajax(url, frm, 'POST', ShowResult_F, true);
	}
}
function ShowResult_F(result)
{
	var msg = eval('(' + result + ')');
    if (msg.method != undefined) {
        switch (msg.method) {
            case "eval":
                eval(msg.data);
                break;
            case "alert":
                alert(msg.data);
                break;
            case "goto":
                window.location.href = msg.data;
                break;
            case "send_goto":
                var data = eval('(' + msg.data + ')');
                alert(data.message);
                window.location.href = data.url;
                break;
            case "reload":
                alert(msg.data);
                location.reload();
                break;
            case "error":
                var data = eval('(' + msg.data + ')');
                var bo = true;
                for (var o in data) {
                    $('#e_'+o).html(data[o]).show();
                }
                break;
        }
    }
}
function AjaxGet(url, func)
{
	Ajax(url, '', 'GET', func, true);
}
function AjaxLoad(url, div, func) {
	Ajax(url, div, 'LOAD', function(data){$('#'+div).html(data);if(func){func(data);}}, false);
}
function Ajax(url, param, type, func, showloadding)
{
	if(showloadding){ShowLoadding();}
    if (url.indexOf('?') == -1) {
        url += "?";
    }
    else
        url += "&";
	url += "timeStamp=" + new Date().getTime()

	if(type=='GET'||type=='LOAD')
	{
		$.ajax({ url: url,
			type: 'GET',
			cache: false,
			timeout: 20000,
			error: function() { if(param!=''){$('#param').html('数据加载失败');}else{alert('数据加载失败，可能是网络连接问题或者服务器错误。'); }},
			success: func,
			complete:function(){if(showloadding){HideLoadding();}}
		});
	}else if(type=='POST')
	{
		$('.submit').each(function(){$(this).attr('title',$(this).html());$(this).html('请稍候');$(this).attr('disabled','disabled');});
		$.ajax({ url: url,
			type: 'POST',
			data: $('#'+param).serialize(),
			cache: false,
			timeout: 20000,
			error: function() { alert('数据加载失败，可能是网络连接问题或者服务器错误。'); },
			success: func,
			complete:function(){if(showloadding){HideLoadding();}$('.submit').each(function(){$(this).html($(this).attr('title'));$(this).attr('disabled',false);});}
		});
	}
}

var oldDiv = new Object();
function TextOnfocus(obj) {
    if (oldDiv.id != null) {
        $(oldDiv.id).className = oldDiv.className;
    }
    var infoid = obj.id + "Info";
    var infoDiv = document.getElementById(infoid);
    oldDiv.id = infoDiv.id;
    oldDiv.className = infoDiv.className;
    infoDiv.className = "regon";
}
//弹出dialog
var dialogTitle;
function openWin(title, param,width,height) {
    if (document.getElementById('dialog')) {
        $("#dialog").dialog("destroy").remove();
    }
    AjaxGet(param, function(t){
		var body = document.getElementsByTagName('body').item(0);
		var div = document.createElement('div');
		div.id = "dialog";
		div.innerHTML = t;
		body.appendChild(div);
		$("#dialog").dialog({ title: title, width: width == undefined ? 'auto' : width, height: height == undefined ? 'auto' : height,  resizable: false,bgiframe: false, modal: true });

	});
}