var	msg_login_error1 = "您輸入的用戶不存在或者蔤碼錯誤，請重新輸入！";
var poll = 
{
	send_poll : function(node_id)
	{
		$("poll-loader").innerHTML = '<img src="/design/ericahk/images/global/ajax-loader-formulaire.gif" alt="Loading" title="Loading" />';
		new Ajax.Request
		( 
		'/layout/set/popup/content/action',{
		asynchronous:false, 
		evalScripts:false, 
		method:'post', 
		parameters:Form.serialize('ajaxpoll'), 
		onComplete:this.after_poll
		})
	},
	after_poll : function(ajax)
	{
	        $("poll-container").innerHTML = ajax.responseText;
	}

};
function poll_result(node_id) {
		$("poll-loader").innerHTML = '<img src="/design/ericahk/images/global/ajax-loader-formulaire.gif" alt="Loading" title="Loading" />';
		var url='/layout/set/popup/content/collectedinfo/'+node_id;
         	new Ajax.Updater
		( 'poll-container',
		url, {
		asynchronous:false, 
		evalScripts:false, 
		method:'get'
		})
}
function init_kv()
{
	Element.show($("kv0"));
	if($("kv1"))
	var timer = setInterval("rouler_img('next')",6000);
}
function rouler_img(position)
{
	var num;
	var new_num;
	var nombre = $A(document.getElementsByClassName('slideone')).length;
	$A(document.getElementsByClassName('slideone')).each(function(element) { 
	if(element.style.display!='none')
	{
		 num = element.id.sub('kv', '');
		 element.style.display='none';
		 if(position == 'prev')
		 {
			if(num == 0)
			 {
			 	new_num = nombre-1;
			 }
			 else
			 { 
			 	new_num = num-1;
			 }	 	
		 }
		 else
		 {
			 if(num == (nombre-1))
			 { 
			 	new_num = '0';
			 }
			 else
			 {
				new_num = num * 1 + 1;
			 }		 	
		 }
		 $('kv' + new_num).style.display='block';
		 throw $break;
	}
	} );
}

function showPopup(idform)
{
	new Effect.Opacity('PopupBg', {duration:1, from:0, to:0.7});
	new Effect.Opacity('PopupWindow', {duration:1, from:0, to:1});

	var url = '/ajaxext/getform/'+idform;

        if(idform=='send_to_a_friend'){
           url = url + '/(url)'+ window.location.pathname;
        }

	new Ajax.Updater
		( 'PopupWindow',
		url, {
		asynchronous:false, 
		evalScripts:false, 
		method:'get'
		})
	window.setTimeout("showPopupLayer();", 100);
}

function showPopupLayer()
{
	$A(document.getElementsByTagName('select')).each(function(el) { Element.hide(el); } );

	$("PopupBg").style.display = "inline";
	$("PopupWindow").style.display = "inline";
	
	// resize and position
	var sizes = getPageSize();

	var widthTotal = sizes[0];
	var heightTotal = sizes[1];

	$('PopupBg').style.width = (widthTotal) + "px";
	$('PopupBg').style.height = (heightTotal) + "px";
	
	var dimension = Element.getDimensions('PopupWindow');
	var screenDim = getScreenSize();
	var screenScroll = getScrollXY();

	var pos_x = (screenDim.width - dimension.width) / 2 + screenScroll.x;
	var pos_y = (screenDim.height - dimension.height) / 2 + screenScroll.y;
	
	$('PopupWindow').style.left = (pos_x-50) + "px";
	$('PopupWindow').style.top = "200px";
	if(isIE6())
	{	$('PopupWindow').style.top = pos_y + "px";}
	 	
		
			
}


function closePopup()
{
	$A(document.getElementsByTagName('select')).each(function(el) { Element.show(el); } );
	
	$("PopupBg").style.display = "none";	
	$("PopupWindow").innerHTML = '<img src="/design/ericahk/images/ajax-loader-formulaire.gif" alt="Loading" title="Loading" />';
	$("PopupWindow").style.display = "none";	
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return { x : scrOfX, y : scrOfY };
}


function getScreenSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return { width : myWidth, height : myHeight };
}
function checkMail(mail)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(mail)) 
		return true;
	else 
		return false;
}
function trim(string)
{
	return string.replace(/(^\s*)|(\s*$)/g,'');
} 

