//------------------ cookie javascript
function getCookie( name ) { 
    var start = document.cookie.indexOf( name + "=" ); 
    var len = start + name.length + 1; 
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { 
        return null; 
    } 
    if ( start == -1 ) return null; 
    var end = document.cookie.indexOf( ';', len ); 
    if ( end == -1 ) end = document.cookie.length; 
    return unescape( document.cookie.substring( len, end ) ); 
} 
 
function setCookie( name, value, expires, path, domain, secure ) { 
    var today = new Date(); 
    today.setTime( today.getTime() ); 
    if (expires) { 
        expires = expires * 1000 * 60 * 60 * 24; 
    } 
    var expires_date = new Date( today.getTime() + (expires) ); 
    document.cookie = name+'='+escape( value ) + 
        ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString() 
        ( ( path ) ? ';path=' + path : '' ) + 
        ( ( domain ) ? ';domain=' + domain : '' ) + 
        ( ( secure ) ? ';secure' : '' ); 
} 
 
function deleteCookie( name, path, domain ) { 
    if ( getCookie( name ) ) document.cookie = name + '=' + 
            ( ( path ) ? ';path=' + path : '') + 
            ( ( domain ) ? ';domain=' + domain : '' ) + 
            ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; 
} 
 
 /*-----------------------------------------------------------------------------------*\
  * shawl.qiu Javascript FixBox class v1.0
 \*-----------------------------------------------------------------------------------*/
	//---------------------------------begin class FixBox()-------------------------------//
 function FixBox()
 { // shawl.qiu code
  //------------------------------------begin public variable
  //---------------begin about
		this.au = {}
		this.au.Subject = "shawl.qiu Javascript FixBox class ";
		this.au.Version = "v1.0";
		this.au.Name = "shawl.qiu";
		this.au.Email = "shawl.qiu@gmail.com";
		this.au.Blog = "http://blog.csdn.net/btbtd";
		this.au.CreatedDate = "2007-5-26";
		this.au.Update = {};
		this.au.Update["1"] = "";
  //---------------end about
		this.Debug = false;
		
		this.Body = null; // string text || string id || object element
		
		this.ID = null;
		this.Prefix = "asdfasg";
		this.Postfix = "qqqppppasdfasdfakjsdf";
		
		this.Size = {}
		this.Size.Width = null;
		this.Size.Height = null;
		this.Size.Left = null;
		this.Size.Top = null;
		
		this.Class = {};
		this.Class.Name = "FixBoxClassName";

		this.Closer = {}
		this.Closer.InnerHtml = "<img src='/images/icon_close.gif' alt='close' />";
		this.Closer.Msg = "close";
		this.Closer.ClassName = "FixBoxCloserClassName";
		
		this.Style = {}
		
		this.Style.Main = {}
		this.Style.Main.Border = "1px solid gainsboro";
		this.Style.Main.Padding = "5px";
		this.Style.Main.Overflow = "auto";
		this.Style.Main.VerticalAlign = "middle";
		this.Style.Main.TextAlign = "left";
		this.Style.Main.Addition = "background:#ffffff";
		
		this.Style.Closer = {}
		//this.Style.Closer.Border = "1px solid black";
		this.Style.Closer.Padding = "2px 0px 0px 3px";
		this.Style.Closer.Addition = "width:auto;cursor:pointer;float:right";
  //------------------------------------end public variable
  
  //------------------------------------begin private variable
  var Tl = this;
		var pMain = null;
		var pClassName = null;
		var pCloserClassName = null;
  //------------------------------------end private variable
  
  //------------------------------------begin public method
  this.Go = fGo;
		this.SetPosition = fSetPosition;
  //------------------------------------end public method
 
  //------------------------------------begin private method
  function fGo()
  {
			if(typeof(Tl.Body)=="object")
			{
			 if(Tl.Body.id=="")Tl.ID = Tl.Prefix+fRandomLetter(10);
			} // end if
			
   if(typeof(Tl.Body)=="string")
			{
				var TempObj = document.getElementById(Tl.Body);
				if(TempObj!=null)
				{
					Tl.ID = Tl.Body;
					Tl.Body = TempObj;
				}
				else
				{
					Tl.ID = Tl.Prefix+fRandomLetter(10);
					
					var EleDiv = document.createElement("div");
	 				EleDiv.id = Tl.ID;
						EleDiv.innerHTML = Tl.Body;
			 		document.body.appendChild(EleDiv);
					
					Tl.Body = document.getElementById(Tl.ID);
				}
			} // end if
			
			if(Tl.Body!=null)pMain = Tl.Body;
			
			pClassName = Tl.Body.id+Tl.Class.Name;
			pCloserClassName = Tl.Body.id+Tl.Closer.ClassName;
			
			fAppendCss();
			
			var arViewport = fGetViewPortSize();
			
			if(!Tl.Size.Width) Tl.Size.Width = Math.ceil(arViewport[0]/3);
			if(!Tl.Size.Height) Tl.Size.Height = Math.ceil(arViewport[1]/3);
			
			if(typeof(Tl.Size.Left)!="number") Tl.Size.Left = (arViewport[0]-Tl.Size.Width)/2;
			if(typeof(Tl.Size.Top)!="number") Tl.Size.Top = (arViewport[1]-Tl.Size.Height)/2;
			
			if(Tl.Debug)
			{
			 defaultStatus =
				""
				+" Tl.Size.Width: "+Tl.Size.Width
				+" Tl.Size.Height: "+Tl.Size.Height
				+" Tl.Size.Left: "+Tl.Size.Left
				+" Tl.Size.Top: "+Tl.Size.Top
				;
			}
			
			pMain.className = pClassName;
		
			with(pMain.style)
			{
				if(fCkBrs()==1)
				{
					position = "absolute";
					
					try{OnScrollFunc = onscroll;} catch(e){}
					onscroll = function(){ try{OnScrollFunc();}catch(e){} fScrollForIe();}
				}
				else
				{
					position = "fixed";
				}
				width = Tl.Size.Width + "px";
				height = Tl.Size.Height + "px";
				left = Tl.Size.Left + "px";
				top = Tl.Size.Top + "px";
			} // end whith
			
			var CloserEle = document.createElement("div");
			 CloserEle.innerHTML = Tl.Closer.InnerHtml+" ";
				CloserEle.className = pCloserClassName;
				CloserEle.onclick = 
				 function()
					{
					 //var bCfm = confirm(Tl.Closer.Msg);
						//if(bCfm)
						this.parentNode.style.display = "none";
					}
				
			var TempEle = document.createElement("span");
			 TempEle.innerHTML = "&nbsp;";
				
			pMain.insertBefore(TempEle, pMain.firstChild);
			pMain.insertBefore(CloserEle, pMain.firstChild);
			
  } // end function fGo

		function fSetPosition(sX, sY, iWidth, iHeight, bDebug)
		{// shawl.qiu script
		 // sX: xleft, xcenter, xright
			// xY: ytop, ymiddle, ybottom
			var iX = iY = 0;
			
			var arViewport = fGetViewPortSize();
			
			if(iWidth===true) 
			{
			 iWidth = arViewport[0];
				if(sX=="xleft"||sX=="xcenter") iWidth-=15;
				if(fCkBrs()!=1) iWidth -= 15;
			}
			if(iHeight===true) iHeight = arViewport[1];
			
			if(!iWidth) iWidth = Math.ceil(arViewport[0]/3);
			if(!iHeight) iHeight = Math.ceil(arViewport[1]/3);
			
			switch(sX)
			{
			 case "xleft":
				 iX=0;
				 break;
					
				case "xright":
				 var iXMinus = 0;
					if(fCkBrs()==1) iXMinus = 12;
					if(fCkBrs()==2) iXMinus = 28;
					if(fCkBrs()==3) iXMinus = 28;
				 iX = arViewport[0]-iWidth-iXMinus;
				 break;
					
				default:
				 iX= (arViewport[0]-iWidth)/2;
				 break;
			}
			
			switch(sY)
			{
			 case "ytop":
				 iY=0;
				 break;
					
				case "ybottom":
				 var iXMinus = 0;
					if(fCkBrs()==1) iXMinus = 12;
					if(fCkBrs()==2) iXMinus = 12;
					if(fCkBrs()==3) iXMinus = 12;
				 iY = arViewport[1]-iHeight-iXMinus;
				 break;
					
				default: 
				 iY = (arViewport[1]-iHeight)/2;
				 break;
			}
			
			if(bDebug)
			{
				defaultStatus =
				""
				+" iX: "+iX
				+" iY "+iY
				+" iWidth: "+iWidth
				+" iHeight: "+iHeight
				;
			}
			
			fSetSize(iX, iY, iWidth, iHeight);
		} // end function fSetPosition
		
		function fSetSize(iX, iY, iWidth, iHeight)
		{
   Tl.Size.Left = iX;
			Tl.Size.Top = iY;
			
			Tl.Size.Width = iWidth;
			Tl.Size.Height = iHeight;
		}
		
  function fScrollForIe()
  {
   if(pMain!=null)
   {
	var top = (document.documentElement && document.documentElement.scrollTop)?document.documentElement.scrollTop:document.body.scrollTop;
    pMain.style.top = top + parseInt(Tl.Size.Top)+ "px"; // patch for scrollTop 2009-01-19
   }
  } // end function fScrollForIe
		
  function fCkBrs()
  {
   switch (navigator.appName)
   {
    case 'Opera': return 2;
    case 'Netscape': return 3;
    default: return 1;
   }
  } // end function fCkBrs 
		
		function fGetViewPortSize() 
		{// shawl.qiu script
			var myWidth = 0, myHeight = 0;
			if(typeof(window.innerWidth ) == 'number' ) 
			{//Non-IE
				myWidth = window.innerWidth;
				myHeight = window.innerHeight;
			} 
			else if 
			(
				document.documentElement && 
				( document.documentElement.clientWidth || document.documentElement.clientHeight ) 
				) 
			{//IE 6
				myWidth = document.documentElement.clientWidth;
				myHeight = document.documentElement.clientHeight;
			} 
			else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
			{ //IE 4
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
			return [myWidth, myHeight];
		} // end function fGetViewPortSize

  function fRandomLetter(nLen, sCase)
		{// shawl.qiu code
   var ar='';
   var arUp=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S',
    'T','U','V','W','X','Y','Z'];
   var arLw=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',
    'u','v','w','x','y','z'];
   var arDgt=[0,1,2,3,4,5,6,7,8,9];
   switch(sCase)
		 {
    case 'upper': ar=arUp; break;
    case 'lower': ar=arLw; break;
    case 'letter': ar=arUp.concat(arLw); break;
    default:ar=arUp.concat(arLw, arDgt);
   }
   if(nLen&&nLen>0)
			{
    if(!isFinite(nLen))return false;
    if(nLen<0)return false;
    var iLetter='';
     nLen=parseInt(nLen);
     for(var i=0; i<nLen; i++)
					{
      iLetter+=ar[fRandomBy(0,ar.length-1)];
     }
     return iLetter;
   }
   return ar[fRandomBy(0,ar.length-1)];
		
			function fRandomBy(under, over)
			{// shawl.qiu script
				switch(arguments.length)
				{
					case 1: return parseInt(Math.random()*under+1);
					case 2: return parseInt(Math.random()*(over-under+1) + under);
					default: return 0;
				} // end switch
			} // end function fRandomBy
  } // end function fRandomLetter
		
	 function fAppendCss()
		{
		 var sStyleId = Tl.Body.id+Tl.Postfix;
   var sStyle = 
			""
			+"."+pClassName
			+"{"
			+" border:"+Tl.Style.Main.Border+";"
			+" padding:"+Tl.Style.Main.Padding+";"
			+" overflow:"+Tl.Style.Main.Overflow+";"
			+" vertical-align:"+Tl.Style.Main.VerticalAlign+";"
			+" text-align:"+Tl.Style.Main.TextAlign+";"
			+Tl.Style.Main.Addition
			+"}"
			+""
			+"."+pCloserClassName
			+"{"
			+" border:"+Tl.Style.Closer.Border+";"
			+" padding:"+Tl.Style.Closer.Padding+";"
			+Tl.Style.Closer.Addition
			+"}"
			;
			fAddStyleFromStr(sStyle, sStyleId);
		} // end function fAppendCss
		
  function fAddStyleFromStr(sIpt, sId)
  {// shawl.qiu script 
   var EleStyle = document.createElement("style");
   EleStyle.type = "text/css";
   if(sId&&sId!="")
   {
    EleStyle.id = sId;
   }
   if(fCkBrs()==1)
   {
    EleStyle.styleSheet.cssText = sIpt;
   }
   else
   {
    EleStyle.innerHTML = sIpt;
   }
   function fCkBrs()
   {
    switch (navigator.appName)
    {
     case 'Opera': return 2;
     case 'Netscape': return 3;
     default: return 1;
    }
   } // end function fCkBrs 
   var EleHead=document.getElementsByTagName("head")[0]
   if(!EleHead) EleHead=document.body;
   EleHead.insertBefore(EleStyle, EleHead.firstChild); 
  } // end function fAddStyleFromStr
  //------------------------------------end private method
 } // shawl.qiu code
	//---------------------------------end class FixBox()---------------------------------//

// var fixbox = new FixBox();