//---------------------------------------------------
//Author: kaichun
//Last Update: 2005Äê5ÔÂ31ÈÕ 20:44:19
//---------------------------------------------------


function setActiveStyleSheet(title){
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	document.getElementById("logo").src="styles/"+title+"/images/logo.gif";
}

function getActiveStyleSheet(){
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet(){
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title"))
			return a.getAttribute("title");
	}
	return null;
}

function createCookie(nm,val,y){
	var exp="";
	if(y){ 
		var dt=new Date(); 
		dt.setTime(dt.getTime()+(y*86400000)); 
		exp="; expires="+dt.toGMTString();
	} 
	document.cookie=nm+"="+escape(val)+exp+";path=/"; 
}

function readCookie(nm){ 
	var m; 
	if(window.RegExp){ 
		var re=new RegExp(";\\s*"+nm+"=([^;]*)","i"); 
		m=re.exec(';'+document.cookie); 
	} 
	return(m?unescape(m[1]):"");
}

window.onload = function(e){
	var cookie = readCookie("styles");
	var title = cookie ? cookie : getPreferredStyleSheet();
	var styleList=document.getElementById("stylelist");
	var flag=true;
	if(styleList){
		for(var i=0;i<styleList.options.length;i++){
			if(title==styleList.options[i].value){
				flag=false;
			}
		}
		if(flag){
			title=styleList.options[0].value;
		}
		styleList.value=title;
	}
	setActiveStyleSheet(title);
}

window.onunload = function(e){
	var title = getActiveStyleSheet();
	createCookie("styles", title, 365);
}

function init(){
	var cookie = readCookie("styles");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}