function isIE()
{
return (navigator.appVersion.indexOf("MSIE")!=-1)?true:false;
}

function isIE6()
{
	var versionArray = navigator.appVersion.split("MSIE");
	if(versionArray.length>1)
	{
	versionArray = versionArray[1].split(";");
	var version  = parseInt(versionArray[0]);
	return (version==6);
	}else{
		return 0;
	}
}

var Login = 
{
	send_login : function()
	{
		$("boxlogin").innerHTML = '<img src="/design/ericahk/images/ajax-loader-formulaire.gif" alt="Loading" title="Loading" />';
		new Ajax.Request
		( 
		'/action/login', {
		asynchronous:true, 
		evalScripts:false, 
		method:'post', 
		parameters:Form.serialize('ajaxlogin'), 
		onComplete:this.after_login
		})
	},
	after_login : function(ajax)
	{
		var res = eval('('+ajax.responseText+')');
		if(res.res)
		{
			if($F('url_redirect')!='') location.href = $F('url_redirect');
			else location.reload();
		}
		else
		{
			alert(msg_login_error1);
			$("boxlogin").innerHTML = '<a href="javascript:void(0);" onclick="Login.send_login();">确認</a>';
		}
	},
	forgetpassword : function()
	{
		if($('PopupWindow').style.display != "none")
		{
			$("PopupWindow").innerHTML = '<img src="/design/ericahk/images/ajax-loader-formulaire.gif" alt="Loading" title="Loading" />';
			new Ajax.Updater
				( 'PopupWindow',
				'/ajaxext/getform/forgetpassword', {
				asynchronous:true, 
				evalScripts:false, 
				method:'get'
				})
		}
		else
		{
			showPopup('forgetpassword');
		}
	},
	send_password : function ()
	{
		$("boxforget").innerHTML = '<img src="/design/ericahk/images/ajax-loader-formulaire.gif" alt="Loading" title="Loading" />';
		new Ajax.Request
		( 
		'/action/forgotpassword', {asynchronous:true, 
		evalScripts:false, 
		method:'post', 
		parameters:Form.serialize('ajaxforgetpassword'), 
		onComplete:this.after_send_password
		})		
	},
	after_send_password : function (ajax)
	{
		var res = eval('('+ajax.responseText+')');
		if(res.res)
		{
			alert("謝謝你，我們已發出附有新密碼的電郵，請查收電郵及啓動新密碼。");
			closePopup();
		}
		else
		{
			alert("對不起，此電郵地址不正確，請重新輸入！");
			$("boxforget").innerHTML = '<a href="javascript:void(0);" onclick="Login.send_password();"> 確認</a>';
		}
		
	}
};


function validNewsletter()
{
	$("newsletter_box").innerHTML = '<img src="/design/ericahk/images/ajax-loader-formulaire.gif" alt="Loading" title="Loading" />';
	var url = "/ajaxext/subscribe_newsletter/";
	new Ajax.Request(url, {
					 method:'post',
					 parameters: 'email=' + escape($F("email")) + '&captcha=' + escape($F("captcha")),
					 onComplete:validNewsletterEnd
					 });
}
function validNewsletterEnd(ajax)
{
	var res = eval('('+ajax.responseText+')');
	alert(res.content);
	if(res.res)
	{
		closePopup();
	}
	else
	{
		$("newsletter_box").innerHTML = '<a href="javascript:void(0);" onclick="validNewsletter()">> 现在注册</a>';
	}
}

function send_rose(id)
{
	var gotrose = getCookie("gotrose" + id);
	if(gotrose != "")
	{
		alert("您已经送过鲜花了");
	}
	else
	{
	var btn_rose = $('btn_rose').innerHTML;
	$('btn_rose').innerHTML = '<img src="/design/ericahk/images/ajax-loader-formulaire.gif" alt="Loading" title="Loading" />';
	var url = "/ajaxext/setrose/" + id;
	new Ajax.Request(url, {
					 method:'post',
					 parameters: 'id=' + id,
					 onSuccess:function(){$('btn_rose').innerHTML = btn_rose;},
					 onComplete:send_rose_finished
					 });
	}
}
function send_rose_finished(ajax)
{
	var res = eval('('+ajax.responseText+')');
	alert(res.content);
	if(res.res)
	{
		$("nb_vote").innerHTML = res.nb;
	}
}
function show_rose(id)
{
	var url = "/ajaxext/getrose/" + id;
	new Ajax.Updater("nb_vote",url, {
					 method:'post',
					 parameters: 'id=' + id});	
}

 function test_search_text(str) {

   var myReg = /[\u4e00-\u9fa5]|^[0-9a-zA-Z\s]+$/; 
  
  if(myReg.test(str)) return true;
  return false;
 }
