/*
+--------------------------------------------------------
+	Copyright (c) 2004-2007 WeSofts
+	JavaScript Project for wespace
+	http://www.wesofts.com
+--------------------------------------------------------
*/

/*
+--------------------------------------------------------
+	Browser list
+--------------------------------------------------------
*/
var uagent    = navigator.userAgent.toLowerCase();
var is_safari = ( (uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var is_ie     = ( (uagent.indexOf('msie') != -1) && (!is_opera) && (!is_safari) && (!is_webtv) );
var is_ie4    = ( (is_ie) && (uagent.indexOf("msie 4.") != -1) );
var is_moz    = (navigator.product == 'Gecko');
var is_ns     = ( (uagent.indexOf('compatible') == -1) && (uagent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_safari) );
var is_ns4    = ( (is_ns) && (parseInt(navigator.appVersion) == 4) );
var is_opera  = (uagent.indexOf('opera') != -1);
var is_kon    = (uagent.indexOf('konqueror') != -1);
var is_webtv  = (uagent.indexOf('webtv') != -1);
var is_win    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
var is_mac    = ( (uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var ua_vers   = parseInt(navigator.appVersion);
if (typeof jslang == 'undefined'){
	var jslang = {}
}

/*
+--------------------------------------------------------
+	Get element by id as simple style
+--------------------------------------------------------
*/
function $(id){
	if (document.getElementById(id)){
		return document.getElementById(id);
	}else{
		return false;
	}
}

/*
+--------------------------------------------------------
+	Get element by tagname
+--------------------------------------------------------
*/
function getags(name){
	if (document.getElementsByTagName(name)){
		return document.getElementsByTagName(name);
	}else{
		var ruturns = new Array();
		return returns;
	}
}

/*
+--------------------------------------------------------
+	Check all checkbox
+--------------------------------------------------------
*/
var checkedall = false;
function checkall(fname){
	var boxform = eval('document.' + fname);
	if (!boxform){
		alert('Error: ' + fname);
	}
	checkedall = checkedall ? false :true;
	for (var i=0;i<boxform.elements.length;i++){
		if (boxform.elements[i].type == 'checkbox'){
			var checkname = boxform.elements[i].name;
			if (checkname.substr(checkname.length-2,2) == '[]'){
				boxform.elements[i].checked = checkedall ? true : false;
			}
		}
	}
}

/*
+--------------------------------------------------------
+	Marquee group
+--------------------------------------------------------
*/
function myscroller(){
	this.speeder = 1;
	this.dheight = 20;
	this.seconds = 3000;
	this.movetyper = new Array();
	this.moveheights = new Array();
	this.screenheights = new Array();
	this.scrollerheight = new Array();
	this.screenaccesses = new Array();
	this.processer = new Array();
	this.up = function(id,mh,sh,rer){
		if (!$(id)){
			return false;
		}
		this.tmperid = id + '_scroller';
		if (!$(this.tmperid)){
			this.movetyper[id] = 'up';
			this.moveheights[id] = mh ? mh : this.dheight;
			this.screenheights[id] = sh ? sh : this.moveheights[id];
			this.appender(id);
			this.scrollerheight[id] = $(this.tmperid).scrollHeight
			this.screenaccesses[id] = true;
			this.processer[id] = setTimeout('marqueer.up("' + id + '")',this.seconds);
		}else{
			if (!this.screenaccesses[id]){
				return false;
			}
			this.tmptop = $(this.tmperid).scrollTop;
			if (rer){
				$(this.tmperid).scrollTop = 0;
				this.processer[id] = setTimeout('marqueer.up("' + id + '")',this.seconds);
			}else if (this.tmptop >= this.scrollerheight[id] - this.screenheights[id]){
				this.processer[id] = setTimeout('marqueer.up("' + id + '","","","true")',this.seconds);
			}else{
				this.tmptop += 1;
				$(this.tmperid).scrollTop = this.tmptop;
				if (this.tmptop % this.moveheights[id] == 0){
					this.processer[id] = setTimeout('marqueer.up("' + id + '")',this.seconds);
				}else{
					this.processer[id] = setTimeout('marqueer.up("' + id + '")',this.speeder);
				}
			}
		}
	}
	this.stoper = function(id){
		this.screenaccesses[id] = false;
		clearTimeout(this.processer[id]);
		this.processer[id] = null;
	}
	this.starter = function(id){
		this.screenaccesses[id] = true;
		this.processer[id] = setTimeout('marqueer.up("' + id + '")',this.speeder);
	}
	this.appender = function(id){
		this.tmperid = id + '_scroller';
		this.tmperhtml = $(id).innerHTML;	$(id).innerHTML = '';
		this.appended = document.createElement('div');
		this.appended.setAttribute('id',this.tmperid);
		$(id).appendChild(this.appended);
		$(this.tmperid).innerHTML = this.tmperhtml;
		$(this.tmperid).style.overflow = 'hidden';
		$(this.tmperid).style.height = this.screenheights[id] + 'px';
	}
}
marqueer = new myscroller();

/*
+--------------------------------------------------------
+	Browser history
+--------------------------------------------------------
*/
function history_object(){
	this.historys = new Array();
	this.create = function(handler,opt,ext){
		this.historyid = 0;
		this.historytmps = new Array();
		for (var i = 0; i < this.historys.length; i++){
			if (this.historys[i]){
				this.historytmps[this.historyid] = this.historys[i];
				this.historyid++;
			}
		}
		this.historytmps[this.historyid] = handler + ',' + opt + ',' + ext;
		this.historys = this.historytmps;
	}
	this.backer = function(){
		for (var i = 0; i < this.historys.length; i++){
			if (this.historys[i]){
				//alert(this.historys[i]);
			}
		}
	}
}
ajaxhistory = new history_object();

/*
+--------------------------------------------------------
+	Leave Page alerm
+--------------------------------------------------------
*/
if (typeof page_leave_active == 'undefined'){
	var page_leave_active = false;
}
function CreateEvent(object,type,fn){ 
	if (object.attachEvent){ 
		object['e' + type + fn] = fn;
		object[type + fn] = function(){
			object['e' + type + fn](window.event);
		} 
		object.attachEvent('on' + type,object[type + fn]); 
	}else{
		object.addEventListener(type,fn,false); 
	}
}
CreateEvent(
	window,
	'beforeunload',
	function(event){
		/*ajaxhistory.backer();
		*/
		if (page_leave_active){
			if (typeof jslang == 'undefined' || typeof jslang.page_leave_active == 'undefined'){
				var msger = ' ';
			}else{
				var msger = jslang.page_leave_active;
			}
			event.returnValue = msger;
		}
	}
);