﻿var PgScript = {}
window.PgScript = PgScript;

if (typeof (jj) != "undefined") {

}
else {
    jj = $;
}

function f(){}

if (window.XMLHttpRequest) { //Mozilla, Safari,...IE7	
    if (!window.ActiveXObject)// Mozilla, Safari,...
    {
    }
    else {
    }
}
else {//IE6
    document.execCommand("BackgroundImageCache", false, true);
}

Array.prototype.unique = function()
{
    var a = {};
    for(var i=0; i<this.length; i++)
    {
        if(typeof a[this[i]] == "undefined")
            a[this[i]] = 1;
    }
    this.length = 0;
    for(var e in a)
        this[this.length] = e;
    return this;
}

String.prototype.trim = function()   
{
    return this.replace(/(^\s*)|(\s*$)/g,"");
}

String.prototype.content = function(val) {
    return this.indexOf(val) > -1;
}

jQuery.fn.outerHTML = function(s) {
	return (s)
	? this.before(s).remove()
	: jQuery("<p>").append(this.eq(0).clone()).html();
}
var FormSendId;
function FormSend(meth, tar, url, valueArr) {
    var methCurr = meth == "get" ? "get" : "post";
    FormSendId = "f" + parseInt(Math.random() * 1000000);
    var currForm = $("<form>", { action: url, method: methCurr, id: FormSendId });
    if (tar != "") {
        currForm.attr("target", tar);
    }    
    for (var i = 0; i < valueArr.length; i++) {
        var ipt = $("<input type=\"hidden\" name=\""+ valueArr[i].Key+"\" value=\""+valueArr[i].Value+"\"  />")
        currForm.append(ipt);
    }
    currForm.appendTo("body");
    currForm.submit();
}

function CheckObj(obj)
{
    if(!obj)return false;
    if(obj===undefined)return false;
    if(obj==null)return false;
    return true;    
}

function $getintf(s,f)
{
    var r=$getstr(s).replace(f,"");
    return $getint(r);
}
function $getint(s)
{
    try
    {
        return parseInt(s);
    }
    catch(ex)
    {
        return 0;
    }
}

function $getstr(s)
{
    try
    {
        return s+"";
    }
    catch(ex)
    {
        return "";
    }
}

function $gettext(s)
{
    try
    {
        var obj=$ce("div");
        obj.innerHTML=s;
        return obj.innerTEXT;
        obj=null;
    }
    catch(ex)
    {
        return " ";
    }
}

function $e(id)
{
	try
	{
		return 	jj('#'+id).get(0);
	}
	catch(e)
	{
		return document.getElementById(id);
	}
}

function GetStrInArray(str,sp,d)
{
	var arr=str.split(sp);
	if(d<arr.length)return arr[d];
	else return "";
}
  
function LoadJs(jspath)
{
	jj($ce("script",""))
	.attr('src',  jspath)
	.attr('type', 'text/javascript') 
	.appendTo('head'); 
}

function CPos(x, y)
{
    this.x = x;
    this.y = y;
}

function GetObjPos(ATarget)
{
    var target = ATarget;
    var pos = new CPos(target.offsetLeft, target.offsetTop);
    
    target = target.parentElement;
    while (target)
    {
        pos.x += target.offsetLeft;
        pos.y += target.offsetTop;        
        target = target.parentElement
    }
    
    return pos;
}

