var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

function getKey(keyStroke) {
	isNetscape=(document.layers);
	eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
	which = String.fromCharCode(eventChooser).toLowerCase();
	which2 = eventChooser;

	var el=event.srcElement;

	if ((el.tagName != "INPUT") && (el.tagName != "TEXTAREA")) {
		if(which == "+" || which == "=")
			zoomInOut('in');
		else if(which == "-" || which == "_")
			zoomInOut('out');
	}
}

var zoomRate = 5;
var maxRate = 150;
var minRate = 100;

function getObject(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}

function zoomInOut(how) {
	var curRate = 100;
	var saveRate = pms_GetCookie("zoomVal");
	if(saveRate != "" && saveRate != null)
		curRate = parseInt(saveRate);

	if(how == "in")
		curRate -= zoomRate;
	else
		curRate += zoomRate;
	if (curRate > maxRate || curRate < minRate) {
		return;
	}
	var obj = getObject("wrapper") == null ? getObject("wrap") : getObject("wrapper");
	obj.style.zoom = curRate+'%'
	pms_SetCookie("zoomVal", curRate, 1);
}

function SetCookie( name, value, expiredays ) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" ;
}

function GetCookie( name ){
    var nameOfCookie = name + "=";
    var x = 0;
    while ( x <= document.cookie.length ) {
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie )  {
	        if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
				endOfCookie = document.cookie.length;
	        return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		x = document.cookie.indexOf( " ", x ) + 1;

		if ( x == 0 )  break;
    }
    return "";
}

function pms_GetCookie( name ) {
	var key = name + "=";
	var key_len = key.length;
	var cookie_len = document.cookie.length;

	var i = 0;
	while ( i <= cookie_len ){
		var j = i + key_len;
		if ( document.cookie.substring( i, j ) == key ){
			var cookie_end = document.cookie.indexOf( ";", j );
			if ( cookie_end == -1 )
				cookie_end = document.cookie.length;
			return unescape( document.cookie.substring( j, cookie_end ) );
		}
		i = document.cookie.indexOf( " ", i ) + 1;

		if ( i == 0 )  break;
	}
	return "";
}

function pms_SetCookie( key, value, term ){
	if ( term >= 0){
		var expire = new Date();
		expire.setDate( expire.getDate() + term );
		document.cookie = key + "=" + escape( value ) + "; path=/; expires=" + expire.toGMTString() + ";";
		return;
	}
	document.cookie = key + "=" + escape( value ) + "; path=/;";
}

//********************************************************
// DOCUMENT Color
//********************************************************
var fgColorIndex = null;
var bgColorIndex = null;

function getSiteDefaultColor(sitecdv) {
	fgColorIndex = pms_GetCookie("fgColorIndex" + sitecdv);
	if(fgColorIndex == null || fgColorIndex == "")
		fgColorIndex = "";
	bgColorIndex = pms_GetCookie("bgColorIndex" + sitecdv);
	if(bgColorIndex == null || bgColorIndex == "")
		bgColorIndex = "";
}

//********************************************************
//font color
//********************************************************/
function changeFontColor(val, sitecdv){
	if(sitecdv == undefined)
		sitecdv = "";
	fgColorIndex = val;
	document.body.style.color = fgColorIndex;
	var nodes = document.getElementsByTagName("div");
	for(var i = 0; i < nodes.length; i++) {
		nodes[i].style.color = fgColorIndex;
	}
	nodes = document.getElementsByTagName("a");
	for(var i = 0; i < nodes.length; i++) {
		nodes[i].style.color = fgColorIndex;
	}
	pms_SetCookie("fgColorIndex" + sitecdv, fgColorIndex, 365);		//Font Color Save
}

//********************************************************
//Background color
//********************************************************/

function changeBgColor(val, sitecdv){
	if(sitecdv == undefined)
		sitecdv = "";
	bgColorIndex = val;
	document.body.bgColor  = bgColorIndex;
	var nodes = document.getElementsByTagName("div");
	for(var i = 0; i < nodes.length; i++) {
		nodes[i].style.bgColor = bgColorIndex;
	}
	pms_SetCookie("bgColorIndex" + sitecdv, bgColorIndex, 365);		//Font Color Save
}
