var Class = {
  create: function() {
    return function() {
      this.init.apply(this, arguments);
    }
  }
}

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 i in a)
this[this.length] = i;
return this;
}

String.prototype.trim = function()   
{
return this.replace(/(^\s*)|(\s*$)/g,"");   
}

function CheckObj(obj)
{
    if(!obj)return false;
    if(obj===undefined)return false;
    if(obj==null)return false;
    return true;    
}

function $e(id)
{
	try
	{
		return 	$('#'+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 JsLoader(){
  this.load=function(url){
  var ss=document.getElementsByTagName("script");  
  for(i=0;i<ss.length;i++)
  {   
    if(ss[i].src && ss[i].src.indexOf(url)!=-1)
    {   
      this.onsuccess(); 
      return;   
    }
  }
  s=document.createElement("script");  
  s.src=url.replace("&amp;","&");
  
  var head=document.getElementsByTagName("head")[0];  
  head.appendChild(s);
  var self=this;
  s.onload=s.onreadystatechange=function()
  {   
  if(this.readyState && this.readyState=="loading")
    return;   
    self.onsuccess();  
  }
  s.onerror=function(){
  head.removeChild(s);   
  self.onfailure();  } 
  };
  this.onsuccess=function(){}; 
  this.onfailure=function(){};
}
  
function LoadJs(jspath,onsu,onfa)
{
var jl=new JsLoader();
if(onsu!=null)jl.onsuccess=onsu;
if(onfa!=null)jl.onfailure=onfa;
jl.load(unescape(jspath));
}

function CPos(x, y)
{
    this.x = x;
    this.y = y;
}

function GetObjPos(ATarget)
{
    var target = ATarget;
    var pos = new CPos(target.offsetLeft, target.offsetTop);
    
    var 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){// all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var pageWidth,pageHeight,windowWidth,windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		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=$(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_"+$(areaid).id+"=window.setInterval(\"PageADTimerClose('"+$(areaid).id+"')\",sc*1000);");
}
function PageADTimerClose(areaid)
{
	$(areaid).style.display='none';
	window.clearInterval(window.eval("ADTimer_"+$(areaid).id));
}

function PageFlashNews(areaid,tempjs)
{
	eval(tempjs);
	var obj=$e(areaid);
	var objid=obj.id;
	obj.innerHTML='';
	var fns="";
	var swf_width=180;
	var swf_height=155;
	var files=tempfile;
	var links=templink;
	var texts=temptext;
	
	fns+=('<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="'+ swf_width +'" height="'+ swf_height +'">');
	fns+=('<param name="movie" value="/images/flashnews.swf"><param name="quality" value="high">');
	fns+=('<param name="menu" value="false"><param name=wmode value="opaque"><param name=AutoPlayTime value="3">');
	fns+=('<param name="FlashVars" value="bcastr_file='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'">');
	fns+=('<embed src="http://www.ruochi.com/product/bcastr3/bcastr3.swf" wmode="opaque" FlashVars="bcastr_file='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'& menu="false" quality="high" width="'+ swf_width +'" height="'+ swf_height +'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	fns+=('</object>'); 	
	$e(areaid).innerHTML=fns;
}

function PnFlashNews(areaid,tempjs,nwidth,nheight,ntitle)
{
	try{eval(tempjs);}
	catch(ex){$(areaid).innerHTML='';return false;}
	var so = new SWFObject("/images/focus.swf", "nPageFlashNews", nwidth, nheight, "7", "#ffffff");
	so.addParam('wmode','transparent');
	so.addVariable("picurl",tempfile);
	so.addVariable("pictext",temptext);
	so.addVariable("piclink",templink);
	so.addVariable("pictime","5");
	so.addVariable("borderwidth",nwidth);
	so.addVariable("borderheight",nheight);
	so.addVariable("borderw","false");
	so.addVariable("buttondisplay","true");
	so.addVariable("textheight",ntitle);
	so.write(areaid);
}

var LoadShowImg=true;
var LoadShowImgUrl="/images/page_loading.gif";

$.ajaxSetup({global: false,type:"GET",async:false});

function LoadInfo(info,oncomplated)
{
	var objid="LoadPart_"+GetRandomNum(1000000);
	var objurl = "/getjs/getinfojs.aspx?area="+GetRandomNum(1000000)+"&info="+escape(info);
	if(LoadShowImg)
		document.write("<div id=\""+objid+"\"><img border=0 src="+LoadShowImgUrl+"></div>");
	else
		document.write("<div id=\""+objid+"\"></div>");
	var LoadPartJs_request;
	if(oncomplated)
	{
		$.ajax({url:objurl,success:function(rpt){$('#'+objid).html('');oncomplated(objid,rpt)}});
	}
	else
	{
		$('#'+objid).load(objurl);
	}
}


function LoadPart(name,oncomplated)
{
	var objid="LoadPart_"+GetRandomNum(1000000);
	var objurl = "/getjs/getpartjs.aspx?area="+GetRandomNum(1000000)+"&part="+name;
	if(LoadShowImg)
		document.write("<div id=\""+objid+"\"><img border=0 src="+LoadShowImgUrl+"></div>");
	else
		document.write("<div id=\""+objid+"\"></div>");
	var LoadPartJs_request;
	if(oncomplated)
	{
		$.ajax({url:objurl,success:function(rpt){$('#'+objid).html('');oncomplated(objid,rpt)}});
	}
	else
	{
		$('#'+objid).load(objurl);
	}
}

function LoadUc(path,oncomplated)
{
	var objid="LoadUc_"+GetRandomNum(1000000);
	var objurl = "/getjs/getucjs.aspx?area="+GetRandomNum(1000000)+"&file="+path;
	if(LoadShowImg)
		document.write("<div id=\""+objid+"\"><img border=0 src="+LoadShowImgUrl+"></div>");
	else
		document.write("<div id=\""+objid+"\"></div>");
	if(oncomplated)
	{
		$.ajax({url:objurl,success:function(rpt){$('#'+objid).html('');oncomplated(objid,rpt)}});
	}
	else
	{
		$('#'+objid).load(objurl);
	}
}

function LoadPage(path)
{
	var objid="LoadPage_"+GetRandomNum(1000000);
	document.write("<div id=\""+objid+"\"></div>");
	$('#'+objurl).load(path);
}

function fillImg(img,w,h,fill)
{
	try
	{
        var imageArr=img;
        var maxWidth=w;
        var maxHeight=h;
	    imageArr.style.display="";
        var imageRate = imageArr.offsetWidth / imageArr.offsetHeight;    
        
    	
        if(imageArr.offsetWidth > maxWidth)
        {
            imageArr.style.width=maxWidth + "px";
            imageArr.style.Height=maxWidth / imageRate + "px";
        }
	    else
	    {
		    if(fill==0)
		    {
			    imageArr.style.width=maxWidth + "px";
			    imageArr.style.Height=maxWidth / imageRate + "px";		
		    }
	    }
        
        if(imageArr.offsetHeight > maxHeight)
        {
            imageArr.style.width = maxHeight * imageRate + "px";
            imageArr.style.Height = maxHeight + "px";
        }
	    else
	    {
		    if(fill==1)
		    {
			    imageArr.style.width = maxHeight * imageRate + "px";
			    imageArr.style.Height = maxHeight + "px";
		    }
	    }
	}
	catch(ex)
	{
	    $(img).css("display","none");
	}
}

function autoImg(img,w,h)
{
    var imageArr=img;
    var maxWidth=w;
    var maxHeight=h;
	imageArr.style.display="";
    var imageRate = imageArr.offsetWidth / imageArr.offsetHeight;    
    
    if(imageArr.offsetWidth > maxWidth)
    {
        imageArr.style.width=maxWidth + "px";
        imageArr.style.Height=maxWidth / imageRate + "px";
    }
    
    if(imageArr.offsetHeight > maxHeight)
    {
        imageArr.style.width = maxHeight * imageRate + "px";
        imageArr.style.Height = maxHeight + "px";
    }
	if(!CheckObj($(img).parent().attr("href")) || $(img).parent().attr("href")=="")
	{
		img.style.cursor='hand';
		img.alt='点击查看大图';
		img.onclick=Function("window.oper=null;window.open(this.src)");
	}
}
FixImgWidth=autoImg

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>");
}

var site_url="http://www.unihotel.com/";
var site_name="广西酒店联盟";
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 startchat()
{
	openZoosUrl('chatwin');
	return false;
}

function fixContentImg(objname)
{
	var imgObj;
	var contentObj=document.getElementById(objname);
	if(contentObj) fixContentImgDo(contentObj);	
}

function fixContentImgDo(cobj)
{
	var imgObj;
	var contentObj=cobj
	for(i = 0; i < contentObj.childNodes.length; i++)
	{
		imgObj = contentObj.childNodes[i];
		if(imgObj.hasChildNodes())fixContentImgDo(imgObj);
		if(!imgObj)continue;
		if(!imgObj.tagName)continue;
		if(imgObj.tagName.toLowerCase()=="img")
		{
			if (imgObj.width >500)
			{ 
				autoImg(imgObj,500,1000);
				imgObj.style.cursor='hand';
				imgObj.alt='点击查看大图';
				imgObj.onclick=Function("window.oper=null;window.open(this.src)");
			} 
		}
	}	
}

fontobj="fontset";
function setfontas(obj,size)
{
	$('#'+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');	
}

//ProjectWork
var linkobj=0;
function pageLink()
{
	if(linkobj!=0)
	{
		window.clearTimeout(linkobj)
	}
	$("a").each(
		function()
		{
			linkobj=$(this);
			if(linkobj.attr("title")=="" || CheckObj(linkobj.attr("title"))==false)
			{
			    linkobj.attr("title",linkobj.html());
			}
		}
	);
}

function $pageinit()
{
	var pagesize=getPageSize();
	window.pageWidth=pagesize[0];
	window.pageHeight=pagesize[1];
	window.windowWidth=pagesize[2];
	window.windowHeight=pagesize[3];

	linkobj=window.setTimeout(pageLink,5000)
}
$(document).ready(function(){$pageinit()});
