
window.onload = function () {
	new ScrollText("scrollDIV").init();
	new showPicture().next();
	new DateFunction('_botton_date_span').start();;
};

function $E(id){
	return document.getElementById(id);
}

function ScrollText(elementID) {
	this.scrollEle = document.getElementById(elementID);
	this.scrollDIVclientHeight = this.scrollEle.clientHeight;
	this.scrollDIVscrollHeight = this.scrollEle.scrollHeight;
	this.html = this.scrollEle.innerHTML;
	this.scrollFlag = true;
	this.top = 0;
	var obj = this;
	this.scrollEle.onmouseover = function () {
		obj.scrollFlag = false;
	};
	this.scrollEle.onmouseout = function () {
		obj.scrollFlag = true;
	};
	this.scroll = function () {
		if (!this.scrollFlag) {
			return;
		}
		this.top += 1;
		this.scrollEle.scrollTop = this.top;
		if (this.top > this.scrollDIVscrollHeight) {
			this.top = 0;
		}
	};
	this.init = function () {
		this.build();
		var o = this;
		function m() {
			o.scroll();
		}
		window.setInterval(m, 100);
	};
	this.build = function () {
		var newHtml = "<table   border='0'   cellspacing='0'   cellpadding='0'   width='100%'>\n";
		newHtml += "     <tr>\n";
		newHtml += "         <td   height='" + this.scrollDIVclientHeight + "'   valign='top'>\n";
		newHtml += this.html + "\n";
		newHtml += "         </td>\n";
		newHtml += "     </tr>\n";
		newHtml += "     <tr>\n";
		newHtml += "         <td   height='" + this.scrollDIVclientHeight + "'   valign='top'>\n";
		newHtml += this.html + "\n";
		newHtml += "         </td>\n";
		newHtml += "     </tr>\n";
		newHtml += "</table>\n";
		this.scrollEle.innerHTML = newHtml;
	};
}
function showPicture() {
	this.index = 0;
	this.hrefObj = document.getElementById("image_url");
	this.imgObj = document.getElementById("image_picture");
	this.plength = cs.length;
	this.next = function () {
		if(this.plength<=0){
			return;
		}
		if (this.index >= this.plength) {
			this.index = 0;
		}
		var obj = cs[this.index];
		this.hrefObj.href = obj.url;
		this.imgObj.src = obj.picture;
		this.imgObj.alt = obj.name;
		this.index += 1;
		var o = this;
		function f() {
			o.next();
		}
		setTimeout(f, 3 * 1000);
	};
}

function getAbsoluteLocationEx(element) {
	if (arguments.length != 1 || element == null) {
		return null;
	}
	var elmt = element;
	var offsetTop = elmt.offsetTop;
	var offsetLeft = elmt.offsetLeft;
	var offsetWidth = elmt.offsetWidth;
	var offsetHeight = elmt.offsetHeight;
	while (elmt = elmt.offsetParent) { 
		if (elmt.style.position == "absolute" || elmt.style.position == "relative" || (elmt.style.overflow != "visible" && elmt.style.overflow != "")) {
			break;
		}
		offsetTop += elmt.offsetTop;
		offsetLeft += elmt.offsetLeft;
	}
	return {absoluteTop :offsetTop, absoluteLeft :offsetLeft, offsetWidth :offsetWidth, offsetHeight :offsetHeight};
}

var autoScroll = false;

function showDIV(id,base,iid,color){
	var falg = true;
	var div = document.getElementById('wise_intro_iframe');
	if(!div.style.display || div.style.display=="" || div.style.display=="block"){
		return true;
	}
	var frame = document.getElementById('wise_intro_iframe');
	if(autoScroll) {
		frame.style.height = "0px";
	}
	//顯示等待信息
	//window.frames['wise_intro_iframe'].document.writeln('<div style="background-color: red;">Loading....</div>');
	var src = base+'/introduce/introduce.jspx?id='+iid;
	if(color){
		src +='&color='+color
	}
	frame.src= src;
	var rec= getAbsoluteLocationEx(id);
    div.style.left = rec.absoluteLeft;
    div.style.top = rec.absoluteTop;
    div.style.display = "";
    document.body.onclick = function(){
	    if(falg){
	    	falg = false;
	    }else{
	    	div.style.display = "none";
	    	document.body.onclick = null;
	    }
    }
}