function search_site()
{

	if(!$F('search_word'))
	{
		alert("请输入要查询的关键字!");
		return false;
	}
	if($F('search_word').length < 2)
	{
		alert("请至少输入2个字!");
		return false;
	}
	if(!test_search_text($F('search_word')))
	{
		alert("您只能搜索汉字字母和数字");
		return false;
	}
	location.href = $F("search_site") + $F('search_word');
}

function go(week)
{
	url = $("solar").value;
	if(!url||url=='-1') 
	{
		alert("请选择一个星座");
		return false;
	}
	if(week!="")
	url	+= "/(week)/" + week;
	location.href = url;
}
function gochinese()
{
	if(!$F("chinese")||$F("chinese")=='-1') 
	{
		alert("请选择一个属相");
		return false;
	}
	location.href = $("chinese").value;
}
function pop_astro(page) {
	window.open('/layout/set/popup/astrology/home/' + page,page,'width=420,height=470');
}

/* home forum switch*/
function change_forum(obj,fid)
{
	$A($$('#forum_bloc a')).each(function(element){element.className='';});
	obj.className = "on";
	$("forum_list").innerHTML = "<img src='/design/ericahk/images/ajax-loader-formulaire.gif' alt='Loading...' title='Loading...' />";
	var url = "/interactive/forum/hottopics.php";
	new Ajax.Updater('forum_list', url, {	 method:'get',	 parameters: 'fid=' + fid });
}

/* market remove switch*/
function remove_marketplace(nodeid)
{
     if(confirm("確定要刪除這條記錄嗎？"))
     {
	  location.href="/action/remove_marketplace/"+nodeid;
     }
}

function showcommentPopup(id,commentid)
{
	new Effect.Opacity('commentPopupBg', {duration:1, from:0, to:0.7});
	new Effect.Opacity('commentPopupWindow', {duration:1, from:0, to:1});

	var url = '/commanage/popup_comment/'+id+'/'+commentid;

	new Ajax.Updater
		( 'commentPopupWindow',
		url, {
		asynchronous:true, 
		evalScripts:false, 
		method:'get'
		})
	window.setTimeout("showcommentPopupLayer();", 100);
}

function showcommentPopupLayer()
{
	$A(document.getElementsByTagName('select')).each(function(el) { Element.hide(el); } );

	$("commentPopupBg").style.display = "inline";
	$("commentPopupWindow").style.display = "inline";
	
	// resize and position
	var sizes = getPageSize();

	var widthTotal = sizes[0];
	var heightTotal = sizes[1];

	$('commentPopupBg').style.width = (widthTotal) + "px";
	$('commentPopupBg').style.height = (heightTotal) + "px";
	
	var dimension = Element.getDimensions('commentPopupWindow');
	var screenDim = getScreenSize();
	var screenScroll = getScrollXY();

	var pos_x = (screenDim.width - dimension.width) / 2 + screenScroll.x;
	var pos_y = (screenDim.height - dimension.height) / 2 + screenScroll.y;
	
	$('commentPopupWindow').style.left = (pos_x-50) + "px";
	$('commentPopupWindow').style.top = "200px";
	if(isIE6())
	{	$('commentPopupWindow').style.top = pos_y + "px";}
	 	
		
			
}

function closecommentPopup()
{
	$A(document.getElementsByTagName('select')).each(function(el) { Element.show(el); } );
	
	$("commentPopupBg").style.display = "none";	
	$("commentPopupWindow").innerHTML = '<img src="/design/ericahk/images/ajax-loader-formulaire.gif" alt="Loading" title="Loading" />';
	$("commentPopupWindow").style.display = "none";	
}
