function goToPageFront(pStart){
	setTimeout(function()
{
    var query = window.location.toString(0);
	
	if (getParameter('start')==""){
	window.location.href=	query+"&start="+pStart;
	return false;
	if (query.search(/[\?]/)>-1) {
	 window.location.href = query+"&start="+pStart;
	 return false;
	 } else
	 {
	 window.location.href = query+"?start="+pStart;
	 return false;
	 }
	 
	}
	else {
		query=query.replace(/start=\d+/,'start='+pStart);
		window.location.href=query;
		return false;
	}
}, 0);
}
function mysearch(key,cid,iid,url){
	setTimeout(function(){
	if (key!=''){ 
	var patt=/[']+/g;
	key = key.replace(patt,'"');
	
	var patt1=/"([^\\"]|\\.)*"/g;
	var patt2=/\s+/g;
	key2 = key.match(patt1);
	if (key2 == null){
		key2='';
	}
	key = key.strip();
	key = key.replace(patt1,'');
	key = key.replace(patt2,',');
	
	
	url = url + '&search=' + encodeURIComponent(key)+','+encodeURIComponent(key2);
	}
	url = url +'&pId='+cid+'&iId='+iid;
 	window.location.href=url;
	}, 0);
}
function sendMsg(  email,message,url,div, loader){
	var gifLoader = (loader == undefined) ? "<img src='images/ajax-loader_small.gif'>" : loader;
	document.getElementById(div+'_error').innerHTML = gifLoader;
	if(document.getElementById('subjectName') != undefined ){
			url += '?subject='+document.getElementById('subjectName').value;
	}
	if(document.getElementById('sender') != undefined ){
			url += '&sender='+document.getElementById('sender').value;
	}
	pemail=document.getElementById(email).value;
	pmessage=document.getElementById(message).value;	
	var re = /^[A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)*[@][A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)+$/;
	
	if (!re.test(pemail)) {
		document.getElementById(div+'_error').innerHTML ="請輸入正確電郵";
		document.getElementById(email).focus();
	} else if (pmessage.strip().length<2 || pmessage.strip().length>250){
		document.getElementById(div+'_error').innerHTML ="留言限制:2-250字元!";
		document.getElementById(message).focus();
	} else {
		
		new Ajax.Request(url, {
	method: "get",
	onSuccess: function(transport) {
      var result = transport.responseText;
	  if (!result) { document.getElementById(div+'_error').innerHTML ="發送失敗!";} else {
		  document.getElementById(div).innerHTML ="發送成功!";
	  }
  	},
		parameters: { message :pmessage, email : pemail}
	});
	}
}




function goToPageFrontAjax(url, pStart, pfun, changeId){
	url = url + '&start=' + pStart;
	startRequest(url, pfun, changeId);
}

function listingPage(url, pfun, changeId, imgLoader){
	var pStart;
	var hiddens=document.getElementById(changeId).getElementsByTagName("input");
	for(var j=0;j<hiddens.length;j++){
		var hidden=hiddens[j];
		if (hidden.id=='item_start' && hidden.type=='hidden') {
		  			pStart = hidden.value;
		}
		if(hidden.id=='item_total' && hidden.type=='hidden') {
					pTotal=hidden.value;
		}
		if(hidden.id=='item_display' && hidden.type=='hidden') {
					pDisplay=hidden.value;
		}
	}
	url = url + '&start=' + pStart + '&total=' + pTotal + '&display=' + pDisplay;
	if(imgLoader == undefined){
		imgLoader = '';
	}
	var packs= changeId + '|' + encodeURIComponent(imgLoader);
	startRequest(url, pfun, packs);
}

function addNewComment(url, pfun, changeId, pStart, pTotal, pDisplay, imgLoader){
	url = url + '&start=' + pStart + '&total=' + pTotal + '&display=' + pDisplay;
	var packs= changeId + '|' + encodeURIComponent(imgLoader);
	startRequest(url, pfun, packs);
}


function displayListingPage(packs) { 
	var params = packs.split('|');
	if(document.getElementById(params[0]+'_loader') == null){
		document.getElementById(params[0]).innerHTML = '<img src="'+decodeURIComponent(params[1])+'">';
	}else{
		document.getElementById(params[0]+'_loader').innerHTML = '<img src="'+decodeURIComponent(params[1])+'">';
	}
	 if(httpRequest.readyState == 4) {
		 	
			if(httpRequest.status == 200) {
			
			 var myJSONObject = httpRequest.responseText.evalJSON();
			  var total=0;
			  var display=0;
			 	var hiddens=document.getElementById(params[0]).getElementsByTagName("input");
				for(var j=0;j<hiddens.length;j++){
					var hidden=hiddens[j];
					if (hidden.id=='item_start' && hidden.type=='hidden') {
								hidden.value = myJSONObject[0];
					}
					if(hidden.id=='item_total' && hidden.type=='hidden') {
								total=hidden.value;
					}
					if(hidden.id=='item_display' && hidden.type=='hidden') {
								display=hidden.value;
					}
				}
			   if(myJSONObject[0] > (total/display) ){
						document.getElementById(params[0]+'_btn').style.display = 'none';	
			   };
			  if((myJSONObject[0]-1) == 0){ 
				  document.getElementById(params[0]).innerHTML = myJSONObject[1];
			  }else{
				   var newList = document.createElement("div");
				   newList.id = params[0]+'_'+myJSONObject[0];
				   newList.innerHTML = myJSONObject[1];
				   document.getElementById(params[0]).appendChild(newList);
			  }
			  document.getElementById(params[0]+'_loader').innerHTML = '';
			}
		}
}