function closeDIV(){
	var frame = document.getElementById('wise_intro_iframe');
	frame.style.display = "none";
	document.body.onclick = null;
} 

function DateFunction(span){
	var span = document.getElementById(span);
	this.changTime = function(){
		var d =new Date();
		var s = formatDate(d,"yyyy/MM/dd a HH:mm:ss");
		span.innerHTML = s;
	}
	this.start = function(){
		window.setInterval(this.changTime, 250);
	}
}

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function LZ(x) {return(x<0||x>9?"":"0")+x}
// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
}
	
function changeFont(font ){
	var fontspan = document.getElementById("contentfont");
	if(font == "big"){
		fontspan.style.fontSize="14";
	}
	if(font == "middle"){
		fontspan.style.fontSize="12";
	}
	if(font == "small"){
		fontspan.style.fontSize="10";
	}
}  

function changeFontSize(font ){
	var table = $E("contentTable");
	var tdfontSize = "12";
	if(font == "big"){
		tdfontSize="14";
	}
	if(font == "middle"){
		tdfontSize="12";
	}
	if(font == "small"){
		tdfontSize="10";
	}
	var cta = $E("contentTextArea");
	if(cta){
		cta.style.fontSize = tdfontSize;
	}
	var cta2 = $E("contentTextArea2");
	if(cta2){
		cta2.style.fontSize = tdfontSize;
	}
	for(var index=0; index<table.rows.length-1; index++) {
		var row = table.rows[index];
		var cells = row.cells;
		if(cells[0]){
			cells[0].style.fontSize = tdfontSize;
		}
		if(cells[1]){
			cells[1].style.fontSize = tdfontSize;
		}
	}
}

function changeAssetFontSize(font ){
	var table = $E("contentTable");
	var tdfontSize = "12";
	if(font == "big"){
		tdfontSize="14";
	}
	if(font == "middle"){
		tdfontSize="12";
	}
	if(font == "small"){
		tdfontSize="10";
	}
	var cta = $E("contentTextArea");
	if(cta){
		cta.style.fontSize = tdfontSize;
	}
	var cta2 = $E("contentTextArea2");
	if(cta2){
		cta2.style.fontSize = tdfontSize;
	}
	for(var index=0; index<table.rows.length; index++) {
		var row = table.rows[index];
		var cells = row.cells;
		if(cells[0]){
			cells[0].style.fontSize = tdfontSize;
		}
		if(cells[1]){
			cells[1].style.fontSize = tdfontSize;
		}
	}
}

function wikiSearch(){
	var form = $E("wikisearch");
    form['search'].value = $E('searchValueInput').value;
	var ifr = $E("searchIframe");
	if(!ifr){
	 	var iframe = '<iframe name="searchIframe"  height="780" width="100%" id="searchIframe" frameborder="0" style="top:0px;"></iframe>';
	 	$E("contentDIV").innerHTML = iframe;
 	}
 	ifr = $E("searchIframe");
 	var sform = $E("wikisearch");
 	sform.target = "searchIframe";
 	sform.submit();
}

function googleSearch(){
	var ifr = $E("searchIframe");
	if(!ifr){
	 	var iframe = '<iframe name="searchIframe"  height="780" width="100%" id="searchIframe" frameborder="0" style="top:0px;"></iframe>';
	 	$E("contentDIV").innerHTML = iframe;
 	}
 	ifr = $E("searchIframe");
 	var sform = $E("searchForm");
 	sform.action="http://www.google.com/search";
 	sform.target = "searchIframe";
 	$E("googleSeachInput").value = $E("searchValueInput").value;
 	sform.submit();
}

function checkEmai4(value){
	var reVal = new RegExp("^[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+@[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+(\.[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+)+$","i");
	return reVal.test(value);
}
function checkEmail3(value){
	if(!value)return false;
	if(value.length!=0) {
		if (value.charAt(0)=="." || 
				value.charAt(0)=="@"|| 
				value.indexOf('@', 0) == -1 || 
				value.indexOf('.', 0) == -1 || 
				value.lastIndexOf("@")== value.length-1 || 
				value.lastIndexOf(".")== value.length-1){
			return false;
		}
		if(!checkEmai4(value)){
			return false;
		}
	}else{
		return false;
	}
	return true;
}