function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{ 
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var pageWidth,pageHeight,windowWidth,windowHeight;
	if (self.innerHeight)
	{
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	} 
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){ 
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function $ce(etype,evalue)
{
	var eobj=document.createElement(etype);
	if(evalue)eobj.innerHTML=evalue;
	return eobj;
}
function $cdiv(ev)
{
	if(ev) return $ce("div");
	else return $ce("div",ev);
}
function $cspan(ev)
{
	if(ev) return $ce("span",ev);
	else return $ce("span");
}

var GetRandomNumObj={};
GetRandomNumObj.today=new Date(); 
GetRandomNumObj.seed=GetRandomNumObj.today.getTime(); 
function GetRandomNumHelper() { 
	GetRandomNumObj.seed = (GetRandomNumObj.seed*9301+49297) % 233280; 
	return GetRandomNumObj.seed/(233280.0); 
}
function GetRandomNum(num) {
	if(num)return Math.ceil(GetRandomNumHelper()*num);
	else return Math.ceil(GetRandomNumHelper()*100000000);
}

function PageADTimer(areaid)
{
	var area=jj(areaid);
	var obj;
	if(area.childNodes.length<1)return;
	obj=area.childNodes[0];
	if(obj.tagName.toLowerCase()!='img')return;
	obj.onLoad=PageADTimerOpen(areaid,5);
}

function PageADTimerOpen(areaid,sc)
{
	eval("ADTimer_"+jj(areaid).id+"=window.setInterval(\"PageADTimerClose('"+jj(areaid).id+"')\",sc*1000);");
}

function PageADTimerClose(areaid)
{
	jj(areaid).style.display='none';
	window.clearInterval(window.eval("ADTimer_"+jj(areaid).id));
}

function FlashNews(areaid, tempfile, temptext, templink, nwidth, nheight) {
	
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ nwidth +'" height="'+ nheight +'">');
	document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="images/FlashNews.swf"><param name="quality" value="high"><param name="bgcolor" value="#DADADA">');
	document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
	document.write('<param name="FlashVars" value="pics='+tempfile+'&links='+templink+'&texts='+temptext+'&borderwidth='+nwidth+'&borderheight='+(nheight - 20)+'&textheight='+20+'">');
	document.write('<embed src="images/FlashNews.swf" wmode="opaque" FlashVars="pics='+tempfile+'&links='+templink+'&texts='+temptext+'&borderwidth='+nwidth+'&borderheight='+(nheight - 20)+'&textheight='+20+'" menu="false" bgcolor="#DADADA" quality="high" width="'+ nwidth +'" height="'+ nheight +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>'); 
}

function tabAlign(obj, w, h) {
	var cObj = $(obj).outerHTML();
	var cTab = $("<table>", { "cellpadding": "0", "cellspacing": "0", "width": w, "height": h })
	.html("<tr><td></td></tr>");

    var href=$(obj).parent().attr("href");
    
	if (href != null) {
	    cObj=$("<a>",{"href":href}).append(cObj);
	}
    
	if (w != 0) {
		$("td", cTab).attr("align", "center");
	}
	
	$("td", cTab).append(cObj);
	
	//alert(cTab.outerHTML());

	$(obj).outerHTML(cTab.outerHTML());
}

function divAlign(obj, w, h)
{
    if ($(obj).attr("divAlign") != null) {
        return;
    }
    $(obj).attr("divAlign", "fixed");

    var objfm = $(obj).height() / 2;
    if (objfm == 0) {
        tabAlign(obj, w, h);
        return;
    }

    var cObj = $(obj).outerHTML();
    var href = $(obj).parent().attr("href");

    if (href != null) {
        cObj = $("<a>", { "href": href }).append(cObj);
    }
    
		
	var cOuterDiv = $("<div>", { "class": "BoxBase" })
	cOuterDiv.css("width","100%").css("text-align","center");
	var cVerDiv = $("<div>", { "class": "BoxBase" });
	cVerDiv.css("width", "100%").css("height", parseInt(h / 2) + "px").css("margin-bottom", "-" + parseInt(objfm) + "px");

	cOuterDiv
	.append(cVerDiv)
	.append(cObj)
	
	$(obj).outerHTML(cOuterDiv.outerHTML());	
}

var LoadShowImg=true;
var LoadShowImgUrl="/images/PageLoading.gif";

function LoadUrl(url,oncomplated)
{
	var objid="LoadUrl_"+GetRandomNum(1000000);
	var objurl = url;
	if(LoadShowImg)
		document.write("<div id=\""+objid+"\"><img border=0 src="+LoadShowImgUrl+"></div>");
	else
		document.write("<div id=\""+objid+"\"></div>");
	if(oncomplated)
	{
		jj.ajax({url:objurl,success:function(rpt){jj('#'+objid).html('');oncomplated(objid,rpt)}});
	}
	else
	{
		jj('#'+objid).load(objurl);
	}
}


function LoadPart(name,oncomplated)
{
	var objid="LoadPart_"+GetRandomNum(1000000);
	var objurl = "/getjs/getpartjs.aspx?part="+name;
	if(LoadShowImg)
		document.write("<div id=\""+objid+"\"><img border=0 src="+LoadShowImgUrl+"></div>");
	else
		document.write("<div id=\""+objid+"\"></div>");
	if(oncomplated)
	{
		jj.ajax({url:objurl,success:function(rpt){jj('#'+objid).html('');oncomplated(objid,rpt)}});
	}
	else
	{
		jj('#'+objid).load(objurl);
	}
}

function LoadUc(path,oncomplated)
{
	var objid="LoadUc_"+GetRandomNum(1000000);
	var objurl = "/getjs/getucjs.aspx?file="+path;
	if(LoadShowImg)
		document.write("<div id=\""+objid+"\"><img border=0 src="+LoadShowImgUrl+"></div>");
	else
		document.write("<div id=\""+objid+"\"></div>");
	if(oncomplated)
	{
		jj.ajax({url:objurl,success:function(rpt){jj('#'+objid).html('');oncomplated(objid,rpt)}});
	}
	else
	{
		jj('#'+objid).load(objurl);
	}
}

function LoadUcIframe(w, h, path) {
    var q = location.search.substr(1);
    var objid = "LoadUc_" + GetRandomNum(1000000);
    var objurl = "/getjs/getuciframe.aspx?file=" + path + "&" + q;
    document.write("<iframe id=\"" + objid + "\" frameborder=\"0\" scrolling=\"no\" allowTransparency=\"true\" width=\"" + w + "\" height=\"" + h + "\" src=\"" + objurl + "\"></iframe>");
}

//填充自适应
function fillImg(img, w, h) {
    try {
        var imageArr = img;
        var maxWidth = w;
        var maxHeight = h;
        imageArr.style.display = "";
        var imageRate = imageArr.offsetWidth / imageArr.offsetHeight;

        if (imageRate > 1) {
            //w
            imageArr.style.width = maxHeight * imageRate + "px";
            imageArr.style.Height = maxHeight + "px";
            img.style.marginLeft = ((w - img.width) / 2) + "px";
        }
        else {
            //h
            imageArr.style.width = maxWidth + "px";
            imageArr.style.Height = maxWidth / imageRate + "px";
            img.style.marginTop = ((h - img.height) / 2) + "px";
        }

    }
    catch (ex) {
        imageArr.style.display = "none";
    }
}

//缩小自适应
function autoImg(obj, w, h) {
    if ($(obj).attr("fixsize") != null) {
        return;
    }

	if(obj.style.display)
    {
		obj.style.display="";
	}
	var image=new Image();  
	image.src=obj.src;  
	if(image.width>0 && image.height>0){

	    if (image.width / image.height >= w / h) {
	        if (image.width > w) {
	            obj.width = w;
	            obj.height = (image.height * w) / image.width;
	        } else {
	            obj.width = image.width;
	            obj.height = image.height;
	        }

	    }
	    else {
	        if (image.height > h) {
	            obj.height = h;
	            obj.width = (image.width * h) / image.height;
	        } else {
	            obj.width = image.width;
	            obj.height = image.height;
	        }
	    }

	    $(obj).attr("fixsize", obj.width + "*" + obj.width);		
		 
	}
}

var DrawImage = autoImg;


//FLASH自动缩小
function autoImgsl(spath,slink,w,h)
{
document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+w+"\" height=\""+h+"\"><param name=\"movie\" value=\"/images/swfoto.swf?image="+spath+"&imageLink="+slink+"\"><embed src=\"/images/swfoto.swf?image="+spath+"&imageLink="+slink+"\" width=\""+w+"\" height=\""+h+"\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"></embed></object>");
}

function ImgError(obj)
{
	obj.src="/images/inner/nopic.jpg";
}

function setHomePage(obj)
{
	obj.homepage.style.behavior='url(#default#homepage)';
	obj.homepage.sethomepage(site_url);
}
function setFavorite()
{
	window.external.AddFavorite(site_url,site_name);
}

function openWin(url)
{
	window.oper=null;
	window.open(url);
}

function setfontas(obj,size)
{
	jj('#'+obj).css("font-size",size);
}

function DataTimePicker(obj)
{
	new WdatePicker(obj,'%Y-%M-%D %h:%m',true,'default');	
}

function DataPicker(obj)
{
	new WdatePicker(obj,'%Y-%M-%D',true,'default');	
}

function tab_chg(pre,cre,d)
{
	var dt=document.getElementById(pre+"_t"+d);
	var dto=document.getElementById(pre+"_t"+eval(pre+"_on+0"));
	var dc=document.getElementById(pre+"_c"+d);
	var dco=document.getElementById(pre+"_c"+eval(pre+"_on+0"));
	if(dt && dto)
	{
		dto.className=cre+"_off";
		dt.className=cre+"_on";			
		dco.style.display="none";
		dc.style.display="block";			
		eval(pre+"_on="+d);
	}
}

function tab_init(pre,cre)
{
	var i;
	var dt,dc
	for(i=1;i<=eval(pre+"_num+0");i++) {
	    dt = document.getElementById(pre + "_t" + i);
	    dc = document.getElementById(pre + "_c" + i);
		if(!dt)
		{alert(pre+"_t"+i+" error!");return;}
		if(!dc)
		{ alert(pre + "_c" + i + " error!"); return; }
		//dt.onClick = function() { tab_chg(pre, cre, i) };
		if(eval(pre+"_on+0")==i)
		{
		    dt.className = cre + "_on";
			dc.style.display="block";
		}
		else
		{
			dt.className=cre+"_off";			
			dc.style.display="none";
		}
	}
}
//ProjectWork

function pageLink()
{
	jj("a").each(
		function()
		{
			var linkobj=jj(this);
			if(linkobj.attr("title")=="" || CheckObj(linkobj.attr("title"))==false)
			{
			    linkobj=linkobj.html();
			    if(linkobj.indexOf("script")||linkobj.indexOf("img"))
			    {return;}
			    linkobj.attr("title",linkobj.html());
			}
		}
	);
}



