// JavaScript Document

// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours, domain)
{
  var expire = "";
  var sDomain = "";
  
  if(domain){
	  sDomain +="; path=/"+"; Domain="+domain;
  }
  
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire+sDomain;
}

// Example:
// alert( readCookie("myCookie") ); 
function readCookie(name){
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function SelectStyle(name){
 var strstyle="";
 var stylecook = readCookie("BBSSTYLE");
 if(name=="title"&&(stylecook=="blueS"||stylecook=="orangeS"))
	name="titlesmall";
 if(stylecook=="") stylecook="blue";
 else stylecook=stylecook.replace("S","");
 strstyle="<link href='http://www.paipai.com/css/bbs/"+stylecook+"/"+name+".css' rel='stylesheet' type='text/css'>";
 document.write(strstyle);
}

function SetTitleSortCookie(iSortType){
	var iAllMark = readCookie("allMark");
	iAllMark = iAllMark & 2; // 2 for "10" bits; set the first bit as 0;
	iAllMark = iAllMark | iSortType;
	writeCookie("allMark", iAllMark, 24*7,"paipai.com");	
}

function GetTitleSortFromCookie(){
	var iAllMark = readCookie("allMark");
	if(iAllMark == ""){
		return 1;
	}
	iAllMark = iAllMark & 1; 	
	return iAllMark;
}