var scrollspeed		= "1"		// SET SCROLLER SPEED 1 = SLOWEST
var speedjump		= "40"		// ADJUST SCROLL JUMPING = RANGE 20 TO 40
var startdelay 		= "0" 		// START SCROLLING DELAY IN SECONDS
var nextdelay		= "0" 		// SECOND SCROLL DELAY IN SECONDS 0 = QUICKEST
var topspace		= "0px"		// TOP SPACING FIRST TIME SCROLLING
var frameheight		= "95px"	// IF YOU RESIZE THE WINDOW EDIT THIS HEIGHT TO MATCH



current = (scrollspeed)

function scrollUp(){
dataobj.style.top=parseInt(dataobj.style.top)-(scrollspeed)-speedjump;
}

function scrollDown(){
dataobj.style.top=parseInt(dataobj.style.top)+20;
if (parseInt(dataobj.style.top)>110) dataobj.style.top=-AreaHeight;
}

function HeightData(){
AreaHeight=dataobj.offsetHeight;
if (AreaHeight==0){
setTimeout("HeightData()",( startdelay * 1000 ))
}
else {
ScrollNewsDiv()
}}

function NewsScrollStart(){

dataobj=document.all? document.all.newsText : document.getElementById("newsText")
dataobj.style.top=topspace
setTimeout("HeightData()",( startdelay * 1000 ))

}

function ScrollNewsDiv(){
dataobj.style.top=parseInt(dataobj.style.top)-(scrollspeed)
if (parseInt(dataobj.style.top)<AreaHeight*(-1)) {

dataobj.style.top=topspace;
setTimeout("ScrollNewsDiv()",( nextdelay * 1000 ))
}
else {
setTimeout("ScrollNewsDiv()",speedjump)
}}


function CheckForm(is_submit){
var re = /^[A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)*[@][A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)+$/;
var re2 = /\d/g; 
a = document.getElementById('form');
pass =true;

if(a.yourmessage.value==""){
document.getElementById('yourmessageEmptyError').style.display="block";

pass = false;
}
else {
	document.getElementById('yourmessageEmptyError').style.display="none";
}
if(a.name.value==""){
document.getElementById('nameEmptyError').style.display="block";

pass = false;
}
else {
	document.getElementById('nameEmptyError').style.display="none";
}
if(a.tel.value==""){
document.getElementById('telEmptyError').style.display="block";

pass =false;
}
else {
	document.getElementById('telEmptyError').style.display="none";
	if(!re2.test(a.tel.value)){
document.getElementById('telInvalidError').style.display="block";

pass = false;
}
else {
	document.getElementById('telInvalidError').style.display="none";
}
}

if(a.email.value==""){
document.getElementById('emailEmptyError').style.display="block";

pass = false;
}
else {
	document.getElementById('emailEmptyError').style.display="none";
	if(!re.test(a.email.value)){
document.getElementById('emailInvalidError').style.display="block";

pass = false;
}
else {
	document.getElementById('emailInvalidError').style.display="none";
}
}


if (pass && is_submit) a.submit();

}



function checkSecurimage(url, inputId){
		input = document.getElementById(inputId);
		url = url + '?code=' + input.value;
		startRequest(url, securChanged, input.id);
}
function securChanged(id) 
{ 
 if(httpRequest.readyState == 4) {
        if(httpRequest.status == 200) {
			var txt = httpRequest.responseText;
           document.getElementById(id+"_error").innerHTML = txt;
		   if(txt.strip() == ""){
				   document.getElementById(id).disabled = 'disabled';
		   }
        }
    }
}

function checkForm(url,param,id,action,overall,pid,actionParam, thumbnail, minimun_thumbnail){
	
	
	if( (thumbnail != undefined ) && ( minimun_thumbnail != undefined ) ){ 

		var thumbs = document.getElementById(thumbnail).getElementsByTagName("img");
		var remainImg = minimun_thumbnail;
		if(thumbs != undefined){
			remainImg = minimun_thumbnail - thumbs.length;
		}
		if(remainImg > 0 ){
			var div_error=document.getElementById(thumbnail+'_error');
			div_error.innerHTML = '請上載最小'+minimun_thumbnail+'張圖片';
			div_error.focus();
		}else{
			var div_error=document.getElementById(thumbnail+'_error');
			div_error.innerHTML = '';
		}
	}

	checkSubmit(url,param,id,action,overall,pid,actionParam);
}

function pageRedirect(){

 if(httpRequest.readyState == 4) {
        if(httpRequest.status == 200) {
			
			var myJSONObject = httpRequest.responseText.evalJSON();
			setTimeout(function(){ window.location=myJSONObject[0]; },0);
        }
    }	
}

function setSameHeight(id,target){
	var oheight = document.getElementById(id).offsetHeight;
	var theight = document.getElementById(target).offsetHeight;
	if (theight<oheight)
	document.getElementById(target).style.height=oheight+'px';

}

function swapDisplay(id){
	var obj = document.getElementById(id);

	if( obj.style.display == "none" ){
		obj.style.display = "block";
		return;
	}
	if( obj.style.display == "block"){
		obj.style.display= "none" ;
		return;
	}
	
}
